Made Blitting more permissive (#3584)

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.
This commit is contained in:
Joseph Gelfand 2018-10-06 08:32:00 -06:00 committed by Jyrki Vesterinen
parent b854057054
commit 80f4bd839f
2 changed files with 13 additions and 14 deletions

View file

@ -413,20 +413,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);
}
@ -1021,7 +1019,12 @@ 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) {
@ -1029,11 +1032,6 @@ REGISTER_MOD_PARSER(BLIT, args)
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():";

View file

@ -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