diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-16 11:20:11 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-16 11:20:11 (GMT) |
| commit | 0646b7fe41bf8dc94b4f2eb1e3e1c0e85ac1f254 (patch) | |
| tree | b3442587a9dc82ba4361ba1f5d79f26b2da8b5dd /src/graphics | |
| parent | ca9ea8bb8ae457acb27de61f635115e433a8e981 (diff) | |
| download | powder-0646b7fe41bf8dc94b4f2eb1e3e1c0e85ac1f254.zip powder-0646b7fe41bf8dc94b4f2eb1e3e1c0e85ac1f254.tar.gz | |
Nicer resize method for VideoBuffer, fix Local and Server save previews
Diffstat (limited to 'src/graphics')
| -rw-r--r-- | src/graphics/Graphics.cpp | 20 | ||||
| -rw-r--r-- | src/graphics/Graphics.h | 2 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index 35120c9..b948189 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -50,20 +50,30 @@ void VideoBuffer::Resize(float factor, bool resample) Resize(newWidth, newHeight); } -void VideoBuffer::Resize(int width, int height, bool resample) +void VideoBuffer::Resize(int width, int height, bool resample, bool fixedRatio) { int newWidth = width; int newHeight = height; pixel * newBuffer; if(newHeight == -1 && newWidth == -1) return; - if(newHeight == -1) + if(newHeight == -1 || newWidth == -1) { - newHeight = ((float)Height)*((float)newWidth/(float)Width); + if(newHeight == -1) + newHeight = ((float)Height)*((float)newWidth/(float)Width); + if(newWidth == -1) + newWidth = ((float)Width)*((float)newHeight/(float)Height); } - if(newWidth == -1) + else if(fixedRatio) { - newWidth = ((float)Width)*((float)newHeight/(float)Height); + //Force proportions + float scaleFactor = 1.0f; + if(Height > newHeight) + scaleFactor = ((float)newHeight)/((float)Height); + if(Width > newWidth) + scaleFactor = ((float)newWidth)/((float)Width); + newWidth = ((float)Width)*scaleFactor; + newHeight = ((float)Height)*scaleFactor; } if(resample) newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight); diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 596d93d..e2ed119 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -113,7 +113,7 @@ public: VideoBuffer(pixel * buffer, int width, int height); VideoBuffer(int width, int height); void Resize(float factor, bool resample = false); - void Resize(int width, int height, bool resample = false); + void Resize(int width, int height, bool resample = false, bool fixedRatio = true); TPT_INLINE void BlendPixel(int x, int y, int r, int g, int b, int a) { #ifdef PIX32OGL |
