cleanup for Core Graphics / removing QD

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46075 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2007-05-16 18:24:01 +00:00
parent 20edcc0e99
commit cc9249ea7f
2 changed files with 75 additions and 36 deletions

View File

@@ -1449,7 +1449,7 @@ void wxBitmap::SetMask(wxMask *mask)
WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
{ {
#ifndef __LP64__ #if !wxMAC_USE_CORE_GRAPHICS
return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((CGContextRef*)mask)); return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((CGContextRef*)mask));
#else #else
return WXHBITMAP(M_BITMAPDATA->GetBitmapContext()); return WXHBITMAP(M_BITMAPDATA->GetBitmapContext());

View File

@@ -27,7 +27,7 @@
#include "wx/metafile.h" #include "wx/metafile.h"
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
#include "wx/mac/private.h" #include "wx/mac/uma.h"
#ifndef __DARWIN__ #ifndef __DARWIN__
#include <Scrap.h> #include <Scrap.h>
@@ -314,25 +314,46 @@ void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
if (m_bitmap.Ok()) if (m_bitmap.Ok())
{ {
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
#ifdef __LP64__ CGImageRef cgImageRef = (CGImageRef) m_bitmap.CGImageCreate();
#else #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
// export as TIFF if ( UMAGetSystemVersion() >= 0x1040 )
GraphicsExportComponent exporter = 0;
OSStatus err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeTIFF, &exporter);
if (noErr == err)
{ {
m_pictHandle = NewHandle(0); CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef destination = CGImageDestinationCreateWithData( data , kUTTypeTIFF , 1 , NULL );
if ( destination )
{
CGImageDestinationAddImage( destination, cgImageRef, NULL );
CGImageDestinationFinalize( destination );
CFRelease( destination );
}
m_pictHandle = NewHandle(CFDataGetLength(data));
if ( m_pictHandle ) if ( m_pictHandle )
{ {
CGImageRef cgImageRef = (CGImageRef) m_bitmap.CGImageCreate(); memcpy( *(Handle)m_pictHandle, (const char *)CFDataGetBytePtr(data), CFDataGetLength(data) );
err = GraphicsExportSetInputCGImage( exporter, cgImageRef); }
err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle); CFRelease( data );
err = GraphicsExportDoExport(exporter, NULL); }
CGImageRelease(cgImageRef); else
#endif
#ifndef __LP64__
{
// export as TIFF
GraphicsExportComponent exporter = 0;
OSStatus err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeTIFF, &exporter);
if (noErr == err)
{
m_pictHandle = NewHandle(0);
if ( m_pictHandle )
{
err = GraphicsExportSetInputCGImage( exporter, cgImageRef);
err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle);
err = GraphicsExportDoExport(exporter, NULL);
}
CloseComponent( exporter );
} }
CloseComponent( exporter );
} }
#endif #endif
CGImageRelease(cgImageRef);
#else #else
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle(); m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
m_pictCreated = false; m_pictCreated = false;
@@ -407,32 +428,50 @@ bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
Handle picHandle = NewHandle( nSize ); Handle picHandle = NewHandle( nSize );
memcpy( *picHandle, pBuf, nSize ); memcpy( *picHandle, pBuf, nSize );
m_pictHandle = picHandle; m_pictHandle = picHandle;
#ifdef __LP64__ CGImageRef cgImageRef = 0;
#else #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if ( UMAGetSystemVersion() >= 0x1040 )
// import from TIFF
GraphicsImportComponent importer = 0;
OSStatus err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypeTIFF, &importer);
if (noErr == err)
{ {
if ( picHandle ) CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) pBuf, nSize, kCFAllocatorNull);
CGImageSourceRef source = CGImageSourceCreateWithData( data, NULL );
if ( source )
{ {
ComponentResult result = GraphicsImportSetDataHandle(importer, picHandle); cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
if ( result == noErr ) }
{ CFRelease( source );
Rect frame; CFRelease( data );
GraphicsImportGetNaturalBounds( importer, &frame ); }
CGImageRef cgImageRef = 0; else
GraphicsImportCreateCGImage( importer, &cgImageRef, kGraphicsImportCreateCGImageUsingCurrentSettings ); #endif
m_bitmap.Create( frame.right - frame.left, frame.bottom - frame.top ); #ifndef __LP64__
CGRect r = CGRectMake( 0 , 0 , frame.right - frame.left , frame.bottom - frame.top ); {
CGContextDrawImage( (CGContextRef) m_bitmap.GetHBITMAP() , r, cgImageRef ) ; // import from TIFF
CGImageRelease(cgImageRef); GraphicsImportComponent importer = 0;
} OSStatus err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypeTIFF, &importer);
if (noErr == err)
{
if ( picHandle )
{
ComponentResult result = GraphicsImportSetDataHandle(importer, picHandle);
if ( result == noErr )
{
Rect frame;
GraphicsImportGetNaturalBounds( importer, &frame );
GraphicsImportCreateCGImage( importer, &cgImageRef, kGraphicsImportCreateCGImageUsingCurrentSettings );
}
}
CloseComponent( importer );
} }
CloseComponent( importer );
} }
#endif #endif
if ( cgImageRef )
{
m_bitmap.Create( CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
CGContextDrawImage( (CGContextRef) m_bitmap.GetHBITMAP() , r, cgImageRef ) ;
CGImageRelease(cgImageRef);
cgImageRef = NULL;
}
#else #else
PicHandle picHandle = (PicHandle)NewHandle( nSize ); PicHandle picHandle = (PicHandle)NewHandle( nSize );
memcpy( *picHandle, pBuf, nSize ); memcpy( *picHandle, pBuf, nSize );