Merge lp:~widelands-dev/widelands/remove_player_color into lp:widelands
- remove_player_color
- Merge into trunk
Proposed by
SirVer
Status: | Merged |
---|---|
Merged at revision: | 7316 |
Proposed branch: | lp:~widelands-dev/widelands/remove_player_color |
Merge into: | lp:widelands |
Diff against target: |
991 lines (+256/-399) 18 files modified
src/graphic/CMakeLists.txt (+0/-2) src/graphic/animation.cc (+28/-35) src/graphic/animation.h (+0/-5) src/graphic/gl/blit_program.cc (+93/-34) src/graphic/gl/blit_program.h (+44/-18) src/graphic/graphic.cc (+0/-3) src/graphic/image_transformations.cc (+0/-186) src/graphic/image_transformations.h (+0/-47) src/graphic/rendertarget.cc (+4/-6) src/graphic/rendertarget.h (+5/-9) src/graphic/surface.cc (+18/-7) src/graphic/surface.h (+10/-4) src/graphic/texture.cc (+22/-9) src/graphic/texture.h (+7/-5) src/ui_basic/button.cc (+2/-3) src/wui/buildingwindow.cc (+4/-5) src/wui/fieldaction.cc (+15/-15) src/wui/waresqueuedisplay.cc (+4/-6) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/remove_player_color |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+243896@code.launchpad.net |
Commit message
Description of the change
- Renamed GrayBlitProgram to MonochromeBlitP
- Removed all uses of ImageTransforma
- Removes image_transform
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/graphic/CMakeLists.txt' |
2 | --- src/graphic/CMakeLists.txt 2014-12-05 07:54:43 +0000 |
3 | +++ src/graphic/CMakeLists.txt 2014-12-08 07:41:03 +0000 |
4 | @@ -157,8 +157,6 @@ |
5 | font_handler1.h |
6 | graphic.cc |
7 | graphic.h |
8 | - image_transformations.cc |
9 | - image_transformations.h |
10 | in_memory_image.cc |
11 | in_memory_image.h |
12 | rendertarget.cc |
13 | |
14 | === modified file 'src/graphic/animation.cc' |
15 | --- src/graphic/animation.cc 2014-12-04 09:00:20 +0000 |
16 | +++ src/graphic/animation.cc 2014-12-08 07:41:03 +0000 |
17 | @@ -38,7 +38,6 @@ |
18 | #include "graphic/graphic.h" |
19 | #include "graphic/image.h" |
20 | #include "graphic/image_cache.h" |
21 | -#include "graphic/image_transformations.h" |
22 | #include "graphic/surface.h" |
23 | #include "graphic/texture_cache.h" |
24 | #include "io/filesystem/layered_filesystem.h" |
25 | @@ -127,7 +126,6 @@ |
26 | uint16_t nr_frames() const override; |
27 | uint32_t frametime() const override; |
28 | const Point& hotspot() const override; |
29 | - const Image& representative_image(const RGBColor& clr) const override; |
30 | const Image& representative_image_from_disk() const override; |
31 | virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) |
32 | const override; |
33 | @@ -135,12 +133,12 @@ |
34 | |
35 | |
36 | private: |
37 | + // Loads the graphics if they are not yet loaded. |
38 | + void ensure_graphics_are_loaded() const; |
39 | + |
40 | // Load the needed graphics from disk. |
41 | void load_graphics(); |
42 | |
43 | - // Returns the given frame image with the given clr (if not NULL). |
44 | - const Image& get_frame(uint32_t time, const RGBColor* playercolor = NULL) const; |
45 | - |
46 | uint32_t frametime_; |
47 | Point hotspot_; |
48 | bool hasplrclrs_; |
49 | @@ -231,6 +229,12 @@ |
50 | } |
51 | } |
52 | |
53 | +void NonPackedAnimation::ensure_graphics_are_loaded() const { |
54 | + if (frames_.empty()) { |
55 | + const_cast<NonPackedAnimation*>(this)->load_graphics(); |
56 | + } |
57 | +} |
58 | + |
59 | void NonPackedAnimation::load_graphics() { |
60 | if (image_files_.empty()) |
61 | throw wexception("animation without pictures."); |
62 | @@ -271,23 +275,17 @@ |
63 | } |
64 | |
65 | uint16_t NonPackedAnimation::width() const { |
66 | - if (frames_.empty()) { |
67 | - const_cast<NonPackedAnimation*>(this)->load_graphics(); |
68 | - } |
69 | + ensure_graphics_are_loaded(); |
70 | return frames_[0]->width(); |
71 | } |
72 | |
73 | uint16_t NonPackedAnimation::height() const { |
74 | - if (frames_.empty()) { |
75 | - const_cast<NonPackedAnimation*>(this)->load_graphics(); |
76 | - } |
77 | + ensure_graphics_are_loaded(); |
78 | return frames_[0]->height(); |
79 | } |
80 | |
81 | uint16_t NonPackedAnimation::nr_frames() const { |
82 | - if (frames_.empty()) { |
83 | - const_cast<NonPackedAnimation*>(this)->load_graphics(); |
84 | - } |
85 | + ensure_graphics_are_loaded(); |
86 | return frames_.size(); |
87 | } |
88 | |
89 | @@ -299,12 +297,9 @@ |
90 | return hotspot_; |
91 | } |
92 | |
93 | -const Image& NonPackedAnimation::representative_image(const RGBColor& clr) const { |
94 | - return get_frame(0, &clr); |
95 | -} |
96 | - |
97 | const Image& NonPackedAnimation::representative_image_from_disk() const { |
98 | - return get_frame(0, nullptr); |
99 | + ensure_graphics_are_loaded(); |
100 | + return *frames_[0]; |
101 | } |
102 | |
103 | void NonPackedAnimation::trigger_soundfx(uint32_t time, uint32_t stereo_position) const { |
104 | @@ -322,24 +317,22 @@ |
105 | { |
106 | assert(target); |
107 | |
108 | - const Image& frame = get_frame(time, clr); |
109 | - target->blit( |
110 | - Rect(dst.x, dst.y, srcrc.w, srcrc.h), frame.texture(), srcrc, 1., BlendMode::UseAlpha); |
111 | -} |
112 | + const int idx = time / frametime_ % nr_frames(); |
113 | + assert(idx < nr_frames()); |
114 | |
115 | -const Image& NonPackedAnimation::get_frame(uint32_t time, const RGBColor* playercolor) const { |
116 | - if (frames_.empty()) { |
117 | - const_cast<NonPackedAnimation*>(this)->load_graphics(); |
118 | + if (!hasplrclrs_ || clr == nullptr) { |
119 | + target->blit(Rect(dst.x, dst.y, srcrc.w, srcrc.h), |
120 | + frames_.at(idx)->texture(), |
121 | + srcrc, |
122 | + 1., |
123 | + BlendMode::UseAlpha); |
124 | + } else { |
125 | + target->blit_blended(Rect(dst.x, dst.y, srcrc.w, srcrc.h), |
126 | + frames_.at(idx)->texture(), |
127 | + pcmasks_.at(idx)->texture(), |
128 | + srcrc, |
129 | + *clr); |
130 | } |
131 | - const uint32_t framenumber = time / frametime_ % nr_frames(); |
132 | - assert(framenumber < nr_frames()); |
133 | - const Image* original = frames_[framenumber]; |
134 | - |
135 | - if (!hasplrclrs_ || !playercolor) |
136 | - return *original; |
137 | - |
138 | - assert(frames_.size() == pcmasks_.size()); |
139 | - return *ImageTransformations::player_colored(*playercolor, original, pcmasks_[framenumber]); |
140 | } |
141 | |
142 | } // namespace |
143 | |
144 | === modified file 'src/graphic/animation.h' |
145 | --- src/graphic/animation.h 2014-07-14 19:48:07 +0000 |
146 | +++ src/graphic/animation.h 2014-12-08 07:41:03 +0000 |
147 | @@ -68,11 +68,6 @@ |
148 | /// so the caller has to adjust for the hotspot himself. |
149 | virtual const Point& hotspot() const = 0; |
150 | |
151 | - // An image frame that shows the first animation frame, colored using the |
152 | - // 'player_clr'. This can be used in the UI (e.g. buildingwindow) to |
153 | - // represent this image. |
154 | - virtual const Image& representative_image(const RGBColor& player_clr) const = 0; |
155 | - |
156 | // An image frame that is guaranteed to be a path to a file on disc. This is |
157 | // a clutch needed to make sure that messages can always be displayed, even |
158 | // no image processing has taken place before. |
159 | |
160 | === modified file 'src/graphic/gl/blit_program.cc' |
161 | --- src/graphic/gl/blit_program.cc 2014-12-04 09:00:20 +0000 |
162 | +++ src/graphic/gl/blit_program.cc 2014-12-08 07:41:03 +0000 |
163 | @@ -58,21 +58,44 @@ |
164 | } |
165 | )"; |
166 | |
167 | -const char kGrayBlitFragmentShader[] = R"( |
168 | -#version 120 |
169 | - |
170 | -uniform float u_luminosity_factor; |
171 | -uniform float u_opacity; |
172 | -uniform sampler2D u_texture; |
173 | - |
174 | -varying vec2 out_texture_coordinate; |
175 | - |
176 | -void main() { |
177 | - vec4 texture_color = texture2D(u_texture, out_texture_coordinate); |
178 | - // See http://en.wikipedia.org/wiki/YUV. |
179 | - float luminance = dot(vec3(0.299, 0.587, 0.114), texture_color.rgb) * u_luminosity_factor; |
180 | - |
181 | - gl_FragColor = vec4(vec3(luminance), u_opacity * texture_color.a); |
182 | +const char kMonochromeBlitFragmentShader[] = R"( |
183 | +#version 120 |
184 | + |
185 | +uniform float u_opacity; |
186 | +uniform sampler2D u_texture; |
187 | +uniform vec3 u_blend; |
188 | + |
189 | +varying vec2 out_texture_coordinate; |
190 | + |
191 | +void main() { |
192 | + vec4 texture_color = texture2D(u_texture, out_texture_coordinate); |
193 | + |
194 | + // See http://en.wikipedia.org/wiki/YUV. |
195 | + float luminance = dot(vec3(0.299, 0.587, 0.114), texture_color.rgb); |
196 | + |
197 | + gl_FragColor = vec4(vec3(luminance) * u_blend, u_opacity * texture_color.a); |
198 | +} |
199 | +)"; |
200 | + |
201 | +const char kBlendedBlitFragmentShader[] = R"( |
202 | +#version 120 |
203 | + |
204 | +uniform float u_opacity; |
205 | +uniform sampler2D u_texture; |
206 | +uniform sampler2D u_mask; |
207 | +uniform vec3 u_blend; |
208 | + |
209 | +varying vec2 out_texture_coordinate; |
210 | + |
211 | +void main() { |
212 | + vec4 texture_color = texture2D(u_texture, out_texture_coordinate); |
213 | + vec4 mask_color = texture2D(u_mask, out_texture_coordinate); |
214 | + |
215 | + // See http://en.wikipedia.org/wiki/YUV. |
216 | + float luminance = dot(vec3(0.299, 0.587, 0.114), texture_color.rgb); |
217 | + float blend_influence = mask_color.r * mask_color.a; |
218 | + gl_FragColor = vec4( |
219 | + mix(texture_color.rgb, u_blend * luminance, blend_influence), u_opacity * texture_color.a); |
220 | } |
221 | )"; |
222 | |
223 | @@ -215,28 +238,64 @@ |
224 | } |
225 | |
226 | // static |
227 | -GrayBlitProgram& GrayBlitProgram::instance() { |
228 | - static GrayBlitProgram blit_program; |
229 | +MonochromeBlitProgram& MonochromeBlitProgram::instance() { |
230 | + static MonochromeBlitProgram blit_program; |
231 | return blit_program; |
232 | } |
233 | |
234 | -GrayBlitProgram::~GrayBlitProgram() { |
235 | -} |
236 | - |
237 | -GrayBlitProgram::GrayBlitProgram() { |
238 | - blit_program_.reset(new BlitProgram(kGrayBlitFragmentShader)); |
239 | - |
240 | - u_luminosity_factor_ = glGetUniformLocation(blit_program_->program_object(), "u_luminosity_factor"); |
241 | -} |
242 | - |
243 | -void GrayBlitProgram::draw(const FloatRect& gl_dest_rect, |
244 | +MonochromeBlitProgram::~MonochromeBlitProgram() { |
245 | +} |
246 | + |
247 | +MonochromeBlitProgram::MonochromeBlitProgram() { |
248 | + blit_program_.reset(new BlitProgram(kMonochromeBlitFragmentShader)); |
249 | + |
250 | + u_blend_ = glGetUniformLocation(blit_program_->program_object(), "u_blend"); |
251 | +} |
252 | + |
253 | +void MonochromeBlitProgram::draw(const FloatRect& gl_dest_rect, |
254 | const FloatRect& gl_src_rect, |
255 | const GLuint gl_texture, |
256 | - const float opacity, |
257 | - const float luminosity_factor) { |
258 | - blit_program_->activate(gl_dest_rect, gl_src_rect, gl_texture, opacity, BlendMode::UseAlpha); |
259 | - |
260 | - glUniform1f(u_luminosity_factor_, luminosity_factor); |
261 | - |
262 | - blit_program_->draw_and_deactivate(BlendMode::UseAlpha); |
263 | + const RGBAColor& blend) { |
264 | + blit_program_->activate(gl_dest_rect, gl_src_rect, gl_texture, blend.a / 255., BlendMode::UseAlpha); |
265 | + |
266 | + glUniform3f(u_blend_, blend.r / 255., blend.g / 255., blend.b / 255.); |
267 | + |
268 | + blit_program_->draw_and_deactivate(BlendMode::UseAlpha); |
269 | +} |
270 | + |
271 | +// static |
272 | +BlendedBlitProgram& BlendedBlitProgram::instance() { |
273 | + static BlendedBlitProgram blit_program; |
274 | + return blit_program; |
275 | +} |
276 | + |
277 | +BlendedBlitProgram::~BlendedBlitProgram() { |
278 | +} |
279 | + |
280 | +BlendedBlitProgram::BlendedBlitProgram() { |
281 | + blit_program_.reset(new BlitProgram(kBlendedBlitFragmentShader)); |
282 | + u_blend_ = glGetUniformLocation(blit_program_->program_object(), "u_blend"); |
283 | + u_mask_ = glGetUniformLocation(blit_program_->program_object(), "u_mask"); |
284 | +} |
285 | + |
286 | +void BlendedBlitProgram::draw(const FloatRect& gl_dest_rect, |
287 | + const FloatRect& gl_src_rect, |
288 | + const GLuint gl_texture_image, |
289 | + const GLuint gl_texture_mask, |
290 | + const RGBAColor& blend) { |
291 | + blit_program_->activate(gl_dest_rect, gl_src_rect, gl_texture_image, blend.a / 255., BlendMode::UseAlpha); |
292 | + |
293 | + glActiveTexture(GL_TEXTURE1); |
294 | + glBindTexture(GL_TEXTURE_2D, gl_texture_mask); |
295 | + glUniform1i(u_mask_, 1); |
296 | + |
297 | + glUniform3f(u_blend_, blend.r / 255., blend.g / 255., blend.b / 255.); |
298 | + |
299 | + blit_program_->draw_and_deactivate(BlendMode::UseAlpha); |
300 | + |
301 | + glActiveTexture(GL_TEXTURE1); |
302 | + glBindTexture(GL_TEXTURE_2D, 0); |
303 | + |
304 | + glActiveTexture(GL_TEXTURE0); |
305 | + glBindTexture(GL_TEXTURE_2D, 0); |
306 | } |
307 | |
308 | === modified file 'src/graphic/gl/blit_program.h' |
309 | --- src/graphic/gl/blit_program.h 2014-12-04 09:00:20 +0000 |
310 | +++ src/graphic/gl/blit_program.h 2014-12-08 07:41:03 +0000 |
311 | @@ -55,32 +55,58 @@ |
312 | DISALLOW_COPY_AND_ASSIGN(VanillaBlitProgram); |
313 | }; |
314 | |
315 | -class GrayBlitProgram { |
316 | +class MonochromeBlitProgram { |
317 | public: |
318 | // Returns the (singleton) instance of this class. |
319 | - static GrayBlitProgram& instance(); |
320 | - ~GrayBlitProgram(); |
321 | + static MonochromeBlitProgram& instance(); |
322 | + ~MonochromeBlitProgram(); |
323 | |
324 | // Draws the rectangle 'gl_src_rect' from the texture with the name |
325 | // 'gl_texture' to 'gl_dest_rect' in the currently bound framebuffer. All |
326 | - // coordinates are in the OpenGL frame. The 'blend_mode' defines if the |
327 | - // values are copied or if alpha values are used. |
328 | - // The image is converted to grayscale during blit. |
329 | + // coordinates are in the OpenGL frame. The image is first converted to |
330 | + // luminance, then all values are multiplied with blend. |
331 | void draw(const FloatRect& gl_dest_rect, |
332 | const FloatRect& gl_src_rect, |
333 | const GLuint gl_texture, |
334 | - float opacity, |
335 | - float luminosity_factor); |
336 | - |
337 | -private: |
338 | - GrayBlitProgram(); |
339 | - |
340 | - std::unique_ptr<BlitProgram> blit_program_; |
341 | - |
342 | - // Uniforms. |
343 | - GLint u_luminosity_factor_; |
344 | - |
345 | - DISALLOW_COPY_AND_ASSIGN(GrayBlitProgram); |
346 | + const RGBAColor& blend); |
347 | + |
348 | +private: |
349 | + MonochromeBlitProgram(); |
350 | + |
351 | + std::unique_ptr<BlitProgram> blit_program_; |
352 | + |
353 | + // Uniforms. |
354 | + GLint u_blend_; |
355 | + |
356 | + DISALLOW_COPY_AND_ASSIGN(MonochromeBlitProgram); |
357 | +}; |
358 | + |
359 | +class BlendedBlitProgram { |
360 | +public: |
361 | + // Returns the (singleton) instance of this class. |
362 | + static BlendedBlitProgram& instance(); |
363 | + ~BlendedBlitProgram(); |
364 | + |
365 | + // Draws the rectangle 'gl_src_rect' from the texture with the name |
366 | + // 'gl_texture_image' to 'gl_dest_rect' in the currently bound framebuffer. All |
367 | + // coordinates are in the OpenGL frame. The 'gl_texture_mask' is used to selectively apply |
368 | + // the 'blend'. This is used for blitting player colored images. |
369 | + void draw(const FloatRect& gl_dest_rect, |
370 | + const FloatRect& gl_src_rect, |
371 | + const GLuint gl_texture_image, |
372 | + const GLuint gl_texture_mask, |
373 | + const RGBAColor& blend); |
374 | + |
375 | +private: |
376 | + BlendedBlitProgram(); |
377 | + |
378 | + std::unique_ptr<BlitProgram> blit_program_; |
379 | + |
380 | + // Uniforms. |
381 | + GLint u_blend_; |
382 | + GLint u_mask_; |
383 | + |
384 | + DISALLOW_COPY_AND_ASSIGN(BlendedBlitProgram); |
385 | }; |
386 | |
387 | #endif // end of include guard: WL_GRAPHIC_GL_DRAW_RECT_PROGRAM_H |
388 | |
389 | === modified file 'src/graphic/graphic.cc' |
390 | --- src/graphic/graphic.cc 2014-12-07 10:31:12 +0000 |
391 | +++ src/graphic/graphic.cc 2014-12-08 07:41:03 +0000 |
392 | @@ -27,7 +27,6 @@ |
393 | #include "graphic/gl/system_headers.h" |
394 | #include "graphic/image.h" |
395 | #include "graphic/image_io.h" |
396 | -#include "graphic/image_transformations.h" |
397 | #include "graphic/rendertarget.h" |
398 | #include "graphic/screen.h" |
399 | #include "graphic/texture.h" |
400 | @@ -71,8 +70,6 @@ |
401 | image_cache_(new ImageCache(texture_cache_.get())), |
402 | animation_manager_(new AnimationManager()) |
403 | { |
404 | - ImageTransformations::initialize(); |
405 | - |
406 | // Request an OpenGL 2 context with double buffering. |
407 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
408 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
409 | |
410 | === removed file 'src/graphic/image_transformations.cc' |
411 | --- src/graphic/image_transformations.cc 2014-12-07 10:31:12 +0000 |
412 | +++ src/graphic/image_transformations.cc 1970-01-01 00:00:00 +0000 |
413 | @@ -1,186 +0,0 @@ |
414 | -/* |
415 | - * Copyright (C) 2006-2013 by the Widelands Development Team |
416 | - * |
417 | - * This program is free software; you can redistribute it and/or |
418 | - * modify it under the terms of the GNU General Public License |
419 | - * as published by the Free Software Foundation; either version 2 |
420 | - * of the License, or (at your option) any later version. |
421 | - * |
422 | - * This program is distributed in the hope that it will be useful, |
423 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
424 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
425 | - * GNU General Public License for more details. |
426 | - * |
427 | - * You should have received a copy of the GNU General Public License |
428 | - * along with this program; if not, write to the Free Software |
429 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
430 | - * |
431 | - */ |
432 | - |
433 | -#include "graphic/image_transformations.h" |
434 | - |
435 | -#include <string> |
436 | - |
437 | -#include <SDL.h> |
438 | -#include <boost/format.hpp> |
439 | - |
440 | -#include "base/macros.h" |
441 | -#include "graphic/color.h" |
442 | -#include "graphic/graphic.h" |
443 | -#include "graphic/texture.h" |
444 | -#include "graphic/texture_cache.h" |
445 | - |
446 | -using namespace std; |
447 | - |
448 | -namespace { |
449 | - |
450 | -// This table is used to transform colors. |
451 | -uint32_t luminance_table_r[0x100]; |
452 | -uint32_t luminance_table_g[0x100]; |
453 | -uint32_t luminance_table_b[0x100]; |
454 | - |
455 | -// Encodes the given Image into the corresponding image for player color. |
456 | -// Takes the neutral set of images and the player color mask. |
457 | -Texture* make_playerclr_texture(Texture& original_texture, |
458 | - Texture& pcmask_texture, |
459 | - const RGBColor& color) { |
460 | - Texture* new_texture = new Texture(original_texture.width(), original_texture.height()); |
461 | - |
462 | - const SDL_PixelFormat & fmt = original_texture.format(); |
463 | - const SDL_PixelFormat & fmt_pc = pcmask_texture.format(); |
464 | - const SDL_PixelFormat & destfmt = new_texture->format(); |
465 | - |
466 | - original_texture.lock(Surface::Lock_Normal); |
467 | - pcmask_texture.lock(Surface::Lock_Normal); |
468 | - new_texture->lock(Surface::Lock_Discard); |
469 | - // This could be done significantly faster, but since we |
470 | - // cache the result, let's keep it simple for now. |
471 | - for (uint32_t y = 0; y < original_texture.height(); ++y) { |
472 | - for (uint32_t x = 0; x < original_texture.width(); ++x) { |
473 | - RGBAColor source; |
474 | - RGBAColor mask; |
475 | - RGBAColor product; |
476 | - |
477 | - source.set(fmt, original_texture.get_pixel(x, y)); |
478 | - mask.set(fmt_pc, pcmask_texture.get_pixel(x, y)); |
479 | - |
480 | - if |
481 | - (uint32_t const influence = |
482 | - static_cast<uint32_t>(mask.r) * mask.a) |
483 | - { |
484 | - uint32_t const intensity = |
485 | - (luminance_table_r[source.r] + |
486 | - luminance_table_g[source.g] + |
487 | - luminance_table_b[source.b] + |
488 | - 8388608U) // compensate for truncation: .5 * 2^24 |
489 | - >> 24; |
490 | - RGBAColor plrclr; |
491 | - |
492 | - plrclr.r = (color.r * intensity) >> 8; |
493 | - plrclr.g = (color.g * intensity) >> 8; |
494 | - plrclr.b = (color.b * intensity) >> 8; |
495 | - |
496 | - product.r = |
497 | - (plrclr.r * influence + source.r * (65536 - influence)) >> 16; |
498 | - product.g = |
499 | - (plrclr.g * influence + source.g * (65536 - influence)) >> 16; |
500 | - product.b = |
501 | - (plrclr.b * influence + source.b * (65536 - influence)) >> 16; |
502 | - product.a = source.a; |
503 | - } else { |
504 | - product = source; |
505 | - } |
506 | - |
507 | - new_texture->set_pixel(x, y, product.map(destfmt)); |
508 | - } |
509 | - } |
510 | - original_texture.unlock(Surface::Unlock_NoChange); |
511 | - pcmask_texture.unlock(Surface::Unlock_NoChange); |
512 | - new_texture->unlock(Surface::Unlock_Update); |
513 | - |
514 | - return new_texture; |
515 | -} |
516 | - |
517 | -// An Image implementation that is the transformation of another Image. Uses |
518 | -// the TextureCache to avoid recalculating the transformation too often. No |
519 | -// ownerships are taken. |
520 | -class TransformedImage : public Image { |
521 | -public: |
522 | - TransformedImage(const string& ghash, const Image& original, TextureCache* texture_cache) : |
523 | - hash_(ghash), original_(original), texture_cache_(texture_cache) {} |
524 | - virtual ~TransformedImage() {} |
525 | - |
526 | - // Implements Image. |
527 | - uint16_t width() const override {return original_.width();} |
528 | - uint16_t height() const override {return original_.height();} |
529 | - const string& hash() const override {return hash_;} |
530 | - Texture* texture() const override { |
531 | - Texture* result = texture_cache_->get(hash_); |
532 | - if (result) { |
533 | - return result; |
534 | - } |
535 | - |
536 | - result = recalculate_texture(); |
537 | - texture_cache_->insert(hash_, result, true); |
538 | - return result; |
539 | - } |
540 | - |
541 | - virtual Texture* recalculate_texture() const = 0; |
542 | - |
543 | -protected: |
544 | - const string hash_; |
545 | - const Image& original_; |
546 | - TextureCache* const texture_cache_; // not owned |
547 | -}; |
548 | - |
549 | -// A copy with applied player colors. Also needs a mask - ownership is not |
550 | -// taken. |
551 | -class PlayerColoredImage : public TransformedImage { |
552 | -public: |
553 | - PlayerColoredImage |
554 | - (const string& ghash, const Image& original, |
555 | - TextureCache* texture_cache, const RGBColor& color, const Image& mask) |
556 | - : TransformedImage(ghash, original, texture_cache), color_(color), mask_(mask) |
557 | - {} |
558 | - virtual ~PlayerColoredImage() {} |
559 | - |
560 | - // Implements TransformedImage. |
561 | - Texture* recalculate_texture() const override { |
562 | - return make_playerclr_texture(*original_.texture(), *mask_.texture(), color_); |
563 | - } |
564 | - |
565 | -private: |
566 | - const RGBColor& color_; |
567 | - const Image& mask_; |
568 | -}; |
569 | - |
570 | -} |
571 | - |
572 | -namespace ImageTransformations { |
573 | - |
574 | -void initialize() { |
575 | - // Initialize the table used to create grayed image |
576 | - for |
577 | - (uint32_t i = 0, r = 0, g = 0, b = 0; |
578 | - i < 0x100; |
579 | - ++i, r += 5016388U, g += 9848226U, b += 1912603U) |
580 | - { |
581 | - luminance_table_r[i] = r; |
582 | - luminance_table_g[i] = g; |
583 | - luminance_table_b[i] = b; |
584 | - } |
585 | -} |
586 | - |
587 | -const Image* player_colored(const RGBColor& clr, const Image* original, const Image* mask) { |
588 | - const string new_hash = |
589 | - (boost::format("%s:%02x%02x%02x") % original->hash() % static_cast<int>(clr.r) % |
590 | - static_cast<int>(clr.g) % static_cast<int>(clr.b)) |
591 | - .str(); |
592 | - if (g_gr->images().has(new_hash)) |
593 | - return g_gr->images().get(new_hash); |
594 | - return |
595 | - g_gr->images().insert |
596 | - (new PlayerColoredImage(new_hash, *original, &g_gr->textures(), clr, *mask)); |
597 | -} |
598 | - |
599 | -} // namespace ImageTransformations |
600 | |
601 | === removed file 'src/graphic/image_transformations.h' |
602 | --- src/graphic/image_transformations.h 2014-12-04 09:18:03 +0000 |
603 | +++ src/graphic/image_transformations.h 1970-01-01 00:00:00 +0000 |
604 | @@ -1,47 +0,0 @@ |
605 | -/* |
606 | - * Copyright (C) 2006-2013 by the Widelands Development Team |
607 | - * |
608 | - * This program is free software; you can redistribute it and/or |
609 | - * modify it under the terms of the GNU General Public License |
610 | - * as published by the Free Software Foundation; either version 2 |
611 | - * of the License, or (at your option) any later version. |
612 | - * |
613 | - * This program is distributed in the hope that it will be useful, |
614 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
615 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
616 | - * GNU General Public License for more details. |
617 | - * |
618 | - * You should have received a copy of the GNU General Public License |
619 | - * along with this program; if not, write to the Free Software |
620 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
621 | - * |
622 | - */ |
623 | - |
624 | -#ifndef WL_GRAPHIC_IMAGE_TRANSFORMATIONS_H |
625 | -#define WL_GRAPHIC_IMAGE_TRANSFORMATIONS_H |
626 | - |
627 | -#include <stdint.h> |
628 | - |
629 | -struct RGBColor; |
630 | -class Image; |
631 | - |
632 | -// A set of image transformations used in Widelands. |
633 | -namespace ImageTransformations { |
634 | - |
635 | -// This must be called once before any of the functions below are called. This |
636 | -// is done when the graphics system is initialized. |
637 | -void initialize(); |
638 | - |
639 | -// All of the functions below take an original image, transform it, cache the |
640 | -// newly created image in the global ImageCache and return it. It is therefore |
641 | -// safe to call the methods with the same arguments multiple times without |
642 | -// construction cost. |
643 | - |
644 | -// Encodes the given Image into the corresponding image with a player color. |
645 | -// Takes the image and the player color mask and the new color the image should |
646 | -// be tainted in. |
647 | -const Image* player_colored(const RGBColor& clr, const Image* original, const Image* mask); |
648 | -} |
649 | - |
650 | - |
651 | -#endif // end of include guard: WL_GRAPHIC_IMAGE_TRANSFORMATIONS_H |
652 | |
653 | === modified file 'src/graphic/rendertarget.cc' |
654 | --- src/graphic/rendertarget.cc 2014-12-04 21:02:35 +0000 |
655 | +++ src/graphic/rendertarget.cc 2014-12-08 07:41:03 +0000 |
656 | @@ -221,20 +221,18 @@ |
657 | } |
658 | } |
659 | |
660 | -void RenderTarget::blitrect_scale_gray(const Rect& destination_rect, |
661 | +void RenderTarget::blitrect_scale_monochrome(const Rect& destination_rect, |
662 | const Image* image, |
663 | const Rect& source_rect, |
664 | - float opacity, |
665 | - float luminosity_factor) { |
666 | + const RGBAColor& blend) { |
667 | Point destination_point(destination_rect.x, destination_rect.y); |
668 | Rect srcrect(source_rect); |
669 | if (to_surface_geometry(&destination_point, &srcrect)) { |
670 | - m_surface->blit_gray( |
671 | + m_surface->blit_monochrome( |
672 | Rect(destination_point.x, destination_point.y, destination_rect.w, destination_rect.h), |
673 | image->texture(), |
674 | source_rect, |
675 | - opacity, |
676 | - luminosity_factor); |
677 | + blend); |
678 | } |
679 | } |
680 | |
681 | |
682 | === modified file 'src/graphic/rendertarget.h' |
683 | --- src/graphic/rendertarget.h 2014-12-04 09:00:20 +0000 |
684 | +++ src/graphic/rendertarget.h 2014-12-08 07:41:03 +0000 |
685 | @@ -87,15 +87,11 @@ |
686 | float opacity, |
687 | BlendMode blend_mode); |
688 | |
689 | - // Like blitrect_scale, but the image is converted to grayscale |
690 | - // and all grayscale values are multiplied with |
691 | - // 'luminosity_factor' to make the image brighter or darker. Alpha |
692 | - // is always used on blending. |
693 | - void blitrect_scale_gray(const Rect& destination_rect, |
694 | - const Image* image, |
695 | - const Rect& source_rect, |
696 | - float opacity, |
697 | - float luminosity_factor); |
698 | + // Like blitrect_scale. See MonochromeBlitProgram for details. |
699 | + void blitrect_scale_monochrome(const Rect& destination_rect, |
700 | + const Image* image, |
701 | + const Rect& source_rect, |
702 | + const RGBAColor& blend); |
703 | |
704 | void tile(const Rect&, |
705 | const Image* image, |
706 | |
707 | === modified file 'src/graphic/surface.cc' |
708 | --- src/graphic/surface.cc 2014-12-04 09:00:20 +0000 |
709 | +++ src/graphic/surface.cc 2014-12-08 07:41:03 +0000 |
710 | @@ -200,16 +200,27 @@ |
711 | gl_dst_rect, gl_src_rect, texture->get_gl_texture(), opacity, blend_mode); |
712 | } |
713 | |
714 | -void Surface::blit_gray(const Rect& dst_rect, |
715 | - const Texture* texture, |
716 | - const Rect& src_rect, |
717 | - const float opacity, |
718 | - float opacity_factor) { |
719 | +void Surface::blit_monochrome(const Rect& dst_rect, |
720 | + const Texture* texture, |
721 | + const Rect& src_rect, |
722 | + const RGBAColor& blend) { |
723 | glViewport(0, 0, width(), height()); |
724 | |
725 | FloatRect gl_dst_rect, gl_src_rect; |
726 | src_and_dst_rect_to_gl(texture, dst_rect, src_rect, &gl_dst_rect, &gl_src_rect); |
727 | |
728 | - GrayBlitProgram::instance().draw( |
729 | - gl_dst_rect, gl_src_rect, texture->get_gl_texture(), opacity, opacity_factor); |
730 | + MonochromeBlitProgram::instance().draw( |
731 | + gl_dst_rect, gl_src_rect, texture->get_gl_texture(), blend); |
732 | +} |
733 | + |
734 | +void Surface::blit_blended(const Rect& dst_rect, |
735 | + const Texture* texture, |
736 | + const Texture* mask, |
737 | + const Rect& src_rect, |
738 | + const RGBColor& blend) { |
739 | + FloatRect gl_dst_rect, gl_src_rect; |
740 | + src_and_dst_rect_to_gl(texture, dst_rect, src_rect, &gl_dst_rect, &gl_src_rect); |
741 | + |
742 | + BlendedBlitProgram::instance().draw( |
743 | + gl_dst_rect, gl_src_rect, texture->get_gl_texture(), mask->get_gl_texture(), blend); |
744 | } |
745 | |
746 | === modified file 'src/graphic/surface.h' |
747 | --- src/graphic/surface.h 2014-12-04 09:00:20 +0000 |
748 | +++ src/graphic/surface.h 2014-12-08 07:41:03 +0000 |
749 | @@ -49,12 +49,18 @@ |
750 | const float opacity, |
751 | BlendMode blend_mode); |
752 | |
753 | - /// This draws a grayed out version. |
754 | - virtual void blit_gray(const Rect& dst, |
755 | + /// This draws a grayed out version. See MonochromeBlitProgram. |
756 | + virtual void blit_monochrome(const Rect& dst, |
757 | const Texture*, |
758 | const Rect& srcrc, |
759 | - const float opacity, |
760 | - float opacity_factor); |
761 | + const RGBAColor& multiplier); |
762 | + |
763 | + /// This draws a playercolor blended image. See BlendedBlitProgram. |
764 | + virtual void blit_blended(const Rect& dst, |
765 | + const Texture* image, |
766 | + const Texture* mask, |
767 | + const Rect& srcrc, |
768 | + const RGBColor& blend); |
769 | |
770 | /// Draws a filled rect to the surface. No blending takes place, the values |
771 | // in the target are just replaced (i.e. / BlendMode would be BlendMode::Copy). |
772 | |
773 | === modified file 'src/graphic/texture.cc' |
774 | --- src/graphic/texture.cc 2014-12-04 09:00:20 +0000 |
775 | +++ src/graphic/texture.cc 2014-12-08 07:41:03 +0000 |
776 | @@ -276,16 +276,29 @@ |
777 | reset_gl(); |
778 | } |
779 | |
780 | -void Texture::blit_gray(const Rect& dst, |
781 | +void Texture::blit_monochrome(const Rect& dst, |
782 | const Texture* src, |
783 | const Rect& srcrc, |
784 | - float opacity, |
785 | - const float opacity_factor) { |
786 | - if (m_w <= 0 || m_h <= 0) { |
787 | - return; |
788 | - } |
789 | - |
790 | - setup_gl(m_texture); |
791 | - Surface::blit_gray(dst, src, srcrc, opacity, opacity_factor); |
792 | + const RGBAColor& blend) { |
793 | + if (m_w <= 0 || m_h <= 0) { |
794 | + return; |
795 | + } |
796 | + |
797 | + setup_gl(m_texture); |
798 | + Surface::blit_monochrome(dst, src, srcrc, blend); |
799 | + reset_gl(); |
800 | +} |
801 | + |
802 | +void Texture::blit_blended(const Rect& dst, |
803 | + const Texture* image, |
804 | + const Texture* mask, |
805 | + const Rect& srcrc, |
806 | + const RGBColor& blend) { |
807 | + if (m_w <= 0 || m_h <= 0) { |
808 | + return; |
809 | + } |
810 | + |
811 | + setup_gl(m_texture); |
812 | + Surface::blit_blended(dst, image, mask, srcrc, blend); |
813 | reset_gl(); |
814 | } |
815 | |
816 | === modified file 'src/graphic/texture.h' |
817 | --- src/graphic/texture.h 2014-12-04 09:00:20 +0000 |
818 | +++ src/graphic/texture.h 2014-12-08 07:41:03 +0000 |
819 | @@ -63,11 +63,13 @@ |
820 | const Rect& srcrc, |
821 | float opacity, |
822 | BlendMode blend_mode) override; |
823 | - void blit_gray(const Rect& dst, |
824 | - const Texture*, |
825 | - const Rect& srcrc, |
826 | - const float opacity, |
827 | - float opacity_factor) override; |
828 | + void |
829 | + blit_monochrome(const Rect& dst, const Texture*, const Rect& srcrc, const RGBAColor& blend) override; |
830 | + void blit_blended(const Rect& dst, |
831 | + const Texture* image, |
832 | + const Texture* mask, |
833 | + const Rect& srcrc, |
834 | + const RGBColor& blend) override; |
835 | |
836 | GLuint get_gl_texture() const {return m_texture;} |
837 | |
838 | |
839 | === modified file 'src/ui_basic/button.cc' |
840 | --- src/ui_basic/button.cc 2014-12-04 09:18:03 +0000 |
841 | +++ src/ui_basic/button.cc 2014-12-08 07:41:03 +0000 |
842 | @@ -185,12 +185,11 @@ |
843 | 1., |
844 | BlendMode::UseAlpha); |
845 | } else { |
846 | - dst.blitrect_scale_gray( |
847 | + dst.blitrect_scale_monochrome( |
848 | Rect((get_w() - blit_width) / 2, (get_h() - blit_height) / 2, blit_width, blit_height), |
849 | m_pic_custom, |
850 | Rect(0, 0, m_pic_custom->width(), m_pic_custom->height()), |
851 | - 0.5 /* opacity */, |
852 | - 1. /* luminosity_factor */); |
853 | + RGBAColor(255, 255, 255, 127)); |
854 | } |
855 | |
856 | } else if (m_title.length()) { |
857 | |
858 | === modified file 'src/wui/buildingwindow.cc' |
859 | --- src/wui/buildingwindow.cc 2014-12-04 09:18:03 +0000 |
860 | +++ src/wui/buildingwindow.cc 2014-12-08 07:41:03 +0000 |
861 | @@ -114,16 +114,15 @@ |
862 | { |
863 | UI::Window::draw(dst); |
864 | |
865 | + // TODO(sirver): chang this to directly blit the animation. This needs support for or removal of |
866 | + // RenderTarget. |
867 | const Animation& anim = g_gr->animations().get_animation(building().get_ui_anim()); |
868 | - |
869 | - const Image* image = |
870 | - &anim.representative_image(building().owner().get_playercolor()); |
871 | - |
872 | + const Image* image = &anim.representative_image_from_disk(); |
873 | dst.blitrect_scale(Rect((get_inner_w() - image->width()) / 2, |
874 | (get_inner_h() - image->height()) / 2, |
875 | image->width(), |
876 | image->height()), |
877 | - image, |
878 | + &anim.representative_image_from_disk(), |
879 | Rect(0, 0, image->width(), image->height()), |
880 | 0.5, |
881 | BlendMode::UseAlpha); |
882 | |
883 | === modified file 'src/wui/fieldaction.cc' |
884 | --- src/wui/fieldaction.cc 2014-12-04 09:18:03 +0000 |
885 | +++ src/wui/fieldaction.cc 2014-12-08 07:41:03 +0000 |
886 | @@ -56,7 +56,6 @@ |
887 | // The BuildGrid presents a selection of buildable buildings |
888 | struct BuildGrid : public UI::IconGrid { |
889 | BuildGrid(UI::Panel* parent, |
890 | - const RGBColor& player_color, |
891 | const Widelands::TribeDescr& tribe, |
892 | int32_t x, |
893 | int32_t y, |
894 | @@ -74,15 +73,13 @@ |
895 | void mousein_slot(int32_t idx); |
896 | |
897 | private: |
898 | - const RGBColor player_color_; |
899 | const Widelands::TribeDescr& tribe_; |
900 | }; |
901 | |
902 | BuildGrid::BuildGrid( |
903 | - UI::Panel* parent, const RGBColor& player_color, const Widelands::TribeDescr& tribe, |
904 | + UI::Panel* parent, const Widelands::TribeDescr& tribe, |
905 | int32_t x, int32_t y, int32_t cols) : |
906 | UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols), |
907 | - player_color_(player_color), |
908 | tribe_(tribe) |
909 | { |
910 | clicked.connect(boost::bind(&BuildGrid::click_slot, this, _1)); |
911 | @@ -99,13 +96,16 @@ |
912 | { |
913 | const Widelands::BuildingDescr & descr = |
914 | *tribe_.get_building_descr(Widelands::BuildingIndex(id)); |
915 | - UI::IconGrid::add( |
916 | - descr.name(), |
917 | - &g_gr->animations().get_animation(descr.get_animation("idle")).representative_image( |
918 | - player_color_), |
919 | - reinterpret_cast<void*>(id), |
920 | - descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" + |
921 | - waremap_to_richtext(tribe_, descr.buildcost())); |
922 | + // TODO(sirver): change this to take a Button subclass instead of |
923 | + // parameters. This will allow overriding the way it is rendered |
924 | + // to bring back player colors. |
925 | + UI::IconGrid::add(descr.name(), |
926 | + &g_gr->animations() |
927 | + .get_animation(descr.get_animation("idle")) |
928 | + .representative_image_from_disk(), |
929 | + reinterpret_cast<void*>(id), |
930 | + descr.descname() + "<br><font size=11>" + _("Construction costs:") + |
931 | + "</font><br>" + waremap_to_richtext(tribe_, descr.buildcost())); |
932 | } |
933 | |
934 | |
935 | @@ -175,7 +175,7 @@ |
936 | |
937 | void init(); |
938 | void add_buttons_auto(); |
939 | - void add_buttons_build(int32_t buildcaps, const RGBColor& player_color); |
940 | + void add_buttons_build(int32_t buildcaps); |
941 | void add_buttons_road(bool flag); |
942 | void add_buttons_attack(); |
943 | |
944 | @@ -392,7 +392,7 @@ |
945 | if ((buildcaps & Widelands::BUILDCAPS_SIZEMASK) || |
946 | (buildcaps & Widelands::BUILDCAPS_MINE)) { |
947 | assert(igbase->get_player()); |
948 | - add_buttons_build(buildcaps, igbase->get_player()->get_playercolor()); |
949 | + add_buttons_build(buildcaps); |
950 | } |
951 | |
952 | // Add build actions |
953 | @@ -488,7 +488,7 @@ |
954 | Add buttons for house building. |
955 | =============== |
956 | */ |
957 | -void FieldActionWindow::add_buttons_build(int32_t buildcaps, const RGBColor& player_color) |
958 | +void FieldActionWindow::add_buttons_build(int32_t buildcaps) |
959 | { |
960 | if (!m_plr) |
961 | return; |
962 | @@ -538,7 +538,7 @@ |
963 | |
964 | // Allocate the tab's grid if necessary |
965 | if (!*ppgrid) { |
966 | - *ppgrid = new BuildGrid(&m_tabpanel, player_color, tribe, 0, 0, 5); |
967 | + *ppgrid = new BuildGrid(&m_tabpanel, tribe, 0, 0, 5); |
968 | (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1)); |
969 | (*ppgrid)->buildmouseout.connect |
970 | (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1)); |
971 | |
972 | === modified file 'src/wui/waresqueuedisplay.cc' |
973 | --- src/wui/waresqueuedisplay.cc 2014-12-04 09:18:03 +0000 |
974 | +++ src/wui/waresqueuedisplay.cc 2014-12-08 07:41:03 +0000 |
975 | @@ -150,12 +150,10 @@ |
976 | BlendMode::UseAlpha); |
977 | } |
978 | for (; nr_empty_to_draw; --nr_empty_to_draw, point.x += CellWidth + CellSpacing) { |
979 | - dst.blitrect_scale_gray( |
980 | - Rect(point.x, point.y, m_icon->width(), m_icon->height()), |
981 | - m_icon, |
982 | - Rect(0, 0, m_icon->width(), m_icon->height()), |
983 | - 0.5, |
984 | - 0.65); |
985 | + dst.blitrect_scale_monochrome(Rect(point.x, point.y, m_icon->width(), m_icon->height()), |
986 | + m_icon, |
987 | + Rect(0, 0, m_icon->width(), m_icon->height()), |
988 | + RGBAColor(166, 166, 166, 127)); |
989 | } |
990 | |
991 | if (!m_show_only) { |
LGTM.
When bringing back the playercolors in the icon grid, remember to check if this bug is gone: https:/ /bugs.launchpad .net/widelands/ +bug/1370144