CVS: winex/dlls/msimg32 msimg32_main.c,1.8,1.9

[email protected]
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/dlls/msimg32 msimg32_main.c,1.8,1.9Update of /var/lib/cvsd/cvsroot/winex/dlls/msimg32
In directory agravaine:/tmp/cvs-serv32016/dlls/msimg32

Modified Files:
	msimg32_main.c 
Log Message:

Better support for alpha blending - use BitBlt to get at the source data,
which allows us to preserve the alpha. Then do the scaling within the 
AlphaBlend function itself using some basic floating point math.


Index: msimg32_main.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/dlls/msimg32/msimg32_main.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- msimg32_main.c	27 Apr 2007 13:17:50 -0000	1.8
+++ msimg32_main.c	27 Apr 2007 13:18:38 -0000	1.9
@@ -1,3 +1,4 @@
+#include <math.h>
 #include "winbase.h"
 #include "wingdi.h"
 #include "winerror.h"
@@ -105,6 +106,7 @@
   HBITMAP hbmSrc, hbmDest;
   BYTE *src, *dest;
   int x,y,c;
+  double scaleX, scaleY;
   
   TRACE("(%d, (%d,%d),(%d,%d), %d, (%d,%d),(%d,%d), (%d,%d,%d,%d)) stub!\n",
         hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
@@ -129,8 +131,8 @@
   /* FIXME: change bmiScratch to a BITMAPV5HEADER to ensure DIB sections have alpha */
   memset(&bmiScratch.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
   bmiScratch.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-  bmiScratch.bmiHeader.biWidth = nWidthDest;
-  bmiScratch.bmiHeader.biHeight = nHeightDest;
+  bmiScratch.bmiHeader.biWidth = nWidthSrc;
+  bmiScratch.bmiHeader.biHeight = nHeightSrc;
   bmiScratch.bmiHeader.biPlanes = 1;
   bmiScratch.bmiHeader.biBitCount = 32;
   bmiScratch.bmiHeader.biCompression = BI_RGB;
@@ -138,27 +140,34 @@
   hdcScratch = CreateCompatibleDC(hdcDest);
   
   /* read in src */
-  /* FIXME: Our StretchBlt implementation is likely losing the alpha data during this copy.. */
   hbmSrc = CreateDIBSection(hdcScratch, &bmiScratch, DIB_RGB_COLORS, (void**)(&src), 0, 0);
   SelectObject(hdcScratch, hbmSrc);
-  StretchBlt(hdcScratch, 0, 0, nWidthDest, nHeightDest,
-             hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
+
+  /* Using BitBlt will preserve the alpha in the original DIB (if there is one), since we do a dib->dib copy */
+  BitBlt(hdcScratch, 0, 0, nWidthSrc, nHeightSrc, hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY);
   
   /* read in dest */
+  bmiScratch.bmiHeader.biWidth = nWidthDest;
+  bmiScratch.bmiHeader.biHeight = nHeightDest;
   hbmDest = CreateDIBSection(hdcScratch, &bmiScratch, DIB_RGB_COLORS, (void**)(&dest), 0, 0);
   SelectObject(hdcScratch, hbmDest);
   BitBlt(hdcScratch, 0, 0, nWidthDest, nHeightDest, hdcDest, nXOriginDest, nYOriginDest, SRCCOPY);
-  
+
+  /* Calculate the scaling factor for sampling - note that we're doing a trivial point-sample on 
+   * the source data */
+  scaleX = (double)nWidthSrc / (double)nWidthDest;
+  scaleY =(double)nHeightSrc / (double)nHeightDest;
+
   /* blend them together in dest */
   if (blendFunction.AlphaFormat == AC_SRC_ALPHA)
   {
     FLOAT sca = blendFunction.SourceConstantAlpha / 255.0;
     for (y=0; y<nHeightDest; y++) {
       for (x=0; x<nWidthDest; x++) {
-        FLOAT sa = src[(y * 4 * nWidthDest) + (x * 4) + 3] / 255.0;
+        FLOAT sa = src[((int)floor(y * scaleY) * 4 * nWidthSrc) + ((int)floor(x * scaleX) * 4) + 3] / 255.0;
         for (c=0; c<4; c++)
         {
-          BYTE s = src[(y * 4 * nWidthDest) + (x * 4) + c];
+          BYTE s = src[((int)floor(y * scaleY) * 4 * nWidthSrc) + ((int)floor(x * scaleX) * 4) + c];
           BYTE d = dest[(y * 4 * nWidthDest) + (x * 4) + c];
           FLOAT t = (s * sca) + ((1 - sa) * d);
           dest[(y * 4 * nWidthDest) + (x * 4) + c] = max(0, min(t, 255));
@@ -171,7 +180,7 @@
       for (x=0; x<nWidthDest; x++) {
         for (c=0; c<4; c++)
         {
-          BYTE s = src[(y * 4 * nWidthDest) + (x * 4) + c];
+          BYTE s = src[((int)floor(y * scaleY) * 4 * nWidthSrc) + ((int)floor(x * scaleX) * 4) + c];
           BYTE d = dest[(y * 4 * nWidthDest) + (x * 4) + c];
           FLOAT t = (s * sca) + ((1 - sca) * d);
           dest[(y * 4 * nWidthDest) + (x * 4) + c] = max(0, min(t, 255));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.