home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / shareware / crystalppc / pcx.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  2KB  |  83 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. //vonmir
  5. //#include <unistd.h>
  6.  
  7. //ersatzlos gestrichen
  8. //
  9. #include "global.h"
  10.  
  11. extern void dprintf (char *, ...);
  12.  
  13. typedef struct
  14. {
  15.         char    manufacturer;
  16.         char    version;
  17.         char    encoding;
  18.         char    bits_per_pixel;
  19.         word    xmin;
  20.         word    ymin;
  21.         word    xmax;
  22.         word    ymax;
  23.         word    hres;
  24.         word    vres;
  25.         byte    palette[48];
  26.         char    reserved;
  27.         char    color_planes;
  28.         word    bytes_per_line;
  29.         word    palette_type;
  30.         char    filler[58];
  31.         byte    data;
  32. } pcx_header;
  33.  
  34. void WritePCX (char *name, char *data, byte *pal, int width, int height)
  35. {
  36.         int i, j, len;
  37.         pcx_header *pcx;
  38.         byte *pack;
  39.         FILE *fp;
  40.  
  41.         pcx = (pcx_header*)malloc (width*height*2+1000);
  42.         pcx->manufacturer = 0;
  43.         pcx->version = 5;
  44.         pcx->encoding = 1;
  45.         pcx->bits_per_pixel = 8;
  46.         pcx->xmin = 0;
  47.         pcx->ymin = 0;
  48.         pcx->xmax = width - 1;
  49.         pcx->ymax = height - 1;
  50.         pcx->hres = width;
  51.         pcx->vres = height;
  52.         memset (pcx->palette, 0, sizeof(pcx->palette));
  53.         pcx->color_planes = 1;
  54.         pcx->bytes_per_line = width;
  55.         pcx->palette_type = 2;
  56.         memset (pcx->filler, 0, sizeof(pcx->filler));
  57.         pack = &(pcx->data);
  58.  
  59.         for (i=0; i<height; i++)
  60.         {
  61.                 for (j=0; j<width; j++)
  62.                 {
  63.                         if  ((*data & 0xc0) != 0xc0)
  64.                                 *pack++ = *data++;
  65.                         else
  66.                         {
  67.                                 *pack++ = 0xc1;
  68.                                 *pack++ = *data++;
  69.                         }
  70.                 }
  71. //              data += width;
  72.         }
  73.         *pack++ = 0x0c;
  74.         for (i=0; i<768; i++)
  75.                 *pack++ = *pal++;
  76.         len = pack - (byte *)pcx;
  77.         fp = fopen (name, "wb");
  78.         if (!fp) return;
  79.         fwrite (pcx, len, 1, fp);
  80.         fclose (fp);
  81.         free (pcx);
  82. }
  83.