pngconf.h 14.7 KB
Newer Older
G
Guy Schalnat 已提交
1 2 3

/* pngconf.c - machine configurable file for libpng

A
Andreas Dilger 已提交
4
   libpng 1.0 beta 6 - version 0.96
G
Guy Schalnat 已提交
5
   For conditions of distribution and use, see copyright notice in png.h
G
Guy Schalnat 已提交
6
   Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
A
Andreas Dilger 已提交
7 8
   Copyright (c) 1996, 1997 Andreas Dilger
   May 12, 1997
G
Guy Schalnat 已提交
9 10 11 12 13 14 15 16 17 18
   */

/* Any machine specific code is near the front of this file, so if you
   are configuring libpng for a machine, you may want to read the section
   starting here down to where it starts to typedef png_color, png_text,
   and png_info */

#ifndef PNGCONF_H
#define PNGCONF_H

A
Andreas Dilger 已提交
19
/* This is the size of the compression buffer, and thus the size of
G
Guy Schalnat 已提交
20 21 22 23 24 25 26 27 28 29 30
   an IDAT chunk.  Make this whatever size you feel is best for your
   machine.  One of these will be allocated per png_struct.  When this
   is full, it writes the data to the disk, and does some other
   calculations.  Making this an extreamly small size will slow
   the library down, but you may want to experiment to determine
   where it becomes significant, if you are concerned with memory
   usage.  Note that zlib allocates at least 32Kb also.  For readers,
   this describes the size of the buffer available to read the data in.
   Unless this gets smaller then the size of a row (compressed),
   it should not make much difference how big this is.  */

G
Guy Schalnat 已提交
31
#define PNG_ZBUF_SIZE 8192
G
Guy Schalnat 已提交
32

A
Andreas Dilger 已提交
33 34 35 36 37 38 39
/* If you are running on a machine where you cannot allocate more
   than 64K of memory at once, uncomment this.  While libpng will not
   normally need that much memory in a chunk (unless you load up a very
   large file), zlib needs to know how big of a chunk it can use, and
   libpng thus makes sure to check any memory allocation to verify it
   will fit into memory.
#define PNG_MAX_MALLOC_64K
G
Guy Schalnat 已提交
40
*/
A
Andreas Dilger 已提交
41 42
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
#define PNG_MAX_MALLOC_64K
G
Guy Schalnat 已提交
43 44
#endif

A
Andreas Dilger 已提交
45
/* This protects us against compilers which run on a windowing system
G
Guy Schalnat 已提交
46 47 48 49
   and thus don't have or would rather us not use the stdio types:
   stdin, stdout, and stderr.  The only one currently used is stderr
   in png_error() and png_warning().  #defining PNG_NO_STDIO will
   prevent these from being compiled and used. */
G
Guy Schalnat 已提交
50 51 52

/* #define PNG_NO_STDIO */

A
Andreas Dilger 已提交
53 54 55 56 57 58 59
/* for FILE.  If you are not using standard io, you don't need this */
#ifndef PNG_NO_STDIO
#include <stdio.h>
#endif

/* This macro protects us against machines that don't have function
   prototypes (ie K&R style headers).  If your compiler does not handle
A
Andreas Dilger 已提交
60 61 62 63
   function prototypes, define this macro and use the included ansi2knr.
   I've always been able to use _NO_PROTO as the indicator, but you may
   need to drag the empty declaration out in front of here, or change the
   ifdef to suit your own needs. */
G
Guy Schalnat 已提交
64 65
#ifndef PNGARG

A
Andreas Dilger 已提交
66
#ifdef OF /* zlib prototype munger */
G
Guy Schalnat 已提交
67 68 69 70
#define PNGARG(arglist) OF(arglist)
#else

#ifdef _NO_PROTO
G
Guy Schalnat 已提交
71
#define PNGARG(arglist) ()
G
Guy Schalnat 已提交
72 73 74 75 76 77 78 79
#else
#define PNGARG(arglist) arglist
#endif /* _NO_PROTO */

#endif /* OF */

#endif /* PNGARG */

A
Andreas Dilger 已提交
80 81 82 83 84
/* Try to determine if we are compiling on a Mac */
#if defined(__MWERKS__) ||defined(applec) ||defined(THINK_C) ||defined(__SC__)
#define MACOS
#endif

G
Guy Schalnat 已提交
85
/* enough people need this for various reasons to include it here */
G
Guy Schalnat 已提交
86
#if !defined(MACOS) && !defined(RISCOS)
G
Guy Schalnat 已提交
87 88
#include <sys/types.h>
#endif
A
Andreas Dilger 已提交
89

A
Andreas Dilger 已提交
90 91
/* This is an attempt to force a single setjmp behaviour on Linux.  If
   the X config stuff didn't define _BSD_SOURCE we wouldn't need this. */
A
Andreas Dilger 已提交
92 93 94 95 96 97
#ifdef linux
#ifdef _BSD_SOURCE
#define _PNG_SAVE_BSD_SOURCE
#undef _BSD_SOURCE
#endif
#ifdef _SETJMP_H
A
Andreas Dilger 已提交
98 99
#error  __png_h_already_includes_setjmp_h__
#error  __dont_include_it_again__
A
Andreas Dilger 已提交
100 101
#endif
#endif /* linux */
G
Guy Schalnat 已提交
102 103 104 105

/* include setjmp.h for error handling */
#include <setjmp.h>

A
Andreas Dilger 已提交
106 107 108 109 110 111 112
#ifdef linux
#ifdef _PNG_SAVE_BSD_SOURCE
#define _BSD_SOURCE
#undef _PNG_SAVE_BSD_SOURCE
#endif
#endif /* linux */

G
Guy Schalnat 已提交
113 114 115 116 117 118
#ifdef BSD
#include <strings.h>
#else
#include <string.h>
#endif

A
Andreas Dilger 已提交
119
/* Other defines for things like memory and the like can go here.  */
G
Guy Schalnat 已提交
120 121
#ifdef PNG_INTERNAL
#include <stdlib.h>
A
Andreas Dilger 已提交
122
/* Where do we need this???
G
Guy Schalnat 已提交
123
#include <ctype.h>
A
Andreas Dilger 已提交
124 125 126 127 128 129 130 131 132 133
*/

/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which
 * aren't usually used outside the library (as far as I know), so it is
 * debatable if they should be exported at all.  In the future, when it is
 * possible to have run-time registry of chunk-handling functions, some of
 * these will be made available again.
#define PNG_EXTERN extern
 */
#define PNG_EXTERN
G
Guy Schalnat 已提交
134

A
Andreas Dilger 已提交
135
/* Other defines specific to compilers can go here.  Try to keep
G
Guy Schalnat 已提交
136 137
   them inside an appropriate ifdef/endif pair for portability */

A
Andreas Dilger 已提交
138 139 140 141 142
#if defined(MACOS)
/* We need to check that <math.h> hasn't already been included earlier
   as it seems it doesn't agree with <fp.h>, yet we should really use
   <fp.h> if possible. */
#if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
A
Andreas Dilger 已提交
143
#include <fp.h>
A
Andreas Dilger 已提交
144
#endif
A
Andreas Dilger 已提交
145 146 147 148 149
#else
#include <math.h>
#endif

/* For some reason, Borland C++ defines memcmp, etc. in mem.h, not
G
Guy Schalnat 已提交
150
   stdlib.h like it should (I think).  Or perhaps this is a C++
A
Andreas Dilger 已提交
151
   "feature"? */
G
Guy Schalnat 已提交
152 153 154 155 156 157 158 159 160
#ifdef __TURBOC__
#include <mem.h>
#include "alloc.h"
#endif

#ifdef _MSC_VER
#include <malloc.h>
#endif

A
Andreas Dilger 已提交
161
/* This controls how fine the dithering gets.  As this allocates
G
Guy Schalnat 已提交
162
   a largish chunk of memory (32K), those who are not as concerned
A
Andreas Dilger 已提交
163
   with dithering quality can decrease some or all of these. */
G
Guy Schalnat 已提交
164 165 166 167
#define PNG_DITHER_RED_BITS 5
#define PNG_DITHER_GREEN_BITS 5
#define PNG_DITHER_BLUE_BITS 5

A
Andreas Dilger 已提交
168
/* This controls how fine the gamma correction becomes when you
G
Guy Schalnat 已提交
169 170
   are only interested in 8 bits anyway.  Increasing this value
   results in more memory being used, and more pow() functions
A
Andreas Dilger 已提交
171
   being called to fill in the gamma tables.  Don't set this
G
Guy Schalnat 已提交
172 173 174 175 176
   value less then 8, and even that may not work (I haven't tested
   it). */

#define PNG_MAX_GAMMA_8 11

A
Andreas Dilger 已提交
177 178 179 180
/* This controls how much a difference in gamma we can tolerate before
   we actually start doing gamma conversion.  */
#define PNG_GAMMA_THRESHOLD 0.05

G
Guy Schalnat 已提交
181 182
#endif /* PNG_INTERNAL */

A
Andreas Dilger 已提交
183
/* The following uses const char * instead of char * for error
G
Guy Schalnat 已提交
184 185 186
   and warning message functions, so some compilers won't complain.
   If you want to use const, define PNG_USE_CONST here.  It is not
   normally defined to make configuration easier, as it is not a
G
Guy Schalnat 已提交
187
   critical part of the code.
G
Guy Schalnat 已提交
188
   */
A
Andreas Dilger 已提交
189
#undef PNG_USE_CONST
A
Andreas Dilger 已提交
190

G
Guy Schalnat 已提交
191 192 193 194 195 196
#ifdef PNG_USE_CONST
#  define PNG_CONST const
#else
#  define PNG_CONST
#endif

A
Andreas Dilger 已提交
197 198 199 200 201 202 203 204 205 206 207 208
/* The following defines give you the ability to remove code from the
   library that you will not be using.  I wish I could figure out how to
   automate this, but I can't do that without making it seriously hard
   on the users.  So if you are not using an ability, change the #define
   to and #undef, and that part of the library will not be compiled.  If
   your linker can't find a function, you may want to make sure the
   ability is defined here.  Some of these depend upon some others being
   defined.  I haven't figured out all the interactions here, so you may
   have to experiment awhile to get everything to compile.  If you are
   creating or using a shared library, you probably shouldn't touch this,
   as it will affect the size of the structures, and this will cause bad
   things to happen if the library and/or application ever change. */
G
Guy Schalnat 已提交
209 210

/* Any transformations you will not be using can be undef'ed here */
G
Guy Schalnat 已提交
211
#define PNG_PROGRESSIVE_READ_SUPPORTED
A
Andreas Dilger 已提交
212
#define PNG_READ_OPT_PLTE_SUPPORTED
G
Guy Schalnat 已提交
213 214 215 216 217 218
#define PNG_READ_INTERLACING_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
#define PNG_READ_BGR_SUPPORTED
#define PNG_READ_SWAP_SUPPORTED
A
Andreas Dilger 已提交
219
#define PNG_READ_PACKSWAP_SUPPORTED
G
Guy Schalnat 已提交
220 221 222 223 224 225 226
#define PNG_READ_INVERT_SUPPORTED
#define PNG_READ_DITHER_SUPPORTED
#define PNG_READ_BACKGROUND_SUPPORTED
#define PNG_READ_16_TO_8_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
A
Andreas Dilger 已提交
227 228
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#define PNG_READ_STRIP_ALPHA_SUPPORTED
G
Guy Schalnat 已提交
229 230 231 232 233 234

#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_BGR_SUPPORTED
#define PNG_WRITE_SWAP_SUPPORTED
A
Andreas Dilger 已提交
235
#define PNG_WRITE_PACKSWAP_SUPPORTED
G
Guy Schalnat 已提交
236
#define PNG_WRITE_INVERT_SUPPORTED
A
Andreas Dilger 已提交
237
#define PNG_WRITE_FILLER_SUPPORTED  /* This is the same as WRITE_STRIP_ALPHA */
G
Guy Schalnat 已提交
238
#define PNG_WRITE_FLUSH_SUPPORTED
A
Andreas Dilger 已提交
239 240 241 242 243 244 245 246 247
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED

/* These are currently experimental features */
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
#undef PNG_READ_COMPOSITE_NODIV_SUPPORTED        /* very little testing */

/* This is only for PowerPC big-endian and 680x0 systems */
#undef PNG_READ_BIG_ENDIAN_SUPPORTED             /* some testing */
G
Guy Schalnat 已提交
248

A
Andreas Dilger 已提交
249 250
/* These functions are turned off by default, as they will be phased out. */
#undef  PNG_USE_OWN_CRC
A
Andreas Dilger 已提交
251
#undef  PNG_USELESS_TESTS_SUPPORTED
A
Andreas Dilger 已提交
252 253
#undef  PNG_CORRECT_PALETTE_SUPPORTED

A
Andreas Dilger 已提交
254 255 256 257 258 259
/* Any chunks you are not interested in, you can undef here.  The
 * ones that allocate memory may be expecially important (hIST,
 * tEXt, zTXt, tRNS, pCAL).  Others will just save time and make png_info
 * a bit smaller.  OPT_PLTE only disables the optional palette in RGB
 * and RGBA images.
 */
G
Guy Schalnat 已提交
260 261

#define PNG_READ_bKGD_SUPPORTED
A
Andreas Dilger 已提交
262 263
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
G
Guy Schalnat 已提交
264 265
#define PNG_READ_hIST_SUPPORTED
#define PNG_READ_oFFs_SUPPORTED
A
Andreas Dilger 已提交
266 267 268
#define PNG_READ_pCAL_SUPPORTED
#define PNG_READ_pHYs_SUPPORTED
#define PNG_READ_sBIT_SUPPORTED
G
Guy Schalnat 已提交
269
#define PNG_READ_tEXt_SUPPORTED
A
Andreas Dilger 已提交
270 271
#define PNG_READ_tIME_SUPPORTED
#define PNG_READ_tRNS_SUPPORTED
G
Guy Schalnat 已提交
272 273 274
#define PNG_READ_zTXt_SUPPORTED

#define PNG_WRITE_bKGD_SUPPORTED
A
Andreas Dilger 已提交
275 276
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
G
Guy Schalnat 已提交
277 278
#define PNG_WRITE_hIST_SUPPORTED
#define PNG_WRITE_oFFs_SUPPORTED
A
Andreas Dilger 已提交
279 280 281
#define PNG_WRITE_pCAL_SUPPORTED
#define PNG_WRITE_pHYs_SUPPORTED
#define PNG_WRITE_sBIT_SUPPORTED
G
Guy Schalnat 已提交
282
#define PNG_WRITE_tEXt_SUPPORTED
A
Andreas Dilger 已提交
283 284
#define PNG_WRITE_tIME_SUPPORTED
#define PNG_WRITE_tRNS_SUPPORTED
G
Guy Schalnat 已提交
285 286
#define PNG_WRITE_zTXt_SUPPORTED

A
Andreas Dilger 已提交
287 288 289 290 291
/* need the time information for reading tIME chunks */
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
#include <time.h>
#endif

A
Andreas Dilger 已提交
292
/* Some typedefs to get us started.  These should be safe on most of the
A
Andreas Dilger 已提交
293 294 295 296 297 298 299
 * common platforms.  The typedefs should be at least as large as the
 * numbers suggest (a png_uint_32 must be at least 32 bits long), but they
 * don't have to be exactly that size.  Some compilers dislike passing
 * unsigned shorts as function parameters, so you may be better off using
 * unsigned int for png_uint_16.  Likewise, for 64-bit systems, you may
 * want to have unsigned int for png_uint_32 instead of unsigned long.
 */
G
Guy Schalnat 已提交
300 301 302 303 304 305 306

typedef unsigned long png_uint_32;
typedef long png_int_32;
typedef unsigned short png_uint_16;
typedef short png_int_16;
typedef unsigned char png_byte;

A
Andreas Dilger 已提交
307
/* This is usually size_t.  It is typedef'ed just in case you need it to
G
Guy Schalnat 已提交
308 309 310
   change (I'm not sure if you will or not, so I thought I'd be safe) */
typedef size_t png_size_t;

A
Andreas Dilger 已提交
311 312 313 314 315 316 317 318
/* The following is needed for medium model support.  It cannot be in the
 * PNG_INTERNAL section.  Needs modification for other compilers besides
 * MSC.  Model independent support declares all arrays and pointers to be
 * large using the far keyword.  The zlib version used must also support
 * model independent data.  As of version zlib 1.0.4, the necessary changes
 * have been made in zlib.  The USE_FAR_KEYWORD define triggers other
 * changes that are needed. (Tim Wegner)
 */
G
Guy Schalnat 已提交
319

A
Andreas Dilger 已提交
320 321
/* Separate compiler dependencies (problem here is that zlib.h always
   defines FAR. (SJT) */
G
Guy Schalnat 已提交
322 323 324
#ifdef __BORLANDC__
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
#define LDATA 1
G
Guy Schalnat 已提交
325
#else
G
Guy Schalnat 已提交
326 327 328 329 330 331 332 333 334 335
#define LDATA 0
#endif

#if !defined(__WIN32__) && !defined(__FLAT__)
#define PNG_MAX_MALLOC_64K
#if (LDATA != 1)
#ifndef FAR
#define FAR __far
#endif
#define USE_FAR_KEYWORD
G
Guy Schalnat 已提交
336
#endif   /* LDATA != 1 */
G
Guy Schalnat 已提交
337

A
Andreas Dilger 已提交
338 339 340
/* Possibly useful for moving data out of default segment.
   Uncomment it if you want. Could also define FARDATA as
   const if your compiler supports it. (SJT)
G
Guy Schalnat 已提交
341 342 343 344
#  define FARDATA FAR
*/
#endif  /* __WIN32__, __FLAT__ */

G
Guy Schalnat 已提交
345
#endif   /* __BORLANDC__ */
G
Guy Schalnat 已提交
346 347


A
Andreas Dilger 已提交
348 349 350
/* Suggest testing for specific compiler first before testing for
   FAR.  The Watcom compiler defines both __MEDIUM__ and M_I86MM,
   making reliance oncertain keywords suspect. (SJT) */
G
Guy Schalnat 已提交
351 352 353 354 355

/* MSC Medium model */
#if defined(FAR)
#  if defined(M_I86MM)
#     define USE_FAR_KEYWORD
A
Andreas Dilger 已提交
356 357
#     define FARDATA FAR
#     include <dos.h>
G
Guy Schalnat 已提交
358 359 360 361 362
#  endif
#endif

/* SJT: default case */
#ifndef FAR
G
Guy Schalnat 已提交
363 364 365
#   define FAR
#endif

A
Andreas Dilger 已提交
366
/* At this point FAR is always defined */
G
Guy Schalnat 已提交
367 368 369 370
#ifndef FARDATA
#define FARDATA
#endif

A
Andreas Dilger 已提交
371
/* Add typedefs for pointers */
A
Andreas Dilger 已提交
372
typedef void            FAR * png_voidp;
G
Guy Schalnat 已提交
373 374 375 376 377 378 379
typedef png_byte        FAR * png_bytep;
typedef png_uint_32     FAR * png_uint_32p;
typedef png_int_32      FAR * png_int_32p;
typedef png_uint_16     FAR * png_uint_16p;
typedef png_int_16      FAR * png_int_16p;
typedef PNG_CONST char  FAR * png_const_charp;
typedef char            FAR * png_charp;
A
Andreas Dilger 已提交
380
typedef double          FAR * png_doublep;
G
Guy Schalnat 已提交
381

A
Andreas Dilger 已提交
382
/* Pointers to pointers; i.e. arrays */
G
Guy Schalnat 已提交
383 384 385 386 387 388 389
typedef png_byte        FAR * FAR * png_bytepp;
typedef png_uint_32     FAR * FAR * png_uint_32pp;
typedef png_int_32      FAR * FAR * png_int_32pp;
typedef png_uint_16     FAR * FAR * png_uint_16pp;
typedef png_int_16      FAR * FAR * png_int_16pp;
typedef PNG_CONST char  FAR * FAR * png_const_charpp;
typedef char            FAR * FAR * png_charpp;
A
Andreas Dilger 已提交
390
typedef double          FAR * FAR * png_doublepp;
G
Guy Schalnat 已提交
391

A
Andreas Dilger 已提交
392 393
/* Pointers to pointers to pointers; i.e. pointer to array */
typedef char            FAR * FAR * FAR * png_charppp;
G
Guy Schalnat 已提交
394

A
Andreas Dilger 已提交
395 396 397 398
/* libpng typedefs for types in zlib. If zlib changes
 * or another compression library is used, then change these.
 * Eliminates need to change all the source files.
 */
G
Guy Schalnat 已提交
399 400
typedef charf *         png_zcharp;
typedef charf * FAR *   png_zcharpp;
A
Andreas Dilger 已提交
401
typedef z_stream FAR *  png_zstreamp; 
G
Guy Schalnat 已提交
402

A
Andreas Dilger 已提交
403 404 405 406 407 408 409 410 411 412
/* allow for compilation as dll under windows */
#ifdef __WIN32DLL__
#define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
#endif

#ifndef PNG_EXPORT
#define PNG_EXPORT(t,s) t s
#endif


G
Guy Schalnat 已提交
413 414
/* User may want to use these so not in PNG_INTERNAL. Any library functions
   that are passed far data must be model independent. */
A
Andreas Dilger 已提交
415

G
Guy Schalnat 已提交
416
#if defined(USE_FAR_KEYWORD)  /* memory model independent fns */
A
Andreas Dilger 已提交
417 418 419 420 421
/* use this to make far-to-near assignments */
#   define CHECK   1
#   define NOCHECK 0
#   define CVT_PTR(ptr) (far_to_near(png_ptr,ptr,CHECK))
#   define CVT_PTR_NOCHECK(ptr) (far_to_near(png_ptr,ptr,NOCHECK))
G
Guy Schalnat 已提交
422
#   define png_strlen _fstrlen
G
Guy Schalnat 已提交
423
#   define png_memcmp _fmemcmp      /* SJT: added */
G
Guy Schalnat 已提交
424 425 426
#   define png_memcpy _fmemcpy
#   define png_memset _fmemset
#else /* use the usual functions */
A
Andreas Dilger 已提交
427 428
#   define CVT_PTR(ptr)         (ptr)
#   define CVT_PTR_NOCHECK(ptr) (ptr)
G
Guy Schalnat 已提交
429
#   define png_strlen strlen
G
Guy Schalnat 已提交
430
#   define png_memcmp memcmp     /* SJT: added */
G
Guy Schalnat 已提交
431 432 433 434 435
#   define png_memcpy memcpy
#   define png_memset memset
#endif
/* End of memory model independent support */

A
Andreas Dilger 已提交
436 437 438 439 440 441 442 443
/* Just a double check that someone hasn't tried to define something
 * contradictory. 
 */
#if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K)
#undef PNG_ZBUF_SIZE
#define PNG_ZBUF_SIZE 65536
#endif

G
Guy Schalnat 已提交
444 445
#endif /* PNGCONF_H */