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 | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame^] | 51 | bool conversionSupported(const SkImageInfo&, SkColorType, bool, |
Leon Scroggins III | 0741818 | 2017-08-15 12:24:02 -0400 | [diff] [blame] | 52 | const SkColorSpace*) const override { |
| 53 | // This will be checked by the embedded codec. |
| 54 | return true; |
| 55 | } |
| 56 | |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 57 | // Handled by the embedded codec. |
| 58 | bool usesColorXform() const override { return false; } |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 59 | private: |
| 60 | |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 61 | Result onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 62 | const SkCodec::Options& options) override; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 63 | |
| 64 | int onGetScanlines(void* dst, int count, size_t rowBytes) override; |
| 65 | |
| 66 | bool onSkipScanlines(int count) override; |
| 67 | |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 68 | Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 69 | const SkCodec::Options&) override; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 70 | |
| 71 | Result onIncrementalDecode(int* rowsDecoded) override; |
| 72 | |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 73 | SkSampler* getSampler(bool createIfNecessary) override; |
| 74 | |
| 75 | /* |
| 76 | * Searches fEmbeddedCodecs for a codec that matches requestedSize. |
| 77 | * The search starts at startIndex and ends when an appropriate codec |
| 78 | * is found, or we have reached the end of the array. |
| 79 | * |
| 80 | * @return the index of the matching codec or -1 if there is no |
| 81 | * matching codec between startIndex and the end of |
| 82 | * the array. |
| 83 | */ |
| 84 | int chooseCodec(const SkISize& requestedSize, int startIndex); |
| 85 | |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Constructor called by NewFromStream |
| 88 | * @param embeddedCodecs codecs for the embedded images, takes ownership |
| 89 | */ |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 90 | SkIcoCodec(int width, int height, const SkEncodedInfo& info, |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 91 | SkTArray<std::unique_ptr<SkCodec>, true>* embeddedCodecs, sk_sp<SkColorSpace> colorSpace); |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 92 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 93 | std::unique_ptr<SkTArray<std::unique_ptr<SkCodec>, true>> fEmbeddedCodecs; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 94 | |
nagarajan.n | 477e9d4 | 2017-09-25 18:13:06 +0530 | [diff] [blame] | 95 | // fCurrCodec is owned by this class, but should not be an |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 96 | // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs. |
nagarajan.n | 477e9d4 | 2017-09-25 18:13:06 +0530 | [diff] [blame] | 97 | SkCodec* fCurrCodec; |
scroggo | 8e6c7ad | 2016-09-16 08:20:38 -0700 | [diff] [blame] | 98 | |
msarett | 9bde918 | 2015-03-25 05:27:48 -0700 | [diff] [blame] | 99 | typedef SkCodec INHERITED; |
| 100 | }; |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 101 | #endif // SkIcoCodec_DEFINED |