blob: 9464f47afd6437a2ca99b6cd6ad31bad5fe4b71e [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 III712476e2018-10-03 15:47:00 -040051 bool conversionSupported(const SkImageInfo&, bool, bool) override {
Leon Scroggins III07418182017-08-15 12:24:02 -040052 // This will be checked by the embedded codec.
53 return true;
54 }
55
Leon Scroggins IIIae79f322017-08-18 10:53:24 -040056 // Handled by the embedded codec.
57 bool usesColorXform() const override { return false; }
msarett9bde9182015-03-25 05:27:48 -070058private:
59
Leon Scroggins571b30f2017-07-11 17:35:31 +000060 Result onStartScanlineDecode(const SkImageInfo& dstInfo,
61 const SkCodec::Options& options) override;
msarettbe8216a2015-12-04 08:00:50 -080062
63 int onGetScanlines(void* dst, int count, size_t rowBytes) override;
64
65 bool onSkipScanlines(int count) override;
66
scroggo8e6c7ad2016-09-16 08:20:38 -070067 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +000068 const SkCodec::Options&) override;
scroggo8e6c7ad2016-09-16 08:20:38 -070069
70 Result onIncrementalDecode(int* rowsDecoded) override;
71
msarettbe8216a2015-12-04 08:00:50 -080072 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
msarett9bde9182015-03-25 05:27:48 -070085 /*
86 * Constructor called by NewFromStream
87 * @param embeddedCodecs codecs for the embedded images, takes ownership
88 */
Leon Scroggins III36f7e322018-08-27 11:55:46 -040089 SkIcoCodec(SkEncodedInfo&& info, SkTArray<std::unique_ptr<SkCodec>, true>* embeddedCodecs);
msarett9bde9182015-03-25 05:27:48 -070090
Ben Wagner145dbcd2016-11-03 14:40:50 -040091 std::unique_ptr<SkTArray<std::unique_ptr<SkCodec>, true>> fEmbeddedCodecs;
msarettbe8216a2015-12-04 08:00:50 -080092
nagarajan.n477e9d42017-09-25 18:13:06 +053093 // fCurrCodec is owned by this class, but should not be an
Ben Wagner145dbcd2016-11-03 14:40:50 -040094 // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs.
nagarajan.n477e9d42017-09-25 18:13:06 +053095 SkCodec* fCurrCodec;
scroggo8e6c7ad2016-09-16 08:20:38 -070096
msarett9bde9182015-03-25 05:27:48 -070097 typedef SkCodec INHERITED;
98};
Hal Canary03a7f5f2017-02-10 09:06:38 -050099#endif // SkIcoCodec_DEFINED