From 907524851af0d656ba049311f7535a4ba5d2b1d2 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 10 Jul 2012 12:02:33 -0700 Subject: [PATCH] Properly resize paletted bitmaps when adjusting for density If an app used a GIF file in the wrong density bucket, the auto-scaling code would not properly resize the bitmap. This issue affects third party applications, here is the external bug report: http://code.google.com/p/android/issues/detail?id=34619 DO NOT MERGE Change-Id: I7f99b28ad6e6c28bdbcb29bbbadcb215268ff710 --- core/jni/android/graphics/BitmapFactory.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 416370e9bc1ef..69ef08099a5d0 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -327,7 +327,18 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding, const float sx = scaledWidth / float(decoded->width()); const float sy = scaledHeight / float(decoded->height()); - bitmap->setConfig(decoded->getConfig(), scaledWidth, scaledHeight); + SkBitmap::Config config = decoded->config(); + switch (config) { + case SkBitmap::kNo_Config: + case SkBitmap::kIndex8_Config: + case SkBitmap::kRLE_Index8_Config: + config = SkBitmap::kARGB_8888_Config; + break; + default: + break; + } + + bitmap->setConfig(config, scaledWidth, scaledHeight); bitmap->setIsOpaque(decoded->isOpaque()); bitmap->allocPixels(&javaAllocator, NULL); bitmap->eraseColor(0);