flat assembler
Message board for the users of flat assembler.

flat assembler > High Level Languages > gif libraries / examples?

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 533
I need to display an animated gif in my program, how? I did jpg and png display with libjpeg and libpng, is there something like that for gif?
Post 08 Apr 2018, 09:44
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 286
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop

_________________
smaller is better
Post 08 Apr 2018, 17:51
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 128
There are also DirectX-compatible samples provided by Microsoft:
Sample link
Direct2D WIC doc

If you're still using DirectX...

I was able to compile and load a GIF of a shark breach from here.


Description: Compiled with VS2017 (may be incompatible with older versions without tweaks)
Filesize: 84.89 KB
Viewed: 2656 Time(s)

GifSample.JPG


Post 09 Apr 2018, 01:05
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
giflib requires gmake to build, I don't know what it is. I used cmake + vs2005 for previous libraries. Also, giflib-4.1.4-src\windows\GifWin.cpp says that "Application Extension: Not implemented. This includes Netscape 2.0 looping extensions". Looping is kind of important for me.

I'd rather not use windows provided libraries for now, I want to understand the format and decoding itself. Maybe after I'll figure out how it works, then I'll use them.
Post 09 Apr 2018, 09:17
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6994
Location: Kraków, Poland
vivik wrote:
I'd rather not use windows provided libraries for now, I want to understand the format and decoding itself.
fasm's old DDRAW example contains a simple single-frame GIF decoder in GIF87A.INC file. As you can see, decompression algorithm is really simple compared to JPEG or PNG. The LZW compression algorithm used by GIF is not very strong compression-wise, but its beauty lies in its simplicity. I consider it one of the better compression algorithm for beginners to learn first.
Post 09 Apr 2018, 10:21
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
@CandyMan
That link is giflib4, there is giflib5 around already: http://giflib.sourceforge.net/ . Not sure what the differense is yet.

@Tomasz Grysztar
I can't really understand that code, but it's calming to know that all decompression fits in just around 200 lines of assembly. Wish there was c code for that as well (c for reading and understanding, asm for actual using).
Post 09 Apr 2018, 13:01
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Post 09 Apr 2018, 13:07
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 85
Location: Argentina
Post 09 Apr 2018, 13:09
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Hm, how to compile http://giflib.sourceforge.net/ ...
Post 12 Apr 2018, 06:11
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Compiling c programs is a torture.

So I compiled giflib with msys2, and got libgif.a ,

To convert it to .lib (to use with visual studio), I'm using objconv from http://www.agner.org/optimize/ , with this command

Code:
objconv -fpe32 -nu libgif.a libgif.lib    


So I'll use libgif.lib and gif_lib.h , need to check if they work.
Post 17 Apr 2018, 16:44
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Tried this:

Code:
                        FILE *file;

                        file = _wfopen(L"256x256_rgb_a_gif_1f.gif", L"rb");

                        int error;

                        GifFileType *gifFile = DGifOpenFileHandle((int)file, &error);

                        DGifSlurp(gifFile);    


Got this:

Code:
libgif.lib(openbsd-reallocarray.o) : error LNK2001: unresolved external symbol ___errno    


So, after all, I compiled it wrong. I need to compile it with visual studio for it to work.
Post 17 Apr 2018, 17:43
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Welp, at least now I have config.h and such. Maybe it will help figure out what is going on in the code.

Need to write CMakeLists.txt (cmake config) for giflib. Need to clean up CMakeLists.txt for libjpeg and libpng, and then wirte CMakeLists.txt for giflib. Cmake is quite confusing, but it still seems less confusing than makefiles and visual studio projects.
Post 17 Apr 2018, 17:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16125
Location: Hyperborea
vivik wrote:
Compiling c programs is a torture.
Yes. But try and tell that to the die-hard C folks and they'll swear at you.
Post 18 Apr 2018, 00:46
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
It's simple, if you and the guy who wrote the program have the same compiler, and the same version of that compiler. Which is rarely the case.

If program supports too many different compilers and oses, it becomes complicated for different reasons: many #ifdef.

I don't know if it's possible to do something about it, other than documenting everything well and the usual git gud. One day there will be a tool to remove unrelated code automatically, and it probably already exists.
Post 18 Apr 2018, 16:48
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
giflib 5 includes <unistd.h>, so I guess it's POSIX only. Can't compile with visual studio then.

Also, problems with "bool" and <stdbool.h>, https://stackoverflow.com/questions/5680340/c-doesnt-have-a-bool-also-vs2010-question

Switching to "giflib 4 for windows" from the second post.
Post 18 Apr 2018, 16:53
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Okay, it compiled. Used dgif_lib.c gifalloc.c gif_err.c , with all the headers. (don't need egif_lib.c , I'm not encoding anything yet.) Created a new VS project for these. Added #define GIFLIB_STATIC in gif_lib.h .

There is fdopen inside, I'm not sure what this supposed to mean. Some streams, how is that different from the usual fopen? Need to replace that with something...
Post 18 Apr 2018, 17:48
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Compiled. It works now. This is a quite simple library, much much simpler than libpng for example. It doesn't really need config.h , they create it to silence some warning somewhere.

Since it's version 4, I can't get delay information for animation. Maybe I'll just copypaste a bit of code from version 5...


Last edited by vivik on 19 Apr 2018, 18:33; edited 1 time in total
Post 19 Apr 2018, 18:30
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
Good info about gif delay and timing: https://humpy77.deviantart.com/journal/Frame-Delay-Times-for-Animated-GIFs-214150546

http://www.humpy.demon.co.uk/da/gif_timing/

For my browser, delay 2 is actually faster than delay 1 and delay 0. Weird.
Post 19 Apr 2018, 18:32
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 533
By the way, back in 2012 I downloaded a few pieces of pixelart from pixiv. I converted all gif images to png. Most of them became smaller, but a few became bigger instead. Here are those "anomalies".

I don't know what is the cause exactly, I guess gif header is smaller than png header. And not all images benefit from png "vertical compression", the simple horizontal compression from gif is enough for them.


Description:
Filesize: 511 Bytes
Viewed: 2351 Time(s)

8739013.gif


Description:
Filesize: 3.21 KB
Viewed: 2351 Time(s)

6474756.gif


Description:
Filesize: 30.77 KB
Viewed: 2351 Time(s)

1025531.gif


Post 19 Apr 2018, 18:45
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 451
Location: Belarus
vivik wrote:
It doesn't really need config.h , they create it to silence some warning somewhere.

<OffTop>I like the way C/C++ folks do stuff that in any other language community is considered evil. A few years later someone comes across a piece of software written with such tricks and starts a new “Why software sucks” thread.</OffTop>
Post 20 Apr 2018, 03:37
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.