提交 e5a37797 编写于 作者: G Guy Schalnat 提交者: Glenn Randers-Pehrson

Imported from libpng-0.89.tar

上级 b2e01bd5
......@@ -10,7 +10,7 @@ pref = /prefix=all
OBJS = png.obj, pngrcb.obj, pngrutil.obj, pngtrans.obj, pngwutil.obj,\
pngread.obj, pngmem.obj, pngwrite.obj, pngrtran.obj, pngwtran.obj,\
pngio.obj, pngerror.obj, pngpread.obj
pngrio.obj, pngwio.obj, pngerror.obj, pngpread.obj
CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)
......@@ -41,7 +41,8 @@ pngrtran.obj : png.h, pngconf.h
pngrutil.obj : png.h, pngconf.h
pngerror.obj : png.h, pngconf.h
pngmem.obj : png.h, pngconf.h
pngio.obj : png.h, pngconf.h
pngrio.obj : png.h, pngconf.h
pngwio.obj : png.h, pngconf.h
pngtest.obj : png.h, pngconf.h
pngtrans.obj : png.h, pngconf.h
pngwrite.obj : png.h, pngconf.h
......
......@@ -48,47 +48,45 @@ void read_png(char *file_name)
if (!fp)
return;
/* allocate the necessary structures */
png_ptr = malloc(sizeof (png_struct));
/* Create and initialize the png_struct with the desired error handler
functions. If you want to use the default stderr and longjump method,
you can supply NULL for the last three parameters. We also check that
the header file is compatible with the library version.
*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
if (!png_ptr)
{
fclose(fp);
return;
}
info_ptr = malloc(sizeof (png_info));
info_ptr = png_create_info_struct();
if (!info_ptr)
{
fclose(fp);
free(png_ptr);
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return;
}
/* set error handling */
/* set error handling if you are using the setjmp/longjmp method */
if (setjmp(png_ptr->jmpbuf))
{
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fp);
free(png_ptr);
free(info_ptr);
/* If we get here, we had a problem reading the file */
return;
}
/* initialize the structures, info first for error handling */
png_info_init(info_ptr);
png_read_init(png_ptr);
/* set up the input control if you are using standard C streams */
png_init_io(png_ptr, fp);
/* if you are using replacement read functions, here you would call */
png_set_read_fn(png_ptr, (void *)io_ptr, user_read_fn);
/* where io_ptr is a structure you want available to the callbacks */
/* if you are using replacement message functions, here you would call */
png_set_message_fn(png_ptr, (void *)msg_ptr, user_error_fn, user_warning_fn);
/* where msg_ptr is a structure you want available to the callbacks */
/* if you are using replacement read functions, instead of calling
png_init_io() here you would call */
png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
/* where user_io_ptr is a structure you want available to the callbacks */
/* read the file information */
png_read_info(png_ptr, info_ptr);
......@@ -96,29 +94,31 @@ void read_png(char *file_name)
/* set up the transformations you want. Note that these are
all optional. Only call them if you want them */
/* expand paletted colors into true rgb */
/* expand paletted colors into true RGB triplets */
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
/* expand grayscale images to the full 8 bits */
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
info_ptr->bit_depth < 8)
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY && info_ptr->bit_depth < 8)
png_set_expand(png_ptr);
/* expand images with transparency to full alpha channels */
/* expand paletted or RGB images with transparency to full alpha channels
* so the data will be available as RGBA quartets */
if (info_ptr->valid & PNG_INFO_tRNS)
png_set_expand(png_ptr);
/* Set the background color to draw transparent and alpha
images over */
images over. It is possible to set the red, green, and blue
components directly for paletted images. */
png_color_16 my_background;
if (info_ptr->valid & PNG_INFO_bKGD)
png_set_background(png_ptr, &(info_ptr->background),
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
/* tell libpng to handle the gamma conversion for you */
if (info_ptr->valid & PNG_INFO_gAMA)
......@@ -126,18 +126,17 @@ void read_png(char *file_name)
else
png_set_gamma(png_ptr, screen_gamma, 0.45);
/* tell libpng to strip 16 bit depth files down to 8 bits */
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
if (info_ptr->bit_depth == 16)
png_set_strip_16(png_ptr);
/* dither rgb files down to 8 bit palettes & reduce palettes
/* dither rgb files down to 8 bit palette & reduce palettes
to the number of colors available on your screen */
if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
{
if (info_ptr->valid & PNG_INFO_PLTE)
png_set_dither(png_ptr, info_ptr->palette,
info_ptr->num_palette, max_screen_colors,
info_ptr->histogram);
png_set_dither(png_ptr, info_ptr->palette, info_ptr->num_palette,
max_screen_colors, info_ptr->histogram);
else
{
png_color std_color_cube[MAX_SCREEN_COLORS] =
......@@ -148,9 +147,8 @@ void read_png(char *file_name)
}
}
/* invert monocrome files */
if (info_ptr->bit_depth == 1 &&
info_ptr->color_type == PNG_COLOR_GRAY)
/* invert monocrome files to have 0 as white and 1 as black */
if (info_ptr->bit_depth == 1 && info_ptr->color_type == PNG_COLOR_GRAY)
png_set_invert(png_ptr);
/* shift the pixels down to their true bit depth */
......@@ -158,7 +156,8 @@ void read_png(char *file_name)
info_ptr->bit_depth > info_ptr->sig_bit)
png_set_shift(png_ptr, &(info_ptr->sig_bit));
/* pack pixels into bytes */
/* pack multiple pixels with bit depths of 1, 2, and 4 into bytes
(useful only for paletted and grayscale images) */
if (info_ptr->bit_depth < 8)
png_set_packing(png_ptr);
......@@ -171,21 +170,15 @@ void read_png(char *file_name)
if (info_ptr->bit_depth == 16)
png_set_swap(png_ptr);
/* add a filler byte to rgb files */
if (info_ptr->bit_depth == 8 &&
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
/* add a filler byte to RGB files (before or after each RGB triplet) */
if (info_ptr->bit_depth == 8 && info_ptr->color_type == PNG_COLOR_TYPE_RGB)
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
/* turn on interlace handling if you are not using png_read_image() */
if (info_ptr->interlace_type)
number_passes = png_set_interlace_handling(png_ptr);
else
number_passes = 1;
/* optional call to update palette with transformations */
png_start_read_image(png_ptr);
number_passes = png_set_interlace_handling(png_ptr);
/* optional call to update the info structure */
/* optional call to gamma correct and add the background to the palette
and update info structure. */
png_read_update_info(png_ptr, info_ptr);
/* allocate the memory to hold the image using the fields
......@@ -193,6 +186,12 @@ void read_png(char *file_name)
/* the easiest way to read the image */
png_bytep row_pointers[height];
for (row = 0; row < height; row++)
{
row_pointers[row] = malloc(info_ptr->rowbytes);
}
png_read_image(png_ptr, row_pointers);
/* the other way to read images - deal with interlacing */
......@@ -216,16 +215,11 @@ void read_png(char *file_name)
so here */
}
/* read the rest of the file, getting any additional chunks
in info_ptr */
/* read the rest of the file, getting any additional chunks in info_ptr */
png_read_end(png_ptr, info_ptr);
/* clean up after the read, and free any memory allocated */
png_read_destroy(png_ptr, info_ptr, (png_infop)0);
/* free the structures */
free(png_ptr);
free(info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
/* close the file */
fclose(fp);
......@@ -236,68 +230,74 @@ void read_png(char *file_name)
/* progressively read a file */
/* these will normally not be global unless you are only
reading in one image at a time */
png_structp png_ptr;
png_infop info_ptr;
int
initialize_png_reader()
initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
{
png_ptr = malloc(sizeof (png_struct));
if (!png_ptr)
return -1;
info_ptr = malloc(sizeof (png_info));
if (!info_ptr)
/* Create and initialize the png_struct with the desired error handler
functions. If you want to use the default stderr and longjump method,
you can supply NULL for the last three parameters. We also check that
the library version is compatible in case we are using dynamically
linked libraries.
*/
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
if (! *png_ptr)
{
free(png_ptr);
return -1;
*info_ptr = NULL;
return ERROR;
}
if (setjmp(png_ptr->jmpbuf))
*info_ptr = png_create_info_struct(png_ptr);
if (! *info_ptr)
{
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
/* free pointers before returning, if necessary */
free(png_ptr);
free(info_ptr);
return -1;
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
return ERROR;
}
png_info_init(info_ptr);
png_read_init(png_ptr);
if (setjmp((*png_ptr)->jmpbuf))
{
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
return ERROR;
}
/* this one's new. You will need to provide all three
function callbacks, even if you aren't using them all.
You can put a void pointer in place of the NULL, and
retrieve the pointer from inside the callbacks using
the function png_get_progressive_ptr(png_ptr); */
png_set_progressive_read_fn(png_ptr, NULL,
These functions shouldn't be dependent on global or
static variables if you are decoding several images
simultaneously. You should store stream specific data
in a separate struct, given as the second parameter,
and retrieve the pointer from inside the callbacks using
the function png_get_progressive_ptr(png_ptr). */
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
info_callback, row_callback, end_callback);
return 0;
return OK;
}
int
process_data(png_bytep buffer, png_uint_32 length)
process_data(png_structp *png_ptr, png_infop *info_ptr,
png_bytep buffer, png_uint_32 length)
{
if (setjmp(png_ptr->jmpbuf))
if (setjmp((*png_ptr)->jmpbuf))
{
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
free(png_ptr);
free(info_ptr);
return -1;
/* Free the png_ptr and info_ptr memory on error */
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
return ERROR;
}
/* this one's new also. Simply give it a chunk of data
from the file stream (in order, of course). On Segmented
machines, don't give it any more then 64K. The library
seems to run fine with sizes of 4K, although you can give
it much less if necessary (I assume you can give it chunks
of 1 byte, but I haven't tried less then 256 bytes yet).
When this function returns, you may want to display any
rows that were generated in the row callback. */
png_process_data(png_ptr, info_ptr, buffer, length);
return 0;
/* this one's new also. Simply give it chunks of data as
they arrive from the data stream (in order, of course).
On Segmented machines, don't give it any more than 64K.
The library seems to run fine with sizes of 4K, although
you can give it much less if necessary (I assume you can
give it chunks of 1 byte, but I haven't tried with less
than 256 bytes yet). When this function returns, you may
want to display any rows that were generated in the row
callback, if you aren't already displaying them there. */
png_process_data(*png_ptr, *info_ptr, buffer, length);
return OK;
}
info_callback(png_structp png_ptr, png_infop info)
......@@ -363,44 +363,41 @@ void write_png(char *file_name, ... other image information ...)
if (!fp)
return;
/* allocate the necessary structures */
png_ptr = malloc(sizeof (png_struct));
/* Create and initialize the png_struct with the desired error handler
functions. If you want to use the default stderr and longjump method,
you can supply NULL for the last three parameters. We also check that
the library version is compatible in case we are using dynamically
linked libraries.
*/
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
if (!png_ptr)
{
fclose(fp);
return;
}
info_ptr = malloc(sizeof (png_info));
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
fclose(fp);
free(png_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
/* set error handling */
if (setjmp(png_ptr->jmpbuf))
{
png_write_destroy(png_ptr);
fclose(fp);
free(png_ptr);
free(info_ptr);
/* If we get here, we had a problem reading the file */
fclose(fp);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
/* initialize the structures */
png_info_init(info_ptr);
png_write_init(png_ptr);
/* set up the output control if you are using standard C streams */
png_init_io(png_ptr, fp);
/* if you are using replacement write functions, here you would call */
png_set_write_fn(png_ptr, (void *)io_ptr, user_write_fn, user_flush_fn);
/* where io_ptr is a structure you want available to the callbacks */
/* if you are using replacement message functions, here you would call */
png_set_message_fn(png_ptr, (void *)msg_ptr, user_error_fn, user_warning_fn);
/* where msg_ptr is a structure you want available to the callbacks */
......@@ -432,9 +429,9 @@ void write_png(char *file_name, ... other image information ...)
info_ptr->valid |= PNG_INFO_gAMA;
info_ptr->gamma = gamma;
/* other optional chunks */
/* other optional chunks like cHRM, bKGD, tRNS, tEXt, tIME, oFFs, pHYs, */
/* write the file information */
/* write the file header information */
png_write_info(png_ptr, info_ptr);
/* set up the transformations you want. Note that these are
......@@ -466,8 +463,10 @@ void write_png(char *file_name, ... other image information ...)
else
number_passes = 1;
/* the easiest way to write the image */
png_bytep row_pointers[height];
/* the easiest way to write the image (you may choose to allocate the
memory differently, however) */
png_byte row_pointers[height][width];
png_write_image(png_ptr, row_pointers);
/* the other way to write the image - deal with interlacing */
......@@ -485,19 +484,23 @@ void write_png(char *file_name, ... other image information ...)
}
}
/* You can write optional chunks like tEXt, tIME at the end as well.
* Note that if you wrote tEXt or zTXt chunks before the image, and
* you aren't writing out more at the end, you have to set
* info_ptr->num_text = 0 or they will be written out again.
*/
/* write the rest of the file */
png_write_end(png_ptr, info_ptr);
/* clean up after the write, and free any memory allocated */
png_write_destroy(png_ptr);
/* if you malloced the palette, free it here */
if (info_ptr->palette)
free(info_ptr->palette);
/* free the structures */
free(png_ptr);
free(info_ptr);
/* if you allocated any text comments, free them here */
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
/* close the file */
fclose(fp);
......
此差异已折叠。
......@@ -13,8 +13,8 @@ RANLIB=echo
prefix=/usr/local
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
pngmem.o pngerror.o pngpread.o
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o
pngwtran.o pngmem.o pngerror.o pngpread.o
all: libpng.a pngtest
......@@ -45,7 +45,8 @@ clean:
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngio.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngrcb.o: png.h pngconf.h
pngread.o: png.h pngconf.h
......
# Project: libpng
# Toolflags:
CCflags = -c -depend !Depend -IC:,Zlib: -g -throwback -DRISCOS -fnah
C++flags = -c -depend !Depend -IC: -throwback
Linkflags = -aif -c++ -o $@
ObjAsmflags = -throwback -NoCache -depend !Depend
CMHGflags =
LibFileflags = -c -o $@
Squeezeflags = -o $@
# Final targets:
@.libpng-lib: @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \
@.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran @.o.pngrutil \
@.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngwio \
@.o.pngmem @.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran \
@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
@.test: @.tests.pngtest
echo Please run "Test" in directory tests
@.tests.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
# User-editable dependencies:
.c.o:
cc $(ccflags) -o $@ $<
# Static dependencies:
@.o.example: @.tests.c.example
cc $(ccflags) -o @.o.example @.tests.c.example
@.o.pngtest: @.tests.c.pngtest
cc $(ccflags) -o @.o.pngtest @.tests.c.pngtest
# Dynamic dependencies:
o.png: c.png
o.png: h.png
o.png: Zlib:h.zlib
o.png: Zlib:h.zconf
o.png: h.pngconf
o.pngerror: c.pngerror
o.pngerror: h.png
o.pngerror: Zlib:h.zlib
o.pngerror: Zlib:h.zconf
o.pngerror: h.pngconf
o.pngrio: c.pngrio
o.pngrio: h.png
o.pngrio: Zlib:h.zlib
o.pngrio: Zlib:h.zconf
o.pngrio: h.pngconf
o.pngwio: c.pngwio
o.pngwio: h.png
o.pngwio: Zlib:h.zlib
o.pngwio: Zlib:h.zconf
o.pngwio: h.pngconf
o.pngmem: c.pngmem
o.pngmem: h.png
o.pngmem: Zlib:h.zlib
o.pngmem: Zlib:h.zconf
o.pngmem: h.pngconf
o.pngpread: c.pngpread
o.pngpread: h.png
o.pngpread: Zlib:h.zlib
o.pngpread: Zlib:h.zconf
o.pngpread: h.pngconf
o.pngrcb: c.pngrcb
o.pngrcb: h.png
o.pngrcb: Zlib:h.zlib
o.pngrcb: Zlib:h.zconf
o.pngrcb: h.pngconf
o.pngread: c.pngread
o.pngread: h.png
o.pngread: Zlib:h.zlib
o.pngread: Zlib:h.zconf
o.pngread: h.pngconf
o.pngrtran: c.pngrtran
o.pngrtran: h.png
o.pngrtran: Zlib:h.zlib
o.pngrtran: Zlib:h.zconf
o.pngrtran: h.pngconf
o.pngrutil: c.pngrutil
o.pngrutil: h.png
o.pngrutil: Zlib:h.zlib
o.pngrutil: Zlib:h.zconf
o.pngrutil: h.pngconf
o.pngtrans: c.pngtrans
o.pngtrans: h.png
o.pngtrans: Zlib:h.zlib
o.pngtrans: Zlib:h.zconf
o.pngtrans: h.pngconf
o.pngwrite: c.pngwrite
o.pngwrite: h.png
o.pngwrite: Zlib:h.zlib
o.pngwrite: Zlib:h.zconf
o.pngwrite: h.pngconf
o.pngwtran: c.pngwtran
o.pngwtran: h.png
o.pngwtran: Zlib:h.zlib
o.pngwtran: Zlib:h.zconf
o.pngwtran: h.pngconf
o.pngwutil: c.pngwutil
o.pngwutil: h.png
o.pngwutil: Zlib:h.zlib
o.pngwutil: Zlib:h.zconf
o.pngwutil: h.pngconf
o.pngtest: tests.c.pngtest
o.pngtest: h.png
o.pngtest: Zlib:h.zlib
o.pngtest: Zlib:h.zconf
o.pngtest: h.pngconf
......@@ -23,7 +23,7 @@ AR= oml
MKDIR= makedir
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o pngpread.o \
pngread.o pngerror.o pngwrite.o pngrtran.o pngwtran.o pngio.o pngmem.o
pngread.o pngerror.o pngwrite.o pngrtran.o pngwtran.o pngrio.o pngwio.o pngmem.o
all: libpng.lib pngtest
......
......@@ -14,7 +14,7 @@ OBJS = $(LBR)(png.o) $(LBR)(pngrcb.o) $(LBR)(pngrutil.o)\
$(LBR)(pngtrans.o) $(LBR)(pngwutil.o)\
$(LBR)(pngread.o) $(LBR)(pngerror.o) $(LBR)(pngwrite.o)\
$(LBR)(pngrtran.o) $(LBR)(pngwtran.o)\
$(LBR)(pngmem.o) $(LBR)(pngio.o) $(LBR)(pngpread.o)
$(LBR)(pngmem.o) $(LBR)(pngrio.o) $(LBR)(pngwio.o) $(LBR)(pngpread.o)
all: $(LBR) pngtest.ttp
......
......@@ -71,35 +71,35 @@ O=obj
## variables
OBJS = \
png.$(O) \
pngerror.$(O) \
pngmem.$(O) \
pngpread.$(O) \
pngrcb.$(O) \
pngread.$(O) \
pngrio.$(O) \
pngrtran.$(O) \
pngrutil.$(O) \
pngtrans.$(O) \
pngwutil.$(O) \
pngmem.$(O) \
pngread.$(O) \
pngpread.$(O) \
pngerror.$(O) \
pngwrite.$(O) \
pngrtran.$(O) \
pngwtran.$(O) \
pngzlib.$(O) \
pngio.$(O)
pngwio.$(O) \
pngwutil.$(O)
LIBOBJS = \
+png.$(O) \
+pngrcb.$(O) \
+pngrutil.$(O) \
+pngtrans.$(O) \
+pngwutil.$(O) \
+pngerror.$(O) \
+pngmem.$(O) \
+pngpread.$(O) \
+pngread.$(O) \
+pngerror.$(O) \
+pngwrite.$(O) \
+pngrcb.$(O) \
+pngrio.$(O) \
+pngrtran.$(O) \
+pngrutil.$(O) \
+pngtrans.$(O) \
+pngwrite.$(O) \
+pngwtran.$(O) \
+pngzlib.$(O) \
+pngio.$(O)
+pngwio.$(O)
+pngwutil.$(O)
LIBNAME=libpng$(MODEL).lib
......@@ -133,12 +133,12 @@ pngrtran.obj: pngrtran.c
pngrutil.obj: pngrutil.c
pngerror.obj: pngerror.c
pngmem.obj: pngmem.c
pngio.obj: pngio.c
pngrio.obj: pngrio.c
pngwio.obj: pngwio.c
pngtrans.obj: pngtrans.c
pngwrite.obj: pngwrite.c
pngwtran.obj: pngwtran.c
pngwutil.obj: pngwutil.c
pngzlib.obj: pngzlib.c
$(LIBNAME): $(OBJS)
......
......@@ -4,19 +4,19 @@
CC=gcc
CFLAGS=-I../zlib -O2 -Wall -fPIC
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
LDFLAGS=-L. -Wl,-rpath,. -L../zlib/ -Wl,-rpath,../zlib/ -lpng -lz -lm
RANLIB=ranlib
#RANLIB=echo
PNGVER = 0.86
PNGVER = 0.89
# where make install puts libpng.a, libpng.so*, and png.h
prefix=/usr/local
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
pngmem.o pngerror.o pngpread.o
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
pngwtran.o pngmem.o pngerror.o pngpread.o
all: libpng.so pngtest
......@@ -59,7 +59,8 @@ clean:
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngio.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngrcb.o: png.h pngconf.h
pngread.o: png.h pngconf.h
......
......@@ -13,7 +13,7 @@ RANLIB=ranlib
prefix=.
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o pngwtran.o \
pngmem.o pngerror.o pngpread.o
all: libpng.a pngtest
......@@ -35,7 +35,8 @@ clean:
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngio.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngrcb.o: png.h pngconf.h
pngread.o: png.h pngconf.h
......
......@@ -15,8 +15,8 @@ RANLIB=ranlib
prefix=/usr/local
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
pngmem.o pngerror.o pngpread.o
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
pngwtran.o pngmem.o pngerror.o pngpread.o
all: ansi2knr libpng.a pngtest
......@@ -57,7 +57,8 @@ clean:
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngio.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngrcb.o: png.h pngconf.h
pngread.o: png.h pngconf.h
......
......@@ -14,8 +14,8 @@ RANLIB=echo
prefix=/usr/local
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
pngmem.o pngerror.o pngpread.o
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
pngwtran.o pngmem.o pngerror.o pngpread.o
all: libpng.a pngtest
......@@ -46,7 +46,8 @@ clean:
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngio.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngrcb.o: png.h pngconf.h
pngread.o: png.h pngconf.h
......
......@@ -17,7 +17,7 @@ ERRFILE= >> pngerrs
# variables
OBJS1 = png$(O) pngrcb$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) pngmem$(O) pngpread$(O)
OBJS2 = pngread$(O) pngerror$(O) pngwrite$(O) pngrtran$(O) pngwtran$(O) pngio$(O)
OBJS2 = pngread$(O) pngerror$(O) pngwrite$(O) pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
all: libpng.lib
......@@ -45,7 +45,10 @@ pngerror$(O): png.h pngconf.h
pngmem$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
pngio$(O): png.h pngconf.h
pngrio$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
pngwio$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
pngtest$(O): png.h pngconf.h
......
......@@ -13,8 +13,8 @@ RANLIB=echo
prefix=/usr/local
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
pngmem.o pngerror.o pngpread.o
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
pngwtran.o pngmem.o pngerror.o pngpread.o
all: libpng.a pngtest
......@@ -45,7 +45,8 @@ clean:
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngio.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngrcb.o: png.h pngconf.h
pngread.o: png.h pngconf.h
......
......@@ -14,9 +14,9 @@ O=.obj
# variables
OBJS1 = png$(O) pngrcb$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) pngmem$(O) pngpread$(O)
OBJS2 = pngread$(O) pngerror$(O) pngwrite$(O) pngrtran$(O) pngwtran$(O) pngio$(O)
OBJS2 = pngread$(O) pngerror$(O) pngwrite$(O) pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
OBJSL1 = +png$(O) +pngrcb$(O) +pngrutil$(O) +pngtrans$(O) +pngwutil$(O) +pngmem$(O) +pngpread$(O)
OBJSL2 = +pngread$(O) +pngerror$(O) +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) pngio$(O)
OBJSL2 = +pngread$(O) +pngerror$(O) +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O)
all: libpng.lib
......@@ -44,7 +44,10 @@ pngerror$(O): png.h pngconf.h
pngmem$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c
pngio$(O): png.h pngconf.h
pngrio$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c
pngwio$(O): png.h pngconf.h
$(CC) -c $(CFLAGS) $*.c
pngtest$(O): png.h pngconf.h
......
......@@ -52,8 +52,10 @@ $ CALL MAKE pngerror.OBJ "cc ''CCOPT' pngerror" -
pngerror.c png.h pngconf.h
$ CALL MAKE pngmem.OBJ "cc ''CCOPT' pngmem" -
pngmem.c png.h pngconf.h
$ CALL MAKE pngio.OBJ "cc ''CCOPT' pngio" -
pngio.c png.h pngconf.h
$ CALL MAKE pngrio.OBJ "cc ''CCOPT' pngrio" -
pngrio.c png.h pngconf.h
$ CALL MAKE pngwio.OBJ "cc ''CCOPT' pngwio" -
pngwio.c png.h pngconf.h
$ CALL MAKE pngtrans.OBJ "cc ''CCOPT' pngtrans" -
pngtrans.c png.h pngconf.h
$ CALL MAKE pngwrite.OBJ "cc ''CCOPT' pngwrite" -
......
/* png.c - location for general purpose png functions
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
*/
#define PNG_INTERNAL
......@@ -13,7 +13,7 @@
/* version information for c files. This better match the version
string defined in png.h */
char png_libpng_ver[] = "0.88";
char png_libpng_ver[] = "0.89";
/* place to hold the signiture string for a png file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
......@@ -25,39 +25,17 @@ png_byte FARDATA png_IHDR[4] = { 73, 72, 68, 82};
png_byte FARDATA png_IDAT[4] = { 73, 68, 65, 84};
png_byte FARDATA png_IEND[4] = { 73, 69, 78, 68};
png_byte FARDATA png_PLTE[4] = { 80, 76, 84, 69};
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
png_byte FARDATA png_gAMA[4] = {103, 65, 77, 65};
#endif
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
png_byte FARDATA png_sBIT[4] = {115, 66, 73, 84};
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
png_byte FARDATA png_cHRM[4] = { 99, 72, 82, 77};
#endif
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
png_byte FARDATA png_tRNS[4] = {116, 82, 78, 83};
#endif
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
png_byte FARDATA png_bKGD[4] = { 98, 75, 71, 68};
#endif
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
png_byte FARDATA png_hIST[4] = {104, 73, 83, 84};
#endif
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED)
png_byte FARDATA png_tEXt[4] = {116, 69, 88, 116};
#endif
#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
png_byte FARDATA png_zTXt[4] = {122, 84, 88, 116};
#endif
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
png_byte FARDATA png_pHYs[4] = {112, 72, 89, 115};
#endif
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
png_byte FARDATA png_oFFs[4] = {111, 70, 70, 115};
#endif
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
png_byte FARDATA png_tIME[4] = {116, 73, 77, 69};
#endif
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
......@@ -209,6 +187,21 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr,
{
png_ptr->crc = update_crc(png_ptr->crc, ptr, length);
}
png_infop
png_create_info_struct(png_structp png_ptr)
{
png_infop info_ptr;
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
{
png_memset(info_ptr, 0, sizeof(png_info));
png_ptr->do_free |= PNG_FREE_INFO;
}
return info_ptr;
}
void
png_info_init(png_infop info)
{
......@@ -216,3 +209,20 @@ png_info_init(png_infop info)
png_memset(info, 0, sizeof (png_info));
}
/* This function returns a pointer to the io_ptr associated with the user
functions. The application should free any memory associated with this
pointer before png_write_destroy and png_read_destroy are called. */
png_voidp
png_get_io_ptr(png_structp png_ptr)
{
return png_ptr->io_ptr;
}
/* Initialize the default input/output functions for the png file. If you
change the read, or write routines, you can call either png_set_read_fn()
or png_set_write_fn() instead of png_init_io(). */
void
png_init_io(png_structp png_ptr, FILE *fp)
{
png_ptr->io_ptr = (png_voidp)fp;
}
此差异已折叠。
......@@ -74,3 +74,30 @@ version 0.88
fixed progressive bugs
replaced tabs with spaces
cleaned up documentation
added callbacks for read/write and warning/error functions
version 0.89
added new initialization API to make libpng work better with shared libs
we now have png_create_read_struct(), png_create_write_struct(),
png_create_info_struct(), png_destroy_read_struct(), and
png_destroy_write_struct() instead of the separate calls to
malloc and png_read_init(), png_info_init(), and png_write_init()
changed warning/error callback functions to fix bug - this means you
should use the new initialization API if you were using the old
png_set_message_fn() calls, and that the old API no longer exists
so that people are aware that they need to change their code
changed filter selection API to allow selection of multiple filters
since it didn't work in previous versions of libpng anyways
optimized filter selection code
fixed png_set_background() to allow using an arbitrary RGB color for
paletted images
fixed gamma and background correction for paletted images, so
png_correct_palette is not needed unless you are correcting an
external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
in pngconf.h)
fixed bug with Borland 64K memory allocation (Alexander Lehmann)
fixed bug in interlace handling (Smaraderagd, I think)
added more error checking for writing and image to reduce invalid files
separated read and write functions so that they won't both be linked
into a binary when only reading or writing functionality is used
new pngtest image also has interlacing and zTXt
updated dcumentation to reflect new API
/* pngconf.c - machine configurable file for libpng
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
*/
/* Any machine specific code is near the front of this file, so if you
......@@ -78,7 +78,7 @@
#endif /* PNGARG */
/* enough people need this for various reasons to include it here */
#ifndef MACOS
#if !defined(MACOS) && !defined(RISCOS)
#include <sys/types.h>
#endif
/* need the time information for reading tIME chunks */
......@@ -179,6 +179,7 @@
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#undef PNG_CORRECT_PALETTE_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
......
/* pngerror.c - stub functions for i/o and memory allocation
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
This file provides a location for all error handling. Users which
need special error handling are expected to write replacement functions
and use png_set_message_fn() to use those functions. See the instructions
and use png_set_error_fn() to use those functions. See the instructions
at each function. */
#define PNG_INTERNAL
#include "png.h"
static void png_default_error PNGARG((png_structp png_ptr,
png_const_charp message));
static void png_default_warning PNGARG((png_structp png_ptr,
png_const_charp message));
/* This function is called whenever there is a fatal error. This function
should not be changed. If there is a need to handle errors differently,
you should supply a replacement error function and use png_set_message_fn()
you should supply a replacement error function and use png_set_error_fn()
to replace the error function at run-time. */
void
png_error(png_structp png_ptr, png_const_charp message)
......@@ -32,7 +37,7 @@ png_error(png_structp png_ptr, png_const_charp message)
/* This function is called whenever there is a non-fatal error. This function
should not be changed. If there is a need to handle warnings differently,
you should supply a replacement warning function and use
png_set_message_fn() to replace the warning function at run-time. */
png_set_error_fn() to replace the warning function at run-time. */
void
png_warning(png_structp png_ptr, png_const_charp message)
{
......@@ -45,8 +50,8 @@ png_warning(png_structp png_ptr, png_const_charp message)
/* This is the default error handling function. Note that replacements for
this function MUST NOT RETURN, or the program will likely crash. This
function is used by default, or if the program supplies NULL for the
error function pointer in png_set_message_fn(). */
void
error function pointer in png_set_error_fn(). */
static void
png_default_error(png_structp png_ptr, png_const_charp message)
{
#ifndef PNG_NO_STDIO
......@@ -68,7 +73,7 @@ png_default_error(png_structp png_ptr, png_const_charp message)
it can continue anyway. Replacement functions don't have to do anything
here if you don't want to. In the default configuration, png_ptr is
not used, but it is passed in case it may be useful. */
void
static void
png_default_warning(png_structp png_ptr, png_const_charp message)
{
if (!png_ptr)
......@@ -81,27 +86,25 @@ png_default_warning(png_structp png_ptr, png_const_charp message)
/* This function is called when the application wants to use another method
of handling errors and warnings. Note that the error function MUST NOT
return to the calling routine or serious problems will occur. The error
return method used in the default routine calls
longjmp(png_ptr->jmpbuf, 1) */
return to the calling routine or serious problems will occur. The return
method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) */
void
png_set_message_fn(png_structp png_ptr, png_voidp msg_ptr, png_msg_ptr error_fn,
png_msg_ptr warning_fn)
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warning_fn)
{
png_ptr->msg_ptr = msg_ptr;
png_ptr->error_ptr = error_ptr;
png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn;
}
/* This function returns a pointer to the msg_ptr associated with the user
/* This function returns a pointer to the error_ptr associated with the user
functions. The application should free any memory associated with this
pointer before png_write_destroy and png_read_destroy are called. */
png_voidp
png_get_msg_ptr(png_structp png_ptr)
png_get_error_ptr(png_structp png_ptr)
{
return png_ptr->msg_ptr;
return png_ptr->error_ptr;
}
......
/* pngmem.c - stub functions for memory allocation
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
This file provides a location for all memory allocation. Users which
need special memory handling are expected to modify the code in this file
......@@ -17,6 +17,39 @@
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* if you change this, be sure to change the one in png.h also */
/* Allocate memory for a png_struct. The malloc and memset can be replaced
* by a single call to calloc() if this is thought to improve performance.
*/
png_voidp
png_create_struct(uInt type)
{
png_size_t type;
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return (png_voidp)NULL;
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
{
png_memset(struct_ptr, 0, size);
}
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct(png_voidp struct_ptr)
{
if (struct_ptr)
farfree (struct_ptr);
}
/* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell
it not to. See zconf.h and png.h for more information. zlib does
......@@ -27,7 +60,9 @@
It gives you a segment with an offset of 8 (perhaps to store it's
memory stuff). zlib doesn't like this at all, so we have to
detect and deal with it. This code should not be needed in
Windows or OS/2 modes, and only in 16 bit mode.
Windows or OS/2 modes, and only in 16 bit mode. This code has
been updated by Alexander Lehmann for version 0.89 to waste less
memory.
*/
png_voidp
......@@ -35,7 +70,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
if (!png_ptr || !size)
return ((voidp)0);
return ((voidp)NULL);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
......@@ -58,7 +93,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
if (ret)
farfree(ret);
ret = 0;
ret = NULL;
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
if (num_blocks < 1)
......@@ -68,7 +103,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
else
num_blocks++;
total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks;
total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
table = farmalloc(total_size);
......@@ -77,27 +112,25 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
png_error(png_ptr, "Out of Memory");
}
if ((long)table & 0xffff)
if ((long)table & 0xfff0)
{
farfree(table);
total_size += (png_uint_32)65536L;
png_error(png_ptr, "Farmalloc didn't return normalized pointer");
}
table = farmalloc(total_size);
png_ptr->offset_table = table;
png_ptr->offset_table_ptr = farmalloc(
num_blocks * sizeof (png_bytep));
if (!table)
if (!png_ptr->offset_table_ptr)
{
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out of memory");
}
png_ptr->offset_table = table;
png_ptr->offset_table_ptr = farmalloc(
num_blocks * sizeof (png_bytep));
hptr = (png_byte huge *)table;
if ((long)hptr & 0xffff)
if ((long)hptr & 0xf)
{
hptr = (png_byte huge *)((long)(hptr) & 0xffff0000L);
hptr += 65536L;
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
hptr += 16L;
}
for (i = 0; i < num_blocks; i++)
{
......@@ -109,12 +142,12 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
png_ptr->offset_table_count = 0;
png_ptr->offset_table_count_free = 0;
}
}
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
png_error(png_ptr, "Out of Memory");
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
png_error(png_ptr, "Out of Memory");
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
else
ret = farmalloc(size);
......@@ -167,13 +200,63 @@ png_large_free(png_structp png_ptr, png_voidp ptr)
#else /* Not the Borland DOS special memory handler */
/* Allocate memory for a png_struct or a png_info. The malloc and
* memset can be replaced by a single call to calloc() if this is thought
* to improve performance noticably.
*/
png_voidp
png_create_struct(uInt type)
{
size_t size;
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return (png_voidp)NULL;
#if defined(__TURBOC__) && !defined(__FLAT__)
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
if ((struct_ptr = (png_voidp)halloc(size)) != NULL)
# else
if ((struct_ptr = (png_voidp)malloc(size)) != NULL)
# endif
#endif
{
png_memset(struct_ptr, 0, size);
}
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct(png_voidp struct_ptr)
{
if (struct_ptr)
#if defined(__TURBOC__) && !defined(__FLAT__)
farfree(struct_ptr);
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(struct_ptr);
# else
free(struct_ptr);
# endif
#endif
}
/* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell
it not to. See zconf.h and png.h for more information. zlib does
need to allocate exactly 64K, so whatever you call here must
have the ability to do that. */
png_voidp
png_large_malloc(png_structp png_ptr, png_uint_32 size)
{
......@@ -300,4 +383,3 @@ png_free(png_structp png_ptr, void * ptr)
free(ptr);
}
/* pngpread.c - read a png file in push mode
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
*/
#define PNG_INTERNAL
......@@ -41,25 +41,25 @@ png_process_some_data(png_structp png_ptr, png_infop info)
}
case PNG_READ_IDAT_MODE:
{
png_push_read_idat(png_ptr);
png_push_read_IDAT(png_ptr);
break;
}
case PNG_READ_PLTE_MODE:
{
png_push_read_plte(png_ptr, info);
png_push_read_PLTE(png_ptr, info);
break;
}
#if defined(PNG_READ_tEXt_SUPPORTED)
case PNG_READ_tEXt_MODE:
{
png_push_read_text(png_ptr, info);
png_push_read_tEXt(png_ptr, info);
break;
}
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
case PNG_READ_zTXt_MODE:
{
png_push_read_ztxt(png_ptr, info);
png_push_read_zTXt(png_ptr, info);
break;
}
#endif
......@@ -107,7 +107,7 @@ png_push_read_sig(png_structp png_ptr)
void
png_push_read_chunk(png_structp png_ptr, png_infop info)
{
if (!png_ptr->have_chunk_header)
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
{
png_byte chunk_start[8];
......@@ -120,7 +120,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
png_push_fill_buffer(png_ptr, chunk_start, 8);
png_ptr->push_length = png_get_uint_32(chunk_start);
png_memcpy(png_ptr->push_chunk_name, (png_voidp)(chunk_start + 4), 4);
png_ptr->have_chunk_header = 1;
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_start + 4, 4);
}
......@@ -128,7 +128,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
if (!png_memcmp(png_ptr->push_chunk_name, png_IHDR, 4))
{
if (png_ptr->mode != PNG_BEFORE_IHDR)
png_error(png_ptr, "Out of Place IHDR");
png_error(png_ptr, "Out of place IHDR");
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
......@@ -168,7 +168,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
}
else if (!png_memcmp(png_ptr->push_chunk_name, png_IEND, 4))
{
png_error(png_ptr, "No Image in File");
png_error(png_ptr, "No image in file");
}
#if defined(PNG_READ_gAMA_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_gAMA, 4))
......@@ -180,7 +180,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
}
if (png_ptr->mode != PNG_HAVE_IHDR)
png_error(png_ptr, "Out of Place gAMA");
png_error(png_ptr, "Out of place gAMA");
png_handle_gAMA(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -196,7 +196,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
}
if (png_ptr->mode != PNG_HAVE_IHDR)
png_error(png_ptr, "Out of Place sBIT");
png_error(png_ptr, "Out of place sBIT");
png_handle_sBIT(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -212,7 +212,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
}
if (png_ptr->mode != PNG_HAVE_IHDR)
png_error(png_ptr, "Out of Place cHRM");
png_error(png_ptr, "Out of place cHRM");
png_handle_cHRM(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -228,7 +228,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
}
if (png_ptr->mode != PNG_HAVE_IHDR &&
png_ptr->mode != PNG_HAVE_PLTE)
png_error(png_ptr, "Out of Place tRNS");
png_error(png_ptr, "Out of place tRNS");
png_handle_tRNS(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -245,7 +245,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
if (png_ptr->mode != PNG_HAVE_IHDR &&
png_ptr->mode != PNG_HAVE_PLTE)
png_error(png_ptr, "Out of Place bKGD");
png_error(png_ptr, "Out of place bKGD");
png_handle_bKGD(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -261,7 +261,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
}
if (png_ptr->mode != PNG_HAVE_PLTE)
png_error(png_ptr, "Out of Place hIST");
png_error(png_ptr, "Out of place hIST");
png_handle_hIST(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -278,7 +278,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
if (png_ptr->mode != PNG_HAVE_IHDR &&
png_ptr->mode != PNG_HAVE_PLTE)
png_error(png_ptr, "Out of Place pHYs");
png_error(png_ptr, "Out of place pHYs");
png_handle_pHYs(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -295,7 +295,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
if (png_ptr->mode != PNG_HAVE_IHDR &&
png_ptr->mode != PNG_HAVE_PLTE)
png_error(png_ptr, "Out of Place oFFs");
png_error(png_ptr, "Out of place oFFs");
png_handle_oFFs(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -312,7 +312,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
if (png_ptr->mode == PNG_BEFORE_IHDR ||
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place tIME");
png_error(png_ptr, "Out of place tIME");
png_handle_tIME(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -323,7 +323,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
{
if (png_ptr->mode == PNG_BEFORE_IHDR ||
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place tEXt");
png_error(png_ptr, "Out of place tEXt");
png_push_handle_tEXt(png_ptr, png_ptr->push_length);
}
......@@ -333,19 +333,43 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
{
if (png_ptr->mode == PNG_BEFORE_IHDR ||
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place zTXt");
png_error(png_ptr, "Out of place zTXt");
png_push_handle_zTXt(png_ptr, png_ptr->push_length);
}
#endif
else
{
if (png_ptr->push_chunk_name[0] <41 || png_ptr->push_chunk_name[0]> 122 ||
(png_ptr->push_chunk_name[0]>90 && png_ptr->push_chunk_name[0]< 97) ||
png_ptr->push_chunk_name[1] <41 || png_ptr->push_chunk_name[1]> 122 ||
(png_ptr->push_chunk_name[1]>90 && png_ptr->push_chunk_name[1]< 97) ||
png_ptr->push_chunk_name[2] <41 || png_ptr->push_chunk_name[2]> 122 ||
(png_ptr->push_chunk_name[2]>90 && png_ptr->push_chunk_name[2]< 97) ||
png_ptr->push_chunk_name[3] <41 || png_ptr->push_chunk_name[3]> 122 ||
(png_ptr->push_chunk_name[3]>90 && png_ptr->push_chunk_name[3]< 97))
{
char msg[200];
sprintf(msg, "Invalid chunk type 0x%02X 0x%02X 0x%02X 0x%02X",
png_ptr->push_chunk_name[0], png_ptr->push_chunk_name[1],
png_ptr->push_chunk_name[2], png_ptr->push_chunk_name[3]);
png_error(png_ptr, msg);
}
if ((png_ptr->push_chunk_name[0] & 0x20) == 0)
png_error(png_ptr, "Unknown Critical Chunk");
{
char msg[200];
sprintf(msg, "Unknown critical chunk %c%c%c%c",
png_ptr->push_chunk_name[0], png_ptr->push_chunk_name[1],
png_ptr->push_chunk_name[2], png_ptr->push_chunk_name[3]);
png_error(png_ptr, msg);
}
png_push_crc_skip(png_ptr, png_ptr->push_length);
}
png_ptr->have_chunk_header = 0;
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
}
void
......@@ -513,9 +537,9 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
}
void
png_push_read_idat(png_structp png_ptr)
png_push_read_IDAT(png_structp png_ptr)
{
if (!png_ptr->have_chunk_header)
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
{
png_byte chunk_start[8];
......@@ -529,13 +553,13 @@ png_push_read_idat(png_structp png_ptr)
png_ptr->push_length = png_get_uint_32(chunk_start);
png_memcpy(png_ptr->push_chunk_name,
(png_voidp)(chunk_start + 4), 4);
png_ptr->have_chunk_header = 1;
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_start + 4, 4);
if (png_memcmp(png_ptr->push_chunk_name, png_IDAT, 4))
{
png_ptr->process_mode = PNG_READ_END_MODE;
if (!png_ptr->zlib_finished)
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
png_error(png_ptr, "Not enough compressed data");
return;
}
......@@ -585,7 +609,7 @@ png_push_read_idat(png_structp png_ptr)
}
png_push_check_crc(png_ptr);
png_ptr->have_chunk_header = 0;
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
}
}
......@@ -595,7 +619,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
{
int ret;
if (png_ptr->zlib_finished && buffer_length)
if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
png_error(png_ptr, "Extra compression data");
png_ptr->zstream->next_in = buffer;
......@@ -612,11 +636,11 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
png_push_process_row(png_ptr);
}
png_ptr->mode = PNG_AT_LAST_IDAT;
png_ptr->zlib_finished = 1;
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
break;
}
if (ret != Z_OK)
png_error(png_ptr, "Compression Error");
png_error(png_ptr, "Decompression Error");
if (!(png_ptr->zstream->avail_out))
{
png_push_process_row(png_ptr);
......@@ -638,10 +662,9 @@ png_push_process_row(png_structp png_ptr)
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
if (png_ptr->row_buf[0])
png_read_filter_row(&(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_read_filter_row(png_ptr, &(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, (png_size_t)png_ptr->rowbytes + 1);
......@@ -811,7 +834,7 @@ void
png_push_handle_PLTE(png_structp png_ptr, png_uint_32 length)
{
if (length % 3)
png_error(png_ptr, "Invalid Palette Chunk");
png_error(png_ptr, "Invalid palette chunk");
png_ptr->num_palette = (png_uint_16)(length / 3);
png_ptr->cur_palette = 0;
......@@ -821,7 +844,7 @@ png_push_handle_PLTE(png_structp png_ptr, png_uint_32 length)
}
void
png_push_read_plte(png_structp png_ptr, png_infop info)
png_push_read_PLTE(png_structp png_ptr, png_infop info)
{
while (png_ptr->cur_palette < png_ptr->num_palette &&
png_ptr->buffer_size >= 3)
......@@ -862,7 +885,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_uint_32 length)
}
void
png_push_read_text(png_structp png_ptr, png_infop info)
png_push_read_tEXt(png_structp png_ptr, png_infop info)
{
if (png_ptr->buffer_size && png_ptr->current_text_left)
{
......@@ -931,7 +954,7 @@ png_push_handle_zTXt(png_structp png_ptr,
}
void
png_push_read_ztxt(png_structp png_ptr, png_infop info)
png_push_read_zTXt(png_structp png_ptr, png_infop info)
{
if (png_ptr->buffer_size && png_ptr->current_text_left)
{
......@@ -1105,13 +1128,13 @@ png_push_have_row(png_structp png_ptr, png_bytep row)
png_voidp
png_get_progressive_ptr(png_structp png_ptr)
{
return png_ptr->push_ptr;
return png_ptr->io_ptr;
}
void
png_push_read_end(png_structp png_ptr, png_infop info)
{
if (!png_ptr->have_chunk_header)
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
{
png_byte chunk_start[8];
......@@ -1124,23 +1147,23 @@ png_push_read_end(png_structp png_ptr, png_infop info)
png_push_fill_buffer(png_ptr, chunk_start, 8);
png_ptr->push_length = png_get_uint_32(chunk_start);
png_memcpy(png_ptr->push_chunk_name, (png_voidp)(chunk_start + 4), 4);
png_ptr->have_chunk_header = 1;
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_start + 4, 4);
}
if (!png_memcmp(png_ptr->push_chunk_name, png_IHDR, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid IHDR after IDAT");
}
else if (!png_memcmp(png_ptr->push_chunk_name, png_PLTE, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid PLTE after IDAT");
}
else if (!png_memcmp(png_ptr->push_chunk_name, png_IDAT, 4))
{
if (png_ptr->push_length > 0 || png_ptr->mode != PNG_AT_LAST_IDAT)
png_error(png_ptr, "too many IDAT's found");
png_error(png_ptr, "Too many IDAT's found");
}
else if (!png_memcmp(png_ptr->push_chunk_name, png_IEND, 4))
{
......@@ -1159,49 +1182,49 @@ png_push_read_end(png_structp png_ptr, png_infop info)
#if defined(PNG_READ_gAMA_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_gAMA, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid gAMA after IDAT");
}
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_sBIT, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid sBIT after IDAT");
}
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_cHRM, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid cHRM after IDAT");
}
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_tRNS, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid tRNS after IDAT");
}
#endif
#if defined(PNG_READ_bKGD_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_bKGD, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid bKGD after IDAT");
}
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_hIST, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid hIST after IDAT");
}
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_pHYs, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid pHYs after IDAT");
}
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
else if (!png_memcmp(png_ptr->push_chunk_name, png_oFFs, 4))
{
png_error(png_ptr, "invalid chunk after IDAT");
png_error(png_ptr, "Invalid oFFs after IDAT");
}
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
......@@ -1215,7 +1238,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
if (png_ptr->mode == PNG_BEFORE_IHDR ||
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place tIME");
png_error(png_ptr, "Out of place tIME");
png_handle_tIME(png_ptr, info, png_ptr->push_length);
png_push_check_crc(png_ptr);
......@@ -1226,7 +1249,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
{
if (png_ptr->mode == PNG_BEFORE_IHDR ||
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place tEXt");
png_error(png_ptr, "Out of place tEXt");
png_push_handle_tEXt(png_ptr, png_ptr->push_length);
}
......@@ -1236,21 +1259,45 @@ png_push_read_end(png_structp png_ptr, png_infop info)
{
if (png_ptr->mode == PNG_BEFORE_IHDR ||
png_ptr->mode == PNG_AFTER_IEND)
png_error(png_ptr, "Out of Place zTXt");
png_error(png_ptr, "Out of place zTXt");
png_push_handle_zTXt(png_ptr, png_ptr->push_length);
}
#endif
else
{
if (png_ptr->push_chunk_name[0] <41 || png_ptr->push_chunk_name[0]> 122 ||
(png_ptr->push_chunk_name[0]>90 && png_ptr->push_chunk_name[0]< 97) ||
png_ptr->push_chunk_name[1] <41 || png_ptr->push_chunk_name[1]> 122 ||
(png_ptr->push_chunk_name[1]>90 && png_ptr->push_chunk_name[1]< 97) ||
png_ptr->push_chunk_name[2] <41 || png_ptr->push_chunk_name[2]> 122 ||
(png_ptr->push_chunk_name[2]>90 && png_ptr->push_chunk_name[2]< 97) ||
png_ptr->push_chunk_name[3] <41 || png_ptr->push_chunk_name[3]> 122 ||
(png_ptr->push_chunk_name[3]>90 && png_ptr->push_chunk_name[3]< 97))
{
char msg[45];
sprintf(msg, "Invalid chunk type 0x%02X 0x%02X 0x%02X 0x%02X",
png_ptr->push_chunk_name[0], png_ptr->push_chunk_name[1],
png_ptr->push_chunk_name[2], png_ptr->push_chunk_name[3]);
png_error(png_ptr, msg);
}
if ((png_ptr->push_chunk_name[0] & 0x20) == 0)
png_error(png_ptr, "Unknown Critical Chunk");
{
char msg[40];
sprintf(msg, "Unknown critical chunk %c%c%c%c",
png_ptr->push_chunk_name[0], png_ptr->push_chunk_name[1],
png_ptr->push_chunk_name[2], png_ptr->push_chunk_name[3]);
png_error(png_ptr, msg);
}
png_push_crc_skip(png_ptr, png_ptr->push_length);
}
if (png_ptr->mode == PNG_AT_LAST_IDAT)
png_ptr->mode = PNG_AFTER_IDAT;
png_ptr->have_chunk_header = 0;
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
}
void
......@@ -1260,9 +1307,9 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
{
png_ptr->info_fn = info_fn;
png_ptr->row_fn = row_fn;
png_ptr->push_ptr = progressive_ptr;
png_ptr->end_fn = end_fn;
png_ptr->read_mode = PNG_READ_PUSH_MODE;
png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
}
void
......
/* pngrcb.c - callbacks while reading a png file
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
*/
#define PNG_INTERNAL
......@@ -185,7 +185,7 @@ png_read_tIME(png_structp png_ptr, png_infop info,
}
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
void
png_read_zTXt(png_structp png_ptr, png_infop info,
png_charp key, png_charp text, png_uint_32 text_len, int compression)
......@@ -214,10 +214,10 @@ png_read_zTXt(png_structp png_ptr, png_infop info,
}
else
{
info->max_text = info->num_text + 16;
info->max_text = 16;
info->num_text = 0;
info->text = (png_textp)png_large_malloc(png_ptr,
info->max_text * sizeof (png_text));
info->num_text = 0;
}
}
......
此差异已折叠。
/* pngrio.c - functions for data input
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
This file provides a location for all input. Users which need
special handling are expected to write a function which has the same
arguments as this, and perform a similar function, but possibly has
a different input method. Note that you shouldn't change this
function, but rather write a replacement function and then make
libpng use it at run time with png_set_read_fn(...) */
#define PNG_INTERNAL
#include "png.h"
/* Read the data from whatever input you are using. The default routine
reads from a file pointer. Note that this routine sometimes gets called
with very small lengths, so you should implement some kind of simple
buffering if you are using unbuffered reads. This should never be asked
to read more then 64K on a 16 bit machine. The cast to png_size_t is
there to quiet some compilers */
void
png_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
if (png_ptr->read_data_fn)
(*(png_ptr->read_data_fn))(png_ptr, data, length);
else
png_error(png_ptr, "Call to NULL read function");
}
/* This is the function which does the actual reading of data. If you are
not reading from a standard C stream, you should create a replacement
read_data function and use it at run time with png_set_read_fn(), rather
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
png_uint_32 check;
check = fread(data, 1, (size_t)length, (FILE *)png_ptr->io_ptr);
if (check != length)
{
png_error(png_ptr, "Read Error");
}
}
#else
/* this is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy
the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
#ifdef _MSC_VER
/* for FP_OFF */
#include <dos.h>
#endif
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
png_uint_32 check;
png_byte *n_data;
/* Check if data really is near. If so, use usual code. */
#ifdef _MSC_VER
/* do it this way just to quiet warning */
FP_OFF(n_data) = FP_OFF(data);
if (FP_SEG(n_data) == FP_SEG(data))
#else
/* this works in MSC also but with lost segment warning */
n_data = (png_byte *)data;
if ((png_bytep)n_data == data)
#endif
{
check = fread(n_data, 1, (size_t)length, (FILE *)png_ptr->io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t read, remaining, err;
check = 0;
remaining = (png_size_t)length;
do
{
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, 1, read, (FILE *)png_ptr->io_ptr);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if(err != read)
break;
else
check += err;
data += read;
remaining -= read;
}
while (remaining != 0);
}
if (check != length)
{
png_error(png_ptr, "read Error");
}
}
#endif
/* This function allows the application to supply a new input function
for libpng if standard C streams aren't being used.
This function takes as its arguments:
png_ptr - pointer to a png input data structure
io_ptr - pointer to user supplied structure containing info about
the input functions. May be NULL.
read_data_fn - pointer to a new input function which takes as it's
arguments a pointer to a png_struct, a pointer to
a location where input data can be stored, and a 32-bit
unsigned int which is the number of bytes to be read.
To exit and output any fatal error messages the new write
function should call png_error(png_ptr, "Error msg"). */
void
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn)
{
png_ptr->io_ptr = io_ptr;
if (read_data_fn)
png_ptr->read_data_fn = read_data_fn;
else
png_ptr->read_data_fn = png_default_read_data;
/* It is an error to write to a read device */
png_ptr->write_data_fn = NULL;
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
png_ptr->output_flush_fn = NULL;
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
}
此差异已折叠。
此差异已折叠。
/* pngtest.c - a simple test program to test libpng
libpng 1.0 beta 2 - version 0.87
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 15, 1996
May 25, 1996
*/
#include <stdio.h>
......@@ -19,27 +19,31 @@
#define STDERR stdout /* for DOS */
/* input and output filenames */
char inname[] = "pngtest.png";
char outname[] = "pngout.png";
png_struct read_ptr;
png_struct write_ptr;
png_info info_ptr;
png_info end_info;
#ifdef RISCOS
char *inname = "pngtest_pn";
char *outname = "pngout_png";
#else
char *inname = "pngtest.png";
char *outname = "pngout.png";
#endif
char inbuf[256], outbuf[256];
int main()
int main(int argc, char *argv[])
{
FILE *fpin, *fpout;
png_structp read_ptr;
png_structp write_ptr;
png_infop info_ptr;
png_infop end_info;
png_bytep row_buf;
png_byte * near_row_buf;
png_byte *near_row_buf;
png_uint_32 rowbytes;
png_uint_32 y;
int channels, num_pass, pass;
row_buf = (png_bytep)0;
near_row_buf = (png_byte *)0;
row_buf = (png_bytep)NULL;
near_row_buf = (png_byte *)NULL;
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
......@@ -51,6 +55,18 @@ int main()
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
}
if (argc > 1)
inname = argv[1];
if (argc > 2)
outname = argv[2];
if (argc > 3)
{
fprintf(stderr, "usage: %s [infile.png] [outfile.png]\n", argv[0]);
exit(1);
}
fpin = fopen(inname, "rb");
if (!fpin)
{
......@@ -61,62 +77,68 @@ int main()
fpout = fopen(outname, "wb");
if (!fpout)
{
fprintf(STDERR, "could not open output file %s\n", outname);
fprintf(STDERR, "Could not open output file %s\n", outname);
fclose(fpin);
return 1;
}
if (setjmp(read_ptr.jmpbuf))
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (void *)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
info_ptr = png_create_info_struct(read_ptr);
end_info = png_create_info_struct(read_ptr);
if (setjmp(read_ptr->jmpbuf))
{
fprintf(STDERR, "libpng read error\n");
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
fclose(fpin);
fclose(fpout);
return 1;
}
if (setjmp(write_ptr.jmpbuf))
if (setjmp(write_ptr->jmpbuf))
{
fprintf(STDERR, "libpng write error\n");
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
fclose(fpin);
fclose(fpout);
return 1;
}
png_read_init(&read_ptr);
png_write_init(&write_ptr);
png_info_init(&info_ptr);
png_info_init(&end_info);
png_init_io(&read_ptr, fpin);
png_init_io(&write_ptr, fpout);
png_init_io(read_ptr, fpin);
png_init_io(write_ptr, fpout);
png_read_info(&read_ptr, &info_ptr);
png_write_info(&write_ptr, &info_ptr);
png_read_info(read_ptr, info_ptr);
png_write_info(write_ptr, info_ptr);
if ((info_ptr.color_type & 3) == 2)
channels = 3;
else
if ((info_ptr->color_type & PNG_COLOR_TYPE_PALETTE)==PNG_COLOR_TYPE_PALETTE)
channels = 1;
if (info_ptr.color_type & 4)
else
channels = 3;
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
channels++;
rowbytes = ((info_ptr.width * info_ptr.bit_depth * channels + 7) >> 3);
rowbytes = ((info_ptr->width * info_ptr->bit_depth * channels + 7) >> 3);
near_row_buf = (png_byte *)malloc((size_t)rowbytes);
row_buf = (png_bytep)near_row_buf;
if (!row_buf)
{
fprintf(STDERR, "no memory to allocate row buffer\n");
png_read_destroy(&read_ptr, &info_ptr, (png_infop )0);
png_write_destroy(&write_ptr);
fprintf(STDERR, "No memory to allocate row buffer\n");
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
fclose(fpin);
fclose(fpout);
return 1;
}
if (info_ptr.interlace_type)
if (info_ptr->interlace_type)
{
num_pass = png_set_interlace_handling(&read_ptr);
num_pass = png_set_interlace_handling(&write_ptr);
num_pass = png_set_interlace_handling(read_ptr);
num_pass = png_set_interlace_handling(write_ptr);
}
else
{
......@@ -125,21 +147,21 @@ int main()
for (pass = 0; pass < num_pass; pass++)
{
for (y = 0; y < info_ptr.height; y++)
for (y = 0; y < info_ptr->height; y++)
{
#ifdef TESTING
fprintf(STDERR, "Processing line #%ld\n", y);
#endif
png_read_rows(&read_ptr, (png_bytepp)&row_buf, (png_bytepp)0, 1);
png_write_rows(&write_ptr, (png_bytepp)&row_buf, 1);
png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)0, 1);
png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
}
}
png_read_end(&read_ptr, &end_info);
png_write_end(&write_ptr, &end_info);
png_read_end(read_ptr, end_info);
png_write_end(write_ptr, end_info);
png_read_destroy(&read_ptr, &info_ptr, &end_info);
png_write_destroy(&write_ptr);
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
fclose(fpin);
fclose(fpout);
......@@ -150,14 +172,14 @@ int main()
if (!fpin)
{
fprintf(STDERR, "could not find file %s\n", inname);
fprintf(STDERR, "Could not find file %s\n", inname);
return 1;
}
fpout = fopen(outname, "rb");
if (!fpout)
{
fprintf(STDERR, "could not find file %s\n", outname);
fprintf(STDERR, "Could not find file %s\n", outname);
fclose(fpin);
return 1;
}
......@@ -171,7 +193,8 @@ int main()
if (num_in != num_out)
{
fprintf(STDERR, "files are of a different size\n");
fprintf(STDERR, "Files %s and %s are of a different size\n",
inname, outname);
fclose(fpin);
fclose(fpout);
return 1;
......@@ -182,7 +205,7 @@ int main()
if (memcmp(inbuf, outbuf, num_in))
{
fprintf(STDERR, "files are different\n");
fprintf(STDERR, "Files %s and %s are different\n", inname, outname);
fclose(fpin);
fclose(fpout);
return 1;
......
pngtest.png

7.0 KB | W: | H:

pngtest.png

8.7 KB | W: | H:

pngtest.png
pngtest.png
pngtest.png
pngtest.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -8,6 +8,8 @@ for 0.9
after 1.0
overlaying one image on top of another
make pull reader use push reader internally to reduce code, and
increase amount of image read in an error situation
optional palette creation
histogram creation
text conversion between different code types
......
......@@ -2,10 +2,10 @@
/* pngtrans.c - transforms the data in a row
routines used by both readers and writers
libpng 1.0 beta 2 - version 0.88
libpng 1.0 beta 3 - version 0.89
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 25, 1996
May 25, 1996
*/
#define PNG_INTERNAL
......@@ -72,7 +72,11 @@ png_set_filler(png_structp png_ptr, int filler, int filler_loc)
{
png_ptr->transformations |= PNG_FILLER;
png_ptr->filler = (png_byte)filler;
png_ptr->filler_loc = (png_byte)filler_loc;
if (filler_loc == PNG_FILLER_AFTER)
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
else
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB &&
png_ptr->bit_depth == 8)
png_ptr->usr_channels = 4;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册