mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 13:10:34 +00:00
Create WritePNGqfs so screenshots can be written as png.
This commit is contained in:
parent
718595db45
commit
d8dbfa9c24
2 changed files with 112 additions and 81 deletions
|
@ -35,6 +35,8 @@
|
||||||
#include "QF/quakefs.h"
|
#include "QF/quakefs.h"
|
||||||
|
|
||||||
struct tex_s *LoadPNG (QFile *infile);
|
struct tex_s *LoadPNG (QFile *infile);
|
||||||
void WritePNG (const char *fileName, byte *data, int width, int height);
|
void WritePNG (const char *fileName, const byte *data, int width, int height);
|
||||||
|
void WritePNGqfs (const char *fileName, const byte *data,
|
||||||
|
int width, int height);
|
||||||
|
|
||||||
#endif//__QF_png_h
|
#endif//__QF_png_h
|
||||||
|
|
|
@ -28,8 +28,7 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static __attribute__ ((used)) const char rcsid[] =
|
static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
||||||
"$Id$";
|
|
||||||
|
|
||||||
#ifdef HAVE_PNG
|
#ifdef HAVE_PNG
|
||||||
|
|
||||||
|
@ -196,10 +195,9 @@ LoadPNG (QFile *infile)
|
||||||
|
|
||||||
#define WRITEPNG_BIT_DEPTH 8
|
#define WRITEPNG_BIT_DEPTH 8
|
||||||
|
|
||||||
VISIBLE void
|
static int
|
||||||
WritePNG (const char *fileName, byte *data, int width, int height)
|
write_png (QFile *outfile, const byte *data, int width, int height)
|
||||||
{
|
{
|
||||||
QFile *outfile;
|
|
||||||
int i;
|
int i;
|
||||||
png_structp png_ptr;
|
png_structp png_ptr;
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
|
@ -209,25 +207,19 @@ WritePNG (const char *fileName, byte *data, int width, int height)
|
||||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (png_ptr == NULL) {
|
if (png_ptr == NULL) {
|
||||||
Sys_Printf ("png_Create_write_struct failed\n");
|
Sys_Printf ("png_Create_write_struct failed\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
info_ptr = png_create_info_struct (png_ptr);
|
info_ptr = png_create_info_struct (png_ptr);
|
||||||
if (png_ptr == NULL) {
|
if (png_ptr == NULL) {
|
||||||
png_destroy_write_struct (&png_ptr, NULL);
|
png_destroy_write_struct (&png_ptr, NULL);
|
||||||
Sys_Printf ("png_create_info_struct failed\n");
|
Sys_Printf ("png_create_info_struct failed\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||||
return;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
outfile = Qopen (fileName, "wb");
|
|
||||||
if (!outfile) {
|
|
||||||
Sys_Printf ("Couldn't open %s\n", fileName);
|
|
||||||
return; /* Can't open file */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
png_set_write_fn (png_ptr, outfile, user_write_data, user_flush_data);
|
png_set_write_fn (png_ptr, outfile, user_write_data, user_flush_data);
|
||||||
|
@ -235,11 +227,12 @@ WritePNG (const char *fileName, byte *data, int width, int height)
|
||||||
/* Write the header */
|
/* Write the header */
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
Sys_Printf ("Error writing png header\n");
|
Sys_Printf ("Error writing png header\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_set_IHDR (png_ptr, info_ptr, width, height, WRITEPNG_BIT_DEPTH,
|
png_set_IHDR (png_ptr, info_ptr, width, height, WRITEPNG_BIT_DEPTH,
|
||||||
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
||||||
|
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||||
|
|
||||||
/* NOTE: Write gamma support? */
|
/* NOTE: Write gamma support? */
|
||||||
/* png_set_gAMA (png_ptr, info_ptr, gamma); */
|
/* png_set_gAMA (png_ptr, info_ptr, gamma); */
|
||||||
|
@ -249,19 +242,21 @@ WritePNG (const char *fileName, byte *data, int width, int height)
|
||||||
png_write_info (png_ptr, info_ptr);
|
png_write_info (png_ptr, info_ptr);
|
||||||
|
|
||||||
/* Setup row pointers */
|
/* Setup row pointers */
|
||||||
if ((row_pointers = (png_bytepp)malloc(height * sizeof(png_bytep))) == NULL) {
|
row_pointers = (png_bytepp)malloc(height * sizeof(png_bytep));
|
||||||
|
if (row_pointers == NULL) {
|
||||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||||
return; /* Out of memory */
|
return 0; /* Out of memory */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < height; i++) {
|
for (i = 0; i < height; i++) {
|
||||||
row_pointers[height - i - 1] = data + (i * width * 3);
|
//FIXME stupid png types :P
|
||||||
|
row_pointers[height - i - 1] = (byte *) data + (i * width * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
Sys_Printf ("Error writing PNG image data\n");
|
Sys_Printf ("Error writing PNG image data\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_write_image (png_ptr, row_pointers);
|
png_write_image (png_ptr, row_pointers);
|
||||||
|
@ -269,11 +264,41 @@ WritePNG (const char *fileName, byte *data, int width, int height)
|
||||||
/* end write */
|
/* end write */
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
Sys_Printf ("Error writing end of PNG image\n");
|
Sys_Printf ("Error writing end of PNG image\n");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_write_end (png_ptr, NULL);
|
png_write_end (png_ptr, NULL);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VISIBLE void
|
||||||
|
WritePNG (const char *fileName, const byte *data, int width, int height)
|
||||||
|
{
|
||||||
|
QFile *outfile;
|
||||||
|
|
||||||
|
outfile = Qopen (fileName, "wb");
|
||||||
|
if (!outfile) {
|
||||||
|
Sys_Printf ("Couldn't open %s\n", fileName);
|
||||||
|
return; /* Can't open file */
|
||||||
|
}
|
||||||
|
if (!write_png (outfile, data, width, height))
|
||||||
|
Qremove (fileName);
|
||||||
|
Qclose (outfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
VISIBLE void
|
||||||
|
WritePNGqfs (const char *fileName, const byte *data, int width, int height)
|
||||||
|
{
|
||||||
|
QFile *outfile;
|
||||||
|
|
||||||
|
outfile = QFS_Open (fileName, "wb");
|
||||||
|
if (!outfile) {
|
||||||
|
Sys_Printf ("Couldn't open %s\n", fileName);
|
||||||
|
return; /* Can't open file */
|
||||||
|
}
|
||||||
|
if (!write_png (outfile, data, width, height))
|
||||||
|
QFS_Remove (fileName);
|
||||||
Qclose (outfile);
|
Qclose (outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +316,11 @@ LoadPNG (QFile *infile)
|
||||||
VISIBLE void
|
VISIBLE void
|
||||||
WritePNG (const char *fileName, byte *data, int width, int height)
|
WritePNG (const char *fileName, byte *data, int width, int height)
|
||||||
{
|
{
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
VISIBLE void
|
||||||
|
WritePNGqfs (const char *fileName, const byte *data, int width, int height)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue