• 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 SkMaskSwizzler_DEFINED
8  #define SkMaskSwizzler_DEFINED
9  
10  #include "SkMasks.h"
11  #include "SkSampler.h"
12  #include "SkSwizzler.h"
13  #include "SkTypes.h"
14  
15  /*
16   *
17   * Used to swizzle images whose pixel components are extracted by bit masks
18   * Currently only used by bmp
19   *
20   */
21  class SkMaskSwizzler : public SkSampler {
22  public:
23  
24      /*
25       * Create a new swizzler
26       * @param masks Unowned pointer to helper class
27       */
28      static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo,
29                                                const SkImageInfo& srcInfo,
30                                                SkMasks* masks,
31                                                uint32_t bitsPerPixel,
32                                                const SkCodec::Options& options);
33  
34      /*
35       * Swizzle a row
36       */
37      void swizzle(void* dst, const uint8_t* SK_RESTRICT src);
38  
39      /**
40       * Implement fill using a custom width.
41       */
fill(const SkImageInfo & info,void * dst,size_t rowBytes,uint32_t colorOrIndex,SkCodec::ZeroInitialized zeroInit)42      void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint32_t colorOrIndex,
43              SkCodec::ZeroInitialized zeroInit) override {
44          const SkImageInfo fillInfo = info.makeWH(fDstWidth, info.height());
45          SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit);
46      }
47  
48  private:
49  
50      /*
51       * Row procedure used for swizzle
52       */
53      typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
54              SkMasks* masks, uint32_t startX, uint32_t sampleX);
55  
56      SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
57  
58      int onSetSampleX(int) override;
59  
60      SkMasks*        fMasks;           // unowned
61      const RowProc   fRowProc;
62  
63      // FIXME: Can this class share more with SkSwizzler? These variables are all the same.
64      const int       fSubsetWidth;     // Width of the subset of source before any sampling.
65      int             fDstWidth;        // Width of dst, which may differ with sampling.
66      int             fSampleX;
67      int             fSrcOffset;
68      int             fX0;
69  };
70  
71  #endif
72