| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkSwizzler_DEFINED | 8 #ifndef SkSwizzler_DEFINED |
| 9 #define SkSwizzler_DEFINED | 9 #define SkSwizzler_DEFINED |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 kRGBX, | 31 kRGBX, |
| 32 kBGRX, | 32 kBGRX, |
| 33 kRGBA, | 33 kRGBA, |
| 34 kBGRA, | 34 kBGRA, |
| 35 kRGB_565, | 35 kRGB_565, |
| 36 kCMYK, | 36 kCMYK, |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 /* | 39 /* |
| 40 * | 40 * |
| 41 * Result code for the alpha components of a row. | |
| 42 * | |
| 43 */ | |
| 44 typedef uint16_t ResultAlpha; | |
| 45 static const ResultAlpha kOpaque_ResultAlpha = 0xFFFF; | |
| 46 static const ResultAlpha kTransparent_ResultAlpha = 0x0000; | |
| 47 | |
| 48 /* | |
| 49 * | |
| 50 * Checks if the result of decoding a row indicates that the row was | |
| 51 * transparent. | |
| 52 * | |
| 53 */ | |
| 54 static bool IsTransparent(ResultAlpha r) { | |
| 55 return kTransparent_ResultAlpha == r; | |
| 56 } | |
| 57 | |
| 58 /* | |
| 59 * | |
| 60 * Checks if the result of decoding a row indicates that the row was | |
| 61 * opaque. | |
| 62 * | |
| 63 */ | |
| 64 static bool IsOpaque(ResultAlpha r) { | |
| 65 return kOpaque_ResultAlpha == r; | |
| 66 } | |
| 67 | |
| 68 /* | |
| 69 * | |
| 70 * Constructs the proper result code based on accumulated alpha masks | |
| 71 * | |
| 72 */ | |
| 73 static ResultAlpha GetResult(uint8_t zeroAlpha, uint8_t maxAlpha); | |
| 74 | |
| 75 /* | |
| 76 * | |
| 77 * Returns bits per pixel for source config | 41 * Returns bits per pixel for source config |
| 78 * | 42 * |
| 79 */ | 43 */ |
| 80 static int BitsPerPixel(SrcConfig sc) { | 44 static int BitsPerPixel(SrcConfig sc) { |
| 81 switch (sc) { | 45 switch (sc) { |
| 82 case kBit: | 46 case kBit: |
| 83 case kIndex1: | 47 case kIndex1: |
| 84 return 1; | 48 return 1; |
| 85 case kIndex2: | 49 case kIndex2: |
| 86 return 2; | 50 return 2; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 106 |
| 143 /** | 107 /** |
| 144 * Swizzle a line. Generally this will be called height times, once | 108 * Swizzle a line. Generally this will be called height times, once |
| 145 * for each row of source. | 109 * for each row of source. |
| 146 * By allowing the caller to pass in the dst pointer, we give the caller | 110 * By allowing the caller to pass in the dst pointer, we give the caller |
| 147 * flexibility to use the swizzler even when the encoded data does not | 111 * flexibility to use the swizzler even when the encoded data does not |
| 148 * store the rows in order. This also improves usability for scaled and | 112 * store the rows in order. This also improves usability for scaled and |
| 149 * subset decodes. | 113 * subset decodes. |
| 150 * @param dst Where we write the output. | 114 * @param dst Where we write the output. |
| 151 * @param src The next row of the source data. | 115 * @param src The next row of the source data. |
| 152 * @return A result code describing if the row was fully opaque, fully | |
| 153 * transparent, or neither | |
| 154 */ | 116 */ |
| 155 ResultAlpha swizzle(void* dst, const uint8_t* SK_RESTRICT src); | 117 void swizzle(void* dst, const uint8_t* SK_RESTRICT src); |
| 156 | 118 |
| 157 /** | 119 /** |
| 158 * Implement fill using a custom width. | 120 * Implement fill using a custom width. |
| 159 */ | 121 */ |
| 160 void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint32_t colo
rOrIndex, | 122 void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint32_t colo
rOrIndex, |
| 161 SkCodec::ZeroInitialized zeroInit) override { | 123 SkCodec::ZeroInitialized zeroInit) override { |
| 162 const SkImageInfo fillInfo = info.makeWH(fAllocatedWidth, info.height())
; | 124 const SkImageInfo fillInfo = info.makeWH(fAllocatedWidth, info.height())
; |
| 163 SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit); | 125 SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit); |
| 164 } | 126 } |
| 165 | 127 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 180 * @param dstRow Row in which to write the resulting pixels. | 142 * @param dstRow Row in which to write the resulting pixels. |
| 181 * @param src Row of src data, in format specified by SrcConfig | 143 * @param src Row of src data, in format specified by SrcConfig |
| 182 * @param dstWidth Width in pixels of the destination | 144 * @param dstWidth Width in pixels of the destination |
| 183 * @param bpp if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel | 145 * @param bpp if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel |
| 184 * else, deltaSrc is bitsPerPixel | 146 * else, deltaSrc is bitsPerPixel |
| 185 * @param deltaSrc bpp * sampleX | 147 * @param deltaSrc bpp * sampleX |
| 186 * @param ctable Colors (used for kIndex source). | 148 * @param ctable Colors (used for kIndex source). |
| 187 * @param offset The offset before the first pixel to sample. | 149 * @param offset The offset before the first pixel to sample. |
| 188 Is in bytes or bits based on what deltaSrc is in. | 150 Is in bytes or bits based on what deltaSrc is in. |
| 189 */ | 151 */ |
| 190 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow, | 152 typedef void (*RowProc)(void* SK_RESTRICT dstRow, |
| 191 const uint8_t* SK_RESTRICT src, | 153 const uint8_t* SK_RESTRICT src, |
| 192 int dstWidth, int bpp, int deltaSrc, int offs
et, | 154 int dstWidth, int bpp, int deltaSrc, int offset, |
| 193 const SkPMColor ctable[]); | 155 const SkPMColor ctable[]); |
| 194 | 156 |
| 195 const RowProc fRowProc; | 157 const RowProc fRowProc; |
| 196 const SkPMColor* fColorTable; // Unowned pointer | 158 const SkPMColor* fColorTable; // Unowned pointer |
| 197 | 159 |
| 198 // Subset Swizzles | 160 // Subset Swizzles |
| 199 // There are two types of subset swizzles that we support. We do not | 161 // There are two types of subset swizzles that we support. We do not |
| 200 // support both at the same time. | 162 // support both at the same time. |
| 201 // TODO: If we want to support partial scanlines for gifs (which may | 163 // TODO: If we want to support partial scanlines for gifs (which may |
| 202 // use frame subsets), we will need to support both subsetting | 164 // use frame subsets), we will need to support both subsetting |
| 203 // modes at the same time. | 165 // modes at the same time. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // fBPP is bitsPerPixel | 241 // fBPP is bitsPerPixel |
| 280 const int fDstBPP; // Bytes per pixel for the destination
color type | 242 const int fDstBPP; // Bytes per pixel for the destination
color type |
| 281 | 243 |
| 282 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidt
h, int dstOffset, | 244 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidt
h, int dstOffset, |
| 283 int dstWidth, int srcBPP, int dstBPP); | 245 int dstWidth, int srcBPP, int dstBPP); |
| 284 | 246 |
| 285 int onSetSampleX(int) override; | 247 int onSetSampleX(int) override; |
| 286 | 248 |
| 287 }; | 249 }; |
| 288 #endif // SkSwizzler_DEFINED | 250 #endif // SkSwizzler_DEFINED |
| OLD | NEW |