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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 SkAutoLockPixels lock(bitmap); | 54 SkAutoLockPixels lock(bitmap); |
55 if (bitmap.getPixels()) { | 55 if (bitmap.getPixels()) { |
56 if (bitmap.getColorTable()) { | 56 if (bitmap.getColorTable()) { |
57 sk_bzero(bitmap.getPixels(), bitmap.getSize()); | 57 sk_bzero(bitmap.getPixels(), bitmap.getSize()); |
58 } else { | 58 } else { |
59 bitmap.eraseColor(SK_ColorWHITE); | 59 bitmap.eraseColor(SK_ColorWHITE); |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 static SkColorTable* init_ctable(SkAlphaType alphaType) { | 64 static SkColorTable* init_ctable() { |
65 static const SkColor colors[] = { | 65 static const SkColor colors[] = { |
66 SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE | 66 SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE |
67 }; | 67 }; |
68 return new SkColorTable(colors, SK_ARRAY_COUNT(colors), alphaType); | 68 return new SkColorTable(colors, SK_ARRAY_COUNT(colors)); |
69 } | 69 } |
70 | 70 |
71 struct Pair { | 71 struct Pair { |
72 SkColorType fColorType; | 72 SkColorType fColorType; |
73 const char* fValid; | 73 const char* fValid; |
74 }; | 74 }; |
75 | 75 |
76 // Utility functions for copyPixelsTo()/copyPixelsFrom() tests. | 76 // Utility functions for copyPixelsTo()/copyPixelsFrom() tests. |
77 // getPixel() | 77 // getPixel() |
78 // setPixel() | 78 // setPixel() |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 { kRGB_565_SkColorType, "010101" }, | 189 { kRGB_565_SkColorType, "010101" }, |
190 { kARGB_4444_SkColorType, "010111" }, | 190 { kARGB_4444_SkColorType, "010111" }, |
191 { kN32_SkColorType, "010111" }, | 191 { kN32_SkColorType, "010111" }, |
192 }; | 192 }; |
193 | 193 |
194 static const int W = 20; | 194 static const int W = 20; |
195 static const int H = 33; | 195 static const int H = 33; |
196 | 196 |
197 static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, | 197 static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, |
198 SkColorType ct) { | 198 SkColorType ct) { |
199 SkColorTable* ctOpaque = NULL; | 199 SkColorTable* ctable = NULL; |
200 SkColorTable* ctPremul = NULL; | |
201 if (kIndex_8_SkColorType == ct) { | 200 if (kIndex_8_SkColorType == ct) { |
202 ctOpaque = init_ctable(kOpaque_SkAlphaType); | 201 ctable = init_ctable(); |
203 ctPremul = init_ctable(kPremul_SkAlphaType); | |
204 } | 202 } |
205 | 203 |
206 srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), | 204 srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), |
207 NULL, ctOpaque); | 205 NULL, ctable); |
208 srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), | 206 srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), |
209 NULL, ctPremul); | 207 NULL, ctable); |
210 SkSafeUnref(ctOpaque); | 208 SkSafeUnref(ctable); |
211 SkSafeUnref(ctPremul); | |
212 init_src(*srcOpaque); | 209 init_src(*srcOpaque); |
213 init_src(*srcPremul); | 210 init_src(*srcPremul); |
214 } | 211 } |
215 | 212 |
216 DEF_TEST(BitmapCopy_extractSubset, reporter) { | 213 DEF_TEST(BitmapCopy_extractSubset, reporter) { |
217 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 214 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
218 SkBitmap srcOpaque, srcPremul; | 215 SkBitmap srcOpaque, srcPremul; |
219 setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType); | 216 setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType); |
220 | 217 |
221 SkBitmap bitmap(srcOpaque); | 218 SkBitmap bitmap(srcOpaque); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 gColorTypeName[tstSafeSize.colorType()]); | 374 gColorTypeName[tstSafeSize.colorType()]); |
378 } | 375 } |
379 | 376 |
380 int subW = 2; | 377 int subW = 2; |
381 int subH = 2; | 378 int subH = 2; |
382 | 379 |
383 // Create bitmap to act as source for copies and subsets. | 380 // Create bitmap to act as source for copies and subsets. |
384 SkBitmap src, subset; | 381 SkBitmap src, subset; |
385 SkColorTable* ct = NULL; | 382 SkColorTable* ct = NULL; |
386 if (kIndex_8_SkColorType == src.colorType()) { | 383 if (kIndex_8_SkColorType == src.colorType()) { |
387 ct = init_ctable(kPremul_SkAlphaType); | 384 ct = init_ctable(); |
388 } | 385 } |
389 | 386 |
390 int localSubW; | 387 int localSubW; |
391 if (isExtracted[copyCase]) { // A larger image to extract from. | 388 if (isExtracted[copyCase]) { // A larger image to extract from. |
392 localSubW = 2 * subW + 1; | 389 localSubW = 2 * subW + 1; |
393 } else { // Tests expect a 2x2 bitmap, so make smaller. | 390 } else { // Tests expect a 2x2 bitmap, so make smaller. |
394 localSubW = subW; | 391 localSubW = subW; |
395 } | 392 } |
396 // could fail if we pass kIndex_8 for the colortype | 393 // could fail if we pass kIndex_8 for the colortype |
397 if (src.tryAllocPixels(SkImageInfo::Make(localSubW, subH, gPairs[i].
fColorType, | 394 if (src.tryAllocPixels(SkImageInfo::Make(localSubW, subH, gPairs[i].
fColorType, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy))
; | 627 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy))
; |
631 } else { | 628 } else { |
632 REPORTER_ASSERT(reporter, 0 == dstC); | 629 REPORTER_ASSERT(reporter, 0 == dstC); |
633 } | 630 } |
634 } | 631 } |
635 } | 632 } |
636 } | 633 } |
637 } | 634 } |
638 } | 635 } |
639 | 636 |
OLD | NEW |