src/librosprite.c
/**
 * Load a sprite image with 8 or fewer bpp.
 *
 * \param[out] sprite On exit, sprite.image will be populated
 */
Load a sprite image with 8 or fewer bpp.
\param[out] sprite On exit, sprite.image will be populated
Load a sprite image with 8 or fewer bpp . \ param [ out ] sprite On exit sprite . image will be populated
static rosprite_error rosprite_load_low_color(uint8_t* image_in, uint8_t* mask, struct rosprite* sprite, struct rosprite_header* header)
{
	uint32_t current_byte_index, currentword;
	uint32_t x, y, x_pixels, pixel;
	uint8_t mask_pixel;
	struct rosprite_mask_state* mask_state = NULL;
	if (sprite->has_mask) {
		ERRCHK(rosprite_init_mask_state(sprite, header, mask, &mask_state));
	}
	sprite->image = malloc(sprite->width * sprite->height * 4); 
	{
	const uint32_t bpp = sprite->mode.colorbpp;
	const uint32_t row_max_bit = header->width_words * 32 - (31 - header->last_used_bit); 
	const uint32_t bitmask = (1 << bpp) - 1; 
	current_byte_index = 0;
	currentword = BTUINT((image_in + current_byte_index));
	current_byte_index += 4;
	for (y = 0; y < sprite->height; y++) {
		x_pixels = 0;
		for (x = header->first_used_bit; x < row_max_bit ; x += bpp) {
			const uint32_t offset_into_word = x % 32;
			pixel = (currentword & (bitmask << offset_into_word)) >> offset_into_word;
			pixel = rosprite_palette_lookup(sprite, pixel); 
			if (sprite->has_mask) {
				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 (x + bpp < row_max_bit && offset_into_word + bpp == 32) {
				currentword = BTUINT((image_in + current_byte_index));
				current_byte_index += 4;
			}
		}
		if (y + 1 < sprite->height) {
			currentword = BTUINT((image_in + current_byte_index));
			current_byte_index += 4;
		}
	}
	}
	if (sprite->has_mask) free(mask_state);
	return ROSPRITE_OK;
}
static rosprite_error rosprite_load_low_color ( uint8_t * image_in , uint8_t * mask , struct rosprite * sprite , struct rosprite_header * header ) { uint32_t current_byte_index , currentword ; uint32_t x , y , x_pixels , pixel ; uint8_t mask_pixel ; struct rosprite_mask_state * mask_state = NULL ; if ( sprite -> has_mask ) { ERRCHK ( rosprite_init_mask_state ( sprite , header , mask , & mask_state ) ) ; } sprite -> image = malloc ( sprite -> width * sprite -> height * 4 ) ; { const uint32_t bpp = sprite -> mode . colorbpp ; const uint32_t row_max_bit = header -> width_words * 32 - ( 31 - header -> last_used_bit ) ; const uint32_t bitmask = ( 1 << bpp ) - 1 ; current_byte_index = 0 ; currentword = BTUINT ( ( image_in + current_byte_index ) ) ; current_byte_index += 4 ; for ( y = 0 ; y < sprite -> height ; y ++ ) { x_pixels = 0 ; for ( x = header -> first_used_bit ; x < row_max_bit ; x += bpp ) { const uint32_t offset_into_word = x % 32 ; pixel = ( currentword & ( bitmask << offset_into_word ) ) >> offset_into_word ; pixel = rosprite_palette_lookup ( sprite , pixel ) ; if ( sprite -> has_mask ) { 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 ( x + bpp < row_max_bit && offset_into_word + bpp == 32 ) { currentword = BTUINT ( ( image_in + current_byte_index ) ) ; current_byte_index += 4 ; } } if ( y + 1 < sprite -> height ) { currentword = BTUINT ( ( image_in + current_byte_index ) ) ; current_byte_index += 4 ; } } } if ( sprite -> has_mask ) free ( mask_state ) ; return ROSPRITE_OK ; }
Load a sprite image with 8 or fewer bpp.
Load a sprite image with 8 or fewer bpp .
/* all image data is 32bpp going out */ /* Last used bit in row */ /* creates a mask of 1s that is bpp bits wide */ /* lookup returns 32bpp */ /* If we're not at the end of the row and we've processed all of this word, fetch the next one */ /* Advance to first word of next row */