Skip to content

Commit

Permalink
add ~SCALE_SHARP image path function, analogous to ~SCALE
Browse files Browse the repository at this point in the history
The syntax is the same but it uses nearest neighbor instead of
bilinear interpolation
  • Loading branch information
cbeck88 committed Nov 3, 2014
1 parent d208c72 commit 5051513
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
57 changes: 57 additions & 0 deletions src/image_modifications.cpp
Expand Up @@ -371,6 +371,39 @@ int scale_modification::get_h() const
return h_;
}

surface scale_sharp_modification::operator()(const surface& src) const
{
const int old_w = src->w;
const int old_h = src->h;
int w = w_;
int h = h_;

if(w <= 0) {
if(w < 0) {
ERR_DP << "width of SCALE_SHARP is negative - resetting to original width" << std::endl;
}
w = old_w;
}
if(h <= 0) {
if(h < 0) {
ERR_DP << "height of SCALE_SHARP is negative - resetting to original height" << std::endl;
}
h = old_h;
}

return scale_surface_sharp(src, w, h);
}

int scale_sharp_modification::get_w() const
{
return w_;
}

int scale_sharp_modification::get_h() const
{
return h_;
}

surface xbrz_modification::operator()(const surface& src) const
{
if (z_ == 1) {
Expand Down Expand Up @@ -888,6 +921,28 @@ REGISTER_MOD_PARSER(SCALE, args)
return new scale_modification(w, h);
}

REGISTER_MOD_PARSER(SCALE_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_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_sharp_modification(w, h);
}


// xBRZ
REGISTER_MOD_PARSER(xBRZ, args)
{
Expand All @@ -899,6 +954,8 @@ REGISTER_MOD_PARSER(xBRZ, args)
return new xbrz_modification(z);
}

// scale

// Gaussian-like blur
REGISTER_MOD_PARSER(BL, args)
{
Expand Down
20 changes: 19 additions & 1 deletion src/image_modifications.hpp
Expand Up @@ -301,7 +301,7 @@ class light_modification : public modification
};

/**
* Scale (SCALE) modification.
* Scale (SCALE) modification. (Uses bilinear interpolation.)
*/
class scale_modification : public modification
{
Expand All @@ -317,6 +317,24 @@ class scale_modification : public modification
int w_, h_;
};

/**
* Scale sharp (SCALE_SHARP) modification. (Uses nearest neighbor.)
*/
class scale_sharp_modification : public modification
{
public:
scale_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
*/
Expand Down

0 comments on commit 5051513

Please sign in to comment.