GIF LZW encoder/decoder

Get help with using AutoHotkey and its commands and hotkeys
Sam_
Posts: 111
Joined: 20 Mar 2014, 20:24

GIF LZW encoder/decoder

06 May 2018, 20:09

I was rather underwhelmed with GDI's support for animated GIFs, so I decided to make my own implementation in pure AHK. I've been making some good progress, but I'm struggling a bit when it comes to the GIF LZW variable code size compression and decompression. I've read quite a bit of documentation and examples, and mostly they go: here is LZW compression (well described and exampled), oh and by the way GIF has a unique implementation (and they list the two differences without explaining well how to implement them), oh and by the way you need to use variable code sizes, here is how you pack bits into bytes (but don't really demonstrate in the example pseudocode where the code sizes change.) I have looked at a couple of the source code implementations out there, but they tend to be rather low level, highly optimized, and in languages I'm not familiar with.

Has GIF LZW ever been implemented in AHK before? My decoder seems to work well enough on small files, but if it's big enough the clear code is encountered a second time, things don't go right after clearing the code table. I'm missing something, but I haven't been able to tell from the documentation I've been reading what exactly. I can post the code if anyone is interested.

TIA,
Sam.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GIF LZW encoder/decoder

06 May 2018, 20:56

- Do share any code and do share any relevant links.
- Also perhaps give a bit of background info about gifs, e.g. how many types of gif/gif compression are there that you've come across/that your script can handle.
- What are you hoping to do with gifs? Get the frames as bitmaps, and update an area of the screen to display them with Gdip, or convert bitmaps to animated gifs?

- Here are 4 links that might be useful:
- You can use a WIA.ImageFile object to get the width/height/frame count for checking purposes.
Move files of a certain dimension to another folder? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 21#p126321
- Some discussions about gifs started recently:
What happened to GIF? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 17&t=47908
- You can use an Internet Explorer_Server control to display an animated gif:
show svg/wdp/jxr/animated gif image files in a GUI - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28658
- This script can draw images onto a window.
no-frills SplashImage - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 35#p212335
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GIF LZW encoder/decoder

06 May 2018, 21:35

- Hello iseahound, many thanks for the link.
- Is there a most efficient way to update the screen? Here are 3 links: the one you just posted in the post above, my SplashImage link based on the AHK source code, and a link you posted earlier.
[Solved] Need help converting autoit code, (Gdip Gif Animation) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=14275
no-frills SplashImage - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 35#p212335
[GDI+ Object] Picture.Render() - Display images from file/web on screen - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=48573
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
iseahound
Posts: 479
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: GIF LZW encoder/decoder

06 May 2018, 21:44

Picture.Render() doesn't handle GIFs at the moment. If people request it, I'll see if I can add it in.

Since you're using BitBlt() that's the most efficient you can get.
User avatar
Drugwash
Posts: 739
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GIF LZW encoder/decoder

10 May 2018, 12:54

Gdiplus is not suitable for (large) GIF animation, it's too slow. Granted it may work on recent, powerful machines, but on two older machines I've tested such script on it had significant lag, in one case the total lag being much higher than the frame delay (250ms lag vs 200ms delay for a 600x610 image) and CPU was constantly at 100% usage.
Part of the significant lag is due to STM_SETIMAGE (100ms out of the total 250ms on the AMD Duron 800MHz machine).
On this machine (Intel Pentium 4 1.8GHz) the same script and image lags between 93 and 141ms, with an average of 62ms in STM_SETIMAGE only.

Here's the script I used for measuring the lag, modified from one of the links above; it includes a few images for testing purposes.
Please note how different images - particularly 'Bom dia' and the puppy - behave when background is set to transparent or normal.
GIFplay MOD.7z
(1.6 MiB) Downloaded 30 times
Regarding LZW encoding/decoding I think you'll have to use either assembler or an external library, as already mentioned in my GIF-related thread. I'm not quite sure how gdiplus would perform for GIF encoding but I'd bet it would still be much faster than a pure AHK implementation. Decoding would be OK too, but playback no.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], BushMange, CEA6597, howardb1, VACO BenQ, w0z and 182 guests