Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkDecodingImageGenerator.h" | 9 #include "SkDecodingImageGenerator.h" |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE; | 28 virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE; |
| 29 virtual bool getPixels(const SkImageInfo& info, | 29 virtual bool getPixels(const SkImageInfo& info, |
| 30 void* pixels, | 30 void* pixels, |
| 31 size_t rowBytes) SK_OVERRIDE; | 31 size_t rowBytes) SK_OVERRIDE; |
| 32 | 32 |
| 33 SkData* fData; | 33 SkData* fData; |
| 34 SkStreamRewindable* fStream; | 34 SkStreamRewindable* fStream; |
| 35 const SkImageInfo fInfo; | 35 const SkImageInfo fInfo; |
| 36 const int fSampleSize; | 36 const int fSampleSize; |
| 37 const bool fDitherImage; | 37 const bool fDitherImage; |
| 38 const bool fRequireUnpremul; | |
|
reed1
2014/04/07 18:21:12
why isn't this deducible from fInfo?
scroggo
2014/04/07 19:00:12
Done. (I'm actually deducing it from the passed in
| |
| 38 | 39 |
| 39 DecodingImageGenerator(SkData* data, | 40 DecodingImageGenerator(SkData* data, |
| 40 SkStreamRewindable* stream, | 41 SkStreamRewindable* stream, |
| 41 const SkImageInfo& info, | 42 const SkImageInfo& info, |
| 42 int sampleSize, | 43 int sampleSize, |
| 43 bool ditherImage); | 44 bool ditherImage, |
| 45 bool requireUnpremul); | |
| 44 typedef SkImageGenerator INHERITED; | 46 typedef SkImageGenerator INHERITED; |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 /** | 49 /** |
| 48 * Special allocator used by getPixels(). Uses preallocated memory | 50 * Special allocator used by getPixels(). Uses preallocated memory |
| 49 * provided if possible, else fall-back on the default allocator | 51 * provided if possible, else fall-back on the default allocator |
| 50 */ | 52 */ |
| 51 class TargetAllocator : public SkBitmap::Allocator { | 53 class TargetAllocator : public SkBitmap::Allocator { |
| 52 public: | 54 public: |
| 53 TargetAllocator(const SkImageInfo& info, | 55 TargetAllocator(const SkImageInfo& info, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 102 } |
| 101 #endif // SK_DEBUG | 103 #endif // SK_DEBUG |
| 102 | 104 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
| 104 | 106 |
| 105 DecodingImageGenerator::DecodingImageGenerator( | 107 DecodingImageGenerator::DecodingImageGenerator( |
| 106 SkData* data, | 108 SkData* data, |
| 107 SkStreamRewindable* stream, | 109 SkStreamRewindable* stream, |
| 108 const SkImageInfo& info, | 110 const SkImageInfo& info, |
| 109 int sampleSize, | 111 int sampleSize, |
| 110 bool ditherImage) | 112 bool ditherImage, |
| 113 bool requireUnpremul) | |
| 111 : fData(data) | 114 : fData(data) |
| 112 , fStream(stream) | 115 , fStream(stream) |
| 113 , fInfo(info) | 116 , fInfo(info) |
| 114 , fSampleSize(sampleSize) | 117 , fSampleSize(sampleSize) |
| 115 , fDitherImage(ditherImage) | 118 , fDitherImage(ditherImage) |
| 119 , fRequireUnpremul(requireUnpremul) | |
| 116 { | 120 { |
| 117 SkASSERT(stream != NULL); | 121 SkASSERT(stream != NULL); |
| 118 SkSafeRef(fData); // may be NULL. | 122 SkSafeRef(fData); // may be NULL. |
| 119 } | 123 } |
| 120 | 124 |
| 121 DecodingImageGenerator::~DecodingImageGenerator() { | 125 DecodingImageGenerator::~DecodingImageGenerator() { |
| 122 SkSafeUnref(fData); | 126 SkSafeUnref(fData); |
| 123 fStream->unref(); | 127 fStream->unref(); |
| 124 } | 128 } |
| 125 | 129 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 return false; | 172 return false; |
| 169 } | 173 } |
| 170 | 174 |
| 171 SkAssertResult(fStream->rewind()); | 175 SkAssertResult(fStream->rewind()); |
| 172 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); | 176 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
| 173 if (NULL == decoder.get()) { | 177 if (NULL == decoder.get()) { |
| 174 return false; | 178 return false; |
| 175 } | 179 } |
| 176 decoder->setDitherImage(fDitherImage); | 180 decoder->setDitherImage(fDitherImage); |
| 177 decoder->setSampleSize(fSampleSize); | 181 decoder->setSampleSize(fSampleSize); |
| 182 decoder->setRequireUnpremultipliedColors(fRequireUnpremul); | |
| 178 | 183 |
| 179 SkBitmap bitmap; | 184 SkBitmap bitmap; |
| 180 TargetAllocator allocator(fInfo, pixels, rowBytes); | 185 TargetAllocator allocator(fInfo, pixels, rowBytes); |
| 181 decoder->setAllocator(&allocator); | 186 decoder->setAllocator(&allocator); |
| 182 // TODO: need to be able to pass colortype directly to decoder | 187 // TODO: need to be able to pass colortype directly to decoder |
| 183 SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); | 188 SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); |
| 184 bool success = decoder->decode(fStream, &bitmap, legacyConfig, | 189 bool success = decoder->decode(fStream, &bitmap, legacyConfig, |
| 185 SkImageDecoder::kDecodePixels_Mode); | 190 SkImageDecoder::kDecodePixels_Mode); |
| 186 decoder->setAllocator(NULL); | 191 decoder->setAllocator(NULL); |
| 187 if (!success) { | 192 if (!success) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } | 248 } |
| 244 } else { | 249 } else { |
| 245 if (!bitmap.canCopyTo(opts.fRequestedColorType)) { | 250 if (!bitmap.canCopyTo(opts.fRequestedColorType)) { |
| 246 SkASSERT(bitmap.colorType() != opts.fRequestedColorType); | 251 SkASSERT(bitmap.colorType() != opts.fRequestedColorType); |
| 247 return NULL; // Can not translate to needed config. | 252 return NULL; // Can not translate to needed config. |
| 248 } | 253 } |
| 249 info.fColorType = opts.fRequestedColorType; | 254 info.fColorType = opts.fRequestedColorType; |
| 250 } | 255 } |
| 251 return SkNEW_ARGS(DecodingImageGenerator, | 256 return SkNEW_ARGS(DecodingImageGenerator, |
| 252 (data, autoStream.detach(), info, | 257 (data, autoStream.detach(), info, |
| 253 opts.fSampleSize, opts.fDitherImage)); | 258 opts.fSampleSize, opts.fDitherImage, |
| 259 opts.fRequireUnpremul)); | |
| 254 } | 260 } |
| 255 | 261 |
| 256 } // namespace | 262 } // namespace |
| 257 | 263 |
| 258 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
| 259 | 265 |
| 260 SkImageGenerator* SkDecodingImageGenerator::Create( | 266 SkImageGenerator* SkDecodingImageGenerator::Create( |
| 261 SkData* data, | 267 SkData* data, |
| 262 const SkDecodingImageGenerator::Options& opts) { | 268 const SkDecodingImageGenerator::Options& opts) { |
| 263 SkASSERT(data != NULL); | 269 SkASSERT(data != NULL); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 274 SkStreamRewindable* stream, | 280 SkStreamRewindable* stream, |
| 275 const SkDecodingImageGenerator::Options& opts) { | 281 const SkDecodingImageGenerator::Options& opts) { |
| 276 SkASSERT(stream != NULL); | 282 SkASSERT(stream != NULL); |
| 277 SkASSERT(stream->unique()); | 283 SkASSERT(stream->unique()); |
| 278 if ((stream == NULL) || !stream->unique()) { | 284 if ((stream == NULL) || !stream->unique()) { |
| 279 SkSafeUnref(stream); | 285 SkSafeUnref(stream); |
| 280 return NULL; | 286 return NULL; |
| 281 } | 287 } |
| 282 return CreateDecodingImageGenerator(NULL, stream, opts); | 288 return CreateDecodingImageGenerator(NULL, stream, opts); |
| 283 } | 289 } |
| OLD | NEW |