]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel-accessor.h
(no commit message)
[imagemagick] / MagickCore / pixel-accessor.h
index e323ed4e98584caa5191744dadcd5fcff6c3588d..d6054083ee1a37ba91a086dba01f89d496f23cad 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2014 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.
 #ifndef _MAGICKCORE_PIXEL_ACCESSOR_H
 #define _MAGICKCORE_PIXEL_ACCESSOR_H
 
+#include "MagickCore/cache.h"
+#include "MagickCore/cache-view.h"
+#include "MagickCore/color.h"
+#include "MagickCore/colorspace.h"
+#include "MagickCore/gem.h"
+#include "MagickCore/image.h"
+
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
 
-#include <math.h>
-#include <MagickCore/cache.h>
-#include <MagickCore/cache-view.h>
-#include <MagickCore/color.h>
-#include <MagickCore/colorspace.h>
-#include <MagickCore/gem.h>
-#include <MagickCore/image.h>
-
 #undef index
 
 static inline Quantum GetPixela(const Image *restrict image,
@@ -198,62 +197,45 @@ static inline MagickRealType GetPixelInfoChannel(
 static inline MagickRealType GetPixelInfoIntensity(
   const PixelInfo *restrict pixel_info)
 {
-  MagickRealType
-    blue,
-    green,
-    red;
-
   if (pixel_info->colorspace == GRAYColorspace)
     return(pixel_info->red);
-  if (pixel_info->colorspace != sRGBColorspace)
-    return(0.298839f*pixel_info->red+0.586811f*pixel_info->green+
-      0.114350f*pixel_info->blue);
-  red=DecodePixelGamma(pixel_info->red);
-  green=DecodePixelGamma(pixel_info->green);
-  blue=DecodePixelGamma(pixel_info->blue);
-  return(0.298839f*red+0.586811f*green+0.114350f*blue);
+  return(0.212656*pixel_info->red+0.715158*pixel_info->green+0.072186*
+    pixel_info->blue);
 }
 
-static inline MagickRealType GetPixelInfoLuminance(
-  const PixelInfo *restrict pixel_info)
+static inline MagickRealType GetPixelInfoLuma(const PixelInfo *restrict pixel)
 {
   MagickRealType
     blue,
     green,
     red;
 
-  if (pixel_info->colorspace == GRAYColorspace)
-    return(pixel_info->red);
-  if (pixel_info->colorspace != sRGBColorspace)
-    return(0.21267f*pixel_info->red+0.71516f*pixel_info->green+
-      0.07217f*pixel_info->blue);
-  red=DecodePixelGamma(pixel_info->red);
-  green=DecodePixelGamma(pixel_info->green);
-  blue=DecodePixelGamma(pixel_info->blue);
-  return(0.21267f*red+0.71516f*green+0.07217f*blue);
+  if (pixel->colorspace == GRAYColorspace)
+    return(pixel->red);
+  if (pixel->colorspace == sRGBColorspace)
+    return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
+  red=EncodePixelGamma(pixel->red);
+  green=EncodePixelGamma(pixel->green);
+  blue=EncodePixelGamma(pixel->blue);
+  return(0.212656*red+0.715158*green+0.072186*blue);
 }
 
-static inline MagickRealType GetPixelIntensity(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline MagickRealType GetPixelInfoLuminance(
+  const PixelInfo *restrict pixel)
 {
   MagickRealType
     blue,
     green,
     red;
 
-  if (image->colorspace == GRAYColorspace)
-    return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
-  if (image->colorspace != sRGBColorspace)
-    return(0.298839f*pixel[image->channel_map[RedPixelChannel].offset]+
-      0.586811f*pixel[image->channel_map[GreenPixelChannel].offset]+
-      0.114350f*pixel[image->channel_map[BluePixelChannel].offset]);
-  red=DecodePixelGamma((MagickRealType)
-    pixel[image->channel_map[RedPixelChannel].offset]);
-  green=DecodePixelGamma((MagickRealType)
-    pixel[image->channel_map[GreenPixelChannel].offset]);
-  blue=DecodePixelGamma((MagickRealType)
-    pixel[image->channel_map[BluePixelChannel].offset]);
-  return(0.298839f*red+0.586811f*green+0.114350f*blue);
+  if (pixel->colorspace == GRAYColorspace)
+    return(pixel->red);
+  if (pixel->colorspace != sRGBColorspace)
+    return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
+  red=DecodePixelGamma(pixel->red);
+  green=DecodePixelGamma(pixel->green);
+  blue=DecodePixelGamma(pixel->blue);
+  return(0.212656*red+0.715158*green+0.072186*blue);
 }
 
 static inline Quantum GetPixelL(const Image *restrict image,
@@ -262,6 +244,16 @@ static inline Quantum GetPixelL(const Image *restrict image,
   return(pixel[image->channel_map[LPixelChannel].offset]);
 }
 
+static inline MagickRealType GetPixelLuma(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  if (image->colorspace == GRAYColorspace)
+    return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
+  return(0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
+    0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
+    0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);  /* Rec709 */
+}
+
 static inline MagickRealType GetPixelLuminance(const Image *restrict image,
   const Quantum *restrict pixel)
 {
@@ -273,16 +265,16 @@ static inline MagickRealType GetPixelLuminance(const Image *restrict image,
   if (image->colorspace == GRAYColorspace)
     return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
   if (image->colorspace != sRGBColorspace)
-    return(0.298839f*pixel[image->channel_map[RedPixelChannel].offset]+
-      0.586811f*pixel[image->channel_map[GreenPixelChannel].offset]+
-      0.114350f*pixel[image->channel_map[BluePixelChannel].offset]);
+    return(0.212656*pixel[image->channel_map[RedPixelChannel].offset]+
+      0.715158*pixel[image->channel_map[GreenPixelChannel].offset]+
+      0.072186*pixel[image->channel_map[BluePixelChannel].offset]);
   red=DecodePixelGamma((MagickRealType)
     pixel[image->channel_map[RedPixelChannel].offset]);
   green=DecodePixelGamma((MagickRealType)
     pixel[image->channel_map[GreenPixelChannel].offset]);
   blue=DecodePixelGamma((MagickRealType)
     pixel[image->channel_map[BluePixelChannel].offset]);
-  return(0.21267f*red+0.71516f*green+0.07217f*blue);
+  return(0.212656*red+0.715158*green+0.072186*blue);  /* Rec709 */
 }
 
 static inline Quantum GetPixelMagenta(const Image *restrict image,
@@ -296,17 +288,25 @@ static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
   return(image->channel_map[MagentaPixelChannel].traits);
 }
 
-static inline Quantum GetPixelMask(const Image *restrict image,
+static inline Quantum GetPixelReadMask(const Image *restrict image,
   const Quantum *restrict pixel)
 {
-  if (image->channel_map[MaskPixelChannel].traits == UndefinedPixelTrait)
-    return((Quantum) 0);
-  return(pixel[image->channel_map[MaskPixelChannel].offset]);
+  if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
+    return((Quantum) QuantumRange);
+  return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelMaskTraits(const Image *restrict image)
+static inline Quantum GetPixelWriteMask(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(image->channel_map[MaskPixelChannel].traits);
+  if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
+    return((Quantum) QuantumRange);
+  return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
+}
+
+static inline PixelTrait GetPixelReadMaskTraits(const Image *restrict image)
+{
+  return(image->channel_map[ReadMaskPixelChannel].traits);
 }
 
 static inline size_t GetPixelMetaChannels(const Image *restrict image)
@@ -394,6 +394,22 @@ static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
   return(x < 0.0f ? -x : x);
 }
 
+static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
+  const QuantumAny range)
+{
+  Quantum
+    quantum;
+
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
+  quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
+    (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
+#else
+  quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
+    (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range);
+#endif
+  return(pixel == quantum ? MagickTrue : MagickFalse);
+}
+
 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
   const Quantum *restrict p,const PixelInfo *restrict q)
 {
@@ -533,6 +549,29 @@ static inline void SetPixelb(const Image *restrict image,
     pixel[image->channel_map[bPixelChannel].offset]=b;
 }
 
+static inline void SetPixelBackgoundColor(const Image *restrict image,
+  Quantum *restrict pixel)
+{
+  register ssize_t
+    i;
+
+  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+    pixel[i]=0;
+  pixel[image->channel_map[RedPixelChannel].offset]=
+    ClampToQuantum(image->background_color.red);
+  pixel[image->channel_map[GreenPixelChannel].offset]=
+    ClampToQuantum(image->background_color.green);
+  pixel[image->channel_map[BluePixelChannel].offset]=
+    ClampToQuantum(image->background_color.blue);
+  if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[BlackPixelChannel].offset]=
+      ClampToQuantum(image->background_color.black);
+  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[AlphaPixelChannel].offset]=
+      image->background_color.alpha_trait != BlendPixelTrait ? OpaqueAlpha :
+      ClampToQuantum(image->background_color.alpha);
+}
+
 static inline void SetPixelBlack(const Image *restrict image,
   const Quantum black,Quantum *restrict pixel)
 {
@@ -687,11 +726,18 @@ static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
   image->channel_map[MagentaPixelChannel].traits=traits;
 }
 
-static inline void SetPixelMask(const Image *restrict image,
+static inline void SetPixelReadMask(const Image *restrict image,
+  const Quantum mask,Quantum *restrict pixel)
+{
+  if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
+}
+
+static inline void SetPixelWriteMask(const Image *restrict image,
   const Quantum mask,Quantum *restrict pixel)
 {
-  if (image->channel_map[MaskPixelChannel].traits != UndefinedPixelTrait)
-    pixel[image->channel_map[MaskPixelChannel].offset]=mask;
+  if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
 }
 
 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)