Loading core/jni/android/graphics/BitmapFactory.cpp +4 −42 Original line number Diff line number Diff line Loading @@ -130,17 +130,6 @@ static void scaleNinePatchChunk(android::Res_png_9patch* chunk, float scale, scaleDivRange(chunk->getYDivs(), chunk->numYDivs, scale, scaledHeight); } static SkColorType colorTypeForScaledOutput(SkColorType colorType) { switch (colorType) { case kUnknown_SkColorType: case kIndex_8_SkColorType: return kN32_SkColorType; default: break; } return colorType; } class ScaleCheckingAllocator : public SkBitmap::HeapAllocator { public: ScaleCheckingAllocator(float scale, int size) Loading @@ -149,8 +138,7 @@ public: virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { // accounts for scale in final allocation, using eventual size and config const int bytesPerPixel = SkColorTypeBytesPerPixel( colorTypeForScaledOutput(bitmap->colorType())); const int bytesPerPixel = SkColorTypeBytesPerPixel(bitmap->colorType()); const int requestedSize = bytesPerPixel * int(bitmap->width() * mScale + 0.5f) * int(bitmap->height() * mScale + 0.5f); Loading Loading @@ -334,13 +322,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding env->SetIntField(options, gOptions_heightFieldID, scaledHeight); env->SetObjectField(options, gOptions_mimeFieldID, mimeType); SkColorType outColorType = decodeColorType; // Scaling can affect the output color type if (willScale || scale != 1.0f) { outColorType = colorTypeForScaledOutput(outColorType); } jint configID = GraphicsJNI::colorTypeToLegacyBitmapConfig(outColorType); jint configID = GraphicsJNI::colorTypeToLegacyBitmapConfig(decodeColorType); if (isHardware) { configID = GraphicsJNI::kHardware_LegacyBitmapConfig; } Loading Loading @@ -397,24 +379,6 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding decodeAllocator = &defaultAllocator; } // Construct a color table for the decode if necessary sk_sp<SkColorTable> colorTable(nullptr); SkPMColor* colorPtr = nullptr; int* colorCount = nullptr; int maxColors = 256; SkPMColor colors[256]; if (kIndex_8_SkColorType == decodeColorType) { colorTable.reset(new SkColorTable(colors, maxColors)); // SkColorTable expects us to initialize all of the colors before creating an // SkColorTable. However, we are using SkBitmap with an Allocator to allocate // memory for the decode, so we need to create the SkColorTable before decoding. // It is safe for SkAndroidCodec to modify the colors because this SkBitmap is // not being used elsewhere. colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); colorCount = &maxColors; } SkAlphaType alphaType = codec->computeOutputAlphaType(requireUnpremultiplied); const SkImageInfo decodeInfo = SkImageInfo::Make(size.width(), size.height(), Loading @@ -437,7 +401,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding } SkBitmap decodingBitmap; if (!decodingBitmap.setInfo(bitmapInfo) || !decodingBitmap.tryAllocPixels(decodeAllocator, colorTable.get())) { !decodingBitmap.tryAllocPixels(decodeAllocator, nullptr)) { // SkAndroidCodec should recommend a valid SkImageInfo, so setInfo() // should only only fail if the calculated value for rowBytes is too // large. Loading @@ -450,8 +414,6 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding SkAndroidCodec::AndroidOptions codecOptions; codecOptions.fZeroInitialized = decodeAllocator == &defaultAllocator ? SkCodec::kYes_ZeroInitialized : SkCodec::kNo_ZeroInitialized; codecOptions.fColorPtr = colorPtr; codecOptions.fColorCount = colorCount; codecOptions.fSampleSize = sampleSize; SkCodec::Result result = codec->getAndroidPixels(decodeInfo, decodingBitmap.getPixels(), decodingBitmap.rowBytes(), &codecOptions); Loading Loading @@ -518,7 +480,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding outputAllocator = &defaultAllocator; } SkColorType scaledColorType = colorTypeForScaledOutput(decodingBitmap.colorType()); SkColorType scaledColorType = decodingBitmap.colorType(); // FIXME: If the alphaType is kUnpremul and the image has alpha, the // colors may not be correct, since Skia does not yet support drawing // to/from unpremultiplied bitmaps. Loading Loading
core/jni/android/graphics/BitmapFactory.cpp +4 −42 Original line number Diff line number Diff line Loading @@ -130,17 +130,6 @@ static void scaleNinePatchChunk(android::Res_png_9patch* chunk, float scale, scaleDivRange(chunk->getYDivs(), chunk->numYDivs, scale, scaledHeight); } static SkColorType colorTypeForScaledOutput(SkColorType colorType) { switch (colorType) { case kUnknown_SkColorType: case kIndex_8_SkColorType: return kN32_SkColorType; default: break; } return colorType; } class ScaleCheckingAllocator : public SkBitmap::HeapAllocator { public: ScaleCheckingAllocator(float scale, int size) Loading @@ -149,8 +138,7 @@ public: virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { // accounts for scale in final allocation, using eventual size and config const int bytesPerPixel = SkColorTypeBytesPerPixel( colorTypeForScaledOutput(bitmap->colorType())); const int bytesPerPixel = SkColorTypeBytesPerPixel(bitmap->colorType()); const int requestedSize = bytesPerPixel * int(bitmap->width() * mScale + 0.5f) * int(bitmap->height() * mScale + 0.5f); Loading Loading @@ -334,13 +322,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding env->SetIntField(options, gOptions_heightFieldID, scaledHeight); env->SetObjectField(options, gOptions_mimeFieldID, mimeType); SkColorType outColorType = decodeColorType; // Scaling can affect the output color type if (willScale || scale != 1.0f) { outColorType = colorTypeForScaledOutput(outColorType); } jint configID = GraphicsJNI::colorTypeToLegacyBitmapConfig(outColorType); jint configID = GraphicsJNI::colorTypeToLegacyBitmapConfig(decodeColorType); if (isHardware) { configID = GraphicsJNI::kHardware_LegacyBitmapConfig; } Loading Loading @@ -397,24 +379,6 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding decodeAllocator = &defaultAllocator; } // Construct a color table for the decode if necessary sk_sp<SkColorTable> colorTable(nullptr); SkPMColor* colorPtr = nullptr; int* colorCount = nullptr; int maxColors = 256; SkPMColor colors[256]; if (kIndex_8_SkColorType == decodeColorType) { colorTable.reset(new SkColorTable(colors, maxColors)); // SkColorTable expects us to initialize all of the colors before creating an // SkColorTable. However, we are using SkBitmap with an Allocator to allocate // memory for the decode, so we need to create the SkColorTable before decoding. // It is safe for SkAndroidCodec to modify the colors because this SkBitmap is // not being used elsewhere. colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); colorCount = &maxColors; } SkAlphaType alphaType = codec->computeOutputAlphaType(requireUnpremultiplied); const SkImageInfo decodeInfo = SkImageInfo::Make(size.width(), size.height(), Loading @@ -437,7 +401,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding } SkBitmap decodingBitmap; if (!decodingBitmap.setInfo(bitmapInfo) || !decodingBitmap.tryAllocPixels(decodeAllocator, colorTable.get())) { !decodingBitmap.tryAllocPixels(decodeAllocator, nullptr)) { // SkAndroidCodec should recommend a valid SkImageInfo, so setInfo() // should only only fail if the calculated value for rowBytes is too // large. Loading @@ -450,8 +414,6 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding SkAndroidCodec::AndroidOptions codecOptions; codecOptions.fZeroInitialized = decodeAllocator == &defaultAllocator ? SkCodec::kYes_ZeroInitialized : SkCodec::kNo_ZeroInitialized; codecOptions.fColorPtr = colorPtr; codecOptions.fColorCount = colorCount; codecOptions.fSampleSize = sampleSize; SkCodec::Result result = codec->getAndroidPixels(decodeInfo, decodingBitmap.getPixels(), decodingBitmap.rowBytes(), &codecOptions); Loading Loading @@ -518,7 +480,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding outputAllocator = &defaultAllocator; } SkColorType scaledColorType = colorTypeForScaledOutput(decodingBitmap.colorType()); SkColorType scaledColorType = decodingBitmap.colorType(); // FIXME: If the alphaType is kUnpremul and the image has alpha, the // colors may not be correct, since Skia does not yet support drawing // to/from unpremultiplied bitmaps. Loading