OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 // these are in the same order as the SkBitmap::Config enum | 15 // these are in the same order as the SkColorType enum |
16 static const char* gConfigName[] = { | 16 static const char* gConfigName[] = { |
17 "None", "A8", "Index8", "565", "4444", "8888" | 17 "Unknown", "Alpha8", "565", "4444", "RGBA", "BGRA", "Index8" |
18 }; | 18 }; |
19 | 19 |
20 /** Returns -1 on success, else the x coord of the first bad pixel, return its | 20 /** Returns -1 on success, else the x coord of the first bad pixel, return its |
21 value in bad | 21 value in bad |
22 */ | 22 */ |
23 typedef int (*Proc)(const void*, int width, uint32_t expected, uint32_t* bad); | 23 typedef int (*Proc)(const void*, int width, uint32_t expected, uint32_t* bad); |
24 | 24 |
25 static int proc_32(const void* ptr, int w, uint32_t expected, uint32_t* bad) { | 25 static int proc_32(const void* ptr, int w, uint32_t expected, uint32_t* bad) { |
26 const SkPMColor* addr = static_cast<const SkPMColor*>(ptr); | 26 const SkPMColor* addr = static_cast<const SkPMColor*>(ptr); |
27 for (int x = 0; x < w; x++) { | 27 for (int x = 0; x < w; x++) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 return false; | 93 return false; |
94 } | 94 } |
95 } | 95 } |
96 return true; | 96 return true; |
97 } | 97 } |
98 | 98 |
99 // Make sure our blits always map src==0 to a noop, and src==FF to full opaque | 99 // Make sure our blits always map src==0 to a noop, and src==FF to full opaque |
100 static void test_00_FF(skiatest::Reporter* reporter) { | 100 static void test_00_FF(skiatest::Reporter* reporter) { |
101 static const int W = 256; | 101 static const int W = 256; |
102 | 102 |
103 static const SkBitmap::Config gDstConfig[] = { | 103 static const SkColorType gDstColorType[] = { |
104 SkBitmap::kARGB_8888_Config, | 104 kPMColor_SkColorType, |
105 SkBitmap::kRGB_565_Config, | 105 kRGB_565_SkColorType, |
106 // SkBitmap::kARGB_4444_Config, | |
107 // SkBitmap::kA8_Config, | |
108 }; | 106 }; |
109 | 107 |
110 static const struct { | 108 static const struct { |
111 SkColor fSrc; | 109 SkColor fSrc; |
112 SkColor fDst; | 110 SkColor fDst; |
113 SkPMColor fResult32; | 111 SkPMColor fResult32; |
114 uint16_t fResult16; | 112 uint16_t fResult16; |
115 uint8_t fResult8; | 113 uint8_t fResult8; |
116 } gSrcRec[] = { | 114 } gSrcRec[] = { |
117 { 0, 0, 0, 0,
0 }, | 115 { 0, 0, 0, 0,
0 }, |
118 { 0, 0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF
, 0xFF }, | 116 { 0, 0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF
, 0xFF }, |
119 { 0xFFFFFFFF, 0, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF
, 0xFF }, | 117 { 0xFFFFFFFF, 0, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF
, 0xFF }, |
120 { 0xFFFFFFFF, 0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF
, 0xFF }, | 118 { 0xFFFFFFFF, 0xFFFFFFFF, SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF), 0xFFFF
, 0xFF }, |
121 }; | 119 }; |
122 | 120 |
123 SkPaint paint; | 121 SkPaint paint; |
124 | 122 |
125 SkBitmap srcBM; | 123 SkBitmap srcBM; |
126 srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, 1); | 124 srcBM.allocN32Pixels(W, 1); |
127 srcBM.allocPixels(); | |
128 | 125 |
129 for (size_t i = 0; i < SK_ARRAY_COUNT(gDstConfig); i++) { | 126 for (size_t i = 0; i < SK_ARRAY_COUNT(gDstColorType); i++) { |
| 127 SkImageInfo info = SkImageInfo::Make(W, 1, gDstColorType[i], |
| 128 kPremul_SkAlphaType); |
130 SkBitmap dstBM; | 129 SkBitmap dstBM; |
131 dstBM.setConfig(gDstConfig[i], W, 1); | 130 dstBM.allocPixels(info); |
132 dstBM.allocPixels(); | |
133 | 131 |
134 SkCanvas canvas(dstBM); | 132 SkCanvas canvas(dstBM); |
135 for (size_t j = 0; j < SK_ARRAY_COUNT(gSrcRec); j++) { | 133 for (size_t j = 0; j < SK_ARRAY_COUNT(gSrcRec); j++) { |
136 srcBM.eraseColor(gSrcRec[j].fSrc); | 134 srcBM.eraseColor(gSrcRec[j].fSrc); |
137 dstBM.eraseColor(gSrcRec[j].fDst); | 135 dstBM.eraseColor(gSrcRec[j].fDst); |
138 | 136 |
139 for (int k = 0; k < 4; k++) { | 137 for (int k = 0; k < 4; k++) { |
140 bool dither = (k & 1) != 0; | 138 bool dither = (k & 1) != 0; |
141 bool blend = (k & 2) != 0; | 139 bool blend = (k & 2) != 0; |
142 if (gSrcRec[j].fSrc != 0 && blend) { | 140 if (gSrcRec[j].fSrc != 0 && blend) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 184 } |
187 | 185 |
188 static bool gOnce; | 186 static bool gOnce; |
189 | 187 |
190 // Make sure our blits are invariant with the width of the blit (i.e. that | 188 // Make sure our blits are invariant with the width of the blit (i.e. that |
191 // special case for 8 at a time have the same results as narrower blits) | 189 // special case for 8 at a time have the same results as narrower blits) |
192 static void test_diagonal(skiatest::Reporter* reporter) { | 190 static void test_diagonal(skiatest::Reporter* reporter) { |
193 static const int W = 64; | 191 static const int W = 64; |
194 static const int H = W; | 192 static const int H = W; |
195 | 193 |
196 static const SkBitmap::Config gDstConfig[] = { | 194 static const SkColorType gDstColorType[] = { |
197 SkBitmap::kARGB_8888_Config, | 195 kPMColor_SkColorType, |
198 SkBitmap::kRGB_565_Config, | 196 kRGB_565_SkColorType, |
199 // SkBitmap::kARGB_4444_Config, | |
200 // SkBitmap::kA8_Config, | |
201 }; | 197 }; |
202 | 198 |
203 static const SkColor gDstBG[] = { 0, 0xFFFFFFFF }; | 199 static const SkColor gDstBG[] = { 0, 0xFFFFFFFF }; |
204 | 200 |
205 SkPaint paint; | 201 SkPaint paint; |
206 | 202 |
207 SkBitmap srcBM; | 203 SkBitmap srcBM; |
208 srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, H); | 204 srcBM.allocN32Pixels(W, H); |
209 srcBM.allocPixels(); | |
210 SkRect srcR = { | 205 SkRect srcR = { |
211 0, 0, SkIntToScalar(srcBM.width()), SkIntToScalar(srcBM.height()) }; | 206 0, 0, SkIntToScalar(srcBM.width()), SkIntToScalar(srcBM.height()) }; |
212 | 207 |
213 // cons up a mesh to draw the bitmap with | 208 // cons up a mesh to draw the bitmap with |
214 Mesh mesh(srcBM, &paint); | 209 Mesh mesh(srcBM, &paint); |
215 | 210 |
216 for (size_t i = 0; i < SK_ARRAY_COUNT(gDstConfig); i++) { | 211 SkImageInfo info = SkImageInfo::Make(W, H, kUnknown_SkColorType, |
| 212 kPremul_SkAlphaType); |
| 213 |
| 214 for (size_t i = 0; i < SK_ARRAY_COUNT(gDstColorType); i++) { |
| 215 info.fColorType = gDstColorType[i]; |
| 216 |
217 SkBitmap dstBM0, dstBM1; | 217 SkBitmap dstBM0, dstBM1; |
218 dstBM0.setConfig(gDstConfig[i], W, H); | 218 dstBM0.allocPixels(info); |
219 dstBM1.setConfig(gDstConfig[i], W, H); | 219 dstBM1.allocPixels(info); |
220 dstBM0.allocPixels(); | |
221 dstBM1.allocPixels(); | |
222 | 220 |
223 SkCanvas canvas0(dstBM0); | 221 SkCanvas canvas0(dstBM0); |
224 SkCanvas canvas1(dstBM1); | 222 SkCanvas canvas1(dstBM1); |
225 SkColor bgColor; | 223 SkColor bgColor; |
226 | 224 |
227 for (size_t j = 0; j < SK_ARRAY_COUNT(gDstBG); j++) { | 225 for (size_t j = 0; j < SK_ARRAY_COUNT(gDstBG); j++) { |
228 bgColor = gDstBG[j]; | 226 bgColor = gDstBG[j]; |
229 | 227 |
230 for (int c = 0; c <= 0xFF; c++) { | 228 for (int c = 0; c <= 0xFF; c++) { |
231 srcBM.eraseARGB(0xFF, c, c, c); | 229 srcBM.eraseARGB(0xFF, c, c, c); |
(...skipping 10 matching lines...) Expand all Loading... |
242 canvas0.drawRect(srcR, paint); | 240 canvas0.drawRect(srcR, paint); |
243 mesh.draw(&canvas1, &paint); | 241 mesh.draw(&canvas1, &paint); |
244 | 242 |
245 if (!gOnce && false) { | 243 if (!gOnce && false) { |
246 save_bm(dstBM0, "drawBitmap.png"); | 244 save_bm(dstBM0, "drawBitmap.png"); |
247 save_bm(dstBM1, "drawMesh.png"); | 245 save_bm(dstBM1, "drawMesh.png"); |
248 gOnce = true; | 246 gOnce = true; |
249 } | 247 } |
250 | 248 |
251 if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.ge
tSize())) { | 249 if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.ge
tSize())) { |
252 ERRORF(reporter, "Diagonal config=%s bg=0x%x dither=%d" | 250 ERRORF(reporter, "Diagonal colortype=%s bg=0x%x dither=%
d" |
253 " alpha=0x%x src=0x%x", | 251 " alpha=0x%x src=0x%x", |
254 gConfigName[gDstConfig[i]], bgColor, dither, | 252 gConfigName[gDstColorType[i]], bgColor, dither, |
255 alpha, c); | 253 alpha, c); |
256 } | 254 } |
257 } | 255 } |
258 } | 256 } |
259 } | 257 } |
260 } | 258 } |
261 } | 259 } |
262 | 260 |
263 DEF_TEST(BlitRow, reporter) { | 261 DEF_TEST(BlitRow, reporter) { |
264 test_00_FF(reporter); | 262 test_00_FF(reporter); |
265 test_diagonal(reporter); | 263 test_diagonal(reporter); |
266 } | 264 } |
OLD | NEW |