home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / include / pbmplus.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-10  |  6.1 KB  |  188 lines

  1. /* pbmplus.h - header file for PBM, PGM, PPM, and PNM
  2. *
  3. * Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
  4. *
  5. * Permission to use, copy, modify, and distribute this software and its
  6. * documentation for any purpose and without fee is hereby granted, provided
  7. * that the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation.  This software is provided "as is" without express or
  10. * implied warranty.
  11. */
  12.  
  13. #ifndef _PBMPLUS_H_
  14. #define _PBMPLUS_H_
  15.  
  16. #include <sys/types.h>
  17. #include <ctype.h>
  18. #include "stdef.h"
  19.  
  20. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS))
  21. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  22. ** System V site, set the SYSV option; and if you're IBM-compatible, set
  23. ** MSDOS.  If your compiler is ANSI C, you're probably better off setting
  24. ** SYSV.
  25. */
  26. #define BSD
  27. /* #define SYSV */
  28. /* #define MSDOS */
  29. #endif
  30.  
  31. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  32. ** "Raw" files are smaller, and much faster to read and write, but you
  33. ** must have a filesystem that allows all 256 ASCII characters to be read
  34. ** and written.  You will no longer be able to mail P?M files without 
  35. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  36. ** Note that reading "raw" files works whether writing is enabled or not.
  37. */
  38. #define PBMPLUS_RAWBITS
  39.  
  40. /* CONFIGURE: On some systems, the putc() macro is broken and will return
  41. ** EOF when you write out a 255.  For example, ULTRIX does this.  This
  42. ** only matters if you have defined RAWBITS.  To test whether your system
  43. ** is broken this way, go ahead and compile things with RAWBITS defined,
  44. ** and then try "pbmmake -b 8 1 > file".  If it works, fine.  If not,
  45. ** define BROKENPUTC1 and try again - if that works, good.  Otherwise,
  46. ** BROKENPUTC2 is guaranteed to work, although it's about twice as slow.
  47. */
  48. /* #define PBMPLUS_BROKENPUTC1 */
  49. /* #define PBMPLUS_BROKENPUTC2 */
  50.  
  51. #ifdef PBMPLUS_BROKENPUTC1
  52. #undef putc
  53. /* This is a fixed version of putc() that should work on most Unix systems. */
  54. #define putc(x,p) (--(p)->_cnt>=0? ((int)(unsigned char)(*(p)->_ptr++=(unsigned char)(x))) : _flsbuf((unsigned char)(x),p))
  55. #endif /*PBMPLUS_BROKENPUTC1*/
  56. #ifdef PBMPLUS_BROKENPUTC2
  57. #undef putc
  58. /* For this one, putc() becomes a function, defined in pbm/libpbm1.c. */
  59. #endif /*PBMPLUS_BROKENPUTC2*/
  60.  
  61. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  62. ** applications, bytes will be big enough, and the memory savings can be
  63. ** substantial.  However, if you need more than 8 bits of resolution, then
  64. ** define this symbol.
  65. **
  66. ** If you are not making PGM, you can ignore this.
  67. */
  68. /* #define PGM_BIGGRAYS */
  69.  
  70. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  71. ** It can also be configured to pack the three values into a single longword,
  72. ** 10 bits each.  If you have configured PGM with the PGM_BIGGRAYS option
  73. ** (store grays as shorts), AND you don't need more than 10 bits for each
  74. ** color component, AND you care more about memory use than speed, then
  75. ** this option might be a win.  Under these circumstances it will make
  76. ** some of the programs use 1.5 times less space,  but all of the programs
  77. ** will run about 1.4 times slower.
  78. **
  79. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  80. ** doesn't save any space, but it still slows things down.
  81. **
  82. ** If you are not making PPM, you can ignore this.
  83. */
  84. /* #define PPM_PACKCOLORS */
  85.  
  86. /* CONFIGURE: uncomment this to enable debugging checks. */
  87. /* #define DEBUG */
  88.  
  89. #ifdef SYSV
  90. #include <string.h>
  91. #define index strchr
  92. #define rindex strrchr
  93. #define srandom srand
  94. #define random rand
  95. #define bzero(dst,len) memset(dst, 0, len)
  96. #define bcopy(src,dst,len) memcpy(dst, src, len)
  97. #define bcmp memcmp
  98. #endif /*SYSV*/
  99.  
  100. extern    int    debug;
  101.  
  102. /* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
  103. ** to do it.  On other systems, for example HP/UX, it declares them
  104. ** incompatibly.  And some systems, for example Dynix, don't have a
  105. ** malloc.h at all.  A sad situation.  If you have compilation problems
  106. ** that point here, feel free to tweak or remove these declarations.
  107. */
  108. #ifndef    TC_Need
  109. #include <malloc.h>
  110. #endif
  111.  
  112. /* End of configurable definitions. */
  113.  
  114. /*    What hell here ?
  115. #undef max
  116. #define max(a,b) ((a) > (b) ? (a) : (b))
  117. #undef min
  118. #define min(a,b) ((a) < (b) ? (a) : (b))
  119. #undef abs
  120. #define abs(a) ((a) >= 0 ? (a) : -(a))
  121. */
  122.  
  123. #undef odd
  124. #define odd(n) ((n) & 1)
  125.  
  126. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  127.  
  128. #ifdef __STDC__
  129. #define ARGS(alist) alist
  130. #else /*__STDC__*/
  131. #define ARGS(alist) ()
  132. #define const
  133. #endif /*__STDC__*/
  134.  
  135.  
  136. /* Initialization. */
  137.  
  138. void pm_init ARGS(( int* argcP, char* argv[] ));
  139.  
  140.  
  141. /* Variable-sized arrays definitions. */
  142.  
  143. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  144. char* pm_allocrow ARGS(( int cols, int size ));
  145. void pm_freearray ARGS(( char** its, int rows ));
  146. void pm_freerow ARGS(( char* itrow ));
  147.  
  148.  
  149. /* Case-insensitive keyword matcher. */
  150.  
  151. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  152.  
  153.  
  154. /* Log base two hacks. */
  155.  
  156. int pm_maxvaltobits ARGS(( int maxval ));
  157. int pm_bitstomaxval ARGS(( int bits ));
  158.  
  159.  
  160. /* Error handling definitions. */
  161.  
  162. void pm_message( /* char* fmt, char* v1, char* v2, char* v3, char* v4, char* v5 */ );    /* prototypes can't handle this */
  163. void pm_error( /* char* fmt, char* v1, char* v2, char* v3, char* v4, char* v5 */ );    /* doesn't return */
  164. void pm_perror ARGS(( char* reason ));            /* doesn't return */
  165. void pm_usage ARGS(( char* usage ));            /* doesn't return */
  166.  
  167.  
  168. /* File open/close that handles "-" as stdin and checks errors. */
  169.  
  170. FILE* pm_openr ARGS(( char* name ));
  171. FILE* pm_openw ARGS(( char* name ));
  172. void pm_close ARGS(( FILE* f ));
  173.  
  174.  
  175. /* Endian I/O. */
  176.  
  177. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  178. int pm_writebigshort ARGS(( FILE* out, short s ));
  179. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  180. int pm_writebiglong ARGS(( FILE* out, long l ));
  181. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  182. int pm_writelittleshort ARGS(( FILE* out, short s ));
  183. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  184. int pm_writelittlelong ARGS(( FILE* out, long l ));
  185.  
  186.  
  187. #endif /*_PBMPLUS_H_*/
  188.