提交 b44b7d86 编写于 作者: A andrew

8081315: 8077982 giflib upgrade breaks system giflib builds with earlier versions

Summary: Add conditionals to provide giflib < 5 API calls and interlacing behaviour
Reviewed-by: prr, azvegint
上级 fe00ca34
...@@ -82,8 +82,8 @@ SplashDecodeGif(Splash * splash, GifFileType * gif) ...@@ -82,8 +82,8 @@ SplashDecodeGif(Splash * splash, GifFileType * gif)
int i, j; int i, j;
int imageIndex; int imageIndex;
int cx, cy, cw, ch; /* clamped coordinates */ int cx, cy, cw, ch; /* clamped coordinates */
int numLines; const int interlacedOffset[] = { 0, 4, 2, 1, 0 }; /* The way Interlaced image should. */
int numPassLines; const int interlacedJumps[] = { 8, 8, 4, 2, 1 }; /* be read - offsets and jumps... */
if (DGifSlurp(gif) == GIF_ERROR) { if (DGifSlurp(gif) == GIF_ERROR) {
return 0; return 0;
...@@ -213,6 +213,16 @@ SplashDecodeGif(Splash * splash, GifFileType * gif) ...@@ -213,6 +213,16 @@ SplashDecodeGif(Splash * splash, GifFileType * gif)
byte_t *pSrc = image->RasterBits; byte_t *pSrc = image->RasterBits;
ImageFormat srcFormat; ImageFormat srcFormat;
ImageRect srcRect, dstRect; ImageRect srcRect, dstRect;
int pass = 4, npass = 5;
#if GIFLIB_MAJOR < 5
/* Interlaced gif support is broken in giflib < 5
so we need to work around this */
if (desc->Interlace) {
pass = 0;
npass = 4;
}
#endif
srcFormat.colorMap = colorMapBuf; srcFormat.colorMap = colorMapBuf;
srcFormat.depthBytes = 1; srcFormat.depthBytes = 1;
...@@ -221,22 +231,26 @@ SplashDecodeGif(Splash * splash, GifFileType * gif) ...@@ -221,22 +231,26 @@ SplashDecodeGif(Splash * splash, GifFileType * gif)
srcFormat.fixedBits = QUAD_ALPHA_MASK; // fixed 100% alpha srcFormat.fixedBits = QUAD_ALPHA_MASK; // fixed 100% alpha
srcFormat.premultiplied = 0; srcFormat.premultiplied = 0;
/* Number of source lines for current pass */ for (; pass < npass; ++pass) {
numPassLines = desc->Height; int jump = interlacedJumps[pass];
/* Number of lines that fits to dest buffer */ int ofs = interlacedOffset[pass];
numLines = ch; /* Number of source lines for current pass */
int numPassLines = (desc->Height + jump - ofs - 1) / jump;
/* Number of lines that fits to dest buffer */
int numLines = (ch + jump - ofs - 1) / jump;
initRect(&srcRect, 0, 0, desc->Width, numLines, 1, initRect(&srcRect, 0, 0, desc->Width, numLines, 1,
desc->Width, pSrc, &srcFormat); desc->Width, pSrc, &srcFormat);
if (numLines > 0) { if (numLines > 0) {
initRect(&dstRect, cx, cy, cw, initRect(&dstRect, cx, cy + ofs, cw,
numLines , 1, stride, pBitmapBits, &splash->imageFormat); numLines , jump, stride, pBitmapBits, &splash->imageFormat);
pSrc += convertRect(&srcRect, &dstRect, CVT_ALPHATEST); pSrc += convertRect(&srcRect, &dstRect, CVT_ALPHATEST);
}
// skip extra source data
pSrc += (numPassLines - numLines) * srcRect.stride;
} }
// skip extra source data
pSrc += (numPassLines - numLines) * srcRect.stride;
} }
// now dispose of the previous frame correctly // now dispose of the previous frame correctly
...@@ -296,7 +310,13 @@ SplashDecodeGif(Splash * splash, GifFileType * gif) ...@@ -296,7 +310,13 @@ SplashDecodeGif(Splash * splash, GifFileType * gif)
free(pBitmapBits); free(pBitmapBits);
free(pOldBitmapBits); free(pOldBitmapBits);
DGifCloseFile(gif, NULL); #if GIFLIB_MAJOR > 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1)
if (DGifCloseFile(gif, NULL) == GIF_ERROR) {
return 0;
}
#else
DGifCloseFile(gif);
#endif
return 1; return 1;
} }
...@@ -304,7 +324,11 @@ SplashDecodeGif(Splash * splash, GifFileType * gif) ...@@ -304,7 +324,11 @@ SplashDecodeGif(Splash * splash, GifFileType * gif)
int int
SplashDecodeGifStream(Splash * splash, SplashStream * stream) SplashDecodeGifStream(Splash * splash, SplashStream * stream)
{ {
#if GIFLIB_MAJOR >= 5
GifFileType *gif = DGifOpen((void *) stream, SplashStreamGifInputFunc, NULL); GifFileType *gif = DGifOpen((void *) stream, SplashStreamGifInputFunc, NULL);
#else
GifFileType *gif = DGifOpen((void *) stream, SplashStreamGifInputFunc);
#endif
if (!gif) if (!gif)
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册