halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | 1ad518b | 2013-12-18 18:33:15 +0000 | [diff] [blame] | 8 | #include "SkData.h" |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 9 | #include "SkDecodingImageGenerator.h" |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 10 | #include "SkImageDecoder.h" |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 11 | #include "SkImageInfo.h" |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 12 | #include "SkImageGenerator.h" |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 13 | #include "SkImagePriv.h" |
| 14 | #include "SkStream.h" |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 15 | #include "SkUtils.h" |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 16 | |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 17 | namespace { |
| 18 | bool equal_modulo_alpha(const SkImageInfo& a, const SkImageInfo& b) { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 19 | return a.width() == b.width() && a.height() == b.height() && |
| 20 | a.colorType() == b.colorType(); |
| 21 | } |
| 22 | |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 23 | class DecodingImageGenerator : public SkImageGenerator { |
| 24 | public: |
| 25 | virtual ~DecodingImageGenerator(); |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 26 | |
| 27 | SkData* fData; |
| 28 | SkStreamRewindable* fStream; |
| 29 | const SkImageInfo fInfo; |
| 30 | const int fSampleSize; |
| 31 | const bool fDitherImage; |
| 32 | |
| 33 | DecodingImageGenerator(SkData* data, |
| 34 | SkStreamRewindable* stream, |
| 35 | const SkImageInfo& info, |
| 36 | int sampleSize, |
| 37 | bool ditherImage); |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 38 | |
| 39 | protected: |
| 40 | virtual SkData* onRefEncodedData() SK_OVERRIDE; |
| 41 | virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
| 42 | *info = fInfo; |
| 43 | return true; |
| 44 | } |
| 45 | virtual bool onGetPixels(const SkImageInfo& info, |
| 46 | void* pixels, size_t rowBytes, |
| 47 | SkPMColor ctable[], int* ctableCount) SK_OVERRIDE; |
sugoi | b227e37 | 2014-10-16 13:10:57 -0700 | [diff] [blame] | 48 | virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
| 49 | SkYUVColorSpace* colorSpace) SK_OVERRIDE; |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 50 | |
| 51 | private: |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 52 | typedef SkImageGenerator INHERITED; |
| 53 | }; |
| 54 | |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 55 | /** |
| 56 | * Special allocator used by getPixels(). Uses preallocated memory |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 57 | * provided if possible, else fall-back on the default allocator |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 58 | */ |
| 59 | class TargetAllocator : public SkBitmap::Allocator { |
| 60 | public: |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 61 | TargetAllocator(const SkImageInfo& info, |
| 62 | void* target, |
| 63 | size_t rowBytes) |
| 64 | : fInfo(info) |
| 65 | , fTarget(target) |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 66 | , fRowBytes(rowBytes) |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 67 | {} |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 68 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 69 | bool isReady() { return (fTarget != NULL); } |
| 70 | |
| 71 | virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 72 | if (NULL == fTarget || !equal_modulo_alpha(fInfo, bm->info())) { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 73 | // Call default allocator. |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 74 | return bm->tryAllocPixels(NULL, ct); |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 75 | } |
skia.committer@gmail.com | 86cbf99 | 2014-02-24 03:01:55 +0000 | [diff] [blame] | 76 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 77 | // TODO(halcanary): verify that all callers of this function |
| 78 | // will respect new RowBytes. Will be moot once rowbytes belongs |
| 79 | // to PixelRef. |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 80 | bm->installPixels(fInfo, fTarget, fRowBytes, ct, NULL, NULL); |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 81 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 82 | fTarget = NULL; // never alloc same pixels twice! |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 83 | return true; |
| 84 | } |
| 85 | |
| 86 | private: |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 87 | const SkImageInfo fInfo; |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 88 | void* fTarget; // Block of memory to be supplied as pixel memory |
| 89 | // in allocPixelRef. Must be large enough to hold |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 90 | // a bitmap described by fInfo and fRowBytes |
| 91 | const size_t fRowBytes; // rowbytes for the destination bitmap |
| 92 | |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 93 | typedef SkBitmap::Allocator INHERITED; |
| 94 | }; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 95 | |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 96 | // TODO(halcanary): Give this macro a better name and move it into SkTypes.h |
| 97 | #ifdef SK_DEBUG |
| 98 | #define SkCheckResult(expr, value) SkASSERT((value) == (expr)) |
| 99 | #else |
| 100 | #define SkCheckResult(expr, value) (void)(expr) |
| 101 | #endif |
| 102 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 103 | #ifdef SK_DEBUG |
| 104 | inline bool check_alpha(SkAlphaType reported, SkAlphaType actual) { |
| 105 | return ((reported == actual) |
| 106 | || ((reported == kPremul_SkAlphaType) |
| 107 | && (actual == kOpaque_SkAlphaType))); |
| 108 | } |
| 109 | #endif // SK_DEBUG |
| 110 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 111 | //////////////////////////////////////////////////////////////////////////////// |
| 112 | |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 113 | DecodingImageGenerator::DecodingImageGenerator( |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 114 | SkData* data, |
| 115 | SkStreamRewindable* stream, |
| 116 | const SkImageInfo& info, |
| 117 | int sampleSize, |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 118 | bool ditherImage) |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 119 | : fData(data) |
| 120 | , fStream(stream) |
| 121 | , fInfo(info) |
| 122 | , fSampleSize(sampleSize) |
| 123 | , fDitherImage(ditherImage) |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 124 | { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 125 | SkASSERT(stream != NULL); |
| 126 | SkSafeRef(fData); // may be NULL. |
| 127 | } |
| 128 | |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 129 | DecodingImageGenerator::~DecodingImageGenerator() { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 130 | SkSafeUnref(fData); |
| 131 | fStream->unref(); |
| 132 | } |
| 133 | |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 134 | SkData* DecodingImageGenerator::onRefEncodedData() { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 135 | // This functionality is used in `gm --serialize` |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 136 | // Does not encode options. |
reed | 33a3050 | 2014-09-11 08:42:36 -0700 | [diff] [blame] | 137 | if (NULL == fData) { |
| 138 | // TODO(halcanary): SkStreamRewindable needs a refData() function |
| 139 | // which returns a cheap copy of the underlying data. |
| 140 | if (!fStream->rewind()) { |
| 141 | return NULL; |
| 142 | } |
| 143 | size_t length = fStream->getLength(); |
reed | 9594da1 | 2014-09-12 12:12:27 -0700 | [diff] [blame] | 144 | if (length) { |
| 145 | fData = SkData::NewFromStream(fStream, length); |
reed | 33a3050 | 2014-09-11 08:42:36 -0700 | [diff] [blame] | 146 | } |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 147 | } |
reed | 9594da1 | 2014-09-12 12:12:27 -0700 | [diff] [blame] | 148 | return SkSafeRef(fData); |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 149 | } |
| 150 | |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 151 | bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, |
| 152 | void* pixels, size_t rowBytes, |
| 153 | SkPMColor ctableEntries[], int* ctableCount) { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 154 | if (fInfo != info) { |
| 155 | // The caller has specified a different info. This is an |
| 156 | // error for this kind of SkImageGenerator. Use the Options |
| 157 | // to change the settings. |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 158 | return false; |
| 159 | } |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 160 | |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 161 | SkAssertResult(fStream->rewind()); |
| 162 | SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
| 163 | if (NULL == decoder.get()) { |
| 164 | return false; |
| 165 | } |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 166 | decoder->setDitherImage(fDitherImage); |
| 167 | decoder->setSampleSize(fSampleSize); |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 168 | decoder->setRequireUnpremultipliedColors(info.alphaType() == kUnpremul_SkAlphaType); |
commit-bot@chromium.org | 1ad518b | 2013-12-18 18:33:15 +0000 | [diff] [blame] | 169 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 170 | SkBitmap bitmap; |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 171 | TargetAllocator allocator(fInfo, pixels, rowBytes); |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 172 | decoder->setAllocator(&allocator); |
reed | bfefc7c | 2014-06-12 17:40:00 -0700 | [diff] [blame] | 173 | bool success = decoder->decode(fStream, &bitmap, info.colorType(), |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 174 | SkImageDecoder::kDecodePixels_Mode); |
| 175 | decoder->setAllocator(NULL); |
| 176 | if (!success) { |
| 177 | return false; |
| 178 | } |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 179 | if (allocator.isReady()) { // Did not use pixels! |
| 180 | SkBitmap bm; |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 181 | SkASSERT(bitmap.canCopyTo(info.colorType())); |
| 182 | bool copySuccess = bitmap.copyTo(&bm, info.colorType(), &allocator); |
| 183 | if (!copySuccess || allocator.isReady()) { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 184 | SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed."); |
| 185 | // Earlier we checked canCopyto(); we expect consistency. |
| 186 | return false; |
| 187 | } |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 188 | SkASSERT(check_alpha(info.alphaType(), bm.alphaType())); |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 189 | } else { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 190 | SkASSERT(check_alpha(info.alphaType(), bitmap.alphaType())); |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 191 | } |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 192 | |
| 193 | if (kIndex_8_SkColorType == info.colorType()) { |
| 194 | if (kIndex_8_SkColorType != bitmap.colorType()) { |
| 195 | return false; // they asked for Index8, but we didn't receive that from decoder |
| 196 | } |
| 197 | SkColorTable* ctable = bitmap.getColorTable(); |
| 198 | if (NULL == ctable) { |
| 199 | return false; |
| 200 | } |
| 201 | const int count = ctable->count(); |
| 202 | memcpy(ctableEntries, ctable->lockColors(), count * sizeof(SkPMColor)); |
| 203 | ctable->unlockColors(); |
| 204 | *ctableCount = count; |
| 205 | } |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 206 | return true; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 207 | } |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 208 | |
sugoi | b227e37 | 2014-10-16 13:10:57 -0700 | [diff] [blame] | 209 | bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], |
| 210 | size_t rowBytes[3], SkYUVColorSpace* colorSpace) { |
| 211 | if (!fStream->rewind()) { |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
| 216 | if (NULL == decoder.get()) { |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | return decoder->decodeYUV8Planes(fStream, sizes, planes, rowBytes, colorSpace); |
| 221 | } |
| 222 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 223 | // A contructor-type function that returns NULL on failure. This |
| 224 | // prevents the returned SkImageGenerator from ever being in a bad |
| 225 | // state. Called by both Create() functions |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 226 | SkImageGenerator* CreateDecodingImageGenerator( |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 227 | SkData* data, |
| 228 | SkStreamRewindable* stream, |
| 229 | const SkDecodingImageGenerator::Options& opts) { |
| 230 | SkASSERT(stream); |
| 231 | SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 232 | SkAssertResult(autoStream->rewind()); |
| 233 | SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(autoStream)); |
| 234 | if (NULL == decoder.get()) { |
| 235 | return NULL; |
| 236 | } |
| 237 | SkBitmap bitmap; |
| 238 | decoder->setSampleSize(opts.fSampleSize); |
commit-bot@chromium.org | 1ae492f | 2014-04-07 21:37:36 +0000 | [diff] [blame] | 239 | decoder->setRequireUnpremultipliedColors(opts.fRequireUnpremul); |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 240 | if (!decoder->decode(stream, &bitmap, SkImageDecoder::kDecodeBounds_Mode)) { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 241 | return NULL; |
| 242 | } |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 243 | if (kUnknown_SkColorType == bitmap.colorType()) { |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 244 | return NULL; |
| 245 | } |
| 246 | |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 247 | SkImageInfo info = bitmap.info(); |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 248 | |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 249 | if (opts.fUseRequestedColorType && (opts.fRequestedColorType != info.colorType())) { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 250 | if (!bitmap.canCopyTo(opts.fRequestedColorType)) { |
| 251 | SkASSERT(bitmap.colorType() != opts.fRequestedColorType); |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 252 | return NULL; // Can not translate to needed config. |
| 253 | } |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 254 | info = info.makeColorType(opts.fRequestedColorType); |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 255 | } |
commit-bot@chromium.org | 1ae492f | 2014-04-07 21:37:36 +0000 | [diff] [blame] | 256 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 257 | if (opts.fRequireUnpremul && info.alphaType() != kOpaque_SkAlphaType) { |
| 258 | info = info.makeAlphaType(kUnpremul_SkAlphaType); |
commit-bot@chromium.org | 1ae492f | 2014-04-07 21:37:36 +0000 | [diff] [blame] | 259 | } |
scroggo | 2fd0d14 | 2014-07-01 07:08:19 -0700 | [diff] [blame] | 260 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 261 | SkAlphaType newAlphaType = info.alphaType(); |
| 262 | if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAlphaType)) { |
scroggo | 2fd0d14 | 2014-07-01 07:08:19 -0700 | [diff] [blame] | 263 | return NULL; |
| 264 | } |
| 265 | |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 266 | return SkNEW_ARGS(DecodingImageGenerator, |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 267 | (data, autoStream.detach(), info.makeAlphaType(newAlphaType), |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 268 | opts.fSampleSize, opts.fDitherImage)); |
halcanary@google.com | 29d9693 | 2013-12-09 13:45:02 +0000 | [diff] [blame] | 269 | } |
commit-bot@chromium.org | 1f2d357 | 2014-04-04 20:13:05 +0000 | [diff] [blame] | 270 | |
| 271 | } // namespace |
| 272 | |
| 273 | //////////////////////////////////////////////////////////////////////////////// |
| 274 | |
| 275 | SkImageGenerator* SkDecodingImageGenerator::Create( |
| 276 | SkData* data, |
| 277 | const SkDecodingImageGenerator::Options& opts) { |
| 278 | SkASSERT(data != NULL); |
| 279 | if (NULL == data) { |
| 280 | return NULL; |
| 281 | } |
| 282 | SkStreamRewindable* stream = SkNEW_ARGS(SkMemoryStream, (data)); |
| 283 | SkASSERT(stream != NULL); |
| 284 | SkASSERT(stream->unique()); |
| 285 | return CreateDecodingImageGenerator(data, stream, opts); |
| 286 | } |
| 287 | |
| 288 | SkImageGenerator* SkDecodingImageGenerator::Create( |
| 289 | SkStreamRewindable* stream, |
| 290 | const SkDecodingImageGenerator::Options& opts) { |
| 291 | SkASSERT(stream != NULL); |
| 292 | SkASSERT(stream->unique()); |
| 293 | if ((stream == NULL) || !stream->unique()) { |
| 294 | SkSafeUnref(stream); |
| 295 | return NULL; |
| 296 | } |
| 297 | return CreateDecodingImageGenerator(NULL, stream, opts); |
| 298 | } |