Skip to content

Commit

Permalink
Cache the actual color table index of transparent gif frames.
Browse files Browse the repository at this point in the history
Progress towards #2471.
  • Loading branch information
sjudd committed Nov 22, 2017
1 parent 4db20db commit 65e5506
Showing 1 changed file with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ private void copyIntoScratchFast(GifFrame currentFrame) {
int width = this.downsampledWidth;
byte[] mainPixels = this.mainPixels;
int[] act = this.act;
@Nullable Boolean isFirstFrameTransparent = this.isFirstFrameTransparent;
byte transparentColorIndex = -1;
for (int i = 0; i < downsampledIH; i++) {
int line = i + downsampledIY;
int k = line * width;
Expand All @@ -518,34 +518,25 @@ private void copyIntoScratchFast(GifFrame currentFrame) {
}
// Start of line in source.
int sx = i * currentFrame.iw;
int averageColor;
if (isFirstFrameTransparent == null && isFirstFrame) {
while (dx < dlim) {
int currentColorIndex = ((int) mainPixels[sx]) & MASK_INT_LOWEST_BYTE;
averageColor = act[currentColorIndex];
if (averageColor != COLOR_TRANSPARENT_BLACK) {
dest[dx] = averageColor;
} else if (isFirstFrameTransparent == null) {
isFirstFrameTransparent = true;
}
++sx;
++dx;
}
} else {
while (dx < dlim) {
int currentColorIndex = ((int) mainPixels[sx]) & MASK_INT_LOWEST_BYTE;
averageColor = act[currentColorIndex];
if (averageColor != COLOR_TRANSPARENT_BLACK) {
dest[dx] = averageColor;

while (dx < dlim) {
byte byteCurrentColorIndex = mainPixels[sx];
int currentColorIndex = ((int) byteCurrentColorIndex) & MASK_INT_LOWEST_BYTE;
if (currentColorIndex != transparentColorIndex) {
int color = act[currentColorIndex];
if (color != COLOR_TRANSPARENT_BLACK) {
dest[dx] = color;
} else {
transparentColorIndex = byteCurrentColorIndex;
}
++sx;
++dx;
}
++sx;
++dx;
}
}

this.isFirstFrameTransparent = isFirstFrameTransparent == null
? false : isFirstFrameTransparent;
isFirstFrameTransparent =
isFirstFrameTransparent == null && isFirstFrame && transparentColorIndex != -1;
}

private void copyCopyIntoScratchRobust(GifFrame currentFrame) {
Expand Down

0 comments on commit 65e5506

Please sign in to comment.