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 |
11 #include <functional> | |
12 | |
11 #include "../private/SkTemplates.h" | 13 #include "../private/SkTemplates.h" |
12 #include "SkColor.h" | 14 #include "SkColor.h" |
13 #include "SkEncodedFormat.h" | 15 #include "SkEncodedFormat.h" |
14 #include "SkEncodedInfo.h" | 16 #include "SkEncodedInfo.h" |
15 #include "SkImageInfo.h" | 17 #include "SkImageInfo.h" |
16 #include "SkSize.h" | 18 #include "SkSize.h" |
17 #include "SkStream.h" | 19 #include "SkStream.h" |
18 #include "SkTypes.h" | 20 #include "SkTypes.h" |
19 #include "SkYUVSizeInfo.h" | 21 #include "SkYUVSizeInfo.h" |
20 | 22 |
21 class SkColorSpace; | 23 class SkColorSpace; |
22 class SkData; | 24 class SkData; |
23 class SkPngChunkReader; | 25 class SkPngChunkReader; |
24 class SkSampler; | 26 class SkSampler; |
25 | 27 |
28 namespace DM { | |
29 class CodecSrc; | |
30 } | |
31 | |
26 /** | 32 /** |
27 * Abstraction layer directly on top of an image codec. | 33 * Abstraction layer directly on top of an image codec. |
28 */ | 34 */ |
29 class SkCodec : SkNoncopyable { | 35 class SkCodec : SkNoncopyable { |
30 public: | 36 public: |
31 /** | 37 /** |
32 * Minimum number of bytes that must be buffered in SkStream input. | 38 * Minimum number of bytes that must be buffered in SkStream input. |
33 * | 39 * |
34 * An SkStream passed to NewFromStream must be able to use this many | 40 * An SkStream passed to NewFromStream must be able to use this many |
35 * bytes to determine the image type. Then the same SkStream must be | 41 * bytes to determine the image type. Then the same SkStream must be |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 return kCouldNotRewind; | 351 return kCouldNotRewind; |
346 } | 352 } |
347 | 353 |
348 return this->onGetYUV8Planes(sizeInfo, planes); | 354 return this->onGetYUV8Planes(sizeInfo, planes); |
349 } | 355 } |
350 | 356 |
351 /** | 357 /** |
352 * The remaining functions revolve around decoding scanlines. | 358 * The remaining functions revolve around decoding scanlines. |
353 */ | 359 */ |
354 | 360 |
361 | |
362 /** | |
363 * Prepare for an incremental decode with the specified options. | |
364 * | |
365 * This may require a rewind. | |
366 * | |
367 * @param dstInfo Info of the destination. If the dimensions do not match | |
368 * those of getInfo, this implies a scale. | |
369 * @param options Contains decoding options, including if memory is zero | |
370 * initialized. | |
371 * The callback will only be called for rows in the subset specified | |
372 * by fSubset. | |
373 * @param ctable A pointer to a color table. When dstInfo.colorType() is | |
374 * kIndex8, this should be non-NULL and have enough storage for 256 | |
375 * colors. The color table will be populated after decoding the palett e. | |
376 * @param ctableCount A pointer to the size of the color table. When | |
377 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will | |
378 * be modified to the true size of the color table (<= 256) after | |
379 * decoding the palette. | |
380 * @return Enum representing success or reason for failure. | |
381 */ | |
382 Result startIncrementalDecode(const SkImageInfo& dstInfo, const SkCodec::Opt ions* = nullptr, | |
383 SkPMColor* ctable = nullptr, int* ctableCount = nullptr); | |
384 | |
385 /** | |
386 * Start/continue the incremental decode. | |
387 * | |
388 * Not valid to call before calling startIncrementalDecode(). | |
389 * | |
390 * After the first call, should only be called again if more data has been | |
391 * provided to the source SkStream. | |
392 * | |
393 * Unlike getPixels and getScanlines, this does not do any filling. This is | |
394 * left up to the caller, since they may be skipping lines or continuing th e | |
395 * decode later. In the latter case, they may choose to initialize all line s | |
396 * first, or only initialize the remaining lines after the first call. | |
397 * | |
398 * @param callback This will be called each time a row has been decoded. | |
399 * The int parameter will be the number of the row (in the Options.fSub set's | |
400 * [fTop, fBottom), provided in startIncrementalDecode). | |
401 * The callback should return either a block of memory to write the row or | |
402 * null to skip writing this row. | |
403 * On consecutive calls, this should always write to the same memory. | |
404 * @param rowsDecoded Optional output variable returning the total number o f | |
405 * lines decoded. This includes all lines decoded from the image, wheth er | |
msarett
2016/05/20 15:04:40
nit: "whether" -> "whether or not" ?
scroggo_chromium
2016/05/20 16:51:59
Done.
| |
406 * the client (via the callback) included it in the output, since the | |
407 * last call to startIncrementalDecode. | |
408 * @return kSuccess if all lines requested in startIncrementalDecode have | |
409 * been completely decoded. kIncompleteInput otherwise. | |
410 */ | |
411 Result incrementalDecode(std::function<void*(int)> callback, | |
412 int* rowsDecoded = nullptr) { | |
413 if (!fStartedIncrementalDecode) { | |
414 return kInvalidParameters; | |
415 } | |
416 return this->onIncrementalDecode(callback, rowsDecoded); | |
417 } | |
418 | |
355 /** | 419 /** |
356 * Prepare for a scanline decode with the specified options. | 420 * Prepare for a scanline decode with the specified options. |
357 * | 421 * |
358 * After this call, this class will be ready to decode the first scanline. | 422 * After this call, this class will be ready to decode the first scanline. |
359 * | 423 * |
360 * This must be called in order to call getScanlines or skipScanlines. | 424 * This must be called in order to call getScanlines or skipScanlines. |
361 * | 425 * |
362 * This may require rewinding the stream. | 426 * This may require rewinding the stream. |
363 * | 427 * |
364 * Not all SkCodecs support this. | 428 * Not all SkCodecs support this. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 * they will not be in logical order. If the scanline format is | 525 * they will not be in logical order. If the scanline format is |
462 * kOutOfOrder, the nextScanline() API should be used to determine the | 526 * kOutOfOrder, the nextScanline() API should be used to determine the |
463 * actual y-coordinate of the next output row. | 527 * actual y-coordinate of the next output row. |
464 * | 528 * |
465 * For this scanline ordering, it is advisable to get and skip | 529 * For this scanline ordering, it is advisable to get and skip |
466 * scanlines one at a time. | 530 * scanlines one at a time. |
467 * | 531 * |
468 * Interlaced gifs are an example. | 532 * Interlaced gifs are an example. |
469 */ | 533 */ |
470 kOutOfOrder_SkScanlineOrder, | 534 kOutOfOrder_SkScanlineOrder, |
471 | |
472 /* | |
473 * Indicates that the entire image must be decoded in order to output | |
474 * any amount of scanlines. In this case, it is a REALLY BAD IDEA to | |
475 * request scanlines 1-by-1 or in small chunks. The client should | |
476 * determine which scanlines are needed and ask for all of them in | |
477 * a single call to getScanlines(). | |
478 * | |
479 * Interlaced pngs are an example. | |
480 */ | |
481 kNone_SkScanlineOrder, | |
482 }; | 535 }; |
483 | 536 |
484 /** | 537 /** |
485 * An enum representing the order in which scanlines will be returned by | 538 * An enum representing the order in which scanlines will be returned by |
486 * the scanline decoder. | 539 * the scanline decoder. |
487 * | 540 * |
488 * This is undefined before startScanlineDecode() is called. | 541 * This is undefined before startScanlineDecode() is called. |
489 */ | 542 */ |
490 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } | 543 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } |
491 | 544 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 const SkImageInfo fSrcInfo; | 704 const SkImageInfo fSrcInfo; |
652 SkAutoTDelete<SkStream> fStream; | 705 SkAutoTDelete<SkStream> fStream; |
653 bool fNeedsRewind; | 706 bool fNeedsRewind; |
654 sk_sp<SkColorSpace> fColorSpace; | 707 sk_sp<SkColorSpace> fColorSpace; |
655 const Origin fOrigin; | 708 const Origin fOrigin; |
656 | 709 |
657 // These fields are only meaningful during scanline decodes. | 710 // These fields are only meaningful during scanline decodes. |
658 SkImageInfo fDstInfo; | 711 SkImageInfo fDstInfo; |
659 SkCodec::Options fOptions; | 712 SkCodec::Options fOptions; |
660 int fCurrScanline; | 713 int fCurrScanline; |
714 bool fStartedIncrementalDecode; | |
661 | 715 |
662 /** | 716 /** |
663 * Return whether these dimensions are supported as a scale. | 717 * Return whether these dimensions are supported as a scale. |
664 * | 718 * |
665 * The codec may choose to cache the information about scale and subset. | 719 * The codec may choose to cache the information about scale and subset. |
666 * Either way, the same information will be passed to onGetPixels/onStart | 720 * Either way, the same information will be passed to onGetPixels/onStart |
667 * on success. | 721 * on success. |
668 * | 722 * |
669 * This must return true for a size returned from getScaledDimensions. | 723 * This must return true for a size returned from getScaledDimensions. |
670 */ | 724 */ |
671 bool dimensionsSupported(const SkISize& dim) { | 725 bool dimensionsSupported(const SkISize& dim) { |
672 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); | 726 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); |
673 } | 727 } |
674 | 728 |
675 // Methods for scanline decoding. | 729 // Methods for scanline decoding. |
676 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/ , | 730 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/ , |
677 const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*c tableCount*/) { | 731 const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*c tableCount*/) { |
678 return kUnimplemented; | 732 return kUnimplemented; |
679 } | 733 } |
680 | 734 |
735 virtual Result onStartIncrementalDecode(const SkImageInfo& /*dstInfo*/, | |
736 const SkCodec::Options&, SkPMColor*, int*) { | |
737 return kUnimplemented; | |
738 } | |
739 | |
740 virtual Result onIncrementalDecode(std::function<void*(int)>, int*) { | |
741 return kUnimplemented; | |
742 } | |
743 | |
744 | |
681 virtual bool onSkipScanlines(int /*countLines*/) { return false; } | 745 virtual bool onSkipScanlines(int /*countLines*/) { return false; } |
682 | 746 |
683 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBy tes*/) { return 0; } | 747 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBy tes*/) { return 0; } |
684 | 748 |
685 /** | 749 /** |
686 * On an incomplete decode, getPixels() and getScanlines() will call this fu nction | 750 * On an incomplete decode, getPixels() and getScanlines() will call this fu nction |
687 * to fill any uinitialized memory. | 751 * to fill any uinitialized memory. |
688 * | 752 * |
689 * @param dstInfo Contains the destination color type | 753 * @param dstInfo Contains the destination color type |
690 * Contains the destination alpha type | 754 * Contains the destination alpha type |
(...skipping 11 matching lines...) Expand all Loading... | |
702 /** | 766 /** |
703 * Return an object which will allow forcing scanline decodes to sample in X. | 767 * Return an object which will allow forcing scanline decodes to sample in X. |
704 * | 768 * |
705 * May create a sampler, if one is not currently being used. Otherwise, doe s | 769 * May create a sampler, if one is not currently being used. Otherwise, doe s |
706 * not affect ownership. | 770 * not affect ownership. |
707 * | 771 * |
708 * Only valid during scanline decoding. | 772 * Only valid during scanline decoding. |
709 */ | 773 */ |
710 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } | 774 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } |
711 | 775 |
776 friend class DM::CodecSrc; // for fillIncompleteImage | |
msarett
2016/05/20 15:04:40
Is this what our clients will do? If not, can we
msarett
2016/05/20 15:06:59
Might be changing my mind on this again. If we ar
scroggo_chromium
2016/05/20 16:51:59
If Chrome continues to behave the way it currently
msarett
2016/05/20 18:21:37
sgtm
| |
712 friend class SkSampledCodec; | 777 friend class SkSampledCodec; |
713 friend class SkIcoCodec; | 778 friend class SkIcoCodec; |
714 }; | 779 }; |
715 #endif // SkCodec_DEFINED | 780 #endif // SkCodec_DEFINED |
OLD | NEW |