Skip to content

Commit 29c553d

Browse files
lihongyusjudd
lihongyu
authored andcommitted
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
1 parent 53438b9 commit 29c553d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ public synchronized Bitmap getNextFrame() {
278278
act = pct;
279279
// Set transparent color if specified.
280280
act[currentFrame.transIndex] = COLOR_TRANSPARENT_BLACK;
281+
282+
if (currentFrame.dispose == DISPOSAL_BACKGROUND && framePointer == 0) {
283+
// TODO: We should check and see if all individual pixels are replaced. If they are, the
284+
// first frame isn't actually transparent. For now, it's simpler and safer to assume
285+
// drawing a transparent background means the GIF contains transparency.
286+
isFirstFrameTransparent = true;
287+
}
281288
}
282289

283290
// Transfer pixel data to image.
@@ -446,11 +453,6 @@ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) {
446453
if (currentFrame.lct != null && header.bgIndex == currentFrame.transIndex) {
447454
c = COLOR_TRANSPARENT_BLACK;
448455
}
449-
} else if (framePointer == 0) {
450-
// TODO: We should check and see if all individual pixels are replaced. If they are, the
451-
// first frame isn't actually transparent. For now, it's simpler and safer to assume
452-
// drawing a transparent background means the GIF contains transparency.
453-
isFirstFrameTransparent = true;
454456
}
455457
// The area used by the graphic must be restored to the background color.
456458
int downsampledIH = previousFrame.ih / sampleSize;
@@ -540,7 +542,8 @@ private void copyIntoScratchFast(GifFrame currentFrame) {
540542
}
541543

542544
isFirstFrameTransparent =
543-
isFirstFrameTransparent == null && isFirstFrame && transparentColorIndex != -1;
545+
(isFirstFrameTransparent != null && isFirstFrameTransparent)
546+
|| (isFirstFrameTransparent == null && isFirstFrame && transparentColorIndex != -1);
544547
}
545548

546549
private void copyCopyIntoScratchRobust(GifFrame currentFrame) {

0 commit comments

Comments
 (0)