Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6580 → Rev 6581

/data/common/media/grafx2/scripts/samples_2.4/picture/CellColourReducer.lua
0,0 → 1,37
-- cell colour reducer - jan'11, from Paulo Silva, with help from people from GrafX2 google group (DawnBringer, Adrien Destugues (PulkoMandy), and Yves Rizoud)
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize()
ok,xcell,ycell=inputbox("Modify cell pixel size","xcell",8,1,16,4,"ycell",8,1,16,4);
if ok==true then
function grayscaleindexed(c)
r,g,b=getcolor(c);return math.floor((b*11+r*30+g*59)/100);end
celcnt={};for n=0,255,1 do celcnt[n+1]=0;end -- Arraycounter must have initial value
for y1=0,h-1,ycell do
for x1=0,w-1,xcell do
for i=0,255,1 do
celcnt[i+1]=0;end
for y2=0,ycell-1,1 do
for x2=0,xcell-1,1 do
x=x1+x2;y=y1+y2;u=getpicturepixel(x,y)
celcnt[u+1]=celcnt[u+1]+(1000*xcell*ycell)+math.random(0,950);end;end
ikattr=0;paattr=0;ikcnt=0;pacnt=0
for i=0,255,1 do
if ikcnt<celcnt[i+1] then ikcnt=celcnt[i+1];ikattr=i;end;end
celcnt[ikattr+1]=0
for i=0,255,1 do
if pacnt<celcnt[i+1] then pacnt=celcnt[i+1];paattr=i;end;end
if grayscaleindexed(ikattr)>grayscaleindexed(paattr) then tmpr=ikattr;ikattr=paattr;paattr=tmpr;end
wmid=math.floor((grayscaleindexed(paattr)+grayscaleindexed(ikattr))/2)
for y2=0,ycell-1,1 do
for x2=0,xcell-1,1 do
x=x1+x2;y=y1+y2;u=getpicturepixel(x,y)
if u==ikattr then
idou=ikattr
elseif u==paattr then
idou=paattr
else
idou=ikattr
if grayscaleindexed(u)>wmid then idou=paattr;end
end
putpicturepixel(x,y,idou)
end;end;end;end;end
/data/common/media/grafx2/scripts/samples_2.4/picture/DrawGridIsometric.lua
0,0 → 1,13
-- Draw isometric grid - Copyright 2010 Paulo Silva
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize();
ok,gsiz,ik=inputbox("draw isometric grid","size",16,0,128,5,"colour",1,0,255,6);
if ok==true then
for y=0,h-1,gsiz do
for x=0,w-1,1 do
putpicturepixel(x,y+(x/2)%gsiz,ik);
end;end
for y=0,h-1,gsiz do
for x=0,w-1,1 do
putpicturepixel(x+((gsiz/2)-1),y+(gsiz-1)-((x/2)%gsiz),ik);
end;end;end
/data/common/media/grafx2/scripts/samples_2.4/picture/DrawGridOrthogonal_RGB.lua
0,0 → 1,14
-- draw grid - rgb (matchcolor) - Copyright 2010 Paulo Silva
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize()
ok,xsiz,ysiz,r,g,b=inputbox("draw grid - rgb (matchcolor)","x size",8,1,64,5,"y size",8,1,64,6,"r",128,0,255,6,"g",128,0,255,6,"b",128,0,255,6);
if ok==true then
c=matchcolor(r,g,b)
for y=0,h-1,1 do
for x=0,w-1,xsiz do
putpicturepixel(x,y,c);
end;end
for y=0,h-1,ysiz do
for x=0,w-1,1 do
putpicturepixel(x,y,c);
end;end;end
/data/common/media/grafx2/scripts/samples_2.4/picture/DrawgridOrthogonal_Index.lua
0,0 → 1,11
-- draw grid - indexed colour - Copyright 2010 Paulo Silva
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize();
ok,xsiz,ysiz,c=inputbox("draw grid - indexed colour)","x size",8,1,64,5,"y size",8,1,64,6,"colour id",0,0,255,6);
if ok==true then
for y=0,h-1,1 do
for x=0,w-1,xsiz do
putpicturepixel(x,y,c);end;end
for y=0,h-1,ysiz do
for x=0,w-1,1 do
putpicturepixel(x,y,c);end;end;end
/data/common/media/grafx2/scripts/samples_2.4/picture/GlassGridFilter.lua
0,0 → 1,12
-- Glass grid filter - Copyright 2010 Paulo Silva
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize();
ok,xsiz,ysiz=inputbox("message","xsize",8,0,64,5,"ysize",8,0,64,6);
if ok==true then
for y1=0,h-1,xsiz do
for x1=0,w-1,ysiz do
for y2=0,(ysiz/2)-1,1 do
for x2=0,xsiz-1,1 do
c1=getpicturepixel(x1+x2,y1+y2);c2=getpicturepixel(x1+(xsiz-1)-x2,y1+(ysiz-1)-y2)
putpicturepixel(x1+x2,y1+y2,c2);putpicturepixel(x1+(xsiz-1)-x2,y1+(ysiz-1)-y2,c1)
end;end;end;end;end
/data/common/media/grafx2/scripts/samples_2.4/picture/PaletteToPicture.lua
0,0 → 1,11
-- palette to picture - Copyright 2010 Paulo Silva
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize();
ok,xsiz,ysiz=inputbox("palette to picture","x size",8,1,16,5,"y size",8,1,16,6);
if ok==true then
for y1=0,7,1 do
for x1=0,31,1 do
for y2=0,ysiz-1,1 do
for x2=0,xsiz-1,1 do
putpicturepixel(x1*xsiz+x2,y1*ysiz+y2,y1+x1*8)
end;end;end;end;end
/data/common/media/grafx2/scripts/samples_2.4/picture/Pic2isometric.lua
0,0 → 1,87
--PICTURE (part of): 2 Isometric v0.1b
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- Copyright 2010 Richard Fhager
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; version 2
-- of the License. See <http://www.gnu.org/licenses/>
 
 
-- Color 0 is assumed to be the background
--
 
iso = {{0, 0, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 1, 1, 1, 1, 3, 3},
{2, 2, 2, 2, 3, 3, 3, 3},
{2, 2, 2, 2, 3, 3, 3, 3},
{2, 2, 2, 2, 3, 3, 3, 3},
{0, 0, 2, 2, 3, 3, 0, 0}}
 
isowidth = 8
isoheight = 7
 
xoff = 0.5
yoff = 0
 
xstep = 4
ystep = 2
zstep = 4
 
-- Part of screen from top-left (4 = 1/4)
xsize = 5
ysize = 4
 
 
w, h = getpicturesize()
 
xo = math.floor(w * xoff)
 
-- just don't render more than can be fittted right now
w = math.floor(w / xsize)
h = math.floor(h / ysize)
 
 
 
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
 
isox = x * xstep - y * xstep
isoy = y * ystep + x * ystep
cb = getbackuppixel(x,y)
 
--
if cb ~= 0 then
 
r,g,b = getbackupcolor(cb);
c1 = matchcolor(r,g,b);
c2 = matchcolor(r+64, g+64, b+64);
c3 = matchcolor(r-64, g-64, b-64);
cols = {0,c1,c2,c3}
 
for iy = 1, isoheight, 1 do
for ix = 1, isowidth, 1 do
i = iso[iy][ix]
c = cols[i+1]
if i ~= 0 then putpicturepixel(xo + isox+ix-1, isoy+iy-1, c); end
end
end
 
end
--
 
end
end
 
 
 
 
/data/common/media/grafx2/scripts/samples_2.4/picture/Rainbow-Dark2Bright.lua
0,0 → 1,36
--PICTURE: Rainbow - Dark to Bright v1.1
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
 
 
--dofile("dawnbringer_lib.lua")
run("../libs/dawnbringer_lib.lua")
--> db.shiftHUE(r,g,b, deg)
 
w, h = getpicturesize()
 
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
 
-- Fractionalize image dimensions
ox = x / w;
oy = y / h;
 
r = 255 * math.sin(oy * 2)
g = (oy-0.5)*512 * oy
b = (oy-0.5)*512 * oy
 
r, g, b = db.shiftHUE(r,g,b,ox * 360);
c = matchcolor(r,g,b)
putpicturepixel(x, y, c);
 
end
updatescreen(); if (waitbreak(0)==1) then return; end
end
 
 
/data/common/media/grafx2/scripts/samples_2.4/picture/RemapImage2RGB.lua
0,0 → 1,50
--SCENE: Remap pic to RGB, diag.dith
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
 
-- Copyright 2010 Richard Fhager
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; version 2
-- of the License. See <http://www.gnu.org/licenses/>
 
-- Set Palette (to a predefined one)
 
colors = {{ 0, 0, 0},
{255, 0, 0},
{ 0,255, 0},
{ 0, 0,255}
}
 
 
chm = {1,0,0}
 
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
 
for c = #colors, 255, 1 do
setcolor(c,0,0,0)
end
 
 
 
w, h = getpicturesize()
 
for y = 0, h - 1, 1 do
 
for x = 0, w - 1, 1 do
r,g,b = getbackupcolor(getbackuppixel(x,y));
 
rn = r * chm[1+(y+0+x)%3]
gn = g * chm[1+(y+1+x)%3]
bn = b * chm[1+(y+2+x)%3]
 
n = matchcolor(rn,gn,bn);
 
putpicturepixel(x, y, n);
 
end
end
/data/common/media/grafx2/scripts/samples_2.4/picture/RemapImage2RGB_ed.lua
0,0 → 1,69
--SCENE: Remap pic 2 RGB, 1lineED-dith. (Same line simple error-diffusion dither)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
 
-- Copyright 2010 Richard Fhager
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; version 2
-- of the License. See <http://www.gnu.org/licenses/>
 
 
power = 0.615
 
c1 = 0.8 -- Error weight (white is green)
c2 = 0.2 -- RGB weight (white is r+g+b)
 
-- Set Palette (to a predefined one)
 
colors = {{ 0, 0, 0},
{255, 0, 0},
{ 0,255, 0},
{ 0, 0,255}
}
 
 
chm = {1,0,0}
 
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
 
for c = #colors, 255, 1 do
setcolor(c,0,0,0)
end
 
 
 
w, h = getpicturesize()
 
for y = 0, h - 1, 1 do
 
re = 0
ge = 0
be = 0
 
for x = (y%2), w - 1, 1 do
r,g,b = getbackupcolor(getbackuppixel(x,y));
 
rn = re * c1 + r * chm[1+(y+0+x)%3] * c2
gn = ge * c1 + g * chm[1+(y+1+x)%3] * c2
bn = be * c1 + b * chm[1+(y+2+x)%3] * c2
 
n = matchcolor(rn,gn,bn);
 
putpicturepixel(x, y, n);
 
rn,gn,bn = getcolor(getpicturepixel(x,y));
re = (re + (r - rn)) * power
ge = (ge + (g - gn)) * power
be = (be + (b - bn)) * power
 
 
end
end
/data/common/media/grafx2/scripts/samples_2.4/picture/RemapImageTo3bitPal.lua
0,0 → 1,80
--SCENE: Remap pic to 3bit, LineEDdith. (Same line simple error-diffusion dither)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
 
-- Copyright 2010 Richard Fhager
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; version 2
-- of the License. See <http://www.gnu.org/licenses/>
 
--
-- Just a demonstration.
--
 
 
 
power = 0.6
 
-- Channel shades (shades = 2 ^ bit-depth)
shades = 2
 
mult = 255 / (shades-1)
 
 
colors = {}
col = 0
for r = 0, shades-1, 1 do
for g = 0, shades-1, 1 do
for b = 0, shades-1, 1 do
col = col + 1
colors[col] = { r*mult, g*mult, b*mult }
end
end
end
 
 
for c = 1, #colors, 1 do
 
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
 
end
 
 
for c = #colors, 255, 1 do
setcolor(c,0,0,0)
end
 
 
 
w, h = getpicturesize()
 
for y = 0, h - 1, 1 do
 
re = 0
ge = 0
be = 0
 
for x = (y%2), w - 1, 1 do
r,g,b = getbackupcolor(getbackuppixel(x,y));
 
rn = re + r
gn = ge + g
bn = be + b
 
n = matchcolor(rn,gn,bn);
 
putpicturepixel(x, y, n);
 
rn,gn,bn = getcolor(getpicturepixel(x,y));
re = (re + (r - rn)) * power
ge = (ge + (g - gn)) * power
be = (be + (b - bn)) * power
 
end
end
/data/common/media/grafx2/scripts/samples_2.4/picture/Tiler.lua
0,0 → 1,112
--Picture Tiler by Adrien Destugues
--Extract unique tiles from the spare page
--to the main one. Main page is erased.
--
-- Copyright 2011 Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; version 2
-- of the License. See <http://www.gnu.org/licenses/>
 
-- Copy palette from spare to main
-- TODO
 
-- Grid size
-- TODO : get it from GrafX2
xgrid = 16;
ygrid = 16;
 
-- picture size
w, h = getpicturesize();
 
-- We may need less if there are duplicates
setsparepicturesize(xgrid, w*h/xgrid);
 
tileid = 0;
 
-- blit part of the spare to picture
function blitpicturetospare(srcx, srcy, dstx, dsty, width, height)
local x,y;
for y = 0, height - 1, 1 do
for x = 0, width - 1, 1 do
putsparepicturepixel(dstx+x, dsty+y, getpicturepixel(srcx + x, srcy + y));
end
end
end
 
function comparesparewithpicture(srcx, srcy, dstx, dsty, width, height)
local x,y,color
for y = 0, height - 1, 1 do
for x = 0, width - 1, 1 do
color = getsparepicturepixel(srcx + x, srcy + y);
if color ~= getpicturepixel(dstx+x, dsty+y) then
-- they are different
return false;
end
end
end
-- they are identical
return true;
end
 
-- compute checksum of a picture area
-- it may not be unique, we use it as a key for an hashmap
function checksum(srcx, srcy, width, height)
local sum,x,y
sum = 0;
for y = 0, height - 1, 1 do
for x = 0, width - 1, 1 do
sum = sum + getpicturepixel(srcx+x, srcy+y);
end
end
 
return sum;
end
 
tilemap = {}
 
-- foreach tile
for y = 0, h-1, ygrid do
for x = 0, w - 1, xgrid do
-- existing one ?
csum = checksum(x,y,xgrid,ygrid);
if tilemap[csum] ~= nil then
-- potential match
-- Find matching tileid
found = false;
for id in pairs(tilemap[csum]) do
-- is it a match ?
if comparesparewithpicture(x,y,0,id*ygrid, xgrid, ygrid) then
-- found it !
tilemap[csum][id] = tilemap[csum][id] + 1;
found = true;
break;
end
end
-- Add tile anyway if needed
if not found then
desty = tileid * ygrid;
blitpicturetospare(x, y, 0, desty, xgrid, ygrid);
 
-- add it to the tilemap
tilemap[csum][tileid] = 1;
-- give it a tile id
tileid = tileid + 1;
end
else
-- Copy to spare
desty = tileid * ygrid;
blitpicturetospare(x, y, 0, desty, xgrid, ygrid);
 
-- add it to the tilemap
tilemap[csum] = {}
tilemap[csum][tileid] = 1;
-- give it a tile id
tileid = tileid + 1;
end
end
end
 
setsparepicturesize(xgrid, (tileid-1)*ygrid)
--updatescreen();
/data/common/media/grafx2/scripts/samples_2.4/picture/XBitColourXpaceFromPalette.lua
0,0 → 1,12
-- Copyright 2010 Paulo Silva
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
w,h=getpicturesize();
ok,bitd=inputbox("colourspace from palette","bitdepth:",4,1,8,5);
if ok==true then
bitd3=(2^bitd);bitd8=(2^(math.floor(bitd/2)));bitd9=(2^((math.floor((bitd-1)/2))+1))
for y1=0,(bitd8-1),1 do
for x1=0,(bitd9-1),1 do
for y2=0,(bitd3-1),1 do
for x2=0,(bitd3-1),1 do
putpicturepixel(x1*bitd3+x2,y1*bitd3+y2,matchcolor((y2*255)/(bitd3-1),((y1*8+x1)*255)/(bitd3-1),(x2*255)/(bitd3-1)))
end;end;end;end;end