MagickCore  6.9.12-67
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
pixel-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 pixel private methods.
17 */
18 #ifndef MAGICKCORE_PIXEL_PRIVATE_H
19 #define MAGICKCORE_PIXEL_PRIVATE_H
20 
21 #include "magick/image.h"
22 #include "magick/color.h"
23 #include "magick/image-private.h"
24 #include "magick/memory_.h"
25 #include "magick/pixel-accessor.h"
26 #include "magick/quantum-private.h"
27 
28 #if defined(__cplusplus) || defined(c_plusplus)
29 extern "C" {
30 #endif
31 
32 static inline MagickBooleanType IsGrayPixel(const PixelPacket *pixel)
33 {
34 #if !defined(MAGICKCORE_HDRI_SUPPORT)
35  if ((GetPixelRed(pixel) == GetPixelGreen(pixel)) &&
36  (GetPixelGreen(pixel) == GetPixelBlue(pixel)))
37  return(MagickTrue);
38 #else
39  {
40  double
41  alpha,
42  beta;
43 
44  alpha=GetPixelRed(pixel)-(double) GetPixelGreen(pixel);
45  beta=GetPixelGreen(pixel)-(double) GetPixelBlue(pixel);
46  if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
47  return(MagickTrue);
48  }
49 #endif
50  return(MagickFalse);
51 }
52 
53 static inline MagickBooleanType IsMonochromePixel(const PixelPacket *pixel)
54 {
55 #if !defined(MAGICKCORE_HDRI_SUPPORT)
56  if (((GetPixelRed(pixel) == 0) ||
57  (GetPixelRed(pixel) == QuantumRange)) &&
58  (GetPixelRed(pixel) == GetPixelGreen(pixel)) &&
59  (GetPixelGreen(pixel) == GetPixelBlue(pixel)))
60  return(MagickTrue);
61 #else
62  {
63  double
64  alpha,
65  beta;
66 
67  alpha=GetPixelRed(pixel)-(double) GetPixelGreen(pixel);
68  beta=GetPixelGreen(pixel)-(double) GetPixelBlue(pixel);
69  if (((fabs((double) GetPixelRed(pixel)) <= MagickEpsilon) ||
70  (fabs((double) GetPixelRed(pixel)-QuantumRange) <= MagickEpsilon)) &&
71  (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
72  return(MagickTrue);
73  }
74 #endif
75  return(MagickFalse);
76 }
77 
78 static inline void SetMagickPixelPacket(const Image *image,
79  const PixelPacket *color,const IndexPacket *index,MagickPixelPacket *pixel)
80 {
81  pixel->red=(MagickRealType) GetPixelRed(color);
82  pixel->green=(MagickRealType) GetPixelGreen(color);
83  pixel->blue=(MagickRealType) GetPixelBlue(color);
84  pixel->opacity=(MagickRealType) GetPixelOpacity(color);
85  if ((image->colorspace == CMYKColorspace) &&
86  (index != (const IndexPacket *) NULL))
87  pixel->index=(MagickRealType) GetPixelIndex(index);
88 }
89 
90 static inline void SetMagickPixelPacketBias(const Image *image,
91  MagickPixelPacket *pixel)
92 {
93  /*
94  Obsoleted by MorphologyApply().
95  */
96  pixel->red=image->bias;
97  pixel->green=image->bias;
98  pixel->blue=image->bias;
99  pixel->opacity=image->bias;
100  pixel->index=image->bias;
101 }
102 
103 static inline void SetPixelPacket(const Image *image,
104  const MagickPixelPacket *pixel,PixelPacket *color,IndexPacket *index)
105 {
106  SetPixelRed(color,ClampToQuantum(pixel->red));
107  SetPixelGreen(color,ClampToQuantum(pixel->green));
108  SetPixelBlue(color,ClampToQuantum(pixel->blue));
109  SetPixelOpacity(color,ClampToQuantum(pixel->opacity));
110  if (index == (IndexPacket *) NULL)
111  return;
112  if ((image->colorspace == CMYKColorspace) ||
113  (image->storage_class == PseudoClass))
114  SetPixelIndex(index,ClampToQuantum(pixel->index));
115 }
116 
117 #if defined(__cplusplus) || defined(c_plusplus)
118 }
119 #endif
120 
121 #endif
Definition: image.h:152