MagickCore  6.9.10
Convert, Edit, Or Compose Bitmap Images
color-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2020 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"
26 #include "magick/pixel-accessor.h"
27 
28 #if defined(__cplusplus) || defined(c_plusplus)
29 extern "C" {
30 #endif
31 
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 
46  const PixelPacket *q)
47 {
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) &&
59  return(MagickTrue);
60  return(MagickFalse);
61 }
62 
64  const MagickPixelPacket *q)
65 {
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);
76  return(MagickTrue); /* no color component if pixel is transparent */
78  return(MagickFalse);
80  return(MagickFalse);
82  return(MagickFalse);
83  if (p->colorspace == CMYKColorspace)
84  {
86  return(MagickFalse);
87  }
88  return(MagickTrue);
89 }
90 
92 {
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 
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 
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 
119 {
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 
136  const MagickPixelPacket *pixel)
137 {
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
MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel)
Definition: pixel.c:351
MagickDoubleType MagickRealType
Definition: magick-type.h:125
#define MagickSQ1_2
Definition: image-private.h:32
MagickRealType opacity
Definition: pixel.h:122
static MagickRealType MagickPixelIntensity(const MagickPixelPacket *pixel)
Definition: color-private.h:101
ColorspaceType colorspace
Definition: pixel.h:110
static MagickRealType MagickPixelLuminance(const MagickPixelPacket *pixel)
Definition: color-private.h:135
Definition: colorspace.h:40
Quantum blue
Definition: pixel.h:143
static Quantum MagickPixelIntensityToQuantum(const MagickPixelPacket *pixel)
Definition: color-private.h:109
MagickPrivate MagickBooleanType IsIntensitySimilar(const Image *, const PixelPacket *, const PixelPacket *)
Definition: color.c:1884
static MagickRealType AbsolutePixelValue(const MagickRealType x)
Definition: pixel-accessor.h:106
static MagickBooleanType IsGrayColorspace(const ColorspaceType colorspace)
Definition: colorspace-private.h:96
Definition: pixel.h:131
Quantum green
Definition: pixel.h:143
#define MagickEpsilon
Definition: magick-type.h:115
static double GetFuzzyColorDistance(const Image *p, const Image *q)
Definition: color-private.h:35
static Quantum ClampToQuantum(const MagickRealType quantum)
Definition: quantum.h:88
Definition: image.h:152
MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
Definition: pixel.c:255
MagickBooleanType
Definition: magick-type.h:198
static MagickBooleanType IssRGBCompatibleColorspace(const ColorspaceType colorspace)
Definition: colorspace-private.h:122
Quantum red
Definition: pixel.h:143
Definition: pixel.h:104
Definition: magick-type.h:201
static MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel)
Definition: color-private.h:91
#define TransparentOpacity
Definition: image.h:28
Definition: colorspace.h:39
#define MagickMax(x, y)
Definition: image-private.h:26
MagickRealType red
Definition: pixel.h:122
MagickBooleanType matte
Definition: pixel.h:113
Definition: magick-type.h:200
unsigned short Quantum
Definition: magick-type.h:85
#define OpaqueOpacity
Definition: image.h:27
MagickRealType green
Definition: pixel.h:122
static MagickRealType MagickPixelLuma(const MagickPixelPacket *pixel)
Definition: color-private.h:118
MagickRealType blue
Definition: pixel.h:122
static MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p, const MagickPixelPacket *q)
Definition: color-private.h:63
#define MagickPrivate
Definition: method-attribute.h:81
double fuzz
Definition: image.h:218
static MagickBooleanType IsColorEqual(const PixelPacket *p, const PixelPacket *q)
Definition: color-private.h:45
MagickRealType index
Definition: pixel.h:122