Reverse engineering: Saturation filter simulation
Posted: Tue May 19, 2020 11:22 pm
If anyone can solve this - then I will be very very happy!
Problem.
Fill a background with any greyscale (>0)
With the saturation filter - draw a rectangle with any colour. The result has a blue hue!
Why??
I know this is an error - but the error is due to internal API calculation. Can the error be replicated??
I have made a lot of observations, but no solid formula.
Here is some code for experimentation.
setupgraphics:
GRAPHICS
SET TOOLBAR on
GET ORIENTATION P
IF p=1 OR p=3 THEN LET p=5
IF p=2 OR p=4 THEN LET p=6
SET ORIENTATION P
xmax=SCREEN_WIDTH()
ymax=SCREEN_HEIGHT()
refresh off
draw font size 10
draw color 0.5,0,0
graphics mode normal
rem draw colour bar
for n=0 to xmax
hs=(1/xmax)*n
rem br<hs=blue
br=hs
fill color br,br,hs
fill rect n,0 to n,100
next n
rem overlay over colour bar
graphics mode saturation
fill color 0,0,0
fill rect 0,50 to xmax,100
rem draw result from custom equation
graphics mode normal
for n=0 to xmax
x=((1/xmax)*n)
b=0.5
if x>=0.5 then b=1
if x<0.5 then b=(x*2)
fill color x,x,b
fill rect n,130 to n,ymax/2
next n
for n=0 to xmax*2
for y=0 to 10
GET PIXEL n,50 color r,g,b
GET PIXEL n,150 color rr,gg,bb
draw color r,0,0
draw pixel n,y+600
draw color 0,g,0
draw pixel n,y+620
draw color 0,0,b
draw pixel n,y+640
draw color rr,0,0
draw pixel n,y+700
draw color 0,gg,0
draw pixel n,y+720
draw color 0,0,bb
draw pixel n,y+740
next y
next n
Refresh
main:
pause 0.1
GET TOUCH 0 AS ttx,tty
IF ttx<>-1 AND tty<>-1 then goto end
goto main
end:
fill color 0,0,0
fill rect 0,390 to xmax,ymax
GET PIXEL ttx*2,50 color r,g,b
GET PIXEL ttx*2,150 color rr,gg,bb
draw color 1,0,0
draw text r at 10,400
draw text rr at 10,450
draw color 0,1,0
draw text g at 10,408
draw text gg at 10,458
draw color 0,0,1
draw text b at 10,416
draw text bb at 10,466
refresh
goto main
Problem.
Fill a background with any greyscale (>0)
With the saturation filter - draw a rectangle with any colour. The result has a blue hue!
Why??
I know this is an error - but the error is due to internal API calculation. Can the error be replicated??
I have made a lot of observations, but no solid formula.
Here is some code for experimentation.
setupgraphics:
GRAPHICS
SET TOOLBAR on
GET ORIENTATION P
IF p=1 OR p=3 THEN LET p=5
IF p=2 OR p=4 THEN LET p=6
SET ORIENTATION P
xmax=SCREEN_WIDTH()
ymax=SCREEN_HEIGHT()
refresh off
draw font size 10
draw color 0.5,0,0
graphics mode normal
rem draw colour bar
for n=0 to xmax
hs=(1/xmax)*n
rem br<hs=blue
br=hs
fill color br,br,hs
fill rect n,0 to n,100
next n
rem overlay over colour bar
graphics mode saturation
fill color 0,0,0
fill rect 0,50 to xmax,100
rem draw result from custom equation
graphics mode normal
for n=0 to xmax
x=((1/xmax)*n)
b=0.5
if x>=0.5 then b=1
if x<0.5 then b=(x*2)
fill color x,x,b
fill rect n,130 to n,ymax/2
next n
for n=0 to xmax*2
for y=0 to 10
GET PIXEL n,50 color r,g,b
GET PIXEL n,150 color rr,gg,bb
draw color r,0,0
draw pixel n,y+600
draw color 0,g,0
draw pixel n,y+620
draw color 0,0,b
draw pixel n,y+640
draw color rr,0,0
draw pixel n,y+700
draw color 0,gg,0
draw pixel n,y+720
draw color 0,0,bb
draw pixel n,y+740
next y
next n
Refresh
main:
pause 0.1
GET TOUCH 0 AS ttx,tty
IF ttx<>-1 AND tty<>-1 then goto end
goto main
end:
fill color 0,0,0
fill rect 0,390 to xmax,ymax
GET PIXEL ttx*2,50 color r,g,b
GET PIXEL ttx*2,150 color rr,gg,bb
draw color 1,0,0
draw text r at 10,400
draw text rr at 10,450
draw color 0,1,0
draw text g at 10,408
draw text gg at 10,458
draw color 0,0,1
draw text b at 10,416
draw text bb at 10,466
refresh
goto main