MagickCore  6.9.12-67
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
color-private.h
1 /*
2  Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore image color methods.
17 */
18 #ifndef MAGICKCORE_COLOR_PRIVATE_H
19 #define MAGICKCORE_COLOR_PRIVATE_H
20 
21 #include "magick/image.h"
22 #include "magick/image-private.h"
23 #include "magick/color.h"
24 #include "magick/colorspace-private.h"
25 #include "magick/exception-private.h"
26 #include "magick/pixel-accessor.h"
27 
28 #if defined(__cplusplus) || defined(c_plusplus)
29 extern "C" {
30 #endif
31 
32 extern MagickPrivate MagickBooleanType
33  IsIntensitySimilar(const Image *,const PixelPacket *,const PixelPacket *);
34 
35 static inline double GetFuzzyColorDistance(const Image *p,const Image *q)
36 {
37  double
38  fuzz;
39 
40  fuzz=(double) MagickMax(MagickMax(p->fuzz,q->fuzz),(MagickRealType)
41  MagickSQ1_2);
42  return(fuzz*fuzz);
43 }
44 
45 static inline MagickBooleanType IsColorEqual(const PixelPacket *p,
46  const PixelPacket *q)
47 {
48  MagickRealType
49  blue,
50  green,
51  red;
52 
53  red=(MagickRealType) p->red;
54  green=(MagickRealType) p->green;
55  blue=(MagickRealType) p->blue;
56  if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
57  (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
58  (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
59  return(MagickTrue);
60  return(MagickFalse);
61 }
62 
63 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p,
64  const MagickPixelPacket *q)
65 {
66  MagickRealType
67  alpha,
68  beta;
69 
70  alpha=p->matte == MagickFalse ? OpaqueOpacity : p->opacity;
71  beta=q->matte == MagickFalse ? OpaqueOpacity : q->opacity;
72  if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
73  return(MagickFalse);
74  if ((AbsolutePixelValue(alpha-TransparentOpacity) < MagickEpsilon) ||
75  (AbsolutePixelValue(beta-TransparentOpacity) < MagickEpsilon))
76  return(MagickTrue); /* no color component if pixel is transparent */
77  if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
78  return(MagickFalse);
79  if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
80  return(MagickFalse);
81  if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
82  return(MagickFalse);
83  if (p->colorspace == CMYKColorspace)
84  {
85  if (AbsolutePixelValue(p->index-q->index) >= MagickEpsilon)
86  return(MagickFalse);
87  }
88  return(MagickTrue);
89 }
90 
91 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel)
92 {
93  if (IssRGBCompatibleColorspace(pixel->colorspace) == MagickFalse)
94  return(MagickFalse);
95  if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
96  (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
97  return(MagickTrue);
98  return(MagickFalse);
99 }
100 
101 static inline MagickRealType MagickPixelIntensity(
102  const MagickPixelPacket *pixel)
103 {
104  if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
105  return(pixel->red);
106  return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
107 }
108 
109 static inline Quantum MagickPixelIntensityToQuantum(
110  const MagickPixelPacket *pixel)
111 {
112  if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
113  return(ClampToQuantum(pixel->red));
114  return(ClampToQuantum(0.212656*pixel->red+0.715158*pixel->green+
115  0.072186*pixel->blue));
116 }
117 
118 static inline MagickRealType MagickPixelLuma(const MagickPixelPacket *pixel)
119 {
120  MagickRealType
121  blue,
122  green,
123  red;
124 
125  if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
126  return(pixel->red);
127  if (pixel->colorspace == sRGBColorspace)
128  return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
129  red=EncodePixelGamma(pixel->red);
130  green=EncodePixelGamma(pixel->green);
131  blue=EncodePixelGamma(pixel->blue);
132  return(0.212656*red+0.715158*green+0.072186*blue);
133 }
134 
135 static inline MagickRealType MagickPixelLuminance(
136  const MagickPixelPacket *pixel)
137 {
138  MagickRealType
139  blue,
140  green,
141  red;
142 
143  if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
144  return(pixel->red);
145  if (pixel->colorspace != sRGBColorspace)
146  return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
147  red=DecodePixelGamma(pixel->red);
148  green=DecodePixelGamma(pixel->green);
149  blue=DecodePixelGamma(pixel->blue);
150  return(0.212656*red+0.715158*green+0.072186*blue);
151 }
152 
153 #if defined(__cplusplus) || defined(c_plusplus)
154 }
155 #endif
156 
157 #endif
Definition: image.h:152