1
0
Fork 0
forked from fte/fteqw

Fixed dynamic linking issues... properly.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4616 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2014-02-17 15:31:47 +00:00
parent b499252a4e
commit 832079f0a6

View file

@ -766,18 +766,30 @@ qboolean LibPNG_Init(void)
{(void **) &qpng_get_error_ptr, "png_get_error_ptr"}, {(void **) &qpng_get_error_ptr, "png_get_error_ptr"},
{NULL, NULL} {NULL, NULL}
}; };
static qboolean tried;
if (!LIBPNG_LOADED()) if (!tried)
{ {
#ifdef _WIN32 tried = true;
libpng_handle = Sys_LoadLibrary("libpng"STRINGIFY(PNG_LIBPNG_VER_DLLNUM), pngfuncs);
#else
libpng_handle = Sys_LoadLibrary("libpng.so."STRINGIFY(PNG_LIBPNG_VER_SONUM), pngfuncs);
#endif
}
// if (!LIBPNG_LOADED())
// libpng_handle = Sys_LoadLibrary("libpng", pngfuncs);
if (!LIBPNG_LOADED())
{
char *libname;
#ifdef _WIN32
libname = va("libpng%i", PNG_LIBPNG_VER_DLLNUM);
#else
if (PNG_LIBPNG_VER_SONUM == 0)
libname = "libpng.so";
else
libname = va("libpng.so.%i", PNG_LIBPNG_VER_SONUM);
#endif
libpng_handle = Sys_LoadLibrary(libname, pngfuncs);
if (!libpng_handle)
Con_Printf("Unable to load %s\n", libname);
}
// if (!LIBPNG_LOADED())
// libpng_handle = Sys_LoadLibrary("libpng", pngfuncs);
}
#endif #endif
return LIBPNG_LOADED(); return LIBPNG_LOADED();
} }
@ -819,7 +831,6 @@ static void VARGS png_onwarning(png_structp png_ptr, png_const_charp warning_msg
Con_Printf("libpng %s: %s\n", err->fname, warning_msg); Con_Printf("libpng %s: %s\n", err->fname, warning_msg);
} }
qbyte *png_rgba;
qbyte *ReadPNGFile(qbyte *buf, int length, int *width, int *height, const char *fname) qbyte *ReadPNGFile(qbyte *buf, int length, int *width, int *height, const char *fname)
{ {
qbyte header[8], **rowpointers = NULL, *data = NULL; qbyte header[8], **rowpointers = NULL, *data = NULL;
@ -831,6 +842,9 @@ qbyte *ReadPNGFile(qbyte *buf, int length, int *width, int *height, const char *
png_uint_32 pngwidth, pngheight; png_uint_32 pngwidth, pngheight;
struct pngerr errctx; struct pngerr errctx;
if (!LibPNG_Init())
return NULL;
memcpy(header, buf, 8); memcpy(header, buf, 8);
errctx.fname = fname; errctx.fname = fname;
@ -842,23 +856,23 @@ error:
if (rowpointers) if (rowpointers)
BZ_Free(rowpointers); BZ_Free(rowpointers);
qpng_destroy_read_struct(&png, &pnginfo, NULL); qpng_destroy_read_struct(&png, &pnginfo, NULL);
return (png_rgba = NULL); return NULL;
} }
if (qpng_sig_cmp(header, 0, 8)) if (qpng_sig_cmp(header, 0, 8))
{ {
return (png_rgba = NULL); return NULL;
} }
if (!(png = qpng_create_read_struct(PNG_LIBPNG_VER_STRING, &errctx, png_onerror, png_onwarning))) if (!(png = qpng_create_read_struct(PNG_LIBPNG_VER_STRING, &errctx, png_onerror, png_onwarning)))
{ {
return (png_rgba = NULL); return NULL;
} }
if (!(pnginfo = qpng_create_info_struct(png))) if (!(pnginfo = qpng_create_info_struct(png)))
{ {
qpng_destroy_read_struct(&png, &pnginfo, NULL); qpng_destroy_read_struct(&png, &pnginfo, NULL);
return (png_rgba = NULL); return NULL;
} }
ri.data=buf; ri.data=buf;
@ -915,7 +929,7 @@ error:
{ {
Con_Printf ("Bad PNG color depth and/or bpp (%s)\n", fname); Con_Printf ("Bad PNG color depth and/or bpp (%s)\n", fname);
qpng_destroy_read_struct(&png, &pnginfo, NULL); qpng_destroy_read_struct(&png, &pnginfo, NULL);
return (png_rgba = NULL); return NULL;
} }
data = BZF_Malloc(*height * rowbytes); data = BZF_Malloc(*height * rowbytes);
@ -932,7 +946,7 @@ error:
qpng_destroy_read_struct(&png, &pnginfo, NULL); qpng_destroy_read_struct(&png, &pnginfo, NULL);
BZ_Free(rowpointers); BZ_Free(rowpointers);
return (png_rgba = data); return data;
} }
@ -951,6 +965,9 @@ int Image_WritePNG (char *filename, int compression, qbyte *pixels, int width, i
if (!FS_NativePath(filename, FS_GAMEONLY, name, sizeof(name))) if (!FS_NativePath(filename, FS_GAMEONLY, name, sizeof(name)))
return false; return false;
if (!LibPNG_Init())
return false;
if (!(fp = fopen (name, "wb"))) if (!(fp = fopen (name, "wb")))
{ {
FS_CreatePath (filename, FS_GAMEONLY); FS_CreatePath (filename, FS_GAMEONLY);