|
Packit |
0ba690 |
//-------------------------------------
|
|
Packit |
0ba690 |
// PNGFILE.C -- Image File Functions
|
|
Packit |
0ba690 |
//-------------------------------------
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// Copyright 2000, Willem van Schaik.
|
|
Packit |
0ba690 |
//
|
|
Packit |
0ba690 |
// This code is released under the libpng license.
|
|
Packit |
0ba690 |
// For conditions of distribution and use, see the disclaimer
|
|
Packit |
0ba690 |
// and license in png.h
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
#include <windows.h>
|
|
Packit |
0ba690 |
#include <commdlg.h>
|
|
Packit |
0ba690 |
#include <stdio.h>
|
|
Packit |
0ba690 |
#include <stdlib.h>
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
#include "png.h"
|
|
Packit |
0ba690 |
#include "pngfile.h"
|
|
Packit |
0ba690 |
#include "cexcept.h"
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
define_exception_type(const char *);
|
|
Packit |
0ba690 |
extern struct exception_context the_exception_context[1];
|
|
Packit |
0ba690 |
struct exception_context the_exception_context[1];
|
|
Packit |
0ba690 |
png_const_charp msg;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static OPENFILENAME ofn;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static png_structp png_ptr = NULL;
|
|
Packit |
0ba690 |
static png_infop info_ptr = NULL;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// cexcept interface
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static void
|
|
Packit |
0ba690 |
png_cexcept_error(png_structp png_ptr, png_const_charp msg)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
if(png_ptr)
|
|
Packit |
0ba690 |
;
|
|
Packit |
0ba690 |
#ifndef PNG_NO_CONSOLE_IO
|
|
Packit |
0ba690 |
fprintf(stderr, "libpng error: %s\n", msg);
|
|
Packit |
0ba690 |
#endif
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
Throw msg;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// Windows open-file functions
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
void PngFileInitialize (HWND hwnd)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
static TCHAR szFilter[] = TEXT ("PNG Files (*.PNG)\0*.png\0")
|
|
Packit |
0ba690 |
TEXT ("All Files (*.*)\0*.*\0\0");
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
ofn.lStructSize = sizeof (OPENFILENAME);
|
|
Packit |
0ba690 |
ofn.hwndOwner = hwnd;
|
|
Packit |
0ba690 |
ofn.hInstance = NULL;
|
|
Packit |
0ba690 |
ofn.lpstrFilter = szFilter;
|
|
Packit |
0ba690 |
ofn.lpstrCustomFilter = NULL;
|
|
Packit |
0ba690 |
ofn.nMaxCustFilter = 0;
|
|
Packit |
0ba690 |
ofn.nFilterIndex = 0;
|
|
Packit |
0ba690 |
ofn.lpstrFile = NULL; // Set in Open and Close functions
|
|
Packit |
0ba690 |
ofn.nMaxFile = MAX_PATH;
|
|
Packit |
0ba690 |
ofn.lpstrFileTitle = NULL; // Set in Open and Close functions
|
|
Packit |
0ba690 |
ofn.nMaxFileTitle = MAX_PATH;
|
|
Packit |
0ba690 |
ofn.lpstrInitialDir = NULL;
|
|
Packit |
0ba690 |
ofn.lpstrTitle = NULL;
|
|
Packit |
0ba690 |
ofn.Flags = 0; // Set in Open and Close functions
|
|
Packit |
0ba690 |
ofn.nFileOffset = 0;
|
|
Packit |
0ba690 |
ofn.nFileExtension = 0;
|
|
Packit |
0ba690 |
ofn.lpstrDefExt = TEXT ("png");
|
|
Packit |
0ba690 |
ofn.lCustData = 0;
|
|
Packit |
0ba690 |
ofn.lpfnHook = NULL;
|
|
Packit |
0ba690 |
ofn.lpTemplateName = NULL;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
ofn.hwndOwner = hwnd;
|
|
Packit |
0ba690 |
ofn.lpstrFile = pstrFileName;
|
|
Packit |
0ba690 |
ofn.lpstrFileTitle = pstrTitleName;
|
|
Packit |
0ba690 |
ofn.Flags = OFN_HIDEREADONLY;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
return GetOpenFileName (&ofn;;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
ofn.hwndOwner = hwnd;
|
|
Packit |
0ba690 |
ofn.lpstrFile = pstrFileName;
|
|
Packit |
0ba690 |
ofn.lpstrFileTitle = pstrTitleName;
|
|
Packit |
0ba690 |
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
return GetSaveFileName (&ofn;;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// PNG image handler functions
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
|
Packit |
0ba690 |
int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
static FILE *pfFile;
|
|
Packit |
0ba690 |
png_byte pbSig[8];
|
|
Packit |
0ba690 |
int iBitDepth;
|
|
Packit |
0ba690 |
int iColorType;
|
|
Packit |
0ba690 |
double dGamma;
|
|
Packit |
0ba690 |
png_color_16 *pBackground;
|
|
Packit |
0ba690 |
png_uint_32 ulChannels;
|
|
Packit |
0ba690 |
png_uint_32 ulRowBytes;
|
|
Packit |
0ba690 |
png_byte *pbImageData = *ppbImageData;
|
|
Packit |
0ba690 |
static png_byte **ppbRowPointers = NULL;
|
|
Packit |
0ba690 |
int i;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// open the PNG input file
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (!pstrFileName)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData = NULL;
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (!(pfFile = fopen(pstrFileName, "rb")))
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData = NULL;
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// first check the eight byte PNG signature
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
fread(pbSig, 1, 8, pfFile);
|
|
Packit |
0ba690 |
if (png_sig_cmp(pbSig, 0, 8))
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData = NULL;
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// create the two png(-info) structures
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
|
|
Packit |
0ba690 |
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
|
Packit |
0ba690 |
if (!png_ptr)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData = NULL;
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
info_ptr = png_create_info_struct(png_ptr);
|
|
Packit |
0ba690 |
if (!info_ptr)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData = NULL;
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
Try
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// initialize the png structure
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
#if !defined(PNG_NO_STDIO)
|
|
Packit |
0ba690 |
png_init_io(png_ptr, pfFile);
|
|
Packit |
0ba690 |
#else
|
|
Packit |
0ba690 |
png_set_read_fn(png_ptr, (png_voidp)pfFile, png_read_data);
|
|
Packit |
0ba690 |
#endif
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_set_sig_bytes(png_ptr, 8);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// read all PNG info up to image data
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_read_info(png_ptr, info_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// get width, height, bit-depth and color-type
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
|
|
Packit |
0ba690 |
&iColorType, NULL, NULL, NULL);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// expand images of all color-type and bit-depth to 3x8 bit RGB images
|
|
Packit |
0ba690 |
// let the library process things like alpha, transparency, background
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (iBitDepth == 16)
|
|
Packit |
0ba690 |
png_set_strip_16(png_ptr);
|
|
Packit |
0ba690 |
if (iColorType == PNG_COLOR_TYPE_PALETTE)
|
|
Packit |
0ba690 |
png_set_expand(png_ptr);
|
|
Packit |
0ba690 |
if (iBitDepth < 8)
|
|
Packit |
0ba690 |
png_set_expand(png_ptr);
|
|
Packit |
0ba690 |
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
|
Packit |
0ba690 |
png_set_expand(png_ptr);
|
|
Packit |
0ba690 |
if (iColorType == PNG_COLOR_TYPE_GRAY ||
|
|
Packit |
0ba690 |
iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
|
Packit |
0ba690 |
png_set_gray_to_rgb(png_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// set the background color to draw transparent and alpha images over.
|
|
Packit |
0ba690 |
if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
|
Packit |
0ba690 |
pBkgColor->red = (byte) pBackground->red;
|
|
Packit |
0ba690 |
pBkgColor->green = (byte) pBackground->green;
|
|
Packit |
0ba690 |
pBkgColor->blue = (byte) pBackground->blue;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
else
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
pBkgColor = NULL;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// if required set gamma conversion
|
|
Packit |
0ba690 |
if (png_get_gAMA(png_ptr, info_ptr, &dGamma))
|
|
Packit |
0ba690 |
png_set_gamma(png_ptr, (double) 2.2, dGamma);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// after the transformations have been registered update info_ptr data
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_read_update_info(png_ptr, info_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// get again width, height and the new bit-depth and color-type
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
|
|
Packit |
0ba690 |
&iColorType, NULL, NULL, NULL);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// row_bytes is the width x number of channels
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
ulRowBytes = png_get_rowbytes(png_ptr, info_ptr);
|
|
Packit |
0ba690 |
ulChannels = png_get_channels(png_ptr, info_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
*piChannels = ulChannels;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// now we can allocate memory to store the image
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (pbImageData)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
free (pbImageData);
|
|
Packit |
0ba690 |
pbImageData = NULL;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
if ((pbImageData = (png_byte *) malloc(ulRowBytes * (*piHeight)
|
|
Packit |
0ba690 |
* sizeof(png_byte))) == NULL)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_error(png_ptr, "Visual PNG: out of memory");
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// and allocate memory for an array of row-pointers
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if ((ppbRowPointers = (png_bytepp) malloc((*piHeight)
|
|
Packit |
0ba690 |
* sizeof(png_bytep))) == NULL)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_error(png_ptr, "Visual PNG: out of memory");
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// set the individual row-pointers to point at the correct offsets
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
for (i = 0; i < (*piHeight); i++)
|
|
Packit |
0ba690 |
ppbRowPointers[i] = pbImageData + i * ulRowBytes;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// now we can go ahead and just read the whole image
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_read_image(png_ptr, ppbRowPointers);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// read the additional chunks in the PNG file (not really needed)
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_read_end(png_ptr, NULL);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// and we're done
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
free (ppbRowPointers);
|
|
Packit |
0ba690 |
ppbRowPointers = NULL;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// yepp, done
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
Catch (msg)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
*ppbImageData = pbImageData = NULL;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if(ppbRowPointers)
|
|
Packit |
0ba690 |
free (ppbRowPointers);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
fclose(pfFile);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
fclose (pfFile);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
return TRUE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
|
Packit |
0ba690 |
int iWidth, int iHeight, png_color bkgColor)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
const int ciBitDepth = 8;
|
|
Packit |
0ba690 |
const int ciChannels = 3;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static FILE *pfFile;
|
|
Packit |
0ba690 |
png_uint_32 ulRowBytes;
|
|
Packit |
0ba690 |
static png_byte **ppbRowPointers = NULL;
|
|
Packit |
0ba690 |
int i;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// open the PNG output file
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (!pstrFileName)
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (!(pfFile = fopen(pstrFileName, "wb")))
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// prepare the standard PNG structures
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
|
|
Packit |
0ba690 |
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
|
Packit |
0ba690 |
if (!png_ptr)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
fclose(pfFile);
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
info_ptr = png_create_info_struct(png_ptr);
|
|
Packit |
0ba690 |
if (!info_ptr) {
|
|
Packit |
0ba690 |
fclose(pfFile);
|
|
Packit |
0ba690 |
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
Try
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
// initialize the png structure
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
#if !defined(PNG_NO_STDIO)
|
|
Packit |
0ba690 |
png_init_io(png_ptr, pfFile);
|
|
Packit |
0ba690 |
#else
|
|
Packit |
0ba690 |
png_set_write_fn(png_ptr, (png_voidp)pfFile, png_write_data, png_flush);
|
|
Packit |
0ba690 |
#endif
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// we're going to write a very simple 3x8 bit RGB image
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_set_IHDR(png_ptr, info_ptr, iWidth, iHeight, ciBitDepth,
|
|
Packit |
0ba690 |
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
|
|
Packit |
0ba690 |
PNG_FILTER_TYPE_BASE);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// write the file header information
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_write_info(png_ptr, info_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// swap the BGR pixels in the DiData structure to RGB
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_set_bgr(png_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// row_bytes is the width x number of channels
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
ulRowBytes = iWidth * ciChannels;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// we can allocate memory for an array of row-pointers
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if ((ppbRowPointers = (png_bytepp) malloc(iHeight * sizeof(png_bytep))) == NULL)
|
|
Packit |
0ba690 |
Throw "Visualpng: Out of memory";
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// set the individual row-pointers to point at the correct offsets
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
for (i = 0; i < iHeight; i++)
|
|
Packit |
0ba690 |
ppbRowPointers[i] = pDiData + i * (((ulRowBytes + 3) >> 2) << 2);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// write out the entire image data in one call
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_write_image (png_ptr, ppbRowPointers);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// write the additional chunks to the PNG file (not really needed)
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_write_end(png_ptr, info_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// and we're done
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
free (ppbRowPointers);
|
|
Packit |
0ba690 |
ppbRowPointers = NULL;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// clean up after the write, and free any memory allocated
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
// yepp, done
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
Catch (msg)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if(ppbRowPointers)
|
|
Packit |
0ba690 |
free (ppbRowPointers);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
fclose(pfFile);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
return FALSE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
fclose (pfFile);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
return TRUE;
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
#ifdef PNG_NO_STDIO
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static void
|
|
Packit |
0ba690 |
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_size_t check;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
|
Packit |
0ba690 |
* instead of an int, which is what fread() actually returns.
|
|
Packit |
0ba690 |
*/
|
|
Packit |
0ba690 |
check = (png_size_t)fread(data, (png_size_t)1, length,
|
|
Packit |
0ba690 |
(FILE *)png_ptr->io_ptr);
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
if (check != length)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_error(png_ptr, "Read Error");
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static void
|
|
Packit |
0ba690 |
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_uint_32 check;
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
|
|
Packit |
0ba690 |
if (check != length)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
png_error(png_ptr, "Write Error");
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
static void
|
|
Packit |
0ba690 |
png_flush(png_structp png_ptr)
|
|
Packit |
0ba690 |
{
|
|
Packit |
0ba690 |
FILE *io_ptr;
|
|
Packit |
0ba690 |
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
|
Packit |
0ba690 |
if (io_ptr != NULL)
|
|
Packit |
0ba690 |
fflush(io_ptr);
|
|
Packit |
0ba690 |
}
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
#endif
|
|
Packit |
0ba690 |
|
|
Packit |
0ba690 |
//-----------------
|
|
Packit |
0ba690 |
// end of source
|
|
Packit |
0ba690 |
//-----------------
|