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 "image/image.hh"
|
---|
10 | #include "loaders/tga_write.hh"
|
---|
11 | #include "file/file.hh"
|
---|
12 | #include "palette/pal.hh"
|
---|
13 |
|
---|
14 |
|
---|
15 | i4_bool i4_tga_write(i4_image_class *im, i4_file_class *fp, int include_alpha)
|
---|
16 | {
|
---|
17 | fp->write_8(0); // no id field
|
---|
18 | fp->write_8(0); // no color map
|
---|
19 | fp->write_8(2); // type = True color uncompressed
|
---|
20 |
|
---|
21 | fp->write_16(0); // first color map entry
|
---|
22 | fp->write_16(0); // color map length
|
---|
23 | fp->write_8(0); // color map entry size
|
---|
24 |
|
---|
25 | fp->write_16(0); // origin x & y
|
---|
26 | fp->write_16(0);
|
---|
27 |
|
---|
28 | sw32 w=im->width(), h=im->height(), x,y;
|
---|
29 | fp->write_16(w); // image width & height
|
---|
30 | fp->write_16(h);
|
---|
31 |
|
---|
32 | if (include_alpha)
|
---|
33 | fp->write_8(32); // bits per pixel
|
---|
34 | else
|
---|
35 | fp->write_8(24); // bits per pixel
|
---|
36 |
|
---|
37 | fp->write_8(0);
|
---|
38 |
|
---|
39 |
|
---|
40 | w8 out[4];
|
---|
41 | i4_color color;
|
---|
42 |
|
---|
43 | const i4_pal *pal=im->get_pal();
|
---|
44 | i4_pixel_format to;
|
---|
45 | to.default_format();
|
---|
46 |
|
---|
47 | if (include_alpha)
|
---|
48 | {
|
---|
49 | for (y=h-1; y>=0; y--)
|
---|
50 | {
|
---|
51 | for (x=0; x<w; x++)
|
---|
52 | {
|
---|
53 | color=im->get_pixel(x,y);
|
---|
54 |
|
---|
55 | out[0]=color&0xff;
|
---|
56 | out[1]=(color>>8)&0xff;
|
---|
57 | out[2]=(color>>16)&0xff;
|
---|
58 | out[3]=(color>>24)&0xff;
|
---|
59 | fp->write(out,4);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | else
|
---|
64 | {
|
---|
65 | for (y=h-1; y>=0; y--)
|
---|
66 | {
|
---|
67 | for (x=0; x<w; x++)
|
---|
68 | {
|
---|
69 | color=im->get_pixel(x,y);
|
---|
70 |
|
---|
71 | out[0]=color&0xff;
|
---|
72 | out[1]=(color>>8)&0xff;
|
---|
73 | out[2]=(color>>16)&0xff;
|
---|
74 | fp->write(out,3);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | return i4_T;
|
---|
80 |
|
---|
81 | }
|
---|