home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / utilities / archiveutils / wmf.lha / src / screendump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-22  |  3.1 KB  |  122 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3.  
  4. #include <exec/types.h>
  5. #include <intuition/intuition.h>
  6. #include <libraries/iffparse.h>
  7. #include <clib/exec_protos.h>
  8. #include <proto/intuition.h>
  9. #include <proto/iffparse.h>
  10. #include <proto/graphics.h>
  11. #include <dos.h>
  12.  
  13. #define ID_ILBM        MAKE_ID('I','L','B','M')
  14. #define ID_BODY        MAKE_ID('B','O','D','Y')
  15. #define ID_BMHD        MAKE_ID('B','M','H','D')
  16. #define ID_CMAP        MAKE_ID('C','M','A','P')
  17.  
  18. typedef struct {
  19.         UWORD w, h;
  20.         WORD  x, y;
  21.         UBYTE nPlanes;
  22.         UBYTE masking;
  23.         UBYTE compression;
  24.         UBYTE reserved;
  25.         UWORD transparentColor;
  26.         UBYTE xAspect, yAspect;
  27.         WORD  pageWidth, pageHeight;
  28. } BitMapHeader;
  29.  
  30. typedef struct {
  31.         unsigned char R, G, B;
  32. } IFFColorReg;
  33.  
  34. typedef struct {
  35.         unsigned pad1:4, red:4, green:4, blue:4;
  36. } color4;
  37.  
  38. extern struct Library *IntuitionBase, *GfxBase;
  39. struct Library *IFFParseBase=NULL;
  40.  
  41. void ScreenDump( struct Screen *scr, char *fname )
  42. {
  43.   
  44.         struct IFFHandle *iff;
  45.         struct ViewPort vp;
  46.     struct BitMap bm;
  47.     struct ColorMap cm, *pcm;
  48.     IFFColorReg *CMAPdata;
  49.         unsigned AmiColorDat;
  50.     unsigned cmapsize,i,j;
  51.         BitMapHeader bmhd;
  52.  
  53.     if (sizeof(IFFColorReg)!=3) {
  54.                 printf("INTERNAL ERROR: IFFColorReg struct not packed!\n");
  55.                 return;
  56.         };
  57.         if (IntuitionBase==NULL || GfxBase==NULL) return;
  58.  
  59.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0))) { 
  60.         printf("Could not open iffparse.library!\n");
  61.         return;
  62.     };
  63.  
  64.         vp = scr->ViewPort;
  65.     bm = scr->BitMap;
  66.     cm = *vp.ColorMap;
  67.         pcm = &cm;
  68.  
  69.         bmhd.w=scr->Width;
  70.         bmhd.h=scr->Height;
  71.         bmhd.x=0; 
  72.         bmhd.y=0;
  73.         bmhd.nPlanes=bm.Depth;
  74.         bmhd.masking=0;
  75.         bmhd.compression=0;
  76.         bmhd.reserved=0;
  77.         bmhd.transparentColor=0;
  78.         bmhd.xAspect=1; 
  79.         bmhd.yAspect=1;
  80.         bmhd.pageWidth=scr->Width
  81.         bmhd.pageHeight=scr->Height;
  82.  
  83.         iff = AllocIFF();
  84.         iff->iff_Stream = Open( fname, MODE_NEWFILE);
  85.         InitIFFasDOS(iff);
  86.         OpenIFF(iff,IFFF_WRITE);
  87.  
  88.         PushChunk(iff, ID_ILBM, ID_FORM, IFFSIZE_UNKNOWN);
  89.  
  90.         PushChunk(iff, ID_ILBM, ID_BMHD, sizeof(BitMapHeader));
  91.         WriteChunkBytes(iff, &bmhd, sizeof(bmhd));
  92.         PopChunk(iff);
  93.  
  94.     cmapsize = ((1<<bm.Depth) * sizeof(IFFColorReg));
  95.     CMAPdata = (IFFColorReg *) calloc(1,cmapsize);
  96.  
  97.         PushChunk(iff, ID_ILBM, ID_CMAP, cmapsize);
  98.         for(i=0; i<(1<<bm.Depth); i++) {
  99.         AmiColorDat = GetRGB4( &cm, i );
  100.                 CMAPdata[i].R = ((AmiColorDat & 0x0f00) >> 8) * 0x10;
  101.                 CMAPdata[i].G = ((AmiColorDat & 0x00f0) >> 4) * 0x10;
  102.                 CMAPdata[i].B =  (AmiColorDat & 0x000f) * 0x10;
  103.         WriteChunkBytes(iff, &CMAPdata[i], 3);
  104.         };
  105.         PopChunk(iff);
  106.  
  107.         PushChunk(iff, ID_ILBM, ID_BODY, IFFSIZE_UNKNOWN);
  108.     for(i=0;i<bm.Rows;i++) {
  109.           for (j=0; j<bm.Depth; j++){
  110.                 WriteChunkBytes(iff, &bm.Planes[j][i*bm.BytesPerRow], bm.BytesPerRow);
  111.           }
  112.         }
  113.         PopChunk(iff);
  114.  
  115.         PopChunk(iff);
  116.  
  117.         CloseIFF(iff);
  118.         Close(iff->iff_Stream);
  119.         FreeIFF(iff);
  120.         if (IFFParseBase) CloseLibrary(IFFParseBase);
  121. }
  122.