Save screenshots as JPG and PNG.
lib/ivis_common/jpeg_encoder.c/h is the JPEG encoder from http://blog.frankvh.com/2009/06/09/blackfin-fast-jpeg-encoding/ (GPL v2+), cleaned up to be C only. Refs #23. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/branches/qt-trunk@11083 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
0c80505d54
commit
4c3a638d21
|
@ -8,6 +8,7 @@ noinst_HEADERS = \
|
|||
ivi.h \
|
||||
ivisdef.h \
|
||||
ivispatch.h \
|
||||
jpeg_encoder.h \
|
||||
pieblitfunc.h \
|
||||
pieclip.h \
|
||||
piedef.h \
|
||||
|
@ -25,6 +26,7 @@ libivis_common_a_SOURCES = \
|
|||
bitimage.c \
|
||||
imd.c \
|
||||
imdload.c \
|
||||
jpeg_encoder.c \
|
||||
pieclip.c \
|
||||
piestate.c \
|
||||
png_util.c
|
||||
|
|
|
@ -160,6 +160,10 @@
|
|||
RelativePath=".\imdload.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\jpeg_encoder.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pieclip.c"
|
||||
>
|
||||
|
@ -198,6 +202,10 @@
|
|||
RelativePath=".\ivispatch.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\jpeg_encoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pieblitfunc.h"
|
||||
>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
|||
#ifndef JPEG_H_asdf
|
||||
#define JPEG_H_asdf
|
||||
|
||||
/*
|
||||
* unsigned char *encode_image(unsigned char *input_ptr, unsigned char *output_ptr, unsigned int quality_factor,
|
||||
* unsigned int image_format, unsigned int image_width, unsigned int image_height)
|
||||
* Example:
|
||||
* output_end = encode_image(input, output_start, quality, JPEG_FORMAT_FOUR_TWO_TWO, 320, 256);
|
||||
*
|
||||
* output_end - output_start gives the size of the JPEG data.
|
||||
*
|
||||
*/
|
||||
unsigned char *jpeg_encode_image (unsigned char *, unsigned char *, unsigned int, unsigned int, unsigned int, unsigned int);
|
||||
|
||||
#define JPEG_FORMAT_FOUR_ZERO_ZERO 0
|
||||
#define JPEG_FORMAT_FOUR_TWO_TWO 2
|
||||
#define JPEG_FORMAT_RGB 4
|
||||
|
||||
#endif
|
|
@ -7,6 +7,7 @@ SRC= \
|
|||
bitimage.c \
|
||||
imd.c \
|
||||
imdload.c \
|
||||
jpeg_encoder.c \
|
||||
pieclip.c \
|
||||
piestate.c \
|
||||
png_util.c
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "lib/framework/frame.h"
|
||||
#include "lib/framework/debug.h"
|
||||
#include "jpeg_encoder.h"
|
||||
#include "png_util.h"
|
||||
#include <png.h>
|
||||
#include <physfs.h>
|
||||
|
@ -188,7 +189,7 @@ static void internal_saveImage_PNG(const char *fileName, const iV_Image *image,
|
|||
fileHandle = PHYSFS_openWrite(fileName);
|
||||
if (fileHandle == NULL)
|
||||
{
|
||||
debug(LOG_ERROR, "pie_PNGSaveFile: PHYSFS_openWrite failed (while openening file %s) with error: %s\n", fileName, PHYSFS_getLastError());
|
||||
debug(LOG_ERROR, "pie_PNGSaveFile: PHYSFS_openWrite failed (while opening file %s) with error: %s\n", fileName, PHYSFS_getLastError());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -283,3 +284,53 @@ void iV_saveImage_PNG_Gray(const char *fileName, const iV_Image *image)
|
|||
{
|
||||
internal_saveImage_PNG(fileName, image, PNG_COLOR_TYPE_GRAY);
|
||||
}
|
||||
|
||||
void iV_saveImage_JPEG(const char *fileName, const iV_Image *image)
|
||||
{
|
||||
unsigned char *buffer = NULL;
|
||||
unsigned char *jpeg = NULL;
|
||||
char newfilename[PATH_MAX];
|
||||
unsigned int currentRow;
|
||||
const unsigned int row_stride = image->width * 3; // 3 bytes per pixel
|
||||
PHYSFS_file* fileHandle;
|
||||
unsigned char *jpeg_end;
|
||||
|
||||
sstrcpy(newfilename, fileName);
|
||||
memcpy(newfilename + strlen(newfilename) - 4, ".jpg", 4);
|
||||
fileHandle = PHYSFS_openWrite(newfilename);
|
||||
if (fileHandle == NULL)
|
||||
{
|
||||
debug(LOG_ERROR, "pie_JPEGSaveFile: PHYSFS_openWrite failed (while opening file %s) with error: %s\n", fileName, PHYSFS_getLastError());
|
||||
return;
|
||||
}
|
||||
|
||||
buffer = malloc(sizeof(const char*) * image->height * image->width);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
debug(LOG_ERROR, "pie_JPEGSaveFile: Couldn't allocate memory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create an array of scanlines
|
||||
for (currentRow = 0; currentRow < image->height; ++currentRow)
|
||||
{
|
||||
// We're filling the scanline from the bottom up here,
|
||||
// otherwise we'd have a vertically mirrored image.
|
||||
memcpy(buffer + row_stride * currentRow, &image->bmp[row_stride * (image->height - currentRow - 1)], row_stride);
|
||||
}
|
||||
|
||||
jpeg = malloc(sizeof(const char*) * image->height * image->width);
|
||||
if (jpeg == NULL)
|
||||
{
|
||||
debug(LOG_ERROR, "pie_JPEGSaveFile: Couldn't allocate memory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
jpeg_end = jpeg_encode_image(buffer, jpeg, 1, JPEG_FORMAT_RGB, image->width, image->height);
|
||||
PHYSFS_write(fileHandle, jpeg, jpeg_end - jpeg, 1);
|
||||
|
||||
free(buffer);
|
||||
free(jpeg);
|
||||
PHYSFS_close(fileHandle);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,4 +59,5 @@ void iV_saveImage_PNG_Gray(const char *fileName, const iV_Image *image);
|
|||
}
|
||||
#endif //__cplusplus
|
||||
|
||||
void iV_saveImage_JPEG(const char *fileName, const iV_Image *image);
|
||||
#endif // _LIBIVIS_COMMON_PNG_H_
|
||||
|
|
|
@ -448,8 +448,8 @@ void screenDoDumpToDiskIfRequired(void)
|
|||
}
|
||||
glReadPixels(0, 0, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.bmp);
|
||||
|
||||
// Write the screen to a PNG
|
||||
iV_saveImage_PNG(fileName, &image);
|
||||
iV_saveImage_JPEG(fileName, &image);
|
||||
|
||||
// display message to user about screenshot
|
||||
snprintf(ConsoleString,sizeof(ConsoleString),"Screenshot %s saved!",fileName);
|
||||
|
|
Loading…
Reference in New Issue