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

Unified Diff: src/image/SkImage_Raster.cpp

Issue 155763004: add ways to peer into an image to get its pixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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/image/SkImage_Base.h ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Raster.cpp
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index ab8a635c1c9af4c0be6dc0bc2303739413226972..262fb97bfa7f3d1cac1f390a4ff7649842d9d8db 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -55,6 +55,8 @@ public:
virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;
+ virtual bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE;
+ virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRIDE;
virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef
@@ -82,13 +84,20 @@ SkImage* SkImage_Raster::NewEmpty() {
return gEmpty;
}
+static void release_data(void* addr, void* context) {
+ SkData* data = static_cast<SkData*>(context);
+ data->unref();
+}
+
SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
- : INHERITED(info.fWidth, info.fHeight) {
- fBitmap.setConfig(info, rowBytes);
- SkAutoTUnref<SkPixelRef> ref(
- SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0));
- fBitmap.setPixelRef(ref);
+ : INHERITED(info.fWidth, info.fHeight)
+{
+ data->ref();
+ void* addr = const_cast<void*>(data->data());
+
+ fBitmap.installPixels(info, addr, rowBytes, release_data, data);
fBitmap.setImmutable();
+ fBitmap.lockPixels();
}
SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes)
@@ -96,6 +105,7 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes
{
fBitmap.setConfig(info, rowBytes);
fBitmap.setPixelRef(pr);
+ fBitmap.lockPixels();
}
SkImage_Raster::~SkImage_Raster() {}
@@ -104,10 +114,34 @@ void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa
canvas->drawBitmap(fBitmap, x, y, paint);
}
-void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) {
+void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src,
+ const SkRect& dst, const SkPaint* paint) {
canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
}
+bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const {
+ if (dst->pixelRef()) {
+ return this->INHERITED::onReadPixels(dst, subset);
+ } else {
+ SkBitmap src;
+ if (!fBitmap.extractSubset(&src, subset)) {
+ return false;
+ }
+ return src.copyTo(dst, src.config());
+ }
+}
+
+const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr,
+ size_t* rowBytesPtr) const {
+ SkImageInfo info;
+ if (!fBitmap.asImageInfo(&info) || !fBitmap.getPixels()) {
+ return false;
+ }
+ *infoPtr = info;
+ *rowBytesPtr = fBitmap.rowBytes();
+ return fBitmap.getPixels();
+}
+
bool SkImage_Raster::getROPixels(SkBitmap* dst) const {
*dst = fBitmap;
return true;
« no previous file with comments | « src/image/SkImage_Base.h ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698