Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

broken colors after raster reprojection #1501

Closed
springmeyer opened this Issue · 2 comments

2 participants

@springmeyer
Owner

Raster reprojection can distort alpha and colors in some cases.

Here is a testcase:

<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" background-color="#b8dee6" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
<Style name="gimpheatmap" filter-mode="first" >
  <Rule>
    <RasterSymbolizer opacity="1" />
  </Rule>
</Style>
<Layer name="gimpheatmap"
  srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
    <StyleName>gimpheatmap</StyleName>
    <Datasource>
       <Parameter name="file">gimp_heatmap.tif</Parameter>
       <Parameter name="type">raster</Parameter>
       <Parameter name="extent">69.0800265306,27.7645909217,75.7630524306,34.1658968217</Parameter>
    </Datasource>
  </Layer>
</Map>

You'll get an image (when reprojection happens) no matter whether gdal/raster datasource like:

When the image should look like:

downstream report was here.

@springmeyer
Owner

this comes close to fixing things:

diff --git a/src/warp.cpp b/src/warp.cpp
index 60232b0..2acfad9 100644
--- a/src/warp.cpp
+++ b/src/warp.cpp
@@ -160,10 +160,10 @@ void reproject_and_scale_raster(raster & target, raster const& source,
             tt.forward(polygon+6, polygon+7);

             rasterizer.reset();
-            rasterizer.move_to_d(polygon[0]-1, polygon[1]-1);
-            rasterizer.line_to_d(polygon[2]+1, polygon[3]-1);
-            rasterizer.line_to_d(polygon[4]+1, polygon[5]+1);
-            rasterizer.line_to_d(polygon[6]-1, polygon[7]+1);
+            rasterizer.move_to_d(polygon[0], polygon[1]);
+            rasterizer.line_to_d(polygon[2], polygon[3]);
+            rasterizer.line_to_d(polygon[4], polygon[5]);
+            rasterizer.line_to_d(polygon[6], polygon[7]);

             unsigned x0 = i * mesh_size;
             unsigned y0 = j * mesh_size;

@artemp
Owner

@springmeyer - yes, that +/-1 padding was a problem with images with alpha channel. Proper fix is in be5a2c1 - closing.

@artemp artemp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.