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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 */ | 270 */ |
271 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con st Options*, | 271 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con st Options*, |
272 SkPMColor ctable[], int* ctableCount); | 272 SkPMColor ctable[], int* ctableCount); |
273 | 273 |
274 /** | 274 /** |
275 * Simplified version of getPixels() that asserts that info is NOT kIndex8_ SkColorType and | 275 * Simplified version of getPixels() that asserts that info is NOT kIndex8_ SkColorType and |
276 * uses the default Options. | 276 * uses the default Options. |
277 */ | 277 */ |
278 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 278 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
279 | 279 |
280 struct YUVSizeInfo { | |
reed1
2016/01/22 16:01:46
Just so I understand the difference...
Size means
msarett
2016/01/22 16:14:14
Yes that's correct.
| |
281 SkISize fYSize; | |
282 SkISize fUSize; | |
283 SkISize fVSize; | |
284 | |
285 /** | |
286 * While the widths of the Y, U, and V planes are not restricted, the | |
287 * implementation requires that the width of the memory allocated for | |
288 * each plane be a multiple of DCTSIZE (which is always 8). | |
289 * | |
290 * This struct allows us to inform the client how many "widthBytes" | |
291 * that we need. Note that we use the new idea of "widthBytes" | |
292 * because this idea is distinct from "rowBytes" (used elsewhere in | |
293 * Skia). "rowBytes" allow the last row of the allocation to not | |
294 * include any extra padding, while, in this case, every single row of | |
295 * the allocation must be at least "widthBytes". | |
296 */ | |
297 size_t fYWidthBytes; | |
298 size_t fUWidthBytes; | |
299 size_t fVWidthBytes; | |
300 }; | |
301 | |
302 /** | |
303 * If decoding to YUV is supported, this returns true. Otherwise, this | |
304 * returns false and does not modify any of the parameters. | |
305 * | |
306 * @param sizeInfo Output parameter indicating the sizes and required | |
307 * allocation widths of the Y, U, and V planes. | |
308 * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, | |
309 * otherwise this is ignored. | |
310 */ | |
311 bool queryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { | |
312 if (nullptr == sizeInfo) { | |
reed1
2016/01/22 16:01:46
interesting: why is one parameter optional and the
msarett
2016/01/22 16:14:14
I'm fine with making both optional or both require
msarett
2016/01/22 21:08:45
Any thoughts?
| |
313 return false; | |
314 } | |
315 | |
316 return this->onQueryYUV8(sizeInfo, colorSpace); | |
317 } | |
318 | |
319 /** | |
320 * Returns kSuccess, or another value explaining the type of failure. | |
321 * This always attempts to perform a full decode. If the client only | |
322 * wants size, it should call queryYUV8(). | |
323 * | |
324 * @param sizeInfo Contains sizes of each of the Y, U, and V planes. | |
325 * The size of the Y plane will be the same size as the | |
326 * image. The size of the U and V planes may be the | |
327 * same size as the image, or they may be a fraction of | |
328 * the size of the image (due to sampling). It is | |
329 * quite common for the width to be sampled at a | |
330 * different rate than the height. 2 and 4 are common | |
331 * sampling rates. The U and V planes are often the | |
332 * same size. | |
333 * Also contains, the width in bytes of each row of the | |
334 * Y, U, and V planes. Each Y, U, or V "sample" is a | |
335 * single byte. Also, the implementation requires that | |
336 * the width of the memory allocated be padded to a | |
reed1
2016/01/22 18:40:16
This comment seems very JPEG specific. Do we need
msarett
2016/01/22 21:08:45
I think the detail is a bit much. Fixed.
So are
| |
337 * multiple of 8. So the widthBytes should at least | |
338 * equal the Y, U, and V widths rounded up to the | |
339 * nearest multiples of 8. | |
340 * @param planes Memory for each of the Y, U, and V planes. | |
341 */ | |
342 Result getYUV8Planes(const YUVSizeInfo& sizeInfo, void* planes[3]) { | |
reed1
2016/01/22 16:01:46
Why do we pass the info back in? Can it (legally)
msarett
2016/01/22 16:14:14
The WidthBytes may be larger than the recommended
| |
343 if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] || | |
344 nullptr == planes[2]) { | |
345 return kInvalidInput; | |
346 } | |
347 | |
348 if (!this->rewindIfNeeded()) { | |
349 return kCouldNotRewind; | |
350 } | |
351 | |
352 return this->onGetYUV8Planes(sizeInfo, planes); | |
353 } | |
354 | |
280 /** | 355 /** |
281 * The remaining functions revolve around decoding scanlines. | 356 * The remaining functions revolve around decoding scanlines. |
282 */ | 357 */ |
283 | 358 |
284 /** | 359 /** |
285 * Prepare for a scanline decode with the specified options. | 360 * Prepare for a scanline decode with the specified options. |
286 * | 361 * |
287 * After this call, this class will be ready to decode the first scanline. | 362 * After this call, this class will be ready to decode the first scanline. |
288 * | 363 * |
289 * This must be called in order to call getScanlines or skipScanlines. | 364 * This must be called in order to call getScanlines or skipScanlines. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 * is located in the encoded data. | 510 * is located in the encoded data. |
436 * | 511 * |
437 * This will equal inputScanline, except in the case of strangely | 512 * This will equal inputScanline, except in the case of strangely |
438 * encoded image types (bottom-up bmps, interlaced gifs). | 513 * encoded image types (bottom-up bmps, interlaced gifs). |
439 */ | 514 */ |
440 int outputScanline(int inputScanline) const; | 515 int outputScanline(int inputScanline) const; |
441 | 516 |
442 protected: | 517 protected: |
443 SkCodec(const SkImageInfo&, SkStream*); | 518 SkCodec(const SkImageInfo&, SkStream*); |
444 | 519 |
445 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 520 virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { |
446 // By default, scaling is not supported. | 521 // By default, scaling is not supported. |
447 return this->getInfo().dimensions(); | 522 return this->getInfo().dimensions(); |
448 } | 523 } |
449 | 524 |
450 // FIXME: What to do about subsets?? | 525 // FIXME: What to do about subsets?? |
451 /** | 526 /** |
452 * Subclasses should override if they support dimensions other than the | 527 * Subclasses should override if they support dimensions other than the |
453 * srcInfo's. | 528 * srcInfo's. |
454 */ | 529 */ |
455 virtual bool onDimensionsSupported(const SkISize&) { | 530 virtual bool onDimensionsSupported(const SkISize&) { |
456 return false; | 531 return false; |
457 } | 532 } |
458 | 533 |
459 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 534 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
460 | 535 |
461 /** | 536 /** |
462 * @param rowsDecoded When the encoded image stream is incomplete, this func tion | 537 * @param rowsDecoded When the encoded image stream is incomplete, this func tion |
463 * will return kIncompleteInput and rowsDecoded will be s et to | 538 * will return kIncompleteInput and rowsDecoded will be s et to |
464 * the number of scanlines that were successfully decoded . | 539 * the number of scanlines that were successfully decoded . |
465 * This will allow getPixels() to fill the uninitialized memory. | 540 * This will allow getPixels() to fill the uninitialized memory. |
466 */ | 541 */ |
467 virtual Result onGetPixels(const SkImageInfo& info, | 542 virtual Result onGetPixels(const SkImageInfo& info, |
468 void* pixels, size_t rowBytes, const Options&, | 543 void* pixels, size_t rowBytes, const Options&, |
469 SkPMColor ctable[], int* ctableCount, | 544 SkPMColor ctable[], int* ctableCount, |
470 int* rowsDecoded) = 0; | 545 int* rowsDecoded) = 0; |
471 | 546 |
472 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 547 virtual bool onQueryYUV8(YUVSizeInfo*, SkYUVColorSpace*) const { |
548 return false; | |
549 } | |
550 | |
551 virtual Result onGetYUV8Planes(const YUVSizeInfo&, void*[3] /*planes*/) { | |
552 return kUnimplemented; | |
553 } | |
554 | |
555 virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const { | |
473 // By default, subsets are not supported. | 556 // By default, subsets are not supported. |
474 return false; | 557 return false; |
475 } | 558 } |
476 | 559 |
477 /** | 560 /** |
478 * If the stream was previously read, attempt to rewind. | 561 * If the stream was previously read, attempt to rewind. |
479 * | 562 * |
480 * If the stream needed to be rewound, call onRewind. | 563 * If the stream needed to be rewound, call onRewind. |
481 * @returns true if the codec is at the right position and can be used. | 564 * @returns true if the codec is at the right position and can be used. |
482 * false if there was a failure to rewind. | 565 * false if there was a failure to rewind. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 * not affect ownership. | 710 * not affect ownership. |
628 * | 711 * |
629 * Only valid during scanline decoding. | 712 * Only valid during scanline decoding. |
630 */ | 713 */ |
631 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } | 714 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } |
632 | 715 |
633 friend class SkSampledCodec; | 716 friend class SkSampledCodec; |
634 friend class SkIcoCodec; | 717 friend class SkIcoCodec; |
635 }; | 718 }; |
636 #endif // SkCodec_DEFINED | 719 #endif // SkCodec_DEFINED |
OLD | NEW |