#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 {
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);
}
}
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); )
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;
}
// parameters to the "decode" call
bool dither = false;
- SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
SkString filename(INHERITED::gResourcePath);
if (!filename.endsWith("/") && !filename.endsWith("\\")) {
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);
}
}
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");
}
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);
}
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);
class FilterIndiaBoxGM : public skiagm::GM {
void onOnceBeforeDraw() {
-
this->makeBitmap();
SkScalar cx = SkScalarHalf(fBM.width());
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");
}
}
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]);
}
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);
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 {
'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.
}
/** 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).
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);
}
/**
* 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.
/** 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);
}
/**
/** 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;
*/
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.
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;
#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;
-
/*
* 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"
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;
}
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);
* 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"
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);
}
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
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;
}
}
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;
}
}
}
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;
}
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) {
#endif
, fAllocator(NULL)
, fSampleSize(1)
- , fDefaultPref(SkBitmap::kNo_Config)
+ , fDefaultPref(kUnknown_SkColorType)
, fDitherImage(true)
, fUsePrefTable(false)
, fSkipWritingZeroes(false)
// 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
: 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
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;
///////////////////////////////////////////////////////////////////////////////
-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);
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;
}
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);
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;
}
return false;
}
-bool SkImageDecoder::decodeSubset(SkBitmap*, const SkIRect&, SkBitmap::Config) {
+bool SkImageDecoder::decodeSubset(SkBitmap*, const SkIRect&, SkColorType) {
return false;
}
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;
}
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;
}
// 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;
}
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) {
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
// 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) {
// 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) {
// 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);
}
}
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;
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);
}
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;
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.
// 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;
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());
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,
}
// 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();
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'",
// 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;