summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Shaw <jshaw@netsurf-browser.org>2007-11-30 11:49:18 (GMT)
committer James Shaw <jshaw@netsurf-browser.org>2007-11-30 11:49:18 (GMT)
commita6c0a6b356abc3cd46c73927146f48738df59943 (patch)
treeaf3b6bf320426f4fe1cfd98da476fa2c5fe7e9ca
parent5fb74e86787a0c8c9e2e8691451f2a5d6d76b9a0 (diff)
downloadlibrosprite-a6c0a6b356abc3cd46c73927146f48738df59943.tar.gz
librosprite-a6c0a6b356abc3cd46c73927146f48738df59943.tar.bz2
Rename all public functions and structs to rosprite_*
svn path=/import/jshaw/libsprite/; revision=10005
-rw-r--r--trunk/example.c6
-rw-r--r--trunk/libsprite.c60
-rw-r--r--trunk/libsprite.h22
-rw-r--r--trunk/palette2c.c6
4 files changed, 48 insertions, 46 deletions
diff --git a/trunk/example.c b/trunk/example.c
index 9870135..f161b58 100644
--- a/trunk/example.c
+++ b/trunk/example.c
@@ -54,9 +54,9 @@ int main(int argc, char *argv[])
}
printf("Loading %s\n", filename);
- sprite_init();
+ rosprite_init();
- struct sprite_area* sprite_area = sprite_load_file(spritefile);
+ struct rosprite_area* sprite_area = rosprite_load_file(spritefile);
printf("sprite_count %u\n", sprite_area->sprite_count);
printf("extension_size %u\n", sprite_area->extension_size);
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
SDL_SetAlpha(screen, SDL_SRCALPHA, 0);
for (uint32_t i = 0; i < sprite_area->sprite_count; i++) {
- struct sprite* sprite = sprite_area->sprites[i];
+ struct rosprite* sprite = sprite_area->sprites[i];
printf("\nname %s\n", sprite->name);
printf("color_model %s\n", sprite->mode->color_model == rosprite_rgb ? "RGB" : "CMYK");
printf("colorbpp %u\n", sprite->mode->colorbpp);
diff --git a/trunk/libsprite.c b/trunk/libsprite.c
index 7ea3b9d..9147fb8 100644
--- a/trunk/libsprite.c
+++ b/trunk/libsprite.c
@@ -15,7 +15,7 @@
/* reverse the byte order of a word such that 0xAABBCCDD becomes 0xDDCCBBAA */
#define BSWAP(word) (((word & (0x000000ff)) << 24) | ((word & 0x0000ff00) << 8) | ((word & 0x00ff0000) >> 8) | ((word & 0xff000000) >> 24))
-struct sprite_header {
+struct rosprite_header {
uint32_t width_words; /* width in words */
/* height defined in sprite struct */
uint32_t first_used_bit; /* old format only (spriteType = 0) */
@@ -24,7 +24,7 @@ struct sprite_header {
uint32_t mask_size; /* bytes */
};
-struct sprite_mask_state {
+struct rosprite_mask_state {
uint32_t x;
uint32_t y;
uint32_t first_used_bit;
@@ -35,7 +35,7 @@ struct sprite_mask_state {
uint32_t bpp;
};
-static struct sprite_mode oldmodes[256];
+static struct rosprite_mode oldmodes[256];
/* table for converting a 5bit channel into an 8bit channel (used for 16bpp to 32bpp conversion) */
static const uint8_t sprite_16bpp_translate[] = {
@@ -127,7 +127,7 @@ static const uint32_t sprite_8bpp_palette[] = {
0xccccccff, 0xddddddff, 0xeeeeeeff, 0xffffffff
};
-void sprite_init(void)
+void rosprite_init(void)
{
for (uint32_t i = 0; i < 256; i++) {
oldmodes[i].colorbpp = 0;
@@ -215,9 +215,9 @@ void sprite_read_bytes(FILE* stream, uint8_t* buf, size_t count)
}
}
-struct sprite_mode* sprite_get_mode(uint32_t spriteMode)
+struct rosprite_mode* sprite_get_mode(uint32_t spriteMode)
{
- struct sprite_mode* mode = malloc(sizeof(struct sprite_mode));
+ struct rosprite_mode* mode = malloc(sizeof(struct rosprite_mode));
uint32_t spriteType = (spriteMode & 0x78000000) >> 27; /* preserve bits 27-30 only */
@@ -257,13 +257,13 @@ struct sprite_mode* sprite_get_mode(uint32_t spriteMode)
} else {
/* clone station mode and return */
assert(spriteMode < 256); /* don't think you can have modes over 255? */
- memcpy(mode, &(oldmodes[spriteMode]), sizeof(struct sprite_mode));
+ memcpy(mode, &(oldmodes[spriteMode]), sizeof(struct rosprite_mode));
}
return mode;
}
-uint32_t sprite_palette_lookup(struct sprite* sprite, uint32_t pixel)
+uint32_t sprite_palette_lookup(struct rosprite* sprite, uint32_t pixel)
{
uint32_t translated_pixel;
/* because we're dealing with 8bpp or less */
@@ -316,7 +316,7 @@ static inline uint32_t sprite_cmyk_to_rgb(uint32_t cmyk)
}
/* TODO: could make static inline? */
-uint32_t sprite_upscale_color(uint32_t pixel, struct sprite_mode* mode, bool* has_alpha_pixel_data)
+uint32_t sprite_upscale_color(uint32_t pixel, struct rosprite_mode* mode, bool* has_alpha_pixel_data)
{
switch (mode->colorbpp) {
case 32:
@@ -376,9 +376,9 @@ void sprite_fix_alpha(uint32_t* image, uint32_t pixels)
}
}
-struct sprite_mask_state* sprite_init_mask_state(struct sprite* sprite, struct sprite_header* header, uint8_t* mask)
+struct rosprite_mask_state* sprite_init_mask_state(struct rosprite* sprite, struct rosprite_header* header, uint8_t* mask)
{
- struct sprite_mask_state* mask_state = malloc(sizeof(struct sprite_mask_state));
+ struct rosprite_mask_state* mask_state = malloc(sizeof(struct rosprite_mask_state));
mask_state->x = header->first_used_bit;
mask_state->y = 0;
@@ -395,7 +395,7 @@ struct sprite_mask_state* sprite_init_mask_state(struct sprite* sprite, struct s
/* Get the next mask byte.
* Mask of 0xff denotes 100% opaque, 0x00 denotes 100% transparent
*/
-uint32_t sprite_next_mask_pixel(uint8_t* mask, struct sprite_mask_state* mask_state)
+uint32_t sprite_next_mask_pixel(uint8_t* mask, struct rosprite_mask_state* mask_state)
{
/* a 1bpp mask (for new mode sprites), each row is word aligned (therefore potential righthand wastage */
const uint32_t bitmask = (1 << mask_state->bpp) - 1;
@@ -429,14 +429,14 @@ uint32_t sprite_next_mask_pixel(uint8_t* mask, struct sprite_mask_state* mask_st
return pixel;
}
-void sprite_load_high_color(uint8_t* image_in, uint8_t* mask, struct sprite* sprite, struct sprite_header* header)
+void sprite_load_high_color(uint8_t* image_in, uint8_t* mask, struct rosprite* sprite, struct rosprite_header* header)
{
- struct sprite_mask_state* mask_state = NULL;
+ struct rosprite_mask_state* mask_state = NULL;
if (sprite->has_mask) mask_state = sprite_init_mask_state(sprite, header, mask);
sprite->image = malloc(sprite->width * sprite->height * 4); /* all image data is 32bpp going out */
- uint32_t currentByteIndex = 0; /* only for standalone test -- fread() will maintain this */
+ uint32_t currentByteIndex = 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); /* Last used bit in row */
@@ -478,9 +478,9 @@ void sprite_load_high_color(uint8_t* image_in, uint8_t* mask, struct sprite* spr
if (sprite->has_mask) free(mask_state);
}
-void sprite_load_low_color(uint8_t* image_in, uint8_t* mask, struct sprite* sprite, struct sprite_header* header)
+void sprite_load_low_color(uint8_t* image_in, uint8_t* mask, struct rosprite* sprite, struct rosprite_header* header)
{
- struct sprite_mask_state* mask_state = NULL;
+ struct rosprite_mask_state* mask_state = NULL;
if (sprite->has_mask) mask_state = sprite_init_mask_state(sprite, header, mask);
sprite->image = malloc(sprite->width * sprite->height * 4); /* all image data is 32bpp going out */
@@ -526,12 +526,12 @@ void sprite_load_low_color(uint8_t* image_in, uint8_t* mask, struct sprite* spri
if (sprite->has_mask) free(mask_state);
}
-struct sprite* sprite_load_sprite(FILE* spritefile)
+struct rosprite* sprite_load_sprite(FILE* spritefile)
{
uint32_t nextSpriteOffset = sprite_read_word(spritefile);
- struct sprite* sprite = malloc(sizeof(struct sprite));
- struct sprite_header* header = malloc(sizeof(struct sprite_header));
+ struct rosprite* sprite = malloc(sizeof(struct rosprite));
+ struct rosprite_header* header = malloc(sizeof(struct rosprite_header));
sprite_read_bytes(spritefile, sprite->name, 12);
sprite->name[12] = '\0';
@@ -619,9 +619,9 @@ struct sprite* sprite_load_sprite(FILE* spritefile)
return sprite;
}
-struct sprite_area* sprite_load_file(FILE* f)
+struct rosprite_area* rosprite_load_file(FILE* f)
{
- struct sprite_area* sprite_area = malloc(sizeof(struct sprite_area));
+ struct rosprite_area* sprite_area = malloc(sizeof(struct rosprite_area));
sprite_area->sprite_count = sprite_read_word(f);
@@ -635,19 +635,19 @@ struct sprite_area* sprite_load_file(FILE* f)
sprite_read_bytes(f, sprite_area->extension_words, (size_t) (sprite_area->extension_size));
}
- sprite_area->sprites = malloc(sizeof(struct sprite*) * sprite_area->sprite_count); /* allocate array of pointers */
+ sprite_area->sprites = malloc(sizeof(struct rosprite*) * sprite_area->sprite_count); /* allocate array of pointers */
for (uint32_t i = 0; i < sprite_area->sprite_count; i++) {
- struct sprite* sprite = sprite_load_sprite(f);
+ struct rosprite* sprite = sprite_load_sprite(f);
sprite_area->sprites[i] = sprite;
}
return sprite_area;
}
-void rosprite_destroy_sprite_area(struct sprite_area* sprite_area)
+void rosprite_destroy_sprite_area(struct rosprite_area* sprite_area)
{
for (uint32_t i = 0; i < sprite_area->sprite_count; i++) {
- struct sprite* sprite = sprite_area->sprites[i];
+ struct rosprite* sprite = sprite_area->sprites[i];
free(sprite->mode);
if (sprite->has_palette) free(sprite->palette);
free(sprite->image);
@@ -659,20 +659,20 @@ void rosprite_destroy_sprite_area(struct sprite_area* sprite_area)
free(sprite_area);
}
-struct sprite_palette* sprite_load_palette(FILE* f)
+struct rosprite_palette* rosprite_load_palette(FILE* f)
{
/* Palette file is in groups of 6 bytes, each is a VDU 19 (set palette)
* http://www.drobe.co.uk/show_manual.php?manual=/sh-cgi?manual=Vdu%26page=19 */
/* TODO: currently assume palette has linear entries (2nd byte in is 00, 01, 02 etc) */
- struct sprite_palette* palette = malloc(sizeof(struct sprite_palette));
+ struct rosprite_palette* palette = malloc(sizeof(struct rosprite_palette));
palette->palette = malloc(sizeof(uint32_t) * 256); /* allocate 256 whether we need them all or not */
uint32_t c = 0;
uint8_t b[6];
- size_t bytesRead = fread(&b, 1, 6, f);
+ size_t bytesRead = fread(&b, 1, 6, f); /* TODO: make this use a pluggable read function */
assert(bytesRead % 6 == 0);
while (bytesRead == 6) {
assert(b[0] == 19); /* VDU 19 */
@@ -697,7 +697,7 @@ struct sprite_palette* sprite_load_palette(FILE* f)
return palette;
}
-void rosprite_destroy_palette(struct sprite_palette* palette)
+void rosprite_destroy_palette(struct rosprite_palette* palette)
{
free(palette->palette);
free(palette);
diff --git a/trunk/libsprite.h b/trunk/libsprite.h
index f0f0806..945e489 100644
--- a/trunk/libsprite.h
+++ b/trunk/libsprite.h
@@ -6,14 +6,14 @@
typedef enum { rosprite_rgb, rosprite_cmyk } rosprite_color_model;
-struct sprite_area {
+struct rosprite_area {
uint32_t extension_size; /* size of extension_words in bytes */
uint8_t* extension_words;
uint32_t sprite_count;
- struct sprite** sprites; /* array of length sprite_count */
+ struct rosprite** sprites; /* array of length sprite_count */
};
-struct sprite_mode {
+struct rosprite_mode {
uint32_t colorbpp;
/* maskbpp denotes the amount of alpha bpp used
* while mask_width is the bits used to store the mask.
@@ -28,14 +28,14 @@ struct sprite_mode {
rosprite_color_model color_model;
};
-struct sprite_palette {
+struct rosprite_palette {
uint32_t size; /* in number of entries (each entry is a word) */
uint32_t* palette;
};
-struct sprite {
+struct rosprite {
unsigned char name[13]; /* last byte for 0 terminator */
- struct sprite_mode* mode;
+ struct rosprite_mode* mode;
bool has_mask;
bool has_palette;
uint32_t palettesize; /* in number of entries (each entry is a word) */
@@ -45,12 +45,12 @@ struct sprite {
uint32_t* image; /* image data in 0xRRGGBBAA words */
};
-void sprite_init(void);
-struct sprite_area* sprite_load_file(FILE* f);
-void rosprite_destroy_sprite_area(struct sprite_area *);
+void rosprite_init(void);
+struct rosprite_area* rosprite_load_file(FILE* f);
+void rosprite_destroy_sprite_area(struct rosprite_area *);
-struct sprite_palette* rosprite_load_palette(FILE* f);
-void rosprite_destroy_palette(struct sprite_palette *);
+struct rosprite_palette* rosprite_load_palette(FILE* f);
+void rosprite_destroy_palette(struct rosprite_palette *);
#endif
diff --git a/trunk/palette2c.c b/trunk/palette2c.c
index c952d95..f384310 100644
--- a/trunk/palette2c.c
+++ b/trunk/palette2c.c
@@ -18,9 +18,9 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- sprite_init();
+ rosprite_init();
- struct sprite_palette* palette = sprite_load_palette(palettefile);
+ struct rosprite_palette* palette = rosprite_load_palette(palettefile);
for (uint32_t i = 0; i < palette->size; i++) {
printf("0x%x, ", palette->palette[i]);
@@ -28,5 +28,7 @@ int main(int argc, char *argv[])
fclose(palettefile);
+ rosprite_destroy_palette(palette);
+
return EXIT_SUCCESS;
}