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/pixel-wand-private.h"
00053 #include "wand/wand.h"
00054
00055
00056
00057
00058 #define PixelWandId "PixelWand"
00059
00060
00061
00062
00063 struct _PixelWand
00064 {
00065 unsigned long
00066 id;
00067
00068 char
00069 name[MaxTextExtent];
00070
00071 ExceptionInfo
00072 *exception;
00073
00074 MagickPixelPacket
00075 pixel;
00076
00077 unsigned long
00078 count;
00079
00080 MagickBooleanType
00081 debug;
00082
00083 unsigned long
00084 signature;
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 WandExport void ClearPixelWand(PixelWand *wand)
00110 {
00111 assert(wand != (PixelWand *) NULL);
00112 assert(wand->signature == WandSignature);
00113 if (wand->debug != MagickFalse)
00114 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00115 ClearMagickException(wand->exception);
00116 wand->pixel.colorspace=RGBColorspace;
00117 wand->debug=IsEventLogging();
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 WandExport PixelWand *ClonePixelWand(const PixelWand *wand)
00143 {
00144 PixelWand
00145 *clone_wand;
00146
00147 assert(wand != (PixelWand *) NULL);
00148 assert(wand->signature == WandSignature);
00149 if (wand->debug != MagickFalse)
00150 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00151 clone_wand=(PixelWand *) AcquireMagickMemory(sizeof(*clone_wand));
00152 if (clone_wand == (PixelWand *) NULL)
00153 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00154 wand->name);
00155 (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
00156 clone_wand->id=AcquireWandId();
00157 (void) FormatMagickString(clone_wand->name,MaxTextExtent,"%s-%lu",PixelWandId,
00158 clone_wand->id);
00159 clone_wand->exception=AcquireExceptionInfo();
00160 InheritException(clone_wand->exception,wand->exception);
00161 clone_wand->pixel=wand->pixel;
00162 clone_wand->count=wand->count;
00163 clone_wand->debug=IsEventLogging();
00164 if (clone_wand->debug != MagickFalse)
00165 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
00166 clone_wand->signature=WandSignature;
00167 return(clone_wand);
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 WandExport PixelWand **ClonePixelWands(const PixelWand **wands,
00196 const unsigned long number_wands)
00197 {
00198 register long
00199 i;
00200
00201 PixelWand
00202 **clone_wands;
00203
00204 clone_wands=(PixelWand **) AcquireQuantumMemory((size_t) number_wands,
00205 sizeof(*clone_wands));
00206 if (clone_wands == (PixelWand **) NULL)
00207 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00208 strerror(errno));
00209 for (i=0; i < (long) number_wands; i++)
00210 clone_wands[i]=ClonePixelWand(wands[i]);
00211 return(clone_wands);
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 WandExport PixelWand *DestroyPixelWand(PixelWand *wand)
00237 {
00238 assert(wand != (PixelWand *) NULL);
00239 assert(wand->signature == WandSignature);
00240 if (wand->debug != MagickFalse)
00241 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00242 wand->exception=DestroyExceptionInfo(wand->exception);
00243 wand->signature=(~WandSignature);
00244 RelinquishWandId(wand->id);
00245 wand=(PixelWand *) RelinquishMagickMemory(wand);
00246 return(wand);
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 WandExport PixelWand **DestroyPixelWands(PixelWand **wand,
00276 const unsigned long number_wands)
00277 {
00278 register long
00279 i;
00280
00281 assert(wand != (PixelWand **) NULL);
00282 assert(*wand != (PixelWand *) NULL);
00283 assert((*wand)->signature == WandSignature);
00284 if ((*wand)->debug != MagickFalse)
00285 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",(*wand)->name);
00286 for (i=(long) number_wands-1; i >= 0; i--)
00287 wand[i]=DestroyPixelWand(wand[i]);
00288 wand=(PixelWand **) RelinquishMagickMemory(wand);
00289 return(wand);
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 WandExport MagickBooleanType IsPixelWandSimilar(PixelWand *p,PixelWand *q,
00322 const double fuzz)
00323 {
00324 assert(p != (PixelWand *) NULL);
00325 assert(p->signature == WandSignature);
00326 if (p->debug != MagickFalse)
00327 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",p->name);
00328 assert(q != (PixelWand *) NULL);
00329 assert(q->signature == WandSignature);
00330 if (q->debug != MagickFalse)
00331 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",q->name);
00332 p->pixel.fuzz=fuzz;
00333 q->pixel.fuzz=fuzz;
00334 return(IsMagickColorSimilar(&p->pixel,&q->pixel));
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 WandExport MagickBooleanType IsPixelWand(const PixelWand *wand)
00360 {
00361 if (wand == (const PixelWand *) NULL)
00362 return(MagickFalse);
00363 if (wand->signature != WandSignature)
00364 return(MagickFalse);
00365 if (LocaleNCompare(wand->name,PixelWandId,strlen(PixelWandId)) != 0)
00366 return(MagickFalse);
00367 return(MagickTrue);
00368 }
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 WandExport PixelWand *NewPixelWand(void)
00389 {
00390 const char
00391 *quantum;
00392
00393 PixelWand
00394 *wand;
00395
00396 unsigned long
00397 depth;
00398
00399 depth=MAGICKCORE_QUANTUM_DEPTH;
00400 quantum=GetMagickQuantumDepth(&depth);
00401 if (depth != MAGICKCORE_QUANTUM_DEPTH)
00402 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
00403 wand=(PixelWand *) AcquireMagickMemory(sizeof(*wand));
00404 if (wand == (PixelWand *) NULL)
00405 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00406 strerror(errno));
00407 (void) ResetMagickMemory(wand,0,sizeof(*wand));
00408 wand->id=AcquireWandId();
00409 (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",PixelWandId,
00410 wand->id);
00411 wand->exception=AcquireExceptionInfo();
00412 GetMagickPixelPacket((Image *) NULL,&wand->pixel);
00413 wand->debug=IsEventLogging();
00414 if (wand->debug != MagickFalse)
00415 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00416 wand->signature=WandSignature;
00417 return(wand);
00418 }
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 WandExport PixelWand **NewPixelWands(const unsigned long number_wands)
00443 {
00444 register long
00445 i;
00446
00447 PixelWand
00448 **wands;
00449
00450 wands=(PixelWand **) AcquireQuantumMemory((size_t) number_wands,
00451 sizeof(*wands));
00452 if (wands == (PixelWand **) NULL)
00453 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00454 strerror(errno));
00455 for (i=0; i < (long) number_wands; i++)
00456 wands[i]=NewPixelWand();
00457 return(wands);
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 WandExport MagickBooleanType PixelClearException(PixelWand *wand)
00483 {
00484 assert(wand != (PixelWand *) NULL);
00485 assert(wand->signature == WandSignature);
00486 if (wand->debug != MagickFalse)
00487 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00488 ClearMagickException(wand->exception);
00489 return(MagickTrue);
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 WandExport double PixelGetAlpha(const PixelWand *wand)
00515 {
00516 assert(wand != (const PixelWand *) NULL);
00517 assert(wand->signature == WandSignature);
00518 if (wand->debug != MagickFalse)
00519 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00520 return((double) QuantumScale*(QuantumRange-wand->pixel.opacity));
00521 }
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 WandExport Quantum PixelGetAlphaQuantum(const PixelWand *wand)
00546 {
00547 assert(wand != (const PixelWand *) NULL);
00548 assert(wand->signature == WandSignature);
00549 if (wand->debug != MagickFalse)
00550 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00551 return((Quantum) QuantumRange-RoundToQuantum(wand->pixel.opacity));
00552 }
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 WandExport double PixelGetBlack(const PixelWand *wand)
00577 {
00578 assert(wand != (const PixelWand *) NULL);
00579 assert(wand->signature == WandSignature);
00580 if (wand->debug != MagickFalse)
00581 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00582 return((double) QuantumScale*wand->pixel.index);
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 WandExport Quantum PixelGetBlackQuantum(const PixelWand *wand)
00608 {
00609 assert(wand != (const PixelWand *) NULL);
00610 assert(wand->signature == WandSignature);
00611 if (wand->debug != MagickFalse)
00612 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00613 return(RoundToQuantum(wand->pixel.index));
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638 WandExport double PixelGetBlue(const PixelWand *wand)
00639 {
00640 assert(wand != (const PixelWand *) NULL);
00641 assert(wand->signature == WandSignature);
00642 if (wand->debug != MagickFalse)
00643 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00644 return((double) QuantumScale*wand->pixel.blue);
00645 }
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 WandExport Quantum PixelGetBlueQuantum(const PixelWand *wand)
00670 {
00671 assert(wand != (const PixelWand *) NULL);
00672 assert(wand->signature == WandSignature);
00673 if (wand->debug != MagickFalse)
00674 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00675 return(RoundToQuantum(wand->pixel.blue));
00676 }
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 WandExport char *PixelGetColorAsString(const PixelWand *wand)
00701 {
00702 char
00703 *color;
00704
00705 MagickPixelPacket
00706 pixel;
00707
00708 assert(wand != (const PixelWand *) NULL);
00709 assert(wand->signature == WandSignature);
00710 if (wand->debug != MagickFalse)
00711 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00712 pixel=wand->pixel;
00713 color=AcquireString((const char *) NULL);
00714 GetColorTuple(&pixel,MagickFalse,color);
00715 return(color);
00716 }
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741 WandExport char *PixelGetColorAsNormalizedString(const PixelWand *wand)
00742 {
00743 char
00744 color[MaxTextExtent];
00745
00746 assert(wand != (const PixelWand *) NULL);
00747 assert(wand->signature == WandSignature);
00748 if (wand->debug != MagickFalse)
00749 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00750 (void) FormatMagickString(color,MaxTextExtent,"%g,%g,%g",
00751 (double) (QuantumScale*wand->pixel.red),
00752 (double) (QuantumScale*wand->pixel.green),
00753 (double) (QuantumScale*wand->pixel.blue));
00754 if (wand->pixel.colorspace == CMYKColorspace)
00755 (void) FormatMagickString(color+strlen(color),MaxTextExtent,",%g",
00756 (double) (QuantumScale*wand->pixel.index));
00757 if (wand->pixel.matte != MagickFalse)
00758 (void) FormatMagickString(color+strlen(color),MaxTextExtent,",%g",
00759 (double) (QuantumScale*wand->pixel.opacity));
00760 return(ConstantString(color));
00761 }
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785 WandExport unsigned long PixelGetColorCount(const PixelWand *wand)
00786 {
00787 assert(wand != (const PixelWand *) NULL);
00788 assert(wand->signature == WandSignature);
00789 if (wand->debug != MagickFalse)
00790 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00791 return(wand->count);
00792 }
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816 WandExport double PixelGetCyan(const PixelWand *wand)
00817 {
00818 assert(wand != (const PixelWand *) NULL);
00819 assert(wand->signature == WandSignature);
00820 if (wand->debug != MagickFalse)
00821 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00822 return((double) QuantumScale*wand->pixel.red);
00823 }
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 WandExport Quantum PixelGetCyanQuantum(const PixelWand *wand)
00848 {
00849 assert(wand != (const PixelWand *) NULL);
00850 assert(wand->signature == WandSignature);
00851 if (wand->debug != MagickFalse)
00852 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00853 return(RoundToQuantum(wand->pixel.red));
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881 WandExport char *PixelGetException(const PixelWand *wand,
00882 ExceptionType *severity)
00883 {
00884 char
00885 *description;
00886
00887 assert(wand != (const PixelWand *) NULL);
00888 assert(wand->signature == WandSignature);
00889 if (wand->debug != MagickFalse)
00890 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00891 assert(severity != (ExceptionType *) NULL);
00892 *severity=wand->exception->severity;
00893 description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
00894 sizeof(*description));
00895 if (description == (char *) NULL)
00896 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00897 wand->name);
00898 *description='\0';
00899 if (wand->exception->reason != (char *) NULL)
00900 (void) CopyMagickString(description,GetLocaleExceptionMessage(
00901 wand->exception->severity,wand->exception->reason),MaxTextExtent);
00902 if (wand->exception->description != (char *) NULL)
00903 {
00904 (void) ConcatenateMagickString(description," (",MaxTextExtent);
00905 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
00906 wand->exception->severity,wand->exception->description),MaxTextExtent);
00907 (void) ConcatenateMagickString(description,")",MaxTextExtent);
00908 }
00909 return(description);
00910 }
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935 WandExport ExceptionType PixelGetExceptionType(const PixelWand *wand)
00936 {
00937 assert(wand != (const PixelWand *) NULL);
00938 assert(wand->signature == WandSignature);
00939 if (wand->debug != MagickFalse)
00940 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00941 return(wand->exception->severity);
00942 }
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966 WandExport double PixelGetFuzz(const PixelWand *wand)
00967 {
00968 assert(wand != (const PixelWand *) NULL);
00969 assert(wand->signature == WandSignature);
00970 if (wand->debug != MagickFalse)
00971 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00972 return((double) wand->pixel.fuzz);
00973 }
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997 WandExport double PixelGetGreen(const PixelWand *wand)
00998 {
00999 assert(wand != (const PixelWand *) NULL);
01000 assert(wand->signature == WandSignature);
01001 if (wand->debug != MagickFalse)
01002 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
01003 return((double) QuantumScale*wand->pixel.green);
01004 }
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028 WandExport Quantum PixelGetGreenQuantum(const PixelWand *wand)
01029 {
01030 assert(wand != (const PixelWand *) NULL);
01031 assert(wand->signature == WandSignature);
01032 if (wand->debug != MagickFalse)
01033 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
01034 return(RoundToQuantum(wand->pixel.green));
01035 }
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063 WandExport void PixelGetHSL(const PixelWand *wand,double *hue,
01064 double *saturation,double *lightness)
01065 {
01066 assert(wand != (const PixelWand *) NULL);
01067 assert(wand->signature == WandSignature);
01068 if (wand->debug != MagickFalse)
01069 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
01070 ConvertRGBToHSL(RoundToQuantum(wand->pixel.red),RoundToQuantum(
01071 wand->pixel.green),RoundToQuantum(wand->pixel.blue),hue,saturation,
01072 lightness);
01073 }
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094