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 8 #ifndef SkBmpMaskCodec_DEFINED 9 #define SkBmpMaskCodec_DEFINED 10 11 #include "include/codec/SkCodec.h" 12 #include "include/core/SkTypes.h" 13 #include "src/codec/SkBmpBaseCodec.h" 14 #include "src/codec/SkMaskSwizzler.h" 15 #include "src/core/SkMasks.h" 16 17 #include <cstddef> 18 #include <cstdint> 19 #include <memory> 20 21 class SkSampler; 22 class SkStream; 23 struct SkEncodedInfo; 24 struct SkImageInfo; 25 26 /* 27 * This class implements the decoding for bmp images using bit masks 28 */ 29 class SkBmpMaskCodec : public SkBmpBaseCodec { 30 public: 31 32 /* 33 * Creates an instance of the decoder 34 * 35 * Called only by SkBmpCodec::MakeFromStream 36 * There should be no other callers despite this being public 37 * 38 * @param info contains properties of the encoded data 39 * @param stream the stream of encoded image data 40 * @param bitsPerPixel the number of bits used to store each pixel 41 * @param masks color masks for certain bmp formats 42 * @param rowOrder indicates whether rows are ordered top-down or bottom-up 43 */ 44 SkBmpMaskCodec(SkEncodedInfo&& info, std::unique_ptr<SkStream>, 45 uint16_t bitsPerPixel, SkMasks* masks, 46 SkCodec::SkScanlineOrder rowOrder); 47 48 protected: 49 50 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, 51 size_t dstRowBytes, const Options&, 52 int*) override; 53 54 SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo, 55 const SkCodec::Options& options) override; 56 57 private: 58 getSampler(bool createIfNecessary)59 SkSampler* getSampler(bool createIfNecessary) override { 60 SkASSERT(fMaskSwizzler); 61 return fMaskSwizzler.get(); 62 } 63 64 int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, 65 const Options& opts) override; 66 67 std::unique_ptr<SkMasks> fMasks; 68 std::unique_ptr<SkMaskSwizzler> fMaskSwizzler; 69 70 using INHERITED = SkBmpBaseCodec; 71 }; 72 #endif // SkBmpMaskCodec_DEFINED 73