SDL_triangle_blit_slow: sync code with SDL_blit_slow to handle ARGB2101010
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c
index ce003e1..694cb4d 100644
--- a/src/render/software/SDL_triangle.c
+++ b/src/render/software/SDL_triangle.c
@@ -718,6 +718,21 @@ end:
}
+#define FORMAT_ALPHA 0
+#define FORMAT_NO_ALPHA -1
+#define FORMAT_2101010 1
+#define FORMAT_HAS_ALPHA(format) format == 0
+#define FORMAT_HAS_NO_ALPHA(format) format < 0
+static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
+ if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
+ return FORMAT_2101010;
+ } else if (pf->Amask) {
+ return FORMAT_ALPHA;
+ } else {
+ return FORMAT_NO_ALPHA;
+ }
+}
+
static void
SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
@@ -738,25 +753,32 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
SDL_PixelFormat *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->BytesPerPixel;
int dstbpp = dst_fmt->BytesPerPixel;
+ int srcfmt_val;
+ int dstfmt_val;
Uint32 rgbmask = ~src_fmt->Amask;
Uint32 ckey = info->colorkey & rgbmask;
Uint8 *dst_ptr = info->dst;
int dst_pitch = info->dst_pitch;;
+ srcfmt_val = detect_format(src_fmt);
+ dstfmt_val = detect_format(dst_fmt);
+
TRIANGLE_BEGIN_LOOP
{
Uint8 *src;
Uint8 *dst = dptr;
TRIANGLE_GET_TEXTCOORD
src = (info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
- if (src_fmt->Amask) {
- DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
- srcB, srcA);
- } else {
- DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
- srcB);
+ if (FORMAT_HAS_ALPHA(srcfmt_val)) {
+ DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB, srcA);
+ } else if (FORMAT_HAS_NO_ALPHA(srcfmt_val)) {
+ DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB);
srcA = 0xFF;
+ } else {
+ /* SDL_PIXELFORMAT_ARGB2101010 */
+ srcpixel = *((Uint32 *)(src));
+ RGBA_FROM_ARGB2101010(srcpixel, srcR, srcG, srcB, srcA);
}
if (flags & SDL_COPY_COLORKEY) {
/* srcpixel isn't set for 24 bpp */
@@ -768,13 +790,15 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
continue;
}
}
- if (dst_fmt->Amask) {
- DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
- dstB, dstA);
- } else {
- DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
- dstB);
+ if (FORMAT_HAS_ALPHA(dstfmt_val)) {
+ DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
+ } else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
+ DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
dstA = 0xFF;
+ } else {
+ /* SDL_PIXELFORMAT_ARGB2101010 */
+ dstpixel = *((Uint32 *)(dst));
+ RGBA_FROM_ARGB2101010(dstpixel, dstR, dstG, dstB, dstA);
}
if (! is_uniform) {
@@ -845,10 +869,15 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
dstA = 255;
break;
}
- if (dst_fmt->Amask) {
+ if (FORMAT_HAS_ALPHA(dstfmt_val)) {
ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
- } else {
+ } else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
+ } else {
+ /* SDL_PIXELFORMAT_ARGB2101010 */
+ Uint32 pixel;
+ ARGB2101010_FROM_RGBA(pixel, dstR, dstG, dstB, dstA);
+ *(Uint32 *)dst = pixel;
}
}
TRIANGLE_END_LOOP