Index: trunk/src/gdi32/blit.cpp
===================================================================
--- trunk/src/gdi32/blit.cpp	(revision 3525)
+++ trunk/src/gdi32/blit.cpp	(revision 3527)
@@ -1,3 +1,3 @@
-/* $Id: blit.cpp,v 1.10 2000-04-18 11:11:52 sandervl Exp $ */
+/* $Id: blit.cpp,v 1.11 2000-05-12 19:14:55 sandervl Exp $ */
 
 /*
@@ -28,7 +28,7 @@
 //******************************************************************************
 BOOL WIN32API StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest,
-                            int nWidthDest, int nHeightDest,
-                            HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
-                            int nWidthSrc, int nHeightSrc, DWORD dwRop)
+                         int nWidthDest, int nHeightDest,
+                         HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
+                         int nWidthSrc, int nHeightSrc, DWORD dwRop)
 {
  BOOL rc;
@@ -155,5 +155,6 @@
     result = O32_SetDIBitsToDevice(hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (PVOID) bits, (PBITMAPINFO)info, coloruse);
     //SvL: Wrong Open32 return value
-    result = (result == TRUE) ? lines : 0;
+//    result = (result == TRUE) ? lines : 0;
+    result = (result == TRUE) ? cy : 0;
 
     dprintf(("GDI32: SetDIBitsToDevice hdc:%X xDest:%d yDest:%d, cx:%d, cy:%d, xSrc:%d, ySrc:%d, startscan:%d, lines:%d \nGDI32: bits 0x%X, info 0x%X, coloruse %d returned %d",
Index: trunk/src/gdi32/dibsect.cpp
===================================================================
--- trunk/src/gdi32/dibsect.cpp	(revision 3525)
+++ trunk/src/gdi32/dibsect.cpp	(revision 3527)
@@ -1,3 +1,3 @@
-/* $Id: dibsect.cpp,v 1.29 2000-04-23 15:34:10 sandervl Exp $ */
+/* $Id: dibsect.cpp,v 1.30 2000-05-12 19:14:55 sandervl Exp $ */
 
 /*
@@ -38,5 +38,5 @@
 //******************************************************************************
 DIBSection::DIBSection(BITMAPINFOHEADER_W *pbmi, char *pColors, DWORD iUsage, DWORD hSection, DWORD dwOffset, DWORD handle, int fFlip)
-                : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsRGB565(NULL)
+                : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsBuffer(NULL)
 {
   bmpsize = pbmi->biWidth;
@@ -143,9 +143,4 @@
                	dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
                	dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
-
-		//double buffer for rgb 555 dib sections (for conversion)
-		if(dibinfo.dsBitfields[1] == 0x03e0) {
-			DosAllocMem((PPVOID)&bmpBitsRGB565, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
-		}
                	break;
 
@@ -167,4 +162,8 @@
 	dprintf(("BI_BITFIELDS %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
    }
+   //double buffer for rgb 555 dib sections (for conversion) or flipped sections
+   if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
+	DosAllocMem((PPVOID)&bmpBitsBuffer, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
+   }
 
    this->handle = handle;
@@ -206,6 +205,6 @@
         DosFreeMem(bmpBits);
 
-   if(bmpBitsRGB565)
- 	DosFreeMem(bmpBitsRGB565);
+   if(bmpBitsBuffer)
+ 	DosFreeMem(bmpBitsBuffer);
 
    if(pOS2bmp)
@@ -320,9 +319,4 @@
                	dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
                	dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
-		if(dibinfo.dsBitfields[1] == 0x03e0) {
-			if(bmpBitsRGB565)
-				DosFreeMem(bmpBitsRGB565);
-			DosAllocMem((PPVOID)&bmpBitsRGB565, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
-		}
                	break;
 
@@ -345,4 +339,12 @@
    }
 
+   //double buffer for rgb 555 dib sections (for conversion) or flipped sections
+   if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
+	if(bmpBitsBuffer) {
+		DosFreeMem(bmpBitsBuffer);
+	}
+	DosAllocMem((PPVOID)&bmpBitsBuffer, dibinfo.dsBm.bmWidthBytes*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
+   }
+
    dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
    if(palsize)
@@ -417,4 +419,15 @@
   }
 
+#if 0
+  nXdest = 0;
+  nYdest = 0;
+  nXsrc  = 0;
+  nXsrc  = 0;
+  nDestWidth = pOS2bmp->cx;
+  nDestHeight = pOS2bmp->cy;
+  nSrcWidth = pOS2bmp->cx;
+  nSrcHeight = pOS2bmp->cy;
+#endif
+
   //win32 coordinates are of the left top, OS/2 expects left bottom
   //source rectangle is non-inclusive (top, right not included)
@@ -443,12 +456,4 @@
 
   oldyinversion = GpiQueryYInversion(hps);
-  if(fFlip & FLIP_VERT)
-  {
-  	if(oldyinversion != hdcHeight-1) {
-    		GpiEnableYInversion(hps, hdcHeight-1);
-		fRestoryYInversion = TRUE;
-	}
-  }
-  else	
   if(oldyinversion != 0) {
 	GpiEnableYInversion(hps, 0);
@@ -464,18 +469,46 @@
   }
 
+  ULONG os2mode, winmode;
+
+  os2mode = BBO_OR;
+  winmode = GetStretchBltMode(hdcDest);
+  switch(winmode) {
+  case BLACKONWHITE_W:
+	os2mode = BBO_AND;
+	break;
+  case WHITEONBLACK_W:
+  case HALFTONE_W: //TODO:
+	os2mode = BBO_OR;
+	break;
+  case COLORONCOLOR_W:
+	os2mode = BBO_IGNORE;
+	break;
+  }
+  if(fFlip & FLIP_VERT) {
+	//manually reverse bitmap data
+	char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
+	char *dst = bmpBitsBuffer;
+	for(int i=0;i<pOS2bmp->cy;i++) {
+		memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
+		dst += dibinfo.dsBm.bmWidthBytes;
+		src -= dibinfo.dsBm.bmWidthBytes;
+	}
+	bmpBits = bmpBitsBuffer;
+  }
+
   //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
   if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
        	dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
 
-	if(bmpBitsRGB565 == NULL)
+	if(bmpBitsBuffer == NULL)
 		DebugInt3();
 
 	if(CPUFeatures & CPUID_MMX) {
-		RGB555to565MMX((WORD *)bmpBitsRGB565, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
+		RGB555to565MMX((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
 	}
-	else   	RGB555to565((WORD *)bmpBitsRGB565, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
-	rc = GpiDrawBits(hps, bmpBitsRGB565, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
-  }
-  else	rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
+	else   	RGB555to565((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
+	rc = GpiDrawBits(hps, bmpBitsBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
+  }
+  else	rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
 
   if(rc == GPI_OK) {
Index: trunk/src/gdi32/dibsect.h
===================================================================
--- trunk/src/gdi32/dibsect.h	(revision 3525)
+++ trunk/src/gdi32/dibsect.h	(revision 3527)
@@ -1,3 +1,3 @@
-/* $Id: dibsect.h,v 1.16 2000-04-18 11:11:52 sandervl Exp $ */
+/* $Id: dibsect.h,v 1.17 2000-05-12 19:14:56 sandervl Exp $ */
 
 /*
@@ -102,5 +102,5 @@
           HWND  hwndParent;
           HDC   hdc;
-          char *bmpBits, *bmpBitsRGB565;
+          char *bmpBits, *bmpBitsBuffer;
           BOOL  fFlip;
           int   bmpsize, os2bmphdrsize;
