home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume36 / chiaro / part10 < prev    next >
Encoding:
Text File  |  1993-03-25  |  55.3 KB  |  1,579 lines

  1. Newsgroups: comp.sources.misc
  2. From: jwbirdsa@picarefy.picarefy.com (James W. Birdsall)
  3. Subject: v36i080:  chiaro - Image Utilities, Part10/18
  4. Message-ID: <1993Mar26.202754.14616@sparky.imd.sterling.com>
  5. X-Md4-Signature: 98a1ac53653d2528c08459055cf0edc5
  6. Date: Fri, 26 Mar 1993 20:27:54 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jwbirdsa@picarefy.picarefy.com (James W. Birdsall)
  10. Posting-number: Volume 36, Issue 80
  11. Archive-name: chiaro/part10
  12. Environment: UNIX, Sun, DECstation, 3B1
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  src/chils.1 src/jfif.h src/pgmppm.c
  19. # Wrapped by kent@sparky on Thu Mar 25 11:20:05 1993
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 10 (of 18)."'
  23. if test -f 'src/chils.1' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'src/chils.1'\"
  25. else
  26.   echo shar: Extracting \"'src/chils.1'\" \(34361 characters\)
  27.   sed "s/^X//" >'src/chils.1' <<'END_OF_FILE'
  28. X.\"
  29. X.\" $Id: chils.1,v 1.4 1993/03/18 21:18:21 jwbirdsa Exp $
  30. X.\"
  31. X.TH CHILS 1 "$Date: 1993/03/18 21:18:21 $"
  32. X.PD 1
  33. X.SH NAME
  34. Xchils \- specialized ls for image files
  35. X.SH SYNOPSIS
  36. X.B chils
  37. X[
  38. X.B \-v
  39. X][
  40. X.B \-f
  41. X][
  42. X.B \-h
  43. X][
  44. X.B \-n
  45. X][
  46. X.B \-w[n]
  47. X][
  48. X.B \-tformat
  49. X][
  50. X.B \-spattern
  51. X] [ target ] [ target... ]
  52. X.br
  53. X.SH DESCRIPTION
  54. X.I Chils
  55. Xis a specialized ls(1)-equivalent for image files. It recognizes a variety
  56. Xof image file formats and prints out the file name, file format, file size,
  57. Xand some details of image size, colors, etc., depending on what information
  58. Xthe format contains and how accessible it is.
  59. X.SH TARGETS
  60. XA target is a filename or directory. Multiple targets may be specified on
  61. Xthe command line. If a target is a directory, all files in that directory
  62. Xwill be processed. If no targets are specified on the command line, all
  63. Xfiles in the current directory will be processed.
  64. X.PP
  65. XIf the format of a file is recognized, various information about the file
  66. Xwill be printed to the standard output. Otherwise, no output is generated
  67. Xfor that file unless the
  68. X.B \-v
  69. Xoption has been specified.
  70. X.SH OPTIONS
  71. XOptions may not be combined. In the case of the
  72. X.B \-t
  73. Xand
  74. X.B \-s
  75. Xoptions, there cannot be a space between the option and the argument to the
  76. Xoption.
  77. X.TP
  78. X.B \-v
  79. XPrint a line for every file checked, whether the format was recognized or
  80. Xnot. If the file format was not recognized, a message "ERROR: file 
  81. X.I filename
  82. Xis of unknown format" is printed.
  83. X.TP
  84. X.B \-f
  85. XPrints a list of the names of files of recognized formats (subject to
  86. Xselection criteria specified by other options) on the standard output,
  87. Xseparated by newlines. The
  88. X.B \-v
  89. Xoption is ignored and all other output is suppressed. This output is
  90. Xintended for use as a front end for 
  91. X.I gifstrip
  92. Xand other Chiaro suite programs.
  93. X.TP
  94. X.B \-h
  95. XPrints a usage message.
  96. X.TP
  97. X.B \-n
  98. X.I Chils
  99. Xnormally removes the path, if present, from filenames when displaying, the
  100. Xbetter to fit everything on one line. This option causes
  101. X.I chils
  102. Xto not remove the path, if present.
  103. X.TP
  104. X.B \-w[n]
  105. X.I Chils
  106. Xnormally determines the width of the screen automatically, or defaults the
  107. Xwidth to 80 columns if it cannot get a better answer. This option overrides
  108. Xthe automatic determination. If a number is not supplied, the width is set
  109. Xto 80 columns. If a number is supplied, the width is set to that value or
  110. X80, whichever is greater.
  111. X.TP
  112. X.B \-tformat
  113. XOnly files of the specified format will be processed. Multiple
  114. X.B \-t
  115. Xoptions may be specified; files of all the specified types will be
  116. Xprocessed. The
  117. X.B \-v
  118. Xoption is ignored. There must not be a space between the "-t" and the
  119. Xformat identifier. The complete list of recognized format identifiers is
  120. Xprinted out in the usage message. Format identifiers are case insensitive.
  121. XAt present, the following format identifiers are recognized:
  122. X.PP
  123. X.RS 10
  124. X.nf
  125. XGIF87a         GIF87a files
  126. XGIF89a         GIF89a files
  127. XGIF            Any GIF file, either GIF87a or GIF89a
  128. XIMG_1          GEM IMG version 1 files
  129. XIMG            Any GEM IMG file
  130. XJFIF101        JPEG File Interchange Format versions
  131. X                  1.00 and 1.01
  132. XJFIF           Any JFIF file
  133. XSUNRAS         Sun raster files
  134. XTARGA          TARGA files
  135. XPBM_NORM       Portable BitMap files, ASCII format
  136. XPBM_RAW        Portable BitMap files, raw format
  137. XPBM            Any Portable BitMap file
  138. XPGM_NORM       Portable GrayMap files, ASCII format
  139. XPGM_RAW        Portable GrayMap files, raw format
  140. XPGM            Any Portable GrayMap file
  141. XPPM_NORM       Portable PixMap files, ASCII format
  142. XPPM_RAW        Portable PixMap files, raw format
  143. XPPM            Any Portable PixMap file
  144. XXBM            X11 BitMap files
  145. XWIN2BMP        MS-Windows 2.x bitmap files
  146. XOS2BMP11       OS/2 1.1-1.3 bitmap files
  147. XWIN3BMP        MS-Windows 3.x bitmap files
  148. XOS2BMP20       OS/2 2.0 bitmap files
  149. XBMP            Any BMP file.
  150. XPCX_25         PCX version 2.5 files.
  151. XPCX_28         PCX version 2.8 files without palettes.
  152. XPCX_28P        PCX version 2.8 files with palettes.
  153. XPCX_30         PCX version 3.0 files.
  154. XPCX            Any PCX file.
  155. X.fi
  156. X.RE
  157. X.TP
  158. X.B \-spattern
  159. XSelects files according to a complicated Boolean search pattern, including
  160. Xsearch on file format, image height, image width, number of colors in the
  161. Ximage, and file size. Only files which meet the specified search criteria
  162. Xare processed. Any
  163. X.B \-t
  164. Xand
  165. X.B \-v
  166. Xoptions are ignored. There must not be a space between the "-s" and the
  167. Xsearch pattern, or within the search pattern. If more than one
  168. X.B \-s
  169. Xoption is specified, only the last one on the command line will have
  170. Xeffect. The search pattern may include the following operator characters:
  171. X.PP
  172. X.RS 10
  173. X.nf
  174. X( )    ( )     parentheses for grouping
  175. X=      =       equal
  176. X>      }       greater than
  177. X<      {       less than
  178. X>=     }=      greater or equal
  179. X<=     {=      less or equal
  180. X&      +       logical AND
  181. X|      ,       logical OR
  182. X.fi
  183. X.RE
  184. X.RS 5
  185. X.PP
  186. XNormally, the operators in the first column should be used.
  187. XIf
  188. X.I chils
  189. Xwas compiled with the DOS_COMSRCH option, then use the operators in the
  190. Xsecond column. Since most of the operators are also shell metacharacters,
  191. Xthe search pattern should be quoted:
  192. X.PP
  193. X.ti+5n
  194. Xchils -s'(W>320)&(H>200)'
  195. X.PP
  196. XThe operator characters work on the following elements:
  197. X.RE
  198. X.PP
  199. X.RS 10
  200. X.nf
  201. XH              image height
  202. XW              image width
  203. XC              image colors
  204. XF              file size
  205. Xdecimal numbers
  206. X.fi
  207. Xformat identifiers as for
  208. X.B \-t
  209. X.RE
  210. X.SH CONFIGURATION
  211. XMany image formats do not include signatures which identify them uniquely.
  212. XThe only way to identify these formats is by filename. Most formats have one
  213. Xor more extensions which are commonly used to identify that format. To
  214. Xaccomodate as wide a variety of naming systems as possible,
  215. X.I chils
  216. Xuses a configuration file which contains lists of formats and extensions
  217. Xwhich identify those formats. Extensions may also be included for those
  218. Xformats which have identification signatures (GIF and SUNRAS), to avoid false
  219. Xrecognition. If extensions for these formats are included, only files with
  220. Xthose extensions will be checked for the signature; otherwise all files
  221. Xwill be checked.
  222. X.PP
  223. XThe configuration file must be named
  224. X.I chils.cfg.
  225. X.I Chils
  226. Xsearches for it first in the current directory. If there is no such file in
  227. Xthe current directory,
  228. X.I chils
  229. Xchecks for the existence of an environment variable
  230. X.I CHIHOME.
  231. XIf it exists, it is assumed to contain the directory in which the
  232. Xconfiguration file resides. Finally,
  233. X.I chils
  234. Xsearches in the directory containing the
  235. X.I chils
  236. Xexecutable. This three-layer system allows local configuration files which
  237. Xoverride the main configuration file, and allows the main configuration
  238. Xfile to be anywhere, not necessarily in the directory with the executable.
  239. XIf the configuration file does not exist, a warning message is issued.
  240. XFormats for which
  241. X.I chils
  242. Xneeds an extension list, but which do not have an entry in the
  243. Xconfiguration file, will not be processed. The default configuration file
  244. Xsupplied with the source code contains entries for all formats which
  245. X.I chils
  246. Xcan process.
  247. X.PP
  248. XBlank lines in
  249. X.I chils.cfg
  250. Xare ignored. Comments begin with '#'. The '#' must be the first
  251. Xnon-whitespace character on the line, but it does not have to be in the
  252. Xfirst column. Both spaces and tabs are recognized as whitespace. Comments
  253. Xare terminated by the end of the line.
  254. X.PP
  255. XEach format entry consists of one line. The syntax of the entry is:
  256. X.PP
  257. X.ti+10n
  258. Xformat_name extension [[,] extension...]
  259. X.PP
  260. XThe format name and extensions are case sensitive. The line may contain
  261. Xleading whitespace before the format name. The format name must be
  262. Xseparated from the first extension by at least one space or tab. There must
  263. Xbe at least one extension on the line. Additional extensions may be
  264. Xseparated by commas and/or whitespace. The entry is terminated by the end
  265. Xof the line. Warnings are generated when
  266. X.I chils
  267. Xencounters an unrecognized format name, an entry with only a format name
  268. X(no extension list), or a zero-length extension (caused by two commas in a
  269. Xrow, for example).
  270. X.PP
  271. XFormat identifiers recognized by CHILS are: GIF, IMG, JFIF, SUNRAS, TARGA,
  272. XPBM, PGM, PPM, XBM, BMP, and PCX.
  273. X.SH OUTPUT
  274. XThe output generated by
  275. X.I chils
  276. Xvaries according to the format of the image, but the meaning of some
  277. Xcolumns is constant.
  278. X.PP
  279. X.nf
  280. X.ti-2n
  281. XGIF87A   -G   110871  381 x  480 @ 64    C~80                    ssb28c.gif
  282. X.ti-2n
  283. XGIF89A   -G-    2657  640 x  480 @ 16    C~1   ASnone          89aillus.gif
  284. X.ti-2n
  285. XGIF89A   -G-   62318  640 x  480 @ 16    C~40  AS49/64           grney5.gif
  286. X.ti-2n
  287. XIMG_1    -     62630  960 x  960 @ 2     C~54  AS 85/85  P1    example1.img
  288. X.ti-2n
  289. XJFIF101  -     18314  264 x  341, 3 @ 8  C~5   AS  1/  1           lat1.jpg
  290. X.ti-2n
  291. XJFIF101  -     44046  976 x  768, 1 @ 8  C~7   AS  1/  1          slf1n.jpg
  292. X.ti-2n
  293. XJFIF101  -     62139  597 x  480, 3 @ 8  C~8    72 x 72 dpi        jol1.jpg
  294. X.ti-2n
  295. XSUNRAS   CV     4435   80 x   50 @ 256   C~90   ML=768          encoded.im8
  296. X.ti-2n
  297. XSUNRAS   C-    32150  871 x  871 @ 2     C~33                  jupiterc.im1
  298. X.ti-2n
  299. XSUNRAS   SV     4800   80 x   50 @ 256   ML=768                standard.sun
  300. X.ti-2n
  301. XSUNRAS   S-     1568   16 x   32, 24 bit                      stndrd24.im24
  302. X.ti-2n
  303. XTARGA    -UM-   4756   80 x   50 @ 246   T1  A0                   type1.tga
  304. X.ti-2n
  305. XTARGA    -UC-   1554   16 x   32, 24 bit T2  A0                   type2.tga
  306. X.ti-2n
  307. XTARGA    -UB-    186   24 x    7 @ 256   T3  A0                   type3.tga
  308. X.ti-2n
  309. XPBM_RAW  R        29   24 x    7 @ 2                           feep-raw.pbm
  310. X.ti-2n
  311. XPGM_RAW  R       180   24 x    7 @ 256   MaxVal = 255          feep-raw.pgm
  312. X.ti-2n
  313. XPPM_RAW  R        59    4 x    4, 24 bit MaxVal = 255          feep-raw.ppm
  314. X.ti-2n
  315. XPBM_NORM N       355   24 x    7 @ 2                               feep.pbm
  316. X.ti-2n
  317. XPGM_NORM N       519   24 x    7 @ 16    MaxVal =  15              feep.pgm
  318. X.ti-2n
  319. XPPM_NORM N       189    4 x    4 @ 4096  MaxVal =  15              feep.ppm
  320. X.ti-2n
  321. XXBM              182   24 x    7 @ 2     'feep'                    feep.xbm
  322. X.ti-2n
  323. XWIN3BMP  --     5078   80 x   50 @ 256                         256color.bmp
  324. X.ti-2n
  325. XWIN3BMP  --      630   32 x   32 @ 16                            argyle.bmp
  326. X.ti-2n
  327. XPCX_30   RC     4715   80 x   50 @ 256   C~114  CX 80,CY 50       color.pcx
  328. X.ti-2n
  329. XPCX_30   RC      191   24 x    7 @ 8     C~100  CX 24,CY  7    feepgray.pcx
  330. X.ti-2n
  331. XPCX_30   RC      152   24 x    7 @ 2     C~114  CX 24,CY  7    feepmono.pcx
  332. X.fi
  333. X.PP
  334. XThe first column is always the format (see the list under the
  335. X.B \-t
  336. Xoption above). The second column, if present, is a group of flags whose
  337. Xmeaning varies according to the image (see below). The third column is the
  338. Xfilesize. Next is the width and the height of the image (or a reasonable
  339. Xapproximation) in pixels, then the number of colors
  340. Xin the image in a format which depends on the image. After that is 
  341. Xmiscellaneous format-dependent information; frequently a compression ratio
  342. Xis given, indicated by "C~". The last column is always the filename. If the
  343. Xfilename is too long to fit on the line, it is put on the line immediately
  344. Xfollowing, right justified.
  345. X.RS 3
  346. X.SS GIF87a
  347. X.PP
  348. X.nf
  349. X.ti-2n
  350. XGIF87A   EG    53882  398 x  548 @ 16    C~49                      bar4.gif
  351. X.ti-2n
  352. XGIF87A   -G   110871  381 x  480 @ 64    C~80                    ssb28c.gif
  353. X.ti-2n
  354. XGIF87A   --    59392  320 x  240 @ ---   C~--                        tt.gif
  355. X.fi
  356. X.PP
  357. XThe GIF87A format has two flags. The first is "E" if extra characters are
  358. Xdetected on the end of the file, or "-" if not. The second is "G" if the
  359. Xfile contains a global color table, or "-" if not. Note that
  360. Xthe "E" flag is only a quick and dirty check for extra characters on the end
  361. Xof the file. If the last character of the file is the GIF Terminator, "-"
  362. Xis displayed; if it is not, "E" is displayed. This check will be
  363. Xfooled if the file contains extra characters which happen to end with the
  364. XGIF Terminator character.
  365. X.I Gifstrip
  366. Xand
  367. X.I gifcheck
  368. Xoffer reliable detection of extra characters (and, in the case of
  369. X.I gifstrip,
  370. Xremoval thereof).
  371. X.PP
  372. XThe width and height displayed are for the logical screen, not the actual
  373. Ximage. Typically the image or images in the file will be the same size as
  374. Xthe logical screen, but this is not required. Unfortunately, it is not
  375. Xpossible to extract the size of the actual image or images without parsing
  376. Xmuch of the file, which is beyond the scope of
  377. X.I chils.
  378. X.PP
  379. XThe number of colors shown is the size of the global color table, or "---"
  380. Xif there is no global color table. Images typically do not use all the colors
  381. Xin the global color table; the number should be regarded as an upper limit on
  382. Xthe colors in the actual image rather than the actual figure.
  383. X.I Gifcheck
  384. Xcan determine the number of unique colors actually used.
  385. X.PP
  386. XThe only format-dependent display is the compression ratio. "--" is
  387. Xdisplayed if no global color table is present, since the calculation relies
  388. Xon the size of that table. The compression ratio 
  389. Xis calculated by multiplying the height by the width, then multiplying that
  390. Xresult by the number of bits required to represent the colors in the image
  391. X(based on the size of the global color table), and dividing by 8 to
  392. Xobtain the number of bytes which the image data would occupy when
  393. Xuncompressed. Finally, the present file size is divided by the
  394. Xcomputed uncompressed size, which yields the size of the compressed image
  395. Xas a percentage of the uncompressed size. Note that the value displayed may
  396. Xbe radically incorrect if the file contains multiple images, if the file
  397. Xcontains extension blocks, if the image uses a local color table, if the
  398. Ximage is smaller than the logical screen size, or if there are very many
  399. Xextra characters on the end of the file.
  400. X.SS GIF89a
  401. X.PP
  402. X.nf
  403. X.ti-2n
  404. XGIF89A   -G-    2657  640 x  480 @ 16    C~1   ASnone          89aillus.gif
  405. X.ti-2n
  406. XGIF89A   -G-   62318  640 x  480 @ 16    C~40  AS49/64           grney5.gif
  407. X.fi
  408. X.PP
  409. XThe GIF89A format has three flags. The first is "E" if extra characters are
  410. Xdetected on the end of the file, or "-" if not. The second is "G" if the
  411. Xfile contains a global color table, or "-" if not. The third is "S" if the
  412. Xglobal color table is sorted in order of decreasing importance, or "-" if
  413. Xnot. Note that the "E" flag is only a quick and dirty check for extra characters
  414. Xon the end of the file. If the last character of the file is the GIF
  415. XTerminator, "-" is displayed; if it is not, "E" is displayed. This check will
  416. Xbe fooled if the file contains extra characters which happen to end with the
  417. XGIF Terminator character.
  418. X.I Gifstrip
  419. Xand
  420. X.I gifcheck
  421. Xoffer reliable detection of extra characters (and, in the case of
  422. X.I gifstrip,
  423. Xremoval thereof).
  424. X.PP
  425. XThe width and height displayed are for the logical screen, not the actual
  426. Ximage. Typically the image or images in the file will be the same size as
  427. Xthe logical screen, but this is not required. Unfortunately, it is not
  428. Xpossible to extract the size of the actual image or images without parsing
  429. Xmuch of the file, which is beyond the scope of
  430. X.I chils.
  431. X.PP
  432. XThe number of colors shown is the size of the global color table, or "---"
  433. Xif there is no global color table. Images typically do not use all the colors
  434. Xin the global color table; the number should be regarded as an upper limit on
  435. Xthe number of colors in the actual image rather than the actual figure.
  436. X.I Gifcheck
  437. Xcan determine the number of unique colors actually used.
  438. X.PP
  439. XFormat-dependent displays for GIF89a are the compression ratio and aspect
  440. Xratio, in that order.
  441. X.PP
  442. XIf no global color table is present, "--" is displayed for the compression
  443. Xratio, since the calculation relies on the size of that table. The compression
  444. Xratio is calculated by multiplying the height by the width, then multiplying
  445. Xthat result by the number of bits required to represent the colors in the image
  446. X(based on the size of the global color table), and dividing by 8 to
  447. Xobtain the number of bytes which the image data would occupy when
  448. Xuncompressed. Finally, the present file size is divided by the
  449. Xcomputed uncompressed size, which yields the size of the compressed image
  450. Xas a percentage of the uncompressed size. Note that the value displayed may
  451. Xbe radically incorrect if the file contains multiple images, if the file
  452. Xcontains extension blocks, if the image uses a local color table, if the
  453. Ximage is smaller than the logical screen size, or if there are very many
  454. Xextra characters on the end of the file.
  455. X.PP
  456. XThe aspect ratio is given in 64ths. If there is no aspect ratio, "none" is
  457. Xdisplayed.
  458. X.SS IMG_1
  459. X.PP
  460. X.nf
  461. X.ti-2n
  462. XIMG_1    -     62630  960 x  960 @ 2     C~54  AS 85/85  P1    example1.img
  463. X.fi
  464. X.PP
  465. XNote that there are many file formats named "IMG", a situation which is
  466. Xconfusing at best.
  467. X.I Chils
  468. Xrecognizes only the GEM IMG format.
  469. X.PP
  470. XThe IMG_1 format has one flag. It is "L" if the IMG header is extended
  471. X(to contain a palette, for example), or "-" if the header is of normal
  472. Xlength.
  473. X.PP
  474. XThe maximum number of colors in the file is calculated from the number of
  475. Xbit planes; the actual number of colors used may be less than the number
  476. Xshown.
  477. X.PP
  478. XFormat-dependent displays for IMG_1 are the compression ratio, aspect ratio,
  479. Xand pattern length, in that order.
  480. X.PP
  481. XThe compression ratio is computed by multiplying the height by the width,
  482. Xthen multiplying that result by the number of bit planes, and dividing by 8
  483. Xto obtain the number of bytes which the image data would occupy when
  484. Xuncompressed. Finally, the present file size minus the header length is
  485. Xdivided by the computed uncompressed size, which yields the size of the
  486. Xcompressed image as a percentage of the uncompressed size. The compression
  487. Xratio is reasonably accurate. Since the header length is known accurately,
  488. Xthat number is subtracted from the filesize to get a more accurate
  489. Xcompressed size. The compression ratio will only be incorrect if there are
  490. Xjunk characters on the end of the file.
  491. X.PP
  492. XThe aspect ratio is always present. The numbers also represent the width and
  493. Xheight, respectively, of a pixel, in microns. 85 microns is approximately
  494. Xequivalent to 300 pixels per inch.
  495. X.PP
  496. XThe pattern length in pixels is used when decompressing the image.
  497. X.SS JFIF1.01
  498. X.PP
  499. X.nf
  500. X.ti-2n
  501. XJFIF101  -     18314  264 x  341, 3 @ 8  C~5   AS  1/  1           lat1.jpg
  502. X.ti-2n
  503. XJFIF101  -     44046  976 x  768, 1 @ 8  C~7   AS  1/  1          slf1n.jpg
  504. X.ti-2n
  505. XJFIF101  -     62139  597 x  480, 3 @ 8  C~8    72 x 72 dpi        jol1.jpg
  506. X.fi
  507. X.PP
  508. XThe JFIF 1.0 and 1.01 formats differ minimally;
  509. X.I chils
  510. Xtreats them as identical.
  511. X.PP
  512. XThe JFIF101 format has one flag. It is "T" if a thumbnail image is present
  513. Xin the file, or "-" if not.
  514. X.PP
  515. XThe number of colors is expressed as the number of "components" (usually 3
  516. Xor 1) by the number of bits per component (usually 8). Images with three
  517. Xcomponents are full-color, while images with one are, by convention,
  518. Xgrayscale.
  519. X.PP
  520. XFormat-dependent displays for JFIF101 are the compression ratio and aspect
  521. Xratio or pixel density, in that order.
  522. X.PP
  523. XThe compression ratio is computed by multiplying the height by the width,
  524. Xthen multiplying that result by the number of components times the bits per
  525. Xcomponent, and dividing by 8 to obtain the number of bytes which the image
  526. Xdata would occupy when uncompressed. Finally, the present file size is
  527. Xdivided by the computed uncompressed size, which yields the size of the
  528. Xcompressed image as a percentage of the uncompressed size. Note that the image
  529. Xitself is actually compressed even more than shown, since the present file
  530. Xsize includes all the headers and other, non-image information present in the
  531. Xfile.
  532. X.PP
  533. XJFIF101 files contain either an aspect ratio or a pixel density. If an
  534. Xaspect ratio is present, it is expressed as a fraction. If pixel density is
  535. Xpresent instead, it is displayed as the horizontal density by the vertical
  536. Xdensity followed by the units, which are either "dpi" (pixels/dots per
  537. Xinch) or "dpcm" (pixels/dots per centimeter).
  538. X.SS SUNRAS
  539. X.PP
  540. X.nf
  541. X.ti-2n
  542. XSUNRAS   CV     4435   80 x   50 @ 256   C~90   ML=768          encoded.im8
  543. X.ti-2n
  544. XSUNRAS   C-    32150  871 x  871 @ 2     C~33                  jupiterc.im1
  545. X.ti-2n
  546. XSUNRAS   SV     4800   80 x   50 @ 256   ML=768                standard.sun
  547. X.ti-2n
  548. XSUNRAS   S-     1568   16 x   32, 24 bit                      stndrd24.im24
  549. X.fi
  550. X.PP
  551. XSun Raster files are a format developed by Sun Microsystems for use on
  552. Xtheir workstations.
  553. X.PP
  554. XThe SUNRAS format has two flags. The first is "O" for 'old' format files
  555. X(left over from ancient versions of SunOS), "S" for standard files, "C"
  556. Xfor compressed files, "R" for 24-bit files with reversed color-component
  557. Xorder, "T" for "tiff <-> standard rasterfile" (don't ask me), "I" for "iff
  558. X(TAAC format) <-> standard rasterfile" (again, don't ask me), and "E" 
  559. Xfor 'experimental' formats. The second flag is "-" if the file does not have a
  560. Xcolormap, "V" if the colormap is in 'vector' format (all red components
  561. Xgrouped together, all green components grouped together in the same order,
  562. Xetc.), or "R" if the colormap is in 'raw' format (usually RGB triples).
  563. X.PP
  564. XThe number of colors is expressed either as a number or as the number of
  565. Xbits per pixel, depending on which fits in the available space. In the case
  566. Xof a plain number, not all colors may be used; the number should be regarded
  567. Xas an upper limit on the number of colors in the actual image rather than
  568. Xthe actual figure.
  569. X.PP
  570. XFormat-dependent displays for SUNRAS are the compression ratio (if a
  571. Xcompressed format) and the length of the colormap in bytes (if a colormap
  572. Xis present), in that order.
  573. X.PP
  574. XThe compression ratio is computed by multiplying the height by the width,
  575. Xthen multiplying that result by the number of bits per pixel, and dividing by
  576. X8 to obtain the number of bytes which the image data would occupy when
  577. Xuncompressed. Finally, the size of the compressed data (maintained in the
  578. Xfile header) is divided by the computed uncompressed size, which yields the
  579. Xsize of the compressed image as a percentage of the uncompressed size. The
  580. Xcompression ratio is accurate unless the file is corrupted.
  581. X.PP
  582. XIf a colormap is present, the length in bytes is displayed as "ML=nnn".
  583. X.SS TARGA
  584. X.PP
  585. X.nf
  586. X.ti-2n
  587. XTARGA    -UM-   4756   80 x   50 @ 246   T1  A0                   type1.tga
  588. X.ti-2n
  589. XTARGA    -UC-   1554   16 x   32, 24 bit T2  A0                   type2.tga
  590. X.ti-2n
  591. XTARGA    -UB-    186   24 x    7 @ 256   T3  A0                   type3.tga
  592. X.fi
  593. X.PP
  594. XThe Targa format was developed by AT&T in conjunction with their TrueVision
  595. Xgraphics hardware.
  596. X.PP
  597. XThe TARGA format has four flags. The first is "-" if the file contains an
  598. Ximage or "N" if not. The second is "-" for no image, "U" for an
  599. Xuncompressed image, "R" for a runlength-encoded image, or "C" for an
  600. XLZW-compressed image. The third is "-" for no image, "M" for a colormapped
  601. Ximage, "B" for a grayscale image, or "C" for a full-color image. The fourth
  602. Xflag indicates the scan-line interleave of the image: "-" for
  603. Xnoninterleaved, "2" or "4" for two- or four-way interleaving, or "R" for a
  604. Xreserved value.
  605. X.PP
  606. XThe number of colors is expressed either as a number or as the number of
  607. Xbits per pixel. If the image is colormapped, the length of the colormap is
  608. Xdisplayed. If the image is not colormapped (either grayscale or
  609. Xfull-color), either a number or the number of bits is displayed depending
  610. Xon which fits in the available space. In the case of a plain number, not
  611. Xall colors may be used; the number should be regarded as an upper limit on
  612. Xthe number of colors in the actual image rather than the actual figure.
  613. X.PP
  614. XFormat-dependent displays for TARGA are the compression ratio (if a
  615. Xrunlength-encoded or LZW-compressed format), the format type "Tn", the number
  616. Xof attribute bits per pixel "An", "M" if an unnecessary colormap is
  617. Xincluded in the file, and "I" if the file has an ID field.
  618. X.PP
  619. XThe compression ratio is computed by multiplying the height by the width,
  620. Xthen multiplying that result by the number of bits per pixel, and dividing
  621. Xby 8 to obtain the number of bytes which the image data would occupy when
  622. Xuncompressed. Finally, the present file size minus the header, ID field,
  623. Xand colormap lengths is divided by the computed uncompressed size, which
  624. Xyields the size of the compressed image as a percentage of the
  625. Xuncompressed size. The compression ratio should be accurate unless the file
  626. Xis corrupted or there are junk characters on the end of the file.
  627. X.SS PBM, PGM, PPM, PBM_RAW, PGM_RAW, PPM_RAW
  628. X.PP
  629. X.nf
  630. X.ti-2n
  631. XPBM_RAW  R        29   24 x    7 @ 2                           feep-raw.pbm
  632. X.ti-2n
  633. XPGM_RAW  R       180   24 x    7 @ 256   MaxVal = 255          feep-raw.pgm
  634. X.ti-2n
  635. XPPM_RAW  R        59    4 x    4, 24 bit MaxVal = 255          feep-raw.ppm
  636. X.ti-2n
  637. XPBM_NORM N       355   24 x    7 @ 2                               feep.pbm
  638. X.ti-2n
  639. XPGM_NORM N       519   24 x    7 @ 16    MaxVal =  15              feep.pgm
  640. X.ti-2n
  641. XPPM_NORM N       189    4 x    4 @ 4096  MaxVal =  15              feep.ppm
  642. X.fi
  643. X.PP
  644. XThese formats were developed by Jef Poskanzer for his Portable Bitmap
  645. X(later Portable Bitmap Plus) package. The formats were designed to be
  646. Xeasily transferable between machines and easily usable on widely differing
  647. Xmachines. There are three basic types, PBM (Portable BitMap, black and
  648. Xwhite only), PGM (Portable GrayMap, grayscale), and PPM (Portable PixMap,
  649. Xfull-color), each of which comes in two varieties, normal (all data is
  650. Xrepresented as ASCII text) and raw (the image data is stored as
  651. Xpacked bytes.)
  652. X.I Chils
  653. Xhandles all six permutations.
  654. X.PP
  655. XThese formats have only one flag, which is "R" for a raw file and "N" for a
  656. Xnormal file, and is redundant.
  657. X.PP
  658. XThe number of colors is expressed either as a number or as the number of
  659. Xbits per pixel. For PBM and PGM images, it is always a number (always 2 for
  660. XPBM). For PPM images, it is either a number or the number of bits depending
  661. Xon which fits in the available space. In the case of a plain number, not
  662. Xall colors may be used; the number should be regarded as an upper limit on
  663. Xthe number of colors in the actual image rather than the actual figure.
  664. X.PP
  665. XThere are no format-dependent displays for PBM; PGM and PPM display the
  666. Xmaximum value that a pixel may take (usually a power of 2 minus 1).
  667. X.SS XBM
  668. X.PP
  669. X.nf
  670. X.ti-2n
  671. XXBM              182   24 x    7 @ 2     'feep'                    feep.xbm
  672. X.fi
  673. X.PP
  674. XThe XBM (X BitMap) format is used by the X Window system developed at MIT.
  675. XThe format is designed for easy incorporation into C-language programs and
  676. Xall data is represented as ASCII text.
  677. X.PP
  678. XThe XBM format has no flags.
  679. X.PP
  680. XThe number of colors is always 2, black and white.
  681. X.PP
  682. XFormat-dependent displays for XBM are the name of the image, which is
  683. Xencoded into the file.
  684. X.SS WIN2BMP
  685. X.PP
  686. X.nf
  687. X.ti-2n
  688. XWIN2BMP  -       630   32 x   32 @ 16                              argh.bmp
  689. X.fi
  690. X.PP
  691. XThe WIN2BMP format is an obsolete format used by MS-Windows 2.x.
  692. X.PP
  693. XThe WIN2BMP format has one flag, which is "D" if the bitmap resource is
  694. Xdiscardable or "-" if it is not.
  695. X.PP
  696. XThe number of colors is expressed either as a number or as the number of
  697. Xbits per pixel, depending on which fits in the available space. In the case
  698. Xof a plain number, not all colors may be used; the number should be regarded
  699. Xas an upper limit on the number of colors in the actual image rather than the
  700. Xactual figure.
  701. X.PP
  702. XThere are no format-dependent displays for WIN2BMP.
  703. X.SS OS2BMP11
  704. X.PP
  705. X.nf
  706. X.ti-2n
  707. XOS2BMP11 -      5078   80 x   50 @ 256                         256color.bmp
  708. X.fi
  709. X.PP
  710. XThe OS2BMP11 format is used by OS/2 1.1-1.3. The WIN3BMP and OS2BMP20
  711. Xformats are loosely based on it.
  712. X.PP
  713. XThe OS2BMP11 format has one flag, which is "E" if the file size in the
  714. Xheader does not match the present file size or "-" if it does.
  715. X.PP
  716. XThe number of colors is expressed either as a number or as the number of
  717. Xbits per pixel, depending on which fits in the available space. In the case
  718. Xof a plain number, not all colors may be used; the number should be regarded
  719. Xas an upper limit on the number of colors in the actual image rather than the
  720. Xactual figure.
  721. X.PP
  722. XThere are no format-dependent displays for OS2BMP11.
  723. X.SS WIN3BMP
  724. X.PP
  725. X.nf
  726. X.ti-2n
  727. XWIN3BMP  --     5078   80 x   50 @ 256                         256color.bmp
  728. X.ti-2n
  729. XWIN3BMP  --      630   32 x   32 @ 16                            argyle.bmp
  730. X.fi
  731. X.PP
  732. XThe WIN3BMP format is used by MS-Windows 3.x. It is loosely based on the
  733. XOS2BMP11 format and the OS2BMP20 format is based on it.
  734. X.PP
  735. XThe WIN3BMP format has two flags. The first one is "E" if the file size in
  736. Xthe header does not match the present file size or "-" if it does. The
  737. Xsecond one is "-" for an uncompressed file, "4" if 4-bit run-length
  738. Xcompression is used, or "8" if 8-bit run-length compression is used.
  739. X.PP
  740. XThe number of colors is expressed either as a number or as the number of
  741. Xbits per pixel, depending on which fits in the available space. In the case
  742. Xof a plain number, not all colors may be used; the number should be regarded
  743. Xas an upper limit on the number of colors in the actual image rather than the
  744. Xactual figure.
  745. X.PP
  746. XFormat-dependent displays for WIN3BMP are the compression ratio (for
  747. Xcompressed files), the horizontal and vertical resolution (if present) and
  748. Xthe number of important colors (if present and different from the number of
  749. Xcolors in the colormap) "Innn".
  750. X.PP
  751. XThe compression ratio is computed by multiplying the height by the width,
  752. Xthen multiplying that result by the number of bits per pixel, and dividing
  753. Xby 8 to obtain the number of bytes which the image data would occupy when
  754. Xuncompressed. Finally, the size of the compressed data (maintained in the
  755. Xfile header) is divided by the computed uncompressed size, which
  756. Xyields the size of the compressed image as a percentage of the
  757. Xuncompressed size. The compression ratio is accurate unless the file is
  758. Xcorrupted.
  759. X.PP
  760. XThe horizontal and vertical resolution are in pixels per meter, displayed
  761. Xas "Xnnn,Ynnn".
  762. X.SS OS2BMP20
  763. X.PP
  764. X.nf
  765. X.ti-2n
  766. XOS2BMP20 --R-   5078   80 x   50 @ 256                         256color.bmp
  767. X.fi
  768. X.PP
  769. XThe OS2BMP20 format is used by OS/2 2.0. It is an extension of the WIN3BMP
  770. Xformat.
  771. X.PP
  772. XThe OS2BMP20 format has four flags. The first one is "E" if the file size
  773. Xin the header does not match the present file size or "-" if it does. The
  774. Xsecond one is "-" for an uncompressed file or "C" for a compressed file.
  775. XThe third one relates to the colormap format and should always be "R". The
  776. Xfourth one is "H" if a halftoning algorithm is specified, "-" otherwise.
  777. X.PP
  778. XThe number of colors is expressed either as a number or as the number of
  779. Xbits per pixel, depending on which fits in the available space. In the case
  780. Xof a plain number, not all colors may be used; the number should be regarded
  781. Xas an upper limit on the number of colors in the actual image rather than the
  782. Xactual figure.
  783. X.PP
  784. XFormat-dependent displays for OS2BMP20 are the compression ratio (for
  785. Xcompressed files), the horizontal and vertical resolution (if present) and
  786. Xthe number of important colors (if present and different from the number of
  787. Xcolors in the colormap) "Innn".
  788. X.PP
  789. XThe compression ratio is computed by multiplying the height by the width,
  790. Xthen multiplying that result by the number of bits per pixel, and dividing
  791. Xby 8 to obtain the number of bytes which the image data would occupy when
  792. Xuncompressed. Finally, the size of the compressed data (maintained in the
  793. Xfile header) is divided by the computed uncompressed size, which
  794. Xyields the size of the compressed image as a percentage of the
  795. Xuncompressed size. The compression ratio is accurate unless the file is
  796. Xcorrupted.
  797. X.PP
  798. XThe horizontal and vertical resolution are displayed as "Xnnn,Ynnn dp?",
  799. Xwhere '?' should always be 'm' (for dots per meter).
  800. X.SS PCX
  801. X.PP
  802. X.nf
  803. X.ti-2n
  804. XPCX_30   RC     4715   80 x   50 @ 256   C~114  CX 80,CY 50       color.pcx
  805. X.ti-2n
  806. XPCX_30   RC      191   24 x    7 @ 8     C~100  CX 24,CY  7    feepgray.pcx
  807. X.ti-2n
  808. XPCX_30   RC      152   24 x    7 @ 2     C~114  CX 24,CY  7    feepmono.pcx
  809. X.fi
  810. X.PP
  811. XThe PCX format was created by the ZSoft Corporation.
  812. X.I Chils
  813. Xrecognizes PCX_25 (version 2.5), PCX_28 (version 2.8 without palette),
  814. XPCX_28P (version 2.8 with palette), and PCX_30 (version 3.0).
  815. X.PP
  816. XThe PCX format has two flags. The first one should always be "R",
  817. Xindicating that the file is run-length encoded. The second one is "G" if
  818. Xthe palette should be interpreted as grayscale or "C" if it should be
  819. Xinterpreted as color.
  820. X.PP
  821. XThe number of colors is expressed either as a number or as the number of
  822. Xbits per pixel, depending on which fits in the available space. In the case
  823. Xof a plain number, not all colors may be used; the number should be regarded
  824. Xas an upper limit on the number of colors in the actual image rather than the
  825. Xactual figure.
  826. X.PP
  827. XFormat-dependent displays for PCX are the compression ratio and the
  828. Xhorizontal and vertical resolution of the file creator, in that order.
  829. X.PP
  830. XThe compression ratio is computed by multiplying the height by the width,
  831. Xthen multiplying that result by the number of bits per pixel, and dividing
  832. Xby 8 to obtain the number of bytes which the image data would occupy when
  833. Xuncompressed. Finally, the present file size minus the length of the PCX
  834. Xheader is divided by the computed uncompressed size, which 
  835. Xyields the size of the compressed image as a percentage of the
  836. Xuncompressed size. The compression ratio should be accurate unless the file 
  837. Xhas extra characters (such as a 256-color palette) on the end.
  838. X.PP
  839. XThe horizontal and vertical resolution are displayed as "CXnnn,CYnnn".
  840. XUnfortunately, it is not clear what these values mean.
  841. X.RE
  842. X.SH COPYRIGHT
  843. X.I Chils
  844. Xis copyright 1993 by James W. Birdsall, all rights reserved.
  845. X.PP
  846. XThe Graphics Interchange Format(c) is the Copyright property of CompuServe
  847. XIncorporated. GIF(sm) is a Service Mark property of CompuServe
  848. XIncorporated.
  849. X.PP
  850. XSunOS is a trademark of Sun Microsystems Inc.
  851. X.PP
  852. XTarga and TrueVision are probably trademarks of AT&T.
  853. X.PP
  854. XMS-Windows is probably a trademark of Microsoft.
  855. X.PP
  856. XOS/2 is a registered trademark of IBM.
  857. X.PP
  858. XOther terms in this document may be trademarks or service marks of or
  859. Xcopyright by various corporations and organizations.
  860. X.SH AUTHOR
  861. XJames W. Birdsall
  862. X.RS 3
  863. X.nf
  864. Xsupport@picarefy.com
  865. Xuunet!uw-coco!amc-gw!picarefy!support
  866. XCompuServe: 71261,1731
  867. XGEnie: J.BIRDSALL2
  868. X.fi
  869. X.RE
  870. X.SH FILES
  871. Xchils.cfg         Configuration file
  872. X.SH "SEE ALSO"
  873. Xgifstrip(1),
  874. Xgifcheck(1)
  875. END_OF_FILE
  876.   if test 34361 -ne `wc -c <'src/chils.1'`; then
  877.     echo shar: \"'src/chils.1'\" unpacked with wrong size!
  878.   fi
  879.   # end of 'src/chils.1'
  880. fi
  881. if test -f 'src/jfif.h' -a "${1}" != "-c" ; then 
  882.   echo shar: Will not clobber existing file \"'src/jfif.h'\"
  883. else
  884.   echo shar: Extracting \"'src/jfif.h'\" \(3868 characters\)
  885.   sed "s/^X//" >'src/jfif.h' <<'END_OF_FILE'
  886. X/***************************************************************************
  887. X*   JFIF.H                                                                 *
  888. X*   HEADER FOR JFIF                                                        *
  889. X*   OS:      UNIX                                                          *
  890. X*                                                                          *
  891. X*   Copyright (c) 1993 James W. Birdsall. All Rights Reserved.             *
  892. X*                                                                          *
  893. X*   $Id: jfif.h,v 1.4 1993/02/10 01:38:45 jwbirdsa Exp $
  894. X*                                                                          *
  895. X*   This file specifies the external interface to the JFIF module.         *
  896. X*                                                                          *
  897. X***************************************************************************/
  898. X
  899. X#ifndef DEPEND_H
  900. X    **** ERROR **** DEPEND.H MUST BE INCLUDED BEFORE JFIF.H
  901. X#endif
  902. X#ifndef FB_H
  903. X    **** ERROR **** FB.H MUST BE INCLUDED BEFORE JFIF.H
  904. X#endif
  905. X
  906. X#ifndef JFIF_H
  907. X
  908. X#define JFIF_H
  909. X
  910. X/*
  911. X** system includes <>
  912. X*/
  913. X
  914. X/*
  915. X** custom includes ""
  916. X*/
  917. X
  918. X#include "status.h"
  919. X
  920. X
  921. X/*
  922. X** local #defines
  923. X*/
  924. X
  925. X/* Version defines. */
  926. X
  927. X#define JFIF_NOT                FORMAT_NOT
  928. X#define JFIF_VER101             (FORMAT_JFIF | MKLONG(1))
  929. X
  930. X/* Block types. */
  931. X
  932. X#define JFIF_SOI                0xD8
  933. X#define JFIF_APP0               0xE0
  934. X#define JFIF_SOF0               0xC0
  935. X#define JFIF_EOI                0xD9
  936. X
  937. X#define JFIF_SEPARATOR          0xFF
  938. X
  939. X/* Offsets in APP0. */
  940. X
  941. X#define JFIF_APP0_LENGTH_OFF    0
  942. X#define JFIF_APP0_SIGNATURE_OFF 2
  943. X#define JFIF_APP0_VERS_OFF      7
  944. X#define JFIF_APP0_DENSUNIT_OFF  9
  945. X#define JFIF_APP0_XDENS_OFF     10
  946. X#define JFIF_APP0_YDENS_OFF     12
  947. X#define JFIF_APP0_XTHUMB_OFF    14
  948. X#define JFIF_APP0_YTHUMB_OFF    15
  949. X#define JFIF_APP0_THUMB_OFF     16
  950. X
  951. X#define JFIF_APP0_LEN           16
  952. X
  953. X/* Offsets in SOF0. */
  954. X
  955. X#define JFIF_SOF0_LENGTH_OFF    0
  956. X#define JFIF_SOF0_PREC_OFF      2
  957. X#define JFIF_SOF0_HI_OFF        3
  958. X#define JFIF_SOF0_WID_OFF       5
  959. X#define JFIF_SOF0_COMP_OFF      7
  960. X#define JFIF_SOF0_STUFF_OFF     8
  961. X
  962. X#define JFIF_SOF0_LEN           8
  963. X
  964. X/* Offsets in misc block. */
  965. X
  966. X#define JFIF_GENERIC_LENGTH_OFF 0
  967. X
  968. X#define JFIF_GENERIC_LEN        2
  969. X
  970. X/* JFIF signature info. */
  971. X
  972. X#define JFIF_SIGNATURE          "JFIF"
  973. X#define JFIF_SIGNATURE_LEN      5
  974. X
  975. X/* JFIF pixel density units types. */
  976. X
  977. X#define JFIF_DENS_ASPECT        0
  978. X#define JFIF_DENS_DPI           1
  979. X#define JFIF_DENS_DPCM          2
  980. X
  981. X/* Error/status defines. */
  982. X
  983. X#define JFIF_NOTJFIF_E          MKERR(1, JFIF_MODULE, ST_ERROR)
  984. X#define JFIF_FILEERR_E          MKERR(2, JFIF_MODULE, ST_ERROR)
  985. X
  986. X
  987. X/*
  988. X** misc: copyright strings, version macros, etc.
  989. X*/
  990. X
  991. Xstatic char CONST RCSjfif[] = "$Id: jfif.h,v 1.4 1993/02/10 01:38:45 jwbirdsa Exp $";
  992. X
  993. X
  994. X/*
  995. X** typedefs
  996. X*/
  997. X
  998. Xtypedef struct {
  999. X    ULONG version;              /* the JFIF format version */
  1000. X    int components;             /* color components (1=grayscale, 3=color) */
  1001. X    int bits;                   /* bits per sample */
  1002. X    unsigned int height;        /* image height, pixels */
  1003. X    unsigned int width;         /* image width, pixels */
  1004. X    int densunit;               /* density unit (see above for meanings) */
  1005. X    unsigned int xdens;         /* horizontal pixel density */
  1006. X    unsigned int ydens;         /* vertical pixel density */
  1007. X    int xthumb;                 /* thumbnail image width, pixels (0 if none) */
  1008. X    int ythumb;                 /* thumbnail image height, pixels (0 if none) */
  1009. X} JFIF_HDR;
  1010. X
  1011. X
  1012. X/*
  1013. X** global variables
  1014. X*/
  1015. X
  1016. X/*
  1017. X** function prototypes
  1018. X*/
  1019. X
  1020. X#ifdef  __STDC__
  1021. X# define P_(s) s
  1022. X#else
  1023. X# define P_(s) ()
  1024. X#endif
  1025. X
  1026. XULONG jfif_verify P_((char *filename, ULONG *version, char **exts));
  1027. X
  1028. XULONG jfif_headerget P_((FB *infile, JFIF_HDR *results));
  1029. X
  1030. Xchar *jfif_errstring P_((ULONG errcode));
  1031. X
  1032. X#undef P_
  1033. X
  1034. X#endif /* JFIF_H */
  1035. X
  1036. END_OF_FILE
  1037.   if test 3868 -ne `wc -c <'src/jfif.h'`; then
  1038.     echo shar: \"'src/jfif.h'\" unpacked with wrong size!
  1039.   fi
  1040.   # end of 'src/jfif.h'
  1041. fi
  1042. if test -f 'src/pgmppm.c' -a "${1}" != "-c" ; then 
  1043.   echo shar: Will not clobber existing file \"'src/pgmppm.c'\"
  1044. else
  1045.   echo shar: Extracting \"'src/pgmppm.c'\" \(14335 characters\)
  1046.   sed "s/^X//" >'src/pgmppm.c' <<'END_OF_FILE'
  1047. X/***************************************************************************
  1048. X*   PGMPPM.C                                                               *
  1049. X*   PNM_MODULE:  PNM                                                           *
  1050. X*   OS:      UNIX                                                          *
  1051. X*                                                                          *
  1052. X*   Copyright (c) 1993 James W. Birdsall. All Rights Reserved.             *
  1053. X*                                                                          *
  1054. X*   $Id: pgmppm.c,v 1.1 1993/03/02 00:58:33 jwbirdsa Exp $
  1055. X*                                                                          *
  1056. X*   This file contains functions to process PGM or PPM format files.       *
  1057. X*   Functions:                                                             *
  1058. X*      p?m_verify    - checks filename to see if it is an PGM file         *
  1059. X*      p?m_getheader - extracts header data from PGM file                  *
  1060. X*                                                                          *
  1061. X*      p?m_errstring - converts error code into message                    *
  1062. X*                                                                          *
  1063. X***************************************************************************/
  1064. X
  1065. X#include "config.h"
  1066. X
  1067. X/*
  1068. X** system includes <>
  1069. X*/
  1070. X
  1071. X#include <stdio.h>
  1072. X#ifndef NO_STDLIB
  1073. X#include <stdlib.h>
  1074. X#endif
  1075. X#ifndef NO_STR_INC
  1076. X#ifdef STRING_PLURAL
  1077. X#include <strings.h>
  1078. X#else
  1079. X#include <string.h>
  1080. X#endif
  1081. X#endif
  1082. X
  1083. X
  1084. X/*
  1085. X** custom includes ""
  1086. X*/
  1087. X
  1088. X#include "depend.h"
  1089. X#include "formats.h"
  1090. X#include "token.h"
  1091. X#include "pnm.h"
  1092. X
  1093. X
  1094. X/*
  1095. X** local #defines
  1096. X*/
  1097. X
  1098. X#ifdef PGM
  1099. X#define VERIFY              pgm_verify
  1100. X#define GETHEADER           pgm_getheader
  1101. X#define ERRSTRING           pgm_errstring
  1102. X
  1103. X#define FILEERR_E           PGM_FILEERR_E
  1104. X#define UNEOF_E             PGM_UNEOF_E
  1105. X#define NOT_E               PGM_NOTPGM_E
  1106. X
  1107. X#define MAGIC_NORM          PGM_MAGIC_NORM
  1108. X#define MAGIC_RAW           PGM_MAGIC_RAW
  1109. X
  1110. X#define NORM                PGM_NORM
  1111. X#define RAW                 PGM_RAW
  1112. X
  1113. X#define PNM_MODULE          PGM_MODULE
  1114. X#else
  1115. X#define VERIFY              ppm_verify
  1116. X#define GETHEADER           ppm_getheader
  1117. X#define ERRSTRING           ppm_errstring
  1118. X
  1119. X#define FILEERR_E           PPM_FILEERR_E
  1120. X#define UNEOF_E             PGM_UNEOF_E
  1121. X#define NOT_E               PGM_NOTPGM_E
  1122. X
  1123. X#define MAGIC_NORM          PPM_MAGIC_NORM
  1124. X#define MAGIC_RAW           PPM_MAGIC_RAW
  1125. X
  1126. X#define NORM                PPM_NORM
  1127. X#define RAW                 PPM_RAW
  1128. X
  1129. X#define PNM_MODULE          PPM_MODULE
  1130. X#endif /* PGM */
  1131. X
  1132. X
  1133. X/*
  1134. X** misc: copyright strings, version macros, etc.
  1135. X*/
  1136. X
  1137. X/*
  1138. X** typedefs
  1139. X*/
  1140. X
  1141. X/*
  1142. X** global variables
  1143. X*/
  1144. X
  1145. X/*
  1146. X** static globals
  1147. X*/
  1148. X
  1149. Xstatic char CONST rcsid[] = "$Id: pgmppm.c,v 1.1 1993/03/02 00:58:33 jwbirdsa Exp $";
  1150. X
  1151. X
  1152. X/*
  1153. X** function prototypes
  1154. X*/
  1155. X
  1156. X#ifdef NO_STDLIB
  1157. Xextern int atoi();
  1158. Xextern long atol();
  1159. X#endif
  1160. X
  1161. X#ifdef NO_STR_INC
  1162. Xextern char *strrchr();
  1163. Xextern int strcmp();
  1164. X#endif
  1165. X
  1166. X
  1167. X/*
  1168. X** functions
  1169. X*/
  1170. X
  1171. X
  1172. X/***************************************************************************
  1173. X*   FUNCTION:    p?m_verify                                                *
  1174. X*                                                                          *
  1175. X*   DESCRIPTION:                                                           *
  1176. X*                                                                          *
  1177. X*       Verifies that a file is an PGM/PPM file by checking filename       *
  1178. X*       against list of extensions. Reads magic number from start of       *
  1179. X*       file.                                                              *
  1180. X*                                                                          *
  1181. X*   ENTRY:                                                                 *
  1182. X*                                                                          *
  1183. X*       filename - name of file to be verified                             *
  1184. X*       version  - pointer to unsigned long in which format/version value  *
  1185. X*                  is returned                                             *
  1186. X*       exts     - array of string pointers, list of extensions for files  *
  1187. X*                                                                          *
  1188. X*   EXIT:                                                                  *
  1189. X*                                                                          *
  1190. X*       Returns an error/status code.                                      *
  1191. X*                                                                          *
  1192. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1193. X*                                                                          *
  1194. X***************************************************************************/
  1195. XULONG
  1196. X#ifdef __STDC__
  1197. XVERIFY(char *filename, ULONG *version, char **exts)
  1198. X#else
  1199. XVERIFY(filename, version, exts)
  1200. Xchar *filename;
  1201. XULONG *version;
  1202. Xchar **exts;
  1203. X#endif
  1204. X{
  1205. X    char *extptr;
  1206. X    int loop;
  1207. X    FILE *pnmfile;
  1208. X    int magic;
  1209. X    ULONG retval;
  1210. X
  1211. X    /* Search for '.' marking extension. */
  1212. X
  1213. X    extptr = strrchr(filename, '.');
  1214. X    if (NULL == extptr)
  1215. X    {
  1216. X        /* No extension, cannot classify. */
  1217. X
  1218. X        *version = FORMAT_NOT;
  1219. X        return 0;
  1220. X    }
  1221. X    extptr++;
  1222. X
  1223. X    /* Now we have the extension, check against list. */
  1224. X
  1225. X    for (loop = 0; exts[loop] != NULL; loop++)
  1226. X    {
  1227. X        /* Case-sensitive string compare. */
  1228. X
  1229. X        if (strcmp(extptr, exts[loop]) == 0)
  1230. X        {
  1231. X            /* Match, so break out of loop. */
  1232. X
  1233. X            break;
  1234. X        }
  1235. X    }
  1236. X
  1237. X    /* Check exit from loop. */
  1238. X
  1239. X    if (NULL == exts[loop])
  1240. X    {
  1241. X        /* No match, return. */
  1242. X
  1243. X        *version = FORMAT_NOT;
  1244. X        return 0;
  1245. X    }
  1246. X
  1247. X    /* Extension is valid for type, so process accordingly. */
  1248. X
  1249. X    if ((pnmfile = fopen(filename, FOPEN_READ_BINARY)) == (FILE *) NULL)
  1250. X    {
  1251. X        return FILEERR_E;
  1252. X    }
  1253. X
  1254. X    /* Read magic number, first character. */
  1255. X
  1256. X    if ((magic = fgetc(pnmfile)) == EOF)
  1257. X    {
  1258. X        *version = FORMAT_NOT;
  1259. X        retval = (feof(pnmfile) ? ST_SUCCESS : FILEERR_E);
  1260. X        fclose(pnmfile);
  1261. X        return retval;
  1262. X    }
  1263. X    if (magic != PNM_MAGIC)
  1264. X    {
  1265. X        *version = FORMAT_NOT;
  1266. X        fclose(pnmfile);
  1267. X        return ST_SUCCESS;
  1268. X    }
  1269. X
  1270. X    /* Read magic number, second character. */
  1271. X
  1272. X    if ((magic = fgetc(pnmfile)) == EOF)
  1273. X    {
  1274. X        *version = FORMAT_NOT;
  1275. X        retval = (feof(pnmfile) ? ST_SUCCESS : FILEERR_E);
  1276. X        fclose(pnmfile);
  1277. X        return retval;
  1278. X    }
  1279. X    if ((magic != MAGIC_NORM) && (magic != MAGIC_RAW))
  1280. X    {
  1281. X        *version = FORMAT_NOT;
  1282. X        fclose(pnmfile);
  1283. X        return ST_SUCCESS;
  1284. X    }
  1285. X
  1286. X    /* Set version according to second character of magic number. */
  1287. X
  1288. X    *version = ((MAGIC_NORM == magic) ? NORM : RAW);
  1289. X
  1290. X    /* Close file. */
  1291. X
  1292. X    if (fclose(pnmfile))
  1293. X    {
  1294. X        return FILEERR_E;
  1295. X    }
  1296. X
  1297. X    /* Return OK. */
  1298. X
  1299. X    return 0;
  1300. X} /* end of p?m_verify() */
  1301. X
  1302. X
  1303. X/***************************************************************************
  1304. X*   FUNCTION:    p?m_getheader                                             *
  1305. X*                                                                          *
  1306. X*   DESCRIPTION:                                                           *
  1307. X*                                                                          *
  1308. X*       Assumes that file is an PGM/PPM file. Reads header from file,      *
  1309. X*       extracts data into PNM_HDR structure.                              *
  1310. X*                                                                          *
  1311. X*   ENTRY:                                                                 *
  1312. X*                                                                          *
  1313. X*       infile  - file to be processed                                     *
  1314. X*       results - pointer to PNM_HDR structure in which data from header   *
  1315. X*                 is returned                                              *
  1316. X*                                                                          *
  1317. X*   EXIT:                                                                  *
  1318. X*                                                                          *
  1319. X*       Returns an error/status code.                                      *
  1320. X*                                                                          *
  1321. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1322. X*                                                                          *
  1323. X*       Leaves file pointing to beginning of image data.                   *
  1324. X*                                                                          *
  1325. X***************************************************************************/
  1326. XULONG
  1327. X#ifdef __STDC__
  1328. XGETHEADER(FILE *infile, PNM_HDR *results)
  1329. X#else
  1330. XGETHEADER(infile, results)
  1331. XFILE *infile;
  1332. XPNM_HDR *results;
  1333. X#endif
  1334. X{
  1335. X    char *token;
  1336. X    ULONG status;
  1337. X
  1338. X    /* Make sure we're at beginning of file. */
  1339. X
  1340. X    if (fseek(infile, 0L, SEEK_SET))
  1341. X    {
  1342. X        return FILEERR_E;
  1343. X    }
  1344. X
  1345. X    /* Get first token, should be magic number. */
  1346. X
  1347. X    if ((token = fm_token(infile)) == NULL)
  1348. X    {
  1349. X        return FILEERR_E;
  1350. X    }
  1351. X    if ((token[0] != PNM_MAGIC) ||
  1352. X        ((token[1] != MAGIC_NORM) && (token[1] != MAGIC_RAW)))
  1353. X    {
  1354. X        return NOT_E;
  1355. X    }
  1356. X    results->version = ((MAGIC_NORM == token[1]) ? NORM : RAW);
  1357. X    free(token);
  1358. X
  1359. X    /* Search for next token that is not a comment. */
  1360. X
  1361. X    if ((token = fm_token(infile)) == NULL)
  1362. X    {
  1363. X        return FILEERR_E;
  1364. X    }
  1365. X    while ('#' == token[0])
  1366. X    {
  1367. X        free(token);
  1368. X        if ((status = fm_eol(infile)) != ST_SUCCESS)
  1369. X        {
  1370. X            return ((FM_EOF_W == status) ? UNEOF_E : FILEERR_E);
  1371. X        }
  1372. X        if ((token = fm_token(infile)) == NULL)
  1373. X        {
  1374. X            return FILEERR_E;
  1375. X        }
  1376. X    }
  1377. X
  1378. X    /* Got a token that is not a comment. Should be width of image. */
  1379. X
  1380. X    if ((results->imwid = (ULONG) atol(token)) == 0L)
  1381. X    {
  1382. X        /* Something is wrong. Shouldn't be zero width. */
  1383. X
  1384. X        free(token);
  1385. X        results->version = FORMAT_NOT;
  1386. X        return NOT_E;
  1387. X    }
  1388. X    free(token);
  1389. X
  1390. X    /* Search for next token that is not a comment. */
  1391. X
  1392. X    if ((token = fm_token(infile)) == NULL)
  1393. X    {
  1394. X        return FILEERR_E;
  1395. X    }
  1396. X    while ('#' == token[0])
  1397. X    {
  1398. X        free(token);
  1399. X        if ((status = fm_eol(infile)) != ST_SUCCESS)
  1400. X        {
  1401. X            return ((FM_EOF_W == status) ? UNEOF_E : FILEERR_E);
  1402. X        }
  1403. X        if ((token = fm_token(infile)) == NULL)
  1404. X        {
  1405. X            return FILEERR_E;
  1406. X        }
  1407. X    }
  1408. X
  1409. X    /* Got a token that is not a comment. Should be height of image. */
  1410. X
  1411. X    if ((results->imhi = (ULONG) atol(token)) == 0L)
  1412. X    {
  1413. X        /* Something is wrong. Shouldn't be zero height. */
  1414. X
  1415. X        free(token);
  1416. X        results->version = FORMAT_NOT;
  1417. X        return NOT_E;
  1418. X    }
  1419. X    free(token);
  1420. X
  1421. X    /* Search for next token that is not a comment. */
  1422. X
  1423. X    if ((token = fm_token(infile)) == NULL)
  1424. X    {
  1425. X        return FILEERR_E;
  1426. X    }
  1427. X    while ('#' == token[0])
  1428. X    {
  1429. X        free(token);
  1430. X        if ((status = fm_eol(infile)) != ST_SUCCESS)
  1431. X        {
  1432. X            return ((FM_EOF_W == status) ? UNEOF_E : FILEERR_E);
  1433. X        }
  1434. X        if ((token = fm_token(infile)) == NULL)
  1435. X        {
  1436. X            return FILEERR_E;
  1437. X        }
  1438. X    }
  1439. X
  1440. X    /* Got a token that is not a comment. Should be max pixval. */
  1441. X
  1442. X    if ((results->maxpix = atoi(token)) == 0)
  1443. X    {
  1444. X        /* Something is wrong. Shouldn't be zero max. */
  1445. X
  1446. X        free(token);
  1447. X        results->version = FORMAT_NOT;
  1448. X        return NOT_E;
  1449. X    }
  1450. X    free(token);
  1451. X
  1452. X    /*
  1453. X    ** Set file to point to start of data. Search for next token that 
  1454. X    ** is not a comment. 
  1455. X    */
  1456. X
  1457. X    if ((token = fm_token(infile)) == NULL)
  1458. X    {
  1459. X        return FILEERR_E;
  1460. X    }
  1461. X    while ('#' == token[0])
  1462. X    {
  1463. X        free(token);
  1464. X        if ((status = fm_eol(infile)) != ST_SUCCESS)
  1465. X        {
  1466. X            return ((FM_EOF_W == status) ? UNEOF_E : FILEERR_E);
  1467. X        }
  1468. X        if ((token = fm_token(infile)) == NULL)
  1469. X        {
  1470. X            return FILEERR_E;
  1471. X        }
  1472. X    }
  1473. X    free(token);
  1474. X
  1475. X    /* Return OK. */
  1476. X
  1477. X    return 0;
  1478. X} /* end of p?m_getheader() */
  1479. X
  1480. X
  1481. X/***************************************************************************
  1482. X*   FUNCTION: p?m_errstring                                                *
  1483. X*                                                                          *
  1484. X*   DESCRIPTION:                                                           *
  1485. X*                                                                          *
  1486. X*      Returns a string corresponding to an error code.                    *
  1487. X*                                                                          *
  1488. X*   ENTRY:                                                                 *
  1489. X*                                                                          *
  1490. X*      errcode - error code to be translated                               *
  1491. X*                                                                          *
  1492. X*   EXIT:                                                                  *
  1493. X*                                                                          *
  1494. X*      Returns a pointer to the appropriate string, or NULL if there is    *
  1495. X*      no appropriate string.                                              *
  1496. X*                                                                          *
  1497. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1498. X*                                                                          *
  1499. X***************************************************************************/
  1500. Xchar *
  1501. X#ifdef __STDC__
  1502. XERRSTRING(ULONG errcode)
  1503. X#else
  1504. XERRSTRING(errcode)
  1505. XULONG errcode;
  1506. X#endif
  1507. X{
  1508. X    char *temp;
  1509. X
  1510. X    /* If error code not from this module, return NULL. */
  1511. X
  1512. X    if ((errcode & ST_MOD_MASK) != PNM_MODULE)
  1513. X    {
  1514. X        return NULL;
  1515. X    }
  1516. X
  1517. X    /* Process by code. */
  1518. X
  1519. X    switch (ERRSEV(errcode))
  1520. X    {
  1521. X        case ERRSEV(NOT_E):
  1522. X#ifdef PGM
  1523. X            temp = "File is not a PGM format file.";
  1524. X#else
  1525. X            temp = "File is not a PPM format file.";
  1526. X#endif
  1527. X            break;
  1528. X        case ERRSEV(FILEERR_E):
  1529. X            temp = "Error accessing file.";
  1530. X            break;
  1531. X        case ERRSEV(UNEOF_E):
  1532. X            temp = "Unexpected End of File";
  1533. X            break;
  1534. X
  1535. X        default:
  1536. X            temp = NULL;
  1537. X            break;
  1538. X    }
  1539. X
  1540. X    return temp;
  1541. X} /* end of p?m_errstring() */
  1542. X
  1543. END_OF_FILE
  1544.   if test 14335 -ne `wc -c <'src/pgmppm.c'`; then
  1545.     echo shar: \"'src/pgmppm.c'\" unpacked with wrong size!
  1546.   fi
  1547.   # end of 'src/pgmppm.c'
  1548. fi
  1549. echo shar: End of archive 10 \(of 18\).
  1550. cp /dev/null ark10isdone
  1551. MISSING=""
  1552. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1553.     if test ! -f ark${I}isdone ; then
  1554.     MISSING="${MISSING} ${I}"
  1555.     fi
  1556. done
  1557. if test "${MISSING}" = "" ; then
  1558.     echo You have unpacked all 18 archives.
  1559.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1560. else
  1561.     echo You still must unpack the following archives:
  1562.     echo "        " ${MISSING}
  1563. fi
  1564. exit 0
  1565. exit 0 # Just in case...
  1566.