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 #include "magick/studio.h"
00042 #include "magick/property.h"
00043 #include "magick/blob.h"
00044 #include "magick/blob-private.h"
00045 #include "magick/color-private.h"
00046 #include "magick/exception.h"
00047 #include "magick/exception-private.h"
00048 #include "magick/cache.h"
00049 #include "magick/constitute.h"
00050 #include "magick/delegate.h"
00051 #include "magick/geometry.h"
00052 #include "magick/list.h"
00053 #include "magick/magick.h"
00054 #include "magick/memory_.h"
00055 #include "magick/monitor.h"
00056 #include "magick/option.h"
00057 #include "magick/pixel.h"
00058 #include "magick/pixel-private.h"
00059 #include "magick/quantum.h"
00060 #include "magick/quantum-private.h"
00061 #include "magick/resource_.h"
00062 #include "magick/semaphore.h"
00063 #include "magick/statistic.h"
00064 #include "magick/stream.h"
00065 #include "magick/string_.h"
00066 #include "magick/thread-private.h"
00067 #include "magick/utility.h"
00068
00069
00070
00071
00072 #define QuantumSignature 0xab
00073
00074
00075
00076
00077 static void
00078 DestroyQuantumPixels(QuantumInfo *);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 static inline unsigned long MagickMax(const unsigned long x,
00106 const unsigned long y)
00107 {
00108 if (x > y)
00109 return(x);
00110 return(y);
00111 }
00112
00113 MagickExport QuantumInfo *AcquireQuantumInfo(const ImageInfo *image_info,
00114 Image *image)
00115 {
00116 MagickBooleanType
00117 status;
00118
00119 QuantumInfo
00120 *quantum_info;
00121
00122 quantum_info=(QuantumInfo *) AcquireMagickMemory(sizeof(*quantum_info));
00123 if (quantum_info == (QuantumInfo *) NULL)
00124 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00125 quantum_info->signature=MagickSignature;
00126 GetQuantumInfo(image_info,quantum_info);
00127 if (image == (const Image *) NULL)
00128 return(quantum_info);
00129 status=SetQuantumDepth(image,quantum_info,image->depth);
00130 if (status == MagickFalse)
00131 quantum_info=DestroyQuantumInfo(quantum_info);
00132 return(quantum_info);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 static MagickBooleanType AcquireQuantumPixels(QuantumInfo *quantum_info,
00161 const size_t extent)
00162 {
00163 register long
00164 i;
00165
00166 assert(quantum_info != (QuantumInfo *) NULL);
00167 assert(quantum_info->signature == MagickSignature);
00168 quantum_info->number_threads=GetOpenMPMaximumThreads();
00169 quantum_info->pixels=(unsigned char **) AcquireQuantumMemory(
00170 quantum_info->number_threads,sizeof(*quantum_info->pixels));
00171 if (quantum_info->pixels == (unsigned char **) NULL)
00172 return(MagickFalse);
00173 quantum_info->extent=extent;
00174 (void) ResetMagickMemory(quantum_info->pixels,0,
00175 sizeof(*quantum_info->pixels));
00176 for (i=0; i < (long) quantum_info->number_threads; i++)
00177 {
00178 quantum_info->pixels[i]=(unsigned char *) AcquireQuantumMemory(extent+1,
00179 sizeof(**quantum_info->pixels));
00180 if (quantum_info->pixels[i] == (unsigned char *) NULL)
00181 return(MagickFalse);
00182 (void) ResetMagickMemory(quantum_info->pixels[i],0,(extent+1)*
00183 sizeof(**quantum_info->pixels));
00184 quantum_info->pixels[i][extent]=QuantumSignature;
00185 }
00186 return(MagickTrue);
00187 }
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 MagickExport QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info)
00213 {
00214 assert(quantum_info != (QuantumInfo *) NULL);
00215 assert(quantum_info->signature == MagickSignature);
00216 if (quantum_info->pixels != (unsigned char **) NULL)
00217 DestroyQuantumPixels(quantum_info);
00218 if (quantum_info->semaphore != (SemaphoreInfo *) NULL)
00219 DestroySemaphoreInfo(&quantum_info->semaphore);
00220 quantum_info->signature=(~MagickSignature);
00221 quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info);
00222 return(quantum_info);
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 static void DestroyQuantumPixels(QuantumInfo *quantum_info)
00248 {
00249 register long
00250 i;
00251
00252 assert(quantum_info != (QuantumInfo *) NULL);
00253 assert(quantum_info->signature == MagickSignature);
00254 assert(quantum_info->pixels != (unsigned char **) NULL);
00255 for (i=0; i < (long) quantum_info->number_threads; i++)
00256 {
00257 assert(quantum_info->pixels[i][quantum_info->extent] == QuantumSignature);
00258 quantum_info->pixels[i]=(unsigned char *) RelinquishMagickMemory(
00259 quantum_info->pixels[i]);
00260 }
00261 quantum_info->pixels=(unsigned char **) RelinquishMagickMemory(
00262 quantum_info->pixels);
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 MagickExport size_t GetQuantumExtent(const Image *image,
00294 const QuantumInfo *quantum_info,const QuantumType quantum_type)
00295 {
00296 size_t
00297 packet_size;
00298
00299 assert(quantum_info != (QuantumInfo *) NULL);
00300 assert(quantum_info->signature == MagickSignature);
00301 packet_size=1;
00302 switch (quantum_type)
00303 {
00304 case GrayAlphaQuantum: packet_size=2; break;
00305 case IndexAlphaQuantum: packet_size=2; break;
00306 case RGBQuantum: packet_size=3; break;
00307 case RGBAQuantum: packet_size=4; break;
00308 case RGBOQuantum: packet_size=4; break;
00309 case CMYKQuantum: packet_size=4; break;
00310 case CMYKAQuantum: packet_size=5; break;
00311 default: break;
00312 }
00313 if (quantum_info->pack == MagickFalse)
00314 return((size_t) (packet_size*image->columns*((image->depth+7)/8)));
00315 return((size_t) ((packet_size*image->columns*image->depth+7)/8));
00316 }
00317
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 MagickExport void GetQuantumInfo(const ImageInfo *image_info,
00343 QuantumInfo *quantum_info)
00344 {
00345 const char
00346 *option;
00347
00348 assert(quantum_info != (QuantumInfo *) NULL);
00349 (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info));
00350 quantum_info->quantum=8;
00351 quantum_info->maximum=1.0;
00352 quantum_info->scale=QuantumRange;
00353 quantum_info->pack=MagickTrue;
00354 quantum_info->semaphore=AllocateSemaphoreInfo();
00355 quantum_info->signature=MagickSignature;
00356 if (image_info == (const ImageInfo *) NULL)
00357 return;
00358 option=GetImageOption(image_info,"quantum:format");
00359 if (option != (char *) NULL)
00360 quantum_info->format=(QuantumFormatType) ParseMagickOption(
00361 MagickQuantumFormatOptions,MagickFalse,option);
00362 option=GetImageOption(image_info,"quantum:minimum");
00363 if (option != (char *) NULL)
00364 quantum_info->minimum=atof(option);
00365 option=GetImageOption(image_info,"quantum:maximum");
00366 if (option != (char *) NULL)
00367 quantum_info->maximum=atof(option);
00368 if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0))
00369 quantum_info->scale=0.0;
00370 else
00371 if (quantum_info->minimum == quantum_info->maximum)
00372 {
00373 quantum_info->scale=(MagickRealType) QuantumRange/quantum_info->minimum;
00374 quantum_info->minimum=0.0;
00375 }
00376 else
00377 quantum_info->scale=(MagickRealType) QuantumRange/(quantum_info->maximum-
00378 quantum_info->minimum);
00379 option=GetImageOption(image_info,"quantum:scale");
00380 if (option != (char *) NULL)
00381 quantum_info->scale=atof(option);
00382 option=GetImageOption(image_info,"quantum:polarity");
00383 if (option != (char *) NULL)
00384 quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ?
00385 MagickTrue : MagickFalse;
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 MagickExport unsigned char *GetQuantumPixels(const QuantumInfo *quantum_info)
00412 {
00413 long
00414 id;
00415
00416 assert(quantum_info != (QuantumInfo *) NULL);
00417 assert(quantum_info->signature == MagickSignature);
00418 id=GetOpenMPThreadId();
00419 return(quantum_info->pixels[id]);
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 MagickExport QuantumType GetQuantumType(Image *image,ExceptionInfo *exception)
00445 {
00446 QuantumType
00447 quantum_type;
00448
00449 assert(image != (Image *) NULL);
00450 assert(image->signature == MagickSignature);
00451 if (image->debug != MagickFalse)
00452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00453 quantum_type=RGBQuantum;
00454 if (image->matte != MagickFalse)
00455 quantum_type=RGBAQuantum;
00456 if (image->colorspace == CMYKColorspace)
00457 {
00458 quantum_type=CMYKQuantum;
00459 if (image->matte != MagickFalse)
00460 quantum_type=CMYKAQuantum;
00461 }
00462 if (IsGrayImage(image,exception) != MagickFalse)
00463 {
00464 quantum_type=GrayQuantum;
00465 if (image->matte != MagickFalse)
00466 quantum_type=GrayAlphaQuantum;
00467 }
00468 else
00469 if (image->storage_class == PseudoClass)
00470 {
00471 quantum_type=IndexQuantum;
00472 if (image->matte != MagickFalse)
00473 quantum_type=IndexAlphaQuantum;
00474 }
00475 return(quantum_type);
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 MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info,
00504 const QuantumAlphaType type)
00505 {
00506 assert(quantum_info != (QuantumInfo *) NULL);
00507 assert(quantum_info->signature == MagickSignature);
00508 quantum_info->alpha_type=type;
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 MagickExport MagickBooleanType SetQuantumDepth(const Image *image,
00539 QuantumInfo *quantum_info,const unsigned long depth)
00540 {
00541 MagickBooleanType
00542 status;
00543
00544
00545
00546
00547 assert(image != (Image *) NULL);
00548 assert(image->signature == MagickSignature);
00549 if (image->debug != MagickFalse)
00550 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00551 assert(quantum_info != (QuantumInfo *) NULL);
00552 assert(quantum_info->signature == MagickSignature);
00553 quantum_info->depth=depth;
00554 if (quantum_info->format == FloatingPointQuantumFormat)
00555 {
00556 if (quantum_info->depth > 32)
00557 quantum_info->depth=64;
00558 else
00559 quantum_info->depth=32;
00560 }
00561 if (quantum_info->pixels != (unsigned char **) NULL)
00562 DestroyQuantumPixels(quantum_info);
00563 status=AcquireQuantumPixels(quantum_info,(quantum_info->pad+5)*image->columns*
00564 ((quantum_info->depth+7)/8));
00565 return(status);
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 MagickExport MagickBooleanType SetQuantumFormat(const Image *image,
00596 QuantumInfo *quantum_info,const QuantumFormatType format)
00597 {
00598 assert(image != (Image *) NULL);
00599 assert(image->signature == MagickSignature);
00600 if (image->debug != MagickFalse)
00601 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00602 assert(quantum_info != (QuantumInfo *) NULL);
00603 assert(quantum_info->signature == MagickSignature);
00604 quantum_info->format=format;
00605 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
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
00634 MagickExport void SetQuantumImageType(Image *image,
00635 const QuantumType quantum_type)
00636 {
00637 assert(image != (Image *) NULL);
00638 assert(image->signature == MagickSignature);
00639 if (image->debug != MagickFalse)
00640 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00641 switch (quantum_type)
00642 {
00643 case IndexQuantum:
00644 case IndexAlphaQuantum:
00645 {
00646 image->type=PaletteType;
00647 break;
00648 }
00649 case GrayQuantum:
00650 case GrayAlphaQuantum:
00651 {
00652 image->type=GrayscaleType;
00653 if (image->depth == 1)
00654 image->type=BilevelType;
00655 break;
00656 }
00657 case CyanQuantum:
00658 case MagentaQuantum:
00659 case YellowQuantum:
00660 case BlackQuantum:
00661 case CMYKQuantum:
00662 case CMYKAQuantum:
00663 {
00664 image->type=ColorSeparationType;
00665 break;
00666 }
00667 default:
00668 {
00669 image->type=TrueColorType;
00670 break;
00671 }
00672 }
00673 }
00674
00675
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 MagickExport void SetQuantumPack(QuantumInfo *quantum_info,
00701 const MagickBooleanType pack)
00702 {
00703 assert(quantum_info != (QuantumInfo *) NULL);
00704 assert(quantum_info->signature == MagickSignature);
00705 quantum_info->pack=pack;
00706 }
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 MagickExport MagickBooleanType SetQuantumPad(const Image *image,
00737 QuantumInfo *quantum_info,const unsigned long pad)
00738 {
00739 assert(image != (Image *) NULL);
00740 assert(image->signature == MagickSignature);
00741 if (image->debug != MagickFalse)
00742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00743 assert(quantum_info != (QuantumInfo *) NULL);
00744 assert(quantum_info->signature == MagickSignature);
00745 quantum_info->pad=pad;
00746 return(SetQuantumDepth(image,quantum_info,quantum_info->depth));
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774 MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info,
00775 const MagickBooleanType min_is_white)
00776 {
00777 assert(quantum_info != (QuantumInfo *) NULL);
00778 assert(quantum_info->signature == MagickSignature);
00779 quantum_info->min_is_white=min_is_white;
00780 }
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807 MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info,
00808 const unsigned long quantum)
00809 {
00810 assert(quantum_info != (QuantumInfo *) NULL);
00811 assert(quantum_info->signature == MagickSignature);
00812 quantum_info->quantum=quantum;
00813 }
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839 MagickExport void SetQuantumScale(QuantumInfo *quantum_info,const double scale)
00840 {
00841 assert(quantum_info != (QuantumInfo *) NULL);
00842 assert(quantum_info->signature == MagickSignature);
00843 quantum_info->scale=scale;
00844 }