+ use rint(v) instead of int(round(v)) + add rint implementation - msvc hasn't got one + minor cleanups

This commit is contained in:
Dane Springmeyer 2010-03-11 23:19:12 +00:00
parent e8a4929a5a
commit 3a44dd3258
4 changed files with 28 additions and 17 deletions

View file

@ -159,6 +159,15 @@ namespace mapnik
#endif #endif
return val; return val;
} }
#ifdef _WINDOWS
// msvc doesn't have rint in <cmath>
inline int rint( double val)
{
return int(floor(val + 0.5));
}
#endif
} }
#endif //GLOBAL_HPP #endif //GLOBAL_HPP

View file

@ -369,10 +369,10 @@ public:
unsigned g0 = (rgba0 >> 16 ) & 0xff; unsigned g0 = (rgba0 >> 16 ) & 0xff;
unsigned b0 = (rgba0 >> 8) & 0xff; unsigned b0 = (rgba0 >> 8) & 0xff;
r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8);
g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8);
b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8);
a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8));
row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ;
#else #else
@ -387,10 +387,10 @@ public:
unsigned g0 = (rgba0 >> 8 ) & 0xff; unsigned g0 = (rgba0 >> 8 ) & 0xff;
unsigned b0 = (rgba0 >> 16) & 0xff; unsigned b0 = (rgba0 >> 16) & 0xff;
r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8);
g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8);
b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8);
a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8));
row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
#endif #endif

View file

@ -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 x=0,y=0,xs=0,ys=0;
int tw2 = target_width/2; int tw2 = target_width/2;
int th2 = target_height/2; int th2 = target_height/2;
int offs_x = int(round((source_width-target_width-x_off_f*2*source_width)/2)); int offs_x = rint((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_y = rint((source_height-target_height-y_off_f*2*source_height)/2);
unsigned yprt, yprt1, xprt, xprt1; unsigned yprt, yprt1, xprt, xprt1;
//no scaling or subpixel offset //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 x=0,y=0,xs=0,ys=0;
int tw2 = target_width/2; int tw2 = target_width/2;
int th2 = target_height/2; int th2 = target_height/2;
int offs_x = int(round((source_width-target_width-x_off_f*2*source_width)/2)); int offs_x = rint((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_y = rint((source_height-target_height-y_off_f*2*source_height)/2);
unsigned yprt, yprt1, xprt, xprt1; unsigned yprt, yprt1, xprt, xprt1;
//no scaling or subpixel offset //no scaling or subpixel offset

View file

@ -76,6 +76,8 @@
#include <iostream> #include <iostream>
#endif #endif
#include <cmath>
namespace mapnik namespace mapnik
{ {
class pattern_source : private boost::noncopyable class pattern_source : private boost::noncopyable
@ -595,7 +597,7 @@ void agg_renderer<T>::process(shield_symbolizer const& sym,
if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) ) if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) )
{ {
//pixmap_.set_rectangle_alpha(px,py,*data); //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<double> dim = ren.prepare_glyphs(&text_placement.placements[0]); box2d<double> dim = ren.prepare_glyphs(&text_placement.placements[0]);
ren.render(x,y); ren.render(x,y);
detector_.insert(label_ext); detector_.insert(label_ext);
@ -749,10 +751,10 @@ void agg_renderer<T>::process(raster_symbolizer const& sym,
box2d<double> ext=t_.forward(raster->ext_); box2d<double> ext=t_.forward(raster->ext_);
int start_x = int(round(ext.minx())); int start_x = rint(ext.minx());
int start_y = int(round(ext.miny())); int start_y = rint(ext.miny());
int raster_width = int(round(ext.width())); int raster_width = rint(ext.width());
int raster_height = int(round(ext.height())); int raster_height = rint(ext.height());
int end_x = start_x + raster_width; int end_x = start_x + raster_width;
int end_y = start_y + raster_height; int end_y = start_y + raster_height;
double err_offs_x = (ext.minx()-start_x + ext.maxx()-end_x)/2; double err_offs_x = (ext.minx()-start_x + ext.maxx()-end_x)/2;