From 29c553df470401211dd080c2b3c8b69916e7ea25 Mon Sep 17 00:00:00 2001 From: lihongyu Date: Sat, 2 Mar 2019 13:09:23 -0800 Subject: [PATCH] Fix GifDecoder with PREFER_RGB_565 With the previous implementation, isFirstFrameTransparent would never be set because previousFrame is always null when framePointer == 0. And even if it is set, it will be set back to false later. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=236478315 --- .../glide/gifdecoder/StandardGifDecoder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java index 9256943d91..446f679534 100644 --- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java +++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java @@ -278,6 +278,13 @@ public synchronized Bitmap getNextFrame() { act = pct; // Set transparent color if specified. act[currentFrame.transIndex] = COLOR_TRANSPARENT_BLACK; + + if (currentFrame.dispose == DISPOSAL_BACKGROUND && framePointer == 0) { + // TODO: We should check and see if all individual pixels are replaced. If they are, the + // first frame isn't actually transparent. For now, it's simpler and safer to assume + // drawing a transparent background means the GIF contains transparency. + isFirstFrameTransparent = true; + } } // Transfer pixel data to image. @@ -446,11 +453,6 @@ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) { if (currentFrame.lct != null && header.bgIndex == currentFrame.transIndex) { c = COLOR_TRANSPARENT_BLACK; } - } else if (framePointer == 0) { - // TODO: We should check and see if all individual pixels are replaced. If they are, the - // first frame isn't actually transparent. For now, it's simpler and safer to assume - // drawing a transparent background means the GIF contains transparency. - isFirstFrameTransparent = true; } // The area used by the graphic must be restored to the background color. int downsampledIH = previousFrame.ih / sampleSize; @@ -540,7 +542,8 @@ private void copyIntoScratchFast(GifFrame currentFrame) { } isFirstFrameTransparent = - isFirstFrameTransparent == null && isFirstFrame && transparentColorIndex != -1; + (isFirstFrameTransparent != null && isFirstFrameTransparent) + || (isFirstFrameTransparent == null && isFirstFrame && transparentColorIndex != -1); } private void copyCopyIntoScratchRobust(GifFrame currentFrame) {