mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-25 12:56:59 +01:00
Add helper in utils to create a SDL_Surface from data
This commit is contained in:
parent
5841aa35a3
commit
f710bacf73
@ -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 = (struct ds_data *)xmalloc(sizeof(struct ds_data) + data_sz);
|
||||||
out->key = key;
|
out->key = key;
|
||||||
out->metadata = metadata;
|
out->metadata = metadata;
|
||||||
|
out->sz = data_sz;
|
||||||
|
|
||||||
memcpy(out->data, data, data_sz);
|
memcpy(out->data, data, data_sz);
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ struct ds_data
|
|||||||
{
|
{
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
uint32_t metadata; /* Type etc */
|
uint32_t metadata; /* Type etc */
|
||||||
|
size_t sz;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,7 +216,6 @@ struct game_info *GameInfo::dump()
|
|||||||
bool GameInfo::fromDump(struct game_info *gi)
|
bool GameInfo::fromDump(struct game_info *gi)
|
||||||
{
|
{
|
||||||
struct game_info *p = gi;
|
struct game_info *p = gi;
|
||||||
SDL_RWops *rw;
|
|
||||||
|
|
||||||
/* Demarshal */
|
/* Demarshal */
|
||||||
switch (ntohs(p->version_magic))
|
switch (ntohs(p->version_magic))
|
||||||
@ -239,13 +238,8 @@ bool GameInfo::fromDump(struct game_info *gi)
|
|||||||
this->score = p->score;
|
this->score = p->score;
|
||||||
this->year = p->year;
|
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);
|
p->sz - p->screenshot_off);
|
||||||
if (!rw)
|
|
||||||
goto bail_out;
|
|
||||||
|
|
||||||
this->screenshot = IMG_Load_RW(rw, 0);
|
|
||||||
SDL_FreeRW(rw);
|
|
||||||
if (!this->screenshot)
|
if (!this->screenshot)
|
||||||
goto bail_out;
|
goto bail_out;
|
||||||
free(p);
|
free(p);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <png.h>
|
#include <png.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
|
#include <SDL_image.h>
|
||||||
|
|
||||||
#include <sysdeps.h>
|
#include <sysdeps.h>
|
||||||
#include <C64.h>
|
#include <C64.h>
|
||||||
@ -270,6 +271,21 @@ void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz)
|
|||||||
return out.data;
|
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,
|
void highlight_background(SDL_Surface *where, Font *font,
|
||||||
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
|
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
|
||||||
int x, int y, int w, int h)
|
int x, int y, int w, int h)
|
||||||
|
@ -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);
|
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,
|
void highlight_background(SDL_Surface *where, Font *font,
|
||||||
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
|
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
|
||||||
int x, int y, int w, int h);
|
int x, int y, int w, int h);
|
||||||
|
Loading…
Reference in New Issue
Block a user