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

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

Issue 2045293002: Add support for multiple frames in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix a test - we now draw transparent background for missing color table Created 4 years, 1 month 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
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkAndroidCodec.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <vector>
22
21 class SkColorSpace; 23 class SkColorSpace;
22 class SkColorSpaceXform; 24 class SkColorSpaceXform;
23 class SkData; 25 class SkData;
24 class SkPngChunkReader; 26 class SkPngChunkReader;
25 class SkSampler; 27 class SkSampler;
26 28
27 namespace DM { 29 namespace DM {
28 class CodecSrc; 30 class CodecSrc;
29 class ColorCodecSrc; 31 class ColorCodecSrc;
30 } 32 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 */ 239 */
238 kNo_ZeroInitialized, 240 kNo_ZeroInitialized,
239 }; 241 };
240 242
241 /** 243 /**
242 * Additional options to pass to getPixels. 244 * Additional options to pass to getPixels.
243 */ 245 */
244 struct Options { 246 struct Options {
245 Options() 247 Options()
246 : fZeroInitialized(kNo_ZeroInitialized) 248 : fZeroInitialized(kNo_ZeroInitialized)
247 , fSubset(NULL) 249 , fSubset(nullptr)
250 , fFrameIndex(0)
251 , fHasPriorFrame(false)
248 {} 252 {}
249 253
250 ZeroInitialized fZeroInitialized; 254 ZeroInitialized fZeroInitialized;
251 /** 255 /**
252 * If not NULL, represents a subset of the original image to decode. 256 * If not NULL, represents a subset of the original image to decode.
253 * Must be within the bounds returned by getInfo(). 257 * Must be within the bounds returned by getInfo().
254 * If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which 258 * If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which
255 * currently supports subsets), the top and left values must be even. 259 * currently supports subsets), the top and left values must be even.
256 * 260 *
257 * In getPixels and incremental decode, we will attempt to decode the 261 * In getPixels and incremental decode, we will attempt to decode the
258 * exact rectangular subset specified by fSubset. 262 * exact rectangular subset specified by fSubset.
259 * 263 *
260 * In a scanline decode, it does not make sense to specify a subset 264 * In a scanline decode, it does not make sense to specify a subset
261 * top or subset height, since the client already controls which rows 265 * top or subset height, since the client already controls which rows
262 * to get and which rows to skip. During scanline decodes, we will 266 * to get and which rows to skip. During scanline decodes, we will
263 * require that the subset top be zero and the subset height be equal 267 * require that the subset top be zero and the subset height be equal
264 * to the full height. We will, however, use the values of 268 * to the full height. We will, however, use the values of
265 * subset left and subset width to decode partial scanlines on calls 269 * subset left and subset width to decode partial scanlines on calls
266 * to getScanlines(). 270 * to getScanlines().
267 */ 271 */
268 SkIRect* fSubset; 272 const SkIRect* fSubset;
273
274 /**
275 * The frame to decode.
276 *
277 * Only meaningful for multi-frame images.
278 */
279 size_t fFrameIndex;
280
281 /**
282 * If true, the dst already contains the prior frame.
283 *
284 * Only meaningful for multi-frame images.
285 *
286 * If fFrameIndex needs to be blended with a prior frame (as reported b y
287 * getFrameInfo[fFrameIndex].fRequiredFrame), the client can set this t o
288 * either true or false:
289 *
290 * true means that the prior frame is already in the dst, and this
291 * codec only needs to decode fFrameIndex and blend it with the dst.
292 * Options.fZeroInitialized is ignored in this case.
293 *
294 * false means that the dst does not contain the prior frame, so this
295 * codec needs to first decode the prior frame (which in turn may need
296 * to decode its prior frame).
297 */
298 bool fHasPriorFrame;
269 }; 299 };
270 300
271 /** 301 /**
272 * Decode into the given pixels, a block of memory of size at 302 * Decode into the given pixels, a block of memory of size at
273 * least (info.fHeight - 1) * rowBytes + (info.fWidth * 303 * least (info.fHeight - 1) * rowBytes + (info.fWidth *
274 * bytesPerPixel) 304 * bytesPerPixel)
275 * 305 *
276 * Repeated calls to this function should give the same results, 306 * Repeated calls to this function should give the same results,
277 * allowing the PixelRef to be immutable. 307 * allowing the PixelRef to be immutable.
278 * 308 *
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 * For subset decodes and sampling, it is simplest to get and skip 546 * For subset decodes and sampling, it is simplest to get and skip
517 * scanlines one at a time, using the nextScanline() API. It is 547 * scanlines one at a time, using the nextScanline() API. It is
518 * possible to ask for larger chunks at a time, but this should be used 548 * possible to ask for larger chunks at a time, but this should be used
519 * with caution. As with full image decodes, the decoder will handle 549 * with caution. As with full image decodes, the decoder will handle
520 * inverting the requested rows, but rows will still be delivered 550 * inverting the requested rows, but rows will still be delivered
521 * starting from the bottom of the image. 551 * starting from the bottom of the image.
522 * 552 *
523 * Upside down bmps are an example. 553 * Upside down bmps are an example.
524 */ 554 */
525 kBottomUp_SkScanlineOrder, 555 kBottomUp_SkScanlineOrder,
526
527 /*
528 * This indicates that the scanline decoder reliably outputs rows, but
529 * they will not be in logical order. If the scanline format is
530 * kOutOfOrder, the nextScanline() API should be used to determine the
531 * actual y-coordinate of the next output row.
532 *
533 * For this scanline ordering, it is advisable to get and skip
534 * scanlines one at a time.
535 *
536 * Interlaced gifs are an example.
537 */
538 kOutOfOrder_SkScanlineOrder,
539 }; 556 };
540 557
541 /** 558 /**
542 * An enum representing the order in which scanlines will be returned by 559 * An enum representing the order in which scanlines will be returned by
543 * the scanline decoder. 560 * the scanline decoder.
544 * 561 *
545 * This is undefined before startScanlineDecode() is called. 562 * This is undefined before startScanlineDecode() is called.
546 */ 563 */
547 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } 564 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; }
548 565
549 /** 566 /**
550 * Returns the y-coordinate of the next row to be returned by the scanline 567 * Returns the y-coordinate of the next row to be returned by the scanline
551 * decoder. 568 * decoder.
552 * 569 *
553 * This will equal fCurrScanline, except in the case of strangely 570 * This will equal fCurrScanline, except in the case of strangely
554 * encoded image types (bottom-up bmps, interlaced gifs). 571 * encoded image types (bottom-up bmps).
555 * 572 *
556 * Results are undefined when not in scanline decoding mode. 573 * Results are undefined when not in scanline decoding mode.
557 */ 574 */
558 int nextScanline() const { return this->outputScanline(fCurrScanline); } 575 int nextScanline() const { return this->outputScanline(fCurrScanline); }
559 576
560 /** 577 /**
561 * Returns the output y-coordinate of the row that corresponds to an input 578 * Returns the output y-coordinate of the row that corresponds to an input
562 * y-coordinate. The input y-coordinate represents where the scanline 579 * y-coordinate. The input y-coordinate represents where the scanline
563 * is located in the encoded data. 580 * is located in the encoded data.
564 * 581 *
565 * This will equal inputScanline, except in the case of strangely 582 * This will equal inputScanline, except in the case of strangely
566 * encoded image types (bottom-up bmps, interlaced gifs). 583 * encoded image types (bottom-up bmps, interlaced gifs).
567 */ 584 */
568 int outputScanline(int inputScanline) const; 585 int outputScanline(int inputScanline) const;
569 586
587 // The required frame for an independent frame is marked as
588 // kNone.
589 static constexpr size_t kNone = static_cast<size_t>(-1);
590
591 /**
592 * Information about individual frames in a multi-framed image.
593 */
594 struct FrameInfo {
595 /**
596 * The frame that this frame needs to be blended with, or
597 * kNone.
598 */
599 size_t fRequiredFrame;
600
601 /**
602 * Number of milliseconds to show this frame.
603 */
604 size_t fDuration;
605 };
606
607 /**
608 * Return info about the frames in the image.
609 *
610 * May require reading through the stream to determine the number of
611 * frames.
612 *
613 * As such, future decoding calls may require a rewind.
614 *
615 * For single-frame images, this will return an empty vector.
616 */
617 std::vector<FrameInfo> getFrameInfo() {
618 return this->onGetFrameInfo();
619 }
620
570 protected: 621 protected:
571 /** 622 /**
572 * Takes ownership of SkStream* 623 * Takes ownership of SkStream*
573 */ 624 */
574 SkCodec(int width, 625 SkCodec(int width,
575 int height, 626 int height,
576 const SkEncodedInfo&, 627 const SkEncodedInfo&,
577 SkStream*, 628 SkStream*,
578 sk_sp<SkColorSpace> = nullptr, 629 sk_sp<SkColorSpace> = nullptr,
579 Origin = kTopLeft_Origin); 630 Origin = kTopLeft_Origin);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 * 754 *
704 * Returns -1 if we have not started a scanline decode. 755 * Returns -1 if we have not started a scanline decode.
705 */ 756 */
706 int currScanline() const { return fCurrScanline; } 757 int currScanline() const { return fCurrScanline; }
707 758
708 virtual int onOutputScanline(int inputScanline) const; 759 virtual int onOutputScanline(int inputScanline) const;
709 760
710 bool initializeColorXform(const SkImageInfo& dstInfo); 761 bool initializeColorXform(const SkImageInfo& dstInfo);
711 SkColorSpaceXform* colorXform() const { return fColorXform.get(); } 762 SkColorSpaceXform* colorXform() const { return fColorXform.get(); }
712 763
764 virtual std::vector<FrameInfo> onGetFrameInfo() {
765 // empty vector - this is not animated.
766 return {};
767 }
768
713 /** 769 /**
714 * Used for testing with qcms. 770 * Used for testing with qcms.
715 * FIXME: Remove this when we are done comparing with qcms. 771 * FIXME: Remove this when we are done comparing with qcms.
716 */ 772 */
717 virtual sk_sp<SkData> getICCData() const { return nullptr; } 773 virtual sk_sp<SkData> getICCData() const { return nullptr; }
718 774
719 private: 775 private:
720 const SkEncodedInfo fEncodedInfo; 776 const SkEncodedInfo fEncodedInfo;
721 const SkImageInfo fSrcInfo; 777 const SkImageInfo fSrcInfo;
722 SkAutoTDelete<SkStream> fStream; 778 SkAutoTDelete<SkStream> fStream;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 */ 837 */
782 void fillIncompleteImage(const SkImageInfo& dstInfo, void* dst, size_t rowBy tes, 838 void fillIncompleteImage(const SkImageInfo& dstInfo, void* dst, size_t rowBy tes,
783 ZeroInitialized zeroInit, int linesRequested, int linesDecoded); 839 ZeroInitialized zeroInit, int linesRequested, int linesDecoded);
784 840
785 /** 841 /**
786 * Return an object which will allow forcing scanline decodes to sample in X. 842 * Return an object which will allow forcing scanline decodes to sample in X.
787 * 843 *
788 * May create a sampler, if one is not currently being used. Otherwise, doe s 844 * May create a sampler, if one is not currently being used. Otherwise, doe s
789 * not affect ownership. 845 * not affect ownership.
790 * 846 *
791 * Only valid during scanline decoding. 847 * Only valid during scanline decoding or incremental decoding.
792 */ 848 */
793 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; } 849 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; }
794 850
795 // For testing with qcms 851 // For testing with qcms
796 // FIXME: Remove these when we are done comparing with qcms. 852 // FIXME: Remove these when we are done comparing with qcms.
797 friend class DM::ColorCodecSrc; 853 friend class DM::ColorCodecSrc;
798 friend class ColorCodecBench; 854 friend class ColorCodecBench;
799 855
800 friend class DM::CodecSrc; // for fillIncompleteImage 856 friend class DM::CodecSrc; // for fillIncompleteImage
801 friend class SkSampledCodec; 857 friend class SkSampledCodec;
802 friend class SkIcoCodec; 858 friend class SkIcoCodec;
803 }; 859 };
804 #endif // SkCodec_DEFINED 860 #endif // SkCodec_DEFINED
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkAndroidCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698