Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: src/codec/SkMaskSwizzler.cpp

Issue 1557403002: Delete reallyHasAlpha() from SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkMaskSwizzler.h ('k') | src/codec/SkSampledCodec.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkMaskSwizzler.h" 10 #include "SkMaskSwizzler.h"
11 11
12 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_opaque( 12 static void swizzle_mask16_to_n32_opaque(
13 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 13 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
14 uint32_t startX, uint32_t sampleX) { 14 uint32_t startX, uint32_t sampleX) {
15 15
16 // Use the masks to decode to the destination 16 // Use the masks to decode to the destination
17 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 17 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
18 SkPMColor* dstPtr = (SkPMColor*) dstRow; 18 SkPMColor* dstPtr = (SkPMColor*) dstRow;
19 for (int i = 0; i < width; i++) { 19 for (int i = 0; i < width; i++) {
20 uint16_t p = srcPtr[0]; 20 uint16_t p = srcPtr[0];
21 uint8_t red = masks->getRed(p); 21 uint8_t red = masks->getRed(p);
22 uint8_t green = masks->getGreen(p); 22 uint8_t green = masks->getGreen(p);
23 uint8_t blue = masks->getBlue(p); 23 uint8_t blue = masks->getBlue(p);
24 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 24 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
25 srcPtr += sampleX; 25 srcPtr += sampleX;
26 } 26 }
27 return SkSwizzler::kOpaque_ResultAlpha;
28 } 27 }
29 28
30 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_unpremul( 29 static void swizzle_mask16_to_n32_unpremul(
31 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 30 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
32 uint32_t startX, uint32_t sampleX) { 31 uint32_t startX, uint32_t sampleX) {
33 32
34 // Use the masks to decode to the destination 33 // Use the masks to decode to the destination
35 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 34 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
36 SkPMColor* dstPtr = (SkPMColor*) dstRow; 35 SkPMColor* dstPtr = (SkPMColor*) dstRow;
37 INIT_RESULT_ALPHA;
38 for (int i = 0; i < width; i++) { 36 for (int i = 0; i < width; i++) {
39 uint16_t p = srcPtr[0]; 37 uint16_t p = srcPtr[0];
40 uint8_t red = masks->getRed(p); 38 uint8_t red = masks->getRed(p);
41 uint8_t green = masks->getGreen(p); 39 uint8_t green = masks->getGreen(p);
42 uint8_t blue = masks->getBlue(p); 40 uint8_t blue = masks->getBlue(p);
43 uint8_t alpha = masks->getAlpha(p); 41 uint8_t alpha = masks->getAlpha(p);
44 UPDATE_RESULT_ALPHA(alpha);
45 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 42 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
46 srcPtr += sampleX; 43 srcPtr += sampleX;
47 } 44 }
48 return COMPUTE_RESULT_ALPHA;
49 } 45 }
50 46
51 static SkSwizzler::ResultAlpha swizzle_mask16_to_n32_premul( 47 static void swizzle_mask16_to_n32_premul(
52 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 48 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
53 uint32_t startX, uint32_t sampleX) { 49 uint32_t startX, uint32_t sampleX) {
54 50
55 // Use the masks to decode to the destination 51 // Use the masks to decode to the destination
56 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 52 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
57 SkPMColor* dstPtr = (SkPMColor*) dstRow; 53 SkPMColor* dstPtr = (SkPMColor*) dstRow;
58 INIT_RESULT_ALPHA;
59 for (int i = 0; i < width; i++) { 54 for (int i = 0; i < width; i++) {
60 uint16_t p = srcPtr[0]; 55 uint16_t p = srcPtr[0];
61 uint8_t red = masks->getRed(p); 56 uint8_t red = masks->getRed(p);
62 uint8_t green = masks->getGreen(p); 57 uint8_t green = masks->getGreen(p);
63 uint8_t blue = masks->getBlue(p); 58 uint8_t blue = masks->getBlue(p);
64 uint8_t alpha = masks->getAlpha(p); 59 uint8_t alpha = masks->getAlpha(p);
65 UPDATE_RESULT_ALPHA(alpha);
66 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 60 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
67 srcPtr += sampleX; 61 srcPtr += sampleX;
68 } 62 }
69 return COMPUTE_RESULT_ALPHA;
70 } 63 }
71 64
72 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to 65 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to
73 // convert it back to 565. Instead, we should swizzle to 565 directly. 66 // convert it back to 565. Instead, we should swizzle to 565 directly.
74 static SkSwizzler::ResultAlpha swizzle_mask16_to_565( 67 static void swizzle_mask16_to_565(
75 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 68 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
76 uint32_t startX, uint32_t sampleX) { 69 uint32_t startX, uint32_t sampleX) {
77 70
78 // Use the masks to decode to the destination 71 // Use the masks to decode to the destination
79 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 72 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
80 uint16_t* dstPtr = (uint16_t*) dstRow; 73 uint16_t* dstPtr = (uint16_t*) dstRow;
81 for (int i = 0; i < width; i++) { 74 for (int i = 0; i < width; i++) {
82 uint16_t p = srcPtr[0]; 75 uint16_t p = srcPtr[0];
83 uint8_t red = masks->getRed(p); 76 uint8_t red = masks->getRed(p);
84 uint8_t green = masks->getGreen(p); 77 uint8_t green = masks->getGreen(p);
85 uint8_t blue = masks->getBlue(p); 78 uint8_t blue = masks->getBlue(p);
86 dstPtr[i] = SkPack888ToRGB16(red, green, blue); 79 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
87 srcPtr += sampleX; 80 srcPtr += sampleX;
88 } 81 }
89 return SkSwizzler::kOpaque_ResultAlpha;
90 } 82 }
91 83
92 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_opaque( 84 static void swizzle_mask24_to_n32_opaque(
93 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 85 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
94 uint32_t startX, uint32_t sampleX) { 86 uint32_t startX, uint32_t sampleX) {
95 87
96 // Use the masks to decode to the destination 88 // Use the masks to decode to the destination
97 srcRow += 3 * startX; 89 srcRow += 3 * startX;
98 SkPMColor* dstPtr = (SkPMColor*) dstRow; 90 SkPMColor* dstPtr = (SkPMColor*) dstRow;
99 for (int i = 0; i < width; i++) { 91 for (int i = 0; i < width; i++) {
100 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 92 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
101 uint8_t red = masks->getRed(p); 93 uint8_t red = masks->getRed(p);
102 uint8_t green = masks->getGreen(p); 94 uint8_t green = masks->getGreen(p);
103 uint8_t blue = masks->getBlue(p); 95 uint8_t blue = masks->getBlue(p);
104 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 96 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
105 srcRow += 3 * sampleX; 97 srcRow += 3 * sampleX;
106 } 98 }
107 return SkSwizzler::kOpaque_ResultAlpha;
108 } 99 }
109 100
110 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_unpremul( 101 static void swizzle_mask24_to_n32_unpremul(
111 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 102 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
112 uint32_t startX, uint32_t sampleX) { 103 uint32_t startX, uint32_t sampleX) {
113 104
114 // Use the masks to decode to the destination 105 // Use the masks to decode to the destination
115 srcRow += 3 * startX; 106 srcRow += 3 * startX;
116 SkPMColor* dstPtr = (SkPMColor*) dstRow; 107 SkPMColor* dstPtr = (SkPMColor*) dstRow;
117 INIT_RESULT_ALPHA;
118 for (int i = 0; i < width; i++) { 108 for (int i = 0; i < width; i++) {
119 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 109 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
120 uint8_t red = masks->getRed(p); 110 uint8_t red = masks->getRed(p);
121 uint8_t green = masks->getGreen(p); 111 uint8_t green = masks->getGreen(p);
122 uint8_t blue = masks->getBlue(p); 112 uint8_t blue = masks->getBlue(p);
123 uint8_t alpha = masks->getAlpha(p); 113 uint8_t alpha = masks->getAlpha(p);
124 UPDATE_RESULT_ALPHA(alpha);
125 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 114 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
126 srcRow += 3 * sampleX; 115 srcRow += 3 * sampleX;
127 } 116 }
128 return COMPUTE_RESULT_ALPHA;
129 } 117 }
130 118
131 static SkSwizzler::ResultAlpha swizzle_mask24_to_n32_premul( 119 static void swizzle_mask24_to_n32_premul(
132 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 120 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
133 uint32_t startX, uint32_t sampleX) { 121 uint32_t startX, uint32_t sampleX) {
134 122
135 // Use the masks to decode to the destination 123 // Use the masks to decode to the destination
136 srcRow += 3 * startX; 124 srcRow += 3 * startX;
137 SkPMColor* dstPtr = (SkPMColor*) dstRow; 125 SkPMColor* dstPtr = (SkPMColor*) dstRow;
138 INIT_RESULT_ALPHA;
139 for (int i = 0; i < width; i++) { 126 for (int i = 0; i < width; i++) {
140 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 127 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
141 uint8_t red = masks->getRed(p); 128 uint8_t red = masks->getRed(p);
142 uint8_t green = masks->getGreen(p); 129 uint8_t green = masks->getGreen(p);
143 uint8_t blue = masks->getBlue(p); 130 uint8_t blue = masks->getBlue(p);
144 uint8_t alpha = masks->getAlpha(p); 131 uint8_t alpha = masks->getAlpha(p);
145 UPDATE_RESULT_ALPHA(alpha);
146 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 132 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
147 srcRow += 3 * sampleX; 133 srcRow += 3 * sampleX;
148 } 134 }
149 return COMPUTE_RESULT_ALPHA;
150 } 135 }
151 136
152 static SkSwizzler::ResultAlpha swizzle_mask24_to_565( 137 static void swizzle_mask24_to_565(
153 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 138 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
154 uint32_t startX, uint32_t sampleX) { 139 uint32_t startX, uint32_t sampleX) {
155 140
156 // Use the masks to decode to the destination 141 // Use the masks to decode to the destination
157 srcRow += 3 * startX; 142 srcRow += 3 * startX;
158 uint16_t* dstPtr = (uint16_t*) dstRow; 143 uint16_t* dstPtr = (uint16_t*) dstRow;
159 for (int i = 0; i < width; i++) { 144 for (int i = 0; i < width; i++) {
160 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 145 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
161 uint8_t red = masks->getRed(p); 146 uint8_t red = masks->getRed(p);
162 uint8_t green = masks->getGreen(p); 147 uint8_t green = masks->getGreen(p);
163 uint8_t blue = masks->getBlue(p); 148 uint8_t blue = masks->getBlue(p);
164 dstPtr[i] = SkPack888ToRGB16(red, green, blue); 149 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
165 srcRow += 3 * sampleX; 150 srcRow += 3 * sampleX;
166 } 151 }
167 return SkSwizzler::kOpaque_ResultAlpha;
168 } 152 }
169 153
170 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_opaque( 154 static void swizzle_mask32_to_n32_opaque(
171 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 155 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
172 uint32_t startX, uint32_t sampleX) { 156 uint32_t startX, uint32_t sampleX) {
173 157
174 // Use the masks to decode to the destination 158 // Use the masks to decode to the destination
175 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 159 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
176 SkPMColor* dstPtr = (SkPMColor*) dstRow; 160 SkPMColor* dstPtr = (SkPMColor*) dstRow;
177 for (int i = 0; i < width; i++) { 161 for (int i = 0; i < width; i++) {
178 uint32_t p = srcPtr[0]; 162 uint32_t p = srcPtr[0];
179 uint8_t red = masks->getRed(p); 163 uint8_t red = masks->getRed(p);
180 uint8_t green = masks->getGreen(p); 164 uint8_t green = masks->getGreen(p);
181 uint8_t blue = masks->getBlue(p); 165 uint8_t blue = masks->getBlue(p);
182 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 166 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
183 srcPtr += sampleX; 167 srcPtr += sampleX;
184 } 168 }
185 return SkSwizzler::kOpaque_ResultAlpha;
186 } 169 }
187 170
188 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_unpremul( 171 static void swizzle_mask32_to_n32_unpremul(
189 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 172 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
190 uint32_t startX, uint32_t sampleX) { 173 uint32_t startX, uint32_t sampleX) {
191 174
192 // Use the masks to decode to the destination 175 // Use the masks to decode to the destination
193 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 176 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
194 SkPMColor* dstPtr = (SkPMColor*) dstRow; 177 SkPMColor* dstPtr = (SkPMColor*) dstRow;
195 INIT_RESULT_ALPHA;
196 for (int i = 0; i < width; i++) { 178 for (int i = 0; i < width; i++) {
197 uint32_t p = srcPtr[0]; 179 uint32_t p = srcPtr[0];
198 uint8_t red = masks->getRed(p); 180 uint8_t red = masks->getRed(p);
199 uint8_t green = masks->getGreen(p); 181 uint8_t green = masks->getGreen(p);
200 uint8_t blue = masks->getBlue(p); 182 uint8_t blue = masks->getBlue(p);
201 uint8_t alpha = masks->getAlpha(p); 183 uint8_t alpha = masks->getAlpha(p);
202 UPDATE_RESULT_ALPHA(alpha);
203 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 184 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
204 srcPtr += sampleX; 185 srcPtr += sampleX;
205 } 186 }
206 return COMPUTE_RESULT_ALPHA;
207 } 187 }
208 188
209 static SkSwizzler::ResultAlpha swizzle_mask32_to_n32_premul( 189 static void swizzle_mask32_to_n32_premul(
210 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 190 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
211 uint32_t startX, uint32_t sampleX) { 191 uint32_t startX, uint32_t sampleX) {
212 192
213 // Use the masks to decode to the destination 193 // Use the masks to decode to the destination
214 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 194 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
215 SkPMColor* dstPtr = (SkPMColor*) dstRow; 195 SkPMColor* dstPtr = (SkPMColor*) dstRow;
216 INIT_RESULT_ALPHA;
217 for (int i = 0; i < width; i++) { 196 for (int i = 0; i < width; i++) {
218 uint32_t p = srcPtr[0]; 197 uint32_t p = srcPtr[0];
219 uint8_t red = masks->getRed(p); 198 uint8_t red = masks->getRed(p);
220 uint8_t green = masks->getGreen(p); 199 uint8_t green = masks->getGreen(p);
221 uint8_t blue = masks->getBlue(p); 200 uint8_t blue = masks->getBlue(p);
222 uint8_t alpha = masks->getAlpha(p); 201 uint8_t alpha = masks->getAlpha(p);
223 UPDATE_RESULT_ALPHA(alpha);
224 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 202 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
225 srcPtr += sampleX; 203 srcPtr += sampleX;
226 } 204 }
227 return COMPUTE_RESULT_ALPHA;
228 } 205 }
229 206
230 static SkSwizzler::ResultAlpha swizzle_mask32_to_565( 207 static void swizzle_mask32_to_565(
231 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 208 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
232 uint32_t startX, uint32_t sampleX) { 209 uint32_t startX, uint32_t sampleX) {
233 // Use the masks to decode to the destination 210 // Use the masks to decode to the destination
234 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 211 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
235 uint16_t* dstPtr = (uint16_t*) dstRow; 212 uint16_t* dstPtr = (uint16_t*) dstRow;
236 for (int i = 0; i < width; i++) { 213 for (int i = 0; i < width; i++) {
237 uint32_t p = srcPtr[0]; 214 uint32_t p = srcPtr[0];
238 uint8_t red = masks->getRed(p); 215 uint8_t red = masks->getRed(p);
239 uint8_t green = masks->getGreen(p); 216 uint8_t green = masks->getGreen(p);
240 uint8_t blue = masks->getBlue(p); 217 uint8_t blue = masks->getBlue(p);
241 dstPtr[i] = SkPack888ToRGB16(red, green, blue); 218 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
242 srcPtr += sampleX; 219 srcPtr += sampleX;
243 } 220 }
244 return SkSwizzler::kOpaque_ResultAlpha;
245 } 221 }
246 222
247 /* 223 /*
248 * 224 *
249 * Create a new mask swizzler 225 * Create a new mask swizzler
250 * 226 *
251 */ 227 */
252 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo, 228 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
253 const SkImageInfo& srcInfo, SkMasks* masks, uint32_t bitsPerPixel, 229 const SkImageInfo& srcInfo, SkMasks* masks, uint32_t bitsPerPixel,
254 const SkCodec::Options& options) { 230 const SkCodec::Options& options) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // check that fX0 is valid 363 // check that fX0 is valid
388 SkASSERT(fX0 >= 0); 364 SkASSERT(fX0 >= 0);
389 return fDstWidth; 365 return fDstWidth;
390 } 366 }
391 367
392 /* 368 /*
393 * 369 *
394 * Swizzle the specified row 370 * Swizzle the specified row
395 * 371 *
396 */ 372 */
397 SkSwizzler::ResultAlpha SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RES TRICT src) { 373 void SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
398 SkASSERT(nullptr != dst && nullptr != src); 374 SkASSERT(nullptr != dst && nullptr != src);
399 return fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX); 375 fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX);
400 } 376 }
OLDNEW
« no previous file with comments | « src/codec/SkMaskSwizzler.h ('k') | src/codec/SkSampledCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698