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 | * @param masks Unowned pointer to helper class |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 26 | */ |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 27 | static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo, |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 28 | bool srcIsOpaque, |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 29 | SkMasks* masks, |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 30 | uint32_t bitsPerPixel, |
| 31 | const SkCodec::Options& options); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
msarett | 614aa07 | 2015-07-27 15:13:17 -0700 | [diff] [blame] | 34 | * Swizzle a row |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 35 | */ |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 36 | void swizzle(void* dst, const uint8_t* SK_RESTRICT src); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 37 | |
Leon Scroggins III | a6161b1 | 2018-10-18 14:45:26 -0400 | [diff] [blame] | 38 | int fillWidth() const override { |
| 39 | return fDstWidth; |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Matt Sarett | 1b96c6f | 2016-11-03 16:15:20 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Returns the byte offset at which we write to destination memory, taking |
| 44 | * scaling, subsetting, and partial frames into account. |
| 45 | * A similar function exists on SkSwizzler. |
| 46 | */ |
| 47 | int swizzleWidth() const { return fDstWidth; } |
| 48 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 49 | private: |
| 50 | |
| 51 | /* |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 52 | * Row procedure used for swizzle |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 53 | */ |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 54 | typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width, |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 55 | SkMasks* masks, uint32_t startX, uint32_t sampleX); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 56 | |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 57 | SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 58 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 59 | int onSetSampleX(int) override; |
| 60 | |
| 61 | SkMasks* fMasks; // unowned |
| 62 | const RowProc fRowProc; |
| 63 | |
| 64 | // 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] | 65 | const int fSubsetWidth; // Width of the subset of source before any sampling. |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 66 | int fDstWidth; // Width of dst, which may differ with sampling. |
| 67 | int fSampleX; |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 68 | int fSrcOffset; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 69 | int fX0; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 70 | }; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 71 | |
| 72 | #endif |