Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / contrib / isode / others / quipu / photo / old / pbmtofax.c
CommitLineData
54fea4c1
C
1/* pbmtofax.c - pbm to FAX filter */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/pbmtofax.c,v 7.2 90/09/24 15:36:49 mrose Exp $";
5#endif
6
7/*
8 * $Header: /f/osi/others/quipu/photo/RCS/pbmtofax.c,v 7.2 90/09/24 15:36:49 mrose Exp $
9 *
10 *
11 * $Log: pbmtofax.c,v $
12 * Revision 7.2 90/09/24 15:36:49 mrose
13 * update
14 *
15 * Revision 7.1 90/07/09 14:40:29 mrose
16 * sync
17 *
18 * Revision 7.0 89/11/23 22:01:46 mrose
19 * Release 6.0
20 *
21 */
22
23/*
24 * NOTICE
25 *
26 * Acquisition, use, and distribution of this module and related
27 * materials are subject to the restrictions of a license agreement.
28 * Consult the Preface in the User's Manual for the full terms of
29 * this agreement.
30 *
31 */
32
33
34#include <stdio.h>
35#include "quipu/photo.h"
36#include "pbm/pbm.h"
37
38/* \f DATA */
39
40int PIC_LINESIZE, STOP, NUMLINES;
41
42extern int optlen;
43
44
45char *encode_t4 ();
46
47
48char *malloc ();
49
50/* \f MAIN */
51
52/* ARGSUSED */
53
54main (argc, argv, envp)
55int argc;
56char **argv,
57 **envp;
58{
59 int cols,
60 format,
61 rows,
62 skip;
63 char *cp,
64 *data,
65 *file,
66 *optbuf;
67 bit black;
68 FILE *fp;
69
70 black = PBM_BLACK;
71
72 file = NULL, fp = stdin;
73 for (argv++; cp = *argv; argv++)
74 if (*cp == '-') {
75 if (cp[1] == NULL)
76 goto usage;
77
78 if (strncmp (cp, "-reversebits", strlen (cp)) == 0) {
79 black = PBM_WHITE;
80 continue;
81 }
82 goto usage;
83 }
84 else
85 if (file) {
86usage: ;
87 fprintf (stderr, "usage: pbmtofax [file]\n");
88 exit (1);
89 }
90 else
91 if ((fp = pm_openr (file = cp)) == NULL)
92 perror (file), exit (1);
93
94 {
95 int bitcount;
96 register int i,
97 j;
98 unsigned char *byteP;
99 bit *bitrow;
100 register bit *bP;
101
102 pbm_readpbminit (fp, &cols, &rows, &format);
103 bitrow = pbm_allocrow (cols);
104
105 if ((data = malloc ((unsigned) (cols * rows))) == NULL)
106 fprintf (stderr, "out of memory\n"), exit (1);
107 byteP = (unsigned char *) data;
108
109 for (i = rows; i-- > 0; ) {
110 pbm_readpbmrow (fp, bP = bitrow, cols, format);
111 *byteP = NULL, bitcount = 7;
112
113 for (j = cols; j-- > 0; ) {
114 unsigned char mask = 1 << bitcount;
115
116 if (*bP++ == black)
117 *byteP |= mask;
118 else
119 *byteP &= ~mask;
120 if (--bitcount < 0)
121 *++byteP = NULL, bitcount = 7;
122 }
123 if (bitcount != 7)
124 byteP++;
125 }
126
127 pm_close (fp);
128 }
129
130 STOP = (PIC_LINESIZE = cols) + 1;
131 NUMLINES = rows;
132 if ((skip = 8 - (PIC_LINESIZE % 8)) == 8)
133 skip = 0;
134
135 optbuf = encode_t4 (4, data, skip);
136 *(optbuf + optlen) = NULL;
137
138 (void) fwrite (optbuf, optlen + 1, sizeof *optbuf, stdout);
139
140 exit (0);
141}