src/librosprite.c
/**
 * Upscale a 16, 24 or 32bpp sprite to the 0xRRGGBBAA representation.
 * Do not call this function with a sprite with less than 16bpp,
 * but use a palette lookup instead.
 */
Upscale a 16, 24 or 32bpp sprite to the 0xRRGGBBAA representation.
Do not call this function with a sprite with less than 16bpp,
but use a palette lookup instead.
Upscale a 16 24 or 32bpp sprite to the 0xRRGGBBAA representation . Do not call this function with a sprite with less than 16bpp but use a palette lookup instead .
static uint32_t rosprite_upscale_color(uint32_t pixel, struct rosprite_mode* mode, bool* has_alpha_pixel_data)
{
	uint8_t alpha;
	switch (mode->colorbpp) {
	case 32:
		if (mode->color_model == ROSPRITE_RGB) {
			pixel = BSWAP(pixel);
		} else {
			pixel = rosprite_cmyk_to_rgb(pixel);
		}
		break;
	case 24:
		pixel = BSWAP(pixel);
		break;
	case 16:
		{
			uint8_t red   = pixel & 31;
			uint8_t green = (pixel & (31 << 5)) >> 5;
			uint8_t blue  = (pixel & (31 << 10)) >> 10;
			assert(red < 32);
			assert(green < 32);
			assert(blue < 32);
			pixel = ((uint32_t)sprite_16bpp_translate[red]   << 24)|
			        ((uint32_t)sprite_16bpp_translate[green] << 16)|
			        ((uint32_t)sprite_16bpp_translate[blue]  <<  8);
		}
		break;
	case 8:
	case 4:
	case 2:
	case 1:
		assert(false); 
	default:
		assert(false); 
	}
	alpha = pixel & 0xff;
	if (alpha == 0x00) {
		if (!(*has_alpha_pixel_data)) {
			pixel = pixel | 0xff;
		}
	} else {
		*has_alpha_pixel_data = true;
	}
	return pixel;
}
static uint32_t rosprite_upscale_color ( uint32_t pixel , struct rosprite_mode * mode , bool * has_alpha_pixel_data ) { uint8_t alpha ; switch ( mode -> colorbpp ) { case 32 : if ( mode -> color_model == ROSPRITE_RGB ) { pixel = BSWAP ( pixel ) ; } else { pixel = rosprite_cmyk_to_rgb ( pixel ) ; } break ; case 24 : pixel = BSWAP ( pixel ) ; break ; case 16 : { uint8_t red = pixel & 31 ; uint8_t green = ( pixel & ( 31 << 5 ) ) >> 5 ; uint8_t blue = ( pixel & ( 31 << 10 ) ) >> 10 ; assert ( red < 32 ) ; assert ( green < 32 ) ; assert ( blue < 32 ) ; pixel = ( ( uint32_t ) sprite_16bpp_translate [ red ] << 24 ) | ( ( uint32_t ) sprite_16bpp_translate [ green ] << 16 ) | ( ( uint32_t ) sprite_16bpp_translate [ blue ] << 8 ) ; } break ; case 8 : case 4 : case 2 : case 1 : assert ( false ) ; default : assert ( false ) ; } alpha = pixel & 0xff ; if ( alpha == 0x00 ) { if ( ! ( * has_alpha_pixel_data ) ) { pixel = pixel | 0xff ; } } else { * has_alpha_pixel_data = true ; } return pixel ; }
Upscale a 16, 24 or 32bpp sprite to the 0xRRGGBBAA representation.
Upscale a 16 24 or 32bpp sprite to the 0xRRGGBBAA representation .
/* swap from 0xAABBGGRR to 0xRRGGBBAA */ /* reverse byte order */ /* incoming format is b_00000000000000000bbbbbgggggrrrrr */ /* sanity check */ /* shouldn't need to call for <= 8bpp, since a palette lookup will return 32bpp */ /* unknown bpp */