]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel-accessor.h
Fix CLUT interpolation method
[imagemagick] / MagickCore / pixel-accessor.h
index ed53ba5bbcefce3de05961ebc4f7376a695fa9bd..78d9bcc31f13c12775602145af4f56100abd878d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2012 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.
@@ -23,6 +23,7 @@ extern "C" {
 #endif
 
 #include <math.h>
+#include <MagickCore/cache.h>
 #include <MagickCore/cache-view.h>
 #include <MagickCore/color.h>
 #include <MagickCore/image.h>
@@ -193,6 +194,48 @@ static inline Quantum GetPixelInfoLuminance(
   return((Quantum) luminance);
 }
 
+static inline Quantum GetPixelIntensity(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
+  if (image->colorspace == GRAYColorspace)
+    return(pixel[image->channel_map[GrayPixelChannel].offset]);
+  return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].offset]+
+    0.587*pixel[image->channel_map[GreenPixelChannel].offset]+0.114*
+    pixel[image->channel_map[BluePixelChannel].offset]+0.5));
+#else
+  {
+    double
+      alpha,
+      beta;
+
+    alpha=pixel[image->channel_map[RedPixelChannel].offset]-(double)
+      pixel[image->channel_map[GreenPixelChannel].offset];
+    beta=pixel[image->channel_map[GreenPixelChannel].offset]-(double)
+      pixel[image->channel_map[BluePixelChannel].offset];
+    if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
+      return(pixel[image->channel_map[RedPixelChannel].offset]);
+    return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].offset]+
+      0.587*pixel[image->channel_map[GreenPixelChannel].offset]+0.114*
+      pixel[image->channel_map[BluePixelChannel].offset]));
+  }
+#endif
+}
+
+static inline Quantum GetPixelLuminance(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
+  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].offset]+
+    0.71516*pixel[image->channel_map[GreenPixelChannel].offset]+0.07217*
+    pixel[image->channel_map[BluePixelChannel].offset]+0.5));
+#else
+  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].offset]+
+    0.71516*pixel[image->channel_map[GreenPixelChannel].offset]+0.07217*
+    pixel[image->channel_map[BluePixelChannel].offset]));
+#endif
+}
+
 static inline Quantum GetPixelMagenta(const Image *restrict image,
   const Quantum *restrict pixel)
 {
@@ -204,6 +247,19 @@ static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
   return(image->channel_map[MagentaPixelChannel].traits);
 }
 
+static inline Quantum GetPixelMask(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  if (image->channel_map[MaskPixelChannel].traits == UndefinedPixelTrait)
+    return(0);
+  return(pixel[image->channel_map[MaskPixelChannel].offset]);
+}
+
+static inline PixelTrait GetPixelMaskTraits(const Image *restrict image)
+{
+  return(image->channel_map[MaskPixelChannel].traits);
+}
+
 static inline size_t GetPixelMetaChannels(const Image *restrict image)
 {
   return(image->number_meta_channels);
@@ -214,6 +270,14 @@ static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
   return(image->metacontent_extent);
 }
 
+static inline Quantum GetPixelOpacity(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
+    return(QuantumRange-OpaqueAlpha);
+  return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
+}
+
 static inline Quantum GetPixelRed(const Image *restrict image,
   const Quantum *restrict pixel)
 {
@@ -228,23 +292,23 @@ static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
 static inline void GetPixelInfoPixel(const Image *restrict image,
   const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
 {
-  pixel_info->red=(MagickRealType)
+  pixel_info->red=(double)
     pixel[image->channel_map[RedPixelChannel].offset];
-  pixel_info->green=(MagickRealType)
+  pixel_info->green=(double)
     pixel[image->channel_map[GreenPixelChannel].offset];
-  pixel_info->blue=(MagickRealType)
+  pixel_info->blue=(double)
     pixel[image->channel_map[BluePixelChannel].offset];
   pixel_info->black=0;
   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
-    pixel_info->black=(MagickRealType)
+    pixel_info->black=(double)
       pixel[image->channel_map[BlackPixelChannel].offset];
   pixel_info->alpha=OpaqueAlpha;
   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
-    pixel_info->alpha=(MagickRealType)
+    pixel_info->alpha=(double)
       pixel[image->channel_map[AlphaPixelChannel].offset];
   pixel_info->index=0;
   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
-    pixel_info->index=(MagickRealType)
+    pixel_info->index=(double)
       pixel[image->channel_map[IndexPixelChannel].offset];
 }
 
@@ -552,23 +616,6 @@ static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
   image->channel_map[IndexPixelChannel].traits=traits;
 }
 
-static inline void SetPixelInfo(const Image *restrict image,
-  const PixelInfo *restrict p,PixelInfo *restrict q)
-{
-  q->red=p->red;
-  q->green=p->green;
-  q->blue=p->blue;
-  q->black=0;
-  if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
-    q->black=p->black;
-  q->alpha=OpaqueAlpha;
-  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
-    q->alpha=p->alpha;
-  q->index=0;
-  if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
-    q->index=p->index;
-}
-
 static inline void SetPixelInfoPixel(const Image *restrict image,
   const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
 {
@@ -597,10 +644,11 @@ static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
   image->channel_map[MagentaPixelChannel].traits=traits;
 }
 
-static inline void SetPixelMetaChannels(Image *image,
-  const size_t number_meta_channels)
+static inline void SetPixelMask(const Image *restrict image,
+  const Quantum mask,Quantum *restrict pixel)
 {
-  image->number_meta_channels=number_meta_channels;
+  if (image->channel_map[MaskPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[MaskPixelChannel].offset]=mask;
 }
 
 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
@@ -608,6 +656,13 @@ static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
   image->metacontent_extent=extent;
 }
 
+static inline void SetPixelOpacity(const Image *restrict image,
+  const Quantum alpha,Quantum *restrict pixel)
+{
+  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
+}
+
 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
   Quantum *restrict pixel)
 {
@@ -641,51 +696,6 @@ static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
   image->channel_map[YPixelChannel].traits=traits;
 }
 
-static inline Quantum GetPixelIntensity(const Image *restrict image,
-  const Quantum *restrict pixel)
-{
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel[image->channel_map[RedPixelChannel].offset] ==
-       pixel[image->channel_map[GreenPixelChannel].offset]) &&
-      (pixel[image->channel_map[GreenPixelChannel].offset] ==
-       pixel[image->channel_map[BluePixelChannel].offset]))
-    return(pixel[image->channel_map[RedPixelChannel].offset]);
-  return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.587*pixel[image->channel_map[GreenPixelChannel].offset]+0.114*
-    pixel[image->channel_map[BluePixelChannel].offset]+0.5));
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel[image->channel_map[RedPixelChannel].offset]-(double)
-      pixel[image->channel_map[GreenPixelChannel].offset];
-    beta=pixel[image->channel_map[GreenPixelChannel].offset]-(double)
-      pixel[image->channel_map[BluePixelChannel].offset];
-    if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(pixel[image->channel_map[RedPixelChannel].offset]);
-    return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].offset]+
-      0.587*pixel[image->channel_map[GreenPixelChannel].offset]+0.114*
-      pixel[image->channel_map[BluePixelChannel].offset]));
-  }
-#endif
-}
-
-static inline Quantum GetPixelLuminance(const Image *restrict image,
-  const Quantum *restrict pixel)
-{
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.71516*pixel[image->channel_map[GreenPixelChannel].offset]+0.07217*
-    pixel[image->channel_map[BluePixelChannel].offset]+0.5));
-#else
-  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.71516*pixel[image->channel_map[GreenPixelChannel].offset]+0.07217*
-    pixel[image->channel_map[BluePixelChannel].offset]));
-#endif
-}
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif