Draw: RescaleCached now has filter parameter

git-svn-id: svn://ultimatepp.org/upp/trunk@5989 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-04-18 18:05:55 +00:00
parent 89683c914a
commit a23e6db5c6
5 changed files with 59 additions and 41 deletions

View file

@ -28,7 +28,7 @@ Image RescaleBicubic(const Image& img, Size sz, const Rect& sr, Gate2<int, int>
double inv_cx = 1.0 / sz.cx;
for(int y = 0; y < sz.cy; y++) {
if(progress(y, sz.cy))
return false;
return ib;
int sy = y * isz.cy / sz.cy;
double dy = y * isz.cy / (double)sz.cy - sy;
for(int x = 0; x < sz.cx; x++) {

View file

@ -156,15 +156,6 @@ void SetMakeImageCacheMax(int m);
Image MakeImagePaintOnly(const ImageMaker& m);
Image CachedRescale(const Image& m, Size sz, const Rect& src);
Image CachedRescale(const Image& m, Size sz);
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src);
Image CachedRescalePaintOnly(const Image& m, Size sz);
Image RescaleBicubic(const Image& src, Size sz, const Rect& src_rc, Gate2<int, int> progress = false);
Image RescaleBicubic(const Image& img, Size sz, Gate2<int, int> progress = false);
Image RescaleBicubic(const Image& img, int cx, int cy, Gate2<int, int> progress = false);
Image RescaleFilter(const Image& img, Size sz, const Rect& sr,
double (*kernel_fn)(double x), int kernel_width, Gate2<int, int> progress);
Image RescaleFilter(const Image& img, Size sz,
@ -188,3 +179,14 @@ enum {
Image RescaleFilter(const Image& img, Size sz, const Rect& sr, int filter, Gate2<int, int> progress = false);
Image RescaleFilter(const Image& img, Size sz, int filter, Gate2<int, int> progress = false);
Image RescaleFilter(const Image& img, int cx, int cy, int filter, Gate2<int, int> progress = false);
Image CachedRescale(const Image& m, Size sz, const Rect& src, int filter = Null);
Image CachedRescale(const Image& m, Size sz, int filter = Null);
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src, int filter = Null);
Image CachedRescalePaintOnly(const Image& m, Size sz, int filter = Null);
// Obsolere, replace with RescaleFilter!
Image RescaleBicubic(const Image& src, Size sz, const Rect& src_rc, Gate2<int, int> progress = false);
Image RescaleBicubic(const Image& img, Size sz, Gate2<int, int> progress = false);
Image RescaleBicubic(const Image& img, int cx, int cy, Gate2<int, int> progress = false);

View file

@ -174,6 +174,7 @@ struct sCachedRescale : public ImageMaker
Rect src;
Size sz;
Image img;
int filter;
virtual String Key() const {
StringBuffer h;
@ -184,16 +185,17 @@ struct sCachedRescale : public ImageMaker
RawCat(h, sz.cx);
RawCat(h, sz.cy);
RawCat(h, img.GetSerialId());
RawCat(h, filter);
return h;
}
virtual Image Make() const {
return Rescale(img, sz, src);
return IsNull(filter) ? Rescale(img, sz, src) : RescaleFilter(img, sz, src, filter);
}
};
Image CachedRescale(const Image& m, Size sz, const Rect& src)
Image CachedRescale(const Image& m, Size sz, const Rect& src, int filter)
{
if(m.GetSize() == sz)
return m;
@ -201,15 +203,16 @@ Image CachedRescale(const Image& m, Size sz, const Rect& src)
cr.sz = sz;
cr.src = src;
cr.img = m;
cr.filter = filter;
return MakeImage(cr);
}
Image CachedRescale(const Image& m, Size sz)
Image CachedRescale(const Image& m, Size sz, int filter)
{
return CachedRescale(m, sz, m.GetSize());
return CachedRescale(m, sz, m.GetSize(), filter);
}
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src)
Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src, int filter)
{
if(m.GetSize() == sz)
return m;
@ -217,12 +220,13 @@ Image CachedRescalePaintOnly(const Image& m, Size sz, const Rect& src)
cr.sz = sz;
cr.src = src;
cr.img = m;
cr.filter = filter;
return MakeImagePaintOnly(cr);
}
Image CachedRescalePaintOnly(const Image& m, Size sz)
Image CachedRescalePaintOnly(const Image& m, Size sz, int filter)
{
return CachedRescalePaintOnly(m, sz, m.GetSize());
return CachedRescalePaintOnly(m, sz, m.GetSize(), filter);
}

View file

@ -212,17 +212,19 @@ static double sCostello(double x)
Image RescaleFilter(const Image& img, Size sz, const Rect& sr, int filter, Gate2<int, int> progress)
{
if(IsNull(filter))
return Rescale(img, sz, sr);
static Tuple2<double (*)(double), int> tab[] = {
sNearest, 1,
sLinear, 1,
sBspline, 2,
sCostello, 2,
sMitchell, 2,
sCatmullRom, 2,
sLanczos2, 2,
sLanczos3, 3,
sLanczos4, 4,
sLanczos5, 5,
{ sNearest, 1 },
{ sLinear, 1 },
{ sBspline, 2 },
{ sCostello, 2 },
{ sMitchell, 2 },
{ sCatmullRom, 2 },
{ sLanczos2, 2 },
{ sLanczos3, 3 },
{ sLanczos4, 4 },
{ sLanczos5, 5 },
};
ASSERT(filter >= FILTER_NEAREST && filter <= FILTER_LANCZOS5);
return RescaleFilter(img, sz, sr, tab[filter].a, tab[filter].b, progress);

View file

@ -87,22 +87,32 @@ t]_[*@3 m])&]
[s2;%% Sets the absolute maximum of image data stored in cache. Default
is one million pixels.&]
[s3;%% &]
[s4; &]
[s5;:CachedRescale`(const Image`&`,Size`,const Rect`&`): [_^Image^ Image]_[* CachedRescal
e]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m], [_^Size^ Size]_[*@3 sz],
[@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 src])&]
[s5;:CachedRescale`(const Image`&`,Size`): [_^Image^ Image]_[* CachedRescale]([@(0.0.255) c
onst]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m], [_^Size^ Size]_[*@3 sz])&]
[s2;%% Returns rescaled Image, with results being cached.&]
[s3;%% &]
[s4; &]
[s5;:CachedRescalePaintOnly`(const Image`&`,Size`,const Rect`&`): [_^Image^ Image]_[* Cac
hedRescalePaintOnly]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m],
[_^Size^ Size]_[*@3 sz], [@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 src])&]
[s5;:CachedRescalePaintOnly`(const Image`&`,Size`): [_^Image^ Image]_[* CachedRescalePain
tOnly]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m], [_^Size^ Size]_[*@3 sz])&]
[s5;:CachedRescale`(const Image`&`,Size`,const Rect`&`,int`): [_^Image^ Image]_[* CachedR
escale]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m], [_^Size^ Size]_[*@3 sz],
[@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 src], [@(0.0.255) int]_[*@3 filter]_`=_
Null)&]
[s5;:CachedRescale`(const Image`&`,Size`,int`): [_^Image^ Image]_[* CachedRescale]([@(0.0.255) c
onst]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m], [_^Size^ Size]_[*@3 sz],
[@(0.0.255) int]_[*@3 filter]_`=_Null)&]
[s2;%% Returns rescaled Image, with results being cached. [%-*@3 filter]
can be one of predefined filters for RescaleFilter function (e.g.
FILTER`_BILINEAR), if Null, standard speed optimized custom algorithm
is used.&]
[s3;%% &]
[s4; &]
[s5;:CachedRescalePaintOnly`(const Image`&`,Size`,const Rect`&`,int`): [_^Image^ Image]_
[* CachedRescalePaintOnly]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m],
[_^Size^ Size]_[*@3 sz], [@(0.0.255) const]_[_^Rect^ Rect][@(0.0.255) `&]_[*@3 src],
[@(0.0.255) int]_[*@3 filter]_`=_Null)&]
[s5;:CachedRescalePaintOnly`(const Image`&`,Size`,int`): [_^Image^ Image]_[* CachedRescal
ePaintOnly]([@(0.0.255) const]_[_^Image^ Image][@(0.0.255) `&]_[*@3 m],
[_^Size^ Size]_[*@3 sz], [@(0.0.255) int]_[*@3 filter]_`=_Null)&]
[s2;%% Returns rescaled Image, with results being cached, that can
only be used with Draw`::DrawImage(this is optimization hint that
can save some memory in certain situations).&]
[s3;%% &]
can save some memory in certain situations). [%-*@3 filter] can
be one of predefined filters for RescaleFilter function (e.g.
FILTER`_BILINEAR), if Null, standard speed optimized custom algorithm
is used.&]
[s0;%% ]]