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 #ifndef SkImageGenerator_DEFINED | 8 #ifndef SkImageGenerator_DEFINED |
9 #define SkImageGenerator_DEFINED | 9 #define SkImageGenerator_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 class SkData; | 15 class SkData; |
16 class SkImageGenerator; | 16 class SkImageGenerator; |
17 | 17 |
18 //#define SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
19 | |
18 /** | 20 /** |
19 * Takes ownership of SkImageGenerator. If this method fails for | 21 * Takes ownership of SkImageGenerator. If this method fails for |
20 * whatever reason, it will return false and immediatetely delete | 22 * whatever reason, it will return false and immediatetely delete |
21 * the generator. If it succeeds, it will modify destination | 23 * the generator. If it succeeds, it will modify destination |
22 * bitmap. | 24 * bitmap. |
23 * | 25 * |
24 * If generator is NULL, will safely return false. | 26 * If generator is NULL, will safely return false. |
25 * | 27 * |
26 * If this fails or when the SkDiscardablePixelRef that is | 28 * If this fails or when the SkDiscardablePixelRef that is |
27 * installed into destination is destroyed, it will call | 29 * installed into destination is destroyed, it will call |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 * If non-NULL is returned, the caller is responsible for calling | 62 * If non-NULL is returned, the caller is responsible for calling |
61 * unref() on the data when it is finished. | 63 * unref() on the data when it is finished. |
62 */ | 64 */ |
63 SkData* refEncodedData() { return this->onRefEncodedData(); } | 65 SkData* refEncodedData() { return this->onRefEncodedData(); } |
64 | 66 |
65 /** | 67 /** |
66 * Return the ImageInfo associated with this generator. | 68 * Return the ImageInfo associated with this generator. |
67 */ | 69 */ |
68 const SkImageInfo& getInfo() const { return fInfo; } | 70 const SkImageInfo& getInfo() const { return fInfo; } |
69 | 71 |
72 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
70 /** | 73 /** |
71 * Used to describe the result of a call to getPixels(). | 74 * Used to describe the result of a call to getPixels(). |
72 * | 75 * |
73 * Result is the union of possible results from subclasses. | 76 * Result is the union of possible results from subclasses. |
74 */ | 77 */ |
75 enum Result { | 78 enum Result { |
76 /** | 79 /** |
77 * General return value for success. | 80 * General return value for success. |
78 */ | 81 */ |
79 kSuccess, | 82 kSuccess, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 133 |
131 /** | 134 /** |
132 * Additional options to pass to getPixels. | 135 * Additional options to pass to getPixels. |
133 */ | 136 */ |
134 struct Options { | 137 struct Options { |
135 Options() | 138 Options() |
136 : fZeroInitialized(kNo_ZeroInitialized) {} | 139 : fZeroInitialized(kNo_ZeroInitialized) {} |
137 | 140 |
138 ZeroInitialized fZeroInitialized; | 141 ZeroInitialized fZeroInitialized; |
139 }; | 142 }; |
143 #endif | |
140 | 144 |
141 /** | 145 /** |
142 * Decode into the given pixels, a block of memory of size at | 146 * Decode into the given pixels, a block of memory of size at |
143 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 147 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
144 * bytesPerPixel) | 148 * bytesPerPixel) |
145 * | 149 * |
146 * Repeated calls to this function should give the same results, | 150 * Repeated calls to this function should give the same results, |
147 * allowing the PixelRef to be immutable. | 151 * allowing the PixelRef to be immutable. |
148 * | 152 * |
149 * @param info A description of the format (config, size) | 153 * @param info A description of the format (config, size) |
(...skipping 10 matching lines...) Expand all Loading... | |
160 * | 164 * |
161 * If info is kIndex8_SkColorType, then the caller must provide storage for up to 256 | 165 * If info is kIndex8_SkColorType, then the caller must provide storage for up to 256 |
162 * SkPMColor values in ctable. On success the generator must copy N colors into that storage, | 166 * SkPMColor values in ctable. On success the generator must copy N colors into that storage, |
163 * (where N is the logical number of table entries) and set ctableCount to N. | 167 * (where N is the logical number of table entries) and set ctableCount to N. |
164 * | 168 * |
165 * If info is not kIndex8_SkColorType, then the last two parameters may be NULL. If ctableCount | 169 * If info is not kIndex8_SkColorType, then the last two parameters may be NULL. If ctableCount |
166 * is not null, it will be set to 0. | 170 * is not null, it will be set to 0. |
167 * | 171 * |
168 * @return Result kSuccess, or another value explaining the type of failure . | 172 * @return Result kSuccess, or another value explaining the type of failure . |
169 */ | 173 */ |
174 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
170 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con st Options*, | 175 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con st Options*, |
171 SkPMColor ctable[], int* ctableCount); | 176 SkPMColor ctable[], int* ctableCount); |
177 #else | |
178 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | |
reed1
2015/07/09 15:26:45
Can you just expose these variants of getPixels w/
scroggo
2015/07/09 15:51:59
Yes. I'd forgotten that all of the callers of getP
| |
179 SkPMColor ctable[], int* ctableCount); | |
180 #endif | |
172 | 181 |
173 /** | 182 /** |
174 * Simplified version of getPixels() that asserts that info is NOT kIndex8_ SkColorType and | 183 * Simplified version of getPixels() that asserts that info is NOT kIndex8_ SkColorType and |
175 * uses the default Options. | 184 * uses the default Options. |
176 */ | 185 */ |
186 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
177 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 187 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
188 #else | |
189 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | |
190 #endif | |
178 | 191 |
179 /** | 192 /** |
180 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an y entry in rowBytes | 193 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an y entry in rowBytes |
181 * is 0, this imagegenerator should output the sizes and return true if it can efficiently | 194 * is 0, this imagegenerator should output the sizes and return true if it can efficiently |
182 * return YUV planar data. If it cannot, it should return false. Note that either planes and | 195 * return YUV planar data. If it cannot, it should return false. Note that either planes and |
183 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL or have NULL or 0 | 196 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL or have NULL or 0 |
184 * entries only. Having only partial planes/rowBytes information is not sup ported. | 197 * entries only. Having only partial planes/rowBytes information is not sup ported. |
185 * | 198 * |
186 * If all planes and rowBytes entries are non NULL or non 0, then it should copy the | 199 * If all planes and rowBytes entries are non NULL or non 0, then it should copy the |
187 * associated YUV data into those planes of memory supplied by the caller. It should validate | 200 * associated YUV data into those planes of memory supplied by the caller. It should validate |
188 * that the sizes match what it expected. If the sizes do not match, it sho uld return false. | 201 * that the sizes match what it expected. If the sizes do not match, it sho uld return false. |
189 */ | 202 */ |
190 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 203 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
191 SkYUVColorSpace* colorSpace); | 204 SkYUVColorSpace* colorSpace); |
192 | 205 |
193 /** | 206 /** |
194 * If the default image decoder system can interpret the specified (encoded ) data, then | 207 * If the default image decoder system can interpret the specified (encoded ) data, then |
195 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E ither way | 208 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E ither way |
196 * the caller is still responsible for managing their ownership of the data . | 209 * the caller is still responsible for managing their ownership of the data . |
197 */ | 210 */ |
198 static SkImageGenerator* NewFromData(SkData*); | 211 static SkImageGenerator* NewFromData(SkData*); |
199 | 212 |
200 protected: | 213 protected: |
201 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} | 214 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} |
202 | 215 |
203 virtual SkData* onRefEncodedData(); | 216 virtual SkData* onRefEncodedData(); |
204 | 217 |
218 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
205 virtual Result onGetPixels(const SkImageInfo& info, | 219 virtual Result onGetPixels(const SkImageInfo& info, |
206 void* pixels, size_t rowBytes, const Options&, | 220 void* pixels, size_t rowBytes, const Options&, |
207 SkPMColor ctable[], int* ctableCount); | 221 SkPMColor ctable[], int* ctableCount); |
222 #else | |
223 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy tes, | |
224 SkPMColor ctable[], int* ctableCount); | |
225 #endif | |
208 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]); | 226 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]); |
209 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], | 227 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], |
210 SkYUVColorSpace* colorSpace); | 228 SkYUVColorSpace* colorSpace); |
211 | 229 |
212 private: | 230 private: |
213 const SkImageInfo fInfo; | 231 const SkImageInfo fInfo; |
214 }; | 232 }; |
215 | 233 |
216 #endif // SkImageGenerator_DEFINED | 234 #endif // SkImageGenerator_DEFINED |
OLD | NEW |