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)  

pbmtoln03.c
Go to the documentation of this file.
1 /*
2 From tim@deakin.edu.au Fri May 7 00:18:57 1993
3 From: Tim Cook <tim@deakin.edu.au>
4 Date: Fri, 7 May 1993 15:18:34 -0500
5 X-Mailer: Mail User's Shell (7.2.4 2/2/92)
6 To: dyson@sunfish.Physics.UIowa.Edu
7 Subject: Re: DEC LN03+ printer (not postscript) under SunOS (on SS10) ?
8 Content-Length: 5893
9 
10 In a message dated 6 May, 9:32, dyson@sunfish.Physics.UIowa.Edu
11 (Richard L. Dyson) wrote:
12 > > Just in case anyone is interested, I have a pbmtoln03 utility I wrote
13 > > when I was mucking about with an LN03+. If you are interested in
14 > > printing your bitmaps at 300x300dpi, ask me for the source.
15 >
16 > I would be interested. We still only have LN03+ printers on our VMS
17 > machines here...
18 
19 Ok, here goes. Note that you will need the source from the pbmplus
20 utilities, because my pbmtoln03 utility uses the library routines that
21 are a part of pbmplus to read a PBM file (I linked it with libpbm.a).
22 I have not tested this utility on VMS, but it looks like it should
23 work.
24 */
25 
26 /* pbmtoln03.c - Converts a PBM bitmap to DEC LN03 SIXEL bitmap
27  *
28  * SYNOPSIS
29  * pbmtoln03 [pbm-file]
30  *
31  * OPTIONS
32  * -l nn Use "nn" as value for left margin (default 0).
33  * -r nn Use "nn" as value for right margin (default 2400).
34  * -t nn Use "nn" as value for top margin (default 0).
35  * -b nn Use "nn" as value for bottom margin (default 3400).
36  * -f nn Use "nn" as value for form length (default 3400).
37  *
38  * Tim Cook, 26 Feb 1992
39  * changed option parsing to PBM standards - Ingo Wilken, 13 Oct 1993
40  */
41 
42 #include <stdio.h>
43 #include "pbm.h"
44 
46 
47 #ifndef print
48 #define print(s) fputs (s, stdout)
49 #define fprint(f, s) fputs (s, f)
50 #endif
51 
52 /* prototypes */
53 void output_sixel_record ARGS((unsigned char *record, int width));
54 void convert ARGS((int width, int height, int format));
55 
56 
57 void output_sixel_record (record, width)
58  unsigned char *record ;
59  int width ;
60 {
61  int i, j, k ;
62  unsigned char last_char ;
63  int start_repeat = 0 ;
64  int repeated ;
65  char repeated_str[16] ;
66  char *p ;
67 
68  /* Do RLE */
69  last_char = record[0] ;
70  j = 0 ;
71 
72  /* This will make the following loop complete */
73  record[width] = '\0' ;
74 
75  for (i = 1 ; i <= width ; i++) {
76 
77  repeated = i - start_repeat ;
78 
79  if (record[i] != last_char || repeated >= 32766) {
80 
81  /* Repeat has ended */
82 
83  if (repeated > 3) {
84 
85  /* Do an encoding */
86  record[j++] = '!' ;
87  sprintf (repeated_str, "%d", i - start_repeat) ;
88  for (p = repeated_str ; *p ; p++)
89  record[j++] = *p ;
90  record[j++] = last_char ; }
91 
92  else {
93  for (k = 0 ; k < repeated ; k++)
94  record[j++] = last_char ; }
95 
96  start_repeat = i ;
97  last_char = record[i] ; }
98  }
99 
100  fwrite ((char *) record, j, 1, stdout) ;
101  putchar ('-') ; /* DECGNL (graphics new-line) */
102  putchar ('\n') ;
103  }
104 
105 
107  int width ;
108  int height ;
109  int format ;
110 {
111  register int i ;
112  unsigned char *sixel ; /* A row of sixels */
113  int sixel_row ;
114 
115  bit *row = pbm_allocrow (width) ;
116 
117  sixel = (unsigned char *) malloc (width + 2) ;
118 
119  sixel_row = 0 ;
120  while (height--) {
122  switch (sixel_row) {
123  case 0 :
124  for (i = 0 ; i < width ; i++)
125  sixel[i] = row[i] ;
126  break ;
127  case 1 :
128  for (i = 0 ; i < width ; i++)
129  sixel[i] += row[i] << 1 ;
130  break ;
131  case 2 :
132  for (i = 0 ; i < width ; i++)
133  sixel[i] += row[i] << 2 ;
134  break ;
135  case 3 :
136  for (i = 0 ; i < width ; i++)
137  sixel[i] += row[i] << 3 ;
138  break ;
139  case 4 :
140  for (i = 0 ; i < width ; i++)
141  sixel[i] += row[i] << 4 ;
142  break ;
143  case 5 :
144  for (i = 0 ; i < width ; i++)
145  sixel[i] += (row[i] << 5) + 077 ;
146  output_sixel_record (sixel, width) ;
147  break ; }
148  if (sixel_row == 5)
149  sixel_row = 0 ;
150  else
151  sixel_row++ ;
152  }
153 
154  if (sixel_row > 0) {
155  /* Incomplete sixel record needs to be output */
156  for (i = 0 ; i < width ; i++)
157  sixel[i] += 077 ;
158  output_sixel_record (sixel, width) ; }
159  }
160 
161 
162 
163 int
165  int argc ;
166  char **argv ;
167 {
168  int argc_copy = argc ;
169  char **argv_copy = argv ;
170  int argn;
171  char *usage = "[-left <nn>] [-right <nn>] [-top <nn>] [-bottom <nn>] [-formlength <nn>] [pbmfile]";
172 
173  /* Options */
174  /* These defaults are for a DEC LN03 with A4 paper (2400x3400 pixels) */
175  char *opt_left_margin = "0";
176  char *opt_top_margin = opt_left_margin;
177  char *opt_right_margin = "2400";
178  char *opt_bottom_margin = "3400";
179  char *opt_form_length = opt_bottom_margin;
180 
181  int width, height, format ;
182 
183  pbm_init (&argc_copy, argv_copy) ;
184 
185  argn = 1;
186  while( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) {
187  if( pm_keymatch(argv[argn], "-left", 2) ) {
188  if( ++argn >= argc )
189  pm_usage(usage);
190  opt_left_margin = argv[argn];
191  }
192  else
193  if( pm_keymatch(argv[argn], "-right", 2) ) {
194  if( ++argn >= argc )
195  pm_usage(usage);
196  opt_right_margin = argv[argn];
197  }
198  else
199  if( pm_keymatch(argv[argn], "-top", 2) ) {
200  if( ++argn >= argc )
201  pm_usage(usage);
202  opt_top_margin = argv[argn];
203  }
204  else
205  if( pm_keymatch(argv[argn], "-bottom", 2) ) {
206  if( ++argn >= argc )
207  pm_usage(usage);
208  opt_bottom_margin = argv[argn];
209  }
210  else
211  if( pm_keymatch(argv[argn], "-formlength", 2) ) {
212  if( ++argn >= argc )
213  pm_usage(usage);
214  opt_form_length = argv[argn];
215  }
216  else
217  pm_usage(usage);
218  ++argn;
219  }
220 
221  if( argn < argc ) {
222  input = pm_openr( argv[argn] );
223  argn++;
224  }
225  else
226  input = stdin;
227 
228  if( argn != argc )
229  pm_usage(usage);
230 
231 
232  /* Initialise pbm file */
234 
235  if (format != PBM_FORMAT && format != RPBM_FORMAT)
236  pm_error ("input not in PBM format") ;
237 
238 /*
239  * In explanation of the sequence below:
240  * <ESC>[!p DECSTR soft terminal reset
241  * <ESC>[11h PUM select unit of measurement
242  * <ESC>[7 I SSU select pixel as size unit
243  * <ESC>[?52l DECOPM origin is corner of printable area
244  * <ESC>[%s;%ss DECSLRM left and right margins
245  * <ESC>[%s;%sr DECSTBM top and bottom margins
246  * <ESC>[%st DECSLPP form length
247  * <ESC>P0;0;1q select sixel graphics mode
248  * "1;1 DECGRA aspect ratio (1:1)
249  */
250 
251  /* Initialise sixel file */
252  printf (
253 "\033[!p\033[11h\033[7 I\033[?52l\033[%s;%ss\033[%s;%sr\033[%st\033P0;0;1q\"1;1",
254  opt_left_margin, opt_right_margin, opt_top_margin, opt_bottom_margin,
255  opt_form_length);
256 
257  /* Convert data */
258  convert (width, height, format) ;
259 
260  /* Terminate sixel data */
261  print ("\033\\\n") ;
262 
263  /* If the program failed, it previously aborted with nonzero completion
264  code, via various function calls.
265  */
266  return 0;
267 }
268 
269 
#define width(a)
Definition: aptex-macros.h:198
#define height(a)
Definition: aptex-macros.h:200
END END END break
Definition: bibtex-3.c:1974
int printf()
static char usage[]
Definition: giftopnm.c:59
int last_char
Definition: hbf2gf.c:340
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
Code related to b fwrite(a, sizeof(char), b, stdout) @d C_printf(c
#define malloc
Definition: alloca.c:91
#define sprintf
Definition: snprintf.c:44
int k
Definition: otp-parser.c:70
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 RPBM_FORMAT
Definition: pbm.h:20
#define pbm_allocrow(cols)
Definition: pbm.h:36
unsigned char bit
Definition: pbm.h:9
#define PBM_FORMAT
Definition: pbm.h:19
static int format
Definition: pbmclean.c:15
#define ARGS(alist)
Definition: pbmplus.h:235
#define print(s)
Definition: pbmtoln03.c:48
void output_sixel_record()
void convert()
int main(argc, argv)
Definition: pbmtoln03.c:164
FILE * input
Definition: pbmtoln03.c:45
#define pm_error
Definition: png22pnm.c:118
#define pm_keymatch(stra, strb, _x)
Definition: png22pnm.c:121
static int row
Definition: ps2pk.c:587
Definition: execute.c:108
#define FILE
Definition: t1stdio.h:34
int j
Definition: t4ht.c:1589
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
#define argn