From fc8e77f8632a0bb365f4d0fa1adf58b493dba127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 8 Jul 2008 17:48:30 +0000 Subject: [PATCH] When a BBitmap is drawn with scale, but also only partly, the inverse image scan generator matrix was calculated wrongly. The part of the offset that lies within the bitmap bounds needs to have the scale applied as well. Maybe this code can be simplified. Appearantly there is not a lot of code that uses BBitmap drawing this way, perhaps because the R5 version has had issues with rounding. But MediaPlayer uses this feature for drawing the peak levels and this is fixed by this change. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26324 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/drawing/Painter/Painter.cpp | 36 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/servers/app/drawing/Painter/Painter.cpp b/src/servers/app/drawing/Painter/Painter.cpp index 5a621fcbd5..75111e3691 100644 --- a/src/servers/app/drawing/Painter/Painter.cpp +++ b/src/servers/app/drawing/Painter/Painter.cpp @@ -45,6 +45,13 @@ #include "Painter.h" +//#define TRACE_PAINTER +#ifdef TRACE_PAINTER +# define TRACE(x...) printf(x) +#else +# define TRACE(x...) +#endif + #define CHECK_CLIPPING if (!fValidClipping) return BRect(0, 0, -1, -1); #define CHECK_CLIPPING_NO_RETURN if (!fValidClipping) return; @@ -1049,6 +1056,16 @@ Painter::DrawBitmap(const ServerBitmap* bitmap, // the native bitmap coordinate system BRect actualBitmapRect(bitmap->Bounds()); + TRACE("Painter::DrawBitmap()\n"); + TRACE(" actualBitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + actualBitmapRect.left, actualBitmapRect.top, + actualBitmapRect.right, actualBitmapRect.bottom); + TRACE(" bitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + bitmapRect.left, bitmapRect.top, bitmapRect.right, + bitmapRect.bottom); + TRACE(" viewRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); + agg::rendering_buffer srcBuffer; srcBuffer.attach(bitmap->Bits(), bitmap->Width(), @@ -1304,10 +1321,16 @@ Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format, } if (!fSubpixelPrecise) { - align_rect_to_pixels(&viewRect); align_rect_to_pixels(&bitmapRect); + align_rect_to_pixels(&viewRect); } - + + TRACE("Painter::_DrawBitmap()\n"); + TRACE(" bitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + bitmapRect.left, bitmapRect.top, bitmapRect.right, bitmapRect.bottom); + TRACE(" viewRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); + double xScale = (viewRect.Width() + 1) / (bitmapRect.Width() + 1); double yScale = (viewRect.Height() + 1) / (bitmapRect.Height() + 1); @@ -1512,6 +1535,11 @@ Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer, double xScale, double yScale, BRect viewRect) const { + TRACE("Painter::_DrawBitmapGeneric32()\n"); + TRACE(" offset: %.1f, %.1f\n", xOffset, yOffset); + TRACE(" scale: %.3f, %.3f\n", xScale, yScale); + TRACE(" viewRect: (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); // AGG pipeline // pixel format attached to bitmap @@ -1524,8 +1552,10 @@ Painter::_DrawBitmapGeneric32(agg::rendering_buffer& srcBuffer, // -actualBitmapRect.top); agg::trans_affine imgMatrix; + imgMatrix *= agg::trans_affine_translation(xOffset - viewRect.left, + yOffset - viewRect.top); imgMatrix *= agg::trans_affine_scaling(xScale, yScale); - imgMatrix *= agg::trans_affine_translation(xOffset, yOffset); + imgMatrix *= agg::trans_affine_translation(viewRect.left, viewRect.top); imgMatrix.invert(); // image interpolator