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

1.1     ! root        1: /* faxtopbm.c - FAX to pbm filter */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/faxtopbm.c,v 7.0 89/11/23 22:01:41 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/others/quipu/photo/RCS/faxtopbm.c,v 7.0 89/11/23 22:01:41 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       faxtopbm.c,v $
        !            12:  * Revision 7.0  89/11/23  22:01:41  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: #include <stdio.h>
        !            29: #include "psap.h"
        !            30: #include "pbm/pbm.h"
        !            31: 
        !            32: /*  */
        !            33: 
        !            34: static int     passno;
        !            35: 
        !            36: static bit     black, white;
        !            37: 
        !            38: /*    MAIN */
        !            39: 
        !            40: /* ARGSUSED */
        !            41: 
        !            42: main (argc, argv, envp)
        !            43: int    argc;
        !            44: char  **argv,
        !            45:       **envp;
        !            46: {
        !            47:     char   *cp,
        !            48:           *file;
        !            49:     FILE   *fp;
        !            50:     PE     pe;
        !            51:     PS     ps;
        !            52: 
        !            53:     black = PBM_BLACK, white = PBM_WHITE;
        !            54: 
        !            55:     file = NULLCP, fp = stdin;
        !            56:     for (argv++; cp = *argv; argv++)
        !            57:        if (*cp == '-') {
        !            58:            if (cp[1] == NULL)
        !            59:                goto usage;
        !            60: 
        !            61:            if (strncmp (cp, "-reversebits", strlen (cp)) == 0) {
        !            62:                black = PBM_WHITE, white = PBM_BLACK;
        !            63:                continue;
        !            64:            }
        !            65:            goto usage;
        !            66:        }
        !            67:        else
        !            68:            if (file) {
        !            69: usage: ;
        !            70:                fprintf (stderr, "usage: faxtopbm [file]\n"), exit (1);
        !            71:            }
        !            72:            else
        !            73:                if ((fp = fopen (file = cp, "r")) == NULL)
        !            74:                    perror (file), exit (1);
        !            75: 
        !            76:     if ((ps = ps_alloc (std_open)) == NULLPS)
        !            77:        fprintf (stderr, "ps_alloc: you lose\n"), exit (1);
        !            78:     if (std_setup (ps, fp) == NOTOK)
        !            79:        ps_die (ps, "std_setup");
        !            80:     if ((pe = ps2pe (ps)) == NULLPE)
        !            81:        ps_die (ps, "ps2pe");
        !            82:     if (pe_pullup (pe) == NOTOK)
        !            83:        pe_die (pe, "pe_pullup");
        !            84:     if (prim2bit (pe) == NULLPE)
        !            85:        pe_die (pe, "prim2bit");
        !            86: 
        !            87:     for (passno = 1; passno < 3; passno++)
        !            88:        if (decode_t4 (pe -> pe_prim, file, ps_get_abs (pe)) == NOTOK)
        !            89:            fprintf (stderr, "\n"), exit (1);
        !            90: 
        !            91:     pe_free (pe);
        !            92:     ps_free (ps);
        !            93: 
        !            94:     exit (0);
        !            95: }
        !            96: 
        !            97: /*    ERRORS */
        !            98: 
        !            99: static ps_die (ps, s)
        !           100: register PS     ps;
        !           101: register char   *s;
        !           102: {
        !           103:     fprintf (stderr, "%s: %s\n", s, ps_error (ps -> ps_errno));
        !           104:     exit (1);
        !           105: }
        !           106: 
        !           107: 
        !           108: static pe_die (pe, s)
        !           109: register PE     pe;
        !           110: register char   *s;
        !           111: {
        !           112:     fprintf (stderr, "%s: %s\n", s, pe_error (pe -> pe_errno));
        !           113:     exit (1);
        !           114: }
        !           115: 
        !           116: /*    PHOTO */
        !           117: 
        !           118: static int     x, y, maxx;
        !           119: 
        !           120: static bit    *bitrow, *bP;
        !           121: 
        !           122: 
        !           123: /* ARGSUSED */
        !           124: 
        !           125: photo_start(name)
        !           126: char   *name;
        !           127: {
        !           128:     if (passno == 1)
        !           129:        maxx = 0;
        !           130:     x = y = 0;
        !           131: 
        !           132:     return OK;
        !           133: }
        !           134: 
        !           135: 
        !           136: /* ARGSUSED */
        !           137: 
        !           138: photo_end (name)
        !           139: char   *name;
        !           140: {
        !           141:     if (passno == 1) {
        !           142:        register int    i;
        !           143: 
        !           144:        x = maxx, y--;
        !           145: 
        !           146:        pbm_writepbminit (stdout, maxx, y);
        !           147:        bitrow = pbm_allocrow (maxx);
        !           148: 
        !           149:        for (i = maxx, bP = bitrow; i-- > 0; )
        !           150:            *bP++ = white;
        !           151:        bP = bitrow;
        !           152:     }
        !           153:     else
        !           154:        pbm_freerow (bitrow);
        !           155: 
        !           156:     return OK;
        !           157: }
        !           158: 
        !           159: 
        !           160: photo_black (length)
        !           161: int    length;
        !           162: {
        !           163:     if (passno == 2) {
        !           164:        register int    i;
        !           165: 
        !           166:        for (i = length; i > 0; i--)
        !           167:            *bP++ = black;
        !           168:     }
        !           169: 
        !           170:     x += length;
        !           171: 
        !           172:     return OK;
        !           173: }
        !           174: 
        !           175: 
        !           176: photo_white (length)
        !           177: int    length;
        !           178: {
        !           179:     if (passno == 2)
        !           180:        bP += length;
        !           181: 
        !           182:     x += length;
        !           183: 
        !           184:     return OK;
        !           185: }
        !           186: 
        !           187: 
        !           188: /* ARGSUSED */
        !           189: 
        !           190: photo_line_end (line)
        !           191: caddr_t line;
        !           192: {
        !           193:     if (passno == 1) {
        !           194:        if (x > maxx)
        !           195:            maxx = x;
        !           196:     }
        !           197:     else {
        !           198:        register int    i;
        !           199: 
        !           200:        pbm_writepbmrow (stdout, bitrow, maxx);
        !           201: 
        !           202:        for (i = maxx, bP = bitrow; i-- > 0; )
        !           203:            *bP++ = white;
        !           204:        bP = bitrow;
        !           205:     }
        !           206: 
        !           207:     x = 0, y++;
        !           208: 
        !           209:     return OK;
        !           210: }

unix.superglobalmegacorp.com

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