00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include "wand/studio.h"
00050 #include "wand/MagickWand.h"
00051 #include "wand/magick-wand-private.h"
00052 #include "wand/wand.h"
00053
00054
00055
00056
00057 #define ThrowWandException(severity,tag,context) \
00058 { \
00059 (void) ThrowMagickException(wand->exception,GetMagickModule(),severity, \
00060 tag,"`%s'",context); \
00061 return(MagickFalse); \
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 WandExport void ClearMagickWand(MagickWand *wand)
00087 {
00088 assert(wand != (MagickWand *) NULL);
00089 assert(wand->signature == WandSignature);
00090 if (wand->debug != MagickFalse)
00091 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00092 wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
00093 wand->image_info=DestroyImageInfo(wand->image_info);
00094 wand->images=DestroyImageList(wand->images);
00095 wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
00096 wand->image_info=AcquireImageInfo();
00097 ClearMagickException(wand->exception);
00098 wand->debug=IsEventLogging();
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
00124 {
00125 MagickWand
00126 *clone_wand;
00127
00128 assert(wand != (MagickWand *) NULL);
00129 assert(wand->signature == WandSignature);
00130 if (wand->debug != MagickFalse)
00131 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00132 clone_wand=(MagickWand *) AcquireAlignedMemory(1,sizeof(*clone_wand));
00133 if (clone_wand == (MagickWand *) NULL)
00134 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00135 wand->name);
00136 (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
00137 clone_wand->id=AcquireWandId();
00138 (void) FormatMagickString(clone_wand->name,MaxTextExtent,"%s-%lu",
00139 MagickWandId,clone_wand->id);
00140 clone_wand->exception=AcquireExceptionInfo();
00141 InheritException(clone_wand->exception,wand->exception);
00142 clone_wand->image_info=CloneImageInfo(wand->image_info);
00143 clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_info);
00144 clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
00145 clone_wand->debug=IsEventLogging();
00146 if (clone_wand->debug != MagickFalse)
00147 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
00148 clone_wand->signature=WandSignature;
00149 return(clone_wand);
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
00175 {
00176 assert(wand != (MagickWand *) NULL);
00177 assert(wand->signature == WandSignature);
00178 if (wand->debug != MagickFalse)
00179 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00180 wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
00181 wand->image_info=DestroyImageInfo(wand->image_info);
00182 wand->images=DestroyImageList(wand->images);
00183 wand->exception=DestroyExceptionInfo(wand->exception);
00184 RelinquishWandId(wand->id);
00185 wand->signature=(~WandSignature);
00186 wand=(MagickWand *) RelinquishMagickMemory(wand);
00187 return(wand);
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
00213 {
00214 if (wand == (const MagickWand *) NULL)
00215 return(MagickFalse);
00216 if (wand->signature != WandSignature)
00217 return(MagickFalse);
00218 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
00219 return(MagickFalse);
00220 return(MagickTrue);
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 WandExport MagickBooleanType MagickClearException(MagickWand *wand)
00246 {
00247 assert(wand != (MagickWand *) NULL);
00248 assert(wand->signature == WandSignature);
00249 if (wand->debug != MagickFalse)
00250 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00251 ClearMagickException(wand->exception);
00252 return(MagickTrue);
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 WandExport char *MagickGetException(const MagickWand *wand,
00281 ExceptionType *severity)
00282 {
00283 char
00284 *description;
00285
00286 assert(wand != (const MagickWand *) NULL);
00287 assert(wand->signature == WandSignature);
00288 if (wand->debug != MagickFalse)
00289 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00290 assert(severity != (ExceptionType *) NULL);
00291 *severity=wand->exception->severity;
00292 description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
00293 sizeof(*description));
00294 if (description == (char *) NULL)
00295 {
00296 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00297 "MemoryAllocationFailed","`%s'",wand->name);
00298 return((char *) NULL);
00299 }
00300 *description='\0';
00301 if (wand->exception->reason != (char *) NULL)
00302 (void) CopyMagickString(description,GetLocaleExceptionMessage(
00303 wand->exception->severity,wand->exception->reason),MaxTextExtent);
00304 if (wand->exception->description != (char *) NULL)
00305 {
00306 (void) ConcatenateMagickString(description," (",MaxTextExtent);
00307 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
00308 wand->exception->severity,wand->exception->description),MaxTextExtent);
00309 (void) ConcatenateMagickString(description,")",MaxTextExtent);
00310 }
00311 return(description);
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
00338 {
00339 assert(wand != (MagickWand *) NULL);
00340 assert(wand->signature == WandSignature);
00341 if (wand->debug != MagickFalse)
00342 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00343 return(wand->exception->severity);
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 WandExport long MagickGetIteratorIndex(MagickWand *wand)
00370 {
00371 assert(wand != (MagickWand *) NULL);
00372 assert(wand->signature == WandSignature);
00373 if (wand->debug != MagickFalse)
00374 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00375 if (wand->images == (Image *) NULL)
00376 {
00377 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00378 "ContainsNoIterators","`%s'",wand->name);
00379 return(-1);
00380 }
00381 return(GetImageIndexInList(wand->images));
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 WandExport char *MagickQueryConfigureOption(const char *option)
00408 {
00409 char
00410 *value;
00411
00412 const ConfigureInfo
00413 **configure_info;
00414
00415 ExceptionInfo
00416 *exception;
00417
00418 unsigned long
00419 number_options;
00420
00421 exception=AcquireExceptionInfo();
00422 configure_info=GetConfigureInfoList(option,&number_options,exception);
00423 exception=DestroyExceptionInfo(exception);
00424 if (configure_info == (const ConfigureInfo **) NULL)
00425 return((char *) NULL);
00426 value=AcquireString(configure_info[0]->value);
00427 configure_info=(const ConfigureInfo **)
00428 RelinquishMagickMemory((void *) configure_info);
00429 return(value);
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 WandExport char **MagickQueryConfigureOptions(const char *pattern,
00461 unsigned long *number_options)
00462 {
00463 char
00464 **options;
00465
00466 ExceptionInfo
00467 *exception;
00468
00469 exception=AcquireExceptionInfo();
00470 options=GetConfigureList(pattern,number_options,exception);
00471 exception=DestroyExceptionInfo(exception);
00472 return(options);
00473 }
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 WandExport double *MagickQueryFontMetrics(MagickWand *wand,
00520 const DrawingWand *drawing_wand,const char *text)
00521 {
00522 double
00523 *font_metrics;
00524
00525 DrawInfo
00526 *draw_info;
00527
00528 MagickBooleanType
00529 status;
00530
00531 TypeMetric
00532 metrics;
00533
00534 assert(wand != (MagickWand *) NULL);
00535 assert(wand->signature == WandSignature);
00536 if (wand->debug != MagickFalse)
00537 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00538 assert(drawing_wand != (const DrawingWand *) NULL);
00539 if (wand->images == (Image *) NULL)
00540 {
00541 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00542 "ContainsNoImages","`%s'",wand->name);
00543 return((double *) NULL);
00544 }
00545 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
00546 if (font_metrics == (double *) NULL)
00547 return((double *) NULL);
00548 draw_info=PeekDrawingWand(drawing_wand);
00549 if (draw_info == (DrawInfo *) NULL)
00550 {
00551 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00552 return((double *) NULL);
00553 }
00554 (void) CloneString(&draw_info->text,text);
00555 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
00556 status=GetTypeMetrics(wand->images,draw_info,&metrics);
00557 draw_info=DestroyDrawInfo(draw_info);
00558 if (status == MagickFalse)
00559 {
00560 InheritException(wand->exception,&wand->images->exception);
00561 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00562 return((double *) NULL);
00563 }
00564 font_metrics[0]=metrics.pixels_per_em.x;
00565 font_metrics[1]=metrics.pixels_per_em.y;
00566 font_metrics[2]=metrics.ascent;
00567 font_metrics[3]=metrics.descent;
00568 font_metrics[4]=metrics.width;
00569 font_metrics[5]=metrics.height;
00570 font_metrics[6]=metrics.max_advance;
00571 font_metrics[7]=metrics.bounds.x1;
00572 font_metrics[8]=metrics.bounds.y1;
00573 font_metrics[9]=metrics.bounds.x2;
00574 font_metrics[10]=metrics.bounds.y2;
00575 font_metrics[11]=metrics.origin.x;
00576 font_metrics[12]=metrics.origin.y;
00577 return(font_metrics);
00578 }
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
00628 const DrawingWand *drawing_wand,const char *text)
00629 {
00630 double
00631 *font_metrics;
00632
00633 DrawInfo
00634 *draw_info;
00635
00636 MagickBooleanType
00637 status;
00638
00639 TypeMetric
00640 metrics;
00641
00642 assert(wand != (MagickWand *) NULL);
00643 assert(wand->signature == WandSignature);
00644 if (wand->debug != MagickFalse)
00645 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00646 assert(drawing_wand != (const DrawingWand *) NULL);
00647 if (wand->images == (Image *) NULL)
00648 {
00649 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00650 "ContainsNoImages","`%s'",wand->name);
00651 return((double *) NULL);
00652 }
00653 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
00654 if (font_metrics == (double *) NULL)
00655 return((double *) NULL);
00656 draw_info=PeekDrawingWand(drawing_wand);
00657 if (draw_info == (DrawInfo *) NULL)
00658 {
00659 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00660 return((double *) NULL);
00661 }
00662 (void) CloneString(&draw_info->text,text);
00663 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
00664 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics);
00665 draw_info=DestroyDrawInfo(draw_info);
00666 if (status == MagickFalse)
00667 {
00668 InheritException(wand->exception,&wand->images->exception);
00669 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00670 return((double *) NULL);
00671 }
00672 font_metrics[0]=metrics.pixels_per_em.x;
00673 font_metrics[1]=metrics.pixels_per_em.y;
00674 font_metrics[2]=metrics.ascent;
00675 font_metrics[3]=metrics.descent;
00676 font_metrics[4]=metrics.width;
00677 font_metrics[5]=metrics.height;
00678 font_metrics[6]=metrics.max_advance;
00679 font_metrics[7]=metrics.bounds.x1;
00680 font_metrics[8]=metrics.bounds.y1;
00681 font_metrics[9]=metrics.bounds.x2;
00682 font_metrics[10]=metrics.bounds.y2;
00683 font_metrics[11]=metrics.origin.x;
00684 font_metrics[12]=metrics.origin.y;
00685 return(font_metrics);
00686 }
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 WandExport char **MagickQueryFonts(const char *pattern,
00715 unsigned long *number_fonts)
00716 {
00717 char
00718 **fonts;
00719
00720 ExceptionInfo
00721 *exception;
00722
00723 exception=AcquireExceptionInfo();
00724 fonts=GetTypeList(pattern,number_fonts,exception);
00725 exception=DestroyExceptionInfo(exception);
00726 return(fonts);
00727 }
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756 WandExport char **MagickQueryFormats(const char *pattern,
00757 unsigned long *number_formats)
00758 {
00759 char
00760 **formats;
00761
00762 ExceptionInfo
00763 *exception;
00764
00765 exception=AcquireExceptionInfo();
00766 formats=GetMagickList(pattern,number_formats,exception);
00767 exception=DestroyExceptionInfo(exception);
00768 return(formats);
00769 }
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 WandExport void *MagickRelinquishMemory(void *memory)
00795 {
00796 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00797 return(RelinquishMagickMemory(memory));
00798 }
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824 WandExport void MagickResetIterator(MagickWand *wand)
00825 {
00826 assert(wand != (MagickWand *) NULL);
00827 assert(wand->signature == WandSignature);
00828 if (wand->debug != MagickFalse)
00829 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00830 wand->active=MagickFalse;
00831 wand->pend=MagickTrue;
00832 wand->images=GetFirstImageInList(wand->images);
00833 }
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857 WandExport void MagickSetFirstIterator(MagickWand *wand)
00858 {
00859 assert(wand != (MagickWand *) NULL);
00860 assert(wand->signature == WandSignature);
00861 if (wand->debug != MagickFalse)
00862 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00863 wand->active=MagickTrue;
00864 wand->pend=MagickFalse;
00865 wand->images=GetFirstImageInList(wand->images);
00866 }
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894 WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
00895 const long index)
00896 {
00897 Image
00898 *image;
00899
00900 assert(wand != (MagickWand *) NULL);
00901 assert(wand->signature == WandSignature);
00902 if (wand->debug != MagickFalse)
00903 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00904 if (wand->images == (Image *) NULL)
00905 return(MagickFalse);
00906 image=GetImageFromList(wand->images,index);
00907 if (image == (Image *) NULL)
00908 {
00909 InheritException(wand->exception,&wand->images->exception);
00910 return(MagickFalse);
00911 }
00912 wand->active=MagickTrue;
00913 wand->pend=MagickFalse;
00914 wand->images=image;
00915 return(MagickTrue);
00916 }
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939 WandExport void MagickSetLastIterator(MagickWand *wand)
00940 {
00941 assert(wand != (MagickWand *) NULL);
00942 assert(wand->signature == WandSignature);
00943 if (wand->debug != MagickFalse)
00944 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00945 wand->active=MagickFalse;
00946 wand->pend=MagickTrue;
00947 wand->images=GetLastImageInList(wand->images);
00948 }
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968 WandExport void MagickWandGenesis(void)
00969 {
00970 if (IsMagickInstantiated() == MagickFalse)
00971 MagickCoreGenesis((char *) NULL,MagickFalse);
00972 }
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992 WandExport void MagickWandTerminus(void)
00993 {
00994 DestroyWandIds();
00995 MagickCoreTerminus();
00996 }
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 WandExport MagickWand *NewMagickWand(void)
01017 {
01018 const char
01019 *quantum;
01020
01021 MagickWand
01022 *wand;
01023
01024 unsigned long
01025 depth;
01026
01027 depth=MAGICKCORE_QUANTUM_DEPTH;
01028 quantum=GetMagickQuantumDepth(&depth);
01029 if (depth != MAGICKCORE_QUANTUM_DEPTH)
01030 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
01031 wand=(MagickWand *) AcquireAlignedMemory(1,sizeof(*wand));
01032 if (wand == (MagickWand *) NULL)
01033 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
01034 GetExceptionMessage(errno));
01035 (void) ResetMagickMemory(wand,0,sizeof(*wand));
01036 wand->id=AcquireWandId();
01037 (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",MagickWandId,
01038 wand->id);
01039 wand->exception=AcquireExceptionInfo();
01040 wand->image_info=AcquireImageInfo();
01041 wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
01042 wand->images=NewImageList();
01043 wand->debug=IsEventLogging();
01044 if (wand->debug != MagickFalse)
01045 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
01046 wand->signature=WandSignature;
01047 return(wand);
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072 WandExport MagickWand *NewMagickWandFromImage(const Image *image)
01073 {
01074 MagickWand
01075 *wand;
01076
01077 wand=NewMagickWand();
01078 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
01079 return(wand);
01080 }