Gamma inspection

For finished programs
User avatar
Dutchman
Posts: 151
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 1747 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: 151
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: 142
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: 151
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

piquadratpi2
Posts: 6
Joined: Thu Mar 12, 2020 6:19 pm

Re: Gamma inspection

Post by piquadratpi2 » Fri Mar 13, 2020 10:55 pm

I was very interested in this program. Many thanks for it. But I never see the text 'Grey = ...' on my screen. Only 'White = ...'. Must I change something? I use an iMac with macOS 10.14.6. Many thanks in advance...

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

Re: Gamma inspection

Post by Dutchman » Sun Apr 05, 2020 10:43 am

piquadratpi2 wrote:
Fri Mar 13, 2020 10:55 pm

Must I change something?
I really do not know. If you really haven't changed or added anything, then it's incomprehensible. However, BestBasic behaves more in an incomprehensible way. I'm done with it.
It is still a long way to go

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

Re: Gamma inspection

Post by kibernetik » Sun Apr 05, 2020 11:27 am

piquadratpi2 wrote:
Fri Mar 13, 2020 10:55 pm
I was very interested in this program. Many thanks for it. But I never see the text 'Grey = ...' on my screen. Only 'White = ...'. Must I change something? I use an iMac with macOS 10.14.6. Many thanks in advance...
Probably there are some errors in the program when setting labels sizes, because even on the author's screenshot you can see an error when text is not shown properly: the label displays text "1.36*gr" instead of "1.36*grey".
Maybe it is the same problem, but in another label. You can try to fix it.

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

Re: Gamma inspection

Post by Dutchman » Mon Apr 06, 2020 7:58 am

kibernetik wrote:
Sun Apr 05, 2020 11:27 am

Maybe it is the same problem, but in another label. You can try to fix it.
Yes, indeed it is the same problem, which is BestBasic incomprehensible behavior.
The text width in the circle is defined as

Code: Select all

tw=1.2*STRWIDTH "1.00*grey "
but even the extra space included is not enough to get enough width from 'STRWIDTH'
Adjusting the factor 1.2 to 1.5 provides a solution. See the change in code in the following section in the subroutine 'SetSigns:'

Code: Select all

…
'--- circle
   txt="": tw=1.5*STRWIDTH "1.00*grey "
…
I am curious about the real solution.
It is still a long way to go

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

Re: Gamma inspection

Post by kibernetik » Mon Apr 06, 2020 8:04 am

BestBASIC returns string size, measured in current font. This string is expected to be a single-line string.

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

Re: Gamma inspection

Post by kibernetik » Mon Apr 06, 2020 8:16 am

Code: Select all

t = "My text"

draw font "Arial" 10
print strwidth t

draw font 20
print strwidth t

draw font 30
print strwidth t
outputs:

Code: Select all

 31.4111 
 62.8223 
 94.2334 

Post Reply