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)  

bmeps.c
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000-2005, Dirk Krause
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms,
6 with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 * Redistributions of source code must retain the above
10  copyright notice, this list of conditions and the
11  following disclaimer.
12 * Redistributions in binary form must reproduce the above
13  opyright notice, this list of conditions and the following
14  disclaimer in the documentation and/or other materials
15  provided with the distribution.
16 * Neither the name of the Dirk Krause nor the names of
17  its contributors may be used to endorse or promote
18  products derived from this software without specific
19  prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
35 DAMAGE.
36 */
37 
38 #include "bmepsco.h"
39 
40 #include <ctype.h>
41 #include <stdio.h>
42 #if HAVE_STDLIB_H
43 #include <stdlib.h>
44 #endif
45 #if HAVE_UNISTD_H
46 #include <unistd.h>
47 #endif
48 #if HAVE_PROCESS_H
49 #include <process.h>
50 #endif
51 
52 #include "pngeps.h"
53 #include "jpgeps.h"
54 #include "pnmeps.h"
55 #if LZW_PATENT_EXPIRED
56 #include "tifeps.h"
57 #endif
58 #include "bmepsoe.h"
59 #define BMEPS_C 1
60 #include "bmeps.h"
61 
62 #ifndef VERSNUMB
63 #define VERSNUMB "1.2.7"
64 #endif
65 static char the_version_number[] = { VERSNUMB };
66 
67 
68 #line 67 "bmeps.ctr"
69 
70 
71 /* Postscript level */
72 static int bmeps_pslevel = 2;
73 
74 /* colored (1) or grayscaled (0) output */
75 static int bmeps_color = 0;
76 
77 /* use ASCII85 encoding */
78 static int bmeps_enc_a85 = 1;
79 
80 /* use runlength encoding */
81 static int bmeps_enc_rl = 1;
82 
83 /* use flate encoding */
84 static int bmeps_enc_fl = 0;
85 
86 /* draft only */
87 static int bmeps_is_draft = 0;
88 
89 /* print DSC comments */
90 static int show_dsc_comments = 0;
91 
92 /* use showpage operator */
93 static int bmeps_shp = 0;
94 
95 /* use private dictionary */
96 static int bmeps_dic = 0;
97 
98 /* use vmreclaim */
99 static int bmeps_vmr = 0;
100 
101 /* use resolution information */
102 static int bmeps_usr = 0;
103 
104 /* verbose mode (error messages) */
105 static int bmeps_verb = 0;
106 
107 /* run from bmeps application (not from dvips) */
108 static int bmeps_app = 0;
109 
111 
112 
113 static int bmeps_alpha = 0; /* use alpha channel */
114 static int bmeps_trans = 0; /* alpha channel is transparency */
115 static int bmeps_altrig = 0; /* 0/1 trigger level alternated */
116 static int bmeps_mix = 0; /* mix foreground with background */
117 static int bmeps_specbg = 0; /* specify your own background color */
118 static int bmeps_bg_red = 255;
119 static int bmeps_bg_green = 255;
120 static int bmeps_bg_blue = 255;
121 
122 int bmeps_get_mix(void) { return bmeps_mix ; }
123 int bmeps_get_specbg(void) { return bmeps_specbg; }
124 int bmeps_get_bg_red(void) { return bmeps_bg_red; }
125 int bmeps_get_bg_green(void) { return bmeps_bg_green; }
126 int bmeps_get_bg_blue(void) { return bmeps_bg_blue; }
128 
129 static int use_trans = 0;
130 
131 
132 static int gsave_done = 0;
133 
134 void bmeps_add_trans(int x) {
135  int val;
136 
137  val = x;
138  if(use_trans) {
139  if(bmeps_trans) {
140  val = 255 - val;
141  }
142  /* if(bmeps_aldual) { */
143  if(bmeps_altrig) {
144  val = (val ? 255 : 0);
145  } else {
146  val = ((val == 255) ? 255 : 0);
147  }
148  /* } */
149 
151  }
152 
153 }
154 
155 
156 
157 static int is_configured = 0;
158 
159 #define correct(x) x = ((x > 255) ? (255) : ((x < 0) ? (0) : (x)))
160 
161 void bmeps_setup(int psl, int col, int a85, int rl, int fl,
162  int alpha, int trans, int altrig,
163  int mix, int specbg, int bg_red, int bg_green, int bg_blue, int dsc_show,
164  int shp, int dic, int vmr, int usr
165 )
166 {
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185  is_configured = 1;
188  bmeps_mix = bmeps_specbg = 0;
190  bmeps_pslevel = psl;
191  bmeps_mix = (mix ? 1 : 0);
192  bmeps_specbg = (specbg ? 1 : 0);
193  bmeps_bg_red = bg_red;
194  bmeps_bg_green = bg_green;
195  bmeps_bg_blue = bg_blue;
196  bmeps_shp = 0; bmeps_dic = 0; bmeps_vmr = 0;
197  bmeps_usr = usr;
198  show_dsc_comments = dsc_show;
202  if(bmeps_pslevel < 1) bmeps_pslevel = 1;
204  if(bmeps_pslevel > 1) {
205  bmeps_color = (col ? 1 : 0);
206  bmeps_enc_a85 = (a85 ? 1 : 0);
207  bmeps_enc_rl = (rl ? 1 : 0);
208  if(bmeps_pslevel > 2) {
209  bmeps_enc_fl = ( fl ? 1 : 0 );
210  if(alpha) {
211  bmeps_alpha = 1;
212  bmeps_trans = (trans ? 1 : 0); bmeps_altrig = (altrig ? 1 : 0);
213  }
214  }
215  bmeps_dic = (dic ? 1 : 0);
216  bmeps_vmr = (vmr ? 1 : 0);
217  }
218  bmeps_shp = (shp ? 1 : 0);
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 }
235 
236 static char *options = NULL;
237 
238 void bmeps_cfg(char *o)
239 {
240  options = o;
241 }
242 
244 {
245  bmeps_is_draft = dr;
246 }
247 
248 static int digit_for_char(char c)
249 {
250  int back = 0;
251  switch(c) {
252  case '0': back = 0; break;
253  case '1': back = 1; break;
254  case '2': back = 2; break;
255  case '3': back = 3; break;
256  case '4': back = 4; break;
257  case '5': back = 5; break;
258  case '6': back = 6; break;
259  case '7': back = 7; break;
260  case '8': back = 8; break;
261  case '9': back = 9; break;
262  }
263  return back;
264 }
265 
266 void bmeps_configure(void)
267 {
268  char *ptr;
269  if(!is_configured) {
270  is_configured = 1;
271  ptr = options;
272  if(!ptr) {
273  ptr = getenv("EPSOUTPUT");
274  }
275  if(ptr) {
276  int psl;
277  int col;
278  int a85;
279  int rl;
280  int fl;
281  int dr;
282  int f;
283  int alpha;
284  int trans;
285  int altrig;
286  int mix;
287  int specbg;
288  int bg_red;
289  int bg_green;
290  int bg_blue;
291  int digit;
292  int digstate;
293  int dsc_show;
294  int shp;
295  int vmr;
296  int dic;
297  int usr;
298  int vrb;
299 
300  digstate = 0; usr = 0;
301  dsc_show = show_dsc_comments;
302  bg_red = bmeps_bg_red;
303  bg_green = bmeps_bg_green;
304  bg_blue = bmeps_bg_blue;
305  specbg = bmeps_specbg;
306  mix = bmeps_mix;
307  psl = bmeps_pslevel;
308  col = bmeps_color;
309  a85 = bmeps_enc_a85;
310  rl = bmeps_enc_rl;
311  fl = bmeps_enc_fl;
312  dr = bmeps_is_draft;
313  alpha = bmeps_alpha;
314  trans = bmeps_trans;
315  altrig = bmeps_altrig;
316  shp = bmeps_shp;
317  vmr = bmeps_vmr;
318  dic = bmeps_dic;
319  usr = bmeps_usr;
320  vrb = bmeps_verb;
321  f = 1;
322  while(*ptr) {
323  switch(*ptr) {
324  case 'x' : dsc_show = 1; break;
325  case 'c' : col = 1; break;
326  case 'g' : col = 0; break;
327  case 'r' : if(f) { f = a85 = fl = rl = 0; } rl = 1; break;
328  case 'f' : if(f) { f = a85 = fl = rl = 0; } fl = 1; break;
329  case 'e' : usr = 1;
330  case 'd' : dr = 1; break;
331  case 'p' : dr = 0; break;
332  case 'a' : {
333  alpha = 1;
334  } break;
335  case 'b' : alpha = 0; break;
336  case 't' : trans = 1; break;
337  case 'o' : trans = 0; break;
338  case 'l' : altrig = 1; break;
339  case 'm' : mix = 1; break;
340  case 's' : specbg = 1; break;
341  case 'h' : shp = 1; break;
342  case 'v' : vmr = 1; break;
343  case 'V' : vrb = 1; break;
344  case 'u' : dic = 1; break;
345  case '0':
346  case '1':
347  case '2':
348  case '3':
349  case '4':
350  case '5':
351  case '6':
352  case '7':
353  case '8':
354  case '9': {
356  switch(digstate) {
357  case 0: {
358  if(alpha || mix) {
359  bg_green = bg_blue = 0;
360  digstate = 1;
361  bg_red = digit;
362  } else {
363  if((digit >= 1) && (digit <=3)) { psl = digit; }
364  if(digit == 8) { if(f) { f = a85 = fl = rl = 0; } a85 = 1; }
365  }
366  } break;
367  case 1: bg_red = 10 * bg_red + digit; break;
368  case 2: bg_green = 10 * bg_green + digit; break;
369  case 3: bg_blue = 10 * bg_blue + digit; break;
370  }
371  } break;
372  case ',' : {
373  if(digstate == 0) {
374  bg_red = bg_green = bg_blue = 0;
375  }
376  digstate += 1;
377  } break;
378  }
379  ptr++;
380  }
381  bmeps_setup(
382  psl,col,a85,rl,fl,
383  alpha,trans,altrig,mix,specbg,bg_red,bg_green,bg_blue,dsc_show,
384  shp, dic, vmr, usr
385  );
386  bmeps_set_verb(vrb);
388  }
389  }
390 }
391 
393 { return bmeps_pslevel; }
394 
396 { return bmeps_color; }
397 
399 { return bmeps_enc_a85; }
400 
402 { return bmeps_enc_rl; }
403 
405 { return bmeps_enc_fl; }
406 
408 { return bmeps_is_draft; }
409 
411 { return bmeps_alpha; }
412 
414 { return bmeps_trans; }
415 
416 
418 { return bmeps_altrig; }
419 
421 { return bmeps_shp; }
422 
424 { return bmeps_dic; }
425 
427 { return bmeps_vmr; }
428 
429 int bmeps_get_usr(void)
430 { return bmeps_usr; }
431 
432 void bmeps_bb(FILE *out, unsigned long w, unsigned long h)
433 {
434  fprintf(out, "%%%%BoundingBox: 0 0 %lu %lu\n", w, h);
435 }
436 
437 static int version_not_yet_printed = 1;
438 
439 void bmeps_header(FILE *out, char *name, unsigned long w, unsigned long h)
440 {
441  char *ptr;
442  use_trans = 0;
443  fprintf(out, "%%!PS-Adobe-%d.0 EPSF-%d.0\n",
445  );
446  bmeps_bb(out, w, h);
447  if(show_dsc_comments) {
448  fprintf(out, "%%%%Creator: bmeps\n");
449  fprintf(out, "%%%%Title: ");
450  if(name) {
451  ptr = name;
452  while(*ptr) {
453  switch(*ptr) {
454  case '\r':
455  case '\n':
456  break;
457  case '\\':
458  fputc('/', out);
459  break;
460  default:
461  fputc(*ptr, out);
462  break;
463  }
464  ptr++;
465  }
466  } else {
467  fprintf(out, "Bitmap image");
468  }
469  fprintf(out, "\n");
470  }
471  if(show_dsc_comments) {
472  fprintf(out, "%%%%Pages: 1\n");
473  fprintf(out, "%%%%EndComments\n");
474  }
475 }
476 
478 {
479  if(show_dsc_comments) {
480  fprintf(out, "%%%%Trailer\n");
481  }
482 }
483 
484 static int rlbuffer[129];
485 static int state = 0;
486 static Byte flate_in_buffer[16384];
487 static Byte flate_out_buffer[17408];
488 
489 #define NTSC(r,g,b) (((30 * (r)) + (59 * (g)) + (11 * (b))) / 100)
490 
491 void bmeps_add_rgb(int red, int green, int blue)
492 {
493  if(state > 0) {
494  int r, g, b;
495  r = red; g = green; b = blue;
496  if(r < 0) r = 256 + r;
497  if(g < 0) g = 256 + g;
498  if(b < 0) b = 256 + b;
499  if(bmeps_color) {
500  oe_byte_add(&bmepsoe, r);
501  oe_byte_add(&bmepsoe, g);
502  oe_byte_add(&bmepsoe, b);
503  } else {
504  oe_byte_add(&bmepsoe, NTSC(r,g,b) );
505  }
506  state = 2;
507  }
508 }
509 
511 {
512  if(state > 0) {
513  int g;
514  g = gray; if(g < 0) g = g + 256;
515  oe_byte_add(&bmepsoe, g);
516  if(bmeps_color) {
517  oe_byte_add(&bmepsoe, g);
518  oe_byte_add(&bmepsoe, g);
519  }
520  state = 2;
521  }
522 }
523 
524 void bmeps_set_usr(int x)
525 { bmeps_usr = x; }
526 
528 {
529  if(state == 0) {
530  if(bmeps_pslevel > 2) {
531  if(bmeps_alpha) {
532  use_trans = (x ? 1 : 0);
533  }
534  } else {
535  use_trans = 0;
536  }
537  }
538 }
539 
540 static int imageno = 1;
541 
542 void bmeps_begin_image(FILE *out, unsigned long w, unsigned long h)
543 {
544  if(out) {
545  if(!(use_trans && (bmeps_pslevel > 2))) {
546  if(show_dsc_comments) {
547  fprintf(out, "%%%%BeginProlog\n");
548  }
549  if(show_dsc_comments) {
550  fprintf(out, "%%%%EndProlog\n");
551  fprintf(out, "%%%%BeginSetup\n");
552  fprintf(out, "%%%%EndSetup\n");
553  }
554  } else {
555  if(show_dsc_comments) {
556  fprintf(out, "%%%%BeginSetup\n");
557  }
558  if(bmeps_color) {
559  fprintf(out, "/DeviceRGB setcolorspace\n");
560  } else {
561  fprintf(out, "/DeviceGray setcolorspace\n");
562  }
563  if(show_dsc_comments) {
564  fprintf(out, "%%%%EndSetup\n");
565  }
566  }
567  if(show_dsc_comments) {
568  fprintf(out, "%%%%Page: Image%d 1\n", imageno++);
569  }
572  fprintf(out,
573  "%%\n%% created by bmeps %s %s\n%%\n",
575  "(SCCS=1.78)"
576  );
577  }
578  if(bmeps_dic && (bmeps_pslevel > 1)) {
579  fprintf(out, "4 dict begin\n");
580  }
581  fprintf(
582  out, "/pstr\n %lu string\ndef\n",
583  (((bmeps_pslevel > 1) && (bmeps_color)) ? (3UL * w) : w)
584  );
585  if(bmeps_pslevel > 1) {
586  fprintf(out, "/inputf\n currentfile\n");
587  if(bmeps_enc_a85) {
588  fprintf(out, " /ASCII85Decode filter\n");
589  } else {
590  fprintf(out, " /ASCIIHexDecode filter\n");
591  }
592  if(bmeps_enc_fl) {
593  fprintf(out, " /FlateDecode filter\n");
594  }
595  if(bmeps_enc_rl) {
596  fprintf(out, " /RunLengthDecode filter\n");
597  }
598  fprintf(out, "def\n");
599  }
600  if(gsave_done) {
601  gsave_done = 0;
602  } else {
603  fprintf(out, "gsave\n");
604  }
605  fprintf(out, "0 %lu translate\n", h);
606  fprintf(out, "%lu %lu scale\n", w, h);
607  if(use_trans && (bmeps_pslevel > 2)) {
608  fprintf(out, "<<\n");
609  fprintf(out, " /ImageType 3\n");
610  fprintf(out, " /DataDict\n <<\n");
611  fprintf(out, " /ImageType 1\n");
612  fprintf(out, " /Width %lu\n", w);
613  fprintf(out, " /Height %lu\n", h);
614  fprintf(out, " /ImageMatrix [%lu 0 0 -%lu 0 0]\n", w, h);
615  fprintf(out, " /MultipleDataSources false\n");
616  fprintf(out, " /DataSource\n currentfile");
617  if(bmeps_enc_a85) {
618  fprintf(out, "\n /ASCII85Decode filter");
619  } else {
620  fprintf(out, "\n /ASCIIHexDecode filter");
621  }
622  if(bmeps_enc_fl) {
623  fprintf(out, "\n /FlateDecode filter");
624  }
625  if(bmeps_enc_rl) {
626  fprintf(out, "\n /RunLengthDecode filter");
627  }
628  fprintf(out, "\n");
629  fprintf(out, " /BitsPerComponent 8\n");
630  if(bmeps_color) {
631  fprintf(out, " /Decode [ 0 1 0 1 0 1 ]\n");
632  } else {
633  fprintf(out, " /Decode [ 0 1 ]\n");
634  }
635  fprintf(out, " >>\n");
636  fprintf(out, " /MaskDict\n <<\n");
637  fprintf(out, " /ImageType 1\n");
638  fprintf(out, " /Width %lu\n", w);
639  fprintf(out, " /Height %lu\n", h);
640  fprintf(out, " /ImageMatrix [%lu 0 0 -%lu 0 0]\n", w, h);
641  fprintf(out, " /BitsPerComponent 8\n");
642  fprintf(out, " /Decode [ 0 1 ]\n");
643  fprintf(out, " >>\n");
644  fprintf(out, " /InterleaveType 1\n");
645  fprintf(out, ">>\nimage\n");
646  } else {
647  fprintf(out, "%lu %lu 8 [%lu 0 0 -%lu 0 0]\n",
648  w, h, w, h
649  );
650  if(bmeps_pslevel > 1) {
651  if(bmeps_color) {
652  fprintf(out, "{ inputf pstr readstring pop }\n");
653  fprintf(out, "false\n3\ncolorimage\n");
654  } else {
655  fprintf(out, "{ inputf pstr readstring pop }\n");
656  fprintf(out, "image\n");
657  }
658  } else {
659  fprintf(out, "{ currentfile pstr readhexstring pop }\n");
660  fprintf(out, "image\n");
661  }
662  }
663  {
664  int mode;
665  mode = 0;
666  if(bmeps_enc_a85) {
667  mode |= OE_ASC85;
668  }
669  if(bmeps_enc_fl) {
670  mode |= OE_FLATE;
671  }
672  if(bmeps_enc_rl) {
673  mode |= OE_RL;
674  }
678  );
679  state = 1;
680  }
681  }
682 }
683 
685 {
686  if(out) {
687  if(state > 1) {
689  state = 0;
690  }
691  if(bmeps_pslevel > 1) {
692  if(bmeps_enc_a85) {
693  fprintf(out, "%s\n", "~>");
694  } else {
695  fprintf(out, "%s\n", ">");
696  }
697  }
698  fprintf(out, "grestore\n");
699  if(bmeps_pslevel > 1) {
700  fprintf(out, "currentdict /inputf undef\n");
701  fprintf(out, "currentdict /pstr undef\n");
702  }
703  if(bmeps_dic && (bmeps_pslevel > 1)) {
704  fprintf(out, "end\n");
705  }
706  if(bmeps_vmr && (bmeps_pslevel > 1)) {
707  fprintf(out, "1 vmreclaim\n");
708  }
709  if(bmeps_shp) {
710  fprintf(out, "showpage\n");
711  }
712  }
713 }
714 
715 void bmeps_draft(FILE *out, unsigned long w, unsigned long h)
716 {
717  if(show_dsc_comments) {
718  fprintf(out, "%%%%EndProlog\n");
719  fprintf(out, "%%%%Page: 1 1\n");
720  }
721  fprintf(out, "gsave\n");
722  fprintf(out, "0.75 setgray\n");
723  fprintf(out, "newpath\n");
724  fprintf(out, "0 0 moveto\n");
725  fprintf(out, "%lu 0 lineto\n", w);
726  fprintf(out, "%lu %lu lineto\n", w, h);
727  fprintf(out, "0 %lu lineto\n", h);
728  fprintf(out, "closepath\n");
729  fprintf(out, "fill\n");
730  fprintf(out, "1 setlinewidth\n");
731  fprintf(out, "0 setgray\n");
732  fprintf(out, "newpath\n");
733  fprintf(out, "1 1 moveto\n");
734  fprintf(out, "%lu 1 lineto\n", (w - 1UL));
735  fprintf(out, "%lu %lu lineto\n", (w - 1UL), (h - 1UL));
736  fprintf(out, "1 %lu lineto\n", (h - 1UL));
737  fprintf(out, "closepath\n");
738  fprintf(out, "stroke\n");
739  fprintf(out, "newpath\n");
740  fprintf(out, "1 1 moveto\n");
741  fprintf(out, "%lu %lu lineto\n", (w - 1UL), (h - 1UL));
742  fprintf(out, "stroke\n");
743  fprintf(out, "newpath\n");
744  fprintf(out, "1 %lu moveto\n", (h - 1UL));
745  fprintf(out, "%lu 1 lineto\n", (w - 1UL));
746  fprintf(out, "stroke\n");
747  fprintf(out, "grestore\n");
748  fprintf(out, "showpage\n");
749 }
750 
751 typedef int FCT(FILE *out, FILE *in, char *name);
752 typedef int FCTWH(FILE *in, unsigned long *w, unsigned long *h);
753 
754 typedef struct {
755  char *suffix;
759  char *xsuffix; /* for version printing */
760 }
762 
764 #if HAVE_LIBPNG
765  { "png", bmeps_png, bmeps_png_bb, bmeps_png_wh , "PNG" },
766 #endif
767 #if HAVE_JPEGLIB_H
768  { "jpg", bmeps_jpg, bmeps_jpg_bb, bmeps_jpg_wh , "JPEG" },
769  { "jpeg", bmeps_jpg, bmeps_jpg_bb, bmeps_jpg_wh , NULL},
770 #endif
771 #if HAVE_PNM_H
772  { "pnm", bmeps_pnm, bmeps_pnm_bb, bmeps_pnm_wh, "NetPBM" },
773  { "ppm", bmeps_pnm, bmeps_pnm_bb, bmeps_pnm_wh, NULL },
774  { "pgm", bmeps_pnm, bmeps_pnm_bb, bmeps_pnm_wh, NULL },
775  { "pbm", bmeps_pnm, bmeps_pnm_bb, bmeps_pnm_wh, NULL },
776 #endif
777 #if HAVE_TIFF_H
778  { "tiff", bmeps_tiff, bmeps_tiff_bb, bmeps_tiff_wh, "TIFF" },
780 #endif
781  { NULL, NULL, NULL, NULL },
782 };
783 
784 static char *get_suffix(char *name)
785 {
786  char *back = NULL;
787  char *ptr;
788  if(name) {
789  ptr = name;
790  while(*ptr) {
791  switch(*ptr) {
792  case '.': back = ptr; break;
793  case '/': back = NULL; break;
794  case '\\': back = NULL; break;
795  }
796  ptr++;
797  }
798  }
799  if(back) { back++; }
800  return back;
801 }
802 
803 #if HAVE_STRCASECMP
804 #define STRCASECMP(a,b) strcasecmp(a,b)
805 #else
806 #if HAVE_STRICMP
807 #define STRCASECMP(a,b) stricmp(a,b)
808 #else
809 #if HAVE__STRICMP
810 #define STRCASECMP(a,b) _stricmp(a,b)
811 #else
812 static int mystrcasecmp(char *p1, char *p2)
813 {
814  int back = 0;
815  int ende;
816  char *ptr1, *ptr2;
817  char c1, c2;
818  if(p1) {
819  if(p2) {
820  ptr1 = p1; ptr2 = p2; ende = 0;
821  while(!ende) {
822  if(*ptr1) {
823  if(*ptr2) {
824  c1 = *ptr1; c2 = *ptr2;
825  if(islower(c1)) { c1 = toupper(c1); }
826  if(islower(c2)) { c2 = toupper(c2); }
827  if(c1 > c2) {
828  back = ende = 1;
829  } else {
830  if(c1 < c2) {
831  back = -1; ende = 1;
832  }
833  }
834  } else {
835  back = 1; ende = 1;
836  }
837  } else {
838  if(*ptr2) {
839  back = -1;
840  }
841  ende = 1;
842  }
843  if(!ende) { ptr1++; ptr2++; }
844  }
845  } else {
846  back = 1;
847  }
848  } else {
849  if(p2) {
850  back = -1;
851  }
852  }
853  return back;
854 }
855 #define STRCASECMP(a,b) mystrcasecmp(a,b)
856 #endif
857 #endif
858 #endif
859 
861 {
862  FCT *back = NULL;
863  if(name) {
864  char *suffix;
866  if(suffix) {
867  HANDLERENTRY *he;
868  he = handlers;
869  while((he->suffix) && (back == NULL)) {
870  if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
871  back = he->fctrun;
872  }
873  he++;
874  }
875  }
876  }
877  return back;
878 }
879 
880 
882 {
883  FCT *back = NULL;
884  if(name) {
885  char *suffix;
887  if(suffix) {
888  HANDLERENTRY *he;
889  he = handlers;
890  while((he->suffix) && (back == NULL)) {
891  if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
892  back = he->fctbb;
893  }
894  he++;
895  }
896  }
897  }
898  return back;
899 }
900 
901 
903 {
904  FCTWH *back = NULL;
905  if(name) {
906  char *suffix;
908  if(suffix) {
909  HANDLERENTRY *he;
910  he = handlers;
911  while((he->suffix) && (back == NULL)) {
912  if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
913  back = he->wh;
914  }
915  he++;
916  }
917  }
918  }
919  return back;
920 }
921 
922 
923 static char *error_no_handler[] = {
924  "ERROR: Can not handle this file type!",
925  "This file type is either not supported by bmeps or bmeps was",
926  "not configured to use the libraries needed for that file type.",
927  NULL
928 };
929 
930 int bmeps_run(FILE *out, FILE *in, char *name)
931 {
932  int back = 0;
933  FCT *fct;
934  bmeps_configure();
935  fct = get_run_handler(name);
936  if(fct) {
937  back = (*fct)(out, in, name);
938  } else {
940  }
941  return back;
942 }
943 
945 {
946  int back = 0;
947  FCT *fct;
948  fct = get_run_handler(name);
949  if(fct) {
950  back = 1;
951  }
952  return back;
953 }
954 
955 int bmeps_run_bb(FILE *out, FILE *in, char *name)
956 {
957  int back = 0;
958  FCT *fct;
959  fct = get_bb_handler(name);
960  if(fct) {
961  back = (*fct)(out, in, name);
962  } else {
964  }
965  return back;
966 }
967 
968 int bmeps_wh(FILE *in, char *name, unsigned long *w, unsigned long *h)
969 {
970  int back = 0;
971  FCTWH *fct;
972  fct = get_wh_handler(name);
973  if(fct) {
974  back = (*fct)(in, w, h);
975  }
976  return back;
977 }
978 
979 
981 {
982  HANDLERENTRY *he;
983  char c, *p;
984  int issecond;
985  if(out) {
986  fprintf(out,
987  "%% libbmeps\tEPS output and bitmap conversion library %s %s\n",
989  "(SCCS=1.78)"
990  );
991  fprintf(out, "%%\t\t(");
992  he = handlers; issecond = 0;
993  while(he->suffix) {
994  if(he->xsuffix) {
995  if(issecond) {
996  fprintf(out, ", ");
997  } else {
998  issecond = 1;
999  }
1000  p = he->xsuffix;
1001  while(*p) {
1002  c = *p;
1003  fprintf(out, "%c", ((islower(c)) ? toupper(c) : c));
1004  p++;
1005  }
1006  }
1007  he++;
1008  }
1009  fprintf(out, ")\n");
1010 #if HAVE_LIBPNG
1011  fprintf(out, "%s", "% libpng\tThe PNG reference library\n");
1012 #endif
1013 #if HAVE_JPEGLIB_H
1014  fprintf(out, "%s", "% jpegsrc\tThe Independent JPEG Group's free JPEG software\n");
1015 #endif
1016 #if HAVE_PNM_H
1017  fprintf(out, "%s", "% netpbm\tThe image conversion toolkit\n");
1018 #endif
1019 #if HAVE_TIFF_H
1020  fprintf(out, "%s", "% libtiff\tThe TIFF library\n");
1021 #endif
1022 #if HAVE_ZLIB
1023  fprintf(out, "%s", "% zlib\t\tGeneral purpose compression library\n");
1024 #endif
1025  }
1026 }
1027 
1029 {
1030  if(bcp) {
1031  bcp->psl = bmeps_get_pslevel();
1032  bcp->col = bmeps_get_colored();
1033  bcp->a85 = bmeps_get_enc_a85();
1034  bcp->rl = bmeps_get_enc_rl();
1035  bcp->fl = bmeps_get_enc_fl();
1036  bcp->alpha = bmeps_get_alpha();
1037  bcp->trans = bmeps_get_trans();
1038  bcp->altrig = bmeps_get_altrig();
1039  bcp->mix = bmeps_get_mix();
1040  bcp->specbg = bmeps_get_specbg();
1041  bcp->bg_red = bmeps_get_bg_red();
1042  bcp->bg_green = bmeps_get_bg_green();
1043  bcp->bg_blue = bmeps_get_bg_blue();
1044  bcp->dsc_show = show_dsc_comments;
1045  }
1046 }
1047 
1049 {
1050  if(bcp) {
1051  bmeps_setup(
1052  bcp->psl,
1053  bcp->col,
1054  bcp->a85,
1055  bcp->rl,
1056  bcp->fl,
1057  bcp->alpha,
1058  bcp->trans,
1059  bcp->altrig,
1060  bcp->mix,
1061  bcp->specbg,
1062  bcp->bg_red,
1063  bcp->bg_green,
1064  bcp->bg_blue,
1065  bcp->dsc_show,
1066  bcp->shp,
1067  bcp->dic,
1068  bcp->vmr,
1069  bcp->usr
1070  );
1071  }
1072 }
1073 
1075 {
1076  if(d && s) {
1077  d->psl = s->psl;
1078  d->col = s->col;
1079  d->a85 = s->a85;
1080  d->rl = s->rl;
1081  d->fl = s->fl;
1082  d->alpha = s->alpha;
1083  d->trans = s->trans;
1084  d->altrig = s->altrig;
1085  d->mix = s->mix;
1086  d->specbg = s->specbg;
1087  d->bg_red = s->bg_red;
1088  d->bg_green = s->bg_green;
1089  d->bg_blue = s->bg_blue;
1090  d->dsc_show = s->dsc_show;
1091  d->shp = s->shp;
1092  d->dic = s->dic;
1093  d->vmr = s->vmr;
1094  d->usr = s->usr;
1095  }
1096 }
1097 
1099 char bmeps_default_tmpname[] = { "BMEPS.TMP" };
1100 static int configured_tmpname = 0;
1101 
1102 char *bmeps_tmpname(void)
1103 {
1104  char *back = NULL;
1106 #if HAVE_GETPID
1107  if(!configured_tmpname) {
1108  configured_tmpname = 1;
1109  sprintf(bmeps_getpid_tmpname, "BMEPS.%lu.TMP", ((unsigned long)getpid()));
1110  }
1112 #else
1113 #if HAVE__GETPID
1114  if(!configured_tmpname) {
1115  configured_tmpname = 1;
1116  sprintf(bmeps_getpid_tmpname, "BMEPS.%lu.TMP", ((unsigned long)_getpid()));
1117  }
1119 #endif
1120 #endif
1121  return back;
1122 }
1123 
1125 {
1126  if(filename) {
1127 #if HAVE_UNLINK
1128  unlink(filename);
1129 #else
1130 #if HAVE_REMOVE
1131  remove(filename);
1132 #else
1133 #if HAVE__UNLINK
1134  _unlink(filename);
1135 #else
1136 #if HAVE__REMOVE
1137  _remove(filename);
1138 #endif
1139 #endif
1140 #endif
1141 #endif
1142  }
1143 }
1144 
1145 
1146 void
1148 {
1149  gsave_done = 1;
1150 }
1151 
1152 
1153 
1154 void
1156 {
1157  bmeps_app = i;
1158 }
1159 
1160 int
1162 { return bmeps_app; }
1163 
1164 
1165 void
1167 {
1168  bmeps_verb = i;
1169 }
1170 
1171 
1172 int
1174 { return bmeps_verb; }
1175 
1176 
1177 
1178 static char ps_error_line_start[] = { "% " };
1179 
1180 void
1182 {
1183  char **ptr;
1184  ptr = t;
1185  while(*ptr) {
1187  fputs(*ptr, of);
1188  fputc('\n', of);
1189  ptr++;
1190  }
1191  if(bmeps_verb) {
1192  ptr = t;
1193  if(!bmeps_app) {
1194  fputc('\n', stderr);
1195  }
1196  while(*ptr) {
1197  fputs(*ptr, stderr);
1198  fputc('\n', stderr);
1199  ptr++;
1200  }
1201  fflush(stderr);
1202  }
1203 }
1204 
1205 
1206 #ifndef LINT
1207 static char sccs_id[] =
1208 {
1209  "@(#)bmeps.ctr 1.78 07/18/06\t(krause) - bitmap to EPS conversion"
1210 };
1211 #endif
1212 
#define name
#define mode
Definition: aptex-macros.h:510
#define blue
Definition: backend_eps.c:37
#define green
Definition: backend_eps.c:36
#define red
Definition: backend_eps.c:35
static char * error_no_handler[]
Definition: bmeps.c:923
int bmeps_get_altrig(void)
Definition: bmeps.c:417
int bmeps_get_dsc_comm(void)
Definition: bmeps.c:127
int bmeps_can_handle(char *name)
Definition: bmeps.c:944
int bmeps_wh(FILE *in, char *name, unsigned long *w, unsigned long *h)
Definition: bmeps.c:968
int bmeps_get_alpha(void)
Definition: bmeps.c:410
static char sccs_id[]
Definition: bmeps.c:1207
void bmeps_set_trans(int x)
Definition: bmeps.c:527
static int show_dsc_comments
Definition: bmeps.c:90
static int bmeps_enc_a85
Definition: bmeps.c:78
int bmeps_get_draft(void)
Definition: bmeps.c:407
void bmeps_cfg(char *o)
Definition: bmeps.c:238
int bmeps_get_enc_a85(void)
Definition: bmeps.c:398
int bmeps_get_pslevel(void)
Definition: bmeps.c:392
#define STRCASECMP(a, b)
Definition: bmeps.c:804
static int bmeps_altrig
Definition: bmeps.c:115
FCT * get_run_handler(char *name)
Definition: bmeps.c:860
void bmeps_draft(FILE *out, unsigned long w, unsigned long h)
Definition: bmeps.c:715
void bmeps_show_error_text(FILE *of, char **t)
Definition: bmeps.c:1181
static int bmeps_bg_red
Definition: bmeps.c:118
static int imageno
Definition: bmeps.c:540
static int bmeps_shp
Definition: bmeps.c:93
void bmeps_end_image(FILE *out)
Definition: bmeps.c:684
int bmeps_run_bb(FILE *out, FILE *in, char *name)
Definition: bmeps.c:955
static int bmeps_trans
Definition: bmeps.c:114
void bmeps_set_cfg(BmepsConfiguration *bcp)
Definition: bmeps.c:1048
int bmeps_get_bg_red(void)
Definition: bmeps.c:124
static int gsave_done
Definition: bmeps.c:132
static char the_version_number[]
Definition: bmeps.c:65
#define VERSNUMB
Definition: bmeps.c:63
int bmeps_get_app(void)
Definition: bmeps.c:1161
char bmeps_getpid_tmpname[32]
Definition: bmeps.c:1098
void bmeps_bb(FILE *out, unsigned long w, unsigned long h)
Definition: bmeps.c:432
int bmeps_get_specbg(void)
Definition: bmeps.c:123
static int bmeps_alpha
Definition: bmeps.c:113
static int bmeps_mix
Definition: bmeps.c:116
int bmeps_run(FILE *out, FILE *in, char *name)
Definition: bmeps.c:930
int bmeps_get_colored(void)
Definition: bmeps.c:395
static int bmeps_enc_fl
Definition: bmeps.c:84
FCTWH * get_wh_handler(char *name)
Definition: bmeps.c:902
void bmeps_configure(void)
Definition: bmeps.c:266
static int bmeps_bg_green
Definition: bmeps.c:119
void bmeps_set_verb(int i)
Definition: bmeps.c:1166
static int rlbuffer[129]
Definition: bmeps.c:484
void bmeps_set_usr(int x)
Definition: bmeps.c:524
int bmeps_get_enc_rl(void)
Definition: bmeps.c:401
HANDLERENTRY handlers[]
Definition: bmeps.c:763
int FCT(FILE *out, FILE *in, char *name)
Definition: bmeps.c:751
static int bmeps_enc_rl
Definition: bmeps.c:81
static int bmeps_vmr
Definition: bmeps.c:99
static int bmeps_specbg
Definition: bmeps.c:117
void bmeps_add_gray(int gray)
Definition: bmeps.c:510
static int bmeps_app
Definition: bmeps.c:108
int bmeps_get_vmreclaim(void)
Definition: bmeps.c:426
void bmeps_begin_image(FILE *out, unsigned long w, unsigned long h)
Definition: bmeps.c:542
static int bmeps_color
Definition: bmeps.c:75
int bmeps_get_bg_green(void)
Definition: bmeps.c:125
int bmeps_get_mix(void)
Definition: bmeps.c:122
int bmeps_get_bg_blue(void)
Definition: bmeps.c:126
void bmeps_footer(FILE *out)
Definition: bmeps.c:477
void bmeps_delete(char *filename)
Definition: bmeps.c:1124
void bmeps_version(FILE *out)
Definition: bmeps.c:980
void bmeps_add_rgb(int red, int green, int blue)
Definition: bmeps.c:491
static int bmeps_bg_blue
Definition: bmeps.c:120
void bmeps_set_app(int i)
Definition: bmeps.c:1155
void bmeps_setup(int psl, int col, int a85, int rl, int fl, int alpha, int trans, int altrig, int mix, int specbg, int bg_red, int bg_green, int bg_blue, int dsc_show, int shp, int dic, int vmr, int usr)
Definition: bmeps.c:161
static Output_Encoder bmepsoe
Definition: bmeps.c:110
static int digit_for_char(char c)
Definition: bmeps.c:248
int bmeps_get_dictionary(void)
Definition: bmeps.c:423
#define correct(x)
Definition: bmeps.c:159
int FCTWH(FILE *in, unsigned long *w, unsigned long *h)
Definition: bmeps.c:752
static int use_trans
Definition: bmeps.c:129
static Byte flate_out_buffer[17408]
Definition: bmeps.c:487
static int is_configured
Definition: bmeps.c:157
static int bmeps_pslevel
Definition: bmeps.c:72
static char * get_suffix(char *name)
Definition: bmeps.c:784
void bmeps_set_gsave_done(void)
Definition: bmeps.c:1147
int bmeps_get_verb(void)
Definition: bmeps.c:1173
int bmeps_get_enc_fl(void)
Definition: bmeps.c:404
static char ps_error_line_start[]
Definition: bmeps.c:1178
void bmeps_add_trans(int x)
Definition: bmeps.c:134
static char * options
Definition: bmeps.c:236
void bmeps_copy_cfg(BmepsConfiguration *d, BmepsConfiguration *s)
Definition: bmeps.c:1074
char * bmeps_tmpname(void)
Definition: bmeps.c:1102
void bmeps_get_cfg(BmepsConfiguration *bcp)
Definition: bmeps.c:1028
void bmeps_header(FILE *out, char *name, unsigned long w, unsigned long h)
Definition: bmeps.c:439
int bmeps_get_showpage(void)
Definition: bmeps.c:420
void bmeps_set_draft(int dr)
Definition: bmeps.c:243
int bmeps_get_trans(void)
Definition: bmeps.c:413
char bmeps_default_tmpname[]
Definition: bmeps.c:1099
static int bmeps_verb
Definition: bmeps.c:105
static int version_not_yet_printed
Definition: bmeps.c:437
static int bmeps_is_draft
Definition: bmeps.c:87
FCT * get_bb_handler(char *name)
Definition: bmeps.c:881
int bmeps_get_usr(void)
Definition: bmeps.c:429
static int bmeps_dic
Definition: bmeps.c:96
#define NTSC(r, g, b)
Definition: bmeps.c:489
static Byte flate_in_buffer[16384]
Definition: bmeps.c:486
static int configured_tmpname
Definition: bmeps.c:1100
static int bmeps_usr
Definition: bmeps.c:102
int bmeps_png_bb(FILE *out, FILE *in, char *name)
Definition: pngeps.c:704
#define MAXPSLEVEL
Definition: bmeps.h:137
int bmeps_png_wh(FILE *in, unsigned long *w, unsigned long *h)
Definition: pngeps.c:714
int bmeps_png(FILE *out, FILE *in, char *name)
Definition: pngeps.c:694
void oe_byte_flush(Output_Encoder *o)
Definition: bmepsoe.c:550
void oe_byte_add(Output_Encoder *o, int b)
Definition: bmepsoe.c:530
void oe_init(Output_Encoder *o, FILE *out, int mode, int rate, int *buf, Bytef *flib, size_t flis, Bytef *flob, size_t flos)
Definition: bmepsoe.c:67
#define OE_RL
Definition: bmepsoe.h:101
#define OE_ASC85
Definition: bmepsoe.h:99
#define OE_FLATE
Definition: bmepsoe.h:100
char * p2
Definition: bmpfont.h:62
char * p1
Definition: bmpfont.h:62
#define b
Definition: jpegint.h:372
int w
Definition: dviconv.c:26
int h
Definition: dviconv.c:9
#define fflush
Definition: xxstdio.h:24
char * digit
Definition: io.c:63
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
#define t
Definition: afcover.h:96
#define c(n)
Definition: gpos-common.c:150
#define d(n)
Definition: gpos-common.c:151
int col
Definition: gsftopk.c:443
FILE * out
Definition: hbf2gf.c:286
int bmeps_jpg(FILE *out, FILE *in, char *name)
Definition: jpgeps.c:344
int bmeps_jpg_bb(FILE *out, FILE *in, char *name)
Definition: jpgeps.c:332
int bmeps_jpg_wh(FILE *in, unsigned long *w, unsigned long *h)
Definition: jpgeps.c:323
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
unsigned char Byte
Definition: ftzconf.h:219
char * getenv()
#define unlink(file)
Definition: config.h:413
#define getpid
Definition: win32lib.h:76
#define fputs
Definition: mendex.h:67
#define fprintf
Definition: mendex.h:64
int remove()
#define sprintf
Definition: snprintf.c:44
float x
Definition: cordic.py:15
char * filename[256]
Definition: pbmtopk.c:46
unsigned int gray
Definition: pgm.h:10
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
const char * suffix
Definition: pkg_icu.cpp:27
@ mix
Definition: pngtopnm.c:65
static enum alpha_handling alpha
Definition: pngtopnm.c:70
int bmeps_pnm_wh(FILE *in, unsigned long *w, unsigned long *h)
Definition: pnmeps.c:92
int bmeps_pnm(FILE *out, FILE *in, char *name)
Definition: pnmeps.c:137
int bmeps_pnm_bb(FILE *out, FILE *in, char *name)
Definition: pnmeps.c:114
int dr
Definition: ppmqvga.c:68
int g
Definition: ppmqvga.c:68
int r
Definition: ppmqvga.c:68
type_C toupper(type_C)
#define islower(ch)
Definition: utype.h:79
static FILE * in
Definition: squeeze.c:36
FCT * fctrun
Definition: bmeps.c:756
FCT * fctbb
Definition: bmeps.c:757
char * suffix
Definition: bmeps.c:755
char * xsuffix
Definition: bmeps.c:759
FCTWH * wh
Definition: bmeps.c:758
Definition: dvips.h:235
Definition: strexpr.c:21
#define c2
Definition: t1io.c:53
#define c1
Definition: t1io.c:52
#define FILE
Definition: t1stdio.h:34
back
Definition: tex4ht.c:3533
val
Definition: tex4ht.c:3227
int bmeps_tiff(FILE *out, FILE *in, char *name)
Definition: tifeps.c:262
int bmeps_tiff_wh(FILE *in, unsigned long *w, unsigned long *h)
Definition: tifeps.c:273
int bmeps_tiff_bb(FILE *out, FILE *in, char *name)
Definition: tifeps.c:284
static zic_t trans[50]
Definition: zic.c:412