Remove references to Index8

BitmapFactory will already not decode to Index8, so stop acting like it
will. Remove colorTypeForScaledOutput, which was only meaningful for
kIndex_8.

Will allow re-landing
https://skia.googlesource.com/skia/+/742a3e298fda669006147e4a305bab8452369b1f

Test: None. This does not change behavior.

Bug: 62483967
Bug: skbug.com/6828

Change-Id: I8d8182436a5c9d9858934183a53eda631f9270d5
This commit is contained in:
Leon Scroggins III
2017-07-10 17:03:55 -04:00
parent 01819001e2
commit ef691a3dba

View File

@@ -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)
@@ -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);
@@ -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;
}
@@ -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(),
@@ -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.
@@ -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);
@@ -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.