[PATCH] gdiplus: Fix errors in image dimensions.
Nathan Beckmann
nathan.beckmann at gmail.com
Thu Mar 6 01:46:20 CST 2008
Use more precise calculations in GdipGetImageDimension.
Add rounding to GdipLoadImageFromStream to account for errors in unit
conversion.
This is in response to a bug found while doing tests for
GdipSaveImageToFile (patch forthcoming). Also fixes Bug 11778.
---
dlls/gdiplus/image.c | 28 ++++++++++++++++++++++------
1 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 330d90f..da1b931 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -45,8 +45,9 @@ static INT ipicture_pixel_height(IPicture *pic)
hdcref = GetDC(0);
- y = (UINT)(((REAL)y) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSY)) /
- ((REAL)INCH_HIMETRIC));
+ /* this calculation can lead to truncation error */
+ y = (UINT)((((REAL)y) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSY)) /
+ ((REAL)INCH_HIMETRIC)) + 0.5);
ReleaseDC(0, hdcref);
return y;
@@ -61,8 +62,9 @@ static INT ipicture_pixel_width(IPicture *pic)
hdcref = GetDC(0);
- x = (UINT)(((REAL)x) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSX)) /
- ((REAL)INCH_HIMETRIC));
+ /* this calculation can lead to truncation error */
+ x = (UINT)((((REAL)x) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSX)) /
+ ((REAL)INCH_HIMETRIC)) + 0.5);
ReleaseDC(0, hdcref);
@@ -485,8 +487,22 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
*width = ((GpBitmap*)image)->width;
}
else{
- *height = ipicture_pixel_height(image->picture);
- *width = ipicture_pixel_width(image->picture);
+ HDC hdc;
+ INT x, y;
+
+ x = y = 0;
+
+ hdc = GetDC(0);
+
+ IPicture_get_Width(image->picture, &x);
+ IPicture_get_Height(image->picture, &y);
+
+ *width = (((REAL)x) * ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) /
+ ((REAL)INCH_HIMETRIC));
+ *height = (((REAL)y) * ((REAL)GetDeviceCaps(hdc, LOGPIXELSY)) /
+ ((REAL)INCH_HIMETRIC));
+
+ ReleaseDC(0, hdc);
}
TRACE("returning (%f, %f)\n", *height, *width);
--
1.5.4.2
More information about the wine-patches
mailing list