aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-07-27 17:43:17 +0200
committerEinar Johan Trøan Sømåen2012-07-27 17:43:17 +0200
commit6262a2ac8751b1bfff7becc8cf181ab9dd16bf87 (patch)
tree91a8caaa6f67dbe292c5e0da7cbed13b1d814c6a /engines
parenta9e9ed7d3b5411e5eaf44ac87f1a10ce53e962d9 (diff)
downloadscummvm-rg350-6262a2ac8751b1bfff7becc8cf181ab9dd16bf87.tar.gz
scummvm-rg350-6262a2ac8751b1bfff7becc8cf181ab9dd16bf87.tar.bz2
scummvm-rg350-6262a2ac8751b1bfff7becc8cf181ab9dd16bf87.zip
WINTERMUTE: Use an arbitrary size nearest neighbour scaler for save thumbnails. Thanks to clone2727
Diffstat (limited to 'engines')
-rw-r--r--engines/wintermute/base/gfx/base_image.cpp16
-rw-r--r--engines/wintermute/graphics/transparent_surface.cpp33
-rw-r--r--engines/wintermute/graphics/transparent_surface.h3
3 files changed, 36 insertions, 16 deletions
diff --git a/engines/wintermute/base/gfx/base_image.cpp b/engines/wintermute/base/gfx/base_image.cpp
index 628bffff55..3aa21d0f7f 100644
--- a/engines/wintermute/base/gfx/base_image.cpp
+++ b/engines/wintermute/base/gfx/base_image.cpp
@@ -224,27 +224,15 @@ bool BaseImage::writeBMPToStream(Common::WriteStream *stream) const {
//////////////////////////////////////////////////////////////////////////
bool BaseImage::copyFrom(BaseImage *origImage, int newWidth, int newHeight) {
-#if 0
- if (_bitmap) {
- FreeImage_Unload(_bitmap);
- }
-
- if (NewWidth == 0) {
- NewWidth = FreeImage_GetWidth(OrigImage->GetBitmap());
- }
- if (NewHeight == 0) {
- NewHeight = FreeImage_GetHeight(OrigImage->GetBitmap());
- }
+ // WME Lite used FILTER_BILINEAR with FreeImage_Rescale here.
- _bitmap = FreeImage_Rescale(OrigImage->GetBitmap(), NewWidth, NewHeight, FILTER_BILINEAR);
-#endif
TransparentSurface temp(*origImage->_surface, false);
if (_deletableSurface) {
_deletableSurface->free();
delete _deletableSurface;
_deletableSurface = NULL;
}
- _surface = _deletableSurface = temp.scale(newWidth, newHeight);
+ _surface = _deletableSurface = temp.scaleSafe((uint16)newWidth, (uint16)newHeight);
return true;
}
diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp
index 65bdbcf5a1..59010d5ed3 100644
--- a/engines/wintermute/graphics/transparent_surface.cpp
+++ b/engines/wintermute/graphics/transparent_surface.cpp
@@ -342,10 +342,39 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p
return retSize;
}
+TransparentSurface *TransparentSurface::scaleSafe(uint16 newWidth, uint16 newHeight) const {
+ Common::Rect srcRect(0, 0, (int16)w, (int16)h);
+ Common::Rect dstRect(0, 0, (int16)newWidth, (int16)newHeight);
+ return scaleSafe(srcRect, dstRect);
+}
+
+// Copied from clone2727's https://github.com/clone2727/scummvm/blob/pegasus/engines/pegasus/surface.cpp#L247
+TransparentSurface *TransparentSurface::scaleSafe(const Common::Rect &srcRect, const Common::Rect &dstRect) const {
+ // I'm doing simple linear scaling here
+ // dstRect(x, y) = srcRect(x * srcW / dstW, y * srcH / dstH);
+ TransparentSurface *target = new TransparentSurface();
+
+ int srcW = srcRect.width();
+ int srcH = srcRect.height();
+ int dstW = dstRect.width();
+ int dstH = dstRect.height();
+
+ target->create((uint16)dstW, (uint16)dstH, this->format);
+
+ for (int y = 0; y < dstH; y++) {
+ for (int x = 0; x < dstW; x++) {
+ uint32 color = READ_UINT32((byte *)getBasePtr(x * srcW / dstW + srcRect.left,
+ y * srcH / dstH + srcRect.top));
+ WRITE_UINT32((byte *)target->getBasePtr(x + dstRect.left, y + dstRect.top), color);
+ }
+ }
+ return target;
+
+}
/**
* Scales a passed surface, creating a new surface with the result
- * @param srcImage Source image to scale
- * @param scaleFactor Scale amount. Must be between 0 and 1.0 (but not zero)
+ * @param xSize target width.
+ * @param ySize target height.
* @remarks Caller is responsible for freeing the returned surface
*/
TransparentSurface *TransparentSurface::scale(int xSize, int ySize) const {
diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h
index e271bf2488..79637037db 100644
--- a/engines/wintermute/graphics/transparent_surface.h
+++ b/engines/wintermute/graphics/transparent_surface.h
@@ -101,6 +101,9 @@ struct TransparentSurface : public Graphics::Surface {
int width = -1, int height = -1);
void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false);
TransparentSurface *scale(int xSize, int ySize) const;
+ // The following scale-code supports arbitrary scaling (i.e. no repeats of column 0 at the end of lines)
+ TransparentSurface *scaleSafe(uint16 newWidth, uint16 newHeight) const;
+ TransparentSurface *scaleSafe(const Common::Rect &srcRect, const Common::Rect &dstRect) const;
private:
static int *scaleLine(int size, int srcSize);
};