[Done] Qt - Image problems

Post bugreports for the Linux version here
wombats
Enthusiast
Enthusiast
Posts: 604
Joined: Thu Dec 29, 2011 5:03 pm

[Done] Qt - Image problems

Post by wombats »

I am having a lot of problems with #PB_Image_Transparent and CustomFilterCallback on Qt (the example in the help behaves differently on GTK and Qt, so I'm unsure how well that command works on Qt). Both when used together and not. I am getting a lot of distortion, GrabImage coordinates being off, etc. Has anyone else had any issues?
Last edited by wombats on Tue Oct 29, 2019 12:19 am, edited 1 time in total.
wombats
Enthusiast
Enthusiast
Posts: 604
Joined: Thu Dec 29, 2011 5:03 pm

Re: Qt - Image problems

Post by wombats »

Here's an example that shows how the positions get messed up with the #PB_Image_Transparent flag. If you take out that flag, it works, but lacks the transparency. It all works fine on GTK, Windows and macOS. Click the button and select a PNG file with transparency. It will split it into 32x32 sub-images and redraw them. I use this code to create icons from an large sheet of them, but it all gets messed up on Qt.

Code: Select all

EnableExplicit

UsePNGImageDecoder()

Runtime Enumeration
  #MyDialog
  #MyDialogOpenButton
  #MyDialogPasteButton
  #MyDialogCanvasGadget
EndEnumeration

Declare DrawMyDialogCanvas()

Global Quit

Procedure.s GetMyDialogXML()
  Protected xml$
  xml$ + "<window id='#MyDialog' name='MyDialog' text='Image' minwidth='auto' minheight='auto' flags='#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered'>"
  xml$ + "  <vbox expand='item:2'>"
  xml$ + "    <button id='#MyDialogOpenButton' text='Open...' width='90' height='25'/>"
  xml$ + "    <canvas id='#MyDialogCanvasGadget' width='350' height='400'/>"
  xml$ + "  </vbox>"
  xml$ + "</window>"
  ProcedureReturn xml$
EndProcedure

Runtime Procedure OnMyDialogClose()
  FreeDialog(#MyDialog)
  Quit = 1
EndProcedure

Runtime Procedure OnMyDialogOpenButtonClick()
  Protected result$, import_img, img, sub_width, sub_height, row_count, column_count,
            new_img, old_img, y, r, c, sub_img
  
  result$ = OpenFileRequester("", "", "", 0)
  
  If FileSize(result$) = -1
    ProcedureReturn
  EndIf
  
  import_img = LoadImage(#PB_Any, result$)
  
  img = CreateImage(#PB_Any, ImageWidth(import_img), ImageHeight(import_img), 32, #PB_Image_Transparent)
  
  If StartDrawing(ImageOutput(img))
    DrawingMode(#PB_2DDrawing_AlphaChannel)
    Box(0, 0, OutputWidth(), OutputHeight(), RGBA(0, 0, 0, 0))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    DrawAlphaImage(ImageID(import_img), 0, 0)
    StopDrawing()
  EndIf  
  
  FreeImage(import_img)
  
  sub_width = 32 : sub_height = 32
  
  row_count = ImageHeight(img) / sub_height
  column_count = ImageWidth(img) / sub_width
  
  new_img = CreateImage(#PB_Any, column_count * sub_width, row_count * sub_height, 32, #PB_Image_Transparent)
  
  y = 0
  If StartDrawing(ImageOutput(new_img))
    For r = 0 To row_count - 1
      For c = 0 To column_count - 1
        sub_img = GrabImage(img, #PB_Any, c * sub_width, r * sub_height, sub_width, sub_height)
        If IsImage(sub_img)
          DrawAlphaImage(ImageID(sub_img), c * sub_width, y)
          FreeImage(sub_img)
        EndIf
      Next
      y + sub_height
    Next
    StopDrawing()
  EndIf
  old_img = GetGadgetData(#MyDialogCanvasGadget)
  If IsImage(old_img) : FreeImage(old_img) : EndIf
  SetGadgetData(#MyDialogCanvasGadget, new_img)
  FreeImage(img)
  DrawMyDialogCanvas()
EndProcedure

Procedure DrawMyDialogCanvas()
  Protected img
  If StartDrawing(CanvasOutput(#MyDialogCanvasGadget))
    Box(0, 0, OutputWidth(), OutputHeight(), RGB(255, 255, 255))
    img = GetGadgetData(#MyDialogCanvasGadget)
    If IsImage(img)
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      DrawImage(ImageID(img), 0, 0)
    EndIf
    StopDrawing()
  EndIf
EndProcedure

Define xml = ParseXML(#PB_Any, GetMyDialogXML())
CreateDialog(#MyDialog) : OpenXMLDialog(#MyDialog, xml, "MyDialog", 0, 0, 0, 0)
BindEvent(#PB_Event_CloseWindow, @OnMyDialogClose(), DialogWindow(#MyDialog))
BindEvent(#PB_Event_Gadget, @OnMyDialogOpenButtonClick(), DialogWindow(#MyDialog), #MyDialogOpenButton)

Repeat : WaitWindowEvent() : Until Quit = 1
deeproot
Enthusiast
Enthusiast
Posts: 221
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: Qt - Image problems

Post by deeproot »

Yes - confirmed. Behaviour on my system is as described above:

QT - image is very poor with transparency, with #PB_Image_Transparent removed the image is clear, but of course black background instead of transparent.

GTK2 and GTK3 - all fine.

PureBasic 5.71 x64, MX Linux 18.3, Xfce. QT version is 5.7.1

I use a similar GrabImage method in a big project that I intend to convert to QT at some time in the future.
wombats
Enthusiast
Enthusiast
Posts: 604
Joined: Thu Dec 29, 2011 5:03 pm

Re: Qt - Image problems

Post by wombats »

Thank you for confirming it behaves the same for you.

Could this please be moved to the bugs forum?
User avatar
Rings
Moderator
Moderator
Posts: 1403
Joined: Sat Apr 26, 2003 1:11 am

Re: Qt - Image problems

Post by Rings »

done
SPAMINATOR NR.1
wombats
Enthusiast
Enthusiast
Posts: 604
Joined: Thu Dec 29, 2011 5:03 pm

Re: Qt - Image problems

Post by wombats »

Rings wrote:done
Thank you.
Fred
Administrator
Administrator
Posts: 14412
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Qt - Image problems

Post by Fred »

Fixed.
Post Reply