| 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 25 matching lines...) Expand all Loading... |
| 36 SkBitmap::Config dstConfig) { | 36 SkBitmap::Config dstConfig) { |
| 37 SkBitmap bitmap(src); | 37 SkBitmap bitmap(src); |
| 38 SkBitmap dst; | 38 SkBitmap dst; |
| 39 | 39 |
| 40 // we need the lock so that we get a valid colorTable (when available) | 40 // we need the lock so that we get a valid colorTable (when available) |
| 41 SkAutoLockPixels alp(bitmap); | 41 SkAutoLockPixels alp(bitmap); |
| 42 SkColorTable* ctable = bitmap.getColorTable(); | 42 SkColorTable* ctable = bitmap.getColorTable(); |
| 43 unsigned ctableFlags = ctable ? ctable->getFlags() : 0; | 43 unsigned ctableFlags = ctable ? ctable->getFlags() : 0; |
| 44 | 44 |
| 45 if (canHaveAlpha(bitmap.config()) && canHaveAlpha(dstConfig)) { | 45 if (canHaveAlpha(bitmap.config()) && canHaveAlpha(dstConfig)) { |
| 46 bitmap.setIsOpaque(false); | 46 bitmap.setAlphaType(kPremul_SkAlphaType); |
| 47 if (ctable) { | 47 if (ctable) { |
| 48 ctable->setFlags(ctableFlags & ~SkColorTable::kColorsAreOpaque_Flag)
; | 48 ctable->setFlags(ctableFlags & ~SkColorTable::kColorsAreOpaque_Flag)
; |
| 49 } | 49 } |
| 50 REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig)); | 50 REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig)); |
| 51 REPORTER_ASSERT(reporter, dst.config() == dstConfig); | 51 REPORTER_ASSERT(reporter, dst.config() == dstConfig); |
| 52 if (bitmap.isOpaque() != dst.isOpaque()) { | 52 if (bitmap.isOpaque() != dst.isOpaque()) { |
| 53 report_opaqueness(reporter, bitmap, dst); | 53 report_opaqueness(reporter, bitmap, dst); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 bitmap.setIsOpaque(true); | 57 bitmap.setAlphaType(kOpaque_SkAlphaType); |
| 58 if (ctable) { | 58 if (ctable) { |
| 59 ctable->setFlags(ctableFlags | SkColorTable::kColorsAreOpaque_Flag); | 59 ctable->setFlags(ctableFlags | SkColorTable::kColorsAreOpaque_Flag); |
| 60 } | 60 } |
| 61 REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig)); | 61 REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig)); |
| 62 REPORTER_ASSERT(reporter, dst.config() == dstConfig); | 62 REPORTER_ASSERT(reporter, dst.config() == dstConfig); |
| 63 if (bitmap.isOpaque() != dst.isOpaque()) { | 63 if (bitmap.isOpaque() != dst.isOpaque()) { |
| 64 report_opaqueness(reporter, bitmap, dst); | 64 report_opaqueness(reporter, bitmap, dst); |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (ctable) { | 67 if (ctable) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGe
nerationID()); | 304 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGe
nerationID()); |
| 305 } else { | 305 } else { |
| 306 REPORTER_ASSERT(reporter, src.getGenerationID() != dst.getGe
nerationID()); | 306 REPORTER_ASSERT(reporter, src.getGenerationID() != dst.getGe
nerationID()); |
| 307 } | 307 } |
| 308 // test extractSubset | 308 // test extractSubset |
| 309 { | 309 { |
| 310 SkBitmap bitmap(src); | 310 SkBitmap bitmap(src); |
| 311 SkBitmap subset; | 311 SkBitmap subset; |
| 312 SkIRect r; | 312 SkIRect r; |
| 313 r.set(1, 1, 2, 2); | 313 r.set(1, 1, 2, 2); |
| 314 bitmap.setIsOpaque(true); | 314 bitmap.setAlphaType(kOpaque_SkAlphaType); |
| 315 bitmap.setIsVolatile(true); | 315 bitmap.setIsVolatile(true); |
| 316 if (bitmap.extractSubset(&subset, r)) { | 316 if (bitmap.extractSubset(&subset, r)) { |
| 317 REPORTER_ASSERT(reporter, subset.width() == 1); | 317 REPORTER_ASSERT(reporter, subset.width() == 1); |
| 318 REPORTER_ASSERT(reporter, subset.height() == 1); | 318 REPORTER_ASSERT(reporter, subset.height() == 1); |
| 319 REPORTER_ASSERT(reporter, | 319 REPORTER_ASSERT(reporter, |
| 320 subset.isOpaque() == bitmap.isOpaque()); | 320 subset.isOpaque() == bitmap.isOpaque()); |
| 321 REPORTER_ASSERT(reporter, | 321 REPORTER_ASSERT(reporter, |
| 322 subset.isVolatile() == true); | 322 subset.isVolatile() == true); |
| 323 | 323 |
| 324 SkBitmap copy; | 324 SkBitmap copy; |
| 325 REPORTER_ASSERT(reporter, | 325 REPORTER_ASSERT(reporter, |
| 326 subset.copyTo(©, subset.config())); | 326 subset.copyTo(©, subset.config())); |
| 327 REPORTER_ASSERT(reporter, copy.width() == 1); | 327 REPORTER_ASSERT(reporter, copy.width() == 1); |
| 328 REPORTER_ASSERT(reporter, copy.height() == 1); | 328 REPORTER_ASSERT(reporter, copy.height() == 1); |
| 329 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4); | 329 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4); |
| 330 | 330 |
| 331 SkAutoLockPixels alp0(subset); | 331 SkAutoLockPixels alp0(subset); |
| 332 SkAutoLockPixels alp1(copy); | 332 SkAutoLockPixels alp1(copy); |
| 333 // they should both have, or both not-have, a colortable | 333 // they should both have, or both not-have, a colortable |
| 334 bool hasCT = subset.getColorTable() != NULL; | 334 bool hasCT = subset.getColorTable() != NULL; |
| 335 REPORTER_ASSERT(reporter, | 335 REPORTER_ASSERT(reporter, |
| 336 (copy.getColorTable() != NULL) == hasCT); | 336 (copy.getColorTable() != NULL) == hasCT); |
| 337 } | 337 } |
| 338 bitmap.setIsOpaque(false); | 338 bitmap.setAlphaType(kPremul_SkAlphaType); |
| 339 bitmap.setIsVolatile(false); | 339 bitmap.setIsVolatile(false); |
| 340 if (bitmap.extractSubset(&subset, r)) { | 340 if (bitmap.extractSubset(&subset, r)) { |
| 341 REPORTER_ASSERT(reporter, | 341 REPORTER_ASSERT(reporter, |
| 342 subset.isOpaque() == bitmap.isOpaque()); | 342 subset.isOpaque() == bitmap.isOpaque()); |
| 343 REPORTER_ASSERT(reporter, | 343 REPORTER_ASSERT(reporter, |
| 344 subset.isVolatile() == false); | 344 subset.isVolatile() == false); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 } else { | 347 } else { |
| 348 // dst should be unchanged from its initial state | 348 // dst should be unchanged from its initial state |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 false); | 596 false); |
| 597 | 597 |
| 598 #endif | 598 #endif |
| 599 } | 599 } |
| 600 } // for (size_t copyCase ... | 600 } // for (size_t copyCase ... |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 | 603 |
| 604 #include "TestClassDef.h" | 604 #include "TestClassDef.h" |
| 605 DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy) | 605 DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy) |
| OLD | NEW |