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], |
| 49 SkYUVColorSpace* colorSpace) SK_OVERRIDE; |
48 | 50 |
49 private: | 51 private: |
50 typedef SkImageGenerator INHERITED; | 52 typedef SkImageGenerator INHERITED; |
51 }; | 53 }; |
52 | 54 |
53 /** | 55 /** |
54 * Special allocator used by getPixels(). Uses preallocated memory | 56 * Special allocator used by getPixels(). Uses preallocated memory |
55 * provided if possible, else fall-back on the default allocator | 57 * provided if possible, else fall-back on the default allocator |
56 */ | 58 */ |
57 class TargetAllocator : public SkBitmap::Allocator { | 59 class TargetAllocator : public SkBitmap::Allocator { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return false; | 199 return false; |
198 } | 200 } |
199 const int count = ctable->count(); | 201 const int count = ctable->count(); |
200 memcpy(ctableEntries, ctable->lockColors(), count * sizeof(SkPMColor)); | 202 memcpy(ctableEntries, ctable->lockColors(), count * sizeof(SkPMColor)); |
201 ctable->unlockColors(); | 203 ctable->unlockColors(); |
202 *ctableCount = count; | 204 *ctableCount = count; |
203 } | 205 } |
204 return true; | 206 return true; |
205 } | 207 } |
206 | 208 |
| 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, colorSpac
e); |
| 221 } |
| 222 |
207 // A contructor-type function that returns NULL on failure. This | 223 // A contructor-type function that returns NULL on failure. This |
208 // prevents the returned SkImageGenerator from ever being in a bad | 224 // prevents the returned SkImageGenerator from ever being in a bad |
209 // state. Called by both Create() functions | 225 // state. Called by both Create() functions |
210 SkImageGenerator* CreateDecodingImageGenerator( | 226 SkImageGenerator* CreateDecodingImageGenerator( |
211 SkData* data, | 227 SkData* data, |
212 SkStreamRewindable* stream, | 228 SkStreamRewindable* stream, |
213 const SkDecodingImageGenerator::Options& opts) { | 229 const SkDecodingImageGenerator::Options& opts) { |
214 SkASSERT(stream); | 230 SkASSERT(stream); |
215 SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. | 231 SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. |
216 SkAssertResult(autoStream->rewind()); | 232 SkAssertResult(autoStream->rewind()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 SkStreamRewindable* stream, | 289 SkStreamRewindable* stream, |
274 const SkDecodingImageGenerator::Options& opts) { | 290 const SkDecodingImageGenerator::Options& opts) { |
275 SkASSERT(stream != NULL); | 291 SkASSERT(stream != NULL); |
276 SkASSERT(stream->unique()); | 292 SkASSERT(stream->unique()); |
277 if ((stream == NULL) || !stream->unique()) { | 293 if ((stream == NULL) || !stream->unique()) { |
278 SkSafeUnref(stream); | 294 SkSafeUnref(stream); |
279 return NULL; | 295 return NULL; |
280 } | 296 } |
281 return CreateDecodingImageGenerator(NULL, stream, opts); | 297 return CreateDecodingImageGenerator(NULL, stream, opts); |
282 } | 298 } |
OLD | NEW |