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 | */ |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 42 | void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint64_t colorOrIndex, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 43 | SkCodec::ZeroInitialized zeroInit) override { |
| 44 | const SkImageInfo fillInfo = info.makeWH(fDstWidth, info.height()); |
| 45 | SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit); |
| 46 | } |
| 47 | |
Matt Sarett | 1b96c6f | 2016-11-03 16:15:20 -0400 | [diff] [blame] | 48 | /** |
| 49 | * Returns the byte offset at which we write to destination memory, taking |
| 50 | * scaling, subsetting, and partial frames into account. |
| 51 | * A similar function exists on SkSwizzler. |
| 52 | */ |
| 53 | int swizzleWidth() const { return fDstWidth; } |
| 54 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 55 | private: |
| 56 | |
| 57 | /* |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 58 | * Row procedure used for swizzle |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 59 | */ |
msarett | a4970dc | 2016-01-11 07:23:23 -0800 | [diff] [blame] | 60 | typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width, |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 61 | SkMasks* masks, uint32_t startX, uint32_t sampleX); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 62 | |
msarett | 80803ff | 2015-10-16 10:54:12 -0700 | [diff] [blame] | 63 | SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 64 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 65 | int onSetSampleX(int) override; |
| 66 | |
| 67 | SkMasks* fMasks; // unowned |
| 68 | const RowProc fRowProc; |
| 69 | |
| 70 | // 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] | 71 | const int fSubsetWidth; // Width of the subset of source before any sampling. |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 72 | int fDstWidth; // Width of dst, which may differ with sampling. |
| 73 | int fSampleX; |
msarett | fdb4757 | 2015-10-13 12:50:14 -0700 | [diff] [blame] | 74 | int fSrcOffset; |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 75 | int fX0; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 76 | }; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 77 | |
| 78 | #endif |