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/load.hh"
|
---|
11 | #include "image_man.hh"
|
---|
12 | #include "string/string.hh"
|
---|
13 | #include "app/app.hh"
|
---|
14 | #include "g1_tint.hh"
|
---|
15 | #include "video/display.hh"
|
---|
16 |
|
---|
17 | // this image is used if the correct image could not be loaded
|
---|
18 | static i4_image_class *default_image=0;
|
---|
19 | static int images_have_been_loaded=0;
|
---|
20 |
|
---|
21 |
|
---|
22 | g1_image_ref *g1_image_ref::first=0;
|
---|
23 |
|
---|
24 | g1_image_ref::g1_image_ref(const char *filename)
|
---|
25 | {
|
---|
26 | image_name=filename;
|
---|
27 | next=first;
|
---|
28 | first=this;
|
---|
29 | im=0;
|
---|
30 | }
|
---|
31 |
|
---|
32 | g1_image_ref::~g1_image_ref()
|
---|
33 | {
|
---|
34 | if (first==this)
|
---|
35 | first=first->next;
|
---|
36 | else
|
---|
37 | {
|
---|
38 | g1_image_ref *f=first;
|
---|
39 | while (f->next!=this)
|
---|
40 | f=f->next;
|
---|
41 | f->next=next;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | void g1_image_ref::load()
|
---|
46 | {
|
---|
47 | im=i4_load_image(image_name);
|
---|
48 | if (!im)
|
---|
49 | {
|
---|
50 | i4_warning("could not load %s", image_name);
|
---|
51 | im=default_image;
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | void g1_image_ref::set_image(const char *filename)
|
---|
57 | {
|
---|
58 | cleanup();
|
---|
59 |
|
---|
60 | image_name=filename;
|
---|
61 |
|
---|
62 | if (images_have_been_loaded)
|
---|
63 | {
|
---|
64 | im=i4_load_image(image_name);
|
---|
65 | if (!im)
|
---|
66 | {
|
---|
67 | i4_warning("could not load %s", image_name);
|
---|
68 | im=default_image;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | void g1_image_ref::cleanup()
|
---|
74 | {
|
---|
75 | if (im && im!=default_image)
|
---|
76 | {
|
---|
77 | delete im;
|
---|
78 | im=0;
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | void g1_load_images()
|
---|
85 | {
|
---|
86 | i4_image_class *old_default_image=default_image;
|
---|
87 |
|
---|
88 | if (default_image)
|
---|
89 | delete default_image;
|
---|
90 | default_image=i4_load_image("bitmaps/default.tga");
|
---|
91 | if (!default_image)
|
---|
92 | i4_error("could not load default image bitmaps/default.tga");
|
---|
93 |
|
---|
94 |
|
---|
95 | for (g1_image_ref *f=g1_image_ref::first; f; f=f->next)
|
---|
96 | {
|
---|
97 | f->cleanup();
|
---|
98 | f->load();
|
---|
99 |
|
---|
100 | }
|
---|
101 |
|
---|
102 | images_have_been_loaded=1;
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | void g1_unload_images()
|
---|
107 | {
|
---|
108 | for (g1_image_ref *f=g1_image_ref::first; f; f=f->next)
|
---|
109 | f->cleanup();
|
---|
110 |
|
---|
111 | if (default_image)
|
---|
112 | {
|
---|
113 | delete default_image;
|
---|
114 | default_image=0;
|
---|
115 | }
|
---|
116 | images_have_been_loaded=0;
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | g1_team_icon_ref::g1_team_icon_ref(const char *filename)
|
---|
121 | : g1_image_ref(filename)
|
---|
122 | {
|
---|
123 | for (int i=0; i<G1_MAX_PLAYERS; i++)
|
---|
124 | tinted_icons[i]=0;
|
---|
125 | }
|
---|
126 |
|
---|
127 | void g1_team_icon_ref::cleanup()
|
---|
128 | {
|
---|
129 | g1_image_ref::cleanup();
|
---|
130 | for (int i=0; i<G1_MAX_PLAYERS; i++)
|
---|
131 | {
|
---|
132 | if (tinted_icons[i] && tinted_icons[i]!=default_image)
|
---|
133 | delete tinted_icons[i];
|
---|
134 | tinted_icons[i]=0;
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | static float tr,tg,tb;
|
---|
140 |
|
---|
141 | inline w32 tint_color(w32 color)
|
---|
142 | {
|
---|
143 | int r=i4_f_to_i(((color>>16)&0xff)*tr);
|
---|
144 | int g=i4_f_to_i(((color>>8)&0xff)*tg);
|
---|
145 | int b=i4_f_to_i(((color>>0)&0xff)*tb);
|
---|
146 |
|
---|
147 | return (r<<16)|(g<<8)|b;
|
---|
148 | }
|
---|
149 |
|
---|
150 | void g1_team_icon_ref::load()
|
---|
151 | {
|
---|
152 | g1_image_ref::load();
|
---|
153 |
|
---|
154 |
|
---|
155 | const i4_pal *pal=i4_current_app->get_display()->get_palette();
|
---|
156 |
|
---|
157 | for (int i=0; i<G1_MAX_PLAYERS; i++)
|
---|
158 | {
|
---|
159 | int w=im->width(), h=im->height();
|
---|
160 | i4_image_class *out=i4_create_image(w,h, pal);
|
---|
161 |
|
---|
162 | tr=g1_player_tint_data[i].r;
|
---|
163 | tg=g1_player_tint_data[i].g;
|
---|
164 | tb=g1_player_tint_data[i].b;
|
---|
165 |
|
---|
166 | for (int y=0; y<h; y++)
|
---|
167 | for (int x=0; x<w; x++)
|
---|
168 | {
|
---|
169 | w32 color=im->get_pixel(x,y);
|
---|
170 | out->put_pixel(x,y, tint_color(color));
|
---|
171 | }
|
---|
172 |
|
---|
173 | tinted_icons[i]=out;
|
---|
174 | }
|
---|
175 | }
|
---|