SFML community forums

Help => Graphics => Topic started by: pdinklag on March 13, 2013, 04:24:06 pm

Title: Mistake in sf::Image::copy?
Post by: pdinklag on March 13, 2013, 04:24:06 pm
I just noticed the following piece of code in sf::Image::copy (Image.cpp line 176 and 177 (https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Image.cpp#L176)):
if (srcRect.width  > static_cast<int>(source.m_size.x)) srcRect.width  = source.m_size.x;
if (srcRect.height > static_cast<int>(source.m_size.y)) srcRect.height = source.m_size.y;

The source rectangle may still be larger than the source texture this way (e.g. if srcRect.left > 0 and srcRect.width = width of source image).

I suppose what was meant is this:
if (srcRect.width  > static_cast<int>(source.m_size.x) - srcRect.left) srcRect.width  = source.m_size.x - srcRect.left;
if (srcRect.height > static_cast<int>(source.m_size.y) - srcRect.top ) srcRect.height = source.m_size.y - srcRect.top;
Title: Re: Mistake in sf::Image::copy?
Post by: Laurent on March 13, 2013, 04:41:00 pm
I think you're right :)