diff --git a/src/graphics.cpp b/src/graphics.cpp index 71a19b068..c7e320c50 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -93,7 +93,22 @@ image_32::~image_32() {} void image_32::set_grayscale_to_alpha() { + for (int y = 0; y < height_; ++y) + { + unsigned int* row_from = data_.getRow(y); + for (int x = 0; x < width_; ++x) + { + unsigned rgba = row_from[x]; + unsigned r = rgba & 0xff; + unsigned g = (rgba >> 8 ) & 0xff; + unsigned b = (rgba >> 16) & 0xff; + + // magic numbers for grayscale + unsigned a = (int)((r * .3) + (g * .59) + (b * .11)); + row_from[x] = (a << 24)| (255 << 16) | (255 << 8) | (255) ; + } + } } void image_32::set_color_to_alpha(const color& c) @@ -113,8 +128,7 @@ void image_32::set_alpha(float opacity) #ifdef MAPNIK_BIG_ENDIAN unsigned a0 = (rgba & 0xff); - //unsigned a1 = int( (rgba & 0xff) * opacity ); - unsigned a1 = opacity; + unsigned a1 = int( (rgba & 0xff) * opacity ); if (a0 == a1) continue; @@ -126,8 +140,8 @@ void image_32::set_alpha(float opacity) #else unsigned a0 = (rgba >> 24) & 0xff; - //unsigned a1 = int( ((rgba >> 24) & 0xff) * opacity ); - unsigned a1 = opacity; + unsigned a1 = int( ((rgba >> 24) & 0xff) * opacity ); + //unsigned a1 = opacity; if (a0 == a1) continue; unsigned r = rgba & 0xff;