Index: src/images/SkDecodingImageGenerator.cpp |
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp |
index b3924a7daa4d2b342cb6ea29f333ce93aa4b7390..2493d89b3848ddafad9f7582700ac2b9775a1da1 100644 |
--- a/src/images/SkDecodingImageGenerator.cpp |
+++ b/src/images/SkDecodingImageGenerator.cpp |
@@ -23,12 +23,6 @@ bool equal_modulo_alpha(const SkImageInfo& a, const SkImageInfo& b) { |
class DecodingImageGenerator : public SkImageGenerator { |
public: |
virtual ~DecodingImageGenerator(); |
- virtual SkData* refEncodedData() SK_OVERRIDE; |
- // This implementaion of getInfo() always returns true. |
- virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE; |
- virtual bool getPixels(const SkImageInfo& info, |
- void* pixels, |
- size_t rowBytes) SK_OVERRIDE; |
SkData* fData; |
SkStreamRewindable* fStream; |
@@ -41,6 +35,18 @@ public: |
const SkImageInfo& info, |
int sampleSize, |
bool ditherImage); |
+ |
+protected: |
+ virtual SkData* onRefEncodedData() SK_OVERRIDE; |
+ virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
+ *info = fInfo; |
+ return true; |
+ } |
+ virtual bool onGetPixels(const SkImageInfo& info, |
+ void* pixels, size_t rowBytes, |
+ SkPMColor ctable[], int* ctableCount) SK_OVERRIDE; |
+ |
+private: |
typedef SkImageGenerator INHERITED; |
}; |
@@ -69,7 +75,7 @@ public: |
// TODO(halcanary): verify that all callers of this function |
// will respect new RowBytes. Will be moot once rowbytes belongs |
// to PixelRef. |
- bm->installPixels(fInfo, fTarget, fRowBytes, NULL, NULL); |
+ bm->installPixels(fInfo, fTarget, fRowBytes, ct, NULL, NULL); |
fTarget = NULL; // never alloc same pixels twice! |
return true; |
@@ -123,14 +129,7 @@ DecodingImageGenerator::~DecodingImageGenerator() { |
fStream->unref(); |
} |
-bool DecodingImageGenerator::getInfo(SkImageInfo* info) { |
- if (info != NULL) { |
- *info = fInfo; |
- } |
- return true; |
-} |
- |
-SkData* DecodingImageGenerator::refEncodedData() { |
+SkData* DecodingImageGenerator::onRefEncodedData() { |
// This functionality is used in `gm --serialize` |
// Does not encode options. |
if (fData != NULL) { |
@@ -151,22 +150,15 @@ SkData* DecodingImageGenerator::refEncodedData() { |
return SkSafeRef(fData); |
} |
-bool DecodingImageGenerator::getPixels(const SkImageInfo& info, |
- void* pixels, |
- size_t rowBytes) { |
- if (NULL == pixels) { |
- return false; |
- } |
+bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, |
+ void* pixels, size_t rowBytes, |
+ SkPMColor ctableEntries[], int* ctableCount) { |
if (fInfo != info) { |
// The caller has specified a different info. This is an |
// error for this kind of SkImageGenerator. Use the Options |
// to change the settings. |
return false; |
} |
- if (info.minRowBytes() > rowBytes) { |
- // The caller has specified a bad rowBytes. |
- return false; |
- } |
SkAssertResult(fStream->rewind()); |
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
@@ -202,6 +194,20 @@ bool DecodingImageGenerator::getPixels(const SkImageInfo& info, |
} else { |
SkASSERT(check_alpha(info.alphaType(), bitmap.alphaType())); |
} |
+ |
+ if (kIndex_8_SkColorType == info.colorType()) { |
+ if (kIndex_8_SkColorType != bitmap.colorType()) { |
+ return false; // they asked for Index8, but we didn't receive that from decoder |
+ } |
+ SkColorTable* ctable = bitmap.getColorTable(); |
+ if (NULL == ctable) { |
+ return false; |
+ } |
+ const int count = ctable->count(); |
+ memcpy(ctableEntries, ctable->lockColors(), count * sizeof(SkPMColor)); |
+ ctable->unlockColors(); |
+ *ctableCount = count; |
+ } |
return true; |
} |
@@ -214,11 +220,6 @@ SkImageGenerator* CreateDecodingImageGenerator( |
const SkDecodingImageGenerator::Options& opts) { |
SkASSERT(stream); |
SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. |
- if (opts.fUseRequestedColorType && |
- (kIndex_8_SkColorType == opts.fRequestedColorType)) { |
- // We do not support indexed color with SkImageGenerators, |
- return NULL; |
- } |
SkAssertResult(autoStream->rewind()); |
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(autoStream)); |
if (NULL == decoder.get()) { |
@@ -227,24 +228,16 @@ SkImageGenerator* CreateDecodingImageGenerator( |
SkBitmap bitmap; |
decoder->setSampleSize(opts.fSampleSize); |
decoder->setRequireUnpremultipliedColors(opts.fRequireUnpremul); |
- if (!decoder->decode(stream, &bitmap, |
- SkImageDecoder::kDecodeBounds_Mode)) { |
+ if (!decoder->decode(stream, &bitmap, SkImageDecoder::kDecodeBounds_Mode)) { |
return NULL; |
} |
- if (bitmap.config() == SkBitmap::kNo_Config) { |
+ if (kUnknown_SkColorType == bitmap.colorType()) { |
return NULL; |
} |
SkImageInfo info = bitmap.info(); |
- if (!opts.fUseRequestedColorType) { |
- // Use default |
- if (kIndex_8_SkColorType == bitmap.colorType()) { |
- // We don't support kIndex8 because we don't support |
- // colortables in this workflow. |
- info.fColorType = kN32_SkColorType; |
- } |
- } else { |
+ if (opts.fUseRequestedColorType && (opts.fRequestedColorType != info.colorType())) { |
if (!bitmap.canCopyTo(opts.fRequestedColorType)) { |
SkASSERT(bitmap.colorType() != opts.fRequestedColorType); |
return NULL; // Can not translate to needed config. |