Rewritten 808x CPU emulation core based on reenigne's XTCE, VisiOn, SnatchIt, and 8088 MPH now work correctly;
Fixed PC speaker sound volume in PIT mode 0; A few CPU emulation clean-ups; Hard disk controller changing redone in a less messy way; Re-added the long-missing key send delay handling to the XT keyboard handler; Fixed a bug that was causing SLiRP not to work when compiled with MingW/GCC 7.3.0-2 or newer; Some serial mouse and port fixes; A lot of changes to printer emulation, mostly based on DOSBox-X; Printer PNG writer now uses statically linked libpng; Added support for the HxC MFM floppy image format and upped 86F format version to 2.12; Ported various things from PCem and some from VARCem; Added the S3 86c801/805 emulation (patch from TheCollector1995); Fixed and renamed the EGA monitor options; Better synchronized the 808x to the PIT and the CGA; Fixed the CGA wait state calculation; Cleaned up some things in mem.c; Fixed some things in the floppy emulation to make VisiOn get the correct errors from the copy protection disk; Fixed several renderer-related bugs, including the SDL2 renderer's failure to take screenshots; The Jenkins builds are now compiled with MingW/GCC 7.4.0-1 and include all the required DLL's.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Provide centralized access to the PNG image handler.
|
||||
*
|
||||
* Version: @(#)png.c 1.0.4 2018/10/07
|
||||
* Version: @(#)png.c 1.0.5 2018/11/19
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*
|
||||
@@ -66,100 +66,40 @@
|
||||
#endif
|
||||
|
||||
|
||||
static void *png_handle = NULL; /* handle to DLL */
|
||||
# define PNGFUNC(x) PNG_ ## x
|
||||
# define PNGFUNC(x) png_ ## x
|
||||
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
static png_structp (*PNG_create_write_struct)(png_const_charp user_png_ver,
|
||||
png_voidp error_ptr,
|
||||
png_error_ptr error_fn,
|
||||
png_error_ptr warn_fn);
|
||||
static void (*PNG_destroy_write_struct)(png_structpp png_ptr_ptr,
|
||||
png_infopp info_ptr_ptr);
|
||||
static png_infop (*PNG_create_info_struct)(png_const_structrp png_ptr);
|
||||
static void (*PNG_init_io)(png_structrp png_ptr, png_FILE_p fp);
|
||||
static void (*PNG_set_IHDR)(png_const_structrp png_ptr,
|
||||
png_inforp 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);
|
||||
static png_size_t (*PNG_get_rowbytes)(png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr);
|
||||
static void (*PNG_write_info)(png_structrp png_ptr,
|
||||
png_const_inforp info_ptr);
|
||||
static void (*PNG_write_image)(png_structrp png_ptr,
|
||||
png_bytepp image);
|
||||
static void (*PNG_write_row)(png_structrp png_ptr,
|
||||
png_bytep row);
|
||||
static void (*PNG_write_rows)(png_structrp png_ptr,
|
||||
png_bytepp rows, int num);
|
||||
static void (*PNG_write_end)(png_structrp png_ptr,
|
||||
png_inforp info_ptr);
|
||||
#ifdef ENABLE_ESCP_LOG
|
||||
int png_do_log = ENABLE_ESCP_LOG;
|
||||
|
||||
|
||||
static dllimp_t png_imports[] = {
|
||||
{ "png_create_write_struct", &PNG_create_write_struct },
|
||||
{ "png_destroy_write_struct", &PNG_destroy_write_struct },
|
||||
{ "png_create_info_struct", &PNG_create_info_struct },
|
||||
{ "png_init_io", &PNG_init_io },
|
||||
{ "png_set_IHDR", &PNG_set_IHDR },
|
||||
{ "png_get_rowbytes", &PNG_get_rowbytes },
|
||||
{ "png_write_info", &PNG_write_info },
|
||||
{ "png_write_row", &PNG_write_row },
|
||||
{ "png_write_rows", &PNG_write_rows },
|
||||
{ "png_write_image", &PNG_write_image },
|
||||
{ "png_write_end", &PNG_write_end },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
static void
|
||||
png_log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (escp_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define png_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
error_handler(png_structp arg, const char *str)
|
||||
{
|
||||
pclog("PNG: stream 0x%08lx error '%s'\n", arg, str);
|
||||
png_log("PNG: stream 0x%08lx error '%s'\n", arg, str);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
warning_handler(png_structp arg, const char *str)
|
||||
{
|
||||
pclog("PNG: stream 0x%08lx warning '%s'\n", arg, str);
|
||||
}
|
||||
|
||||
|
||||
/* Prepare the PNG library for use, load DLL if needed. */
|
||||
int
|
||||
png_load(void)
|
||||
{
|
||||
const char *fn = PATH_PNG_DLL;
|
||||
|
||||
/* If already loaded, good! */
|
||||
if (png_handle != NULL) return(1);
|
||||
|
||||
/* Try loading the DLL. */
|
||||
png_handle = dynld_module(fn, png_imports);
|
||||
if (png_handle == NULL) {
|
||||
ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2081);
|
||||
pclog("PNG: unable to load '%s'; format disabled!\n", fn);
|
||||
return(0);
|
||||
} else
|
||||
pclog("PNG: module '%s' loaded.\n", fn);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* PNG library no longer needed, unload DLL if needed. */
|
||||
void
|
||||
png_unload(void)
|
||||
{
|
||||
/* Unload the DLL if possible. */
|
||||
if (png_handle != NULL)
|
||||
dynld_close(png_handle);
|
||||
|
||||
png_handle = NULL;
|
||||
png_log("PNG: stream 0x%08lx warning '%s'\n", arg, str);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,18 +113,15 @@ png_write_gray(wchar_t *fn, int inv, uint8_t *pix, int16_t w, int16_t h)
|
||||
int16_t x, y;
|
||||
FILE *fp;
|
||||
|
||||
/* Load the DLL if needed, give up if that fails. */
|
||||
if (! png_load()) return(0);
|
||||
|
||||
/* Create the image file. */
|
||||
fp = plat_fopen(fn, L"wb");
|
||||
if (fp == NULL) {
|
||||
/* Yes, this looks weird. */
|
||||
if (fp == NULL)
|
||||
pclog("PNG: file %ls could not be opened for writing!\n", fn);
|
||||
png_log("PNG: file %ls could not be opened for writing!\n", fn);
|
||||
else
|
||||
error:
|
||||
pclog("PNG: fatal error, bailing out, error = %i\n", errno);
|
||||
png_log("PNG: fatal error, bailing out, error = %i\n", errno);
|
||||
if (png != NULL)
|
||||
PNGFUNC(destroy_write_struct)(&png, &info);
|
||||
if (fp != NULL)
|
||||
@@ -196,13 +133,13 @@ error:
|
||||
png = PNGFUNC(create_write_struct)(PNG_LIBPNG_VER_STRING, NULL,
|
||||
error_handler, warning_handler);
|
||||
if (png == NULL) {
|
||||
pclog("PNG: create_write_struct failed!\n");
|
||||
png_log("PNG: create_write_struct failed!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
info = PNGFUNC(create_info_struct)(png);
|
||||
if (info == NULL) {
|
||||
pclog("PNG: create_info_struct failed!\n");
|
||||
png_log("PNG: create_info_struct failed!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -247,103 +184,81 @@ error:
|
||||
|
||||
|
||||
/* Write the given BITMAP-format image as an 8-bit RGBA PNG image file. */
|
||||
int
|
||||
png_write_rgb(wchar_t *fn, uint8_t *pix, int16_t w, int16_t h)
|
||||
void
|
||||
png_write_rgb(wchar_t *fn, uint8_t *pix, int16_t w, int16_t h, uint16_t pitch, PALETTE palcol)
|
||||
{
|
||||
png_structp png = NULL;
|
||||
png_infop info = NULL;
|
||||
png_bytepp rows;
|
||||
uint8_t *r, *b;
|
||||
uint32_t *rgb;
|
||||
png_bytep* rows;
|
||||
png_color palette[256];
|
||||
FILE *fp;
|
||||
int y, x;
|
||||
|
||||
/* Load the DLL if needed, give up if that fails. */
|
||||
if (! png_load()) return(0);
|
||||
int i;
|
||||
|
||||
/* Create the image file. */
|
||||
fp = plat_fopen(fn, L"wb");
|
||||
if (fp == NULL) {
|
||||
pclog("PNG: File %ls could not be opened for writing!\n", fn);
|
||||
png_log("PNG: File %ls could not be opened for writing!\n", fn);
|
||||
error:
|
||||
if (png != NULL)
|
||||
PNGFUNC(destroy_write_struct)(&png, &info);
|
||||
if (fp != NULL)
|
||||
(void)fclose(fp);
|
||||
return(0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Initialize PNG stuff. */
|
||||
png = PNGFUNC(create_write_struct)(PNG_LIBPNG_VER_STRING, NULL,
|
||||
error_handler, warning_handler);
|
||||
if (png == NULL) {
|
||||
pclog("PNG: create_write_struct failed!\n");
|
||||
png_log("PNG: create_write_struct failed!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
info = PNGFUNC(create_info_struct)(png);
|
||||
if (info == NULL) {
|
||||
pclog("PNG: create_info_struct failed!\n");
|
||||
png_log("PNG: create_info_struct failed!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Finalize the initing of png library */
|
||||
PNGFUNC(init_io)(png, fp);
|
||||
PNGFUNC(set_compression_level)(png, 9);
|
||||
|
||||
PNGFUNC(set_IHDR)(png, info, w, h, 8, PNG_COLOR_TYPE_RGB,
|
||||
/* set other zlib parameters */
|
||||
PNGFUNC(set_compression_mem_level)(png, 8);
|
||||
PNGFUNC(set_compression_strategy)(png, PNG_Z_DEFAULT_STRATEGY);
|
||||
PNGFUNC(set_compression_window_bits)(png, 15);
|
||||
PNGFUNC(set_compression_method)(png, 8);
|
||||
PNGFUNC(set_compression_buffer_size)(png, 8192);
|
||||
|
||||
PNGFUNC(set_IHDR)(png, info, w, h, 8, PNG_COLOR_TYPE_PALETTE,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
PNGFUNC(write_info)(png, info);
|
||||
for (i = 0; i < 256; i++) {
|
||||
palette[i].red = palcol[i].r;
|
||||
palette[i].green = palcol[i].g;
|
||||
palette[i].blue = palcol[i].b;
|
||||
}
|
||||
|
||||
PNGFUNC(set_PLTE)(png, info, palette, 256);
|
||||
|
||||
/* Create a buffer for scanlines of pixels. */
|
||||
rows = (png_bytepp)malloc(sizeof(png_bytep) * h);
|
||||
for (y = 0; y < h; y++) {
|
||||
rows = (png_bytep *)malloc(sizeof(png_bytep) * h);
|
||||
for (i = 0; i < h; i++) {
|
||||
/* Create a buffer for this scanline. */
|
||||
rows[y] = (png_bytep)malloc(PNGFUNC(get_rowbytes)(png, info));
|
||||
rows[i] = (pix + (i * pitch));
|
||||
}
|
||||
|
||||
/*
|
||||
* Process all scanlines in the image.
|
||||
*
|
||||
* Since the bitmap is in 'bottom-up' mode, we have to
|
||||
* convert all pixels to RGB mode, but also 'flip' the
|
||||
* image to the normal top-down mode.
|
||||
*/
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
/* Get pointer to pixel in bitmap data. */
|
||||
b = &pix[((y * w) + x) * 4];
|
||||
|
||||
/* Transform if needed. */
|
||||
if (invert_display) {
|
||||
rgb = (uint32_t *)b;
|
||||
*rgb = video_color_transform(*rgb);
|
||||
}
|
||||
|
||||
/* Get pointer to png row data. */
|
||||
r = &rows[(h - 1) - y][x * 3];
|
||||
|
||||
/* Copy the pixel data. */
|
||||
r[0] = b[2];
|
||||
r[1] = b[1];
|
||||
r[2] = b[0];
|
||||
}
|
||||
}
|
||||
|
||||
/* Write image to the file. */
|
||||
PNGFUNC(write_image)(png, rows);
|
||||
|
||||
/* No longer need the row buffers. */
|
||||
for (y = 0; y < h; y++)
|
||||
free(rows[y]);
|
||||
free(rows);
|
||||
|
||||
PNGFUNC(write_end)(png, NULL);
|
||||
|
||||
PNGFUNC(destroy_write_struct)(&png, &info);
|
||||
PNGFUNC(set_rows)(png, info, rows);
|
||||
|
||||
PNGFUNC(write_png)(png, info, 0, NULL);
|
||||
|
||||
/* Clean up. */
|
||||
(void)fclose(fp);
|
||||
(void)fclose(fp);
|
||||
|
||||
return(1);
|
||||
PNGFUNC(destroy_write_struct)(&png, &info);
|
||||
|
||||
/* No longer need the row buffers. */
|
||||
free(rows);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user