860e91ba85e0070b3deb854f8a8e9952bceca480
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c   1) /* BlinkenLib
BlinkenLib/BlinkenGif.c   2)    Copyright 2004-2016 Stefan Schuermans <stefan@schuermans.info>
BlinkenLib/BlinkenGif.c   3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
BlinkenLib/BlinkenGif.c   4)    a blinkenarea.org project */
BlinkenLib/BlinkenGif.c   5) 
BlinkenLib/BlinkenGif.c   6) #include <gif_lib.h>
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c   7) #include <stdlib.h>
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c   8) 
BlinkenLib/BlinkenGif.c   9) #include <BlinkenLib/BlinkenFrame.h>
BlinkenLib/BlinkenGif.c  10) #include <BlinkenLib/BlinkenMovie.h>
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         11) #include <BlinkenLib/config.h>
Stefan Schuermans restructure directories

Stefan Schuermans authored 5 years ago

src/BlinkenGif.c         12) 
src/BlinkenGif.c         13) #include "BlinkenConstants.h"
src/BlinkenGif.c         14) #include "BlinkenGif.h"
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  15) 
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  16) #ifdef BLINKENLIB_CFG_GIF5
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         17) #define GIF5_err , &giferr
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  18) #else
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         19) #define GIF5_err
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  20) #endif
BlinkenLib/BlinkenGif.c  21) 
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  22) // get color from GIF color map
BlinkenLib/BlinkenGif.c  23) static void BlinkenGifGetColor(ColorMapObject *pMap, int idx, int transparent,
BlinkenLib/BlinkenGif.c  24)                                unsigned char *r, unsigned char *g,
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         25)                                unsigned char *b, unsigned char *t) {
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  26)   if (transparent >= 0 && idx == transparent) {
BlinkenLib/BlinkenGif.c  27)     *t = 1;
BlinkenLib/BlinkenGif.c  28)   } else {
BlinkenLib/BlinkenGif.c  29)     *t = 0;
BlinkenLib/BlinkenGif.c  30)   }
BlinkenLib/BlinkenGif.c  31)   if (pMap != NULL) {
BlinkenLib/BlinkenGif.c  32)     if (idx >= 0 && idx < pMap->ColorCount) {
BlinkenLib/BlinkenGif.c  33)       *r = pMap->Colors[idx].Red;
BlinkenLib/BlinkenGif.c  34)       *g = pMap->Colors[idx].Green;
BlinkenLib/BlinkenGif.c  35)       *b = pMap->Colors[idx].Blue;
BlinkenLib/BlinkenGif.c  36)     } else {
BlinkenLib/BlinkenGif.c  37)       *r = 0;
BlinkenLib/BlinkenGif.c  38)       *g = 0;
BlinkenLib/BlinkenGif.c  39)       *b = 0;
BlinkenLib/BlinkenGif.c  40)       *t = 1;
BlinkenLib/BlinkenGif.c  41)     }
BlinkenLib/BlinkenGif.c  42)   } else {
BlinkenLib/BlinkenGif.c  43)     *r = 0;
BlinkenLib/BlinkenGif.c  44)     *g = 0;
BlinkenLib/BlinkenGif.c  45)     *b = 0;
BlinkenLib/BlinkenGif.c  46)     *t = 1;
BlinkenLib/BlinkenGif.c  47)   }
BlinkenLib/BlinkenGif.c  48) }
BlinkenLib/BlinkenGif.c  49) 
BlinkenLib/BlinkenGif.c  50) // set pixel to GIF color
BlinkenLib/BlinkenGif.c  51) static void BlinkenGifSetPixel(ColorMapObject *pMap, int idx, int transparent,
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         52)                                stBlinkenFrame *pFrame, int y, int x) {
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  53)   unsigned char r, g, b, t;
BlinkenLib/BlinkenGif.c  54) 
BlinkenLib/BlinkenGif.c  55)   if (pFrame != NULL) {
BlinkenLib/BlinkenGif.c  56)     BlinkenGifGetColor(pMap, idx, transparent, &r, &g, &b, &t);
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         57)     if (!t) {
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  58)       BlinkenFrameSetPixel(pFrame, y, x, 0, r);
BlinkenLib/BlinkenGif.c  59)       BlinkenFrameSetPixel(pFrame, y, x, 1, g);
BlinkenLib/BlinkenGif.c  60)       BlinkenFrameSetPixel(pFrame, y, x, 2, b);
BlinkenLib/BlinkenGif.c  61)     }
BlinkenLib/BlinkenGif.c  62)   }
BlinkenLib/BlinkenGif.c  63) }
BlinkenLib/BlinkenGif.c  64) 
BlinkenLib/BlinkenGif.c  65) // load a GIF file as BlinkenMovie
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         66) stBlinkenMovie *BlinkenGifLoad(const char *pFilename) {
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  67)   GifFileType *gif;
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         68)   struct sPass {
src/BlinkenGif.c         69)     int ofs, stride;
Stefan Schuermans support reading interlaced...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  70)   };
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         71)   static struct sPass const passes_linear[] = {{0, 1}, {0, 0}};
src/BlinkenGif.c         72)   static struct sPass const passes_interlaced[] = {
src/BlinkenGif.c         73)       {0, 8}, {4, 8}, {2, 4}, {1, 2}};
Stefan Schuermans support reading interlaced...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  74)   struct sPass const *pass;
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c         75)   int height, width, frameCnt, frameIdx, i, y, x, y1, x1, bg, disposal, delay,
src/BlinkenGif.c         76)       transp, idx;
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  77)   ColorMapObject *pGlobalMap, *pMap;
BlinkenLib/BlinkenGif.c  78)   SavedImage *pImg;
BlinkenLib/BlinkenGif.c  79)   GifImageDesc *pDesc;
BlinkenLib/BlinkenGif.c  80)   ExtensionBlock *pEx;
BlinkenLib/BlinkenGif.c  81)   stBlinkenMovie *pMovie;
BlinkenLib/BlinkenGif.c  82)   stBlinkenFrame *pBack, *pFrame;
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  83) #ifdef BLINKENLIB_CFG_GIF5
BlinkenLib/BlinkenGif.c  84)   int giferr;
BlinkenLib/BlinkenGif.c  85) #endif
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  86) 
BlinkenLib/BlinkenGif.c  87)   if (pFilename == NULL)
BlinkenLib/BlinkenGif.c  88)     return NULL;
BlinkenLib/BlinkenGif.c  89) 
BlinkenLib/BlinkenGif.c  90)   // open GIF file for decoding
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  91)   gif = DGifOpenFileName(pFilename GIF5_err);
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  92)   if (gif == NULL) {
BlinkenLib/BlinkenGif.c  93)     return NULL;
BlinkenLib/BlinkenGif.c  94)   }
BlinkenLib/BlinkenGif.c  95) 
BlinkenLib/BlinkenGif.c  96)   // read GIF file
BlinkenLib/BlinkenGif.c  97)   if (DGifSlurp(gif) != GIF_OK) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  98)     DGifCloseFile(gif GIF5_err);
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c  99)     return NULL;
BlinkenLib/BlinkenGif.c 100)   }
BlinkenLib/BlinkenGif.c 101)   height = gif->SHeight;
BlinkenLib/BlinkenGif.c 102)   width = gif->SWidth;
BlinkenLib/BlinkenGif.c 103)   frameCnt = gif->ImageCount;
BlinkenLib/BlinkenGif.c 104)   pGlobalMap = gif->SColorMap;
BlinkenLib/BlinkenGif.c 105)   bg = gif->SBackGroundColor;
BlinkenLib/BlinkenGif.c 106) 
BlinkenLib/BlinkenGif.c 107)   // create movie
BlinkenLib/BlinkenGif.c 108)   pMovie = BlinkenMovieNew(height, width, 3, 255);
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        109)   if (!pMovie) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 110)     DGifCloseFile(gif GIF5_err);
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 111)     return NULL;
BlinkenLib/BlinkenGif.c 112)   }
BlinkenLib/BlinkenGif.c 113) 
BlinkenLib/BlinkenGif.c 114)   // create background frame and set it to background color
BlinkenLib/BlinkenGif.c 115)   pBack = BlinkenFrameNew(height, width, 3, 255, 1);
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        116)   if (!pBack) {
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 117)     BlinkenMovieFree(pMovie);
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 118)     DGifCloseFile(gif GIF5_err);
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 119)     return NULL;
BlinkenLib/BlinkenGif.c 120)   }
BlinkenLib/BlinkenGif.c 121)   for (y = 0; y < height; ++y) {
BlinkenLib/BlinkenGif.c 122)     for (x = 0; x < width; ++x) {
BlinkenLib/BlinkenGif.c 123)       BlinkenGifSetPixel(pGlobalMap, bg, -1, pBack, y, x);
BlinkenLib/BlinkenGif.c 124)     }
BlinkenLib/BlinkenGif.c 125)   }
BlinkenLib/BlinkenGif.c 126) 
BlinkenLib/BlinkenGif.c 127)   // process all frames
BlinkenLib/BlinkenGif.c 128)   for (frameIdx = 0; frameIdx < frameCnt; ++frameIdx) {
BlinkenLib/BlinkenGif.c 129)     pImg = &gif->SavedImages[frameIdx];
BlinkenLib/BlinkenGif.c 130)     pDesc = &pImg->ImageDesc;
BlinkenLib/BlinkenGif.c 131) 
BlinkenLib/BlinkenGif.c 132)     // get local color map
BlinkenLib/BlinkenGif.c 133)     pMap = pDesc->ColorMap != NULL ? pDesc->ColorMap : pGlobalMap;
BlinkenLib/BlinkenGif.c 134) 
BlinkenLib/BlinkenGif.c 135)     // get disposal mode, delay and transparent color
BlinkenLib/BlinkenGif.c 136)     disposal = 0;
BlinkenLib/BlinkenGif.c 137)     delay = 100;
BlinkenLib/BlinkenGif.c 138)     transp = -1;
BlinkenLib/BlinkenGif.c 139)     for (i = 0; i < pImg->ExtensionBlockCount; ++i) {
BlinkenLib/BlinkenGif.c 140)       pEx = &pImg->ExtensionBlocks[i];
BlinkenLib/BlinkenGif.c 141)       if (pEx->Function == GRAPHICS_EXT_FUNC_CODE && pEx->ByteCount == 4) {
BlinkenLib/BlinkenGif.c 142)         disposal = pEx->Bytes[0] >> 2 & 0x07;
BlinkenLib/BlinkenGif.c 143)         delay = (unsigned int)(unsigned char)pEx->Bytes[1] |
BlinkenLib/BlinkenGif.c 144)                 (unsigned int)(unsigned char)pEx->Bytes[2] << 8;
BlinkenLib/BlinkenGif.c 145)         transp = pEx->Bytes[0] & 0x01 ? (int)(unsigned char)pEx->Bytes[3] : -1;
BlinkenLib/BlinkenGif.c 146)       }
BlinkenLib/BlinkenGif.c 147)     }
BlinkenLib/BlinkenGif.c 148) 
BlinkenLib/BlinkenGif.c 149)     // draw new frame based on background frame, maybe update background frame
BlinkenLib/BlinkenGif.c 150)     if (delay > 0) {
BlinkenLib/BlinkenGif.c 151)       pFrame = BlinkenFrameClone(pBack);
BlinkenLib/BlinkenGif.c 152)       BlinkenFrameSetDuration(pFrame, delay * 10); // GIF delay is in 10ms
BlinkenLib/BlinkenGif.c 153)     } else {
BlinkenLib/BlinkenGif.c 154)       // frames with no duration -> only effect on background
BlinkenLib/BlinkenGif.c 155)       pFrame = NULL;
BlinkenLib/BlinkenGif.c 156)     }
Stefan Schuermans support reading interlaced...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 157)     for (pass = pDesc->Interlace ? passes_interlaced : passes_linear;
BlinkenLib/BlinkenGif.c 158)          pass->stride > 0; ++pass) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        159)       for (y = pass->ofs, y1 = pDesc->Top + pass->ofs, i = 0; y < pDesc->Height;
src/BlinkenGif.c        160)            y += pass->stride, y1 += pass->stride) {
Stefan Schuermans support reading interlaced...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 161)         for (x = 0, x1 = pDesc->Left; x < pDesc->Width; ++x, ++x1, ++i) {
BlinkenLib/BlinkenGif.c 162)           idx = pImg->RasterBits[i];
BlinkenLib/BlinkenGif.c 163)           switch (disposal) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        164)           // undefined
src/BlinkenGif.c        165)           case 0:
src/BlinkenGif.c        166)           case 4:
src/BlinkenGif.c        167)           case 5:
src/BlinkenGif.c        168)           case 6:
src/BlinkenGif.c        169)           case 7:
src/BlinkenGif.c        170)           // do not dispose -> draw to frame and update background
src/BlinkenGif.c        171)           case 1:
src/BlinkenGif.c        172)             BlinkenGifSetPixel(pMap, idx, transp, pFrame, y1, x1);
src/BlinkenGif.c        173)             BlinkenGifSetPixel(pMap, idx, transp, pBack, y1, x1);
src/BlinkenGif.c        174)             break;
src/BlinkenGif.c        175)           // restore background -> draw to frame and reset background
src/BlinkenGif.c        176)           case 2:
src/BlinkenGif.c        177)             BlinkenGifSetPixel(pMap, idx, transp, pFrame, y1, x1);
src/BlinkenGif.c        178)             BlinkenGifSetPixel(pMap, bg, transp, pBack, y1, x1);
src/BlinkenGif.c        179)             break;
src/BlinkenGif.c        180)           // restore previous -> draw to frame only
src/BlinkenGif.c        181)           case 3:
src/BlinkenGif.c        182)             BlinkenGifSetPixel(pMap, idx, transp, pFrame, y1, x1);
src/BlinkenGif.c        183)             break;
Stefan Schuermans support reading interlaced...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 184)           } // switch disposal
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        185)         }   // for x
src/BlinkenGif.c        186)       }     // for y
src/BlinkenGif.c        187)     }       // for pass
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 188) 
BlinkenLib/BlinkenGif.c 189)     // append frame to movie
BlinkenLib/BlinkenGif.c 190)     if (pFrame) {
BlinkenLib/BlinkenGif.c 191)       if (BlinkenMovieAppendFrame(pMovie, pFrame) != 0) {
BlinkenLib/BlinkenGif.c 192)         BlinkenFrameFree(pFrame);
BlinkenLib/BlinkenGif.c 193)       }
BlinkenLib/BlinkenGif.c 194)     }
BlinkenLib/BlinkenGif.c 195) 
BlinkenLib/BlinkenGif.c 196)   } // for frameIdx
BlinkenLib/BlinkenGif.c 197) 
BlinkenLib/BlinkenGif.c 198)   // delete background frame
BlinkenLib/BlinkenGif.c 199)   BlinkenFrameFree(pBack);
BlinkenLib/BlinkenGif.c 200) 
BlinkenLib/BlinkenGif.c 201)   // close GIF file
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 202)   DGifCloseFile(gif GIF5_err);
Stefan Schuermans implement reading GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 203) 
BlinkenLib/BlinkenGif.c 204)   return pMovie;
BlinkenLib/BlinkenGif.c 205) }
BlinkenLib/BlinkenGif.c 206) 
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        207) int BlinkenGifSave(stBlinkenMovie *pMovie, const char *pFilename) {
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 208)   GifFileType *gif;
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        209)   int frameCnt, height, width, channels, maxval, channels_new, maxval_new, r, g,
src/BlinkenGif.c        210)       b, i, frame, y, x, c, y1, x1, y2, x2, v, ret;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 211)   unsigned int delay;
BlinkenLib/BlinkenGif.c 212)   stBlinkenMovie *pOutMovie;
BlinkenLib/BlinkenGif.c 213)   stBlinkenFrame *pFrame, *pLast;
BlinkenLib/BlinkenGif.c 214)   SavedImage *pImg;
BlinkenLib/BlinkenGif.c 215)   GifImageDesc *pDesc;
BlinkenLib/BlinkenGif.c 216)   ExtensionBlock *pEx;
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 217) #ifdef BLINKENLIB_CFG_GIF5
BlinkenLib/BlinkenGif.c 218)   int giferr;
BlinkenLib/BlinkenGif.c 219) #endif
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 220) 
BlinkenLib/BlinkenGif.c 221)   if (pMovie == NULL || pFilename == NULL)
BlinkenLib/BlinkenGif.c 222)     return -1; // error
BlinkenLib/BlinkenGif.c 223) 
BlinkenLib/BlinkenGif.c 224)   frameCnt = BlinkenMovieGetFrameCnt(pMovie);
BlinkenLib/BlinkenGif.c 225)   height = BlinkenMovieGetHeight(pMovie);
BlinkenLib/BlinkenGif.c 226)   width = BlinkenMovieGetWidth(pMovie);
BlinkenLib/BlinkenGif.c 227)   channels = BlinkenMovieGetChannels(pMovie);
BlinkenLib/BlinkenGif.c 228)   maxval = BlinkenMovieGetMaxval(pMovie);
BlinkenLib/BlinkenGif.c 229) 
BlinkenLib/BlinkenGif.c 230)   // convert movie to suitable color depth (i.e. at most 256 colors)
BlinkenLib/BlinkenGif.c 231)   if (channels > 3)
BlinkenLib/BlinkenGif.c 232)     channels_new = 3;
BlinkenLib/BlinkenGif.c 233)   else
BlinkenLib/BlinkenGif.c 234)     channels_new = channels;
BlinkenLib/BlinkenGif.c 235)   switch (channels) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        236)   case 1:
src/BlinkenGif.c        237)     maxval_new = 255;
src/BlinkenGif.c        238)     break;
src/BlinkenGif.c        239)   case 2:
src/BlinkenGif.c        240)     maxval_new = 15;
src/BlinkenGif.c        241)     break;
src/BlinkenGif.c        242)   case 3:
src/BlinkenGif.c        243)     maxval_new = 5;
src/BlinkenGif.c        244)     break;
src/BlinkenGif.c        245)   default:
src/BlinkenGif.c        246)     maxval_new = 255;
src/BlinkenGif.c        247)     break;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 248)   }
BlinkenLib/BlinkenGif.c 249)   pOutMovie = BlinkenMovieClone(pMovie);
BlinkenLib/BlinkenGif.c 250)   if (pOutMovie == NULL)
BlinkenLib/BlinkenGif.c 251)     return -1; // error
BlinkenLib/BlinkenGif.c 252)   if (channels_new != channels || maxval_new != maxval) {
BlinkenLib/BlinkenGif.c 253)     BlinkenMovieResize(pOutMovie, height, width, channels_new, maxval_new);
BlinkenLib/BlinkenGif.c 254)     channels = channels_new;
BlinkenLib/BlinkenGif.c 255)     maxval = maxval_new;
BlinkenLib/BlinkenGif.c 256)   }
BlinkenLib/BlinkenGif.c 257) 
BlinkenLib/BlinkenGif.c 258)   // open GIF file for encoding
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 259)   gif = EGifOpenFileName(pFilename, 0 GIF5_err);
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 260)   if (gif == NULL) {
BlinkenLib/BlinkenGif.c 261)     BlinkenMovieFree(pOutMovie);
BlinkenLib/BlinkenGif.c 262)     return -1; // error
BlinkenLib/BlinkenGif.c 263)   }
BlinkenLib/BlinkenGif.c 264) 
BlinkenLib/BlinkenGif.c 265)   // set global GIF config
BlinkenLib/BlinkenGif.c 266)   gif->SWidth = width;
BlinkenLib/BlinkenGif.c 267)   gif->SHeight = height;
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 268)   gif->SColorResolution = 256;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 269)   gif->SBackGroundColor = 0;
BlinkenLib/BlinkenGif.c 270)   gif->SColorMap = NULL;
BlinkenLib/BlinkenGif.c 271)   gif->ImageCount = frameCnt;
BlinkenLib/BlinkenGif.c 272)   gif->Image.Left = 0;
BlinkenLib/BlinkenGif.c 273)   gif->Image.Top = 0;
BlinkenLib/BlinkenGif.c 274)   gif->Image.Width = width;
BlinkenLib/BlinkenGif.c 275)   gif->Image.Height = height;
BlinkenLib/BlinkenGif.c 276)   gif->Image.ColorMap = NULL;
BlinkenLib/BlinkenGif.c 277)   gif->SavedImages = NULL;
BlinkenLib/BlinkenGif.c 278)   gif->UserData = NULL;
BlinkenLib/BlinkenGif.c 279) 
BlinkenLib/BlinkenGif.c 280)   // create color map
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 281) #ifdef BLINKENLIB_CFG_GIF5
BlinkenLib/BlinkenGif.c 282)   gif->SColorMap = GifMakeMapObject(256, NULL);
BlinkenLib/BlinkenGif.c 283) #else
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 284)   gif->SColorMap = MakeMapObject(256, NULL);
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 285) #endif
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 286)   if (gif->SColorMap == NULL) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 287)     EGifCloseFile(gif GIF5_err);
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 288)     BlinkenMovieFree(pOutMovie);
BlinkenLib/BlinkenGif.c 289)     return -1; // error
BlinkenLib/BlinkenGif.c 290)   }
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 291)   i = 0;
BlinkenLib/BlinkenGif.c 292)   switch (channels) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        293)   case 1:
src/BlinkenGif.c        294)     for (r = 0; r <= maxval; ++r) {
src/BlinkenGif.c        295)       gif->SColorMap->Colors[i].Red = ((int)r * 255 + maxval / 2) / maxval;
src/BlinkenGif.c        296)       gif->SColorMap->Colors[i].Green = gif->SColorMap->Colors[i].Red;
src/BlinkenGif.c        297)       gif->SColorMap->Colors[i].Blue = gif->SColorMap->Colors[i].Red;
src/BlinkenGif.c        298)       ++i;
src/BlinkenGif.c        299)     }
src/BlinkenGif.c        300)     break;
src/BlinkenGif.c        301)   case 2:
src/BlinkenGif.c        302)     for (g = 0; g <= maxval; ++g) {
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 303)       for (r = 0; r <= maxval; ++r) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        304)         gif->SColorMap->Colors[i].Red = ((int)r * 255 + maxval / 2) / maxval;
src/BlinkenGif.c        305)         gif->SColorMap->Colors[i].Green = ((int)g * 255 + maxval / 2) / maxval;
src/BlinkenGif.c        306)         gif->SColorMap->Colors[i].Blue = gif->SColorMap->Colors[i].Green;
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 307)         ++i;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 308)       }
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        309)     }
src/BlinkenGif.c        310)     break;
src/BlinkenGif.c        311)   case 3:
src/BlinkenGif.c        312)     for (b = 0; b <= maxval; ++b) {
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 313)       for (g = 0; g <= maxval; ++g) {
BlinkenLib/BlinkenGif.c 314)         for (r = 0; r <= maxval; ++r) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        315)           gif->SColorMap->Colors[i].Red = ((int)r * 255 + maxval / 2) / maxval;
src/BlinkenGif.c        316)           gif->SColorMap->Colors[i].Green =
src/BlinkenGif.c        317)               ((int)g * 255 + maxval / 2) / maxval;
src/BlinkenGif.c        318)           gif->SColorMap->Colors[i].Blue = ((int)b * 255 + maxval / 2) / maxval;
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 319)           ++i;
BlinkenLib/BlinkenGif.c 320)         }
BlinkenLib/BlinkenGif.c 321)       }
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        322)     }
src/BlinkenGif.c        323)     break;
Stefan Schuermans fix creation of color map

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 324)   } // switch channels
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 325)   for (; i < 256; ++i) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        326)     gif->SColorMap->Colors[i].Red = 0;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 327)     gif->SColorMap->Colors[i].Green = 0;
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        328)     gif->SColorMap->Colors[i].Blue = 0;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 329)   }
BlinkenLib/BlinkenGif.c 330) 
BlinkenLib/BlinkenGif.c 331)   // create space for saved images
BlinkenLib/BlinkenGif.c 332)   gif->SavedImages = calloc(frameCnt, sizeof(SavedImage));
BlinkenLib/BlinkenGif.c 333)   if (gif->SavedImages == NULL) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 334)     EGifCloseFile(gif GIF5_err);
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 335)     BlinkenMovieFree(pOutMovie);
BlinkenLib/BlinkenGif.c 336)     return -1; // error
BlinkenLib/BlinkenGif.c 337)   }
BlinkenLib/BlinkenGif.c 338) 
BlinkenLib/BlinkenGif.c 339)   // put frames into GIF structure
BlinkenLib/BlinkenGif.c 340)   pLast = NULL;
BlinkenLib/BlinkenGif.c 341)   for (frame = 0; frame < frameCnt; ++frame) {
BlinkenLib/BlinkenGif.c 342)     pFrame = BlinkenMovieGetFrame(pOutMovie, frame);
BlinkenLib/BlinkenGif.c 343)     pImg = &gif->SavedImages[frame];
BlinkenLib/BlinkenGif.c 344)     pDesc = &pImg->ImageDesc;
BlinkenLib/BlinkenGif.c 345) 
BlinkenLib/BlinkenGif.c 346)     // find smallest rectangle with changes
BlinkenLib/BlinkenGif.c 347)     if (pLast != NULL) {
BlinkenLib/BlinkenGif.c 348)       y1 = height - 1;
BlinkenLib/BlinkenGif.c 349)       x1 = width - 1;
BlinkenLib/BlinkenGif.c 350)       y2 = 0;
BlinkenLib/BlinkenGif.c 351)       x2 = 0;
BlinkenLib/BlinkenGif.c 352)       for (y = 0; y < height; ++y) {
BlinkenLib/BlinkenGif.c 353)         for (x = 0; x < width; ++x) {
BlinkenLib/BlinkenGif.c 354)           for (c = 0; c < channels; ++c) {
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        355)             if (BlinkenFrameGetPixel(pFrame, y, x, c) !=
src/BlinkenGif.c        356)                 BlinkenFrameGetPixel(pLast, y, x, c))
src/BlinkenGif.c        357)               break;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 358)           }
BlinkenLib/BlinkenGif.c 359)           if (c < channels) { // change detected at x,y
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        360)             if (y < y1)
src/BlinkenGif.c        361)               y1 = y;
src/BlinkenGif.c        362)             if (x < x1)
src/BlinkenGif.c        363)               x1 = x;
src/BlinkenGif.c        364)             if (y > y2)
src/BlinkenGif.c        365)               y2 = y;
src/BlinkenGif.c        366)             if (x > x2)
src/BlinkenGif.c        367)               x2 = x;
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 368)           }
BlinkenLib/BlinkenGif.c 369)         } // for x
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        370)       }   // for y
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 371)       if (y1 <= y2 && x1 <= x2) {
BlinkenLib/BlinkenGif.c 372)         // changes detected -> encode changed rectangle
BlinkenLib/BlinkenGif.c 373)         pDesc->Left = x1;
BlinkenLib/BlinkenGif.c 374)         pDesc->Top = y1;
BlinkenLib/BlinkenGif.c 375)         pDesc->Width = x2 - x1 + 1;
BlinkenLib/BlinkenGif.c 376)         pDesc->Height = y2 - y1 + 1;
BlinkenLib/BlinkenGif.c 377)       } else {
BlinkenLib/BlinkenGif.c 378)         // no changes detected -> encode top left pixel (empty does not work)
BlinkenLib/BlinkenGif.c 379)         pDesc->Left = 0;
BlinkenLib/BlinkenGif.c 380)         pDesc->Top = 0;
BlinkenLib/BlinkenGif.c 381)         pDesc->Width = 1;
BlinkenLib/BlinkenGif.c 382)         pDesc->Height = 1;
BlinkenLib/BlinkenGif.c 383)       }
BlinkenLib/BlinkenGif.c 384)     } else { // if pLast
BlinkenLib/BlinkenGif.c 385)       // no last frame -> encode full frame
BlinkenLib/BlinkenGif.c 386)       pDesc->Left = 0;
BlinkenLib/BlinkenGif.c 387)       pDesc->Top = 0;
BlinkenLib/BlinkenGif.c 388)       pDesc->Width = width;
BlinkenLib/BlinkenGif.c 389)       pDesc->Height = height;
BlinkenLib/BlinkenGif.c 390)     } // if pLast ... else
BlinkenLib/BlinkenGif.c 391)     pDesc->Interlace = 0;
BlinkenLib/BlinkenGif.c 392)     pDesc->ColorMap = NULL;
BlinkenLib/BlinkenGif.c 393) 
BlinkenLib/BlinkenGif.c 394)     // allocate pixel buffer
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        395)     pImg->RasterBits =
src/BlinkenGif.c        396)         calloc(pDesc->Width * pDesc->Height, sizeof(unsigned char));
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 397)     if (pImg->RasterBits == NULL) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 398)       EGifCloseFile(gif GIF5_err);
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 399)       BlinkenMovieFree(pOutMovie);
BlinkenLib/BlinkenGif.c 400)       return -1; // error
BlinkenLib/BlinkenGif.c 401)     }
BlinkenLib/BlinkenGif.c 402) 
BlinkenLib/BlinkenGif.c 403)     // fill pixel buffer
BlinkenLib/BlinkenGif.c 404)     for (y = 0, y1 = pDesc->Top, i = 0; y < pDesc->Height; ++y, ++y1) {
BlinkenLib/BlinkenGif.c 405)       for (x = 0, x1 = pDesc->Left; x < pDesc->Width; ++x, ++x1, ++i) {
BlinkenLib/BlinkenGif.c 406)         v = 0;
BlinkenLib/BlinkenGif.c 407)         for (c = channels - 1; c >= 0; --c) {
BlinkenLib/BlinkenGif.c 408)           v *= (maxval + 1);
BlinkenLib/BlinkenGif.c 409)           v += BlinkenFrameGetPixel(pFrame, y1, x1, c);
BlinkenLib/BlinkenGif.c 410)         }
BlinkenLib/BlinkenGif.c 411)         pImg->RasterBits[i] = v;
BlinkenLib/BlinkenGif.c 412)       } // for x
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        413)     }   // for y
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 414) 
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        415)         // allocate and fill extension block with delay and disposal mode
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 416) #ifndef BLINKENLIB_CFG_GIF5
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 417)     pImg->Function = 0;
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 418) #endif
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 419)     pImg->ExtensionBlockCount = 1;
BlinkenLib/BlinkenGif.c 420)     pImg->ExtensionBlocks = calloc(1, sizeof(ExtensionBlock));
BlinkenLib/BlinkenGif.c 421)     if (pImg->ExtensionBlocks == NULL) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 422)       EGifCloseFile(gif GIF5_err);
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 423)       BlinkenMovieFree(pOutMovie);
BlinkenLib/BlinkenGif.c 424)       return -1; // error
BlinkenLib/BlinkenGif.c 425)     }
BlinkenLib/BlinkenGif.c 426)     pEx = pImg->ExtensionBlocks;
BlinkenLib/BlinkenGif.c 427)     pEx->Function = GRAPHICS_EXT_FUNC_CODE;
BlinkenLib/BlinkenGif.c 428)     pEx->ByteCount = 4;
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        429)     pEx->Bytes = calloc(pEx->ByteCount, sizeof(unsigned char));
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 430)     if (pEx->Bytes == NULL) {
Stefan Schuermans support for giflib 5.x (unt...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 431)       EGifCloseFile(gif GIF5_err);
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 432)       BlinkenMovieFree(pOutMovie);
Stefan Schuermans format

Stefan Schuermans authored 1 year ago

src/BlinkenGif.c        433)       return -1;            // error
Stefan Schuermans implement writing GIFs

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 434)     }
BlinkenLib/BlinkenGif.c 435)     pEx->Bytes[0] = 1 << 2; // disposal mode: do not dispose
BlinkenLib/BlinkenGif.c 436)     delay = (BlinkenFrameGetDuration(pFrame) + 5) / 10;
BlinkenLib/BlinkenGif.c 437)     if (delay <= 0)
BlinkenLib/BlinkenGif.c 438)       delay = 1;
BlinkenLib/BlinkenGif.c 439)     pEx->Bytes[1] = delay & 0xFF;
BlinkenLib/BlinkenGif.c 440)     pEx->Bytes[2] = delay >> 8 & 0xFF;
BlinkenLib/BlinkenGif.c 441)     pEx->Bytes[3] = 0xFF;
BlinkenLib/BlinkenGif.c 442)     // transparent color (Bytes[3]) not used, flag 0x01 in Bytes[0] not set
BlinkenLib/BlinkenGif.c 443) 
BlinkenLib/BlinkenGif.c 444)     pLast = pFrame;
BlinkenLib/BlinkenGif.c 445)   } // for frame
BlinkenLib/BlinkenGif.c 446) 
Stefan Schuermans fix double free: EGifSpew c...

Stefan Schuermans authored 7 years ago

BlinkenLib/BlinkenGif.c 447)   // encode GIF file (closes GIF file)