[BACK]Return to pbm.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/pbm.trm, Revision 1.1.1.2

1.1       maekawa     1: /*
1.1.1.2 ! maekawa     2:  * $Id: pbm.trm,v 1.10 1998/12/15 20:21:52 lhecking Exp $
1.1       maekawa     3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - pbm.trm */
                      7:
                      8: /*[
                      9:  * Copyright 1990 - 1993, 1998
                     10:  *
                     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.
                     16:  *
                     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,
                     21:  * provided you
                     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
                     29:  *    software.
                     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.
                     33:  *
                     34:  * This software is provided "as is" without express or implied warranty
                     35:  * to the extent permitted by applicable law.
                     36: ]*/
                     37:
                     38: /*
                     39:  * This file is included by ../term.c.
                     40:  *
                     41:  * This terminal driver supports:
                     42:  *  pbm
                     43:  *
                     44:  * AUTHORS
                     45:  *  Russell Lang
                     46:  *
                     47:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
                     48:  *
                     49:  */
                     50:
                     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. */
                     62:
                     63: #include "driver.h"
                     64:
                     65: #ifdef TERM_REGISTER
                     66: register_term(pbm_driver)
                     67: #endif
                     68:
                     69: #ifdef TERM_PROTO
                     70: TERM_PUBLIC void PBMoptions __PROTO((void));
                     71: TERM_PUBLIC void PBMinit __PROTO((void));
                     72: TERM_PUBLIC void PBMreset __PROTO((void));
                     73: TERM_PUBLIC void PBMsetfont __PROTO((void));
                     74: TERM_PUBLIC void PBMgraphics __PROTO((void));
                     75: TERM_PUBLIC void PBMmonotext __PROTO((void));
                     76: TERM_PUBLIC void PBMgraytext __PROTO((void));
                     77: TERM_PUBLIC void PBMcolortext __PROTO((void));
                     78: TERM_PUBLIC void PBMtext __PROTO((void));
                     79: TERM_PUBLIC void PBMlinetype __PROTO((int linetype));
                     80: TERM_PUBLIC void PBMpoint __PROTO((unsigned int x, unsigned int y, int point));
                     81: #endif /* TERM_PROTO */
                     82:
                     83: #ifdef TERM_BODY
                     84:
                     85: /* make XMAX and YMAX a multiple of 8 */
                     86: #define PBM_XMAX (640)
                     87: #define PBM_YMAX (480)
                     88: #define PBM_VCHAR (FNT5X9_VCHAR)
                     89: #define PBM_HCHAR (FNT5X9_VCHAR)
                     90: #define PBM_VTIC FNT5X9_HBITS
                     91: #define PBM_HTIC FNT5X9_HBITS
                     92:
                     93: static int pbm_font = 1;       /* small font */
                     94: static int pbm_mode = 0;       /* 0:monochrome 1:gray 2:color */
                     95:
                     96: /* 7=black, 0=white */
                     97: static int pgm_gray[] = { 7, 1, 6, 5, 4, 3, 2, 1, 7 }; /* grays  */
                     98: /* bit3=!intensify, bit2=!red, bit1=!green, bit0=!blue */
                     99: static int ppm_color[] ={ 15, 8, 3, 5, 6, 2, 4, 1, 11, 13, 14 };  /* colors */
                    100:
                    101: TERM_PUBLIC void PBMoptions()
                    102: {
                    103:     pbm_font = 1;
                    104:     pbm_mode = 0;
                    105:
                    106:     term_options[0] = NUL;
                    107:
                    108:     while (!END_OF_COMMAND) {
                    109:        if (almost_equals(c_token, "s$mall"))
                    110:            pbm_font = 1;
                    111:        else if (almost_equals(c_token, "me$dium"))
                    112:            pbm_font = 2;
                    113:        else if (almost_equals(c_token, "l$arge"))
                    114:            pbm_font = 3;
                    115:        else if (almost_equals(c_token, "mo$nochrome"))
                    116:            pbm_mode = 0;
                    117:        else if (almost_equals(c_token, "g$ray"))
                    118:            pbm_mode = 1;
                    119:        else if (almost_equals(c_token, "c$olor")
                    120:                 || almost_equals(c_token, "c$olour"))
                    121:            pbm_mode = 2;
                    122:        else {
                    123:            /* reset to default, since term is already set */
                    124:            pbm_font = 1;
                    125:            pbm_mode = 0;
                    126:            int_error("expecting: {small, medium, large} and {monochrome, gray, color}", c_token);
                    127:        }
                    128:        c_token++;
                    129:     }
                    130:
                    131:     /* setup options string */
                    132:
                    133:     switch (pbm_font) {
                    134:     case 1:
                    135:        strcat(term_options, "small");
                    136:        break;
                    137:     case 2:
                    138:        strcat(term_options, "medium");
                    139:        break;
                    140:     case 3:
                    141:        strcat(term_options, "large");
                    142:        break;
                    143:     }
                    144:
                    145:     switch (pbm_mode) {
                    146:     case 0:
                    147:        strcat(term_options, " monochrome");
                    148:        break;
                    149:     case 1:
                    150:        strcat(term_options, " gray");
                    151:        break;
                    152:     case 2:
                    153:        strcat(term_options, " color");
                    154:        break;
                    155:     }
                    156: }
                    157:
                    158:
                    159: TERM_PUBLIC void PBMinit()
                    160: {
                    161:     PBMsetfont();              /* HBB 980226: call it here! */
                    162: }
                    163:
                    164:
                    165: TERM_PUBLIC void PBMreset()
                    166: {
                    167: #ifdef VMS
                    168:     fflush_binary();
                    169: #endif /* VMS */
                    170: }
                    171:
                    172:
                    173: TERM_PUBLIC void PBMsetfont()
                    174: {
                    175:     switch (pbm_font) {
                    176:     case 1:
                    177:        b_charsize(FNT5X9);
                    178:        term->v_char = FNT5X9_VCHAR;
                    179:        term->h_char = FNT5X9_HCHAR;
                    180:        term->v_tic = FNT5X9_HBITS;
                    181:        term->h_tic = FNT5X9_HBITS;
                    182:        break;
                    183:     case 2:
                    184:        b_charsize(FNT9X17);
                    185:        term->v_char = FNT9X17_VCHAR;
                    186:        term->h_char = FNT9X17_HCHAR;
                    187:        term->v_tic = FNT9X17_HBITS;
                    188:        term->h_tic = FNT9X17_HBITS;
                    189:        break;
                    190:     case 3:
                    191:        b_charsize(FNT13X25);
                    192:        term->v_char = FNT13X25_VCHAR;
                    193:        term->h_char = FNT13X25_HCHAR;
                    194:        term->v_tic = FNT13X25_HBITS;
                    195:        term->h_tic = FNT13X25_HBITS;
                    196:        break;
                    197:     }
                    198: }
                    199:
                    200:
                    201: TERM_PUBLIC void PBMgraphics()
                    202: {
                    203:     int numplanes = 1;
                    204:
                    205:     switch (pbm_mode) {
                    206:     case 1:
                    207:        numplanes = 3;
                    208:        break;
                    209:     case 2:
                    210:        numplanes = 4;
                    211:        break;
                    212:     }
                    213:
                    214:     /* HBB 980226: this is not the right place to do this: setfont() influences
                    215:      * fields of the termtable entry, and therefore must be called by init()
                    216:      * already. */
                    217:     /* PBMsetfont(); */
                    218:     /* rotate plot -90 degrees by reversing XMAX and YMAX and by
                    219:        setting b_rastermode to TRUE */
                    220:     b_makebitmap((unsigned int) (PBM_YMAX * ysize),
                    221:                 (unsigned int) (PBM_XMAX * xsize), numplanes);
                    222:     b_rastermode = TRUE;
                    223:
                    224:     if (pbm_mode != 0)
                    225:        b_setlinetype(0);       /* solid lines */
                    226: }
                    227:
                    228:
                    229: static void PBMmonotext()
                    230: {
                    231:     register int x, j, row;
                    232:
                    233:     fputs("P4\n", gpoutfile);
                    234:     fprintf(gpoutfile, "%u %u\n", b_ysize, b_xsize);
                    235:
                    236:     /* dump bitmap in raster mode */
                    237:     for (x = b_xsize - 1; x >= 0; x--) {
                    238:        row = (b_ysize / 8) - 1;
                    239:        for (j = row; j >= 0; j--) {
                    240:            (void) fputc((char) (*((*b_p)[j] + x)), gpoutfile);
                    241:        }
                    242:     }
                    243:
                    244:     b_freebitmap();
                    245: }
                    246:
                    247: static void PBMgraytext()
                    248: {
                    249:     register int x, j, row;
                    250:     register int i, value;
                    251:     int mask, plane1, plane2, plane3;
                    252:
                    253:     fprintf(gpoutfile, "\
                    254: P5\n\
                    255: %u %u\n\
                    256: %u\n",
                    257:            b_ysize, b_xsize,
                    258:            255);
                    259:
                    260:     /* dump bitmap in raster mode */
                    261:     for (x = b_xsize - 1; x >= 0; x--) {
                    262:        row = (b_ysize / 8) - 1;
                    263:        for (j = row; j >= 0; j--) {
                    264:            mask = 0x80;
                    265:            plane1 = (*((*b_p)[j] + x));
                    266:            plane2 = (*((*b_p)[j + b_psize] + x));
                    267:            plane3 = (*((*b_p)[j + b_psize + b_psize] + x));
                    268:            for (i = 0; i < 8; i++) {
                    269:                /* HBB: The values below are set to span the full range
                    270:                 * from 0 up to 255 in 7 steps: */
                    271:                value = 255;
                    272:                if (plane1 & mask)
                    273:                    value -= 36;
                    274:                if (plane2 & mask)
                    275:                    value -= 73;
                    276:                if (plane3 & mask)
                    277:                    value -= 146;
                    278:                (void) fputc((char) (value), gpoutfile);
                    279:                mask >>= 1;
                    280:            }
                    281:        }
                    282:     }
                    283:
                    284:     b_freebitmap();
                    285: }
                    286:
                    287: static void PBMcolortext()
                    288: {
                    289:     register int x, j, row;
                    290:     register int i;
                    291:     int mask, plane1, plane2, plane3, plane4;
                    292:     int red, green, blue;
                    293:
                    294:     fprintf(gpoutfile, "P6\n\
                    295: %u %u\n\
                    296: %u\n",
                    297:            b_ysize, b_xsize,
                    298:            255);
                    299:
                    300:     /* dump bitmap in raster mode */
                    301:     for (x = b_xsize - 1; x >= 0; x--) {
                    302:        row = (b_ysize / 8) - 1;
                    303:        for (j = row; j >= 0; j--) {
                    304:            mask = 0x80;
                    305:            plane1 = (*((*b_p)[j] + x));
                    306:            plane2 = (*((*b_p)[j + b_psize] + x));
                    307:            plane3 = (*((*b_p)[j + b_psize + b_psize] + x));
                    308:            plane4 = (*((*b_p)[j + b_psize + b_psize + b_psize] + x));
                    309:            for (i = 0; i < 8; i++) {
                    310:                red = (plane3 & mask) ? 1 : 3;
                    311:                green = (plane2 & mask) ? 1 : 3;
                    312:                blue = (plane1 & mask) ? 1 : 3;
                    313:                if (plane4 & mask) {
                    314:                    red--;
                    315:                    green--;
                    316:                    blue--;
                    317:                }
                    318:                /* HBB: '85' is exactly 255/3, so this spans the full
                    319:                 * range of colors in three steps: */
                    320:                (void) fputc((char) (red * 85), gpoutfile);
                    321:                (void) fputc((char) (green * 85), gpoutfile);
                    322:                (void) fputc((char) (blue * 85), gpoutfile);
                    323:                mask >>= 1;
                    324:            }
                    325:        }
                    326:     }
                    327:
                    328:     b_freebitmap();
                    329: }
                    330:
                    331: TERM_PUBLIC void PBMtext()
                    332: {
                    333:     switch (pbm_mode) {
                    334:     case 0:
                    335:        PBMmonotext();
                    336:        break;
                    337:     case 1:
                    338:        PBMgraytext();
                    339:        break;
                    340:     case 2:
                    341:        PBMcolortext();
                    342:        break;
                    343:     }
                    344: }
                    345:
                    346:
                    347: TERM_PUBLIC void PBMlinetype(linetype)
                    348: int linetype;
                    349: {
                    350:     switch (pbm_mode) {
                    351:     case 0:
                    352:        b_setlinetype(linetype);
                    353:        break;
                    354:     case 1:
                    355:        if (linetype >= 7)
                    356:            linetype %= 7;
                    357:        b_setvalue(pgm_gray[linetype + 2]);
                    358:        break;
                    359:     case 2:
                    360:        if (linetype >= 9)
                    361:            linetype %= 9;
                    362:        b_setvalue(ppm_color[linetype + 2]);
                    363:        break;
                    364:     }
                    365: }
                    366:
                    367: TERM_PUBLIC void PBMpoint(x, y, point)
                    368: unsigned int x, y;
                    369: int point;
                    370: {
                    371:     if (pbm_mode == 0)
                    372:        line_and_point(x, y, point);
                    373:     else
                    374:        do_point(x, y, point);
                    375: }
                    376:
                    377: #endif /* TERM_BODY */
                    378:
                    379: #ifdef TERM_TABLE
                    380:
                    381: #define PBMmove b_move
                    382: #define PBMvector b_vector
                    383: #define PBMtext_angle b_text_angle
                    384: #define PBMput_text b_put_text
                    385:
                    386: TERM_TABLE_START(pbm_driver)
                    387:     "pbm", "Portable bitmap [small medium large] [monochrome gray color]",
                    388:     PBM_XMAX, PBM_YMAX, PBM_VCHAR,
                    389:     PBM_HCHAR, PBM_VTIC, PBM_HTIC, PBMoptions,
                    390:     PBMinit, PBMreset, PBMtext, null_scale,
                    391:     PBMgraphics, PBMmove, PBMvector, PBMlinetype,
                    392:     PBMput_text, PBMtext_angle, null_justify_text, PBMpoint,
                    393:     do_arrow, set_font_null,
                    394:     0,                         /* pointsize */
                    395:     TERM_CAN_MULTIPLOT | TERM_BINARY
                    396: TERM_TABLE_END(pbm_driver)
                    397:
                    398: #undef LAST_TERM
                    399: #define LAST_TERM pbm_driver
                    400:
                    401: #endif /* TERM_TABLE */
                    402:
                    403:
                    404: #ifdef TERM_HELP
                    405: START_HELP(pbm)
                    406: "1 pbm",
                    407: "?commands set terminal pbm",
                    408: "?set terminal pbm",
                    409: "?set term pbm",
                    410: "?terminal pbm",
                    411: "?term pbm",
                    412: "?pbm",
                    413: " Several options may be set in the `pbm` terminal---the driver for PBMplus.",
                    414: "",
                    415: " Syntax:",
                    416: "       set terminal pbm {<fontsize>} {<mode>}",
                    417: "",
                    418: " where <fontsize> is `small`, `medium`, or `large` and <mode> is `monochrome`,",
                    419: " `gray` or `color`.  The default plot size is 640 pixels wide and 480 pixels",
                    420: " high; this may be changed by `set size`.",
                    421: "",
                    422: " The output of the `pbm` driver depends upon <mode>: `monochrome` produces a",
                    423: " portable bitmap (one bit per pixel), `gray` a portable graymap (three bits",
                    424: " per pixel) and `color` a portable pixmap (color, four bits per pixel).",
                    425: "",
                    426: " The output of this driver can be used with Jef Poskanzer's excellent PBMPLUS",
                    427: " package, which provides programs to convert the above PBMPLUS formats to GIF,",
                    428: " TIFF, MacPaint, Macintosh PICT, PCX, X11 bitmap and many others.  PBMPLUS may",
                    429: " be obtained from ftp.x.org.  The relevant files have names that begin with",
                    430: " \"netpbm-1mar1994.p1\"; they reside in /contrib/utilities.  The package can",
                    431: " probably also be obtained from one of the many sites that mirrors ftp.x.org.",
                    432: "",
                    433: " Examples:",
                    434: "       set terminal pbm small monochrome             # defaults",
                    435: "       set size 2,2; set terminal pbm color medium"
                    436: END_HELP(pbm)
                    437: #endif /* TERM_HELP */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>