+ use rint(v) instead of int(round(v))

+ add rint implementation - msvc hasn't got one
+ minor cleanups
This commit is contained in:
Artem Pavlenko 2010-03-11 15:20:04 +00:00
parent e62fb19c7c
commit 8b3c390ebf
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 @@ namespace mapnik
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 @@ namespace mapnik
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

@ -319,8 +319,8 @@ namespace mapnik {
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
@ -406,8 +406,8 @@ namespace mapnik {
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

@ -74,6 +74,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
@ -570,7 +572,7 @@ namespace mapnik
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()));
Envelope<double> dim = ren.prepare_glyphs(&text_placement.placements[0]); Envelope<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);
@ -714,10 +716,10 @@ namespace mapnik
if (raster) if (raster)
{ {
Envelope<double> ext=t_.forward(raster->ext_); Envelope<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;