Gamma inspection

For finished programs
Post Reply
User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Gamma inspection

Post by Dutchman » Sat Sep 14, 2019 5:32 pm

The gamma test of viewtopic.php?f=4&p=236#p236 was a reason to make a program with which the gamma could be determined at various grayscale values.

Code: Select all

'Gamma control
'by Ton Nillesen, September 2019
'See https://bestbasic.net/forum/viewtopic.php?f=4&t=14&p=235#p233
'
'==== User settings ===
White=0.8 ' start value
Gamma=1.5 ' start value
DRAWCLEAR 0.2,0.2,0.7 ' background colour
'
'=== Constants ===
wh=300 ' width and height of testfield
sw,sh = SCRSIZE|2
xc,yc=SCRCENTER|2 ' center point
r=wh/3 'radius of center field
sc=SCRSCALE
'--- on pixel scale
px0,py0=xc*sc-wh,yc*sc-wh ' upper left corner
pxm,pym=xc*sc+wh,yc*sc+wh ' bottom right corner
'
'==== Initialisation ====
'--- Set buttons and signs 
GOSUB SetButtons
GOSUB SetSigns
'--- display
DRAW MANUAL
GOSUB DrawGrid
GOSUB Display
'
'==== MAIN CYCLE ====
DO
  oldgamma=gamma : oldwhite=white
  GOSUB CallButtons
  IF (oldgamma<>gamma) THEN GOSUB Display
  IF (oldwhite<>white)
    GOSUB DrawGrid
    GOSUB Display
  ENDIF
REDO
END
'
'========= Functions and Subroutines ========
'NB SignFont.size and ButtFont.size should be set before use
DEF SignFont :RETURN "Menlo",size :END DEF
DEF ButtFont :RETURN "Arial",size :END DEF
'
DEF Parmtext$
'text with whitw/grey parameters
  txt="White="+STRTEXT(.white, "0.0 ")
  txt+=CR$+"Grey="+STRTEXT(.grey, "0.00")
  RETURN txt
END DEF
'
DEF CircleText$
'text in circle
  txt=" ϒ="+STRTEXT(.gamma,"0.00")+CR$
  txt+=STRTEXT(.col/.grey, "0.00")+"*grey"
  RETURN txt
END DEF
'
Display:
  grey=white/2
  col=grey^(1/gamma) ' gamma encoded colour
'--- Draw circle
  DRAWCOLOR col,col,col
  DRAW FCIRC xc,yc,r
'--- draw settings
  INSIGN TEXT parms Parmtext$
  INSIGN TEXT circle CircleText$
'--- Update
  DRAW UPDATE
RETURN
'
CallButtons:
  IF (INBUTT HIT +1) THEN gamma+=0.05
  IF (INBUTT HIT -1) AND gamma>0.05 THEN gamma-=0.05
  IF (INBUTT HIT -2) AND white>=0.2 THEN white-=0.1
  IF (INBUTT HIT +2) AND white<=0.9 THEN white+=0.1
RETURN
'
SetButtons:
  ButtFont.size=50 ' font size
  DRAW FONT ButtFont|2
  bw= 3+STRWIDTH "🔼"
  bh= 3+STRHEIGHT "🔼"
'--- gamma buttons
  bx=(px0/sc-bw)/2
  INBUTT SET    +1 "🔼" bx,yc-bh bw,bh
  INBUTT FONT   +1 ButtFont|2
  INBUTT BCOLOR +1 0,0,0,0
  INBUTT SET    -1 "🔽" bx,yc bw,bh
  INBUTT FONT   -1 ButtFont|2
  INBUTT BCOLOR -1 0,0,0,0
'--- white buttons
  bx=sw-bx-bw
  INBUTT SET    +2 "🔼" bx,yc-bh bw,bh
  INBUTT FONT   +2 ButtFont|2
  INBUTT BCOLOR +2 0,0,0,0
  INBUTT SET    -2 "🔽" bx,yc bw,bh
  INBUTT FONT   -2 ButtFont|2
  INBUTT BCOLOR -2 0,0,0,0
RETURN
'
SetSigns: ' initiate text panels
  fsize=r/5 ' font size
  DRAW FONT fsize : w=STRWIDTH "ABCDEMW abcdemw 1234"
  SignFont.size=(pxm-px0)/sc/w*fsize*0.7 ' fit size
'--- idents
  parms=1 ' parameters white & grey
  circle=2 ' info in circle
'--- parms
  txt=Parmtext$
  th=3.5*STRHEIGHT txt : tw=STRWIDTH txt
  INSIGN SET parms txt,pxm/sc+fsize,yc-bh-th,tw,th
  INSIGN FONT parms, SignFont|2
  INSIGN FCOLOR parms 1,1,0
'--- circle 
  txt="" :tw=1.2*STRWIDTH "1.00*grey "
  INSIGN SET circle txt,xc-tw/2,yc-th/2,tw,th
  INSIGN FONT circle, SignFont|2
  INSIGN FCOLOR circle 1,1,0
'--- draw Y label
  bx=(px0/sc-bw)/2
  DRAW FONT SignFont|2
  DRAWCOLOR 1,1,0
  DRAW TEXT "ϒ",bx+(bw-fsize)/2,yc-bh-fsize/2
RETURN
'
DrawGrid: ' draw black and white pixeel lines
  INSIGN HIDE parms
  DRAW COLOR 0,0,0
  DRAW FRECT px0/sc,py0/sc,pxm/sc,pym/sc
  DRAW UPDATE
  IF (white<0) OR (white>1) THEN white=1
  DRAW COLOR white,white,white
  FOR py=py0 to pym STEP 2
    DRAWPIXEL px0,py,pxm,py
    [OLD version, pixel after pixel
    FOR px=px0 TO pxm
      DRAW PIXEL px,py
    NEXT ]
  NEXT
  INSIGN TEXT parms Parmtext$
  INSIGN SHOW parms
RETURN
Screen shot gamma correction.JPG
Screen shot gamma correction.JPG (42.08 KiB) Viewed 249 times
.
Thanks to this program I discovered that the Mac does not use a constant gamma at all.
It seems more that the values, at least up to 0.5, are simply multiplied by 1.45.
I am curious what is done with values between 0.5 and 1.
Last edited by Dutchman on Sun Sep 22, 2019 9:24 am, edited 1 time in total.
It is still a long way to go

User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Gamma inspection

Post by Dutchman » Fri Sep 20, 2019 8:20 am

I have modified the code for the extended version of the DRAWPIXEL command. This also makes the SIGN "Wait" superfluous during drawing.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Gamma inspection

Post by kibernetik » Fri Sep 20, 2019 8:54 am

Yes, now works much faster

User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Gamma inspection

Post by Dutchman » Sun Sep 22, 2019 9:26 am

I have deleted the unnecessary SIGN "Wait" and cleaned the code. ;)
It is still a long way to go

Post Reply