blob: 9a3f248af5860641bb91e17d5f416ac1b2465644 [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 */
7
8#include "SkCodec.h"
9#include "SkImageInfo.h"
10#include "SkStream.h"
11#include "SkTypes.h"
12
13/*
14 * This class implements the decoding for bmp images
15 */
16class SkIcoCodec : public SkCodec {
17public:
scroggodb30be22015-12-08 18:54:13 -080018 static bool IsIco(const void*, size_t);
msarett9bde9182015-03-25 05:27:48 -070019
20 /*
21 * Assumes IsIco was called and returned true
22 * Creates an Ico decoder
23 * Reads enough of the stream to determine the image format
24 */
25 static SkCodec* NewFromStream(SkStream*);
26
27protected:
28
29 /*
30 * Chooses the best dimensions given the desired scale
31 */
mtklein36352bf2015-03-25 18:17:31 -070032 SkISize onGetScaledDimensions(float desiredScale) const override;
msarett9bde9182015-03-25 05:27:48 -070033
scroggoe7fc14b2015-10-02 13:14:46 -070034 bool onDimensionsSupported(const SkISize&) override;
35
msarett9bde9182015-03-25 05:27:48 -070036 /*
37 * Initiates the Ico decode
38 */
msarette6dd0042015-10-09 11:07:34 -070039 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
40 SkPMColor*, int*, int*) override;
msarett9bde9182015-03-25 05:27:48 -070041
mtklein36352bf2015-03-25 18:17:31 -070042 SkEncodedFormat onGetEncodedFormat() const override {
msarett9bde9182015-03-25 05:27:48 -070043 return kICO_SkEncodedFormat;
44 }
45
msarettbe8216a2015-12-04 08:00:50 -080046 SkScanlineOrder onGetScanlineOrder() const override;
47
msarett9bde9182015-03-25 05:27:48 -070048private:
49
msarettbe8216a2015-12-04 08:00:50 -080050 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Options& options,
51 SkPMColor inputColorPtr[], int* inputColorCount) override;
52
53 int onGetScanlines(void* dst, int count, size_t rowBytes) override;
54
55 bool onSkipScanlines(int count) override;
56
57 SkSampler* getSampler(bool createIfNecessary) override;
58
59 /*
60 * Searches fEmbeddedCodecs for a codec that matches requestedSize.
61 * The search starts at startIndex and ends when an appropriate codec
62 * is found, or we have reached the end of the array.
63 *
64 * @return the index of the matching codec or -1 if there is no
65 * matching codec between startIndex and the end of
66 * the array.
67 */
68 int chooseCodec(const SkISize& requestedSize, int startIndex);
69
msarett9bde9182015-03-25 05:27:48 -070070 /*
71 * Constructor called by NewFromStream
72 * @param embeddedCodecs codecs for the embedded images, takes ownership
73 */
msarettbe8216a2015-12-04 08:00:50 -080074 SkIcoCodec(const SkImageInfo& srcInfo, SkTArray<SkAutoTDelete<SkCodec>, true>* embeddedCodecs);
msarett9bde9182015-03-25 05:27:48 -070075
msarettbe8216a2015-12-04 08:00:50 -080076 SkAutoTDelete<SkTArray<SkAutoTDelete<SkCodec>, true>> fEmbeddedCodecs; // owned
77
78 // Only used by the scanline decoder. onStartScanlineDecode() will set
79 // fCurrScanlineCodec to one of the fEmbeddedCodecs, if it can find a
80 // codec of the appropriate size. We will use fCurrScanlineCodec for
81 // subsequent calls to onGetScanlines() or onSkipScanlines().
82 // fCurrScanlineCodec is owned by this class, but should not be an
83 // SkAutoTDelete. It will be deleted by the destructor of fEmbeddedCodecs.
84 SkCodec* fCurrScanlineCodec;
msarett9bde9182015-03-25 05:27:48 -070085
86 typedef SkCodec INHERITED;
87};