1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: pbm.trm,v 1.26.2.1 2006/11/23 05:36:01 sfeam Exp $
6 /* GNUPLOT - pbm.trm */
9 * Copyright 1990 - 1993, 1998, 2004
11 * Permission to use, copy, and distribute this software and its
12 * documentation for any purpose with or without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and
14 * that both that copyright notice and this permission notice appear
15 * in supporting documentation.
17 * Permission to modify the software is granted, but not the right to
18 * distribute the complete modified source code. Modifications are to
19 * be distributed as patches to the released version. Permission to
20 * distribute binaries produced by compiling modified sources is granted,
22 * 1. distribute the corresponding source modifications from the
23 * released version in the form of a patch file along with the binaries,
24 * 2. add special version identification to distinguish your version
25 * in addition to the base release version number,
26 * 3. provide your name and address as the primary contact for the
27 * support of your modified version, and
28 * 4. retain our contact information in regard to use of the base
30 * Permission to distribute the released version of the source code along
31 * with corresponding source modifications in the form of a patch file is
32 * granted with same provisions 2 through 4 for binary distributions.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
47 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
51 /* The following pbmplus drivers use the generic bit mapped graphics
52 routines from bitmap.c to build up a bit map in memory. The driver
53 interchanges colomns and lines in order to access entire lines
54 easily and returns the lines to get bits in the right order :
55 (x,y) -> (y,XMAX-1-x). */
56 /* This interchange is done by calling b_makebitmap() with reversed
57 xmax and ymax, and then setting b_rastermode to TRUE. b_setpixel()
58 will then perform the interchange before each pixel is plotted */
59 /* See Jef Poskanzer's excellent PBMplus package for more details of
60 the Portable BitMap format and for programs to convert PBM files
61 to other bitmap formats. */
66 register_term(pbm_driver)
70 TERM_PUBLIC void PBM_options __PROTO((void));
71 TERM_PUBLIC void PBM_init __PROTO((void));
72 TERM_PUBLIC void PBM_reset __PROTO((void));
73 TERM_PUBLIC void PBM_setfont __PROTO((void));
74 TERM_PUBLIC void PBM_graphics __PROTO((void));
75 TERM_PUBLIC void PBM_monotext __PROTO((void));
76 TERM_PUBLIC void PBM_graytext __PROTO((void));
77 TERM_PUBLIC void PBM_colortext __PROTO((void));
78 TERM_PUBLIC void PBM_text __PROTO((void));
79 TERM_PUBLIC void PBM_linetype __PROTO((int linetype));
80 TERM_PUBLIC void PBM_point __PROTO((unsigned int x, unsigned int y, int point));
81 #endif /* TERM_PROTO */
83 /* make XMAX and YMAX a multiple of 8 */
84 #define PBM_XMAX (640)
85 #define PBM_YMAX (480)
86 #define PBM_VCHAR (FNT5X9_VCHAR)
87 #define PBM_HCHAR (FNT5X9_VCHAR)
88 #define PBM_VTIC FNT5X9_HBITS
89 #define PBM_HTIC FNT5X9_HBITS
93 static int pbm_font = 1; /* small font */
94 static int pbm_mode = 0; /* 0:monochrome 1:gray 2:color */
96 /* Only needed for dubious backwards compatibility with 'set size'
97 * in pre-4.2 versions that didn't support 'set term size'
99 static TBOOLEAN PBM_explicit_size = FALSE;
101 /* 7=black, 0=white */
102 static int pgm_gray[] = { 7, 1, 6, 5, 4, 3, 2, 1, 7 }; /* grays */
103 /* bit3=!intensify, bit2=!red, bit1=!green, bit0=!blue */
104 static int ppm_color[] ={ 15, 8, 3, 5, 6, 2, 4, 1, 11, 13, 14 }; /* colors */
107 PBM_SMALL, PBM_MEDIUM, PBM_LARGE,
108 PBM_MONOCHROME, PBM_GRAY, PBM_COLOR, PBM_SIZE,
112 static struct gen_table PBM_opts[] =
114 { "s$mall", PBM_SMALL },
115 { "me$dium", PBM_MEDIUM },
116 { "l$arge", PBM_LARGE },
117 { "mo$nochrome", PBM_MONOCHROME },
118 { "g$ray", PBM_GRAY },
119 { "c$olor", PBM_COLOR },
120 { "c$olour", PBM_COLOR },
121 { "size", PBM_SIZE },
128 int xpixels = PBM_XMAX;
129 int ypixels = PBM_YMAX;
134 term_options[0] = NUL;
136 while (!END_OF_COMMAND) {
137 switch(lookup_table(&PBM_opts[0],c_token)) {
164 if (END_OF_COMMAND) {
165 term->xmax = PBM_XMAX;
166 term->ymax = PBM_YMAX;
167 PBM_explicit_size = FALSE;
169 xpixels = real(const_express(&a));
170 if (equals(c_token, ",")) {
172 ypixels = real(const_express(&a));
174 PBM_explicit_size = TRUE;
177 term->xmax = xpixels;
179 term->ymax = ypixels;
183 /* reset to default, since term is already set */
186 int_error(c_token, "expecting: {small, medium, large} and {monochrome, gray, color}");
191 /* setup options string */
195 strcat(term_options, "small");
198 strcat(term_options, "medium");
201 strcat(term_options, "large");
207 strcat(term_options, " monochrome");
210 strcat(term_options, " gray");
213 strcat(term_options, " color");
217 if (PBM_explicit_size)
218 sprintf(term_options + strlen(term_options), " size %d,%d",
219 term->xmax, term->ymax);
226 PBM_setfont(); /* HBB 980226: call it here! */
245 term->v_char = FNT5X9_VCHAR;
246 term->h_char = FNT5X9_HCHAR;
247 term->v_tic = FNT5X9_HBITS;
248 term->h_tic = FNT5X9_HBITS;
252 term->v_char = FNT9X17_VCHAR;
253 term->h_char = FNT9X17_HCHAR;
254 term->v_tic = FNT9X17_HBITS;
255 term->h_tic = FNT9X17_HBITS;
258 b_charsize(FNT13X25);
259 term->v_char = FNT13X25_VCHAR;
260 term->h_char = FNT13X25_HCHAR;
261 term->v_tic = FNT13X25_HBITS;
262 term->h_tic = FNT13X25_HBITS;
272 unsigned int xpixels = term->xmax;
273 unsigned int ypixels = term->ymax;
275 /* 'set size' should not affect the size of the canvas in pixels,
276 * but versions prior to 4.2 did not have a separate 'set term size'
278 if (!PBM_explicit_size) {
292 /* HBB 980226: this is not the right place to do this: setfont() influences
293 * fields of the termtable entry, and therefore must be called by init()
296 /* rotate plot -90 degrees by reversing XMAX and YMAX and by
297 setting b_rastermode to TRUE */
298 b_makebitmap(ypixels, xpixels, numplanes);
302 b_setlinetype(0); /* solid lines */
309 register int x, j, row;
311 fputs("P4\n", gpoutfile);
312 fprintf(gpoutfile, "%u %u\n", b_ysize, b_xsize);
314 /* dump bitmap in raster mode */
315 for (x = b_xsize - 1; x >= 0; x--) {
316 row = (b_ysize / 8) - 1;
317 for (j = row; j >= 0; j--) {
318 (void) fputc((char) (*((*b_p)[j] + x)), gpoutfile);
328 register int x, j, row;
329 register int i, value;
330 int mask, plane1, plane2, plane3;
332 fprintf(gpoutfile, "\
339 /* dump bitmap in raster mode */
340 for (x = b_xsize - 1; x >= 0; x--) {
341 row = (b_ysize / 8) - 1;
342 for (j = row; j >= 0; j--) {
344 plane1 = (*((*b_p)[j] + x));
345 plane2 = (*((*b_p)[j + b_psize] + x));
346 plane3 = (*((*b_p)[j + b_psize + b_psize] + x));
347 for (i = 0; i < 8; i++) {
348 /* HBB: The values below are set to span the full range
349 * from 0 up to 255 in 7 steps: */
357 (void) fputc((char) (value), gpoutfile);
369 register int x, j, row;
371 int mask, plane1, plane2, plane3, plane4;
372 int red, green, blue;
374 fprintf(gpoutfile, "P6\n\
380 /* dump bitmap in raster mode */
381 for (x = b_xsize - 1; x >= 0; x--) {
382 row = (b_ysize / 8) - 1;
383 for (j = row; j >= 0; j--) {
385 plane1 = (*((*b_p)[j] + x));
386 plane2 = (*((*b_p)[j + b_psize] + x));
387 plane3 = (*((*b_p)[j + b_psize + b_psize] + x));
388 plane4 = (*((*b_p)[j + b_psize + b_psize + b_psize] + x));
389 for (i = 0; i < 8; i++) {
390 red = (plane3 & mask) ? 1 : 3;
391 green = (plane2 & mask) ? 1 : 3;
392 blue = (plane1 & mask) ? 1 : 3;
398 /* HBB: '85' is exactly 255/3, so this spans the full
399 * range of colors in three steps: */
400 (void) fputc((char) (red * 85), gpoutfile);
401 (void) fputc((char) (green * 85), gpoutfile);
402 (void) fputc((char) (blue * 85), gpoutfile);
429 PBM_linetype(int linetype)
436 b_setlinetype(linetype);
441 b_setvalue(pgm_gray[linetype + 2]);
446 b_setvalue(ppm_color[linetype + 2]);
452 PBM_point(unsigned int x, unsigned int y, int point)
455 line_and_point(x, y, point);
457 do_point(x, y, point);
460 #endif /* TERM_BODY */
464 TERM_TABLE_START(pbm_driver)
465 "pbm", "Portable bitmap [small medium large] [monochrome gray color]",
466 PBM_XMAX, PBM_YMAX, PBM_VCHAR,
467 PBM_HCHAR, PBM_VTIC, PBM_HTIC, PBM_options,
468 PBM_init, PBM_reset, PBM_text, null_scale,
469 PBM_graphics, b_move, b_vector, PBM_linetype,
470 b_put_text, b_text_angle, null_justify_text, PBM_point,
471 do_arrow, set_font_null,
473 TERM_CAN_MULTIPLOT | TERM_BINARY,
475 TERM_TABLE_END(pbm_driver)
478 #define LAST_TERM pbm_driver
480 #endif /* TERM_TABLE */
486 "?commands set terminal pbm",
492 " Several options may be set in the `pbm` terminal---the driver for PBMplus.",
495 " set terminal pbm {<fontsize>} {<mode>} {size <x>,<y>}",
497 " where <fontsize> is `small`, `medium`, or `large` and <mode> is `monochrome`,",
498 " `gray` or `color`. The default plot size is 640 pixels wide and 480 pixels",
501 " The output of the `pbm` driver depends upon <mode>: `monochrome` produces a",
502 " portable bitmap (one bit per pixel), `gray` a portable graymap (three bits",
503 " per pixel) and `color` a portable pixmap (color, four bits per pixel).",
505 " The output of this driver can be used with various image conversion and",
506 " manipulation utilities provided by NETPBM. Based on Jef Poskanzer's",
507 " PBMPLUS package, NETPBM provides programs to convert the above PBM formats",
508 " to GIF, TIFF, MacPaint, Macintosh PICT, PCX, X11 bitmap and many others.",
509 " Complete information is available at http://netpbm.sourceforge.net/.",
512 " set terminal pbm small monochrome # defaults",
513 " set terminal pbm color medium size 800,600",
514 " set output '| pnmrotate 45 | pnmtopng > tilted.png' # uses NETPBM"
516 #endif /* TERM_HELP */