source: ImageMagick/branches/ImageMagick-6/magick/pixel-private.h @ 10122

Revision 10122, 3.8 KB checked in by cristy, 6 months ago (diff)
Line 
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 pixel private methods.
17*/
18#ifndef _MAGICKCORE_PIXEL_PRIVATE_H
19#define _MAGICKCORE_PIXEL_PRIVATE_H
20
21#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
25#include "magick/image.h"
26#include "magick/color.h"
27#include "magick/image-private.h"
28#include "magick/memory_.h"
29#include "magick/pixel-accessor.h"
30#include "magick/quantum-private.h"
31
32static 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
53static 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
78static inline double PerceptibleReciprocal(const double x)
79{
80  double
81    sign;
82
83  /*
84    Return 1/x where x is perceptible (not unlimited or infinitesimal).
85  */
86  sign=x < 0.0 ? -1.0 : 1.0;
87  if ((sign*x) >= MagickEpsilon)
88    return(1.0/x);
89  return(sign/MagickEpsilon);
90}
91
92static inline void SetMagickPixelPacket(const Image *image,
93  const PixelPacket *color,const IndexPacket *index,MagickPixelPacket *pixel)
94{
95  pixel->red=(MagickRealType) GetPixelRed(color);
96  pixel->green=(MagickRealType) GetPixelGreen(color);
97  pixel->blue=(MagickRealType) GetPixelBlue(color);
98  pixel->opacity=(MagickRealType) GetPixelOpacity(color);
99  if ((image->colorspace == CMYKColorspace) &&
100      (index != (const IndexPacket *) NULL))
101    pixel->index=(MagickRealType) GetPixelIndex(index);
102}
103
104static inline void SetMagickPixelPacketBias(const Image *image,
105  MagickPixelPacket *pixel)
106{
107  /*
108    Obsoleted by MorphologyApply().
109  */
110  pixel->red=image->bias;
111  pixel->green=image->bias;
112  pixel->blue=image->bias;
113  pixel->opacity=image->bias;
114  pixel->index=image->bias;
115}
116
117static inline void SetPixelPacket(const Image *image,
118  const MagickPixelPacket *pixel,PixelPacket *color,IndexPacket *index)
119{
120  SetPixelRed(color,ClampToQuantum(pixel->red));
121  SetPixelGreen(color,ClampToQuantum(pixel->green));
122  SetPixelBlue(color,ClampToQuantum(pixel->blue));
123  SetPixelOpacity(color,ClampToQuantum(pixel->opacity));
124  if ((image->colorspace == CMYKColorspace) ||
125      (image->storage_class == PseudoClass))
126    SetPixelIndex(index,ClampToQuantum(pixel->index));
127}
128
129#if defined(__cplusplus) || defined(c_plusplus)
130}
131#endif
132
133#endif
Note: See TracBrowser for help on using the repository browser.