-// [FIX ME]
-// I couldn't get the loop count of animated GIF which is defined in the
-// application extension block of header using lib(un)gif.
-// Ask the author of lib(un)gif it's really impossible.
-
-U16 getGifLoopCount(GifFileType * gft) {
- int i;
- char sig[11];
- ExtensionBlock* ext = gft->SavedImages[0].ExtensionBlocks;
-
- // info: http://members.aol.com/royalef/gifabout.htm#net-extension
- for (i=0; i < gft->SavedImages[0].ExtensionBlockCount; i++, ext++)
- if (ext->Function == APPLICATION_EXT_FUNC_CODE) {
-// fprintf(stderr, "extension size: %d\n", ext->ByteCount);
- memcpy(sig, &ext->Bytes[0], 11);
-// if(memcmp(sig, "NETSCAPE2.0", 11) == 0)
-// fprintf(stderr, "NETSCAPE2.0\n");
-// fprintf(stderr, "data: %d %d\n", ext->Bytes[13], ext->Bytes[14]);
- }
-
- return 0;
+int getGifLoopCount(GifFileType * gft)
+{
+ int i, loop = -1;
+ ExtensionBlock *ext = gft->SavedImages[0].ExtensionBlocks;
+
+ for (i = 0; i < gft->SavedImages[0].ExtensionBlockCount; i++, ext++)
+ if (ext->Function == APPLICATION_EXT_FUNC_CODE) {
+ // info: http://semmix.pl/color/exgraf/eeg24.htm
+ if (ext->ByteCount == 11 &&
+ (strncmp(&ext->Bytes[0], "NETSCAPE2.0", 11) == 0 ||
+ strncmp(&ext->Bytes[0], "ANIMEXTS1.0", 11) == 0)) {
+ // check for the subblock
+ ext++;
+ if (ext->ByteCount != 3)
+ ext--;
+ else {
+ loop = GET16(&ext->Bytes[1]);
+ break;
+ }
+ }
+ }
+
+ return loop;