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
|
/*
Copyright @ 1999 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
https://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.
MagickCore pixel accessor methods.
*/
#ifndef MAGICKCORE_PIXEL_ACCESSOR_H
#define MAGICKCORE_PIXEL_ACCESSOR_H
#include "MagickCore/cache.h"
#include "MagickCore/cache-view.h"
#include "MagickCore/color.h"
#include "MagickCore/colorspace.h"
#include "MagickCore/gem.h"
#include "MagickCore/image.h"
#include "MagickCore/memory_.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#undef index
static inline Quantum ClampPixel(const MagickRealType pixel)
{
if (pixel < 0.0)
return((Quantum) 0);
if (pixel >= (MagickRealType) QuantumRange)
return((Quantum) QuantumRange);
#if !defined(MAGICKCORE_HDRI_SUPPORT)
return((Quantum) (pixel+0.5f));
#else
return((Quantum) pixel);
#endif
}
static inline Quantum GetPixela(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[aPixelChannel].offset]);
}
static inline Quantum GetPixelAlpha(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
return(OpaqueAlpha);
return(pixel[image->channel_map[AlphaPixelChannel].offset]);
}
static inline PixelTrait GetPixelAlphaTraits(const Image *magick_restrict image)
{
return(image->channel_map[AlphaPixelChannel].traits);
}
static inline Quantum GetPixelb(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[bPixelChannel].offset]);
}
static inline Quantum GetPixelBlack(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
return((Quantum) 0);
return(pixel[image->channel_map[BlackPixelChannel].offset]);
}
static inline PixelTrait GetPixelBlackTraits(const Image *magick_restrict image)
{
return(image->channel_map[BlackPixelChannel].traits);
}
static inline Quantum GetPixelBlue(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[BluePixelChannel].offset]);
}
static inline PixelTrait GetPixelBlueTraits(const Image *magick_restrict image)
{
return(image->channel_map[BluePixelChannel].traits);
}
static inline Quantum GetPixelCb(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[CbPixelChannel].offset]);
}
static inline PixelTrait GetPixelCbTraits(const Image *magick_restrict image)
{
return(image->channel_map[CbPixelChannel].traits);
}
static inline Quantum GetPixelChannel(const Image *magick_restrict image,
const PixelChannel channel,const Quantum *magick_restrict pixel)
{
if ((size_t) channel >= MaxPixelChannels)
return((Quantum) 0);
if (image->channel_map[channel].traits == UndefinedPixelTrait)
return((Quantum) 0);
return(pixel[image->channel_map[channel].offset]);
}
static inline PixelChannel GetPixelChannelChannel(
const Image *magick_restrict image,const ssize_t offset)
{
if ((offset < 0) || (offset >= MaxPixelChannels))
return(UndefinedPixelChannel);
return(image->channel_map[offset].channel);
}
static inline ssize_t GetPixelChannelOffset(const Image *magick_restrict image,
const PixelChannel channel)
{
return(image->channel_map[channel].offset);
}
static inline PixelTrait GetPixelChannelTraits(
const Image *magick_restrict image,const PixelChannel channel)
{
if ((size_t) channel >= MaxPixelChannels)
return(UndefinedPixelTrait);
return(image->channel_map[channel].traits);
}
static inline size_t GetPixelChannels(const Image *magick_restrict image)
{
return(image->number_channels);
}
static inline Quantum GetPixelCompositeMask(
const Image *magick_restrict image,const Quantum *magick_restrict pixel)
{
if (image->channel_map[CompositeMaskPixelChannel].traits == UndefinedPixelTrait)
return((Quantum) QuantumRange);
return(pixel[image->channel_map[CompositeMaskPixelChannel].offset]);
}
static inline PixelTrait GetPixelCompositeMaskTraits(
const Image *magick_restrict image)
{
return(image->channel_map[CompositeMaskPixelChannel].traits);
}
static inline Quantum GetPixelCr(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[CrPixelChannel].offset]);
}
static inline PixelTrait GetPixelCrTraits(const Image *magick_restrict image)
{
return(image->channel_map[CrPixelChannel].traits);
}
static inline Quantum GetPixelCyan(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[CyanPixelChannel].offset]);
}
static inline PixelTrait GetPixelCyanTraits(const Image *magick_restrict image)
{
return(image->channel_map[CyanPixelChannel].traits);
}
static inline Quantum GetPixelGray(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[GrayPixelChannel].offset]);
}
static inline PixelTrait GetPixelGrayTraits(const Image *magick_restrict image)
{
return(image->channel_map[GrayPixelChannel].traits);
}
static inline Quantum GetPixelGreen(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[GreenPixelChannel].offset]);
}
static inline PixelTrait GetPixelGreenTraits(const Image *magick_restrict image)
{
return(image->channel_map[GreenPixelChannel].traits);
}
static inline Quantum GetPixelIndex(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
return((Quantum) 0);
return(pixel[image->channel_map[IndexPixelChannel].offset]);
}
static inline PixelTrait GetPixelIndexTraits(const Image *magick_restrict image)
{
return(image->channel_map[IndexPixelChannel].traits);
}
static inline MagickRealType GetPixelInfoChannel(
const PixelInfo *magick_restrict pixel_info,const PixelChannel channel)
{
switch (channel)
{
case RedPixelChannel: return(pixel_info->red);
case GreenPixelChannel: return(pixel_info->green);
case BluePixelChannel: return(pixel_info->blue);
case BlackPixelChannel:
{
if (pixel_info->colorspace != CMYKColorspace)
return(0.0);
return(pixel_info->black);
}
case AlphaPixelChannel:
{
if (pixel_info->alpha_trait == UndefinedPixelTrait)
return(OpaqueAlpha);
return(pixel_info->alpha);
}
case IndexPixelChannel: return(pixel_info->index);
default: break;
}
return((MagickRealType) 0.0);
}
static inline double PerceptibleReciprocal(const double x)
{
double
sign;
/*
Return 1/x where x is perceptible (not unlimited or infinitesimal).
*/
sign=x < 0.0 ? -1.0 : 1.0;
if ((sign*x) >= MagickEpsilon)
return(1.0/x);
return(sign/MagickEpsilon);
}
static inline MagickRealType GetPixelInfoLuma(
const PixelInfo *magick_restrict pixel)
{
MagickRealType
intensity;
if (pixel->colorspace == sRGBColorspace)
{
intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
0.072186*pixel->blue);
return(intensity);
}
intensity=(MagickRealType) (0.212656*EncodePixelGamma(pixel->red)+
0.715158*EncodePixelGamma(pixel->green)+
0.072186*EncodePixelGamma(pixel->blue));
return(intensity);
}
static inline MagickRealType GetPixelInfoLuminance(
const PixelInfo *magick_restrict pixel)
{
MagickRealType
intensity;
if (pixel->colorspace != sRGBColorspace)
{
intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
0.072186*pixel->blue);
return(intensity);
}
intensity=(MagickRealType) (0.212656*DecodePixelGamma(pixel->red)+
0.715158*DecodePixelGamma(pixel->green)+
0.072186*DecodePixelGamma(pixel->blue));
return(intensity);
}
static inline Quantum GetPixelL(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[LPixelChannel].offset]);
}
static inline ssize_t GetPixelLabel(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
}
static inline MagickRealType GetPixelLuma(
const Image *magick_restrict image,const Quantum *magick_restrict pixel)
{
MagickRealType
intensity;
intensity=
0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
return(intensity);
}
static inline MagickRealType GetPixelLuminance(
const Image *magick_restrict image,const Quantum *magick_restrict pixel)
{
MagickRealType
intensity;
if (image->colorspace != sRGBColorspace)
{
intensity=
0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
return(intensity);
}
intensity=(MagickRealType) (0.212656*DecodePixelGamma((MagickRealType)
pixel[image->channel_map[RedPixelChannel].offset])+0.715158*
DecodePixelGamma((MagickRealType)
pixel[image->channel_map[GreenPixelChannel].offset])+0.072186*
DecodePixelGamma((MagickRealType)
pixel[image->channel_map[BluePixelChannel].offset]));
return(intensity);
}
static inline Quantum GetPixelMagenta(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[MagentaPixelChannel].offset]);
}
static inline PixelTrait GetPixelMagentaTraits(
const Image *magick_restrict image)
{
return(image->channel_map[MagentaPixelChannel].traits);
}
static inline Quantum GetPixelMeta(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
return(OpaqueAlpha);
return(pixel[image->channel_map[MetaPixelChannels].offset]);
}
static inline PixelTrait GetPixelMetaTraits(const Image *magick_restrict image)
{
return(image->channel_map[MetaPixelChannels].traits);
}
static inline Quantum GetPixelReadMask(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
return((Quantum) QuantumRange);
return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
}
static inline void GetPixelInfoRGBA(const Quantum red,const Quantum green,
const Quantum blue,const Quantum alpha,PixelInfo *magick_restrict pixel)
{
GetPixelInfo((Image *) NULL,pixel);
pixel->red=red;
pixel->green=green;
pixel->blue=blue;
pixel->alpha=alpha;
}
static inline Quantum GetPixelWriteMask(
const Image *magick_restrict image,const Quantum *magick_restrict pixel)
{
if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
return((Quantum) QuantumRange);
return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
}
static inline PixelTrait GetPixelReadMaskTraits(
const Image *magick_restrict image)
{
return(image->channel_map[ReadMaskPixelChannel].traits);
}
static inline size_t GetPixelMetaChannels(const Image *magick_restrict image)
{
return(image->number_meta_channels);
}
static inline size_t GetPixelMetacontentExtent(
const Image *magick_restrict image)
{
return(image->metacontent_extent);
}
static inline Quantum GetPixelOpacity(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
return(QuantumRange-OpaqueAlpha);
return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
}
static inline Quantum GetPixelRed(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[RedPixelChannel].offset]);
}
static inline PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
{
return(image->channel_map[RedPixelChannel].traits);
}
static inline void GetPixelInfoPixel(const Image *magick_restrict image,
const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
{
(void) ResetMagickMemory(pixel_info,0,sizeof(*pixel_info));
pixel_info->storage_class=DirectClass;
pixel_info->colorspace=sRGBColorspace;
pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
pixel_info->alpha_trait=UndefinedPixelTrait;
pixel_info->alpha=(MagickRealType) OpaqueAlpha;
if (image != (Image *) NULL)
{
pixel_info->storage_class=image->storage_class;
pixel_info->colorspace=image->colorspace;
pixel_info->fuzz=image->fuzz;
pixel_info->depth=image->depth;
pixel_info->alpha_trait=image->alpha_trait;
if (pixel != (Quantum *) NULL)
{
pixel_info->red=(MagickRealType)
pixel[image->channel_map[RedPixelChannel].offset];
pixel_info->green=(MagickRealType)
pixel[image->channel_map[GreenPixelChannel].offset];
pixel_info->blue=(MagickRealType)
pixel[image->channel_map[BluePixelChannel].offset];
if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
pixel_info->black=(MagickRealType)
pixel[image->channel_map[BlackPixelChannel].offset];
if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
pixel_info->alpha=(MagickRealType)
pixel[image->channel_map[AlphaPixelChannel].offset];
if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
pixel_info->index=(MagickRealType)
pixel[image->channel_map[IndexPixelChannel].offset];
}
}
}
static inline PixelTrait GetPixelTraits(const Image *magick_restrict image,
const PixelChannel channel)
{
if ((size_t) channel >= MaxPixelChannels)
return(UndefinedPixelTrait);
return(image->channel_map[channel].traits);
}
static inline PixelTrait GetPixelWriteMaskTraits(
const Image *magick_restrict image)
{
return(image->channel_map[WriteMaskPixelChannel].traits);
}
static inline Quantum GetPixelY(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[YPixelChannel].offset]);
}
static inline PixelTrait GetPixelYTraits(const Image *magick_restrict image)
{
return(image->channel_map[YPixelChannel].traits);
}
static inline Quantum GetPixelYellow(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
return(pixel[image->channel_map[YellowPixelChannel].offset]);
}
static inline PixelTrait GetPixelYellowTraits(
const Image *magick_restrict image)
{
return(image->channel_map[YellowPixelChannel].traits);
}
static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
{
return(x < 0.0 ? -x : x);
}
static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
const QuantumAny range)
{
Quantum
quantum;
if (range == 0)
return(MagickTrue);
#if !defined(MAGICKCORE_HDRI_SUPPORT)
quantum=(Quantum) (((double) QuantumRange*((QuantumAny) (((double) range*
pixel)/(double) QuantumRange+0.5)))/(double) range+0.5);
#else
quantum=(Quantum) (((double) QuantumRange*((QuantumAny) (((double) range*
(double) pixel)/(double) QuantumRange+0.5)))/(double) range);
#endif
return(pixel == quantum ? MagickTrue : MagickFalse);
}
static inline MagickBooleanType IsPixelEquivalent(
const Image *magick_restrict image,const Quantum *magick_restrict p,
const PixelInfo *magick_restrict q)
{
MagickRealType
alpha,
beta,
color;
color=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
alpha=image->alpha_trait == UndefinedPixelTrait ? (MagickRealType)
OpaqueAlpha : color;
beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
q->alpha;
if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
return(MagickFalse);
if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
(AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
return(MagickTrue); /* no color component if pixel is transparent */
color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
return(MagickFalse);
color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
return(MagickFalse);
color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
return(MagickFalse);
if (image->colorspace == CMYKColorspace)
{
color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
return(MagickFalse);
}
return(MagickTrue);
}
static inline MagickBooleanType IsPixelGray(const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
{
MagickRealType
green_blue,
red_green;
red_green=
(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
green_blue=
(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
(AbsolutePixelValue(green_blue) < MagickEpsilon))
return(MagickTrue);
return(MagickFalse);
}
static inline MagickBooleanType IsPixelInfoEquivalent(
const PixelInfo *magick_restrict p,const PixelInfo *magick_restrict q)
{
MagickRealType
alpha,
beta;
alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
p->alpha;
beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
q->alpha;
if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
return(MagickFalse);
if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
(AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
return(MagickTrue); /* no color component if pixel is transparent */
if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
return(MagickFalse);
if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
return(MagickFalse);
if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
return(MagickFalse);
if (p->colorspace == CMYKColorspace)
{
if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
return(MagickFalse);
}
return(MagickTrue);
}
static inline MagickBooleanType IsPixelMonochrome(
const Image *magick_restrict image,const Quantum *magick_restrict pixel)
{
MagickRealType
green_blue,
red,
red_green;
red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
(AbsolutePixelValue(red-(MagickRealType) QuantumRange) >= MagickEpsilon))
return(MagickFalse);
red_green=
(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
green_blue=
(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
(AbsolutePixelValue(green_blue) < MagickEpsilon))
return(MagickTrue);
return(MagickFalse);
}
static inline MagickBooleanType IsPixelInfoGray(
const PixelInfo *magick_restrict pixel)
{
if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
(AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
return(MagickTrue);
return(MagickFalse);
}
static inline MagickBooleanType IsPixelInfoMonochrome(
const PixelInfo *magick_restrict pixel_info)
{
MagickRealType
green_blue,
red_green;
if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
(AbsolutePixelValue(pixel_info->red-(MagickRealType) QuantumRange) >= MagickEpsilon))
return(MagickFalse);
red_green=pixel_info->red-pixel_info->green;
green_blue=pixel_info->green-pixel_info->blue;
if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
(AbsolutePixelValue(green_blue) < MagickEpsilon))
return(MagickTrue);
return(MagickFalse);
}
static inline void SetPixela(const Image *magick_restrict image,
const Quantum a,Quantum *magick_restrict pixel)
{
if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[aPixelChannel].offset]=a;
}
static inline void SetPixelAlpha(const Image *magick_restrict image,
const Quantum alpha,Quantum *magick_restrict pixel)
{
if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
}
static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
{
image->channel_map[AlphaPixelChannel].traits=traits;
}
static inline void SetPixelb(const Image *magick_restrict image,
const Quantum b,Quantum *magick_restrict pixel)
{
if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[bPixelChannel].offset]=b;
}
static inline void SetPixelBackgroundColor(const Image *magick_restrict image,
Quantum *magick_restrict pixel)
{
ssize_t
i;
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
pixel[i]=(Quantum) 0;
pixel[image->channel_map[RedPixelChannel].offset]=
ClampToQuantum(image->background_color.red);
pixel[image->channel_map[GreenPixelChannel].offset]=
ClampToQuantum(image->background_color.green);
pixel[image->channel_map[BluePixelChannel].offset]=
ClampToQuantum(image->background_color.blue);
if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[BlackPixelChannel].offset]=
ClampToQuantum(image->background_color.black);
if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[AlphaPixelChannel].offset]=
image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
ClampToQuantum(image->background_color.alpha);
}
static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
Quantum *magick_restrict pixel) magick_attribute((deprecated));
static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
Quantum *magick_restrict pixel)
{
SetPixelBackgroundColor(image,pixel);
}
static inline void SetPixelBlack(const Image *magick_restrict image,
const Quantum black,Quantum *magick_restrict pixel)
{
if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[BlackPixelChannel].offset]=black;
}
static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
{
image->channel_map[BlackPixelChannel].traits=traits;
}
static inline void SetPixelBlue(const Image *magick_restrict image,
const Quantum blue,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[BluePixelChannel].offset]=blue;
}
static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
{
image->channel_map[BluePixelChannel].traits=traits;
}
static inline void SetPixelCb(const Image *magick_restrict image,
const Quantum cb,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[CbPixelChannel].offset]=cb;
}
static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
{
image->channel_map[CbPixelChannel].traits=traits;
}
static inline void SetPixelChannel(const Image *magick_restrict image,
const PixelChannel channel,const Quantum quantum,
Quantum *magick_restrict pixel)
{
if ((size_t) channel >= MaxPixelChannels)
return;
if (image->channel_map[channel].traits != UndefinedPixelTrait)
pixel[image->channel_map[channel].offset]=quantum;
}
static inline void SetPixelChannelAttributes(
const Image *magick_restrict image,const PixelChannel channel,
const PixelTrait traits,const ssize_t offset)
{
if ((offset < 0) || (offset >= MaxPixelChannels))
return;
if ((size_t) channel >= MaxPixelChannels)
return;
image->channel_map[offset].channel=channel;
image->channel_map[channel].offset=offset;
image->channel_map[channel].traits=traits;
}
static inline void SetPixelChannelChannel(const Image *magick_restrict image,
const PixelChannel channel,const ssize_t offset)
{
if ((offset < 0) || (offset >= MaxPixelChannels))
return;
if ((size_t) channel >= MaxPixelChannels)
return;
image->channel_map[offset].channel=channel;
image->channel_map[channel].offset=offset;
}
static inline void SetPixelChannels(Image *image,const size_t number_channels)
{
image->number_channels=number_channels;
}
static inline void SetPixelChannelTraits(Image *image,
const PixelChannel channel,const PixelTrait traits)
{
if ((size_t) channel >= MaxPixelChannels)
return;
image->channel_map[channel].traits=traits;
}
static inline void SetPixelCompositeMask(const Image *magick_restrict image,
const Quantum mask,Quantum *magick_restrict pixel)
{
if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
}
static inline void SetPixelCr(const Image *magick_restrict image,
const Quantum cr,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[CrPixelChannel].offset]=cr;
}
static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
{
image->channel_map[CrPixelChannel].traits=traits;
}
static inline void SetPixelCyan(const Image *magick_restrict image,
const Quantum cyan,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
}
static inline void SetPixelGray(const Image *magick_restrict image,
const Quantum gray,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[GrayPixelChannel].offset]=gray;
}
static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
{
image->channel_map[GrayPixelChannel].traits=traits;
}
static inline void SetPixelGreen(const Image *magick_restrict image,
const Quantum green,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[GreenPixelChannel].offset]=green;
}
static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
{
image->channel_map[GreenPixelChannel].traits=traits;
}
static inline void SetPixelIndex(const Image *magick_restrict image,
const Quantum index,Quantum *magick_restrict pixel)
{
if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[IndexPixelChannel].offset]=index;
}
static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
{
image->channel_map[IndexPixelChannel].traits=traits;
}
static inline void SetPixelViaPixelInfo(const Image *magick_restrict image,
const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[RedPixelChannel].offset]=
ClampToQuantum(pixel_info->red);
pixel[image->channel_map[GreenPixelChannel].offset]=
ClampToQuantum(pixel_info->green);
pixel[image->channel_map[BluePixelChannel].offset]=
ClampToQuantum(pixel_info->blue);
if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[BlackPixelChannel].offset]=
ClampToQuantum(pixel_info->black);
if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[AlphaPixelChannel].offset]=
pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
ClampToQuantum(pixel_info->alpha);
}
static inline void SetPixelL(const Image *magick_restrict image,const Quantum L,
Quantum *magick_restrict pixel)
{
if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[LPixelChannel].offset]=L;
}
static inline void SetPixelMagenta(const Image *magick_restrict image,
const Quantum magenta,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
}
static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
{
image->channel_map[MagentaPixelChannel].traits=traits;
}
static inline void SetPixelMeta(const Image *magick_restrict image,
const Quantum red,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[MetaPixelChannels].offset]=red;
}
static inline void SetPixelMetaTraits(Image *image,const PixelTrait traits)
{
image->channel_map[MetaPixelChannels].traits=traits;
}
static inline void SetPixelReadMask(const Image *magick_restrict image,
const Quantum mask,Quantum *magick_restrict pixel)
{
if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
}
static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
{
image->metacontent_extent=extent;
}
static inline void SetPixelOpacity(const Image *magick_restrict image,
const Quantum alpha,Quantum *magick_restrict pixel)
{
if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
}
static inline void SetPixelRed(const Image *magick_restrict image,
const Quantum red,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[RedPixelChannel].offset]=red;
}
static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
{
image->channel_map[RedPixelChannel].traits=traits;
}
static inline void SetPixelWriteMask(const Image *magick_restrict image,
const Quantum mask,Quantum *magick_restrict pixel)
{
if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
}
static inline void SetPixelYellow(const Image *magick_restrict image,
const Quantum yellow,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
}
static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
{
image->channel_map[YellowPixelChannel].traits=traits;
}
static inline void SetPixelY(const Image *magick_restrict image,
const Quantum y,Quantum *magick_restrict pixel)
{
pixel[image->channel_map[YPixelChannel].offset]=y;
}
static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
{
image->channel_map[YPixelChannel].traits=traits;
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif
|