Hi!
The idea came recently here:
http://chdk.setepontos.com/index.php?topic=8306.msg87778#msg87778and some nice progress has been done there. However to not bump that thread I decided to start new thread for development ov universal CHDK palette.
Replacement of two sets of addresses starting at C0F14400 and C0F14800 provides possibility to replace any color from palette with YUV values. The example script is posted in mentioned thread.
See:
http://magiclantern.wikia.com/wiki/Register_Map/60DCurrently I play with converting RGB value to YUV but with no success. Y is unsigned 8-bit value where values of YUV model are 0-1 (0-255)
Problems are with U and V values, which are also unsigned ints but values -1 to 0 are probably 128-255 and 0 to 1 are 0-127.
I tried to implement the code from online converter:
http://www.mikekohn.net/file_formats/yuv_rgb_converter.phpwhich bases on:
http://softpixel.com/~cwright/programming/colorspace/yuv/but no success - colors are wrong. I don't know a lot about YUV model and need help with convertion.
Nevertheless the whole thing works - we can replace unused palette colors for any colors we need.
Here's a script in which I tried to use RGB values. Any suggestions?
--[[
@title palette tests
@param r R
@default r 0
@param g G
@default g 0
@param b B
@default b 0
--]]
set_console_layout(0,0,40,10)
base1 = 0xc0f14400
base2 = 0xc0f14800
function rgb_to_y(rv,gv,bv)
yv = (299*rv + 587*gv + 114*bv)/1000
return(yv)
end
function rgb_to_u(rv,gv,bv)
uv = (-169*rv - 331*gv + 500*bv)/1000 + 128
return(uv)
end
function rgb_to_v(rv,gv,bv)
vv = (500*rv - 419*gv - 81*bv)/1000 + 128
return(vv)
end
y=rgb_to_y(r,g,b)
u=rgb_to_u(r,g,b)
v=rgb_to_v(r,g,b)
print("r "..r.." g "..g.." b "..b)
print("y "..y.." u "..u.." v "..v)
value=v+256*u+65536*y
repeat
poke(base1+4,value)
poke(base2+4,value)
draw_rect_filled( 0, 0, 150, 150, 1, 1, 1)
sleep(100)
until 2==3
The picture posted below is taken from SX13IS with palette modified with script:
--[[
@title palette tests
@param s start
@default s 0
@range s 0 255
@param e end
@default e 255
@range e 0 255
--]]
base1 = 0xc0f14400
base2 = 0xc0f14800
paletteY={}
paletteU={}
paletteV={}
paletteOp={}
for p=0, 255 do
paletteY[p]=math.random(1,255)
paletteU[p]=math.random(1,255)
paletteV[p]=math.random(1,255)
paletteOp[p]=math.random(1,255)
end
repeat
for i=0, 255 do
--print(i)
if i>s and i<e then
value=paletteU[i]+256*paletteV[i]+65536*paletteV[i]
poke(base1+4*i, value) -- opacity
end
end
sleep(100)
until 2==3
-------------
-------------