aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-12-10 09:53:42 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-10 09:53:42 -0800
commit96472deea70169396b8e1f576e470138f55fdb1f (patch)
treef245c0de946d6068ba465b9b46b02263cda9ea44 /src/core
parent18abd1acef7b2aa1967196e1b541c8e640c56091 (diff)
dd readPixels to SkImage
patch from issue 789673007 at patchset 1 (http://crrev.com/789673007#ps1) BUG=skia: Review URL: https://codereview.chromium.org/793723002
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkCanvas.cpp38
-rw-r--r--src/core/SkImageInfo.cpp44
2 files changed, 50 insertions, 32 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index bf86005315..083a8ed7e8 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -19,6 +19,7 @@
#include "SkPatchUtils.h"
#include "SkPicture.h"
#include "SkRasterClip.h"
+#include "SkReadPixelsRec.h"
#include "SkRRect.h"
#include "SkSmallAllocator.h"
#include "SkSurface_Base.h"
@@ -686,47 +687,20 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
return true;
}
-bool SkCanvas::readPixels(const SkImageInfo& origInfo, void* dstP, size_t rowBytes, int x, int y) {
- switch (origInfo.colorType()) {
- case kUnknown_SkColorType:
- case kIndex_8_SkColorType:
- return false;
- default:
- break;
- }
- if (NULL == dstP || rowBytes < origInfo.minRowBytes()) {
- return false;
- }
- if (0 == origInfo.width() || 0 == origInfo.height()) {
- return false;
- }
-
+bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowBytes, int x, int y) {
SkBaseDevice* device = this->getDevice();
if (!device) {
return false;
}
-
const SkISize size = this->getBaseLayerSize();
- SkIRect srcR = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height());
- if (!srcR.intersect(0, 0, size.width(), size.height())) {
+
+ SkReadPixelsRec rec(dstInfo, dstP, rowBytes, x, y);
+ if (!rec.trim(size.width(), size.height())) {
return false;
}
- // the intersect may have shrunk info's logical size
- const SkImageInfo info = origInfo.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
- dstP = ((char*)dstP - y * rowBytes - x * info.bytesPerPixel());
-
// The device can assert that the requested area is always contained in its bounds
- return device->readPixels(info, dstP, rowBytes, srcR.x(), srcR.y());
+ return device->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY);
}
bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) {
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index 7931358d82..146a3aeed8 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -76,3 +76,47 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
}
return true;
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "SkReadPixelsRec.h"
+
+bool SkReadPixelsRec::trim(int srcWidth, int srcHeight) {
+ switch (fInfo.colorType()) {
+ case kUnknown_SkColorType:
+ case kIndex_8_SkColorType:
+ return false;
+ default:
+ break;
+ }
+ if (NULL == fPixels || fRowBytes < fInfo.minRowBytes()) {
+ return false;
+ }
+ if (0 == fInfo.width() || 0 == fInfo.height()) {
+ return false;
+ }
+
+ int x = fX;
+ int y = fY;
+ SkIRect srcR = SkIRect::MakeXYWH(x, y, fInfo.width(), fInfo.height());
+ if (!srcR.intersect(0, 0, srcWidth, srcHeight)) {
+ return false;
+ }
+
+ // 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
+ fPixels = ((char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel());
+ // the intersect may have shrunk info's logical size
+ fInfo = fInfo.makeWH(srcR.width(), srcR.height());
+ fX = srcR.x();
+ fY = srcR.y();
+
+ return true;
+}
+