is there a faster/better method for this?
Code: Select all
a=a+b
if a>255
a=255
endif
Code: Select all
a=a+b
if a>255
a=255
endif
Code: Select all
b.a = 100
a.a = 200
a + b
Debug a ; shows 44
Code: Select all
b.a = 100
a.u = 200
a = a + b
;1. version (assumes a and b were < 256 before the addition)
a = ((a >> 8) * $ff) | (a & $ff)
;2. version (works for every value of a and b)
;a = (Bool(a > 255) * $ff) | (a & $ff)
Debug a
Code: Select all
Protected *red.Ascii, *green.Ascii, *blue.Ascii, x,y,r,g,b,gwhite.f,gblack.f
r=*red\a*gwhite:If r>255:r=255:EndIf:*red\a=r
Code: Select all
a.ascii=200
a=a+100
if a>255
a=255
endif
Code: Select all
a.q=200
a=a+100
if a>255
a=255
endif
Problems of not speaking non-native language.Jac de Lad wrote:That's exactly what I said...
My bad, the code I really need is this:NicTheQuick wrote:If a is of type Ascii, you will never be able to get a value above 255. It will always overflow. So you condition "a > 255" will never be true.Well, it works like this without branching, and therefore the prefetching of your CPU can help to make it faster. But I never tested it. And I guess there will be an assembler instruction which can do all of this in one clock cycle:Code: Select all
b.a = 100 a.a = 200 a + b Debug a ; shows 44
Code: Select all
b.a = 100 a.u = 200 a = a + b ;1. version (assumes a and b were < 256 before the addition) a = ((a >> 8) * $ff) | (a & $ff) ;2. version (works for every value of a and b) ;a = (Bool(a > 255) * $ff) | (a & $ff) Debug a
Code: Select all
define a.q, b.f
a=200: b=1.3
a=a*b
if a>255
a=255
endif
Code: Select all
a=a*1.3
a=a-256*Mod(a,256)
Code: Select all
define.a a, b
a = 251
b = 6
! xor ax,ax ; reset registers
! xor bx,bx
! mov dx,65280 ; dh = 255
! mov ah, [v_a] ; input a and b values
! mov bh, [v_b]
! add ah,bh ; does the sum and updates carry flag if the result requires it
! cmovc ax,dx ; if carry is set, then ah = dh = 255
! mov [v_a], ah
debug a
Please test asm code before, in the way it has already a bug you find. (just the version for over than 255 for now)Jac de Lad wrote:[...]and bottom to 0[...]
Code: Select all
#IGammaShift = (SizeOf(Integer) - 2) * 8 - 1
#IGammaFactor = 1 << #IGammaShift
Define gamma.f = 1.3
;convert gamma value to integer BEFORE iterating over all the pixel values
Define iGamma.i
If gamma >= 256
iGamma = #IGammaFactor << 8
Else
iGamma = gamma * #IGammaFactor
EndIf
; No iterate over the values and apply the gamma
Define a.i, ag.i
For a = 0 To 255
ag = (a * iGamma) >> #IGammaShift
ag = (ag | (Bool(ag > $ff) * $ff)) & $ff
Debug "a = " + a + " -> " + ag
Next
Code: Select all
Procedure Limit(iData)
If iData>255:iData=255:EndIf
If iData<0:iData=0:EndIf
ProedureReturn iData
EndProcedure