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

Unified Diff: src/core/SkPixmap.cpp

Issue 1162013008: add extractSubset and SkAutoPixmapStorage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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 | « include/core/SkPixmap.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 3a0fad2a3936763cbd24f01da041d8be04bb2b55..9b7f993792dca69adf90a52fd716819198e3fea7 100644
--- a/src/core/SkPixmap.cpp
+++ b/src/core/SkPixmap.cpp
@@ -6,6 +6,7 @@
*/
#include "SkConfig8888.h"
+#include "SkMask.h"
#include "SkPixmap.h"
void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) {
@@ -37,6 +38,37 @@ void SkPixmap::reset(const SkImageInfo& info, const void* addr, size_t rowBytes,
fInfo = info;
}
+bool SkPixmap::reset(const SkMask& src) {
+ if (SkMask::kA8_Format == src.fFormat) {
+ this->reset(SkImageInfo::MakeA8(src.fBounds.width(), src.fBounds.height()),
+ src.fImage, src.fRowBytes, NULL);
+ return true;
+ }
+ this->reset();
+ return false;
+}
+
+bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const {
+ SkIRect srcRect, r;
+ srcRect.set(0, 0, this->width(), this->height());
+ if (!r.intersect(srcRect, subset)) {
+ return false; // r is empty (i.e. no intersection)
+ }
+
+ // If the upper left of the rectangle was outside the bounds of this SkBitmap, we should have
+ // exited above.
+ SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width()));
+ SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height()));
+
+ const void* pixels = NULL;
+ if (fPixels) {
+ const size_t bpp = fInfo.bytesPerPixel();
+ pixels = (const uint8_t*)fPixels + r.fTop * fRowBytes + r.fLeft * bpp;
+ }
+ result->reset(fInfo.makeWH(r.width(), r.height()), pixels, fRowBytes, fCTable);
+ return true;
+}
+
bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB,
int x, int y) const {
if (kUnknown_SkColorType == requestedDstInfo.colorType()) {
@@ -72,3 +104,36 @@ bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB,
srcInfo, srcPixels, this->rowBytes(), this->ctable());
}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(NULL) {}
+
+SkAutoPixmapStorage::~SkAutoPixmapStorage() {
+ sk_free(fStorage);
+}
+
+bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
+ if (fStorage) {
+ sk_free(fStorage);
+ fStorage = NULL;
+ }
+
+ size_t rb = info.minRowBytes();
+ size_t size = info.getSafeSize(rb);
+ if (0 == size) {
+ return false;
+ }
+ fStorage = sk_malloc_flags(size, 0);
+ if (NULL == fStorage) {
+ return false;
+ }
+ this->reset(info, fStorage, rb);
+ return true;
+}
+
+void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
+ if (!this->tryAlloc(info)) {
+ sk_throw();
+ }
+}
« no previous file with comments | « include/core/SkPixmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698