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