[PB 5.73 LTS x64] QT vs GTK2 DrawingBuffer Size Difference

Linux specific forum
BIOS
New User
New User
Posts: 3
Joined: Thu May 27, 2021 2:10 pm

[PB 5.73 LTS x64] QT vs GTK2 DrawingBuffer Size Difference

Post by BIOS »

Image DrawingBuffer has different size on GTK2 and QT subsystems
Expected = 36
RealSize = 65 (GTK2)
RealSize = 48 (QT)
RealSize = 49 (Empty)
Also get "*ImageData is not Valid" error on Windows (MemorySize(*ImageData) line)

Code: Select all

UsePNGImageDecoder()
Define *FileImage = LoadImage(#PB_Any, GetCurrentDirectory() + "test.png")

StartDrawing(ImageOutput(*FileImage))
Define *ImageData = DrawingBuffer()
Define BufferPitch = DrawingBufferPitch()

Debug "Expected = " + Str(BufferPitch * ImageHeight(*FileImage))
Debug "RealSize = " + Str(MemorySize(*ImageData)) + " (File)"

StopDrawing()
FreeImage(*FileImage)

Define *EmptyImage = CreateImage(#PB_Any, 3, 3)
StartDrawing(ImageOutput(*EmptyImage))
*ImageData = DrawingBuffer()

Debug "RealSize = " + Str(MemorySize(*ImageData)) + " (Empty)"

StopDrawing()
FreeImage(*EmptyImage)
Used image: https://sea.ver0.ru/f/044a57efe47340f1896c/?dl=1

P.S. I think "DrawingBuffer Size = DrawingBufferPitch * ImageHeight"... Am I wrong?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: [PB 5.73 LTS x64] QT vs GTK2 DrawingBuffer Size Difference

Post by GPI »

The buffer must contain the complete Image, but for better performace it can be much bigger.

also MemorySize() ist only valid for memorys allocated with AllocateMemory(), not from DrawingBuffer().
With your example you get some value, but it can be complete wrong.
I personaly think, that the Windows-Version does the only right thing here: Crash.
BIOS
New User
New User
Posts: 3
Joined: Thu May 27, 2021 2:10 pm

Re: [PB 5.73 LTS x64] QT vs GTK2 DrawingBuffer Size Difference

Post by BIOS »

MemorySize is not allowed, then...
Can I use CopyMemory on/from DrawingBuffer, to make independent copy? Sometimes it is work - sometimes I get "Invalid memory access" error....
I am trying to find images that might be causing the error.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: [PB 5.73 LTS x64] QT vs GTK2 DrawingBuffer Size Difference

Post by freak »

BIOS wrote: Fri Jul 02, 2021 6:40 pmP.S. I think "DrawingBuffer Size = DrawingBufferPitch * ImageHeight"... Am I wrong?
For Gtk it might be a little bit smaller because the last line of the image may omit the padding:
If you are doing memcpy() of raw pixbuf data, note that the last row in the pixbuf may not be as wide as the full rowstride, but rather just as wide as the pixel data needs to be. That is, it is unsafe to do memcpy (dest, pixels, rowstride * height) to copy a whole pixbuf. Use gdk_pixbuf_copy() instead, or compute the width in bytes of the last row as width * ((n_channels * bits_per_sample + 7) / 8 ).
"rowstride" is the same as DrawingBufferPitch().

See here: https://developer.gnome.org/gdk-pixbuf/ ... escription
quidquid Latine dictum sit altum videtur
Post Reply