-Fixed and extended the brush factory API. The factory now does a backup before running a script.
-Updated the convolution sample factory to do a proper convolution, reading from the backup. There is still no colormapping. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1262 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
247d7f54fd
commit
ae873551ff
25
factory.c
25
factory.c
@ -33,6 +33,7 @@
|
|||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
#include "io.h" // find_last_slash
|
#include "io.h" // find_last_slash
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "pages.h" // Backup()
|
||||||
#include "readline.h"
|
#include "readline.h"
|
||||||
#include "sdlscreen.h"
|
#include "sdlscreen.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
@ -102,6 +103,14 @@ int L_GetPicturePixel(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int L_GetBackupPixel(lua_State* L)
|
||||||
|
{
|
||||||
|
uint8_t c = Read_pixel_from_backup_screen(lua_tonumber(L, 1),
|
||||||
|
lua_tonumber(L, 2));
|
||||||
|
lua_pushinteger(L, c);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int L_SetColor(lua_State* L)
|
int L_SetColor(lua_State* L)
|
||||||
{
|
{
|
||||||
Set_color(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3),
|
Set_color(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3),
|
||||||
@ -120,6 +129,13 @@ int L_GetColor(lua_State* L)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int L_MatchColor(lua_State* L)
|
||||||
|
{
|
||||||
|
int c = Best_color_nonexcluded(lua_tonumber(L,1), lua_tonumber(L, 2), lua_tonumber(L, 3));
|
||||||
|
lua_pushinteger(L, c);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int L_BrushEnable(__attribute__((unused)) lua_State* L)
|
int L_BrushEnable(__attribute__((unused)) lua_State* L)
|
||||||
{
|
{
|
||||||
Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH);
|
Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH);
|
||||||
@ -204,12 +220,14 @@ void Button_Brush_Factory(void)
|
|||||||
lua_register(L,"getbrushpixel",L_GetBrushPixel);
|
lua_register(L,"getbrushpixel",L_GetBrushPixel);
|
||||||
lua_register(L,"putpicturepixel",L_PutPicturePixel);
|
lua_register(L,"putpicturepixel",L_PutPicturePixel);
|
||||||
lua_register(L,"getpicturepixel",L_GetPicturePixel);
|
lua_register(L,"getpicturepixel",L_GetPicturePixel);
|
||||||
|
lua_register(L,"getbackuppixel",L_GetBackupPixel);
|
||||||
lua_register(L,"setbrushsize",L_SetBrushSize);
|
lua_register(L,"setbrushsize",L_SetBrushSize);
|
||||||
lua_register(L,"setpicturesize",L_SetPictureSize);
|
lua_register(L,"setpicturesize",L_SetPictureSize);
|
||||||
lua_register(L,"getbrushsize",L_GetBrushSize);
|
lua_register(L,"getbrushsize",L_GetBrushSize);
|
||||||
lua_register(L,"getpicturesize",L_GetPictureSize);
|
lua_register(L,"getpicturesize",L_GetPictureSize);
|
||||||
lua_register(L,"setcolor",L_SetColor);
|
lua_register(L,"setcolor",L_SetColor);
|
||||||
lua_register(L,"getcolor",L_GetColor);
|
lua_register(L,"getcolor",L_GetColor);
|
||||||
|
lua_register(L,"matchcolor",L_MatchColor);
|
||||||
lua_register(L,"brushenable",L_BrushEnable);
|
lua_register(L,"brushenable",L_BrushEnable);
|
||||||
|
|
||||||
// For debug only
|
// For debug only
|
||||||
@ -220,6 +238,13 @@ void Button_Brush_Factory(void)
|
|||||||
strcat(scriptdir, Get_item_by_index(&Scripts_list,
|
strcat(scriptdir, Get_item_by_index(&Scripts_list,
|
||||||
scriptlist->List_start + scriptlist->Cursor_position)
|
scriptlist->List_start + scriptlist->Cursor_position)
|
||||||
-> Full_name);
|
-> Full_name);
|
||||||
|
|
||||||
|
// TODO The script may modify the picture, so we do a backup here.
|
||||||
|
// If the script is only touching the brush, this isn't needed...
|
||||||
|
// The backup also allows the script to read from it to make something
|
||||||
|
// like a feedback off effect (convolution matrix comes to mind).
|
||||||
|
Backup();
|
||||||
|
|
||||||
if (luaL_loadfile(L,scriptdir) != 0)
|
if (luaL_loadfile(L,scriptdir) != 0)
|
||||||
{
|
{
|
||||||
message = lua_tostring(L, 1);
|
message = lua_tostring(L, 1);
|
||||||
|
|||||||
@ -2,7 +2,10 @@
|
|||||||
w, h = getpicturesize();
|
w, h = getpicturesize();
|
||||||
|
|
||||||
-- Here is the filtering matrix
|
-- Here is the filtering matrix
|
||||||
matrix = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
|
matrix = {
|
||||||
|
{ 0, -1, 0 },
|
||||||
|
{ -1, 5, -1 },
|
||||||
|
{ 0, -1, 0 }};
|
||||||
|
|
||||||
-- Loop trough all the pixels
|
-- Loop trough all the pixels
|
||||||
-- To make this script simpler we don't handle the picture borders
|
-- To make this script simpler we don't handle the picture borders
|
||||||
@ -11,15 +14,15 @@ w, h = getpicturesize();
|
|||||||
for y = 1, h - 2, 1 do
|
for y = 1, h - 2, 1 do
|
||||||
for x = 1, w - 2, 1 do
|
for x = 1, w - 2, 1 do
|
||||||
filtered =
|
filtered =
|
||||||
matrix[1][1] * getpicturepixel(x - 1, y - 1) +
|
matrix[1][1] * getbackuppixel(x - 1, y - 1) +
|
||||||
matrix[1][2] * getpicturepixel(x , y - 1) +
|
matrix[1][2] * getbackuppixel(x , y - 1) +
|
||||||
matrix[1][3] * getpicturepixel(x + 1, y - 1) +
|
matrix[1][3] * getbackuppixel(x + 1, y - 1) +
|
||||||
matrix[2][1] * getpicturepixel(x - 1, y ) +
|
matrix[2][1] * getbackuppixel(x - 1, y ) +
|
||||||
matrix[2][2] * getpicturepixel(x , y ) +
|
matrix[2][2] * getbackuppixel(x , y ) +
|
||||||
matrix[2][3] * getpicturepixel(x + 1, y ) +
|
matrix[2][3] * getbackuppixel(x + 1, y ) +
|
||||||
matrix[3][1] * getpicturepixel(x - 1, y + 1) +
|
matrix[3][1] * getbackuppixel(x - 1, y + 1) +
|
||||||
matrix[3][2] * getpicturepixel(x , y + 1) +
|
matrix[3][2] * getbackuppixel(x , y + 1) +
|
||||||
matrix[3][3] * getpicturepixel(x + 1, y + 1);
|
matrix[3][3] * getbackuppixel(x + 1, y + 1);
|
||||||
putpicturepixel(x,y,filtered);
|
putpicturepixel(x,y,filtered);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2609,11 +2609,13 @@ byte Best_color_nonexcluded(byte red,byte green,byte blue)
|
|||||||
delta_r=(int)Main_palette[col].R-red;
|
delta_r=(int)Main_palette[col].R-red;
|
||||||
delta_g=(int)Main_palette[col].G-green;
|
delta_g=(int)Main_palette[col].G-green;
|
||||||
delta_b=(int)Main_palette[col].B-blue;
|
delta_b=(int)Main_palette[col].B-blue;
|
||||||
|
|
||||||
|
if(delta_r == delta_g == delta_b) return col;
|
||||||
|
|
||||||
rmean = ( Main_palette[col].R + red ) / 2;
|
rmean = ( Main_palette[col].R + red ) / 2;
|
||||||
|
|
||||||
if (!(dist= ( ( (512+rmean) *delta_r*delta_r) >>8) + 4*delta_g*delta_g + (((767-rmean)*delta_b*delta_b)>>8)))
|
dist= ( ( (512+rmean) *delta_r*delta_r) >>8) + 4*delta_g*delta_g + (((767-rmean)*delta_b*delta_b)>>8);
|
||||||
//if (!(dist=(delta_r*delta_r*30)+(delta_g*delta_g*59)+(delta_b*delta_b*11)))
|
//dist=(delta_r*delta_r*30)+(delta_g*delta_g*59)+(delta_b*delta_b*11)
|
||||||
return col;
|
|
||||||
|
|
||||||
if (dist<best_dist)
|
if (dist<best_dist)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user