| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 protected: | 39 protected: |
| 40 virtual SkData* onRefEncodedData() SK_OVERRIDE; | 40 virtual SkData* onRefEncodedData() SK_OVERRIDE; |
| 41 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { | 41 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
| 42 *info = fInfo; | 42 *info = fInfo; |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 virtual bool onGetPixels(const SkImageInfo& info, | 45 virtual bool onGetPixels(const SkImageInfo& info, |
| 46 void* pixels, size_t rowBytes, | 46 void* pixels, size_t rowBytes, |
| 47 SkPMColor ctable[], int* ctableCount) SK_OVERRIDE; | 47 SkPMColor ctable[], int* ctableCount) SK_OVERRIDE; |
| 48 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]) SK_OVERRIDE; |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 typedef SkImageGenerator INHERITED; | 51 typedef SkImageGenerator INHERITED; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 /** | 54 /** |
| 54 * Special allocator used by getPixels(). Uses preallocated memory | 55 * Special allocator used by getPixels(). Uses preallocated memory |
| 55 * provided if possible, else fall-back on the default allocator | 56 * provided if possible, else fall-back on the default allocator |
| 56 */ | 57 */ |
| 57 class TargetAllocator : public SkBitmap::Allocator { | 58 class TargetAllocator : public SkBitmap::Allocator { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return false; | 203 return false; |
| 203 } | 204 } |
| 204 const int count = ctable->count(); | 205 const int count = ctable->count(); |
| 205 memcpy(ctableEntries, ctable->lockColors(), count * sizeof(SkPMColor)); | 206 memcpy(ctableEntries, ctable->lockColors(), count * sizeof(SkPMColor)); |
| 206 ctable->unlockColors(); | 207 ctable->unlockColors(); |
| 207 *ctableCount = count; | 208 *ctableCount = count; |
| 208 } | 209 } |
| 209 return true; | 210 return true; |
| 210 } | 211 } |
| 211 | 212 |
| 213 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], |
| 214 size_t rowBytes[3]) { |
| 215 if (!fStream->rewind()) { |
| 216 return false; |
| 217 } |
| 218 |
| 219 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); |
| 220 if (NULL == decoder.get()) { |
| 221 return false; |
| 222 } |
| 223 |
| 224 if (planes && (NULL != planes[0]) && (NULL != planes[1]) && (NULL != planes[
2]) && |
| 225 rowBytes && (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2
])) { |
| 226 decoder->setYUVBuffers(planes, rowBytes); |
| 227 return this->onGetPixels(fInfo, NULL, 0, NULL, NULL); |
| 228 } |
| 229 |
| 230 return decoder->getComponentSizes(fStream, sizes); |
| 231 } |
| 232 |
| 212 // A contructor-type function that returns NULL on failure. This | 233 // A contructor-type function that returns NULL on failure. This |
| 213 // prevents the returned SkImageGenerator from ever being in a bad | 234 // prevents the returned SkImageGenerator from ever being in a bad |
| 214 // state. Called by both Create() functions | 235 // state. Called by both Create() functions |
| 215 SkImageGenerator* CreateDecodingImageGenerator( | 236 SkImageGenerator* CreateDecodingImageGenerator( |
| 216 SkData* data, | 237 SkData* data, |
| 217 SkStreamRewindable* stream, | 238 SkStreamRewindable* stream, |
| 218 const SkDecodingImageGenerator::Options& opts) { | 239 const SkDecodingImageGenerator::Options& opts) { |
| 219 SkASSERT(stream); | 240 SkASSERT(stream); |
| 220 SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. | 241 SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. |
| 221 SkAssertResult(autoStream->rewind()); | 242 SkAssertResult(autoStream->rewind()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 SkStreamRewindable* stream, | 298 SkStreamRewindable* stream, |
| 278 const SkDecodingImageGenerator::Options& opts) { | 299 const SkDecodingImageGenerator::Options& opts) { |
| 279 SkASSERT(stream != NULL); | 300 SkASSERT(stream != NULL); |
| 280 SkASSERT(stream->unique()); | 301 SkASSERT(stream->unique()); |
| 281 if ((stream == NULL) || !stream->unique()) { | 302 if ((stream == NULL) || !stream->unique()) { |
| 282 SkSafeUnref(stream); | 303 SkSafeUnref(stream); |
| 283 return NULL; | 304 return NULL; |
| 284 } | 305 } |
| 285 return CreateDecodingImageGenerator(NULL, stream, opts); | 306 return CreateDecodingImageGenerator(NULL, stream, opts); |
| 286 } | 307 } |
| OLD | NEW |