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)  

pbmclean.c
Go to the documentation of this file.
1 /* pbmclean.c - pixel cleaning. Remove pixel if less than n connected
2  * identical neighbours, n=1 default.
3  * AJCD 20/9/90
4  */
5 
6 #include <stdio.h>
7 #include "pbm.h"
8 
9 /* prototypes */
10 void nextrow ARGS((FILE *ifd, int row));
11 
12 #define PBM_INVERT(p) ((p) == PBM_WHITE ? PBM_BLACK : PBM_WHITE)
13 
14 /* input bitmap size and storage */
15 static int rows, columns, format ;
16 static bit *inrow[3] ;
17 
18 #define thisrow (1)
19 
20 /* compass directions from west clockwise */
21 int xd[] = { -1, -1, 0, 1, 1, 1, 0, -1 } ;
22 int yd[] = { 0, -1, -1, -1, 0, 1, 1, 1 } ;
23 
24 /* get a new row
25  */
26 
27 void nextrow(ifd, row)
28  FILE *ifd;
29  int row;
30 {
31  bit *shuffle = inrow[0] ;
32  inrow[0] = inrow[1];
33  inrow[1] = inrow[2];
34  inrow[2] = shuffle ;
35  if (row < rows) {
36  if (shuffle == NULL)
37  inrow[2] = shuffle = pbm_allocrow(columns);
38  pbm_readpbmrow(ifd, inrow[2], columns, format) ;
39  } else inrow[2] = NULL; /* discard storage */
40 
41 }
42 
43 int
45  int argc;
46  char *argv[];
47 {
48  FILE *ifd;
49  register bit *outrow;
50  register int row, col, i;
51  int connect ;
52 
53 
54  pbm_init( &argc, argv );
55 
56  if (argc > 3)
57  pm_usage("[-connect] [pbmfile]");
58 
59  if (argc > 1 && argv[1][0] == '-') {
60  connect = atoi(argv[1]+1);
61  argv++; argc--;
62  }
63  else connect = 1;
64 
65  if (argc == 2)
66  ifd = pm_openr(argv[1]);
67  else
68  ifd = stdin ;
69 
70  inrow[0] = inrow[1] = inrow[2] = NULL;
71  pbm_readpbminit(ifd, &columns, &rows, &format) ;
72 
74 
76 
77  nextrow(ifd, 0);
78  for (row = 0; row < rows; row++) {
79  nextrow(ifd, row+1);
80  for (col = 0; col < columns; col++) {
81  int point = inrow[thisrow][col];
82  int joined = 0 ;
83  for (i = 0; i < 8; i++) {
84  int x = col + xd[i] ;
85  int y = thisrow + yd[i] ;
86  if (x < 0 || x >= columns) {
87  if (point == PBM_WHITE) joined++;
88  }
89  else if (inrow[y] && inrow[y][x] == point) joined++ ;
90  }
91  outrow[col] = (joined < connect) ? PBM_INVERT(point) : point;
92  }
94  }
95  pm_close(ifd);
96  exit(0);
97 }
int col
Definition: gsftopk.c:443
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
kerning y
Definition: ttdriver.c:212
int atoi(const char *)
float x
Definition: cordic.py:15
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_readpbminit(FILE *file, int *colsP, int *rowsP, int *formatP)
Definition: libpbm2.c:62
void pbm_readpbmrow(FILE *file, bit *bitrow, int cols, int format)
Definition: libpbm2.c:82
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_WHITE
Definition: pbm.h:10
static int rows
Definition: pbmclean.c:15
static int format
Definition: pbmclean.c:15
static int columns
Definition: pbmclean.c:15
#define thisrow
Definition: pbmclean.c:18
void nextrow()
int xd[]
Definition: pbmclean.c:21
int yd[]
Definition: pbmclean.c:22
static bit * inrow[3]
Definition: pbmclean.c:16
#define PBM_INVERT(p)
Definition: pbmclean.c:12
int main(int argc, argv)
Definition: pbmclean.c:44
#define ARGS(alist)
Definition: pbmplus.h:235
static unsigned char * outrow
Definition: pbmtogem.c:107
#define pm_close(file)
Definition: png22pnm.c:120
static int row
Definition: ps2pk.c:587
Definition: mpost.c:238
#define FILE
Definition: t1stdio.h:34
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269