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