PictToBmpFlt.cxx (45fd3b9a) | PictToBmpFlt.cxx (76e2130f) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 25 unchanged lines hidden (view full) --- 34#include <QuickTime/QuickTime.h> 35#include <postmac.h> 36 37#include "PictToBmpFlt.hxx" 38 39bool PICTtoPNG( com::sun::star::uno::Sequence<sal_Int8>& rPictData, 40 com::sun::star::uno::Sequence<sal_Int8>& rPngData) 41{ | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 25 unchanged lines hidden (view full) --- 34#include <QuickTime/QuickTime.h> 35#include <postmac.h> 36 37#include "PictToBmpFlt.hxx" 38 39bool PICTtoPNG( com::sun::star::uno::Sequence<sal_Int8>& rPictData, 40 com::sun::star::uno::Sequence<sal_Int8>& rPngData) 41{ |
42#ifdef MAC_OS_X_VERSION_10_6 43 return false; 44#else // MAC_OS_X_VERSION_10_6 |
|
42 ComponentInstance pngExporter = NULL; 43 if( OpenADefaultComponent( GraphicsExporterComponentType, kQTFileTypePNG, &pngExporter) != noErr) 44 return false; 45 46 Handle hPict = NULL; 47 if( PtrToHand( rPictData.getArray(), &hPict, rPictData.getLength()) != noErr) 48 hPict = NULL; 49 --- 17 unchanged lines hidden (view full) --- 67 if( hPict) 68 DisposeHandle( hPict); 69 if( hPng) 70 DisposeHandle( hPng); 71 if( pngExporter) 72 CloseComponent( pngExporter); 73 74 return (nPngSize > 0); | 45 ComponentInstance pngExporter = NULL; 46 if( OpenADefaultComponent( GraphicsExporterComponentType, kQTFileTypePNG, &pngExporter) != noErr) 47 return false; 48 49 Handle hPict = NULL; 50 if( PtrToHand( rPictData.getArray(), &hPict, rPictData.getLength()) != noErr) 51 hPict = NULL; 52 --- 17 unchanged lines hidden (view full) --- 70 if( hPict) 71 DisposeHandle( hPict); 72 if( hPng) 73 DisposeHandle( hPng); 74 if( pngExporter) 75 CloseComponent( pngExporter); 76 77 return (nPngSize > 0); |
78#endif // MAC_OS_X_VERSION_10_6 |
|
75} 76 77 78bool PNGtoPICT( com::sun::star::uno::Sequence<sal_Int8>& rPngData, 79 com::sun::star::uno::Sequence<sal_Int8>& rPictData) 80{ | 79} 80 81 82bool PNGtoPICT( com::sun::star::uno::Sequence<sal_Int8>& rPngData, 83 com::sun::star::uno::Sequence<sal_Int8>& rPictData) 84{ |
85#ifdef MAC_OS_X_VERSION_10_6 86 return false; 87#else // MAC_OS_X_VERSION_10_6 |
|
81 ComponentInstance pictExporter; 82 if( OpenADefaultComponent( GraphicsImporterComponentType, kQTFileTypePNG, &pictExporter) != noErr) 83 return false; 84 85 Handle hPng = NULL; 86 if( PtrToHand( rPngData.getArray(), &hPng, rPngData.getLength()) != noErr) 87 hPng = NULL; 88 --- 5 unchanged lines hidden (view full) --- 94 { 95 nPictSize = GetHandleSize( (Handle)hPict); 96 rPictData.realloc( nPictSize); 97 98 HLock( (Handle)hPict); 99 rtl_copyMemory( rPictData.getArray(), ((sal_Int8*)*hPict), nPictSize); 100 HUnlock( (Handle)hPict); 101 | 88 ComponentInstance pictExporter; 89 if( OpenADefaultComponent( GraphicsImporterComponentType, kQTFileTypePNG, &pictExporter) != noErr) 90 return false; 91 92 Handle hPng = NULL; 93 if( PtrToHand( rPngData.getArray(), &hPng, rPngData.getLength()) != noErr) 94 hPng = NULL; 95 --- 5 unchanged lines hidden (view full) --- 101 { 102 nPictSize = GetHandleSize( (Handle)hPict); 103 rPictData.realloc( nPictSize); 104 105 HLock( (Handle)hPict); 106 rtl_copyMemory( rPictData.getArray(), ((sal_Int8*)*hPict), nPictSize); 107 HUnlock( (Handle)hPict); 108 |
109#if __MAC_OS_X_VERSION_MAX_ALLOWED <= 1060 |
|
102 // Release the data associated with the picture | 110 // Release the data associated with the picture |
103 // Note: This function is deprecated in Mac OSX 10.4 | 111 // Note: This function has been deprecated in OSX 10.4 and removed in OSX 10.7 |
104 KillPicture( hPict); | 112 KillPicture( hPict); |
113#endif |
|
105 } 106 107 if( hPng) 108 DisposeHandle( hPng); 109 if( pictExporter) 110 CloseComponent( pictExporter); 111 112 return (nPictSize > 512); | 114 } 115 116 if( hPng) 117 DisposeHandle( hPng); 118 if( pictExporter) 119 CloseComponent( pictExporter); 120 121 return (nPictSize > 512); |
122#endif // MAC_OS_X_VERSION_10_6 |
|
113} 114 115bool ImageToPNG( com::sun::star::uno::Sequence<sal_Int8>& rImgData, 116 com::sun::star::uno::Sequence<sal_Int8>& rPngData, 117 NSBitmapImageFileType eInFormat) 118{ | 123} 124 125bool ImageToPNG( com::sun::star::uno::Sequence<sal_Int8>& rImgData, 126 com::sun::star::uno::Sequence<sal_Int8>& rPngData, 127 NSBitmapImageFileType eInFormat) 128{ |
129 // short circuit for PNG->PNG request 130 if( eInFormat == NSPNGFileType) { 131 rPngData = rImgData; 132 return true; 133 } 134 135 // special handling for old PICT images that are not supported by NSBitmapImage |
|
119 if( eInFormat == PICTImageFileType) 120 return PICTtoPNG( rImgData, rPngData); 121 | 136 if( eInFormat == PICTImageFileType) 137 return PICTtoPNG( rImgData, rPngData); 138 |
139 // let Cocoa's NSBitmapImageRep do the conversion |
|
122 NSData* pData = [NSData dataWithBytesNoCopy: (void*)rImgData.getConstArray() length: rImgData.getLength() freeWhenDone: 0]; 123 if( !pData) 124 return false; 125 126 NSBitmapImageRep* pRep =[NSBitmapImageRep imageRepWithData: pData]; 127 if( !pRep) 128 return false; 129 130 NSData* pOut = [pRep representationUsingType: NSPNGFileType properties: nil]; 131 if( !pOut) 132 return false; 133 | 140 NSData* pData = [NSData dataWithBytesNoCopy: (void*)rImgData.getConstArray() length: rImgData.getLength() freeWhenDone: 0]; 141 if( !pData) 142 return false; 143 144 NSBitmapImageRep* pRep =[NSBitmapImageRep imageRepWithData: pData]; 145 if( !pRep) 146 return false; 147 148 NSData* pOut = [pRep representationUsingType: NSPNGFileType properties: nil]; 149 if( !pOut) 150 return false; 151 |
152 // get the conversion result |
|
134 const size_t nPngSize = [pOut length]; 135 rPngData.realloc( nPngSize); 136 [pOut getBytes: rPngData.getArray() length: nPngSize]; 137 return (nPngSize > 0); 138} 139 140bool PNGToImage( com::sun::star::uno::Sequence<sal_Int8>& rPngData, 141 com::sun::star::uno::Sequence<sal_Int8>& rImgData, 142 NSBitmapImageFileType eOutFormat 143 ) 144{ | 153 const size_t nPngSize = [pOut length]; 154 rPngData.realloc( nPngSize); 155 [pOut getBytes: rPngData.getArray() length: nPngSize]; 156 return (nPngSize > 0); 157} 158 159bool PNGToImage( com::sun::star::uno::Sequence<sal_Int8>& rPngData, 160 com::sun::star::uno::Sequence<sal_Int8>& rImgData, 161 NSBitmapImageFileType eOutFormat 162 ) 163{ |
164 // short circuit for PNG->PNG request 165 if( eOutFormat == NSPNGFileType) { 166 rImgData = rPngData; 167 return true; 168 } 169 170 // special handling for old PICT images that are not supported by NSBitmapImage |
|
145 if( eOutFormat == PICTImageFileType) 146 return PNGtoPICT( rPngData, rImgData); | 171 if( eOutFormat == PICTImageFileType) 172 return PNGtoPICT( rPngData, rImgData); |
147 | 173 174 // let Cocoa's NSBitmapImageRep do the conversion |
148 NSData* pData = [NSData dataWithBytesNoCopy: const_cast<sal_Int8*>(rPngData.getConstArray()) length: rPngData.getLength() freeWhenDone: 0]; 149 if( !pData) 150 return false; 151 152 NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData: pData]; 153 if( !pRep) 154 return false; 155 156 NSData* pOut = [pRep representationUsingType: eOutFormat properties: nil]; 157 if( !pOut) 158 return false; 159 | 175 NSData* pData = [NSData dataWithBytesNoCopy: const_cast<sal_Int8*>(rPngData.getConstArray()) length: rPngData.getLength() freeWhenDone: 0]; 176 if( !pData) 177 return false; 178 179 NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData: pData]; 180 if( !pRep) 181 return false; 182 183 NSData* pOut = [pRep representationUsingType: eOutFormat properties: nil]; 184 if( !pOut) 185 return false; 186 |
187 // get the conversion result |
|
160 const size_t nImgSize = [pOut length]; 161 rImgData.realloc( nImgSize); 162 [pOut getBytes: rImgData.getArray() length: nImgSize]; 163 return (nImgSize > 0); 164} 165 | 188 const size_t nImgSize = [pOut length]; 189 rImgData.realloc( nImgSize); 190 [pOut getBytes: rImgData.getArray() length: nImgSize]; 191 return (nImgSize > 0); 192} 193 |