home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / hp500c.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  12.2 KB  |  510 lines

  1. /*
  2.  * $Id: hp500c.trm,v 1.7 1995/12/20 21:47:53 drd Exp $
  3.  *
  4.  */
  5. /* GNUPLOT - hp500c.trm */
  6. /*
  7.  * Copyright (C) 1993
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *  hpdj 500c
  25.  *
  26.  * AUTHORS
  27.  *  John Engels      -- \
  28.  *  Russell Lang     ----> HPLJII.trm
  29.  *  Maurice Castro   -- /
  30.  *  UdoHessenauer    ----> derived this version from the above one
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  * 
  34.  */
  35.  
  36. /* The following HP Deskjet500c  driver uses generic bit mapped graphics
  37.    routines from bitmap.c to build up a bit map in memory.  The driver
  38.    interchanges colomns and lines in order to access entire lines
  39.    easily and returns the lines to get bits in the right order :
  40.    (x,y) -> (y,XMAX-1-x). */
  41. /* This interchange is done by calling b_makebitmap() with reversed 
  42.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  43.    will then perform the interchange before each pixel is plotted */
  44. /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
  45.    of Jyrki Yli-Nokari */
  46.  
  47. /*
  48.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  49.  */
  50.  
  51. #ifndef GOT_DRIVER_H
  52. #include "driver.h"
  53. #endif
  54.  
  55. #ifdef TERM_REGISTER
  56. register_term(hp500c)
  57. #endif
  58.  
  59. #ifdef TERM_PROTO
  60. TERM_PUBLIC void HP500Coptions __P((void));
  61. TERM_PUBLIC void HP500Cinit __P((void));
  62. TERM_PUBLIC void HP500Creset __P((void));
  63. TERM_PUBLIC void HP500Clinetype __P((int linetype));
  64. TERM_PUBLIC void HP500Cgraphics __P((void));
  65. TERM_PUBLIC void HP500Ctext __P((void));
  66. #define HP500Ctext_angle b_text_angle
  67. #define HP500Cput_text b_put_text
  68. #define HP500Cmove b_move
  69. #define HP500Cvector b_vector
  70. /* default values for term_tbl */
  71. #define HP500C_75PPI_XMAX (1920/4)
  72. #define HP500C_75PPI_YMAX (1920/4)
  73. #define HP500C_75PPI_HCHAR (1920/4/6)
  74. #define HP500C_75PPI_VCHAR (1920/4/10)
  75. #define HP500C_75PPI_VTIC 5
  76. #define HP500C_75PPI_HTIC 5
  77.  
  78. #define GOT_HP500C_PROTO
  79. #endif
  80.  
  81. #ifndef TERM_PROTO_ONLY
  82. #ifdef TERM_BODY
  83.  
  84.  
  85. /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
  86.    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
  87.  
  88. #define HP500C_DPP (hpdj_dpp)   /* dots per pixel */
  89. #define HP500C_PPI (300/HP500C_DPP) /* pixel per inch */
  90. /* make XMAX and YMAX a multiple of 8 */
  91. #define HP500C_XMAX (8*(unsigned int)(xsize*1920/HP500C_DPP/8.0+0.9))
  92. #define HP500C_YMAX (8*(unsigned int)(ysize*1920/HP500C_DPP/8.0+0.9))
  93.  
  94. #define HP500C_VCHAR (HP500C_PPI/6) /* Courier font with 6 lines per inch */
  95. #define HP500C_HCHAR (HP500C_PPI/10) /* Courier font with 10 caracters
  96. per inch */
  97.  
  98.  
  99.  
  100. #define HP500C_PUSH_CURSOR fprintf(outfile,"\033&f0S") /* Save current
  101. cursor position */
  102. #define HP500C_POP_CURSOR fprintf(outfile,"\033&f1S") /* Restore
  103. cursor position */
  104. #define HP500C_COURIER fprintf(outfile,"\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D")
  105. /* be sure to use courier font with 6lpi and 10cpi */
  106.  
  107. int compress __P((unsigned char *op, unsigned char *oe, unsigned char *cp));
  108. unsigned char complement __P((int c));
  109. int compress_to_TIFF __P((unsigned char *op, unsigned char *oe, unsigned char *cp));
  110. int nocompress __P((unsigned char *op, unsigned char *oe, unsigned char *cp));
  111.  
  112. static int hpdj_dpp=4;
  113. static int HP_COMP_MODE = 0;
  114.  
  115. /* bm_pattern not appropriate for 300ppi graphics */
  116. #ifndef GOT_300_PATTERN
  117. #define GOT_300_PATTERN
  118. static unsigned int b_300ppi_pattern[] = {
  119.   0xffff, 0x1111,
  120.   0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff};
  121. #endif
  122.  
  123.  
  124. TERM_PUBLIC void HP500Coptions()
  125. {
  126.   char opt[6];
  127.   
  128. #define HPDJCERROR "expecting dots per inch size 75, 100, 150 or 300 and/or compression method"
  129.   while (!END_OF_COMMAND) {
  130.     if (token[c_token].length>4)
  131.       int_error(HPDJCERROR,c_token);
  132.     
  133.     /* almost_equals() won't accept numbers - use strcmp() instead */
  134.     capture(opt,c_token,c_token, 6);
  135.     if (!strcmp(opt,"75")) {
  136.       hpdj_dpp = 4;
  137.       HP_COMP_MODE = 0;
  138.     
  139. }
  140.     else if (!strcmp(opt,"100")) {
  141.       hpdj_dpp = 3;
  142.       HP_COMP_MODE = 0;
  143.     }
  144.     else if (!strcmp(opt,"150")) {
  145.       hpdj_dpp = 2;
  146.       HP_COMP_MODE = 0;
  147.     }
  148.     else if (!strcmp(opt,"300")) {
  149.       hpdj_dpp = 1;
  150.       HP_COMP_MODE = 0;
  151.     }
  152.     else if (!strcmp(opt,"rle")){
  153.       HP_COMP_MODE = 1;
  154.     }
  155.     else if (!strcmp(opt,"tiff")){
  156.       HP_COMP_MODE = 2;
  157.     }
  158.     c_token++;
  159.   }
  160.   
  161.   term->xmax = HP500C_XMAX;
  162.   term->ymax = HP500C_YMAX;
  163.   switch(hpdj_dpp) {
  164.   case 1:
  165.     strcpy(term_options,"300");
  166.     term->v_tic = 15;
  167.     term->h_tic = 15;
  168.     break;
  169.   case 2:
  170.     strcpy(term_options,"150");
  171.     term->v_tic = 8;
  172.     term->h_tic = 8;
  173.     break;
  174.   case 3:
  175.     strcpy(term_options,"100");
  176.     term->v_tic = 6;
  177.     term->h_tic = 6;
  178.     break;
  179.   case 4:
  180.     strcpy(term_options,"75");
  181.     term->v_tic = 5;
  182.     term->h_tic = 5;
  183.     break; 
  184.   }
  185.   switch(HP_COMP_MODE) {
  186.   case 0:
  187.     strcat(term_options," no comp");
  188.     break;
  189.   case 1:
  190.     strcat(term_options," RLE");
  191.     break;
  192.   case 2:
  193.     strcat(term_options," TIFF");
  194.     break;
  195.   case 3:     /* not implemented yet */
  196.     strcat(term_options," Delta Row");
  197.     break;
  198.   }
  199. }
  200.  
  201. TERM_PUBLIC void HP500Cinit()
  202. {
  203. #ifdef REOPEN_BINARY
  204.     reopen_binary();
  205. #endif /* REOPEN_BINARY */
  206. }
  207.  
  208. TERM_PUBLIC void HP500Creset()
  209. {
  210. #ifdef vms
  211.     fflush_binary();
  212. #endif
  213. }
  214.  
  215.  
  216.  
  217. /* HP DeskJet 500c routines */
  218.  
  219. TERM_PUBLIC void HP500Clinetype(linetype)
  220. int linetype;
  221. {
  222.     if (linetype < 0)
  223.         linetype = 7;
  224.     else if (linetype >=8){
  225.         linetype %=8;
  226.     }
  227.     switch (linetype){
  228.     case 0 :
  229.         linetype = 6;
  230.         break;
  231.     case 1 :
  232.         linetype = 5;
  233.         break;
  234.     case 2 :
  235.         linetype = 3;
  236.         break;
  237.     case 3 :
  238.         linetype = 2;
  239.         break;
  240.     case 4 :
  241.         linetype = 1;
  242.         break;
  243.     case 5 :
  244.         linetype = 4;
  245.         break;
  246.     case 6 :
  247.         linetype = 7;
  248.     }
  249.     b_setvalue(linetype);
  250.  
  251. }
  252.  
  253. /*
  254. void HP500Cpoint(x,y,value)
  255. int x;
  256. int y;
  257. int value;
  258. {
  259.      HP500Clinetype(value);
  260.      do_point(x,y,value);
  261. }
  262. */
  263.  
  264. TERM_PUBLIC void HP500Cgraphics()
  265. {
  266.     switch(hpdj_dpp) {
  267.     case 1:
  268.         b_charsize(FNT13X25);
  269.         term->v_char = FNT13X25_VCHAR;
  270.         term->h_char = FNT13X25_HCHAR;
  271.         break;
  272.     case 2:
  273.         b_charsize(FNT13X25);
  274.         term->v_char = FNT13X25_VCHAR;
  275.         term->h_char = FNT13X25_HCHAR;
  276.         break;
  277.     case 3:
  278.         b_charsize(FNT9X17);
  279.         term->v_char = FNT9X17_VCHAR;
  280.         term->h_char = FNT9X17_HCHAR;
  281.         break;
  282.     case 4:
  283.         b_charsize(FNT5X9);
  284.         term->v_char = FNT5X9_VCHAR;
  285.         term->h_char = FNT5X9_HCHAR;
  286.         break;
  287.     }
  288.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  289.     setting b_rastermode to TRUE */
  290.     b_makebitmap(HP500C_YMAX,HP500C_XMAX,3);
  291.     b_rastermode = TRUE;
  292. }
  293. /*
  294.  * Run-length encoding for the DeskJet. We have pairs of <count>
  295.  * <what>, where count goes from 0 (meaning one count) to 255
  296.  * this might double the size of the image.
  297.  */
  298.  
  299. int  compress(op, oe, cp)
  300. unsigned char *op, *oe, *cp;
  301. {
  302.     unsigned char *ce = cp;
  303.     while ( op < oe ) {
  304.         unsigned char prevchar;
  305.         unsigned char count;
  306.  
  307.         prevchar = *op;     /* remember char */
  308.         count = 1;          /* its read the first time */
  309.  
  310.         while ( ++op < oe && *op == prevchar && count < 255){  /* set op to the next char */
  311.             count++;                                             /* and count it  */
  312.         }
  313.         *ce++ = --count; /* were ready, so correct the count */
  314.         *ce++ = prevchar; /* and store <what> */
  315.     }
  316.     *ce = 0;          /* just to be safe   */
  317.     return ce - cp;    /* length of  cbufs */
  318. }
  319.  
  320. unsigned char complement(c)
  321. int c;
  322. {
  323.     return (unsigned char)(256 - c);
  324. }
  325.  
  326.  
  327. int compress_to_TIFF(op,oe,cp)
  328.      unsigned char *op;     /* original pointer */
  329.      unsigned char *oe;     /* end of orig string */
  330.      unsigned char *cp;     /* pointer for compressed data */
  331. {
  332.   unsigned char *countposition;
  333.   unsigned char *ce = cp;
  334.   while ( op < oe ) {
  335.     unsigned char prevchar;
  336.     unsigned char count;
  337.     
  338.     prevchar = *op;     /* gelesenes Zeichen aufbewaren */
  339.     count = 1;          /* bisher wurde es einmal gelesen */
  340.     
  341.     while ( ++op < oe && *op == prevchar && count < 128){  
  342.       count++;                                           
  343.     }
  344.     *ce = complement(count-1);
  345.     countposition = ce++;           /* remember count for building blocks of literal bytes */
  346.     *ce++ = prevchar;           
  347.     
  348.     if (count < 2) {      
  349.       while(op < oe && (prevchar!=*op||*op != *(op + 1))){/* only use rle for at leat 3 equal bytes */
  350.     
  351.     *ce++ = *op;                                       
  352.     count++;                                         
  353.     prevchar = *op++;                              
  354.     if (op > oe)
  355.       puts("FATAL op> oe!!\n");
  356.       }
  357.       if (op < oe && prevchar == *op){                             
  358.     op--;                                           
  359.     count--;                                       
  360.     ce--;                                         
  361.       }
  362.       
  363.       *countposition = count-1;                           
  364.     }
  365.   }
  366.   return ce - cp;  
  367.   
  368. }
  369.  
  370. int
  371. nocompress(op,oe,cp)
  372.      unsigned char *op;
  373.      unsigned char *oe;
  374.      unsigned char *cp;
  375. {
  376.   unsigned char *ce = cp;
  377.   while(op < oe)
  378.     *ce++ = *op++;
  379.   return ce - cp;
  380. }
  381.  
  382. /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
  383.    hopefully compatible with other HP Deskjet printers */
  384.  
  385. TERM_PUBLIC void HP500Ctext()
  386. {
  387.   register int x,j,row,count=0;
  388.   unsigned char *obuf,*oe,*cbuf,*ce;
  389.   
  390.   if((obuf = (unsigned char *) malloc(100*b_psize))==0)
  391.     puts("FATAL!-- couldn't get enough memory for obuf");
  392.   if((cbuf = (unsigned char *) malloc(400*b_psize))==0)
  393.     puts("FATAL!-- couldn't get enough memory for cbuf");
  394.   
  395.   oe = obuf;
  396.   
  397.   fprintf(outfile,"\033*t%dR", HP500C_PPI);
  398.   fprintf(outfile, "\033*r1A");
  399.   fprintf(outfile,"\033*b%1dM",HP_COMP_MODE);
  400.   fprintf(outfile, "\033*r%dS",b_ysize);
  401.   fprintf(outfile,"\033*r-3U");
  402.   
  403.   
  404.   /* dump bitmap in raster mode */
  405.   for (x = b_xsize-1; x >= 0; x--) {
  406.     row = (b_ysize/8)-1;
  407.     for (j = row; j >= 0; j-- ) {
  408.       *oe++ =  (char)(*((*b_p)[j]+x));    
  409.     }
  410.     switch (HP_COMP_MODE){
  411.     case 2 :
  412.       count = compress_to_TIFF(obuf,oe,cbuf);
  413.       break;
  414.     case 1 :
  415.       count = compress(obuf,oe,cbuf);
  416.       break;
  417.     case 0 :
  418.       count = nocompress(obuf,oe,cbuf);
  419.       break;
  420.     }
  421.     fprintf(outfile, "\033*b%dV", count);
  422.     ce = cbuf;
  423.     while(count--)
  424.       fputc(*ce++,outfile);
  425.     oe = obuf;
  426.     
  427.     for (j = row; j >=0; j-- ) {
  428.       *oe++ = (char)(*((*b_p)[j+b_psize]+x));
  429.     }
  430.     switch (HP_COMP_MODE){
  431.     case 2 :
  432.       count = compress_to_TIFF(obuf,oe,cbuf);
  433.       break;
  434.     case 1 :
  435.       count = compress(obuf,oe,cbuf);
  436.       break;
  437.     case 0 :
  438.       count = nocompress(obuf,oe,cbuf);
  439.       break;
  440.       
  441.     }
  442.     
  443.     fprintf(outfile, "\033*b%dV", count);
  444.     ce = cbuf;
  445.     while(count--)
  446.       fputc(*ce++,outfile);
  447.     oe = obuf;
  448.     
  449.     for (j = row; j >=0; j-- ) {
  450.       *oe++ =  (char)(*((*b_p)[j+(2*b_psize)]+x));
  451.     }
  452.     switch (HP_COMP_MODE){
  453.     case 2 :
  454.       count = compress_to_TIFF(obuf,oe,cbuf);
  455.       break;
  456.     case 1 :
  457.       count = compress(obuf,oe,cbuf);
  458.       break;
  459.     case 0 :
  460.       count = nocompress(obuf,oe,cbuf);
  461.       break;
  462.     }
  463.     fprintf(outfile, "\033*b%dW", count);
  464.     ce = cbuf;
  465.     while(count--)
  466.       fputc(*ce++,outfile);
  467.     oe = obuf;
  468.     
  469.   }
  470.   fprintf(outfile, "\033*rbC");
  471.   free(cbuf);
  472.   free(obuf);  
  473.   b_freebitmap();
  474.   
  475. #ifndef vms  /* most vms spoolers add a formfeed character */
  476.   fprintf(outfile,"\f");
  477. #endif /* not vms */
  478. }
  479.  
  480. #endif
  481.  
  482. #ifdef TERM_TABLE
  483.  
  484. TERM_TABLE_START(hp500c_driver)
  485.       "hp500c", "HP DeskJet 500c, [75 100 150 300] [rle tiff]",
  486.        HP500C_75PPI_XMAX, HP500C_75PPI_YMAX, HP500C_75PPI_VCHAR,
  487.        HP500C_75PPI_HCHAR, HP500C_75PPI_VTIC, HP500C_75PPI_HTIC, HP500Coptions,
  488.        HP500Cinit, HP500Creset, HP500Ctext, null_scale,
  489.        HP500Cgraphics, HP500Cmove, HP500Cvector, HP500Clinetype,
  490.        HP500Cput_text, HP500Ctext_angle, null_justify_text, do_point,
  491.        do_arrow, set_font_null
  492. TERM_TABLE_END(hp500c_driver)
  493. #undef LAST_TERM
  494. #define LAST_TERM hp500c_driver
  495.  
  496. #endif
  497. #endif
  498.  
  499. /*
  500.  * NAME: hp500c
  501.  *
  502.  * OPTIONS: dpi (legal 75, 100, 150, 300; default = 75)
  503.  *        compression (rle, tiff, no comp; default = no comp)
  504.  *
  505.  * SUPPORTS: HP DeskJet 500c 
  506.  *
  507.  * Further Info: none
  508.  *
  509.  */
  510.