summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Shaw <jshaw@netsurf-browser.org>2007-11-28 17:15:39 +0000
committerJames Shaw <jshaw@netsurf-browser.org>2007-11-28 17:15:39 +0000
commitaa9395bfc965e4a6974f8b2d84760646534f321f (patch)
treec618b649751f1d318f5c78ced2fd56f2a7d5012c
parentfd6e983aff4bbeb2e9e7e5115fafa1aca7e409a8 (diff)
downloadlibrosprite-aa9395bfc965e4a6974f8b2d84760646534f321f.tar.gz
librosprite-aa9395bfc965e4a6974f8b2d84760646534f321f.tar.bz2
Fixed masking for low colour sprites
svn path=/import/jshaw/libsprite/; revision=9999
-rw-r--r--trunk/example.c13
-rw-r--r--trunk/libsprite.c5
2 files changed, 10 insertions, 8 deletions
diff --git a/trunk/example.c b/trunk/example.c
index f2a7a86..7afd5a4 100644
--- a/trunk/example.c
+++ b/trunk/example.c
@@ -9,13 +9,12 @@ void sdl_draw_pixel(SDL_Surface* surface, uint32_t x, uint32_t y, uint32_t color
{
uint32_t* pixel = ((uint32_t*) (surface->pixels)) + (y * surface->pitch/4) + x;
/* pretty sure SDL can do this, but can't figure out how */
+ uint32_t bg_color = ((int) (x / 4.0) + ((int)(y / 4.0) % 2)) % 2 ? 0x99 : 0x66;
+
uint32_t alpha = color & 0x000000ff;
- uint32_t r = alpha;
- uint32_t g = alpha;
- uint32_t b = alpha;
- /*uint32_t r = ((color & 0xff000000) >> 24) * (alpha / 255.0);
- uint32_t g = ((color & 0x00ff0000) >> 16) * (alpha / 255.0);
- uint32_t b = ((color & 0x0000ff00) >> 8) * (alpha / 255.0);*/
+ uint32_t r = (bg_color + (((color & 0xff000000) >> 24) - bg_color) * (alpha / 255.0));
+ uint32_t g = (bg_color + (((color & 0x00ff0000) >> 16) - bg_color) * (alpha / 255.0));
+ uint32_t b = (bg_color + (((color & 0x0000ff00) >> 8) - bg_color) * (alpha / 255.0));
uint32_t mapped_color = SDL_MapRGB(surface->format, r, g, b);
*pixel = mapped_color;
@@ -25,7 +24,7 @@ void sdl_blank(SDL_Surface* surface)
{
for (uint32_t y = 0; y < (uint32_t) surface->h; y++) {
for (uint32_t x = 0; x < (uint32_t) surface->w; x++) {
- sdl_draw_pixel(surface, x, y, (uint32_t) 0);
+ sdl_draw_pixel(surface, x, y, (uint32_t) ((int) (x / 4.0) + ((int)(y / 4.0) % 2)) % 2 ? 0x999999ff : 0x666666ff);
}
}
}
diff --git a/trunk/libsprite.c b/trunk/libsprite.c
index aef9f96..3e1d90e 100644
--- a/trunk/libsprite.c
+++ b/trunk/libsprite.c
@@ -378,6 +378,7 @@ uint32_t sprite_next_mask_pixel(uint8_t* mask, struct sprite_mask_state* mask_st
const uint32_t bitmask = (1 << mask_state->bpp) - 1;
const uint32_t offset_into_word = mask_state->x % 32;
uint32_t pixel = (mask_state->current_word & (bitmask << offset_into_word)) >> offset_into_word;
+ printf("%2x ", pixel);
if (mask_state->x + mask_state->bpp < mask_state->row_max_bit && offset_into_word + mask_state->bpp == 32) {
mask_state->current_word = BTUINT((mask + mask_state->current_byte_index));
@@ -465,7 +466,7 @@ void sprite_load_low_color(uint8_t* image_in, uint8_t* mask, struct sprite* spri
pixel = sprite_palette_lookup(sprite, pixel); /* lookup returns 32bpp */
if (sprite->has_mask) {
uint8_t mask_pixel = sprite_next_mask_pixel(mask, mask_state);
- pixel = pixel | mask_pixel;
+ pixel = (pixel & 0xffffff00) | mask_pixel;
}
sprite->image[y*sprite->width + x_pixels] = pixel;
x_pixels++;
@@ -482,6 +483,8 @@ void sprite_load_low_color(uint8_t* image_in, uint8_t* mask, struct sprite* spri
currentword = BTUINT((image_in + current_byte_index));
current_byte_index += 4;
}
+
+ printf("\n");
}
if (sprite->has_mask) free(mask_state);