msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 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 | */ |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 7 | #ifndef SkMaskSwizzler_DEFINED |
| 8 | #define SkMaskSwizzler_DEFINED |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 9 | |
| 10 | #include "SkMasks.h" |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 11 | #include "SkSampler.h" |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 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 | */ |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 21 | class SkMaskSwizzler : public SkSampler { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 22 | public: |
| 23 | |
| 24 | /* |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 25 | * Create a new swizzler |
| 26 | * @param masks Unowned pointer to helper class |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 27 | */ |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 28 | static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo, |
| 29 | const SkImageInfo& srcInfo, |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 30 | SkMasks* masks, |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 31 | uint32_t bitsPerPixel, |
| 32 | const SkCodec::Options& options); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 33 | |
| 34 | /* |
msarett | 614aa07 | 2015-07-27 15:13:17 -0700 | [diff] [blame] | 35 | * Swizzle a row |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 36 | */ |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 37 | void swizzle(void* dst, const uint8_t* SK_RESTRICT src); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 38 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Implement fill using a custom width. |
| 41 | */ |
| 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 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 48 | private: |
| 49 | |
| 50 | /* |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 51 | * Row procedure used for swizzle |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 52 | */ |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 53 | typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width, |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 54 | SkMasks* masks, uint32_t startX, uint32_t sampleX); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 55 | |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 56 | SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 57 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 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. |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 64 | const int fSubsetWidth; // Width of the subset of source before any sampling. |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 65 | int fDstWidth; // Width of dst, which may differ with sampling. |
| 66 | int fSampleX; |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 67 | int fSrcOffset; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 68 | int fX0; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 69 | }; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 70 | |
| 71 | #endif |