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)  

pbmto4425.c
Go to the documentation of this file.
1 #include "pbm.h"
2 
3 /*extern char *sys_errlist[];
4 char *malloc();*/
5 
6 /* prototypes */
7 static void init_map ARGS((void));
8 static void fill_map ARGS((FILE *pbmfp));
9 static void set_vmap ARGS((int x, int y));
10 static void print_map ARGS((void));
11 #define max(a,b) ((a) > (b) ? (a) : (b))
12 
13 static char bit_table[2][3] = {
14 {1, 4, 0x10},
15 {2, 8, 0x40}
16 };
17 
18 static int vmap_width;
19 static int vmap_height;
20 
21 static int xres;
22 static int yres;
23 
24 static char *vmap;
25 
26 
27 int
29 int argc;
30 char *argv[];
31 {
32  int argn;
33  char *pbmfile;
34  FILE *pbmfp;
35  char *usage="[pbmfile]";
36 
37  pbm_init( &argc, argv );
38  for(argn = 1;
39  argn < argc && argv[argn][0] == '-' && strlen(argv[argn]) > 1;
40  ++argn)
41  {
42  pm_usage(usage);
43  }
44 
45  if(argn >= argc)
46  {
47  pbmfile = "-";
48  }
49  else if(argc - argn != 1)
50  {
51  pm_usage(usage);
52  }
53  else
54  {
55  pbmfile = argv[argn];
56  }
57 
58  if(strcmp(pbmfile, "-") == 0)
59  {
60  pbmfp = stdin;
61  }
62  else
63  {
64  pbmfp = pm_openr( argv[argn] );
65  }
66 
67  vmap_width = 132;
68  vmap_height = 23;
69 
70  xres = vmap_width * 2;
71  yres = vmap_height * 3;
72 
73  vmap = malloc(vmap_width * vmap_height * sizeof(char));
74  if(vmap == NULL)
75  {
76  pm_error( "Cannot allocate memory" );
77  }
78 
79  init_map();
80  fill_map(pbmfp);
81  print_map();
82  /* If the program failed, it previously aborted with nonzero completion
83  code, via various function calls.
84  */
85  return 0;
86 }
87 
88 
89 
90 static void
92 {
93  int x, y;
94 
95 
96  for(x = 0; x < vmap_width; ++x)
97  {
98  for(y = 0; y < vmap_height; ++y)
99  {
100  vmap[y*(vmap_width) + x] = 0x20;
101  }
102  }
103 }
104 
105 
106 static void
107 fill_map(pbmfp)
108 FILE *pbmfp;
109 {
110  bit **pbm_image;
111  int cols;
112  int rows;
113  int x;
114  int y;
115 
116  pbm_image = pbm_readpbm(pbmfp, &cols, &rows);
117  for(y = 0; y < rows && y < yres; ++y)
118  {
119  for(x = 0; x < cols && x < xres; ++x)
120  {
121  if(pbm_image[y][x] == PBM_WHITE)
122  {
123  set_vmap(x, y);
124  }
125  }
126  }
127 }
128 
129 
130 static void
132  int x, y;
133 {
134  int ix, iy;
135 
136  ix = x/2;
137  iy = y/3;
138 
139  vmap[iy*(vmap_width) + ix] |= bit_table[x % 2][y % 3];
140 }
141 
142 
143 static void
145 {
146  int x, y;
147  int last_byte;
148 
149 #ifdef BUFFERED
150  char *iobuf;
151  iobuf = (char *)malloc(BUFSIZ);
152  if(iobuf == NULL)
153  {
154  pm_message( "Can't allocate space for I/O buffer. Using unbuffered I/O...\n" );
155  setbuf(stdout, NULL);
156  }
157  else
158  {
159  setbuf(stdout, iobuf);
160  }
161 #endif
162 
163  fputs("\033[H\033[J", stdout); /* clear screen */
164  fputs("\033[?3h", stdout); /* 132 column mode */
165  fputs("\033)}\016", stdout); /* mosaic mode */
166 
167  for(y = 0; y < vmap_height; ++y)
168  {
169  for(last_byte = vmap_width - 1;
170  last_byte >= 0
171  && vmap[y * vmap_width + last_byte] == 0x20;
172  --last_byte)
173  ;
174 
175  for(x = 0; x <= last_byte; ++x)
176  {
177  fputc(vmap[y*(vmap_width) + x], stdout);
178  }
179  fputc('\n', stdout);
180  }
181 
182  fputs("\033(B\017", stdout);
183 }
int strcmp()
Definition: coll.cpp:143
void setbuf()
static char usage[]
Definition: giftopnm.c:59
#define NULL
Definition: ftobjs.h:61
kerning y
Definition: ttdriver.c:212
#define fputs
Definition: mendex.h:67
#define malloc
Definition: alloca.c:91
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
bit ** pbm_readpbm(FILE *file, int *colsP, int *rowsP)
Definition: libpbm2.c:161
unsigned char bit
Definition: pbm.h:9
#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
static void print_map()
Definition: pbmto4425.c:144
static void set_vmap()
static void init_map()
Definition: pbmto4425.c:91
static int xres
Definition: pbmto4425.c:21
static void fill_map()
static char * vmap
Definition: pbmto4425.c:24
static int vmap_width
Definition: pbmto4425.c:18
static int yres
Definition: pbmto4425.c:22
static char bit_table[2][3]
Definition: pbmto4425.c:13
static int vmap_height
Definition: pbmto4425.c:19
int main(int argc, argv)
Definition: pbmto4425.c:28
#define pm_error
Definition: png22pnm.c:118
#define pm_message
Definition: png22pnm.c:116
#define FILE
Definition: t1stdio.h:34
*job_name strlen((char *) job_name) - 4)
#define BUFSIZ
Definition: ps.c:61
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
#define argn