Skip to content

Commit

Permalink
Fix wrong colors in UI (swizzle pixels to framebuffer format)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahefner committed Jul 4, 2015
1 parent 6019e03 commit 94cf38a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 23 deletions.
12 changes: 0 additions & 12 deletions filters.c
Expand Up @@ -57,18 +57,6 @@ void inline emit_unscaled (Uint32 *out, byte *colors, byte *emphasis, size_t n)
out[x] = convert_pixel(colors[x], emphasis[x], sw);
}

void swizzle_pixels (uint32_t *pixels, size_t len)
{
struct rgb_shifts sw = rgb_shifts;

for (size_t x = 0; x < len; x++)
{
unsigned px = pixels[x];
byte r = (px >> 16) & 0xFF, g = (px >> 8) & 0xFF, b = px & 0xFF;
pixels[x] = (r << sw.r_shift) | (g << sw.g_shift) | (b << sw.b_shift);
}
}

void no_filter_emitter (unsigned y, byte *colors, byte *emphasis)
{
Uint32 *dest = display_ptr(0,y);
Expand Down
4 changes: 0 additions & 4 deletions filters.h
Expand Up @@ -40,8 +40,4 @@ static inline Uint32 rgbi_clamp (int r, int g, int b)
return rgbi(clamp_byte(r), clamp_byte(g), clamp_byte(b));
}

#define RED(x) (((x)>>16)&0xFF)
#define GREEN(x) (((x)>>8)&0xFF)
#define BLUE(x) ((x)&0xFF)

#endif
2 changes: 2 additions & 0 deletions font.c
Expand Up @@ -249,6 +249,8 @@ int draw_string (int x0, int baseline, char *string, unsigned color)
int len = strlen(string);
int x;

swizzle_pixels(&color, 1);

for (int line = 0; line < text_height; line++) {
x = x0;
int y = baseline - text_ascent + line;
Expand Down
2 changes: 2 additions & 0 deletions global.h
Expand Up @@ -142,6 +142,8 @@ static inline Uint32 *next_line (Uint32 *ptr, int n)
return (Uint32 *)(((byte *)ptr) + n*window_surface->pitch);
}

void swizzle_pixels (uint32_t *pixels, size_t len);

#endif

#define max(x,y) ((x)>(y)?(x):(y))
Expand Down
12 changes: 12 additions & 0 deletions sys.c
Expand Up @@ -170,3 +170,15 @@ void make_dir (const char *path)
#endif
}

void swizzle_pixels (uint32_t *pixels, size_t len)
{
struct rgb_shifts sw = rgb_shifts;

for (size_t x = 0; x < len; x++)
{
unsigned px = pixels[x];
byte r = (px >> 16) & 0xFF, g = (px >> 8) & 0xFF, b = px & 0xFF;
pixels[x] = (r << sw.r_shift) | (g << sw.g_shift) | (b << sw.b_shift);
}
}

42 changes: 35 additions & 7 deletions ui.c
Expand Up @@ -503,6 +503,8 @@ void age_pixels (Uint32 *ptr, size_t n)
level += 31;
ptr[i] = rgbi_clamp(level+30, level+30, level);
}

swizzle_pixels(ptr,n);
}

/*** Menu dispatch ***/
Expand Down Expand Up @@ -580,6 +582,25 @@ void update_state_image (void)
printf("Updated screencap %s\n", buf);
}

static Uint32 getbyte (Uint32 x, unsigned shift)
{
return (x >> shift) & 0xFF;
}

static Uint32 blendbyte (Uint32 x, Uint32 y, int fade, int notfade)
{
return (x * fade + y * notfade) >> 8;
}

static Uint32 blend (Uint32 x, Uint32 y, int fade)
{
int notfade = 256 - fade;
return blendbyte(getbyte(x,0), getbyte(y,0), fade, notfade)
| blendbyte(getbyte(x,8), getbyte(y,8), fade, notfade) << 8
| blendbyte(getbyte(x,16), getbyte(y,16), fade, notfade) << 16
| blendbyte(getbyte(x,24), getbyte(y,24), fade, notfade) << 24;
}

void render_restorestate (struct inputctx *input)
{
const int photo_border = 10;
Expand Down Expand Up @@ -614,20 +635,25 @@ void render_restorestate (struct inputctx *input)

int d_fade = hover? -10: 10;
fade = clamp_byte(fade + d_fade);
int notfade = 255-fade;

if (have_screencap) {
if (have_screencap)
{
for (int i=0; i<actual_height; i++)
{
Uint32 *ptr = display_ptr(vx, vy+i);
Uint32 *aged = &aged_screencap[i+overscan][overscan];
Uint32 *rgb = &rgb_screencap[i+overscan][overscan];
if (fade==255) memcpy(ptr, aged, 4*actual_width);
else for (int x = 0; x<actual_width; x++) {
ptr[x] = rgbi((fade*(RED(aged[x])) + notfade*(RED(rgb[x]))) >> 8,
(fade*(GREEN(aged[x])) + notfade*(GREEN(rgb[x]))) >> 8,
(fade*(BLUE(aged[x])) + notfade*(BLUE(rgb[x]))) >> 8);
if (fade==255)
{
memcpy(ptr, aged, 4*actual_width);
}
else
{
for (int x = 0; x<actual_width; x++)
{
ptr[x] = blend(aged[x], rgb[x], fade);
}
}
}
}

Expand Down Expand Up @@ -1020,6 +1046,8 @@ image_t render_gamepak_label (struct gbent *ent)

noinline void fill_rect (Uint32 color, int x0, int y0, int x1, int y1)
{
swizzle_pixels(&color,1);

int width = x1 - x0;
x0 = clampi(0, x0, window_surface->w);
x1 = clampi(0, x1, window_surface->w);
Expand Down

0 comments on commit 94cf38a

Please sign in to comment.