From 544cbb249ae2a4ba05c91ba36f4cb774f1844f67 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 7 Apr 2009 23:06:51 +0000 Subject: [PATCH] Apply patch from Marcin to handle smooth transitions between raster layers for both gdal and raster plugin - closed #295 --- CHANGELOG | 2 ++ plugins/input/gdal/gdal_featureset.cpp | 8 +++---- plugins/input/raster/raster_featureset.cpp | 4 ++-- src/agg_renderer.cpp | 26 ++++++++++++---------- src/cairo_renderer.cpp | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c116842ab..a74f0eff7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,8 @@ For a complete change history, see the SVN log. 0.6.1 SVN --------- +- Rasters: Handle rounding to allow better alignment of raster layers (r1079) (#295) + - AGG Renderer: Added option to control output JPEG quality (r1078) (#198) - Plugins: Fixed segfault in OGC Plugin with empty geometries (r1074) (#292) diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index 07df30678..a9ea9d25c 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -125,10 +125,10 @@ feature_ptr gdal_featureset::next() Envelope intersection = raster_extent.intersect(query_extent_); Envelope box = t.forward(intersection); - int start_x = int(box.minx()); - int start_y = int(box.miny()); - int width = int(box.width()); - int height = int(box.height()); + int start_x = int(box.minx()+0.5); + int start_y = int(box.miny()+0.5); + int width = int(box.width()+0.5); + int height = int(box.height()+0.5); if (width > 0 && height > 0) { diff --git a/plugins/input/raster/raster_featureset.cpp b/plugins/input/raster/raster_featureset.cpp index 23fcd2614..f92ad8839 100644 --- a/plugins/input/raster/raster_featureset.cpp +++ b/plugins/input/raster/raster_featureset.cpp @@ -68,8 +68,8 @@ feature_ptr raster_featureset::next() Envelope intersect=extent_.intersect(curIter_->envelope()); Envelope ext=t.forward(intersect); - ImageData32 image((int)ext.width(),(int)ext.height()); - reader->read((int)ext.minx(),(int)ext.miny(),image); + ImageData32 image((int)(ext.width()+0.5),(int)(ext.height()+0.5)); + reader->read((int)(ext.minx()+0.5),(int)(ext.miny()+0.5),image); feature->set_raster(mapnik::raster_ptr(new raster(intersect,image))); } } diff --git a/src/agg_renderer.cpp b/src/agg_renderer.cpp index f2ea459b0..3b9ef0999 100644 --- a/src/agg_renderer.cpp +++ b/src/agg_renderer.cpp @@ -669,6 +669,8 @@ namespace mapnik { Envelope ext=t_.forward(raster->ext_); ImageData32 target(int(ext.width() + 0.5),int(ext.height() + 0.5)); + int start_x = int(ext.minx()+0.5); + int start_y = int(ext.miny()+0.5); if (sym.get_scaling() == "fast"){ scale_image(target,raster->data_); @@ -682,31 +684,31 @@ namespace mapnik if (sym.get_mode() == "normal"){ if (sym.get_opacity() == 1.0) { - pixmap_.set_rectangle(int(ext.minx()),int(ext.miny()),target); + pixmap_.set_rectangle(start_x,start_y,target); } else { - pixmap_.set_rectangle_alpha2(target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.set_rectangle_alpha2(target,start_x,start_y, sym.get_opacity()); } } else if (sym.get_mode() == "grain_merge"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "grain_merge2"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "multiply"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "multiply2"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "divide"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "divide2"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "screen"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else if (sym.get_mode() == "hard_light"){ - pixmap_.template merge_rectangle (target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); } else { if (sym.get_opacity() == 1.0){ - pixmap_.set_rectangle(int(ext.minx()),int(ext.miny()),target); + pixmap_.set_rectangle(start_x,start_y,target); } else { - pixmap_.set_rectangle_alpha2(target,int(ext.minx()),int(ext.miny()), sym.get_opacity()); + pixmap_.set_rectangle_alpha2(target,start_x,start_y, sym.get_opacity()); } } // TODO: other modes? (add,diff,sub,...) diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 36f89b312..39ec8d36a 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -987,7 +987,7 @@ namespace mapnik cairo_context context(context_); //TODO -- support for advanced image merging - context.add_image(int(ext.minx()), int(ext.miny()), target, sym.get_opacity()); + context.add_image(int(ext.minx()+0.5), int(ext.miny()+0.5), target, sym.get_opacity()); } }