Author: alink
Date: Fri Jun 22 15:14:12 2007
New Revision: 18380
URL: http://svn.gna.org/viewcvs/wesnoth?rev=18380&view=rev
Log:
copy paste the new blur code to a second version blurring alpha too (for
floating labels)
because I don't want to modify the code used for dialogue (and impact its
peformance)
This is a quick working hack, but need to be clean later and probably improve
the algorithm
about the color of fully tranparent pixels.
Modified:
trunk/src/sdl_utils.cpp
trunk/src/sdl_utils.hpp
Modified: trunk/src/sdl_utils.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.cpp?rev=18380&r1=18379&r2=18380&view=diff
==============================================================================
--- trunk/src/sdl_utils.cpp (original)
+++ trunk/src/sdl_utils.cpp Fri Jun 22 15:14:12 2007
@@ -813,6 +813,131 @@
return create_optimized_surface(res);
}
+// Cross-fades a surface with alpha channel
+// FIXME: This is just a adapted copy-paste of the normal blur
+// but with blur alpha channel too
+surface blur_alpha_surface(surface const &surf, int depth)
+{
+ if(surf == NULL) {
+ return NULL;
+ }
+
+ surface res = make_neutral_surface(surf);
+
+ if(res == NULL) {
+ std::cerr << "could not make neutral surface...\n";
+ return NULL;
+ }
+
+ const int max_blur = 256;
+ if(depth > max_blur) {
+ depth = max_blur;
+ }
+
+ Uint32 queue[max_blur];
+ const Uint32* end_queue = queue + max_blur;
+
+ const Uint32 ff = 0xff;
+
+ surface_lock lock(res);
+ int x, y;
+ for(y = 0; y < res->h; ++y) {
+ const Uint32* front = &queue[0];
+ Uint32* back = &queue[0];
+ Uint32 alpha=0, red = 0, green = 0, blue = 0, avg = 0;
+ Uint32* p = lock.pixels() + y*res->w;
+ for(x = 0; x <= depth && x < res->w; ++x, ++p) {
+ alpha += ((*p) >> 24)&0xFF;
+ red += ((*p) >> 16)&0xFF;
+ green += ((*p) >> 8)&0xFF;
+ blue += (*p)&0xFF;
+ ++avg;
+ *back++ = *p;
+ if(back == end_queue) {
+ back = &queue[0];
+ }
+ }
+
+ p = lock.pixels() + y*res->w;
+ for(x = 0; x < res->w; ++x, ++p) {
+ *p = (minimum(alpha/avg,ff) << 24) |
(minimum(red/avg,ff) << 16) | (minimum(green/avg,ff) << 8) |
minimum(blue/avg,ff);
+ if(x >= depth) {
+ alpha -= ((*front) >> 24)&0xFF;
+ red -= ((*front) >> 16)&0xFF;
+ green -= ((*front) >> 8)&0xFF;
+ blue -= *front&0xFF;
+ --avg;
+ ++front;
+ if(front == end_queue) {
+ front = &queue[0];
+ }
+ }
+
+ if(x + depth+1 < res->w) {
+ Uint32* q = p + depth+1;
+ alpha += ((*q) >> 24)&0xFF;
+ red += ((*q) >> 16)&0xFF;
+ green += ((*q) >> 8)&0xFF;
+ blue += (*q)&0xFF;
+ ++avg;
+ *back++ = *q;
+ if(back == end_queue) {
+ back = &queue[0];
+ }
+ }
+ }
+ }
+
+ for(x = 0; x < res->w; ++x) {
+ const Uint32* front = &queue[0];
+ Uint32* back = &queue[0];
+ Uint32 alpha=0, red = 0, green = 0, blue = 0, avg = 0;
+ Uint32* p = lock.pixels() + x;
+ for(y = 0; y <= depth && y < res->h; ++y, p += res->w) {
+ alpha += ((*p) >> 24)&0xFF;
+ red += ((*p) >> 16)&0xFF;
+ green += ((*p) >> 8)&0xFF;
+ blue += *p&0xFF;
+ ++avg;
+ *back++ = *p;
+ if(back == end_queue) {
+ back = &queue[0];
+ }
+ }
+
+ p = lock.pixels() + x;
+ for(y = 0; y < res->h; ++y, p += res->w) {
+ *p = (minimum(alpha/avg,ff) << 24) |
(minimum(red/avg,ff) << 16) | (minimum(green/avg,ff) << 8) |
minimum(blue/avg,ff);
+ if(y >= depth) {
+ alpha -= ((*front) >> 24)&0xFF;
+ red -= ((*front) >> 16)&0xFF;
+ green -= ((*front) >> 8)&0xFF;
+ blue -= *front&0xFF;
+ --avg;
+ ++front;
+ if(front == end_queue) {
+ front = &queue[0];
+ }
+ }
+
+ if(y + depth+1 < res->h) {
+ Uint32* q = p + (depth+1)*res->w;
+ alpha += ((*q) >> 24)&0xFF;
+ red += ((*q) >> 16)&0xFF;
+ green += ((*q) >> 8)&0xFF;
+ blue += (*q)&0xFF;
+ ++avg;
+ *back++ = *q;
+ if(back == end_queue) {
+ back = &queue[0];
+ }
+ }
+ }
+ }
+
+ return create_optimized_surface(res);
+}
+
// Cuts a rectangle from a surface.
surface cut_surface(surface const &surf, SDL_Rect const &r)
{
Modified: trunk/src/sdl_utils.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.hpp?rev=18380&r1=18379&r2=18380&view=diff
==============================================================================
--- trunk/src/sdl_utils.hpp (original)
+++ trunk/src/sdl_utils.hpp Fri Jun 22 15:14:12 2007
@@ -127,6 +127,7 @@
surface adjust_surface_alpha_add(surface const &surf, int amount);
surface mask_surface(surface const &surf, surface const &mask);
surface blur_surface(surface const &surf, int depth = 1);
+surface blur_alpha_surface(surface const &surf, int depth = 1);
surface cut_surface(surface const &surf, SDL_Rect const &r);
surface blend_surface(surface const &surf, double amount, Uint32 colour);
surface flip_surface(surface const &surf);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits