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)  

pbmto10x.c
Go to the documentation of this file.
1 /* pbmto10x.c - read a portable bitmap and produce a Gemini 10X printer file
2 **
3 ** Copyright (C) 1990, 1994 by Ken Yap
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 ** Modified to shorten stripes and eliminate blank stripes. Dec 1994.
13 */
14 
15 #include "pbm.h"
16 
17 #define LOW_RES_ROWS 8 /* printed per pass */
18 #define HIGH_RES_ROWS 16 /* printed per pass */
19 
20 static void res_60x72 ARGS(( void ));
21 static void res_120x144 ARGS(( void ));
22 
23 static int highres = 0;
24 static FILE *ifp;
25 static int rows, cols, format;
26 
27 int
29  int argc;
30  char *argv[];
31 {
32  pbm_init( &argc, argv );
33  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
34  {
35  highres = 1;
36  --argc;
37  ++argv;
38  }
39  if (argc > 2)
40  pm_usage("[pbmfile]");
41  if (argc == 2)
42  ifp = pm_openr(argv[1]);
43  else
44  ifp = stdin;
45 
47  if (highres)
48  res_120x144();
49  else
50  res_60x72();
51 
52  pm_close(ifp);
53  exit(0);
54 }
55 
56 static void
57 outstripe(stripe, sP, reschar)
58  register char *stripe, *sP;
59  register int reschar;
60 {
61  register int ncols;
62 
63  /* scan backwards, removing empty columns */
64  while (sP != stripe)
65  if (*--sP != 0)
66  {
67  ++sP;
68  break;
69  }
70  ncols = sP - stripe;
71  if (ncols > 0)
72  {
73  printf("\033%c%c%c", reschar, ncols % 256, ncols / 256);
74  fwrite(stripe, sizeof(char), ncols, stdout);
75  }
76  putchar('\n'); /* flush buffer */
77 }
78 
79 static void
81 {
82  register int i, item, npins, row, col;
83  bit *bitrows[LOW_RES_ROWS], *bP[LOW_RES_ROWS];
84  char *stripe, *sP;
85 
86  stripe = malloc(cols);
87  for (i = 0; i < LOW_RES_ROWS; ++i)
88  bitrows[i] = pbm_allocrow(cols);
89  printf("\033A\010"); /* '\n' = 8/72 */
90  for (row = 0, sP = stripe; row < rows; row += LOW_RES_ROWS, sP = stripe)
91  {
92  if (row + LOW_RES_ROWS <= rows)
93  npins = LOW_RES_ROWS;
94  else
95  npins = rows - row;
96  for (i = 0; i < npins; ++i)
97  pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
98  for (col = 0; col < cols; ++col)
99  {
100  item = 0;
101  for (i = 0; i < npins; ++i)
102  if (*(bP[i]++) == PBM_BLACK)
103  item |= 1 << (7 - i);
104  *sP++ = item;
105  }
106  outstripe(stripe, sP, 'K');
107  }
108  printf("\033@");
109  free(stripe);
110 }
111 
112 static void
114 {
115  register int i, pin, item, npins, row, col;
116  bit *bitrows[HIGH_RES_ROWS], *bP[HIGH_RES_ROWS];
117  char *stripe, *sP;
118 
119  stripe = malloc(cols);
120  for (i = 0; i < HIGH_RES_ROWS; ++i)
121  bitrows[i] = pbm_allocrow(cols);
122  printf("\0333\001"); /* \n = 1/144" */
123  for (row = 0, sP = stripe; row < rows; row += HIGH_RES_ROWS, sP = stripe)
124  {
125  if (row + HIGH_RES_ROWS <= rows)
126  npins = HIGH_RES_ROWS;
127  else
128  npins = rows - row;
129  for (i = 0; i < npins; ++i)
130  pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
131  for (col = 0; col < cols; ++col)
132  {
133  item = 0;
134  /* even rows */
135  for (pin = i = 0; i < npins; i += 2, ++pin)
136  if (*(bP[i]++) == PBM_BLACK)
137  item |= 1 << (7 - pin);
138  *sP++ = item;
139  }
140  outstripe(stripe, sP, 'L');
141  sP = stripe;
142  for (col = 0; col < cols; ++col)
143  {
144  item = 0;
145  /* odd rows */
146  for (i = 1, pin = 0; i < npins; i += 2, ++pin)
147  if (*(bP[i]++) == PBM_BLACK)
148  item |= 1 << (7 - pin);
149  *sP++ = item;
150  }
151  outstripe(stripe, sP, 'L');
152  printf("\033J\016"); /* 14/144 down, \n did 1/144 */
153  }
154  printf("\033@");
155  free(stripe);
156 }
static int item
Definition: brushtopbm.c:66
#define free(a)
Definition: decNumber.cpp:310
int printf()
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()
Code related to b fwrite(a, sizeof(char), b, stdout) @d C_printf(c
#define malloc
Definition: alloca.c:91
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
#define pbm_allocrow(cols)
Definition: pbm.h:36
unsigned char bit
Definition: pbm.h:9
#define PBM_BLACK
Definition: pbm.h:11
#define ARGS(alist)
Definition: pbmplus.h:235
static int rows
Definition: pbmto10x.c:25
#define HIGH_RES_ROWS
Definition: pbmto10x.c:18
static void outstripe(char *stripe, char *sP, int reschar)
Definition: pbmto10x.c:57
#define LOW_RES_ROWS
Definition: pbmto10x.c:17
static int format
Definition: pbmto10x.c:25
static void res_60x72()
Definition: pbmto10x.c:80
static int cols
Definition: pbmto10x.c:25
static FILE * ifp
Definition: pbmto10x.c:24
static void res_120x144()
Definition: pbmto10x.c:113
static int highres
Definition: pbmto10x.c:23
int main(int argc, argv)
Definition: pbmto10x.c:28
#define pm_close(file)
Definition: png22pnm.c:120
static int row
Definition: ps2pk.c:587
#define FILE
Definition: t1stdio.h:34
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269