Chromium Code Reviews| Index: src/image/SkImage.cpp |
| diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp |
| index 97e7475a34ff28dc49b6499d5ecaef86c3c8d7fa..dc2fd7dfd85cda5d57dfac2546a62042e0a20985 100644 |
| --- a/src/image/SkImage.cpp |
| +++ b/src/image/SkImage.cpp |
| @@ -94,6 +94,22 @@ const char* SkImage::toString(SkString* str) const { |
| return str->c_str(); |
| } |
| +SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset, |
| + SkFilterQuality quality) const { |
| + if (newWidth < 0 || newHeight < 0) { |
|
scroggo
2015/01/22 20:05:14
Did you make a decision on whether to allow SkImag
reed1
2015/01/22 21:52:52
Good question... I'll give you an answer soon.
reed1
2015/01/22 21:58:24
Zero is illegal, will update this check.
|
| + return NULL; |
| + } |
| + if (subset && !SkIRect::MakeWH(this->width(), this->height()).contains(*subset)) { |
| + return NULL; |
| + } |
| + |
| + if (NULL == subset && this->width() == newWidth && this->height() == newHeight) { |
|
scroggo
2015/01/22 20:05:14
What if the subset == this->dimensions?
(Silly us
reed1
2015/01/22 21:52:52
Ah, good catch. Will add that check.
|
| + return SkRef(const_cast<SkImage*>(this)); |
| + } |
| + |
| + return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality); |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| static bool raster_canvas_supports(const SkImageInfo& info) { |
| @@ -126,3 +142,32 @@ bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz |
| return true; |
| } |
| + |
| +SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* subset, |
| + SkFilterQuality quality) const { |
| + const bool opaque = this->isOpaque(); |
| + const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColorType, |
| + opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| + SkAutoTUnref<SkSurface> surface(this->newSurface(info, NULL)); |
| + if (!surface.get()) { |
| + return NULL; |
| + } |
| + |
| + SkRect src; |
| + if (subset) { |
| + src.set(*subset); |
| + } else { |
| + src = SkRect::MakeIWH(this->width(), this->height()); |
| + } |
| + |
| + surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height()); |
| + surface->getCanvas()->translate(-src.x(), -src.y()); |
| + |
| + SkPaint paint; |
| + paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| + paint.setFilterQuality(quality); |
| + surface->getCanvas()->drawImage(this, 0, 0, &paint); |
| + return surface->newImageSnapshot(); |
| +} |
| + |
| + |