diff options
author | reed <reed@google.com> | 2014-07-10 14:15:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-07-10 14:15:57 -0700 |
commit | c4f216151b6ade70c35fade09a353052f40236b1 (patch) | |
tree | 7393796575579df79176730ff0d25123044a0502 /src/core/SkBitmapDevice.cpp | |
parent | e372e78223a8ce916d276d6e0420d552fb0267e9 (diff) |
add readPixels() to SkBitmap
BUG=chromium:390782
R=scroggo@google.com, bsalomon@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/377303002
Diffstat (limited to 'src/core/SkBitmapDevice.cpp')
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 76 |
1 files changed, 2 insertions, 74 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 86c5702f03..09b3b605f8 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -141,59 +141,8 @@ void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { return NULL; } -static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow, - int rowCount) { - SkASSERT(bytesPerRow <= srcRB); - SkASSERT(bytesPerRow <= dstRB); - for (int i = 0; i < rowCount; ++i) { - memcpy(dst, src, bytesPerRow); - dst = (char*)dst + dstRB; - src = (const char*)src + srcRB; - } -} - #include "SkConfig8888.h" -static bool copy_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, - const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes) { - if (srcInfo.dimensions() != dstInfo.dimensions()) { - return false; - } - if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { - SkDstPixelInfo dstPI; - dstPI.fColorType = dstInfo.colorType(); - dstPI.fAlphaType = dstInfo.alphaType(); - dstPI.fPixels = dstPixels; - dstPI.fRowBytes = dstRowBytes; - - SkSrcPixelInfo srcPI; - srcPI.fColorType = srcInfo.colorType(); - srcPI.fAlphaType = srcInfo.alphaType(); - srcPI.fPixels = srcPixels; - srcPI.fRowBytes = srcRowBytes; - - return srcPI.convertPixelsTo(&dstPI, srcInfo.width(), srcInfo.height()); - } - if (srcInfo.colorType() == dstInfo.colorType()) { - switch (srcInfo.colorType()) { - case kRGB_565_SkColorType: - case kAlpha_8_SkColorType: - break; - case kARGB_4444_SkColorType: - if (srcInfo.alphaType() != dstInfo.alphaType()) { - return false; - } - break; - default: - return false; - } - rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes, - srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height()); - } - // TODO: add support for more conversions as needed - return false; -} - bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes, int x, int y) { // since we don't stop creating un-pixeled devices yet, check for no pixels here @@ -208,7 +157,7 @@ bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi void* dstPixels = fBitmap.getAddr(x, y); size_t dstRowBytes = fBitmap.rowBytes(); - if (copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) { + if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) { fBitmap.notifyPixelsChanged(); return true; } @@ -217,28 +166,7 @@ bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int x, int y) { - // since we don't stop creating un-pixeled devices yet, check for no pixels here - if (NULL == fBitmap.getPixels()) { - return false; - } - - SkImageInfo srcInfo = fBitmap.info(); - - // perhaps can relax these in the future - if (4 != dstInfo.bytesPerPixel()) { - return false; - } - if (4 != srcInfo.bytesPerPixel()) { - return false; - } - - srcInfo.fWidth = dstInfo.width(); - srcInfo.fHeight = dstInfo.height(); - - const void* srcPixels = fBitmap.getAddr(x, y); - const size_t srcRowBytes = fBitmap.rowBytes(); - - return copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes); + return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); } /////////////////////////////////////////////////////////////////////////////// |