Change SCALE_INTO() to use BI and added SCALE_INTO_SHARP() which uses NN
This commit is contained in:
parent
931376954b
commit
23be0d74f3
3 changed files with 78 additions and 3 deletions
|
@ -9,7 +9,10 @@ Version 1.13.4+dev:
|
|||
* Add highlight=yes|no to [scroll_to], [scroll_to_unit], [message]
|
||||
Defaults to no in the first two cases, yes in the third
|
||||
If yes, the target hex is outlined.
|
||||
* New ~SCALE_INTO(w,h) IPF which preserves aspect ratio, using NN.
|
||||
* New ~SCALE_INTO(w,h) IPF which preserves aspect ratio, using bilinear
|
||||
interlopation scaling.
|
||||
* New ~SCALE_INTO_SHARP(w,h) IPF which preserves aspect ratio, using
|
||||
nearest neighbor scaling.
|
||||
* Lua API:
|
||||
* wesnoth.match_unit can now take a location (rather than a unit) as
|
||||
the optional third parameter. This will cause the filter to consider
|
||||
|
|
|
@ -448,7 +448,7 @@ surface scale_into_modification::operator()(const surface& src) const
|
|||
|
||||
long double ratio = std::min(w / old_w, h / old_h);
|
||||
|
||||
return scale_surface_sharp(src, old_w * ratio, old_h * ratio);
|
||||
return scale_surface(src, old_w * ratio, old_h * ratio);
|
||||
}
|
||||
|
||||
int scale_into_modification::get_w() const
|
||||
|
@ -461,6 +461,41 @@ int scale_into_modification::get_h() const
|
|||
return h_;
|
||||
}
|
||||
|
||||
surface scale_into_sharp_modification::operator()(const surface& src) const
|
||||
{
|
||||
const int old_w = src->w;
|
||||
const int old_h = src->h;
|
||||
long double w = w_;
|
||||
long double h = h_;
|
||||
|
||||
if(w <= 0) {
|
||||
if(w < 0) {
|
||||
ERR_DP << "width of SCALE_INTO_SHARP is negative - resetting to original width" << std::endl;
|
||||
}
|
||||
w = old_w;
|
||||
}
|
||||
if(h <= 0) {
|
||||
if(h < 0) {
|
||||
ERR_DP << "height of SCALE_INTO_SHARP is negative - resetting to original height" << std::endl;
|
||||
}
|
||||
h = old_h;
|
||||
}
|
||||
|
||||
long double ratio = std::min(w / old_w, h / old_h);
|
||||
|
||||
return scale_surface_sharp(src, old_w * ratio, old_h * ratio);
|
||||
}
|
||||
|
||||
int scale_into_sharp_modification::get_w() const
|
||||
{
|
||||
return w_;
|
||||
}
|
||||
|
||||
int scale_into_sharp_modification::get_h() const
|
||||
{
|
||||
return h_;
|
||||
}
|
||||
|
||||
surface xbrz_modification::operator()(const surface& src) const
|
||||
{
|
||||
if (z_ == 1) {
|
||||
|
@ -1136,6 +1171,26 @@ REGISTER_MOD_PARSER(SCALE_INTO, args)
|
|||
return new scale_into_modification(w, h);
|
||||
}
|
||||
|
||||
REGISTER_MOD_PARSER(SCALE_INTO_SHARP, args)
|
||||
{
|
||||
std::vector<std::string> const& scale_params = utils::split(args, ',', utils::STRIP_SPACES);
|
||||
const size_t s = scale_params.size();
|
||||
|
||||
if(s == 0 || (s == 1 && scale_params[0].empty())) {
|
||||
ERR_DP << "no arguments passed to the ~SCALE_INTO_SHARP() function" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int w = 0, h = 0;
|
||||
|
||||
w = lexical_cast_default<int, const std::string&>(scale_params[0]);
|
||||
|
||||
if(s > 1) {
|
||||
h = lexical_cast_default<int, const std::string&>(scale_params[1]);
|
||||
}
|
||||
|
||||
return new scale_into_sharp_modification(w, h);
|
||||
}
|
||||
|
||||
// xBRZ
|
||||
REGISTER_MOD_PARSER(XBRZ, args)
|
||||
|
|
|
@ -402,7 +402,7 @@ private:
|
|||
};
|
||||
|
||||
/**
|
||||
* Scale into (SCALE_INTO) modification. (Uses nearest neighbor.)
|
||||
* Scale into (SCALE_INTO) modification. (Uses bilinear interpolation.)
|
||||
* Preserves aspect ratio.
|
||||
*/
|
||||
class scale_into_modification : public modification
|
||||
|
@ -419,6 +419,23 @@ private:
|
|||
int w_, h_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Scale into (SCALE_INTO_SHARP) modification. (Uses nearest neighbor.)
|
||||
* Preserves aspect ratio.
|
||||
*/
|
||||
class scale_into_sharp_modification : public modification
|
||||
{
|
||||
public:
|
||||
scale_into_sharp_modification(int width, int height)
|
||||
: w_(width), h_(height)
|
||||
{}
|
||||
virtual surface operator()(const surface& src) const;
|
||||
int get_w() const;
|
||||
int get_h() const;
|
||||
|
||||
private:
|
||||
int w_, h_;
|
||||
};
|
||||
|
||||
/**
|
||||
* xBRZ scale (xBRZ) modification
|
||||
|
|
Loading…
Add table
Reference in a new issue