1999-10-23 09:39:18 -04:00
|
|
|
/*
|
|
|
|
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
|
2019-01-23 09:05:54 -05:00
|
|
|
* copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com>
|
1999-10-23 09:39:18 -04:00
|
|
|
*
|
2019-01-23 09:05:54 -05:00
|
|
|
* This software is released under the MIT license. For conditions of
|
|
|
|
* distribution and use, see the LICENSE file part of this package.
|
1999-10-23 09:39:18 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#ifndef BOOL
|
|
|
|
#define BOOL unsigned char
|
|
|
|
#endif
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE (BOOL) 1
|
|
|
|
#endif
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE (BOOL) 0
|
|
|
|
#endif
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
/* make png2pnm verbose so we can find problems (needs to be before png.h) */
|
1999-10-23 09:39:18 -04:00
|
|
|
#ifndef PNG_DEBUG
|
|
|
|
#define PNG_DEBUG 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "png.h"
|
|
|
|
|
|
|
|
/* function prototypes */
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
int main (int argc, char *argv[]);
|
1999-10-23 09:39:18 -04:00
|
|
|
void usage ();
|
2018-08-05 21:44:11 -04:00
|
|
|
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
|
|
|
|
BOOL raw, BOOL alpha);
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* main
|
|
|
|
*/
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
int main (int argc, char *argv[])
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
FILE *fp_rd = stdin;
|
|
|
|
FILE *fp_wr = stdout;
|
|
|
|
FILE *fp_al = NULL;
|
|
|
|
BOOL raw = TRUE;
|
|
|
|
BOOL alpha = FALSE;
|
|
|
|
int argi;
|
|
|
|
|
|
|
|
for (argi = 1; argi < argc; argi++)
|
|
|
|
{
|
|
|
|
if (argv[argi][0] == '-')
|
|
|
|
{
|
|
|
|
switch (argv[argi][1])
|
|
|
|
{
|
|
|
|
case 'n':
|
|
|
|
raw = FALSE;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
raw = TRUE;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
alpha = TRUE;
|
|
|
|
argi++;
|
|
|
|
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "PNM2PNG\n");
|
2018-08-05 21:44:11 -04:00
|
|
|
fprintf (stderr, "Error: cannot create alpha-channel file %s\n",
|
|
|
|
argv[argi]);
|
1999-10-23 09:39:18 -04:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
2018-08-05 21:44:11 -04:00
|
|
|
usage ();
|
|
|
|
exit (0);
|
1999-10-23 09:39:18 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
|
|
|
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
2018-08-05 21:44:11 -04:00
|
|
|
usage ();
|
|
|
|
exit (1);
|
1999-10-23 09:39:18 -04:00
|
|
|
break;
|
|
|
|
} /* end switch */
|
|
|
|
}
|
|
|
|
else if (fp_rd == stdin)
|
|
|
|
{
|
|
|
|
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
|
|
|
{
|
2018-08-05 21:44:11 -04:00
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
|
|
|
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
|
|
|
exit (1);
|
1999-10-23 09:39:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fp_wr == stdout)
|
|
|
|
{
|
|
|
|
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
2018-08-05 21:44:11 -04:00
|
|
|
fprintf (stderr, "Error: cannot create file %s\n", argv[argi]);
|
1999-10-23 09:39:18 -04:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
|
|
|
fprintf (stderr, "Error: too many parameters\n");
|
2018-08-05 21:44:11 -04:00
|
|
|
usage ();
|
|
|
|
exit (1);
|
1999-10-23 09:39:18 -04:00
|
|
|
}
|
|
|
|
} /* end for */
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
#if defined(O_BINARY) && (O_BINARY != 0)
|
1999-10-23 09:39:18 -04:00
|
|
|
/* set stdin/stdout if required to binary */
|
|
|
|
if (fp_rd == stdin)
|
2018-08-05 21:44:11 -04:00
|
|
|
setmode (fileno (stdin), O_BINARY);
|
1999-10-23 09:39:18 -04:00
|
|
|
if ((raw) && (fp_wr == stdout))
|
2018-08-05 21:44:11 -04:00
|
|
|
setmode (fileno (stdout), O_BINARY);
|
1999-10-23 09:39:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* call the conversion program itself */
|
|
|
|
if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
2011-06-16 10:08:53 -04:00
|
|
|
fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n");
|
2018-08-05 21:44:11 -04:00
|
|
|
exit (1);
|
1999-10-23 09:39:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* close input file */
|
|
|
|
fclose (fp_rd);
|
|
|
|
/* close output file */
|
|
|
|
fclose (fp_wr);
|
|
|
|
/* close alpha file */
|
|
|
|
if (alpha)
|
|
|
|
fclose (fp_al);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usage
|
|
|
|
*/
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
void usage ()
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
|
|
|
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
|
|
|
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
|
|
|
|
fprintf (stderr, " or: ... | png2pnm [options]\n");
|
|
|
|
fprintf (stderr, "Options:\n");
|
2014-06-13 12:06:33 -04:00
|
|
|
fprintf (stderr,
|
2018-08-05 21:44:11 -04:00
|
|
|
" -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
|
1999-10-23 09:39:18 -04:00
|
|
|
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
|
2014-06-13 12:06:33 -04:00
|
|
|
fprintf (stderr,
|
2018-08-05 21:44:11 -04:00
|
|
|
" -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
|
1999-10-23 09:39:18 -04:00
|
|
|
fprintf (stderr, " -h | -? print this help-information\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* png2pnm
|
|
|
|
*/
|
|
|
|
|
2014-06-13 12:06:33 -04:00
|
|
|
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
|
2018-08-05 21:44:11 -04:00
|
|
|
BOOL raw, BOOL alpha)
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
png_struct *png_ptr = NULL;
|
2018-08-05 21:44:11 -04:00
|
|
|
png_info *info_ptr = NULL;
|
1999-10-23 09:39:18 -04:00
|
|
|
png_byte buf[8];
|
|
|
|
png_byte *png_pixels = NULL;
|
|
|
|
png_byte **row_pointers = NULL;
|
|
|
|
png_byte *pix_ptr = NULL;
|
|
|
|
png_uint_32 row_bytes;
|
|
|
|
|
|
|
|
png_uint_32 width;
|
|
|
|
png_uint_32 height;
|
|
|
|
int bit_depth;
|
|
|
|
int channels;
|
|
|
|
int color_type;
|
|
|
|
int alpha_present;
|
|
|
|
int row, col;
|
|
|
|
int ret;
|
|
|
|
int i;
|
2000-11-10 13:26:19 -05:00
|
|
|
long dep_16;
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
/* read and check signature in PNG file */
|
|
|
|
ret = fread (buf, 1, 8, png_file);
|
|
|
|
if (ret != 8)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-11-09 11:49:12 -05:00
|
|
|
ret = png_sig_cmp (buf, 0, 8);
|
2018-08-05 21:44:11 -04:00
|
|
|
if (ret != 0)
|
1999-10-23 09:39:18 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* create png and info structures */
|
|
|
|
|
2014-11-05 00:33:46 -05:00
|
|
|
png_ptr = png_create_read_struct (png_get_libpng_ver(NULL),
|
2018-08-05 21:44:11 -04:00
|
|
|
NULL, NULL, NULL);
|
1999-10-23 09:39:18 -04:00
|
|
|
if (!png_ptr)
|
2018-08-05 21:44:11 -04:00
|
|
|
return FALSE; /* out of memory */
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
info_ptr = png_create_info_struct (png_ptr);
|
1999-12-10 10:43:02 -05:00
|
|
|
if (!info_ptr)
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
2018-08-05 21:44:11 -04:00
|
|
|
return FALSE; /* out of memory */
|
1999-10-23 09:39:18 -04:00
|
|
|
}
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
if (setjmp (png_jmpbuf (png_ptr)))
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set up the input control for C streams */
|
|
|
|
png_init_io (png_ptr, png_file);
|
2018-08-05 21:44:11 -04:00
|
|
|
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
/* read the file information */
|
|
|
|
png_read_info (png_ptr, info_ptr);
|
|
|
|
|
|
|
|
/* get size and bit-depth of the PNG-image */
|
2018-08-05 21:44:11 -04:00
|
|
|
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
|
|
|
NULL, NULL, NULL);
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
/* set-up the transformations */
|
|
|
|
|
|
|
|
/* transform paletted images into full-color rgb */
|
|
|
|
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
|
|
|
png_set_expand (png_ptr);
|
|
|
|
/* expand images to bit-depth 8 (only applicable for grayscale images) */
|
|
|
|
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
|
|
|
png_set_expand (png_ptr);
|
|
|
|
/* transform transparency maps into full alpha-channel */
|
|
|
|
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
|
|
|
png_set_expand (png_ptr);
|
|
|
|
|
|
|
|
#ifdef NJET
|
2015-08-13 21:57:18 -04:00
|
|
|
/* downgrade 16-bit images to 8-bit */
|
1999-10-23 09:39:18 -04:00
|
|
|
if (bit_depth == 16)
|
|
|
|
png_set_strip_16 (png_ptr);
|
|
|
|
/* transform grayscale images into full-color */
|
|
|
|
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
2018-08-05 21:44:11 -04:00
|
|
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
1999-10-23 09:39:18 -04:00
|
|
|
png_set_gray_to_rgb (png_ptr);
|
|
|
|
/* only if file has a file gamma, we do a correction */
|
|
|
|
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
|
|
|
|
png_set_gamma (png_ptr, (double) 2.2, file_gamma);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* all transformations have been registered; now update info_ptr data,
|
|
|
|
* get rowbytes and channels, and allocate image memory */
|
|
|
|
|
|
|
|
png_read_update_info (png_ptr, info_ptr);
|
|
|
|
|
|
|
|
/* get the new color-type and bit-depth (after expansion/stripping) */
|
|
|
|
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
2018-08-05 21:44:11 -04:00
|
|
|
NULL, NULL, NULL);
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
/* check for 16-bit files */
|
|
|
|
if (bit_depth == 16)
|
|
|
|
{
|
|
|
|
raw = FALSE;
|
2018-08-05 21:44:11 -04:00
|
|
|
#if defined(O_BINARY) && (O_BINARY != 0)
|
|
|
|
setmode (fileno (pnm_file), O_BINARY);
|
1999-10-23 09:39:18 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate new number of channels and store alpha-presence */
|
|
|
|
if (color_type == PNG_COLOR_TYPE_GRAY)
|
|
|
|
channels = 1;
|
|
|
|
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
|
|
|
channels = 2;
|
|
|
|
else if (color_type == PNG_COLOR_TYPE_RGB)
|
|
|
|
channels = 3;
|
|
|
|
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
|
|
|
channels = 4;
|
|
|
|
else
|
1999-12-10 10:43:02 -05:00
|
|
|
channels = 0; /* should never happen */
|
1999-10-23 09:39:18 -04:00
|
|
|
alpha_present = (channels - 1) % 2;
|
|
|
|
|
|
|
|
/* check if alpha is expected to be present in file */
|
|
|
|
if (alpha && !alpha_present)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "PNG2PNM\n");
|
|
|
|
fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
|
|
|
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
if ((row_bytes == 0) ||
|
|
|
|
((size_t) height > (size_t) (-1) / (size_t) row_bytes))
|
2017-08-11 11:05:53 -04:00
|
|
|
{
|
2018-08-05 21:44:11 -04:00
|
|
|
/* too big */
|
2017-04-22 16:21:58 -04:00
|
|
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-13 12:06:33 -04:00
|
|
|
if ((png_pixels = (png_byte *)
|
2018-08-05 21:44:11 -04:00
|
|
|
malloc ((size_t) row_bytes * (size_t) height)) == NULL)
|
2017-08-11 11:05:53 -04:00
|
|
|
{
|
1999-10-23 09:39:18 -04:00
|
|
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-06-13 12:06:33 -04:00
|
|
|
if ((row_pointers = (png_byte **)
|
2018-08-05 21:44:11 -04:00
|
|
|
malloc ((size_t) height * sizeof (png_byte *))) == NULL)
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
|
|
|
free (png_pixels);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the individual row_pointers to point at the correct offsets */
|
2014-06-13 12:06:33 -04:00
|
|
|
for (i = 0; i < ((int) height); i++)
|
1999-10-23 09:39:18 -04:00
|
|
|
row_pointers[i] = png_pixels + i * row_bytes;
|
|
|
|
|
|
|
|
/* now we can go ahead and just read the whole image */
|
|
|
|
png_read_image (png_ptr, row_pointers);
|
|
|
|
|
|
|
|
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
|
|
|
png_read_end (png_ptr, info_ptr);
|
|
|
|
|
|
|
|
/* clean up after the read, and free any memory allocated - REQUIRED */
|
2018-08-05 21:44:11 -04:00
|
|
|
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
/* write header of PNM file */
|
|
|
|
|
|
|
|
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
|
|
|
|
(color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
|
|
|
{
|
|
|
|
fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2");
|
|
|
|
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
|
|
|
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
|
|
|
}
|
|
|
|
else if ((color_type == PNG_COLOR_TYPE_RGB) ||
|
|
|
|
(color_type == PNG_COLOR_TYPE_RGB_ALPHA))
|
|
|
|
{
|
|
|
|
fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3");
|
|
|
|
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
|
|
|
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write header of PGM file with alpha channel */
|
|
|
|
|
|
|
|
if ((alpha) &&
|
|
|
|
((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
|
|
|
|
(color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
|
|
|
|
{
|
|
|
|
fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2");
|
|
|
|
fprintf (alpha_file, "%d %d\n", (int) width, (int) height);
|
|
|
|
fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write data to PNM file */
|
|
|
|
pix_ptr = png_pixels;
|
|
|
|
|
2014-06-13 12:06:33 -04:00
|
|
|
for (row = 0; row < (int) height; row++)
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
2014-06-13 12:06:33 -04:00
|
|
|
for (col = 0; col < (int) width; col++)
|
1999-10-23 09:39:18 -04:00
|
|
|
{
|
|
|
|
for (i = 0; i < (channels - alpha_present); i++)
|
|
|
|
{
|
|
|
|
if (raw)
|
2018-08-05 21:44:11 -04:00
|
|
|
{
|
|
|
|
fputc ((int) *pix_ptr++, pnm_file);
|
|
|
|
}
|
1999-10-23 09:39:18 -04:00
|
|
|
else
|
2018-08-05 21:44:11 -04:00
|
|
|
{
|
|
|
|
if (bit_depth == 16)
|
|
|
|
{
|
2010-03-15 10:48:37 -04:00
|
|
|
dep_16 = (long) *pix_ptr++;
|
2000-11-10 13:26:19 -05:00
|
|
|
fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++));
|
|
|
|
}
|
1999-10-23 09:39:18 -04:00
|
|
|
else
|
2018-08-05 21:44:11 -04:00
|
|
|
{
|
1999-10-23 09:39:18 -04:00
|
|
|
fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
|
2018-08-05 21:44:11 -04:00
|
|
|
}
|
|
|
|
}
|
1999-10-23 09:39:18 -04:00
|
|
|
}
|
|
|
|
if (alpha_present)
|
|
|
|
{
|
|
|
|
if (!alpha)
|
|
|
|
{
|
|
|
|
pix_ptr++; /* alpha */
|
|
|
|
if (bit_depth == 16)
|
|
|
|
pix_ptr++;
|
|
|
|
}
|
|
|
|
else /* output alpha-channel as pgm file */
|
|
|
|
{
|
|
|
|
if (raw)
|
2018-08-05 21:44:11 -04:00
|
|
|
{
|
|
|
|
fputc ((int) *pix_ptr++, alpha_file);
|
|
|
|
}
|
1999-10-23 09:39:18 -04:00
|
|
|
else
|
2018-08-05 21:44:11 -04:00
|
|
|
{
|
2017-08-11 11:05:53 -04:00
|
|
|
if (bit_depth == 16)
|
|
|
|
{
|
2010-03-15 10:48:37 -04:00
|
|
|
dep_16 = (long) *pix_ptr++;
|
2000-11-10 13:26:19 -05:00
|
|
|
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
|
2011-05-07 11:52:49 -04:00
|
|
|
}
|
1999-10-23 09:39:18 -04:00
|
|
|
else
|
2018-08-05 21:44:11 -04:00
|
|
|
{
|
1999-10-23 09:39:18 -04:00
|
|
|
fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
|
2018-08-05 21:44:11 -04:00
|
|
|
}
|
|
|
|
}
|
1999-10-23 09:39:18 -04:00
|
|
|
}
|
2018-08-05 21:44:11 -04:00
|
|
|
} /* end if alpha_present */
|
1999-10-23 09:39:18 -04:00
|
|
|
|
|
|
|
if (!raw)
|
|
|
|
if (col % 4 == 3)
|
|
|
|
fprintf (pnm_file, "\n");
|
|
|
|
} /* end for col */
|
|
|
|
|
|
|
|
if (!raw)
|
|
|
|
if (col % 4 != 0)
|
|
|
|
fprintf (pnm_file, "\n");
|
|
|
|
} /* end for row */
|
|
|
|
|
2018-08-05 21:44:11 -04:00
|
|
|
if (row_pointers != NULL)
|
1999-10-23 09:39:18 -04:00
|
|
|
free (row_pointers);
|
2018-08-05 21:44:11 -04:00
|
|
|
if (png_pixels != NULL)
|
1999-10-23 09:39:18 -04:00
|
|
|
free (png_pixels);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} /* end of source */
|