Last change
on this file since 608 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.0 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 | #include "loaders/bmp_write.hh"
|
---|
10 | #include "image/image.hh"
|
---|
11 | #include "palette/pal.hh"
|
---|
12 | #include "file/file.hh"
|
---|
13 |
|
---|
14 | inline void i4_32bpp_to_rgb(w32 color, w8 &r, w8 &g, w8 &b)
|
---|
15 | {
|
---|
16 | r=(color>>16)&0xff;
|
---|
17 | g=(color>>8)&0xff;
|
---|
18 | b=color&0xff;
|
---|
19 | }
|
---|
20 |
|
---|
21 | i4_bool i4_write_bmp(i4_image_class *im, i4_file_class *fp)
|
---|
22 | {
|
---|
23 | const i4_pal *pal=im->get_pal();
|
---|
24 |
|
---|
25 | if (pal->source.pixel_depth==I4_8BIT)
|
---|
26 | {
|
---|
27 | w32 w=im->width();
|
---|
28 | w32 h=im->height();
|
---|
29 | w32 store_width=(w+3)&(~3);
|
---|
30 | sw32 i;
|
---|
31 |
|
---|
32 | w8 buf[10];
|
---|
33 | buf[0]='B'; buf[1]='M';
|
---|
34 |
|
---|
35 | if (fp->write(buf,2)!=2) return i4_F;
|
---|
36 | fp->write_32(54 +
|
---|
37 | 4*256 +
|
---|
38 | store_width * h);
|
---|
39 |
|
---|
40 | fp->write_32(0);
|
---|
41 | fp->write_32(54 + 256*4);
|
---|
42 |
|
---|
43 | fp->write_32(40);
|
---|
44 | fp->write_32(w);
|
---|
45 | fp->write_32(h);
|
---|
46 | fp->write_16(1);
|
---|
47 | fp->write_16(8);
|
---|
48 | fp->write_32(0);
|
---|
49 | fp->write_32(0);
|
---|
50 | fp->write_32(320);
|
---|
51 | fp->write_32(200);
|
---|
52 | fp->write_32(256);
|
---|
53 | fp->write_32(256);
|
---|
54 |
|
---|
55 | w32 *p=pal->source.lookup;
|
---|
56 | for (i=0; i<256; i++)
|
---|
57 | {
|
---|
58 | w8 r,g,b;
|
---|
59 | i4_32bpp_to_rgb(*p,r,g,b);
|
---|
60 |
|
---|
61 | buf[0]=b;
|
---|
62 | buf[1]=g;
|
---|
63 | buf[2]=r;
|
---|
64 | buf[3]=0;
|
---|
65 |
|
---|
66 | fp->write(buf,4);
|
---|
67 | p++;
|
---|
68 | }
|
---|
69 |
|
---|
70 | buf[0]=0;
|
---|
71 | buf[1]=0;
|
---|
72 | buf[2]=0;
|
---|
73 |
|
---|
74 |
|
---|
75 | w8 *data=(w8 *)im->data;
|
---|
76 | for (i=h; i; i--)
|
---|
77 | {
|
---|
78 | fp->write(data, w);
|
---|
79 | data-=w;
|
---|
80 |
|
---|
81 | if (w!=store_width)
|
---|
82 | fp->write(buf,w&3);
|
---|
83 | }
|
---|
84 | return i4_T;
|
---|
85 | }
|
---|
86 | else
|
---|
87 | return i4_F;
|
---|
88 | }
|
---|
89 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.