Add helper in utils to create a SDL_Surface from data

This commit is contained in:
simon.kagstrom 2010-02-10 18:10:31 +00:00
parent 5841aa35a3
commit f710bacf73
5 changed files with 21 additions and 7 deletions

View File

@ -24,6 +24,7 @@ struct ds_data *DataStore::registerNetworkData(uint32_t key, uint32_t metadata,
out = (struct ds_data *)xmalloc(sizeof(struct ds_data) + data_sz);
out->key = key;
out->metadata = metadata;
out->sz = data_sz;
memcpy(out->data, data, data_sz);

View File

@ -9,6 +9,7 @@ struct ds_data
{
uint32_t key;
uint32_t metadata; /* Type etc */
size_t sz;
uint8_t data[];
};

View File

@ -216,7 +216,6 @@ struct game_info *GameInfo::dump()
bool GameInfo::fromDump(struct game_info *gi)
{
struct game_info *p = gi;
SDL_RWops *rw;
/* Demarshal */
switch (ntohs(p->version_magic))
@ -239,13 +238,8 @@ bool GameInfo::fromDump(struct game_info *gi)
this->score = p->score;
this->year = p->year;
rw = SDL_RWFromMem(p->data + p->screenshot_off,
this->screenshot = sdl_surface_from_data(p->data + p->screenshot_off,
p->sz - p->screenshot_off);
if (!rw)
goto bail_out;
this->screenshot = IMG_Load_RW(rw, 0);
SDL_FreeRW(rw);
if (!this->screenshot)
goto bail_out;
free(p);

View File

@ -4,6 +4,7 @@
#include <png.h>
#include <sys/stat.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
#include <sysdeps.h>
#include <C64.h>
@ -270,6 +271,21 @@ void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz)
return out.data;
}
SDL_Surface *sdl_surface_from_data(void *data, size_t sz)
{
SDL_RWops *rw;
SDL_Surface *out;
rw = SDL_RWFromMem(data, sz);
if (!rw)
return NULL;
out = IMG_Load_RW(rw, 0);
SDL_FreeRW(rw);
return out;
}
void highlight_background(SDL_Surface *where, Font *font,
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
int x, int y, int w, int h)

View File

@ -78,6 +78,8 @@ const char **get_file_list(const char *base_dir, const char *exts[]);
void *sdl_surface_to_png(SDL_Surface *src, size_t *out_sz);
SDL_Surface *sdl_surface_from_data(void *data, size_t sz);
void highlight_background(SDL_Surface *where, Font *font,
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
int x, int y, int w, int h);