From 675b3bd39e62ad9854c615e22723d5246a6710f5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 7 Oct 2023 05:05:40 +0300 Subject: [PATCH 58/58] sdl2: Drop graphics.c code for unsupported bit depths See osdn #48673 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/graphics.c | 487 +------------------------------------ 1 file changed, 1 insertion(+), 486 deletions(-) diff --git a/client/gui-sdl2/graphics.c b/client/gui-sdl2/graphics.c index 6936d91051..aa1f35a254 100644 --- a/client/gui-sdl2/graphics.c +++ b/client/gui-sdl2/graphics.c @@ -709,223 +709,6 @@ int main_window_height(void) (((( s & (mask | mask << 16)) + ( d & ( mask | mask << 16 ))) >> 1) + \ ( s & d & ( ~(mask | mask << 16)))) -/**********************************************************************//** - Fill rectangle for "565" format surface -**************************************************************************/ -static int __FillRectAlpha565(SDL_Surface *surf, SDL_Rect *prect, - SDL_Color *pcolor) -{ - Uint32 y, end; - Uint32 *start; - Uint32 *pixel; - register Uint32 D, S = - SDL_MapRGB(surf->format, pcolor->r, pcolor->g, pcolor->b); - register Uint32 A = pcolor->a >> 3; - - S &= 0xFFFF; - - lock_surf(surf); - if (prect == NULL) { - end = surf->w * surf->h; - pixel = surf->pixels; - if (A == 16) { /* A == 128 >> 3 */ - /* This code doesn't work (A == 128) */ - if (end & 0x1) { /* end % 2 */ - D = *pixel; - *pixel++ = BLEND16_50(D, S, MASK565); - end--; - } - - S = S | S << 16; - for (y = 0; y < end; y += 2) { - D = *(Uint32 *) pixel; - *(Uint32 *) pixel = BLEND2x16_50(D, S, MASK565); - pixel += 2; - } - } else { - S = (S | S << 16) & 0x07e0f81f; - DUFFS_LOOP8( - { - D = *pixel; - D = (D | D << 16) & 0x07e0f81f; - D += (S - D) * A >> 5; - D &= 0x07e0f81f; - *pixel++ = (D | (D >> 16)) & 0xFFFF; - }, end); - } - } else { - /* Correct prect size */ - if (prect->x < 0) { - prect->w += prect->x; - prect->x = 0; - } else if (prect->x >= surf->w - prect->w) { - prect->w = surf->w - prect->x; - } - - if (prect->y < 0) { - prect->h += prect->y; - prect->y = 0; - } else if (prect->y >= surf->h - prect->h) { - prect->h = surf->h - prect->y; - } - - start = pixel = (Uint32 *) surf->pixels + - (prect->y * surf->pitch) + prect->x / 2; - - if (A == 16) { /* A == 128 >> 3 */ - /* This code doesn't work (A == 128) */ - S = S | S << 16; - for (y = 0; y < prect->h; y++) { - end = 0; - - if (prect->w & 0x1) { - D = *pixel; - *pixel++ = BLEND16_50(D, (S & 0xFFFF), MASK565); - end++; - } - - for (; end < prect->w; end += 2) { - D = *(Uint32 *) pixel; - *(Uint32 *) pixel = BLEND2x16_50(D, S, MASK565); - pixel += 2; - } - - pixel = start + surf->pitch; - start = pixel; - } - } else { - S = (S | S << 16) & 0x07e0f81f; - y = prect->h; - end = prect->w; - - while (y--) { - DUFFS_LOOP8( - { - D = *pixel; - D = (D | D << 16) & 0x07e0f81f; - D += (S - D) * A >> 5; - D &= 0x07e0f81f; - *pixel++ = (D | (D >> 16)) & 0xFFFF; - }, end); - - pixel = start + surf->pitch; - start = pixel; - } /* while */ - } - } - - unlock_surf(surf); - return 0; -} - -/**********************************************************************//** - Fill rectangle for "555" format surface -**************************************************************************/ -static int __FillRectAlpha555(SDL_Surface *surf, SDL_Rect *prect, - SDL_Color *pcolor) -{ - Uint32 y, end; - Uint32 *start, *pixel; - register Uint32 D, S = - SDL_MapRGB(surf->format, pcolor->r, pcolor->g, pcolor->b); - register Uint32 A = pcolor->a >> 3; - - S &= 0xFFFF; - - lock_surf(surf); - - if (prect == NULL) { - end = surf->w * surf->h; - pixel = surf->pixels; - if (A == 16) { /* A == 128 >> 3 */ - if (end & 0x1) { - D = *pixel; - *pixel++ = BLEND16_50(D, S, MASK555); - end--; - } - - S = S | S << 16; - for (y = 0; y < end; y += 2) { - D = *pixel; - *pixel = BLEND2x16_50(D, S, MASK555); - pixel += 2; - } - } else { - S = (S | S << 16) & 0x03e07c1f; - DUFFS_LOOP8( - { - D = *pixel; - D = (D | D << 16) & 0x03e07c1f; - D += (S - D) * A >> 5; - D &= 0x03e07c1f; - *pixel++ = (D | (D >> 16)) & 0xFFFF; - }, end); - } - } else { - /* Correct prect size */ - if (prect->x < 0) { - prect->w += prect->x; - prect->x = 0; - } else if (prect->x >= surf->w - prect->w) { - prect->w = surf->w - prect->x; - } - - if (prect->y < 0) { - prect->h += prect->y; - prect->y = 0; - } else if (prect->y >= surf->h - prect->h) { - prect->h = surf->h - prect->y; - } - - start = pixel = (Uint32 *) surf->pixels + - (prect->y * surf->pitch) + prect->x / 2; - - if (A == 16) { /* A == 128 >> 3 */ - S = S | S << 16; - for (y = 0; y < prect->h; y++) { - end = 0; - - if (prect->w & 0x1) { - D = *pixel; - *pixel++ = BLEND16_50(D, (S & 0xFFFF), MASK555); - end++; - } - - for (; end < prect->w; end += 2) { - D = *(Uint32 *) pixel; - *(Uint32 *) pixel = BLEND2x16_50(D, S, MASK555); - pixel += 2; - } - - pixel = start + surf->pitch; - start = pixel; - } - } else { - - S = (S | S << 16) & 0x03e07c1f; - y = prect->h; - end = prect->w; - - while (y--) { - DUFFS_LOOP8( - { - D = *pixel; - D = (D | D << 16) & 0x03e07c1f; - D += (S - D) * A >> 5; - D &= 0x03e07c1f; - *pixel++ = (D | (D >> 16)) & 0xFFFF; - }, end); - - pixel = start + surf->pitch; - start = pixel; - } /* while */ - } - } - - unlock_surf(surf); - return 0; -} - /**********************************************************************//** Fill rectangle for 32bit "8888" format surface **************************************************************************/ @@ -1071,246 +854,6 @@ static int __FillRectAlpha8888_32bit(SDL_Surface *surf, SDL_Rect *prect, } } - unlock_surf(surf); - return 0; -} - -/**********************************************************************//** - Fill rectangle for 32bit "888" format surface -**************************************************************************/ -static int __FillRectAlpha888_32bit(SDL_Surface *surf, SDL_Rect *prect, - SDL_Color *pcolor) -{ - register Uint32 A = pcolor->a; - register Uint32 dSIMD1, dSIMD2; - register Uint32 sSIMD1, sSIMD2 = SDL_MapRGB(surf->format, - pcolor->r, pcolor->g, - pcolor->b); - Uint32 y, end; - Uint32 *start, *pixel; - - sSIMD1 = sSIMD2 & 0x00FF00FF; - - lock_surf(surf); - - if (prect == NULL) { - end = surf->w * surf->h; - pixel = (Uint32 *) surf->pixels; - if (A == 128) { /* 50% A */ - for (y = 0; y < end; y++) { - dSIMD2 = *pixel; - *pixel++ = ((((sSIMD2 & 0x00fefefe) + (dSIMD2 & 0x00fefefe)) >> 1) - + (sSIMD2 & dSIMD2 & 0x00010101)) | 0xFF000000; - } - } else { - sSIMD2 &= 0xFF00; - sSIMD2 = sSIMD2 >> 8 | sSIMD2 << 8; - DUFFS_LOOP_DOUBLE2( - { - dSIMD2 = *pixel; - dSIMD1 = dSIMD2 & 0x00FF00FF; - dSIMD1 += (sSIMD1 - dSIMD1) * A >> 8; - dSIMD1 &= 0x00FF00FF; - dSIMD2 &= 0xFF00; - dSIMD2 += (((sSIMD2 << 8) & 0xFF00) - dSIMD2) * A >> 8; - dSIMD2 &= 0xFF00; - *pixel++ = dSIMD1 | dSIMD2 | 0xFF000000; - }, { - dSIMD1 = *pixel & 0x00FF00FF; - dSIMD1 += (sSIMD1 - dSIMD1) * A >> 8; - dSIMD1 &= 0x00FF00FF; - - dSIMD2 = ((*pixel & 0xFF00) >> 8)| ((pixel[1] & 0xFF00) << 8); - dSIMD2 += (sSIMD2 - dSIMD2) * A >> 8; - dSIMD2 &= 0x00FF00FF; - - *pixel++ = dSIMD1 | ((dSIMD2 << 8) & 0xFF00) | 0xFF000000; - - dSIMD1 = *pixel & 0x00FF00FF; - dSIMD1 += (sSIMD1 - dSIMD1) * A >> 8; - dSIMD1 &= 0x00FF00FF; - - *pixel++ = dSIMD1 | ((dSIMD2 >> 8) & 0xFF00) | 0xFF000000; - }, end); - } - } else { - /* Correct prect size */ - if (prect->x < 0) { - prect->w += prect->x; - prect->x = 0; - } else if (prect->x >= surf->w - prect->w) { - prect->w = surf->w - prect->x; - } - - if (prect->y < 0) { - prect->h += prect->y; - prect->y = 0; - } else if (prect->y >= surf->h - prect->h) { - prect->h = surf->h - prect->y; - } - - start = pixel = (Uint32 *) surf->pixels + - (prect->y * (surf->pitch >> 2)) + prect->x; - - if (A == 128) { /* 50% A */ - - for (y = 0; y < prect->h; y++) { - - for (end = 0; end < prect->w; end++) { - dSIMD2 = *pixel; - *pixel++ = ((((sSIMD2 & 0x00fefefe) + (dSIMD2 & 0x00fefefe)) >> 1) - + (sSIMD2 & dSIMD2 & 0x00010101)) | 0xFF000000; - } - - pixel = start + (surf->pitch >> 2); - start = pixel; - } - } else { - y = prect->h; - end = prect->w; - - sSIMD2 &= 0xFF00; - sSIMD2 = sSIMD2 >> 8 | sSIMD2 << 8; - - while (y--) { - DUFFS_LOOP_DOUBLE2( - { - dSIMD2 = *pixel; - dSIMD1 = dSIMD2 & 0x00FF00FF; - dSIMD1 += (sSIMD1 - dSIMD1) * A >> 8; - dSIMD1 &= 0x00FF00FF; - dSIMD2 &= 0xFF00; - dSIMD2 += (((sSIMD2 << 8) & 0xFF00) - dSIMD2) * A >> 8; - dSIMD2 &= 0xFF00; - *pixel++ = dSIMD1 | dSIMD2 | 0xFF000000; - }, { - dSIMD1 = *pixel & 0x00FF00FF; - dSIMD1 += (sSIMD1 - dSIMD1) * A >> 8; - dSIMD1 &= 0x00FF00FF; - - dSIMD2 = ((*pixel & 0xFF00) >> 8)| ((pixel[1] & 0xFF00) << 8); - dSIMD2 += (sSIMD2 - dSIMD2) * A >> 8; - dSIMD2 &= 0x00FF00FF; - - *pixel++ = dSIMD1 | ((dSIMD2 << 8) & 0xFF00) | 0xFF000000; - - dSIMD1 = *pixel & 0x00FF00FF; - dSIMD1 += (sSIMD1 - dSIMD1) * A >> 8; - dSIMD1 &= 0x00FF00FF; - - *pixel++ = dSIMD1 | ((dSIMD2 >> 8) & 0xFF00) | 0xFF000000; - }, end); - - pixel = start + (surf->pitch >> 2); - start = pixel; - - } /* while */ - } - } - - unlock_surf(surf); - return 0; -} - -/**********************************************************************//** - Fill rectangle for 24bit "888" format surface -**************************************************************************/ -static int __FillRectAlpha888_24bit(SDL_Surface *surf, SDL_Rect *prect, - SDL_Color *pcolor) -{ - Uint32 y, end; - Uint8 *start, *pixel; - register Uint32 P, D, S1, S2 = SDL_MapRGB(surf->format, - pcolor->r, pcolor->g, - pcolor->b); - register Uint32 A = pcolor->a; - - S1 = S2 & 0x00FF00FF; - - S2 &= 0xFF00; - - lock_surf(surf); - - if (prect == NULL) { - end = surf->w * surf->h; - pixel = (Uint8 *) surf->pixels; - - for (y = 0; y < end; y++) { - D = (pixel[0] << 16) + (pixel[1] << 8) + pixel[2]; - - P = D & 0x00FF00FF; - P += (S1 - P) * A >> 8; - P &= 0x00ff00ff; - - D = (D & 0xFF00); - D += (S2 - D) * A >> 8; - D &= 0xFF00; - - P = P | D; - - /* Fix me to little - big ENDIAN */ - - pixel[0] = P & 0xff; - pixel[1] = (P >> 8) & 0xff; - pixel[2] = (P >> 16) & 0xff; - - pixel += 3; - } - - } else { - /* Correct prect size */ - if (prect->x < 0) { - prect->w += prect->x; - prect->x = 0; - } else { - if (prect->x >= surf->w - prect->w) { - prect->w = surf->w - prect->x; - } - } - - if (prect->y < 0) { - prect->h += prect->y; - prect->y = 0; - } else { - if (prect->y >= surf->h - prect->h) { - prect->h = surf->h - prect->y; - } - } - - end = prect->w * prect->h; - start = pixel = (Uint8 *) surf->pixels + - (prect->y * surf->pitch) + prect->x * 3; - - y = 0; - while (y != prect->h) { - D = (pixel[0] << 16) + (pixel[1] << 8) + pixel[2]; - - P = D & 0x00FF00FF; - P += (S1 - P) * A >> 8; - P &= 0x00ff00ff; - - D = (D & 0xFF00); - D += (S2 - D) * A >> 8; - D &= 0xFF00; - - P = P | D; - - /* Fix me to little - big ENDIAN */ - - pixel[0] = P & 0xff; - pixel[1] = (P >> 8) & 0xff; - pixel[2] = (P >> 16) & 0xff; - - if ((pixel - start) == (prect->w * 3)) { - pixel = start + surf->pitch; - start = pixel; - y++; - } else { - pixel += 3; - } - } - } - unlock_surf(surf); return 0; @@ -1336,35 +879,7 @@ int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, return -3; } - switch (surf->format->BytesPerPixel) { - case 1: - /* PORT ME */ - return -1; - - case 2: - if (surf->format->Gmask == 0x7E0) { - return __FillRectAlpha565(surf, prect, pcolor); - } else { - if (surf->format->Gmask == 0x3E0) { - return __FillRectAlpha555(surf, prect, pcolor); - } else { - return -1; - } - } - break; - - case 3: - return __FillRectAlpha888_24bit(surf, prect, pcolor); - - case 4: - if (surf->format->Amask) { - return __FillRectAlpha8888_32bit(surf, prect, pcolor); - } else { - return __FillRectAlpha888_32bit(surf, prect, pcolor); - } - } - - return -1; + return __FillRectAlpha8888_32bit(surf, prect, pcolor); } /**********************************************************************//** -- 2.40.1