libs for win64. corrected libjpeg fastcall issues by hacking the header to make sure its all properly cdecl.
Added support for DYNAMIC_LIBBLAH, for people that don't want to statically link for whatever reason. git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3644 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
43e13f50c4
commit
89dae21703
20 changed files with 558 additions and 335 deletions
|
@ -552,15 +552,107 @@ return NULL;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib, MSVCLIBSPATH "libpng64.lib")
|
||||
#else
|
||||
#pragma comment(lib, MSVCLIBSPATH "libpng.lib")
|
||||
#ifdef DYNAMIC_LIBPNG
|
||||
#define PSTATIC(n)
|
||||
static dllhandle_t *libpng_handle;
|
||||
#define LIBPNG_LOADED() (libpng_handle != NULL)
|
||||
#else
|
||||
#define LIBPNG_LOADED() 1
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib, MSVCLIBSPATH "libpng64.lib")
|
||||
#else
|
||||
#pragma comment(lib, MSVCLIBSPATH "libpng.lib")
|
||||
#define PSTATIC(n) = &n
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void (PNGAPI *qpng_error) PNGARG((png_structp png_ptr, png_const_charp error_message)) PNG_NORETURN PSTATIC(png_error);
|
||||
void (PNGAPI *qpng_read_end) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_read_end);
|
||||
void (PNGAPI *qpng_read_image) PNGARG((png_structp png_ptr, png_bytepp image)) PSTATIC(png_read_image);
|
||||
png_byte (PNGAPI *qpng_get_bit_depth) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_get_bit_depth);
|
||||
png_byte (PNGAPI *qpng_get_channels) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_get_channels);
|
||||
png_size_t (PNGAPI *qpng_get_rowbytes) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_get_rowbytes);
|
||||
void (PNGAPI *qpng_read_update_info) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_read_update_info);
|
||||
void (PNGAPI *qpng_set_strip_16) PNGARG((png_structp png_ptr)) PSTATIC(png_set_strip_16);
|
||||
void (PNGAPI *qpng_set_expand) PNGARG((png_structp png_ptr)) PSTATIC(png_set_expand);
|
||||
void (PNGAPI *qpng_set_gray_to_rgb) PNGARG((png_structp png_ptr)) PSTATIC(png_set_gray_to_rgb);
|
||||
void (PNGAPI *qpng_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)) PSTATIC(png_set_tRNS_to_alpha);
|
||||
png_uint_32 (PNGAPI *qpng_get_valid) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)) PSTATIC(png_get_valid);
|
||||
void (PNGAPI *qpng_set_expand_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)) PSTATIC(png_set_expand_gray_1_2_4_to_8);
|
||||
void (PNGAPI *qpng_set_filler) PNGARG((png_structp png_ptr, png_uint_32 filler, int flags)) PSTATIC(png_set_filler);
|
||||
void (PNGAPI *qpng_set_palette_to_rgb) PNGARG((png_structp png_ptr)) PSTATIC(png_set_palette_to_rgb);
|
||||
png_uint_32 (PNGAPI *qpng_get_IHDR) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
|
||||
int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method)) PSTATIC(png_get_IHDR);
|
||||
void (PNGAPI *qpng_read_info) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_read_info);
|
||||
void (PNGAPI *qpng_set_sig_bytes) PNGARG((png_structp png_ptr, int num_bytes)) PSTATIC(png_set_sig_bytes);
|
||||
void (PNGAPI *qpng_set_read_fn) PNGARG((png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn)) PSTATIC(png_set_read_fn);
|
||||
void (PNGAPI *qpng_destroy_read_struct) PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)) PSTATIC(png_destroy_read_struct);
|
||||
png_infop (PNGAPI *qpng_create_info_struct) PNGARG((png_structp png_ptr)) PNG_ALLOCATED PSTATIC(png_create_info_struct);
|
||||
png_structp (PNGAPI *qpng_create_read_struct) PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)) PNG_ALLOCATED PSTATIC(png_create_read_struct);
|
||||
int (PNGAPI *qpng_sig_cmp) PNGARG((png_bytep sig, png_size_t start, png_size_t num_to_check)) PSTATIC(png_sig_cmp);
|
||||
|
||||
void (PNGAPI *qpng_write_end) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_write_end);
|
||||
void (PNGAPI *qpng_write_image) PNGARG((png_structp png_ptr, png_bytepp image)) PSTATIC(png_write_image);
|
||||
void (PNGAPI *qpng_write_info) PNGARG((png_structp png_ptr, png_infop info_ptr)) PSTATIC(png_write_info);
|
||||
void (PNGAPI *qpng_set_IHDR) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height,
|
||||
int bit_depth, int color_type, int interlace_method, int compression_method, int filter_method)) PSTATIC(png_set_IHDR);
|
||||
void (PNGAPI *qpng_set_compression_level) PNGARG((png_structp png_ptr, int level)) PSTATIC(png_set_compression_level);
|
||||
void (PNGAPI *qpng_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp)) PSTATIC(png_init_io);
|
||||
void (PNGAPI *qpng_destroy_write_struct) PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)) PSTATIC(png_destroy_write_struct);
|
||||
png_structp (PNGAPI *qpng_create_write_struct) PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)) PNG_ALLOCATED PSTATIC(png_create_write_struct);
|
||||
|
||||
qboolean LibPNG_Init(void)
|
||||
{
|
||||
#ifdef DYNAMIC_LIBPNG
|
||||
static dllfunction_t pngfuncs[] =
|
||||
{
|
||||
{(void **) &qpng_error, "png_error"},
|
||||
{(void **) &qpng_read_end, "png_read_end"},
|
||||
{(void **) &qpng_read_image, "png_read_image"},
|
||||
{(void **) &qpng_get_bit_depth, "png_get_bit_depth"},
|
||||
{(void **) &qpng_get_channels, "png_get_channels"},
|
||||
{(void **) &qpng_get_rowbytes, "png_get_rowbytes"},
|
||||
{(void **) &qpng_read_update_info, "png_read_update_info"},
|
||||
{(void **) &qpng_set_strip_16, "png_set_strip_16"},
|
||||
{(void **) &qpng_set_expand, "png_set_expand"},
|
||||
{(void **) &qpng_set_gray_to_rgb, "png_set_gray_to_rgb"},
|
||||
{(void **) &qpng_set_tRNS_to_alpha, "png_set_tRNS_to_alpha"},
|
||||
{(void **) &qpng_get_valid, "png_get_valid"},
|
||||
{(void **) &qpng_set_expand_gray_1_2_4_to_8, "png_set_expand_gray_1_2_4_to_8"},
|
||||
{(void **) &qpng_set_filler, "png_set_filler"},
|
||||
{(void **) &qpng_set_palette_to_rgb, "png_set_palette_to_rgb"},
|
||||
{(void **) &qpng_get_IHDR, "png_get_IHDR"},
|
||||
{(void **) &qpng_read_info, "png_read_info"},
|
||||
{(void **) &qpng_set_sig_bytes, "png_set_sig_bytes"},
|
||||
{(void **) &qpng_set_read_fn, "png_set_read_fn"},
|
||||
{(void **) &qpng_destroy_read_struct, "png_destroy_read_struct"},
|
||||
{(void **) &qpng_create_info_struct, "png_create_info_struct"},
|
||||
{(void **) &qpng_create_read_struct, "png_create_read_struct"},
|
||||
{(void **) &qpng_sig_cmp, "png_sig_cmp"},
|
||||
|
||||
{(void **) &qpng_write_end, "png_write_end"},
|
||||
{(void **) &qpng_write_image, "png_write_image"},
|
||||
{(void **) &qpng_write_info, "png_write_info"},
|
||||
{(void **) &qpng_set_IHDR, "png_set_IHDR"},
|
||||
{(void **) &qpng_set_compression_level, "png_set_compression_level"},
|
||||
{(void **) &qpng_init_io, "png_init_io"},
|
||||
{(void **) &qpng_destroy_write_struct, "png_destroy_write_struct"},
|
||||
{(void **) &qpng_create_write_struct, "png_create_write_struct"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
if (!LIBPNG_LOADED())
|
||||
libpng_handle = Sys_LoadLibrary("libpng", pngfuncs);
|
||||
#endif
|
||||
return LIBPNG_LOADED();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(MINGW) //hehehe... add annother symbol so the statically linked cygwin libpng can link
|
||||
#undef setjmp
|
||||
int setjmp (jmp_buf jb)
|
||||
|
@ -582,7 +674,7 @@ void VARGS readpngdata(png_structp png_ptr,png_bytep data,png_size_t len)
|
|||
pngreadinfo_t *ri = (pngreadinfo_t*)png_ptr->io_ptr;
|
||||
if (ri->readposition+len > ri->filelen)
|
||||
{
|
||||
png_error(png_ptr, "unexpected eof");
|
||||
qpng_error(png_ptr, "unexpected eof");
|
||||
return;
|
||||
}
|
||||
memcpy(data, &ri->data[ri->readposition], len);
|
||||
|
@ -602,19 +694,19 @@ qbyte *ReadPNGFile(qbyte *buf, int length, int *width, int *height, const char *
|
|||
|
||||
memcpy(header, buf, 8);
|
||||
|
||||
if (png_sig_cmp(header, 0, 8))
|
||||
if (qpng_sig_cmp(header, 0, 8))
|
||||
{
|
||||
return (png_rgba = NULL);
|
||||
}
|
||||
|
||||
if (!(png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
|
||||
if (!(png = qpng_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
|
||||
{
|
||||
return (png_rgba = NULL);
|
||||
}
|
||||
|
||||
if (!(pnginfo = png_create_info_struct(png)))
|
||||
if (!(pnginfo = qpng_create_info_struct(png)))
|
||||
{
|
||||
png_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
qpng_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
return (png_rgba = NULL);
|
||||
}
|
||||
|
||||
|
@ -625,64 +717,64 @@ error:
|
|||
BZ_Free(data);
|
||||
if (rowpointers)
|
||||
BZ_Free(rowpointers);
|
||||
png_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
qpng_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
return (png_rgba = NULL);
|
||||
}
|
||||
|
||||
ri.data=buf;
|
||||
ri.readposition=8;
|
||||
ri.filelen=length;
|
||||
png_set_read_fn(png, &ri, readpngdata);
|
||||
qpng_set_read_fn(png, &ri, readpngdata);
|
||||
|
||||
png_set_sig_bytes(png, 8);
|
||||
png_read_info(png, pnginfo);
|
||||
png_get_IHDR(png, pnginfo, &pngwidth, &pngheight, &bitdepth, &colortype, &interlace, &compression, &filter);
|
||||
qpng_set_sig_bytes(png, 8);
|
||||
qpng_read_info(png, pnginfo);
|
||||
qpng_get_IHDR(png, pnginfo, &pngwidth, &pngheight, &bitdepth, &colortype, &interlace, &compression, &filter);
|
||||
|
||||
*width = pngwidth;
|
||||
*height = pngheight;
|
||||
|
||||
if (colortype == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
png_set_palette_to_rgb(png);
|
||||
png_set_filler(png, 255, PNG_FILLER_AFTER);
|
||||
qpng_set_palette_to_rgb(png);
|
||||
qpng_set_filler(png, 255, PNG_FILLER_AFTER);
|
||||
}
|
||||
|
||||
if (colortype == PNG_COLOR_TYPE_GRAY && bitdepth < 8)
|
||||
{
|
||||
#if PNG_LIBPNG_VER > 10400
|
||||
png_set_expand_gray_1_2_4_to_8(png);
|
||||
qpng_set_expand_gray_1_2_4_to_8(png);
|
||||
#else
|
||||
png_set_gray_1_2_4_to_8(png);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (png_get_valid( png, pnginfo, PNG_INFO_tRNS))
|
||||
png_set_tRNS_to_alpha(png);
|
||||
if (qpng_get_valid( png, pnginfo, PNG_INFO_tRNS))
|
||||
qpng_set_tRNS_to_alpha(png);
|
||||
|
||||
if (bitdepth >= 8 && colortype == PNG_COLOR_TYPE_RGB)
|
||||
png_set_filler(png, 255, PNG_FILLER_AFTER);
|
||||
qpng_set_filler(png, 255, PNG_FILLER_AFTER);
|
||||
|
||||
if (colortype == PNG_COLOR_TYPE_GRAY || colortype == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
png_set_gray_to_rgb( png );
|
||||
png_set_filler(png, 255, PNG_FILLER_AFTER);
|
||||
qpng_set_gray_to_rgb( png );
|
||||
qpng_set_filler(png, 255, PNG_FILLER_AFTER);
|
||||
}
|
||||
|
||||
if (bitdepth < 8)
|
||||
png_set_expand (png);
|
||||
qpng_set_expand (png);
|
||||
else if (bitdepth == 16)
|
||||
png_set_strip_16(png);
|
||||
qpng_set_strip_16(png);
|
||||
|
||||
|
||||
png_read_update_info(png, pnginfo);
|
||||
rowbytes = png_get_rowbytes(png, pnginfo);
|
||||
bytesperpixel = png_get_channels(png, pnginfo);
|
||||
bitdepth = png_get_bit_depth(png, pnginfo);
|
||||
qpng_read_update_info(png, pnginfo);
|
||||
rowbytes = qpng_get_rowbytes(png, pnginfo);
|
||||
bytesperpixel = qpng_get_channels(png, pnginfo);
|
||||
bitdepth = qpng_get_bit_depth(png, pnginfo);
|
||||
|
||||
if (bitdepth != 8 || bytesperpixel != 4)
|
||||
{
|
||||
Con_Printf ("Bad PNG color depth and/or bpp (%s)\n", fname);
|
||||
png_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
qpng_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
return (png_rgba = NULL);
|
||||
}
|
||||
|
||||
|
@ -695,10 +787,10 @@ error:
|
|||
for (y = 0; y < *height; y++)
|
||||
rowpointers[y] = data + y * rowbytes;
|
||||
|
||||
png_read_image(png, rowpointers);
|
||||
png_read_end(png, NULL);
|
||||
qpng_read_image(png, rowpointers);
|
||||
qpng_read_end(png, NULL);
|
||||
|
||||
png_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
qpng_destroy_read_struct(&png, &pnginfo, NULL);
|
||||
BZ_Free(rowpointers);
|
||||
return (png_rgba = data);
|
||||
}
|
||||
|
@ -725,40 +817,40 @@ int Image_WritePNG (char *filename, int compression, qbyte *pixels, int width, i
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
|
||||
if (!(png_ptr = qpng_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
|
||||
{
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(info_ptr = png_create_info_struct(png_ptr)))
|
||||
if (!(info_ptr = qpng_create_info_struct(png_ptr)))
|
||||
{
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
qpng_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
qpng_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
qpng_init_io(png_ptr, fp);
|
||||
compression = bound(0, compression, 100);
|
||||
png_set_compression_level(png_ptr, Z_NO_COMPRESSION + (compression*(Z_BEST_COMPRESSION-Z_NO_COMPRESSION))/100);
|
||||
qpng_set_compression_level(png_ptr, Z_NO_COMPRESSION + (compression*(Z_BEST_COMPRESSION-Z_NO_COMPRESSION))/100);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
qpng_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
qpng_write_info(png_ptr, info_ptr);
|
||||
|
||||
row_pointers = BZ_Malloc (sizeof(png_byte *) * height);
|
||||
for (i = 0; i < height; i++)
|
||||
row_pointers[height - i - 1] = pixels + i * width * 3;
|
||||
png_write_image(png_ptr, row_pointers);
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
qpng_write_image(png_ptr, row_pointers);
|
||||
qpng_write_end(png_ptr, info_ptr);
|
||||
BZ_Free(row_pointers);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
qpng_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
@ -783,21 +875,85 @@ int Image_WritePNG (char *filename, int compression, qbyte *pixels, int width, i
|
|||
#include <jerror.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib, MSVCLIBSPATH "libjpeg64.lib")
|
||||
#else
|
||||
#pragma comment(lib, MSVCLIBSPATH "jpeg.lib")
|
||||
#ifdef DYNAMIC_LIBJPEG
|
||||
#define JSTATIC(n)
|
||||
static dllhandle_t *libjpeg_handle;
|
||||
#define LIBJPEG_LOADED() (libjpeg_handle != NULL)
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib, MSVCLIBSPATH "libjpeg64.lib")
|
||||
#else
|
||||
#pragma comment(lib, MSVCLIBSPATH "jpeg.lib")
|
||||
#endif
|
||||
#endif
|
||||
#define JSTATIC(n) = &n
|
||||
#define LIBJPEG_LOADED() (1)
|
||||
#endif
|
||||
|
||||
#define qjpeg_create_compress(cinfo) \
|
||||
qjpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
|
||||
(size_t) sizeof(struct jpeg_compress_struct))
|
||||
#define qjpeg_create_decompress(cinfo) \
|
||||
qjpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
|
||||
(size_t) sizeof(struct jpeg_decompress_struct))
|
||||
|
||||
boolean (VARGS *qjpeg_resync_to_restart) JPP((j_decompress_ptr cinfo, int desired)) JSTATIC(jpeg_resync_to_restart);
|
||||
boolean (VARGS *qjpeg_finish_decompress) JPP((j_decompress_ptr cinfo)) JSTATIC(jpeg_finish_decompress);
|
||||
JDIMENSION (VARGS *qjpeg_read_scanlines) JPP((j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)) JSTATIC(jpeg_read_scanlines);
|
||||
boolean (VARGS *qjpeg_start_decompress) JPP((j_decompress_ptr cinfo)) JSTATIC(jpeg_start_decompress);
|
||||
int (VARGS *qjpeg_read_header) JPP((j_decompress_ptr cinfo, boolean require_image)) JSTATIC(jpeg_read_header);
|
||||
void (VARGS *qjpeg_CreateDecompress) JPP((j_decompress_ptr cinfo, int version, size_t structsize)) JSTATIC(jpeg_CreateDecompress);
|
||||
void (VARGS *qjpeg_destroy_decompress) JPP((j_decompress_ptr cinfo)) JSTATIC(jpeg_destroy_decompress);
|
||||
|
||||
struct jpeg_error_mgr * (VARGS *qjpeg_std_error) JPP((struct jpeg_error_mgr * err)) JSTATIC(jpeg_std_error);
|
||||
|
||||
void (VARGS *qjpeg_finish_compress) JPP((j_compress_ptr cinfo)) JSTATIC(jpeg_finish_compress);
|
||||
JDIMENSION (VARGS *qjpeg_write_scanlines) JPP((j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)) JSTATIC(jpeg_write_scanlines);
|
||||
void (VARGS *qjpeg_start_compress) JPP((j_compress_ptr cinfo, boolean write_all_tables)) JSTATIC(jpeg_start_compress);
|
||||
void (VARGS *qjpeg_set_quality) JPP((j_compress_ptr cinfo, int quality, boolean force_baseline)) JSTATIC(jpeg_set_quality);
|
||||
void (VARGS *qjpeg_set_defaults) JPP((j_compress_ptr cinfo)) JSTATIC(jpeg_set_defaults);
|
||||
void (VARGS *qjpeg_CreateCompress) JPP((j_compress_ptr cinfo, int version, size_t structsize)) JSTATIC(jpeg_CreateCompress);
|
||||
void (VARGS *qjpeg_destroy_compress) JPP((j_compress_ptr cinfo)) JSTATIC(jpeg_destroy_compress);
|
||||
|
||||
qboolean LibJPEG_Init(void)
|
||||
{
|
||||
#ifdef DYNAMIC_LIBJPEG
|
||||
static dllfunction_t jpegfuncs[] =
|
||||
{
|
||||
{(void **) &qjpeg_resync_to_restart, "jpeg_resync_to_restart"},
|
||||
{(void **) &qjpeg_finish_decompress, "jpeg_finish_decompress"},
|
||||
{(void **) &qjpeg_read_scanlines, "jpeg_read_scanlines"},
|
||||
{(void **) &qjpeg_start_decompress, "jpeg_start_decompress"},
|
||||
{(void **) &qjpeg_read_header, "jpeg_read_header"},
|
||||
{(void **) &qjpeg_CreateDecompress, "jpeg_CreateDecompress"},
|
||||
{(void **) &qjpeg_destroy_decompress, "jpeg_destroy_decompress"},
|
||||
|
||||
{(void **) &qjpeg_std_error, "jpeg_std_error"},
|
||||
|
||||
{(void **) &qjpeg_finish_compress, "jpeg_finish_compress"},
|
||||
{(void **) &qjpeg_write_scanlines, "jpeg_write_scanlines"},
|
||||
{(void **) &qjpeg_start_compress, "jpeg_start_compress"},
|
||||
{(void **) &qjpeg_set_quality, "jpeg_set_quality"},
|
||||
{(void **) &qjpeg_set_defaults, "jpeg_set_defaults"},
|
||||
{(void **) &qjpeg_CreateCompress, "jpeg_CreateCompress"},
|
||||
{(void **) &qjpeg_destroy_compress, "jpeg_destroy_compress"},
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
if (!LIBJPEG_LOADED())
|
||||
libjpeg_handle = Sys_LoadLibrary("libjpeg", jpegfuncs);
|
||||
#endif
|
||||
|
||||
return LIBJPEG_LOADED();
|
||||
}
|
||||
|
||||
#ifndef JPEG_FALSE
|
||||
#define JPEG_boolean boolean
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*begin jpeg read*/
|
||||
|
||||
struct my_error_mgr {
|
||||
struct jpeg_error_mgr pub; /* "public" fields */
|
||||
|
@ -934,7 +1090,7 @@ ftejpeg_mem_src (j_decompress_ptr cinfo, qbyte * infile, int maxlen)
|
|||
src->pub.init_source = init_source;
|
||||
src->pub.fill_input_buffer = fill_input_buffer;
|
||||
src->pub.skip_input_data = skip_input_data;
|
||||
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||
src->pub.resync_to_restart = qjpeg_resync_to_restart; /* use default method */
|
||||
src->pub.term_source = term_source;
|
||||
src->infile = infile;
|
||||
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
|
@ -949,98 +1105,99 @@ qbyte *ReadJPEGFile(qbyte *infile, int length, int *width, int *height)
|
|||
qbyte *mem=NULL, *in, *out;
|
||||
int i;
|
||||
|
||||
/* This struct contains the JPEG decompression parameters and pointers to
|
||||
* working space (which is allocated as needed by the JPEG library).
|
||||
*/
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
/* We use our private extension JPEG error handler.
|
||||
* Note that this struct must live as long as the main JPEG parameter
|
||||
* struct, to avoid dangling-pointer problems.
|
||||
*/
|
||||
struct my_error_mgr jerr;
|
||||
/* More stuff */
|
||||
JSAMPARRAY buffer; /* Output row buffer */
|
||||
int size_stride; /* physical row width in output buffer */
|
||||
/* This struct contains the JPEG decompression parameters and pointers to
|
||||
* working space (which is allocated as needed by the JPEG library).
|
||||
*/
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
/* We use our private extension JPEG error handler.
|
||||
* Note that this struct must live as long as the main JPEG parameter
|
||||
* struct, to avoid dangling-pointer problems.
|
||||
*/
|
||||
struct my_error_mgr jerr;
|
||||
/* More stuff */
|
||||
JSAMPARRAY buffer; /* Output row buffer */
|
||||
int size_stride; /* physical row width in output buffer */
|
||||
|
||||
if (!LIBJPEG_LOADED())
|
||||
return NULL;
|
||||
|
||||
/* Step 1: allocate and initialize JPEG decompression object */
|
||||
|
||||
/* We set up the normal JPEG error routines, then override error_exit. */
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
/* Establish the setjmp return context for my_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer)) {
|
||||
// If we get here, the JPEG code has signaled an error.
|
||||
/* Step 1: allocate and initialize JPEG decompression object */
|
||||
|
||||
/* We set up the normal JPEG error routines, then override error_exit. */
|
||||
cinfo.err = qjpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
/* Establish the setjmp return context for my_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
// If we get here, the JPEG code has signaled an error.
|
||||
badjpeg:
|
||||
qjpeg_destroy_decompress(&cinfo);
|
||||
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
if (mem)
|
||||
BZ_Free(mem);
|
||||
return 0;
|
||||
}
|
||||
qjpeg_create_decompress(&cinfo);
|
||||
|
||||
if (mem)
|
||||
BZ_Free(mem);
|
||||
return 0;
|
||||
}
|
||||
jpeg_create_decompress(&cinfo);
|
||||
ftejpeg_mem_src(&cinfo, infile, length);
|
||||
|
||||
ftejpeg_mem_src(&cinfo, infile, length);
|
||||
(void) qjpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
(void) jpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
(void) jpeg_start_decompress(&cinfo);
|
||||
(void) qjpeg_start_decompress(&cinfo);
|
||||
|
||||
|
||||
if (cinfo.output_components == 0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
Con_Printf("No JPEG Components, not a JPEG.\n");
|
||||
#endif
|
||||
goto badjpeg;
|
||||
}
|
||||
if (cinfo.output_components!=3)
|
||||
{
|
||||
if (cinfo.output_components == 0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
Con_Printf("No JPEG Components, not a JPEG.\n");
|
||||
#endif
|
||||
goto badjpeg;
|
||||
}
|
||||
if (cinfo.output_components!=3)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
Con_Printf("Bad number of components in JPEG: '%d', should be '3'.\n",cinfo.output_components);
|
||||
#endif
|
||||
goto badjpeg;
|
||||
}
|
||||
size_stride = cinfo.output_width * cinfo.output_components;
|
||||
/* Make a one-row-high sample array that will go away when done with image */
|
||||
buffer = (*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr) &cinfo, JPOOL_IMAGE, size_stride, 1);
|
||||
|
||||
out=mem=BZ_Malloc(cinfo.output_height*cinfo.output_width*4);
|
||||
memset(out, 0, cinfo.output_height*cinfo.output_width*4);
|
||||
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
|
||||
|
||||
in = buffer[0];
|
||||
for (i = 0; i < cinfo.output_width; i++)
|
||||
{//rgb to rgba
|
||||
*out++ = *in++;
|
||||
*out++ = *in++;
|
||||
*out++ = *in++;
|
||||
*out++ = 255;
|
||||
}
|
||||
}
|
||||
size_stride = cinfo.output_width * cinfo.output_components;
|
||||
/* Make a one-row-high sample array that will go away when done with image */
|
||||
buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, size_stride, 1);
|
||||
|
||||
(void) jpeg_finish_decompress(&cinfo);
|
||||
out=mem=BZ_Malloc(cinfo.output_height*cinfo.output_width*4);
|
||||
memset(out, 0, cinfo.output_height*cinfo.output_width*4);
|
||||
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
while (cinfo.output_scanline < cinfo.output_height)
|
||||
{
|
||||
(void) qjpeg_read_scanlines(&cinfo, buffer, 1);
|
||||
|
||||
*width = cinfo.output_width;
|
||||
*height = cinfo.output_height;
|
||||
in = buffer[0];
|
||||
for (i = 0; i < cinfo.output_width; i++)
|
||||
{//rgb to rgba
|
||||
*out++ = *in++;
|
||||
*out++ = *in++;
|
||||
*out++ = *in++;
|
||||
*out++ = 255;
|
||||
}
|
||||
}
|
||||
|
||||
return mem;
|
||||
(void) qjpeg_finish_decompress(&cinfo);
|
||||
|
||||
qjpeg_destroy_decompress(&cinfo);
|
||||
|
||||
*width = cinfo.output_width;
|
||||
*height = cinfo.output_height;
|
||||
|
||||
return mem;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*end read*/
|
||||
/*begin write*/
|
||||
#define OUTPUT_BUF_SIZE 4096
|
||||
typedef struct {
|
||||
struct jpeg_error_mgr pub;
|
||||
struct jpeg_error_mgr pub;
|
||||
|
||||
jmp_buf setjmp_buffer;
|
||||
jmp_buf setjmp_buffer;
|
||||
} jpeg_error_mgr_wrapper;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1080,30 +1237,32 @@ METHODDEF(void) term_destination (j_compress_ptr cinfo)
|
|||
|
||||
void ftejpeg_mem_dest (j_compress_ptr cinfo, vfsfile_t *vfs)
|
||||
{
|
||||
my_destination_mgr *dest;
|
||||
my_destination_mgr *dest;
|
||||
|
||||
if (cinfo->dest == NULL)
|
||||
{ /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(my_destination_mgr));
|
||||
dest = (my_destination_mgr*) cinfo->dest;
|
||||
// dest->buffer = (JOCTET *)
|
||||
// (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
// OUTPUT_BUF_SIZE * sizeof(JOCTET));
|
||||
}
|
||||
|
||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(my_destination_mgr));
|
||||
dest = (my_destination_mgr*) cinfo->dest;
|
||||
// dest->buffer = (JOCTET *)
|
||||
// (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
// OUTPUT_BUF_SIZE * sizeof(JOCTET));
|
||||
}
|
||||
|
||||
dest = (my_destination_mgr*) cinfo->dest;
|
||||
dest->pub.init_destination = init_destination;
|
||||
dest->pub.empty_output_buffer = empty_output_buffer;
|
||||
dest->pub.term_destination = term_destination;
|
||||
dest->pub.free_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
dest->pub.next_output_byte = NULL; /* until buffer loaded */
|
||||
dest->vfs = vfs;
|
||||
dest->pub.init_destination = init_destination;
|
||||
dest->pub.empty_output_buffer = empty_output_buffer;
|
||||
dest->pub.term_destination = term_destination;
|
||||
dest->pub.free_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
dest->pub.next_output_byte = NULL; /* until buffer loaded */
|
||||
dest->vfs = vfs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
METHODDEF(void) jpeg_error_exit (j_common_ptr cinfo) {
|
||||
METHODDEF(void) jpeg_error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
longjmp(((jpeg_error_mgr_wrapper *) cinfo->err)->setjmp_buffer, 1);
|
||||
}
|
||||
void screenshotJPEG(char *filename, int compression, qbyte *screendata, int screenwidth, int screenheight) //input is rgb NOT rgba
|
||||
|
@ -1114,6 +1273,9 @@ void screenshotJPEG(char *filename, int compression, qbyte *screendata, int scre
|
|||
struct jpeg_compress_struct cinfo;
|
||||
JSAMPROW row_pointer[1];
|
||||
|
||||
if (!LIBJPEG_LOADED())
|
||||
return;
|
||||
|
||||
if (!(outfile = FS_OpenVFS(filename, "wb", FS_GAMEONLY)))
|
||||
{
|
||||
FS_CreatePath (filename, FS_GAME);
|
||||
|
@ -1124,17 +1286,17 @@ void screenshotJPEG(char *filename, int compression, qbyte *screendata, int scre
|
|||
}
|
||||
}
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
cinfo.err = qjpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = jpeg_error_exit;
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
qjpeg_destroy_compress(&cinfo);
|
||||
VFS_CLOSE(outfile);
|
||||
FS_Remove(filename, FS_GAME);
|
||||
Con_Printf("Failed to create jpeg\n");
|
||||
return;
|
||||
}
|
||||
jpeg_create_compress(&cinfo);
|
||||
qjpeg_create_compress(&cinfo);
|
||||
|
||||
buffer = screendata;
|
||||
|
||||
|
@ -1143,21 +1305,20 @@ void screenshotJPEG(char *filename, int compression, qbyte *screendata, int scre
|
|||
cinfo.image_height = screenheight;
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality (&cinfo, bound(0, compression, 100), true);
|
||||
jpeg_start_compress(&cinfo, true);
|
||||
qjpeg_set_defaults(&cinfo);
|
||||
qjpeg_set_quality (&cinfo, bound(0, compression, 100), true);
|
||||
qjpeg_start_compress(&cinfo, true);
|
||||
|
||||
while (cinfo.next_scanline < cinfo.image_height)
|
||||
{
|
||||
*row_pointer = &buffer[(cinfo.image_height - cinfo.next_scanline - 1) * cinfo.image_width * 3];
|
||||
jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
qjpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
}
|
||||
|
||||
jpeg_finish_compress(&cinfo);
|
||||
qjpeg_finish_compress(&cinfo);
|
||||
VFS_CLOSE(outfile);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
qjpeg_destroy_compress(&cinfo);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -495,6 +495,9 @@ void R_SetRenderer_f (void);
|
|||
|
||||
void Renderer_Init(void)
|
||||
{
|
||||
LibJPEG_Init();
|
||||
LibPNG_Init();
|
||||
|
||||
currentrendererstate.renderer = NULL;
|
||||
qrenderer = QR_NONE;
|
||||
|
||||
|
|
|
@ -59,7 +59,15 @@ dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs)
|
|||
|
||||
lib = LoadLibrary(name);
|
||||
if (!lib)
|
||||
return NULL;
|
||||
{
|
||||
#ifdef _WIN64
|
||||
lib = LoadLibrary(va("%s_64", name));
|
||||
#elif defined(_WIN32)
|
||||
lib = LoadLibrary(va("%s_32", name));
|
||||
#endif
|
||||
if (!lib)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (funcs)
|
||||
{
|
||||
|
|
|
@ -72,6 +72,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define AVAIL_D3D
|
||||
#endif
|
||||
|
||||
//#define DYNAMIC_ZLIB
|
||||
//#define DYNAMIC_LIBPNG
|
||||
//#define DYNAMIC_LIBJPEG
|
||||
|
||||
#ifdef _WIN32
|
||||
//needs testing on other platforms
|
||||
#define AVAIL_FREETYPE
|
||||
|
|
|
@ -13,14 +13,6 @@
|
|||
#include "./mingw-libs/SDL_syswm.h" // mingw sdl cross binary complains off sys_parentwindow
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# ifdef _WIN64
|
||||
# pragma comment (lib, "../libs/zlib64.lib")
|
||||
# else
|
||||
# pragma comment (lib, "../libs/zlib.lib")
|
||||
# endif
|
||||
#endif
|
||||
|
||||
hashtable_t filesystemhash;
|
||||
qboolean com_fschanged = true;
|
||||
static unsigned int fs_restarts;
|
||||
|
@ -761,158 +753,6 @@ static const char *FS_GetCleanPath(const char *pattern, char *outbuf, int outlen
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef AVAIL_ZLIB
|
||||
typedef struct {
|
||||
unsigned char ident1;
|
||||
unsigned char ident2;
|
||||
unsigned char cm;
|
||||
unsigned char flags;
|
||||
unsigned int mtime;
|
||||
unsigned char xflags;
|
||||
unsigned char os;
|
||||
} gzheader_t;
|
||||
#define sizeofgzheader_t 10
|
||||
|
||||
#define GZ_FTEXT 1
|
||||
#define GZ_FHCRC 2
|
||||
#define GZ_FEXTRA 4
|
||||
#define GZ_FNAME 8
|
||||
#define GZ_FCOMMENT 16
|
||||
#define GZ_RESERVED (32|64|128)
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
vfsfile_t *FS_DecompressGZip(vfsfile_t *infile, gzheader_t *header)
|
||||
{
|
||||
char inchar;
|
||||
unsigned short inshort;
|
||||
vfsfile_t *temp;
|
||||
|
||||
if (header->flags & GZ_RESERVED)
|
||||
{ //reserved bits should be 0
|
||||
//this is probably static, so it's not a gz. doh.
|
||||
VFS_SEEK(infile, 0);
|
||||
return infile;
|
||||
}
|
||||
|
||||
if (header->flags & GZ_FEXTRA)
|
||||
{
|
||||
VFS_READ(infile, &inshort, sizeof(inshort));
|
||||
inshort = LittleShort(inshort);
|
||||
VFS_SEEK(infile, VFS_TELL(infile) + inshort);
|
||||
}
|
||||
|
||||
if (header->flags & GZ_FNAME)
|
||||
{
|
||||
Con_Printf("gzipped file name: ");
|
||||
do {
|
||||
if (VFS_READ(infile, &inchar, sizeof(inchar)) != 1)
|
||||
break;
|
||||
Con_Printf("%c", inchar);
|
||||
} while(inchar);
|
||||
Con_Printf("\n");
|
||||
}
|
||||
|
||||
if (header->flags & GZ_FCOMMENT)
|
||||
{
|
||||
Con_Printf("gzipped file comment: ");
|
||||
do {
|
||||
if (VFS_READ(infile, &inchar, sizeof(inchar)) != 1)
|
||||
break;
|
||||
Con_Printf("%c", inchar);
|
||||
} while(inchar);
|
||||
Con_Printf("\n");
|
||||
}
|
||||
|
||||
if (header->flags & GZ_FHCRC)
|
||||
{
|
||||
VFS_READ(infile, &inshort, sizeof(inshort));
|
||||
}
|
||||
|
||||
|
||||
|
||||
temp = FS_OpenTemp();
|
||||
if (!temp)
|
||||
{
|
||||
VFS_SEEK(infile, 0); //doh
|
||||
return infile;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
unsigned char inbuffer[16384];
|
||||
unsigned char outbuffer[16384];
|
||||
int ret;
|
||||
|
||||
z_stream strm = {
|
||||
inbuffer,
|
||||
0,
|
||||
0,
|
||||
|
||||
outbuffer,
|
||||
sizeof(outbuffer),
|
||||
0,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
Z_UNKNOWN,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
strm.avail_in = VFS_READ(infile, inbuffer, sizeof(inbuffer));
|
||||
strm.next_in = inbuffer;
|
||||
|
||||
inflateInit2(&strm, -MAX_WBITS);
|
||||
|
||||
while ((ret=inflate(&strm, Z_SYNC_FLUSH)) != Z_STREAM_END)
|
||||
{
|
||||
if (strm.avail_in == 0 || strm.avail_out == 0)
|
||||
{
|
||||
if (strm.avail_in == 0)
|
||||
{
|
||||
strm.avail_in = VFS_READ(infile, inbuffer, sizeof(inbuffer));
|
||||
strm.next_in = inbuffer;
|
||||
}
|
||||
|
||||
if (strm.avail_out == 0)
|
||||
{
|
||||
strm.next_out = outbuffer;
|
||||
VFS_WRITE(temp, outbuffer, strm.total_out);
|
||||
strm.total_out = 0;
|
||||
strm.avail_out = sizeof(outbuffer);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//doh, it terminated for no reason
|
||||
inflateEnd(&strm);
|
||||
if (ret != Z_STREAM_END)
|
||||
{
|
||||
Con_Printf("Couldn't decompress gz file\n");
|
||||
VFS_CLOSE(temp);
|
||||
VFS_CLOSE(infile);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
//we got to the end
|
||||
VFS_WRITE(temp, outbuffer, strm.total_out);
|
||||
|
||||
inflateEnd(&strm);
|
||||
|
||||
VFS_SEEK(temp, 0);
|
||||
}
|
||||
VFS_CLOSE(infile);
|
||||
|
||||
return temp;
|
||||
}
|
||||
#endif
|
||||
|
||||
vfsfile_t *VFS_Filter(const char *filename, vfsfile_t *handle)
|
||||
{
|
||||
// char *ext;
|
||||
|
@ -923,15 +763,7 @@ vfsfile_t *VFS_Filter(const char *filename, vfsfile_t *handle)
|
|||
#ifdef AVAIL_ZLIB
|
||||
// if (!stricmp(ext, ".gz"))
|
||||
{
|
||||
gzheader_t gzh;
|
||||
if (VFS_READ(handle, &gzh, sizeofgzheader_t) == sizeofgzheader_t)
|
||||
{
|
||||
if (gzh.ident1 == 0x1f && gzh.ident2 == 0x8b && gzh.cm == 8)
|
||||
{ //it'll do
|
||||
return FS_DecompressGZip(handle, &gzh);
|
||||
}
|
||||
}
|
||||
VFS_SEEK(handle, 0);
|
||||
return FS_DecompressGZip(handle);
|
||||
}
|
||||
#endif
|
||||
return handle;
|
||||
|
@ -2309,6 +2141,8 @@ void FS_StartupWithGame(int gamenum)
|
|||
{
|
||||
int i;
|
||||
|
||||
LibZ_Init();
|
||||
|
||||
Cvar_Set(&com_gamename, gamemode_info[gamenum].protocolname);
|
||||
|
||||
//
|
||||
|
|
|
@ -25,6 +25,7 @@ typedef struct {
|
|||
//warning: the handle is known to be a string pointer to the dir name
|
||||
extern searchpathfuncs_t osfilefuncs;
|
||||
vfsfile_t *VFSOS_Open(const char *osname, const char *mode);
|
||||
vfsfile_t *FS_DecompressGZip(vfsfile_t *infile);
|
||||
|
||||
int FS_RegisterFileSystemType(const char *extension, searchpathfuncs_t *funcs);
|
||||
void FS_UnRegisterFileSystemType(int idx);
|
||||
|
|
|
@ -2,8 +2,202 @@
|
|||
#include "fs.h"
|
||||
|
||||
#ifdef AVAIL_ZLIB
|
||||
|
||||
#define ZEXPORT VARGS
|
||||
#include <zlib.h>
|
||||
|
||||
typedef struct {
|
||||
unsigned char ident1;
|
||||
unsigned char ident2;
|
||||
unsigned char cm;
|
||||
unsigned char flags;
|
||||
unsigned int mtime;
|
||||
unsigned char xflags;
|
||||
unsigned char os;
|
||||
} gzheader_t;
|
||||
#define sizeofgzheader_t 10
|
||||
|
||||
#define GZ_FTEXT 1
|
||||
#define GZ_FHCRC 2
|
||||
#define GZ_FEXTRA 4
|
||||
#define GZ_FNAME 8
|
||||
#define GZ_FCOMMENT 16
|
||||
#define GZ_RESERVED (32|64|128)
|
||||
|
||||
#ifdef DYNAMIC_ZLIB
|
||||
#define ZLIB_LOADED() (zlib_handle!=NULL)
|
||||
void *zlib_handle;
|
||||
#define ZSTATIC(n)
|
||||
#else
|
||||
#define ZLIB_LOADED() 1
|
||||
#define ZSTATIC(n) = &n
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# ifdef _WIN64
|
||||
# pragma comment (lib, "../libs/zlib64.lib")
|
||||
# else
|
||||
# pragma comment (lib, "../libs/zlib.lib")
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int (ZEXPORT *qinflateEnd) OF((z_streamp strm)) ZSTATIC(inflateEnd);
|
||||
static int (ZEXPORT *qinflate) OF((z_streamp strm, int flush)) ZSTATIC(inflate);
|
||||
static int (ZEXPORT *qinflateInit2_) OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size)) ZSTATIC(inflateInit2_);
|
||||
static uLong (ZEXPORT *qcrc32) OF((uLong crc, const Bytef *buf, uInt len)) ZSTATIC(crc32);
|
||||
|
||||
#define qinflateInit2(strm, windowBits) \
|
||||
qinflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
qboolean LibZ_Init(void)
|
||||
{
|
||||
#ifdef DYNAMIC_ZLIB
|
||||
static dllfunction_t funcs[] =
|
||||
{
|
||||
{(void*)&qinflateEnd, "inflateEnd"},
|
||||
{(void*)&qinflate, "inflate"},
|
||||
{(void*)&qinflateInit2_, "inflateInit2_"},
|
||||
{(void*)&qcrc32, "crc32"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
if (!ZLIB_LOADED())
|
||||
zlib_handle = Sys_LoadLibrary("zlib1", funcs);
|
||||
#endif
|
||||
return ZLIB_LOADED();
|
||||
}
|
||||
|
||||
vfsfile_t *FS_DecompressGZip(vfsfile_t *infile)
|
||||
{
|
||||
char inchar;
|
||||
unsigned short inshort;
|
||||
vfsfile_t *temp;
|
||||
gzheader_t header;
|
||||
|
||||
if (VFS_READ(infile, &header, sizeofgzheader_t) == sizeofgzheader_t)
|
||||
{
|
||||
if (header.ident1 != 0x1f || header.ident2 != 0x8b || header.cm != 8 || header.flags & GZ_RESERVED)
|
||||
{
|
||||
VFS_SEEK(infile, 0);
|
||||
return infile;
|
||||
}
|
||||
}
|
||||
if (header.flags & GZ_FEXTRA)
|
||||
{
|
||||
VFS_READ(infile, &inshort, sizeof(inshort));
|
||||
inshort = LittleShort(inshort);
|
||||
VFS_SEEK(infile, VFS_TELL(infile) + inshort);
|
||||
}
|
||||
|
||||
if (header.flags & GZ_FNAME)
|
||||
{
|
||||
Con_Printf("gzipped file name: ");
|
||||
do {
|
||||
if (VFS_READ(infile, &inchar, sizeof(inchar)) != 1)
|
||||
break;
|
||||
Con_Printf("%c", inchar);
|
||||
} while(inchar);
|
||||
Con_Printf("\n");
|
||||
}
|
||||
|
||||
if (header.flags & GZ_FCOMMENT)
|
||||
{
|
||||
Con_Printf("gzipped file comment: ");
|
||||
do {
|
||||
if (VFS_READ(infile, &inchar, sizeof(inchar)) != 1)
|
||||
break;
|
||||
Con_Printf("%c", inchar);
|
||||
} while(inchar);
|
||||
Con_Printf("\n");
|
||||
}
|
||||
|
||||
if (header.flags & GZ_FHCRC)
|
||||
{
|
||||
VFS_READ(infile, &inshort, sizeof(inshort));
|
||||
}
|
||||
|
||||
|
||||
|
||||
temp = FS_OpenTemp();
|
||||
if (!temp)
|
||||
{
|
||||
VFS_SEEK(infile, 0); //doh
|
||||
return infile;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
unsigned char inbuffer[16384];
|
||||
unsigned char outbuffer[16384];
|
||||
int ret;
|
||||
|
||||
z_stream strm = {
|
||||
inbuffer,
|
||||
0,
|
||||
0,
|
||||
|
||||
outbuffer,
|
||||
sizeof(outbuffer),
|
||||
0,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
Z_UNKNOWN,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
strm.avail_in = VFS_READ(infile, inbuffer, sizeof(inbuffer));
|
||||
strm.next_in = inbuffer;
|
||||
|
||||
qinflateInit2(&strm, -MAX_WBITS);
|
||||
|
||||
while ((ret=qinflate(&strm, Z_SYNC_FLUSH)) != Z_STREAM_END)
|
||||
{
|
||||
if (strm.avail_in == 0 || strm.avail_out == 0)
|
||||
{
|
||||
if (strm.avail_in == 0)
|
||||
{
|
||||
strm.avail_in = VFS_READ(infile, inbuffer, sizeof(inbuffer));
|
||||
strm.next_in = inbuffer;
|
||||
}
|
||||
|
||||
if (strm.avail_out == 0)
|
||||
{
|
||||
strm.next_out = outbuffer;
|
||||
VFS_WRITE(temp, outbuffer, strm.total_out);
|
||||
strm.total_out = 0;
|
||||
strm.avail_out = sizeof(outbuffer);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//doh, it terminated for no reason
|
||||
qinflateEnd(&strm);
|
||||
if (ret != Z_STREAM_END)
|
||||
{
|
||||
Con_Printf("Couldn't decompress gz file\n");
|
||||
VFS_CLOSE(temp);
|
||||
VFS_CLOSE(infile);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
//we got to the end
|
||||
VFS_WRITE(temp, outbuffer, strm.total_out);
|
||||
|
||||
qinflateEnd(&strm);
|
||||
|
||||
VFS_SEEK(temp, 0);
|
||||
}
|
||||
VFS_CLOSE(infile);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
#include "unzip.c"
|
||||
|
||||
typedef struct
|
||||
|
@ -435,6 +629,11 @@ vfsfile_t *FSZIP_OpenVFS(void *handle, flocation_t *loc, const char *mode)
|
|||
VFS_SEEK(zip->raw, vfsz->startpos);
|
||||
vfsz->parent->currentfile = (vfsfile_t*)vfsz;
|
||||
}
|
||||
else if (!ZLIB_LOADED())
|
||||
{
|
||||
Z_Free(vfsz);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zip->references++;
|
||||
|
||||
|
|
|
@ -56,6 +56,10 @@ void Sys_CloseLibrary(dllhandle_t *lib);
|
|||
void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname);
|
||||
char *Sys_GetNameForAddress(dllhandle_t *module, void *address);
|
||||
|
||||
qboolean LibZ_Init(void);
|
||||
qboolean LibJPEG_Init(void);
|
||||
qboolean LibPNG_Init(void);
|
||||
|
||||
unsigned int Sys_Milliseconds (void);
|
||||
double Sys_DoubleTime (void);
|
||||
|
||||
|
|
|
@ -661,7 +661,7 @@ extern int ZEXPORT unzOpenCurrentFile (unzFile file) {
|
|||
pfile_in_zip_read_info->stream.zfree = (free_func)0;
|
||||
pfile_in_zip_read_info->stream.opaque = (voidpf)0;
|
||||
|
||||
err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
|
||||
err=qinflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
|
||||
if (err == Z_OK) pfile_in_zip_read_info->stream_initialised=1;
|
||||
/* windowBits is passed < 0 to tell that there is no zlib header.
|
||||
* Note that in this case inflate *requires* an extra "dummy" byte
|
||||
|
@ -811,7 +811,7 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) {
|
|||
for (i=0;i<uDoCopy;i++)
|
||||
*(pfile_in_zip_read_info->stream.next_out+i) = *(pfile_in_zip_read_info->stream.next_in+i);
|
||||
|
||||
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, pfile_in_zip_read_info->stream.next_out, uDoCopy);
|
||||
pfile_in_zip_read_info->crc32 = qcrc32(pfile_in_zip_read_info->crc32, pfile_in_zip_read_info->stream.next_out, uDoCopy);
|
||||
pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
|
||||
pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
|
||||
pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
|
||||
|
@ -828,12 +828,12 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) {
|
|||
uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
|
||||
bufBefore = pfile_in_zip_read_info->stream.next_out;
|
||||
|
||||
err=inflate(&pfile_in_zip_read_info->stream,flush);
|
||||
err=qinflate(&pfile_in_zip_read_info->stream,flush);
|
||||
|
||||
uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
|
||||
uOutThis = uTotalOutAfter-uTotalOutBefore;
|
||||
|
||||
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (unsigned int)(uOutThis));
|
||||
pfile_in_zip_read_info->crc32 = qcrc32(pfile_in_zip_read_info->crc32,bufBefore, (unsigned int)(uOutThis));
|
||||
|
||||
pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
|
||||
|
||||
|
@ -948,7 +948,7 @@ extern int ZEXPORT unzCloseCurrentFile (unzFile file) {
|
|||
|
||||
TRYFREE(pfile_in_zip_read_info->read_buffer);
|
||||
pfile_in_zip_read_info->read_buffer = NULL;
|
||||
if (pfile_in_zip_read_info->stream_initialised) inflateEnd(&pfile_in_zip_read_info->stream);
|
||||
if (pfile_in_zip_read_info->stream_initialised) qinflateEnd(&pfile_in_zip_read_info->stream);
|
||||
|
||||
pfile_in_zip_read_info->stream_initialised = 0;
|
||||
TRYFREE(pfile_in_zip_read_info);
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
#include "shader.h"
|
||||
#include <d3d9.h>
|
||||
|
||||
#ifndef GLQUAKE
|
||||
/*shaders have a few GL_FOO constants in them. they shouldn't, but they do.*/
|
||||
#include <GL/gl.h>
|
||||
#include "glsupp.h"
|
||||
#endif
|
||||
|
||||
extern LPDIRECT3DDEVICE9 pD3DDev9;
|
||||
|
||||
|
@ -1455,6 +1458,11 @@ static void BE_DrawMeshChain_Internal(void)
|
|||
{
|
||||
if (!BE_DrawMeshChain_SetupPass(pass+passno, vertcount))
|
||||
continue;
|
||||
#ifdef BENCH
|
||||
shaderstate.bench.draws++;
|
||||
if (shaderstate.bench.clamp && shaderstate.bench.clamp < shaderstate.bench.draws)
|
||||
continue;
|
||||
#endif
|
||||
d3dcheck(IDirect3DDevice9_DrawIndexedPrimitive(pD3DDev9, D3DPT_TRIANGLELIST, 0, 0, vertcount, idxfirst, idxcount/3));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1132,7 +1132,7 @@ static void D3D9_SetupViewPort(void)
|
|||
static void (D3D9_R_RenderView) (void)
|
||||
{
|
||||
D3D9_SetupViewPort();
|
||||
d3d9error(IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1, 0));
|
||||
d3d9error(IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET| D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1, 0));
|
||||
R_SetFrustum (r_refdef.m_projection, r_refdef.m_view);
|
||||
RQ_BeginFrame();
|
||||
Surf_DrawWorld();
|
||||
|
|
|
@ -206,7 +206,7 @@ typedef struct {
|
|||
|
||||
static fontplanes_t fontplanes;
|
||||
|
||||
#define FONT_CHAR_BUFFER 64
|
||||
#define FONT_CHAR_BUFFER 512
|
||||
static index_t font_indicies[FONT_CHAR_BUFFER*6];
|
||||
static vecV_t font_coord[FONT_CHAR_BUFFER*4];
|
||||
static vec2_t font_texcoord[FONT_CHAR_BUFFER*4];
|
||||
|
|
|
@ -31,8 +31,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef GLQUAKE
|
||||
/*the shaders have a few GL_FOO constants in them. they shouldn't, but they do.*/
|
||||
#include <GL/gl.h>
|
||||
#include "glsupp.h"
|
||||
#endif
|
||||
|
||||
|
||||
extern texid_t missing_texture;
|
||||
|
|
|
@ -1001,7 +1001,6 @@ rendererinfo_t openglrendererinfo = {
|
|||
GLR_NewMap,
|
||||
GLR_PreNewMap,
|
||||
GLR_LightPoint,
|
||||
GLR_PushDlights,
|
||||
|
||||
|
||||
Surf_AddStain,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 95 or NT. */
|
||||
/* see jconfig.txt for explanations */
|
||||
/* see jconfig.doc for explanations */
|
||||
|
||||
#define HAVE_PROTOTYPES
|
||||
#define HAVE_UNSIGNED_CHAR
|
||||
|
@ -21,7 +21,6 @@ typedef unsigned char boolean;
|
|||
#endif
|
||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||
|
||||
|
||||
#ifdef JPEG_INTERNALS
|
||||
|
||||
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||
|
|
|
@ -188,13 +188,13 @@ typedef unsigned int JDIMENSION;
|
|||
*/
|
||||
|
||||
/* a function called through method pointers: */
|
||||
#define METHODDEF(type) static type
|
||||
#define METHODDEF(type) static type JPEG_API
|
||||
/* a function used only in its module: */
|
||||
#define LOCAL(type) static type
|
||||
/* a function referenced thru EXTERNs: */
|
||||
#define GLOBAL(type) type
|
||||
#define GLOBAL(type) type JPEG_API
|
||||
/* a reference to a GLOBAL function: */
|
||||
#define EXTERN(type) extern type
|
||||
#define EXTERN(type) extern type JPEG_API
|
||||
|
||||
|
||||
/* This macro is used to declare a "method", that is, a function pointer.
|
||||
|
@ -204,9 +204,9 @@ typedef unsigned int JDIMENSION;
|
|||
*/
|
||||
|
||||
#ifdef HAVE_PROTOTYPES
|
||||
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
|
||||
#define JMETHOD(type,methodname,arglist) type (JPEG_API *methodname) arglist
|
||||
#else
|
||||
#define JMETHOD(type,methodname,arglist) type (*methodname) ()
|
||||
#define JMETHOD(type,methodname,arglist) type (JPEG_API *methodname) ()
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Binary file not shown.
BIN
engine/libs/libjpeg64.lib
Normal file
BIN
engine/libs/libjpeg64.lib
Normal file
Binary file not shown.
BIN
engine/libs/libpng64.lib
Normal file
BIN
engine/libs/libpng64.lib
Normal file
Binary file not shown.
BIN
engine/libs/zlib64.lib
Normal file
BIN
engine/libs/zlib64.lib
Normal file
Binary file not shown.
Loading…
Reference in a new issue