Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6580 → Rev 6581

/data/common/media/grafx2/scripts/samples_2.4/palette/Desaturate.lua
0,0 → 1,40
--PALETTE Adjust: Desaturate v1.1
--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/>
 
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
 
 
-- Note: Negative values will work as INCREASED saturation, but I'm not sure if this function is 100% correct
 
 
--percent = 25
 
OK,percent = inputbox("Desaturate Palette","Percent %", 25, 0,100,0);
 
--
function desaturate(percent,r,g,b) -- V1.0 by Richard Fhager
p = percent / 100
a = (math.min(math.max(r,g,b),255) + math.max(math.min(r,g,b),0)) * 0.5 * p
r = r + (a-r*p)
g = g + (a-g*p)
b = b + (a-b*p)
return r,g,b
end
--
 
if OK == true then
 
for c = 0, 255, 1 do
setcolor(c, desaturate(percent,getcolor(c)))
end
 
end
/data/common/media/grafx2/scripts/samples_2.4/palette/ExpandColors.lua
0,0 → 1,171
--PALETTE: Expand Colors v1.0
--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/>
 
 
-- Continously fill the greatest void in the area of the color-cube enclosed by (or along ramps of) initial colors
-- This algorithm will create lines of allowed colors (all ranges) in 3d colorspace and the pick
-- new colors from the most void areas (on any line). Almost like a Median-cut in reverse.
--
-- Rather than filling the colorcube symmetrically it adds intermediate colors to the existing ones.
--
-- Running this script on the C64 16-color palette might be educational
--
--
-- Source cols#, Expand to #,
-- Ex: 15-31 means that palette colors 0-15 is expanded to 16 new colors placed at slots 16-31
--
-- Spread mode: OFF - New colors will conform to the contrast & saturation of original colors
-- (new colors will stay on the ramps possible from the original colors)
--
-- ON - New colors will expand their variance by each new addition (mostly notable when adding many new colors)
-- Will add range lines/ramps to all new colors from old ones, but keep within max/min values of the
-- original colors. 15-bit mode will dampen the spread towards extreme colors (if starting with low contrast)
--
-- 15-bit colors: Higher color-resolution, 32768 possible colors rather than the 4096 of 12bit. Slower but perhaps better.
--
 
SHADES = 16 -- Going 24bit will probably be too slow and steal too much memory, so start with 12bit (4096 colors) for now
 
ini = 0
exp = 255
 
OK,ini,exp,linemode,fbit = inputbox("Expand Colors (0-255):",
"Source Cols #: 1-254", 15, 1,254,0,
"Expand to #: 2-255", 31, 2,255,0,
"Spread mode", 0, 0,1,0,
"15-bit colors (slow)", 0, 0,1,0
);
 
if (fbit == 1) then SHADES = 32; end
 
 
 
function initColorCube(sha)
ary = {}
for z = 0, sha-1, 1 do
ary[z+1] = {}
for y = 0, sha-1, 1 do
ary[z+1][y+1] = {}
for x = 0, sha-1, 1 do
ary[z+1][y+1][x+1] = {false,0}
end
end
end
return ary
end
 
-- Gravity model (think of colors as stars of equal mass/brightness in a 3d space)
function addColor2Cube(cube,sha,r,g,b)
star = 1000000
fade = 1000
 
cube[r+1][g+1][b+1] = {false,star}
 
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
 
d = fade / ( (x-b)^2 + (y-g)^2 + (z-r)^2 )
 
cube[z+1][y+1][x+1][2] = cube[z+1][y+1][x+1][2] + d
 
end;end;end
end
 
 
-- Create new allowed colorlines in colorspace (ramps from which colors can be picked)
function enableRangeColorsInCube(cube,sha,r1,g1,b1,r2,g2,b2)
 
local div,r,g,b
div = 256 / sha
rs = (r2 - r1) / sha / div
gs = (g2 - g1) / sha / div
bs = (b2 - b1) / sha / div
 
for n = 0, sha-1, 1 do
 
r = math.floor(r1/div + rs * n)
g = math.floor(g1/div + gs * n)
b = math.floor(b1/div + bs * n)
 
cube[r+1][g+1][b+1][1] = true
 
end
end
 
 
function findVoid(cube,sha)
weakest = 999999999999
weak_i = {-1,-1,-1}
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
c = cube[z+1][y+1][x+1]
if c[1] == true then
w = c[2]
if w <= weakest then weakest = w; weak_i = {z,y,x}; end
end
end;end;end
return weak_i[1],weak_i[2],weak_i[3]
end
 
--
 
if OK == true then
 
cube = initColorCube(SHADES)
 
-- Define allowed colorspace
for y = 0, ini-1, 1 do
r1,g1,b1 = getcolor(y)
for x = y+1, ini, 1 do
r2,g2,b2 = getcolor(x)
enableRangeColorsInCube(cube,SHADES,r1,g1,b1,r2,g2,b2)
end
end
 
div = 256 / SHADES
 
-- Fill cube with initial colors
for n = 0, ini, 1 do
r,g,b = getcolor(n)
addColor2Cube(cube,SHADES,math.floor(r/div),math.floor(g/div),math.floor(b/div))
end
 
 
for n = ini+1, exp, 1 do
r,g,b = findVoid(cube,SHADES)
 
if (r == -1) then messagebox("Report:","No more colors can be found, exit at "..n); break; end
 
mult = 255 / (SHADES - 1)
setcolor(n, r*mult,g*mult,b*mult)
 
if linemode == 1 then
-- Add lines from new color to all old
for x = 0, n-1, 1 do
r2,g2,b2 = getcolor(x)
enableRangeColorsInCube(cube,SHADES,r*mult,g*mult,b*mult,r2,g2,b2) -- uses 24bit values rgb
end
end
addColor2Cube(cube,SHADES,r,g,b) -- rgb is in 'shade' format here
end
 
end
 
 
 
/data/common/media/grafx2/scripts/samples_2.4/palette/FillColorCube.lua
0,0 → 1,105
--PALETTE: Fill ColorCube voids v1.0
--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/>
 
--
-- Create a palette by continously filling the greatest void in the RGB color-cube
--
 
 
SHADES = 16 -- Going 24bit will probably be too slow and steal too much memory, so we're 12bit (4096 colors) for now
 
ini = 0
exp = 255
 
OK,ini,exp = inputbox("Fill Palette Color voids",
"From/Keep #: 0-254", 0, 0,254,0,
"Replace to #: 1-255", 31, 1,255,0
);
 
 
function initColorCube(sha)
ary = {}
for z = 0, sha-1, 1 do
ary[z+1] = {}
for y = 0, sha-1, 1 do
ary[z+1][y+1] = {}
end
end
return ary
end
 
 
function addColor2Cube(cube,sha,r,g,b) -- Gravity model
star = 1000000
fade = 1000
 
cube[r+1][g+1][b+1] = star
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
 
d = fade / ( (x-b)^2 + (y-g)^2 + (z-r)^2 )
 
if cube[z+1][y+1][x+1] ~= nil then
cube[z+1][y+1][x+1] = cube[z+1][y+1][x+1] + d
else
cube[z+1][y+1][x+1] = d
end
 
end;end;end
end
 
 
function findVoid(cube,sha)
weakest = 999999999999
weak_i = {-1,-1,-1}
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
w = cube[z+1][y+1][x+1]
if w <= weakest then weakest = w; weak_i = {z,y,x}; end
end;end;end
return weak_i[1],weak_i[2],weak_i[3]
end
 
--
 
if OK == true then
 
cube = initColorCube(SHADES)
-- Fill cube with initial colors
for n = 0, ini-1, 1 do
r,g,b = getcolor(n)
div = SHADES
addColor2Cube(cube,SHADES,math.floor(r/div),math.floor(g/div),math.floor(b/div))
end
 
if ini == 0 then -- With no inital color, some inital data must be added to the colorcube.
addColor2Cube(cube,SHADES,0,0,0)
setcolor(0, 0,0,0)
ini = ini + 1
end
 
for n = ini, exp, 1 do
r,g,b = findVoid(cube,SHADES)
mult = 255 / (SHADES - 1)
setcolor(n, r*mult,g*mult,b*mult)
addColor2Cube(cube,SHADES,r,g,b)
end
 
end
 
 
 
/data/common/media/grafx2/scripts/samples_2.4/palette/InvertedRGB.lua
0,0 → 1,27
--PALETTE Modify: Inverted RGB
--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/>
 
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
 
 
 
for c = 0, 255, 1 do
 
r,g,b = getcolor(c)
r2 = (g+b)/2
g2 = (r+b)/2
b2 = (r+g)/2
 
setcolor(c, r2,g2,b2)
 
end
/data/common/media/grafx2/scripts/samples_2.4/palette/Set3bit.lua
0,0 → 1,39
--PALETTE Set: 3 Bit (8 Primaries)
--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/>
 
 
-- Generate palette of all colors possible with a given number of shades for each channel
-- 2 shades = 1 bit / channel = 3 bit palette = 2^3 colors = 8 colors
-- 4 shades = 2 bit / channel = 6 bit palette = 2^6 colors = 64 colors
 
-- 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
/data/common/media/grafx2/scripts/samples_2.4/palette/Set6bit.lua
0,0 → 1,39
--PALETTE Set: Full 6 Bit (64 colors)
--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/>
 
 
-- Generate palette of all colors possible with a given number of shades for each channel
-- 2 shades = 1 bit / channel = 3 bit palette = 2^3 colors = 8 colors
-- 4 shades = 2 bit / channel = 6 bit palette = 2^6 colors = 64 colors
 
-- Channel shades (shades = 2 ^ bit-depth)
shades = 4
 
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
/data/common/media/grafx2/scripts/samples_2.4/palette/SetC64Palette.lua
0,0 → 1,50
--PALETTE Set: C64 Palette (16 colors)
--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/>
 
 
OK,clean = inputbox("C64 Palette:", "Remove old palette", 0, 0,1,0
);
 
 
 
colors = {{0, 0, 0}, -- 0 Black
{62, 49,162}, -- 1 D.Blue
{87, 66, 0}, -- 2 Brown
{140, 62, 52}, -- 3 D.Red
{84, 84, 84}, -- 4 D.Grey
{141, 72,179}, -- 5 Purple
{144, 95, 37}, -- 6 Orange
{124,112,218}, -- 7 B.Blue
{128,128,128}, -- 8 Grey
{104,169, 65}, -- 9 Green
{187,119,109}, -- 10 B.Red
{122,191,199}, -- 11 Cyan
{171,171,171}, -- 12 B.Grey
{208,220,113}, -- 13 Yellow
{172,234,136}, -- 14 B.Green
{255,255,255} -- 15 White
}
 
 
if OK == true then
 
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
 
 
if clean == 1 then
for c = #colors+1, 256, 1 do
setcolor(c-1,0,0,0)
end
end
 
end
/data/common/media/grafx2/scripts/samples_2.4/palette/ShiftHue.lua
0,0 → 1,55
--PALETTE Adjust: Shift Hue v0.9
--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/>
 
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
 
 
--Shift_degrees = 45
 
OK,Shift_degrees = inputbox("Shift Hue v0.9","Degrees", 45, 0,360,3);
 
 
--
function shiftHUE(r,g,b,deg) -- V1.3 R.Fhager 2007, adopted from Evalion
local c,h,mi,mx,d,s,p,i,f,q,t
c = {g,b,r}
mi = math.min(r,g,b)
mx = math.max(r,g,b); v = mx;
d = mx - mi;
s = 0; if mx ~= 0 then s = d/mx; end
p = 1; if g ~= mx then p = 2; if b ~= mx then p = 0; end; end
if s~=0 then
h=(deg/60+(6+p*2+(c[1+p]-c[1+(p+1)%3])/d))%6;
i=math.floor(h);
f=h-i;
p=v*(1-s);
q=v*(1-s*f);
t=v*(1-s*(1-f));
c={v,q,p,p,t,v}
r = c[1+i]
g = c[1+(i+4)%6]
b = c[1+(i+2)%6]
end
 
return r,g,b
end
--
 
if OK == true then
 
for c = 0, 255, 1 do
r,g,b = getcolor(c)
setcolor(c, shiftHUE(r,g,b,Shift_degrees))
end
 
end