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

  1. Newsgroups: comp.sources.misc
  2. From: danisch@ira.uka.de (Hadmut Danisch)
  3. Subject: v39i002:  hpcdtoppm - convert Photo-CD file into portable pixmap v0.5pl1, Part01/03
  4. Message-ID: <csm-v39i002=hpcdtoppm.154016@sparky.Sterling.COM>
  5. X-Md4-Signature: 8c6d1f04799e8a3999ff1c472c9b35d0
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Mon, 16 Aug 1993 20:40:40 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: danisch@ira.uka.de (Hadmut Danisch)
  12. Posting-number: Volume 39, Issue 2
  13. Archive-name: hpcdtoppm/part01
  14. Environment: Photo-CD
  15. Supersedes: hpcdtoppm: Volume 34, Issue 83
  16.  
  17. This is version v0.5pl1 (Patch-Level 1) of the PhotoCD-Decoder
  18. hpcdtoppm. It produces output in Portable Pixmap Format (ppm) and
  19. Postscript. You need an ANSI-C-Compiler and enough memory.
  20.  
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then feed it
  23. # into a shell via "sh file" or similar.  To overwrite existing files,
  24. # type "sh file -c".
  25. # Contents:  hpcdtoppm.0.5.pl1 hpcdtoppm.0.5.pl1/TODO
  26. #   hpcdtoppm.0.5.pl1/const.c hpcdtoppm.0.5.pl1/main.c
  27. #   hpcdtoppm.0.5.pl1/tools.c
  28. # Wrapped by kent@sparky on Mon Aug 16 10:49:22 1993
  29. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  30. echo If this archive is complete, you will see the following message:
  31. echo '          "shar: End of archive 1 (of 3)."'
  32. if test ! -d 'hpcdtoppm.0.5.pl1' ; then
  33.     echo shar: Creating directory \"'hpcdtoppm.0.5.pl1'\"
  34.     mkdir 'hpcdtoppm.0.5.pl1'
  35. fi
  36. if test -f 'hpcdtoppm.0.5.pl1/TODO' -a "${1}" != "-c" ; then 
  37.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/TODO'\"
  38. else
  39.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/TODO'\" \(204 characters\)
  40.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/TODO' <<'END_OF_FILE'
  41. XThings i want to do when i find time:
  42. X
  43. X- Better gamma correction procedures
  44. X
  45. X- Color conversion to YMC and YMCK for printer drivers
  46. X
  47. X- Driver for color printers
  48. X
  49. X- Better correction of reading errors
  50. X
  51. X
  52. X
  53. X
  54. END_OF_FILE
  55.   if test 204 -ne `wc -c <'hpcdtoppm.0.5.pl1/TODO'`; then
  56.     echo shar: \"'hpcdtoppm.0.5.pl1/TODO'\" unpacked with wrong size!
  57.   fi
  58.   # end of 'hpcdtoppm.0.5.pl1/TODO'
  59. fi
  60. if test -f 'hpcdtoppm.0.5.pl1/const.c' -a "${1}" != "-c" ; then 
  61.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/const.c'\"
  62. else
  63.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/const.c'\" \(14361 characters\)
  64.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/const.c' <<'END_OF_FILE'
  65. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  66. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  67. X*  Permission to use and distribute this software and its
  68. X*  documentation for noncommercial use and without fee is hereby granted,
  69. X*  provided that the above copyright notice appear in all copies and that
  70. X*  both that copyright notice and this permission notice appear in
  71. X*  supporting documentation. It is not allowed to sell this software in 
  72. X*  any way. This software is not public domain.
  73. X*/
  74. X
  75. X#include "hpcdtoppm.h"
  76. X
  77. X
  78. XsINT RGB_BitSh1=8;
  79. XsINT RGB_Maximum1=1023;
  80. X
  81. X
  82. XsINT RGB_F_LL=1391;
  83. XsINT RGB_F_C1=2271;
  84. XsINT RGB_O_C1=-353784;
  85. XsINT RGB_F_C2=1865;
  86. XsINT RGB_O_C2=-255023;
  87. XsINT RGB_F_G1=-441;
  88. XsINT RGB_F_G2=-949;
  89. XsINT RGB_O_G =199313;
  90. X
  91. X
  92. XuBYTE RGB_corr0[]={
  93. X  0,  0,  0,  0,  1,  1,  1,  1,  2,  2,  2,  2,  3,  3,  3,  3,
  94. X  4,  4,  4,  4,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,
  95. X  8,  8,  8,  8,  9,  9,  9,  9, 10, 10, 10, 10, 11, 11, 11, 11,
  96. X 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15,
  97. X 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19,
  98. X 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
  99. X 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27,
  100. X 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31,
  101. X 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35,
  102. X 36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39,
  103. X 40, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 43, 43, 43, 43,
  104. X 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47,
  105. X 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51,
  106. X 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55,
  107. X 56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59, 59, 59,
  108. X 60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63,
  109. X 64, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 66, 67, 67, 67, 67,
  110. X 68, 68, 68, 68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71,
  111. X 72, 72, 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75,
  112. X 76, 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79,
  113. X 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83, 83,
  114. X 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87, 87, 87,
  115. X 88, 88, 88, 88, 89, 89, 89, 89, 90, 90, 90, 90, 91, 91, 91, 91,
  116. X 92, 92, 92, 92, 93, 93, 93, 93, 94, 94, 94, 94, 95, 95, 95, 95,
  117. X 96, 96, 96, 96, 97, 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, 99,
  118. X100,100,100,100,101,101,101,101,102,102,102,102,103,103,103,103,
  119. X104,104,104,104,105,105,105,105,106,106,106,106,107,107,107,107,
  120. X108,108,108,108,109,109,109,109,110,110,110,110,111,111,111,111,
  121. X112,112,112,112,113,113,113,113,114,114,114,114,115,115,115,115,
  122. X116,116,116,116,117,117,117,117,118,118,118,118,119,119,119,119,
  123. X120,120,120,120,121,121,121,121,122,122,122,122,123,123,123,123,
  124. X124,124,124,124,125,125,125,125,126,126,126,126,127,127,127,127,
  125. X128,128,128,128,129,129,129,129,130,130,130,130,131,131,131,131,
  126. X132,132,132,132,133,133,133,133,134,134,134,134,135,135,135,135,
  127. X136,136,136,136,137,137,137,137,138,138,138,138,139,139,139,139,
  128. X140,140,140,140,141,141,141,141,142,142,142,142,143,143,143,143,
  129. X144,144,144,144,145,145,145,145,146,146,146,146,147,147,147,147,
  130. X148,148,148,148,149,149,149,149,150,150,150,150,151,151,151,151,
  131. X152,152,152,152,153,153,153,153,154,154,154,154,155,155,155,155,
  132. X156,156,156,156,157,157,157,157,158,158,158,158,159,159,159,159,
  133. X160,160,160,160,161,161,161,161,162,162,162,162,163,163,163,163,
  134. X164,164,164,164,165,165,165,165,166,166,166,166,167,167,167,167,
  135. X168,168,168,168,169,169,169,169,170,170,170,170,171,171,171,171,
  136. X172,172,172,172,173,173,173,173,174,174,174,174,175,175,175,175,
  137. X176,176,176,176,177,177,177,177,178,178,178,178,179,179,179,179,
  138. X180,180,180,180,181,181,181,181,182,182,182,182,183,183,183,183,
  139. X184,184,184,184,185,185,185,185,186,186,186,186,187,187,187,187,
  140. X188,188,188,188,189,189,189,189,190,190,190,190,191,191,191,191,
  141. X192,192,192,192,193,193,193,193,194,194,194,194,195,195,195,195,
  142. X196,196,196,196,197,197,197,197,198,198,198,198,199,199,199,199,
  143. X200,200,200,200,201,201,201,201,202,202,202,202,203,203,203,203,
  144. X204,204,204,204,205,205,205,205,206,206,206,206,207,207,207,207,
  145. X208,208,208,208,209,209,209,209,210,210,210,210,211,211,211,211,
  146. X212,212,212,212,213,213,213,213,214,214,214,214,215,215,215,215,
  147. X216,216,216,216,217,217,217,217,218,218,218,218,219,219,219,219,
  148. X220,220,220,220,221,221,221,221,222,222,222,222,223,223,223,223,
  149. X224,224,224,224,225,225,225,225,226,226,226,226,227,227,227,227,
  150. X228,228,228,228,229,229,229,229,230,230,230,230,231,231,231,231,
  151. X232,232,232,232,233,233,233,233,234,234,234,234,235,235,235,235,
  152. X236,236,236,236,237,237,237,237,238,238,238,238,239,239,239,239,
  153. X240,240,240,240,241,241,241,241,242,242,242,242,243,243,243,243,
  154. X244,244,244,244,245,245,245,245,246,246,246,246,247,247,247,247,
  155. X248,248,248,248,249,249,249,249,250,250,250,250,251,251,251,251,
  156. X252,252,252,252,253,253,253,253,254,254,254,254,255,255,255,255
  157. X};
  158. X
  159. X
  160. XuBYTE RGB_corr1[]={
  161. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  162. X  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
  163. X  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
  164. X  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
  165. X  3,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  4,  4,  4,
  166. X  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,
  167. X  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,
  168. X  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,
  169. X  7,  7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,
  170. X  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
  171. X  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11,
  172. X 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  173. X 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
  174. X 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16,
  175. X 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17,
  176. X 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19,
  177. X 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
  178. X 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 24,
  179. X 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26,
  180. X 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28,
  181. X 28, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 31, 31,
  182. X 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33,
  183. X 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36,
  184. X 36, 36, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39,
  185. X 39, 39, 39, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 42, 42,
  186. X 42, 42, 42, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45,
  187. X 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48,
  188. X 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51,
  189. X 52, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55,
  190. X 55, 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58,
  191. X 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62,
  192. X 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 65, 65, 65, 65, 66, 66,
  193. X 66, 66, 67, 67, 67, 67, 68, 68, 68, 68, 69, 69, 69, 69, 69, 70,
  194. X 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, 73, 73, 73, 73, 74, 74,
  195. X 74, 74, 75, 75, 75, 75, 76, 76, 76, 76, 77, 77, 77, 77, 78, 78,
  196. X 78, 78, 79, 79, 79, 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82,
  197. X 83, 83, 83, 83, 84, 84, 84, 84, 85, 85, 85, 86, 86, 86, 86, 87,
  198. X 87, 87, 87, 88, 88, 88, 89, 89, 89, 89, 90, 90, 90, 91, 91, 91,
  199. X 91, 92, 92, 92, 93, 93, 93, 94, 94, 94, 94, 95, 95, 95, 96, 96,
  200. X 96, 96, 97, 97, 97, 98, 98, 98, 99, 99, 99, 99,100,100,100,101,
  201. X101,101,102,102,102,102,103,103,103,104,104,104,105,105,105,106,
  202. X106,106,107,107,107,107,108,108,108,109,109,109,110,110,110,111,
  203. X111,111,112,112,112,113,113,113,114,114,114,114,115,115,115,116,
  204. X116,116,117,117,117,118,118,118,119,119,119,120,120,120,121,121,
  205. X121,122,122,122,123,123,123,124,124,124,125,125,126,126,126,127,
  206. X127,127,128,128,128,129,129,129,130,130,130,131,131,131,132,132,
  207. X132,133,133,134,134,134,135,135,135,136,136,136,137,137,137,138,
  208. X138,139,139,139,140,140,140,141,141,141,142,142,143,143,143,144,
  209. X144,144,145,145,146,146,146,147,147,147,148,148,149,149,149,150,
  210. X150,150,151,151,152,152,152,153,153,153,154,154,155,155,155,156,
  211. X156,157,157,157,158,158,158,159,159,160,160,160,161,161,162,162,
  212. X162,163,163,164,164,164,165,165,166,166,166,167,167,168,168,168,
  213. X169,169,170,170,170,171,171,172,172,172,173,173,174,174,174,175,
  214. X175,176,176,177,177,177,178,178,179,179,179,180,180,181,181,182,
  215. X182,182,183,183,184,184,184,185,185,186,186,187,187,187,188,188,
  216. X189,189,190,190,190,191,191,192,192,193,193,193,194,194,195,195,
  217. X196,196,197,197,197,198,198,199,199,200,200,200,201,201,202,202,
  218. X203,203,204,204,204,205,205,206,206,207,207,208,208,209,209,209,
  219. X210,210,211,211,212,212,213,213,214,214,214,215,215,216,216,217,
  220. X217,218,218,219,219,220,220,220,221,221,222,222,223,223,224,224,
  221. X225,225,226,226,227,227,228,228,228,229,229,230,230,231,231,232,
  222. X232,233,233,234,234,235,235,236,236,237,237,238,238,239,239,240,
  223. X240,241,241,242,242,243,243,244,244,245,245,245,246,246,247,247,
  224. X248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255
  225. X};
  226. X
  227. X
  228. XuBYTE RGB_corr2[]={
  229. X  0,  1,  2,  3,  4,  5,  6,  7,  9, 10, 11, 12, 13, 14, 15, 16,
  230. X 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 32,
  231. X 33, 34, 35, 36, 37, 37, 38, 39, 40, 40, 41, 42, 42, 43, 44, 45,
  232. X 45, 46, 46, 47, 48, 48, 49, 50, 50, 51, 51, 52, 53, 53, 54, 54,
  233. X 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 63, 63,
  234. X 64, 64, 65, 65, 66, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 71,
  235. X 71, 72, 72, 73, 73, 73, 74, 74, 75, 75, 76, 76, 76, 77, 77, 78,
  236. X 78, 79, 79, 79, 80, 80, 81, 81, 81, 82, 82, 83, 83, 83, 84, 84,
  237. X 85, 85, 85, 86, 86, 86, 87, 87, 88, 88, 88, 89, 89, 89, 90, 90,
  238. X 91, 91, 91, 92, 92, 92, 93, 93, 93, 94, 94, 95, 95, 95, 96, 96,
  239. X 96, 97, 97, 97, 98, 98, 98, 99, 99, 99,100,100,100,101,101,101,
  240. X102,102,102,103,103,103,104,104,104,104,105,105,105,106,106,106,
  241. X107,107,107,108,108,108,109,109,109,109,110,110,110,111,111,111,
  242. X112,112,112,112,113,113,113,114,114,114,114,115,115,115,116,116,
  243. X116,116,117,117,117,118,118,118,118,119,119,119,120,120,120,120,
  244. X121,121,121,121,122,122,122,123,123,123,123,124,124,124,124,125,
  245. X125,125,126,126,126,126,127,127,127,127,128,128,128,128,129,129,
  246. X129,129,130,130,130,130,131,131,131,131,132,132,132,132,133,133,
  247. X133,133,134,134,134,134,135,135,135,135,136,136,136,136,137,137,
  248. X137,137,138,138,138,138,139,139,139,139,140,140,140,140,140,141,
  249. X141,141,141,142,142,142,142,143,143,143,143,143,144,144,144,144,
  250. X145,145,145,145,146,146,146,146,146,147,147,147,147,148,148,148,
  251. X148,148,149,149,149,149,150,150,150,150,150,151,151,151,151,152,
  252. X152,152,152,152,153,153,153,153,153,154,154,154,154,155,155,155,
  253. X155,155,156,156,156,156,156,157,157,157,157,157,158,158,158,158,
  254. X159,159,159,159,159,160,160,160,160,160,161,161,161,161,161,162,
  255. X162,162,162,162,163,163,163,163,163,164,164,164,164,164,165,165,
  256. X165,165,165,166,166,166,166,166,167,167,167,167,167,168,168,168,
  257. X168,168,169,169,169,169,169,170,170,170,170,170,171,171,171,171,
  258. X171,171,172,172,172,172,172,173,173,173,173,173,174,174,174,174,
  259. X174,174,175,175,175,175,175,176,176,176,176,176,177,177,177,177,
  260. X177,177,178,178,178,178,178,179,179,179,179,179,179,180,180,180,
  261. X180,180,181,181,181,181,181,181,182,182,182,182,182,183,183,183,
  262. X183,183,183,184,184,184,184,184,184,185,185,185,185,185,186,186,
  263. X186,186,186,186,187,187,187,187,187,187,188,188,188,188,188,189,
  264. X189,189,189,189,189,190,190,190,190,190,190,191,191,191,191,191,
  265. X191,192,192,192,192,192,192,193,193,193,193,193,193,194,194,194,
  266. X194,194,194,195,195,195,195,195,195,196,196,196,196,196,196,197,
  267. X197,197,197,197,197,198,198,198,198,198,198,199,199,199,199,199,
  268. X199,200,200,200,200,200,200,201,201,201,201,201,201,201,202,202,
  269. X202,202,202,202,203,203,203,203,203,203,204,204,204,204,204,204,
  270. X205,205,205,205,205,205,205,206,206,206,206,206,206,207,207,207,
  271. X207,207,207,207,208,208,208,208,208,208,209,209,209,209,209,209,
  272. X210,210,210,210,210,210,210,211,211,211,211,211,211,211,212,212,
  273. X212,212,212,212,213,213,213,213,213,213,213,214,214,214,214,214,
  274. X214,215,215,215,215,215,215,215,216,216,216,216,216,216,216,217,
  275. X217,217,217,217,217,217,218,218,218,218,218,218,219,219,219,219,
  276. X219,219,219,220,220,220,220,220,220,220,221,221,221,221,221,221,
  277. X221,222,222,222,222,222,222,222,223,223,223,223,223,223,223,224,
  278. X224,224,224,224,224,224,225,225,225,225,225,225,225,226,226,226,
  279. X226,226,226,226,227,227,227,227,227,227,227,228,228,228,228,228,
  280. X228,228,229,229,229,229,229,229,229,230,230,230,230,230,230,230,
  281. X231,231,231,231,231,231,231,231,232,232,232,232,232,232,232,233,
  282. X233,233,233,233,233,233,234,234,234,234,234,234,234,234,235,235,
  283. X235,235,235,235,235,236,236,236,236,236,236,236,237,237,237,237,
  284. X237,237,237,237,238,238,238,238,238,238,238,239,239,239,239,239,
  285. X239,239,239,240,240,240,240,240,240,240,241,241,241,241,241,241,
  286. X241,241,242,242,242,242,242,242,242,243,243,243,243,243,243,243,
  287. X243,244,244,244,244,244,244,244,244,245,245,245,245,245,245,245,
  288. X246,246,246,246,246,246,246,246,247,247,247,247,247,247,247,247,
  289. X248,248,248,248,248,248,248,248,249,249,249,249,249,249,249,249,
  290. X250,250,250,250,250,250,250,250,251,251,251,251,251,251,251,252,
  291. X252,252,252,252,252,252,252,253,253,253,253,253,253,253,253,254,
  292. X254,254,254,254,254,254,254,255,255,255,255,255,255,255,255,255
  293. X};
  294. X
  295. X
  296. XsINT dithtab[]={
  297. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  298. X  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  299. X  0,  0,  1,  2,  2,  3,  3,  4,  5,  5,  6,  7,  8,  8,  9, 10,
  300. X 11, 12, 13, 14, 15, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26,
  301. X 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 42, 43, 44, 46, 47,
  302. X 49, 50, 51, 53, 54, 56, 57, 59, 60, 62, 64, 65, 67, 68, 70, 71,
  303. X 73, 75, 76, 78, 80, 81, 83, 85, 86, 88, 90, 91, 93, 95, 96, 98,
  304. X100,102,103,105,107,109,110,112,114,116,117,119,121,123,124,126,
  305. X128,130,131,133,135,137,138,140,142,144,145,147,149,151,152,154,
  306. X156,157,159,161,163,164,166,168,169,171,173,174,176,178,179,181,
  307. X183,184,186,187,189,190,192,194,195,197,198,200,201,203,204,206,
  308. X207,208,210,211,213,214,215,217,218,219,221,222,223,224,226,227,
  309. X228,229,230,231,233,234,235,236,237,238,239,240,241,242,243,243,
  310. X244,245,246,247,248,248,249,250,250,251,252,252,253,253,254,255,
  311. X255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  312. X255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  313. X};
  314. X
  315. X
  316. END_OF_FILE
  317.   if test 14361 -ne `wc -c <'hpcdtoppm.0.5.pl1/const.c'`; then
  318.     echo shar: \"'hpcdtoppm.0.5.pl1/const.c'\" unpacked with wrong size!
  319.   fi
  320.   # end of 'hpcdtoppm.0.5.pl1/const.c'
  321. fi
  322. if test -f 'hpcdtoppm.0.5.pl1/main.c' -a "${1}" != "-c" ; then 
  323.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/main.c'\"
  324. else
  325.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/main.c'\" \(24343 characters\)
  326.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/main.c' <<'END_OF_FILE'
  327. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  328. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  329. X*  Permission to use and distribute this software and its
  330. X*  documentation for noncommercial use and without fee is hereby granted,
  331. X*  provided that the above copyright notice appear in all copies and that
  332. X*  both that copyright notice and this permission notice appear in
  333. X*  supporting documentation. It is not allowed to sell this software in 
  334. X*  any way. This software is not public domain.
  335. X*/
  336. X
  337. X#include "hpcdtoppm.h"
  338. X
  339. X
  340. XuBYTE sbuffer[SECSIZE];
  341. X
  342. Xenum TURNS  turn     = T_UNSPEC;
  343. Xenum TURNS  contori  = T_UNSPEC;
  344. Xenum SIZES  size     = S_UNSPEC;
  345. Xenum OUTFOR outfor   = O_UNSPEC;
  346. Xenum CORR   corrmode = C_UNSPEC;
  347. X
  348. XsINT do_info,do_diff,do_overskip,do_sharp,monochrome,paper;
  349. XsINT do_melde,do_rep,do_crop;
  350. XsINT flhori=0,flvert=0;
  351. XsINT bufpos=0;
  352. X
  353. Xchar *pcdname=0,*ppmname=0;
  354. Xstatic FILE  *fin=0,*fout=0;
  355. X
  356. Xstatic char    *suba1=0,*suba2=0;
  357. Xstatic implane Luma, Chroma1,Chroma2;
  358. Xstatic implane *PLuma,*PChroma1,*PChroma2;
  359. Xstatic sINT    contsize=1;
  360. Xstatic sINT    emulate_seek=0;
  361. Xstatic sINT    print_pos;
  362. X
  363. X
  364. X#define PrintPos(x) {if(print_pos) fprintf(stderr,"File-Offset: %8d = %8x (hex)\n",(x),(x));}
  365. X
  366. Xstatic void checkin(void);
  367. Xstatic void parseargs(int,char**);
  368. Xstatic void sizecontrol(sizeinfo *,dim,dim);
  369. Xstatic void f_1 (dim,dim,sINT,sINT);
  370. Xstatic void f_3 (dim,dim,sINT);
  371. Xstatic void f_4 (dim,dim,sINT);
  372. Xstatic void f_5 (dim,dim);
  373. Xstatic void f_ov(dim,dim,sINT,sINT);
  374. Xstatic void f_co(dim,dim,sINT,sINT);
  375. X
  376. X
  377. X
  378. Xvoid close_all(void)
  379. X {
  380. X  if(fin && (fin != stdin)) fclose(fin);
  381. X
  382. X  if(fout)
  383. X   {if(fout==stdout) 
  384. X      fflush(fout);
  385. X    else 
  386. X      fclose(fout);
  387. X   }
  388. X }
  389. X
  390. X
  391. X
  392. X
  393. X
  394. X
  395. X
  396. X
  397. Xvoid main(int argc,char **argv)
  398. X {
  399. X
  400. X  typecheck();
  401. X
  402. X  do_info=do_diff=do_overskip=do_sharp=monochrome=paper=0;
  403. X  do_melde=do_rep=do_crop=0;
  404. X  print_pos=0;
  405. X
  406. X
  407. X  parseargs(argc,argv);
  408. X
  409. X  if(size     == S_UNSPEC) size     = S_DEFAULT;
  410. X  if(outfor   == O_UNSPEC) outfor   = O_DEFAULT;
  411. X  if(corrmode == C_UNSPEC) corrmode = C_DEFAULT;
  412. X  if(turn     == T_UNSPEC) turn     = T_DEFAULT;
  413. X
  414. X  monochrome=(outfor==O_PGM)||(outfor==O_PSG)||(outfor==O_EPSG)||(outfor==O_PSD)||(outfor==O_EPSD);
  415. X  paper     =(outfor==O_PS )||(outfor==O_EPS)||(outfor==O_PSG )||(outfor==O_EPSG)||(outfor==O_PSD)||(outfor==O_EPSD);
  416. X
  417. X
  418. X
  419. X  if((size==S_Over) && (!ppmname)) error(E_ARG);
  420. X  if((size==S_Contact) && do_crop) error(E_ARG);
  421. X  if(do_overskip && do_diff)       error(E_OPT);
  422. X
  423. X  if(do_diff && (size != S_4Base) && (size != S_16Base)) error(E_OPT);
  424. X
  425. X  if(do_overskip && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OVSKIP);
  426. X  if(print_pos   && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OPT);
  427. X  if(do_info     && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OPT);
  428. X  if(monochrome && do_overskip) error(E_OPT);
  429. X  if((size==S_Contact) &&((contsize<1) || (contsize>100))) error(E_OPT);
  430. X  if(suba1 && ( size==S_Contact || size==S_Over)) error(E_OPT);
  431. X  if(suba1 && do_crop) error(E_OPT);
  432. X
  433. X  if((!paper) && (PSIZE_SET || DPI_SET || FAK_SET)) error(E_OPT);
  434. X  if(PSIZE_SET && DPI_SET && FAK_SET) error(E_OPT);
  435. X  if((DPI_SET || FAK_SET) && (outfor!=O_PSD) && (outfor!=O_EPSD)) error(E_OPT);
  436. X
  437. X
  438. X
  439. X
  440. X  if(strcmp(pcdname,"-"))
  441. X   { if(!(fin=fopen(pcdname,R_OP))) error(E_READ);
  442. X     emulate_seek=0;
  443. X   }
  444. X  else
  445. X   {pcdname="<stdin>";
  446. X    emulate_seek=1;
  447. X#ifdef USE_FDOPEN
  448. X    fin=fdopen(fileno(stdin),R_OP);
  449. X    if(!fin) error(E_READ);
  450. X#else
  451. X    fin=stdin;
  452. X#endif
  453. X   }
  454. X
  455. X  bufpos=0;
  456. X
  457. X
  458. X  if((size != S_Over) && (size != S_Contact)) checkin();
  459. X
  460. X  PLuma=    &Luma;
  461. X  PChroma1= monochrome ? 0 : &Chroma1; 
  462. X  PChroma2= monochrome ? 0 : &Chroma2; 
  463. X
  464. X  switch(size)
  465. X   {
  466. X    case S_Base16:  f_1(BaseW/4,BaseH/4,L_Head,(L_Head+L_Base16));
  467. X                    break;
  468. X
  469. X    case S_Base4:   f_1(BaseW/2,BaseH/2,(L_Head+L_Base16),(L_Head+L_Base16+L_Base4));
  470. X                    break;
  471. X
  472. X    case S_Base:    f_3(BaseW,BaseH,(L_Head+L_Base16+L_Base4));
  473. X                    break;
  474. X
  475. X    case S_4Base:   f_4(BaseW*2,BaseH*2,(L_Head+L_Base16+L_Base4));
  476. X                    break;
  477. X
  478. X    case S_16Base:  f_5(BaseW*4,BaseH*4);
  479. X                    break;
  480. X
  481. X    case S_Over:    f_ov(BaseW/4,BaseH/4,5,SeBase16);
  482. X                    break;
  483. X
  484. X    case S_Contact: f_co(BaseW/4,BaseH/4,5,SeBase16);
  485. X                    break;
  486. X
  487. X    default: error(E_INTERN); 
  488. X   }
  489. X
  490. X  close_all();
  491. X  exit(0);
  492. X
  493. X }
  494. X
  495. X
  496. X
  497. X
  498. X
  499. X
  500. Xstatic void openoutput(void)
  501. X {
  502. X  if(!ppmname) 
  503. X   {
  504. X#ifdef USE_FDOPEN
  505. X    fout=fdopen(fileno(stdout),W_OP);
  506. X    if(!fout) error(E_WRITE);
  507. X#else
  508. X    fout=stdout;
  509. X#endif
  510. X   }
  511. X  else
  512. X   {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  513. X   }
  514. X }
  515. X
  516. X
  517. X
  518. X
  519. X
  520. X
  521. X
  522. Xstatic void f_1(dim w,dim h,sINT normal,sINT overskip)
  523. X {sizeinfo si;
  524. X  sizecontrol(&si,w,h);
  525. X
  526. X                   planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  527. X  if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  528. X  if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  529. X
  530. X  PrintPos(normal*SECSIZE);
  531. X  SEEK(normal+1);                   
  532. X      
  533. X  if(!do_overskip)
  534. X    { error(readplain(&si,1,PLuma,PChroma1,PChroma2));
  535. X      if (!monochrome) 
  536. X        {interpolate(PChroma1);
  537. X         interpolate(PChroma2);
  538. X        }
  539. X    }
  540. X  else
  541. X    { error(readplain(&si,1,PLuma,nullplane,nullplane));
  542. X      SEEK(overskip+1);
  543. X      error(readplain(&si,2,nullplane,PChroma1,PChroma2));
  544. X    }
  545. X   
  546. X
  547. X  colconvert(&si,PLuma,PChroma1,PChroma2);
  548. X  /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  549. X
  550. X
  551. X  openoutput();
  552. X  writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  553. X
  554. X } 
  555. X
  556. X
  557. Xstatic void f_3(dim w,dim h,sINT normal)
  558. X {sINT cd_offset,cd_offhelp;
  559. X  sizeinfo si;
  560. X
  561. X  sizecontrol(&si,w,h);
  562. X
  563. X  PrintPos(normal*SECSIZE);
  564. X  SEEK(normal+1);
  565. X
  566. X  if(!do_overskip)
  567. X    {                 planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  568. X     if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  569. X     if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  570. X
  571. X     error(readplain(&si,1,PLuma,PChroma1,PChroma2));
  572. X      if (!monochrome) 
  573. X        {interpolate(PChroma1);
  574. X         interpolate(PChroma2);
  575. X        }
  576. X    }
  577. X   else
  578. X    {planealloc(PLuma   ,  si.rdhlen,  si.rdvlen);
  579. X     planealloc(PChroma1,2*si.rdhlen,2*si.rdvlen);
  580. X     planealloc(PChroma2,2*si.rdhlen,2*si.rdvlen);
  581. X
  582. X     error(readplain(&si,1,PLuma,PChroma1,PChroma2));
  583. X     interpolate(PChroma1);
  584. X     interpolate(PChroma2);
  585. X     interpolate(PChroma1);
  586. X     interpolate(PChroma2);
  587. X
  588. X     cd_offset=Skip4Base();
  589. X     SEEK(cd_offset+10);          EREADBUF;    cd_offhelp=(((uINT)sbuffer[2])<<8)|sbuffer[3];
  590. X     SEEK(cd_offset+12);          readhqt(3);
  591. X     SEEK(cd_offset+cd_offhelp);  decode(&si,4,nullplane,PChroma1,PChroma2,1);
  592. X
  593. X     halve(PChroma1);
  594. X     halve(PChroma2);
  595. X    }
  596. X  colconvert(&si,PLuma,PChroma1,PChroma2);
  597. X  /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  598. X
  599. X  openoutput();
  600. X  writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  601. X
  602. X
  603. X }
  604. X
  605. X
  606. X
  607. Xstatic void f_4(dim w,dim h,sINT normal)
  608. X {sINT cd_offset,cd_offhelp;
  609. X  sizeinfo si;
  610. X  sizecontrol(&si,w,h);
  611. X
  612. X                   planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  613. X  if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  614. X  if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  615. X
  616. X  PrintPos((L_Head+L_Base16+L_Base4+L_Base)*SECSIZE);
  617. X
  618. X  if(!do_overskip)
  619. X   {SEEK(L_Head+L_Base16+L_Base4+1);
  620. X    error(readplain(&si,-2,PLuma,PChroma1,PChroma2));
  621. X    interpolate(PLuma);
  622. X    if (!monochrome) 
  623. X     {interpolate(PChroma1);
  624. X      interpolate(PChroma1);
  625. X      interpolate(PChroma2);
  626. X      interpolate(PChroma2);
  627. X     }
  628. X
  629. X    if(do_diff) {clearimpl(PLuma,neutrLum);clearimpl(PChroma1,neutrCh1);clearimpl(PChroma2,neutrCh2);}
  630. X
  631. X    cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  632. X    SEEK(cd_offset + 4);     readhqt(1);
  633. X    SEEK(cd_offset + 5);     decode(&si,1,PLuma,nullplane,nullplane,0);
  634. X   }
  635. X  else
  636. X   {SEEK(L_Head+L_Base16+L_Base4+1);
  637. X    error(readplain(&si,-2,PLuma,PChroma1,PChroma2));
  638. X    interpolate(PLuma);
  639. X    interpolate(PChroma1);
  640. X    interpolate(PChroma1);
  641. X    interpolate(PChroma2);
  642. X    interpolate(PChroma2);
  643. X
  644. X    cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  645. X    SEEK(cd_offset + 4);     readhqt(1);
  646. X    SEEK(cd_offset + 5);     decode(&si,1,PLuma,nullplane,nullplane,0);
  647. X
  648. X    cd_offset=bufpos;
  649. X    if(cd_offset % SECSIZE) error(E_POS);
  650. X    cd_offset/=SECSIZE;
  651. X    SEEK(cd_offset+10);          EREADBUF;    cd_offhelp=(((uINT)sbuffer[2])<<8)|sbuffer[3];
  652. X    SEEK(cd_offset+12);          readhqt(3);
  653. X    SEEK(cd_offset+cd_offhelp);  decode(&si,2,nullplane,PChroma1,PChroma2,1);
  654. X     
  655. X   }
  656. X  colconvert(&si,PLuma,PChroma1,PChroma2);
  657. X  /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  658. X
  659. X  openoutput();
  660. X  writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  661. X
  662. X }
  663. X
  664. X
  665. X
  666. Xstatic void f_5(dim w,dim h)
  667. X {sINT cd_offset;
  668. X  sizeinfo si;
  669. X
  670. X  sizecontrol(&si,w,h);
  671. X
  672. X                   planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  673. X  if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  674. X  if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  675. X
  676. X  SEEK(L_Head+L_Base16+L_Base4+1);
  677. X  error(readplain(&si,-4,PLuma,PChroma1,PChroma2));
  678. X  interpolate(PLuma);
  679. X  if(!monochrome)
  680. X   {interpolate(PChroma1);
  681. X    interpolate(PChroma1);
  682. X    interpolate(PChroma2);
  683. X    interpolate(PChroma2);
  684. X   }
  685. X
  686. X  cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  687. X  SEEK(cd_offset + 4);       readhqt(1);
  688. X  SEEK(cd_offset + 5);       decode(&si,-2,PLuma,nullplane,nullplane,0);
  689. X  interpolate(PLuma);
  690. X
  691. X  if(do_diff) {clearimpl(PLuma,neutrLum);clearimpl(PChroma1,neutrCh1);clearimpl(PChroma2,neutrCh2);}
  692. X
  693. X  cd_offset=bufpos;
  694. X  if(cd_offset % SECSIZE) error(E_POS);
  695. X  PrintPos(cd_offset);
  696. X  cd_offset/=SECSIZE;
  697. X
  698. X  SEEK(cd_offset+12);        readhqt(3);
  699. X  SEEK(cd_offset+14);        decode(&si,1,PLuma,PChroma1,PChroma2,0);
  700. X
  701. X  if(!monochrome)
  702. X   {interpolate(PChroma1);
  703. X    interpolate(PChroma2);
  704. X   }
  705. X
  706. X  colconvert(&si,PLuma,PChroma1,PChroma2);
  707. X  /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  708. X
  709. X  openoutput();
  710. X  writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn);
  711. X
  712. X }
  713. X
  714. X
  715. X
  716. X
  717. Xstatic void f_ov(dim w,dim h,sINT offset,sINT imsize)
  718. X {sINT bildnr,bilder;
  719. X  dim wx,hx;
  720. X  enum ERRORS eret;
  721. X  enum TURNS imorient;
  722. X  char nbuf[100];
  723. X  uBYTE hbuf[SECSIZE];
  724. X  sizeinfo si;
  725. X  
  726. X  sizecontrol(&si,w,h);
  727. X
  728. X  wx=w; hx=h;
  729. X
  730. X                   planealloc(PLuma   ,si.rdhlen,si.rdvlen);
  731. X  if (!monochrome) planealloc(PChroma1,si.rdhlen,si.rdvlen);
  732. X  if (!monochrome) planealloc(PChroma2,si.rdhlen,si.rdvlen);
  733. X
  734. X  SEEK(0); 
  735. X  if(READ(hbuf,sizeof(hbuf))<1) error(E_READ);
  736. X
  737. X  bilder=(((sINT) hbuf[10])<<8) | hbuf[11];
  738. X
  739. X
  740. X  for(bildnr=0;bildnr<bilder;bildnr++)
  741. X   {w=wx;h=hx;
  742. X    sizecontrol(&si,w,h);
  743. X    PLuma->im=PLuma->mp;
  744. X    if(PChroma1) PChroma1->im=PChroma1->mp;
  745. X    if(PChroma2) PChroma2->im=PChroma2->mp;
  746. X
  747. X    SEEK(offset+imsize*bildnr);
  748. X  
  749. X    eret=readplain(&si,1,PLuma,PChroma1,PChroma2);
  750. X    if(eret==E_READ) break;
  751. X    error(eret);
  752. X
  753. X    if(!monochrome)
  754. X     {interpolate(PChroma1);
  755. X      interpolate(PChroma2);
  756. X     }
  757. X
  758. X    colconvert(&si,PLuma,PChroma1,PChroma2);
  759. X  
  760. X    sprintf(nbuf,"%s%04d",ppmname,bildnr+1);
  761. X    if (!(fout=fopen(nbuf,W_OP))) error(E_WRITE);
  762. X     switch(hbuf[12+bildnr] & 3)
  763. X      {case 0:  imorient=T_NONE;  break;
  764. X       case 1:  imorient=T_LEFT;  break;
  765. X       case 2:  imorient=T_HEAD;  break;
  766. X       case 3:  imorient=T_RIGHT; break;
  767. X       default: imorient=T_NONE;
  768. X      }
  769. X    writepicture(fout,&si,PLuma,PChroma1,PChroma2,turn != T_AUTO ? turn : imorient);
  770. X    fclose(fout);
  771. X    fout=0;
  772. X   }
  773. X }
  774. X
  775. X
  776. X
  777. X
  778. Xstatic void f_co(dim w,dim h,sINT offset,sINT imsize)
  779. X {sINT bildnr,bilder,cols,rows,xstep,ystep,mw,mh;
  780. X  enum ERRORS eret;
  781. X  enum TURNS imorient;
  782. X  implane mLuma,mChroma1,mChroma2;
  783. X  implane *pmL,*pmCh1,*pmCh2;
  784. X  uBYTE hbuf[SECSIZE];
  785. X  sizeinfo sibig,sismall;
  786. X
  787. X  pmL=                    &mLuma;
  788. X  pmCh1= monochrome ? 0 : &mChroma1; 
  789. X  pmCh2= monochrome ? 0 : &mChroma2; 
  790. X
  791. X
  792. X  SEEK(0); 
  793. X  if(READ(hbuf,sizeof(hbuf))<1) error(E_READ);
  794. X  bilder=(((sINT) hbuf[10])<<8) | hbuf[11];
  795. X
  796. X  cols=contsize;
  797. X  rows=(bilder+cols-1)/cols;
  798. X
  799. X  xstep=ystep=0;
  800. X  switch(turn)
  801. X   {case T_NONE: 
  802. X    case T_HEAD: xstep=w;ystep=h; break;
  803. X    case T_RIGHT:
  804. X    case T_LEFT: xstep=h;ystep=w; break;
  805. X    case T_AUTO: xstep=ystep=w;   break;
  806. X    default: error(E_INTERN);
  807. X   }
  808. X
  809. X  mw=cols*xstep;
  810. X  mh=rows*ystep;
  811. X
  812. X  sizecontrol(&sibig  ,mw,mh);
  813. X  sizecontrol(&sismall, w, h);
  814. X
  815. X  planealloc(PLuma   ,w,h);
  816. X  if (!monochrome) planealloc(PChroma1,w,h);
  817. X  if (!monochrome) planealloc(PChroma2,w,h);
  818. X
  819. X  planealloc(pmL,mw,mh);
  820. X  mLuma.iwidth=mw;
  821. X  mLuma.iheight=mh;
  822. X  clearimpl(pmL,CONTLUM);
  823. X
  824. X  if(!monochrome)
  825. X   { planealloc(pmCh1,mw,mh);
  826. X     mChroma1.iwidth=mw;
  827. X     mChroma1.iheight=mh;
  828. X     clearimpl(pmCh1,CONTCH1);
  829. X
  830. X     planealloc(pmCh2,mw,mh);
  831. X     mChroma2.iwidth=mw;
  832. X     mChroma2.iheight=mh;
  833. X     clearimpl(pmCh2,CONTCH2);
  834. X   }
  835. X
  836. X
  837. X  for(bildnr=0;bildnr<bilder;bildnr++)
  838. X   {SEEK(offset+imsize*bildnr);
  839. X  
  840. X    eret=readplain(&sismall,1,PLuma,PChroma1,PChroma2);
  841. X    if(eret==E_READ) break;
  842. X    error(eret);
  843. X
  844. X    if(!monochrome)
  845. X     {interpolate(PChroma1);
  846. X      interpolate(PChroma2);
  847. X     }
  848. X
  849. X    switch(hbuf[12+bildnr] & 3)
  850. X     {case 0:  imorient=T_NONE;  break;
  851. X      case 1:  imorient=T_LEFT;  break;
  852. X      case 2:  imorient=T_HEAD;  break;
  853. X      case 3:  imorient=T_RIGHT; break;
  854. X      default: imorient=T_NONE;
  855. X     }
  856. X    pastein(pmL,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PLuma,((turn==T_AUTO)? imorient:turn));
  857. X    if(!monochrome)
  858. X     {pastein(pmCh1,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PChroma1,((turn==T_AUTO)? imorient:turn));
  859. X      pastein(pmCh2,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PChroma2,((turn==T_AUTO)? imorient:turn));
  860. X     }
  861. X   }
  862. X
  863. X  colconvert(&sibig,pmL,pmCh1,pmCh2);
  864. X
  865. X  openoutput();
  866. X  writepicture(fout,&sibig,pmL,pmCh1,pmCh2,contori);
  867. X
  868. X }
  869. X
  870. X
  871. X
  872. X
  873. X
  874. X
  875. X
  876. X
  877. X#define ASKIP { argc--; argv ++;}
  878. X
  879. Xstatic void parseargs(int  argc,char **argv)
  880. X {
  881. X  char *opt;
  882. X
  883. X  ASKIP;
  884. X
  885. X  while((argc>0) && argv[0][0]=='-' && argv[0][1])
  886. X   {
  887. X    opt= (*argv)+1;
  888. X    ASKIP;
  889. X
  890. X/**** additional options ****/
  891. X
  892. X    if(!strcmp(opt,"x")) 
  893. X     { if (!do_overskip) do_overskip=1;
  894. X       else error(E_ARG);
  895. X       continue;
  896. X     }
  897. X
  898. X    if(!strcmp(opt,"s")) 
  899. X     { if (!do_sharp) do_sharp=1;
  900. X       else error(E_ARG);
  901. X       continue;
  902. X     }
  903. X
  904. X    if(!strcmp(opt,"d")) 
  905. X     { if (!do_diff) do_diff=1;
  906. X       else error(E_ARG);
  907. X       continue;
  908. X     }
  909. X
  910. X    if(!strcmp(opt,"i")) 
  911. X     { if (!do_info) do_info=1;
  912. X       else error(E_ARG);
  913. X       continue;
  914. X     }
  915. X
  916. X
  917. X    if(!strcmp(opt,"m")) 
  918. X     { if (!do_melde) do_melde=1;
  919. X       else error(E_ARG);
  920. X       continue;
  921. X     }
  922. X
  923. X    if(!strcmp(opt,"crop")) 
  924. X     { if (!do_crop) do_crop=1;
  925. X       else error(E_ARG);
  926. X       continue;
  927. X     }
  928. X
  929. X    if(!strcmp(opt,"pos")) 
  930. X     { if (!print_pos) print_pos=1;
  931. X       else error(E_ARG);
  932. X       continue;
  933. X     }
  934. X
  935. X    if(!strcmp(opt,"rep")) 
  936. X     { if (!do_rep) do_rep=1;
  937. X       else error(E_ARG);
  938. X       continue;
  939. X     }
  940. X
  941. X/****  Orientation options ****/
  942. X    if(!strcmp(opt,"n"))
  943. X     {if (turn == T_UNSPEC) turn=T_NONE;
  944. X      else error(E_ARG);
  945. X      continue;
  946. X     }
  947. X
  948. X    if(!strcmp(opt,"r"))
  949. X     {if (turn == T_UNSPEC) turn=T_RIGHT;
  950. X      else error(E_ARG);
  951. X      continue;
  952. X     }
  953. X
  954. X    if(!strcmp(opt,"l"))
  955. X     {if (turn == T_UNSPEC) turn=T_LEFT;
  956. X      else error(E_ARG);
  957. X      continue;
  958. X     }
  959. X
  960. X    if(!strcmp(opt,"h"))
  961. X     {if (turn == T_UNSPEC) turn=T_HEAD;
  962. X      else error(E_ARG);
  963. X      continue;
  964. X     }
  965. X
  966. X    if(!strcmp(opt,"a"))
  967. X     {if (turn == T_UNSPEC) turn=T_AUTO;
  968. X      else error(E_ARG);
  969. X      continue;
  970. X     }
  971. X
  972. X    if(!strcmp(opt,"vert"))
  973. X     {if (!flvert) flvert=1;
  974. X      else error(E_ARG);
  975. X      continue;
  976. X     }
  977. X
  978. X    if(!strcmp(opt,"hori"))
  979. X     {if (!flhori) flhori=1;
  980. X      else error(E_ARG);
  981. X      continue;
  982. X     }
  983. X
  984. X
  985. X
  986. X
  987. X
  988. X
  989. X/**** Output options ****/
  990. X
  991. X
  992. X    if((!strcmp(opt,"ppm")) || (!strcmp(opt,"PPM")))
  993. X     { if (outfor == O_UNSPEC) outfor=O_PPM;
  994. X       else error(E_ARG);
  995. X       continue;
  996. X     }
  997. X
  998. X    if((!strcmp(opt,"pgm")) || (!strcmp(opt,"PGM")))
  999. X     { if (outfor == O_UNSPEC) outfor=O_PGM;
  1000. X       else error(E_ARG);
  1001. X       continue;
  1002. X     }
  1003. X
  1004. X    if(!strcmp(opt,"ycc")) 
  1005. X     { if (outfor == O_UNSPEC) outfor=O_YCC;
  1006. X       else error(E_ARG);
  1007. X       continue;
  1008. X     }
  1009. X
  1010. X    if((!strcmp(opt,"ps")) || (!strcmp(opt,"PS")))
  1011. X     { if (outfor == O_UNSPEC) outfor=O_PS;
  1012. X       else error(E_ARG);
  1013. X       continue;
  1014. X     }
  1015. X
  1016. X    if((!strcmp(opt,"eps")) || (!strcmp(opt,"EPS")))
  1017. X     { if (outfor == O_UNSPEC) outfor=O_EPS;
  1018. X       else error(E_ARG);
  1019. X       continue;
  1020. X     }
  1021. X
  1022. X    if((!strcmp(opt,"psg")) || (!strcmp(opt,"PSG")))
  1023. X     { if (outfor == O_UNSPEC) outfor=O_PSG;
  1024. X       else error(E_ARG);
  1025. X       continue;
  1026. X     }
  1027. X
  1028. X    if((!strcmp(opt,"epsg")) || (!strcmp(opt,"EPSG")))
  1029. X     { if (outfor == O_UNSPEC) outfor=O_EPSG;
  1030. X       else error(E_ARG);
  1031. X       continue;
  1032. X     }
  1033. X
  1034. X    if((!strcmp(opt,"psd")) || (!strcmp(opt,"PSD")))
  1035. X     { if (outfor == O_UNSPEC) outfor=O_PSD;
  1036. X       else error(E_ARG);
  1037. X       continue;
  1038. X     }
  1039. X
  1040. X    if((!strcmp(opt,"epsd")) || (!strcmp(opt,"EPSD")))
  1041. X     { if (outfor == O_UNSPEC) outfor=O_EPSD;
  1042. X       else error(E_ARG);
  1043. X       continue;
  1044. X     }
  1045. X
  1046. X
  1047. X
  1048. X
  1049. X
  1050. X    if(!strcmp(opt,"pl" ))
  1051. X     { if(argc<1) error(E_ARG);
  1052. X       if((sscanf(*argv,SSFLTPT,&PAPER_LEFT))!=1) error(E_ARG);
  1053. X       ASKIP;
  1054. X       continue;
  1055. X     }
  1056. X
  1057. X    if(!strcmp(opt,"pb" ))
  1058. X     { if(argc<1) error(E_ARG);
  1059. X       if((sscanf(*argv,SSFLTPT,&PAPER_BOTTOM))!=1) error(E_ARG);
  1060. X       ASKIP;
  1061. X       continue;
  1062. X     }
  1063. X
  1064. X
  1065. X    if(!strcmp(opt,"pw" ))
  1066. X     { if(argc<1) error(E_ARG);
  1067. X       PSIZE_SET=1;
  1068. X       if((sscanf(*argv,SSFLTPT,&PAPER_WIDTH))!=1) error(E_ARG);
  1069. X       ASKIP;
  1070. X       continue;
  1071. X     }
  1072. X
  1073. X    if(!strcmp(opt,"ph" ))
  1074. X     { if(argc<1) error(E_ARG);
  1075. X       PSIZE_SET=1;
  1076. X       if((sscanf(*argv,SSFLTPT,&PAPER_HEIGHT))!=1) error(E_ARG);
  1077. X       ASKIP;
  1078. X       continue;
  1079. X     }
  1080. X
  1081. X
  1082. X    if(!strcmp(opt,"dpi" ))
  1083. X     { if(argc<1) error(E_ARG);
  1084. X       DPI_SET=1;
  1085. X       if((sscanf(*argv,SSFLTPT,&PRINTER_XDPI))!=1) error(E_ARG);
  1086. X       if(PRINTER_XDPI <= 0.0) error(E_OPT);
  1087. X       PRINTER_YDPI=PRINTER_XDPI;
  1088. X       ASKIP;
  1089. X       continue;
  1090. X     }
  1091. X
  1092. X    if(!strcmp(opt,"fak" ))
  1093. X     { if(argc<1) error(E_ARG);
  1094. X       FAK_SET=1;
  1095. X       if((sscanf(*argv,SSFLTPT,&PRINTER_FAK))!=1) error(E_ARG);
  1096. X       if(PRINTER_FAK <= 0.0) error(E_OPT);
  1097. X       if(PRINTER_FAK >  1000.0) error(E_OPT);
  1098. X       ASKIP;
  1099. X       continue;
  1100. X     }
  1101. X
  1102. X
  1103. X
  1104. X/**** Color model options ****/
  1105. X
  1106. X    if(!strcmp(opt,"c0")) 
  1107. X     { if (corrmode == C_UNSPEC) corrmode = C_LINEAR;
  1108. X       else error(E_ARG);
  1109. X       continue;
  1110. X     }
  1111. X
  1112. X    if(!strcmp(opt,"c-")) 
  1113. X     { if (corrmode == C_UNSPEC) corrmode = C_DARK;
  1114. X       else error(E_ARG);
  1115. X       continue;
  1116. X     }
  1117. X
  1118. X    if(!strcmp(opt,"c+")) 
  1119. X     { if (corrmode == C_UNSPEC) corrmode = C_BRIGHT;
  1120. X       else error(E_ARG);
  1121. X       continue;
  1122. X     }
  1123. X
  1124. X   
  1125. X/**** Subrectangel option ****/
  1126. X    
  1127. X    if(!strcmp(opt,"S"))
  1128. X     { if (suba1) error(E_ARG);
  1129. X       if(argc<2) error(E_ARG);
  1130. X       suba1=argv[0];
  1131. X       ASKIP;
  1132. X       suba2=argv[0];
  1133. X       ASKIP;
  1134. X       continue;
  1135. X     }
  1136. X
  1137. X
  1138. X/**** Resolution options ****/
  1139. X   
  1140. X    if((!strcmp(opt,"Base/16")) || (!strcmp(opt,"1"))  || (!strcmp(opt,"128x192")))
  1141. X     { if (size == S_UNSPEC) size = S_Base16;
  1142. X       else error(E_ARG);
  1143. X       continue;
  1144. X     }
  1145. X    if((!strcmp(opt,"Base/4" )) || (!strcmp(opt,"2"))  || (!strcmp(opt,"256x384")))
  1146. X     { if (size == S_UNSPEC) size = S_Base4;
  1147. X       else error(E_ARG);
  1148. X       continue;
  1149. X     }
  1150. X    if((!strcmp(opt,"Base"   )) || (!strcmp(opt,"3"))  || (!strcmp(opt,"512x768")))
  1151. X     { if (size == S_UNSPEC) size = S_Base;
  1152. X       else error(E_ARG);
  1153. X       continue;
  1154. X     }
  1155. X    if((!strcmp(opt,"4Base"  )) || (!strcmp(opt,"4"))  || (!strcmp(opt,"1024x1536")))
  1156. X     { if (size == S_UNSPEC) size = S_4Base;
  1157. X       else error(E_ARG);
  1158. X       continue;
  1159. X     }
  1160. X    if((!strcmp(opt,"16Base" )) || (!strcmp(opt,"5"))  || (!strcmp(opt,"2048x3072")))
  1161. X     { if (size == S_UNSPEC) size = S_16Base;
  1162. X       else error(E_ARG);
  1163. X       continue;
  1164. X     }
  1165. X
  1166. X    if((!strcmp(opt,"Overview" )) || (!strcmp(opt,"0"))  || (!strcmp(opt,"O")))
  1167. X     { if (size == S_UNSPEC) size = S_Over;
  1168. X       else error(E_ARG);
  1169. X       continue;
  1170. X     }
  1171. X
  1172. X    if((!strcmp(opt,"Contact" )) || (!strcmp(opt,"C")))
  1173. X     { if (size == S_UNSPEC) size = S_Contact;
  1174. X       else error(E_ARG);
  1175. X       if(argc<2) error(E_ARG);
  1176. X       if((sscanf(*argv,"%d",&contsize))!=1) error(E_ARG);
  1177. X       ASKIP;
  1178. X       if     (!strcmp(*argv,"n")) contori=T_NONE;
  1179. X       else if(!strcmp(*argv,"r")) contori=T_RIGHT;
  1180. X       else if(!strcmp(*argv,"l")) contori=T_LEFT;
  1181. X       else if(!strcmp(*argv,"h")) contori=T_HEAD;
  1182. X       else error(E_ARG);
  1183. X       ASKIP;
  1184. X
  1185. X       continue;
  1186. X     }
  1187. X
  1188. X   fprintf(stderr,"Unknown option: -%s\n",opt);
  1189. X   error(E_ARG);
  1190. X   }
  1191. X
  1192. X  
  1193. X  if(argc<1) error(E_ARG);
  1194. X  pcdname= *argv;
  1195. X  ASKIP;
  1196. X
  1197. X  if(argc>0) 
  1198. X   {ppmname= *argv;
  1199. X    ASKIP;
  1200. X   }
  1201. X  
  1202. X  if(argc>0) error(E_ARG);
  1203. X
  1204. X
  1205. X }
  1206. X#undef ASKIP
  1207. X
  1208. X
  1209. X
  1210. X
  1211. X
  1212. X
  1213. X
  1214. X
  1215. X
  1216. X
  1217. Xvoid checkin(void)
  1218. X { 
  1219. X   if (do_info || (turn==T_AUTO)) 
  1220. X     { SEEK(1);
  1221. X       EREADBUF;
  1222. X     }
  1223. X
  1224. X    if(turn==T_AUTO) 
  1225. X     {
  1226. X      switch(sbuffer[0xe02 & 0x7ff]&0x03)
  1227. X       {case 0x00: turn=T_NONE;  break;
  1228. X        case 0x01: turn=T_LEFT;  break;
  1229. X        case 0x02: turn=T_HEAD;  break;
  1230. X        case 0x03: turn=T_RIGHT; break;
  1231. X        default: error(E_TCANT);
  1232. X       }
  1233. X      }
  1234. X
  1235. X    if(do_info) druckeid();
  1236. X
  1237. X }
  1238. X
  1239. X
  1240. X
  1241. X/************************** file access functions **************/
  1242. X
  1243. Xint READ(uBYTE *ptr,int n)
  1244. X {int d;
  1245. X  if(!n) return 1;
  1246. X  bufpos+=n;
  1247. X  for(;;)
  1248. X   {d=fread((char *)ptr,1,n,fin);
  1249. X    if(d<1) return 0;
  1250. X    n-=d;
  1251. X    if (!n) break;
  1252. X    ptr+=d;
  1253. X   }
  1254. X  return 1;
  1255. X }
  1256. X
  1257. Xstatic int friss(int n)
  1258. X {int d;
  1259. X
  1260. X  while(n>0)
  1261. X   {
  1262. X    d= n>sizeof(sbuffer) ? sizeof(sbuffer) : n;
  1263. X    n-=d;
  1264. X    if(READ(sbuffer,d) !=1) return 1;
  1265. X   }
  1266. X
  1267. X  return 0;
  1268. X }
  1269. X
  1270. X
  1271. Xvoid SEEK(int x)
  1272. X {
  1273. X  x *= SECSIZE;
  1274. X  if(x<bufpos) error(E_INTERN);
  1275. X  if(x==bufpos) return;
  1276. X
  1277. X  if(emulate_seek)
  1278. X   {if(friss(x-bufpos)) error(E_READ);
  1279. X    if(x!=bufpos) error(E_INTERN);
  1280. X   }
  1281. X  else
  1282. X   {bufpos=x;
  1283. X    if (fseek(fin,x,0)) error(E_READ);
  1284. X   }
  1285. X#ifdef DEBUG
  1286. X  fprintf(stderr,"S-Position %x\n",bufpos);
  1287. X#endif
  1288. X
  1289. X }
  1290. X
  1291. X
  1292. X
  1293. Xint SKIPn(int n)
  1294. X {
  1295. X  if(!n) return 0;
  1296. X  if(n<0) error(E_INTERN);
  1297. X    
  1298. X  if(emulate_seek)
  1299. X   {return friss(n);
  1300. X   }
  1301. X  else
  1302. X   {bufpos+=n;
  1303. X    return fseek(fin,(n),1);
  1304. X   }
  1305. X }
  1306. X
  1307. X
  1308. X
  1309. X
  1310. X
  1311. X/************************** size control functions **************/
  1312. X
  1313. X#define ISDIGIT(x) (((x)>='0') && ((x)<='9'))
  1314. X
  1315. Xstatic void number(char **s,char **i,char **f)
  1316. X {char *p;
  1317. X
  1318. X  p= *s;
  1319. X  (*i)=(*f)=0;
  1320. X
  1321. X  if(!ISDIGIT(*p)) error(E_SUBR);
  1322. X  while(ISDIGIT(*p)) p++;
  1323. X  if(*p != '.') 
  1324. X   { *i=*s;
  1325. X     *s=p; 
  1326. X     return;
  1327. X   }
  1328. X  p++;
  1329. X  if(!ISDIGIT(*p)) error(E_SUBR);
  1330. X  while(ISDIGIT(*p)) p++;
  1331. X  *f=*s;
  1332. X  *s=p;  
  1333. X }
  1334. X
  1335. Xstatic sdim makedim(full,i,f)
  1336. X  sdim full;
  1337. X  char *i,*f;
  1338. X {sdim val;
  1339. X  FLTPT fl;
  1340. X
  1341. X  if(i) 
  1342. X   {if(f) error(E_INTERN);
  1343. X    if(sscanf(i,"%u",&val) != 1) error(E_SUBR);
  1344. X    if((val<0) || (val >full)) error(E_SUBR);
  1345. X    return val;
  1346. X   }
  1347. X  else
  1348. X   {if(!f) error(E_INTERN);
  1349. X    if(sscanf(f,SSFLTPT,&fl) != 1) error(E_SUBR);
  1350. X    if((fl < 0.0) || (fl > 1.0)) error(E_SUBR);
  1351. X    val= full * fl + 0.5;
  1352. X    return val;
  1353. X   }
  1354. X }
  1355. X
  1356. X
  1357. X#define sMASK (~7)
  1358. Xstatic void sizealign(char *str,dim full,
  1359. X                      dim *rdoff,dim *rdlen,dim *imoff,dim *imlen)
  1360. X {char *i1,*f1,*tr,*i2,*f2,*ptr;
  1361. X  int vonbis=0;
  1362. X  sdim von,len,rest;
  1363. X
  1364. X  i1=f1=tr=i2=f2=0;
  1365. X
  1366. X  ptr=str;
  1367. X  number(&ptr,&i1,&f1);
  1368. X
  1369. X  if(*ptr == '-') vonbis=1;
  1370. X  else if (*ptr == '+') vonbis=0;
  1371. X  else error(E_SUBR);
  1372. X  ptr++;
  1373. X
  1374. X  number(&ptr,&i2,&f2);
  1375. X  if(*ptr) error(E_SUBR);
  1376. X
  1377. X  von=makedim(full,i1,f1);
  1378. X  len=makedim(full,i2,f2);
  1379. X  if(vonbis) len-=von;
  1380. X  rest=full-von-len;
  1381. X
  1382. X  if((von<0) || (len<1) || (rest<0)) error(E_SUBR);
  1383. X  
  1384. X  *imlen = (dim) len;
  1385. X
  1386. X  *rdoff = (dim) (von & sMASK); 
  1387. X  *rdlen = full - *rdoff - ((dim)( rest & sMASK) );
  1388. X
  1389. X  *imoff = ((dim) von) - *rdoff;
  1390. X
  1391. X }
  1392. X
  1393. X
  1394. Xstatic void sizecontrol(sizeinfo *si,dim w,dim h)
  1395. X {
  1396. X  si->w=w;
  1397. X  si->h=h;
  1398. X
  1399. X  if(!suba1)
  1400. X   {
  1401. X    si->rdhlen=w;
  1402. X    si->rdvlen=h;
  1403. X    si->rdhoff=0;
  1404. X    si->rdvoff=0;
  1405. X    si->imhlen=0;
  1406. X    si->imvlen=0;
  1407. X    si->imhoff=0;
  1408. X    si->imvoff=0;
  1409. X   }
  1410. X  else
  1411. X   {sizealign(suba1,w,&si->rdhoff,&si->rdhlen,&si->imhoff,&si->imhlen);
  1412. X    sizealign(suba2,h,&si->rdvoff,&si->rdvlen,&si->imvoff,&si->imvlen);
  1413. X   }
  1414. X
  1415. X#ifdef DEBUG
  1416. X  fprintf(stderr,"Align: %5d %5d \n",si->w,si->h);
  1417. X  fprintf(stderr,"Align: %5d %5d %5d %5d \n",si->rdhoff,si->rdhlen,si->rdvoff,si->rdvlen);
  1418. X  fprintf(stderr,"Align: %5d %5d %5d %5d \n",si->imhoff,si->imhlen,si->imvoff,si->imvlen);
  1419. X#endif
  1420. X
  1421. X }
  1422. END_OF_FILE
  1423.   if test 24343 -ne `wc -c <'hpcdtoppm.0.5.pl1/main.c'`; then
  1424.     echo shar: \"'hpcdtoppm.0.5.pl1/main.c'\" unpacked with wrong size!
  1425.   fi
  1426.   # end of 'hpcdtoppm.0.5.pl1/main.c'
  1427. fi
  1428. if test -f 'hpcdtoppm.0.5.pl1/tools.c' -a "${1}" != "-c" ; then 
  1429.   echo shar: Will not clobber existing file \"'hpcdtoppm.0.5.pl1/tools.c'\"
  1430. else
  1431.   echo shar: Extracting \"'hpcdtoppm.0.5.pl1/tools.c'\" \(8936 characters\)
  1432.   sed "s/^X//" >'hpcdtoppm.0.5.pl1/tools.c' <<'END_OF_FILE'
  1433. X/* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  1434. X*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  1435. X*  Permission to use and distribute this software and its
  1436. X*  documentation for noncommercial use and without fee is hereby granted,
  1437. X*  provided that the above copyright notice appear in all copies and that
  1438. X*  both that copyright notice and this permission notice appear in
  1439. X*  supporting documentation. It is not allowed to sell this software in 
  1440. X*  any way. This software is not public domain.
  1441. X*/
  1442. X
  1443. X#include "hpcdtoppm.h"
  1444. X
  1445. X
  1446. Xvoid clearimpl(implane *l,sINT n)
  1447. X{ dim x,y;
  1448. X  uBYTE *ptr;
  1449. X
  1450. X  ptr=l->im;
  1451. X  for (x=0;x<l->mwidth;x++)
  1452. X    for (y=0; y<l->mheight;y++)
  1453. X      *(ptr++)=n;
  1454. X}
  1455. X
  1456. X
  1457. X
  1458. X
  1459. Xvoid halve(implane *p)
  1460. X {dim w,h,x,y;
  1461. X  uBYTE *optr,*nptr;
  1462. X
  1463. X  melde("halve\n");
  1464. X  if ((!p) || (!p->im)) error(E_INTERN);
  1465. X
  1466. X  w=p->iwidth/=2;      
  1467. X  h=p->iheight/=2;     
  1468. X
  1469. X
  1470. X  for(y=0;y<h;y++)
  1471. X   {
  1472. X    nptr=(p->im) +   y*(p->mwidth);
  1473. X    optr=(p->im) + 2*y*(p->mwidth);
  1474. X
  1475. X    for(x=0;x<w;x++,nptr++,optr+=2)
  1476. X     { *nptr = *optr;
  1477. X     }
  1478. X
  1479. X   }
  1480. X
  1481. X }
  1482. X
  1483. X
  1484. X
  1485. X
  1486. X
  1487. X
  1488. X
  1489. Xvoid interpolate(implane *p)
  1490. X {dim w,h,x,y,yi;
  1491. X  uBYTE *optr,*nptr,*uptr;
  1492. X
  1493. X  melde("interpolate\n");
  1494. X  if ((!p) || (!p->im)) error(E_INTERN);
  1495. X
  1496. X  w=p->iwidth;
  1497. X  h=p->iheight;
  1498. X
  1499. X  if(p->mwidth  < 2*w ) error(E_INTERN);
  1500. X  if(p->mheight < 2*h ) error(E_INTERN);
  1501. X
  1502. X
  1503. X  p->iwidth=2*w;
  1504. X  p->iheight=2*h;
  1505. X
  1506. X
  1507. X  for(y=0;y<h;y++)
  1508. X   {yi=h-1-y;
  1509. X    optr=p->im+  yi*p->mwidth + (w-1);
  1510. X    nptr=p->im+2*yi*p->mwidth + (2*w - 2);
  1511. X
  1512. X    nptr[0]=nptr[1]=optr[0];
  1513. X
  1514. X    for(x=1;x<w;x++)
  1515. X     { optr--; nptr-=2;
  1516. X       nptr[0]=optr[0];
  1517. X       nptr[1]=(((sINT)optr[0])+((sINT)optr[1])+1)>>1;
  1518. X     }
  1519. X    }
  1520. X
  1521. X  for(y=0;y<h-1;y++)
  1522. X   {optr=p->im + 2*y*p->mwidth;
  1523. X    nptr=optr+p->mwidth;
  1524. X    uptr=nptr+p->mwidth;
  1525. X
  1526. X    for(x=0;x<w-1;x++)
  1527. X     {
  1528. X      nptr[0]=(((sINT)optr[0])+((sINT)uptr[0])+1)>>1;
  1529. X      nptr[1]=(((sINT)optr[0])+((sINT)optr[2])+((sINT)uptr[0])+((sINT)uptr[2])+2)>>2;
  1530. X      nptr+=2; optr+=2; uptr+=2;
  1531. X     }
  1532. X    *(nptr++)=(((sINT)*(optr++))+((sINT)*(uptr++))+1)>>1;
  1533. X    *(nptr++)=(((sINT)*(optr++))+((sINT)*(uptr++))+1)>>1;
  1534. X   }
  1535. X
  1536. X
  1537. X  optr=p->im + (2*h-2)*p->mwidth;
  1538. X  nptr=p->im + (2*h-1)*p->mwidth;
  1539. X  for(x=0;x<w;x++)
  1540. X   { *(nptr++) = *(optr++);  *(nptr++) = *(optr++); }
  1541. X
  1542. X }
  1543. X
  1544. X
  1545. X
  1546. X
  1547. Xstatic sINT testbegin(void)
  1548. X {sINT i,j;
  1549. X  for(i=j=0;i<32;i++)
  1550. X    if(sbuffer[i]==0xff) j++;
  1551. X
  1552. X  return (j>30);
  1553. X  
  1554. X }
  1555. X
  1556. X
  1557. XsINT Skip4Base(void)
  1558. X {sINT cd_offset,cd_offhelp;
  1559. X  
  1560. X  cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  1561. X  SEEK(cd_offset+3);          
  1562. X  EREADBUF;    
  1563. X  cd_offhelp=((((sINT)sbuffer[510])<<8)|sbuffer[511]) + 1;
  1564. X
  1565. X  cd_offset+=cd_offhelp;
  1566. X
  1567. X  SEEK(cd_offset);
  1568. X  EREADBUF;
  1569. X  while(!testbegin())
  1570. X   {cd_offset++;
  1571. X    EREADBUF;
  1572. X   }
  1573. X  return cd_offset;
  1574. X }
  1575. X
  1576. X
  1577. X
  1578. X
  1579. X
  1580. Xvoid planealloc(implane *p, dim width, dim height)
  1581. X {melde("planealloc\n");
  1582. X  p->iwidth=p->iheight=0;
  1583. X  p->mwidth=width;
  1584. X  p->mheight=height;
  1585. X
  1586. X  p->mp = ( p->im = ( uBYTE * ) malloc  (width*height*sizeof(uBYTE)) );
  1587. X  if(!(p->im)) error(E_MEM);
  1588. X }
  1589. X
  1590. X
  1591. Xstatic void pastequer(implane *gross,dim px,dim py,implane *klein)
  1592. X {dim x,y;
  1593. X  uBYTE *von,*nach;
  1594. X
  1595. X  if(px+klein->iwidth  > gross->iwidth)  error(E_INTERN);
  1596. X  if(py+klein->iheight > gross->iheight) error(E_INTERN);
  1597. X
  1598. X  for(y=0;y<klein->iheight;y++)
  1599. X   { von=klein->im + y * klein->mwidth;
  1600. X     nach=gross->im + (y+py) * gross->mwidth + px;
  1601. X     for(x=0;x<klein->iwidth;x++)
  1602. X        *(nach++)=*(von++);
  1603. X   }
  1604. X }
  1605. X
  1606. Xstatic void pastehead(implane *gross,dim px,dim py,implane *klein)
  1607. X {dim x,y;
  1608. X  uBYTE *von,*nach;
  1609. X
  1610. X  if(px+klein->iwidth  > gross->iwidth)  error(E_INTERN);
  1611. X  if(py+klein->iheight > gross->iheight) error(E_INTERN);
  1612. X
  1613. X  for(y=0;y<klein->iheight;y++)
  1614. X   { von= klein->im + (klein->iheight-1-y) * klein->mwidth + (klein->iwidth - 1);
  1615. X     nach=gross->im + (y+py) * gross->mwidth + px;
  1616. X     for(x=0;x<klein->iwidth;x++)
  1617. X        *(nach++)=*(von--);
  1618. X   }
  1619. X }
  1620. X
  1621. Xstatic void pastelinks(implane *gross,dim px,dim py,implane *klein)
  1622. X {dim x,y;
  1623. X  uBYTE *von,*nach;
  1624. X
  1625. X  if(px+klein->iheight > gross->iwidth)  error(E_INTERN);
  1626. X  if(py+klein->iwidth  > gross->iheight) error(E_INTERN);
  1627. X
  1628. X  for(y=0;y<klein->iwidth;y++)
  1629. X   { von=klein->im + klein->iwidth - 1 - y;
  1630. X     nach=gross->im + (y+py) * gross->mwidth + px;
  1631. X     for(x=0;x<klein->iheight;x++,von+=klein->mwidth)
  1632. X        *(nach++)=*(von);
  1633. X   }
  1634. X }
  1635. Xstatic void pasterechts(implane *gross,dim px,dim py,implane *klein)
  1636. X {dim x,y;
  1637. X  uBYTE *von,*nach;
  1638. X
  1639. X  if(px+klein->iheight > gross->iwidth)  error(E_INTERN);
  1640. X  if(py+klein->iwidth  > gross->iheight) error(E_INTERN);
  1641. X
  1642. X  for(y=0;y<klein->iwidth;y++)
  1643. X   { von=klein->im + (klein->iheight-1)*klein->mwidth + y;
  1644. X     nach=gross->im + (y+py) * gross->mwidth + px;
  1645. X     for(x=0;x<klein->iheight;x++,von-=klein->mwidth)
  1646. X        *(nach++)=*(von);
  1647. X   }
  1648. X }
  1649. X
  1650. X
  1651. Xvoid pastein(implane *gross,
  1652. X             dim xpos,dim xw,
  1653. X             dim ypos,dim yh,
  1654. X             implane *klein, enum TURNS ori)
  1655. X {
  1656. X  switch (ori)
  1657. X   {
  1658. X    case T_NONE: pastequer(gross,xpos+(xw-klein->iwidth)/2,ypos+(yh-klein->iheight)/2,klein);
  1659. X                 break;
  1660. X    case T_LEFT: pastelinks(gross,xpos+(xw-klein->iheight)/2,ypos+(yh-klein->iwidth)/2,klein);
  1661. X                 break;
  1662. X    case T_RIGHT:pasterechts(gross,xpos+(xw-klein->iheight)/2,ypos+(yh-klein->iwidth)/2,klein);
  1663. X                 break;
  1664. X    case T_HEAD: pastehead(gross,xpos+(xw-klein->iwidth)/2,ypos+(yh-klein->iheight)/2,klein);
  1665. X                 break;
  1666. X    case T_AUTO:
  1667. X    default: error(E_INTERN);
  1668. X   }
  1669. X }
  1670. X
  1671. X
  1672. X
  1673. X
  1674. X#define cro(p,d) {if(p) {p->im+=d*p->mwidth; p->iheight-=d;}}
  1675. X#define cru(p,d) {if(p) {p->iheight-=d;}}
  1676. X#define crl(p,d) {if(p) {p->im+=d; p->iwidth-=d;}}
  1677. X#define crr(p,d) {if(p) {p->iwidth-=d;}}
  1678. X
  1679. Xvoid cropit(sizeinfo *si,implane *l,implane *c1,implane *c2)
  1680. X {dim x,y,s,w,h;
  1681. X  sINT nl,nr,no,nu;
  1682. X
  1683. X  uBYTE *ptr;
  1684. X
  1685. X  melde("crop\n");
  1686. X
  1687. X  if(si->imvlen || si->imhlen) error(E_INTERN);
  1688. X  w=si->rdhlen;
  1689. X  h=si->rdvlen;
  1690. X
  1691. X  if((!l) || (l->iwidth != w) || (l->iheight != h)) error(E_INTERN);
  1692. X  
  1693. X  if(!monochrome)
  1694. X   {if((!c1) || (c1->iwidth != w) || (c1->iheight != h)) error(E_INTERN);
  1695. X    if((!c2) || (c2->iwidth != w) || (c2->iheight != h)) error(E_INTERN);
  1696. X   }
  1697. X
  1698. X
  1699. X  for(y=0,no=0;y<h;y++,no++)
  1700. X   {for(x=0,ptr=(l->im)+y*(l->mwidth); x<w && (*ptr)<MAX_BLACK ;x++,ptr++);
  1701. X    if(x<w) break;
  1702. X   }
  1703. X  cro(l ,no);
  1704. X  cro(c1,no);
  1705. X  cro(c2,no);
  1706. X  h-=no;
  1707. X
  1708. X
  1709. X  for(y=h-1,nu=0;y;y--,nu++)
  1710. X   {for(x=0,ptr=(l->im)+y*(l->mwidth); x<w && (*ptr)<MAX_BLACK ;x++,ptr++);
  1711. X    if(x<w) break;
  1712. X   }
  1713. X  cru(l ,nu);
  1714. X  cru(c1,nu);
  1715. X  cru(c2,nu);
  1716. X  h-=nu;
  1717. X
  1718. X
  1719. X  s=l->mwidth;
  1720. X
  1721. X  for(x=0,nl=0;x<w;x++,nl++)
  1722. X   {for(y=0,ptr=(l->im)+x; y<h && (*ptr)<MAX_BLACK ; y++, ptr+=s);
  1723. X    if(y<h) break;
  1724. X   }
  1725. X  crl(l ,nl);
  1726. X  crl(c1,nl);
  1727. X  crl(c2,nl);
  1728. X  w-=nl;
  1729. X  
  1730. X
  1731. X  for(x=w-1,nr=0;x;x--,nr++)
  1732. X   {for(y=0,ptr=(l->im)+x; y<h && (*ptr)<MAX_BLACK ; y++, ptr+=s);
  1733. X    if(y<h) break;
  1734. X   }
  1735. X  crr(l ,nr);
  1736. X  crr(c1,nr);
  1737. X  crr(c2,nr);
  1738. X  w-=nr;
  1739. X  
  1740. X  if (do_melde) 
  1741. X   {
  1742. X    if (no || nu || nr || nl )
  1743. X      fprintf(stderr,"Cut off %d top, %d bottom, %d left, %d right,  new size is %ldx%ld\n",
  1744. X              no,nu,nl,nr,w,h);
  1745. X    else
  1746. X      fprintf(stderr,"Nothing cut off\n");
  1747. X   }
  1748. X
  1749. X  si->imvlen=h;
  1750. X  si->imhlen=w;
  1751. X }
  1752. X
  1753. X
  1754. X
  1755. X
  1756. X
  1757. X
  1758. X
  1759. X
  1760. X
  1761. X
  1762. X
  1763. X
  1764. X
  1765. X
  1766. X
  1767. Xvoid shrink(sizeinfo *si,implane *l,implane *c1,implane *c2)
  1768. X {dim w,h;
  1769. X
  1770. X  melde("shrink\n");
  1771. X
  1772. X  w=si->rdhlen;
  1773. X  h=si->rdvlen;
  1774. X
  1775. X  if((!l) || (l->iwidth != w) || (l->iheight != h)) error(E_INTERN);
  1776. X  
  1777. X  if(!monochrome)
  1778. X   {if((!c1) || (c1->iwidth != w) || (c1->iheight != h)) error(E_INTERN);
  1779. X    if((!c2) || (c2->iwidth != w) || (c2->iheight != h)) error(E_INTERN);
  1780. X   }
  1781. X
  1782. X  if((!si->imvlen) && (!si->imhlen))  /* no subrectangle given */
  1783. X   {si->imvlen=si->rdvlen;
  1784. X    si->imhlen=si->rdhlen;
  1785. X    return;
  1786. X   }
  1787. X
  1788. X  if (si->imvlen>h || si->imvlen<1 )       error(E_INTERN);
  1789. X  if (si->imvoff> si->rdvlen - si->imvlen) error(E_INTERN);
  1790. X
  1791. X  if (si->imhlen>w || si->imhlen<1 ) error(E_INTERN);
  1792. X  if (si->imhoff> si->rdhlen - si->imhlen) error(E_INTERN);
  1793. X
  1794. X  cro(l ,si->imvoff);
  1795. X  cro(c1,si->imvoff);
  1796. X  cro(c2,si->imvoff);
  1797. X
  1798. X  cru(l ,si->rdvlen - si->imvoff - si->imvlen);
  1799. X  cru(c1,si->rdvlen - si->imvoff - si->imvlen);
  1800. X  cru(c2,si->rdvlen - si->imvoff - si->imvlen);
  1801. X  
  1802. X  crl(l ,si->imhoff);
  1803. X  crl(c1,si->imhoff);
  1804. X  crl(c2,si->imhoff);
  1805. X
  1806. X  crr(l ,si->rdhlen - si->imhoff - si->imhlen);
  1807. X  crr(c1,si->rdhlen - si->imhoff - si->imhlen);
  1808. X  crr(c2,si->rdhlen - si->imhoff - si->imhlen);
  1809. X  
  1810. X
  1811. X }
  1812. X
  1813. X
  1814. X
  1815. X/* Test Data types for their size an whether they 
  1816. X   are signed / unsigned */
  1817. X
  1818. Xvoid typecheck(void)
  1819. X { sBYTE sbyte;
  1820. X   uBYTE ubyte;
  1821. X   sINT  sint;
  1822. X   uINT  uint;
  1823. X
  1824. X
  1825. X   if(sizeof(sBYTE) != 1) error(E_CONFIG);
  1826. X   sbyte=126; sbyte++; sbyte++;
  1827. X   if(sbyte > 126 ) error(E_CONFIG);
  1828. X
  1829. X   if(sizeof(uBYTE) != 1) error(E_CONFIG);
  1830. X   ubyte=126; ubyte++; ubyte++;
  1831. X   if(ubyte < 126 ) error(E_CONFIG);
  1832. X
  1833. X#ifdef U_TOO_LONG
  1834. X   if(sizeof(sINT) < 4) error(E_CONFIG);
  1835. X   if(sizeof(uINT) < 4) error(E_CONFIG);
  1836. X#else
  1837. X   if(sizeof(sINT) != 4) error(E_CONFIG);
  1838. X   if(sizeof(uINT) != 4) error(E_CONFIG);
  1839. X#endif
  1840. X
  1841. X   sint=1; sint--; sint--;
  1842. X   if(sint>1) error(E_CONFIG);
  1843. X
  1844. X   uint=1; uint--; uint--;
  1845. X   if(uint<1) error(E_CONFIG);
  1846. X
  1847. X }
  1848. X
  1849. END_OF_FILE
  1850.   if test 8936 -ne `wc -c <'hpcdtoppm.0.5.pl1/tools.c'`; then
  1851.     echo shar: \"'hpcdtoppm.0.5.pl1/tools.c'\" unpacked with wrong size!
  1852.   fi
  1853.   # end of 'hpcdtoppm.0.5.pl1/tools.c'
  1854. fi
  1855. echo shar: End of archive 1 \(of 3\).
  1856. cp /dev/null ark1isdone
  1857. MISSING=""
  1858. for I in 1 2 3 ; do
  1859.     if test ! -f ark${I}isdone ; then
  1860.     MISSING="${MISSING} ${I}"
  1861.     fi
  1862. done
  1863. if test "${MISSING}" = "" ; then
  1864.     echo You have unpacked all 3 archives.
  1865.     rm -f ark[1-9]isdone
  1866. else
  1867.     echo You still must unpack the following archives:
  1868.     echo "        " ${MISSING}
  1869. fi
  1870. exit 0
  1871. exit 0 # Just in case...
  1872.