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