[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 907
Date       : Wed Apr 26 21:21:04 BST 2006

Changed paths:
   M /Trunk/XaraLX/wxOil/oilbitmap.cpp
   M /Trunk/XaraLX/wxOil/oilbitmap.h
   M /Trunk/XaraLX/wxOil/osrndrgn.cpp

Some bitmap gallery progress


Diff:
Index: Trunk/XaraLX/wxOil/oilbitmap.cpp
===================================================================
--- Trunk/XaraLX/wxOil/oilbitmap.cpp	(revision 906)
+++ Trunk/XaraLX/wxOil/oilbitmap.cpp	(revision 907)
@@ -2145,8 +2145,60 @@
 	return(TRUE);
 }
 
+/********************************************************************************************
 
+>	virtual wxImage * CWxBitmap::MakewxImage(BOOL UsePalette) const;
 
+	Author:		Alex Bligh
+	Created:	26/04/2006
+
+	Inputs:		UsePalette -Ignored for deep bitmaps
+							For <=8bpp bitmaps, if this value is:
+								FALSE, the bitmap's palette will be ignored, and the actual pixel
+								(palette index) value will be returned as a greyscale RGB value
+								TRUE, the pixel index value will be used to retrieve the 24bpp
+								palette entry for the pixel, if a palette is available.
+
+	Outputs:	None
+
+	Returns:	A pointer to a wxImage, or NULL for failure
+
+	Purpose:	Makes a wxBitmap, slowly
+
+				The scanline will be converted up from 1, 4, 8, 24, or 32bpp into
+				the generic Pixel32bpp format.
+
+	Notes:		This function basically just calls ReadPixel for all pixels in the scanline
+
+	SeeAlso:	CWxBitmap::ReadPixel32bpp
+
+********************************************************************************************/
+
+wxImage * CWxBitmap::MakewxImage(BOOL UsePalette)
+{
+	wxImage * pImage = new wxImage(GetWidth(), GetHeight(), /*TYPENOTE: Correct*/ false);
+	if (!pImage)
+		return NULL;
+	pImage->SetAlpha();
+	if (!pImage->HasAlpha())
+	{
+		delete pImage;
+		return NULL;
+	}
+
+	RebuildXPEBitmap();
+
+	for (UINT32 YPos = 0; YPos < GetHeight(); YPos++) for (UINT32 XPos = 0; XPos < GetWidth(); XPos++)
+	{
+		Pixel32bpp p = ReadPixel32bpp(XPos, YPos, UsePalette);
+		pImage->SetRGB(XPos, YPos, p.Red, p.Blue, p.Green);
+		pImage->SetAlpha(XPos, YPos, 255-p.Alpha); // wxImage alpha has 0 for fully transparent
+	}
+
+	return(pImage);
+}
+
+
 /********************************************************************************************
 
 >	void CWxBitmap::ColourSeparateScanline32to8(ColourContext *OutputContext, BYTE *SepTables,
Index: Trunk/XaraLX/wxOil/oilbitmap.h
===================================================================
--- Trunk/XaraLX/wxOil/oilbitmap.h	(revision 906)
+++ Trunk/XaraLX/wxOil/oilbitmap.h	(revision 907)
@@ -161,6 +161,7 @@
 	// Helper function used by ExportSeparatedData - this retrieves one scanline of the
 	// bitmap as generic 24bpp RGB data.
 	virtual BOOL GetScanline32bpp(UINT32 YPos, BOOL UsePalette, Pixel32bpp *Scanline);
+	virtual wxImage * MakewxImage(BOOL UsePalette=TRUE);
 
 	virtual OILBitmap* MakeCopy(); // returns a copy of this object
 protected:
Index: Trunk/XaraLX/wxOil/osrndrgn.cpp
===================================================================
--- Trunk/XaraLX/wxOil/osrndrgn.cpp	(revision 906)
+++ Trunk/XaraLX/wxOil/osrndrgn.cpp	(revision 907)
@@ -2202,20 +2202,21 @@
 {
 	wxString Text = (wxString)(TCHAR *)(*TheText);
 	wxRect Rect(0,0,0,0);
+
+	wxDC * pDC = RenderDC;
+	wxSize DPI = GetFixedDCPPI(*pDC);
+	INT32 XDPI = DPI.GetWidth();
+	INT32 YDPI = DPI.GetHeight();
+	INT32 LineHeight = RenderDC->GetCharHeight();
+
 	if (uFormat & FORMAT_CALCRECT) // just calculate the rect needed to draw the text and return
 	{
-		INT32 LineHeight = 0;
 		// This won't actually draw the text, instead it returns a rectangle in 'Rect'	
 		// LineHeight = RenderDC->DrawText((TCHAR *) (*TheText), -1, &Rect, uFormat);
-		LineHeight = RenderDC->GetCharHeight();
 		wxCoord w, h;
 		RenderDC->GetTextExtent(Text, &w, &h);
 		Rect = wxRect(0, 0, w, h);
 
-		wxDC * pDC = RenderDC;
-		wxSize DPI = GetFixedDCPPI(*pDC);
-		INT32 XDPI = DPI.GetWidth();
-		INT32 YDPI = DPI.GetHeight();
 
 		if(XDPI == 0 || YDPI == 0 || LineHeight == 0)
 		{
@@ -2231,7 +2232,13 @@
 		return;
 	}
 	
-	Rect = DocRectToWin(BoundsRect, 0,0,0,0, TRUE);
+	// We plot using the TOP of the rectangle supplied (that's the highest DocCoord
+	// but we need to center it (i.e. reduce the value
+	DocRect brect=BoundsRect;
+
+	brect.hi.y -= ((brect.hi.y-brect.lo.y)-(INT32)(((double)LineHeight * IN_MP_VAL) / YDPI))/2;
+
+	Rect = DocRectToWin(brect, 0,0,0,0, TRUE);
 	// Rect = DocRectToWin(BoundsRect, 0,-1,1,0, TRUE);
 
 	// Small 'fix' - If we DrawRect the 'BoundsRect' then windows draws the text 1 pixel
@@ -2240,7 +2247,6 @@
 	if (Rect.width>0)		// Still a valid rectangle?
 	{
 //		Rect.x--;
-//		INT32 LineHeight;
 
 		RenderDC->SetBackgroundMode(wxTRANSPARENT);
 		RenderDC->DrawText(Text, Rect.GetLeft(), Rect.GetTop());
@@ -3385,8 +3391,6 @@
 
 BOOL OSRenderRegion::DrawTransformedBitmap(NodeBitmap *pNodeBitmap)
 {
-	PORTNOTETRACE("other","OSRenderRegion::DrawTransformedBitmap - do nothing");
-#ifndef EXCLUDE_FROM_XARALX
 	// If we are not printing, then we'll always render as a bitmap fill
 	// (eg. Gallery items).
 	if (IsPrinting())
@@ -3424,40 +3428,16 @@
 				INT32 DestWidth = (INT32) ((((double) Width) / dPixelSize) + 0.5);
 				INT32 DestHeight = (INT32) ((((double) Height) / dPixelSize) + 0.5);
 
-				// Make sure the Blit is the correct quality
-				INT32 OldMode = RenderDC->SetStretchBltMode(HALFTONE);
-
-				// Must call SetBrushOrgEx() after setting the stretchblt mode 
-				// to HALFTONE (see Win32 SDK docs).
-				POINT OldOrg;
-				SetBrushOrgEx(RenderDC->m_hDC, 0, 0, &OldOrg);
-
 				// Get handle to bitmap (must be a WinBitmap as we are in winoil!)
-				WinBitmap *WinBM = (WinBitmap *) pNodeBitmap->GetBitmap()->ActualBitmap;
+				CWxBitmap *WxBM = (CWxBitmap *) pNodeBitmap->GetBitmap()->ActualBitmap;
 
-				// Blit the bitmap to the DC
-				INT32 Result = StretchDIBits( RenderDC->m_hDC, 
+				wxImage *pwxImage=WxBM->MakewxImage();
 
-						  					DestTopLeft.x, DestTopLeft.y,
-						  					DestWidth, DestHeight,
-
-						  					0,0,										// source 0,0
-						  					WinBM->BMInfo->bmiHeader.biWidth,			// source W
-						  					WinBM->BMInfo->bmiHeader.biHeight,			// source H
-
-						  					WinBM->BMBytes,
-						  					WinBM->BMInfo,
-						  					DIB_RGB_COLORS,
-						  					SRCCOPY );
-
-				// Restore StretchBlt mode and brush origin
-				RenderDC->SetStretchBltMode(OldMode);
-				SetBrushOrgEx(RenderDC->m_hDC, OldOrg.x, OldOrg.y, NULL);
-
-				if (Result != GDI_ERROR)
+				if (pwxImage)
 				{
-					// All done
-					return TRUE;
+					wxBitmap TheBitmap(pwxImage->Rescale(DestWidth, DestHeight));
+					delete pwxImage;
+					RenderDC->DrawBitmap(TheBitmap, DestTopLeft.x, DestTopLeft.y, TRUE);
 				}
 			}
 		}
@@ -3469,9 +3449,6 @@
 	RenderComplexShapes = FALSE;
 
 	return bOk;
-#else
-	return TRUE;
-#endif
 }
 
 /********************************************************************************************


Xara