blob: c43fcf8cc038aaf76bbe49ac9b164a21c9ac37ce [file] [log] [blame]
msarett9bde9182015-03-25 05:27:48 -07001/*
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 Canary03a7f5f2017-02-10 09:06:38 -05007#ifndef SkIcoCodec_DEFINED
8#define SkIcoCodec_DEFINED
msarett9bde9182015-03-25 05:27:48 -07009
10#include "SkCodec.h"
11#include "SkImageInfo.h"
12#include "SkStream.h"
Ben Wagner4d1955c2017-03-10 13:08:15 -050013#include "SkTArray.h"
msarett9bde9182015-03-25 05:27:48 -070014#include "SkTypes.h"
15
16/*
17 * This class implements the decoding for bmp images
18 */
19class SkIcoCodec : public SkCodec {
20public:
scroggodb30be22015-12-08 18:54:13 -080021 static bool IsIco(const void*, size_t);
msarett9bde9182015-03-25 05:27:48 -070022
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 Reedede7bac2017-07-23 15:30:02 -040028 static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
msarett9bde9182015-03-25 05:27:48 -070029
30protected:
31
32 /*
33 * Chooses the best dimensions given the desired scale
34 */
mtklein36352bf2015-03-25 18:17:31 -070035 SkISize onGetScaledDimensions(float desiredScale) const override;
msarett9bde9182015-03-25 05:27:48 -070036
scroggoe7fc14b2015-10-02 13:14:46 -070037 bool onDimensionsSupported(const SkISize&) override;
38
msarett9bde9182015-03-25 05:27:48 -070039 /*
40 * Initiates the Ico decode
41 */
msarette6dd0042015-10-09 11:07:34 -070042 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
Leon Scroggins571b30f2017-07-11 17:35:31 +000043 int*) override;
msarett9bde9182015-03-25 05:27:48 -070044
Hal Canarydb683012016-11-23 08:55:18 -070045 SkEncodedImageFormat onGetEncodedFormat() const override {
46 return SkEncodedImageFormat::kICO;
msarett9bde9182015-03-25 05:27:48 -070047 }
48
msarettbe8216a2015-12-04 08:00:50 -080049 SkScanlineOrder onGetScanlineOrder() const override;
50
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050051 bool conversionSupported(const SkImageInfo&, SkColorType, bool,
Leon Scroggins III07418182017-08-15 12:24:02 -040052 const SkColorSpace*) const override {
53 // This will be checked by the embedded codec.
54 return true;
55 }
56
Leon Scroggins IIIae79f322017-08-18 10:53:24 -040057 // Handled by the embedded codec.
58 bool usesColorXform() const override { return false; }
msarett9bde9182015-03-25 05:27:48 -070059private:
60
Leon Scroggins571b30f2017-07-11 17:35:31 +000061 Result onStartScanlineDecode(const SkImageInfo& dstInfo,
62 const SkCodec::Options& options) override;
msarettbe8216a2015-12-04 08:00:50 -080063
64 int onGetScanlines(void* dst, int count, size_t rowBytes) override;
65
66 bool onSkipScanlines(int count) override;
67
scroggo8e6c7ad2016-09-16 08:20:38 -070068 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +000069 const SkCodec::Options&) override;
scroggo8e6c7ad2016-09-16 08:20:38 -070070
71 Result onIncrementalDecode(int* rowsDecoded) override;
72
msarettbe8216a2015-12-04 08:00:50 -080073 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
msarett9bde9182015-03-25 05:27:48 -070086 /*
87 * Constructor called by NewFromStream
88 * @param embeddedCodecs codecs for the embedded images, takes ownership
89 */
msarettc30c4182016-04-20 11:53:35 -070090 SkIcoCodec(int width, int height, const SkEncodedInfo& info,
Ben Wagner145dbcd2016-11-03 14:40:50 -040091 SkTArray<std::unique_ptr<SkCodec>, true>* embeddedCodecs, sk_sp<SkColorSpace> colorSpace);
msarett9bde9182015-03-25 05:27:48 -070092
Ben Wagner145dbcd2016-11-03 14:40:50 -040093 std::unique_ptr<SkTArray<std::unique_ptr<SkCodec>, true>> fEmbeddedCodecs;
msarettbe8216a2015-12-04 08:00:50 -080094
nagarajan.n477e9d42017-09-25 18:13:06 +053095 // fCurrCodec is owned by this class, but should not be an
Ben Wagner145dbcd2016-11-03 14:40:50 -040096 // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs.
nagarajan.n477e9d42017-09-25 18:13:06 +053097 SkCodec* fCurrCodec;
scroggo8e6c7ad2016-09-16 08:20:38 -070098
msarett9bde9182015-03-25 05:27:48 -070099 typedef SkCodec INHERITED;
100};
Hal Canary03a7f5f2017-02-10 09:06:38 -0500101#endif // SkIcoCodec_DEFINED