mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Draw: RescaleBicubic
git-svn-id: svn://ultimatepp.org/upp/trunk@5973 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5288da7273
commit
c940282a17
5 changed files with 73 additions and 25 deletions
65
uppsrc/Draw/BiCubic.cpp
Normal file
65
uppsrc/Draw/BiCubic.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include "Draw.h"
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
double BicubicKernel(double x)
|
||||
{
|
||||
double r = 0;
|
||||
double xp2 = x + 2;
|
||||
double xp1 = x + 1;
|
||||
double xm1 = x - 1;
|
||||
if(xp2 > 0)
|
||||
r += xp2 * xp2 * xp2;
|
||||
if(xp1 > 0)
|
||||
r -= 4 * xp1 * xp1 * xp1;
|
||||
if(x > 0)
|
||||
r += 6 * x * x * x;
|
||||
if(xm1 > 0)
|
||||
r -= 4 * xm1 * xm1 * xm1;
|
||||
return 1 / 6.0 * r;
|
||||
}
|
||||
|
||||
Image RescaleBicubic(const Image& img, int cx, int cy)
|
||||
{
|
||||
Size isz = img.GetSize();
|
||||
ImageBuffer ib(cx, cy);
|
||||
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 dx = x * isz.cx * inv_cx - sx;
|
||||
double red = 0;
|
||||
double green = 0;
|
||||
double blue = 0;
|
||||
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)];
|
||||
for(int xx = -1; xx <= 2; xx++) {
|
||||
const RGBA& s = l[minmax(sx + xx, 0, isz.cx - 1)];
|
||||
double weight = ky * BicubicKernel(xx - dx);
|
||||
red += weight * s.r;
|
||||
green += weight * s.g;
|
||||
blue += weight * s.b;
|
||||
alpha += weight * s.a;
|
||||
}
|
||||
}
|
||||
t->r = (int)fround(red);
|
||||
t->g = (int)fround(green);
|
||||
t->b = (int)fround(blue);
|
||||
t->a = (int)fround(alpha);
|
||||
t++;
|
||||
}
|
||||
}
|
||||
return ib;
|
||||
}
|
||||
|
||||
Image RescaleBicubic(const Image& src, Size sz)
|
||||
{
|
||||
return RescaleBicubic(src, sz.cx, sz.cy);
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
@ -50,6 +50,7 @@ file
|
|||
ImageOp.cpp,
|
||||
ImageChOp.cpp,
|
||||
ImageScale.cpp,
|
||||
BiCubic.cpp,
|
||||
MakeCache.cpp,
|
||||
DrawRasterData.cpp,
|
||||
iml.h,
|
||||
|
|
|
|||
|
|
@ -161,27 +161,6 @@ const RGBA* Image::operator~() const
|
|||
return data ? ~data->buffer : NULL;
|
||||
}
|
||||
|
||||
Image::operator const RGBA*() const
|
||||
{
|
||||
return data ? ~data->buffer : NULL;
|
||||
}
|
||||
|
||||
const RGBA* Image::operator[](int i) const
|
||||
{
|
||||
ASSERT(data);
|
||||
return data->buffer[i];
|
||||
}
|
||||
|
||||
Size Image::GetSize() const
|
||||
{
|
||||
return data ? data->buffer.GetSize() : Size(0, 0);
|
||||
}
|
||||
|
||||
int Image::GetLength() const
|
||||
{
|
||||
return data ? data->buffer.GetLength() : 0;
|
||||
}
|
||||
|
||||
Point Image::GetHotSpot() const
|
||||
{
|
||||
return data ? data->buffer.GetHotSpot() : Point(0, 0);
|
||||
|
|
|
|||
|
|
@ -159,13 +159,13 @@ private:
|
|||
|
||||
public:
|
||||
const RGBA* operator~() const;
|
||||
operator const RGBA*() const;
|
||||
const RGBA* operator[](int i) const;
|
||||
operator const RGBA*() const { return data ? ~data->buffer : NULL; }
|
||||
const RGBA* operator[](int i) const { ASSERT(data); return data->buffer[i]; }
|
||||
|
||||
Size GetSize() const;
|
||||
Size GetSize() const { return data ? data->buffer.GetSize() : Size(0, 0); }
|
||||
int GetWidth() const { return GetSize().cx; }
|
||||
int GetHeight() const { return GetSize().cy; }
|
||||
int GetLength() const;
|
||||
int GetLength() const { return data ? data->buffer.GetLength() : 0; }
|
||||
Point GetHotSpot() const;
|
||||
Point Get2ndSpot() const;
|
||||
Size GetDots() const;
|
||||
|
|
|
|||
|
|
@ -75,6 +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);
|
||||
|
||||
struct ImageFilter9 {
|
||||
virtual RGBA operator()(const RGBA **mx) = 0;
|
||||
virtual ~ImageFilter9() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue