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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // Utility function to read the value of a given pixel in bm. All | 90 // Utility function to read the value of a given pixel in bm. All |
91 // values converted to uint32_t for simplification of comparisons. | 91 // values converted to uint32_t for simplification of comparisons. |
92 static uint32_t getPixel(int x, int y, const SkBitmap& bm) { | 92 static uint32_t getPixel(int x, int y, const SkBitmap& bm) { |
93 uint32_t val = 0; | 93 uint32_t val = 0; |
94 uint16_t val16; | 94 uint16_t val16; |
95 uint8_t val8, shift; | 95 uint8_t val8, shift; |
96 SkAutoLockPixels lock(bm); | 96 SkAutoLockPixels lock(bm); |
97 const void* rawAddr = bm.getAddr(x,y); | 97 const void* rawAddr = bm.getAddr(x,y); |
98 | 98 |
99 switch (bm.getConfig()) { | 99 switch (bm.config()) { |
100 case SkBitmap::kARGB_8888_Config: | 100 case SkBitmap::kARGB_8888_Config: |
101 memcpy(&val, rawAddr, sizeof(uint32_t)); | 101 memcpy(&val, rawAddr, sizeof(uint32_t)); |
102 break; | 102 break; |
103 case SkBitmap::kARGB_4444_Config: | 103 case SkBitmap::kARGB_4444_Config: |
104 case SkBitmap::kRGB_565_Config: | 104 case SkBitmap::kRGB_565_Config: |
105 memcpy(&val16, rawAddr, sizeof(uint16_t)); | 105 memcpy(&val16, rawAddr, sizeof(uint16_t)); |
106 val = val16; | 106 val = val16; |
107 break; | 107 break; |
108 case SkBitmap::kA8_Config: | 108 case SkBitmap::kA8_Config: |
109 case SkBitmap::kIndex8_Config: | 109 case SkBitmap::kIndex8_Config: |
(...skipping 13 matching lines...) Expand all Loading... |
123 | 123 |
124 // Utility function to set value of any pixel in bm. | 124 // Utility function to set value of any pixel in bm. |
125 // bm.getConfig() specifies what format 'val' must be | 125 // bm.getConfig() specifies what format 'val' must be |
126 // converted to, but at present uint32_t can handle all formats. | 126 // converted to, but at present uint32_t can handle all formats. |
127 static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { | 127 static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { |
128 uint16_t val16; | 128 uint16_t val16; |
129 uint8_t val8, shift; | 129 uint8_t val8, shift; |
130 SkAutoLockPixels lock(bm); | 130 SkAutoLockPixels lock(bm); |
131 void* rawAddr = bm.getAddr(x,y); | 131 void* rawAddr = bm.getAddr(x,y); |
132 | 132 |
133 switch (bm.getConfig()) { | 133 switch (bm.config()) { |
134 case SkBitmap::kARGB_8888_Config: | 134 case SkBitmap::kARGB_8888_Config: |
135 memcpy(rawAddr, &val, sizeof(uint32_t)); | 135 memcpy(rawAddr, &val, sizeof(uint32_t)); |
136 break; | 136 break; |
137 case SkBitmap::kARGB_4444_Config: | 137 case SkBitmap::kARGB_4444_Config: |
138 case SkBitmap::kRGB_565_Config: | 138 case SkBitmap::kRGB_565_Config: |
139 val16 = val & 0xFFFF; | 139 val16 = val & 0xFFFF; |
140 memcpy(rawAddr, &val16, sizeof(uint16_t)); | 140 memcpy(rawAddr, &val16, sizeof(uint16_t)); |
141 break; | 141 break; |
142 case SkBitmap::kA8_Config: | 142 case SkBitmap::kA8_Config: |
143 case SkBitmap::kIndex8_Config: | 143 case SkBitmap::kIndex8_Config: |
(...skipping 11 matching lines...) Expand all Loading... |
155 break; | 155 break; |
156 default: | 156 default: |
157 // Ignore. | 157 // Ignore. |
158 break; | 158 break; |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 // Utility to return string containing name of each format, to | 162 // Utility to return string containing name of each format, to |
163 // simplify diagnostic output. | 163 // simplify diagnostic output. |
164 static const char* getSkConfigName(const SkBitmap& bm) { | 164 static const char* getSkConfigName(const SkBitmap& bm) { |
165 switch (bm.getConfig()) { | 165 switch (bm.config()) { |
166 case SkBitmap::kNo_Config: return "SkBitmap::kNo_Config"; | 166 case SkBitmap::kNo_Config: return "SkBitmap::kNo_Config"; |
167 case SkBitmap::kA1_Config: return "SkBitmap::kA1_Config"; | 167 case SkBitmap::kA1_Config: return "SkBitmap::kA1_Config"; |
168 case SkBitmap::kA8_Config: return "SkBitmap::kA8_Config"; | 168 case SkBitmap::kA8_Config: return "SkBitmap::kA8_Config"; |
169 case SkBitmap::kIndex8_Config: return "SkBitmap::kIndex8_Config"; | 169 case SkBitmap::kIndex8_Config: return "SkBitmap::kIndex8_Config"; |
170 case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config"; | 170 case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config"; |
171 case SkBitmap::kARGB_4444_Config: return "SkBitmap::kARGB_4444_Config"; | 171 case SkBitmap::kARGB_4444_Config: return "SkBitmap::kARGB_4444_Config"; |
172 case SkBitmap::kARGB_8888_Config: return "SkBitmap::kARGB_8888_Config"; | 172 case SkBitmap::kARGB_8888_Config: return "SkBitmap::kARGB_8888_Config"; |
173 default: return "Unknown SkBitmap configuration."; | 173 default: return "Unknown SkBitmap configuration."; |
174 } | 174 } |
175 } | 175 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 SkIRect r; | 451 SkIRect r; |
452 if (gPairs[i].fConfig == SkBitmap::kA1_Config) | 452 if (gPairs[i].fConfig == SkBitmap::kA1_Config) |
453 // This config seems to need byte-alignment of | 453 // This config seems to need byte-alignment of |
454 // extracted subset bits. | 454 // extracted subset bits. |
455 r.set(0, 0, subW, subH); | 455 r.set(0, 0, subW, subH); |
456 else | 456 else |
457 r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap | 457 r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap |
458 | 458 |
459 srcReady = src.extractSubset(&subset, r); | 459 srcReady = src.extractSubset(&subset, r); |
460 } else { | 460 } else { |
461 srcReady = src.copyTo(&subset, src.getConfig()); | 461 srcReady = src.copyTo(&subset, src.config()); |
462 } | 462 } |
463 | 463 |
464 // Not all configurations will generate a valid 'subset'. | 464 // Not all configurations will generate a valid 'subset'. |
465 if (srcReady) { | 465 if (srcReady) { |
466 | 466 |
467 // Allocate our target buffer 'buf' for all copies. | 467 // Allocate our target buffer 'buf' for all copies. |
468 // To simplify verifying correctness of copies attach | 468 // To simplify verifying correctness of copies attach |
469 // buf to a SkBitmap, but copies are done using the | 469 // buf to a SkBitmap, but copies are done using the |
470 // raw buffer pointer. | 470 // raw buffer pointer. |
471 const size_t bufSize = subH * | 471 const size_t bufSize = subH * |
472 SkBitmap::ComputeRowBytes(src.getConfig(), subW) * 2; | 472 SkBitmap::ComputeRowBytes(src.config(), subW) * 2; |
473 SkAutoMalloc autoBuf (bufSize); | 473 SkAutoMalloc autoBuf (bufSize); |
474 uint8_t* buf = static_cast<uint8_t*>(autoBuf.get()); | 474 uint8_t* buf = static_cast<uint8_t*>(autoBuf.get()); |
475 | 475 |
476 SkBitmap bufBm; // Attach buf to this bitmap. | 476 SkBitmap bufBm; // Attach buf to this bitmap. |
477 bool successExpected; | 477 bool successExpected; |
478 | 478 |
479 // Set up values for each pixel being copied. | 479 // Set up values for each pixel being copied. |
480 Coordinates coords(subW * subH); | 480 Coordinates coords(subW * subH); |
481 for (int x = 0; x < subW; ++x) | 481 for (int x = 0; x < subW; ++x) |
482 for (int y = 0; y < subH; ++y) | 482 for (int y = 0; y < subH; ++y) |
483 { | 483 { |
484 int index = y * subW + x; | 484 int index = y * subW + x; |
485 SkASSERT(index < coords.length); | 485 SkASSERT(index < coords.length); |
486 coords[index]->fX = x; | 486 coords[index]->fX = x; |
487 coords[index]->fY = y; | 487 coords[index]->fY = y; |
488 } | 488 } |
489 | 489 |
490 writeCoordPixels(subset, coords); | 490 writeCoordPixels(subset, coords); |
491 | 491 |
492 // Test #1 //////////////////////////////////////////// | 492 // Test #1 //////////////////////////////////////////// |
493 | 493 |
494 // Before/after comparisons easier if we attach buf | 494 // Before/after comparisons easier if we attach buf |
495 // to an appropriately configured SkBitmap. | 495 // to an appropriately configured SkBitmap. |
496 memset(buf, 0xFF, bufSize); | 496 memset(buf, 0xFF, bufSize); |
497 // Config with stride greater than src but that fits in buf. | 497 // Config with stride greater than src but that fits in buf. |
498 bufBm.setConfig(gPairs[i].fConfig, subW, subH, | 498 bufBm.setConfig(gPairs[i].fConfig, subW, subH, |
499 SkBitmap::ComputeRowBytes(subset.getConfig(), subW) | 499 SkBitmap::ComputeRowBytes(subset.config(), subW) * 2); |
500 * 2); | |
501 bufBm.setPixels(buf); | 500 bufBm.setPixels(buf); |
502 successExpected = false; | 501 successExpected = false; |
503 // Then attempt to copy with a stride that is too large | 502 // Then attempt to copy with a stride that is too large |
504 // to fit in the buffer. | 503 // to fit in the buffer. |
505 REPORTER_ASSERT(reporter, | 504 REPORTER_ASSERT(reporter, |
506 subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes() * 3) | 505 subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes() * 3) |
507 == successExpected); | 506 == successExpected); |
508 | 507 |
509 if (successExpected) | 508 if (successExpected) |
510 reportCopyVerification(subset, bufBm, coords, | 509 reportCopyVerification(subset, bufBm, coords, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 false); | 590 false); |
592 | 591 |
593 #endif | 592 #endif |
594 } | 593 } |
595 } // for (size_t copyCase ... | 594 } // for (size_t copyCase ... |
596 } | 595 } |
597 } | 596 } |
598 | 597 |
599 #include "TestClassDef.h" | 598 #include "TestClassDef.h" |
600 DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy) | 599 DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy) |
OLD | NEW |