| 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 "SkRect.h" | 9 #include "SkRect.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 { kRGB_565_SkColorType, "010101" }, | 186 { kRGB_565_SkColorType, "010101" }, |
| 187 { kARGB_4444_SkColorType, "010111" }, | 187 { kARGB_4444_SkColorType, "010111" }, |
| 188 { kN32_SkColorType, "010111" }, | 188 { kN32_SkColorType, "010111" }, |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 static const int W = 20; | 191 static const int W = 20; |
| 192 static const int H = 33; | 192 static const int H = 33; |
| 193 | 193 |
| 194 static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, | 194 static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, |
| 195 SkColorType ct) { | 195 SkColorType ct) { |
| 196 SkColorTable* ctable = NULL; | 196 SkColorTable* ctable = nullptr; |
| 197 if (kIndex_8_SkColorType == ct) { | 197 if (kIndex_8_SkColorType == ct) { |
| 198 ctable = init_ctable(); | 198 ctable = init_ctable(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), | 201 srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), |
| 202 NULL, ctable); | 202 nullptr, ctable); |
| 203 srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), | 203 srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), |
| 204 NULL, ctable); | 204 nullptr, ctable); |
| 205 SkSafeUnref(ctable); | 205 SkSafeUnref(ctable); |
| 206 init_src(*srcOpaque); | 206 init_src(*srcOpaque); |
| 207 init_src(*srcPremul); | 207 init_src(*srcPremul); |
| 208 } | 208 } |
| 209 | 209 |
| 210 DEF_TEST(BitmapCopy_extractSubset, reporter) { | 210 DEF_TEST(BitmapCopy_extractSubset, reporter) { |
| 211 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 211 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
| 212 SkBitmap srcOpaque, srcPremul; | 212 SkBitmap srcOpaque, srcPremul; |
| 213 setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType); | 213 setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType); |
| 214 | 214 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 241 // change. | 241 // change. |
| 242 REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.getGe
nerationID()); | 242 REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.getGe
nerationID()); |
| 243 | 243 |
| 244 REPORTER_ASSERT(reporter, copy.width() == W); | 244 REPORTER_ASSERT(reporter, copy.width() == W); |
| 245 REPORTER_ASSERT(reporter, copy.height() == 2); | 245 REPORTER_ASSERT(reporter, copy.height() == 2); |
| 246 | 246 |
| 247 if (gPairs[i].fColorType == gPairs[j].fColorType) { | 247 if (gPairs[i].fColorType == gPairs[j].fColorType) { |
| 248 SkAutoLockPixels alp0(subset); | 248 SkAutoLockPixels alp0(subset); |
| 249 SkAutoLockPixels alp1(copy); | 249 SkAutoLockPixels alp1(copy); |
| 250 // they should both have, or both not-have, a colortable | 250 // they should both have, or both not-have, a colortable |
| 251 bool hasCT = subset.getColorTable() != NULL; | 251 bool hasCT = subset.getColorTable() != nullptr; |
| 252 REPORTER_ASSERT(reporter, (copy.getColorTable() != NULL) ==
hasCT); | 252 REPORTER_ASSERT(reporter, (copy.getColorTable() != nullptr)
== hasCT); |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 bitmap = srcPremul; | 257 bitmap = srcPremul; |
| 258 bitmap.setIsVolatile(false); | 258 bitmap.setIsVolatile(false); |
| 259 if (bitmap.extractSubset(&subset, r)) { | 259 if (bitmap.extractSubset(&subset, r)) { |
| 260 REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType()); | 260 REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType()); |
| 261 REPORTER_ASSERT(reporter, subset.isVolatile() == false); | 261 REPORTER_ASSERT(reporter, subset.isVolatile() == false); |
| 262 } | 262 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 if (sizeFail) { | 369 if (sizeFail) { |
| 370 ERRORF(reporter, "computeSafeSize64() wrong size: %s", | 370 ERRORF(reporter, "computeSafeSize64() wrong size: %s", |
| 371 gColorTypeName[tstSafeSize.colorType()]); | 371 gColorTypeName[tstSafeSize.colorType()]); |
| 372 } | 372 } |
| 373 | 373 |
| 374 int subW = 2; | 374 int subW = 2; |
| 375 int subH = 2; | 375 int subH = 2; |
| 376 | 376 |
| 377 // Create bitmap to act as source for copies and subsets. | 377 // Create bitmap to act as source for copies and subsets. |
| 378 SkBitmap src, subset; | 378 SkBitmap src, subset; |
| 379 SkColorTable* ct = NULL; | 379 SkColorTable* ct = nullptr; |
| 380 if (kIndex_8_SkColorType == src.colorType()) { | 380 if (kIndex_8_SkColorType == src.colorType()) { |
| 381 ct = init_ctable(); | 381 ct = init_ctable(); |
| 382 } | 382 } |
| 383 | 383 |
| 384 int localSubW; | 384 int localSubW; |
| 385 if (isExtracted[copyCase]) { // A larger image to extract from. | 385 if (isExtracted[copyCase]) { // A larger image to extract from. |
| 386 localSubW = 2 * subW + 1; | 386 localSubW = 2 * subW + 1; |
| 387 } else { // Tests expect a 2x2 bitmap, so make smaller. | 387 } else { // Tests expect a 2x2 bitmap, so make smaller. |
| 388 localSubW = subW; | 388 localSubW = subW; |
| 389 } | 389 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy))
; | 624 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy))
; |
| 625 } else { | 625 } else { |
| 626 REPORTER_ASSERT(reporter, 0 == dstC); | 626 REPORTER_ASSERT(reporter, 0 == dstC); |
| 627 } | 627 } |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 } | 632 } |
| 633 | 633 |
| OLD | NEW |