Page 1 of 1

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

Posted: Fri Jul 02, 2021 6:40 pm
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?

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

Posted: Sat Jul 03, 2021 8:33 pm
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.

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

Posted: Sat Jul 03, 2021 8:47 pm
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.

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

Posted: Sat Jul 03, 2021 11:20 pm
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