diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-05 17:27:16 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-05 17:27:16 (GMT) |
| commit | 98725dea26857f9caac15ff88aff005dbba80530 (patch) | |
| tree | 41238b972f78f989d15312a8e877ad3b7f7d9b00 /src/graphics | |
| parent | d61690bc091af0e253abe18832cc06f6c998724a (diff) | |
| download | powder-98725dea26857f9caac15ff88aff005dbba80530.zip powder-98725dea26857f9caac15ff88aff005dbba80530.tar.gz | |
Only use stairstepping for resampling when absolutely necessary (when the downscaling factor is a power of 2). Somewhat fixes #176
Diffstat (limited to 'src/graphics')
| -rw-r--r-- | src/graphics/Graphics.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index e7cce03..c4c0d31 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -334,6 +334,30 @@ pixel *Graphics::resample_img(pixel *src, int sw, int sh, int rw, int rh) #ifdef DEBUG std::cout << "Resampling " << sw << "x" << sh << " to " << rw << "x" << rh << std::endl; #endif + bool stairstep = false; + if(rw < sw || rh < sh) + { + float fx = (float)(((float)sw)/((float)rw)); + float fy = (float)(((float)sh)/((float)rh)); + + int fxint, fyint; + double fxintp_t, fyintp_t; + + float fxf = modf(fx, &fxintp_t), fyf = modf(fy, &fyintp_t); + fxint = fxintp_t; + fyint = fyintp_t; + + if(((fxint & (fxint-1)) == 0 && fxf < 0.1f) || ((fyint & (fyint-1)) == 0 && fyf < 0.1f)) + stairstep = true; + +#ifdef DEBUG + if(stairstep) + std::cout << "Downsampling by " << fx << "x" << fy << " using stairstepping" << std::endl; + else + std::cout << "Downsampling by " << fx << "x" << fy << " without stairstepping" << std::endl; +#endif + } + int y, x, fxceil, fyceil; //int i,j,x,y,w,h,r,g,b,c; pixel *q = NULL; @@ -341,7 +365,7 @@ pixel *Graphics::resample_img(pixel *src, int sw, int sh, int rw, int rh) //Don't resample q = (pixel *)malloc(rw*rh*PIXELSIZE); memcpy(q, src, rw*rh*PIXELSIZE); - } else if(rw >= sw && rh >= sh){ + } else if(!stairstep) { float fx, fy, fyc, fxc; double intp; pixel tr, tl, br, bl; |
