aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmap.cpp
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-05-05 23:13:23 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-05-05 23:13:23 +0000
commit311c82db3115fc6810855cbcc42a6bc6fbd48265 (patch)
tree2183ec768b21bda915011bacc4740a353aa2c684 /src/core/SkBitmap.cpp
parent7a561082645315215949fb7ad9c80c883ffd89ad (diff)
fix copyTo to only copy the minimum pixels per row, and to lock the src before
trying to access its colorTable. Update unittest for copyTo. Add sample for using a mask to clip a layer. git-svn-id: http://skia.googlecode.com/svn/trunk@168 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkBitmap.cpp')
-rw-r--r--src/core/SkBitmap.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 3debd81dc7..2765fab194 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -710,6 +710,9 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const {
return false;
}
+ // we lock this now, since we may need its colortable
+ SkAutoLockPixels srclock(*this);
+
SkBitmap tmp;
tmp.setConfig(dstConfig, this->width(), this->height());
@@ -721,7 +724,6 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const {
return false;
}
- SkAutoLockPixels srclock(*this);
SkAutoLockPixels dstlock(tmp);
if (!this->readyToDraw() || !tmp.readyToDraw()) {
@@ -733,7 +735,19 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const {
re-draw for the !sameConfigs cases
*/
if (sameConfigs) {
- memcpy(tmp.getPixels(), this->getPixels(), this->getSize());
+ if (tmp.getSize() == this->getSize()) {
+ memcpy(tmp.getPixels(), this->getPixels(), this->getSize());
+ } else {
+ const char* srcP = reinterpret_cast<const char*>(this->getPixels());
+ char* dstP = reinterpret_cast<char*>(tmp.getPixels());
+ // to be sure we don't read too much, only copy our logical pixels
+ size_t bytesToCopy = tmp.width() * tmp.bytesPerPixel();
+ for (int y = 0; y < tmp.height(); y++) {
+ memcpy(dstP, srcP, bytesToCopy);
+ srcP += this->rowBytes();
+ dstP += tmp.rowBytes();
+ }
+ }
} else {
// if the src has alpha, we have to clear the dst first
if (!this->isOpaque()) {