It is currently Thu Nov 26, 2020 8:10 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Done] ResizeImage and GIF
PostPosted: Sat Aug 19, 2017 9:33 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1129
Location: Russia
Code:
; Enable the GIF decoder
UseGIFImageDecoder()

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
 
  ResizeImage(0, 200, 200)

  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "GIF viewer")
 
  CanvasGadget(0, 0, 0, ImageWidth(0), ImageHeight(0))
 
  ; Add a timer to animate the GIF, starts immediately to display the first frame witout delay
  AddWindowTimer(0, 0, 1)
 
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Timer
      SetImageFrame(0, Frame)
     
      ; Each GIF frame can have its own delay, so change the timer accordingly
      ;
      RemoveWindowTimer(0, 0)
      AddWindowTimer(0, 0, GetImageFrameDelay(0))
     
      If StartDrawing(CanvasOutput(0))
        DrawImage(ImageID(0), 0, 0)          ; <----- Error.
        StopDrawing()
      EndIf
     
      ; Go to next frame
      Frame+1
      If Frame >= ImageFrameCount(0) ; Cycle back to first frame, to play in loop
        Frame = 0
      EndIf
    EndIf
   
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf
Error in line
Code:
 DrawImage(ImageID(0), 0, 0)



First frame OK.
Code:
; Enable the GIF decoder
UseGIFImageDecoder()

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
 
  ResizeImage(0, 200, 200)

  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "GIF viewer")
 
  ;SetImageFrame(0, 0)
 
  ImageGadget(0, 0, 0, ImageWidth(0), ImageHeight(0), ImageID(0))
   
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf


Here the first frame is empty.
Code:
; Enable the GIF decoder
UseGIFImageDecoder()

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
 
  ResizeImage(0, 200, 200)

  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "GIF viewer")
 
  SetImageFrame(0, 0)
 
  ImageGadget(0, 0, 0, ImageWidth(0), ImageHeight(0), ImageID(0))
   
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf


Incorrect resizing of GIF (second and other frames).
Code:
; Enable the GIF decoder
UseGIFImageDecoder()

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
 
  ResizeImage(0, 200, 200)

  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "GIF viewer")
 
  SetImageFrame(0, 2)
 
  ImageGadget(0, 0, 0, ImageWidth(0), ImageHeight(0), ImageID(0))
   
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: ResizeImage and GIF
PostPosted: Sat Aug 19, 2017 10:55 pm 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 930
This works not, a multi frame Gif is a container, PB handle this not
The way is, create a resized temporary image frame for output

Also you should handle zero delays=100ms and a window timer is not good for Gif delay,
a available second window timer influence the Gif delays

Code:
; Enable the GIF decoder
UseGIFImageDecoder()

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")

  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "GIF viewer")
 
  CanvasGadget(0, 0, 0, ImageWidth(0), ImageHeight(0))
 
  ; Add a timer to animate the GIF, starts immediately to display the first frame without delay
  AddWindowTimer(0, 0, 1)
 
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Timer
      SetImageFrame(0, Frame)
     
      ; Each GIF frame can have its own delay, so change the timer accordingly

      AddWindowTimer(0, 0, GetImageFrameDelay(0))
     
      If StartDrawing(CanvasOutput(0))
        CopyImage(0, 1)
        ResizeImage(1, 200, 200)
        DrawImage(ImageID(1), 0, 0)
        StopDrawing()
      EndIf
     
      ; Go to next frame
      Frame+1
      If Frame >= ImageFrameCount(0) ; Cycle back to first frame, to play in loop
        Frame = 0
      EndIf
    EndIf
   
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: ResizeImage and GIF
PostPosted: Wed Feb 05, 2020 3:13 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14179
Location: France
Fixed (not supported for multiframes)


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] ResizeImage and GIF
PostPosted: Wed Feb 05, 2020 7:16 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1129
Location: Russia
A simple but non-functional solution!
I expected the ResizeImage function to correctly resize multiframes images.

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] ResizeImage and GIF
PostPosted: Sat Mar 07, 2020 7:33 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8143
Location: Fort Nelson, BC, Canada
Quote:
I expected the ResizeImage function to correctly resize multiframes images.

Say you have a multi-frame gif where frame 1 is 256x256 positioned at 0,0 and frame 2 is 10x21 positioned at 93,31. Resizing that is problematic as frame 2, positioned precisely at the original size, would look terrible if the resize resulted in it being even one pixel off. Resizing is a feature best left alone by PB developers imho. The developers of the gif format went to great lengths to achieve tiny filesizes with maximum performance but the unfortunate side effect is massive headaches if you try making changes to the size or aspect of the gif.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] ResizeImage and GIF
PostPosted: Mon Mar 30, 2020 9:32 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1129
Location: Russia
netmaestro wrote:
Resizing is a feature best left alone by PB developers imho.
How to do it?
For example, I want to resize an image in a zero frame.
Code:
; Enable the GIF decoder
UseGIFImageDecoder()

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
 
  SetImageFrame(0, 0)
  ResizeImage(0, 200, 200)

  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "GIF viewer")
 
  CanvasGadget(0, 0, 0, ImageWidth(0), ImageHeight(0))
 
  ; Add a timer to animate the GIF, starts immediately to display the first frame witout delay
  AddWindowTimer(0, 0, 1)
 
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Timer
      SetImageFrame(0, Frame)
     
      ; Each GIF frame can have its own delay, so change the timer accordingly
      ;
      RemoveWindowTimer(0, 0)
      AddWindowTimer(0, 0, GetImageFrameDelay(0))
     
      If StartDrawing(CanvasOutput(0))
        DrawImage(ImageID(0), 0, 0)          ; <----- Error.
        StopDrawing()
      EndIf
     
      ; Go to next frame
      Frame+1
      If Frame >= ImageFrameCount(0) ; Cycle back to first frame, to play in loop
        Frame = 0
      EndIf
    EndIf
   
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf
But an error message appears.
I wrote about this before. Fred needed to be allowed to resize individual frames. This would solve the problem, but he went the simplest way by disabling the ResizeImage function.

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] ResizeImage and GIF
PostPosted: Mon Mar 30, 2020 11:13 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2730
Location: Germany
Extract GIF Images to array of images
Code:
; Enable the GIF decoder
UseGIFImageDecoder()


Procedure GIFImagesToImages(GIFImage, Array Images(1))
  Protected cnt, i, dx, dy
  cnt = ImageFrameCount(GIFImage) - 1
  Dim Images(cnt)
  For i = 0 To cnt
    SetImageFrame(GIFImage, i)
    Images(i) = CopyImage(GIFImage, #PB_Any)
  Next
EndProcedure

Procedure UpdateWindow()
  ResizeGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
EndProcedure

; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
 
  OpenWindow(0, 100, 100, 800, 600, "GIF viewer", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
 
  CanvasGadget(0, 0, 0, 800, 600)
 
  ; Add a timer to animate the GIF, starts immediately to display the first frame witout delay
  AddWindowTimer(0, 0, 1)
 
  Dim Images(0)
 
  GIFImagesToImages(0, Images())
 
  BindEvent(#PB_Event_SizeWindow, @UpdateWindow())
 
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Timer
      RemoveWindowTimer(0, 0)
      AddWindowTimer(0, 0, GetImageFrameDelay(0))
     
      If StartDrawing(CanvasOutput(0))
        Box(0, 0, GadgetWidth(0), GadgetHeight(0), $FF8080)
        DrawImage(ImageID(Images(Frame)), 20, 20, GadgetWidth(0) - 40, GadgetHeight(0) - 40)          ; <----- Error.
        StopDrawing()
      EndIf
     
      ; Go to next frame
      Frame+1
      If Frame >= ImageFrameCount(0) ; Cycle back to first frame, to play in loop
        Frame = 0
      EndIf
    EndIf
   
  Until Event = #PB_Event_CloseWindow
Else
  Debug "Impossible to load the file: " + Filename$
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 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