mirror of
				https://git.code.sf.net/p/libpng/code.git
				synced 2025-07-10 18:04:09 +02:00 
			
		
		
		
	[libpng16] Make all three "make check" test programs work without READ or WRITE
support. Now "make check" will succeed even if libpng is compiled with -DPNG_NO_READ or -DPNG_NO_WRITE. The tests performed are reduced, but the basic reading and writing of a PNG file is always tested by one or more of the tests.
This commit is contained in:
		
							parent
							
								
									26849f4693
								
							
						
					
					
						commit
						e2098ba085
					
				
							
								
								
									
										4
									
								
								ANNOUNCE
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								ANNOUNCE
									
									
									
									
									
								
							@ -433,6 +433,10 @@ Version 1.6.0beta27 [August 10, 2012]
 | 
			
		||||
    for compressed text chunks).
 | 
			
		||||
  Consistently use png_memset(), png_memcpy(), and png_memcmp(), except in
 | 
			
		||||
    pngtest.c and example.c where these macros are not visible.
 | 
			
		||||
  Make all three "make check" test programs work without READ or WRITE support.
 | 
			
		||||
    Now "make check" will succeed even if libpng is compiled with -DPNG_NO_READ
 | 
			
		||||
    or -DPNG_NO_WRITE.  The tests performed are reduced, but the basic reading
 | 
			
		||||
    and writing of a PNG file is always tested by one or more of the tests.
 | 
			
		||||
 | 
			
		||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 | 
			
		||||
(subscription required; visit
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								CHANGES
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								CHANGES
									
									
									
									
									
								
							@ -4184,6 +4184,10 @@ Version 1.6.0beta27 [August 10, 2012]
 | 
			
		||||
    for compressed text chunks).
 | 
			
		||||
  Consistently use png_memset(), png_memcpy(), and png_memcmp(), except in
 | 
			
		||||
    pngtest.c and example.c where these macros are not visible.
 | 
			
		||||
  Make all three "make check" test programs work without READ or WRITE support.
 | 
			
		||||
    Now "make check" will succeed even if libpng is compiled with -DPNG_NO_READ
 | 
			
		||||
    or -DPNG_NO_WRITE.  The tests performed are reduced, but the basic reading
 | 
			
		||||
    and writing of a PNG file is always tested by one or more of the tests.
 | 
			
		||||
 | 
			
		||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 | 
			
		||||
(subscription required; visit
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,7 @@
 | 
			
		||||
#  include "../../png.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED /* Else nothing can be done */
 | 
			
		||||
#include "../tools/sRGB.h"
 | 
			
		||||
 | 
			
		||||
/* KNOWN ISSUES
 | 
			
		||||
@ -3152,6 +3153,7 @@ read_one_file(Image *image)
 | 
			
		||||
   return read_file(image, FORMAT_NO_CHANGE, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
 | 
			
		||||
static int
 | 
			
		||||
write_one_file(Image *output, Image *image, int convert_to_8bit)
 | 
			
		||||
{
 | 
			
		||||
@ -3240,6 +3242,7 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
 | 
			
		||||
      return logerror(output, output->tmpfile_name,
 | 
			
		||||
         ": read of new file failed", "");
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
testimage(Image *image, png_uint_32 opts, format_list *pf)
 | 
			
		||||
@ -3327,8 +3330,10 @@ testimage(Image *image, png_uint_32 opts, format_list *pf)
 | 
			
		||||
         if (!result)
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
         /* Write the *copy* just made to a new file to make sure the write side
 | 
			
		||||
          * works ok.  Check the conversion to sRGB if the copy is linear.
 | 
			
		||||
#        ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
 | 
			
		||||
            /* Write the *copy* just made to a new file to make sure the write
 | 
			
		||||
             * side works ok.  Check the conversion to sRGB if the copy is
 | 
			
		||||
             * linear.
 | 
			
		||||
             */
 | 
			
		||||
            output.opts = opts;
 | 
			
		||||
            result = write_one_file(&output, ©, 0/*convert to 8bit*/);
 | 
			
		||||
@ -3345,15 +3350,16 @@ testimage(Image *image, png_uint_32 opts, format_list *pf)
 | 
			
		||||
            if ((format & PNG_FORMAT_FLAG_LINEAR) != 0 &&
 | 
			
		||||
               (format & PNG_FORMAT_FLAG_COLORMAP) == 0)
 | 
			
		||||
            {
 | 
			
		||||
            /* 'output' is linear, convert to the corresponding sRGB format. */
 | 
			
		||||
               /* 'output' is linear, convert to the corresponding sRGB format.
 | 
			
		||||
                */
 | 
			
		||||
               output.opts = opts;
 | 
			
		||||
               result = write_one_file(&output, ©, 1/*convert to 8bit*/);
 | 
			
		||||
               if (!result)
 | 
			
		||||
                  break;
 | 
			
		||||
 | 
			
		||||
            /* This may involve a conversion via linear; in the ideal world this
 | 
			
		||||
             * would round-trip correctly, but libpng 1.5.7 is not the ideal
 | 
			
		||||
             * world so allow a drift (error_via_linear).
 | 
			
		||||
               /* This may involve a conversion via linear; in the ideal world
 | 
			
		||||
                * this would round-trip correctly, but libpng 1.5.7 is not the
 | 
			
		||||
                * ideal world so allow a drift (error_via_linear).
 | 
			
		||||
                *
 | 
			
		||||
                * 'image' has an alpha channel but 'output' does not then there
 | 
			
		||||
                * will a strip-alpha-channel operation (because 'output' is
 | 
			
		||||
@ -3365,6 +3371,7 @@ testimage(Image *image, png_uint_32 opts, format_list *pf)
 | 
			
		||||
               if (!result)
 | 
			
		||||
                  break;
 | 
			
		||||
            }
 | 
			
		||||
#        endif /* PNG_SIMPLIFIED_WRITE_SUPPORTED */
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      freeimage(&output);
 | 
			
		||||
@ -3400,6 +3407,10 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
 | 
			
		||||
      else
 | 
			
		||||
         printf("FAIL:");
 | 
			
		||||
 | 
			
		||||
#     ifndef PNG_SIMPLIFIED_WRITE_SUPPORTED
 | 
			
		||||
         printf(" (no write)");
 | 
			
		||||
#     endif
 | 
			
		||||
 | 
			
		||||
      print_opts(opts);
 | 
			
		||||
      printf(" %s\n", file_name);
 | 
			
		||||
      /* stdout may not be line-buffered if it is piped to a file, so: */
 | 
			
		||||
@ -3679,3 +3690,11 @@ main(int argc, char **argv)
 | 
			
		||||
 | 
			
		||||
   return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else /* !PNG_SIMPLIFIED_READ_SUPPORTED */
 | 
			
		||||
int main(void)
 | 
			
		||||
{
 | 
			
		||||
   fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,7 @@
 | 
			
		||||
#define _GNU_SOURCE 1 /* For the floating point exception extension */
 | 
			
		||||
 | 
			
		||||
#include <signal.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
 | 
			
		||||
#  include <config.h>
 | 
			
		||||
@ -42,6 +43,8 @@
 | 
			
		||||
#  include "../../png.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_WRITE_SUPPORTED /* else pngvalid can do nothing */
 | 
			
		||||
 | 
			
		||||
#if PNG_LIBPNG_VER < 10500
 | 
			
		||||
/* This deliberately lacks the PNG_CONST. */
 | 
			
		||||
typedef png_byte *png_const_bytep;
 | 
			
		||||
@ -82,10 +85,10 @@ typedef png_byte *png_const_bytep;
 | 
			
		||||
   /* 1.6.0 constifies many APIs, the following exists to allow pngvalid to be
 | 
			
		||||
    * compiled against earlier versions.
 | 
			
		||||
    */
 | 
			
		||||
#  define png_const_strutp png_structp
 | 
			
		||||
#  define png_const_structp png_structp
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "zlib.h"   /* For crc32 */
 | 
			
		||||
#include <zlib.h>   /* For crc32 */
 | 
			
		||||
 | 
			
		||||
#include <float.h>  /* For floating point constants */
 | 
			
		||||
#include <stdlib.h> /* For malloc */
 | 
			
		||||
@ -170,6 +173,7 @@ static PNG_CONST char *colour_types[8] =
 | 
			
		||||
   "grayscale with alpha", invalid, "truecolour with alpha", invalid
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* Convert a double precision value to fixed point. */
 | 
			
		||||
static png_fixed_point
 | 
			
		||||
fix(double d)
 | 
			
		||||
@ -177,6 +181,7 @@ fix(double d)
 | 
			
		||||
   d = floor(d * PNG_FP_1 + .5);
 | 
			
		||||
   return (png_fixed_point)d;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* Generate random bytes.  This uses a boring repeatable algorithm and it
 | 
			
		||||
 * is implemented here so that it gives the same set of numbers on every
 | 
			
		||||
@ -215,6 +220,7 @@ make_four_random_bytes(png_uint_32* seed, png_bytep bytes)
 | 
			
		||||
   make_random_bytes(seed, bytes, 4);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static void
 | 
			
		||||
randomize(void *pv, size_t size)
 | 
			
		||||
{
 | 
			
		||||
@ -243,6 +249,7 @@ random_choice(void)
 | 
			
		||||
 | 
			
		||||
   return x & 1;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* A numeric ID based on PNG file characteristics.  The 'do_interlace' field
 | 
			
		||||
 * simply records whether pngvalid did the interlace itself or whether it
 | 
			
		||||
@ -461,6 +468,7 @@ pixel_copy(png_bytep toBuffer, png_uint_32 toIndex,
 | 
			
		||||
      memmove(toBuffer+(toIndex>>3), fromBuffer+(fromIndex>>3), pixelSize>>3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* Copy a complete row of pixels, taking into account potential partial
 | 
			
		||||
 * bytes at the end.
 | 
			
		||||
 */
 | 
			
		||||
@ -526,6 +534,7 @@ pixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width)
 | 
			
		||||
      return 1+where;
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/*************************** BASIC PNG FILE WRITING ***************************/
 | 
			
		||||
/* A png_store takes data from the sequential writer or provides data
 | 
			
		||||
@ -636,6 +645,7 @@ store_pool_mark(png_bytep mark)
 | 
			
		||||
   make_four_random_bytes(store_seed, mark);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* Use this for random 32 bit values; this function makes sure the result is
 | 
			
		||||
 * non-zero.
 | 
			
		||||
 */
 | 
			
		||||
@ -655,6 +665,7 @@ random_32(void)
 | 
			
		||||
         return result;
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
store_pool_init(png_store *ps, store_pool *pool)
 | 
			
		||||
@ -860,6 +871,7 @@ store_log(png_store* ps, png_const_structp pp, png_const_charp message,
 | 
			
		||||
      store_verbose(ps, pp, is_error ? "error: " : "warning: ", message);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* Internal error function, called with a png_store but no libpng stuff. */
 | 
			
		||||
static void
 | 
			
		||||
internal_error(png_store *ps, png_const_charp message)
 | 
			
		||||
@ -872,6 +884,7 @@ internal_error(png_store *ps, png_const_charp message)
 | 
			
		||||
      Throw ps;
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* Functions to use as PNG callbacks. */
 | 
			
		||||
static void
 | 
			
		||||
@ -1009,6 +1022,7 @@ store_ensure_image(png_store *ps, png_const_structp pp, int nImages,
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static void
 | 
			
		||||
store_image_check(PNG_CONST png_store* ps, png_const_structp pp, int iImage)
 | 
			
		||||
{
 | 
			
		||||
@ -1038,6 +1052,7 @@ store_image_check(PNG_CONST png_store* ps, png_const_structp pp, int iImage)
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
store_write(png_structp ppIn, png_bytep pb, png_size_t st)
 | 
			
		||||
@ -1073,6 +1088,7 @@ store_flush(png_structp ppIn)
 | 
			
		||||
   UNUSED(ppIn) /*DOES NOTHING*/
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static size_t
 | 
			
		||||
store_read_buffer_size(png_store *ps)
 | 
			
		||||
{
 | 
			
		||||
@ -1190,6 +1206,7 @@ store_progressive_read(png_store *ps, png_structp pp, png_infop pi)
 | 
			
		||||
   }
 | 
			
		||||
   while (store_read_buffer_next(ps));
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* The caller must fill this in: */
 | 
			
		||||
static store_palette_entry *
 | 
			
		||||
@ -1216,6 +1233,7 @@ store_write_palette(png_store *ps, int npalette)
 | 
			
		||||
   return ps->palette;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static store_palette_entry *
 | 
			
		||||
store_current_palette(png_store *ps, int *npalette)
 | 
			
		||||
{
 | 
			
		||||
@ -1229,6 +1247,7 @@ store_current_palette(png_store *ps, int *npalette)
 | 
			
		||||
   *npalette = ps->current->npalette;
 | 
			
		||||
   return ps->current->palette;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/***************************** MEMORY MANAGEMENT*** ***************************/
 | 
			
		||||
/* A store_memory is simply the header for an allocated block of memory.  The
 | 
			
		||||
@ -1503,10 +1522,13 @@ set_store_for_write(png_store *ps, png_infopp ppi,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Cleanup when finished reading (either due to error or in the success case).
 | 
			
		||||
 * This routine exists even when there is no read support to make the code
 | 
			
		||||
 * tidier (avoid a mass of ifdefs) and so easier to maintain.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
store_read_reset(png_store *ps)
 | 
			
		||||
{
 | 
			
		||||
#  ifdef PNG_READ_SUPPORTED
 | 
			
		||||
      if (ps->pread != NULL)
 | 
			
		||||
      {
 | 
			
		||||
         anon_context(ps);
 | 
			
		||||
@ -1522,6 +1544,7 @@ store_read_reset(png_store *ps)
 | 
			
		||||
         ps->pread = NULL;
 | 
			
		||||
         ps->piread = NULL;
 | 
			
		||||
      }
 | 
			
		||||
#  endif
 | 
			
		||||
 | 
			
		||||
   /* Always do this to be safe. */
 | 
			
		||||
   store_pool_delete(ps, &ps->read_memory_pool);
 | 
			
		||||
@ -1532,6 +1555,7 @@ store_read_reset(png_store *ps)
 | 
			
		||||
   ps->validated = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static void
 | 
			
		||||
store_read_set(png_store *ps, png_uint_32 id)
 | 
			
		||||
{
 | 
			
		||||
@ -1609,6 +1633,7 @@ set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,
 | 
			
		||||
 | 
			
		||||
   return ps->pread;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* The overall cleanup of a store simply calls the above then removes all the
 | 
			
		||||
 * saved files.  This does not delete the store itself.
 | 
			
		||||
@ -1648,18 +1673,6 @@ typedef struct CIE_color
 | 
			
		||||
   double X, Y, Z;
 | 
			
		||||
} CIE_color;
 | 
			
		||||
 | 
			
		||||
static double
 | 
			
		||||
chromaticity_x(CIE_color c)
 | 
			
		||||
{
 | 
			
		||||
   return c.X / (c.X + c.Y + c.Z);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static double
 | 
			
		||||
chromaticity_y(CIE_color c)
 | 
			
		||||
{
 | 
			
		||||
   return c.Y / (c.X + c.Y + c.Z);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef struct color_encoding
 | 
			
		||||
{
 | 
			
		||||
   /* A description of an (R,G,B) encoding of color (as defined above); this
 | 
			
		||||
@ -1672,6 +1685,19 @@ typedef struct color_encoding
 | 
			
		||||
   CIE_color red, green, blue; /* End points */
 | 
			
		||||
} color_encoding;
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static double
 | 
			
		||||
chromaticity_x(CIE_color c)
 | 
			
		||||
{
 | 
			
		||||
   return c.X / (c.X + c.Y + c.Z);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static double
 | 
			
		||||
chromaticity_y(CIE_color c)
 | 
			
		||||
{
 | 
			
		||||
   return c.Y / (c.X + c.Y + c.Z);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static CIE_color
 | 
			
		||||
white_point(PNG_CONST color_encoding *encoding)
 | 
			
		||||
{
 | 
			
		||||
@ -1743,6 +1769,7 @@ safecat_color_encoding(char *buffer, size_t bufsize, size_t pos,
 | 
			
		||||
 | 
			
		||||
   return pos;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
typedef struct png_modifier
 | 
			
		||||
{
 | 
			
		||||
@ -3121,6 +3148,7 @@ transform_height(png_const_structp pp, png_byte colour_type, png_byte bit_depth)
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* The following can only be defined here, now we have the definitions
 | 
			
		||||
 * of the transform image sizes.
 | 
			
		||||
 */
 | 
			
		||||
@ -3156,6 +3184,7 @@ standard_rowsize(png_const_structp pp, png_uint_32 id)
 | 
			
		||||
   width *= bit_size(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));
 | 
			
		||||
   return (width + 7) / 8;
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
 | 
			
		||||
@ -3464,6 +3493,7 @@ interlace_row(png_bytep buffer, png_const_bytep imageRow,
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
static void
 | 
			
		||||
deinterlace_row(png_bytep buffer, png_const_bytep row,
 | 
			
		||||
   unsigned int pixel_size, png_uint_32 w, int pass)
 | 
			
		||||
@ -3484,6 +3514,7 @@ deinterlace_row(png_bytep buffer, png_const_bytep row,
 | 
			
		||||
      ++xin;
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* Build a single row for the 'size' test images; this fills in only the
 | 
			
		||||
 * first bit_width bits of the sample row.
 | 
			
		||||
@ -3727,6 +3758,7 @@ make_size_images(png_store *ps)
 | 
			
		||||
   make_size(ps, 6, 3, WRITE_BDHI);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* Return a row based on image id and 'y' for checking: */
 | 
			
		||||
static void
 | 
			
		||||
standard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX],
 | 
			
		||||
@ -3738,6 +3770,7 @@ standard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX],
 | 
			
		||||
      size_row(std, WIDTH_FROM_ID(id) * bit_size(pp, COL_FROM_ID(id),
 | 
			
		||||
         DEPTH_FROM_ID(id)), y);
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* Tests - individual test cases */
 | 
			
		||||
/* Like 'make_standard' but errors are deliberately introduced into the calls
 | 
			
		||||
@ -4022,6 +4055,7 @@ perform_formatting_test(png_store *volatile ps)
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED
 | 
			
		||||
/* Because we want to use the same code in both the progressive reader and the
 | 
			
		||||
 * sequential reader it is necessary to deal with the fact that the progressive
 | 
			
		||||
 * reader callbacks only have one parameter (png_get_progressive_ptr()), so this
 | 
			
		||||
@ -9142,6 +9176,7 @@ perform_gamma_test(png_modifier *pm, int summary)
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
 | 
			
		||||
#endif /* PNG_READ_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
/* INTERLACE MACRO VALIDATION */
 | 
			
		||||
/* This is copied verbatim from the specification, it is simply the pass
 | 
			
		||||
@ -9950,7 +9985,9 @@ int main(int argc, char **argv)
 | 
			
		||||
      {
 | 
			
		||||
         perform_interlace_macro_validation();
 | 
			
		||||
         perform_formatting_test(&pm.this);
 | 
			
		||||
#        ifdef PNG_READ_SUPPORTED
 | 
			
		||||
            perform_standard_test(&pm);
 | 
			
		||||
#        endif
 | 
			
		||||
         perform_error_test(&pm);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -9958,7 +9995,9 @@ int main(int argc, char **argv)
 | 
			
		||||
      if (pm.test_size)
 | 
			
		||||
      {
 | 
			
		||||
         make_size_images(&pm.this);
 | 
			
		||||
#        ifdef PNG_READ_SUPPORTED
 | 
			
		||||
            perform_size_test(&pm);
 | 
			
		||||
#        endif
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
 | 
			
		||||
@ -10055,3 +10094,10 @@ int main(int argc, char **argv)
 | 
			
		||||
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
#else /* write not supported */
 | 
			
		||||
int main(void)
 | 
			
		||||
{
 | 
			
		||||
   fprintf(stderr, "pngvalid: no write support in libpng, all tests skipped\n");
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										64
									
								
								pngtest.c
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								pngtest.c
									
									
									
									
									
								
							@ -33,15 +33,22 @@
 | 
			
		||||
 | 
			
		||||
#define _POSIX_SOURCE 1
 | 
			
		||||
 | 
			
		||||
#include "zlib.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
/* Defined so I can write to a file on gui/windowing platforms */
 | 
			
		||||
/*  #define STDERR stderr  */
 | 
			
		||||
#define STDERR stdout   /* For DOS */
 | 
			
		||||
 | 
			
		||||
#include "png.h"
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_SUPPORTED /* else nothing can be done */
 | 
			
		||||
#include "zlib.h"
 | 
			
		||||
/* Copied from pngpriv.h but only used in error messages below. */
 | 
			
		||||
#ifndef PNG_ZBUF_SIZE
 | 
			
		||||
#  define PNG_ZBUF_SIZE 8192
 | 
			
		||||
#endif
 | 
			
		||||
#  include <stdio.h>
 | 
			
		||||
#  include <stdlib.h>
 | 
			
		||||
#  include <string.h>
 | 
			
		||||
#define FCLOSE(file) fclose(file)
 | 
			
		||||
 | 
			
		||||
#ifndef PNG_STDIO_SUPPORTED
 | 
			
		||||
@ -96,10 +103,6 @@ static int warning_count = 0; /* count calls to png_warning */
 | 
			
		||||
#include <mem.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* Defined so I can write to a file on gui/windowing platforms */
 | 
			
		||||
/*  #define STDERR stderr  */
 | 
			
		||||
#define STDERR stdout   /* For DOS */
 | 
			
		||||
 | 
			
		||||
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
 | 
			
		||||
#ifndef png_jmpbuf
 | 
			
		||||
#  define png_jmpbuf(png_ptr) png_ptr->jmpbuf
 | 
			
		||||
@ -134,6 +137,7 @@ read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
 | 
			
		||||
   fprintf(stdout, "r");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_WRITE_SUPPORTED
 | 
			
		||||
static void PNGCBAPI
 | 
			
		||||
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
 | 
			
		||||
{
 | 
			
		||||
@ -142,6 +146,7 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
 | 
			
		||||
 | 
			
		||||
   fprintf(stdout, "w");
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
 | 
			
		||||
@ -272,8 +277,6 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
 | 
			
		||||
}
 | 
			
		||||
#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
static int wrote_question = 0;
 | 
			
		||||
 | 
			
		||||
#ifndef PNG_STDIO_SUPPORTED
 | 
			
		||||
/* START of code to validate stdio-free compilation */
 | 
			
		||||
/* These copies of the default read/write functions come from pngrio.c and
 | 
			
		||||
@ -694,8 +697,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
   int num_pass, pass;
 | 
			
		||||
   int bit_depth, color_type;
 | 
			
		||||
 | 
			
		||||
   char inbuf[256], outbuf[256];
 | 
			
		||||
 | 
			
		||||
   row_buf = NULL;
 | 
			
		||||
 | 
			
		||||
   if ((fpin = fopen(inname, "rb")) == NULL)
 | 
			
		||||
@ -796,8 +797,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
      /* Treat png_benign_error() as errors on read */
 | 
			
		||||
      png_set_benign_errors(read_ptr, 0);
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_WRITE_SUPPORTED
 | 
			
		||||
      /* Treat them as errors on write */
 | 
			
		||||
      png_set_benign_errors(write_ptr, 0);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
      /* if strict is not set, then both are treated as warnings. */
 | 
			
		||||
   }
 | 
			
		||||
@ -1383,22 +1386,25 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
      /* We don't really expect to get here because of the setjmp handling
 | 
			
		||||
       * above, but this is safe.
 | 
			
		||||
       */
 | 
			
		||||
      fprintf(STDERR, "%s: %d libpng errors found (%d warnings)\n",
 | 
			
		||||
      fprintf(STDERR, "\n  %s: %d libpng errors found (%d warnings)",
 | 
			
		||||
         inname, error_count, warning_count);
 | 
			
		||||
 | 
			
		||||
      if (strict != 0)
 | 
			
		||||
         return (1);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
#  ifdef PNG_WRITE_SUPPORTED
 | 
			
		||||
      /* If there we no write support nothing was written! */
 | 
			
		||||
      else if (unsupported_chunks > 0)
 | 
			
		||||
      {
 | 
			
		||||
      fprintf(STDERR, "%s: unsupported chunks (%d)%s\n",
 | 
			
		||||
         fprintf(STDERR, "\n  %s: unsupported chunks (%d)%s",
 | 
			
		||||
            inname, unsupported_chunks, strict ? ": IGNORED --strict!" : "");
 | 
			
		||||
      }
 | 
			
		||||
#  endif
 | 
			
		||||
 | 
			
		||||
   else if (warning_count > 0)
 | 
			
		||||
   {
 | 
			
		||||
      fprintf(STDERR, "%s: %d libpng warnings found\n",
 | 
			
		||||
      fprintf(STDERR, "\n  %s: %d libpng warnings found",
 | 
			
		||||
         inname, warning_count);
 | 
			
		||||
 | 
			
		||||
      if (strict != 0)
 | 
			
		||||
@ -1419,12 +1425,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
      return (1);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
 | 
			
		||||
   {
 | 
			
		||||
      int wrote_question = 0;
 | 
			
		||||
 | 
			
		||||
      for (;;)
 | 
			
		||||
      {
 | 
			
		||||
         png_size_t num_in, num_out;
 | 
			
		||||
         char inbuf[256], outbuf[256];
 | 
			
		||||
 | 
			
		||||
         num_in = fread(inbuf, 1, 1, fpin);
 | 
			
		||||
         num_out = fread(outbuf, 1, 1, fpout);
 | 
			
		||||
 | 
			
		||||
         num_in = fread(inbuf, 1, sizeof inbuf, fpin);
 | 
			
		||||
         num_out = fread(outbuf, 1, sizeof outbuf, fpout);
 | 
			
		||||
 | 
			
		||||
         if (num_in != num_out)
 | 
			
		||||
         {
 | 
			
		||||
@ -1459,7 +1471,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
 | 
			
		||||
         if (memcmp(inbuf, outbuf, num_in))
 | 
			
		||||
         {
 | 
			
		||||
         fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
 | 
			
		||||
            fprintf(STDERR, "\nFiles %s and %s are different\n", inname,
 | 
			
		||||
               outname);
 | 
			
		||||
 | 
			
		||||
            if (wrote_question == 0 && unsupported_chunks == 0)
 | 
			
		||||
            {
 | 
			
		||||
@ -1479,8 +1492,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
 | 
			
		||||
            /* NOTE: the unsupported_chunks escape is permitted here because
 | 
			
		||||
             * unsupported text chunk compression will result in the compression
 | 
			
		||||
          * mode being changed (to NONE) yet, in the test case, the result can
 | 
			
		||||
          * be exactly the same size!
 | 
			
		||||
             * mode being changed (to NONE) yet, in the test case, the result
 | 
			
		||||
             * can be exactly the same size!
 | 
			
		||||
             */
 | 
			
		||||
            if (strict != 0 && unsupported_chunks == 0)
 | 
			
		||||
              return (1);
 | 
			
		||||
@ -1489,6 +1502,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 | 
			
		||||
              return (0);
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
#endif /* PNG_WRITE_SUPPORTED */
 | 
			
		||||
 | 
			
		||||
   FCLOSE(fpin);
 | 
			
		||||
   FCLOSE(fpout);
 | 
			
		||||
@ -1782,6 +1797,15 @@ main(int argc, char *argv[])
 | 
			
		||||
 | 
			
		||||
   return (int)(ierror != 0);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
int
 | 
			
		||||
main(void)
 | 
			
		||||
{
 | 
			
		||||
   fprintf(STDERR,
 | 
			
		||||
      " test ignored because libpng was not built with read support\n");
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* Generate a compiler error if there is an old png.h in the search path. */
 | 
			
		||||
typedef png_libpng_version_1_6_0beta27 Your_png_h_is_not_version_1_6_0beta27;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user