Example #1
0
// ****************************************************************************
//
//  Function Name:	REditImageInterfaceImp::GetClippingPath( )
//
//  Description:		Returns the component image's clipping path
//                   (if any).
//
//  Returns:			
//
//  Exceptions:		
//
// ****************************************************************************
//
BOOLEAN REditImageInterfaceImp::GetClippingPath( RClippingPath& rPath )
{
	// Get a pointer to the image document's image.  Note,
	// normally we can assume that it is a RBitmapImage
	// as this interface is only provided by image components,
	// but if this is a placeholder from a layout there is no
	// RBitmapImage so just return FALSE in that case.
	RBitmapImage* pImage = dynamic_cast<RBitmapImage*>(
		m_pImageDocument->GetImage() );
	if (!pImage)
		return FALSE;

	rPath.Undefine();
	RClippingPath* pPath = pImage->GetClippingRPath();

	if (pPath)
	{
		const RImageEffects& rEffects = GetImageEffects();
		RRealSize rSize = RImageLibrary().GetImageDimensions(
			m_pImageDocument->m_rInternalDataBuffer );

		R2dTransform xform;
		xform.PostScale( rSize.m_dx, rSize.m_dy );
		RRealRect rRect( rEffects.m_rCropArea * xform );

		xform.MakeIdentity();
		xform.PostTranslate( rRect.m_Left, rSize.m_dy - rRect.m_Bottom - rRect.m_Top );
		rPath = RClippingPath( *pPath, xform );

		return TRUE;
	}

	return FALSE;
}
Example #2
0
// ****************************************************************************
//
//  Function Name:	REditImageInterfaceImp::SetClippingPath( )
//
//  Description:		Sets the clipping path into the components
//                   image.
//
//  Returns:			
//
//  Exceptions:		
//
// ****************************************************************************
//
void REditImageInterfaceImp::SetClippingPath( const RClippingPath* path )
{
	// Get a pointer to the image document's image.  Note,
	// we should be able to assume that it is a RBitmapImage,
	// as this interface is only provided by image components
	// with RBitmapImages.
	RBitmapImage* pImage = dynamic_cast<RBitmapImage*>(
		m_pImageDocument->GetImage() );
	TpsAssert( pImage, "Invalid image component!" );

	if (path)
	{
		RClippingPath rPath( *path );
		m_pImageDocument->SetCropRectFromPath( &rPath, TRUE );
		pImage->SetRPath( &rPath );
	}
	else if (!pImage->PathFromImport())
	{
		m_pImageDocument->SetCropRectFromPath( NULL, FALSE );
		pImage->DeleteRPath();
	}

	else
		return;

	ApplyImageEffects();
}
Example #3
0
void	RRotateDialog::RotateDisplay( int iPos )
{
	if ( iPos == m_iPrevPos )
		return;

	// We need to use the RBitmap::Rotate() function, so to do that, convert to
	// Renaissance types.
	CClientDC			clientDC( &m_staticDisplay );
	HDC					hClientDC = clientDC.GetSafeHdc();

	RDcDrawingSurface	drawSurface;
	drawSurface.Initialize( hClientDC, hClientDC );

	R2dTransform transform;

	// Prepare the image on an offscreen DC
	RAutoDrawingSurface	drawSurfaceOffscreen;
	RRealRect				rRealStaticRect(m_rectStaticDisplay);
	BOOLEAN					fPrepared = drawSurfaceOffscreen.Prepare( &drawSurface, transform, rRealStaticRect );
	RDrawingSurface*		pSurface	= ( (fPrepared)? &drawSurfaceOffscreen : &drawSurface );

	// Paint the offscreen DC white
	RColor rColor = RSolidColor( kWhite );
	pSurface->SetFillColor( rColor );
	pSurface->SetPenColor( rColor );
	pSurface->FillRectangle( m_rectStaticDisplay );

	YAngle	flRadiansRotation = ::DegreesToRadians( YFloatType( iPos ) );

	// The rotation leaves a black background, so blit with a mask.  The mask
	// has to be created the same size as the original (not rotated) bitmap
	// size, so create it and then rotate it.
	RBitmapImage		bmpRotated;
	RBitmapImage		bmpMaskRotated;
	RImageLibrary rLibrary;
	rLibrary.Rotate( m_rBitmapImage, bmpRotated, bmpMaskRotated, flRadiansRotation );

	RIntSize				sizeBmpRotated;
	sizeBmpRotated.m_dx = bmpRotated.GetWidthInPixels();
	sizeBmpRotated.m_dy = bmpRotated.GetHeightInPixels();

	RIntRect				rectSource;
	RIntRect				rectDest;
	DeriveSourceAndDestinationRects( sizeBmpRotated, rectSource, rectDest );

	bmpRotated.RenderWithMask( *pSurface, bmpMaskRotated, rectSource, rectDest );

	if ( fPrepared )
		drawSurfaceOffscreen.Release();
	drawSurface.DetachDCs();

	m_iPrevPos = iPos;
}
Example #4
0
// ****************************************************************************
//
//  Function Name:	RImageInterfaceImp::GetImage( )
//
//  Description:		Gets the image of a component
//
//  Returns:			the components image
//
//  Exceptions:		None
//
// ****************************************************************************
//
RImage* RImageInterfaceImp::CopySourceImage()
{
	RImageLibrary rLibrary;
	RImage* pImage = rLibrary.ImportImage( m_pImageDocument->m_rInternalDataBuffer );

	RBitmapImage* pBitmap = dynamic_cast<RBitmapImage*>( pImage );

	if (pBitmap)
	{
		REditImageInterfaceImp rInterface( (RImageView *)
			m_pImageDocument->GetActiveView() );

		RClippingPath rPath;
		rInterface.GetClippingPath( rPath );
		pBitmap->SetRPath( &rPath );
	}

	return pImage;
}
// ****************************************************************************
//
//  Function Name:	BitmapImageList::Add()
//
//  Description:		Adds one or more images or an icon to the image 
//                   list.
//
//  Returns:			Zero-based index of the first new image if 
//                   successful; otherwise -1.
//
//  Exceptions:		None
//
// ****************************************************************************
int RBitmapImageList::Add( RBitmapImage* pbmImage, YPlatformColor crMask )
{
	if (m_fMask)
	{
		RBitmapImage bmMask ;

		try
		{
			uLONG ulWidth  = pbmImage->GetWidthInPixels() ;
			uLONG ulHeight = pbmImage->GetHeightInPixels() ;

			bmMask.Initialize( ulWidth, ulHeight, 1 ) ;

			ROffscreenDrawingSurface dsDest ;
			ROffscreenDrawingSurface dsSrc;

			dsDest.SetImage( &bmMask ) ;

			dsSrc.SetImage( pbmImage ) ;
			dsSrc.SetFontColor( RSolidColor( !crMask ) ) ;
			dsSrc.SetFillColor( RSolidColor( crMask ) ) ;

			RIntRect rcRect( 0, 0, ulWidth, ulHeight ) ;
			dsDest.BlitDrawingSurface( dsSrc, rcRect, rcRect, kBlitSourceCopy ) ;

			dsSrc.ReleaseImage() ;
			dsDest.ReleaseImage() ;

			return Add( pbmImage, &bmMask ) ;
		}
		catch( YException )
		{
			return -1 ;
		}
	}

	return Add( pbmImage, (RBitmapImage*) NULL ) ;
}
//////////////////////////////////////////////////////////////////////////////
//
//	void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir ) 
//
//	export a graphic to file from a component view
//
//////////////////////////////////////////////////////////////////////////////
void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir /*=NULL*/) 
{
	RImageLibrary rLibrary ;
	CArray<int, int> arrFileFormats ;

	//
	// Build the export file filter list...
	//
	CString strFilter, str ;

	for (int i = 0; i < kNumFormats - 1; i++)
	{
		if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] ))
		{
			str.LoadString( kImageExportFilters[i][1] ) ;
			strFilter += str ;

			arrFileFormats.Add( kImageExportFilters[i][0] ) ;
		}
	}

	TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ;
	str.LoadString( kImageExportFilters[i][1] ) ;  
	strFilter += str ;
	strFilter += "|" ;

	arrFileFormats.Add( kImageExportFilters[i][0] ) ;

	//
	// Create and execute the dialog...
	//
	RExportGraphicDlg dlg( pComponentView, strFilter ) ;

	// Load in the dialog title string
	CString strTitle ;
	strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ;
	dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ;
	if( pInitialDir )
	{
		dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir;
	}

	if (IDOK == dlg.DoModal())
	{
		RMBCString   strPathName = dlg.GetPathName() ;
		RIntSize     szImageSize = dlg.GetSize() ;

		_nFilterIndex = dlg.m_ofn.nFilterIndex ;
		EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ;
		RRealSize pictureSize  = pComponentView->GetReferenceSize() ;

		try
		{
			if (kImageFormatXRX == eFormat)
			{
				RRealSize outputSize( szImageSize.m_dx, szImageSize.m_dy ) ; //   = pictureSize ;
				RRealSize screenDPI    = ::GetScreenDPI() ;

				RVectorImage vectorImage ;
				vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( outputSize.m_dx, (uLONG) screenDPI.m_dx ) ) ;
				vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( outputSize.m_dy, (uLONG) screenDPI.m_dy ) ) ;

				// Create an offscreen drawing surface and set the picture
				ROffscreenDrawingSurface drawingSurface;
				drawingSurface.SetImage( &vectorImage );

				R2dTransform transform ;

				// Scale to the device DPI
				RRealSize deviceDPI = drawingSurface.GetDPI( );
				transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, 
					(YFloatType) deviceDPI.m_dy / screenDPI.m_dy );

				transform.PreScale( 
					outputSize.m_dx / pictureSize.m_dx,
					outputSize.m_dy / pictureSize.m_dy ) ;

				// Render the component
				RRealRect outputRect( pictureSize ) ;
				pComponentView->Render( drawingSurface, transform, outputRect ) ;

				drawingSurface.ReleaseImage( );

				rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ;
				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			} // if (XRX)
			else
			{
				// Check for a image interface
				RImageInterface* pInterface = (RImageInterface *) 
					pComponentView->GetInterface( kImageInterfaceId ) ;

				if (pInterface)
				{
					pInterface->Export( strPathName, eFormat ) ;
					delete pInterface ;
				}
				else
				{
					// Initialize the new bitmap at a bit depth of 24
					RBitmapImage image ;
					image.Initialize( szImageSize.m_dx, szImageSize.m_dy, 24 ) ;

					ROffscreenDrawingSurface dsMem ; 
					dsMem.SetImage( &image ) ;

					R2dTransform transform ;
					transform.PreScale( 
						szImageSize.m_dx / pictureSize.m_dx,
						szImageSize.m_dy / pictureSize.m_dy ) ;

					// Render the component
					dsMem.SetFillColor( RSolidColor( kWhite ) ) ;
					dsMem.FillRectangle( RRealRect( pictureSize ), transform ) ;
					pComponentView->Render( dsMem, transform, RIntRect( 
						RIntSize( pictureSize.m_dx, pictureSize.m_dy ) ) ) ;

					dsMem.ReleaseImage() ;
					
					rLibrary.ExportImage( image, strPathName, eFormat ) ;
				}

				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			
			} // else

		} // try

		catch( YException e)
		{
			ReportException( e ) ;
		}

	} // if (IDOK)
}
Example #7
0
RBitmapImage&	RWinColorPalette::GetPaletteBitmapImage( )
{
	static BOOLEAN			m_fPaletteInitialized = FALSE;
	static RBitmapImage	m_biPalette;

	if ( !m_fPaletteInitialized )
	{
		// find the resource in the resource file
		HRSRC hRsrc = FindResource( AfxGetResourceHandle(), 
			MAKEINTRESOURCE( m_uPaletteBitmapID ), RT_BITMAP );

		if ( hRsrc != NULL )
		{
			// get a handle to the resource data
			HGLOBAL hTemp = LoadResource( AfxGetResourceHandle(), hRsrc );

			if ( hTemp != NULL )
			{
				// Initlize the palette bitmap with the resource data
				m_biPalette.Initialize( LockResource( hTemp ) );

				// unlock and free the resource
				UnlockResource( hTemp );
				FreeResource( hTemp );
			}
			else
				AfxThrowResourceException( );
		}
		else
			AfxThrowResourceException( );

		m_fPaletteInitialized = TRUE;

		COLORMAP crColorMap[] =
		{
			{ RGB( 255, 255, 255 ), GetSysColor( COLOR_BTNHIGHLIGHT ) },
			{ RGB( 192, 192, 192 ), GetSysColor( COLOR_BTNFACE )      },
			{ RGB( 128, 128, 128 ), GetSysColor( COLOR_BTNSHADOW )    }
		};

		RIntPoint ptCells[] = 
		{
			FindColor( crColorMap[0].from ),
			FindColor( crColorMap[1].from ),
			FindColor( crColorMap[2].from )
		};

		void*     pRawData   = m_biPalette.GetRawData();
		RGBQUAD*  pColorData = (RGBQUAD *) RBitmapImage::GetColorData( pRawData );
		LPBYTE    pImageData = (LPBYTE) RBitmapImage::GetImageData( pRawData );

		for (int j = 0; (LPVOID) pColorData < (LPVOID) pImageData; j++, pColorData++)
		{
			for (int i = 0; i < NumElements( crColorMap ); i++)
			{
				if (crColorMap[i].from == RGB( pColorData->rgbRed, pColorData->rgbGreen, pColorData->rgbBlue ))
				{
					pColorData->rgbBlue  = GetBValue( crColorMap[i].to );
					pColorData->rgbRed   = GetRValue( crColorMap[i].to );
					pColorData->rgbGreen = GetGValue( crColorMap[i].to );
					pColorData->rgbReserved = 0;
				}
			}

			if (j == 9)
			{
				// We only need to look at the system colors, so
				// jump to the last 10 entries in the palette.
				pColorData += 235;
			}
		}

		m_biPalette.UpdatePalette();

		//
		// Relace the cells that got remapped
		//
		ROffscreenDrawingSurface dsMem;
		dsMem.SetImage( &m_biPalette );

		RSolidColor rSolid;

		for (int i = 0; i < NumElements( ptCells ); i++)
		{
			if (ptCells[i].m_x >= 0 && ptCells[i].m_y >= 0)
			{
				RIntRect rcCell( RIntSize( kCellSize.m_dx - 2, kCellSize.m_dy - 2 ) );
				rcCell.Offset( RIntSize( ptCells[i].m_x + 1, ptCells[i].m_y + 1 ) );

				rSolid = crColorMap[i].from;

				RColor rColor( rSolid );
				dsMem.SetFillColor( rColor );
				dsMem.FillRectangle( rcCell );
			}
		}

		dsMem.ReleaseImage();
	}

	return m_biPalette;
}