From 78e86e3bbd1af8093a21e133aa33d6f0065e4f3c Mon Sep 17 00:00:00 2001 From: avolkov Date: Tue, 15 Feb 2005 10:18:20 +0000 Subject: [PATCH] Rounding error corrections in offseting hotspots math git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1538 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/graphics/tfb_prim.c | 35 ++++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/sc2/src/sc2code/libs/graphics/tfb_prim.c b/sc2/src/sc2code/libs/graphics/tfb_prim.c index 6165b6185..0eef41250 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_prim.c +++ b/sc2/src/sc2code/libs/graphics/tfb_prim.c @@ -55,10 +55,13 @@ TFB_Prim_Rect (PRECT r, TFB_Palette *color) arm.extent.height = r->extent.height; arm.extent.width = 1; TFB_Prim_FillRect (&arm, color); - arm.corner.x += ((r->extent.width * gscale) / GSCALE_IDENTITY) - 1; + // rounding error correction here + arm.corner.x += ((r->extent.width * gscale + (GSCALE_IDENTITY >> 1)) + / GSCALE_IDENTITY) - 1; TFB_Prim_FillRect (&arm, color); arm.corner.x = r->corner.x; - arm.corner.y += ((r->extent.height * gscale) / GSCALE_IDENTITY) - 1; + arm.corner.y += ((r->extent.height * gscale + (GSCALE_IDENTITY >> 1)) + / GSCALE_IDENTITY) - 1; arm.extent.width = r->extent.width; arm.extent.height = 1; TFB_Prim_FillRect (&arm, color); @@ -77,9 +80,11 @@ TFB_Prim_FillRect (PRECT r, TFB_Palette *color) gscale = GetGraphicScale (); if (gscale != GSCALE_IDENTITY) - { - rect.extent.width = (rect.extent.width * gscale) / GSCALE_IDENTITY; - rect.extent.height = (rect.extent.height * gscale) / GSCALE_IDENTITY; + { // rounding error correction here + rect.extent.width = (rect.extent.width * gscale + + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; + rect.extent.height = (rect.extent.height * gscale + + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; rect.corner.x += (r->extent.width - rect.extent.width) >> 1; rect.corner.y += (r->extent.height - @@ -140,11 +145,11 @@ TFB_Prim_Stamp (PSTAMP stmp) paletted = FALSE; if (gscale != GSCALE_IDENTITY) - { - x += (SrcFramePtr->HotSpot.x * - (GSCALE_IDENTITY - gscale)) / GSCALE_IDENTITY; - y += (SrcFramePtr->HotSpot.y * - (GSCALE_IDENTITY - gscale)) / GSCALE_IDENTITY; + { // rounding error correction here + x += (SrcFramePtr->HotSpot.x * (GSCALE_IDENTITY - gscale) + + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; + y += (SrcFramePtr->HotSpot.y * (GSCALE_IDENTITY - gscale) + + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; } if (TFB_DrawCanvas_IsPaletted(img->NormalImg) && img->colormap_index != -1) @@ -200,11 +205,11 @@ TFB_Prim_StampFill (PSTAMP stmp, TFB_Palette *color) b = color->b; if (gscale != GSCALE_IDENTITY) - { - x += (SrcFramePtr->HotSpot.x * - (GSCALE_IDENTITY - gscale)) / GSCALE_IDENTITY; - y += (SrcFramePtr->HotSpot.y * - (GSCALE_IDENTITY - gscale)) / GSCALE_IDENTITY; + { // rounding error correction here + x += (SrcFramePtr->HotSpot.x * (GSCALE_IDENTITY - gscale) + + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; + y += (SrcFramePtr->HotSpot.y * (GSCALE_IDENTITY - gscale) + + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; } UnlockMutex (img->mutex);