mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-12-30 23:52:25 +02:00
Update to use the latest libopk API, and simplify loadPNG
This commit is contained in:
parent
0b922e97f3
commit
8d96f3c261
@ -15,27 +15,12 @@
|
|||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
#include <opk.h>
|
#include <opk.h>
|
||||||
|
|
||||||
struct OpkParams {
|
|
||||||
std::string *sqfs_file, *icon_file;
|
|
||||||
unsigned int offset;
|
|
||||||
char *buf;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void __readFromOpk(png_structp png_ptr, png_bytep ptr, png_size_t length)
|
static void __readFromOpk(png_structp png_ptr, png_bytep ptr, png_size_t length)
|
||||||
{
|
{
|
||||||
struct OpkParams *params = (struct OpkParams *) png_get_io_ptr(png_ptr);
|
char **buf = (char **) png_get_io_ptr(png_ptr);
|
||||||
|
|
||||||
if (!params->buf) {
|
memcpy(ptr, *buf, length);
|
||||||
params->buf = opk_extract_file(params->sqfs_file->c_str(),
|
*buf += length;
|
||||||
params->icon_file->c_str());
|
|
||||||
if (!params->buf) {
|
|
||||||
png_error(png_ptr, "Unable to open OPK package\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(ptr, params->buf + params->offset, length);
|
|
||||||
params->offset += length;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -47,8 +32,9 @@ SDL_Surface *loadPNG(const std::string &path) {
|
|||||||
png_structp png = NULL;
|
png_structp png = NULL;
|
||||||
png_infop info = NULL;
|
png_infop info = NULL;
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
struct OpkParams *params = NULL;
|
|
||||||
std::string::size_type pos;
|
std::string::size_type pos;
|
||||||
|
struct ParserData *pdata = NULL;
|
||||||
|
char *buffer = NULL, *param;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create and initialize the top-level libpng struct.
|
// Create and initialize the top-level libpng struct.
|
||||||
@ -72,13 +58,16 @@ SDL_Surface *loadPNG(const std::string &path) {
|
|||||||
if (pos != path.npos) {
|
if (pos != path.npos) {
|
||||||
DEBUG("Registering specific callback for icon %s\n", path.c_str());
|
DEBUG("Registering specific callback for icon %s\n", path.c_str());
|
||||||
|
|
||||||
params = (struct OpkParams *) malloc(sizeof(*params));
|
pdata = opk_open(path.substr(0, pos).c_str());
|
||||||
params->sqfs_file = new std::string(path.substr(0, pos));
|
if (!pdata) {
|
||||||
params->icon_file = new std::string(path.substr(pos + 1));
|
ERROR("Unable to open OPK\n");
|
||||||
params->offset = 0;
|
goto cleanup;
|
||||||
params->buf = NULL;
|
}
|
||||||
|
|
||||||
png_set_read_fn(png, params, __readFromOpk);
|
buffer = opk_extract_file(pdata, path.substr(pos + 1).c_str());
|
||||||
|
param = buffer;
|
||||||
|
|
||||||
|
png_set_read_fn(png, ¶m, __readFromOpk);
|
||||||
} else {
|
} else {
|
||||||
#else
|
#else
|
||||||
if (1) {
|
if (1) {
|
||||||
@ -165,11 +154,10 @@ cleanup:
|
|||||||
png_destroy_read_struct(&png, &info, NULL);
|
png_destroy_read_struct(&png, &info, NULL);
|
||||||
if (fp) fclose(fp);
|
if (fp) fclose(fp);
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
if (params) {
|
if (buffer)
|
||||||
if (params->buf)
|
free(buffer);
|
||||||
free(params->buf);
|
if (pdata)
|
||||||
free(params);
|
opk_close(pdata);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return surface;
|
return surface;
|
||||||
|
@ -90,6 +90,12 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!opk_open_metadata(pdata)) {
|
||||||
|
ERROR("OPK does not contain any meta-data\n");
|
||||||
|
opk_close(pdata);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
opkFile = file;
|
opkFile = file;
|
||||||
pos = file.rfind('/');
|
pos = file.rfind('/');
|
||||||
opkMount = file.substr(pos+1);
|
opkMount = file.substr(pos+1);
|
||||||
|
Loading…
Reference in New Issue
Block a user