Point() function : what is the type of its result ?

Just starting out? Need help? Post your questions and find answers here.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Point() function : what is the type of its result ?

Post by Olli »

Hello,

I find a light problem of execution with the Point command, and I did not find a type convention in the doc.

In the doc, we have this :

Code: Select all

Syntax :

Result = Point(X, Y)
This seems to mean implicitly this (I suppose) :

Code: Select all

Result.I = Point(X.I, Y.I)
And this cause a variable type, depending of the range mode execution : x86 or x64.

On x86 :

Code: Select all

Result.L = Point(X.L, Y.L)
On x64 :

Code: Select all

Result.Q = Point(X.Q, Y.Q)

So, the problem I met is the next one :

On X64, I tried to store an alpha color value from the Point() result to an array of 32-bits longs, which are ever signed.

So, lets see the binary process :

Code: Select all

Point(X, Y) hex result :
0x00000000FFAABBCCh

Result of Longs array storage :
0xFFAABBCCh

Result comparison between a other pixel being the same alpha color and the value on the Longs array :
False (!)

Analysis of this comparison :
Is
0x00000000FFAABBCCh
Equ to
0x800000007FAABBCCh
?
Question : Am I right when a doc does not mention the result type, that the result is so ever an integer ?

Because, when I did not find a result type in the doc, after have made my beautiful light type bug, I was wondering myself what good change to choose to stay retro-compatible from x64 code to x86.

My choice on X64 is change my array type from Long to Integer, but I am not sure, seeing no information or rule about the default type in the doc...
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Point() function : what is the type of its result ?

Post by Mijikai »

DrawingBufferPixelFormat() describes how to treat the result.
Anyway, you are free to put the result into anything you want if it serves your purpose.
You could also use structures, Macros like Red(), Green() or inline assembly, bitshifting or pointers.
There are countless ways to treat and work with color values.
It all depends on what you want to do.
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Point() function : what is the type of its result ?

Post by mk-soft »

This is once again the typical problem with the conversion from x86 to x64. The result of Point is a LONG (32Bit Unsigned).

With PB, however, a LONG is always signed.

PB x86 converts the LONG (as signed) into a QUAD (as signed).

PB x64 takes the result from Point into a QUAD as it should be, without converting the Unsigned LONG.

Update
- Added direct components access
Update 2
- Added direct buffer access

Code: Select all

;-TOP

Structure udtRGBA
  Red.a
  Green.a
  Blue.a
  Alpha.a
EndStructure

Structure udtBGRA
  Blue.a
  Green.a
  Red.a
  Alpha.a
EndStructure

Structure udtColor
  StructureUnion
    Value.l
    Component.udtRGBA
  EndStructureUnion
EndStructure

Define qVal.q, lVal.l
Define Color.udtColor

Structure udtImage32
  StructureUnion
    Value.l[0]
    RGBA.udtRGBA[0]
    BGRA.udtBGRA[0]
  EndStructureUnion
EndStructure

image = CreateImage(0, 32, 32, 32, #Red)

If StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  qVal = Point(1, 1)
  lVal = Point(1, 1)
  Color\Value = Point(1, 1)
  
  Debug "qVal  = " + RSet(Hex(qVal, #PB_Quad), 16, "0") + " / Signed Value = " + qVal
  Debug "lVal  = " + RSet(Hex(lval, #PB_Long), 16, "x") + " / Signed Value = " + lVal
  
  Debug "--- Values"
  Debug "Alpha = " + Color\Component\Alpha
  Debug "Red   = " + Color\Component\Red
  Debug "Green = " + Color\Component\Green
  Debug "Blue  = " + Color\Component\Blue
  
  Debug "--- Buffer"
  *Buffer.udtImage32 = DrawingBuffer()
  If *Buffer
    Pitch       = DrawingBufferPitch()
    PixelFormat = DrawingBufferPixelFormat()
    
    x = 1
    y = 1
    Plot(x, y, $7F008000)
    
    If PixelFormat & #PB_PixelFormat_ReversedY
      Debug "ReversY"
      offset = ((ImageHeight(0) - y -1) * ImageWidth(0)) + x
    Else
      offset = (y * ImageWidth(0)) + x
    EndIf  
    If PixelFormat & #PB_PixelFormat_32Bits_RGB
      Debug "RGB"
      Debug "Alpha = " + *Buffer\RGBA[offset]\Alpha
      Debug "Red   = " + *Buffer\RGBA[offset]\Red
      Debug "Green = " + *Buffer\RGBA[offset]\Green
      Debug "Blue  = " + *Buffer\RGBA[offset]\blue
    ElseIf PixelFormat & #PB_PixelFormat_32Bits_BGR
      Debug "BGR"
      Debug "Alpha = " + *Buffer\BGRA[offset]\Alpha
      Debug "Red   = " + *Buffer\BGRA[offset]\Red
      Debug "Green = " + *Buffer\BGRA[offset]\Green
      Debug "Blue  = " + *Buffer\BGRA[offset]\blue
    EndIf
  EndIf
  StopDrawing()
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Point() function : what is the type of its result ?

Post by Olli »

Ooch... The code is not short ! :lol: This has cast my brain on the floor... I will try it to watch the evidence it contains...
Post Reply