msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 7 | #ifndef SkIcoCodec_DEFINED |
| 8 | #define SkIcoCodec_DEFINED |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 9 | |
| 10 | #include "SkCodec.h" |
| 11 | #include "SkImageInfo.h" |
| 12 | #include "SkStream.h" |
Ben Wagner | 4d1955c | 2017-03-10 13:08:15 -0500 | [diff] [blame] | 13 | #include "SkTArray.h" |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 14 | #include "SkTypes.h" |
| 15 | |
| 16 | /* |
| 17 | * This class implements the decoding for bmp images |
| 18 | */ |
| 19 | class SkIcoCodec : public SkCodec { |
| 20 | public: |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 21 | static bool IsIco(const void*, size_t); |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Assumes IsIco was called and returned true |
| 25 | * Creates an Ico decoder |
| 26 | * Reads enough of the stream to determine the image format |
| 27 | */ |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 28 | static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*); |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 29 | |
| 30 | protected: |
| 31 | |
| 32 | /* |
| 33 | * Chooses the best dimensions given the desired scale |
| 34 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 35 | SkISize onGetScaledDimensions(float desiredScale) const override; |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 36 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 37 | bool onDimensionsSupported(const SkISize&) override; |
| 38 | |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Initiates the Ico decode |
| 41 | */ |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 42 | Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 43 | int*) override; |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 44 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 45 | SkEncodedImageFormat onGetEncodedFormat() const override { |
| 46 | return SkEncodedImageFormat::kICO; |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 47 | } |
| 48 | |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 49 | SkScanlineOrder onGetScanlineOrder() const override; |
| 50 | |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 51 | bool conversionSupported(const SkImageInfo&, bool, bool) override { |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 52 | // This will be checked by the embedded codec. |
| 53 | return true; |
| 54 | } |
| 55 | |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 56 | // Handled by the embedded codec. |
| 57 | bool usesColorXform() const override { return false; } |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 58 | private: |
| 59 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 60 | Result onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 61 | const SkCodec::Options& options) override; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 62 | |
| 63 | int onGetScanlines(void* dst, int count, size_t rowBytes) override; |
| 64 | |
| 65 | bool onSkipScanlines(int count) override; |
| 66 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 67 | Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 68 | const SkCodec::Options&) override; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 69 | |
| 70 | Result onIncrementalDecode(int* rowsDecoded) override; |
| 71 | |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 72 | SkSampler* getSampler(bool createIfNecessary) override; |
| 73 | |
| 74 | /* |
| 75 | * Searches fEmbeddedCodecs for a codec that matches requestedSize. |
| 76 | * The search starts at startIndex and ends when an appropriate codec |
| 77 | * is found, or we have reached the end of the array. |
| 78 | * |
| 79 | * @return the index of the matching codec or -1 if there is no |
| 80 | * matching codec between startIndex and the end of |
| 81 | * the array. |
| 82 | */ |
| 83 | int chooseCodec(const SkISize& requestedSize, int startIndex); |
| 84 | |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 85 | /* |
| 86 | * Constructor called by NewFromStream |
| 87 | * @param embeddedCodecs codecs for the embedded images, takes ownership |
| 88 | */ |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 89 | SkIcoCodec(SkEncodedInfo&& info, SkTArray<std::unique_ptr<SkCodec>, true>* embeddedCodecs); |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 90 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 91 | std::unique_ptr<SkTArray<std::unique_ptr<SkCodec>, true>> fEmbeddedCodecs; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 92 | |
nagarajan.n | 477e9d4 | 2017-09-25 18:13:06 +0530 | [diff] [blame] | 93 | // fCurrCodec is owned by this class, but should not be an |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 94 | // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs. |
nagarajan.n | 477e9d4 | 2017-09-25 18:13:06 +0530 | [diff] [blame] | 95 | SkCodec* fCurrCodec; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 96 | |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 97 | typedef SkCodec INHERITED; |
| 98 | }; |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 99 | #endif // SkIcoCodec_DEFINED |