source: golgotha/src/i4/loaders/pcx_write.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 15 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.6 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9
10#include "image/depth.hh"
11#include "image/image8.hh"
12#include "file/file.hh"
13#include "palette/pal.hh"
14
15void i4_write_pcx(i4_image_class *im,
16                  const i4_pal_handle_class &pal,
17                  i4_file_class *fp)
18{
19  if (im->get_pal().type()!=i4_pal_handle_class::ID_8BIT)
20    i4_error("cannot save non 8bit pcx files");
21
22  fp->write_8(10);   // manufacturer
23  fp->write_8(5);    // version
24  fp->write_8(1);    // encoding
25  fp->write_8(8);    // bits_per_pixel
26
27  fp->write_16(0);               // xmin
28  fp->write_16(0);               // ymin
29  fp->write_16(im->width()-1);   // xmax
30  fp->write_16(im->height()-1);  // ymax
31  fp->write_16(320);             // hres
32  fp->write_16(200);             // vres
33
34
35  w8 scrap[58];
36  memset(scrap,0,sizeof(scrap));
37  fp->write(scrap,48);
38
39  fp->write_8(0);                // reserved
40  fp->write_8(1);                // color planes
41  fp->write_16(im->width());     // bytes per line
42  fp->write_16(0);               // palette type
43 
44  fp->write(filter,58);
45
46 
47  sw32 y,run_length,x;
48  w8 code; 
49  i4_unmatched_image8 *im8=(i4_unmatched_image8 *)im;
50  i4_unmatched_image8::iterator sl,run;
51
52  for (y=0; y<im->height(); y++)
53  {
54    sl=im->create_iterator(0,y);
55
56    for (x=0;x<im->width();)
57    {
58      run_length=1;     
59      run=sl;
60      while (x+run_length<im->width() && im->iterator_get(run)==im->iterator_get(sl))
61      {
62        ++run;
63        ++run_length;
64      }
65
66      if (run_length==1 && im->iterator_get(sl)<64)
67        fp->write_8(im->iterator_get(sl));
68      else
69      {
70        if (run_length>=64)
71          run_length=63;
72        code=0xc0 | run_length;
73        fp->write_8(code);
74        fp->write_8(im->iterator_get(sl));     
75      }     
76      x+=run_length;
77      sl=run;
78    }
79  }
80  fp->write_8(12);  // note that there is a palette attached
81
82  w8 packed_pal[256*3];
83  w32 *p=i4_pal_man.get_pal(pal);
84  for (w32 x=0; x<256; x++)
85  {
86    packed_pal[x*3+0]=((*p)>>16)&0xff;
87    packed_pal[x*3+1]=((*p)>>8)&0xff;
88    packed_pal[x*3+2]=((*p)>>0)&0xff;
89  }
90
91  fp->write(packed_pal,256*3);
92  fclose(fp);   
93}
94
95
96
Note: See TracBrowser for help on using the repository browser.