- ExtensionBlock* ext = gft->SavedImages[0].ExtensionBlocks;
-
- for (i=0; i < gft->SavedImages[0].ExtensionBlockCount; i++, ext++)
- if ((ext->Function == GRAPHICS_EXT_FUNC_CODE) &&
- (ext->Bytes[0] & 1)) { // there is a transparent color
- return ext->Bytes[3] == 0 ?
- 255 : // exception
- ext->Bytes[3];
+ ExtensionBlock *ext = gft->SavedImages[framenum].ExtensionBlocks;
+
+ for (i = 0; i < gft->SavedImages[framenum].ExtensionBlockCount; i++, ext++)
+ if (ext->Function == GRAPHICS_EXT_FUNC_CODE)
+ return ((ext->Bytes[0] & 0x1C) >> 2);
+
+ return -1;
+}
+
+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;
+}
+
+U16 getGifDelayTime(GifFileType * gft, int framenum)
+{
+ int i;
+ ExtensionBlock *ext = gft->SavedImages[framenum].ExtensionBlocks;
+
+ for (i = 0; i < gft->SavedImages[framenum].ExtensionBlockCount; i++, ext++)
+ if (ext->Function == GRAPHICS_EXT_FUNC_CODE)
+ return GET16(&ext->Bytes[1]);
+
+ return 0;
+}
+
+int getTransparentColor(GifFileType * gft, int framenum)
+{
+ int i;
+ ExtensionBlock *ext = gft->SavedImages[framenum].ExtensionBlocks;
+
+ // Get transparency color from graphic extension block
+ for (i = 0; i < gft->SavedImages[framenum].ExtensionBlockCount; i++, ext++)
+ if ((ext->Function == GRAPHICS_EXT_FUNC_CODE) && (ext->Bytes[0] & 1)) {
+ // there is a transparent color
+ return ext->Bytes[3] == 0 ? 0 : // exception
+ (U8) ext->Bytes[3]; // transparency color