OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkRect.h" | 10 #include "SkRect.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 const int H = 33; | 242 const int H = 33; |
243 | 243 |
244 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 244 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
245 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { | 245 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { |
246 SkBitmap srcOpaque, srcPremul, dst; | 246 SkBitmap srcOpaque, srcPremul, dst; |
247 | 247 |
248 { | 248 { |
249 SkColorTable* ctOpaque = NULL; | 249 SkColorTable* ctOpaque = NULL; |
250 SkColorTable* ctPremul = NULL; | 250 SkColorTable* ctPremul = NULL; |
251 | 251 |
252 srcOpaque.setConfig(gPairs[i].fConfig, W, H); | 252 srcOpaque.setConfig(gPairs[i].fConfig, W, H, 0, kOpaque_SkAlphaT
ype); |
253 srcPremul.setConfig(gPairs[i].fConfig, W, H); | 253 srcPremul.setConfig(gPairs[i].fConfig, W, H, 0, kPremul_SkAlphaT
ype); |
254 if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) { | 254 if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) { |
255 ctOpaque = init_ctable(kOpaque_SkAlphaType); | 255 ctOpaque = init_ctable(kOpaque_SkAlphaType); |
256 ctPremul = init_ctable(kPremul_SkAlphaType); | 256 ctPremul = init_ctable(kPremul_SkAlphaType); |
257 } | 257 } |
258 srcOpaque.allocPixels(ctOpaque); | 258 srcOpaque.allocPixels(ctOpaque); |
259 srcPremul.allocPixels(ctPremul); | 259 srcPremul.allocPixels(ctPremul); |
260 SkSafeUnref(ctOpaque); | 260 SkSafeUnref(ctOpaque); |
261 SkSafeUnref(ctPremul); | 261 SkSafeUnref(ctPremul); |
262 | |
263 srcOpaque.setIsOpaque(true); | |
264 srcPremul.setIsOpaque(false); | |
265 } | 262 } |
266 init_src(srcOpaque); | 263 init_src(srcOpaque); |
267 init_src(srcPremul); | 264 init_src(srcPremul); |
268 | 265 |
269 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); | 266 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); |
270 bool expected = gPairs[i].fValid[j] != '0'; | 267 bool expected = gPairs[i].fValid[j] != '0'; |
271 if (success != expected) { | 268 if (success != expected) { |
272 SkString str; | 269 SkString str; |
273 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned
%s", | 270 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned
%s", |
274 gConfigName[i], gConfigName[j], boolStr(expected), | 271 gConfigName[i], gConfigName[j], boolStr(expected), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 { | 305 { |
309 SkBitmap bitmap(srcOpaque); | 306 SkBitmap bitmap(srcOpaque); |
310 SkBitmap subset; | 307 SkBitmap subset; |
311 SkIRect r; | 308 SkIRect r; |
312 r.set(1, 1, 2, 2); | 309 r.set(1, 1, 2, 2); |
313 bitmap.setIsVolatile(true); | 310 bitmap.setIsVolatile(true); |
314 if (bitmap.extractSubset(&subset, r)) { | 311 if (bitmap.extractSubset(&subset, r)) { |
315 REPORTER_ASSERT(reporter, subset.width() == 1); | 312 REPORTER_ASSERT(reporter, subset.width() == 1); |
316 REPORTER_ASSERT(reporter, subset.height() == 1); | 313 REPORTER_ASSERT(reporter, subset.height() == 1); |
317 REPORTER_ASSERT(reporter, | 314 REPORTER_ASSERT(reporter, |
318 subset.isOpaque() == bitmap.isOpaque()); | 315 subset.alphaType() == bitmap.alphaType()
); |
319 REPORTER_ASSERT(reporter, | 316 REPORTER_ASSERT(reporter, |
320 subset.isVolatile() == true); | 317 subset.isVolatile() == true); |
321 | 318 |
322 SkBitmap copy; | 319 SkBitmap copy; |
323 REPORTER_ASSERT(reporter, | 320 REPORTER_ASSERT(reporter, |
324 subset.copyTo(©, subset.config())); | 321 subset.copyTo(©, subset.config())); |
325 REPORTER_ASSERT(reporter, copy.width() == 1); | 322 REPORTER_ASSERT(reporter, copy.width() == 1); |
326 REPORTER_ASSERT(reporter, copy.height() == 1); | 323 REPORTER_ASSERT(reporter, copy.height() == 1); |
327 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4); | 324 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4); |
328 | 325 |
329 SkAutoLockPixels alp0(subset); | 326 SkAutoLockPixels alp0(subset); |
330 SkAutoLockPixels alp1(copy); | 327 SkAutoLockPixels alp1(copy); |
331 // they should both have, or both not-have, a colortable | 328 // they should both have, or both not-have, a colortable |
332 bool hasCT = subset.getColorTable() != NULL; | 329 bool hasCT = subset.getColorTable() != NULL; |
333 REPORTER_ASSERT(reporter, | 330 REPORTER_ASSERT(reporter, |
334 (copy.getColorTable() != NULL) == hasCT); | 331 (copy.getColorTable() != NULL) == hasCT); |
335 } | 332 } |
336 | |
337 bitmap = srcPremul; | 333 bitmap = srcPremul; |
338 bitmap.setIsVolatile(false); | 334 bitmap.setIsVolatile(false); |
339 if (bitmap.extractSubset(&subset, r)) { | 335 if (bitmap.extractSubset(&subset, r)) { |
340 REPORTER_ASSERT(reporter, | 336 REPORTER_ASSERT(reporter, |
341 subset.isOpaque() == bitmap.isOpaque()); | 337 subset.alphaType() == bitmap.alphaType()
); |
342 REPORTER_ASSERT(reporter, | 338 REPORTER_ASSERT(reporter, |
343 subset.isVolatile() == false); | 339 subset.isVolatile() == false); |
344 } | 340 } |
345 } | 341 } |
346 } else { | 342 } else { |
347 // dst should be unchanged from its initial state | 343 // dst should be unchanged from its initial state |
348 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config); | 344 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config); |
349 REPORTER_ASSERT(reporter, dst.width() == 0); | 345 REPORTER_ASSERT(reporter, dst.width() == 0); |
350 REPORTER_ASSERT(reporter, dst.height() == 0); | 346 REPORTER_ASSERT(reporter, dst.height() == 0); |
351 } | 347 } |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 false); | 591 false); |
596 | 592 |
597 #endif | 593 #endif |
598 } | 594 } |
599 } // for (size_t copyCase ... | 595 } // for (size_t copyCase ... |
600 } | 596 } |
601 } | 597 } |
602 | 598 |
603 #include "TestClassDef.h" | 599 #include "TestClassDef.h" |
604 DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy) | 600 DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy) |
OLD | NEW |