| 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 "TestClassDef.h" | 9 #include "TestClassDef.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkRect.h" | 11 #include "SkRect.h" |
| 12 | 12 |
| 13 static const char* boolStr(bool value) { | 13 static const char* boolStr(bool value) { |
| 14 return value ? "true" : "false"; | 14 return value ? "true" : "false"; |
| 15 } | 15 } |
| 16 | 16 |
| 17 // these are in the same order as the SkBitmap::Config enum | 17 // these are in the same order as the SkBitmap::Config enum |
| 18 static const char* gConfigName[] = { | 18 static const char* gConfigName[] = { |
| 19 "None", "A8", "Index8", "565", "4444", "8888" | 19 "None", "A8", "Index8", "565", "4444", "8888" |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src, | 22 static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src, |
| 23 const SkBitmap& dst) { | 23 const SkBitmap& dst) { |
| 24 SkString str; | 24 REPORTF(reporter, |
| 25 str.printf("src %s opaque:%d, dst %s opaque:%d", | 25 ("src %s opaque:%d, dst %s opaque:%d", |
| 26 gConfigName[src.config()], src.isOpaque(), | 26 gConfigName[src.config()], src.isOpaque(), |
| 27 gConfigName[dst.config()], dst.isOpaque()); | 27 gConfigName[dst.config()], dst.isOpaque())); |
| 28 reporter->reportFailed(str); | |
| 29 } | 28 } |
| 30 | 29 |
| 31 static bool canHaveAlpha(SkBitmap::Config config) { | 30 static bool canHaveAlpha(SkBitmap::Config config) { |
| 32 return config != SkBitmap::kRGB_565_Config; | 31 return config != SkBitmap::kRGB_565_Config; |
| 33 } | 32 } |
| 34 | 33 |
| 35 // copyTo() should preserve isOpaque when it makes sense | 34 // copyTo() should preserve isOpaque when it makes sense |
| 36 static void test_isOpaque(skiatest::Reporter* reporter, | 35 static void test_isOpaque(skiatest::Reporter* reporter, |
| 37 const SkBitmap& srcOpaque, const SkBitmap& srcPremul, | 36 const SkBitmap& srcOpaque, const SkBitmap& srcPremul, |
| 38 SkBitmap::Config dstConfig) { | 37 SkBitmap::Config dstConfig) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool success = true; | 184 bool success = true; |
| 186 | 185 |
| 187 // Confirm all pixels in the list match. | 186 // Confirm all pixels in the list match. |
| 188 for (int i = 0; i < coords.length; ++i) { | 187 for (int i = 0; i < coords.length; ++i) { |
| 189 success = success && | 188 success = success && |
| 190 (getPixel(coords[i]->fX, coords[i]->fY, bm1) == | 189 (getPixel(coords[i]->fX, coords[i]->fY, bm1) == |
| 191 getPixel(coords[i]->fX, coords[i]->fY, bm2)); | 190 getPixel(coords[i]->fX, coords[i]->fY, bm2)); |
| 192 } | 191 } |
| 193 | 192 |
| 194 if (!success) { | 193 if (!success) { |
| 195 SkString str; | 194 REPORTF(reporter, ("%s [config = %s]", msg, getSkConfigName(bm1))); |
| 196 str.printf("%s [config = %s]", | |
| 197 msg, getSkConfigName(bm1)); | |
| 198 reporter->reportFailed(str); | |
| 199 } | 195 } |
| 200 } | 196 } |
| 201 | 197 |
| 202 // Writes unique pixel values at locations specified by coords. | 198 // Writes unique pixel values at locations specified by coords. |
| 203 static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { | 199 static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { |
| 204 for (int i = 0; i < coords.length; ++i) | 200 for (int i = 0; i < coords.length; ++i) |
| 205 setPixel(coords[i]->fX, coords[i]->fY, i, bm); | 201 setPixel(coords[i]->fX, coords[i]->fY, i, bm); |
| 206 } | 202 } |
| 207 | 203 |
| 208 DEF_TEST(BitmapCopy, reporter) { | 204 DEF_TEST(BitmapCopy, reporter) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 srcPremul.allocPixels(ctPremul); | 236 srcPremul.allocPixels(ctPremul); |
| 241 SkSafeUnref(ctOpaque); | 237 SkSafeUnref(ctOpaque); |
| 242 SkSafeUnref(ctPremul); | 238 SkSafeUnref(ctPremul); |
| 243 } | 239 } |
| 244 init_src(srcOpaque); | 240 init_src(srcOpaque); |
| 245 init_src(srcPremul); | 241 init_src(srcPremul); |
| 246 | 242 |
| 247 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); | 243 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); |
| 248 bool expected = gPairs[i].fValid[j] != '0'; | 244 bool expected = gPairs[i].fValid[j] != '0'; |
| 249 if (success != expected) { | 245 if (success != expected) { |
| 250 SkString str; | 246 REPORTF(reporter, |
| 251 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned
%s", | 247 ("SkBitmap::copyTo from %s to %s. expected %s " |
| 252 gConfigName[i], gConfigName[j], boolStr(expected), | 248 "returned %s", gConfigName[i], gConfigName[j], |
| 253 boolStr(success)); | 249 boolStr(expected), boolStr(success))); |
| 254 reporter->reportFailed(str); | |
| 255 } | 250 } |
| 256 | 251 |
| 257 bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig); | 252 bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig); |
| 258 if (success != canSucceed) { | 253 if (success != canSucceed) { |
| 259 SkString str; | 254 REPORTF(reporter, |
| 260 str.printf("SkBitmap::copyTo from %s to %s. returned %s canCopyT
o %s", | 255 ("SkBitmap::copyTo from %s to %s. returned %s " |
| 261 gConfigName[i], gConfigName[j], boolStr(success), | 256 "canCopyTo %s", gConfigName[i], gConfigName[j], |
| 262 boolStr(canSucceed)); | 257 boolStr(success), boolStr(canSucceed))); |
| 263 reporter->reportFailed(str); | |
| 264 } | 258 } |
| 265 | 259 |
| 266 if (success) { | 260 if (success) { |
| 267 REPORTER_ASSERT(reporter, srcPremul.width() == dst.width()); | 261 REPORTER_ASSERT(reporter, srcPremul.width() == dst.width()); |
| 268 REPORTER_ASSERT(reporter, srcPremul.height() == dst.height()); | 262 REPORTER_ASSERT(reporter, srcPremul.height() == dst.height()); |
| 269 REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig); | 263 REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig); |
| 270 test_isOpaque(reporter, srcOpaque, srcPremul, dst.config()); | 264 test_isOpaque(reporter, srcOpaque, srcPremul, dst.config()); |
| 271 if (srcPremul.config() == dst.config()) { | 265 if (srcPremul.config() == dst.config()) { |
| 272 SkAutoLockPixels srcLock(srcPremul); | 266 SkAutoLockPixels srcLock(srcPremul); |
| 273 SkAutoLockPixels dstLock(dst); | 267 SkAutoLockPixels dstLock(dst); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // Please take care if modifying. | 332 // Please take care if modifying. |
| 339 | 333 |
| 340 // Tests for getSafeSize64(). | 334 // Tests for getSafeSize64(). |
| 341 // Test with a very large configuration without pixel buffer | 335 // Test with a very large configuration without pixel buffer |
| 342 // attached. | 336 // attached. |
| 343 SkBitmap tstSafeSize; | 337 SkBitmap tstSafeSize; |
| 344 tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U, | 338 tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U, |
| 345 100000000U); | 339 100000000U); |
| 346 int64_t safeSize = tstSafeSize.computeSafeSize64(); | 340 int64_t safeSize = tstSafeSize.computeSafeSize64(); |
| 347 if (safeSize < 0) { | 341 if (safeSize < 0) { |
| 348 SkString str; | 342 REPORTF(reporter, |
| 349 str.printf("getSafeSize64() negative: %s", | 343 ("getSafeSize64() negative: %s", |
| 350 getSkConfigName(tstSafeSize)); | 344 getSkConfigName(tstSafeSize))); |
| 351 reporter->reportFailed(str); | |
| 352 } | 345 } |
| 353 bool sizeFail = false; | 346 bool sizeFail = false; |
| 354 // Compare against hand-computed values. | 347 // Compare against hand-computed values. |
| 355 switch (gPairs[i].fConfig) { | 348 switch (gPairs[i].fConfig) { |
| 356 case SkBitmap::kNo_Config: | 349 case SkBitmap::kNo_Config: |
| 357 break; | 350 break; |
| 358 | 351 |
| 359 case SkBitmap::kA8_Config: | 352 case SkBitmap::kA8_Config: |
| 360 case SkBitmap::kIndex8_Config: | 353 case SkBitmap::kIndex8_Config: |
| 361 if (safeSize != 0x2386F26FC10000LL) { | 354 if (safeSize != 0x2386F26FC10000LL) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 373 case SkBitmap::kARGB_8888_Config: | 366 case SkBitmap::kARGB_8888_Config: |
| 374 if (safeSize != 0x8E1BC9BF040000LL) { | 367 if (safeSize != 0x8E1BC9BF040000LL) { |
| 375 sizeFail = true; | 368 sizeFail = true; |
| 376 } | 369 } |
| 377 break; | 370 break; |
| 378 | 371 |
| 379 default: | 372 default: |
| 380 break; | 373 break; |
| 381 } | 374 } |
| 382 if (sizeFail) { | 375 if (sizeFail) { |
| 383 SkString str; | 376 REPORTF(reporter, |
| 384 str.printf("computeSafeSize64() wrong size: %s", | 377 ("computeSafeSize64() wrong size: %s", |
| 385 getSkConfigName(tstSafeSize)); | 378 getSkConfigName(tstSafeSize))); |
| 386 reporter->reportFailed(str); | |
| 387 } | 379 } |
| 388 | 380 |
| 389 int subW = 2; | 381 int subW = 2; |
| 390 int subH = 2; | 382 int subH = 2; |
| 391 | 383 |
| 392 // Create bitmap to act as source for copies and subsets. | 384 // Create bitmap to act as source for copies and subsets. |
| 393 SkBitmap src, subset; | 385 SkBitmap src, subset; |
| 394 SkColorTable* ct = NULL; | 386 SkColorTable* ct = NULL; |
| 395 if (isExtracted[copyCase]) { // A larger image to extract from. | 387 if (isExtracted[copyCase]) { // A larger image to extract from. |
| 396 src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH); | 388 src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 // for the transfer. | 536 // for the transfer. |
| 545 REPORTER_ASSERT(reporter, | 537 REPORTER_ASSERT(reporter, |
| 546 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) == | 538 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) == |
| 547 false); | 539 false); |
| 548 | 540 |
| 549 #endif | 541 #endif |
| 550 } | 542 } |
| 551 } // for (size_t copyCase ... | 543 } // for (size_t copyCase ... |
| 552 } | 544 } |
| 553 } | 545 } |
| OLD | NEW |