~ubuntu-branches/ubuntu/jaunty/netpbm-free/jaunty

« back to all changes in this revision

Viewing changes to pbm/pbmtoptx.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2004-07-29 20:25:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040729202546-5x43bcfsdlt7dspl
Tags: upstream-10.0
ImportĀ upstreamĀ versionĀ 10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file
 
2
**
 
3
** Copyright (C) 1988 by Jef Poskanzer.
 
4
**
 
5
** Permission to use, copy, modify, and distribute this software and its
 
6
** documentation for any purpose and without fee is hereby granted, provided
 
7
** that the above copyright notice appear in all copies and that both that
 
8
** copyright notice and this permission notice appear in supporting
 
9
** documentation.  This software is provided "as is" without express or
 
10
** implied warranty.
 
11
*/
 
12
 
 
13
#include "pbm.h"
 
14
 
 
15
static void putinit ARGS(( void ));
 
16
static void putbit ARGS(( bit b ));
 
17
static void putrest ARGS(( void ));
 
18
static void putitem ARGS(( void ));
 
19
 
 
20
int
 
21
main( argc, argv )
 
22
int argc;
 
23
char *argv[];
 
24
    {
 
25
    FILE *ifp;
 
26
    register bit *bitrow, *bP;
 
27
    int rows, cols, format, row, col;
 
28
    char *usage = "[pbmfile]";
 
29
 
 
30
    pbm_init( &argc, argv );
 
31
 
 
32
    if ( argc > 2 )
 
33
        pm_usage( usage );
 
34
 
 
35
    if ( argc == 2 )
 
36
        ifp = pm_openr( argv[1] );
 
37
    else
 
38
        ifp = stdin;
 
39
 
 
40
    pbm_readpbminit( ifp, &cols, &rows, &format );
 
41
    bitrow = pbm_allocrow( cols );
 
42
 
 
43
    putinit( );
 
44
    for ( row = 0; row < rows; row++ )
 
45
        {
 
46
        pbm_readpbmrow( ifp, bitrow, cols, format );
 
47
        for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
 
48
            putbit( *bP );
 
49
        putrest( );
 
50
        putchar( 5 );
 
51
        putchar( '\n' );
 
52
        }
 
53
 
 
54
    pm_close( ifp );
 
55
    
 
56
    exit( 0 );
 
57
    }
 
58
 
 
59
static char item;
 
60
static int bitsperitem, bitshift;
 
61
 
 
62
static void
 
63
putinit( )
 
64
    {
 
65
    bitsperitem = 0;
 
66
    item = 64;
 
67
    bitshift = 0;
 
68
    }
 
69
 
 
70
#if __STDC__
 
71
static void
 
72
putbit( bit b )
 
73
#else /*__STDC__*/
 
74
static void
 
75
putbit( b )
 
76
    bit b;
 
77
#endif /*__STDC__*/
 
78
    {
 
79
    if ( bitsperitem == 6 )
 
80
        putitem( );
 
81
    if ( b == PBM_BLACK )
 
82
        item += 1 << bitshift;
 
83
    bitsperitem++;
 
84
    bitshift++;
 
85
    }
 
86
 
 
87
static void
 
88
putrest( )
 
89
    {
 
90
    if ( bitsperitem > 0 )
 
91
        putitem( );
 
92
    }
 
93
 
 
94
static void
 
95
putitem( )
 
96
    {
 
97
    putchar( item );
 
98
    bitsperitem = 0;
 
99
    item = 64;
 
100
    bitshift = 0;
 
101
    }