It is currently Wed Nov 20, 2019 11:44 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Qt - Image problems
PostPosted: Mon Oct 28, 2019 11:01 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 500
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.

Top
 Profile  
Reply with quote  
 Post subject: Re: Qt - Image problems
PostPosted: Tue Oct 29, 2019 12:19 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 500
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Qt - Image problems
PostPosted: Wed Oct 30, 2019 4:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Dec 17, 2009 12:00 pm
Posts: 185
Location: Llangadog, Wales, UK
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.

_________________
www.deeproot.co.uk


Top
 Profile  
Reply with quote  
 Post subject: Re: Qt - Image problems
PostPosted: Thu Oct 31, 2019 10:15 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 500
Thank you for confirming it behaves the same for you.

Could this please be moved to the bugs forum?


Top
 Profile  
Reply with quote  
 Post subject: Re: Qt - Image problems
PostPosted: Thu Oct 31, 2019 11:03 am 
Offline
Moderator
Moderator
User avatar

Joined: Sat Apr 26, 2003 1:11 am
Posts: 1390
done

_________________
SPAMINATOR NR.1


Top
 Profile  
Reply with quote  
 Post subject: Re: Qt - Image problems
PostPosted: Thu Oct 31, 2019 12:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 500
Rings wrote:
done

Thank you.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye