Chromium Code Reviews| 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 "../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 Loading... | |
| 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 Loading... | |
| 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, | |
|
reed1
2016/05/24 15:11:38
The first 3 parameters could be SkPixmap ...
scroggo
2016/05/26 16:10:57
+1. I've been thinking about that for getPixels as
| |
| 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 Loading... | |
| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 /** | 684 /** |
| 631 * Update the current scanline. Used by interlaced png. | 685 * Update the current scanline. Used by interlaced png. |
| 632 */ | 686 */ |
| 633 void updateCurrScanline(int newY) { fCurrScanline = newY; } | 687 void updateCurrScanline(int newY) { fCurrScanline = newY; } |
|
scroggo
2016/05/26 16:10:57
Forgot to remove this last time...
Gone now, in p
| |
| 634 | 688 |
| 635 const SkImageInfo& dstInfo() const { return fDstInfo; } | 689 const SkImageInfo& dstInfo() const { return fDstInfo; } |
| 636 | 690 |
| 637 const SkCodec::Options& options() const { return fOptions; } | 691 const SkCodec::Options& options() const { return fOptions; } |
| 638 | 692 |
| 639 /** | 693 /** |
| 640 * Returns the number of scanlines that have been decoded so far. | 694 * Returns the number of scanlines that have been decoded so far. |
| 641 * This is unaffected by the SkScanlineOrder. | 695 * This is unaffected by the SkScanlineOrder. |
| 642 * | 696 * |
| 643 * Returns -1 if we have not started a scanline decode. | 697 * Returns -1 if we have not started a scanline decode. |
| 644 */ | 698 */ |
| 645 int currScanline() const { return fCurrScanline; } | 699 int currScanline() const { return fCurrScanline; } |
| 646 | 700 |
| 647 virtual int onOutputScanline(int inputScanline) const; | 701 virtual int onOutputScanline(int inputScanline) const; |
| 648 | 702 |
| 649 private: | 703 private: |
| 650 const SkEncodedInfo fEncodedInfo; | 704 const SkEncodedInfo fEncodedInfo; |
| 651 const SkImageInfo fSrcInfo; | 705 const SkImageInfo fSrcInfo; |
| 652 SkAutoTDelete<SkStream> fStream; | 706 SkAutoTDelete<SkStream> fStream; |
| 653 bool fNeedsRewind; | 707 bool fNeedsRewind; |
| 654 sk_sp<SkColorSpace> fColorSpace; | 708 sk_sp<SkColorSpace> fColorSpace; |
| 655 const Origin fOrigin; | 709 const Origin fOrigin; |
| 656 | 710 |
| 657 // These fields are only meaningful during scanline decodes. | 711 // These fields are only meaningful during scanline decodes. |
| 658 SkImageInfo fDstInfo; | 712 SkImageInfo fDstInfo; |
| 659 SkCodec::Options fOptions; | 713 SkCodec::Options fOptions; |
| 660 int fCurrScanline; | 714 int fCurrScanline; |
| 715 bool fStartedIncrementalDecode; | |
| 661 | 716 |
| 662 /** | 717 /** |
| 663 * Return whether these dimensions are supported as a scale. | 718 * Return whether these dimensions are supported as a scale. |
| 664 * | 719 * |
| 665 * The codec may choose to cache the information about scale and subset. | 720 * The codec may choose to cache the information about scale and subset. |
| 666 * Either way, the same information will be passed to onGetPixels/onStart | 721 * Either way, the same information will be passed to onGetPixels/onStart |
| 667 * on success. | 722 * on success. |
| 668 * | 723 * |
| 669 * This must return true for a size returned from getScaledDimensions. | 724 * This must return true for a size returned from getScaledDimensions. |
| 670 */ | 725 */ |
| 671 bool dimensionsSupported(const SkISize& dim) { | 726 bool dimensionsSupported(const SkISize& dim) { |
| 672 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); | 727 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); |
| 673 } | 728 } |
| 674 | 729 |
| 675 // Methods for scanline decoding. | 730 // Methods for scanline decoding. |
| 676 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/ , | 731 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/ , |
| 677 const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*c tableCount*/) { | 732 const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*c tableCount*/) { |
| 678 return kUnimplemented; | 733 return kUnimplemented; |
| 679 } | 734 } |
| 680 | 735 |
| 736 virtual Result onStartIncrementalDecode(const SkImageInfo& /*dstInfo*/, void *, size_t, | |
| 737 const SkCodec::Options&, SkPMColor*, int*) { | |
| 738 return kUnimplemented; | |
| 739 } | |
| 740 | |
| 741 virtual Result onIncrementalDecode(int*) { | |
| 742 return kUnimplemented; | |
| 743 } | |
| 744 | |
| 745 | |
| 681 virtual bool onSkipScanlines(int /*countLines*/) { return false; } | 746 virtual bool onSkipScanlines(int /*countLines*/) { return false; } |
| 682 | 747 |
| 683 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBy tes*/) { return 0; } | 748 virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBy tes*/) { return 0; } |
| 684 | 749 |
| 685 /** | 750 /** |
| 686 * On an incomplete decode, getPixels() and getScanlines() will call this fu nction | 751 * On an incomplete decode, getPixels() and getScanlines() will call this fu nction |
| 687 * to fill any uinitialized memory. | 752 * to fill any uinitialized memory. |
| 688 * | 753 * |
| 689 * @param dstInfo Contains the destination color type | 754 * @param dstInfo Contains the destination color type |
| 690 * Contains the destination alpha type | 755 * Contains the destination alpha type |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 702 /** | 767 /** |
| 703 * Return an object which will allow forcing scanline decodes to sample in X. | 768 * Return an object which will allow forcing scanline decodes to sample in X. |
| 704 * | 769 * |
| 705 * May create a sampler, if one is not currently being used. Otherwise, doe s | 770 * May create a sampler, if one is not currently being used. Otherwise, doe s |
| 706 * not affect ownership. | 771 * not affect ownership. |
| 707 * | 772 * |
| 708 * Only valid during scanline decoding. | 773 * Only valid during scanline decoding. |
| 709 */ | 774 */ |
| 710 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } | 775 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } |
| 711 | 776 |
| 777 friend class DM::CodecSrc; // for fillIncompleteImage | |
| 712 friend class SkSampledCodec; | 778 friend class SkSampledCodec; |
| 713 friend class SkIcoCodec; | 779 friend class SkIcoCodec; |
| 714 }; | 780 }; |
| 715 #endif // SkCodec_DEFINED | 781 #endif // SkCodec_DEFINED |
| OLD | NEW |