Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: src/core/SkPixmap.cpp

Issue 1153893003: move readPixels from bitmap -> pixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkConfig8888.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « src/core/SkConfig8888.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698