w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

brushtopbm.c
Go to the documentation of this file.
1 /* brushtopbm.c - read a doodle brush file and write a portable bitmap
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 getinit ARGS(( FILE* file, int* colsP, int* rowsP ));
16 static bit getbit ARGS(( FILE* file ));
17 
18 int
20  int argc;
21  char* argv[];
22  {
23  FILE* ifp;
24  bit* bitrow;
25  register bit* bP;
26  int rows, cols, padright, row, col;
27 
28 
29  pbm_init( &argc, argv );
30 
31  if ( argc > 2 )
32  pm_usage( "[brushfile]" );
33 
34  if ( argc == 2 )
35  ifp = pm_openr( argv[1] );
36  else
37  ifp = stdin;
38 
39  getinit( ifp, &cols, &rows );
40 
42  bitrow = pbm_allocrow( cols );
43 
44  /* Compute padding to round cols up to the next multiple of 16. */
45  padright = ( ( cols + 15 ) / 16 ) * 16 - cols;
46 
47  for ( row = 0; row < rows; ++row )
48  {
49  /* Get data. */
50  for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
51  *bP = getbit( ifp );
52  /* Discard line padding. */
53  for ( col = 0; col < padright; ++col )
54  (void) getbit( ifp );
55  /* Write row. */
56  pbm_writepbmrow( stdout, bitrow, cols, 0 );
57  }
58 
59  pm_close( ifp );
60  pm_close( stdout );
61 
62  exit( 0 );
63  }
64 
65 
66 static int item, bitsperitem, bitshift;
67 
68 static void
69 getinit( file, colsP, rowsP )
70  FILE* file;
71  int* colsP;
72  int* rowsP;
73  {
74  int i;
75 
76  if ( getc( file ) != 1 )
77  pm_error( "bad magic number 1" );
78  if ( getc( file ) != 0 )
79  pm_error( "bad magic number 2" );
80  *colsP = getc( file ) << 8;
81  *colsP += getc( file );
82  *rowsP = getc( file ) << 8;
83  *rowsP += getc( file );
84  bitsperitem = 8;
85 
86  /* Junk rest of header. */
87  for ( i = 0; i < 10; ++i ) /* 10 is just a guess at the header size */
88  (void) getc( file );
89  }
90 
91 static bit
93  FILE* file;
94  {
95  bit b;
96 
97  if ( bitsperitem == 8 )
98  {
99  item = getc( file );
100  bitsperitem = 0;
101  bitshift = 7;
102  }
103  ++bitsperitem;
104  b = ( ( item >> bitshift) & 1 ) ? PBM_WHITE : PBM_BLACK;
105  --bitshift;
106  return b;
107  }
static int item
Definition: brushtopbm.c:66
static int bitsperitem
Definition: brushtopbm.c:66
static void getinit()
static int bitshift
Definition: brushtopbm.c:66
static bit getbit()
int main(int argc, argv)
Definition: brushtopbm.c:19
#define b
Definition: jpegint.h:372
int col
Definition: gsftopk.c:443
unsigned char * bP
Definition: hbf2gf.c:371
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
#define getc
Definition: line.c:39
void pm_usage(char *usage)
Definition: libpbm1.c:343
void pbm_init(int *argcP, argv)
Definition: libpbm1.c:332
FILE * pm_openr(char *name)
Definition: libpbm1.c:600
void pbm_writepbminit(FILE *file, int cols, int rows, int forceplain)
Definition: libpbm3.c:22
void pbm_writepbmrow(FILE *file, bit *bitrow, int cols, int forceplain)
Definition: libpbm3.c:95
#define pbm_allocrow(cols)
Definition: pbm.h:36
unsigned char bit
Definition: pbm.h:9
#define PBM_BLACK
Definition: pbm.h:11
#define PBM_WHITE
Definition: pbm.h:10
static int rows
Definition: pbmclean.c:15
static int cols
Definition: pbmmask.c:21
#define ARGS(alist)
Definition: pbmplus.h:235
#define pm_error
Definition: png22pnm.c:118
#define pm_close(file)
Definition: png22pnm.c:120
static int row
Definition: ps2pk.c:587
Definition: filedef.h:30
#define FILE
Definition: t1stdio.h:34
char * file
Definition: t4ht.c:931
FILE * ifp
Definition: t1asm.c:88
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269