From ac92e906114ed7216cfd99e0deecfb7be0fd91ec Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 28 Jul 2009 09:55:20 +0200 Subject: Fixed drawImage() so that it doesn't sample outside the source image. In qt_scale_image_16bit() and qt_scale_image_32bit(), when a sample point was located on the border between two pixels in the source image, the sample point was rounded up instead of down. If a sample point was exactly on the bottom or right edge of the source image, the function would therefore sample a pixel outside the image. Because of how the target rectangle is rounded, a sample point will never be exactly on the top or left edge of the source image, so we will not get a similar problem there. I extended the lance test pixmap_scaling.qps. Task-number: 258533 Reviewed-by: Samuel --- src/gui/painting/qblendfunctions.cpp | 8 +- tests/arthur/data/qps/pixmap_scaling.qps | 346 +++++++++++++++++++++++++++++-- 2 files changed, 331 insertions(+), 23 deletions(-) diff --git a/src/gui/painting/qblendfunctions.cpp b/src/gui/painting/qblendfunctions.cpp index baea140..82abec3 100644 --- a/src/gui/painting/qblendfunctions.cpp +++ b/src/gui/painting/qblendfunctions.cpp @@ -192,8 +192,8 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl, int h = ty2 - ty1; int w = tx2 - tx1; - const int dstx = int((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix); - const int dsty = int((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy); + const int dstx = qCeil((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix) - 1; + const int dsty = qCeil((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1; quint32 basex = quint32((sx < 0 ? srcRect.right() : srcRect.left()) * 65536) + dstx; quint32 srcy = quint32((sy < 0 ? srcRect.bottom() : srcRect.top()) * 65536) + dsty; @@ -667,8 +667,8 @@ template void qt_scale_image_32bit(uchar *destPixels, int dbpl, int h = ty2 - ty1; int w = tx2 - tx1; - const int dstx = int((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix); - const int dsty = int((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy); + const int dstx = qCeil((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix) - 1; + const int dsty = qCeil((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1; quint32 basex = quint32((sx < 0 ? srcRect.right() : srcRect.left()) * 65536) + dstx; quint32 srcy = quint32((sy < 0 ? srcRect.bottom() : srcRect.top()) * 65536) + dsty; diff --git a/tests/arthur/data/qps/pixmap_scaling.qps b/tests/arthur/data/qps/pixmap_scaling.qps index 81b8fae..c5053ad 100644 --- a/tests/arthur/data/qps/pixmap_scaling.qps +++ b/tests/arthur/data/qps/pixmap_scaling.qps @@ -3,8 +3,8 @@ translate 5 25 setFont "arial" 8 -save - drawText 15 0 "opaque image" +save + drawText 15 0 "opaque image" translate 50 50 save translate 1 1 @@ -16,23 +16,23 @@ save scale -20 20 drawImage solid2x2.png 0 0 restore - save + save translate 1 -1 scale 20 -20 drawImage solid2x2.png 0 0 restore - save + save translate -1 -1 scale -20 -20 drawImage solid2x2.png 0 0 restore - -restore + +restore save translate 150 0 - drawText 15 0 "alpha image" + drawText 15 0 "alpha image" translate 50 50 save translate 1 1 @@ -44,12 +44,12 @@ save scale -20 20 drawImage alpha2x2.png 0 0 restore - save + save translate 1 -1 scale 20 -20 drawImage alpha2x2.png 0 0 restore - save + save translate -1 -1 scale -20 -20 drawImage alpha2x2.png 0 0 @@ -59,7 +59,7 @@ restore save translate 0 150 - drawText 15 0 "solid pixmap" + drawText 15 0 "solid pixmap" translate 50 50 save translate 1 1 @@ -71,12 +71,12 @@ save scale -20 20 drawPixmap solid2x2.png 0 0 restore - save + save translate 1 -1 scale 20 -20 drawPixmap solid2x2.png 0 0 restore - save + save translate -1 -1 scale -20 -20 drawPixmap solid2x2.png 0 0 @@ -85,9 +85,9 @@ restore save - translate 150 150 + translate 150 150 drawText 15 0 "alpha pixmap" - translate 50 50 + translate 50 50 save translate 1 1 scale 20 20 @@ -98,12 +98,12 @@ save scale -20 20 drawPixmap alpha2x2.png 0 0 restore - save + save translate 1 -1 scale 20 -20 drawPixmap alpha2x2.png 0 0 restore - save + save translate -1 -1 scale -20 -20 drawPixmap alpha2x2.png 0 0 @@ -111,7 +111,7 @@ save restore -save +save translate 300 10 save drawText 0 -10 "subrect solid image" @@ -138,7 +138,7 @@ save drawImage solid2x2.png 45 0 5 50 1.8 0 0.2 2 restore - save + save translate 150 0 drawText 0 -10 "subrect solid image" drawImage alpha2x2.png 0 0 50 5 0 0.0 2 0.2 @@ -151,7 +151,7 @@ save drawImage alpha2x2.png 0 35 50 5 0 1.4 2 0.2 drawImage alpha2x2.png 0 40 50 5 0 1.6 2 0.2 drawImage alpha2x2.png 0 45 50 5 0 1.8 2 0.2 - translate 60 0 + translate 60 0 drawImage alpha2x2.png 0 0 5 50 0.0 0 0.2 2 drawImage alpha2x2.png 5 0 5 50 0.2 0 0.2 2 drawImage alpha2x2.png 10 0 5 50 0.4 0 0.2 2 @@ -217,3 +217,311 @@ save restore restore + + + +image_load alpha2x2.png alpha2x2 +image_convertToFormat alpha2x2 alpha2x2_argb32 ARGB32 +image_convertToFormat alpha2x2 alpha2x2_argb32pre ARGB32_Premultiplied +image_convertToFormat alpha2x2 alpha2x2_rgb888 Format_RGB888 +image_convertToFormat alpha2x2 alpha2x2_rgb32 RGB32 +image_convertToFormat alpha2x2 alpha2x2_rgb16 Format_RGB16 + +save + translate 0 300 + drawText 15 0 "drawImage - argb32" + translate 50 50 + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_argb32 0 0 + restore +restore + +save + translate 150 300 + drawText 15 0 "drawImage - argb32premul" + translate 50 50 + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_argb32pre 0 0 + restore +restore + + + +save + translate 0 450 + drawText 15 0 "drawImage - rgb888" + translate 50 50 + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_rgb888 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_rgb888 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_rgb888 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_rgb888 0 0 + restore +restore + +save + translate 150 450 + drawText 15 0 "drawImage - rgb32" + translate 50 50 + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_rgb32 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_rgb32 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_rgb32 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_rgb32 0 0 + restore +restore + +save + translate 300 450 + drawText 15 0 "drawImage - rgb16" + translate 50 50 + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_rgb16 0 0 + restore +restore + + + +save + translate 0 600 + drawText 15 0 "clipping - argb32" + translate 50 50 + setClipRect -30 -30 60 60 ReplaceClip + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_argb32 0 0 + restore +restore + +save + translate 150 600 + drawText 15 0 "clipping - argb32premul" + translate 50 50 + setClipRect -30 -30 60 60 ReplaceClip + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_argb32pre 0 0 + restore +restore + +save + translate 300 600 + drawText 15 0 "clipping - rgb16" + translate 50 50 + setClipRect -30 -30 60 60 ReplaceClip + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_rgb16 0 0 + restore +restore + + +path_addEllipse ellipse -30 -30 60 60 + +save + translate 0 750 + drawText 15 0 "clipping - argb32" + translate 50 50 + setClipPath ellipse ReplaceClip + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_argb32 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_argb32 0 0 + restore +restore + +save + translate 150 750 + drawText 15 0 "clipping - argb32premul" + translate 50 50 + setClipPath ellipse ReplaceClip + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_argb32pre 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_argb32pre 0 0 + restore +restore + +save + translate 300 750 + drawText 15 0 "clipping - rgb16" + translate 50 50 + setClipPath ellipse ReplaceClip + save + translate 0.5 0.5 + scale 20 20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate -0.5 0.5 + scale -20 20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate 0.5 -0.5 + scale 20 -20 + drawImage alpha2x2_rgb16 0 0 + restore + save + translate -0.5 -0.5 + scale -20 -20 + drawImage alpha2x2_rgb16 0 0 + restore +restore -- cgit v0.12