Skip to content

Commit

Permalink
Fix GifDecoder with PREFER_RGB_565
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lihongyu authored and sjudd committed Mar 7, 2019
1 parent 53438b9 commit 29c553d
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 29c553d

Please sign in to comment.