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