]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/colorspace-private.h
https://github.com/ImageMagick/ImageMagick/issues/1711
[imagemagick] / MagickCore / colorspace-private.h
index 39335b62660397fd6d48a3f4d23040778f3f4f02..21d8e20e7128717f3e8bb5f9c379131621c8631a 100644 (file)
@@ -1,11 +1,11 @@
 /*
-  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization
   dedicated to making software imaging solutions freely available.
   
-  You may not use this file except in compliance with the License.
+  You may not use this file except in compliance with the License.  You may
   obtain a copy of the License at
   
-    http://www.imagemagick.org/script/license.php
+    https://imagemagick.org/script/license.php
   
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
 
   MagickCore image colorspace private methods.
 */
-#ifndef _MAGICKCORE_COLORSPACE_PRIVATE_H
-#define _MAGICKCORE_COLORSPACE_PRIVATE_H
+#ifndef MAGICKCORE_COLORSPACE_PRIVATE_H
+#define MAGICKCORE_COLORSPACE_PRIVATE_H
+
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/pixel.h"
+#include "MagickCore/pixel-accessor.h"
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
 
-#include <MagickCore/image.h>
-#include <MagickCore/image-private.h>
-#include <MagickCore/pixel.h>
+static inline void ConvertCMYKToRGB(PixelInfo *pixel)
+{
+  pixel->red=((QuantumRange-(QuantumScale*pixel->red*(QuantumRange-
+    pixel->black)+pixel->black)));
+  pixel->green=((QuantumRange-(QuantumScale*pixel->green*(QuantumRange-
+    pixel->black)+pixel->black)));
+  pixel->blue=((QuantumRange-(QuantumScale*pixel->blue*(QuantumRange-
+    pixel->black)+pixel->black)));
+}
 
 static inline void ConvertRGBToCMYK(PixelInfo *pixel)
 {
   MagickRealType
     black,
+    blue,
     cyan,
+    green,
     magenta,
+    red,
     yellow;
-                                                                                
-  if ((fabs(pixel->red) < MagickEpsilon) &&
-      (fabs(pixel->green) < MagickEpsilon) &&
-      (fabs(pixel->blue) < MagickEpsilon))
+
+  if (pixel->colorspace != sRGBColorspace)
+    {
+      red=QuantumScale*pixel->red;
+      green=QuantumScale*pixel->green;
+      blue=QuantumScale*pixel->blue;
+    }
+  else
+    {
+      red=QuantumScale*DecodePixelGamma(pixel->red);
+      green=QuantumScale*DecodePixelGamma(pixel->green);
+      blue=QuantumScale*DecodePixelGamma(pixel->blue);
+    }
+  if ((fabs((double) red) < MagickEpsilon) &&
+      (fabs((double) green) < MagickEpsilon) &&
+      (fabs((double) blue) < MagickEpsilon))
     {
       pixel->black=(MagickRealType) QuantumRange;
       return;
     }
-  cyan=(MagickRealType) (1.0-QuantumScale*pixel->red);
-  magenta=(MagickRealType) (1.0-QuantumScale*pixel->green);
-  yellow=(MagickRealType) (1.0-QuantumScale*pixel->blue);
+  cyan=(MagickRealType) (1.0-red);
+  magenta=(MagickRealType) (1.0-green);
+  yellow=(MagickRealType) (1.0-blue);
   black=cyan;
   if (magenta < black)
     black=magenta;
   if (yellow < black)
     black=yellow;
-  cyan=(MagickRealType) ((cyan-black)/(1.0-black));
-  magenta=(MagickRealType) ((magenta-black)/(1.0-black));
-  yellow=(MagickRealType) ((yellow-black)/(1.0-black));
+  cyan=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(cyan-black));
+  magenta=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(magenta-black));
+  yellow=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(yellow-black));
   pixel->colorspace=CMYKColorspace;
   pixel->red=QuantumRange*cyan;
   pixel->green=QuantumRange*magenta;
@@ -59,19 +85,44 @@ static inline void ConvertRGBToCMYK(PixelInfo *pixel)
   pixel->black=QuantumRange*black;
 }
 
+static inline MagickBooleanType IsCMYKColorspace(
+  const ColorspaceType colorspace)
+{
+  if (colorspace == CMYKColorspace)
+    return(MagickTrue);
+  return(MagickFalse);
+}
+
 static inline MagickBooleanType IsGrayColorspace(
   const ColorspaceType colorspace)
 {
-  if ((colorspace == GRAYColorspace) || (colorspace == Rec601LumaColorspace) ||
-      (colorspace == Rec709LumaColorspace))
+  if ((colorspace == LinearGRAYColorspace) || (colorspace == GRAYColorspace))
     return(MagickTrue);
   return(MagickFalse);
 }
 
 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
 {
-  if ((IsGrayColorspace(colorspace) != MagickFalse) ||
-      (colorspace == RGBColorspace) || (colorspace == TransparentColorspace))
+  if ((colorspace == RGBColorspace) || (colorspace == scRGBColorspace) ||
+      (colorspace == LinearGRAYColorspace))
+    return(MagickTrue);
+  return(MagickFalse);
+}
+
+static inline MagickBooleanType IssRGBColorspace(
+  const ColorspaceType colorspace)
+{
+  if ((colorspace == sRGBColorspace) || (colorspace == TransparentColorspace))
+    return(MagickTrue);
+  return(MagickFalse);
+}
+
+static inline MagickBooleanType IssRGBCompatibleColorspace(
+  const ColorspaceType colorspace)
+{
+  if ((colorspace == sRGBColorspace) || (colorspace == RGBColorspace) ||
+      (colorspace == scRGBColorspace) || (colorspace == TransparentColorspace) ||
+      (colorspace == GRAYColorspace) || (colorspace == LinearGRAYColorspace))
     return(MagickTrue);
   return(MagickFalse);
 }