From eadd4fa4eede56b01c35dab8436f22046d54affe Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 10 Apr 2013 14:47:03 +0000 Subject: [PATCH] Draw: RescaleBicubic now supports source rectangle git-svn-id: svn://ultimatepp.org/upp/trunk@5974 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Draw/BiCubic.cpp | 34 +++++++++++++++++++++------------- uppsrc/Draw/ImageOp.h | 5 +++-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/uppsrc/Draw/BiCubic.cpp b/uppsrc/Draw/BiCubic.cpp index 341b5e227..def12de18 100644 --- a/uppsrc/Draw/BiCubic.cpp +++ b/uppsrc/Draw/BiCubic.cpp @@ -19,17 +19,20 @@ double BicubicKernel(double x) return 1 / 6.0 * r; } -Image RescaleBicubic(const Image& img, int cx, int cy) +Image RescaleBicubic(const Image& img, Size sz, const Rect& sr, Gate2 progress) { - Size isz = img.GetSize(); - ImageBuffer ib(cx, cy); + ASSERT(sr.top >= 0 && sr.left >= 0 && sr.right <= img.GetWidth() && sr.bottom <= img.GetHeight()); + Size isz = sr.GetSize(); + ImageBuffer ib(sz); RGBA *t = ~ib; - double inv_cx = 1.0 / cx; - for(int y = 0; y < cy; y++) { - int sy = (y * isz.cy) / cy; - double dy = y * isz.cy / (double)cy - sy; - for(int x = 0; x < cx; x++) { - int sx = (x * isz.cx) / cx; + double inv_cx = 1.0 / sz.cx; + for(int y = 0; y < sz.cy; y++) { + if(progress(y, sz.cy)) + return false; + int sy = y * isz.cy / sz.cy; + double dy = y * isz.cy / (double)sz.cy - sy; + for(int x = 0; x < sz.cx; x++) { + int sx = x * isz.cx / sz.cx; double dx = x * isz.cx * inv_cx - sx; double red = 0; double green = 0; @@ -37,9 +40,9 @@ Image RescaleBicubic(const Image& img, int cx, int cy) double alpha = 0; for(int yy = -1; yy <= 2; yy++) { double ky = BicubicKernel(yy - dy); - const RGBA *l = img[minmax(sy + yy, 0, isz.cy - 1)]; + const RGBA *l = img[minmax(sy + yy + sr.top, sr.top, sr.bottom - 1)]; for(int xx = -1; xx <= 2; xx++) { - const RGBA& s = l[minmax(sx + xx, 0, isz.cx - 1)]; + const RGBA& s = l[minmax(sx + xx + sr.left, sr.left, sr.right - 1)]; double weight = ky * BicubicKernel(xx - dx); red += weight * s.r; green += weight * s.g; @@ -57,9 +60,14 @@ Image RescaleBicubic(const Image& img, int cx, int cy) return ib; } -Image RescaleBicubic(const Image& src, Size sz) +Image RescaleBicubic(const Image& img, int cx, int cy, Gate2 progress) { - return RescaleBicubic(src, sz.cx, sz.cy); + return RescaleBicubic(img, Size(cx, cy), img.GetSize(), progress); +} + +Image RescaleBicubic(const Image& img, Size sz, Gate2 progress) +{ + return RescaleBicubic(img, sz, img.GetSize(), progress); } END_UPP_NAMESPACE diff --git a/uppsrc/Draw/ImageOp.h b/uppsrc/Draw/ImageOp.h index 51188063a..22dfacdc9 100644 --- a/uppsrc/Draw/ImageOp.h +++ b/uppsrc/Draw/ImageOp.h @@ -75,8 +75,9 @@ Image Rescale(const Image& src, Size sz, const Rect& src_rc, Gate2 pro Image Rescale(const Image& src, Size sz, Gate2 progress = false); Image Rescale(const Image& src, int cx, int cy, Gate2 progress = false); -Image RescaleBicubic(const Image& img, int cx, int cy); -Image RescaleBicubic(const Image& img, Size sz); +Image RescaleBicubic(const Image& src, Size sz, const Rect& src_rc, Gate2 progress = false); +Image RescaleBicubic(const Image& img, int cx, int cy, Gate2 progress = false); +Image RescaleBicubic(const Image& img, Size sz, Gate2 progress = false); struct ImageFilter9 { virtual RGBA operator()(const RGBA **mx) = 0;