MagickCore  6.8.5
color-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2013 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.
6  obtain a copy of the License at
7 
8  http://www.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 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24 
25 #include "magick/image.h"
26 #include "magick/color.h"
28 #include "magick/pixel-accessor.h"
29 
31  const PixelPacket *q)
32 {
34  blue,
35  green,
36  red;
37 
38  red=(MagickRealType) p->red;
39  green=(MagickRealType) p->green;
40  blue=(MagickRealType) p->blue;
41  if ((fabs(red-q->red) < MagickEpsilon) &&
42  (fabs(green-q->green) < MagickEpsilon) &&
43  (fabs(blue-q->blue) < MagickEpsilon))
44  return(MagickTrue);
45  return(MagickFalse);
46 }
47 
49  const MagickPixelPacket *q)
50 {
51  if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
52  (fabs(p->opacity-OpaqueOpacity) >= MagickEpsilon))
53  return(MagickFalse);
54  if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
55  (fabs(q->opacity-OpaqueOpacity)) >= MagickEpsilon)
56  return(MagickFalse);
57  if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
58  {
59  if (fabs(p->opacity-q->opacity) >= MagickEpsilon)
60  return(MagickFalse);
62  return(MagickTrue);
63  }
64  if (fabs(p->red-q->red) >= MagickEpsilon)
65  return(MagickFalse);
66  if (fabs(p->green-q->green) >= MagickEpsilon)
67  return(MagickFalse);
68  if (fabs(p->blue-q->blue) >= MagickEpsilon)
69  return(MagickFalse);
70  if ((p->colorspace == CMYKColorspace) &&
71  (fabs(p->index-q->index) >= MagickEpsilon))
72  return(MagickFalse);
73  return(MagickTrue);
74 }
75 
77 {
78  if ((pixel->colorspace != GRAYColorspace) &&
79  (pixel->colorspace != RGBColorspace))
80  return(MagickFalse);
81  if ((fabs(pixel->red-pixel->green) < MagickEpsilon) &&
82  (fabs(pixel->green-pixel->blue) < MagickEpsilon))
83  return(MagickTrue);
84  return(MagickFalse);
85 }
86 
88  const MagickPixelPacket *pixel)
89 {
91  blue,
92  green,
93  red;
94 
95  if (pixel->colorspace == GRAYColorspace)
96  return(pixel->red);
97  if (pixel->colorspace != sRGBColorspace)
98  return(0.298839*pixel->red+0.586811*pixel->green+0.114350*pixel->blue);
99  red=DecodePixelGamma(pixel->red);
100  green=DecodePixelGamma(pixel->green);
101  blue=DecodePixelGamma(pixel->blue);
102  return(0.298839*red+0.586811*green+0.114350*blue);
103 }
104 
106  const MagickPixelPacket *pixel)
107 {
109  blue,
110  green,
111  red;
112 
113  if (pixel->colorspace == GRAYColorspace)
114  return(ClampToQuantum(pixel->red));
115  if (pixel->colorspace != sRGBColorspace)
116  return(ClampToQuantum(0.298839*pixel->red+0.586811*pixel->green+
117  0.114350*pixel->blue));
118  red=DecodePixelGamma(pixel->red);
119  green=DecodePixelGamma(pixel->green);
120  blue=DecodePixelGamma(pixel->blue);
121  return(ClampToQuantum(0.298839*red+0.586811*green+0.114350*blue));
122 }
123 
125  const MagickPixelPacket *pixel)
126 {
128  blue,
129  green,
130  red;
131 
132  if (pixel->colorspace == GRAYColorspace)
133  return(pixel->red);
134  if (pixel->colorspace != sRGBColorspace)
135  return(0.21267f*pixel->red+0.71516f*pixel->green+0.07217f*pixel->blue);
136  red=DecodePixelGamma(pixel->red);
137  green=DecodePixelGamma(pixel->green);
138  blue=DecodePixelGamma(pixel->blue);
139  return(0.21267f*red+0.71516f*green+0.07217f*blue);
140 }
141 
142 #if defined(__cplusplus) || defined(c_plusplus)
143 }
144 #endif
145 
146 #endif