blob: 1878dfa4d5d40035e47e1347e5aef00fb50c7e37 [file] [log] [blame]
reed@android.com42263962009-05-01 04:00:01 +00001#include "Test.h"
2#include "SkBitmap.h"
reed@android.com311c82d2009-05-05 23:13:23 +00003#include "SkRect.h"
reed@android.com42263962009-05-01 04:00:01 +00004
5static const char* boolStr(bool value) {
6 return value ? "true" : "false";
7}
8
9// these are in the same order as the SkBitmap::Config enum
10static const char* gConfigName[] = {
11 "None", "A1", "A8", "Index8", "565", "4444", "8888", "RLE_Index8"
12};
13
reed@android.comcafc9f92009-08-22 03:44:57 +000014static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src,
15 const SkBitmap& dst) {
16 SkString str;
17 str.printf("src %s opaque:%d, dst %s opaque:%d",
18 gConfigName[src.config()], src.isOpaque(),
19 gConfigName[dst.config()], dst.isOpaque());
20 reporter->reportFailed(str);
21}
22
23static bool canHaveAlpha(SkBitmap::Config config) {
24 return config != SkBitmap::kRGB_565_Config;
25}
26
27// copyTo() should preserve isOpaque when it makes sense
28static void test_isOpaque(skiatest::Reporter* reporter, const SkBitmap& src,
29 SkBitmap::Config dstConfig) {
30 SkBitmap bitmap(src);
31 SkBitmap dst;
32
33 // we need the lock so that we get a valid colorTable (when available)
34 SkAutoLockPixels alp(bitmap);
35 SkColorTable* ctable = bitmap.getColorTable();
36 unsigned ctableFlags = ctable ? ctable->getFlags() : 0;
37
38 if (canHaveAlpha(bitmap.config()) && canHaveAlpha(dstConfig)) {
39 bitmap.setIsOpaque(false);
40 if (ctable) {
41 ctable->setFlags(ctableFlags & ~SkColorTable::kColorsAreOpaque_Flag);
42 }
43 REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig));
44 REPORTER_ASSERT(reporter, dst.config() == dstConfig);
45 if (bitmap.isOpaque() != dst.isOpaque()) {
46 report_opaqueness(reporter, bitmap, dst);
47 }
48 }
49
50 bitmap.setIsOpaque(true);
51 if (ctable) {
52 ctable->setFlags(ctableFlags | SkColorTable::kColorsAreOpaque_Flag);
53 }
54 REPORTER_ASSERT(reporter, bitmap.copyTo(&dst, dstConfig));
55 REPORTER_ASSERT(reporter, dst.config() == dstConfig);
56 if (bitmap.isOpaque() != dst.isOpaque()) {
57 report_opaqueness(reporter, bitmap, dst);
58 }
59
60 if (ctable) {
61 ctable->setFlags(ctableFlags);
62 }
63}
64
reed@google.com9ce6e752011-01-10 14:04:07 +000065static void init_src(const SkBitmap& bitmap, const SkColorTable* ct) {
weita@google.comf9ab99a2009-05-03 18:23:30 +000066 SkAutoLockPixels lock(bitmap);
reed@android.com42263962009-05-01 04:00:01 +000067 if (bitmap.getPixels()) {
reed@google.com9ce6e752011-01-10 14:04:07 +000068 if (ct) {
69 sk_bzero(bitmap.getPixels(), bitmap.getSize());
70 } else {
71 bitmap.eraseColor(SK_ColorWHITE);
72 }
reed@android.com42263962009-05-01 04:00:01 +000073 }
74}
75
76SkColorTable* init_ctable() {
77 static const SkColor colors[] = {
78 SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
79 };
80 return new SkColorTable(colors, SK_ARRAY_COUNT(colors));
81}
82
83struct Pair {
84 SkBitmap::Config fConfig;
85 const char* fValid;
86};
87
wjmaclean@chromium.org86bff1f2010-11-16 20:22:41 +000088// Utility functions for copyPixelsTo()/copyPixelsFrom() tests.
89// getPixel()
90// setPixel()
91// getSkConfigName()
92// struct Coordinates
93// reportCopyVerification()
94// writeCoordPixels()
95
96// Utility function to read the value of a given pixel in bm. All
97// values converted to uint32_t for simplification of comparisons.
98uint32_t getPixel(int x, int y, const SkBitmap& bm) {
99 uint32_t val = 0;
100 uint16_t val16;
101 uint8_t val8, shift;
102 SkAutoLockPixels lock(bm);
103 const void* rawAddr = bm.getAddr(x,y);
104
105 switch (bm.getConfig()) {
106 case SkBitmap::kARGB_8888_Config:
107 memcpy(&val, rawAddr, sizeof(uint32_t));
108 break;
109 case SkBitmap::kARGB_4444_Config:
110 case SkBitmap::kRGB_565_Config:
111 memcpy(&val16, rawAddr, sizeof(uint16_t));
112 val = val16;
113 break;
114 case SkBitmap::kA8_Config:
115 case SkBitmap::kIndex8_Config:
116 memcpy(&val8, rawAddr, sizeof(uint8_t));
117 val = val8;
118 break;
119 case SkBitmap::kA1_Config:
120 memcpy(&val8, rawAddr, sizeof(uint8_t));
121 shift = x % 8;
122 val = (val8 >> shift) & 0x1 ;
123 break;
124 default:
125 break;
126 }
127 return val;
128}
129
130// Utility function to set value of any pixel in bm.
131// bm.getConfig() specifies what format 'val' must be
132// converted to, but at present uint32_t can handle all formats.
133void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
134 uint16_t val16;
135 uint8_t val8, shift;
136 SkAutoLockPixels lock(bm);
137 void* rawAddr = bm.getAddr(x,y);
138
139 switch (bm.getConfig()) {
140 case SkBitmap::kARGB_8888_Config:
141 memcpy(rawAddr, &val, sizeof(uint32_t));
142 break;
143 case SkBitmap::kARGB_4444_Config:
144 case SkBitmap::kRGB_565_Config:
145 val16 = val & 0xFFFF;
146 memcpy(rawAddr, &val16, sizeof(uint16_t));
147 break;
148 case SkBitmap::kA8_Config:
149 case SkBitmap::kIndex8_Config:
150 val8 = val & 0xFF;
151 memcpy(rawAddr, &val8, sizeof(uint8_t));
152 break;
153 case SkBitmap::kA1_Config:
154 shift = x % 8; // We assume we're in the right byte.
155 memcpy(&val8, rawAddr, sizeof(uint8_t));
156 if (val & 0x1) // Turn bit on.
157 val8 |= (0x1 << shift);
158 else // Turn bit off.
159 val8 &= ~(0x1 << shift);
160 memcpy(rawAddr, &val8, sizeof(uint8_t));
161 break;
162 default:
163 // Ignore.
164 break;
165 }
166}
167
168// Utility to return string containing name of each format, to
169// simplify diagnostic output.
170const char* getSkConfigName(const SkBitmap& bm) {
171 switch (bm.getConfig()) {
172 case SkBitmap::kNo_Config: return "SkBitmap::kNo_Config";
173 case SkBitmap::kA1_Config: return "SkBitmap::kA1_Config";
174 case SkBitmap::kA8_Config: return "SkBitmap::kA8_Config";
175 case SkBitmap::kIndex8_Config: return "SkBitmap::kIndex8_Config";
176 case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config";
177 case SkBitmap::kARGB_4444_Config: return "SkBitmap::kARGB_4444_Config";
178 case SkBitmap::kARGB_8888_Config: return "SkBitmap::kARGB_8888_Config";
179 case SkBitmap::kRLE_Index8_Config:
180 return "SkBitmap::kRLE_Index8_Config,";
181 default: return "Unknown SkBitmap configuration.";
182 }
183}
184
185// Helper struct to contain pixel locations, while avoiding need for STL.
186struct Coordinates {
187
188 const int length;
189 SkIPoint* const data;
190
191 explicit Coordinates(int _length): length(_length)
192 , data(new SkIPoint[length]) { }
193
194 ~Coordinates(){
195 delete [] data;
196 }
197
198 SkIPoint* operator[](int i) const {
199 // Use with care, no bounds checking.
200 return data + i;
201 }
202};
203
204// A function to verify that two bitmaps contain the same pixel values
205// at all coordinates indicated by coords. Simplifies verification of
206// copied bitmaps.
207void reportCopyVerification(const SkBitmap& bm1, const SkBitmap& bm2,
208 Coordinates& coords,
209 const char* msg,
210 skiatest::Reporter* reporter){
211 bool success = true;
212
213 // Confirm all pixels in the list match.
214 for (int i = 0; i < coords.length; ++i)
215 success = success &&
216 (getPixel(coords[i]->fX, coords[i]->fY, bm1) ==
217 getPixel(coords[i]->fX, coords[i]->fY, bm2));
218
219 if (!success) {
220 SkString str;
221 str.printf("%s [config = %s]",
222 msg, getSkConfigName(bm1));
223 reporter->reportFailed(str);
224 }
225}
226
227// Writes unique pixel values at locations specified by coords.
228void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) {
229 for (int i = 0; i < coords.length; ++i)
230 setPixel(coords[i]->fX, coords[i]->fY, i, bm);
231}
232
reed@android.com42263962009-05-01 04:00:01 +0000233static void TestBitmapCopy(skiatest::Reporter* reporter) {
234 static const Pair gPairs[] = {
235 { SkBitmap::kNo_Config, "00000000" },
weita@google.comf9ab99a2009-05-03 18:23:30 +0000236 { SkBitmap::kA1_Config, "01000000" },
reed@android.com42263962009-05-01 04:00:01 +0000237 { SkBitmap::kA8_Config, "00101110" },
238 { SkBitmap::kIndex8_Config, "00111110" },
239 { SkBitmap::kRGB_565_Config, "00101110" },
240 { SkBitmap::kARGB_4444_Config, "00101110" },
241 { SkBitmap::kARGB_8888_Config, "00101110" },
reed@android.comfbaa88d2009-05-06 17:44:34 +0000242// TODO: create valid RLE bitmap to test with
243 // { SkBitmap::kRLE_Index8_Config, "00101111" }
reed@android.com42263962009-05-01 04:00:01 +0000244 };
weita@google.comf9ab99a2009-05-03 18:23:30 +0000245
wjmaclean@chromium.org86bff1f2010-11-16 20:22:41 +0000246 static const bool isExtracted[] = {
247 false, true
248 };
249
reed@android.com42263962009-05-01 04:00:01 +0000250 const int W = 20;
251 const int H = 33;
weita@google.comf9ab99a2009-05-03 18:23:30 +0000252
reed@android.com42263962009-05-01 04:00:01 +0000253 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
254 for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
255 SkBitmap src, dst;
256 SkColorTable* ct = NULL;
weita@google.comf9ab99a2009-05-03 18:23:30 +0000257
reed@android.com42263962009-05-01 04:00:01 +0000258 src.setConfig(gPairs[i].fConfig, W, H);
reed@android.comfbaa88d2009-05-06 17:44:34 +0000259 if (SkBitmap::kIndex8_Config == src.config() ||
260 SkBitmap::kRLE_Index8_Config == src.config()) {
reed@android.com42263962009-05-01 04:00:01 +0000261 ct = init_ctable();
262 }
263 src.allocPixels(ct);
reed@android.comd0a529d2010-01-08 14:01:41 +0000264 SkSafeUnref(ct);
reed@android.com42263962009-05-01 04:00:01 +0000265
reed@google.com9ce6e752011-01-10 14:04:07 +0000266 init_src(src, ct);
reed@android.com42263962009-05-01 04:00:01 +0000267 bool success = src.copyTo(&dst, gPairs[j].fConfig);
268 bool expected = gPairs[i].fValid[j] != '0';
269 if (success != expected) {
270 SkString str;
271 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned %s",
272 gConfigName[i], gConfigName[j], boolStr(expected),
273 boolStr(success));
274 reporter->reportFailed(str);
275 }
reed@google.com1fcd51e2011-01-05 15:50:27 +0000276
reed@android.comfbaa88d2009-05-06 17:44:34 +0000277 bool canSucceed = src.canCopyTo(gPairs[j].fConfig);
278 if (success != canSucceed) {
279 SkString str;
280 str.printf("SkBitmap::copyTo from %s to %s. returned %s canCopyTo %s",
281 gConfigName[i], gConfigName[j], boolStr(success),
282 boolStr(canSucceed));
283 reporter->reportFailed(str);
284 }
weita@google.comf9ab99a2009-05-03 18:23:30 +0000285
reed@android.com42263962009-05-01 04:00:01 +0000286 if (success) {
287 REPORTER_ASSERT(reporter, src.width() == dst.width());
288 REPORTER_ASSERT(reporter, src.height() == dst.height());
weita@google.comf9ab99a2009-05-03 18:23:30 +0000289 REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig);
reed@android.comcafc9f92009-08-22 03:44:57 +0000290 test_isOpaque(reporter, src, dst.config());
reed@android.com42263962009-05-01 04:00:01 +0000291 if (src.config() == dst.config()) {
weita@google.comf9ab99a2009-05-03 18:23:30 +0000292 SkAutoLockPixels srcLock(src);
reed@android.com42263962009-05-01 04:00:01 +0000293 SkAutoLockPixels dstLock(dst);
294 REPORTER_ASSERT(reporter, src.readyToDraw());
295 REPORTER_ASSERT(reporter, dst.readyToDraw());
296 const char* srcP = (const char*)src.getAddr(0, 0);
297 const char* dstP = (const char*)dst.getAddr(0, 0);
298 REPORTER_ASSERT(reporter, srcP != dstP);
299 REPORTER_ASSERT(reporter, !memcmp(srcP, dstP,
300 src.getSize()));
301 }
reed@android.com311c82d2009-05-05 23:13:23 +0000302 // test extractSubset
303 {
304 SkBitmap subset;
305 SkIRect r;
306 r.set(1, 1, 2, 2);
307 if (src.extractSubset(&subset, r)) {
308 REPORTER_ASSERT(reporter, subset.width() == 1);
309 REPORTER_ASSERT(reporter, subset.height() == 1);
310
311 SkBitmap copy;
312 REPORTER_ASSERT(reporter,
313 subset.copyTo(&copy, subset.config()));
314 REPORTER_ASSERT(reporter, copy.width() == 1);
315 REPORTER_ASSERT(reporter, copy.height() == 1);
316 REPORTER_ASSERT(reporter, copy.rowBytes() <= 4);
reed@google.com1fcd51e2011-01-05 15:50:27 +0000317
reed@android.com311c82d2009-05-05 23:13:23 +0000318 SkAutoLockPixels alp0(subset);
319 SkAutoLockPixels alp1(copy);
320 // they should both have, or both not-have, a colortable
321 bool hasCT = subset.getColorTable() != NULL;
322 REPORTER_ASSERT(reporter,
323 (copy.getColorTable() != NULL) == hasCT);
324 }
325 }
reed@android.com42263962009-05-01 04:00:01 +0000326 } else {
327 // dst should be unchanged from its initial state
328 REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config);
329 REPORTER_ASSERT(reporter, dst.width() == 0);
330 REPORTER_ASSERT(reporter, dst.height() == 0);
331 }
wjmaclean@chromium.org86bff1f2010-11-16 20:22:41 +0000332 } // for (size_t j = ...
333
334 // Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(),
335 // copyPixelsFrom().
336 //
337 for (size_t copyCase = 0; copyCase < SK_ARRAY_COUNT(isExtracted);
338 ++copyCase) {
339 // Test copying to/from external buffer.
340 // Note: the tests below have hard-coded values ---
341 // Please take care if modifying.
342 if (gPairs[i].fConfig != SkBitmap::kRLE_Index8_Config) {
343
344 // Tests for getSafeSize64().
345 // Test with a very large configuration without pixel buffer
346 // attached.
347 SkBitmap tstSafeSize;
348 tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U,
349 100000000U);
350 Sk64 safeSize = tstSafeSize.getSafeSize64();
351 if (safeSize.isNeg()) {
352 SkString str;
353 str.printf("getSafeSize64() negative: %s",
354 getSkConfigName(tstSafeSize));
355 reporter->reportFailed(str);
356 }
357 bool sizeFail = false;
358 // Compare against hand-computed values.
359 switch (gPairs[i].fConfig) {
360 case SkBitmap::kNo_Config:
361 break;
362
363 case SkBitmap::kA1_Config:
364 if (safeSize.fHi != 0x470DE ||
365 safeSize.fLo != 0x4DF82000)
366 sizeFail = true;
367 break;
368
369 case SkBitmap::kA8_Config:
370 case SkBitmap::kIndex8_Config:
371 if (safeSize.fHi != 0x2386F2 ||
372 safeSize.fLo != 0x6FC10000)
373 sizeFail = true;
374 break;
375
376 case SkBitmap::kRGB_565_Config:
377 case SkBitmap::kARGB_4444_Config:
378 if (safeSize.fHi != 0x470DE4 ||
379 safeSize.fLo != 0xDF820000)
380 sizeFail = true;
381 break;
382
383 case SkBitmap::kARGB_8888_Config:
384 if (safeSize.fHi != 0x8E1BC9 ||
385 safeSize.fLo != 0xBF040000)
386 sizeFail = true;
387 break;
388
389 case SkBitmap::kRLE_Index8_Config:
390 break;
391
392 default:
393 break;
394 }
395 if (sizeFail) {
396 SkString str;
397 str.printf("getSafeSize64() wrong size: %s",
398 getSkConfigName(tstSafeSize));
399 reporter->reportFailed(str);
400 }
401
402 size_t subW, subH;
403 // Set sizes to be height = 2 to force the last row of the
404 // source to be used, thus verifying correct operation if
405 // the bitmap is an extracted subset.
406 if (gPairs[i].fConfig == SkBitmap::kA1_Config) {
407 // If one-bit per pixel, use 9 pixels to force more than
408 // one byte per row.
409 subW = 9;
410 subH = 2;
411 } else {
412 // All other configurations are at least one byte per pixel,
413 // and different configs will test copying different numbers
414 // of bytes.
415 subW = subH = 2;
416 }
417
418 // Create bitmap to act as source for copies and subsets.
419 SkBitmap src, subset;
420 SkColorTable* ct = NULL;
421 if (isExtracted[copyCase]) { // A larger image to extract from.
422 src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH);
423 } else // Tests expect a 2x2 bitmap, so make smaller.
424 src.setConfig(gPairs[i].fConfig, subW, subH);
425 if (SkBitmap::kIndex8_Config == src.config() ||
426 SkBitmap::kRLE_Index8_Config == src.config()) {
427 ct = init_ctable();
428 }
429
430 src.allocPixels(ct);
431 SkSafeUnref(ct);
432
433 // Either copy src or extract into 'subset', which is used
434 // for subsequent calls to copyPixelsTo/From.
435 bool srcReady = false;
436 if (isExtracted[copyCase]) {
437 // The extractedSubset() test case allows us to test copy-
438 // ing when src and dst mave possibly different strides.
439 SkIRect r;
440 if (gPairs[i].fConfig == SkBitmap::kA1_Config)
441 // This config seems to need byte-alignment of
442 // extracted subset bits.
443 r.set(0, 0, subW, subH);
444 else
445 r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap
446
447 srcReady = src.extractSubset(&subset, r);
448 } else {
449 srcReady = src.copyTo(&subset, src.getConfig());
450 }
451
452 // Not all configurations will generate a valid 'subset'.
453 if (srcReady) {
454
455 // Allocate our target buffer 'buf' for all copies.
456 // To simplify verifying correctness of copies attach
457 // buf to a SkBitmap, but copies are done using the
458 // raw buffer pointer.
459 const uint32_t bufSize = subH *
460 SkBitmap::ComputeRowBytes(src.getConfig(), subW) * 2;
461 uint8_t* buf = new uint8_t[bufSize];
462
463 SkBitmap bufBm; // Attach buf to this bitmap.
464 bool successExpected;
465
466 // Set up values for each pixel being copied.
467 Coordinates coords(subW * subH);
468 for (size_t x = 0; x < subW; ++x)
469 for (size_t y = 0; y < subH; ++y)
470 {
reed@google.com1fcd51e2011-01-05 15:50:27 +0000471 int index = y * subW + x;
wjmaclean@chromium.org86bff1f2010-11-16 20:22:41 +0000472 SkASSERT(index < coords.length);
473 coords[index]->fX = x;
474 coords[index]->fY = y;
475 }
476
477 writeCoordPixels(subset, coords);
478
479 // Test #1 ////////////////////////////////////////////
480
481 // Before/after comparisons easier if we attach buf
482 // to an appropriately configured SkBitmap.
483 memset(buf, 0xFF, bufSize);
484 // Config with stride greater than src but that fits in buf.
485 bufBm.setConfig(gPairs[i].fConfig, subW, subH,
486 SkBitmap::ComputeRowBytes(subset.getConfig(), subW)
487 * 2);
488 bufBm.setPixels(buf);
489 successExpected = false;
490 // Then attempt to copy with a stride that is too large
491 // to fit in the buffer.
492 REPORTER_ASSERT(reporter,
493 subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes() * 3)
494 == successExpected);
495
496 if (successExpected)
497 reportCopyVerification(subset, bufBm, coords,
498 "copyPixelsTo(buf, bufSize, 1.5*maxRowBytes)",
499 reporter);
500
501 // Test #2 ////////////////////////////////////////////
502 // This test should always succeed, but in the case
503 // of extracted bitmaps only because we handle the
504 // issue of getSafeSize(). Without getSafeSize()
505 // buffer overrun/read would occur.
506 memset(buf, 0xFF, bufSize);
507 bufBm.setConfig(gPairs[i].fConfig, subW, subH,
508 subset.rowBytes());
509 bufBm.setPixels(buf);
510 successExpected = subset.getSafeSize() <= bufSize;
511 REPORTER_ASSERT(reporter,
512 subset.copyPixelsTo(buf, bufSize) ==
513 successExpected);
514 if (successExpected)
515 reportCopyVerification(subset, bufBm, coords,
516 "copyPixelsTo(buf, bufSize)", reporter);
517
518 // Test #3 ////////////////////////////////////////////
519 // Copy with different stride between src and dst.
520 memset(buf, 0xFF, bufSize);
521 bufBm.setConfig(gPairs[i].fConfig, subW, subH,
522 subset.rowBytes()+1);
523 bufBm.setPixels(buf);
524 successExpected = true; // Should always work.
525 REPORTER_ASSERT(reporter,
526 subset.copyPixelsTo(buf, bufSize,
527 subset.rowBytes()+1) == successExpected);
528 if (successExpected)
529 reportCopyVerification(subset, bufBm, coords,
530 "copyPixelsTo(buf, bufSize, rowBytes+1)", reporter);
531
532 // Test #4 ////////////////////////////////////////////
533 // Test copy with stride too small.
534 memset(buf, 0xFF, bufSize);
535 bufBm.setConfig(gPairs[i].fConfig, subW, subH);
536 bufBm.setPixels(buf);
537 successExpected = false;
538 // Request copy with stride too small.
539 REPORTER_ASSERT(reporter,
540 subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes()-1)
541 == successExpected);
542 if (successExpected)
543 reportCopyVerification(subset, bufBm, coords,
544 "copyPixelsTo(buf, bufSize, rowBytes()-1)", reporter);
545
546 // Test #5 ////////////////////////////////////////////
547 // Tests the case where the source stride is too small
548 // for the source configuration.
549 memset(buf, 0xFF, bufSize);
550 bufBm.setConfig(gPairs[i].fConfig, subW, subH);
551 bufBm.setPixels(buf);
552 writeCoordPixels(bufBm, coords);
553 REPORTER_ASSERT(reporter,
554 subset.copyPixelsFrom(buf, bufSize, 1) == false);
555
556 // Test #6 ////////////////////////////////////////////
557 // Tests basic copy from an external buffer to the bitmap.
558 // If the bitmap is "extracted", this also tests the case
559 // where the source stride is different from the dest.
560 // stride.
561 // We've made the buffer large enough to always succeed.
562 bufBm.setConfig(gPairs[i].fConfig, subW, subH);
563 bufBm.setPixels(buf);
564 writeCoordPixels(bufBm, coords);
565 REPORTER_ASSERT(reporter,
566 subset.copyPixelsFrom(buf, bufSize, bufBm.rowBytes()) ==
567 true);
568 reportCopyVerification(bufBm, subset, coords,
569 "copyPixelsFrom(buf, bufSize)",
570 reporter);
571
572 // Test #7 ////////////////////////////////////////////
573 // Tests the case where the source buffer is too small
574 // for the transfer.
575 REPORTER_ASSERT(reporter,
576 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) ==
577 false);
578
579 delete [] buf;
580 }
581 }
582 } // for (size_t copyCase ...
reed@android.com42263962009-05-01 04:00:01 +0000583 }
584}
585
586#include "TestClassDef.h"
587DEFINE_TESTCLASS("BitmapCopy", TestBitmapCopyClass, TestBitmapCopy)