OLD | NEW |
---|---|
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 #include "Test.h" | 7 #include "Test.h" |
9 #include "TestClassDef.h" | 8 #include "TestClassDef.h" |
10 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
11 #include "SkRect.h" | 10 #include "SkRect.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 }; | 215 }; |
217 | 216 |
218 static const bool isExtracted[] = { | 217 static const bool isExtracted[] = { |
219 false, true | 218 false, true |
220 }; | 219 }; |
221 | 220 |
222 const int W = 20; | 221 const int W = 20; |
223 const int H = 33; | 222 const int H = 33; |
224 | 223 |
225 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 224 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
225 SkBitmap srcOpaque, srcPremul; | |
226 { | |
227 SkColorTable* ctOpaque = NULL; | |
228 SkColorTable* ctPremul = NULL; | |
229 | |
230 srcOpaque.setConfig(gPairs[i].fConfig, W, H, 0, kOpaque_SkAlphaType) ; | |
231 srcPremul.setConfig(gPairs[i].fConfig, W, H, 0, kPremul_SkAlphaType) ; | |
232 if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) { | |
233 ctOpaque = init_ctable(kOpaque_SkAlphaType); | |
234 ctPremul = init_ctable(kPremul_SkAlphaType); | |
235 } | |
236 srcOpaque.allocPixels(ctOpaque); | |
237 srcPremul.allocPixels(ctPremul); | |
238 SkSafeUnref(ctOpaque); | |
239 SkSafeUnref(ctPremul); | |
240 } | |
241 init_src(srcOpaque); | |
242 init_src(srcPremul); | |
243 | |
244 // test extractSubset | |
mtklein
2014/01/09 15:58:07
A block like this makes me think you might want to
scroggo
2014/01/09 20:45:23
Why so, for clarity? Or is there an advantage I'm
mtklein
2014/01/09 21:29:18
Yeah, clarity. It's nearly-independent from the c
scroggo
2014/01/09 21:47:29
Thanks for the justification - you have me convinc
| |
245 { | |
246 SkBitmap bitmap(srcOpaque); | |
247 SkBitmap subset; | |
248 SkIRect r; | |
249 // Extract a subset which has the same width as the original. This | |
250 // catches a bug where we cloned the genID incorrectly. | |
251 r.set(0, 1, W, 3); | |
252 bitmap.setIsVolatile(true); | |
253 if (bitmap.extractSubset(&subset, r)) { | |
254 REPORTER_ASSERT(reporter, subset.width() == W); | |
255 REPORTER_ASSERT(reporter, subset.height() == 2); | |
256 REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType ()); | |
257 REPORTER_ASSERT(reporter, subset.isVolatile() == true); | |
258 | |
259 // Test copying an extracted subset. | |
260 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { | |
261 SkBitmap copy; | |
262 bool success = subset.copyTo(©, gPairs[j].fConfig); | |
263 if (!success) { | |
264 // Skip checking that success matches fValid, which is r edundant | |
265 // with the code below. | |
266 REPORTER_ASSERT(reporter, gPairs[i].fConfig != gPairs[j] .fConfig); | |
267 continue; | |
268 } | |
269 | |
270 // When performing a copy of an extracted subset, the gen id should | |
271 // change. | |
272 REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.g etGenerationID()); | |
273 | |
274 REPORTER_ASSERT(reporter, copy.width() == W); | |
275 REPORTER_ASSERT(reporter, copy.height() == 2); | |
276 | |
277 if (gPairs[i].fConfig == gPairs[j].fConfig) { | |
278 SkAutoLockPixels alp0(subset); | |
279 SkAutoLockPixels alp1(copy); | |
280 // they should both have, or both not-have, a colortable | |
281 bool hasCT = subset.getColorTable() != NULL; | |
282 REPORTER_ASSERT(reporter, (copy.getColorTable() != NULL) == hasCT); | |
283 } | |
284 } | |
285 } | |
286 | |
287 bitmap = srcPremul; | |
288 bitmap.setIsVolatile(false); | |
289 if (bitmap.extractSubset(&subset, r)) { | |
290 REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType ()); | |
291 REPORTER_ASSERT(reporter, subset.isVolatile() == false); | |
292 } | |
293 } | |
294 | |
226 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { | 295 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { |
227 SkBitmap srcOpaque, srcPremul, dst; | 296 SkBitmap dst; |
228 | |
229 { | |
230 SkColorTable* ctOpaque = NULL; | |
231 SkColorTable* ctPremul = NULL; | |
232 | |
233 srcOpaque.setConfig(gPairs[i].fConfig, W, H, 0, kOpaque_SkAlphaT ype); | |
234 srcPremul.setConfig(gPairs[i].fConfig, W, H, 0, kPremul_SkAlphaT ype); | |
235 if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) { | |
236 ctOpaque = init_ctable(kOpaque_SkAlphaType); | |
237 ctPremul = init_ctable(kPremul_SkAlphaType); | |
238 } | |
239 srcOpaque.allocPixels(ctOpaque); | |
240 srcPremul.allocPixels(ctPremul); | |
241 SkSafeUnref(ctOpaque); | |
242 SkSafeUnref(ctPremul); | |
243 } | |
244 init_src(srcOpaque); | |
245 init_src(srcPremul); | |
246 | 297 |
247 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); | 298 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); |
248 bool expected = gPairs[i].fValid[j] != '0'; | 299 bool expected = gPairs[i].fValid[j] != '0'; |
249 if (success != expected) { | 300 if (success != expected) { |
250 SkString str; | 301 SkString str; |
251 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned %s", | 302 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned %s", |
252 gConfigName[i], gConfigName[j], boolStr(expected), | 303 gConfigName[i], gConfigName[j], boolStr(expected), |
253 boolStr(success)); | 304 boolStr(success)); |
254 reporter->reportFailed(str); | 305 reporter->reportFailed(str); |
255 } | 306 } |
(...skipping 19 matching lines...) Expand all Loading... | |
275 REPORTER_ASSERT(reporter, dst.readyToDraw()); | 326 REPORTER_ASSERT(reporter, dst.readyToDraw()); |
276 const char* srcP = (const char*)srcPremul.getAddr(0, 0); | 327 const char* srcP = (const char*)srcPremul.getAddr(0, 0); |
277 const char* dstP = (const char*)dst.getAddr(0, 0); | 328 const char* dstP = (const char*)dst.getAddr(0, 0); |
278 REPORTER_ASSERT(reporter, srcP != dstP); | 329 REPORTER_ASSERT(reporter, srcP != dstP); |
279 REPORTER_ASSERT(reporter, !memcmp(srcP, dstP, | 330 REPORTER_ASSERT(reporter, !memcmp(srcP, dstP, |
280 srcPremul.getSize())); | 331 srcPremul.getSize())); |
281 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() == dst .getGenerationID()); | 332 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() == dst .getGenerationID()); |
282 } else { | 333 } else { |
283 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() != dst .getGenerationID()); | 334 REPORTER_ASSERT(reporter, srcPremul.getGenerationID() != dst .getGenerationID()); |
284 } | 335 } |
285 // test extractSubset | |
286 { | |
287 SkBitmap bitmap(srcOpaque); | |
288 SkBitmap subset; | |
289 SkIRect r; | |
290 r.set(1, 1, 2, 2); | |
291 bitmap.setIsVolatile(true); | |
292 if (bitmap.extractSubset(&subset, r)) { | |
293 REPORTER_ASSERT(reporter, subset.width() == 1); | |
294 REPORTER_ASSERT(reporter, subset.height() == 1); | |
295 REPORTER_ASSERT(reporter, | |
296 subset.alphaType() == bitmap.alphaType() ); | |
297 REPORTER_ASSERT(reporter, | |
298 subset.isVolatile() == true); | |
299 | |
300 SkBitmap copy; | |
301 REPORTER_ASSERT(reporter, | |
302 subset.copyTo(©, subset.config())); | |
303 REPORTER_ASSERT(reporter, copy.width() == 1); | |
304 REPORTER_ASSERT(reporter, copy.height() == 1); | |
305 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4); | |
306 | |
307 SkAutoLockPixels alp0(subset); | |
308 SkAutoLockPixels alp1(copy); | |
309 // they should both have, or both not-have, a colortable | |
310 bool hasCT = subset.getColorTable() != NULL; | |
311 REPORTER_ASSERT(reporter, | |
312 (copy.getColorTable() != NULL) == hasCT); | |
313 } | |
314 bitmap = srcPremul; | |
315 bitmap.setIsVolatile(false); | |
316 if (bitmap.extractSubset(&subset, r)) { | |
317 REPORTER_ASSERT(reporter, | |
318 subset.alphaType() == bitmap.alphaType() ); | |
319 REPORTER_ASSERT(reporter, | |
320 subset.isVolatile() == false); | |
321 } | |
322 } | |
323 } else { | 336 } else { |
324 // dst should be unchanged from its initial state | 337 // dst should be unchanged from its initial state |
325 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config); | 338 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config); |
326 REPORTER_ASSERT(reporter, dst.width() == 0); | 339 REPORTER_ASSERT(reporter, dst.width() == 0); |
327 REPORTER_ASSERT(reporter, dst.height() == 0); | 340 REPORTER_ASSERT(reporter, dst.height() == 0); |
328 } | 341 } |
329 } // for (size_t j = ... | 342 } // for (size_t j = ... |
330 | 343 |
331 // Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(), | 344 // Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(), |
332 // copyPixelsFrom(). | 345 // copyPixelsFrom(). |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 // for the transfer. | 557 // for the transfer. |
545 REPORTER_ASSERT(reporter, | 558 REPORTER_ASSERT(reporter, |
546 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) == | 559 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) == |
547 false); | 560 false); |
548 | 561 |
549 #endif | 562 #endif |
550 } | 563 } |
551 } // for (size_t copyCase ... | 564 } // for (size_t copyCase ... |
552 } | 565 } |
553 } | 566 } |
OLD | NEW |