home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 9 / CD_ASCQ_09_1193.iso / news / 4441 / mpegcode / src / pbmplus / pbmplus.h < prev    next >
C/C++ Source or Header  |  1993-09-27  |  6KB  |  192 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 <stdio.h>
  19.  
  20. #if defined(USG) || defined(SVR4)
  21. #define SYSV
  22. #endif
  23. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) )
  24. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  25. ** System V site, set the SYSV option; and if you're IBM-compatible, set
  26. ** MSDOS.  If your compiler is ANSI C, you're probably better off setting
  27. ** SYSV - all it affects is string handling.
  28. */
  29. #define BSD
  30. /* #define SYSV */
  31. /* #define MSDOS */
  32. #endif
  33.  
  34. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  35. ** "Raw" files are smaller, and much faster to read and write, but you
  36. ** must have a filesystem that allows all 256 ASCII characters to be read
  37. ** and written.  You will no longer be able to mail P?M files without 
  38. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  39. ** Note that reading "raw" files works whether writing is enabled or not.
  40. */
  41. #define PBMPLUS_RAWBITS
  42.  
  43. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  44. ** applications, bytes will be big enough, and the memory savings can be
  45. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  46. ** then define this symbol.
  47. */
  48. /* #define PGM_BIGGRAYS */
  49.  
  50. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  51. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  52. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  53. ** can also be configured to pack the three grays into a single longword,
  54. ** 10 bits each, 30 bits per pixel.
  55. **
  56. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  57. ** need more than 10 bits for each color component, AND you care more about
  58. ** memory use than speed, then this option might be a win.  Under these
  59. ** circumstances it will make some of the programs use 1.5 times less space,
  60. ** but all of the programs will run about 1.4 times slower.
  61. **
  62. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  63. ** doesn't save any space, but it still slows things down.
  64. */
  65. /* #define PPM_PACKCOLORS */
  66.  
  67. /* CONFIGURE: uncomment this to enable debugging checks. */
  68. /* #define DEBUG */
  69.  
  70. #ifdef SYSV
  71.  
  72. #include <string.h>
  73. #define index(s,c) strchr(s,c)
  74. #define rindex(s,c) strrchr(s,c)
  75. #define srandom(s) srand(s)
  76. #define random rand
  77. #define bzero(dst,len) memset(dst,0,len)
  78. #define bcopy(src,dst,len) memcpy(dst,src,len)
  79. #define bcmp memcmp
  80. extern void srand();
  81. extern int rand();
  82.  
  83. #else /*SYSV*/
  84.  
  85. #include <strings.h>
  86. extern void srandom();
  87. extern long random();
  88.  
  89. #endif /*SYSV*/
  90.  
  91. extern int atoi();
  92. #ifdef BLEAH
  93. extern void exit();
  94. extern long time();
  95. #endif
  96. extern int write();
  97.  
  98. /* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
  99. ** to do it.  On other systems, for example HP/UX, it declares them
  100. ** incompatibly.  And some systems, for example Dynix, don't have a
  101. ** malloc.h at all.  A sad situation.  If you have compilation problems
  102. ** that point here, feel free to tweak or remove these declarations.
  103. */
  104. #include <malloc.h>
  105.  
  106. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  107. ** error-reporting routines.  If you compile and get a link error about
  108. ** this routine, uncomment the first define, which gives you a vfprintf
  109. ** that uses the theoretically non-portable but fairly common routine
  110. ** _doprnt().  If you then get a link error about _doprnt, or
  111. ** message-printing doesn't look like it's working, try the second
  112. ** define instead.
  113. */
  114. /* #define NEED_VFPRINTF1 */
  115. /* #define NEED_VFPRINTF2 */
  116.  
  117. /* End of configurable definitions. */
  118.  
  119.  
  120. #undef max
  121. #define max(a,b) ((a) > (b) ? (a) : (b))
  122. #undef min
  123. #define min(a,b) ((a) < (b) ? (a) : (b))
  124. #undef abs
  125. #define abs(a) ((a) >= 0 ? (a) : -(a))
  126. #undef odd
  127. #define odd(n) ((n) & 1)
  128.  
  129.  
  130. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  131.  
  132. #if __STDC__
  133. #define ARGS(alist) alist
  134. #else /*__STDC__*/
  135. #define ARGS(alist) ()
  136. #define const
  137. #endif /*__STDC__*/
  138.  
  139.  
  140. /* Initialization. */
  141.  
  142. void pm_init ARGS(( int* argcP, char* argv[] ));
  143.  
  144.  
  145. /* Variable-sized arrays definitions. */
  146.  
  147. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  148. char* pm_allocrow ARGS(( int cols, int size ));
  149. void pm_freearray ARGS(( char** its, int rows ));
  150. void pm_freerow ARGS(( char* itrow ));
  151.  
  152.  
  153. /* Case-insensitive keyword matcher. */
  154.  
  155. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  156.  
  157.  
  158. /* Log base two hacks. */
  159.  
  160. int pm_maxvaltobits ARGS(( int maxval ));
  161. int pm_bitstomaxval ARGS(( int bits ));
  162.  
  163.  
  164. /* Error handling definitions. */
  165.  
  166. void pm_message ARGS(( char*, ... ));
  167. void pm_error ARGS(( char*, ... ));            /* doesn't return */
  168. void pm_perror ARGS(( char* reason ));            /* doesn't return */
  169. void pm_usage ARGS(( char* usage ));            /* doesn't return */
  170.  
  171.  
  172. /* File open/close that handles "-" as stdin and checks errors. */
  173.  
  174. FILE* pm_openr ARGS(( char* name ));
  175. FILE* pm_openw ARGS(( char* name ));
  176. void pm_close ARGS(( FILE* f ));
  177.  
  178.  
  179. /* Endian I/O. */
  180.  
  181. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  182. int pm_writebigshort ARGS(( FILE* out, short s ));
  183. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  184. int pm_writebiglong ARGS(( FILE* out, long l ));
  185. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  186. int pm_writelittleshort ARGS(( FILE* out, short s ));
  187. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  188. int pm_writelittlelong ARGS(( FILE* out, long l ));
  189.  
  190.  
  191. #endif /*_PBMPLUS_H_*/
  192.