Yup, that’s just an oversight.
On Mon, Feb 18, 2013 at 8:30 AM, Mason Wheeler <masonwheeler at yahoo.com <mailto:masonwheeler at yahoo.com>> wrote:
As I said to John, there's nothing in this code that would respond
to
a
#define like that. Looking at this further, it appears that several
of
the
other blit routines are coded to respect this #define, but a bunch
of
them,
including the one my code is going through (BlitNtoN) are not. An
oversight?
Mason
*From:* Sam Lantinga <slouken at libsdl.org
<mailto:slouken at libsdl.org>>
To: Mason Wheeler <masonwheeler at yahoo.com
<mailto:masonwheeler at yahoo.com>>; SDL Development List
<sdl at lists.libsdl.org
<mailto:sdl at lists.libsdl.org>>
Sent: Sunday, February 17, 2013 11:25 PM
Subject: Re: [SDL] Proposal: remove DUFFS_LOOP macro from SDL
blit
code
As John said, you can turn it off by commenting out USE_DUFFS_LOOP
in
SDL_blit.h
It was originally added when I was optimizing the blitters and
that
yielded
about 15% speed increase over standard loops with gcc using -O2.
If you a proposing disabling it by default, I'm not opposed, but I
would
suggest benchmarking first.
Regarding your original issue, the SDL destination alpha semantics
are
a
little weird. From the SDL documentation:
RGBA->RGB:
SDL_SRCALPHA set:
alpha-blend (using alpha-channel).
SDL_SRCCOLORKEY ignored.
SDL_SRCALPHA not set:
copy RGB.
if SDL_SRCCOLORKEY set, only copy the pixels matching the
RGB values of the source colour key, ignoring alpha in
the
comparison.
RGB->RGBA:
SDL_SRCALPHA set:
alpha-blend (using the source per-surface alpha value);
set destination alpha to opaque.
SDL_SRCALPHA not set:
copy RGB, set destination alpha to source per-surface
alpha
value.
both:
if SDL_SRCCOLORKEY set, only copy the pixels matching the
source colour key.
RGBA->RGBA:
SDL_SRCALPHA set:
alpha-blend (using the source alpha channel) the RGB
values;
leave destination alpha untouched. [Note: is this
correct?]
SDL_SRCCOLORKEY ignored.
SDL_SRCALPHA not set:
copy all of RGBA to the destination.
if SDL_SRCCOLORKEY set, only copy the pixels matching the
RGB values of the source colour key, ignoring alpha in
the
comparison.
RGB->RGB:
SDL_SRCALPHA set:
alpha-blend (using the source per-surface alpha value).
SDL_SRCALPHA not set:
copy RGB.
both:
if SDL_SRCCOLORKEY set, only copy the pixels matching the
source colour key.
On Sun, Feb 17, 2013 at 7:36 AM, Mason Wheeler <masonwheeler at yahoo.com <mailto:masonwheeler at yahoo.com>> wrote:
I've got a strange problem that goes something like this:
Load two surfaces with SDL_Image. Call them A and B.
Create a new SDL_Surface with SDL_CreateRGBSurface, passing 0
for
all
the mask values. This creates a surface that does not
necessarily
have
the same pixel format as the two surfaces already loaded. Call
it
Target.
Perform a blit from A to Target. This works fine.
Perform a blit from B to Target. B contains an alpha channel,
and
I
expect Target to contain an image overlaying B onto A.
Instead, I
end
up with the entirety of Target having an alpha of 0.
I traced into SDL in the debugger, trying to figure out what
was
going
wrong, only to be stopped cold inside of BlitNtoN because the
meat
of
the function takes place inside a silly DUFFS_LOOP macro. You
can’t
trace into a macro like you can in a function call, and this
seems
like
a strange thing to have in there anyway, for two reasons.
First, Duff's Device was designed to squeeze every last cycle
out
of
direct memory copies, back when cycles were a lot more
expensive
than
they are now, but there’s a sizeable block of code in the body
of
the
loop here, not just a simple “*dest++ = *src++” type thing.
Second, Duff’s Device was invented back before a lot of modern
optimizations, both in compiler design and in CPU
architecture,
and
according to the Wikipedia article, it tends to screw some of
them
up
rather badly, leading to a net decrease in performance.
So it hurts readability, debugabilty and performance on modern
computers. Could we just replace it with a simple loop
please?
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org