src/librosprite.c
/**
 * Load a sprite image with 16 or more bpp.
 *
 * \param[out] sprite On exit, sprite.image will be populated
 */
Load a sprite image with 16 or more bpp.
\param[out] sprite On exit, sprite.image will be populated
Load a sprite image with 16 or more bpp . \ param [ out ] sprite On exit sprite . image will be populated
static rosprite_error rosprite_load_high_color(uint8_t* image_in, uint8_t* mask, struct rosprite* sprite, struct rosprite_header* header)
{
	struct rosprite_mask_state* mask_state = NULL;
	uint32_t currentByteIndex = 0;
	uint32_t j, x, y, x_pixels, pixel;
	bool has_alpha_pixel_data = false;
	uint32_t b;
	bool old_has_alpha;
	if (sprite->has_mask) {
		ERRCHK(rosprite_init_mask_state(sprite, header, mask, &mask_state));
	}
	sprite->image = malloc(sprite->width * sprite->height * 4); 
	assert(header->first_used_bit == 0);
	{
	const uint32_t bpp = sprite->mode.colorbpp;
	const uint32_t bytesPerPixel = bpp / 8;
	const uint32_t row_max_bit = header->width_words * 32 - (31 - header->last_used_bit); 
	for (y = 0; y < sprite->height; y++) {
		x_pixels = 0;
		for (x = 0; x < row_max_bit; x += bpp) {
			pixel = 0;
			for (j = 0; j < bytesPerPixel; j++) {
				b = image_in[currentByteIndex++];
				pixel = pixel | (b << (j * 8));
			}
			old_has_alpha = has_alpha_pixel_data;
			pixel = rosprite_upscale_color(pixel, &(sprite->mode), &has_alpha_pixel_data);
			if (old_has_alpha != has_alpha_pixel_data && (y > 0 || x_pixels > 0)) {
				rosprite_fix_alpha(sprite->image, (y * sprite->width) + x_pixels - 1);
			}
			if (sprite->has_mask) {
				uint8_t mask_pixel = rosprite_next_mask_pixel(mask, mask_state);
				pixel = (pixel & 0xffffff00) | mask_pixel;
			}
			sprite->image[y*sprite->width + x_pixels] = pixel;
			x_pixels++;
		}
		if (y + 1 < sprite->height) {
			currentByteIndex = (currentByteIndex + 3) & ~3; 
		}
	}
	}
	if (sprite->has_mask) free(mask_state);
	return ROSPRITE_OK;
}
static rosprite_error rosprite_load_high_color ( uint8_t * image_in , uint8_t * mask , struct rosprite * sprite , struct rosprite_header * header ) { struct rosprite_mask_state * mask_state = NULL ; uint32_t currentByteIndex = 0 ; uint32_t j , x , y , x_pixels , pixel ; bool has_alpha_pixel_data = false ; uint32_t b ; bool old_has_alpha ; if ( sprite -> has_mask ) { ERRCHK ( rosprite_init_mask_state ( sprite , header , mask , & mask_state ) ) ; } sprite -> image = malloc ( sprite -> width * sprite -> height * 4 ) ; assert ( header -> first_used_bit == 0 ) ; { const uint32_t bpp = sprite -> mode . colorbpp ; const uint32_t bytesPerPixel = bpp / 8 ; const uint32_t row_max_bit = header -> width_words * 32 - ( 31 - header -> last_used_bit ) ; for ( y = 0 ; y < sprite -> height ; y ++ ) { x_pixels = 0 ; for ( x = 0 ; x < row_max_bit ; x += bpp ) { pixel = 0 ; for ( j = 0 ; j < bytesPerPixel ; j ++ ) { b = image_in [ currentByteIndex ++ ] ; pixel = pixel | ( b << ( j * 8 ) ) ; } old_has_alpha = has_alpha_pixel_data ; pixel = rosprite_upscale_color ( pixel , & ( sprite -> mode ) , & has_alpha_pixel_data ) ; if ( old_has_alpha != has_alpha_pixel_data && ( y > 0 || x_pixels > 0 ) ) { rosprite_fix_alpha ( sprite -> image , ( y * sprite -> width ) + x_pixels - 1 ) ; } if ( sprite -> has_mask ) { uint8_t mask_pixel = rosprite_next_mask_pixel ( mask , mask_state ) ; pixel = ( pixel & 0xffffff00 ) | mask_pixel ; } sprite -> image [ y * sprite -> width + x_pixels ] = pixel ; x_pixels ++ ; } if ( y + 1 < sprite -> height ) { currentByteIndex = ( currentByteIndex + 3 ) & ~ 3 ; } } } if ( sprite -> has_mask ) free ( mask_state ) ; return ROSPRITE_OK ; }
Load a sprite image with 16 or more bpp.
Load a sprite image with 16 or more bpp .
/* all image data is 32bpp going out */ /* Spec says that there must be no left-hand wastage */ /* Last used bit in row */ /* Ensure byte index is pointing at start of next row */ /* Round up to next multiple of 4 */