+++ /dev/null
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include "stdafx.h"\r
-\r
-#include <d2d1.h>\r
-#include <d2d1helper.h>\r
-\r
-#include "../DataStream.h"\r
-\r
-#include "Direct2DException.h"\r
-\r
-#include "ConversionMethods.h"\r
-#include "Bitmap.h"\r
-\r
-const IID IID_ID2D1Bitmap = __uuidof(ID2D1Bitmap);\r
-\r
-using namespace System;\r
-using namespace System::Drawing;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct2D\r
-{\r
- Bitmap::Bitmap( RenderTarget^ renderTarget, System::Drawing::Size size )\r
- {\r
- ID2D1Bitmap *bitmap = NULL;\r
-\r
- HRESULT hr = renderTarget->InternalPointer->CreateBitmap( D2D1::SizeU( size.Width, size.Height ), D2D1::BitmapProperties(), &bitmap );\r
- if( RECORD_D2D( hr ).IsFailure )\r
- throw gcnew Direct2DException( Result::Last );\r
-\r
- Construct( bitmap );\r
- }\r
-\r
- Bitmap::Bitmap( RenderTarget^ renderTarget, System::Drawing::Size size, BitmapProperties properties )\r
- {\r
- ID2D1Bitmap *bitmap = NULL;\r
-\r
- HRESULT hr = renderTarget->InternalPointer->CreateBitmap( D2D1::SizeU( size.Width, size.Height ), BitmapProperties::ToUnmanaged( properties ), &bitmap );\r
- if( RECORD_D2D( hr ).IsFailure )\r
- throw gcnew Direct2DException( Result::Last );\r
-\r
- Construct( bitmap );\r
- }\r
-\r
- Bitmap::Bitmap( RenderTarget^ renderTarget, System::Drawing::Size size, DataStream^ data, int pitch )\r
- {\r
- ID2D1Bitmap *bitmap = NULL;\r
-\r
- HRESULT hr = renderTarget->InternalPointer->CreateBitmap( D2D1::SizeU( size.Width, size.Height ), data->DataPointer.ToPointer(), pitch,\r
- D2D1::BitmapProperties(), &bitmap );\r
-\r
- if( RECORD_D2D( hr ).IsFailure )\r
- throw gcnew Direct2DException( Result::Last );\r
-\r
- Construct( bitmap );\r
- }\r
-\r
- Bitmap::Bitmap( RenderTarget^ renderTarget, System::Drawing::Size size, DataStream^ data, int pitch, BitmapProperties properties )\r
- {\r
- ID2D1Bitmap *bitmap = NULL;\r
-\r
- HRESULT hr = renderTarget->InternalPointer->CreateBitmap( D2D1::SizeU( size.Width, size.Height ), data->DataPointer.ToPointer(), pitch,\r
- BitmapProperties::ToUnmanaged( properties ), &bitmap );\r
-\r
- if( RECORD_D2D( hr ).IsFailure )\r
- throw gcnew Direct2DException( Result::Last );\r
-\r
- Construct( bitmap );\r
- }\r
-\r
- Result Bitmap::FromBitmap( Bitmap^ sourceBitmap )\r
- {\r
- HRESULT hr = InternalPointer->CopyFromBitmap( NULL, sourceBitmap->InternalPointer, NULL );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromBitmap( Bitmap^ sourceBitmap, Point destinationPoint )\r
- {\r
- HRESULT hr = InternalPointer->CopyFromBitmap( reinterpret_cast<D2D1_POINT_2U*>( &destinationPoint ), sourceBitmap->InternalPointer, NULL );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromBitmap( Bitmap^ sourceBitmap, Point destinationPoint, System::Drawing::Rectangle sourceArea )\r
- {\r
- D2D1_RECT_U rect = ConvertRectangle( sourceArea );\r
-\r
- HRESULT hr = InternalPointer->CopyFromBitmap( reinterpret_cast<D2D1_POINT_2U*>( &destinationPoint ), sourceBitmap->InternalPointer, &rect );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromRenderTarget( RenderTarget^ renderTarget )\r
- {\r
- HRESULT hr = InternalPointer->CopyFromRenderTarget( NULL, renderTarget->InternalPointer, NULL );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromRenderTarget( RenderTarget^ renderTarget, System::Drawing::Point destinationPoint )\r
- {\r
- HRESULT hr = InternalPointer->CopyFromRenderTarget( reinterpret_cast<D2D1_POINT_2U*>( &destinationPoint ), renderTarget->InternalPointer, NULL );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromRenderTarget( RenderTarget^ renderTarget, System::Drawing::Point destinationPoint, System::Drawing::Rectangle sourceArea )\r
- {\r
- D2D1_RECT_U rect = ConvertRectangle( sourceArea );\r
-\r
- HRESULT hr = InternalPointer->CopyFromRenderTarget( reinterpret_cast<D2D1_POINT_2U*>( &destinationPoint ), renderTarget->InternalPointer, &rect );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromMemory( array<Byte>^ memory, int pitch )\r
- {\r
- pin_ptr<Byte> pinnedMemory = &memory[0];\r
-\r
- HRESULT hr = InternalPointer->CopyFromMemory( NULL, pinnedMemory, pitch );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromMemory( array<Byte>^ memory, int pitch, System::Drawing::Rectangle destinationArea )\r
- {\r
- pin_ptr<Byte> pinnedMemory = &memory[0];\r
- D2D1_RECT_U rect = ConvertRectangle( destinationArea );\r
-\r
- HRESULT hr = InternalPointer->CopyFromMemory( &rect, pinnedMemory, pitch );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromMemory( IntPtr pointer, int pitch )\r
- {\r
- HRESULT hr = InternalPointer->CopyFromMemory( NULL, pointer.ToPointer(), pitch );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromMemory( IntPtr pointer, int pitch, System::Drawing::Rectangle destinationArea )\r
- {\r
- D2D1_RECT_U rect = ConvertRectangle( destinationArea );\r
-\r
- HRESULT hr = InternalPointer->CopyFromMemory( &rect, pointer.ToPointer(), pitch );\r
- return RECORD_D2D( hr );\r
- }\r
-\r
- Result Bitmap::FromStream( System::IO::Stream^ stream, int pitch, int length )\r
- {\r
- DataStream^ dataStream;\r
- array<Byte>^ bytes = Utilities::ReadStream( stream, length, &dataStream );\r
-\r
- if( bytes == nullptr )\r
- return FromMemory( dataStream->DataPointer, pitch );\r
- else\r
- return FromMemory( bytes, pitch );\r
- }\r
-\r
- Result Bitmap::FromStream( System::IO::Stream^ stream, int pitch, int length, System::Drawing::Rectangle destinationArea )\r
- {\r
- DataStream^ dataStream;\r
- array<Byte>^ bytes = Utilities::ReadStream( stream, length, &dataStream );\r
-\r
- if( bytes == nullptr )\r
- return FromMemory( dataStream->DataPointer, pitch, destinationArea );\r
- else\r
- return FromMemory( bytes, pitch, destinationArea );\r
- }\r
-\r
- SlimDX::Direct2D::PixelFormat Bitmap::PixelFormat::get()\r
- {\r
- D2D1_PIXEL_FORMAT pf = InternalPointer->GetPixelFormat();\r
- return SlimDX::Direct2D::PixelFormat( static_cast<SlimDX::DXGI::Format>( pf.format ), static_cast<AlphaMode>( pf.alphaMode ) );\r
- }\r
-\r
- System::Drawing::SizeF Bitmap::Size::get()\r
- {\r
- D2D1_SIZE_F size = InternalPointer->GetSize();\r
- return System::Drawing::SizeF( size.width, size.height );\r
- }\r
-\r
- System::Drawing::Size Bitmap::PixelSize::get()\r
- {\r
- D2D1_SIZE_U size = InternalPointer->GetPixelSize();\r
- return System::Drawing::Size( size.width, size.height );\r
- }\r
-\r
- System::Drawing::SizeF Bitmap::DotsPerInch::get()\r
- {\r
- float x, y;\r
- InternalPointer->GetDpi( &x, &y );\r
- return System::Drawing::SizeF( x, y );\r
- }\r
-}\r
-}
\ No newline at end of file