Index: src/core/SkPixmap.cpp |
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp |
index 2d15e8a1857ba9f93a3862a9bfddc4e383bc0b6c..7c08fb96bd4c5f394d64c4a534f629e7929706f9 100644 |
--- a/src/core/SkPixmap.cpp |
+++ b/src/core/SkPixmap.cpp |
@@ -5,6 +5,7 @@ |
* found in the LICENSE file. |
*/ |
+#include "SkConfig8888.h" |
#include "SkPixmap.h" |
void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) { |
@@ -16,3 +17,41 @@ void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* |
fUnlockContext = ctx; |
fIsLocked = true; |
} |
+ |
+///////////////////////////////////////////////////////////////////////////////////////////////// |
+ |
+bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB, |
+ int x, int y) const { |
+ if (kUnknown_SkColorType == requestedDstInfo.colorType()) { |
+ return false; |
+ } |
+ if (NULL == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { |
+ return false; |
+ } |
+ if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { |
+ return false; |
+ } |
+ |
+ SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDstInfo.height()); |
+ if (!srcR.intersect(0, 0, this->width(), this->height())) { |
+ return false; |
+ } |
+ |
+ // the intersect may have shrunk info's logical size |
+ const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.height()); |
+ |
+ // if x or y are negative, then we have to adjust pixels |
+ if (x > 0) { |
+ x = 0; |
+ } |
+ if (y > 0) { |
+ y = 0; |
+ } |
+ // here x,y are either 0 or negative |
+ dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); |
+ |
+ const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.height()); |
+ const void* srcPixels = this->addr(srcR.x(), srcR.y()); |
+ return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, |
+ srcInfo, srcPixels, this->rowBytes(), this->ctable()); |
+} |