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