Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: include/codec/SkCodec.h

Issue 1997703003: Make SkPngCodec decode progressively. (Closed) Base URL: https://skia.googlesource.com/skia.git@foil
Patch Set: Use the correct Options object Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../private/SkTemplates.h" 11 #include "../private/SkTemplates.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkEncodedFormat.h" 13 #include "SkEncodedFormat.h"
14 #include "SkEncodedInfo.h" 14 #include "SkEncodedInfo.h"
15 #include "SkImageInfo.h" 15 #include "SkImageInfo.h"
16 #include "SkSize.h" 16 #include "SkSize.h"
17 #include "SkStream.h" 17 #include "SkStream.h"
18 #include "SkTypes.h" 18 #include "SkTypes.h"
19 #include "SkYUVSizeInfo.h" 19 #include "SkYUVSizeInfo.h"
20 20
21 class SkColorSpace; 21 class SkColorSpace;
22 class SkData; 22 class SkData;
23 class SkPngChunkReader; 23 class SkPngChunkReader;
24 class SkSampler; 24 class SkSampler;
25 25
26 namespace DM {
27 class CodecSrc;
28 }
29
26 /** 30 /**
27 * Abstraction layer directly on top of an image codec. 31 * Abstraction layer directly on top of an image codec.
28 */ 32 */
29 class SkCodec : SkNoncopyable { 33 class SkCodec : SkNoncopyable {
30 public: 34 public:
31 /** 35 /**
32 * Minimum number of bytes that must be buffered in SkStream input. 36 * Minimum number of bytes that must be buffered in SkStream input.
33 * 37 *
34 * An SkStream passed to NewFromStream must be able to use this many 38 * 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 39 * bytes to determine the image type. Then the same SkStream must be
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 , fSubset(NULL) 250 , fSubset(NULL)
247 {} 251 {}
248 252
249 ZeroInitialized fZeroInitialized; 253 ZeroInitialized fZeroInitialized;
250 /** 254 /**
251 * If not NULL, represents a subset of the original image to decode. 255 * If not NULL, represents a subset of the original image to decode.
252 * Must be within the bounds returned by getInfo(). 256 * Must be within the bounds returned by getInfo().
253 * If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which 257 * If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which
254 * currently supports subsets), the top and left values must be even. 258 * currently supports subsets), the top and left values must be even.
255 * 259 *
256 * In getPixels, we will attempt to decode the exact rectangular 260 * In getPixels and incremental decode, we will attempt to decode the
257 * subset specified by fSubset. 261 * exact rectangular subset specified by fSubset.
258 * 262 *
259 * In a scanline decode, it does not make sense to specify a subset 263 * In a scanline decode, it does not make sense to specify a subset
260 * top or subset height, since the client already controls which rows 264 * top or subset height, since the client already controls which rows
261 * to get and which rows to skip. During scanline decodes, we will 265 * to get and which rows to skip. During scanline decodes, we will
262 * require that the subset top be zero and the subset height be equal 266 * require that the subset top be zero and the subset height be equal
263 * to the full height. We will, however, use the values of 267 * to the full height. We will, however, use the values of
264 * subset left and subset width to decode partial scanlines on calls 268 * subset left and subset width to decode partial scanlines on calls
265 * to getScanlines(). 269 * to getScanlines().
266 */ 270 */
267 SkIRect* fSubset; 271 SkIRect* fSubset;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 346 }
343 347
344 if (!this->rewindIfNeeded()) { 348 if (!this->rewindIfNeeded()) {
345 return kCouldNotRewind; 349 return kCouldNotRewind;
346 } 350 }
347 351
348 return this->onGetYUV8Planes(sizeInfo, planes); 352 return this->onGetYUV8Planes(sizeInfo, planes);
349 } 353 }
350 354
351 /** 355 /**
356 * Prepare for an incremental decode with the specified options.
357 *
358 * This may require a rewind.
359 *
360 * @param dstInfo Info of the destination. If the dimensions do not match
361 * those of getInfo, this implies a scale.
362 * @param dst Memory to write to. Needs to be large enough to hold the subs et,
363 * if present, or the full image as described in dstInfo.
364 * @param options Contains decoding options, including if memory is zero
365 * initialized and whether to decode a subset.
366 * @param ctable A pointer to a color table. When dstInfo.colorType() is
367 * kIndex8, this should be non-NULL and have enough storage for 256
368 * colors. The color table will be populated after decoding the palett e.
369 * @param ctableCount A pointer to the size of the color table. When
370 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will
371 * be modified to the true size of the color table (<= 256) after
372 * decoding the palette.
373 * @return Enum representing success or reason for failure.
374 */
375 Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
376 const SkCodec::Options*, SkPMColor* ctable, int* ctableCount);
377
378 Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
379 const SkCodec::Options* options) {
380 return this->startIncrementalDecode(dstInfo, dst, rowBytes, options, nul lptr, nullptr);
381 }
382
383 Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes) {
384 return this->startIncrementalDecode(dstInfo, dst, rowBytes, nullptr, nul lptr, nullptr);
385 }
386
387 /**
388 * Start/continue the incremental decode.
389 *
390 * Not valid to call before calling startIncrementalDecode().
391 *
392 * After the first call, should only be called again if more data has been
393 * provided to the source SkStream.
394 *
395 * Unlike getPixels and getScanlines, this does not do any filling. This is
396 * left up to the caller, since they may be skipping lines or continuing th e
397 * decode later. In the latter case, they may choose to initialize all line s
398 * first, or only initialize the remaining lines after the first call.
399 *
400 * @param rowsDecoded Optional output variable returning the total number o f
401 * lines initialized. Only meaningful if this method returns kIncomplet eInput.
402 * Otherwise the implementation may not set it.
403 * Note that some implementations may have initialized this many rows, but
404 * not necessarily finished those rows (e.g. interlaced PNG). This may be
405 * useful for determining what rows the client needs to initialize.
406 * @return kSuccess if all lines requested in startIncrementalDecode have
407 * been completely decoded. kIncompleteInput otherwise.
408 */
409 Result incrementalDecode(int* rowsDecoded = nullptr) {
410 if (!fStartedIncrementalDecode) {
411 return kInvalidParameters;
412 }
413 return this->onIncrementalDecode(rowsDecoded);
414 }
415
416 /**
352 * The remaining functions revolve around decoding scanlines. 417 * The remaining functions revolve around decoding scanlines.
353 */ 418 */
354 419
355 /** 420 /**
356 * Prepare for a scanline decode with the specified options. 421 * Prepare for a scanline decode with the specified options.
357 * 422 *
358 * After this call, this class will be ready to decode the first scanline. 423 * After this call, this class will be ready to decode the first scanline.
359 * 424 *
360 * This must be called in order to call getScanlines or skipScanlines. 425 * This must be called in order to call getScanlines or skipScanlines.
361 * 426 *
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 * they will not be in logical order. If the scanline format is 526 * they will not be in logical order. If the scanline format is
462 * kOutOfOrder, the nextScanline() API should be used to determine the 527 * kOutOfOrder, the nextScanline() API should be used to determine the
463 * actual y-coordinate of the next output row. 528 * actual y-coordinate of the next output row.
464 * 529 *
465 * For this scanline ordering, it is advisable to get and skip 530 * For this scanline ordering, it is advisable to get and skip
466 * scanlines one at a time. 531 * scanlines one at a time.
467 * 532 *
468 * Interlaced gifs are an example. 533 * Interlaced gifs are an example.
469 */ 534 */
470 kOutOfOrder_SkScanlineOrder, 535 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 }; 536 };
483 537
484 /** 538 /**
485 * An enum representing the order in which scanlines will be returned by 539 * An enum representing the order in which scanlines will be returned by
486 * the scanline decoder. 540 * the scanline decoder.
487 * 541 *
488 * This is undefined before startScanlineDecode() is called. 542 * This is undefined before startScanlineDecode() is called.
489 */ 543 */
490 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } 544 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; }
491 545
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 674
621 /** 675 /**
622 * The remaining functions revolve around decoding scanlines. 676 * The remaining functions revolve around decoding scanlines.
623 */ 677 */
624 678
625 /** 679 /**
626 * Most images types will be kTopDown and will not need to override this fu nction. 680 * Most images types will be kTopDown and will not need to override this fu nction.
627 */ 681 */
628 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; } 682 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; }
629 683
630 /**
631 * Update the current scanline. Used by interlaced png.
632 */
633 void updateCurrScanline(int newY) { fCurrScanline = newY; }
634
635 const SkImageInfo& dstInfo() const { return fDstInfo; } 684 const SkImageInfo& dstInfo() const { return fDstInfo; }
636 685
637 const SkCodec::Options& options() const { return fOptions; } 686 const SkCodec::Options& options() const { return fOptions; }
638 687
639 /** 688 /**
640 * Returns the number of scanlines that have been decoded so far. 689 * Returns the number of scanlines that have been decoded so far.
641 * This is unaffected by the SkScanlineOrder. 690 * This is unaffected by the SkScanlineOrder.
642 * 691 *
643 * Returns -1 if we have not started a scanline decode. 692 * Returns -1 if we have not started a scanline decode.
644 */ 693 */
645 int currScanline() const { return fCurrScanline; } 694 int currScanline() const { return fCurrScanline; }
646 695
647 virtual int onOutputScanline(int inputScanline) const; 696 virtual int onOutputScanline(int inputScanline) const;
648 697
649 private: 698 private:
650 const SkEncodedInfo fEncodedInfo; 699 const SkEncodedInfo fEncodedInfo;
651 const SkImageInfo fSrcInfo; 700 const SkImageInfo fSrcInfo;
652 SkAutoTDelete<SkStream> fStream; 701 SkAutoTDelete<SkStream> fStream;
653 bool fNeedsRewind; 702 bool fNeedsRewind;
654 sk_sp<SkColorSpace> fColorSpace; 703 sk_sp<SkColorSpace> fColorSpace;
655 const Origin fOrigin; 704 const Origin fOrigin;
656 705
657 // These fields are only meaningful during scanline decodes. 706 // These fields are only meaningful during scanline decodes.
658 SkImageInfo fDstInfo; 707 SkImageInfo fDstInfo;
659 SkCodec::Options fOptions; 708 SkCodec::Options fOptions;
660 int fCurrScanline; 709 int fCurrScanline;
710 bool fStartedIncrementalDecode;
661 711
662 /** 712 /**
663 * Return whether these dimensions are supported as a scale. 713 * Return whether these dimensions are supported as a scale.
664 * 714 *
665 * The codec may choose to cache the information about scale and subset. 715 * The codec may choose to cache the information about scale and subset.
666 * Either way, the same information will be passed to onGetPixels/onStart 716 * Either way, the same information will be passed to onGetPixels/onStart
667 * on success. 717 * on success.
668 * 718 *
669 * This must return true for a size returned from getScaledDimensions. 719 * This must return true for a size returned from getScaledDimensions.
670 */ 720 */
671 bool dimensionsSupported(const SkISize& dim) { 721 bool dimensionsSupported(const SkISize& dim) {
672 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); 722 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim);
673 } 723 }
674 724
675 // Methods for scanline decoding. 725 // Methods for scanline decoding.
676 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/ , 726 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/ ,
677 const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*c tableCount*/) { 727 const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*c tableCount*/) {
678 return kUnimplemented; 728 return kUnimplemented;
679 } 729 }
680 730
731 virtual Result onStartIncrementalDecode(const SkImageInfo& /*dstInfo*/, void *, size_t,
732 const SkCodec::Options&, SkPMColor*, int*) {
733 return kUnimplemented;
734 }
735
736 virtual Result onIncrementalDecode(int*) {
737 return kUnimplemented;
738 }
739
740
681 virtual bool onSkipScanlines(int /*countLines*/) { return false; } 741 virtual bool onSkipScanlines(int /*countLines*/) { return false; }
682 742
683 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBy tes*/) { return 0; } 743 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBy tes*/) { return 0; }
684 744
685 /** 745 /**
686 * On an incomplete decode, getPixels() and getScanlines() will call this fu nction 746 * On an incomplete decode, getPixels() and getScanlines() will call this fu nction
687 * to fill any uinitialized memory. 747 * to fill any uinitialized memory.
688 * 748 *
689 * @param dstInfo Contains the destination color type 749 * @param dstInfo Contains the destination color type
690 * Contains the destination alpha type 750 * Contains the destination alpha type
(...skipping 11 matching lines...) Expand all
702 /** 762 /**
703 * Return an object which will allow forcing scanline decodes to sample in X. 763 * Return an object which will allow forcing scanline decodes to sample in X.
704 * 764 *
705 * May create a sampler, if one is not currently being used. Otherwise, doe s 765 * May create a sampler, if one is not currently being used. Otherwise, doe s
706 * not affect ownership. 766 * not affect ownership.
707 * 767 *
708 * Only valid during scanline decoding. 768 * Only valid during scanline decoding.
709 */ 769 */
710 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } 770 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; }
711 771
772 friend class DM::CodecSrc; // for fillIncompleteImage
712 friend class SkSampledCodec; 773 friend class SkSampledCodec;
713 friend class SkIcoCodec; 774 friend class SkIcoCodec;
714 }; 775 };
715 #endif // SkCodec_DEFINED 776 #endif // SkCodec_DEFINED
OLDNEW
« no previous file with comments | « fuzz/fuzz.cpp ('k') | src/codec/SkCodec.cpp » ('j') | src/codec/SkGifCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698