00001 /* 00002 Copyright 1999-2019 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 "MagickCore/image.h" 00022 #include "MagickCore/image-private.h" 00023 #include "MagickCore/pixel.h" 00024 #include "MagickCore/pixel-accessor.h" 00025 00026 #if defined(__cplusplus) || defined(c_plusplus) 00027 extern "C" { 00028 #endif 00029 00030 static inline void ConvertCMYKToRGB(PixelInfo *pixel) 00031 { 00032 pixel->red=((QuantumRange-(QuantumScale*pixel->red*(QuantumRange- 00033 pixel->black)+pixel->black))); 00034 pixel->green=((QuantumRange-(QuantumScale*pixel->green*(QuantumRange- 00035 pixel->black)+pixel->black))); 00036 pixel->blue=((QuantumRange-(QuantumScale*pixel->blue*(QuantumRange- 00037 pixel->black)+pixel->black))); 00038 } 00039 00040 static inline void ConvertRGBToCMYK(PixelInfo *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->black=(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) ((cyan-black)/(1.0-black)); 00079 magenta=(MagickRealType) ((magenta-black)/(1.0-black)); 00080 yellow=(MagickRealType) ((yellow-black)/(1.0-black)); 00081 pixel->colorspace=CMYKColorspace; 00082 pixel->red=QuantumRange*cyan; 00083 pixel->green=QuantumRange*magenta; 00084 pixel->blue=QuantumRange*yellow; 00085 pixel->black=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 return(MagickTrue); 00101 return(MagickFalse); 00102 } 00103 00104 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace) 00105 { 00106 if ((colorspace == RGBColorspace) || (colorspace == scRGBColorspace)) 00107 return(MagickTrue); 00108 return(MagickFalse); 00109 } 00110 00111 static inline MagickBooleanType IssRGBColorspace( 00112 const ColorspaceType colorspace) 00113 { 00114 if ((colorspace == sRGBColorspace) || (colorspace == TransparentColorspace)) 00115 return(MagickTrue); 00116 return(MagickFalse); 00117 } 00118 00119 static inline MagickBooleanType IssRGBCompatibleColorspace( 00120 const ColorspaceType colorspace) 00121 { 00122 if ((colorspace == sRGBColorspace) || (colorspace == RGBColorspace) || 00123 (colorspace == scRGBColorspace) || (colorspace == GRAYColorspace) || 00124 (colorspace == LinearGRAYColorspace)) 00125 return(MagickTrue); 00126 return(MagickFalse); 00127 } 00128 00129 #if defined(__cplusplus) || defined(c_plusplus) 00130 } 00131 #endif 00132 00133 #endif