home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / GPT34SRC / TERM / PBM.TRM < prev    next >
Text File  |  1993-05-11  |  8KB  |  305 lines

  1. /*
  2.  * $Id: pbm.trm 3.38.2.42 1993/01/07 17:23:59 woo Exp woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - pbm.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  pbm
  26.  *
  27.  * AUTHORS
  28.  *  Russell Lang
  29.  *
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  * 
  32.  */
  33.  
  34. /* The following pbmplus drivers use the generic bit mapped graphics
  35.    routines from bitmap.c to build up a bit map in memory.  The driver
  36.    interchanges colomns and lines in order to access entire lines
  37.    easily and returns the lines to get bits in the right order :
  38.    (x,y) -> (y,XMAX-1-x). */
  39. /* This interchange is done by calling b_makebitmap() with reversed 
  40.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  41.    will then perform the interchange before each pixel is plotted */
  42. /* See Jef Poskanzer's excellent PBMplus package for more details of
  43.    the Portable BitMap format and for programs to convert PBM files  
  44.    to other bitmap formats. */
  45.  
  46. #ifdef PBM
  47.  
  48. /* make XMAX and YMAX a multiple of 8 */
  49. #define PBM_XMAX (640)
  50. #define PBM_YMAX (480)
  51. #define PBM_VCHAR (FNT5X9_VCHAR)
  52. #define PBM_HCHAR (FNT5X9_VCHAR)
  53. #define PBM_VTIC FNT5X9_HBITS
  54. #define PBM_HTIC FNT5X9_HBITS
  55.  
  56. static int pbm_font=1;    /* small font */
  57. static int pbm_mode=0;  /* 0:monochrome 1:gray 2:color */
  58.  
  59. /* 7=black, 0=white */
  60. static int pgm_gray[]={7,1,6,5,4,3,2,1,7};  /* grays  */
  61. /* bit3=!intensify, bit2=!red, bit1=!green, bit0=!blue */
  62. static int ppm_color[]={15,8,3,5,6,4,2,1,11,13,14}; /* colors */
  63.  
  64. PBMoptions()
  65. {
  66.   pbm_font=1;
  67.   pbm_mode=0;
  68.  
  69.   term_options[0]='\0';
  70.  
  71.   while (!END_OF_COMMAND) {
  72.     if (almost_equals(c_token,"s$mall"))
  73.       pbm_font=1;
  74.     else if (almost_equals(c_token,"me$dium"))
  75.       pbm_font=2;
  76.     else if (almost_equals(c_token,"l$arge"))
  77.       pbm_font=3;
  78.     else if (almost_equals(c_token,"mo$nochrome"))
  79.       pbm_mode=0;
  80.     else if (almost_equals(c_token,"g$ray"))
  81.       pbm_mode=1;
  82.     else if (almost_equals(c_token,"c$olor"))
  83.       pbm_mode=2;
  84.     else {
  85.       pbm_font=1; /* reset to default, since term is already set */
  86.       pbm_mode=0;
  87.       int_error("expecting: {small, medium, large} and {monochrome, gray, color}",c_token);
  88.     }
  89.     c_token++;
  90.   }
  91.  
  92.   /* setup options string */
  93.  
  94.   switch(pbm_font) {
  95.     case 1: strcat(term_options,"small"); break;
  96.     case 2: strcat(term_options,"medium"); break;
  97.     case 3: strcat(term_options,"large"); break;
  98.   }
  99.  
  100.   switch(pbm_mode) {
  101.     case 0: strcat(term_options," monochrome"); break;
  102.     case 1: strcat(term_options," gray"); break;
  103.     case 2: strcat(term_options," color"); break;
  104.   }
  105. }
  106.  
  107.  
  108. PBMinit()
  109. {
  110. #ifdef REOPEN_BINARY
  111.    reopen_binary();
  112. #endif /* REOPEN_BINARY */
  113. }
  114.  
  115.  
  116. PBMreset()
  117. {
  118. #ifdef vms
  119.    fflush_binary();
  120. #endif /* vms */
  121. }
  122.  
  123.  
  124. PBMsetfont()
  125. {
  126.     switch(pbm_font) {
  127.         case 1:
  128.             b_charsize(FNT5X9);
  129.             term_tbl[term].v_char = FNT5X9_VCHAR;
  130.             term_tbl[term].h_char = FNT5X9_HCHAR;
  131.             term_tbl[term].v_tic = FNT5X9_HBITS;
  132.             term_tbl[term].h_tic = FNT5X9_HBITS;
  133.             break;
  134.         case 2:
  135.             b_charsize(FNT9X17);
  136.             term_tbl[term].v_char = FNT9X17_VCHAR;
  137.             term_tbl[term].h_char = FNT9X17_HCHAR;
  138.             term_tbl[term].v_tic = FNT9X17_HBITS;
  139.             term_tbl[term].h_tic = FNT9X17_HBITS;
  140.             break;
  141.         case 3:
  142.             b_charsize(FNT13X25);
  143.             term_tbl[term].v_char = FNT13X25_VCHAR;
  144.             term_tbl[term].h_char = FNT13X25_HCHAR;
  145.             term_tbl[term].v_tic = FNT13X25_HBITS;
  146.             term_tbl[term].h_tic = FNT13X25_HBITS;
  147.             break;
  148.     }
  149. }
  150.  
  151.  
  152. PBMgraphics()
  153. {
  154.   int numplanes;
  155.  
  156.   switch(pbm_mode) {
  157.     case 0: numplanes=1; break;
  158.     case 1: numplanes=3; break;
  159.     case 2: numplanes=4; break;
  160.   }
  161.  
  162.   PBMsetfont();
  163.   /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  164.   setting b_rastermode to TRUE */
  165.   b_makebitmap((unsigned int)(PBM_YMAX*ysize),
  166.                (unsigned int)(PBM_XMAX*xsize),numplanes);
  167.   b_rastermode = TRUE;
  168.  
  169.   if(pbm_mode!=0)
  170.     b_setlinetype(0); /* solid lines */
  171. }
  172.  
  173.  
  174. PBMmonotext()
  175. {
  176.   register int x,j,row;
  177.  
  178.    fprintf(outfile,"P4\n");
  179.    fprintf(outfile,"%u %u\n", b_ysize, b_xsize);
  180.  
  181.    /* dump bitmap in raster mode */
  182.    for (x = b_xsize-1; x >= 0; x--) {
  183.       row = (b_ysize/8)-1;
  184.       for (j = row; j >= 0; j--) {
  185.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  186.       }
  187.    }
  188.  
  189.    b_freebitmap();
  190. }
  191.  
  192. PBMgraytext()
  193. {
  194.   register int x,j,row;
  195.   register int i,value;
  196.   int mask, plane1, plane2, plane3;
  197.  
  198.    fprintf(outfile,"P5\n");
  199.    fprintf(outfile,"%u %u\n", b_ysize, b_xsize);
  200.    fprintf(outfile,"%u\n",7);
  201.  
  202.    /* dump bitmap in raster mode */
  203.    for (x = b_xsize-1; x >= 0; x--) {
  204.       row = (b_ysize/8)-1;
  205.       for (j = row; j >= 0; j--) {
  206.          mask = 0x80;
  207.          plane1=(*((*b_p)[j]+x));
  208.          plane2=(*((*b_p)[j+b_psize]+x));
  209.          plane3=(*((*b_p)[j+b_psize+b_psize]+x));
  210.          for (i=0; i<8; i++) {
  211.             value=7;
  212.             if (plane1 & mask)  value-=1;
  213.             if (plane2 & mask)  value-=2;
  214.             if (plane3 & mask)  value-=4;
  215.             (void) fputc( (char)(value), outfile );
  216.             mask>>=1;
  217.          }
  218.       }
  219.    }
  220.  
  221.    b_freebitmap();
  222. }
  223.  
  224. PBMcolortext()
  225. {
  226.   register int x,j,row;
  227.   register int i;
  228.   int mask, plane1, plane2, plane3, plane4;
  229.   int red, green, blue;
  230.  
  231.    fprintf(outfile,"P6\n");
  232.    fprintf(outfile,"%u %u\n", b_ysize, b_xsize);
  233.    fprintf(outfile,"%u\n",3);
  234.  
  235.    /* dump bitmap in raster mode */
  236.    for (x = b_xsize-1; x >= 0; x--) {
  237.       row = (b_ysize/8)-1;
  238.       for (j = row; j >= 0; j--) {
  239.          mask = 0x80;
  240.          plane1=(*((*b_p)[j]+x));
  241.          plane2=(*((*b_p)[j+b_psize]+x));
  242.          plane3=(*((*b_p)[j+b_psize+b_psize]+x));
  243.          plane4=(*((*b_p)[j+b_psize+b_psize+b_psize]+x));
  244.          for (i=0; i<8; i++) {
  245.             red = (plane3 & mask) ? 1 : 3;
  246.             green = (plane2 & mask) ? 1 : 3;
  247.             blue = (plane1 & mask) ? 1 : 3;
  248.             if (plane4 & mask) {
  249.                red--; green--; blue--;
  250.             }
  251.             (void) fputc( (char)(red), outfile );
  252.             (void) fputc( (char)(green), outfile );
  253.             (void) fputc( (char)(blue), outfile );
  254.             mask>>=1;
  255.          }
  256.       }
  257.    }
  258.  
  259.    b_freebitmap();
  260. }
  261.  
  262. PBMtext()
  263. {
  264.   switch(pbm_mode) {
  265.     case 0: PBMmonotext(); break;
  266.     case 1: PBMgraytext(); break;
  267.     case 2: PBMcolortext(); break;
  268.   }
  269. }
  270.  
  271.  
  272. PBMlinetype(linetype)
  273. int linetype;
  274. {
  275.   switch(pbm_mode) {
  276.     case 0:
  277.       b_setlinetype(linetype);
  278.     break;
  279.     case 1:
  280.       if (linetype>=7)
  281.         linetype %= 7;
  282.       b_setvalue(pgm_gray[linetype+2]);
  283.     break;
  284.     case 2:
  285.       if (linetype>=9)
  286.         linetype %= 9;
  287.       b_setvalue(ppm_color[linetype+2]);
  288.     break;
  289.   }
  290. }
  291.  
  292. PBMpoint(x,y,point)
  293. int x,y,point;
  294. {
  295.   if(pbm_mode==0) line_and_point(x,y,point);
  296.   else            do_point(x,y,point);
  297. }
  298.  
  299. #define PBMmove b_move
  300. #define PBMvector b_vector
  301. #define PBMtext_angle b_text_angle
  302. #define PBMput_text b_put_text
  303.  
  304. #endif /* PBM */
  305.