diff options
author | 2017-01-20 16:59:02 -0500 | |
---|---|---|
committer | 2017-01-23 15:23:31 +0000 | |
commit | 977f64cbfad1ecd7fd4b1231c694c7e828fda1f0 (patch) | |
tree | d419cde9e63734448b8f01da25105123086d667c /src/core/SkImageInfo.cpp | |
parent | 6987b00fae08ef0731042bb341b4e002a2da72c2 (diff) |
Refactor trimming logic for read/writePixels()
(1) Move trimming logic into Bitmap/Pixmap level for
raster. Everything goes through here, so we'll
only do the work once.
(2) This means it also goes to GPU level.
(3) Always use SkReadPixelsRec rather than inlining
the logic.
(4) Create an SkWritePixelsRec to encapsulate write
trimming.
(5) Disabled kIndex8 as a dst - always.
BUG=skia:6021
Change-Id: I748f50c3b726f7c6de5462e2b1ccb54bc387a510
Reviewed-on: https://skia-review.googlesource.com/7326
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/core/SkImageInfo.cpp')
-rw-r--r-- | src/core/SkImageInfo.cpp | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 0453c7b38f..1b7c09b2f9 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -98,9 +98,6 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, #include "SkReadPixelsRec.h" bool SkReadPixelsRec::trim(int srcWidth, int srcHeight) { - if (kIndex_8_SkColorType == fInfo.colorType()) { - return false; - } if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) { return false; } @@ -131,3 +128,39 @@ bool SkReadPixelsRec::trim(int srcWidth, int srcHeight) { return true; } + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "SkWritePixelsRec.h" + +bool SkWritePixelsRec::trim(int dstWidth, int dstHeight) { + if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) { + return false; + } + if (0 >= fInfo.width() || 0 >= fInfo.height()) { + return false; + } + + int x = fX; + int y = fY; + SkIRect dstR = SkIRect::MakeXYWH(x, y, fInfo.width(), fInfo.height()); + if (!dstR.intersect(0, 0, dstWidth, dstHeight)) { + 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 = ((const char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel()); + // the intersect may have shrunk info's logical size + fInfo = fInfo.makeWH(dstR.width(), dstR.height()); + fX = dstR.x(); + fY = dstR.y(); + + return true; +} |