• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkBmpStandardCodec_DEFINED
8 #define SkBmpStandardCodec_DEFINED
9 
10 #include "include/core/SkImageInfo.h"
11 #include "include/core/SkTypes.h"
12 #include "src/codec/SkBmpBaseCodec.h"
13 #include "src/codec/SkColorTable.h"
14 #include "src/codec/SkSwizzler.h"
15 
16 /*
17  * This class implements the decoding for bmp images that use "standard" modes,
18  * which essentially means they do not contain bit masks or RLE codes.
19  */
20 class SkBmpStandardCodec : public SkBmpBaseCodec {
21 public:
22 
23     /*
24      * Creates an instance of the decoder
25      *
26      * Called only by SkBmpCodec::MakeFromStream
27      * There should be no other callers despite this being public
28      *
29      * @param info contains properties of the encoded data
30      * @param stream the stream of encoded image data
31      * @param bitsPerPixel the number of bits used to store each pixel
32      * @param numColors the number of colors in the color table
33      * @param bytesPerColor the number of bytes in the stream used to represent
34                             each color in the color table
35      * @param offset the offset of the image pixel data from the end of the
36      *               headers
37      * @param rowOrder indicates whether rows are ordered top-down or bottom-up
38      * @param isOpaque indicates if the bmp itself is opaque (before applying
39      *                 the icp mask, if there is one)
40      * @param inIco    indicates if the bmp is embedded in an ico file
41      */
42     SkBmpStandardCodec(SkEncodedInfo&& info, std::unique_ptr<SkStream> stream,
43                        uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor,
44                        uint32_t offset, SkCodec::SkScanlineOrder rowOrder,
45                        bool isOpaque, bool inIco);
46 
47 protected:
48 
49     Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
50                        size_t dstRowBytes, const Options&,
51                        int*) override;
52 
onInIco()53     bool onInIco() const override {
54         return fInIco;
55     }
56 
57     SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo,
58             const SkCodec::Options& options) override;
59 
getSampler(bool createIfNecessary)60     SkSampler* getSampler(bool createIfNecessary) override {
61         SkASSERT(fSwizzler);
62         return fSwizzler.get();
63     }
64 
65 private:
66     bool createColorTable(SkColorType colorType, SkAlphaType alphaType);
67     SkEncodedInfo swizzlerInfo() const;
68     void initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts);
69 
70     int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
71             const Options& opts) override;
72 
73     /*
74      * @param stream This may be a pointer to the stream owned by the parent SkCodec
75      *               or a sub-stream of the stream owned by the parent SkCodec.
76      *               Either way, this stream is unowned.
77      */
78     void decodeIcoMask(SkStream* stream, const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes);
79 
80     sk_sp<SkColorTable>         fColorTable;
81     // fNumColors is the number specified in the header, or 0 if not present in the header.
82     const uint32_t              fNumColors;
83     const uint32_t              fBytesPerColor;
84     const uint32_t              fOffset;
85     std::unique_ptr<SkSwizzler> fSwizzler;
86     const bool                  fIsOpaque;
87     const bool                  fInIco;
88     const size_t                fAndMaskRowBytes; // only used for fInIco decodes
89 
90     typedef SkBmpBaseCodec INHERITED;
91 };
92 #endif  // SkBmpStandardCodec_DEFINED
93