xref: /aosp_15_r20/external/skia/src/codec/SkMaskSwizzler.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 "include/codec/SkCodec.h"
11  #include "include/core/SkTypes.h"
12  #include "src/codec/SkSampler.h"
13  
14  #include <cstdint>
15  
16  class SkMasks;
17  struct SkImageInfo;
18  
19  /*
20   *
21   * Used to swizzle images whose pixel components are extracted by bit masks
22   * Currently only used by bmp
23   *
24   */
25  class SkMaskSwizzler : public SkSampler {
26  public:
27  
28      /*
29       * @param masks Unowned pointer to helper class
30       */
31      static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo,
32                                                bool srcIsOpaque,
33                                                SkMasks* masks,
34                                                uint32_t bitsPerPixel,
35                                                const SkCodec::Options& options);
36  
37      /*
38       * Swizzle a row
39       */
40      void swizzle(void* dst, const uint8_t* SK_RESTRICT src);
41  
fillWidth()42      int fillWidth() const override {
43          return fDstWidth;
44      }
45  
46      /**
47       *  Returns the byte offset at which we write to destination memory, taking
48       *  scaling, subsetting, and partial frames into account.
49       *  A similar function exists on SkSwizzler.
50       */
swizzleWidth()51      int swizzleWidth() const { return fDstWidth; }
52  
53  private:
54  
55      /*
56       * Row procedure used for swizzle
57       */
58      typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
59              SkMasks* masks, uint32_t startX, uint32_t sampleX);
60  
61      SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
62  
63      int onSetSampleX(int) override;
64  
65      SkMasks*        fMasks;           // unowned
66      const RowProc   fRowProc;
67  
68      // FIXME: Can this class share more with SkSwizzler? These variables are all the same.
69      const int       fSubsetWidth;     // Width of the subset of source before any sampling.
70      int             fDstWidth;        // Width of dst, which may differ with sampling.
71      int             fSampleX;
72      int             fSrcOffset;
73      int             fX0;
74  };
75  
76  #endif
77