Debian Codegraph @

src/codec/SkIcoCodec.h

raw
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 */
7 #ifndef SkIcoCodec_DEFINED
8 #define SkIcoCodec_DEFINED
9
10 #include "include/codec/SkCodec.h"
11 #include "include/codec/SkEncodedImageFormat.h"
12 #include "include/core/SkSize.h"
13 #include "include/core/SkTypes.h"
14 #include "include/private/base/SkTArray.h"
15
16 #include <cstddef>
17 #include <memory>
18
19 class SkSampler;
20 class SkStream;
21 struct SkEncodedInfo;
22 struct SkImageInfo;
23
24 /*
25 * This class implements the decoding for bmp images
26 */
27 class SkIcoCodec : public SkCodec {
28 public:
29 static bool IsIco(const void*, size_t);
30
31 /*
32 * Assumes IsIco was called and returned true
33 * Creates an Ico decoder
34 * Reads enough of the stream to determine the image format
35 */
36 static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
37
38 protected:
39
40 /*
41 * Chooses the best dimensions given the desired scale
42 */
43 SkISize onGetScaledDimensions(float desiredScale) const override;
44
45 bool onDimensionsSupported(const SkISize&) override;
46
47 /*
48 * Initiates the Ico decode
49 */
50 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
51 int*) override;
52
53 SkEncodedImageFormat onGetEncodedFormat() const override {
54 return SkEncodedImageFormat::kICO;
55 }
56
57 SkScanlineOrder onGetScanlineOrder() const override;
58
59 bool conversionSupported(const SkImageInfo&, bool, bool) override {
60 // This will be checked by the embedded codec.
61 return true;
62 }
63
64 // Handled by the embedded codec.
65 bool usesColorXform() const override { return false; }
66 private:
67
68 Result onStartScanlineDecode(const SkImageInfo& dstInfo,
69 const SkCodec::Options& options) override;
70
71 int onGetScanlines(void* dst, int count, size_t rowBytes) override;
72
73 bool onSkipScanlines(int count) override;
74
75 bool onSupportsIncrementalDecode(const SkImageInfo&) override;
76 Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
77 const SkCodec::Options&) override;
78
79 Result onIncrementalDecode(int* rowsDecoded) override;
80
81 SkSampler* getSampler(bool createIfNecessary) override;
82
83 /*
84 * Searches fEmbeddedCodecs for a codec that matches requestedSize.
85 * The search starts at startIndex and ends when an appropriate codec
86 * is found, or we have reached the end of the array.
87 *
88 * @return the index of the matching codec or -1 if there is no
89 * matching codec between startIndex and the end of
90 * the array.
91 */
92 int chooseCodec(const SkISize& requestedSize, int startIndex);
93
94 /*
95 * Constructor called by NewFromStream
96 * @param embeddedCodecs codecs for the embedded images, takes ownership
97 */
98 SkIcoCodec(SkEncodedInfo&& info,
99 std::unique_ptr<SkStream>,
100 std::unique_ptr<skia_private::TArray<std::unique_ptr<SkCodec>>> embeddedCodecs);
101
102 std::unique_ptr<skia_private::TArray<std::unique_ptr<SkCodec>>> fEmbeddedCodecs;
103
104 // fCurrCodec is owned by this class, but should not be an
105 // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs.
106 SkCodec* fCurrCodec;
107
108 using INHERITED = SkCodec;
109 };
110 #endif // SkIcoCodec_DEFINED