45 #if defined(macintosh)
51 #include <AppleEvents.h>
52 #include <AERegistry.h>
53 #include <AEObjects.h>
54 #include <AEPackObject.h>
55 #include <Processes.h>
56 #include <QuickDraw.h>
57 #include <QDOffscreen.h>
59 #include <ImageCompression.h>
60 #include <PictUtils.h>
63 #include <TextUtils.h>
64 #define ColorInfo KolorInfo
83 ImageDescriptionHandle
84 image_description = nil;
90 SearchForFile(OSType,OSType,FSSpec *,
short);
93 ArcMethod(GrafVerb,Rect *,
short,
short),
94 BitsMethod(BitMap *,Rect *,Rect *,
short,RgnHandle),
95 FilenameToFSSpec(
const char *
filename,FSSpec *fsspec),
97 OvalMethod(GrafVerb,Rect *),
98 PolyMethod(GrafVerb,PolyHandle),
99 RRectMethod(GrafVerb,Rect *,
short,
short),
100 RectMethod(GrafVerb,Rect *),
101 RegionMethod(GrafVerb,RgnHandle),
102 StandardPixmap(PixMapPtr,Rect *,MatrixRecordPtr,
short,RgnHandle,PixMapPtr,
104 TextMethod(
short,Ptr,Point,Point);
109 #if defined(DISABLE_SIOUX)
110 static MACEventHookPtr
113 static MACErrorHookPtr
114 exception.hook = nil;
147 static pascal
void ArcMethod(GrafVerb verb,Rect *r,
short startAngle,
150 #pragma unused (verb,r,startAngle,arcAngle)
153 static pascal
void BitsMethod(BitMap *bitPtr,Rect *source_rectangle,
154 Rect *dstRect,
short mode,RgnHandle maskRgn)
156 #pragma unused (bitPtr,source_rectangle,dstRect,mode,maskRgn)
159 static pascal
void LineMethod(Point newPt)
161 #pragma unused (newPt)
164 static pascal
void OvalMethod(GrafVerb verb,Rect *r)
166 #pragma unused (verb,r)
169 static pascal
void PolyMethod(GrafVerb verb,PolyHandle poly)
171 #pragma unused (verb,poly)
174 static pascal
void RectMethod(GrafVerb verb,Rect *r)
176 #pragma unused (verb,r)
179 static pascal
void RegionMethod(GrafVerb verb,RgnHandle rgn)
181 #pragma unused (verb,rgn)
184 static pascal
void RRectMethod(GrafVerb verb,Rect *r,
short ovalWidth,
187 #pragma unused (verb,r,ovalWidth,ovalHeight)
190 static pascal
void StandardPixmap(PixMapPtr source,Rect *source_rectangle,
191 MatrixRecordPtr matrix,
short mode,RgnHandle mask,PixMapPtr matte,
192 Rect *matte_rectangle,
short flags)
194 #pragma unused (source_rectangle,matrix,mode,mask,matte,matte_rectangle,flags)
202 GetCompressedPixMapInfo(source,&image_description,&data,&size,nil,nil);
205 static pascal
void TextMethod(
short byteCount,Ptr textBuf,Point numer,
208 #pragma unused (byteCount,textBuf,numer,denom)
211 #if !defined(DISABLE_QUICKTIME)
212 static short BottleneckTest(PicHandle picture,CodecType *codec,
int *depth,
227 status=Gestalt(gestaltQuickTime,&version);
230 ParamText(
"\pQuickTime not installed. Please install, then try again.",
238 SetStdCProcs(&bottlenecks);
239 bottlenecks.textProc=NewQDTextUPP(&TextMethod);
240 bottlenecks.lineProc=NewQDLineUPP(&LineMethod);
241 bottlenecks.rectProc=NewQDRectUPP(&RectMethod);
242 bottlenecks.rRectProc=NewQDRRectUPP(&RRectMethod);
243 bottlenecks.ovalProc=NewQDOvalUPP(&OvalMethod);
244 bottlenecks.arcProc=NewQDArcUPP(&ArcMethod);
245 bottlenecks.polyProc=NewQDPolyUPP(&PolyMethod);
246 bottlenecks.rgnProc=NewQDRgnUPP(&RegionMethod);
247 bottlenecks.bitsProc=NewQDBitsUPP(&BitsMethod);
248 bottlenecks.newProc1=(UniversalProcPtr) NewStdPixUPP(&StandardPixmap);
252 (*(qd.thePort)).grafProcs=(QDProcs *) &bottlenecks;
253 DrawPicture(picture,&((**picture).picFrame));
254 PaintRect(&rectangle);
255 (*(qd.thePort)).grafProcs=0L;
262 if (image_description != nil)
264 *codec=(**image_description).cType;
265 *depth=(**image_description).depth;
266 *colormap_id=(**image_description).clutID;
268 DisposeQDTextUPP(bottlenecks.textProc);
269 DisposeQDLineUPP(bottlenecks.lineProc);
270 DisposeQDRectUPP(bottlenecks.rectProc);
271 DisposeQDRRectUPP(bottlenecks.rRectProc);
272 DisposeQDOvalUPP(bottlenecks.ovalProc);
273 DisposeQDArcUPP(bottlenecks.arcProc);
274 DisposeQDPolyUPP(bottlenecks.polyProc);
275 DisposeQDRgnUPP(bottlenecks.rgnProc);
276 DisposeQDBitsUPP(bottlenecks.bitsProc);
277 DisposeStdPixUPP(bottlenecks.newProc1);
282 #if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
310 assert(entry != (
DIR *) NULL);
341 #if !defined(DISABLE_SIOUX)
378 assert(filename != (
char *) NULL);
379 c2pstrcpy(name,filename);
380 FSMakeFSSpec(0,0,name,fsspec);
410 static OSErr HGetVInfo(
short volume_index,StringPtr volume_name,
short *volume,
411 size_t *free_bytes,
size_t *total_bytes)
429 pb.volumeParam.ioVRefNum=0;
430 pb.volumeParam.ioNamePtr=volume_name;
431 pb.volumeParam.ioVolIndex=volume_index;
432 result=PBHGetVInfoSync(&pb);
435 *volume=pb.volumeParam.ioVRefNum;
436 blocksize=(size_t) pb.volumeParam.ioVAlBlkSiz;
437 allocation_blocks=(
unsigned short) pb.volumeParam.ioVNmAlBlks;
438 free_blocks=(
unsigned short) pb.volumeParam.ioVFrBlk;
439 *free_bytes=free_blocks*blocksize;
440 *total_bytes=allocation_blocks*blocksize;
459 assert(magick != (
char *) NULL);
463 c2pstr((
char *) volume_name);
464 if (volume_name[volume_name[0]] !=
':')
465 volume_name[++volume_name[0]]=
':';
466 status=HGetVInfo(-1,volume_name,&volume,&free_bytes,&number_bytes);
500 const char *description)
505 if (reason == (
char *) NULL)
507 if (description == (
char *) NULL)
513 #if defined(DISABLE_SIOUX)
514 if(exception.hook != (MACErrorHookPtr) NULL)
515 exception.hook(error,buffer);
528 #if defined(DISABLE_SIOUX)
558 static void MACFatalErrorHandler(
const ExceptionType severity,
559 const char *reason,
const char *description)
564 if (reason == (
char *) NULL)
566 if (description == (
char *) NULL)
572 if(exception.hook != (MACErrorHookPtr) NULL)
573 exception.hook(severity, buffer);
597 static OSErr MacGSExecuteCommand(
const char *command,ssize_t length)
603 reply = {typeNull, NULL};
606 event = {typeNull, NULL};
623 (void) AECreateDesc(typeApplSignature,&
id,
sizeof(
id),&event_descriptor);
624 (void) AECreateAppleEvent(
id,
'exec',&event_descriptor,-1,kAnyTransactionID,
626 (void) AEPutParamPtr(&event,keyDirectObject,typeChar,command,length);
627 (void) AESend(&event,&reply,kAEWaitReply+kAENeverInteract,kAENormalPriority,
628 kNoTimeOut,NULL,NULL);
632 (void) AEGetParamPtr(&reply,keyDirectObject,typeInteger,&descriptor_type,
633 &error,
sizeof(error),&actualSize);
634 (void) AEDisposeDesc(&event_descriptor);
635 (void) AEDisposeDesc(&event);
636 if (reply.descriptorType != NULL)
637 AEDisposeDesc(&reply);
638 return((OSErr) error);
656 static OSErr MacGSLaunchApplicationCore(ssize_t flags)
667 if (!SearchForFile(
'gsVR',
'APPL',&file_info,1))
669 launch_info.launchBlockID=extendedBlock;
670 launch_info.launchEPBLength=extendedBlockLen;
671 launch_info.launchFileFlags=0;
672 launch_info.launchControlFlags=launchContinue+launchNoFileFlags+flags;
673 launch_info.launchAppSpec=(&file_info);
674 launch_info.launchAppParameters=nil;
675 error=LaunchApplication(&launch_info);
694 static OSErr MacGSLaunchApplication(
void)
696 return(MacGSLaunchApplicationCore(launchDontSwitch));
714 static OSErr MacGSLaunchApplicationToFront(
void)
716 return(MacGSLaunchApplicationCore(0));
734 static void MacGSQuitApplication(
void)
740 reply = {typeNull, NULL};
743 event = {typeNull, NULL};
751 (void) AECreateDesc(typeApplSignature,&
id,
sizeof(
id),&event_descriptor);
752 (void) AECreateAppleEvent(typeAppleEvent,kAEQuitApplication,
753 &event_descriptor,-1,kAnyTransactionID,&event);
754 (void) AESend(&event,&reply,kAENoReply,kAENormalPriority,kNoTimeOut,NULL,
759 (void) AEDisposeDesc(&event_descriptor);
760 (void) AEDisposeDesc(&event);
761 if (reply.descriptorType != NULL)
762 AEDisposeDesc(&reply);
780 static OSErr MacGSSetWorkingFolder(
char *directory)
783 application_descriptor,
794 folder_type =
'wfdr';
805 AECreateDesc(typeNull,NULL,0,&application_descriptor);
806 AECreateDesc(typeChar,directory,strlen(directory),&path_descriptor);
807 (void) AECreateDesc(typeType,&folder_type,
sizeof(DescType),&type_descriptor);
808 CreateObjSpecifier(cProperty,&application_descriptor,formPropertyID,
809 &type_descriptor,0,&
object);
810 (void) AECreateDesc(typeApplSignature,&
id,
sizeof(
id),&event_descriptor);
811 (void) AECreateAppleEvent(kAECoreSuite,kAESetData,&event_descriptor,-1,
812 kAnyTransactionID,&event);
813 (void) AEPutParamDesc(&event,keyDirectObject,&
object);
814 (void) AEPutParamDesc(&event,keyAEData,&path_descriptor);
815 error=AESend(&event,&reply,kAENoReply+kAENeverInteract,kAENormalPriority,
816 kNoTimeOut,NULL,NULL);
817 (void) AEDisposeDesc(&event);
818 (void) AEDisposeDesc(&event_descriptor);
819 (void) AEDisposeDesc(&
object);
820 (void) AEDisposeDesc(&type_descriptor);
821 (void) AEDisposeDesc(&path_descriptor);
822 (void) AEDisposeDesc(&application_descriptor);
918 if (MacGSLaunchApplicationToFront())
920 return(MacGSExecuteCommand(command,strlen(command)));
953 const char *reason,
const char *description)
958 if (reason == (
char *) NULL)
960 if (description == (
char *) NULL)
966 #if defined(DISABLE_SIOUX)
967 if(exception.hook != (MACErrorHookPtr) NULL)
968 exception.hook(warning, buffer);
975 #if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
1013 search_info.hFileInfo.ioNamePtr=0;
1014 if ((path != (
char *) NULL) || (*path !=
'\0'))
1015 if ((path[0] !=
'.') || (path[1] !=
'\0'))
1017 c2pstrcpy(pathname,path);
1018 search_info.hFileInfo.ioNamePtr=pathname;
1020 search_info.hFileInfo.ioCompletion=0;
1021 search_info.hFileInfo.ioVRefNum=0;
1022 search_info.hFileInfo.ioFDirIndex=0;
1023 search_info.hFileInfo.ioDirID=0;
1024 error=PBGetCatInfoSync(&search_info);
1028 return((
DIR *) NULL);
1031 if (entry == (
DIR *) NULL)
1032 return((
DIR *) NULL);
1033 entry->
d_VRefNum=search_info.hFileInfo.ioVRefNum;
1034 entry->
d_DirID=search_info.hFileInfo.ioDirID;
1066 #if defined(DISABLE_SIOUX)
1067 if (event_hook != (MACEventHookPtr) NULL)
1071 *mark = (
char *) NULL;
1076 while (WaitNextEvent(everyEvent,&event,0L,nil))
1077 SIOUXHandleOneEvent(&event);
1086 #if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
1122 static unsigned char
1125 if (entry == (
DIR *) NULL)
1126 return((
struct dirent *) NULL);
1127 search_info.hFileInfo.ioCompletion=0;
1128 search_info.hFileInfo.ioNamePtr=pathname;
1129 search_info.hFileInfo.ioVRefNum=0;
1130 search_info.hFileInfo.ioFDirIndex=entry->
d_index;
1131 search_info.hFileInfo.ioDirID=entry->
d_DirID;
1132 error=PBGetCatInfoSync(&search_info);
1136 return((
struct dirent *) NULL);
1139 p2cstrcpy(dir_entry.d_name,search_info.hFileInfo.ioNamePtr);
1140 dir_entry.d_namlen=strlen(dir_entry.d_name);
1180 static inline size_t MagickMax(
const size_t x,
const size_t y)
1190 #define PICTHeaderSize 512
1242 PICTHeaderSize,PICTHeaderSize));
1243 if (picture_handle == nil)
1245 HLock((Handle) picture_handle);
1246 (void)
ReadBlob(image,PICTHeaderSize,*(
unsigned char **) picture_handle);
1251 DisposeHandle((Handle) picture_handle);
1254 GetGWorld(&port,&device);
1255 theErr=NewGWorld(&graphic_world,0,&(**picture_handle).picFrame,nil,nil,
1256 useTempMem | keepLocal);
1257 if ((theErr != noErr) && (graphic_world == nil))
1259 DisposeHandle((Handle) picture_handle);
1262 HUnlock((Handle) picture_handle);
1263 SetGWorld(graphic_world,nil);
1264 theErr=GetPictInfo(picture_handle,&picture_info,0,1,systemMethod,0);
1265 if (theErr != noErr)
1267 DisposeGWorld(graphic_world);
1268 DisposeHandle((Handle) picture_handle);
1271 #if defined(DISABLE_QUICKTIME)
1274 depth=picture_info.depth;
1276 BottleneckTest(picture_handle,&codec,&depth,&colormap_id);
1289 picture_info.theColorTable=GetCTable(colormap_id);
1295 depth=picture_info.depth;
1297 (void) GetPictInfo(picture_handle,&picture_info,returnColorTable,
1298 (
short) (1 << picture_info.depth),systemMethod,0);
1305 image->
columns=picture_info.sourceRect.right-picture_info.sourceRect.left;
1306 image->
rows=picture_info.sourceRect.bottom-picture_info.sourceRect.top;
1307 if ((depth <= 8) && ((*(picture_info.theColorTable))->ctSize != 0))
1315 number_colors=(*(picture_info.theColorTable))->ctSize;
1318 if (picture_info.theColorTable != nil)
1319 DisposeHandle((Handle) picture_info.theColorTable);
1320 DisposeGWorld(graphic_world);
1321 DisposeHandle((Handle) picture_handle);
1324 for (x=0; x < image->
colors; x++)
1327 (*(picture_info.theColorTable))->ctTable[x].rgb.red;
1329 (*(picture_info.theColorTable))->ctTable[x].rgb.green;
1331 (*(picture_info.theColorTable))->ctTable[x].rgb.blue;
1334 SetRect(&rectangle,0,0,image->
columns,image->
rows);
1335 (void) UpdateGWorld(&graphic_world,depth,&rectangle,
1336 picture_info.theColorTable,nil,0);
1337 LockPixels(GetGWorldPixMap(graphic_world));
1338 EraseRect(&rectangle);
1339 DrawPicture(picture_handle,&rectangle);
1340 if ((depth <= 8) && (colormap_id == -1))
1342 DisposeHandle((Handle) picture_info.theColorTable);
1343 picture_info.theColorTable=nil;
1345 DisposeHandle((Handle) picture_handle);
1349 for (y=0; y < image->
rows; y++)
1360 for (x=0; x < image->
columns; x++)
1362 GetCPixel(x,y,&Pixel);
1363 SetPixelRed(image,ScaleCharToQuantum(Pixel.red & 0xff),q);
1364 SetPixelGreen(image,ScaleCharToQuantum(Pixel.green & 0xff),q);
1365 SetPixelBlue(image,ScaleCharToQuantum(Pixel.blue & 0xff),q);
1376 UnlockPixels(GetGWorldPixMap(graphic_world));
1377 SetGWorld(port,device);
1378 if (picture_info.theColorTable != nil)
1379 DisposeHandle((Handle) picture_info.theColorTable);
1380 DisposeGWorld(graphic_world);
1400 static Boolean SearchForFile(OSType creator_type,OSType file_type,FSSpec *file,
1426 buffer_size = 16384;
1428 serial_number.lowLongOfPSN=kCurrentProcess;
1429 serial_number.highLongOfPSN=0;
1430 application_info.processInfoLength=
sizeof(ProcessInfoRec);
1431 application_info.processName=NULL;
1432 application_info.processAppSpec=(&application);
1433 GetProcessInformation(&serial_number,&application_info);
1434 buffer=NewPtr(buffer_size);
1435 if (buffer == (
char *) NULL)
1437 parameter_info.csParam.ioCompletion=NULL;
1438 parameter_info.csParam.ioNamePtr=NULL;
1439 parameter_info.csParam.ioVRefNum=application.vRefNum;
1440 parameter_info.csParam.ioMatchPtr=file;
1441 parameter_info.csParam.ioReqMatchCount=count;
1442 parameter_info.csParam.ioSearchBits=fsSBFlFndrInfo;
1443 parameter_info.csParam.ioSearchInfo1=&search1_info;
1444 parameter_info.csParam.ioSearchInfo2=&search2_info;
1445 parameter_info.csParam.ioSearchTime=0;
1446 parameter_info.csParam.ioCatPosition.initialize=0;
1447 parameter_info.csParam.ioOptBuffer=buffer;
1448 parameter_info.csParam.ioOptBufSize=buffer_size;
1449 search1_info.hFileInfo.ioNamePtr=NULL;
1450 search1_info.hFileInfo.ioFlFndrInfo.fdType=file_type;
1451 search1_info.hFileInfo.ioFlFndrInfo.fdCreator=creator_type;
1452 search1_info.hFileInfo.ioFlAttrib=0;
1453 search1_info.hFileInfo.ioFlParID=0;
1454 search2_info=search1_info;
1455 search2_info.hFileInfo.ioFlAttrib=0x10;
1456 search2_info.hFileInfo.ioFlFndrInfo.fdCreator=creator_type;
1457 search2_info.hFileInfo.ioFlFndrInfo.fdType=(-1);
1458 search2_info.hFileInfo.ioFlFndrInfo.fdFlags=0;
1459 search2_info.hFileInfo.ioFlFndrInfo.fdLocation.h=0;
1460 search2_info.hFileInfo.ioFlFndrInfo.fdLocation.v=0;
1461 search2_info.hFileInfo.ioFlFndrInfo.fdFldr=0;
1462 search2_info.hFileInfo.ioFlParID=0;
1463 error=PBCatSearchSync((CSParamPtr) ¶meter_info);
1465 if (parameter_info.csParam.ioReqMatchCount ==
1466 parameter_info.csParam.ioActMatchCount)
1468 if (parameter_info.csParam.ioActMatchCount == 0)
1470 return(error == eofErr);
1473 #if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
1504 assert(entry != (
DIR *) NULL);
1537 static inline size_t MagickMin(
const size_t x,
const size_t y)
1556 assert(filename != (
char *) NULL);
1559 assert(magick != (
const char *) NULL);
1565 c2pstrcpy(name,filename);
1566 FSMakeFSSpec(0,0,name,&file_specification);
1567 FSpCreate(&file_specification,application,filetype,smSystemScript);
1570 #if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
static MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
static void SetPixelRed(const Image *restrict image, const Quantum red, Quantum *restrict pixel)
MagickExport void MagickCoreTerminus(void)
MagickExport MagickBooleanType CloseBlob(Image *image)
static void SetPixelIndex(const Image *restrict image, const Quantum index, Quantum *restrict pixel)
MagickExport const char LoadImageTag[]
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *restrict format,...)
MagickExport Image * ReadPICTImage(const ImageInfo *, ExceptionInfo *)
MagickExport int Exit(int)
MagickExport int MACSystemCommand(const char *)
MagickExport void closedir(DIR *)
MagickExport int LocaleCompare(const char *p, const char *q)
MagickExport void MACWarningHandler(const ExceptionType, const char *, const char *)
MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
#define ThrowReaderException(severity, tag)
static size_t GetPixelChannels(const Image *restrict image)
MagickExport Image * AcquireImage(const ImageInfo *image_info, ExceptionInfo *exception)
static void SetPixelGreen(const Image *restrict image, const Quantum green, Quantum *restrict pixel)
static void SetPixelBlue(const Image *restrict image, const Quantum blue, Quantum *restrict pixel)
MagickExport size_t CopyMagickString(char *destination, const char *source, const size_t length)
MagickExport const char * GetClientName(void)
MagickExport void ProcessPendingEvents(const char *)
MagickExport MagickBooleanType AcquireImageColormap(Image *image, const size_t colors, ExceptionInfo *exception)
MagickExport ssize_t FormatLocaleString(char *restrict string, const size_t length, const char *restrict format,...)
#define GetMagickModule()
MagickExport void SetApplicationType(const char *, const char *, OSType)
MagickExport MagickSizeType GetBlobSize(const Image *image)
MagickExport long telldir(DIR *)
MagickExport struct dirent * readdir(DIR *)
MagickExport MagickBooleanType SyncAuthenticPixels(Image *image, ExceptionInfo *exception)
MagickExport void * AcquireMagickMemory(const size_t size)
MagickExport Quantum * QueueAuthenticPixels(Image *image, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
MagickExport void MACErrorHandler(const ExceptionType, const char *, const char *)
MagickExport DIR * opendir(const char *)
MagickExport void * RelinquishMagickMemory(void *memory)
MagickExport MagickBooleanType MACIsMagickConflict(const char *)
MagickExport void seekdir(DIR *, long)
MagickExport ssize_t ReadBlob(Image *image, const size_t length, void *data)
MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info, Image *image, const BlobMode mode, ExceptionInfo *exception)