hide Config in SkImageDecoder -- use SkColorType instead patch from issue 334613003 TBR=scroggo Author: reed@chromium.org Review URL: https://codereview.chromium.org/334793002
diff --git a/bench/DecodeBench.cpp b/bench/DecodeBench.cpp index a6ab4a5..15a80b1 100644 --- a/bench/DecodeBench.cpp +++ b/bench/DecodeBench.cpp
@@ -11,22 +11,17 @@ #include "SkImageDecoder.h" #include "SkOSFile.h" #include "SkString.h" +#include "sk_tool_utils.h" DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench."); -static const char* gConfigName[] = { - "ERROR", "a1", "a8", "index8", "565", "4444", "8888" -}; - class DecodeBench : public SkBenchmark { - SkBitmap::Config fPrefConfig; - SkString fName; + const SkColorType fPrefColorType; + SkString fName; public: - DecodeBench(SkBitmap::Config c) { - fPrefConfig = c; - + DecodeBench(SkColorType ct) : fPrefColorType(ct) { SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]); - fName.printf("decode_%s_%s", gConfigName[c], fname.c_str()); + fName.printf("decode_%s_%s", sk_tool_utils::colortype_name(ct), fname.c_str()); } virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { @@ -41,9 +36,7 @@ virtual void onDraw(const int loops, SkCanvas*) { for (int i = 0; i < loops; i++) { SkBitmap bm; - SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], - &bm, - fPrefConfig, + SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], &bm, fPrefColorType, SkImageDecoder::kDecodePixels_Mode); } } @@ -52,6 +45,6 @@ typedef SkBenchmark INHERITED; }; -DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); ) -DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); ) -DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); ) +DEF_BENCH( return new DecodeBench(kN32_SkColorType); ) +DEF_BENCH( return new DecodeBench(kRGB_565_SkColorType); ) +DEF_BENCH( return new DecodeBench(kARGB_4444_SkColorType); )
diff --git a/experimental/PdfViewer/chop_transparency_main.cpp b/experimental/PdfViewer/chop_transparency_main.cpp index b6a104c..3f4b1fd 100644 --- a/experimental/PdfViewer/chop_transparency_main.cpp +++ b/experimental/PdfViewer/chop_transparency_main.cpp
@@ -108,8 +108,7 @@ stream.rewind(); - if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode)) { + if (!codec->decode(&stream, &bitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode)) { return; }
diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp index b30fd4d..2d0c275 100644 --- a/gm/cmykjpeg.cpp +++ b/gm/cmykjpeg.cpp
@@ -24,7 +24,6 @@ // parameters to the "decode" call bool dither = false; - SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config; SkString filename(INHERITED::gResourcePath); if (!filename.endsWith("/") && !filename.endsWith("\\")) { @@ -43,8 +42,7 @@ if (codec) { stream.rewind(); codec->setDitherImage(dither); - codec->decode(&stream, &fBitmap, prefConfig, - SkImageDecoder::kDecodePixels_Mode); + codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); SkDELETE(codec); } }
diff --git a/gm/copyTo4444.cpp b/gm/copyTo4444.cpp index ed0c046..76dc66c 100644 --- a/gm/copyTo4444.cpp +++ b/gm/copyTo4444.cpp
@@ -31,8 +31,7 @@ virtual void onDraw(SkCanvas* canvas) { SkBitmap bm, bm4444; SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png"); - if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, - SkBitmap::kARGB_8888_Config, + if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode)) { SkDebugf("Could not decode the file. Did you forget to set the " "resourcePath?\n");
diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp index 00b1a4b..d7b9307 100644 --- a/gm/downsamplebitmap.cpp +++ b/gm/downsamplebitmap.cpp
@@ -183,8 +183,7 @@ } if (codec) { stream.rewind(); - codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode); + codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); SkDELETE(codec); } else { fBM.allocN32Pixels(1, 1);
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp index c650902..351fb2a 100644 --- a/gm/filterbitmap.cpp +++ b/gm/filterbitmap.cpp
@@ -204,8 +204,7 @@ } if (codec) { stream.rewind(); - codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode); + codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); SkDELETE(codec); } else { fBM.allocN32Pixels(1, 1);
diff --git a/gm/filterindiabox.cpp b/gm/filterindiabox.cpp index c03dfba..4acb2c3 100644 --- a/gm/filterindiabox.cpp +++ b/gm/filterindiabox.cpp
@@ -45,7 +45,6 @@ class FilterIndiaBoxGM : public skiagm::GM { void onOnceBeforeDraw() { - this->makeBitmap(); SkScalar cx = SkScalarHalf(fBM.width()); @@ -63,14 +62,11 @@ SkMatrix fMatrix[2]; SkString fName; - FilterIndiaBoxGM() - { + FilterIndiaBoxGM() { this->setBGColor(0xFFDDDDDD); } - FilterIndiaBoxGM(const char filename[]) - : fFilename(filename) - { + FilterIndiaBoxGM(const char filename[]) : fFilename(filename) { fName.printf("filterindiabox"); } @@ -88,7 +84,6 @@ } virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - canvas->translate(10, 10); for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) { SkSize size = computeSize(fBM, fMatrix[i]); @@ -120,8 +115,7 @@ } if (codec) { stream.rewind(); - codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode); + codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); SkDELETE(codec); } else { fBM.allocN32Pixels(1, 1);
diff --git a/gm/gm_expectations.cpp b/gm/gm_expectations.cpp index d2d629e..f0ccb3e 100644 --- a/gm/gm_expectations.cpp +++ b/gm/gm_expectations.cpp
@@ -207,10 +207,8 @@ SkString path = SkOSPath::SkPathJoin(fRootDir.c_str(), testName); SkBitmap referenceBitmap; bool decodedReferenceBitmap = - SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, - SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode, - NULL); + SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, kN32_SkColorType, + SkImageDecoder::kDecodePixels_Mode, NULL); if (decodedReferenceBitmap) { return Expectations(referenceBitmap); } else {
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi index 3258a34..223d504 100644 --- a/gyp/skia_for_android_framework_defines.gypi +++ b/gyp/skia_for_android_framework_defines.gypi
@@ -15,6 +15,7 @@ 'skia_for_android_framework_defines': [ 'SK_SUPPORT_LEGACY_SETCONFIG_INFO', 'SK_SUPPORT_LEGACY_SETCONFIG', + 'SK_SUPPORT_LEGACY_IMAGEDECODER_CONFIG', # Needed until we fix skbug.com/2440. 'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG', # Transitional, for deprecated SkCanvas::SaveFlags methods.
diff --git a/include/core/SkImageDecoder.h b/include/core/SkImageDecoder.h index 5892099..ed17f0f 100644 --- a/include/core/SkImageDecoder.h +++ b/include/core/SkImageDecoder.h
@@ -239,22 +239,22 @@ } /** Passed to the decode method. If kDecodeBounds_Mode is passed, then - only the bitmap's width/height/config need be set. If kDecodePixels_Mode + only the bitmap's info need be set. If kDecodePixels_Mode is passed, then the bitmap must have pixels or a pixelRef. */ enum Mode { - kDecodeBounds_Mode, //!< only return width/height/config in bitmap + kDecodeBounds_Mode, //!< only return info in bitmap kDecodePixels_Mode //!< return entire bitmap (including pixels) }; /** Given a stream, decode it into the specified bitmap. - If the decoder can decompress the image, it calls bitmap.setConfig(), + If the decoder can decompress the image, it calls bitmap.setInfo(), and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), which will allocated a pixelRef. To access the pixel memory, the codec needs to call lockPixels/unlockPixels on the bitmap. It can then set the pixels with the decompressed image. * If the image cannot be decompressed, return false. After the - * decoding, the function converts the decoded config in bitmap + * decoding, the function converts the decoded colortype in bitmap * to pref if possible. Whether a conversion is feasible is * tested by Bitmap::canCopyTo(pref). @@ -265,13 +265,10 @@ If a Peeker is installed via setPeeker, it may be used to peek into meta data during the decode. - - If a Chooser is installed via setChooser, it may be used to select - which image to return from a format that contains multiple images. */ - bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode); + bool decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { - return this->decode(stream, bitmap, SkBitmap::kNo_Config, mode); + return this->decode(stream, bitmap, kUnknown_SkColorType, mode); } /** @@ -290,7 +287,7 @@ * Return true for success. * Return false if the index is never built or failing in decoding. */ - bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkBitmap::Config pref); + bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkColorType pref); /** Given a stream, this will try to find an appropriate decoder object. If none is found, the method returns NULL. @@ -300,34 +297,31 @@ /** Decode the image stored in the specified file, and store the result in bitmap. Return true for success or false on failure. - @param prefConfig If the PrefConfigTable is not set, prefer this config. + @param pref If the PrefConfigTable is not set, prefer this colortype. See NOTE ABOUT PREFERRED CONFIGS. @param format On success, if format is non-null, it is set to the format of the decoded file. On failure it is ignored. */ - static bool DecodeFile(const char file[], SkBitmap* bitmap, - SkBitmap::Config prefConfig, Mode, + static bool DecodeFile(const char file[], SkBitmap* bitmap, SkColorType pref, Mode, Format* format = NULL); static bool DecodeFile(const char file[], SkBitmap* bitmap) { - return DecodeFile(file, bitmap, SkBitmap::kNo_Config, - kDecodePixels_Mode, NULL); + return DecodeFile(file, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); } + /** Decode the image stored in the specified memory buffer, and store the result in bitmap. Return true for success or false on failure. - @param prefConfig If the PrefConfigTable is not set, prefer this config. + @param pref If the PrefConfigTable is not set, prefer this colortype. See NOTE ABOUT PREFERRED CONFIGS. @param format On success, if format is non-null, it is set to the format of the decoded buffer. On failure it is ignored. */ - static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, - SkBitmap::Config prefConfig, Mode, - Format* format = NULL); + static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, SkColorType pref, + Mode, Format* format = NULL); static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ - return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, - kDecodePixels_Mode, NULL); + return DecodeMemory(buffer, size, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); } /** @@ -348,20 +342,39 @@ /** Decode the image stored in the specified SkStreamRewindable, and store the result in bitmap. Return true for success or false on failure. - @param prefConfig If the PrefConfigTable is not set, prefer this config. + @param pref If the PrefConfigTable is not set, prefer this colortype. See NOTE ABOUT PREFERRED CONFIGS. @param format On success, if format is non-null, it is set to the format of the decoded stream. On failure it is ignored. */ - static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, - SkBitmap::Config prefConfig, Mode, + static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkColorType pref, Mode, Format* format = NULL); static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { - return DecodeStream(stream, bitmap, SkBitmap::kNo_Config, - kDecodePixels_Mode, NULL); + return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_Mode, NULL); } +#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CONFIG + bool decode(SkStream*, SkBitmap* bitmap, SkBitmap::Config pref, Mode mode) { + return this->decode(stream, bitmap, SkBitmapConfigToColorType(pref), mode); + } + bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkBitmap::Config pref) { + return this->decodeSubset(bm, subset, SkBitmapConfigToColorType(pref)); + } + static bool DecodeFile(const char file[], SkBitmap* bitmap, SkBitmapConfig pref, Mode mode, + Format* format = NULL) { + return DecodeFile(file, bitmap, SkBitmapConfigToColorType(pref), mode, format); + } + static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, + SkBitmap::Config pref, Mode mode, Format* format = NULL) { + return DecodeMemory(buffer, size, bitmap, SkBitmapConfigToColorType(pref), mode, format); + } + static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkBitmap::Config pref, + Mode mode, Format* format = NULL) { + return DecodeStream(stream, bitmap, SkBitmapConfigToColorType(pref), mode, format); + } +#endif + protected: // must be overridden in subclasses. This guy is called by decode(...) virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; @@ -403,12 +416,6 @@ */ void copyFieldsToOther(SkImageDecoder* other); - /** - * Return the default preference being used by the current or latest call to - * decode. - */ - SkBitmap::Config getDefaultPref() { return fDefaultPref; } - /** Can be queried from within onDecode, to see if the user (possibly in a different thread) has requested the decode to cancel. If this returns true, your onDecode() should stop and return false. @@ -424,15 +431,19 @@ protected: SkImageDecoder(); + /** + * Return the default preference being used by the current or latest call to decode. + */ + SkColorType getDefaultPref() { return fDefaultPref; } + #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER // helper function for decoders to handle the (common) case where there is only // once choice available in the image file. bool chooseFromOneChoice(SkColorType, int width, int height) const; #endif - /* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's - width/height/rowbytes/config. Returns true on success. This method handles checking - for an optional Allocator. + /* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's info. + Returns true on success. This method handles checking for an optional Allocator. */ bool allocPixelRef(SkBitmap*, SkColorTable*) const; @@ -461,7 +472,7 @@ #endif SkBitmap::Allocator* fAllocator; int fSampleSize; - SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false + SkColorType fDefaultPref; // use if fUsePrefTable is false PrefConfigTable fPrefTable; // use if fUsePrefTable is true bool fDitherImage; bool fUsePrefTable;
diff --git a/samplecode/SampleFilter2.cpp b/samplecode/SampleFilter2.cpp index 552ce8a..0c81196 100644 --- a/samplecode/SampleFilter2.cpp +++ b/samplecode/SampleFilter2.cpp
@@ -1,10 +1,10 @@ - /* * Copyright 2011 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + #include "SampleCode.h" #include "SkView.h" #include "SkCanvas.h" @@ -35,14 +35,12 @@ fBitmaps = new SkBitmap[fBitmapCount]; for (int i = 0; i < fBitmapCount/2; i++) { - SkImageDecoder::DecodeFile(gNames[i], &fBitmaps[i], - SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode, NULL); + SkImageDecoder::DecodeFile(gNames[i], &fBitmaps[i], kN32_SkColorType, + SkImageDecoder::kDecodePixels_Mode, NULL); } for (int i = fBitmapCount/2; i < fBitmapCount; i++) { - SkImageDecoder::DecodeFile(gNames[i-fBitmapCount/2], &fBitmaps[i], - SkBitmap::kRGB_565_Config, - SkImageDecoder::kDecodePixels_Mode, NULL); + SkImageDecoder::DecodeFile(gNames[i-fBitmapCount/2], &fBitmaps[i], kRGB_565_SkColorType, + SkImageDecoder::kDecodePixels_Mode, NULL); } fCurrIndex = 0;
diff --git a/samplecode/SampleSubpixelTranslate.cpp b/samplecode/SampleSubpixelTranslate.cpp index 686a153..afb31c1 100644 --- a/samplecode/SampleSubpixelTranslate.cpp +++ b/samplecode/SampleSubpixelTranslate.cpp
@@ -37,8 +37,7 @@ } if (codec) { stream.rewind(); - codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode); + codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); SkDELETE(codec); } else { fBM.allocN32Pixels(1, 1);
diff --git a/samplecode/SampleUnpremul.cpp b/samplecode/SampleUnpremul.cpp index 0b1848d..c84e1d4 100644 --- a/samplecode/SampleUnpremul.cpp +++ b/samplecode/SampleUnpremul.cpp
@@ -4,6 +4,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + #include "gm.h" #include "SampleCode.h" #include "SkBlurMask.h" @@ -182,8 +183,7 @@ if (!fPremul) { decoder->setRequireUnpremultipliedColors(true); } - fDecodeSucceeded = decoder->decode(&stream, &fBitmap, - SkBitmap::kARGB_8888_Config, + fDecodeSucceeded = decoder->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); this->inval(NULL); }
diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp index 56afd66..3ea61d5 100644 --- a/src/image/SkImagePriv.cpp +++ b/src/image/SkImagePriv.cpp
@@ -33,10 +33,6 @@ return SkBitmap::kNo_Config; } -SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { - return SkColorTypeToBitmapConfig(info.fColorType); -} - SkColorType SkBitmapConfigToColorType(SkBitmap::Config config) { static const SkColorType gCT[] = { kUnknown_SkColorType, // kNo_Config
diff --git a/src/image/SkImage_Codec.cpp b/src/image/SkImage_Codec.cpp index 64f58a6..3d815ce 100644 --- a/src/image/SkImage_Codec.cpp +++ b/src/image/SkImage_Codec.cpp
@@ -41,8 +41,7 @@ void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) { if (!fBitmap.pixelRef()) { - if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), - &fBitmap)) { + if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), &fBitmap)) { return; } } @@ -52,8 +51,7 @@ void SkImage_Codec::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { if (!fBitmap.pixelRef()) { - if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), - &fBitmap)) { + if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), &fBitmap)) { return; } } @@ -68,8 +66,7 @@ } SkBitmap bitmap; - if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, - SkBitmap::kNo_Config, + if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, kUnknown_SkColorType, SkImageDecoder::kDecodeBounds_Mode)) { return NULL; }
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp index 2493d89..88cdef9 100644 --- a/src/images/SkDecodingImageGenerator.cpp +++ b/src/images/SkDecodingImageGenerator.cpp
@@ -173,9 +173,7 @@ SkBitmap bitmap; TargetAllocator allocator(fInfo, pixels, rowBytes); decoder->setAllocator(&allocator); - // TODO: need to be able to pass colortype directly to decoder - SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); - bool success = decoder->decode(fStream, &bitmap, legacyConfig, + bool success = decoder->decode(fStream, &bitmap, info.colorType(), SkImageDecoder::kDecodePixels_Mode); decoder->setAllocator(NULL); if (!success) {
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index 223ae15..3c6ff69 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp
@@ -21,7 +21,7 @@ #endif , fAllocator(NULL) , fSampleSize(1) - , fDefaultPref(SkBitmap::kNo_Config) + , fDefaultPref(kUnknown_SkColorType) , fDitherImage(true) , fUsePrefTable(false) , fSkipWritingZeroes(false) @@ -148,9 +148,11 @@ // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmapConfigToColorType() // SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha) const { - SkBitmap::Config config = SkBitmap::kNo_Config; + SkColorType ct = fDefaultPref; if (fUsePrefTable) { + // Until we kill or change the PrefTable, we have to go into Config land for a moment. + SkBitmap::Config config = SkBitmap::kNo_Config; switch (srcDepth) { case kIndex_SrcDepth: config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src @@ -164,18 +166,16 @@ : fPrefTable.fPrefFor_8bpc_NoAlpha_src; break; } - } else { - config = fDefaultPref; + // now return to SkColorType land + ct = SkBitmapConfigToColorType(config); } - - return SkBitmapConfigToColorType(config); + return ct; } -bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, - SkBitmap::Config pref, Mode mode) { +bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mode mode) { // we reset this to false before calling onDecode fShouldCancelDecode = false; - // assign this, for use by getPrefConfig(), in case fUsePrefTable is false + // assign this, for use by getPrefColorType(), in case fUsePrefTable is false fDefaultPref = pref; // pass a temporary bitmap, so that if we return false, we are assured of @@ -188,18 +188,16 @@ return true; } -bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, - SkBitmap::Config pref) { +bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, SkColorType pref) { // we reset this to false before calling onDecodeSubset fShouldCancelDecode = false; - // assign this, for use by getPrefConfig(), in case fUsePrefTable is false + // assign this, for use by getPrefColorType(), in case fUsePrefTable is false fDefaultPref = pref; return this->onDecodeSubset(bm, rect); } -bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream, - int *width, int *height) { +bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream, int *width, int *height) { // we reset this to false before calling onBuildTileIndex fShouldCancelDecode = false; @@ -255,8 +253,8 @@ /////////////////////////////////////////////////////////////////////////////// -bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, - SkBitmap::Config pref, Mode mode, Format* format) { +bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, SkColorType pref, Mode mode, + Format* format) { SkASSERT(file); SkASSERT(bm); @@ -270,8 +268,8 @@ return false; } -bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, - SkBitmap::Config pref, Mode mode, Format* format) { +bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, SkColorType pref, + Mode mode, Format* format) { if (0 == size) { return false; } @@ -281,9 +279,8 @@ return SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format); } -bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, - SkBitmap::Config pref, Mode mode, - Format* format) { +bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, SkColorType pref, + Mode mode, Format* format) { SkASSERT(stream); SkASSERT(bm);
diff --git a/src/ports/SkImageDecoder_empty.cpp b/src/ports/SkImageDecoder_empty.cpp index 50b1d44..7824732 100644 --- a/src/ports/SkImageDecoder_empty.cpp +++ b/src/ports/SkImageDecoder_empty.cpp
@@ -28,24 +28,19 @@ void SkImageDecoder::copyFieldsToOther(SkImageDecoder* ) {} -bool SkImageDecoder::DecodeFile(const char[], SkBitmap*, SkBitmap::Config, - SkImageDecoder::Mode, SkImageDecoder::Format*) { +bool SkImageDecoder::DecodeFile(const char[], SkBitmap*, SkColorType, Mode, Format*) { return false; } -bool SkImageDecoder::decode(SkStream*, SkBitmap*, SkBitmap::Config, Mode) { +bool SkImageDecoder::decode(SkStream*, SkBitmap*, SkColorType, Mode) { return false; } -bool SkImageDecoder::DecodeStream(SkStreamRewindable*, SkBitmap*, SkBitmap::Config, - SkImageDecoder::Mode, - SkImageDecoder::Format*) { +bool SkImageDecoder::DecodeStream(SkStreamRewindable*, SkBitmap*, SkColorType, Mode, Format*) { return false; } -bool SkImageDecoder::DecodeMemory(const void*, size_t, SkBitmap*, - SkBitmap::Config, SkImageDecoder::Mode, - SkImageDecoder::Format*) { +bool SkImageDecoder::DecodeMemory(const void*, size_t, SkBitmap*, SkColorType, Mode, Format*) { return false; } @@ -53,7 +48,7 @@ return false; } -bool SkImageDecoder::decodeSubset(SkBitmap*, const SkIRect&, SkBitmap::Config) { +bool SkImageDecoder::decodeSubset(SkBitmap*, const SkIRect&, SkColorType) { return false; }
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp index 16f602b..3b9c194 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp
@@ -90,7 +90,7 @@ return; } - bool success = decoder->decode(&stream, &bm8888, SkBitmap::kARGB_8888_Config, + bool success = decoder->decode(&stream, &bm8888, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); if (!success) { return; @@ -103,7 +103,7 @@ } decoder->setRequireUnpremultipliedColors(true); - success = decoder->decode(&stream, &bm8888Unpremul, SkBitmap::kARGB_8888_Config, + success = decoder->decode(&stream, &bm8888Unpremul, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); if (!success) { return; @@ -117,8 +117,7 @@ } // Only do the comparison if the two bitmaps are both 8888. - if (bm8888.config() != SkBitmap::kARGB_8888_Config - || bm8888Unpremul.config() != SkBitmap::kARGB_8888_Config) { + if (bm8888.colorType() != kN32_SkColorType || bm8888Unpremul.colorType() != kN32_SkColorType) { return; } @@ -182,7 +181,7 @@ decoder->setRequireUnpremultipliedColors(requireUnpremul); // Decode just the bounds. This should always succeed. - bool success = decoder->decode(&stream, &bm, SkBitmap::kARGB_8888_Config, + bool success = decoder->decode(&stream, &bm, kN32_SkColorType, SkImageDecoder::kDecodeBounds_Mode); REPORTER_ASSERT(reporter, success); if (!success) { @@ -202,8 +201,7 @@ return; } - success = decoder->decode(&stream, &bm, SkBitmap::kARGB_8888_Config, - SkImageDecoder::kDecodePixels_Mode); + success = decoder->decode(&stream, &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); if (!success) { // When the decoder is set to require unpremul, if it does not support @@ -285,7 +283,7 @@ // Test unpremultiplied. We know what color this should result in. decoder->setRequireUnpremultipliedColors(true); - bool success = decoder->decode(&stream, &bm, SkBitmap::kARGB_8888_Config, + bool success = decoder->decode(&stream, &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); REPORTER_ASSERT(reporter, success); if (!success) { @@ -307,7 +305,7 @@ // Test premultiplied. Once again, we know which color this should // result in. decoder->setRequireUnpremultipliedColors(false); - success = decoder->decode(&stream, &bm, SkBitmap::kARGB_8888_Config, + success = decoder->decode(&stream, &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); REPORTER_ASSERT(reporter, success); if (!success) { @@ -381,8 +379,7 @@ // Now unref the stream to make sure it survives stream.reset(NULL); SkBitmap bm; - decoder->decodeSubset(&bm, SkIRect::MakeWH(width, height), - SkBitmap::kARGB_8888_Config); + decoder->decodeSubset(&bm, SkIRect::MakeWH(width, height), kN32_SkColorType); } } @@ -629,14 +626,13 @@ return; } - SkBitmap::Config requestedConfig - = SkColorTypeToBitmapConfig(opts.fRequestedColorType); + SkColorType requestedColorType = opts.fRequestedColorType; REPORTER_ASSERT(reporter, (!opts.fUseRequestedColorType) - || (bm.config() == requestedConfig)); + || (bm.colorType() == requestedColorType)); // Condition under which we should check the decoding results: - if ((SkBitmap::kARGB_8888_Config == bm.config()) + if ((kN32_SkColorType == bm.colorType()) && (!path.endsWith(".jpg")) // lossy && (opts.fSampleSize == 1)) { // scaled const SkColor* correctPixels = kExpectedPixels;
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index ec21cb7..850053c 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp
@@ -130,7 +130,7 @@ SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str()); } // Put in a dummy bitmap. - return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config, + return SkImageDecoder::DecodeStream(&memStream, bitmap, kUnknown_SkColorType, SkImageDecoder::kDecodeBounds_Mode); }
diff --git a/tools/skdiff_utils.cpp b/tools/skdiff_utils.cpp index 5c9aae2..9157ac6 100644 --- a/tools/skdiff_utils.cpp +++ b/tools/skdiff_utils.cpp
@@ -63,7 +63,7 @@ SkAutoTDelete<SkImageDecoder> ad(codec); stream.rewind(); - if (!codec->decode(&stream, &resource.fBitmap, SkBitmap::kARGB_8888_Config, mode)) { + if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) { SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c_str()); resource.fStatus = DiffResource::kCouldNotDecode_Status; return false;
diff --git a/tools/skimage_main.cpp b/tools/skimage_main.cpp index 3740f0f..a488aa7 100644 --- a/tools/skimage_main.cpp +++ b/tools/skimage_main.cpp
@@ -117,7 +117,7 @@ static SkTArray<SkString, false> gKnownFailures; static SkTArray<SkString, false> gKnownSubsetFailures; -static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config); +static SkColorType gPrefColorType(kUnknown_SkColorType); // Expections read from a file specified by readExpectationsPath. The expectations must have been // previously written using createExpectationsPath. @@ -445,7 +445,7 @@ // path should never fail. SkASSERT(stream.isValid()); SkBitmap bm; - if (!codec->decode(&stream, &bm, gPrefConfig, SkImageDecoder::kDecodePixels_Mode)) { + if (!codec->decode(&stream, &bm, gPrefColorType, SkImageDecoder::kDecodePixels_Mode)) { gDecodeFailures.push_back().appendf("Without using getLength, %s failed to decode\n", srcPath); return; @@ -510,8 +510,7 @@ replace_char(&basename, '.', '-'); const char* filename = basename.c_str(); - if (!codec->decode(&stream, &bitmap, gPrefConfig, - SkImageDecoder::kDecodePixels_Mode)) { + if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecodePixels_Mode)) { if (NULL != gJsonExpectations.get()) { const SkString name_config = create_json_key(filename); skiagm::Expectations jsExpectations = gJsonExpectations->get(name_config.c_str()); @@ -597,7 +596,7 @@ SkIRect rect = generate_random_rect(&rand, width, height); SkString subsetDim = SkStringPrintf("%d_%d_%d_%d", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); - if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, gPrefConfig)) { + if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, gPrefColorType)) { SkString subsetName = SkStringPrintf("%s-%s", filename, subsetDim.c_str()); skiagm::BitmapAndDigest subsetBitmapAndDigest(bitmapFromDecodeSubset); if (compare_to_expectations_if_necessary(subsetBitmapAndDigest.fDigest, @@ -627,7 +626,7 @@ } // Do not attempt to re-encode A8, since our image encoders do not support encoding to A8. - if (FLAGS_reencode && bitmap.config() != SkBitmap::kA8_Config) { + if (FLAGS_reencode && bitmap.colorType() != kAlpha_8_SkColorType) { // Encode to the format the file was originally in, or PNG if the encoder for the same // format is unavailable. SkImageDecoder::Format format = codec->getFormat(); @@ -684,9 +683,9 @@ SkMemoryStream memStream(data); SkBitmap redecodedBitmap; SkImageDecoder::Format formatOnSecondDecode; - if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, gPrefConfig, - SkImageDecoder::kDecodePixels_Mode, - &formatOnSecondDecode)) { + if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, gPrefColorType, + SkImageDecoder::kDecodePixels_Mode, + &formatOnSecondDecode)) { SkASSERT(format_to_type(formatOnSecondDecode) == type); } else { gDecodeFailures.push_back().printf("Failed to redecode %s after reencoding to '%s'", @@ -772,11 +771,11 @@ // Only consider the first config specified on the command line. const char* config = FLAGS_config[0]; if (0 == strcmp(config, "8888")) { - gPrefConfig = SkBitmap::kARGB_8888_Config; + gPrefColorType = kN32_SkColorType; } else if (0 == strcmp(config, "565")) { - gPrefConfig = SkBitmap::kRGB_565_Config; + gPrefColorType = kRGB_565_SkColorType; } else if (0 == strcmp(config, "A8")) { - gPrefConfig = SkBitmap::kA8_Config; + gPrefColorType = kAlpha_8_SkColorType; } else if (0 != strcmp(config, "None")) { SkDebugf("Invalid preferred config\n"); return -1;