diff options
author | reed <reed@chromium.org> | 2014-06-12 17:40:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-06-12 17:40:00 -0700 |
commit | bfefc7c95fc0e8ebd5000c68f6d16e1a3ea0e71e (patch) | |
tree | 9e68e04fa38c4e28ac478786bfe6d402a3bff239 | |
parent | 9a8699f45c2bd8dac0c06829a06b6b244d19b6b2 (diff) |
hide Config in SkImageDecoder -- use SkColorType instead
patch from issue 334613003
TBR=scroggo
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/334793002
-rw-r--r-- | bench/DecodeBench.cpp | 25 | ||||
-rw-r--r-- | experimental/PdfViewer/chop_transparency_main.cpp | 3 | ||||
-rw-r--r-- | gm/cmykjpeg.cpp | 4 | ||||
-rw-r--r-- | gm/copyTo4444.cpp | 3 | ||||
-rw-r--r-- | gm/downsamplebitmap.cpp | 3 | ||||
-rw-r--r-- | gm/filterbitmap.cpp | 3 | ||||
-rw-r--r-- | gm/filterindiabox.cpp | 12 | ||||
-rw-r--r-- | gm/gm_expectations.cpp | 6 | ||||
-rw-r--r-- | gyp/skia_for_android_framework_defines.gypi | 1 | ||||
-rw-r--r-- | include/core/SkImageDecoder.h | 83 | ||||
-rw-r--r-- | samplecode/SampleFilter2.cpp | 12 | ||||
-rw-r--r-- | samplecode/SampleSubpixelTranslate.cpp | 3 | ||||
-rw-r--r-- | samplecode/SampleUnpremul.cpp | 4 | ||||
-rw-r--r-- | src/image/SkImagePriv.cpp | 4 | ||||
-rw-r--r-- | src/image/SkImage_Codec.cpp | 9 | ||||
-rw-r--r-- | src/images/SkDecodingImageGenerator.cpp | 4 | ||||
-rw-r--r-- | src/images/SkImageDecoder.cpp | 39 | ||||
-rw-r--r-- | src/ports/SkImageDecoder_empty.cpp | 15 | ||||
-rw-r--r-- | tests/ImageDecodingTest.cpp | 26 | ||||
-rw-r--r-- | tools/render_pictures_main.cpp | 2 | ||||
-rw-r--r-- | tools/skdiff_utils.cpp | 2 | ||||
-rw-r--r-- | tools/skimage_main.cpp | 23 |
22 files changed, 126 insertions, 160 deletions
diff --git a/bench/DecodeBench.cpp b/bench/DecodeBench.cpp index a6ab4a5953..15a80b1b5c 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 @@ protected: 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 @@ private: 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 b6a104cc59..3f4b1fdee2 100644 --- a/experimental/PdfViewer/chop_transparency_main.cpp +++ b/experimental/PdfViewer/chop_transparency_main.cpp @@ -108,8 +108,7 @@ static void decodeFileAndWrite(const char srcPath[]) { 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 b30fd4d315..2d0c275b8d 100644 --- a/gm/cmykjpeg.cpp +++ b/gm/cmykjpeg.cpp @@ -24,7 +24,6 @@ protected: // 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 @@ protected: 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 ed0c046fa9..76dc66ca7c 100644 --- a/gm/copyTo4444.cpp +++ b/gm/copyTo4444.cpp @@ -31,8 +31,7 @@ protected: 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 00b1a4b587..d7b93072c8 100644 --- a/gm/downsamplebitmap.cpp +++ b/gm/downsamplebitmap.cpp @@ -183,8 +183,7 @@ class DownsampleBitmapImageGM: public DownsampleBitmapGM { } 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 c650902b4b..351fb2aaf7 100644 --- a/gm/filterbitmap.cpp +++ b/gm/filterbitmap.cpp @@ -204,8 +204,7 @@ class FilterBitmapImageGM: public FilterBitmapGM { } 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 c03dfba293..4acb2c3a71 100644 --- a/gm/filterindiabox.cpp +++ b/gm/filterindiabox.cpp @@ -45,7 +45,6 @@ static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, class FilterIndiaBoxGM : public skiagm::GM { void onOnceBeforeDraw() { - this->makeBitmap(); SkScalar cx = SkScalarHalf(fBM.width()); @@ -63,14 +62,11 @@ public: 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 @@ protected: } 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 @@ protected: } 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 d2d629e8d3..f0ccb3e378 100644 --- a/gm/gm_expectations.cpp +++ b/gm/gm_expectations.cpp @@ -207,10 +207,8 @@ namespace skiagm { 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 3258a34237..223d504337 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 58920992e1..ed17f0fbf8 100644 --- a/include/core/SkImageDecoder.h +++ b/include/core/SkImageDecoder.h @@ -239,22 +239,22 @@ public: } /** 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 @@ public: 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 @@ public: * 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 @@ public: /** 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 @@ public: /** 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 @@ protected: */ 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 @@ public: 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 @@ private: #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 552ce8a83c..0c811969ba 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 @@ public: 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 686a153df6..afb31c162c 100644 --- a/samplecode/SampleSubpixelTranslate.cpp +++ b/samplecode/SampleSubpixelTranslate.cpp @@ -37,8 +37,7 @@ public: } 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 0b1848df95..c84e1d44e8 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 @@ private: 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 56afd6649c..3ea61d519b 100644 --- a/src/image/SkImagePriv.cpp +++ b/src/image/SkImagePriv.cpp @@ -33,10 +33,6 @@ SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType colorType) { 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 64f58a6aef..3d815ce7f4 100644 --- a/src/image/SkImage_Codec.cpp +++ b/src/image/SkImage_Codec.cpp @@ -41,8 +41,7 @@ SkImage_Codec::~SkImage_Codec() { 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::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai 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 @@ SkImage* SkImage::NewEncodedData(SkData* data) { } 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 2493d89b38..88cdef9a32 100644 --- a/src/images/SkDecodingImageGenerator.cpp +++ b/src/images/SkDecodingImageGenerator.cpp @@ -173,9 +173,7 @@ bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, 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 223ae15264..3c6ff69982 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -21,7 +21,7 @@ SkImageDecoder::SkImageDecoder() #endif , fAllocator(NULL) , fSampleSize(1) - , fDefaultPref(SkBitmap::kNo_Config) + , fDefaultPref(kUnknown_SkColorType) , fDitherImage(true) , fUsePrefTable(false) , fSkipWritingZeroes(false) @@ -148,9 +148,11 @@ void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { // 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 @@ SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha : 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 @@ bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, 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::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, /////////////////////////////////////////////////////////////////////////////// -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 @@ bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, 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 @@ bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, 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 50b1d44fa8..7824732bb9 100644 --- a/src/ports/SkImageDecoder_empty.cpp +++ b/src/ports/SkImageDecoder_empty.cpp @@ -28,24 +28,19 @@ SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable*) { 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 @@ bool SkImageDecoder::buildTileIndex(SkStreamRewindable*, int *width, int *height 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 16f602b605..3b9c194929 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -90,7 +90,7 @@ static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filen 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 @@ static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filen } 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 @@ static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filen } // 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 @@ static void test_alphaType(skiatest::Reporter* reporter, const SkString& filenam 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 @@ static void test_alphaType(skiatest::Reporter* reporter, const SkString& filenam 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 @@ DEF_TEST(ImageDecoding_unpremul, reporter) { // 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 @@ DEF_TEST(ImageDecoding_unpremul, reporter) { // 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 @@ static void test_stream_life() { // 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 @@ static void test_options(skiatest::Reporter* reporter, 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 ec21cb7da3..850053cfc6 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -130,7 +130,7 @@ static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma 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 5c9aae275a..9157ac6b91 100644 --- a/tools/skdiff_utils.cpp +++ b/tools/skdiff_utils.cpp @@ -63,7 +63,7 @@ bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode m 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 3740f0fa07..a488aa7e2f 100644 --- a/tools/skimage_main.cpp +++ b/tools/skimage_main.cpp @@ -117,7 +117,7 @@ static SkTArray<SkString, false> gMissingSubsetExpectations; 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 @@ static void test_stream_without_length(const char srcPath[], SkImageDecoder* cod // 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 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) 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 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) 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 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) } // 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 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) 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 @@ int tool_main(int argc, char** argv) { // 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; |