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

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: Small cleanups Created 4 years, 2 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
« no previous file with comments | « gm/animatedGif.cpp ('k') | src/codec/SkCodecAnimation.h » ('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 SkData; 24 class SkData;
23 class SkPngChunkReader; 25 class SkPngChunkReader;
24 class SkSampler; 26 class SkSampler;
25 27
26 namespace DM { 28 namespace DM {
27 class CodecSrc; 29 class CodecSrc;
28 class ColorCodecSrc; 30 class ColorCodecSrc;
29 } 31 }
30 class ColorCodecBench; 32 class ColorCodecBench;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 */ 215 */
214 kCouldNotRewind, 216 kCouldNotRewind,
215 /** 217 /**
216 * This method is not implemented by this codec. 218 * This method is not implemented by this codec.
217 * FIXME: Perhaps this should be kUnsupported? 219 * FIXME: Perhaps this should be kUnsupported?
218 */ 220 */
219 kUnimplemented, 221 kUnimplemented,
220 }; 222 };
221 223
222 /** 224 /**
225 * Additional options that only apply to multiframe images.
226 */
227 struct MultiFrameOptions {
228 MultiFrameOptions()
229 : fIndex(0)
230 , fHasPriorFrame(false)
231 {}
232
233 /**
234 * The frame to decode.
235 */
236 size_t fIndex;
237
238 /**
239 * If true, the dst already contains the prior frame.
240 *
241 * If fIndex needs to be blended with a prior frame (as reported by
242 * getRequiredFrame(fIndex)), the client can set this to either
243 * true or false:
244 *
245 * true means that the prior frame is already in the dst, and this
246 * codec only needs to decode fIndex and blend it with the dst.
247 * Options.fZeroInitialized is ignored in this case.
248 *
249 * false means that the dst does not contain the prior frame, so this
250 * codec needs to first decode the prior frame (which in turn may need
251 * to decode its prior frame).
252 */
253 bool fHasPriorFrame;
254 };
255
256 /**
223 * Whether or not the memory passed to getPixels is zero initialized. 257 * Whether or not the memory passed to getPixels is zero initialized.
224 */ 258 */
225 enum ZeroInitialized { 259 enum ZeroInitialized {
226 /** 260 /**
227 * The memory passed to getPixels is zero initialized. The SkCodec 261 * The memory passed to getPixels is zero initialized. The SkCodec
228 * may take advantage of this by skipping writing zeroes. 262 * may take advantage of this by skipping writing zeroes.
229 */ 263 */
230 kYes_ZeroInitialized, 264 kYes_ZeroInitialized,
231 /** 265 /**
232 * The memory passed to getPixels has not been initialized to zero, 266 * The memory passed to getPixels has not been initialized to zero,
233 * so the SkCodec must write all zeroes to memory. 267 * so the SkCodec must write all zeroes to memory.
234 * 268 *
235 * This is the default. It will be used if no Options struct is used. 269 * This is the default. It will be used if no Options struct is used.
236 */ 270 */
237 kNo_ZeroInitialized, 271 kNo_ZeroInitialized,
238 }; 272 };
239 273
240 /** 274 /**
241 * Additional options to pass to getPixels. 275 * Additional options to pass to getPixels.
242 */ 276 */
243 struct Options { 277 struct Options {
244 Options() 278 Options()
245 : fZeroInitialized(kNo_ZeroInitialized) 279 : fZeroInitialized(kNo_ZeroInitialized)
246 , fSubset(NULL) 280 , fSubset(nullptr)
281 , fFrameOptions(nullptr)
247 {} 282 {}
248 283
249 ZeroInitialized fZeroInitialized; 284 ZeroInitialized fZeroInitialized;
250 /** 285 /**
251 * If not NULL, represents a subset of the original image to decode. 286 * If not NULL, represents a subset of the original image to decode.
252 * Must be within the bounds returned by getInfo(). 287 * Must be within the bounds returned by getInfo().
253 * If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which 288 * If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which
254 * currently supports subsets), the top and left values must be even. 289 * currently supports subsets), the top and left values must be even.
255 * 290 *
256 * In getPixels and incremental decode, we will attempt to decode the 291 * In getPixels and incremental decode, we will attempt to decode the
257 * exact rectangular subset specified by fSubset. 292 * exact rectangular subset specified by fSubset.
258 * 293 *
259 * In a scanline decode, it does not make sense to specify a subset 294 * 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 295 * top or subset height, since the client already controls which rows
261 * to get and which rows to skip. During scanline decodes, we will 296 * 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 297 * 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 298 * to the full height. We will, however, use the values of
264 * subset left and subset width to decode partial scanlines on calls 299 * subset left and subset width to decode partial scanlines on calls
265 * to getScanlines(). 300 * to getScanlines().
266 */ 301 */
267 SkIRect* fSubset; 302 SkIRect* fSubset;
303
304 /**
305 * Options that are only relevant for multi-frame images.
306 *
307 * Unowned pointer.
308 */
309 MultiFrameOptions* fFrameOptions;
268 }; 310 };
269 311
270 /** 312 /**
271 * Decode into the given pixels, a block of memory of size at 313 * Decode into the given pixels, a block of memory of size at
272 * least (info.fHeight - 1) * rowBytes + (info.fWidth * 314 * least (info.fHeight - 1) * rowBytes + (info.fWidth *
273 * bytesPerPixel) 315 * bytesPerPixel)
274 * 316 *
275 * Repeated calls to this function should give the same results, 317 * Repeated calls to this function should give the same results,
276 * allowing the PixelRef to be immutable. 318 * allowing the PixelRef to be immutable.
277 * 319 *
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 /** 601 /**
560 * Returns the output y-coordinate of the row that corresponds to an input 602 * Returns the output y-coordinate of the row that corresponds to an input
561 * y-coordinate. The input y-coordinate represents where the scanline 603 * y-coordinate. The input y-coordinate represents where the scanline
562 * is located in the encoded data. 604 * is located in the encoded data.
563 * 605 *
564 * This will equal inputScanline, except in the case of strangely 606 * This will equal inputScanline, except in the case of strangely
565 * encoded image types (bottom-up bmps, interlaced gifs). 607 * encoded image types (bottom-up bmps, interlaced gifs).
566 */ 608 */
567 int outputScanline(int inputScanline) const; 609 int outputScanline(int inputScanline) const;
568 610
611 // The required frame for an independent frame is marked as
612 // kIndependentFrame.
613 static constexpr size_t kIndependentFrame = static_cast<size_t>(-1);
614
615 /**
616 * Information about individual frames in a multi-framed image.
617 */
618 struct FrameInfo {
scroggo 2016/09/26 15:51:43 I also considered "FrameMetaData". Any preference
msarett 2016/09/26 17:30:53 I prefer FrameInfo, but don't feel strongly.
619 /**
620 * The frame that this frame needs to be blended with, or
621 * kIndependentFrame.
622 */
623 size_t fRequiredFrame;
624
625 /**
626 * Number of 1/100 seconds to show this frame.
msarett 2016/09/26 17:30:53 I'm guessing "1/100 seconds" is what Chrome does?
scroggo 2016/09/26 17:43:11 D'oh - good catch. I just used 1/100 seconds becau
627 */
628 size_t fDuration;
629 };
630
631 /**
632 * Return info about the frames in the image.
633 *
634 * May require reading through the stream to determine the number of
635 * frames.
636 *
637 * As such, future decoding calls may require a rewind.
638 *
639 * For single-frame images, this will return an empty vector.
640 */
641 std::vector<FrameInfo> getFrameInfo() {
642 return this->onGetFrameInfo();
643 }
644
569 protected: 645 protected:
570 /** 646 /**
571 * Takes ownership of SkStream* 647 * Takes ownership of SkStream*
572 */ 648 */
573 SkCodec(int width, 649 SkCodec(int width,
574 int height, 650 int height,
575 const SkEncodedInfo&, 651 const SkEncodedInfo&,
576 SkStream*, 652 SkStream*,
577 sk_sp<SkColorSpace> = nullptr, 653 sk_sp<SkColorSpace> = nullptr,
578 Origin = kTopLeft_Origin); 654 Origin = kTopLeft_Origin);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 /** 775 /**
700 * Returns the number of scanlines that have been decoded so far. 776 * Returns the number of scanlines that have been decoded so far.
701 * This is unaffected by the SkScanlineOrder. 777 * This is unaffected by the SkScanlineOrder.
702 * 778 *
703 * Returns -1 if we have not started a scanline decode. 779 * Returns -1 if we have not started a scanline decode.
704 */ 780 */
705 int currScanline() const { return fCurrScanline; } 781 int currScanline() const { return fCurrScanline; }
706 782
707 virtual int onOutputScanline(int inputScanline) const; 783 virtual int onOutputScanline(int inputScanline) const;
708 784
785 virtual std::vector<FrameInfo> onGetFrameInfo() {
786 // empty vector - this is not animated.
787 return {};
788 }
789
709 /** 790 /**
710 * Used for testing with qcms. 791 * Used for testing with qcms.
711 * FIXME: Remove this when we are done comparing with qcms. 792 * FIXME: Remove this when we are done comparing with qcms.
712 */ 793 */
713 virtual sk_sp<SkData> getICCData() const { return nullptr; } 794 virtual sk_sp<SkData> getICCData() const { return nullptr; }
714 private: 795 private:
715 const SkEncodedInfo fEncodedInfo; 796 const SkEncodedInfo fEncodedInfo;
716 const SkImageInfo fSrcInfo; 797 const SkImageInfo fSrcInfo;
717 SkAutoTDelete<SkStream> fStream; 798 SkAutoTDelete<SkStream> fStream;
718 bool fNeedsRewind; 799 bool fNeedsRewind;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 // For testing with qcms 870 // For testing with qcms
790 // FIXME: Remove these when we are done comparing with qcms. 871 // FIXME: Remove these when we are done comparing with qcms.
791 friend class DM::ColorCodecSrc; 872 friend class DM::ColorCodecSrc;
792 friend class ColorCodecBench; 873 friend class ColorCodecBench;
793 874
794 friend class DM::CodecSrc; // for fillIncompleteImage 875 friend class DM::CodecSrc; // for fillIncompleteImage
795 friend class SkSampledCodec; 876 friend class SkSampledCodec;
796 friend class SkIcoCodec; 877 friend class SkIcoCodec;
797 }; 878 };
798 #endif // SkCodec_DEFINED 879 #endif // SkCodec_DEFINED
OLDNEW
« no previous file with comments | « gm/animatedGif.cpp ('k') | src/codec/SkCodecAnimation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698