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

  1. #include <portab.h>
  2. #include <mintbind.h>
  3. #include <atarierr.h>
  4.  
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #include <treiber.h>
  9.  
  10.  
  11.  
  12. /* Versucht Zeile zu Komprimieren */
  13. WORD    compress_img_run( UBYTE *ziel, UBYTE *p, WORD *limit )
  14. {
  15.     UBYTE    i;
  16.  
  17.         /* Sonst getrennt */
  18.     if(  p[0]==0xFF  ||  p[0]==0  )
  19.     {
  20.         for(  i=1;  p[i]==p[0]  &&  i<*limit  &&  i<0x7F;  i++  )
  21.             ;
  22.         ziel[0] = (0x80 & p[0]) | i;
  23.         (*limit) -= i;
  24.         return 1;
  25.     }
  26.     else
  27.     {
  28.         /* Abstand zum nächsten Ungleichen... */
  29.         for(  i=0;  p[i]!=0  &&  p[i]!=0xFF  &&  i<127  &&  i<*limit;  i++  )
  30.             ziel[i+2] = p[i];
  31.         ziel[0] = 0x80;
  32.         ziel[1] = i;
  33.         (*limit) -= i;
  34.         return i+2;
  35.     }
  36. }
  37. /* 17.1.93 */
  38.  
  39.  
  40. typedef struct {
  41.     unsigned version;
  42.     unsigned headlen;
  43.     unsigned nplanes;
  44.     unsigned patlen;
  45.     unsigned pixelw;
  46.     unsigned pixelh;
  47.     unsigned linew;
  48.     unsigned lines;
  49. /*    unsigned palette[16]; Sind eh monochrom */
  50. } IMGHEADER;
  51.  
  52.  
  53. UBYTE            line[8192];
  54.  
  55. /* Schreibe in DVI-Datei */
  56. WORD    drucke( UBYTE *p, LONG weite, LONG max_zeile, LONG h_dpi, LONG v_dpi )
  57. {
  58.     IMGHEADER    hdr;
  59.     WORD            max_spalte, zeile, lz;
  60.     WORD            rep, th, i;
  61.     UBYTE            l;
  62.  
  63.     th = (WORD)get_tempfile( "img" );
  64.     if(  th<0  )
  65.         return -1;
  66.  
  67.         /* Header */
  68.     hdr.version = 1;
  69.     hdr.headlen = (WORD)sizeof(IMGHEADER)/2;
  70.     hdr.nplanes = 1;
  71.     hdr.patlen = 2;
  72.         /* Grafikauflösung festlegen */
  73.     hdr.pixelw = (WORD)((25400L+h_dpi/2)/h_dpi);
  74.     hdr.pixelh = (WORD)((25400L+v_dpi/2)/v_dpi);
  75.         /* Grafikweite festlegen */
  76.     hdr.linew = (WORD)weite;
  77.     hdr.lines = (WORD)max_zeile;
  78.     Fwrite( th, sizeof(IMGHEADER), &hdr );
  79.  
  80.     max_spalte = (WORD)((weite+7)/8);
  81.     zeile = 0;
  82.     weite = (weite+15)/16;
  83.     weite *= 2;
  84.  
  85.     while(  zeile<max_zeile  )
  86.      {
  87.              /* Zeilenkopf */
  88.              /* gleiche Zeilen komprimieren */
  89.          for(  l=1;  0==memcmp( p, p+weite, max_spalte )  &&  zeile<max_zeile  &&  l<255;  l++, zeile++  )
  90.              p += weite;
  91.          Fwrite( th, 3L, "\0\0\xFF" );
  92.         Fwrite( th, 1L, &l );
  93.  
  94.             /* Eine Zeile in die Datei! */
  95.         rep = lz = max_spalte;
  96.         i = 0;
  97.             /* Wir komprimieren (es bleibt auch nichts übrig) */
  98.         while(  lz>0  )
  99.             i += compress_img_run( line+i, p+rep-lz, &lz );
  100.         Fwrite( th, (LONG)i, line );
  101.  
  102.         p += weite;
  103.         zeile++;
  104.     }
  105.     Fclose( th );
  106.     /* Sollte immer gut gehen! (d.h. kein File zum Drucken!) */
  107.     return 0;
  108. }
  109. /* 22.1.93 */
  110.  
  111.  
  112.