SDL 2.0
SDL_blit_A.c File Reference
#include "../SDL_internal.h"
#include "SDL_video.h"
#include "SDL_blit.h"
+ Include dependency graph for SDL_blit_A.c:

Go to the source code of this file.

Macros

#define BLEND16_50(d, s, mask)    ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
 
#define BLEND2x16_50(d, s, mask)
 

Functions

static void BlitNto1SurfaceAlpha (SDL_BlitInfo *info)
 
static void BlitNto1PixelAlpha (SDL_BlitInfo *info)
 
static void BlitNto1SurfaceAlphaKey (SDL_BlitInfo *info)
 
static void BlitRGBtoRGBSurfaceAlpha128 (SDL_BlitInfo *info)
 
static void BlitRGBtoRGBSurfaceAlpha (SDL_BlitInfo *info)
 
static void BlitRGBtoRGBPixelAlpha (SDL_BlitInfo *info)
 
static void Blit16to16SurfaceAlpha128 (SDL_BlitInfo *info, Uint16 mask)
 
static void Blit565to565SurfaceAlpha (SDL_BlitInfo *info)
 
static void Blit555to555SurfaceAlpha (SDL_BlitInfo *info)
 
static void BlitARGBto565PixelAlpha (SDL_BlitInfo *info)
 
static void BlitARGBto555PixelAlpha (SDL_BlitInfo *info)
 
static void BlitNtoNSurfaceAlpha (SDL_BlitInfo *info)
 
static void BlitNtoNSurfaceAlphaKey (SDL_BlitInfo *info)
 
static void BlitNtoNPixelAlpha (SDL_BlitInfo *info)
 
SDL_BlitFunc SDL_CalculateBlitA (SDL_Surface *surface)
 

Macro Definition Documentation

◆ BLEND16_50

#define BLEND16_50 (   d,
  s,
  mask 
)     ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))

Definition at line 588 of file SDL_blit_A.c.

◆ BLEND2x16_50

#define BLEND2x16_50 (   d,
  s,
  mask 
)
Value:
(((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
+ (s & d & (~(mask | mask << 16))))
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
GLdouble s
Definition: SDL_opengl.h:2063
GLenum GLint GLuint mask

Definition at line 592 of file SDL_blit_A.c.

Function Documentation

◆ Blit16to16SurfaceAlpha128()

static void Blit16to16SurfaceAlpha128 ( SDL_BlitInfo info,
Uint16  mask 
)
static

Definition at line 597 of file SDL_blit_A.c.

598{
599 int width = info->dst_w;
600 int height = info->dst_h;
601 Uint16 *srcp = (Uint16 *) info->src;
602 int srcskip = info->src_skip >> 1;
603 Uint16 *dstp = (Uint16 *) info->dst;
604 int dstskip = info->dst_skip >> 1;
605
606 while (height--) {
607 if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) {
608 /*
609 * Source and destination not aligned, pipeline it.
610 * This is mostly a win for big blits but no loss for
611 * small ones
612 */
613 Uint32 prev_sw;
614 int w = width;
615
616 /* handle odd destination */
617 if ((uintptr_t) dstp & 2) {
618 Uint16 d = *dstp, s = *srcp;
619 *dstp = BLEND16_50(d, s, mask);
620 dstp++;
621 srcp++;
622 w--;
623 }
624 srcp++; /* srcp is now 32-bit aligned */
625
626 /* bootstrap pipeline with first halfword */
627 prev_sw = ((Uint32 *) srcp)[-1];
628
629 while (w > 1) {
630 Uint32 sw, dw, s;
631 sw = *(Uint32 *) srcp;
632 dw = *(Uint32 *) dstp;
633#if SDL_BYTEORDER == SDL_BIG_ENDIAN
634 s = (prev_sw << 16) + (sw >> 16);
635#else
636 s = (prev_sw >> 16) + (sw << 16);
637#endif
638 prev_sw = sw;
639 *(Uint32 *) dstp = BLEND2x16_50(dw, s, mask);
640 dstp += 2;
641 srcp += 2;
642 w -= 2;
643 }
644
645 /* final pixel if any */
646 if (w) {
647 Uint16 d = *dstp, s;
648#if SDL_BYTEORDER == SDL_BIG_ENDIAN
649 s = (Uint16) prev_sw;
650#else
651 s = (Uint16) (prev_sw >> 16);
652#endif
653 *dstp = BLEND16_50(d, s, mask);
654 srcp++;
655 dstp++;
656 }
657 srcp += srcskip - 1;
658 dstp += dstskip;
659 } else {
660 /* source and destination are aligned */
661 int w = width;
662
663 /* first odd pixel? */
664 if ((uintptr_t) srcp & 2) {
665 Uint16 d = *dstp, s = *srcp;
666 *dstp = BLEND16_50(d, s, mask);
667 srcp++;
668 dstp++;
669 w--;
670 }
671 /* srcp and dstp are now 32-bit aligned */
672
673 while (w > 1) {
674 Uint32 sw = *(Uint32 *) srcp;
675 Uint32 dw = *(Uint32 *) dstp;
676 *(Uint32 *) dstp = BLEND2x16_50(dw, sw, mask);
677 srcp += 2;
678 dstp += 2;
679 w -= 2;
680 }
681
682 /* last odd pixel? */
683 if (w) {
684 Uint16 d = *dstp, s = *srcp;
685 *dstp = BLEND16_50(d, s, mask);
686 srcp++;
687 dstp++;
688 }
689 srcp += srcskip;
690 dstp += dstskip;
691 }
692 }
693}
#define BLEND16_50(d, s, mask)
Definition: SDL_blit_A.c:588
#define BLEND2x16_50(d, s, mask)
Definition: SDL_blit_A.c:592
unsigned int uintptr_t
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
GLubyte GLubyte GLubyte GLubyte w
uint32_t Uint32
Definition: SDL_stdinc.h:203
uint16_t Uint16
Definition: SDL_stdinc.h:191
int dst_skip
Definition: SDL_blit.h:64
int src_skip
Definition: SDL_blit.h:60
Uint8 * src
Definition: SDL_blit.h:57
Uint8 * dst
Definition: SDL_blit.h:61

References BLEND16_50, BLEND2x16_50, d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by Blit555to555SurfaceAlpha(), and Blit565to565SurfaceAlpha().

◆ Blit555to555SurfaceAlpha()

static void Blit555to555SurfaceAlpha ( SDL_BlitInfo info)
static

Definition at line 1015 of file SDL_blit_A.c.

1016{
1017 unsigned alpha = info->a; /* downscale alpha to 5 bits */
1018 if (alpha == 128) {
1019 Blit16to16SurfaceAlpha128(info, 0xfbde);
1020 } else {
1021 int width = info->dst_w;
1022 int height = info->dst_h;
1023 Uint16 *srcp = (Uint16 *) info->src;
1024 int srcskip = info->src_skip >> 1;
1025 Uint16 *dstp = (Uint16 *) info->dst;
1026 int dstskip = info->dst_skip >> 1;
1027 alpha >>= 3; /* downscale alpha to 5 bits */
1028
1029 while (height--) {
1030 /* *INDENT-OFF* */
1031 DUFFS_LOOP4({
1032 Uint32 s = *srcp++;
1033 Uint32 d = *dstp;
1034 /*
1035 * shift out the middle component (green) to
1036 * the high 16 bits, and process all three RGB
1037 * components at the same time.
1038 */
1039 s = (s | s << 16) & 0x03e07c1f;
1040 d = (d | d << 16) & 0x03e07c1f;
1041 d += (s - d) * alpha >> 5;
1042 d &= 0x03e07c1f;
1043 *dstp++ = (Uint16)(d | d >> 16);
1044 }, width);
1045 /* *INDENT-ON* */
1046 srcp += srcskip;
1047 dstp += dstskip;
1048 }
1049 }
1050}
#define DUFFS_LOOP4(pixel_copy_increment, width)
Definition: SDL_blit.h:488
static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
Definition: SDL_blit_A.c:597
GLfloat GLfloat GLfloat alpha
Uint8 a
Definition: SDL_blit.h:70

References SDL_BlitInfo::a, Blit16to16SurfaceAlpha128(), d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ Blit565to565SurfaceAlpha()

static void Blit565to565SurfaceAlpha ( SDL_BlitInfo info)
static

Definition at line 976 of file SDL_blit_A.c.

977{
978 unsigned alpha = info->a;
979 if (alpha == 128) {
980 Blit16to16SurfaceAlpha128(info, 0xf7de);
981 } else {
982 int width = info->dst_w;
983 int height = info->dst_h;
984 Uint16 *srcp = (Uint16 *) info->src;
985 int srcskip = info->src_skip >> 1;
986 Uint16 *dstp = (Uint16 *) info->dst;
987 int dstskip = info->dst_skip >> 1;
988 alpha >>= 3; /* downscale alpha to 5 bits */
989
990 while (height--) {
991 /* *INDENT-OFF* */
993 Uint32 s = *srcp++;
994 Uint32 d = *dstp;
995 /*
996 * shift out the middle component (green) to
997 * the high 16 bits, and process all three RGB
998 * components at the same time.
999 */
1000 s = (s | s << 16) & 0x07e0f81f;
1001 d = (d | d << 16) & 0x07e0f81f;
1002 d += (s - d) * alpha >> 5;
1003 d &= 0x07e0f81f;
1004 *dstp++ = (Uint16)(d | d >> 16);
1005 }, width);
1006 /* *INDENT-ON* */
1007 srcp += srcskip;
1008 dstp += dstskip;
1009 }
1010 }
1011}

References SDL_BlitInfo::a, Blit16to16SurfaceAlpha128(), d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitARGBto555PixelAlpha()

static void BlitARGBto555PixelAlpha ( SDL_BlitInfo info)
static

Definition at line 1100 of file SDL_blit_A.c.

1101{
1102 int width = info->dst_w;
1103 int height = info->dst_h;
1104 Uint32 *srcp = (Uint32 *) info->src;
1105 int srcskip = info->src_skip >> 2;
1106 Uint16 *dstp = (Uint16 *) info->dst;
1107 int dstskip = info->dst_skip >> 1;
1108
1109 while (height--) {
1110 /* *INDENT-OFF* */
1111 DUFFS_LOOP4({
1112 unsigned alpha;
1113 Uint32 s = *srcp;
1114 alpha = s >> 27; /* downscale alpha to 5 bits */
1115 /* FIXME: Here we special-case opaque alpha since the
1116 compositioning used (>>8 instead of /255) doesn't handle
1117 it correctly. Also special-case alpha=0 for speed?
1118 Benchmark this! */
1119 if(alpha) {
1120 if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
1121 *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f));
1122 } else {
1123 Uint32 d = *dstp;
1124 /*
1125 * convert source and destination to G0RAB65565
1126 * and blend all components at the same time
1127 */
1128 s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00)
1129 + (s >> 3 & 0x1f);
1130 d = (d | d << 16) & 0x03e07c1f;
1131 d += (s - d) * alpha >> 5;
1132 d &= 0x03e07c1f;
1133 *dstp = (Uint16)(d | d >> 16);
1134 }
1135 }
1136 srcp++;
1137 dstp++;
1138 }, width);
1139 /* *INDENT-ON* */
1140 srcp += srcskip;
1141 dstp += dstskip;
1142 }
1143}
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46

References d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_ALPHA_OPAQUE, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitARGBto565PixelAlpha()

static void BlitARGBto565PixelAlpha ( SDL_BlitInfo info)
static

Definition at line 1054 of file SDL_blit_A.c.

1055{
1056 int width = info->dst_w;
1057 int height = info->dst_h;
1058 Uint32 *srcp = (Uint32 *) info->src;
1059 int srcskip = info->src_skip >> 2;
1060 Uint16 *dstp = (Uint16 *) info->dst;
1061 int dstskip = info->dst_skip >> 1;
1062
1063 while (height--) {
1064 /* *INDENT-OFF* */
1065 DUFFS_LOOP4({
1066 Uint32 s = *srcp;
1067 unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
1068 /* FIXME: Here we special-case opaque alpha since the
1069 compositioning used (>>8 instead of /255) doesn't handle
1070 it correctly. Also special-case alpha=0 for speed?
1071 Benchmark this! */
1072 if(alpha) {
1073 if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
1074 *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
1075 } else {
1076 Uint32 d = *dstp;
1077 /*
1078 * convert source and destination to G0RAB65565
1079 * and blend all components at the same time
1080 */
1081 s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800)
1082 + (s >> 3 & 0x1f);
1083 d = (d | d << 16) & 0x07e0f81f;
1084 d += (s - d) * alpha >> 5;
1085 d &= 0x07e0f81f;
1086 *dstp = (Uint16)(d | d >> 16);
1087 }
1088 }
1089 srcp++;
1090 dstp++;
1091 }, width);
1092 /* *INDENT-ON* */
1093 srcp += srcskip;
1094 dstp += dstskip;
1095 }
1096}

References d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_ALPHA_OPAQUE, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitNto1PixelAlpha()

static void BlitNto1PixelAlpha ( SDL_BlitInfo info)
static

Definition at line 77 of file SDL_blit_A.c.

78{
79 int width = info->dst_w;
80 int height = info->dst_h;
81 Uint8 *src = info->src;
82 int srcskip = info->src_skip;
83 Uint8 *dst = info->dst;
84 int dstskip = info->dst_skip;
85 Uint8 *palmap = info->table;
86 SDL_PixelFormat *srcfmt = info->src_fmt;
87 SDL_PixelFormat *dstfmt = info->dst_fmt;
88 int srcbpp = srcfmt->BytesPerPixel;
89 Uint32 Pixel;
90 unsigned sR, sG, sB, sA;
91 unsigned dR, dG, dB;
92
93 while (height--) {
94 /* *INDENT-OFF* */
96 {
97 DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
98 dR = dstfmt->palette->colors[*dst].r;
99 dG = dstfmt->palette->colors[*dst].g;
100 dB = dstfmt->palette->colors[*dst].b;
101 ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB);
102 dR &= 0xff;
103 dG &= 0xff;
104 dB &= 0xff;
105 /* Pack RGB into 8bit pixel */
106 if ( palmap == NULL ) {
107 *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
108 } else {
109 *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
110 }
111 dst++;
112 src += srcbpp;
113 },
114 width);
115 /* *INDENT-ON* */
116 src += srcskip;
117 dst += dstskip;
118 }
119}
#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)
Definition: SDL_blit.h:353
#define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB)
Definition: SDL_blit.h:445
GLenum src
GLenum GLenum dst
uint8_t Uint8
Definition: SDL_stdinc.h:179
#define NULL
Definition: begin_code.h:167
SDL_PixelFormat * src_fmt
Definition: SDL_blit.h:65
Uint8 * table
Definition: SDL_blit.h:67
SDL_PixelFormat * dst_fmt
Definition: SDL_blit.h:66
Uint8 r
Definition: SDL_pixels.h:297
Uint8 b
Definition: SDL_pixels.h:299
Uint8 g
Definition: SDL_pixels.h:298
SDL_Color * colors
Definition: SDL_pixels.h:307
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
SDL_Palette * palette
Definition: SDL_pixels.h:318

References ALPHA_BLEND_RGB, SDL_Color::b, SDL_PixelFormat::BytesPerPixel, SDL_Palette::colors, DISEMBLE_RGBA, SDL_BlitInfo::dst, SDL_BlitInfo::dst_fmt, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_Color::g, NULL, SDL_PixelFormat::palette, SDL_Color::r, SDL_BlitInfo::src, SDL_BlitInfo::src_fmt, SDL_BlitInfo::src_skip, and SDL_BlitInfo::table.

Referenced by SDL_CalculateBlitA().

◆ BlitNto1SurfaceAlpha()

static void BlitNto1SurfaceAlpha ( SDL_BlitInfo info)
static

Definition at line 30 of file SDL_blit_A.c.

31{
32 int width = info->dst_w;
33 int height = info->dst_h;
34 Uint8 *src = info->src;
35 int srcskip = info->src_skip;
36 Uint8 *dst = info->dst;
37 int dstskip = info->dst_skip;
38 Uint8 *palmap = info->table;
39 SDL_PixelFormat *srcfmt = info->src_fmt;
40 SDL_PixelFormat *dstfmt = info->dst_fmt;
41 int srcbpp = srcfmt->BytesPerPixel;
42 Uint32 Pixel;
43 unsigned sR, sG, sB;
44 unsigned dR, dG, dB;
45 const unsigned A = info->a;
46
47 while (height--) {
48 /* *INDENT-OFF* */
50 {
51 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
52 dR = dstfmt->palette->colors[*dst].r;
53 dG = dstfmt->palette->colors[*dst].g;
54 dB = dstfmt->palette->colors[*dst].b;
55 ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
56 dR &= 0xff;
57 dG &= 0xff;
58 dB &= 0xff;
59 /* Pack RGB into 8bit pixel */
60 if ( palmap == NULL ) {
61 *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
62 } else {
63 *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
64 }
65 dst++;
66 src += srcbpp;
67 },
68 width);
69 /* *INDENT-ON* */
70 src += srcskip;
71 dst += dstskip;
72 }
73}
#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b)
Definition: SDL_blit.h:177

References SDL_BlitInfo::a, ALPHA_BLEND_RGB, SDL_Color::b, SDL_PixelFormat::BytesPerPixel, SDL_Palette::colors, DISEMBLE_RGB, SDL_BlitInfo::dst, SDL_BlitInfo::dst_fmt, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_Color::g, NULL, SDL_PixelFormat::palette, SDL_Color::r, SDL_BlitInfo::src, SDL_BlitInfo::src_fmt, SDL_BlitInfo::src_skip, and SDL_BlitInfo::table.

Referenced by SDL_CalculateBlitA().

◆ BlitNto1SurfaceAlphaKey()

static void BlitNto1SurfaceAlphaKey ( SDL_BlitInfo info)
static

Definition at line 123 of file SDL_blit_A.c.

124{
125 int width = info->dst_w;
126 int height = info->dst_h;
127 Uint8 *src = info->src;
128 int srcskip = info->src_skip;
129 Uint8 *dst = info->dst;
130 int dstskip = info->dst_skip;
131 Uint8 *palmap = info->table;
132 SDL_PixelFormat *srcfmt = info->src_fmt;
133 SDL_PixelFormat *dstfmt = info->dst_fmt;
134 int srcbpp = srcfmt->BytesPerPixel;
135 Uint32 ckey = info->colorkey;
136 Uint32 Pixel;
137 unsigned sR, sG, sB;
138 unsigned dR, dG, dB;
139 const unsigned A = info->a;
140
141 while (height--) {
142 /* *INDENT-OFF* */
144 {
145 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
146 if ( Pixel != ckey ) {
147 dR = dstfmt->palette->colors[*dst].r;
148 dG = dstfmt->palette->colors[*dst].g;
149 dB = dstfmt->palette->colors[*dst].b;
150 ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
151 dR &= 0xff;
152 dG &= 0xff;
153 dB &= 0xff;
154 /* Pack RGB into 8bit pixel */
155 if ( palmap == NULL ) {
156 *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
157 } else {
158 *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
159 }
160 }
161 dst++;
162 src += srcbpp;
163 },
164 width);
165 /* *INDENT-ON* */
166 src += srcskip;
167 dst += dstskip;
168 }
169}
#define DUFFS_LOOP(pixel_copy_increment, width)
Definition: SDL_blit.h:500
Uint32 colorkey
Definition: SDL_blit.h:69

References SDL_BlitInfo::a, ALPHA_BLEND_RGB, SDL_Color::b, SDL_PixelFormat::BytesPerPixel, SDL_BlitInfo::colorkey, SDL_Palette::colors, DISEMBLE_RGB, SDL_BlitInfo::dst, SDL_BlitInfo::dst_fmt, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP, SDL_Color::g, NULL, SDL_PixelFormat::palette, SDL_Color::r, SDL_BlitInfo::src, SDL_BlitInfo::src_fmt, SDL_BlitInfo::src_skip, and SDL_BlitInfo::table.

Referenced by SDL_CalculateBlitA().

◆ BlitNtoNPixelAlpha()

static void BlitNtoNPixelAlpha ( SDL_BlitInfo info)
static

Definition at line 1227 of file SDL_blit_A.c.

1228{
1229 int width = info->dst_w;
1230 int height = info->dst_h;
1231 Uint8 *src = info->src;
1232 int srcskip = info->src_skip;
1233 Uint8 *dst = info->dst;
1234 int dstskip = info->dst_skip;
1235 SDL_PixelFormat *srcfmt = info->src_fmt;
1236 SDL_PixelFormat *dstfmt = info->dst_fmt;
1237 int srcbpp;
1238 int dstbpp;
1239 Uint32 Pixel;
1240 unsigned sR, sG, sB, sA;
1241 unsigned dR, dG, dB, dA;
1242
1243 /* Set up some basic variables */
1244 srcbpp = srcfmt->BytesPerPixel;
1245 dstbpp = dstfmt->BytesPerPixel;
1246
1247 while (height--) {
1248 /* *INDENT-OFF* */
1250 {
1251 DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
1252 if(sA) {
1253 DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
1254 ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
1255 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
1256 }
1257 src += srcbpp;
1258 dst += dstbpp;
1259 },
1260 width);
1261 /* *INDENT-ON* */
1262 src += srcskip;
1263 dst += dstskip;
1264 }
1265}
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)
Definition: SDL_blit.h:402
#define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA)
Definition: SDL_blit.h:454

References ALPHA_BLEND_RGBA, ASSEMBLE_RGBA, SDL_PixelFormat::BytesPerPixel, DISEMBLE_RGBA, SDL_BlitInfo::dst, SDL_BlitInfo::dst_fmt, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_BlitInfo::src, SDL_BlitInfo::src_fmt, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitNtoNSurfaceAlpha()

static void BlitNtoNSurfaceAlpha ( SDL_BlitInfo info)
static

Definition at line 1147 of file SDL_blit_A.c.

1148{
1149 int width = info->dst_w;
1150 int height = info->dst_h;
1151 Uint8 *src = info->src;
1152 int srcskip = info->src_skip;
1153 Uint8 *dst = info->dst;
1154 int dstskip = info->dst_skip;
1155 SDL_PixelFormat *srcfmt = info->src_fmt;
1156 SDL_PixelFormat *dstfmt = info->dst_fmt;
1157 int srcbpp = srcfmt->BytesPerPixel;
1158 int dstbpp = dstfmt->BytesPerPixel;
1159 Uint32 Pixel;
1160 unsigned sR, sG, sB;
1161 unsigned dR, dG, dB, dA;
1162 const unsigned sA = info->a;
1163
1164 if (sA) {
1165 while (height--) {
1166 /* *INDENT-OFF* */
1168 {
1169 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
1170 DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
1171 ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
1172 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
1173 src += srcbpp;
1174 dst += dstbpp;
1175 },
1176 width);
1177 /* *INDENT-ON* */
1178 src += srcskip;
1179 dst += dstskip;
1180 }
1181 }
1182}

References SDL_BlitInfo::a, ALPHA_BLEND_RGBA, ASSEMBLE_RGBA, SDL_PixelFormat::BytesPerPixel, DISEMBLE_RGB, DISEMBLE_RGBA, SDL_BlitInfo::dst, SDL_BlitInfo::dst_fmt, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_BlitInfo::src, SDL_BlitInfo::src_fmt, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitNtoNSurfaceAlphaKey()

static void BlitNtoNSurfaceAlphaKey ( SDL_BlitInfo info)
static

Definition at line 1186 of file SDL_blit_A.c.

1187{
1188 int width = info->dst_w;
1189 int height = info->dst_h;
1190 Uint8 *src = info->src;
1191 int srcskip = info->src_skip;
1192 Uint8 *dst = info->dst;
1193 int dstskip = info->dst_skip;
1194 SDL_PixelFormat *srcfmt = info->src_fmt;
1195 SDL_PixelFormat *dstfmt = info->dst_fmt;
1196 Uint32 ckey = info->colorkey;
1197 int srcbpp = srcfmt->BytesPerPixel;
1198 int dstbpp = dstfmt->BytesPerPixel;
1199 Uint32 Pixel;
1200 unsigned sR, sG, sB;
1201 unsigned dR, dG, dB, dA;
1202 const unsigned sA = info->a;
1203
1204 while (height--) {
1205 /* *INDENT-OFF* */
1207 {
1208 RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
1209 if(sA && Pixel != ckey) {
1210 RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
1211 DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
1212 ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
1213 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
1214 }
1215 src += srcbpp;
1216 dst += dstbpp;
1217 },
1218 width);
1219 /* *INDENT-ON* */
1220 src += srcskip;
1221 dst += dstskip;
1222 }
1223}
#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel)
Definition: SDL_blit.h:146
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)
Definition: SDL_blit.h:122

References SDL_BlitInfo::a, ALPHA_BLEND_RGBA, ASSEMBLE_RGBA, SDL_PixelFormat::BytesPerPixel, SDL_BlitInfo::colorkey, DISEMBLE_RGBA, SDL_BlitInfo::dst, SDL_BlitInfo::dst_fmt, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, RETRIEVE_RGB_PIXEL, RGB_FROM_PIXEL, SDL_BlitInfo::src, SDL_BlitInfo::src_fmt, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitRGBtoRGBPixelAlpha()

static void BlitRGBtoRGBPixelAlpha ( SDL_BlitInfo info)
static

Definition at line 461 of file SDL_blit_A.c.

462{
463 int width = info->dst_w;
464 int height = info->dst_h;
465 Uint32 *srcp = (Uint32 *) info->src;
466 int srcskip = info->src_skip >> 2;
467 Uint32 *dstp = (Uint32 *) info->dst;
468 int dstskip = info->dst_skip >> 2;
469
470 while (height--) {
471 /* *INDENT-OFF* */
473 Uint32 dalpha;
474 Uint32 d;
475 Uint32 s1;
476 Uint32 d1;
477 Uint32 s = *srcp;
478 Uint32 alpha = s >> 24;
479 /* FIXME: Here we special-case opaque alpha since the
480 compositioning used (>>8 instead of /255) doesn't handle
481 it correctly. Also special-case alpha=0 for speed?
482 Benchmark this! */
483 if (alpha) {
484 if (alpha == SDL_ALPHA_OPAQUE) {
485 *dstp = *srcp;
486 } else {
487 /*
488 * take out the middle component (green), and process
489 * the other two in parallel. One multiply less.
490 */
491 d = *dstp;
492 dalpha = d >> 24;
493 s1 = s & 0xff00ff;
494 d1 = d & 0xff00ff;
495 d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
496 s &= 0xff00;
497 d &= 0xff00;
498 d = (d + ((s - d) * alpha >> 8)) & 0xff00;
499 dalpha = alpha + (dalpha * (alpha ^ 0xFF) >> 8);
500 *dstp = d1 | d | (dalpha << 24);
501 }
502 }
503 ++srcp;
504 ++dstp;
505 }, width);
506 /* *INDENT-ON* */
507 srcp += srcskip;
508 dstp += dstskip;
509 }
510}
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1

References d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_ALPHA_OPAQUE, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitRGBtoRGBSurfaceAlpha()

static void BlitRGBtoRGBSurfaceAlpha ( SDL_BlitInfo info)
static

Definition at line 419 of file SDL_blit_A.c.

420{
421 unsigned alpha = info->a;
422 if (alpha == 128) {
424 } else {
425 int width = info->dst_w;
426 int height = info->dst_h;
427 Uint32 *srcp = (Uint32 *) info->src;
428 int srcskip = info->src_skip >> 2;
429 Uint32 *dstp = (Uint32 *) info->dst;
430 int dstskip = info->dst_skip >> 2;
431 Uint32 s;
432 Uint32 d;
433 Uint32 s1;
434 Uint32 d1;
435
436 while (height--) {
437 /* *INDENT-OFF* */
439 s = *srcp;
440 d = *dstp;
441 s1 = s & 0xff00ff;
442 d1 = d & 0xff00ff;
443 d1 = (d1 + ((s1 - d1) * alpha >> 8))
444 & 0xff00ff;
445 s &= 0xff00;
446 d &= 0xff00;
447 d = (d + ((s - d) * alpha >> 8)) & 0xff00;
448 *dstp = d1 | d | 0xff000000;
449 ++srcp;
450 ++dstp;
451 }, width);
452 /* *INDENT-ON* */
453 srcp += srcskip;
454 dstp += dstskip;
455 }
456 }
457}
static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:394

References SDL_BlitInfo::a, BlitRGBtoRGBSurfaceAlpha128(), d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by SDL_CalculateBlitA().

◆ BlitRGBtoRGBSurfaceAlpha128()

static void BlitRGBtoRGBSurfaceAlpha128 ( SDL_BlitInfo info)
static

Definition at line 394 of file SDL_blit_A.c.

395{
396 int width = info->dst_w;
397 int height = info->dst_h;
398 Uint32 *srcp = (Uint32 *) info->src;
399 int srcskip = info->src_skip >> 2;
400 Uint32 *dstp = (Uint32 *) info->dst;
401 int dstskip = info->dst_skip >> 2;
402
403 while (height--) {
404 /* *INDENT-OFF* */
406 Uint32 s = *srcp++;
407 Uint32 d = *dstp;
408 *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
409 + (s & d & 0x00010101)) | 0xff000000;
410 }, width);
411 /* *INDENT-ON* */
412 srcp += srcskip;
413 dstp += dstskip;
414 }
415}

References d, SDL_BlitInfo::dst, SDL_BlitInfo::dst_h, SDL_BlitInfo::dst_skip, SDL_BlitInfo::dst_w, DUFFS_LOOP4, SDL_BlitInfo::src, and SDL_BlitInfo::src_skip.

Referenced by BlitRGBtoRGBSurfaceAlpha().

◆ SDL_CalculateBlitA()

SDL_BlitFunc SDL_CalculateBlitA ( SDL_Surface surface)

Definition at line 1269 of file SDL_blit_A.c.

1270{
1272 SDL_PixelFormat *df = surface->map->dst->format;
1273
1274 switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
1275 case SDL_COPY_BLEND:
1276 /* Per-pixel alpha blits */
1277 switch (df->BytesPerPixel) {
1278 case 1:
1279 if (df->palette != NULL) {
1280 return BlitNto1PixelAlpha;
1281 } else {
1282 /* RGB332 has no palette ! */
1283 return BlitNtoNPixelAlpha;
1284 }
1285
1286 case 2:
1287 if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
1288 && sf->Gmask == 0xff00
1289 && ((sf->Rmask == 0xff && df->Rmask == 0x1f)
1290 || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
1291 if (df->Gmask == 0x7e0)
1293 else if (df->Gmask == 0x3e0)
1295 }
1296 return BlitNtoNPixelAlpha;
1297
1298 case 4:
1299 if (sf->Rmask == df->Rmask
1300 && sf->Gmask == df->Gmask
1301 && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
1302#if defined(__MMX__) || defined(__3dNOW__)
1303 if (sf->Rshift % 8 == 0
1304 && sf->Gshift % 8 == 0
1305 && sf->Bshift % 8 == 0
1306 && sf->Ashift % 8 == 0 && sf->Aloss == 0) {
1307#ifdef __3dNOW__
1308 if (SDL_Has3DNow())
1309 return BlitRGBtoRGBPixelAlphaMMX3DNOW;
1310#endif
1311#ifdef __MMX__
1312 if (SDL_HasMMX())
1313 return BlitRGBtoRGBPixelAlphaMMX;
1314#endif
1315 }
1316#endif /* __MMX__ || __3dNOW__ */
1317 if (sf->Amask == 0xff000000) {
1319 }
1320 }
1321 return BlitNtoNPixelAlpha;
1322
1323 case 3:
1324 default:
1325 break;
1326 }
1327 return BlitNtoNPixelAlpha;
1328
1330 if (sf->Amask == 0) {
1331 /* Per-surface alpha blits */
1332 switch (df->BytesPerPixel) {
1333 case 1:
1334 if (df->palette != NULL) {
1335 return BlitNto1SurfaceAlpha;
1336 } else {
1337 /* RGB332 has no palette ! */
1338 return BlitNtoNSurfaceAlpha;
1339 }
1340
1341 case 2:
1342 if (surface->map->identity) {
1343 if (df->Gmask == 0x7e0) {
1344#ifdef __MMX__
1345 if (SDL_HasMMX())
1346 return Blit565to565SurfaceAlphaMMX;
1347 else
1348#endif
1350 } else if (df->Gmask == 0x3e0) {
1351#ifdef __MMX__
1352 if (SDL_HasMMX())
1353 return Blit555to555SurfaceAlphaMMX;
1354 else
1355#endif
1357 }
1358 }
1359 return BlitNtoNSurfaceAlpha;
1360
1361 case 4:
1362 if (sf->Rmask == df->Rmask
1363 && sf->Gmask == df->Gmask
1364 && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
1365#ifdef __MMX__
1366 if (sf->Rshift % 8 == 0
1367 && sf->Gshift % 8 == 0
1368 && sf->Bshift % 8 == 0 && SDL_HasMMX())
1369 return BlitRGBtoRGBSurfaceAlphaMMX;
1370#endif
1371 if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) {
1373 }
1374 }
1375 return BlitNtoNSurfaceAlpha;
1376
1377 case 3:
1378 default:
1379 return BlitNtoNSurfaceAlpha;
1380 }
1381 }
1382 break;
1383
1385 if (sf->Amask == 0) {
1386 if (df->BytesPerPixel == 1) {
1387
1388 if (df->palette != NULL) {
1390 } else {
1391 /* RGB332 has no palette ! */
1393 }
1394 } else {
1396 }
1397 }
1398 break;
1399 }
1400
1401 return NULL;
1402}
#define SDL_COPY_RLE_MASK
Definition: SDL_blit.h:44
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:39
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:77
static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:1147
static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:30
static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:123
static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:1100
static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:1186
static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:976
static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:419
static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:1054
static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:1227
static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:461
static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info)
Definition: SDL_blit_A.c:1015
#define SDL_HasMMX
#define SDL_Has3DNow
EGLSurface surface
Definition: eglext.h:248

References SDL_PixelFormat::Aloss, SDL_PixelFormat::Amask, SDL_PixelFormat::Ashift, Blit555to555SurfaceAlpha(), Blit565to565SurfaceAlpha(), BlitARGBto555PixelAlpha(), BlitARGBto565PixelAlpha(), BlitNto1PixelAlpha(), BlitNto1SurfaceAlpha(), BlitNto1SurfaceAlphaKey(), BlitNtoNPixelAlpha(), BlitNtoNSurfaceAlpha(), BlitNtoNSurfaceAlphaKey(), BlitRGBtoRGBPixelAlpha(), BlitRGBtoRGBSurfaceAlpha(), SDL_PixelFormat::Bmask, SDL_PixelFormat::Bshift, SDL_PixelFormat::BytesPerPixel, SDL_PixelFormat::format, SDL_PixelFormat::Gmask, SDL_PixelFormat::Gshift, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rmask, SDL_PixelFormat::Rshift, SDL_COPY_BLEND, SDL_COPY_COLORKEY, SDL_COPY_MODULATE_ALPHA, SDL_COPY_RLE_MASK, SDL_Has3DNow, and SDL_HasMMX.

Referenced by SDL_CalculateBlit().