Debian Codegraph @

converter/pbm/pbmtoplot.c

raw
1 /* pbmtoplot.c - read a portable bitmap and produce a UNIX-format plot file.
2 **
3 ** Copyright (C) 1990 by Arthur David Olson.
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 <stdio.h>
14 #include "pbm.h"
15
16 static void
17 puttwo(int const i)
18 {
19 (void) putchar(i);
20 (void) putchar(i >> 8);
21 }
22
23
24
25 int
26 main(int argc, char * argv[]) {
27
28 FILE* ifp;
29 bit** bits;
30 int row, col, scol;
31 int rows, cols;
32
33 pbm_init( &argc, argv );
34
35 if ( argc > 2 )
36 pm_usage( "[pbmfile]" );
37
38 ifp = (argc == 2) ? pm_openr( argv[1] ) : stdin;
39
40 bits = pbm_readpbm( ifp, &cols, &rows );
41
42 pm_close( ifp );
43
44 (void) putchar( 's' );
45 puttwo( 0 );
46 puttwo( 0 );
47 puttwo( rows - 1 );
48 puttwo( cols - 1 );
49 for ( row = 0; row < rows; ++row )
50 {
51 for ( col = 0; col < cols; ++col )
52 {
53 if ( bits[row][col] == PBM_WHITE )
54 continue;
55 scol = col;
56 while ( ++col < cols && bits[row][col] == PBM_BLACK )
57 ; /* nothing */
58 --col;
59 if ( col == scol )
60 (void) putchar( 'p' );
61 else
62 {
63 (void) putchar( 'l' );
64 puttwo( scol );
65 puttwo( rows - 1 - row );
66 }
67 puttwo( col );
68 puttwo( rows - 1 - row );
69 }
70 }
71
72 exit( 0 );
73 }
74
75
76