From 327c7207a0967537289d3e20e7be5504f9646e6a Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Wed, 22 Feb 2017 17:38:20 -0500 Subject: [PATCH] BitmapFactory: Remove legacy premultiply hacks Skia now has a mode that will perform color correction, but still do the premultiply on gamma encoded bytes. Test: Flashed device, ran cts. Change-Id: Ib1d1ea1074b5e6d1a49ecfc45e25552643dc04bc --- core/jni/Android.mk | 1 - core/jni/android/graphics/BitmapFactory.cpp | 48 +-------------------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 0c071929534e3..3dd24987d8e06 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -220,7 +220,6 @@ LOCAL_C_INCLUDES += \ external/skia/src/effects \ external/skia/src/image \ external/skia/src/images \ - external/skia/src/utils \ external/sqlite/dist \ external/sqlite/android \ external/tremor/Tremor \ diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 30d6337d3e247..417ef8a0a162b 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -8,7 +8,6 @@ #include "SkBRDAllocator.h" #include "SkFrontBufferedStream.h" #include "SkMath.h" -#include "SkOpts.h" #include "SkPixelRef.h" #include "SkStream.h" #include "SkUtils.h" @@ -229,45 +228,6 @@ static bool needsFineScale(const SkISize fullSize, const SkISize decodedSize, needsFineScale(fullSize.height(), decodedSize.height(), sampleSize); } -static inline SkAlphaType computeDecodeAlphaType(SkColorType colorType, SkAlphaType alphaType) { -#ifndef ANDROID_ENABLE_LINEAR_BLENDING - // Skia premultiplies linearly. Until the framework enables linear blending, - // it expects a legacy premultiply. - if (kPremul_SkAlphaType == alphaType && kRGBA_F16_SkColorType != colorType) { - return kUnpremul_SkAlphaType; - } -#endif - - return alphaType; -} - -static inline void premultiplyIfNecessary(SkBitmap* bitmap, SkPMColor* colorPtr, int* colorCount, - SkAlphaType alphaType, bool requireUnpremultiplied) { -#ifndef ANDROID_ENABLE_LINEAR_BLENDING - if (kUnpremul_SkAlphaType != alphaType || requireUnpremultiplied) { - return; - } - - switch (bitmap->colorType()) { - case kN32_SkColorType: - for (int y = 0; y < bitmap->height(); y++) { - SkOpts::RGBA_to_rgbA(bitmap->getAddr32(0, y), bitmap->getAddr32(0, y), - bitmap->width()); - } - - return; - case kIndex_8_SkColorType: - SkOpts::RGBA_to_rgbA(colorPtr, colorPtr, *colorCount); - return; - default: - // kRGBA_F16 will be premultiplied by the codec if necessary. - // kGray_8 (alias kAlpha_8) and k565 are opaque. - LOG_ALWAYS_FATAL("Should be unreachable - no need for legacy premultiply."); - return; - } -#endif -} - static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding, jobject options) { // This function takes ownership of the input stream. Since the SkAndroidCodec // will take ownership of the stream, we don't necessarily need to take ownership @@ -450,15 +410,13 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding } SkAlphaType alphaType = codec->computeOutputAlphaType(requireUnpremultiplied); - SkAlphaType decodeAlphaType = computeDecodeAlphaType(decodeColorType, alphaType); const SkImageInfo decodeInfo = SkImageInfo::Make(size.width(), size.height(), - decodeColorType, decodeAlphaType, codec->computeOutputColorSpace(decodeColorType)); - - SkImageInfo bitmapInfo = decodeInfo.makeAlphaType(alphaType); + decodeColorType, alphaType, codec->computeOutputColorSpace(decodeColorType)); // For wide gamut images, we will leave the color space on the SkBitmap. Otherwise, // use the default. + SkImageInfo bitmapInfo = decodeInfo; sk_sp srgb = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kSRGB_Gamut, @@ -502,8 +460,6 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding default: return nullObjectReturn("codec->getAndroidPixels() failed."); } - premultiplyIfNecessary(&decodingBitmap, colorPtr, colorCount, decodeAlphaType, - requireUnpremultiplied); jbyteArray ninePatchChunk = NULL; if (peeker.mPatch != NULL) {