Reverse engineering: Saturation filter simulation

Post Reply
IRIGIMA
Posts: 21
Joined: Wed May 03, 2017 10:30 pm
My devices: iOS iPhone 6
Flag: Great Britain
Contact:

Reverse engineering: Saturation filter simulation

Post by IRIGIMA »

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
Last edited by IRIGIMA on Wed May 20, 2020 9:42 pm, edited 1 time in total.

IRIGIMA
Posts: 21
Joined: Wed May 03, 2017 10:30 pm
My devices: iOS iPhone 6
Flag: Great Britain
Contact:

Re: Quest: Saturation filter simulation

Post by IRIGIMA »

Here is a newer version working from a 0>B<1 and R&G channels set to B/4.
I'm now looking for an equation to match all (R=G)<B !! So please help lol.

Top blue row input
Below output

RGB values shown and equation value shown far right matching read values*3

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/4
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
GET PIXEL ttx*2,300 color rrr,ggg,bbb


draw color 1,0,0
draw text r at 10,400
draw text rr at 10,450
draw text rrr at 10,500

draw color 0,1,0
draw text g at 10,408
draw text gg at 10,458
draw text ggg at 10,508

draw color 0,0,1
draw text b at 10,416
draw text bb at 10,466
draw text bbb at 10,516

draw color 0.5,0.5,0.5
draw text (r+g+b)at 100,408
draw text (rr+gg+bb)at 100,458
draw text (rrr+ggg+bbb)at 100,508

a1=(r+g+b)*2
a2=(a1/3)

draw text a2 at 200,408

refresh

goto main
Attachments
164EA033-A0F2-4CB5-AF8B-E5B0B6627E6B.jpeg
164EA033-A0F2-4CB5-AF8B-E5B0B6627E6B.jpeg (369.99 KiB) Viewed 2862 times

IRIGIMA
Posts: 21
Joined: Wed May 03, 2017 10:30 pm
My devices: iOS iPhone 6
Flag: Great Britain
Contact:

Re: Reverse engineering: Saturation filter simulation

Post by IRIGIMA »

Update:

Working version with exact results for R < 0.5 with results for grey background.
Code needs help for values >0.5

(This bit)


(

rem ******* code needs adjusting for r>0.5
if r>0.5 then
r=0.3*r
g=0.59*g
pp=(r+g)/0.89
r=pp
g=pp
b=(r+g)+(b*0.11)
end if
rem ***************************************

)


Full code here:

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

br=hs/1
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 ******* if background grey
graphics mode normal
for n=0 to xmax
x=((1/xmax)*n)
GET PIXEL n*2,5 color r,g,b
if r<=0.5 then
r=0.3*r
g=0.59*g
pp=(r+g)
r=pp
g=pp
b=(r+g)+(b*0.11)
end if


rem ******* code needs adjusting for r>0.5
if r>0.5 then
r=0.3*r
g=0.59*g
pp=(r+g)/0.89
r=pp
g=pp
b=(r+g)+(b*0.11)
end if
rem ***************************************

fill color r,g,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

rem if background blue
graphics mode normal
for n=0 to xmax
x=((1/xmax)*n)
GET PIXEL n*2,50 color r,g,b

a2=((0.3*R)+(0.59*G)+(0.11*B))


fill color a2,a2,a2
rem fill rect n,102 to n,ymax/2
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
GET PIXEL ttx*2,300 color rrr,ggg,bbb


draw color 1,0,0
draw text r at 10,400
draw text rr at 10,450
draw text rrr at 10,500

draw color 0,1,0
draw text g at 10,408
draw text gg at 10,458
draw text ggg at 10,508

draw color 0,0,1
draw text b at 10,416
draw text bb at 10,466
draw text bbb at 10,516

draw color 0.5,0.5,0.5
draw text (r+g+b)at 100,408
draw text (rr+gg+bb)at 100,458
draw text (rrr+ggg+bbb)at 100,508

a2= ((0.3*R)+(0.59*G)+(0.11*B))

draw text a2 at 200,408

refresh

goto main
Attachments
38C4A2C9-1440-41F4-9456-56B06FCEC2B8.png
38C4A2C9-1440-41F4-9456-56B06FCEC2B8.png (571.31 KiB) Viewed 2850 times

IRIGIMA
Posts: 21
Joined: Wed May 03, 2017 10:30 pm
My devices: iOS iPhone 6
Flag: Great Britain
Contact:

Re: Reverse engineering: Saturation filter simulation

Post by IRIGIMA »

Solved.
🤓

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Reverse engineering: Saturation filter simulation

Post by Mr. Kibernetik »

Congratulation!

But why the color of your app toolbar text is blue on your screenshots? Strange. It should be black...

Post Reply