From 3a44dd3258c6f715d1e624e18118dd8f23ede326 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 11 Mar 2010 23:19:12 +0000 Subject: [PATCH] + use rint(v) instead of int(round(v)) + add rint implementation - msvc hasn't got one + minor cleanups --- include/mapnik/global.hpp | 9 +++++++++ include/mapnik/graphics.hpp | 16 ++++++++-------- include/mapnik/image_util.hpp | 8 ++++---- src/agg_renderer.cpp | 12 +++++++----- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/include/mapnik/global.hpp b/include/mapnik/global.hpp index 6802c94fa..63b7262b3 100644 --- a/include/mapnik/global.hpp +++ b/include/mapnik/global.hpp @@ -159,6 +159,15 @@ namespace mapnik #endif return val; } + +#ifdef _WINDOWS +// msvc doesn't have rint in +inline int rint( double val) +{ + return int(floor(val + 0.5)); +} +#endif + } #endif //GLOBAL_HPP diff --git a/include/mapnik/graphics.hpp b/include/mapnik/graphics.hpp index c3b093dcb..5b86c5d7a 100644 --- a/include/mapnik/graphics.hpp +++ b/include/mapnik/graphics.hpp @@ -369,10 +369,10 @@ public: unsigned g0 = (rgba0 >> 16 ) & 0xff; unsigned b0 = (rgba0 >> 8) & 0xff; - r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); - g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); - b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); - a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); + r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8); + g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8); + b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8); + a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8)); row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; #else @@ -387,10 +387,10 @@ public: unsigned g0 = (rgba0 >> 8 ) & 0xff; unsigned b0 = (rgba0 >> 16) & 0xff; - r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); - g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); - b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); - a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); + r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8); + g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8); + b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8); + a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8)); row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; #endif diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 83f09ba23..247683b86 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -232,8 +232,8 @@ inline void scale_image_bilinear (Image& target,const Image& source, double x_of int x=0,y=0,xs=0,ys=0; int tw2 = target_width/2; int th2 = target_height/2; - int offs_x = int(round((source_width-target_width-x_off_f*2*source_width)/2)); - int offs_y = int(round((source_height-target_height-y_off_f*2*source_height)/2)); + int offs_x = rint((source_width-target_width-x_off_f*2*source_width)/2); + int offs_y = rint((source_height-target_height-y_off_f*2*source_height)/2); unsigned yprt, yprt1, xprt, xprt1; //no scaling or subpixel offset @@ -319,8 +319,8 @@ inline void scale_image_bilinear8 (Image& target,const Image& source, double x_o int x=0,y=0,xs=0,ys=0; int tw2 = target_width/2; int th2 = target_height/2; - int offs_x = int(round((source_width-target_width-x_off_f*2*source_width)/2)); - int offs_y = int(round((source_height-target_height-y_off_f*2*source_height)/2)); + int offs_x = rint((source_width-target_width-x_off_f*2*source_width)/2); + int offs_y = rint((source_height-target_height-y_off_f*2*source_height)/2); unsigned yprt, yprt1, xprt, xprt1; //no scaling or subpixel offset diff --git a/src/agg_renderer.cpp b/src/agg_renderer.cpp index 4c3c8d55e..3f443e915 100644 --- a/src/agg_renderer.cpp +++ b/src/agg_renderer.cpp @@ -76,6 +76,8 @@ #include #endif +#include + namespace mapnik { class pattern_source : private boost::noncopyable @@ -595,7 +597,7 @@ void agg_renderer::process(shield_symbolizer const& sym, if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) ) { //pixmap_.set_rectangle_alpha(px,py,*data); - pixmap_.set_rectangle_alpha2(*(*data),px,py,sym.get_opacity()); + pixmap_.set_rectangle_alpha2(*(*data),px,py,float(sym.get_opacity())); box2d dim = ren.prepare_glyphs(&text_placement.placements[0]); ren.render(x,y); detector_.insert(label_ext); @@ -749,10 +751,10 @@ void agg_renderer::process(raster_symbolizer const& sym, box2d ext=t_.forward(raster->ext_); - int start_x = int(round(ext.minx())); - int start_y = int(round(ext.miny())); - int raster_width = int(round(ext.width())); - int raster_height = int(round(ext.height())); + int start_x = rint(ext.minx()); + int start_y = rint(ext.miny()); + int raster_width = rint(ext.width()); + int raster_height = rint(ext.height()); int end_x = start_x + raster_width; int end_y = start_y + raster_height; double err_offs_x = (ext.minx()-start_x + ext.maxx()-end_x)/2;