COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 06-13-2017, 10:27 AM   #1
1eqinfinity
Human being with feelings
 
Join Date: Apr 2014
Posts: 84
Default Drawing animated gifs

Hi everybody,

I want to draw a looped gif animation in my plugin. I'm reading through IGraphics and Lice source code and have some sketchy ideas, but some things don't click for me yet.
Now I must load and store the contents of the gif somewhere. As far as I understand LICE_GIF_LoadEx() from lice_gif.cpp would do (or perhaps I better use LICE_gifldr?).
Then goes some magic with LICE_GIF_UpdateFrame() and applyGifFrameToBitmap().
And LICE_GIF_Close() before the destruction to free up the memory.

Am I missing some simpler/more elegant way to achieve that?
__________________
soundcloud.com/crimsonbrain

Last edited by 1eqinfinity; 06-14-2017 at 01:27 AM. Reason: shorten
1eqinfinity is offline   Reply With Quote
Old 06-14-2017, 04:13 AM   #2
1eqinfinity
Human being with feelings
 
Join Date: Apr 2014
Posts: 84
Default SOLVED

Ok so that doesn't seem hard looking back. Naming conventions may be a bit confusing, but after trial and error and lots of careful debugging steps it gets clearer.

Obviously, first of all you drop giflib and lice_gif from WDL folder into your project.

Then you need to load a png file in a usual way, with LoadIBitmap(). This file will be your base layer to where each next gif frame will be copied. Hence you want its width and height to match that of the gif. Its content is ignored. I drew a smiley face to cheer myself up.

There's no convenient function to load gif from the resource as in LICE_LoadPNGFromResource(), so for starters I defined the _full_ name of my animated gif in resource.h.

Then you build your custom control class that handles gifs. In that class you add a member of type lice_gif_read_ctx*. It will hold all the gif data. It can actually be void*, but I stick to the concrete type for debugging purposes.
And another member will be IBitmap that you initiate with the result of that LoadIBitmap(<base png ID> <base png filename>).
So you have something like
private:
IBitmap frame;
lice_gif_read_ctx* gif;

Then somewhere (say, in the constructor) you do
gif = (lice_gif_read_ctx*)_LICE::LICE_GIF_LoadEx(<full filename to your gif>);

In each Draw() you can copy the next gif frame to your Bitmap and draw it:
_LICE::LICE_GIF_UpdateFrame(gif, (LICE_IBitmap*)(frame.mData));
pIGraphics->DrawBitmap(&frame, &mRECT);

And of course in the destructor you must
LICE_GIF_Close(gif);

It looks like you have to manually use LICE_GIF_GetFilePos(gif) and LICE_GIF_Rewind(gif) to loop through.

Also, I did not yet solve the problem of adding the whole gif as an independent resource to work with after compilation.
__________________
soundcloud.com/crimsonbrain

Last edited by 1eqinfinity; 06-14-2017 at 07:22 AM.
1eqinfinity is offline   Reply With Quote
Old 06-15-2017, 09:09 AM   #3
1eqinfinity
Human being with feelings
 
Join Date: Apr 2014
Posts: 84
Default

I've managed to playback gifs from resource, but that required additional functions in lice_gif.cpp and corresponding declarations in lice.h. Nothing too fancy, but it was impossible to make it work with given implementations.
Maybe I'll create a pull request to WDL-OL repo later.
__________________
soundcloud.com/crimsonbrain

Last edited by 1eqinfinity; 06-15-2017 at 11:54 AM.
1eqinfinity is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:29 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.