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 #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 Loading... |
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 * getFrameInfo[fIndex].fRequiredFrame), the client can set this to |
| 243 * either 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 const SkIRect* fSubset; |
| 303 |
| 304 /** |
| 305 * Options that are only relevant for multi-frame images. |
| 306 * |
| 307 * Unowned pointer. |
| 308 */ |
| 309 const 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 * For subset decodes and sampling, it is simplest to get and skip | 557 * For subset decodes and sampling, it is simplest to get and skip |
516 * scanlines one at a time, using the nextScanline() API. It is | 558 * scanlines one at a time, using the nextScanline() API. It is |
517 * possible to ask for larger chunks at a time, but this should be used | 559 * possible to ask for larger chunks at a time, but this should be used |
518 * with caution. As with full image decodes, the decoder will handle | 560 * with caution. As with full image decodes, the decoder will handle |
519 * inverting the requested rows, but rows will still be delivered | 561 * inverting the requested rows, but rows will still be delivered |
520 * starting from the bottom of the image. | 562 * starting from the bottom of the image. |
521 * | 563 * |
522 * Upside down bmps are an example. | 564 * Upside down bmps are an example. |
523 */ | 565 */ |
524 kBottomUp_SkScanlineOrder, | 566 kBottomUp_SkScanlineOrder, |
525 | |
526 /* | |
527 * This indicates that the scanline decoder reliably outputs rows, but | |
528 * they will not be in logical order. If the scanline format is | |
529 * kOutOfOrder, the nextScanline() API should be used to determine the | |
530 * actual y-coordinate of the next output row. | |
531 * | |
532 * For this scanline ordering, it is advisable to get and skip | |
533 * scanlines one at a time. | |
534 * | |
535 * Interlaced gifs are an example. | |
536 */ | |
537 kOutOfOrder_SkScanlineOrder, | |
538 }; | 567 }; |
539 | 568 |
540 /** | 569 /** |
541 * An enum representing the order in which scanlines will be returned by | 570 * An enum representing the order in which scanlines will be returned by |
542 * the scanline decoder. | 571 * the scanline decoder. |
543 * | 572 * |
544 * This is undefined before startScanlineDecode() is called. | 573 * This is undefined before startScanlineDecode() is called. |
545 */ | 574 */ |
546 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder()
; } | 575 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder()
; } |
547 | 576 |
548 /** | 577 /** |
549 * Returns the y-coordinate of the next row to be returned by the scanline | 578 * Returns the y-coordinate of the next row to be returned by the scanline |
550 * decoder. | 579 * decoder. |
551 * | 580 * |
552 * This will equal fCurrScanline, except in the case of strangely | 581 * This will equal fCurrScanline, except in the case of strangely |
553 * encoded image types (bottom-up bmps, interlaced gifs). | 582 * encoded image types (bottom-up bmps). |
554 * | 583 * |
555 * Results are undefined when not in scanline decoding mode. | 584 * Results are undefined when not in scanline decoding mode. |
556 */ | 585 */ |
557 int nextScanline() const { return this->outputScanline(fCurrScanline); } | 586 int nextScanline() const { return this->outputScanline(fCurrScanline); } |
558 | 587 |
559 /** | 588 /** |
560 * Returns the output y-coordinate of the row that corresponds to an input | 589 * Returns the output y-coordinate of the row that corresponds to an input |
561 * y-coordinate. The input y-coordinate represents where the scanline | 590 * y-coordinate. The input y-coordinate represents where the scanline |
562 * is located in the encoded data. | 591 * is located in the encoded data. |
563 * | 592 * |
564 * This will equal inputScanline, except in the case of strangely | 593 * This will equal inputScanline, except in the case of strangely |
565 * encoded image types (bottom-up bmps, interlaced gifs). | 594 * encoded image types (bottom-up bmps, interlaced gifs). |
566 */ | 595 */ |
567 int outputScanline(int inputScanline) const; | 596 int outputScanline(int inputScanline) const; |
568 | 597 |
| 598 // The required frame for an independent frame is marked as |
| 599 // kIndependentFrame. |
| 600 // FIXME: This sounds like the frame depends on an independent frame, |
| 601 // rather than this frame is independent. Is there a better name for |
| 602 // this? kInvalidFrameIndex? kNone? |
| 603 static constexpr size_t kIndependentFrame = static_cast<size_t>(-1); |
| 604 |
| 605 /** |
| 606 * Information about individual frames in a multi-framed image. |
| 607 */ |
| 608 struct FrameInfo { |
| 609 /** |
| 610 * The frame that this frame needs to be blended with, or |
| 611 * kIndependentFrame. |
| 612 */ |
| 613 size_t fRequiredFrame; |
| 614 |
| 615 /** |
| 616 * Number of milliseconds to show this frame. |
| 617 */ |
| 618 size_t fDuration; |
| 619 }; |
| 620 |
| 621 /** |
| 622 * Return info about the frames in the image. |
| 623 * |
| 624 * May require reading through the stream to determine the number of |
| 625 * frames. |
| 626 * |
| 627 * As such, future decoding calls may require a rewind. |
| 628 * |
| 629 * For single-frame images, this will return an empty vector. |
| 630 */ |
| 631 std::vector<FrameInfo> getFrameInfo() { |
| 632 return this->onGetFrameInfo(); |
| 633 } |
| 634 |
569 protected: | 635 protected: |
570 /** | 636 /** |
571 * Takes ownership of SkStream* | 637 * Takes ownership of SkStream* |
572 */ | 638 */ |
573 SkCodec(int width, | 639 SkCodec(int width, |
574 int height, | 640 int height, |
575 const SkEncodedInfo&, | 641 const SkEncodedInfo&, |
576 SkStream*, | 642 SkStream*, |
577 sk_sp<SkColorSpace> = nullptr, | 643 sk_sp<SkColorSpace> = nullptr, |
578 Origin = kTopLeft_Origin); | 644 Origin = kTopLeft_Origin); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 /** | 765 /** |
700 * Returns the number of scanlines that have been decoded so far. | 766 * Returns the number of scanlines that have been decoded so far. |
701 * This is unaffected by the SkScanlineOrder. | 767 * This is unaffected by the SkScanlineOrder. |
702 * | 768 * |
703 * Returns -1 if we have not started a scanline decode. | 769 * Returns -1 if we have not started a scanline decode. |
704 */ | 770 */ |
705 int currScanline() const { return fCurrScanline; } | 771 int currScanline() const { return fCurrScanline; } |
706 | 772 |
707 virtual int onOutputScanline(int inputScanline) const; | 773 virtual int onOutputScanline(int inputScanline) const; |
708 | 774 |
| 775 virtual std::vector<FrameInfo> onGetFrameInfo() { |
| 776 // empty vector - this is not animated. |
| 777 return {}; |
| 778 } |
| 779 |
709 /** | 780 /** |
710 * Used for testing with qcms. | 781 * Used for testing with qcms. |
711 * FIXME: Remove this when we are done comparing with qcms. | 782 * FIXME: Remove this when we are done comparing with qcms. |
712 */ | 783 */ |
713 virtual sk_sp<SkData> getICCData() const { return nullptr; } | 784 virtual sk_sp<SkData> getICCData() const { return nullptr; } |
714 private: | 785 private: |
715 const SkEncodedInfo fEncodedInfo; | 786 const SkEncodedInfo fEncodedInfo; |
716 const SkImageInfo fSrcInfo; | 787 const SkImageInfo fSrcInfo; |
717 SkAutoTDelete<SkStream> fStream; | 788 SkAutoTDelete<SkStream> fStream; |
718 bool fNeedsRewind; | 789 bool fNeedsRewind; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 */ | 846 */ |
776 void fillIncompleteImage(const SkImageInfo& dstInfo, void* dst, size_t rowBy
tes, | 847 void fillIncompleteImage(const SkImageInfo& dstInfo, void* dst, size_t rowBy
tes, |
777 ZeroInitialized zeroInit, int linesRequested, int linesDecoded); | 848 ZeroInitialized zeroInit, int linesRequested, int linesDecoded); |
778 | 849 |
779 /** | 850 /** |
780 * Return an object which will allow forcing scanline decodes to sample in
X. | 851 * Return an object which will allow forcing scanline decodes to sample in
X. |
781 * | 852 * |
782 * May create a sampler, if one is not currently being used. Otherwise, doe
s | 853 * May create a sampler, if one is not currently being used. Otherwise, doe
s |
783 * not affect ownership. | 854 * not affect ownership. |
784 * | 855 * |
785 * Only valid during scanline decoding. | 856 * Only valid during scanline decoding or incremental decoding. |
786 */ | 857 */ |
787 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} | 858 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} |
788 | 859 |
789 // For testing with qcms | 860 // For testing with qcms |
790 // FIXME: Remove these when we are done comparing with qcms. | 861 // FIXME: Remove these when we are done comparing with qcms. |
791 friend class DM::ColorCodecSrc; | 862 friend class DM::ColorCodecSrc; |
792 friend class ColorCodecBench; | 863 friend class ColorCodecBench; |
793 | 864 |
794 friend class DM::CodecSrc; // for fillIncompleteImage | 865 friend class DM::CodecSrc; // for fillIncompleteImage |
795 friend class SkSampledCodec; | 866 friend class SkSampledCodec; |
796 friend class SkIcoCodec; | 867 friend class SkIcoCodec; |
797 }; | 868 }; |
798 #endif // SkCodec_DEFINED | 869 #endif // SkCodec_DEFINED |
OLD | NEW |