colorspace-private.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004 
00005   You may not use this file except in compliance with the License.  You may
00006   obtain a copy of the License at
00007 
00008     https://imagemagick.org/script/license.php
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore image colorspace private methods.
00017 */
00018 #ifndef MAGICKCORE_COLORSPACE_PRIVATE_H
00019 #define MAGICKCORE_COLORSPACE_PRIVATE_H
00020 
00021 #include "magick/image.h"
00022 #include "magick/image-private.h"
00023 #include "magick/pixel.h"
00024 #include "magick/pixel-accessor.h"
00025 
00026 #if defined(__cplusplus) || defined(c_plusplus)
00027 extern "C" {
00028 #endif
00029 
00030 static inline void ConvertCMYKToRGB(MagickPixelPacket *pixel)
00031 {
00032   pixel->red=((QuantumRange-(QuantumScale*pixel->red*(QuantumRange-
00033     pixel->index)+pixel->index)));
00034   pixel->green=((QuantumRange-(QuantumScale*pixel->green*(QuantumRange-
00035     pixel->index)+pixel->index)));
00036   pixel->blue=((QuantumRange-(QuantumScale*pixel->blue*(QuantumRange-
00037     pixel->index)+pixel->index)));
00038 }
00039 
00040 static inline void ConvertRGBToCMYK(MagickPixelPacket *pixel)
00041 {
00042   MagickRealType
00043     black,
00044     blue,
00045     cyan,
00046     green,
00047     magenta,
00048     red,
00049     yellow;
00050 
00051   if (pixel->colorspace != sRGBColorspace)
00052     {
00053       red=QuantumScale*pixel->red;
00054       green=QuantumScale*pixel->green;
00055       blue=QuantumScale*pixel->blue;
00056     }
00057   else
00058     {
00059       red=QuantumScale*DecodePixelGamma(pixel->red);
00060       green=QuantumScale*DecodePixelGamma(pixel->green);
00061       blue=QuantumScale*DecodePixelGamma(pixel->blue);
00062     }
00063   if ((fabs((double) red) < MagickEpsilon) &&
00064       (fabs((double) green) < MagickEpsilon) &&
00065       (fabs((double) blue) < MagickEpsilon))
00066     {
00067       pixel->index=(MagickRealType) QuantumRange;
00068       return;
00069     }
00070   cyan=(MagickRealType) (1.0-red);
00071   magenta=(MagickRealType) (1.0-green);
00072   yellow=(MagickRealType) (1.0-blue);
00073   black=cyan;
00074   if (magenta < black)
00075     black=magenta;
00076   if (yellow < black)
00077     black=yellow;
00078   cyan=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(cyan-black));
00079   magenta=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(magenta-black));
00080   yellow=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(yellow-black));
00081   pixel->colorspace=CMYKColorspace;
00082   pixel->red=QuantumRange*cyan;
00083   pixel->green=QuantumRange*magenta;
00084   pixel->blue=QuantumRange*yellow;
00085   pixel->index=QuantumRange*black;
00086 }
00087 
00088 static inline MagickBooleanType IsCMYKColorspace(
00089   const ColorspaceType colorspace)
00090 {
00091   if (colorspace == CMYKColorspace)
00092     return(MagickTrue);
00093   return(MagickFalse);
00094 }
00095 
00096 static inline MagickBooleanType IsGrayColorspace(
00097   const ColorspaceType colorspace)
00098 {
00099   if ((colorspace == LinearGRAYColorspace) || (colorspace == GRAYColorspace) ||
00100       (colorspace == Rec601LumaColorspace) ||
00101       (colorspace == Rec709LumaColorspace))
00102     return(MagickTrue);
00103   return(MagickFalse);
00104 }
00105 
00106 static inline MagickBooleanType IsHueCompatibleColorspace(
00107   const ColorspaceType colorspace)
00108 {
00109   if ((colorspace == HCLColorspace) || (colorspace == HCLpColorspace) ||
00110       (colorspace == HSBColorspace) || (colorspace == HSIColorspace) ||
00111       (colorspace == HSLColorspace) || (colorspace == HSVColorspace))
00112     return(MagickTrue);
00113   return(MagickFalse);
00114 }
00115 
00116 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
00117 {
00118   if ((colorspace == RGBColorspace) || (colorspace == scRGBColorspace) ||
00119       (colorspace == LinearGRAYColorspace))
00120     return(MagickTrue);
00121   return(MagickFalse);
00122 }
00123 
00124 static inline MagickBooleanType IssRGBColorspace(
00125   const ColorspaceType colorspace)
00126 {
00127   if ((colorspace == sRGBColorspace) || (colorspace == TransparentColorspace))
00128     return(MagickTrue);
00129   return(MagickFalse);
00130 }
00131 
00132 static inline MagickBooleanType IssRGBCompatibleColorspace(
00133   const ColorspaceType colorspace)
00134 {
00135   if ((colorspace == sRGBColorspace) || (colorspace == RGBColorspace) ||
00136       (colorspace == scRGBColorspace) || (colorspace == TransparentColorspace) ||
00137       (colorspace == GRAYColorspace) || (colorspace == LinearGRAYColorspace))
00138     return(MagickTrue);
00139   return(MagickFalse);
00140 }
00141 
00142 #if defined(__cplusplus) || defined(c_plusplus)
00143 }
00144 #endif
00145 
00146 #endif

Generated on 15 Jun 2020 for MagickCore by  doxygen 1.6.1