From e7a494253187f14bc73a909f522e4da2ce093920 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Mon, 20 Nov 2017 21:36:53 -0800 Subject: [PATCH] Create local references of instance variables used in GIF decoder loops. Cuts ~40% off of frame rendering times on API 23 emulators and devices. Progress towards #2471. --- .../glide/gifdecoder/StandardGifDecoder.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 3d5d38b8e3..8662835b14 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 @@ -487,6 +487,12 @@ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) { int inc = 8; int iline = 0; boolean isFirstFrame = framePointer == 0; + int sampleSize = this.sampleSize; + int downsampledWidth = this.downsampledWidth; + int downsampledHeight = this.downsampledHeight; + byte[] mainPixels = this.mainPixels; + int[] act = this.act; + boolean isFirstFrameTransparent = false; for (int i = 0; i < downsampledIH; i++) { int line = i; if (currentFrame.interlace) { @@ -538,7 +544,7 @@ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) { } if (averageColor != COLOR_TRANSPARENT_BLACK) { dest[dx] = averageColor; - } else if (!isFirstFrameTransparent && isFirstFrame) { + } else if (isFirstFrame && !isFirstFrameTransparent) { isFirstFrameTransparent = true; } sx += sampleSize; @@ -547,6 +553,8 @@ private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) { } } + this.isFirstFrameTransparent = isFirstFrameTransparent; + // Copy pixels into previous image if (savePrevious && (currentFrame.dispose == DISPOSAL_UNSPECIFIED || currentFrame.dispose == DISPOSAL_NONE)) { @@ -629,15 +637,19 @@ private void decodeBitmapData(GifFrame frame) { // Allocate new pixel array. mainPixels = bitmapProvider.obtainByteArray(npix); } + byte[] mainPixels = this.mainPixels; if (prefix == null) { prefix = new short[MAX_STACK_SIZE]; } + short[] prefix = this.prefix; if (suffix == null) { suffix = new byte[MAX_STACK_SIZE]; } + byte[] suffix = this.suffix; if (pixelStack == null) { pixelStack = new byte[MAX_STACK_SIZE + 1]; } + byte[] pixelStack = this.pixelStack; // Initialize GIF data stream decoder. dataSize = readByte(); @@ -653,6 +665,7 @@ private void decodeBitmapData(GifFrame frame) { suffix[code] = (byte) code; } + byte[] block = this.block; // Decode GIF pixel stream. datum = bits = count = first = top = pi = bi = 0; for (i = 0; i < npix; ) { @@ -665,6 +678,7 @@ private void decodeBitmapData(GifFrame frame) { break; } bi = 0; + block = this.block; } datum += (((int) block[bi]) & MASK_INT_LOWEST_BYTE) << bits;