home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / hpcd06 / hpcdtopp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  6.0 KB  |  204 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6.beta
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <malloc.h>
  15. #include <sys/types.h>
  16. #include <ctype.h>
  17. #include "config.h"
  18.  
  19. /* Format definitions */
  20.  
  21. #define BaseW ((dim)768)
  22. #define BaseH ((dim)512)
  23.  
  24. #define SECSIZE 0x800
  25.  
  26. #define SeHead   2
  27. #define L_Head   (1+SeHead)
  28.  
  29. #define SeBase16 18
  30. #define L_Base16 (1+SeBase16)
  31.  
  32. #define SeBase4  72
  33. #define L_Base4  (1+SeBase4)
  34.  
  35. #define SeBase   288
  36. #define L_Base   (1+SeBase)
  37.  
  38.  
  39. #define neutrLum 128
  40. #define neutrCh1 156
  41. #define neutrCh2 137
  42.  
  43. /* Structures and definitions */
  44. struct _implane
  45.  {dim  mwidth,mheight,
  46.        iwidth,iheight;
  47.   uBYTE *im,*mp;
  48.  };
  49. typedef struct _implane implane;
  50.  
  51. #define nullplane ((implane *) 0)
  52.  
  53. struct _sizeinfo
  54.  {dim w,h;  /* Image Resolution */
  55.   dim rdhoff,rdhlen, rdvoff, rdvlen; /* Size of Image in Memory */
  56.   dim imhoff,imhlen, imvoff, imvlen; /* Real Size of Image */
  57.  };
  58. typedef struct _sizeinfo sizeinfo;
  59.  
  60. /* Definitions for 64Base */
  61.  
  62. struct file32 { uBYTE x1,x2,x3,x4;};
  63. struct file16 { uBYTE x1,x2;};
  64. #define FILE32(x) ( (((uINT)x.x1)<<24) | (((uINT)x.x2)<<16) | (((uINT)x.x3)<<8) | (uINT)x.x4 )
  65. #define FILE16(x) ( (((uINT)x.x1)<<8) | (uINT)x.x2 )
  66.  
  67. struct ic_header {char ic_name[0x28];
  68.                   struct file16 val1;
  69.                   struct file16 val2;
  70.                   struct file32 off_descr;
  71.                   struct file32 off_fnames;
  72.                   struct file32 off_pointers;
  73.                   struct file32 off_huffman;
  74.                  };
  75.  
  76. struct ic_descr {struct file16 len;
  77.                  uBYTE  color;
  78.                  uBYTE  fill;  /* Don't know */
  79.                  struct file16 width;
  80.                  struct file16 height;
  81.                  struct file16 offset;
  82.                  struct file32 length;
  83.                  struct file32 off_pointers;
  84.                  struct file32 off_huffman;
  85.                 };
  86.  
  87.  
  88. struct ic_fname  {char fname[12];
  89.                   struct file32 size;
  90.                  };
  91.  
  92.  
  93.  
  94.  
  95.  
  96. enum   TURNS  { T_UNSPEC,T_NONE,T_RIGHT,T_LEFT,T_HEAD,T_AUTO };
  97. enum   SIZES  { S_UNSPEC,S_Base16,S_Base4,S_Base,S_4Base,S_16Base,S_64Base,S_Over,S_Contact };
  98. /* SD : added TGA */
  99. enum   OUTFOR { O_UNSPEC,O_PPM,O_PGM,O_YCC,O_PS,O_EPS,O_PSG,O_EPSG,O_PSD,O_EPSD,O_TGA };
  100. enum   CORR   { C_UNSPEC,C_LINEAR,C_DARK,C_BRIGHT };
  101.  
  102. enum   ERRORS { E_NONE,E_READ,E_WRITE,E_INTERN,E_ARG,E_OPT,E_MEM,E_HUFF,
  103.                 E_SEQ,E_SEQ1,E_SEQ2,E_SEQ3,E_SEQ4,E_SEQ5,E_SEQ6,E_SEQ7,E_POS,E_IMP,E_OVSKIP,
  104.                 E_TAUTO,E_TCANT,E_SUBR,E_PRPAR,E_CONFIG,E_FOPEN };
  105.  
  106. /**** Macros ****/
  107.  
  108. #ifdef DEBUG
  109. #define RPRINT  {fprintf(stderr,"R-Position %x\n",bufpos);}
  110. #else
  111. #define RPRINT
  112. #endif
  113.  
  114. #define melde(x) {if (do_melde) fprintf(stderr,x);}
  115.  
  116.  
  117. #define READBUF   READ(sbuffer,sizeof(sbuffer))
  118. #define EREADBUF {if(READBUF < 1) error(E_READ);}
  119.  
  120. #define SKIP(p)  { if (SKIPn(p)) error(E_READ);}
  121. #define SKIPr(p) { if (SKIPn(p)) return(E_READ);}
  122.  
  123.  
  124. #define TRIF(x,u,o,a,b,c) ((x)<(u)? (a) : ( (x)>(o)?(c):(b)  ))
  125. #define xNORM(x) x=TRIF(x,0,255,0,x,255)
  126. #define NORM(x) { if(x<0) x=0; else if (x>255) x=255;}
  127.  
  128. #ifndef MIN
  129. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  130. #endif
  131.  
  132. /* main.c */
  133. extern void         close_all(void);
  134.  
  135. extern char         *ppmname,*pcdname;
  136. extern sINT         do_diff,do_info,do_sharp,do_overskip,monochrome;
  137. extern sINT         do_melde,do_rep,do_crop;
  138. extern sINT         flvert,flhori;
  139. extern uBYTE        sbuffer[SECSIZE];
  140. extern enum TURNS   turn;
  141. extern enum SIZES   size;
  142. extern enum OUTFOR  outfor;
  143. extern enum CORR    corrmode;
  144.  
  145. extern void         SEEK(int);
  146. extern int          SKIPn(int);
  147. extern int          READ(uBYTE *,int);
  148. extern sINT         bufpos;
  149.  
  150.  
  151. /* error.c */
  152. extern void         eerror(enum ERRORS,char *, int);
  153.  
  154.  
  155. /* color.c */
  156. extern void         colconvert(sizeinfo *,implane *,implane *,implane *);
  157.  
  158. /* tools.c */
  159. extern void         clearimpl(implane *,sINT);
  160. extern void         halve(implane *);
  161. extern void         interpolate(implane *);
  162. extern sINT         Skip4Base(void);
  163. extern void         planealloc(implane *,dim,dim);
  164. extern void         pastein(implane *,dim,dim,dim,dim,implane *, enum TURNS);
  165. extern void         cropit(sizeinfo *,implane *,implane *,implane *);
  166. extern void         shrink(sizeinfo *,implane *,implane *,implane *);
  167. extern void         typecheck(void);
  168.  
  169.  
  170. /* format.c */
  171. extern void         readhqt(sINT);
  172. extern void         readhqtx(sINT);
  173. extern void         decode(sizeinfo *,int,implane *,implane *,implane *,sINT);
  174. extern void         decodex(FILE *,int tag,struct ic_descr *,sizeinfo *,int,implane *,sINT);
  175. extern enum ERRORS  readplain(sizeinfo *,int,implane *,implane *,implane *);
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /* Type definitions for output format drives, used in output.c and the drivers */
  182.  
  183. typedef void (OUT1PL)(FILE *,dim,dim, uBYTE *,sdim,sdim);
  184. typedef void (OUT3PL)(FILE *,dim,dim, uBYTE *,sdim,sdim, uBYTE *,sdim,sdim, uBYTE *,sdim,sdim);
  185.  
  186. /* output.c */
  187. extern void         writepicture(FILE *,sizeinfo *,implane *,implane *,implane *,enum TURNS);
  188. extern void         druckeid(void);
  189.  
  190.  
  191. /* ppm.c */
  192. extern OUT3PL       write_ppm;
  193. extern OUT1PL       write_pgm;
  194.  
  195. /* postscr.c */
  196. extern OUT3PL       write_epsrgb,write_psrgb;
  197. extern OUT1PL       write_epsgrey,write_psgrey,write_epsdith,write_psdith;
  198.  
  199. extern FLTPT        PAPER_LEFT,PAPER_BOTTOM,PAPER_WIDTH,PAPER_HEIGHT,PRINTER_XDPI,PRINTER_YDPI,PRINTER_FAK;
  200. extern sINT         PSIZE_SET,DPI_SET,FAK_SET;
  201.  
  202. /* tga.c */
  203. extern OUT3PL   write_tga ;
  204.