avoid extra image allocation and invoking scaling if not absolutely needed #1544

springmeyer opened this Issue Oct 21, 2012 · 2 comments


None yet

2 participants


It appears that in raster rendering we can shortcut and avoid scaling images if gdal returns a raster scaled already to the map size. This should be the case if scaling=near and filter_factor=1.

In testing locally it appears we have rounding errors however that make the source/dest width/height not exactly match. Will need to avoid this.


I faced off-by-one errors when I was resizing some images with GraphicsMagick. The problem there was that I rounded width and height separately before calling resize, so sometimes width rounded up and height rounded down, and GM in order to keep the aspect ratio closer to original gave me an image resized to (width-1, height).

Not sure if it helps here, I solved it like this:

double w1 = floor(fwidth);
double h1 = floor(fheight);
double w2 = ceil(fwidth);
double h2 = ceil(fheight);
double floor_error = abs(fwidth * h1 - fheight * w1);
double ceil_error = abs(fwidth * h2 - fheight * w2);
int w, h;

if (floor_error < ceil_error) { w = int(w1); h = int(h1); }
else { w = int(w2); h = int(h2); }

need to return to testing this again after #1748. btw, hi @lightmare!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment