Add support for converting 8-bit SDL_Surfaces.

This commit is contained in:
simon.kagstrom 2010-01-30 12:35:54 +00:00
parent 7ff83399c1
commit 89ba23647c
3 changed files with 39 additions and 13 deletions

View File

@ -34,6 +34,18 @@
extern SDL_Surface *real_screen;
#endif
// Colors for speedometer/drive LEDs
enum {
black = 0,
white = 1,
fill_gray = 16,
shine_gray = 17,
shadow_gray = 18,
red = 19,
green = 20,
PALETTE_SIZE = 21,
};
#ifdef WIN32
#include <ddraw.h>
#endif

View File

@ -53,17 +53,6 @@ static itimerval pulse_tv;
// SDL joysticks
static SDL_Joystick *joy[2] = {NULL, NULL};
// Colors for speedometer/drive LEDs
enum {
black = 0,
white = 1,
fill_gray = 16,
shine_gray = 17,
shadow_gray = 18,
red = 19,
green = 20,
PALETTE_SIZE = 21,
};
static Uint16 palette_16[PALETTE_SIZE];
static Uint32 palette_32[PALETTE_SIZE];
SDL_Color sdl_palette[PALETTE_SIZE];
@ -375,7 +364,7 @@ SDL_Surface *C64Display::SurfaceFromC64Display()
dst_pixels[ dst_off ] = v;
}
}
SDL_SetPalette(out, SDL_LOGPAL | SDL_PHYSPAL, sdl_palette, 0, PALETTE_SIZE);
SDL_SetColors(out, sdl_palette, 0, PALETTE_SIZE);
return out;
}

View File

@ -5,6 +5,9 @@
#include <sys/stat.h>
#include <SDL_ttf.h>
#include <sysdeps.h>
#include <C64.h>
#include "gui/font.hh"
#include "utils.hh"
@ -185,6 +188,8 @@ static void png_user_error(png_structp ctx, png_const_charp str)
fprintf(stderr, "libpng: error: %s\n", str);
}
extern SDL_Color sdl_palette[PALETTE_SIZE];
/* This is taken from http://encelo.netsons.org/programming/sdl (GPLed) */
void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz)
{
@ -192,6 +197,7 @@ void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz)
png_infop info_ptr;
int i, colortype;
png_bytep *row_pointers;
png_colorp palette;
struct png_write_user_struct out;
out.sz = 0;
@ -223,6 +229,25 @@ void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz)
png_set_IHDR(png_ptr, info_ptr, surf->w, surf->h, 8, colortype, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
if (colortype & PNG_COLOR_MASK_PALETTE)
{
/* Set the palette if there is one. REQUIRED for indexed-color images */
palette = (png_colorp)png_malloc(png_ptr,
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
/* KLUDGE! For some reason, surf->format->palette doesn't work... */
for (int i = 0; i < PALETTE_SIZE; i++)
{
SDL_Color *p = &sdl_palette[i];
palette[i].red = p->r;
palette[i].green = p->g;
palette[i].blue = p->b;
}
/* ... Set palette colors ... */
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
}
/* Writing the image */
png_write_info(png_ptr, info_ptr);
png_set_packing(png_ptr);