Skip to content

Commit

Permalink
Made Blitting more permissive (#3584)
Browse files Browse the repository at this point in the history
Made Blitting more permissive

SDL_BlitSurface's documentation (https://wiki.libsdl.org/SDL_BlitSurface) notes that "Blits with negative dstrect coordinates will be clipped properly".

Looking at the source code for SDL_UpperBlit() convinced me that dstrect coordinates that were too big would also be handled appropriately.

Fixes #2225.
  • Loading branch information
JGelfand authored and jyrkive committed Oct 6, 2018
1 parent 4a23c8b commit 04674b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 10 additions & 12 deletions src/image_modifications.cpp
Expand Up @@ -407,20 +407,18 @@ surface blit_modification::operator()(const surface& src) const
throw imod_exception(sstr);
}

if(surf_->w + x_ > src->w) {
if(surf_->w + x_ < 0) {
std::stringstream sstr;
sstr << "~BLIT(): offset and width '"
<< x_ + surf_->w << "' larger than destination image's width '"
<< src->w << "' no blitting performed.\n";
<< x_ + surf_->w << "' less than zero no blitting performed.\n";

throw imod_exception(sstr);
}

if(surf_->h + y_ > src->h) {
if(surf_->h + y_ < 0) {
std::stringstream sstr;
sstr << "~BLIT(): offset and height '"
<< y_ + surf_->h << "' larger than destination image's height '"
<< src->h << "' no blitting performed.\n";
<< y_ + surf_->h << "' less than zero no blitting performed.\n";

throw imod_exception(sstr);
}
Expand Down Expand Up @@ -1015,19 +1013,19 @@ REGISTER_MOD_PARSER(BLIT, args)
ERR_DP << "no arguments passed to the ~BLIT() function" << std::endl;
return nullptr;
}


if(s > 3){
ERR_DP << "too many arguments passed to the ~BLIT() function" << std::endl;
return nullptr;
}

int x = 0, y = 0;

if(s == 3) {
x = lexical_cast_default<int>(param[1]);
y = lexical_cast_default<int>(param[2]);
}

if(x < 0 || y < 0) {
ERR_DP << "negative position arguments in ~BLIT() function" << std::endl;
return nullptr;
}

const image::locator img(param[0]);
std::stringstream message;
message << "~BLIT():";
Expand Down
5 changes: 3 additions & 2 deletions src/tests/test_image_modifications.cpp
Expand Up @@ -502,9 +502,10 @@ BOOST_AUTO_TEST_CASE(test_blit_modification_decoding_invalid_args)
modification::decode("~BLIT()"
"~BLIT(wesnoth-icon.png,1,-2)"
"~BLIT(wesnoth-icon.png,-1,2)"
"~BLIT(wesnoth-icon.png,-1,-2)");
"~BLIT(wesnoth-icon.png,-1,-2)"
"~BLIT(wesnoth-icon.png,1,2,3)");

BOOST_CHECK_EQUAL(queue.size(), 0);
BOOST_CHECK_EQUAL(queue.size(), 3);
}

/** Tests if the MASK modification with one argument is correctly decoded
Expand Down

0 comments on commit 04674b6

Please sign in to comment.