home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0657.ZIP / CCE_0657.PD / EPSON_90.C < prev    next >
C/C++ Source or Header  |  1993-08-31  |  6KB  |  262 lines

  1. /*************************************************************************
  2. **** Querdruck für EPSON ESC/P 9-Nadeldrucker                         ****
  3. *************************************************************************/
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7.  
  8. #include <portab.h>
  9. #include <mintbind.h>
  10.  
  11. #include "treiber.h"
  12.  
  13. /** Vorläufige Parameter */
  14. #define MAX_DPI    240L
  15. #define    HOEHE    1920L
  16. #define WEITE -1L
  17. #define BITS_PER_CHAR    20    /* Elite-Dichte! */
  18. #define COMPRESSION 2    /* Von 2 bis 0 (so lassen) */
  19.  
  20. #ifdef FAST_PRN
  21. #define WRITE(i,j) ((th>0)?(Fwrite(th,i,j)):(print_block(i,j)))
  22. #endif
  23.  
  24.  
  25. /* Reset + NLQ + Einheit 1/MAX_DPI" + Zeilenabstand 1/216" */
  26. UBYTE    *INIT = "\033@\033M\033\063\001\015";
  27. UBYTE    *V_STEP    =    "\033f\001x";
  28. UBYTE    *H_STEP = "\033lx";
  29.  
  30.  
  31.  
  32.  
  33. void write_compressed( WORD th, UBYTE *tmp, LONG len, long bpc )
  34. {
  35. #if COMPRESSION==2
  36. /* Schneidet nur links und rechts ab */
  37. /* Diese Routine sollte mit nahezu jedem Drucker gehen! */
  38. /* wenn man BITS_PER_CHAR (bpc) kennt! */
  39.     LONG    i, j;
  40.  
  41.     for(  i=0;  i<len  &&  tmp[5+i]==0;  i++  )
  42.         ;
  43.     while(  tmp[len+4]==0  &&  len>i  )
  44.         len--;
  45.     if(  i==len  )
  46.         WRITE( 2L, "\015\012" );
  47.     else
  48.     {
  49.         for(  j=0;  j<i/bpc;  j++  )
  50.             WRITE( 1L, " " );
  51.         j *= bpc;
  52.         len -= j;
  53.         tmp[3] = (UBYTE)(len % 256);
  54.         tmp[4] = (UBYTE)(len / 256);
  55.         WRITE( 5L, tmp );
  56.         WRITE( len, tmp+5+j );
  57.         WRITE( 2L, "\015\012" );
  58.     }
  59. #elif COMPRESSION==1
  60.     LONG    i;
  61.  
  62. /* Schneidet nur rechts ab */
  63.     for(  i=len;  i>0  && tmp[i+5]==0;  i--  )
  64.         ;
  65.     len--;
  66.     if(  i==0  )
  67.         WRITE( 2L, "\015\012" );
  68.     else
  69.     {
  70.         len = i;
  71.         tmp[3] = (UBYTE)(len % 256);
  72.         tmp[4] = (UBYTE)(len / 256);
  73.         WRITE( 5L+len, tmp );
  74.         WRITE( 2L, "\015\012" );
  75.     }
  76. #else
  77.     WRITE( 7L+len, tmp );
  78. #endif
  79. }
  80. /* 23.8.93 */
  81.  
  82.  
  83. /* Zwischenspeicher für eine Zeile */
  84. static UBYTE    tmp1[HOEHE+6L];
  85. static UBYTE    tmp2[HOEHE+6L];
  86. static UBYTE    tmp3[HOEHE+6L];
  87.  
  88. static LONG    bit_table[]=
  89. {
  90.     0x00800000L,0x00400000L,0x00200000L,0x00100000L,
  91.     0x00080000L,0x00040000L,0x00020000L,0x00010000L,
  92.     0x00008000L,0x00004000L,0x00002000L,0x00001000L,
  93.     0x00000800L,0x00000400L,0x00000200L,0x00000100L,
  94.     0x00000080L,0x00000040L,0x00000020L,0x00000010L,
  95.     0x00000008L,0x00000004L,0x00000002L,0x00000001L
  96. };
  97.  
  98.  
  99.  
  100. WORD    drucke( UBYTE *p, LONG weite, LONG hoehe, LONG h_dpi, LONG v_dpi )
  101. {
  102.     extern char    tmp_file[256]; /* In Datei drucken? */
  103.  
  104.     LONG    max_spalte, max_zeile, zeile, lz;
  105.     LONG    len, bytes_per_row, offset, i, j, k;
  106.     WORD    th=0;
  107.     UBYTE    t;
  108.  
  109. #ifdef FAST_PRN
  110.     /* Für viel Geschwindigkeit */
  111.     if(  tmp_file[0]>0  ||  open_printer()<0  )
  112. #endif
  113.         th = (WORD)get_tempfile( "n9q" );
  114.     if(  th<0  )
  115.         return -1;
  116.  
  117.     t = '3';
  118.     j = 240;
  119.     if(  v_dpi<150  )
  120.     {
  121.         t = '1';
  122.         j = 120;
  123.     }
  124.  
  125.     v_dpi = 216;
  126.     bytes_per_row = 3;
  127.     if(  h_dpi<80  )
  128.     {
  129.         v_dpi = 72;
  130.         bytes_per_row = 1;
  131.     }
  132.     else
  133.         if(  h_dpi<160  )
  134.         {
  135.             v_dpi = 144;
  136.             bytes_per_row = 2;
  137.         }
  138.     h_dpi = j;
  139.  
  140.         /* Ab hier wird es ernst */
  141.     if(  hoehe>(HOEHE*h_dpi)/MAX_DPI  )
  142.         max_spalte = (HOEHE*h_dpi)/MAX_DPI;
  143.  
  144.         /* Diverse Variablen initialisieren */
  145.     zeile = 0;
  146.     if(  WEITE>0    &&    (weite*v_dpi)/MAX_DPI>WEITE  )
  147.         max_zeile = (WEITE+7)*v_dpi/(8*MAX_DPI);
  148.     else
  149.         max_zeile = (weite+7L)/8L;
  150.     weite = (weite+15L)/16L;
  151.     weite *= 2;
  152.  
  153.         /* Reset + LQ-Mode */
  154.     WRITE( 8L, INIT );
  155.  
  156.     /* Endlich drucken */
  157.     max_zeile--;
  158.     while(    zeile<max_zeile )
  159.     {
  160.         for(  lz=0;  ist_next_leer( p+lz, weite, hoehe )  &&  lz<max_zeile;  lz++  )
  161.             ;
  162.         if(     lz>0    )
  163.         {    /* Leerzeilen überspringen */
  164.             zeile += lz;
  165.             p += lz;
  166.             lz = lz*8*3/bytes_per_row;
  167.              while(  lz>0  )
  168.             {
  169.                 if(  lz>255  )
  170.                     V_STEP[3] = 255;
  171.                 else
  172.                     V_STEP[3] = lz;
  173.                 WRITE( 4L, V_STEP );
  174.                 lz -= 255;
  175.             }
  176.         }
  177.         if(  zeile>=max_zeile  )
  178.             break;
  179.  
  180.         len = max_spalte;
  181.         if(  max_spalte<(HOEHE*h_dpi)/MAX_DPI  )
  182.             offset = (HOEHE*h_dpi)/MAX_DPI-max_spalte;
  183.         else
  184.             offset = 0;
  185.         tmp1[0] = '\033';
  186.         tmp1[1] = '*';
  187.         tmp1[2] = t;
  188.  
  189.         switch(  (int)bytes_per_row  )
  190.         {
  191.             case 1:    for(  lz=0;  lz<len;  lz++  )
  192.                                 tmp1[4L+offset+len-lz] = p[lz*weite];
  193.                             memset( tmp1+5, 0, offset );
  194.                             tmp1[3] = (UBYTE)((len+offset) % 256);
  195.                             tmp1[4] = (UBYTE)((len+offset) / 256);
  196.                             write_compressed( th, tmp1, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  197.                             p += 1;
  198.                         break;
  199.             case 2:    memset(  tmp1+5, 0, offset+len );
  200.                             memcpy(  tmp2, tmp1, 5+offset+len );
  201.                             for(  lz=0;  lz<len;  lz++  )
  202.                             {
  203.                                 i = 256L*p[lz*weite]+p[lz*weite+1];
  204.                                 if(  i==0L  )
  205.                                     continue;
  206.                                 for(  j=8,k=0;  k<8;  k++  )
  207.                                 {
  208.                                     if(  (i&bit_table[j++])!=0L  )
  209.                                         tmp1[4L+offset+len-lz] |= bit_table[16+k];
  210.                                     if(  (i&bit_table[j++])!=0L  )
  211.                                         tmp2[4L+offset+len-lz] |= bit_table[16+k];
  212.                                 }
  213.                             }
  214.                             /* Komprimiert schreiben */
  215.                             write_compressed( th, tmp1, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  216.                             write_compressed( th, tmp2, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  217.                             p += 2;
  218.                         break;
  219.             case 3:    memset(  tmp1+5, 0, offset+len );
  220.                             memcpy(  tmp2, tmp1, 5+offset+len );
  221.                             memcpy(  tmp3, tmp1, 5+offset+len );
  222.                             for(  lz=0;  lz<len;  lz++  )
  223.                             {
  224.                                 i = p[lz*weite]*65536L+p[lz*weite+1]*256L+p[lz*weite+2];
  225.                                 if(  i==0  )
  226.                                     continue;
  227.                                 for(  j=k=0;  k<8;  k++  )
  228.                                 {
  229.                                     if(  (i&bit_table[j++])!=0  )
  230.                                         tmp1[4L+offset+len-lz] |= bit_table[16+k];
  231.                                     if(  (i&bit_table[j++])!=0  )
  232.                                         tmp2[4L+offset+len-lz] |= bit_table[16+k];
  233.                                     if(  (i&bit_table[j++])!=0  )
  234.                                         tmp3[4L+offset+len-lz] |= bit_table[16+k];
  235.                                 }
  236.                             }
  237.                             write_compressed( th, tmp1, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  238.                             write_compressed( th, tmp2, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  239.                             write_compressed( th, tmp3, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  240.                             p += 3;
  241.                         break;
  242.         }
  243.         V_STEP[3] = 24-bytes_per_row;
  244.         WRITE( 4L, V_STEP );
  245.         zeile += bytes_per_row;
  246.     }
  247.  
  248.         /* Ende Seite */
  249.     if(  2!=WRITE( 1L, " \014" )  )
  250.     {
  251.         /* Platz reichte nicht aus */
  252.         if(  th>0  )
  253.             Fclose( th );
  254.         th = -1;
  255.     }
  256.  
  257.     if(  tmp_file[0]==0  )
  258.         flush_block();
  259.     return th;
  260. }
  261. /* 17.1.93 */
  262.