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 #include "SkMasks.h"
9 #include "SkSwizzler.h"
10 #include "SkTypes.h"
11 
12 /*
13  *
14  * Used to swizzle images whose pixel components are extracted by bit masks
15  * Currently only used by bmp
16  *
17  */
18 class SkMaskSwizzler {
19 public:
20 
21     /*
22      *
23      * Create a new swizzler
24      * @param masks Unowned pointer to helper class
25      *
26      */
27     static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& imageInfo,
28                                               void* dst, size_t dstRowBytes,
29                                               SkMasks* masks,
30                                               uint32_t bitsPerPixel);
31 
32     /*
33      *
34      * Swizzle the row with the specified y value
35      *
36      */
37     SkSwizzler::ResultAlpha next(const uint8_t* SK_RESTRICT src, int y);
38 
39 private:
40 
41     /*
42      *
43      * Row procedure used for swizzle
44      *
45      */
46     typedef SkSwizzler::ResultAlpha (*RowProc)(
47             void* dstRow, const uint8_t* srcRow, int width,
48             SkMasks* masks);
49 
50     /*
51      *
52      * Constructor for mask swizzler
53      *
54      */
55     SkMaskSwizzler(const SkImageInfo& info, void* dst, size_t dstRowBytes,
56             SkMasks* masks, RowProc proc);
57 
58     // Fields
59     const SkImageInfo& fDstInfo;
60     void*              fDst;
61     size_t             fDstRowBytes;
62     SkMasks*           fMasks;       // unowned
63     const RowProc      fRowProc;
64 };
65