The copyFrom method called in the constructor always sets
_disposeAfterUse to true, so in the case we call the constructor
with DisposeAfterUse::NO, we need to set the field value after
the call to prevent it being overwritten.
I'm also not entirely happy that the DisposeAfterUse::YES case
automatically deletes the passed surface immediately, it seems
like it'll be prone to nasty side effects. But I'm leaving as is,
because I'm not sure which code, if any, currently relies on it
to prevent a memory leak.
The create() overload of ManagedSurface that creates a
new, owned surface, previously assumed that the
_innerSurface was owned before the call was made. Thus,
when switching between sub-surface and owning surface
modes, a segfault would occur when attempting to free
the pixel data of the inner surface, which is not actually
owned by the ManagedSurface. This commit makes sure
that when free() is called, the inner surface no longer
has an active pointer to its old pixel data.
TransparentSurface now scales in place instead of making a copy. This
is much faster than before.
Also BlendBlit::blit now takes a scale offset parameter to help with
vary large images being cropped, otherwise people can leave it to 0.
Added an explicit -1 argument for transColor in a call to transBlitFrom()
inside one of the overloads of blitFrom(). This fixes an issue where
calling blitFrom() with a Rect destination would result in the transparent
color being ignored.
Function `blitFromInner()` excludes source formats with 3 bytes per pixel. These are commonly returned from opaque full-color image decoders, like JPEG. This change enables blitting with these source images.
- Add `== 3` to the list of acceptable source formats
- Add READ_UINT24 handling for 3-byte source formats
- Add READ_UINT24 and RGBA conversion for 3-byte destination when blending (copying non-opaque source to 24bpp surface)
The color components computation had intermediate results that could overflow
a signed int. So now the computation is done using unsigned int instead, which
prevents the overflow (since the max intermediate value is 255*255*257*257,
which fits in an unsigned int).
Note: I also considered adding an explicit cast to do the uint8 * uint8
operations using uint32, but decided not to as it is not required (there is no
overflow due to integer promotion) and makes the code more difficult to read.
In the case of the ManagedSurface constructor from a Surface object,
_disposeAfterUse is not initialized. But more, copyFrom() sets
_disposeAfterUse to YES after allocation of buffer. And then,
after the call to copyFrom, _disposeAfterUse was set to NO, what
made the pixels buffer not freed.
The code was only working for one specific case of 24bpp
pixel formats, and it is now generic. This fixes wrong
colors in the AGS savegame screenshots.