MagickCore  6.7.5
colorspace-private.h
Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2012 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.
00006   obtain a copy of the License at
00007   
00008     http://www.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 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 #include <MagickCore/image.h>
00026 #include <MagickCore/image-private.h>
00027 #include <MagickCore/pixel.h>
00028 
00029 static inline void ConvertRGBToCMYK(PixelInfo *pixel)
00030 {
00031   MagickRealType
00032     black,
00033     cyan,
00034     magenta,
00035     yellow;
00036                                                                                 
00037   if ((fabs(pixel->red) < MagickEpsilon) &&
00038       (fabs(pixel->green) < MagickEpsilon) &&
00039       (fabs(pixel->blue) < MagickEpsilon))
00040     {
00041       pixel->black=(MagickRealType) QuantumRange;
00042       return;
00043     }
00044   cyan=(MagickRealType) (1.0-QuantumScale*pixel->red);
00045   magenta=(MagickRealType) (1.0-QuantumScale*pixel->green);
00046   yellow=(MagickRealType) (1.0-QuantumScale*pixel->blue);
00047   black=cyan;
00048   if (magenta < black)
00049     black=magenta;
00050   if (yellow < black)
00051     black=yellow;
00052   cyan=(MagickRealType) ((cyan-black)/(1.0-black));
00053   magenta=(MagickRealType) ((magenta-black)/(1.0-black));
00054   yellow=(MagickRealType) ((yellow-black)/(1.0-black));
00055   pixel->colorspace=CMYKColorspace;
00056   pixel->red=QuantumRange*cyan;
00057   pixel->green=QuantumRange*magenta;
00058   pixel->blue=QuantumRange*yellow;
00059   pixel->black=QuantumRange*black;
00060 }
00061 
00062 static inline MagickBooleanType IsGrayColorspace(
00063   const ColorspaceType colorspace)
00064 {
00065   if ((colorspace == GRAYColorspace) || (colorspace == Rec601LumaColorspace) ||
00066       (colorspace == Rec709LumaColorspace))
00067     return(MagickTrue);
00068   return(MagickFalse);
00069 }
00070 
00071 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
00072 {
00073   if ((IsGrayColorspace(colorspace) != MagickFalse) ||
00074       (colorspace == RGBColorspace) || (colorspace == TransparentColorspace))
00075     return(MagickTrue);
00076   return(MagickFalse);
00077 }
00078 
00079 #if defined(__cplusplus) || defined(c_plusplus)
00080 }
00081 #endif
00082 
00083 #endif