Skip to content

Commit

Permalink
rwpng update
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Dec 12, 2011
1 parent 0315c34 commit 3c72382
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
23 changes: 7 additions & 16 deletions rwpng.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "png.h" /* libpng header; includes zlib.h */
#include "rwpng.h" /* typedefs, common macros, public prototypes */

#include "png.h"
#include "zlib.h"
#include "rwpng.h"

static void rwpng_error_handler(png_structp png_ptr, png_const_charp msg);

Expand Down Expand Up @@ -91,13 +92,6 @@ pngquant_error rwpng_read_image(FILE *infile, read_info *mainprog_ptr)
return PNG_OUT_OF_MEMORY_ERROR; /* out of memory */
}


/* GRR TO DO: use end_info struct */
/* we could create a second info struct here (end_info), but it's only
* useful if we want to keep pre- and post-IDAT chunk info separated
* (mainly for PNG-aware image editors and converters) */


/* setjmp() must be called in every function that calls a non-trivial
* libpng function */

Expand Down Expand Up @@ -125,10 +119,7 @@ pngquant_error rwpng_read_image(FILE *infile, read_info *mainprog_ptr)
* transparency chunks to full alpha channel; strip 16-bit-per-sample
* images to 8 bits per sample; and convert grayscale to RGB[A] */

/* GRR TO DO: handle each of GA, RGB, RGBA without conversion to RGBA */
/* GRR TO DO: allow sub-8-bit quantization? */
/* GRR TO DO: preserve all safe-to-copy ancillary PNG chunks */
/* GRR TO DO: get and map background color? */

if (!(color_type & PNG_COLOR_MASK_ALPHA)) {
/* GRP: expand palette to RGB, and grayscale or RGB to GA or RGBA */
Expand All @@ -142,10 +133,9 @@ pngquant_error rwpng_read_image(FILE *infile, read_info *mainprog_ptr)
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
*/
/* GRR TO DO: handle 16-bps data natively? */
if (bit_depth == 16)
png_set_strip_16(png_ptr);
/* GRR TO DO: probably want to handle this separately, without expansion */

if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
Expand All @@ -157,6 +147,8 @@ pngquant_error rwpng_read_image(FILE *infile, read_info *mainprog_ptr)
mainprog_ptr->gamma = 0.45455;
}

png_set_interlace_handling(png_ptr);

/* all transformations have been registered; now update info_ptr data,
* get rowbytes and channels, and allocate image memory */

Expand All @@ -178,7 +170,6 @@ pngquant_error rwpng_read_image(FILE *infile, read_info *mainprog_ptr)
return PNG_OUT_OF_MEMORY_ERROR;
}


/* set the individual row_pointers to point at the correct offsets */

for (i = 0; i < mainprog_ptr->height; ++i)
Expand Down
21 changes: 7 additions & 14 deletions rwpng.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,32 @@
---------------------------------------------------------------------------*/

#include "png.h" /* libpng header; includes zlib.h */

#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif

#ifndef MAX
# define MAX(a,b) ((a) > (b)? (a) : (b))
# define MIN(a,b) ((a) < (b)? (a) : (b))
#endif

#ifdef DEBUG
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
#else
# define Trace(x) ;
#endif

#include <setjmp.h>

typedef enum {
SUCCESS = 0,
MISSING_ARGUMENT = 1,
READ_ERROR = 2,
INVALID_ARGUMENT = 4,
TOO_MANY_COLORS = 5,
TOO_LOW_QUALITY = 6,
NOT_OVERWRITING_ERROR = 15,
CANT_WRITE_ERROR = 16,
OUT_OF_MEMORY_ERROR = 17,
WRONG_ARCHITECTURE = 18, // Missing SSE3
PNG_OUT_OF_MEMORY_ERROR = 24,
INIT_OUT_OF_MEMORY_ERROR = 34,
INTERNAL_LOGIC_ERROR = 18,
BAD_SIGNATURE_ERROR = 21,
LIBPNG_FATAL_ERROR = 25,
LIBPNG_INIT_ERROR = 35,
LIBPNG_WRITE_ERROR = 55,
LIBPNG_WRITE_WHOLE_ERROR = 45,

} pngquant_error;

typedef struct {
Expand Down

0 comments on commit 3c72382

Please sign in to comment.