home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0657.ZIP / CCE_0657.PD / IMG_90.C < prev    next >
C/C++ Source or Header  |  1993-09-01  |  2KB  |  114 lines

  1. /***************************************************************************/
  2. /*  Querdruck für IMG-Dateien                                              */
  3. /***************************************************************************/
  4.  
  5.  
  6. #include <portab.h>
  7. #include <string.h>
  8. #include <mintbind.h>
  9.  
  10. #include <stdio.h>
  11. #include "treiber.h"
  12.  
  13.  
  14.  
  15. /* Versucht Zeile zu Komprimieren */
  16. LONG    compress_img_run( UBYTE *ziel, UBYTE *p, LONG *limit )
  17. {
  18.     UBYTE    i;
  19.  
  20.         /* Sonst getrennt */
  21.     if(  p[0]==0xFF  ||  p[0]==0  )
  22.     {
  23.         for(  i=1;  p[i]==p[0]  &&  i<*limit  &&  i<0x7F;  i++  )
  24.             ;
  25.         ziel[0] = (0x80 & p[0]) | i;
  26.         (*limit) -= i;
  27.         return 1;
  28.     }
  29.     else
  30.     {
  31.         /* Abstand zum nächsten Ungleichen... */
  32.         for(  i=0;  p[i]!=0  &&  p[i]!=0xFF  &&  i<127  &&  i<*limit;  i++  )
  33.             ziel[i+2] = p[i];
  34.         ziel[0] = 0x80;
  35.         ziel[1] = i;
  36.         (*limit) -= i;
  37.         return i+2;
  38.     }
  39. }
  40. /* 17.1.93 */
  41.  
  42.  
  43.  
  44. typedef struct {
  45.     unsigned version;
  46.     unsigned headlen;
  47.     unsigned nplanes;
  48.     unsigned patlen;
  49.     unsigned pixelw;
  50.     unsigned pixelh;
  51.     unsigned linew;
  52.     unsigned lines;
  53. /*    unsigned palette[16]; Sind eh monochrom */
  54. } IMGHEADER;
  55.  
  56.  
  57. char    tmp_zeile[8192];    /* Gedrehte Zeilen + Sicherheit */
  58. char    line[8192];    /* Gedrehte Zeilen + Sicherheit */
  59. char    display_status[4]="\033H*";
  60.  
  61.  
  62. /* Datei ausdrucken */
  63. WORD    drucke( UBYTE *p, LONG weite, LONG hoehe, LONG h_dpi, LONG v_dpi )
  64. {
  65.     IMGHEADER    hdr;
  66.     LONG            max_spalte, wweite, lz;
  67.     LONG            rep, i, x;
  68.     WORD            th;
  69.  
  70.     th = (WORD)get_tempfile( "img" );
  71.     if(  th<0  )
  72.         return -1;
  73.  
  74.         /* Header */
  75.     hdr.version = 1;
  76.     hdr.headlen = (WORD)sizeof(IMGHEADER)/2;
  77.     hdr.nplanes = 1;
  78.     hdr.patlen = 2;
  79.         /* Grafikauflösung festlegen */
  80.     hdr.pixelw = (WORD)((25400L+v_dpi/2)/v_dpi);
  81.     hdr.pixelh = (WORD)((25400L+h_dpi/2)/h_dpi);
  82.         /* Grafikweite festlegen */
  83.     hdr.linew = (WORD)hoehe;
  84.     hdr.lines = (WORD)weite;
  85.     Fwrite( th, sizeof(IMGHEADER), &hdr );
  86.  
  87.     max_spalte = (hoehe+7)/8;
  88.     x = 0;
  89.     wweite = (weite+15)/16;
  90.     wweite *= 2;
  91.     Cconws( display_status );
  92.  
  93.     for(  i=0;  x<weite;  x++  )
  94.     {
  95.         if(  (x%128)==0  )
  96.         {
  97.             Cconws( display_status );
  98.             display_status[2] ^= 1;
  99.         }
  100.         drehe_90( p, tmp_zeile, wweite, max_spalte, x );
  101.          Fwrite( th, 4L, "\000\000\377\001" );
  102.  
  103.             /* Eine Zeile in die Datei! */
  104.         rep = lz = max_spalte;
  105.         i = 0;
  106.         while(  lz>0  )
  107.             i += compress_img_run( line+i, tmp_zeile+rep-lz, &lz );
  108.         Fwrite( th, (LONG)i, line );
  109.      }
  110.     return 0;
  111. }
  112.  
  113.  
  114.