aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-26 14:35:02 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-26 14:35:02 +0000
commit2cb1480ff8ae030946cb5f218f9c5cbc1e54c7a9 (patch)
treeee7bfa8d603930c9fdb29e86ae0f3bda3af65c47
parent73a4b4f91fac1783b589eead5e82b0c0771644de (diff)
remove kRLE_Index8_Config from SkBitmap
BUG= R=djsollen@google.com Review URL: https://codereview.chromium.org/17740003 git-svn-id: http://skia.googlecode.com/svn/trunk@9764 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkBitmap.h14
-rw-r--r--src/core/SkBitmap.cpp66
-rw-r--r--src/gpu/SkGr.cpp5
-rw-r--r--src/pdf/SkPDFImage.cpp19
-rw-r--r--tests/BitmapCopyTest.cpp462
5 files changed, 242 insertions, 324 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 81c0342ff9..dd9dc61bc0 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -53,18 +53,12 @@ public:
kRGB_565_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packing)
kARGB_4444_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packing)
kARGB_8888_Config, //!< 32-bits per pixel, (see SkColorPriv.h for packing)
- /**
- * Custom compressed format, not supported on all platforms.
- * Cannot be used as a destination (target of a canvas).
- * i.e. you may be able to draw from one, but you cannot draw into one.
- */
- kRLE_Index8_Config,
};
// do not add this to the Config enum, otherwise the compiler will let us
// pass this as a valid parameter for Config.
enum {
- kConfigCount = kRLE_Index8_Config + 1
+ kConfigCount = kARGB_8888_Config + 1
};
/**
@@ -366,9 +360,7 @@ public:
*/
bool readyToDraw() const {
return this->getPixels() != NULL &&
- ((this->config() != kIndex8_Config &&
- this->config() != kRLE_Index8_Config) ||
- fColorTable != NULL);
+ (this->config() != kIndex8_Config || NULL != fColorTable);
}
/** Returns the pixelRef's texture, or NULL
@@ -376,7 +368,7 @@ public:
SkGpuTexture* getTexture() const;
/** Return the bitmap's colortable, if it uses one (i.e. fConfig is
- kIndex8_Config or kRLE_Index8_Config) and the pixels are locked.
+ kIndex8_Config) and the pixels are locked.
Otherwise returns NULL. Does not affect the colortable's
reference count.
*/
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index e308b88b42..f89ea4beca 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -161,7 +161,6 @@ int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) {
case kA1_Config:
bpp = 0; // not applicable
break;
- case kRLE_Index8_Config:
case kA8_Config:
case kIndex8_Config:
bpp = 1;
@@ -191,7 +190,6 @@ size_t SkBitmap::ComputeRowBytes(Config c, int width) {
switch (c) {
case kNo_Config:
- case kRLE_Index8_Config:
break;
case kA1_Config:
rowBytes.set(width);
@@ -473,8 +471,7 @@ bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize,
dstRowBytes = fRowBytes;
}
- if (getConfig() == kRLE_Index8_Config ||
- dstRowBytes < ComputeRowBytes(getConfig(), fWidth) ||
+ if (dstRowBytes < ComputeRowBytes(getConfig(), fWidth) ||
dst == NULL || (getPixels() == NULL && pixelRef() == NULL))
return false;
@@ -538,19 +535,18 @@ bool SkBitmap::isOpaque() const {
case kARGB_8888_Config:
return (fFlags & kImageIsOpaque_Flag) != 0;
- case kIndex8_Config:
- case kRLE_Index8_Config: {
- uint32_t flags = 0;
-
- this->lockPixels();
- // if lockPixels failed, we may not have a ctable ptr
- if (fColorTable) {
- flags = fColorTable->getFlags();
- }
- this->unlockPixels();
+ case kIndex8_Config: {
+ uint32_t flags = 0;
- return (flags & SkColorTable::kColorsAreOpaque_Flag) != 0;
+ this->lockPixels();
+ // if lockPixels failed, we may not have a ctable ptr
+ if (fColorTable) {
+ flags = fColorTable->getFlags();
}
+ this->unlockPixels();
+
+ return (flags & SkColorTable::kColorsAreOpaque_Flag) != 0;
+ }
case kRGB_565_Config:
return true;
@@ -606,10 +602,6 @@ void* SkBitmap::getAddr(int x, int y) const {
case SkBitmap::kA1_Config:
base += x >> 3;
break;
- case kRLE_Index8_Config:
- SkDEBUGFAIL("Can't return addr for kRLE_Index8_Config");
- base = NULL;
- break;
default:
SkDEBUGFAIL("Can't return addr for config");
base = NULL;
@@ -654,13 +646,6 @@ SkColor SkBitmap::getColor(int x, int y) const {
uint32_t* addr = this->getAddr32(x, y);
return SkUnPreMultiply::PMColorToColor(addr[0]);
}
- case kRLE_Index8_Config: {
- uint8_t dst;
- const SkBitmap::RLEPixels* rle =
- (const SkBitmap::RLEPixels*)this->getPixels();
- SkPackBits::Unpack8(&dst, x, 1, rle->packedAtY(y));
- return SkUnPreMultiply::PMColorToColor((*fColorTable)[dst]);
- }
case kNo_Config:
SkASSERT(false);
return 0;
@@ -695,7 +680,6 @@ bool SkBitmap::ComputeIsOpaque(const SkBitmap& bm) {
}
return true;
} break;
- case kRLE_Index8_Config:
case SkBitmap::kIndex8_Config: {
SkAutoLockColors alc(bm);
const SkPMColor* table = alc.colors();
@@ -946,34 +930,6 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
}
}
- if (kRLE_Index8_Config == fConfig) {
- SkAutoLockPixels alp(*this);
- // don't call readyToDraw(), since we can operate w/o a colortable
- // at this stage
- if (this->getPixels() == NULL) {
- return false;
- }
- SkBitmap bm;
-
- bm.setConfig(kIndex8_Config, r.width(), r.height());
- bm.allocPixels(this->getColorTable());
- if (NULL == bm.getPixels()) {
- return false;
- }
-
- const RLEPixels* rle = (const RLEPixels*)this->getPixels();
- uint8_t* dst = bm.getAddr8(0, 0);
- const int width = bm.width();
- const size_t rowBytes = bm.rowBytes();
-
- for (int y = r.fTop; y < r.fBottom; y++) {
- SkPackBits::Unpack8(dst, r.fLeft, width, rle->packedAtY(y));
- dst += rowBytes;
- }
- result->swap(bm);
- return true;
- }
-
// If the upper left of the rectangle was outside the bounds of this SkBitmap, we should have
// exited above.
SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width()));
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 23aa49b419..4935d8ff85 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2010 Google Inc.
*
@@ -6,8 +5,6 @@
* found in the LICENSE file.
*/
-
-
#include "SkGr.h"
/* Fill out buffer with the compressed format Ganesh expects from a colortable
@@ -213,7 +210,7 @@ GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) {
case SkBitmap::kARGB_8888_Config:
return kSkia8888_GrPixelConfig;
default:
- // kNo_Config, kA1_Config missing, and kRLE_Index8_Config
+ // kNo_Config, kA1_Config missing
return kUnknown_GrPixelConfig;
}
}
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 102bd58b53..a5cb4c20d1 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2010 The Android Open Source Project
*
@@ -6,13 +5,11 @@
* found in the LICENSE file.
*/
-
#include "SkPDFImage.h"
#include "SkBitmap.h"
#include "SkColor.h"
#include "SkColorPriv.h"
-#include "SkPackBits.h"
#include "SkPDFCatalog.h"
#include "SkRect.h"
#include "SkStream.h"
@@ -40,19 +37,6 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
}
break;
}
- case SkBitmap::kRLE_Index8_Config: {
- const int rowBytes = srcRect.width();
- image = new SkMemoryStream(rowBytes * srcRect.height());
- uint8_t* dst = (uint8_t*)image->getMemoryBase();
- const SkBitmap::RLEPixels* rle =
- (const SkBitmap::RLEPixels*)bitmap.getPixels();
- for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
- SkPackBits::Unpack8(dst, srcRect.fLeft, rowBytes,
- rle->packedAtY(y));
- dst += rowBytes;
- }
- break;
- }
case SkBitmap::kARGB_4444_Config: {
isTransparent = true;
const int rowBytes = (srcRect.width() * 3 + 1) / 2;
@@ -319,8 +303,7 @@ SkPDFImage::SkPDFImage(SkStream* imageData,
// if (!image mask) {
if (doingAlpha || alphaOnly) {
insertName("ColorSpace", "DeviceGray");
- } else if (config == SkBitmap::kIndex8_Config ||
- config == SkBitmap::kRLE_Index8_Config) {
+ } else if (config == SkBitmap::kIndex8_Config) {
SkAutoLockPixels alp(bitmap);
insert("ColorSpace",
makeIndexedColorSpace(bitmap.getColorTable()))->unref();
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 4058b04775..10e5163dbb 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -183,8 +183,6 @@ static const char* getSkConfigName(const SkBitmap& bm) {
case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config";
case SkBitmap::kARGB_4444_Config: return "SkBitmap::kARGB_4444_Config";
case SkBitmap::kARGB_8888_Config: return "SkBitmap::kARGB_8888_Config";
- case SkBitmap::kRLE_Index8_Config:
- return "SkBitmap::kRLE_Index8_Config,";
default: return "Unknown SkBitmap configuration.";
}
}
@@ -247,8 +245,6 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) {
{ SkBitmap::kRGB_565_Config, "00101010" },
{ SkBitmap::kARGB_4444_Config, "00101110" },
{ SkBitmap::kARGB_8888_Config, "00101010" },
-// TODO: create valid RLE bitmap to test with
- // { SkBitmap::kRLE_Index8_Config, "00101111" }
};
static const bool isExtracted[] = {
@@ -264,8 +260,7 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) {
SkColorTable* ct = NULL;
src.setConfig(gPairs[i].fConfig, W, H);
- if (SkBitmap::kIndex8_Config == src.config() ||
- SkBitmap::kRLE_Index8_Config == src.config()) {
+ if (SkBitmap::kIndex8_Config == src.config()) {
ct = init_ctable();
}
src.allocPixels(ct);
@@ -365,247 +360,242 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) {
// Test copying to/from external buffer.
// Note: the tests below have hard-coded values ---
// Please take care if modifying.
- if (gPairs[i].fConfig != SkBitmap::kRLE_Index8_Config) {
-
- // Tests for getSafeSize64().
- // Test with a very large configuration without pixel buffer
- // attached.
- SkBitmap tstSafeSize;
- tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U,
- 100000000U);
- Sk64 safeSize = tstSafeSize.getSafeSize64();
- if (safeSize.isNeg()) {
- SkString str;
- str.printf("getSafeSize64() negative: %s",
- getSkConfigName(tstSafeSize));
- reporter->reportFailed(str);
- }
- bool sizeFail = false;
- // Compare against hand-computed values.
- switch (gPairs[i].fConfig) {
- case SkBitmap::kNo_Config:
- break;
-
- case SkBitmap::kA1_Config:
- if (safeSize.fHi != 0x470DE ||
- safeSize.fLo != 0x4DF82000)
- sizeFail = true;
- break;
-
- case SkBitmap::kA8_Config:
- case SkBitmap::kIndex8_Config:
- if (safeSize.fHi != 0x2386F2 ||
- safeSize.fLo != 0x6FC10000)
- sizeFail = true;
- break;
-
- case SkBitmap::kRGB_565_Config:
- case SkBitmap::kARGB_4444_Config:
- if (safeSize.fHi != 0x470DE4 ||
- safeSize.fLo != 0xDF820000)
- sizeFail = true;
- break;
-
- case SkBitmap::kARGB_8888_Config:
- if (safeSize.fHi != 0x8E1BC9 ||
- safeSize.fLo != 0xBF040000)
- sizeFail = true;
- break;
-
- case SkBitmap::kRLE_Index8_Config:
- break;
-
- default:
- break;
- }
- if (sizeFail) {
- SkString str;
- str.printf("getSafeSize64() wrong size: %s",
- getSkConfigName(tstSafeSize));
- reporter->reportFailed(str);
- }
- size_t subW, subH;
- // Set sizes to be height = 2 to force the last row of the
- // source to be used, thus verifying correct operation if
- // the bitmap is an extracted subset.
- if (gPairs[i].fConfig == SkBitmap::kA1_Config) {
- // If one-bit per pixel, use 9 pixels to force more than
- // one byte per row.
- subW = 9;
- subH = 2;
- } else {
- // All other configurations are at least one byte per pixel,
- // and different configs will test copying different numbers
- // of bytes.
- subW = subH = 2;
- }
+ // Tests for getSafeSize64().
+ // Test with a very large configuration without pixel buffer
+ // attached.
+ SkBitmap tstSafeSize;
+ tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U,
+ 100000000U);
+ Sk64 safeSize = tstSafeSize.getSafeSize64();
+ if (safeSize.isNeg()) {
+ SkString str;
+ str.printf("getSafeSize64() negative: %s",
+ getSkConfigName(tstSafeSize));
+ reporter->reportFailed(str);
+ }
+ bool sizeFail = false;
+ // Compare against hand-computed values.
+ switch (gPairs[i].fConfig) {
+ case SkBitmap::kNo_Config:
+ break;
+
+ case SkBitmap::kA1_Config:
+ if (safeSize.fHi != 0x470DE ||
+ safeSize.fLo != 0x4DF82000)
+ sizeFail = true;
+ break;
+
+ case SkBitmap::kA8_Config:
+ case SkBitmap::kIndex8_Config:
+ if (safeSize.fHi != 0x2386F2 ||
+ safeSize.fLo != 0x6FC10000)
+ sizeFail = true;
+ break;
+
+ case SkBitmap::kRGB_565_Config:
+ case SkBitmap::kARGB_4444_Config:
+ if (safeSize.fHi != 0x470DE4 ||
+ safeSize.fLo != 0xDF820000)
+ sizeFail = true;
+ break;
+
+ case SkBitmap::kARGB_8888_Config:
+ if (safeSize.fHi != 0x8E1BC9 ||
+ safeSize.fLo != 0xBF040000)
+ sizeFail = true;
+ break;
+
+ default:
+ break;
+ }
+ if (sizeFail) {
+ SkString str;
+ str.printf("getSafeSize64() wrong size: %s",
+ getSkConfigName(tstSafeSize));
+ reporter->reportFailed(str);
+ }
- // Create bitmap to act as source for copies and subsets.
- SkBitmap src, subset;
- SkColorTable* ct = NULL;
- if (isExtracted[copyCase]) { // A larger image to extract from.
- src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH);
- } else // Tests expect a 2x2 bitmap, so make smaller.
- src.setConfig(gPairs[i].fConfig, subW, subH);
- if (SkBitmap::kIndex8_Config == src.config() ||
- SkBitmap::kRLE_Index8_Config == src.config()) {
- ct = init_ctable();
- }
+ size_t subW, subH;
+ // Set sizes to be height = 2 to force the last row of the
+ // source to be used, thus verifying correct operation if
+ // the bitmap is an extracted subset.
+ if (gPairs[i].fConfig == SkBitmap::kA1_Config) {
+ // If one-bit per pixel, use 9 pixels to force more than
+ // one byte per row.
+ subW = 9;
+ subH = 2;
+ } else {
+ // All other configurations are at least one byte per pixel,
+ // and different configs will test copying different numbers
+ // of bytes.
+ subW = subH = 2;
+ }
- src.allocPixels(ct);
- SkSafeUnref(ct);
+ // Create bitmap to act as source for copies and subsets.
+ SkBitmap src, subset;
+ SkColorTable* ct = NULL;
+ if (isExtracted[copyCase]) { // A larger image to extract from.
+ src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH);
+ } else { // Tests expect a 2x2 bitmap, so make smaller.
+ src.setConfig(gPairs[i].fConfig, subW, subH);
+ }
+ if (SkBitmap::kIndex8_Config == src.config()) {
+ ct = init_ctable();
+ }
- // Either copy src or extract into 'subset', which is used
- // for subsequent calls to copyPixelsTo/From.
- bool srcReady = false;
- if (isExtracted[copyCase]) {
- // The extractedSubset() test case allows us to test copy-
- // ing when src and dst mave possibly different strides.
- SkIRect r;
- if (gPairs[i].fConfig == SkBitmap::kA1_Config)
- // This config seems to need byte-alignment of
- // extracted subset bits.
- r.set(0, 0, subW, subH);
- else
- r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap
-
- srcReady = src.extractSubset(&subset, r);
- } else {
- srcReady = src.copyTo(&subset, src.getConfig());
- }
+ src.allocPixels(ct);
+ SkSafeUnref(ct);
- // Not all configurations will generate a valid 'subset'.
- if (srcReady) {
-
- // Allocate our target buffer 'buf' for all copies.
- // To simplify verifying correctness of copies attach
- // buf to a SkBitmap, but copies are done using the
- // raw buffer pointer.
- const uint32_t bufSize = subH *
- SkBitmap::ComputeRowBytes(src.getConfig(), subW) * 2;
- SkAutoMalloc autoBuf (bufSize);
- uint8_t* buf = static_cast<uint8_t*>(autoBuf.get());
-
- SkBitmap bufBm; // Attach buf to this bitmap.
- bool successExpected;
-
- // Set up values for each pixel being copied.
- Coordinates coords(subW * subH);
- for (size_t x = 0; x < subW; ++x)
- for (size_t y = 0; y < subH; ++y)
- {
- int index = y * subW + x;
- SkASSERT(index < coords.length);
- coords[index]->fX = x;
- coords[index]->fY = y;
- }
-
- writeCoordPixels(subset, coords);
-
- // Test #1 ////////////////////////////////////////////
-
- // Before/after comparisons easier if we attach buf
- // to an appropriately configured SkBitmap.
- memset(buf, 0xFF, bufSize);
- // Config with stride greater than src but that fits in buf.
- bufBm.setConfig(gPairs[i].fConfig, subW, subH,
- SkBitmap::ComputeRowBytes(subset.getConfig(), subW)
- * 2);
- bufBm.setPixels(buf);
- successExpected = false;
- // Then attempt to copy with a stride that is too large
- // to fit in the buffer.
- REPORTER_ASSERT(reporter,
- subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes() * 3)
- == successExpected);
+ // Either copy src or extract into 'subset', which is used
+ // for subsequent calls to copyPixelsTo/From.
+ bool srcReady = false;
+ if (isExtracted[copyCase]) {
+ // The extractedSubset() test case allows us to test copy-
+ // ing when src and dst mave possibly different strides.
+ SkIRect r;
+ if (gPairs[i].fConfig == SkBitmap::kA1_Config)
+ // This config seems to need byte-alignment of
+ // extracted subset bits.
+ r.set(0, 0, subW, subH);
+ else
+ r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap
+
+ srcReady = src.extractSubset(&subset, r);
+ } else {
+ srcReady = src.copyTo(&subset, src.getConfig());
+ }
- if (successExpected)
- reportCopyVerification(subset, bufBm, coords,
- "copyPixelsTo(buf, bufSize, 1.5*maxRowBytes)",
- reporter);
-
- // Test #2 ////////////////////////////////////////////
- // This test should always succeed, but in the case
- // of extracted bitmaps only because we handle the
- // issue of getSafeSize(). Without getSafeSize()
- // buffer overrun/read would occur.
- memset(buf, 0xFF, bufSize);
- bufBm.setConfig(gPairs[i].fConfig, subW, subH,
- subset.rowBytes());
- bufBm.setPixels(buf);
- successExpected = subset.getSafeSize() <= bufSize;
- REPORTER_ASSERT(reporter,
- subset.copyPixelsTo(buf, bufSize) ==
- successExpected);
- if (successExpected)
- reportCopyVerification(subset, bufBm, coords,
- "copyPixelsTo(buf, bufSize)", reporter);
-
- // Test #3 ////////////////////////////////////////////
- // Copy with different stride between src and dst.
- memset(buf, 0xFF, bufSize);
- bufBm.setConfig(gPairs[i].fConfig, subW, subH,
- subset.rowBytes()+1);
- bufBm.setPixels(buf);
- successExpected = true; // Should always work.
- REPORTER_ASSERT(reporter,
- subset.copyPixelsTo(buf, bufSize,
- subset.rowBytes()+1) == successExpected);
- if (successExpected)
- reportCopyVerification(subset, bufBm, coords,
- "copyPixelsTo(buf, bufSize, rowBytes+1)", reporter);
-
- // Test #4 ////////////////////////////////////////////
- // Test copy with stride too small.
- memset(buf, 0xFF, bufSize);
- bufBm.setConfig(gPairs[i].fConfig, subW, subH);
- bufBm.setPixels(buf);
- successExpected = false;
- // Request copy with stride too small.
- REPORTER_ASSERT(reporter,
- subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes()-1)
- == successExpected);
- if (successExpected)
- reportCopyVerification(subset, bufBm, coords,
- "copyPixelsTo(buf, bufSize, rowBytes()-1)", reporter);
+ // Not all configurations will generate a valid 'subset'.
+ if (srcReady) {
+
+ // Allocate our target buffer 'buf' for all copies.
+ // To simplify verifying correctness of copies attach
+ // buf to a SkBitmap, but copies are done using the
+ // raw buffer pointer.
+ const uint32_t bufSize = subH *
+ SkBitmap::ComputeRowBytes(src.getConfig(), subW) * 2;
+ SkAutoMalloc autoBuf (bufSize);
+ uint8_t* buf = static_cast<uint8_t*>(autoBuf.get());
+
+ SkBitmap bufBm; // Attach buf to this bitmap.
+ bool successExpected;
+
+ // Set up values for each pixel being copied.
+ Coordinates coords(subW * subH);
+ for (size_t x = 0; x < subW; ++x)
+ for (size_t y = 0; y < subH; ++y)
+ {
+ int index = y * subW + x;
+ SkASSERT(index < coords.length);
+ coords[index]->fX = x;
+ coords[index]->fY = y;
+ }
-#if 0 // copyPixelsFrom is gone
- // Test #5 ////////////////////////////////////////////
- // Tests the case where the source stride is too small
- // for the source configuration.
- memset(buf, 0xFF, bufSize);
- bufBm.setConfig(gPairs[i].fConfig, subW, subH);
- bufBm.setPixels(buf);
- writeCoordPixels(bufBm, coords);
- REPORTER_ASSERT(reporter,
- subset.copyPixelsFrom(buf, bufSize, 1) == false);
-
- // Test #6 ///////////////////////////////////////////
- // Tests basic copy from an external buffer to the bitmap.
- // If the bitmap is "extracted", this also tests the case
- // where the source stride is different from the dest.
- // stride.
- // We've made the buffer large enough to always succeed.
- bufBm.setConfig(gPairs[i].fConfig, subW, subH);
- bufBm.setPixels(buf);
- writeCoordPixels(bufBm, coords);
- REPORTER_ASSERT(reporter,
- subset.copyPixelsFrom(buf, bufSize, bufBm.rowBytes()) ==
- true);
- reportCopyVerification(bufBm, subset, coords,
- "copyPixelsFrom(buf, bufSize)",
+ writeCoordPixels(subset, coords);
+
+ // Test #1 ////////////////////////////////////////////
+
+ // Before/after comparisons easier if we attach buf
+ // to an appropriately configured SkBitmap.
+ memset(buf, 0xFF, bufSize);
+ // Config with stride greater than src but that fits in buf.
+ bufBm.setConfig(gPairs[i].fConfig, subW, subH,
+ SkBitmap::ComputeRowBytes(subset.getConfig(), subW)
+ * 2);
+ bufBm.setPixels(buf);
+ successExpected = false;
+ // Then attempt to copy with a stride that is too large
+ // to fit in the buffer.
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes() * 3)
+ == successExpected);
+
+ if (successExpected)
+ reportCopyVerification(subset, bufBm, coords,
+ "copyPixelsTo(buf, bufSize, 1.5*maxRowBytes)",
reporter);
- // Test #7 ////////////////////////////////////////////
- // Tests the case where the source buffer is too small
- // for the transfer.
- REPORTER_ASSERT(reporter,
- subset.copyPixelsFrom(buf, 1, subset.rowBytes()) ==
- false);
+ // Test #2 ////////////////////////////////////////////
+ // This test should always succeed, but in the case
+ // of extracted bitmaps only because we handle the
+ // issue of getSafeSize(). Without getSafeSize()
+ // buffer overrun/read would occur.
+ memset(buf, 0xFF, bufSize);
+ bufBm.setConfig(gPairs[i].fConfig, subW, subH,
+ subset.rowBytes());
+ bufBm.setPixels(buf);
+ successExpected = subset.getSafeSize() <= bufSize;
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsTo(buf, bufSize) ==
+ successExpected);
+ if (successExpected)
+ reportCopyVerification(subset, bufBm, coords,
+ "copyPixelsTo(buf, bufSize)", reporter);
+
+ // Test #3 ////////////////////////////////////////////
+ // Copy with different stride between src and dst.
+ memset(buf, 0xFF, bufSize);
+ bufBm.setConfig(gPairs[i].fConfig, subW, subH,
+ subset.rowBytes()+1);
+ bufBm.setPixels(buf);
+ successExpected = true; // Should always work.
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsTo(buf, bufSize,
+ subset.rowBytes()+1) == successExpected);
+ if (successExpected)
+ reportCopyVerification(subset, bufBm, coords,
+ "copyPixelsTo(buf, bufSize, rowBytes+1)", reporter);
+
+ // Test #4 ////////////////////////////////////////////
+ // Test copy with stride too small.
+ memset(buf, 0xFF, bufSize);
+ bufBm.setConfig(gPairs[i].fConfig, subW, subH);
+ bufBm.setPixels(buf);
+ successExpected = false;
+ // Request copy with stride too small.
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes()-1)
+ == successExpected);
+ if (successExpected)
+ reportCopyVerification(subset, bufBm, coords,
+ "copyPixelsTo(buf, bufSize, rowBytes()-1)", reporter);
+
+#if 0 // copyPixelsFrom is gone
+ // Test #5 ////////////////////////////////////////////
+ // Tests the case where the source stride is too small
+ // for the source configuration.
+ memset(buf, 0xFF, bufSize);
+ bufBm.setConfig(gPairs[i].fConfig, subW, subH);
+ bufBm.setPixels(buf);
+ writeCoordPixels(bufBm, coords);
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsFrom(buf, bufSize, 1) == false);
+
+ // Test #6 ///////////////////////////////////////////
+ // Tests basic copy from an external buffer to the bitmap.
+ // If the bitmap is "extracted", this also tests the case
+ // where the source stride is different from the dest.
+ // stride.
+ // We've made the buffer large enough to always succeed.
+ bufBm.setConfig(gPairs[i].fConfig, subW, subH);
+ bufBm.setPixels(buf);
+ writeCoordPixels(bufBm, coords);
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsFrom(buf, bufSize, bufBm.rowBytes()) ==
+ true);
+ reportCopyVerification(bufBm, subset, coords,
+ "copyPixelsFrom(buf, bufSize)",
+ reporter);
+
+ // Test #7 ////////////////////////////////////////////
+ // Tests the case where the source buffer is too small
+ // for the transfer.
+ REPORTER_ASSERT(reporter,
+ subset.copyPixelsFrom(buf, 1, subset.rowBytes()) ==
+ false);
#endif
- }
}
} // for (size_t copyCase ...
}