1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
|
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M AAA CCCC %
% MM MM A A C %
% M M M AAAAA C %
% M M A A C %
% M M A A CCCC %
% %
% %
% Macintosh Utility Methods for MagickCore %
% %
% Software Design %
% John Cristy %
% September 1996 %
% %
% %
% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
% http://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The directory methods are strongly based on similar methods written
% by Steve Summit, scs@eskimo.com. The Ghostscript launch code is strongly
% based on Dave Schooley's Mac Gnuplot and contributed by
% schindall@wave14i.nrl.navy.mil. Mac-centric improvements contributed by
% leonardr@digapp.com.
%
%
*/
#if defined(macintosh)
/*
Include declarations.
*/
#define _X_H
#define _WIDGET_H
#include <AppleEvents.h>
#include <AERegistry.h>
#include <AEObjects.h>
#include <AEPackObject.h>
#include <Processes.h>
#include <QuickDraw.h>
#include <QDOffscreen.h>
#include <Palettes.h>
#include <ImageCompression.h>
#include <PictUtils.h>
#include <Files.h>
#include <Gestalt.h>
#include <TextUtils.h>
#define ColorInfo KolorInfo
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/client.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/quantum.h"
#include "magick/string_.h"
#include "magick/utility.h"
#include "magick/mac.h"
/*
Global declaractions.
*/
ImageDescriptionHandle
image_description = nil;
/*
Forward declaractions.
*/
static Boolean
SearchForFile(OSType,OSType,FSSpec *,short);
static pascal void
ArcMethod(GrafVerb,Rect *,short,short),
BitsMethod(BitMap *,Rect *,Rect *,short,RgnHandle),
FilenameToFSSpec(const char *filename,FSSpec *fsspec),
LineMethod(Point),
OvalMethod(GrafVerb,Rect *),
PolyMethod(GrafVerb,PolyHandle),
RRectMethod(GrafVerb,Rect *,short,short),
RectMethod(GrafVerb,Rect *),
RegionMethod(GrafVerb,RgnHandle),
StandardPixmap(PixMapPtr,Rect *,MatrixRecordPtr,short,RgnHandle,PixMapPtr,
Rect *,short),
TextMethod(short,Ptr,Point,Point);
/*
Static declarations
*/
#if defined(DISABLE_SIOUX)
static MACEventHookPtr
event_hook = nil;
static MACErrorHookPtr
exception.hook = nil;
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% B o t t l e n e c k T e s t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% BottleneckTest() intercepts any compressed images.
%
% The format of the BottleneckTest method is:
%
% int BottleneckTest(const char *magick)
%
% A description of each parameter follows:
%
% o picture: Specifies a pointer to a PicHandle structure.
%
% o codec: the code type is returned in this CodecType pointer structure.
%
% o depth: the image depth is returned as an integer pointer.
%
% o colormap_id: the colormap ID is returned in this short pointer.
%
%
*/
static pascal void ArcMethod(GrafVerb verb,Rect *r,short startAngle,
short arcAngle)
{
#pragma unused (verb,r,startAngle,arcAngle)
}
static pascal void BitsMethod(BitMap *bitPtr,Rect *source_rectangle,
Rect *dstRect,short mode,RgnHandle maskRgn)
{
#pragma unused (bitPtr,source_rectangle,dstRect,mode,maskRgn)
}
static pascal void LineMethod(Point newPt)
{
#pragma unused (newPt)
}
static pascal void OvalMethod(GrafVerb verb,Rect *r)
{
#pragma unused (verb,r)
}
static pascal void PolyMethod(GrafVerb verb,PolyHandle poly)
{
#pragma unused (verb,poly)
}
static pascal void RectMethod(GrafVerb verb,Rect *r)
{
#pragma unused (verb,r)
}
static pascal void RegionMethod(GrafVerb verb,RgnHandle rgn)
{
#pragma unused (verb,rgn)
}
static pascal void RRectMethod(GrafVerb verb,Rect *r,short ovalWidth,
short ovalHeight)
{
#pragma unused (verb,r,ovalWidth,ovalHeight)
}
static pascal void StandardPixmap(PixMapPtr source,Rect *source_rectangle,
MatrixRecordPtr matrix,short mode,RgnHandle mask,PixMapPtr matte,
Rect *matte_rectangle,short flags)
{
#pragma unused (source_rectangle,matrix,mode,mask,matte,matte_rectangle,flags)
long
size;
Ptr
data;
GetCompressedPixMapInfo(source,&image_description,&data,&size,nil,nil);
}
static pascal void TextMethod(short byteCount,Ptr textBuf,Point numer,
Point denom)
{
#pragma unused (byteCount,textBuf,numer,denom)
}
#if !defined(DISABLE_QUICKTIME)
static short BottleneckTest(PicHandle picture,CodecType *codec,int *depth,
short *colormap_id)
{
CQDProcs
bottlenecks;
int
status;
long
version;
Rect
rectangle;
status=Gestalt(gestaltQuickTime,&version);
if (status != noErr)
{
ParamText("\pQuickTime not installed. Please install, then try again.",
"\p","\p","\p");
Alert(128,nil);
return(-1);
}
/*
Define our own bottlenecks to do nothing.
*/
SetStdCProcs(&bottlenecks);
bottlenecks.textProc=NewQDTextUPP(&TextMethod);
bottlenecks.lineProc=NewQDLineUPP(&LineMethod);
bottlenecks.rectProc=NewQDRectUPP(&RectMethod);
bottlenecks.rRectProc=NewQDRRectUPP(&RRectMethod);
bottlenecks.ovalProc=NewQDOvalUPP(&OvalMethod);
bottlenecks.arcProc=NewQDArcUPP(&ArcMethod);
bottlenecks.polyProc=NewQDPolyUPP(&PolyMethod);
bottlenecks.rgnProc=NewQDRgnUPP(&RegionMethod);
bottlenecks.bitsProc=NewQDBitsUPP(&BitsMethod);
bottlenecks.newProc1=(UniversalProcPtr) NewStdPixUPP(&StandardPixmap);
/*
Install our custom bottlenecks to intercept any compressed images.
*/
(*(qd.thePort)).grafProcs=(QDProcs *) &bottlenecks;
DrawPicture(picture,&((**picture).picFrame));
PaintRect(&rectangle);
(*(qd.thePort)).grafProcs=0L;
/*
Initialize our return values.
*/
*codec='unkn';
*depth=0;
*colormap_id=(-1);
if (image_description != nil)
{
*codec=(**image_description).cType;
*depth=(**image_description).depth;
*colormap_id=(**image_description).clutID;
}
DisposeQDTextUPP(bottlenecks.textProc);
DisposeQDLineUPP(bottlenecks.lineProc);
DisposeQDRectUPP(bottlenecks.rectProc);
DisposeQDRRectUPP(bottlenecks.rRectProc);
DisposeQDOvalUPP(bottlenecks.ovalProc);
DisposeQDArcUPP(bottlenecks.arcProc);
DisposeQDPolyUPP(bottlenecks.polyProc);
DisposeQDRgnUPP(bottlenecks.rgnProc);
DisposeQDBitsUPP(bottlenecks.bitsProc);
DisposeStdPixUPP(bottlenecks.newProc1);
return(0);
}
#endif
#if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% c l o s e d i r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% closedir() closes the named directory stream and frees the DIR structure.
%
% The format of the closedir method is:
%
% closedir(entry)
%
% A description of each parameter follows:
%
% o entry: Specifies a pointer to a DIR structure.
%
%
*/
MagickExport void closedir(DIR *entry)
{
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
assert(entry != (DIR *) NULL);
RelinquishMagickMemory(entry);
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% E x i t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Exit() exits the process.
%
% The format of the exit method is:
%
% Exit(status)
%
% A description of each parameter follows:
%
% o status: an integer value representing the status of the terminating
% process.
%
%
*/
MagickExport int Exit(int status)
{
#if !defined(DISABLE_SIOUX)
(void) fprintf(stdout,"Select File->Quit to exit.\n");
#endif
exit(status);
return(0);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% F i l e n a m e T o F S S p e c %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FilenameToFSSpec() sets the file type of an image.
%
% The format of the FilenameToFSSpec method is:
%
% FilenameToFSSpec(filename,fsspec)
%
% A description of each parameter follows:
%
% o filename: Specifies the name of the file.
%
% o fsspec: A pointer to type FSSpec.
%
%
*/
MagickExport void pascal FilenameToFSSpec(const char *filename,FSSpec *fsspec)
{
Str255
name;
assert(filename != (char *) NULL);
c2pstrcpy(name,filename);
FSMakeFSSpec(0,0,name,fsspec);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s M a g i c k C o n f l i c t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MACIsMagickConflict() returns true if the image format conflicts with a
% logical drive (.e.g. X:).
%
% Contributed by Mark Gavin of Digital Applications, Inc.
%
% The format of the MACIsMagickConflict method is:
%
% status=MACIsMagickConflict(magick)
%
% A description of each parameter follows:
%
% o magick: Specifies the image format.
%
%
*/
static OSErr HGetVInfo(short volume_index,StringPtr volume_name,short *volume,
unsigned long *free_bytes,unsigned long *total_bytes)
{
HParamBlockRec
pb;
OSErr
result;
unsigned long
blocksize;
unsigned short
allocation_blocks,
free_blocks;
/*
Use the File Manager to get the real vRefNum.
*/
pb.volumeParam.ioVRefNum=0;
pb.volumeParam.ioNamePtr=volume_name;
pb.volumeParam.ioVolIndex=volume_index;
result=PBHGetVInfoSync(&pb);
if (result != noErr)
return(result);
*volume=pb.volumeParam.ioVRefNum;
blocksize=(unsigned long) pb.volumeParam.ioVAlBlkSiz;
allocation_blocks=(unsigned short) pb.volumeParam.ioVNmAlBlks;
free_blocks=(unsigned short) pb.volumeParam.ioVFrBlk;
*free_bytes=free_blocks*blocksize;
*total_bytes=allocation_blocks*blocksize;
return(result);
}
MagickExport MagickBooleanType MACIsMagickConflict(const char *magick)
{
unsigned long
free_bytes,
number_bytes;
OSErr
status;
short
volume;
Str255
volume_name;
assert(magick != (char *) NULL);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",magick);
(void) CopyMagickString((char *) volume_name,magick,MaxTextExtent);
c2pstr((char *) volume_name);
if (volume_name[volume_name[0]] != ':')
volume_name[++volume_name[0]]=':';
status=HGetVInfo(-1,volume_name,&volume,&free_bytes,&number_bytes);
return(status != 0 ? MagickFalse : MagickTrue);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ M A C E r r o r H a n d l e r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MACErrorHandler() displays an error reason and then terminates the program.
%
% The format of the MACErrorHandler method is:
%
% void MACErrorHandler(const ExceptionType error,const char *reason,
% const char *description)
%
% A description of each parameter follows:
%
% o exception: Specifies the numeric error category.
%
% o reason: Specifies the reason to display before terminating the
% program.
%
% o description: Specifies any description to the reason.
%
%
*/
MagickExport void MACErrorHandler(const ExceptionType error,const char *reason,
const char *description)
{
char
buffer[3*MaxTextExtent];
if (reason == (char *) NULL)
return;
if (description == (char *) NULL)
(void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
reason);
else
(void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
GetClientName(),reason,description);
#if defined(DISABLE_SIOUX)
if(exception.hook != (MACErrorHookPtr) NULL)
exception.hook(error,buffer);
else
{
MagickCoreTerminus();
exit(error);
}
#else
puts(buffer);
MagickCoreTerminus();
exit(error);
#endif
}
#if defined(DISABLE_SIOUX)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ M A C F a t a l E r r o r H a n d l e r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MACFatalErrorHandler() displays an error reason and then terminates the
% program.
%
% The format of the MACFatalErrorHandler method is:
%
% void MACFatalErrorHandler(const ExceptionType severity,
% const char *reason,const char *description)
%
% A description of each parameter follows:
%
% o severity: Specifies the numeric error category.
%
% o reason: Specifies the reason to display before terminating the
% program.
%
% o description: Specifies any description to the reason.
%
*/
static void MACFatalErrorHandler(const ExceptionType severity,
const char *reason,const char *description)
{
char
buffer[3*MaxTextExtent];
if (reason == (char *) NULL)
return;
if (description == (char *) NULL)
(void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
reason);
else
(void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
GetClientName(),reason,description);
if(exception.hook != (MACErrorHookPtr) NULL)
exception.hook(severity, buffer);
else
{
MagickCoreTerminus();
exit(severity);
}
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a c G S E x e c u t e C o m m a n d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MacGSExecuteCommand() executes the Ghostscript command.
%
%
*/
static OSErr MacGSExecuteCommand(const char *command,long length)
{
AEAddressDesc
event_descriptor;
AEDesc
reply = {typeNull, NULL};
AppleEvent
event = {typeNull, NULL};
DescType
descriptor_type;
int
error;
OSType
id = 'gsVR';
Size
actualSize;
/*
Send the Apple Event.
*/
(void) AECreateDesc(typeApplSignature,&id,sizeof(id),&event_descriptor);
(void) AECreateAppleEvent(id,'exec',&event_descriptor,-1,kAnyTransactionID,
&event);
(void) AEPutParamPtr(&event,keyDirectObject,typeChar,command,length);
(void) AESend(&event,&reply,kAEWaitReply+kAENeverInteract,kAENormalPriority,
kNoTimeOut,NULL,NULL);
/*
Handle the reply and exit.
*/
(void) AEGetParamPtr(&reply,keyDirectObject,typeInteger,&descriptor_type,
&error,sizeof(error),&actualSize);
(void) AEDisposeDesc(&event_descriptor);
(void) AEDisposeDesc(&event);
if (reply.descriptorType != NULL)
AEDisposeDesc(&reply);
return((OSErr) error);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a c G S L a u n c h A p p l i c a t i o n C o r e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MacGSLaunchApplicationCore() launches the Ghostscript command.
%
%
*/
static OSErr MacGSLaunchApplicationCore(long flags)
{
FSSpec
file_info;
LaunchParamBlockRec
launch_info;
OSErr
error;
if (!SearchForFile('gsVR','APPL',&file_info,1))
return(-43);
launch_info.launchBlockID=extendedBlock;
launch_info.launchEPBLength=extendedBlockLen;
launch_info.launchFileFlags=0;
launch_info.launchControlFlags=launchContinue+launchNoFileFlags+flags;
launch_info.launchAppSpec=(&file_info);
launch_info.launchAppParameters=nil;
error=LaunchApplication(&launch_info);
return(error);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a c G S L a u n c h A p p l i c a t i o n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MacGSLaunchApplication() launches the Ghostscript command.
%
%
*/
static OSErr MacGSLaunchApplication(void)
{
return(MacGSLaunchApplicationCore(launchDontSwitch));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a c G S L a u n c h A p p l i c a t i o n T o F r o n t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MacGSLaunchApplicationToFront() moves the Ghostscript window to the front.
%
%
*/
static OSErr MacGSLaunchApplicationToFront(void)
{
return(MacGSLaunchApplicationCore(0));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a c G S Q u i t A p p l i c a t i o n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MacGSQuitApplication() quits the Ghostscript application.
%
%
*/
static void MacGSQuitApplication(void)
{
AEAddressDesc
event_descriptor;
AEDesc
reply = {typeNull, NULL};
AppleEvent
event = {typeNull, NULL};
OSType
id = 'GPLT';
/*
Send the Apple Event.
*/
(void) AECreateDesc(typeApplSignature,&id,sizeof(id),&event_descriptor);
(void) AECreateAppleEvent(typeAppleEvent,kAEQuitApplication,
&event_descriptor,-1,kAnyTransactionID,&event);
(void) AESend(&event,&reply,kAENoReply,kAENormalPriority,kNoTimeOut,NULL,
NULL);
/*
Clean up and exit.
*/
(void) AEDisposeDesc(&event_descriptor);
(void) AEDisposeDesc(&event);
if (reply.descriptorType != NULL)
AEDisposeDesc(&reply);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a c G S S e t W o r k i n g F o l d e r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MacGSSetWorkingFolder() set the Ghostscript working folder.
%
%
*/
static OSErr MacGSSetWorkingFolder(char *directory)
{
AEDesc
application_descriptor,
event_descriptor,
object,
path_descriptor,
type_descriptor,
reply;
AppleEvent
event;
DescType
folder_type = 'wfdr';
OSErr
error;
OSType
id = 'GPLT';
/*
Send the Apple Event.
*/
AECreateDesc(typeNull,NULL,0,&application_descriptor);
AECreateDesc(typeChar,directory,strlen(directory),&path_descriptor);
(void) AECreateDesc(typeType,&folder_type,sizeof(DescType),&type_descriptor);
CreateObjSpecifier(cProperty,&application_descriptor,formPropertyID,
&type_descriptor,0,&object);
(void) AECreateDesc(typeApplSignature,&id,sizeof(id),&event_descriptor);
(void) AECreateAppleEvent(kAECoreSuite,kAESetData,&event_descriptor,-1,
kAnyTransactionID,&event);
(void) AEPutParamDesc(&event,keyDirectObject,&object);
(void) AEPutParamDesc(&event,keyAEData,&path_descriptor);
error=AESend(&event,&reply,kAENoReply+kAENeverInteract,kAENormalPriority,
kNoTimeOut,NULL,NULL);
(void) AEDisposeDesc(&event);
(void) AEDisposeDesc(&event_descriptor);
(void) AEDisposeDesc(&object);
(void) AEDisposeDesc(&type_descriptor);
(void) AEDisposeDesc(&path_descriptor);
(void) AEDisposeDesc(&application_descriptor);
return(error);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M A C S e t E r r o r H o o k %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MACSetErrorHook sets a callback function which is called if any error
% occurs within ImageMagick.
%
% The format of the MACSetErrorHook method is:
%
% int MACSetErrorHook(MACErrorHookPtr hook)
%
% A description of each parameter follows:
%
% o hook: This function pointer is the callback function.
%
%
*/
MagickExport void MACSetErrorHook(MACErrorHookPtr hook)
{
/*
We forget any previously set exception.hook.
*/
exception.hook=hook;
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M A C S e t E v e n t H o o k %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MACSetEventHook sets a callback function which is called every time
% ImageMagick likes to release the processor.
%
% The format of the MACSetEventHook method is:
%
% int MACSetEventHook(MACEventHookPtr hook)
%
% A description of each parameter follows:
%
% o hook: This function pointer is the callback function.
%
%
*/
MagickExport void MACSetEventHook(MACEventHookPtr hook)
{
/*
We forget any previously set event hook.
*/
event_hook=hook;
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M A C S y s t e m C o m m a n d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method MACSystemCommand executes the specified command and waits until it
% terminates. The returned value is the exit status of the command.
%
% The format of the MACSystemCommand method is:
%
% int MACSystemCommand(MagickFalse,const char * command)
%
% A description of each parameter follows:
%
% o command: This string is the command to execute.
%
*/
MagickExport int MACSystemCommand(const char * command)
{
/*
We only know how to launch Ghostscript.
*/
if (MacGSLaunchApplicationToFront())
return(-1);
return(MacGSExecuteCommand(command,strlen(command)));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M A C W a r n i n g H a n d l e r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MACWarningHandler() displays a warning reason.
%
% The format of the MACWarningHandler method is:
%
+ void MACWarningHandler(const ExceptionType warning,const char *reason,
% const char *description)
%
% A description of each parameter follows:
%
% o warning: Specifies the numeric warning category.
%
% o reason: Specifies the reason to display before terminating the
% program.
%
% o description: Specifies any description to the reason.
%
%
*/
MagickExport void MACWarningHandler(const ExceptionType warning,
const char *reason,const char *description)
{
char
buffer[1664];
if (reason == (char *) NULL)
return;
if (description == (char *) NULL)
(void) FormatMagickString(buffer,MaxTextExtent,"%s: %s.\n",GetClientName(),
reason);
else
(void) FormatMagickString(buffer,MaxTextExtent,"%s: %s (%s).\n",
GetClientName(),reason,description);
#if defined(DISABLE_SIOUX)
if(exception.hook != (MACErrorHookPtr) NULL)
exception.hook(warning, buffer);
#else
(void)warning;
puts(buffer);
#endif
}
#if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% o p e n d i r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% opendir() opens the directory named by filename and associates a directory
% stream with it.
%
% The format of the opendir method is:
%
% MagickExport DIR *opendir(char *path)
%
% A description of each parameter follows:
%
% o entry: Specifies a pointer to a DIR structure.
%
%
*/
MagickExport DIR *opendir(const char *path)
{
Str255 pathname;
CInfoPBRec
search_info;
DIR
*entry;
int
error;
search_info.hFileInfo.ioNamePtr=0;
if ((path != (char *) NULL) || (*path != '\0'))
if ((path[0] != '.') || (path[1] != '\0'))
{
c2pstrcpy(pathname,path);
search_info.hFileInfo.ioNamePtr=pathname;
}
search_info.hFileInfo.ioCompletion=0;
search_info.hFileInfo.ioVRefNum=0;
search_info.hFileInfo.ioFDirIndex=0;
search_info.hFileInfo.ioDirID=0;
error=PBGetCatInfoSync(&search_info);
if (error != noErr)
{
errno=error;
return((DIR *) NULL);
}
entry=(DIR *) AcquireAlignedMemory(1,sizeof(DIR));
if (entry == (DIR *) NULL)
return((DIR *) NULL);
entry->d_VRefNum=search_info.hFileInfo.ioVRefNum;
entry->d_DirID=search_info.hFileInfo.ioDirID;
entry->d_index=1;
return(entry);
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% P r o c e s s P e n d i n g E v e n t s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ProcessPendingEvents() processes any pending events. This prevents
% ImageMagick from monopolizing the processor.
%
% The format of the ProcessPendingEvents method is:
%
% ProcessPendingEvents(text)
%
% A description of each parameter follows:
%
% o text: A character string representing the current process.
%
%
*/
MagickExport void ProcessPendingEvents(const char *text)
{
#if defined(DISABLE_SIOUX)
if (event_hook != (MACEventHookPtr) NULL)
event_hook(text);
#else
static const char
*mark = (char *) NULL;
EventRecord
event;
while (WaitNextEvent(everyEvent,&event,0L,nil))
SIOUXHandleOneEvent(&event);
if (isatty(STDIN_FILENO) && (text != mark))
{
(void) puts(text);
mark=text;
}
#endif
}
#if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% r e a d d i r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% readdir() returns a pointer to a structure representing the directory entry
% at the current position in the directory stream to which entry refers.
%
% The format of the readdir
%
% struct dirent *readdir(DIR *entry)
%
% A description of each parameter follows:
%
% o entry: Specifies a pointer to a DIR structure.
%
%
*/
MagickExport struct dirent *readdir(DIR *entry)
{
CInfoPBRec
search_info;
int
error;
static struct dirent
dir_entry;
static unsigned char
pathname[MaxTextExtent];
if (entry == (DIR *) NULL)
return((struct dirent *) NULL);
search_info.hFileInfo.ioCompletion=0;
search_info.hFileInfo.ioNamePtr=pathname;
search_info.hFileInfo.ioVRefNum=0;
search_info.hFileInfo.ioFDirIndex=entry->d_index;
search_info.hFileInfo.ioDirID=entry->d_DirID;
error=PBGetCatInfoSync(&search_info);
if (error != noErr)
{
errno=error;
return((struct dirent *) NULL);
}
entry->d_index++;
p2cstrcpy(dir_entry.d_name,search_info.hFileInfo.ioNamePtr);
dir_entry.d_namlen=strlen(dir_entry.d_name);
return(&dir_entry);
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P I C T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPICTImage() reads an Apple Macintosh QuickDraw/PICT image file using
% MacOS QuickDraw methods and returns it. It allocates the memory necessary
% for the new Image structure and returns a pointer to the new image.
%
% This method was written and contributed by spd@daphne.cps.unizar.es
% (feel free to copy and use it as you want. No warranty).
%
% The format of the ReadPICTImage method is:
%
% Image *ReadPICTImage(const ImageInfo *image_info,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image: Method ReadPICTImage returns a pointer to the image after
% reading. A null image is returned if there is a memory shortage or
% if the image cannot be read.
%
% o image_info: the image info..
%
% o exception: return any errors or warnings in this structure.
%
*/
static inline size_t MagickMax(const size_t x,const size_t y)
{
if (x > y)
return(x);
return(y);
}
MagickExport Image *ReadPICTImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
#define PICTHeaderSize 512
CodecType
codec;
GDHandle
device;
GWorldPtr
graphic_world,
port;
Image
*image;
int
depth,
status;
long
y;
MagickBooleanType
proceed,
status;
PicHandle
picture_handle;
PictInfo
picture_info;
QDErr
theErr = noErr;
Rect
rectangle;
RGBColor
Pixel;
short
colormap_id;
/*
Open image file.
*/
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
return(NULL);
picture_handle=(PicHandle) NewHandle(MagickMax(GetBlobSize(image)-
PICTHeaderSize,PICTHeaderSize));
if (picture_handle == nil)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
HLock((Handle) picture_handle);
(void) ReadBlob(image,PICTHeaderSize,*(unsigned char **) picture_handle);
status=ReadBlob(image,GetBlobSize(image)-PICTHeaderSize,*(unsigned char **)
picture_handle);
if (status == MagickFalse)
{
DisposeHandle((Handle) picture_handle);
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
}
GetGWorld(&port,&device);
theErr=NewGWorld(&graphic_world,0,&(**picture_handle).picFrame,nil,nil,
useTempMem | keepLocal);
if ((theErr != noErr) && (graphic_world == nil))
{
DisposeHandle((Handle) picture_handle);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
HUnlock((Handle) picture_handle);
SetGWorld(graphic_world,nil);
theErr=GetPictInfo(picture_handle,&picture_info,0,1,systemMethod,0);
if (theErr != noErr)
{
DisposeGWorld(graphic_world);
DisposeHandle((Handle) picture_handle);
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
}
#if defined(DISABLE_QUICKTIME)
codec='unkn';
colormap_id=(-1);
depth=picture_info.depth;
#else
BottleneckTest(picture_handle,&codec,&depth,&colormap_id);
#endif
switch (codec)
{
case 'rpza':
case 'jpeg':
case 'rle ':
case 'raw ':
case 'smc ':
{
if (depth > 200)
{
depth-=32;
picture_info.theColorTable=GetCTable(colormap_id);
}
break;
}
default:
{
depth=picture_info.depth;
if (depth <= 8)
(void) GetPictInfo(picture_handle,&picture_info,returnColorTable,
(short) (1 << picture_info.depth),systemMethod,0);
break;
}
}
image->x_resolution=(picture_info.hRes) >> 16;
image->y_resolution=(picture_info.vRes) >> 16;
image->units=PixelsPerInchResolution;
image->columns=picture_info.sourceRect.right-picture_info.sourceRect.left;
image->rows=picture_info.sourceRect.bottom-picture_info.sourceRect.top;
if ((depth <= 8) && ((*(picture_info.theColorTable))->ctSize != 0))
{
unsigned long
number_colors;
/*
Colormapped PICT image.
*/
number_colors=(*(picture_info.theColorTable))->ctSize;
if (!AcquireImageColormap(image,number_colors))
{
if (picture_info.theColorTable != nil)
DisposeHandle((Handle) picture_info.theColorTable);
DisposeGWorld(graphic_world);
DisposeHandle((Handle) picture_handle);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
for (x=0; x < image->colors; x++)
{
image->colormap[x].red=
(*(picture_info.theColorTable))->ctTable[x].rgb.red;
image->colormap[x].green=
(*(picture_info.theColorTable))->ctTable[x].rgb.green;
image->colormap[x].blue=
(*(picture_info.theColorTable))->ctTable[x].rgb.blue;
}
}
SetRect(&rectangle,0,0,image->columns,image->rows);
(void) UpdateGWorld(&graphic_world,depth,&rectangle,
picture_info.theColorTable,nil,0);
LockPixels(GetGWorldPixMap(graphic_world)); /*->portPixMap); */
EraseRect(&rectangle);
DrawPicture(picture_handle,&rectangle);
if ((depth <= 8) && (colormap_id == -1))
{
DisposeHandle((Handle) picture_info.theColorTable);
picture_info.theColorTable=nil;
}
DisposeHandle((Handle) picture_handle);
/*
Convert PICT pixels to pixel packets.
*/
for (y=0; y < image->rows; y++)
{
register IndexPacket
*restrict indexes;
register long
x;
register PixelPacket
*restrict q;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < image->columns; x++)
{
GetCPixel(x,y,&Pixel);
q->red=ScaleCharToQuantum(Pixel.red & 0xff);
q->green=ScaleCharToQuantum(Pixel.green & 0xff);
q->blue=ScaleCharToQuantum(Pixel.blue & 0xff);
if (image->storage_class == PseudoClass)
indexes[x]=Color2Index(&Pixel);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
proceed=SetImageProgress(image,LoadImageTag,y,image->rows);
if (proceed == MagickFalse)
break;
}
UnlockPixels(GetGWorldPixMap(graphic_world));
SetGWorld(port,device);
if (picture_info.theColorTable != nil)
DisposeHandle((Handle) picture_info.theColorTable);
DisposeGWorld(graphic_world);
(void) CloseBlob(image);
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% S e a r c h F o r F i l e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% SearchForFile() searches for a file.
%
%
*/
static Boolean SearchForFile(OSType creator_type,OSType file_type,FSSpec *file,
short count)
{
char
*buffer;
CInfoPBRec
search1_info,
search2_info;
FSSpec
application;
HParamBlockRec
parameter_info;
long
buffer_size = 16384;
OSErr
error;
ProcessInfoRec
application_info;
ProcessSerialNumber
serial_number;
serial_number.lowLongOfPSN=kCurrentProcess;
serial_number.highLongOfPSN=0;
application_info.processInfoLength=sizeof(ProcessInfoRec);
application_info.processName=NULL;
application_info.processAppSpec=(&application);
GetProcessInformation(&serial_number,&application_info);
buffer=NewPtr(buffer_size);
if (buffer == (char *) NULL)
return(false);
parameter_info.csParam.ioCompletion=NULL;
parameter_info.csParam.ioNamePtr=NULL;
parameter_info.csParam.ioVRefNum=application.vRefNum;
parameter_info.csParam.ioMatchPtr=file;
parameter_info.csParam.ioReqMatchCount=count;
parameter_info.csParam.ioSearchBits=fsSBFlFndrInfo;
parameter_info.csParam.ioSearchInfo1=&search1_info;
parameter_info.csParam.ioSearchInfo2=&search2_info;
parameter_info.csParam.ioSearchTime=0;
parameter_info.csParam.ioCatPosition.initialize=0;
parameter_info.csParam.ioOptBuffer=buffer;
parameter_info.csParam.ioOptBufSize=buffer_size;
search1_info.hFileInfo.ioNamePtr=NULL;
search1_info.hFileInfo.ioFlFndrInfo.fdType=file_type;
search1_info.hFileInfo.ioFlFndrInfo.fdCreator=creator_type;
search1_info.hFileInfo.ioFlAttrib=0;
search1_info.hFileInfo.ioFlParID=0;
search2_info=search1_info;
search2_info.hFileInfo.ioFlAttrib=0x10;
search2_info.hFileInfo.ioFlFndrInfo.fdCreator=creator_type;
search2_info.hFileInfo.ioFlFndrInfo.fdType=(-1);
search2_info.hFileInfo.ioFlFndrInfo.fdFlags=0;
search2_info.hFileInfo.ioFlFndrInfo.fdLocation.h=0;
search2_info.hFileInfo.ioFlFndrInfo.fdLocation.v=0;
search2_info.hFileInfo.ioFlFndrInfo.fdFldr=0;
search2_info.hFileInfo.ioFlParID=0;
error=PBCatSearchSync((CSParamPtr) ¶meter_info);
DisposePtr(buffer);
if (parameter_info.csParam.ioReqMatchCount ==
parameter_info.csParam.ioActMatchCount)
error=eofErr;
if (parameter_info.csParam.ioActMatchCount == 0)
error=0;
return(error == eofErr);
}
#if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% s e e k d i r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% seekdir() sets the position of the next readdir() operation on the directory
% stream.
%
% The format of the seekdir method is:
%
% void seekdir(DIR *entry,long position)
%
% A description of each parameter follows:
%
% o entry: Specifies a pointer to a DIR structure.
%
% o position: specifies the position associated with the directory
% stream.
%
%
%
*/
MagickExport void seekdir(DIR *entry,long position)
{
assert(entry != (DIR *) NULL);
entry->d_index=position;
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% S e t A p p l i c a t i o n T y p e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% SetApplicationType() sets the file type of an image.
%
% The format of the SetApplicationType method is:
%
% void SetApplicationType(const char *filename,const char *magick,
% OSType application)
%
% A description of each parameter follows:
%
% o filename: Specifies the name of the file.
%
% o filename: Specifies the file type.
%
% o application: Specifies the type of the application.
%
*/
static inline size_t MagickMin(const size_t x,const size_t y)
{
if (x < y)
return(x);
return(y);
}
MagickExport void SetApplicationType(const char *filename,const char *magick,
OSType application)
{
FSSpec
file_specification;
OSType
filetype;
Str255
name;
assert(filename != (char *) NULL);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
assert(magick != (const char *) NULL);
filetype=' ';
(void) CopyMagickString((char *) &filetype,magick,MagickMin(strlen(magick),
4));
if (LocaleCompare(magick,"JPG") == 0)
(void) CopyMagickString((char *) &filetype,"JPEG",MaxTextExtent);
c2pstrcpy(name,filename);
FSMakeFSSpec(0,0,name,&file_specification);
FSpCreate(&file_specification,application,filetype,smSystemScript);
}
#if !defined(_MAGICKCORE_POSIX_SUPPORT_VERSION)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% t e l l d i r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method telldir returns the current location associated with the
% named directory stream.
%
% The format of the telldir method is:
%
% telldir(DIR *entry)
%
% A description of each parameter follows:
%
% o entry: Specifies a pointer to a DIR structure.
%
%
*/
MagickExport long telldir(DIR *entry)
{
return(entry->d_index);
}
#endif
#endif
|