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_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS |
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 * supported for this input. | 112 * supported for this input. |
111 */ | 113 */ |
112 kCouldNotRewind, | 114 kCouldNotRewind, |
113 /** | 115 /** |
114 * This method is not implemented by this generator. | 116 * This method is not implemented by this generator. |
115 */ | 117 */ |
116 kUnimplemented, | 118 kUnimplemented, |
117 }; | 119 }; |
118 | 120 |
119 /** | 121 /** |
| 122 * Whether or not the memory passed to getPixels is zero initialized. |
| 123 */ |
| 124 enum ZeroInitialized { |
| 125 /** |
| 126 * The memory passed to getPixels is zero initialized. The SkCodec |
| 127 * may take advantage of this by skipping writing zeroes. |
| 128 */ |
| 129 kYes_ZeroInitialized, |
| 130 /** |
| 131 * The memory passed to getPixels has not been initialized to zero, |
| 132 * so the SkCodec must write all zeroes to memory. |
| 133 * |
| 134 * This is the default. It will be used if no Options struct is used. |
| 135 */ |
| 136 kNo_ZeroInitialized, |
| 137 }; |
| 138 |
| 139 /** |
| 140 * Additional options to pass to getPixels. |
| 141 */ |
| 142 struct Options { |
| 143 Options() |
| 144 : fZeroInitialized(kNo_ZeroInitialized) {} |
| 145 |
| 146 ZeroInitialized fZeroInitialized; |
| 147 }; |
| 148 |
| 149 /** |
120 * Decode into the given pixels, a block of memory of size at | 150 * Decode into the given pixels, a block of memory of size at |
121 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 151 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
122 * bytesPerPixel) | 152 * bytesPerPixel) |
123 * | 153 * |
124 * Repeated calls to this function should give the same results, | 154 * Repeated calls to this function should give the same results, |
125 * allowing the PixelRef to be immutable. | 155 * allowing the PixelRef to be immutable. |
126 * | 156 * |
127 * @param info A description of the format (config, size) | 157 * @param info A description of the format (config, size) |
128 * expected by the caller. This can simply be identical | 158 * expected by the caller. This can simply be identical |
129 * to the info returned by getInfo(). | 159 * to the info returned by getInfo(). |
130 * | 160 * |
131 * This contract also allows the caller to specify | 161 * This contract also allows the caller to specify |
132 * different output-configs, which the implementation can | 162 * different output-configs, which the implementation can |
133 * decide to support or not. | 163 * decide to support or not. |
134 * | 164 * |
135 * A size that does not match getInfo() implies a request | 165 * A size that does not match getInfo() implies a request |
136 * to scale. If the generator cannot perform this scale, | 166 * to scale. If the generator cannot perform this scale, |
137 * it will return kInvalidScale. | 167 * it will return kInvalidScale. |
138 * | 168 * |
139 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 | 169 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 |
140 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, | 170 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, |
141 * (where N is the logical number of table entries) and set ctableCount to
N. | 171 * (where N is the logical number of table entries) and set ctableCount to
N. |
142 * | 172 * |
143 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount | 173 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount |
144 * is not null, it will be set to 0. | 174 * is not null, it will be set to 0. |
145 * | 175 * |
146 * @return Result kSuccess, or another value explaining the type of failure
. | 176 * @return Result kSuccess, or another value explaining the type of failure
. |
147 */ | 177 */ |
148 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 178 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, |
149 SkPMColor ctable[], int* ctableCount); | 179 SkPMColor ctable[], int* ctableCount); |
150 | 180 |
151 /** | 181 /** |
152 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType. | 182 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and |
| 183 * uses the default Options. |
153 */ | 184 */ |
154 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 185 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
155 | 186 |
156 /** | 187 /** |
157 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an
y entry in rowBytes | 188 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an
y entry in rowBytes |
158 * is 0, this imagegenerator should output the sizes and return true if it
can efficiently | 189 * is 0, this imagegenerator should output the sizes and return true if it
can efficiently |
159 * return YUV planar data. If it cannot, it should return false. Note that
either planes and | 190 * return YUV planar data. If it cannot, it should return false. Note that
either planes and |
160 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL
or have NULL or 0 | 191 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL
or have NULL or 0 |
161 * entries only. Having only partial planes/rowBytes information is not sup
ported. | 192 * entries only. Having only partial planes/rowBytes information is not sup
ported. |
162 * | 193 * |
163 * If all planes and rowBytes entries are non NULL or non 0, then it should
copy the | 194 * If all planes and rowBytes entries are non NULL or non 0, then it should
copy the |
164 * associated YUV data into those planes of memory supplied by the caller.
It should validate | 195 * associated YUV data into those planes of memory supplied by the caller.
It should validate |
165 * that the sizes match what it expected. If the sizes do not match, it sho
uld return false. | 196 * that the sizes match what it expected. If the sizes do not match, it sho
uld return false. |
166 */ | 197 */ |
167 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 198 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
168 SkYUVColorSpace* colorSpace); | 199 SkYUVColorSpace* colorSpace); |
169 | 200 |
170 /** | 201 /** |
171 * If the default image decoder system can interpret the specified (encoded
) data, then | 202 * If the default image decoder system can interpret the specified (encoded
) data, then |
172 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way | 203 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way |
173 * the caller is still responsible for managing their ownership of the data
. | 204 * the caller is still responsible for managing their ownership of the data
. |
174 */ | 205 */ |
175 static SkImageGenerator* NewFromData(SkData*); | 206 static SkImageGenerator* NewFromData(SkData*); |
176 | 207 |
177 protected: | 208 protected: |
178 virtual SkData* onRefEncodedData(); | 209 virtual SkData* onRefEncodedData(); |
179 virtual bool onGetInfo(SkImageInfo* info); | 210 virtual bool onGetInfo(SkImageInfo* info); |
| 211 #ifdef SK_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS |
180 virtual Result onGetPixels(const SkImageInfo& info, | 212 virtual Result onGetPixels(const SkImageInfo& info, |
181 void* pixels, size_t rowBytes, | 213 void* pixels, size_t rowBytes, |
182 SkPMColor ctable[], int* ctableCount); | 214 SkPMColor ctable[], int* ctableCount); |
| 215 #endif |
| 216 virtual Result onGetPixels(const SkImageInfo& info, |
| 217 void* pixels, size_t rowBytes, const Options&, |
| 218 SkPMColor ctable[], int* ctableCount); |
183 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); | 219 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); |
184 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 220 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
185 SkYUVColorSpace* colorSpace); | 221 SkYUVColorSpace* colorSpace); |
186 }; | 222 }; |
187 | 223 |
188 #endif // SkImageGenerator_DEFINED | 224 #endif // SkImageGenerator_DEFINED |
OLD | NEW |