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