OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The Android Open Source Project | 2 * Copyright 2015 The Android Open Source Project |
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 "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 }; | 33 }; |
34 | 34 |
35 class SkImageDecoderGenerator : public SkImageGenerator { | 35 class SkImageDecoderGenerator : public SkImageGenerator { |
36 const SkImageInfo fInfo; | 36 const SkImageInfo fInfo; |
37 SkAutoTDelete<SkImageDecoder> fDecoder; | 37 SkAutoTDelete<SkImageDecoder> fDecoder; |
38 SkAutoTUnref<SkData> fData; | 38 SkAutoTUnref<SkData> fData; |
39 | 39 |
40 public: | 40 public: |
41 SkImageDecoderGenerator(const SkImageInfo& info, SkImageDecoder* decoder, Sk
Data* data) | 41 SkImageDecoderGenerator(const SkImageInfo& info, SkImageDecoder* decoder, Sk
Data* data) |
42 : fInfo(info), fDecoder(decoder), fData(SkRef(data)) | 42 : INHERITED(info), fInfo(info), fDecoder(decoder), fData(SkRef(data)) |
43 {} | 43 {} |
44 | 44 |
45 protected: | 45 protected: |
46 SkData* onRefEncodedData() SK_OVERRIDE { | 46 SkData* onRefEncodedData() SK_OVERRIDE { |
47 return SkRef(fData.get()); | 47 return SkRef(fData.get()); |
48 } | 48 } |
49 | 49 |
| 50 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO |
50 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { | 51 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
51 *info = fInfo; | 52 *info = fInfo; |
52 return true; | 53 return true; |
53 } | 54 } |
| 55 #endif |
54 | 56 |
55 virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t row
Bytes, | 57 virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t row
Bytes, |
56 const Options&, | 58 const Options&, |
57 SkPMColor ctableEntries[], int* ctableCount) SK_O
VERRIDE { | 59 SkPMColor ctableEntries[], int* ctableCount) SK_O
VERRIDE { |
58 SkMemoryStream stream(fData->data(), fData->size(), false); | 60 SkMemoryStream stream(fData->data(), fData->size(), false); |
59 SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat
or, | 61 SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocat
or, |
60 (info, pixels, ro
wBytes))); | 62 (info, pixels, ro
wBytes))); |
61 fDecoder->setAllocator(allocator); | 63 fDecoder->setAllocator(allocator); |
62 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.
alphaType()); | 64 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.
alphaType()); |
63 | 65 |
(...skipping 21 matching lines...) Expand all Loading... |
85 return kIncompleteInput; | 87 return kIncompleteInput; |
86 } | 88 } |
87 return kSuccess; | 89 return kSuccess; |
88 } | 90 } |
89 | 91 |
90 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 92 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
91 SkYUVColorSpace* colorSpace) SK_OVERRIDE { | 93 SkYUVColorSpace* colorSpace) SK_OVERRIDE { |
92 SkMemoryStream stream(fData->data(), fData->size(), false); | 94 SkMemoryStream stream(fData->data(), fData->size(), false); |
93 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
rSpace); | 95 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo
rSpace); |
94 } | 96 } |
95 | 97 |
| 98 private: |
| 99 typedef SkImageGenerator INHERITED; |
96 }; | 100 }; |
97 | 101 |
98 SkImageGenerator* SkImageGenerator::NewFromData(SkData* data) { | 102 SkImageGenerator* SkImageGenerator::NewFromData(SkData* data) { |
99 if (NULL == data) { | 103 if (NULL == data) { |
100 return NULL; | 104 return NULL; |
101 } | 105 } |
102 | 106 |
103 SkMemoryStream stream(data->data(), data->size(), false); | 107 SkMemoryStream stream(data->data(), data->size(), false); |
104 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); | 108 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); |
105 if (NULL == decoder) { | 109 if (NULL == decoder) { |
106 return NULL; | 110 return NULL; |
107 } | 111 } |
108 | 112 |
109 SkBitmap bm; | 113 SkBitmap bm; |
110 stream.rewind(); | 114 stream.rewind(); |
111 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
codeBounds_Mode)) { | 115 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe
codeBounds_Mode)) { |
112 SkDELETE(decoder); | 116 SkDELETE(decoder); |
113 return NULL; | 117 return NULL; |
114 } | 118 } |
115 | 119 |
116 return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); | 120 return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data)); |
117 } | 121 } |
OLD | NEW |