OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 SkCodec_DEFINED | 8 #ifndef SkCodec_DEFINED |
9 #define SkCodec_DEFINED | 9 #define SkCodec_DEFINED |
10 | 10 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, | 165 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, |
166 SkPMColor ctable[], int* ctableCount); | 166 SkPMColor ctable[], int* ctableCount); |
167 | 167 |
168 /** | 168 /** |
169 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and | 169 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and |
170 * uses the default Options. | 170 * uses the default Options. |
171 */ | 171 */ |
172 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 172 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
173 | 173 |
174 /** | 174 /** |
175 * Return an object which can be used to decode individual scanlines. | 175 * Create a new object which can be used to decode individual scanlines. |
176 * | 176 * |
177 * This object is owned by the SkCodec, which will handle its lifetime. The | 177 * The returned object has its own state, independent of the SkCodec, or an
y |
178 * returned object is only valid until the SkCodec is deleted or the next | 178 * previously spawned SkScanlineDecoders. At creation, it will be ready to |
179 * call to getScanlineDecoder, whichever comes first. | 179 * return the first scanline. |
180 * | |
181 * Calling a second time will rewind and replace the existing one with a | |
182 * new one. If the stream cannot be rewound, this will delete the existing | |
183 * one and return NULL. | |
184 * | 180 * |
185 * @param dstInfo Info of the destination. If the dimensions do not match | 181 * @param dstInfo Info of the destination. If the dimensions do not match |
186 * those of getInfo, this implies a scale. | 182 * those of getInfo, this implies a scale. |
187 * @param options Contains decoding options, including if memory is zero | 183 * @param options Contains decoding options, including if memory is zero |
188 * initialized. | 184 * initialized. |
189 * @param ctable A pointer to a color table. When dstInfo.colorType() is | 185 * @param ctable A pointer to a color table. When dstInfo.colorType() is |
190 * kIndex8, this should be non-NULL and have enough storage for 256 | 186 * kIndex8, this should be non-NULL and have enough storage for 256 |
191 * colors. The color table will be populated after decoding the palett
e. | 187 * colors. The color table will be populated after decoding the palett
e. |
192 * @param ctableCount A pointer to the size of the color table. When | 188 * @param ctableCount A pointer to the size of the color table. When |
193 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will | 189 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will |
194 * be modified to the true size of the color table (<= 256) after | 190 * be modified to the true size of the color table (<= 256) after |
195 * decoding the palette. | 191 * decoding the palette. |
196 * @return New SkScanlineDecoder, or NULL on failure. | 192 * @return New SkScanlineDecoder, or NULL on failure. |
197 * | 193 * |
198 * NOTE: If any rows were previously decoded, this requires rewinding the | 194 * NOTE: This requires duplicating the SkStream. |
199 * SkStream. | |
200 * | |
201 * NOTE: The scanline decoder is owned by the SkCodec and will delete it | |
202 * when the SkCodec is deleted. | |
203 */ | 195 */ |
204 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo, const Opti
ons* options, | 196 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo, const Opti
ons* options, |
205 SkPMColor ctable[], int* ctableCount); | 197 SkPMColor ctable[], int* ctableCount); |
206 | 198 |
207 /** | 199 /** |
208 * Simplified version of getScanlineDecoder() that asserts that info is NOT | 200 * Simplified version of getScanlineDecoder() that asserts that info is NOT |
209 * kIndex8_SkColorType and uses the default Options. | 201 * kIndex8_SkColorType and uses the default Options. |
210 */ | 202 */ |
211 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo); | 203 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo); |
212 | 204 |
(...skipping 19 matching lines...) Expand all Loading... |
232 | 224 |
233 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 225 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
234 | 226 |
235 virtual Result onGetPixels(const SkImageInfo& info, | 227 virtual Result onGetPixels(const SkImageInfo& info, |
236 void* pixels, size_t rowBytes, const Options&, | 228 void* pixels, size_t rowBytes, const Options&, |
237 SkPMColor ctable[], int* ctableCount) = 0; | 229 SkPMColor ctable[], int* ctableCount) = 0; |
238 | 230 |
239 /** | 231 /** |
240 * Override if your codec supports scanline decoding. | 232 * Override if your codec supports scanline decoding. |
241 * | 233 * |
242 * As in onGetPixels(), the implementation must call rewindIfNeeded() and | |
243 * handle as appropriate. | |
244 * | |
245 * @param dstInfo Info of the destination. If the dimensions do not match | 234 * @param dstInfo Info of the destination. If the dimensions do not match |
246 * those of getInfo, this implies a scale. | 235 * those of getInfo, this implies a scale. |
247 * @param options Contains decoding options, including if memory is zero | 236 * @param options Contains decoding options, including if memory is zero |
248 * initialized. | 237 * initialized. |
249 * @param ctable A pointer to a color table. When dstInfo.colorType() is | 238 * @param ctable A pointer to a color table. When dstInfo.colorType() is |
250 * kIndex8, this should be non-NULL and have enough storage for 256 | 239 * kIndex8, this should be non-NULL and have enough storage for 256 |
251 * colors. The color table will be populated after decoding the palett
e. | 240 * colors. The color table will be populated after decoding the palett
e. |
252 * @param ctableCount A pointer to the size of the color table. When | 241 * @param ctableCount A pointer to the size of the color table. When |
253 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will | 242 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will |
254 * be modified to the true size of the color table (<= 256) after | 243 * be modified to the true size of the color table (<= 256) after |
255 * decoding the palette. | 244 * decoding the palette. |
256 * @return New SkScanlineDecoder on success, NULL otherwise. The SkCodec | 245 * @return New SkScanlineDecoder on success, NULL otherwise. The caller is |
257 * will take ownership of the returned scanline decoder. | 246 * responsible for deleting the returned object. |
258 */ | 247 */ |
259 virtual SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, | 248 virtual SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, |
260 const Options& options, | 249 const Options& options, |
261 SkPMColor ctable[], | 250 SkPMColor ctable[], |
262 int* ctableCount) { | 251 int* ctableCount) { |
263 return NULL; | 252 return NULL; |
264 } | 253 } |
265 | 254 |
266 virtual bool onReallyHasAlpha() const { return false; } | 255 virtual bool onReallyHasAlpha() const { return false; } |
267 | 256 |
(...skipping 18 matching lines...) Expand all Loading... |
286 */ | 275 */ |
287 RewindState SK_WARN_UNUSED_RESULT rewindIfNeeded(); | 276 RewindState SK_WARN_UNUSED_RESULT rewindIfNeeded(); |
288 | 277 |
289 /** | 278 /** |
290 * Get method for the input stream | 279 * Get method for the input stream |
291 */ | 280 */ |
292 SkStream* stream() { | 281 SkStream* stream() { |
293 return fStream.get(); | 282 return fStream.get(); |
294 } | 283 } |
295 | 284 |
296 /** | |
297 * If the codec has a scanline decoder, return it (no ownership change occur
s) | |
298 * else return NULL. | |
299 * The returned decoder is valid while the codec exists and the client has n
ot | |
300 * created a new scanline decoder. | |
301 */ | |
302 SkScanlineDecoder* scanlineDecoder() { | |
303 return fScanlineDecoder; | |
304 } | |
305 | |
306 /** | |
307 * Allow the codec subclass to detach and take ownership of the scanline dec
oder. | |
308 * This will likely be used when the scanline decoder needs to be destroyed | |
309 * in the destructor of the subclass. | |
310 */ | |
311 SkScanlineDecoder* detachScanlineDecoder() { | |
312 SkScanlineDecoder* scanlineDecoder = fScanlineDecoder; | |
313 fScanlineDecoder = NULL; | |
314 return scanlineDecoder; | |
315 } | |
316 | |
317 private: | 285 private: |
318 const SkImageInfo fInfo; | 286 const SkImageInfo fInfo; |
319 SkAutoTDelete<SkStream> fStream; | 287 SkAutoTDelete<SkStream> fStream; |
320 bool fNeedsRewind; | 288 bool fNeedsRewind; |
321 SkScanlineDecoder* fScanlineDecoder; | |
322 }; | 289 }; |
323 #endif // SkCodec_DEFINED | 290 #endif // SkCodec_DEFINED |
OLD | NEW |