Annotation of 43BSDReno/contrib/isode-beta/others/quipu/photo/pbmtofax.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.