mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-18 06:06:52 -06:00
Draw: RescaleBicubic now supports source rectangle
git-svn-id: svn://ultimatepp.org/upp/trunk@5974 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
c0075840b2
commit
eadd4fa4ee
2 changed files with 24 additions and 15 deletions
|
|
@ -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<int, int> 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<int, int> 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<int, int> progress)
|
||||
{
|
||||
return RescaleBicubic(img, sz, img.GetSize(), progress);
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -75,8 +75,9 @@ Image Rescale(const Image& src, Size sz, const Rect& src_rc, Gate2<int, int> pro
|
|||
Image Rescale(const Image& src, Size sz, Gate2<int, int> progress = false);
|
||||
Image Rescale(const Image& src, int cx, int cy, Gate2<int, int> 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<int, int> progress = false);
|
||||
Image RescaleBicubic(const Image& img, int cx, int cy, Gate2<int, int> progress = false);
|
||||
Image RescaleBicubic(const Image& img, Size sz, Gate2<int, int> progress = false);
|
||||
|
||||
struct ImageFilter9 {
|
||||
virtual RGBA operator()(const RGBA **mx) = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue