home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / hpcd2ppm / part02 < prev    next >
Encoding:
Text File  |  1993-08-16  |  53.6 KB  |  1,746 lines

  1. Newsgroups: comp.sources.misc
  2. From: danisch@ira.uka.de (Hadmut Danisch)
  3. Subject: v39i003:  hpcdtoppm - convert Photo-CD file into portable pixmap v0.5pl1, Part02/03
  4. Message-ID: <1993Aug16.204116.22146@sparky.sterling.com>
  5. X-Md4-Signature: 9eb24718dfa213dc0029dd2a77ee9aba
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Mon, 16 Aug 1993 20:41:16 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: danisch@ira.uka.de (Hadmut Danisch)
  12. Posting-number: Volume 39, Issue 3
  13. Archive-name: hpcdtoppm/part02
  14. Environment: Photo-CD
  15. Supersedes: hpcdtoppm: Volume 34, Issue 83
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  hpcdtoppm.0.5.pl1/Makefile hpcdtoppm.0.5.pl1/error.c
  22. #   hpcdtoppm.0.5.pl1/format.c hpcdtoppm.0.5.pl1/hpcdtoppm.man
  23. #   hpcdtoppm.0.5.pl1/output.c hpcdtoppm.0.5.pl1/pcdindex
  24. #   hpcdtoppm.0.5.pl1/postscr.c
  25. # Wrapped by kent@sparky on Mon Aug 16 10:49:23 1993
  26. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  27. echo If this archive is complete, you will see the following message:
  28. echo '          "shar: End of archive 2 (of 3)."'
  29. if test -f 'hpcdtoppm.0.5.pl1/Makefile' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/Makefile'\"
  31. else
  32.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/Makefile'\" \(472 characters\)
  33.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/Makefile' <<'END_OF_FILE'
  34. X#
  35. X#
  36. X# Use the hpcdtoppm procedures for writing ppm and pgm
  37. XVFLAGS= -DOWN_WRITE
  38. XVLIBS=
  39. X# Use the pbmplus procedures for writing ppm and pgm
  40. X#VFLAGS=
  41. X#VLIBS= libpbm.a libpgm.a libppm.a
  42. X#
  43. X#
  44. XCC=    gcc 
  45. XCFLAGS=    -O4 -ansi -Wall ${VFLAGS} 
  46. XINCL=    hpcdtoppm.h config.h
  47. XOBJ=    main.o output.o color.o format.o tools.o error.o \
  48. X    ppm.o postscr.o const.o
  49. XCOMPILE=${CC} ${CFLAGS}  -c
  50. X#
  51. Xhpcdtoppm: ${OBJ}
  52. X    ${CC} -o hpcdtoppm ${OBJ} ${VLIBS}
  53. X#
  54. X${OBJ}: ${$@:.o=.c} ${INCL}
  55. X    ${COMPILE} ${*}.c
  56. END_OF_FILE
  57.   if test 472 -ne `wc -c <'hpcdtoppm.0.5.pl1/Makefile'`; then
  58.     echo shar: \"'hpcdtoppm.0.5.pl1/Makefile'\" unpacked with wrong size!
  59.   fi
  60.   # end of 'hpcdtoppm.0.5.pl1/Makefile'
  61. fi
  62. if test -f 'hpcdtoppm.0.5.pl1/error.c' -a "${1}" != "-c" ; then 
  63.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/error.c'\"
  64. else
  65.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/error.c'\" \(8903 characters\)
  66.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/error.c' <<'END_OF_FILE'
  67. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  68. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  69. X*  Permission to use and distribute this software and its
  70. X*  documentation for noncommercial use and without fee is hereby granted,
  71. X*  provided that the above copyright notice appear in all copies and that
  72. X*  both that copyright notice and this permission notice appear in
  73. X*  supporting documentation. It is not allowed to sell this software in 
  74. X*  any way. This software is not public domain.
  75. X*/
  76. X
  77. X#include "hpcdtoppm.h"
  78. X#define X(a,b) ((a == b) ? "->" : "  ")
  79. X
  80. Xvoid eerror(enum ERRORS e,char *file,int line)
  81. X {
  82. X  
  83. X  switch(e)
  84. X   {case E_NONE:   return;
  85. X    case E_IMP:    fprintf(stderr,"Sorry, Not yet implemented. [%s:%d]\n",file,line); break;
  86. X    case E_READ:   fprintf(stderr,"Error while reading.\n"); break;
  87. X    case E_WRITE:  fprintf(stderr,"Error while writing.\n"); break;
  88. X    case E_INTERN: fprintf(stderr,"Internal error. [%s:%d]\n",file,line); break;
  89. X    case E_ARG:    fprintf(stderr,"Error in Arguments !\n\n"); 
  90. X#ifdef SHORT_HELP
  91. X                   fprintf(stderr,"Usage: hpcdtoppm [options] pcd-file [ppm-file]\n");
  92. X                   fprintf(stderr,"       ( - means stdin )\n");
  93. X                   fprintf(stderr,"Opts:         [ -> = Default ] \n\n");
  94. X                   fprintf(stderr,"   [-x] [-s] [-d] [-i] [-m]\n");
  95. X                   fprintf(stderr,"   [-crop] [-pos] [-rep] [-vert] [-hori] [-S h v]\n");
  96. X                   fprintf(stderr,"   [-n] [-r] [-l] [-h] [-a]\n");
  97. X                   fprintf(stderr,"   [-ppm] [-pgm] [-ycc] [-ps] [-eps] [-psg] [-epsg] [-psd] [-epsd]\n");
  98. X                   fprintf(stderr,"   [-pl f] [-pb f] [-pw f] [-ph f] [-dpi f] [-fak f]\n");
  99. X                   fprintf(stderr,"   [-c0] [-c-] [-c+]\n");
  100. X                   fprintf(stderr,"   [-0] [-C d s] [-1] [-2] [-3] [-4] [-5]\n");
  101. X
  102. X#endif
  103. X#ifdef LONG_HELP
  104. X                   fprintf(stderr,"Usage: hpcdtoppm [options] pcd-file [ppm-file]\n");
  105. X                   fprintf(stderr,"       ( - means stdin )\n");
  106. X                   fprintf(stderr,"Opts:         [ -> = Default ] \n\n");
  107. X
  108. X                   fprintf(stderr,"     -x     Overskip mode (tries to improve color quality.)\n");
  109. X                   fprintf(stderr,"     -s     Apply simple sharpness-operator on the Luma-channel.\n");
  110. X                   fprintf(stderr,"     -d     Show differential picture only.\n");
  111. X                   fprintf(stderr,"     -i     Give some (buggy) informations from fileheader.\n");
  112. X                   fprintf(stderr,"     -m     Show the decoding steps to stderr.\n");
  113. X                   fprintf(stderr,"     -crop  Try to cut off the black frame.\n");
  114. X                   fprintf(stderr,"     -pos   Print file position of image to stderr.\n");
  115. X                   fprintf(stderr,"     -rep   Try to jump over defects in the Huffman Code.\n");
  116. X                   fprintf(stderr,"     -vert  Flip image vert.\n");
  117. X                   fprintf(stderr,"     -hori  Flip image horiz.\n");
  118. X                   fprintf(stderr,"     -S h v Decode subrectangle with hori. and vert. boundaries h,v,\n");
  119. X                   fprintf(stderr,"            h,v of the form a-b or a+b, a and b integer or float [0.0...1.0]\n");
  120. X                   fprintf(stderr,"\n");
  121. X
  122. X                   fprintf(stderr," %s  -n     Don't rotate.\n",                                 X(T_DEFAULT,T_NONE));
  123. X                   fprintf(stderr," %s  -r     Rotate clockwise for portraits.\n" ,              X(T_DEFAULT,T_RIGHT));
  124. X                   fprintf(stderr," %s  -l     Rotate counter-clockwise for portraits.\n",       X(T_DEFAULT,T_LEFT));
  125. X                   fprintf(stderr," %s  -h     Rotate twice, turn on head.\n",                   X(T_DEFAULT,T_HEAD));
  126. X                   fprintf(stderr," %s  -a     Try to find out orientation automatically.\n",    X(T_DEFAULT,T_AUTO));
  127. X                   fprintf(stderr,"\n");
  128. X
  129. X                   fprintf(stderr," %s  -ppm   output rgb  (ppm-format). \n",                    X(O_DEFAULT,O_PPM));
  130. X                   fprintf(stderr," %s  -pgm   output gray (pgm-format). \n",                    X(O_DEFAULT,O_PGM));
  131. X                   fprintf(stderr," %s  -ycc   output ycc  (ppm-format). \n",                    X(O_DEFAULT,O_YCC));
  132. X                   fprintf(stderr," %s  -ps    output postscript (rgb). \n",                     X(O_DEFAULT,O_PS));
  133. X                   fprintf(stderr," %s  -eps   output encapsulated postscript (rgb). \n",        X(O_DEFAULT,O_EPS));
  134. X                   fprintf(stderr," %s  -psg   output postscript (grayscale). \n",               X(O_DEFAULT,O_PSG));
  135. X                   fprintf(stderr," %s  -epsg  output encapsulated postscript (grayscale). \n",  X(O_DEFAULT,O_EPSG));
  136. X                   fprintf(stderr," %s  -psd   output postscript (b&w dithered). \n",            X(O_DEFAULT,O_PSG));
  137. X                   fprintf(stderr," %s  -epsd  output encapsulated postscript (b&w dithered).\n",X(O_DEFAULT,O_EPSG));
  138. X                   fprintf(stderr,"     -pl  f Postscript paper left position    [ Def:  %8.3f ]\n",DEF_PAPER_LEFT);
  139. X                   fprintf(stderr,"     -pb  f Postscript paper bottom position  [ Def:  %8.3f ]\n",DEF_PAPER_BOTTOM);
  140. X                   fprintf(stderr,"     -pw  f Postscript paper width            [ Def:  %8.3f ]\n",DEF_PAPER_WIDTH);
  141. X                   fprintf(stderr,"     -ph  f Postscript paper height           [ Def:  %8.3f ]\n",DEF_PAPER_HEIGHT);
  142. X                   fprintf(stderr,"     -dpi f Postscript resolution for dith.   [ Def:  %8.3f ]\n",DEF_DPI);
  143. X                   fprintf(stderr,"     -fak f Scaling factor for dith.          [ Def:     1.0   ]\n");
  144. X                   fprintf(stderr,"\n");
  145. X
  146. X                   fprintf(stderr," %s  -c0    don't correct (linear).\n", X(C_DEFAULT,C_LINEAR));
  147. X                   fprintf(stderr," %s  -c-    correct darker.\n",         X(C_DEFAULT,C_DARK));
  148. X                   fprintf(stderr," %s  -c+    correct brighter.\n",       X(C_DEFAULT,C_BRIGHT));
  149. X                   fprintf(stderr,"\n");
  150. X
  151. X                   fprintf(stderr," %s  -0     Extract thumbnails from Overview file.\n",        X(S_DEFAULT,S_Over));
  152. X                   fprintf(stderr," %s  -C d s Extract contact sheet from Overview file, d images width,\n",X(S_DEFAULT,S_Contact)); 
  153. X                   fprintf(stderr,"            with contact sheet orientation s ( one of n l r h).\n");
  154. X                   fprintf(stderr," %s  -1     Extract  128x192   from Image file.\n",           X(S_DEFAULT,S_Base16));
  155. X                   fprintf(stderr," %s  -2     Extract  256x384   from Image file.\n",           X(S_DEFAULT,S_Base4));
  156. X                   fprintf(stderr," %s  -3     Extract  512x768   from Image file.\n",           X(S_DEFAULT,S_Base));
  157. X                   fprintf(stderr," %s  -4     Extract 1024x1536  from Image file.\n",           X(S_DEFAULT,S_4Base));
  158. X                   fprintf(stderr," %s  -5     Extract 2048x3072  from Image file.\n",           X(S_DEFAULT,S_16Base));
  159. X                   fprintf(stderr,"\n");
  160. X#endif
  161. X                   break;
  162. X    case E_OPT:    fprintf(stderr,"These Options are not allowed together.\n");break;
  163. X    case E_MEM:    fprintf(stderr,"Not enough memory !\n"); break;
  164. X    case E_HUFF:   fprintf(stderr,"Error in Huffman-Code-Table\n"); break;
  165. X    case E_SEQ:    fprintf(stderr,"Error in Huffman-Sequence, try option -rep\n"); break;
  166. X    case E_SEQ1:   fprintf(stderr,"Error1 in Huffman-Sequence, try option -rep\n"); break;
  167. X    case E_SEQ2:   fprintf(stderr,"Error2 in Huffman-Sequence, try option -rep\n"); break;
  168. X    case E_SEQ3:   fprintf(stderr,"Error3 in Huffman-Sequence, try option -rep\n"); break;
  169. X    case E_SEQ4:   fprintf(stderr,"Error4 in Huffman-Sequence, try option -rep\n"); break;
  170. X    case E_SEQ5:   fprintf(stderr,"Error5 in Huffman-Sequence, try option -rep\n"); break;
  171. X    case E_SEQ6:   fprintf(stderr,"Error6 in Huffman-Sequence, try option -rep\n"); break;
  172. X    case E_SEQ7:   fprintf(stderr,"Error7 in Huffman-Sequence, try option -rep\n"); break;
  173. X    case E_POS:    fprintf(stderr,"Error in file-position\n"); break;
  174. X    case E_OVSKIP: fprintf(stderr,"Can't read this resolution in overskip-mode\n"); break;
  175. X    case E_TAUTO:  fprintf(stderr,"Can't determine the orientation in overview mode\n");break;
  176. X    case E_SUBR:   fprintf(stderr,"Error in Subrectangle Parameters\n");break;
  177. X    case E_PRPAR:  fprintf(stderr,"Bad printing parameters\n");break;
  178. X    case E_CONFIG: fprintf(stderr,"Something is wrong with your configuration [see %s:%d]\n",file,line);
  179. X                   fprintf(stderr,"Edit the config.h and recompile...\n"); break;
  180. X    case E_TCANT:  fprintf(stderr,"Sorry, can't determine orientation for this file.\n");
  181. X                   fprintf(stderr,"Please give orientation parameters. \n");break;
  182. X    default:       fprintf(stderr,"Unknown error %d ???  [%s:%d]\n",e,file,line);break;
  183. X   }
  184. X  close_all();
  185. X  exit(9);
  186. X }
  187. X
  188. X
  189. END_OF_FILE
  190.   if test 8903 -ne `wc -c <'hpcdtoppm.0.5.pl1/error.c'`; then
  191.     echo shar: \"'hpcdtoppm.0.5.pl1/error.c'\" unpacked with wrong size!
  192.   fi
  193.   # end of 'hpcdtoppm.0.5.pl1/error.c'
  194. fi
  195. if test -f 'hpcdtoppm.0.5.pl1/format.c' -a "${1}" != "-c" ; then 
  196.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/format.c'\"
  197. else
  198.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/format.c'\" \(11918 characters\)
  199.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/format.c' <<'END_OF_FILE'
  200. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  201. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  202. X*  Permission to use and distribute this software and its
  203. X*  documentation for noncommercial use and without fee is hereby granted,
  204. X*  provided that the above copyright notice appear in all copies and that
  205. X*  both that copyright notice and this permission notice appear in
  206. X*  supporting documentation. It is not allowed to sell this software in 
  207. X*  any way. This software is not public domain.
  208. X*/
  209. X
  210. X#include "hpcdtoppm.h"
  211. X
  212. Xstruct pcdquad { uBYTE len,highseq,lowseq,key;};
  213. Xstruct pcdhqt  { uBYTE entries; struct pcdquad entry[256];};
  214. Xstruct myhqt   { uINT seq,mask,len; uBYTE key; };
  215. X
  216. Xstatic struct myhqt myhuff0[256],myhuff1[256],myhuff2[256];
  217. Xstatic sINT          myhufflen0=0,myhufflen1=0,myhufflen2=0;
  218. X
  219. X
  220. X
  221. X
  222. Xstatic void readhqtsub(struct pcdhqt *quelle,struct myhqt *ziel,sINT *anzahl)
  223. X#define E ((uINT) 1)
  224. X {sINT i;
  225. X  struct pcdquad *sub;
  226. X  struct myhqt *help;
  227. X  *anzahl=(quelle->entries)+1;
  228. X
  229. X  for(i=0;i<*anzahl;i++)
  230. X   {sub = (struct pcdquad *)(((uBYTE *)quelle)+1+i*sizeof(*sub));
  231. X    help=ziel+i;
  232. X
  233. X    help->seq = (((uINT) sub->highseq) << 24) |(((uINT) sub->lowseq) << 16);
  234. X    help->len = ((uINT) sub->len) +1;
  235. X    help->key = sub->key;
  236. X
  237. X#ifdef DEBUGhuff
  238. X   fprintf(stderr," Anz: %d A1: %08x  A2: %08x X:%02x %02x %02x %02x Seq:  %08x   Laenge:  %d %d\n",
  239. X          *anzahl,(uINT)sbuffer,(uINT)sub,
  240. X          ((uBYTE *)sub)[0],((uBYTE *)sub)[1],((uBYTE *)sub)[2],((uBYTE *)sub)[3],
  241. X          help->seq,help->len,sizeof(uBYTE));
  242. X#endif
  243. X
  244. X    if(help->len > 16) error(E_HUFF);
  245. X
  246. X    help->mask = ~ ( (E << (32-help->len)) -1); 
  247. X
  248. X  }
  249. X#ifdef DEBUG
  250. X  for(i=0;i<*anzahl;i++)
  251. X   {help=ziel+i;
  252. X    fprintf(stderr,"H: %3d  %08lx & %08lx (%2d) = %02x = %5d  %8x\n",
  253. X        i, help->seq,help->mask,help->len,help->key,(signed char)help->key,
  254. X        help->seq & (~help->mask));
  255. X   }
  256. X#endif
  257. X
  258. X#undef E
  259. X}
  260. X
  261. X
  262. X
  263. X
  264. X
  265. X
  266. X
  267. Xvoid readhqt(sINT n)
  268. X {
  269. X  uBYTE *ptr;
  270. X
  271. X  melde("readhqt\n");
  272. X  EREADBUF;
  273. X  ptr = sbuffer;
  274. X
  275. X  readhqtsub((struct pcdhqt *)ptr,myhuff0,&myhufflen0);
  276. X
  277. X  if(n<2) return;
  278. X  ptr+= 1 + 4* myhufflen0;
  279. X  readhqtsub((struct pcdhqt *)ptr,myhuff1,&myhufflen1);
  280. X
  281. X  if(n<3) return;
  282. X  ptr+= 1 + 4* myhufflen1;
  283. X  readhqtsub((struct pcdhqt *)ptr,myhuff2,&myhufflen2);
  284. X
  285. X}
  286. X
  287. X
  288. X
  289. X
  290. X
  291. X
  292. X
  293. X#ifdef FASTHUFF
  294. X
  295. Xstatic struct myhqt *HTAB0[0x10000],*HTAB1[0x10000],*HTAB2[0x10000];
  296. X
  297. Xstatic void inithuff(sINT hlen,struct myhqt *ptr,struct myhqt *TAB[])
  298. X {sINT i,n;
  299. X  sINT seq,len;
  300. X  struct myhqt *help;
  301. X
  302. X  for(i=0;i<0x10000;i++) TAB[i]=0;
  303. X
  304. X  for(n=0;n<hlen;n++)
  305. X   {help=ptr+n;
  306. X    seq=(help->seq)>>16;
  307. X    len=help->len;
  308. X
  309. X    for(i=0;i<(1<<(16-len));i++)
  310. X      TAB[seq | i] = help;
  311. X   }
  312. X }
  313. X#endif
  314. X
  315. X
  316. X
  317. X
  318. Xstatic char *pn[]={"Luma Channel","Chroma1 Channel","Chroma2 Channel"};
  319. X
  320. X
  321. Xvoid decode(sizeinfo *si,int fak,implane *f,implane *f1,implane *f2,sINT autosync)
  322. X {dim w,h,hoff,hlen,hende,voff,vlen,vende,anfang,ende;
  323. X  sINT htlen,sum,do_inform,part;
  324. X  uINT sreg,maxwidth;
  325. X  uINT inh,n,zeile,segment,ident;
  326. X  struct myhqt *hp;
  327. X
  328. X  uBYTE *nptr;
  329. X  uBYTE *lptr;
  330. X
  331. X#define nextbuf  {  nptr=sbuffer; if(READBUF<1) { if(!do_rep) error(E_READ); \
  332. X                                                  fprintf(stderr,"Read error\n"); \
  333. X                                                  return; } }
  334. X#define checkbuf { if (nptr >= sbuffer + sizeof(sbuffer)) nextbuf; }
  335. X
  336. X#ifdef U_TOO_LONG
  337. X#define shiftreg(n) sreg = (sreg<< n ) & 0xffffffff;
  338. X#else
  339. X#define shiftreg(n) sreg<<=n;
  340. X#endif
  341. X
  342. X#define shiftout(n){ shiftreg(n); inh-=n; \
  343. X                     while (inh<=24) \
  344. X                      {checkbuf; \
  345. X                       sreg |= ((uINT)(*(nptr++)))<<(24-inh);\
  346. X                       inh+=8;\
  347. X                      }\
  348. X                    }  
  349. X#define issync     ((sreg & 0xffffff00) == 0xfffffe00) 
  350. X#define brutesync  ((sreg & 0x00fff000) == 0x00fff000) 
  351. X#define seeksync { while (!brutesync) shiftout(8); while (!issync) shiftout(1);}
  352. X
  353. X#ifdef FASTHUFF
  354. X  struct myhqt **HTAB;
  355. X  HTAB=0;
  356. X  inithuff(myhufflen0,myhuff0,HTAB0);
  357. X  inithuff(myhufflen1,myhuff1,HTAB1);
  358. X  inithuff(myhufflen2,myhuff2,HTAB2);
  359. X#define SETHUFF0 HTAB=HTAB0;
  360. X#define SETHUFF1 HTAB=HTAB1;
  361. X#define SETHUFF2 HTAB=HTAB2;
  362. X#define FINDHUFF(x) {x=HTAB[sreg>>16];}
  363. X
  364. X#else
  365. X
  366. X  sINT i;
  367. X  struct myhqt *htptr;
  368. X  htptr=0;
  369. X#define SETHUFF0 { htlen=myhufflen0 ; htptr = myhuff0 ; }
  370. X#define SETHUFF1 { htlen=myhufflen1 ; htptr = myhuff1 ; }
  371. X#define SETHUFF2 { htlen=myhufflen2 ; htptr = myhuff2 ; }
  372. X#define FINDHUFF(x)  {for(i=0, x=htptr;(i<htlen) && ((sreg & x ->mask)!= x->seq); i++,x++); \
  373. X                      if(i>=htlen) x=0;}
  374. X#endif
  375. X
  376. X  melde("decode\n");
  377. X  anfang=ende=0;
  378. X
  379. X  if(fak >= 0)
  380. X   {w   =si->w     *fak;
  381. X    h   =si->h     *fak;
  382. X    hoff=si->rdhoff*fak;  if(hoff & 1 ) error(E_INTERN);  /* Must be all even */
  383. X    hlen=si->rdhlen*fak;  if(hlen & 1 ) error(E_INTERN); hende=hlen+hoff;
  384. X    voff=si->rdvoff*fak;  if(voff & 1 ) error(E_INTERN);
  385. X    vlen=si->rdvlen*fak;  if(vlen & 1 ) error(E_INTERN); vende=vlen+voff;
  386. X   }
  387. X  else
  388. X   {fak = -fak;
  389. X    w   =si->w     /fak;
  390. X    h   =si->h     /fak;
  391. X    hoff=si->rdhoff/fak;  if(hoff & 1 ) error(E_INTERN);  /* Must be all even */
  392. X    hlen=si->rdhlen/fak;  if(hlen & 1 ) error(E_INTERN); hende=hlen+hoff; 
  393. X    voff=si->rdvoff/fak;  if(voff & 1 ) error(E_INTERN);
  394. X    vlen=si->rdvlen/fak;  if(vlen & 1 ) error(E_INTERN); vende=vlen+voff;
  395. X   }
  396. X
  397. X
  398. X  if( f  && ((! f->im) || ( f->iheight != vlen  ) ||  (f->iwidth != hlen  ))) error(E_INTERN);
  399. X  if( f1 && ((!f1->im) || (f1->iheight != vlen/2) || (f1->iwidth != hlen/2))) error(E_INTERN);
  400. X  if( f2 && ((!f2->im) || (f2->iheight != vlen/2) || (f2->iwidth != hlen/2))) error(E_INTERN);
  401. X
  402. X  htlen=sreg=maxwidth=0;
  403. X  zeile=0;
  404. X  nextbuf;
  405. X  inh=32;
  406. X  lptr=0;
  407. X  part=do_inform=0;
  408. X  shiftout(16);
  409. X  shiftout(16);
  410. X
  411. X  if(autosync) seeksync;
  412. X  
  413. X  if(!issync)
  414. X   { if(!do_rep) error(E_SEQ6);
  415. X     else 
  416. X      {fprintf(stderr,"Image does not start with synchron mark, seeking...\n");
  417. X       seeksync;
  418. X       do_inform=1;
  419. X      }
  420. X   }
  421. X
  422. X  n=0;
  423. X
  424. X  for(;;)
  425. X   {
  426. X    if (issync)
  427. X     {shiftout(24);
  428. X      ident=sreg>>16;
  429. X      shiftout(16);
  430. X
  431. X      zeile=(ident>>1) & 0x1fff;
  432. X      segment=ident>>14;
  433. X      if(do_inform) {fprintf(stderr,"Synchron mark found Line %d\n",zeile);do_inform=0;}
  434. X#ifdef DEBUG
  435. X      fprintf(stderr,"Id %4x Zeile: %6d Seg %3d Pix bisher: %5d  Position: %8lx+%5lx=%8x\n",
  436. X          ident,zeile,segment,n,bufpos,nptr-sbuffer,bufpos+nptr-sbuffer);
  437. X#endif
  438. X
  439. X
  440. X      if(lptr && (n!=maxwidth)) 
  441. X       {if(!do_rep)error(E_SEQ1);
  442. X        else fprintf(stderr,"Line %d in %s : wrong length of last line (%d)\n",zeile,pn[part],n);
  443. X       }
  444. X      n=0;
  445. X
  446. X      if(zeile==h) {RPRINT; return; }
  447. X      if(zeile >h) 
  448. X       { if(!do_rep) error(E_SEQ2);
  449. X         else 
  450. X          {fprintf(stderr,"Wrong line number %d, ignoring line\n",zeile);
  451. X           seeksync;
  452. X           n=maxwidth;
  453. X           do_inform=1;
  454. X          }
  455. X       }    
  456. X      else switch(segment)
  457. X       {
  458. X        case 1: if(!do_rep) error(E_SEQ3);
  459. X                fprintf(stderr,"Abnormal line tag in %d, interpreting as Luma tag\n",zeile);
  460. X        case 0: maxwidth=w;
  461. X                if((!f) && autosync) {seeksync; n=maxwidth; break;}
  462. X                if(!f) error(E_SEQ7);
  463. X                if((zeile<voff) || (zeile >= vende)) {seeksync; n=maxwidth; break;}
  464. X                anfang=hoff; ende=hende;
  465. X                lptr=f->im + (zeile-voff)*f->mwidth;
  466. X                SETHUFF0;
  467. X                part=0;
  468. X                break;
  469. X
  470. X        case 2: maxwidth=w>>1;
  471. X                if(!f1) return;
  472. X                /*if((!f1) && autosync) {seeksync; break;}*/
  473. X                if((zeile<voff) || (zeile >= vende)) {seeksync; n=maxwidth; break;}
  474. X                anfang=hoff>>1; ende=hende>>1;
  475. X                lptr=f1->im + ((zeile-voff)>>1)*f1->mwidth;
  476. X                SETHUFF1;
  477. X                part=1;
  478. X                break;
  479. X        case 3: maxwidth=w>>1;
  480. X                if(!f2) return;
  481. X                /*if((!f2) && autosync) {seeksync; break;}*/
  482. X                if((zeile<voff) || (zeile >= vende)) {seeksync; n=maxwidth; break;}
  483. X                anfang=hoff>>1; ende=hende>>1;
  484. X                lptr=f2->im + ((zeile-voff)>>1)*f2->mwidth;
  485. X                SETHUFF2;
  486. X                part=2;
  487. X                break;
  488. X
  489. X        default:error(E_SEQ3);
  490. X    }
  491. X     }
  492. X    else
  493. X     {
  494. X      if(!lptr)      error(E_SEQ6);
  495. X
  496. X      if(n>maxwidth) 
  497. X        {
  498. X#ifdef DEBUG
  499. X         fprintf(stderr,"Register: %08lx Pos: %08lx\n",sreg,bufpos+nptr-sbuffer);
  500. X#endif
  501. X         if (!do_rep) error(E_SEQ4);
  502. X         else { fprintf(stderr,"Missing synchron mark in %s line %d\n",pn[part],zeile);
  503. X                seeksync;
  504. X                do_inform=1;
  505. X                n=maxwidth;
  506. X              }
  507. X       }
  508. X      else
  509. X       {FINDHUFF(hp);
  510. X        if(!hp)
  511. X         { if(!do_rep) error(E_SEQ5);
  512. X           fprintf(stderr,"Unable to decode, ignoring rest of line\n");
  513. X           seeksync;
  514. X           n=maxwidth;
  515. X           do_inform=1;
  516. X         }
  517. X        else
  518. X         {if((n>= anfang) && (n<ende))
  519. X           {sum=((sINT)(*lptr)) + ((sBYTE)hp->key);
  520. X            NORM(sum);
  521. X            *(lptr++) = sum;
  522. X           }
  523. X
  524. X          n++; 
  525. X          shiftout(hp->len);
  526. X         }
  527. X       }
  528. X     }
  529. X
  530. X   }
  531. X
  532. X
  533. X#undef nextbuf  
  534. X#undef checkbuf 
  535. X#undef shiftout
  536. X#undef issync
  537. X#undef seeksync
  538. X
  539. X }
  540. X
  541. X
  542. X
  543. X
  544. Xenum ERRORS readplain(sizeinfo *si,int fak,implane *l,implane *c1,implane *c2)
  545. X {dim i,w,h,hoff,hlen,voff,vlen;
  546. X  uBYTE *pl=0,*pc1=0,*pc2=0;
  547. X
  548. X  melde("readplain\n");
  549. X
  550. X#ifdef DEBUG
  551. X  fprintf(stderr,"readplain %d %d %d %d %d %d %d\n",fak,si->w,si->h,si->rdhoff,si->rdhlen,si->rdvoff,si->rdvlen);
  552. X#endif
  553. X
  554. X  if(fak >= 0)
  555. X   {w   =si->w     *fak;
  556. X    h   =si->h     *fak;
  557. X    hoff=si->rdhoff*fak;  if(hoff & 1 ) error(E_INTERN);  /* Must be all even */
  558. X    hlen=si->rdhlen*fak;  if(hlen & 1 ) error(E_INTERN);
  559. X    voff=si->rdvoff*fak;  if(voff & 1 ) error(E_INTERN);
  560. X    vlen=si->rdvlen*fak;  if(vlen & 1 ) error(E_INTERN);
  561. X   }
  562. X  else
  563. X   {fak = -fak;
  564. X    w   =si->w     /fak;
  565. X    h   =si->h     /fak;
  566. X    hoff=si->rdhoff/fak;  if(hoff & 1 ) error(E_INTERN);  /* Must be all even */
  567. X    hlen=si->rdhlen/fak;  if(hlen & 1 ) error(E_INTERN);
  568. X    voff=si->rdvoff/fak;  if(voff & 1 ) error(E_INTERN);
  569. X    vlen=si->rdvlen/fak;  if(vlen & 1 ) error(E_INTERN);
  570. X   }
  571. X
  572. X
  573. X    
  574. X  if(l)
  575. X   { if ((l->mwidth<hlen) || (l->mheight<vlen) || (!l->im)) error(E_INTERN);
  576. X     l->iwidth=hlen;
  577. X     l->iheight=vlen;
  578. X     pl=l->im;
  579. X   }
  580. X
  581. X  if(c1)
  582. X   { if ((c1->mwidth<(hlen>>1)) || (c1->mheight<(vlen>>1)) || (!c1->im)) error(E_INTERN);
  583. X     c1->iwidth=hlen>>1;
  584. X     c1->iheight=vlen>>1;
  585. X     pc1=c1->im;
  586. X   }
  587. X
  588. X  if(c2)
  589. X   { if ((c2->mwidth<(hlen>>1)) || (c2->mheight<(vlen>>1)) || (!c2->im)) error(E_INTERN);
  590. X     c2->iwidth=hlen>>1;
  591. X     c2->iheight=vlen>>1;
  592. X     pc2=c2->im;
  593. X   }
  594. X
  595. X  if(voff) SKIPr(w*3*(voff>>1));
  596. X
  597. X  for(i=0;i<vlen>>1;i++)
  598. X   {
  599. X    if(pl)
  600. X     { if(hlen==w)
  601. X        {if(READ(pl,w)<1) return(E_READ);
  602. X         pl+= l->mwidth;
  603. X
  604. X         if(READ(pl,w)<1) return(E_READ);
  605. X         pl+= l->mwidth;
  606. X        }
  607. X       else
  608. X        {SKIPr(hoff);
  609. X
  610. X         if(READ(pl,hlen)<1) return(E_READ);
  611. X         pl+= l->mwidth;
  612. X         
  613. X         SKIPr(w-hlen);    /* w - hlen - hoff + hoff */ 
  614. X
  615. X         if(READ(pl,hlen)<1) return(E_READ);
  616. X         pl+= l->mwidth;
  617. X
  618. X         SKIPr(w-hoff-hlen);         
  619. X        }
  620. X     }
  621. X    else SKIPr(2*w);
  622. X     
  623. X    if(pc1)
  624. X     {
  625. X       if(hlen==w)
  626. X        {
  627. X         if(READ(pc1,w>>1)<1) return(E_READ);
  628. X         pc1+= c1->mwidth;
  629. X        }
  630. X       else
  631. X        {SKIPr((hoff)>>1);
  632. X         if(READ(pc1,hlen>>1)<1) return(E_READ);
  633. X         pc1+= c1->mwidth;
  634. X         SKIPr((w-hoff-hlen)>>1);
  635. X        }
  636. X     }
  637. X    else SKIPr(w>>1);
  638. X     
  639. X    if(pc2)
  640. X     {
  641. X       if(hlen==w)
  642. X        {
  643. X         if(READ(pc2,w>>1)<1) return(E_READ);
  644. X         pc2+= c2->mwidth;
  645. X        }
  646. X       else
  647. X        {SKIPr((hoff)>>1);
  648. X         if(READ(pc2,hlen>>1)<1) return(E_READ);
  649. X         pc2+= c2->mwidth;
  650. X         SKIPr((w-hoff-hlen)>>1);
  651. X        }
  652. X     }
  653. X    else SKIPr(w>>1);
  654. X
  655. X
  656. X   }
  657. X  RPRINT;
  658. X  return E_NONE;
  659. X }
  660. END_OF_FILE
  661.   if test 11918 -ne `wc -c <'hpcdtoppm.0.5.pl1/format.c'`; then
  662.     echo shar: \"'hpcdtoppm.0.5.pl1/format.c'\" unpacked with wrong size!
  663.   fi
  664.   # end of 'hpcdtoppm.0.5.pl1/format.c'
  665. fi
  666. if test -f 'hpcdtoppm.0.5.pl1/hpcdtoppm.man' -a "${1}" != "-c" ; then 
  667.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/hpcdtoppm.man'\"
  668. else
  669.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/hpcdtoppm.man'\" \(6820 characters\)
  670.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/hpcdtoppm.man' <<'END_OF_FILE'
  671. X.TH hpcdtoppm 1 " 5 Aug 1993"
  672. X.IX hpcdtoppm
  673. X.SH NAME
  674. Xhpcdtoppm v0.5 pl1 - convert a Photo-CD file into a portable pixmap
  675. X.SH SYNOPSIS
  676. X.B hpcdtoppm
  677. X[options] pcd-file [ppm-file]
  678. X.SH DESCRIPTION
  679. XDecodes a Photo-CD Image file or Overview file.
  680. XImage files you can find on the Photo-CD in photo_cd/images, they are named
  681. Xas "imgnnnn.pcd", where nnnn is a 4-digit-number. The Overview file is at
  682. Xphoto_cd/overview.pcd . If there is no output filename given, output will be
  683. Xprinted to stdout. hpcdtoppm stands for "Hadmut's pcdtoppm" to make it
  684. Xdistinguishable in case someone else is building the same thing and
  685. Xcalling it pcdtoppm. Call hpcdtoppm without arguments to see the 
  686. Xdefaults values. If pcd-file is "-", the Photo-CD file is read from
  687. Xstdin.
  688. X.IX GIF
  689. X.SH OPTIONS
  690. X.TP
  691. X.B -x
  692. XOverskip Mode. Works on Base/16, Base/4, Base and 4Base. In Photo-CD
  693. Ximages the luma channel is stored in full resolution, the two chroma
  694. Xchannels are stored in half resolution only and have to be interpolated.
  695. XIn the Overskip Mode the chroma channels of the next higher resolution are
  696. Xtaken instead of interpolating. To see the difference, generate one ppm with
  697. Xand one ppm without this flag. Use pnmarith to generate the difference image
  698. Xof these two images. Call ppmhist for this difference or show it with xv
  699. X(push the HistEq button in the color editor).
  700. X.TP
  701. X.B -s
  702. XApply simple sharpness-operator on the Luma-channel.
  703. X.TP
  704. X.B -d
  705. XDo not show the complete image, but only the decompressed difference.
  706. XIt works only on the 4Base and the 16Base resolution. It does not
  707. Xhave any deeper sense, but it was simple to implement and it shows what
  708. Xcauses different sizes of image files.
  709. X.TP
  710. X.B -i
  711. XGive some information from the fileheader to stderr. It works only for 
  712. XImage files. (It is not working correctly, just printing some strings.)
  713. X.TP
  714. X.B -m
  715. XShow the phases of decoding to stderr.
  716. X.TP
  717. X.B -crop
  718. XTry to cut off the black frame which is sometimes scanned
  719. Xat the image borders. The image size shrinks.
  720. X.TP
  721. X.B -pos
  722. XPrint the file relative start position of the data for
  723. Xthe current resolution.
  724. X.TP
  725. X.B -rep
  726. XTry to jump over reading errors in Huffman code. 
  727. X.TP
  728. X.B -n
  729. XDon't rotate the image.
  730. X.TP
  731. X.B -r
  732. XRotate the picture clockwise for portraits.
  733. X.TP
  734. X.B -l
  735. XRotate the picture counter-clockwise for portraits.
  736. X.TP
  737. X.B -a
  738. XTry to find out the image orientation byself. This doesn't work
  739. Xfor overview files yet. It is very experimental and depends on
  740. Xone byte. Please tell me if it doesn't work.
  741. X.TP
  742. X.B -vert
  743. XVertical flip.
  744. X.TP
  745. X.B -hori
  746. XHorizontal flip.
  747. X.TP
  748. X.B -S h v
  749. XCut out subrectangle with boundaries h (longer side of the image) and
  750. Xv (shorter side). h and v are of the form a-b ( cut from a to b ) or
  751. Xa+b ( offset a, length b). a and b are integer (pixels) or float 
  752. X[0.0 ... 1.0] relative to the length of the side.
  753. X.TP
  754. X.B -ppm
  755. XWrite rgb image in ppm-format.
  756. X.TP
  757. X.B -pgm
  758. XWrite grayscale image in pgm-format.
  759. X.TP
  760. X.B -ycc
  761. XWrite ycc image in ppm-format.
  762. X.TP
  763. X.B -ps
  764. XWrite rgb image in postscript.
  765. X.TP
  766. X.B -eps
  767. XWrite rgb image in encapsulated postscript.
  768. X.TP
  769. X.B -psg
  770. XWrite grayscale image in postscript.
  771. X.TP
  772. X.B -epsg
  773. XWrite grayscale image in encapsulated postscript.
  774. X.TP
  775. X.B -psd
  776. XWrite a Floyd-Steinberg dithered image in postscript.
  777. XSee the Postscript section below.
  778. X.TP
  779. X.B -epsd
  780. XWrite a Floyd-Steinberg dithered image in encapsulated postscript.
  781. XSee the Postscript section below.
  782. X.TP
  783. X.B -pl f
  784. XSet left position of Postscript image to f.
  785. X.TP
  786. X.B -pb f
  787. XSet bottom position of Postscript image to f.
  788. X.TP
  789. X.B -pw f
  790. XSet width of Postscript image to f.
  791. X.TP
  792. X.B -ph f
  793. XSet height of Postscript image to f.
  794. X.TP
  795. X.B -dpi f
  796. XSet printer resolution for dithered postscript images. 
  797. XSee the Postscript section below.
  798. X.TP
  799. X.B -fak f
  800. XSets a scaling factor for dithered postscript images. 
  801. XSee the Postscript section below.
  802. X.TP
  803. X.B -c0
  804. XDon't correct the image.
  805. X.TP
  806. X.B -c-
  807. XDo a correction (darker). Hardware and taste dependend.
  808. X.TP
  809. X.B -c+
  810. XDo a correction (brighter). Hardware and taste dependend.
  811. X.TP
  812. X.B -1 | -Base/16 | -128x192
  813. XExtract the Base/16 size picture (size 128x192 pixels). Note that you
  814. Xcan only give one size option.
  815. X.TP
  816. X.B -2 | -Base/4 | -256x384
  817. XExtract the Base/4 size picture.
  818. X.TP
  819. X.B -3 | -Base | -512x768
  820. XExtract the Base size picture.
  821. X.TP
  822. X.B -4 | -4Base | -1024x1536
  823. XExtract the 4Base size picture.
  824. X.TP
  825. X.B -5 | -16Base | -2048x3072
  826. XExtract the 16Base size picture.
  827. X.TP
  828. X.B -0 | -Overview | -O
  829. XExtract all pictures from an Overview file. A ppmfilename must be given. If the
  830. Xgiven name is "foo", the files are named "foonnnn", where nnnn is a 4-digit number.
  831. XSince they are stored in Base/16 format, they are extracted in this format.
  832. X.TP
  833. X.B -C d s
  834. XExtract all pictures from an Overview file. A ppmfilename must be given. If the
  835. Xgiven name is "foo", the files are named "foonnnn", where nnnn is a 4-digit number.
  836. XSince they are stored in Base/16 format, they are extracted in this format. s is one
  837. Xof "n", "l" and "r" and determines the orientation of the contact sheet image.
  838. X
  839. X
  840. X.PP
  841. X
  842. X.SH POSTSCRIPT OUTPUT
  843. X
  844. XFor postscript output ( ps, eps, psg, epsg, psd, epsg ) you
  845. Xcan choose parameters for the resolution and placement on the paper.
  846. XThe default values are used if none of the following options is given.
  847. X
  848. XThe position of the image within the paper (down left corner) is changed
  849. Xwith the -pl and -pb option for all resolutions. The unit is 1/72 inch.
  850. X
  851. XFor color and grayscale postscript you can change the image size with
  852. Xthe -pw and -ph option (1/72 inch). Every image pixel is mapped onto one
  853. Xpostscript pixel.
  854. X
  855. XFor dithered postscript (-psd and -epsd) there are three options,
  856. Xthe image size (-pw and -ph), the printer resolution (-dpi) and
  857. Xa scaling factor (-fak). Since these values depend from each other,
  858. Xyou can not give more than two of these options. You should play with
  859. Xthese options to get the results you like. You will get pretty images
  860. Xif you use the -dpi and the -pw/-ph options together. Even if you
  861. Xuse the default values, the result will not be the same as without
  862. Xoptions. 
  863. X
  864. X
  865. X.PP
  866. X
  867. X.SH BUGS
  868. Xhpcdtoppm seems to ignore the read protection. :-)
  869. XThe informations i have are quite vague and this program
  870. Xwas developed by staring at the hex-dumps and the famous 
  871. Xtrial-and-error-method. If anything
  872. Xdoesn't work, please send me a report and perhaps you could try to
  873. Xfind out, why it doesn't work.
  874. X.SH "SEE ALSO"
  875. Xppm(5), ppmquant(1), ppmtopgm(1), ppmhist(1), pnmarith(1), ppmtorgb3(1), xv(1)
  876. X.SH AUTHOR
  877. XCopyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  878. XPermission to use and distribute this software and its
  879. Xdocumentation for noncommercial use and without fee is hereby granted,
  880. Xprovided that the above copyright notice appear in all copies and that
  881. Xboth that copyright notice and this permission notice appear in
  882. Xsupporting documentation. It is not allowed to sell this software in 
  883. Xany way. This software is not public domain.
  884. END_OF_FILE
  885.   if test 6820 -ne `wc -c <'hpcdtoppm.0.5.pl1/hpcdtoppm.man'`; then
  886.     echo shar: \"'hpcdtoppm.0.5.pl1/hpcdtoppm.man'\" unpacked with wrong size!
  887.   fi
  888.   # end of 'hpcdtoppm.0.5.pl1/hpcdtoppm.man'
  889. fi
  890. if test -f 'hpcdtoppm.0.5.pl1/output.c' -a "${1}" != "-c" ; then 
  891.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/output.c'\"
  892. else
  893.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/output.c'\" \(5153 characters\)
  894.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/output.c' <<'END_OF_FILE'
  895. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  896. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  897. X*  Permission to use and distribute this software and its
  898. X*  documentation for noncommercial use and without fee is hereby granted,
  899. X*  provided that the above copyright notice appear in all copies and that
  900. X*  both that copyright notice and this permission notice appear in
  901. X*  supporting documentation. It is not allowed to sell this software in 
  902. X*  any way. This software is not public domain.
  903. X*/
  904. X
  905. X#include "hpcdtoppm.h"
  906. X
  907. X
  908. X
  909. X
  910. Xstatic void flip_corr(dim w,dim h,uBYTE **ptr,sdim *ystep,sdim *xstep)
  911. X {if(flvert) 
  912. X   { (*ptr) += (h-1)* (*ystep);
  913. X     (*ystep) = -(*ystep);
  914. X   }
  915. X
  916. X  if(flhori)
  917. X   {(*ptr) += (w-1)* (*xstep);
  918. X    (*xstep) = -(*xstep);
  919. X   }
  920. X }
  921. X
  922. X
  923. X
  924. X
  925. Xstatic void call_1plane(OUT1PL proc, FILE *fout,
  926. X                        dim w,    dim h,uBYTE * ptr,
  927. X                        sdim zeil, sdim pix) 
  928. X {
  929. X  flip_corr(w,h,&ptr,&zeil,&pix);
  930. X  (*proc)(fout,w,h,ptr,zeil,pix);
  931. X }
  932. X
  933. X
  934. X
  935. Xstatic void do_1plane(OUT1PL proc, FILE *fout,
  936. X                      dim w,dim h,implane *g,enum TURNS t)
  937. X {
  938. X   switch(t)
  939. X    {case T_NONE: call_1plane(proc,fout,w,h,g->im,g->mwidth,1);
  940. X                  break;
  941. X     case T_RIGHT:call_1plane(proc,fout,h,w,g->im + g->mwidth * ( g->iheight - 1) , 1 , -(g->mwidth));
  942. X                  break;
  943. X     case T_LEFT: call_1plane(proc,fout,h,w,g->im + g->iwidth - 1 , -1 , (g->mwidth));
  944. X                  break; 
  945. X     case T_HEAD: call_1plane(proc,fout,w,h,g->im + g->iwidth - 1 + g->mwidth * ( g->iheight - 1)  , -(g->mwidth) , -1);
  946. X                  break;     
  947. X     default:error(E_INTERN);
  948. X    }
  949. X
  950. X }
  951. X
  952. X
  953. X
  954. X
  955. X
  956. X
  957. X
  958. Xstatic void call_3plane(OUT3PL proc, FILE *fout,  dim w,dim h, 
  959. X                        uBYTE *rptr,sdim rzeil,sdim rpix,  
  960. X                        uBYTE *gptr,sdim gzeil,sdim gpix,  
  961. X                        uBYTE *bptr,sdim bzeil,sdim bpix) 
  962. X {
  963. X  flip_corr(w,h,&rptr,&rzeil,&rpix);
  964. X  flip_corr(w,h,&gptr,&gzeil,&gpix);
  965. X  flip_corr(w,h,&bptr,&bzeil,&bpix);
  966. X
  967. X  (*proc)(fout,w,h,rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix );
  968. X }
  969. X
  970. X
  971. Xstatic void do_3plane(OUT3PL proc,FILE *fout,dim w,dim h,
  972. X                      implane *r,implane *g,implane *b,
  973. X                      enum TURNS t)
  974. X {
  975. X   switch(t)
  976. X    {case T_NONE: call_3plane(proc,fout,w,h,r->im,r->mwidth,1,
  977. X                                            g->im,g->mwidth,1,
  978. X                                            b->im,b->mwidth,1);
  979. X                  break;     
  980. X     case T_RIGHT:call_3plane(proc,fout,h,w,r->im + r->mwidth * ( r->iheight - 1) , 1 , -(r->mwidth),
  981. X                                            g->im + g->mwidth * ( g->iheight - 1) , 1 , -(g->mwidth),
  982. X                                            b->im + b->mwidth * ( b->iheight - 1) , 1 , -(b->mwidth));
  983. X                  break;     
  984. X     case T_LEFT: call_3plane(proc,fout,h,w,r->im + r->iwidth - 1 , -1 , (r->mwidth),
  985. X                                            g->im + g->iwidth - 1 , -1 , (g->mwidth),
  986. X                                            b->im + b->iwidth - 1 , -1 , (b->mwidth));
  987. X                  break;           
  988. X     case T_HEAD: call_3plane(proc,fout,w,h,r->im + r->iwidth - 1 + r->mwidth * ( r->iheight - 1)  , -(r->mwidth) , -1,
  989. X                                            g->im + g->iwidth - 1 + g->mwidth * ( g->iheight - 1)  , -(g->mwidth) , -1,
  990. X                                            b->im + b->iwidth - 1 + b->mwidth * ( b->iheight - 1)  , -(b->mwidth) , -1);
  991. X                  break;     
  992. X     default:error(E_INTERN);
  993. X    }
  994. X
  995. X }
  996. X
  997. X
  998. X
  999. X
  1000. X
  1001. X
  1002. X
  1003. X
  1004. X
  1005. X
  1006. X
  1007. Xvoid writepicture(FILE *fout, sizeinfo *si, 
  1008. X                  implane *r,implane *g,implane *b,
  1009. X                  enum TURNS t)
  1010. X {dim w,h;
  1011. X
  1012. X  w=si->imhlen;
  1013. X  h=si->imvlen;
  1014. X
  1015. X  melde("writepicture\n");
  1016. X     if((!r) || (r->iwidth != w ) || (r->iheight != h) || (!r->im)) error(E_INTERN);
  1017. X  
  1018. X  if(!monochrome)
  1019. X   {
  1020. X     if((!g) || (g->iwidth != w ) || (g->iheight != h) || (!g->im)) error(E_INTERN);
  1021. X     if((!b) || (b->iwidth != w ) || (b->iheight != h) || (!b->im)) error(E_INTERN);
  1022. X   }
  1023. X
  1024. X  switch(outfor)
  1025. X   {case O_YCC:
  1026. X    case O_PPM:  do_3plane(write_ppm     ,fout,w,h,r,g,b,t); break;
  1027. X    case O_PS:   do_3plane(write_psrgb   ,fout,w,h,r,g,b,t); break;
  1028. X    case O_EPS:  do_3plane(write_epsrgb  ,fout,w,h,r,g,b,t); break;
  1029. X
  1030. X    case O_PGM:  do_1plane(write_pgm     ,fout,w,h,r,t);     break;
  1031. X    case O_PSG:  do_1plane(write_psgrey  ,fout,w,h,r,t);     break;
  1032. X    case O_EPSG: do_1plane(write_epsgrey ,fout,w,h,r,t);     break;
  1033. X    case O_PSD:  do_1plane(write_psdith  ,fout,w,h,r,t);     break;
  1034. X    case O_EPSD: do_1plane(write_epsdith ,fout,w,h,r,t);     break;
  1035. X    default: error(E_INTERN);
  1036. X   }
  1037. X
  1038. X
  1039. X }
  1040. X
  1041. X
  1042. X
  1043. X
  1044. X
  1045. X
  1046. X
  1047. X
  1048. X
  1049. Xstruct ph1 
  1050. X {char  id1[8];
  1051. X  uBYTE ww1[14];
  1052. X  char  id2[20];
  1053. X  char  id3[4*16+4];
  1054. X  short ww2;
  1055. X  char  id4[20];
  1056. X  uBYTE ww3[2*16+1];
  1057. X  char  id5[4*16];
  1058. X  uBYTE idx[11*16];
  1059. X } ;
  1060. X
  1061. X
  1062. Xvoid druckeid(void)
  1063. X{struct ph1 *d;
  1064. X char ss[100];
  1065. X
  1066. X d=(struct ph1 *)sbuffer;
  1067. X
  1068. X#define dr(feld,kennung)   \
  1069. X     strncpy(ss,feld,sizeof(feld));\
  1070. X     ss[sizeof(feld)]=0;\
  1071. X     fprintf(stderr,"%s: %s \n",kennung,ss);
  1072. X
  1073. X
  1074. Xdr(d->id1,"Id1")
  1075. Xdr(d->id2,"Id2")
  1076. Xdr(d->id3,"Id3")
  1077. Xdr(d->id4,"Id4")
  1078. Xdr(d->id5,"Id5")
  1079. X
  1080. X#undef dr 
  1081. X
  1082. X}
  1083. X
  1084. X
  1085. X
  1086. X
  1087. X
  1088. X
  1089. END_OF_FILE
  1090.   if test 5153 -ne `wc -c <'hpcdtoppm.0.5.pl1/output.c'`; then
  1091.     echo shar: \"'hpcdtoppm.0.5.pl1/output.c'\" unpacked with wrong size!
  1092.   fi
  1093.   # end of 'hpcdtoppm.0.5.pl1/output.c'
  1094. fi
  1095. if test -f 'hpcdtoppm.0.5.pl1/pcdindex' -a "${1}" != "-c" ; then 
  1096.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/pcdindex'\"
  1097. else
  1098.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/pcdindex'\" \(4832 characters\)
  1099.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/pcdindex' <<'END_OF_FILE'
  1100. X#!/bin/csh -f
  1101. X#
  1102. X# pcdindex - generate a single PPM file from a PCD overview file
  1103. X#
  1104. X# This script assumes that the PBMPLUS and hpcdtoppm software
  1105. X# packages are installed, and that /tmp has enough space
  1106. X# (worst case 150Kbyte per image).
  1107. X# Based on pnmindex (PBMPLUS), which was written by Jef Poskanzer,
  1108. X# this script makes also use of hpcdtoppm, written by Hadmut Danisch.
  1109. X#
  1110. X# A similar result can be achieved by using "hpcdtoppm -Overview"
  1111. X# followed by "pnmindex -black" on the generated PPM images.
  1112. X# This shell just makes it more convenient and transparent to
  1113. X# convert from one PCD to one PPM overview file.
  1114. X#
  1115. X# Additional options (compared to pnmindex) are -maxwidth and
  1116. X# -font <font>. See "man pbmtext" on how to create your own font.
  1117. X#
  1118. X# Pieter S. van der Meulen, 1992.
  1119. X
  1120. X# You may want to change the default values in the next 6 lines:
  1121. Xset maxwidth=1152    # maximum width of the index image
  1122. Xset size=192        # make the images about this big
  1123. Xset across=6        # show this many images per row
  1124. Xset colors="noquant"    # maximum amount of colors or noquant (no quantization)
  1125. Xset back="-black"    # default background color
  1126. Xset font=" "        # default font or none (pbmtext's internal font)
  1127. X
  1128. X# Parse the options
  1129. Xwhile ( 1 )
  1130. X    switch ( "$1" )
  1131. X
  1132. X    case -m*:
  1133. X    if ( $#argv < 2 ) goto usage
  1134. X    set maxwidth="$2"
  1135. X    shift
  1136. X    shift
  1137. X    breaksw
  1138. X
  1139. X    case -s*:
  1140. X    if ( $#argv < 2 ) goto usage
  1141. X    set size="$2"
  1142. X    shift
  1143. X    shift
  1144. X    breaksw
  1145. X
  1146. X    case -a*:
  1147. X    if ( $#argv < 2 ) goto usage
  1148. X    set across="$2"
  1149. X    shift
  1150. X    shift
  1151. X    breaksw
  1152. X
  1153. X    case -c*:
  1154. X    set colors="$2"
  1155. X    shift
  1156. X    shift
  1157. X    breaksw
  1158. X
  1159. X    case -f*:
  1160. X    set font="-font $2"
  1161. X    shift
  1162. X    shift
  1163. X    breaksw
  1164. X
  1165. X    case -b*:
  1166. X    set back="-black"
  1167. X    shift
  1168. X    breaksw
  1169. X
  1170. X    case -w*:
  1171. X    set back="-white"
  1172. X    shift
  1173. X    breaksw
  1174. X
  1175. X    case -*:
  1176. X    echo "$0 : Unknown option $1"
  1177. X    echo " "
  1178. X    goto usage
  1179. X    breaksw
  1180. X
  1181. X    default:
  1182. X    break
  1183. X    breaksw
  1184. X
  1185. X    endsw
  1186. Xend
  1187. X
  1188. Xif ( $#argv == 0 ) then
  1189. X    goto usage
  1190. Xendif
  1191. X
  1192. Xset tmpfile=/tmp/pi.tmp.$$
  1193. Xrm -f $tmpfile
  1194. Xtouch /tmp/img0001 # Avoid complaints about non matching
  1195. Xrm -f /tmp/img*
  1196. X
  1197. Xset rowfiles=()
  1198. Xset imagefiles=()
  1199. X@ row = 1
  1200. X@ col = 1
  1201. X@ width = $size
  1202. X
  1203. X# Convert the PCD overview file to many PPM images
  1204. Xif (-f $1) then
  1205. X    hpcdtoppm -Overview $1 /tmp/img
  1206. Xelse
  1207. X    echo "$0 : Could not access $1"
  1208. X    echo " "
  1209. X    goto usage
  1210. Xendif
  1211. X
  1212. Xforeach i ( /tmp/img* )
  1213. X
  1214. Xif (-f $i) then
  1215. X    set description=`pnmfile $i`
  1216. X    if ( $description[4] <= $size && $description[6] <= $size ) then
  1217. X    cat $i > $tmpfile
  1218. X    else
  1219. X        if ( $colors =~ n* ) then
  1220. X        pnmscale -quiet -xysize $size $size $i > $tmpfile
  1221. X        else
  1222. X        pnmscale -quiet -xysize $size $size $i | ppmquant -quiet $colors > $tmpfile
  1223. X        endif
  1224. X    endif
  1225. X    set imagefile=/tmp/pi.${row}.${col}.$$
  1226. X    rm -f $imagefile
  1227. X    set ttext=$i:t
  1228. X    if ( "$back" == "-white" ) then
  1229. X    pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2| pnmcat $back -tb $tmpfile - > $imagefile
  1230. X    else
  1231. X    pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | pnminvert | pnmcat $back -tb $tmpfile - > $imagefile
  1232. X    endif
  1233. X    rm -f $tmpfile
  1234. X    set description=`pnmfile $imagefile`
  1235. X    @ width += $description[4]
  1236. X    set imagefiles=( $imagefiles $imagefile )
  1237. X
  1238. X    if (( $col >= $across ) || ( $width > $maxwidth)) then
  1239. X    set rowfile=/tmp/pi.${row}.$$
  1240. X    rm -f $rowfile
  1241. X    if ( $colors =~ n* ) then
  1242. X        pnmcat $back -lr -jbottom $imagefiles > $rowfile
  1243. X    else
  1244. X        pnmcat $back -lr -jbottom $imagefiles | ppmquant -quiet $colors > $rowfile
  1245. X    endif
  1246. X    rm -f $imagefiles
  1247. X    set imagefiles=()
  1248. X    set rowfiles=( $rowfiles $rowfile )
  1249. X    @ col = 1
  1250. X    @ row += 1
  1251. X    @ width = $size
  1252. X    else
  1253. X    @ col += 1
  1254. X    endif
  1255. Xendif
  1256. X
  1257. Xend
  1258. X
  1259. Xif ( $#imagefiles > 0 ) then
  1260. X    set rowfile=/tmp/pi.${row}.$$
  1261. X    rm -f $rowfile
  1262. X    if ( $colors =~ n* ) then
  1263. X    pnmcat $back -lr -jbottom $imagefiles > $rowfile
  1264. X    else
  1265. X    pnmcat $back -lr -jbottom $imagefiles | ppmquant -quiet $colors > $rowfile
  1266. X    endif
  1267. X    rm -f $imagefiles
  1268. X    set rowfiles=( $rowfiles $rowfile )
  1269. Xendif
  1270. X
  1271. Xif ( $#rowfiles == 1 ) then
  1272. X    cat $rowfiles
  1273. Xelse
  1274. X    if ( $colors =~ n* ) then
  1275. X    pnmcat $back -tb $rowfiles
  1276. X    else
  1277. X    pnmcat $back -tb $rowfiles | ppmquant -quiet $colors
  1278. X    endif
  1279. Xendif
  1280. Xrm -f $rowfiles
  1281. Xrm -f /tmp/img*
  1282. X
  1283. Xexit 0
  1284. X
  1285. Xusage:
  1286. X    echo "Usage: $0 [-m W] [-s S] [-a A] [-c N|n] [-f F] [-b|-w] <overview.pcd>"
  1287. X    echo " with"
  1288. X    echo "    W = maximum width of the result image    (default: $maxwidth)"
  1289. X    echo "    S = maximum size of each of the images    (default: $size)"
  1290. X    echo "    A = maximum number of images across    (default: $across)"
  1291. X    echo "    N = maximum number of colors or noquant    (default: $colors)"
  1292. X    echo -n "    F = font to be used for annotation      (default: "
  1293. X    if ( "$font" == " " ) then
  1294. X    echo "internal font)"
  1295. X    else
  1296. X    echo "$font)"
  1297. X    endif
  1298. X    echo "    -b/-w = black/white background color    (default: $back)"
  1299. X    echo " "
  1300. X    echo " e.g.: $0 -m 768 -s 96 -f smallfont.pbm overview.pcd > overview.ppm"
  1301. X    echo " or  : $0 /cdrom/photo_cd/overview.pcd | cjpeg > overview.jpg"
  1302. Xexit 1
  1303. X
  1304. X
  1305. END_OF_FILE
  1306.   if test 4832 -ne `wc -c <'hpcdtoppm.0.5.pl1/pcdindex'`; then
  1307.     echo shar: \"'hpcdtoppm.0.5.pl1/pcdindex'\" unpacked with wrong size!
  1308.   fi
  1309.   chmod +x 'hpcdtoppm.0.5.pl1/pcdindex'
  1310.   # end of 'hpcdtoppm.0.5.pl1/pcdindex'
  1311. fi
  1312. if test -f 'hpcdtoppm.0.5.pl1/postscr.c' -a "${1}" != "-c" ; then 
  1313.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/postscr.c'\"
  1314. else
  1315.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/postscr.c'\" \(10071 characters\)
  1316.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/postscr.c' <<'END_OF_FILE'
  1317. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  1318. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  1319. X*  Permission to use and distribute this software and its
  1320. X*  documentation for noncommercial use and without fee is hereby granted,
  1321. X*  provided that the above copyright notice appear in all copies and that
  1322. X*  both that copyright notice and this permission notice appear in
  1323. X*  supporting documentation. It is not allowed to sell this software in 
  1324. X*  any way. This software is not public domain.
  1325. X*/
  1326. X
  1327. X#include "hpcdtoppm.h"
  1328. X#define DITH_NEUTR 128
  1329. X
  1330. XFLTPT PAPER_LEFT    =DEF_PAPER_LEFT;
  1331. XFLTPT PAPER_BOTTOM  =DEF_PAPER_BOTTOM;
  1332. XFLTPT PAPER_WIDTH   =DEF_PAPER_WIDTH;
  1333. XFLTPT PAPER_HEIGHT  =DEF_PAPER_HEIGHT;
  1334. XFLTPT PRINTER_XDPI  =DEF_DPI;
  1335. XFLTPT PRINTER_YDPI  =DEF_DPI;
  1336. XFLTPT PRINTER_FAK   =1.0;
  1337. XsINT  PSIZE_SET=0,DPI_SET=0,FAK_SET=0;
  1338. X
  1339. X
  1340. Xstatic char pshdr[]="%%Creator: hpcdtoppm v0.5pl1\n";
  1341. Xstatic char hex[]="0123456789ABCDEF";
  1342. X#define HEX(x) {fputc(hex[((x)>>4)&0xf],fout);fputc(hex[(x)&0xf],fout);}
  1343. X
  1344. X
  1345. X/* find an appropriate scaling coefficient and generate a ps header
  1346. X * including a BoundingBox comment and a translate/scale sequence to 
  1347. X * fit the pixw*pixh image into a square on paper with PS user coordinates 
  1348. X * x,y,w,h 
  1349. X */
  1350. Xstatic void size_dependant(FILE *fout,sINT pixw,sINT pixh,
  1351. X                           FLTPT x,FLTPT y,FLTPT w,FLTPT h)
  1352. X{ FLTPT scale=(FLTPT)w/pixw,scaley=(FLTPT)h/pixh;
  1353. X
  1354. X  if(scale>scaley) scale=scaley;
  1355. X  x+=w/2.0;y+=h/2.0;
  1356. X  fprintf(fout,"%%%%BoundingBox: %.8g %.8g %.8g %.8g\n",
  1357. X     x-scale*pixw/2.0,y-scale*pixh/2.0,
  1358. X     x+scale*pixw/2.0,y+scale*pixh/2.0);
  1359. X  fprintf(fout,"%s",pshdr);
  1360. X  fputs("%%Pages: 1 1\n",fout);
  1361. X
  1362. X  if(pcdname) fprintf(fout,"%%%%Title: %s\n",pcdname);
  1363. X  fputs("%%EndComments\n\n",fout);
  1364. X
  1365. X  fprintf(fout,"%f %f translate\n",x-scale*pixw/2.0,y-scale*pixh/2.0);
  1366. X  fprintf(fout,"%f %f scale\n",scale*pixw,scale*pixh);
  1367. X}
  1368. X
  1369. X
  1370. X
  1371. Xstatic void end_postscript(FILE *fout)
  1372. X {
  1373. X  fputs("%%EOF\n\n",fout);
  1374. X }
  1375. X
  1376. X
  1377. X
  1378. X
  1379. Xstatic void sub_psgrey(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix)
  1380. X{ dim x,y;
  1381. X  register uBYTE *p;
  1382. X  sINT c;
  1383. X
  1384. X  size_dependant(fout,w,h,PAPER_LEFT,PAPER_BOTTOM,PAPER_WIDTH,PAPER_HEIGHT);
  1385. X  fprintf(fout,"%ld string\n",w);
  1386. X  fprintf(fout,"%ld %ld 8\n",w,h);    /* always 8 bit per channel */
  1387. X  fprintf(fout,"[%ld 0 0 %ld 0 %ld]\n",w,-h,h);
  1388. X  fputs("{currentfile 1 index readhexstring pop} image\n",fout);
  1389. X  
  1390. X  c=0;
  1391. X  for(y=0;y<h;y++,ptr+=zeil)
  1392. X    for(p=ptr,x=0;x<w;x++,p+=pix)
  1393. X      {HEX(*p);
  1394. X       if(!(++c % 36)) fputs("\n",fout);
  1395. X      }
  1396. X
  1397. X  fputs("\npop\n\n",fout);
  1398. X}
  1399. X
  1400. X
  1401. X
  1402. X
  1403. X
  1404. X
  1405. X
  1406. Xvoid write_epsgrey(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix)
  1407. X{ 
  1408. X  fputs("%!PS-Adobe-2.0 EPSF-2.0\n",fout);
  1409. X  sub_psgrey(fout,w,h, ptr,zeil,pix);
  1410. X  end_postscript(fout);
  1411. X}
  1412. X
  1413. Xvoid write_psgrey(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix)
  1414. X{ 
  1415. X  fputs("%!PS-Adobe-2.0\n",fout);
  1416. X  sub_psgrey(fout,w,h, ptr,zeil,pix);
  1417. X  fputs("showpage\n",fout);
  1418. X  end_postscript(fout);
  1419. X}
  1420. X
  1421. X
  1422. X
  1423. X
  1424. X
  1425. X
  1426. X
  1427. X
  1428. X
  1429. X
  1430. X
  1431. Xstatic void sub_psrgb(FILE *fout,dim w,dim h, 
  1432. X                      uBYTE *rptr,sdim rzeil,sdim rpix,  
  1433. X              uBYTE *gptr,sdim gzeil,sdim gpix,  
  1434. X              uBYTE *bptr,sdim bzeil,sdim bpix) 
  1435. X{ dim x,y;
  1436. X  register uBYTE *pr,*pg,*pb;
  1437. X  sINT c;
  1438. X
  1439. X  size_dependant(fout,w,h,PAPER_LEFT,PAPER_BOTTOM,PAPER_WIDTH,PAPER_HEIGHT);
  1440. X  fprintf(fout,"%ld string\n",w*3);
  1441. X  fprintf(fout,"%ld %ld 8\n",w,h);    /* always 8 bit per channel */
  1442. X  fprintf(fout,"[%ld 0 0 %ld 0 %ld]\n",w,-h,h);
  1443. X  fputs("{currentfile 1 index readhexstring pop} false 3 colorimage\n",fout);
  1444. X  
  1445. X  c=0; 
  1446. X  for(y=0;y<h;y++,rptr+=rzeil,gptr+=gzeil,bptr+=bzeil)
  1447. X    for(pr=rptr,pg=gptr,pb=bptr,x=0;x<w;x++,pr+=rpix,pg+=gpix,pb+=bpix)
  1448. X      {HEX(*pr);HEX(*pg);HEX(*pb);
  1449. X       if(!(++c % 12)) fputs("\n",fout);
  1450. X      }
  1451. X
  1452. X  fputs("\npop\n\n",fout);
  1453. X}
  1454. X
  1455. X
  1456. Xvoid write_epsrgb(FILE *fout,dim w,dim h, 
  1457. X                      uBYTE *rptr,sdim rzeil,sdim rpix,  
  1458. X              uBYTE *gptr,sdim gzeil,sdim gpix,  
  1459. X              uBYTE *bptr,sdim bzeil,sdim bpix) 
  1460. X{ 
  1461. X  fputs("%!PS-Adobe-2.0 EPSF-2.0\n",fout);
  1462. X  sub_psrgb(fout,w,h, rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix);
  1463. X  end_postscript(fout);
  1464. X}
  1465. X
  1466. X
  1467. X
  1468. Xvoid write_psrgb(FILE *fout,dim w,dim h, 
  1469. X                      uBYTE *rptr,sdim rzeil,sdim rpix,  
  1470. X              uBYTE *gptr,sdim gzeil,sdim gpix,  
  1471. X              uBYTE *bptr,sdim bzeil,sdim bpix) 
  1472. X{ 
  1473. X  fputs("%!PS-Adobe-2.0\n",fout);
  1474. X  sub_psrgb(fout,w,h, rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix);
  1475. X  fputs("showpage\n",fout);
  1476. X  end_postscript(fout);
  1477. X}
  1478. X
  1479. X
  1480. X
  1481. X
  1482. X
  1483. X
  1484. X
  1485. X
  1486. X
  1487. Xtypedef sINT dt;
  1488. Xextern sINT dithtab[];
  1489. X#define DS 4
  1490. X#define DA (1<<(DS-1))
  1491. X#define DT 127
  1492. X
  1493. Xstatic void fakcopy(dim worig,dim horig, uBYTE *ptr1,sdim zeil,sdim pix,
  1494. X                    sdim wx,sINT zn,dt *dest)
  1495. X {FLTPT owf,ohf,wbruch,hbruch,m1,m2,ha,hb;
  1496. X  dim   owd,ohd,x;
  1497. X  uBYTE *ptr2;
  1498. X  sINT  md;
  1499. X  
  1500. X  ohf=zn/PRINTER_FAK;
  1501. X  ohd=(dim)ohf;
  1502. X  hbruch=ohf-(FLTPT)ohd;
  1503. X  if(ohd>=horig) error(E_INTERN);
  1504. X
  1505. X  ptr1+=zeil*ohd;
  1506. X  ptr2= (ohd < horig - 1) ? ptr1+zeil : ptr1;
  1507. X
  1508. X  dest[-1]=DITH_NEUTR;
  1509. X
  1510. X  for(x=0;x<wx;x++)
  1511. X   {owf=x/PRINTER_FAK;
  1512. X    owd=(dim)owf;
  1513. X    wbruch=owf-(FLTPT)owd;
  1514. X    if(owd>=worig) error(E_INTERN);
  1515. X
  1516. X    if(owd<worig-1)
  1517. X     {ha=(FLTPT)ptr1[owd*pix];
  1518. X      hb=(FLTPT)ptr1[(owd+1)*pix];
  1519. X      m1=ha+wbruch*(hb-ha);
  1520. X
  1521. X      ha=(FLTPT)ptr2[owd*pix];
  1522. X      hb=(FLTPT)ptr2[(owd+1)*pix];
  1523. X      m2=ha+wbruch*(hb-ha);
  1524. X     }
  1525. X    else
  1526. X     { m1=(FLTPT)ptr1[owd*pix];
  1527. X       m2=(FLTPT)ptr2[owd*pix];
  1528. X     }
  1529. X    md=(sINT)(m1+hbruch*(m2-m1));
  1530. X    if(md<0 || md>255) {fprintf(stderr,"md %d\n",md); error(E_INTERN);}
  1531. X    *(dest++)=dithtab[md];
  1532. X
  1533. X   }
  1534. X  
  1535. X  dest[0]=DITH_NEUTR;
  1536. X }
  1537. X
  1538. Xstatic void sub_psdith(FILE *fout,dim worig,dim horig, uBYTE *ptr,sdim zeil,sdim pix)
  1539. X{ register uBYTE *p;
  1540. X  sINT c,i,ii,j,reg,bit;
  1541. X  dt new,diff;
  1542. X  dt *dP1,*dP2,*akt,*nex,*help,*rrun;
  1543. X  dim ww=0,wl=0,wr=0,hh=0,ho=0,hu=0,wx=0,hx=0;
  1544. X  int ccase;
  1545. X  FLTPT PW=0.0,PH=0.0;
  1546. X
  1547. X#define copy(n,d) {if(FAK_SET) fakcopy(worig,horig,ptr,zeil,pix,wx,n,d); \
  1548. X                   else{p=ptr+((n)*zeil); rrun=d;\
  1549. X                        for(ii=0;ii<wx;ii++,p+=pix,rrun++) *rrun = dithtab[*p]; \
  1550. X                        d[-1]=d[wx]=DITH_NEUTR; }}
  1551. X
  1552. X
  1553. X#define pr(x) { reg= (reg<<1) | x; bit++;    \
  1554. X     if(bit==8) {HEX(reg);   \
  1555. X                 if(!(++c % 36)) fputs("\n",fout);\
  1556. X                 bit=reg=0;}}
  1557. X
  1558. X#define flush { while(bit) pr(1); }
  1559. X#define fill pr(1)
  1560. X
  1561. X
  1562. X
  1563. X#define MakeFit(wi,he) {  ww=(wi+7) & (~7);   wl=(ww-wi)/2;  wr=ww-wi-wl; \
  1564. X                          hh=(he+7) & (~7);   ho=(hh-he)/2;  hu=hh-he-ho; }
  1565. X
  1566. X
  1567. X  
  1568. X  ccase=( FAK_SET   ? 4 : 0 ) |
  1569. X        ( DPI_SET   ? 2 : 0 ) |
  1570. X        ( PSIZE_SET ? 1 : 0 ) ;
  1571. X
  1572. X  switch (ccase)
  1573. X   {case 0: /*  no option or -dpi option */
  1574. X    case 2: hx=horig;
  1575. X            wx=worig;
  1576. X            MakeFit(wx,hx);
  1577. X            PW=ww*72.0/PRINTER_XDPI;
  1578. X            PH=hh*72.0/PRINTER_YDPI;
  1579. X            break;
  1580. X
  1581. X    case 1: /* paper size set with -pw and/or -ph */
  1582. X            hx=horig;
  1583. X            wx=worig;
  1584. X            MakeFit(wx,hx);
  1585. X            PW=PAPER_WIDTH;
  1586. X            PH=PAPER_HEIGHT;
  1587. X            break;
  1588. X
  1589. X    case 6: /* -fak option (and perhaps -dpi) */
  1590. X    case 4: hx=PRINTER_FAK*horig+0.5;
  1591. X            wx=PRINTER_FAK*worig+0.5;
  1592. X            MakeFit(wx,hx);
  1593. X            PW=ww*72.0/PRINTER_XDPI;
  1594. X            PH=hh*72.0/PRINTER_YDPI; 
  1595. X            break;
  1596. X
  1597. X    case 5: /* -fak and papersize */
  1598. X            hx=PRINTER_FAK*horig+0.5;
  1599. X            wx=PRINTER_FAK*worig+0.5;
  1600. X            MakeFit(wx,hx);
  1601. X            PW=PAPER_WIDTH;
  1602. X            PH=PAPER_HEIGHT;
  1603. X            break;
  1604. X
  1605. X    case 3: /* papersize and dpi set, probably the most important case */
  1606. X            PW=PAPER_WIDTH;
  1607. X            PH=PAPER_HEIGHT;
  1608. X
  1609. X            FAK_SET=1;
  1610. X            {FLTPT fw,fh;
  1611. X             fw=PW/72.0*PRINTER_XDPI/worig;
  1612. X             fh=PH/72.0*PRINTER_YDPI/horig;
  1613. X             PRINTER_FAK=MIN(fw,fh);
  1614. X            }
  1615. X            hx=PRINTER_FAK*horig+0.5;
  1616. X            wx=PRINTER_FAK*worig+0.5;
  1617. X            MakeFit(wx,hx);
  1618. X            PW=ww*72.0/PRINTER_XDPI;
  1619. X            PH=hh*72.0/PRINTER_YDPI; 
  1620. X            break;
  1621. X
  1622. X
  1623. X    case 7: /* size, dpi and factor set, this case should have been
  1624. X               cought earlier... */
  1625. X    default: error(E_INTERN);
  1626. X   };
  1627. X
  1628. X  if(FAK_SET && (PRINTER_FAK<=0.0  || PRINTER_FAK >=1000.0)) error(E_PRPAR);
  1629. X  if(PW<=0.0 || PH<=0.0) error(E_PRPAR);
  1630. X
  1631. X  if(wx < 4 || hx < 4) error(E_PRPAR);
  1632. X
  1633. X
  1634. X  if (!(dP1=(dt *)malloc((wx+2)*sizeof(dt)))) error(E_MEM);
  1635. X  if (!(dP2=(dt *)malloc((wx+2)*sizeof(dt)))) error(E_MEM);
  1636. X
  1637. X
  1638. X
  1639. X  size_dependant(fout,ww,hh,PAPER_LEFT,PAPER_BOTTOM,PW,PH);
  1640. X
  1641. X  fprintf(fout,"%ld string\n",ww);
  1642. X  fprintf(fout,"%ld %ld 1\n",ww,hh);    /* always 8 bit per channel */
  1643. X  fprintf(fout,"[%ld 0 0 %ld 0 %ld]\n",ww,-hh,hh);
  1644. X  fputs("{currentfile 1 index readhexstring pop} image\n",fout);
  1645. X  
  1646. X  c=bit=reg=0;
  1647. X  akt=dP1+1;
  1648. X  nex=dP2+1;
  1649. X
  1650. X  for(i=0;i<ho;i++)
  1651. X    for(j=0;j<ww;j++)
  1652. X      fill;
  1653. X
  1654. X  copy(0,nex);
  1655. X  for(i=0;i<hx;i++)
  1656. X   {help=akt; akt=nex; nex=help;
  1657. X    if(i<hx-1) copy(i+1,nex);
  1658. X
  1659. X    if(i&1)
  1660. X      for(j=0;j<wx;j++)
  1661. X       { new=akt[j]>DT ? 255 : 0;
  1662. X         diff = akt[j]-new;
  1663. X         akt[j]=new;
  1664. X         akt[j+1]+=(diff*7 + DA)>>DS;
  1665. X         nex[j+1]+=(diff   + DA)>>DS;
  1666. X         nex[j  ]+=(diff*5 + DA)>>DS;
  1667. X         nex[j-1]+=(diff*3 + DA)>>DS;
  1668. X       }
  1669. X    else
  1670. X      for(j=wx-1;j>=0;j--)
  1671. X       { new=akt[j]>DT ? 255 : 0;
  1672. X         diff = akt[j]-new;
  1673. X         akt[j]=new;
  1674. X         akt[j-1]+=(diff*7 + DA)>>DS;
  1675. X         nex[j-1]+=(diff   + DA)>>DS;
  1676. X         nex[j  ]+=(diff*5 + DA)>>DS;
  1677. X         nex[j+1]+=(diff*3 + DA)>>DS;
  1678. X       }
  1679. X
  1680. X
  1681. X    for(j=0;j<wl;j++) fill;
  1682. X
  1683. X    for(j=0;j<wx;j++)
  1684. X     {if (akt[j]>DT) { pr(1); }
  1685. X      else           { pr(0); }
  1686. X     }
  1687. X
  1688. X    for(j=0;j<wr;j++) fill;
  1689. X
  1690. X    flush;
  1691. X   }
  1692. X
  1693. X  for(i=0;i<hu;i++)
  1694. X    for(j=0;j<ww;j++)
  1695. X      fill;
  1696. X  flush;
  1697. X
  1698. X  fputs("\npop\n\n",fout);
  1699. X  free(dP1);
  1700. X  free(dP2);
  1701. X}
  1702. X
  1703. X
  1704. Xvoid write_epsdith(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix)
  1705. X{ 
  1706. X  fputs("%!PS-Adobe-2.0 EPSF-2.0\n",fout);
  1707. X  sub_psdith(fout,w,h, ptr,zeil,pix);
  1708. X  end_postscript(fout);
  1709. X}
  1710. X
  1711. Xvoid write_psdith(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix)
  1712. X{ 
  1713. X  fputs("%!PS-Adobe-2.0\n",fout);
  1714. X  sub_psdith(fout,w,h, ptr,zeil,pix);
  1715. X  fputs("showpage\n",fout);
  1716. X  end_postscript(fout);
  1717. X}
  1718. X
  1719. X
  1720. X
  1721. END_OF_FILE
  1722.   if test 10071 -ne `wc -c <'hpcdtoppm.0.5.pl1/postscr.c'`; then
  1723.     echo shar: \"'hpcdtoppm.0.5.pl1/postscr.c'\" unpacked with wrong size!
  1724.   fi
  1725.   # end of 'hpcdtoppm.0.5.pl1/postscr.c'
  1726. fi
  1727. echo shar: End of archive 2 \(of 3\).
  1728. cp /dev/null ark2isdone
  1729. MISSING=""
  1730. for I in 1 2 3 ; do
  1731.     if test ! -f ark${I}isdone ; then
  1732.     MISSING="${MISSING} ${I}"
  1733.     fi
  1734. done
  1735. if test "${MISSING}" = "" ; then
  1736.     echo You have unpacked all 3 archives.
  1737.     rm -f ark[1-9]isdone
  1738. else
  1739.     echo You still must unpack the following archives:
  1740.     echo "        " ${MISSING}
  1741. fi
  1742. exit 0
  1743. exit 0 # Just in case...
  1744.