]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel-accessor.h
https://github.com/ImageMagick/ImageMagick/issues/539
[imagemagick] / MagickCore / pixel-accessor.h
index eb3294879065378232993897cda9966cc52975c9..6c4623696228bc27b038dee261788d76808e316f 100644 (file)
@@ -1,11 +1,11 @@
 /*
-  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2017 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.
   obtain a copy of the License at
 
-    http://www.imagemagick.org/script/license.php
+    https://www.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 pixel accessor methods.
 */
-#ifndef _MAGICKCORE_PIXEL_ACCESSOR_H
-#define _MAGICKCORE_PIXEL_ACCESSOR_H
+#ifndef MAGICKCORE_PIXEL_ACCESSOR_H
+#define MAGICKCORE_PIXEL_ACCESSOR_H
 
+#include <assert.h>
 #include "MagickCore/cache.h"
 #include "MagickCore/cache-view.h"
 #include "MagickCore/color.h"
@@ -34,7 +35,7 @@ extern "C" {
 static inline Quantum ClampPixel(const MagickRealType value)
 { 
   if (value < 0.0f)
-    return(0); 
+    return((Quantum) 0); 
   if (value >= (MagickRealType) QuantumRange)
     return((Quantum) QuantumRange);
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
@@ -44,156 +45,160 @@ static inline Quantum ClampPixel(const MagickRealType value)
 #endif
 }
 
-static inline Quantum GetPixela(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixela(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[aPixelChannel].offset]);
 }
 
-static inline Quantum GetPixelAlpha(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelAlpha(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
     return(OpaqueAlpha);
   return(pixel[image->channel_map[AlphaPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelAlphaTraits(const Image *restrict image)
+static inline PixelTrait GetPixelAlphaTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[AlphaPixelChannel].traits);
 }
 
-static inline Quantum GetPixelb(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelb(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[bPixelChannel].offset]);
 }
 
-static inline Quantum GetPixelBlack(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelBlack(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
     return((Quantum) 0);
   return(pixel[image->channel_map[BlackPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelBlackTraits(const Image *restrict image)
+static inline PixelTrait GetPixelBlackTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[BlackPixelChannel].traits);
 }
 
-static inline Quantum GetPixelBlue(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelBlue(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[BluePixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelBlueTraits(const Image *restrict image)
+static inline PixelTrait GetPixelBlueTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[BluePixelChannel].traits);
 }
 
-static inline Quantum GetPixelCb(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelCb(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[CbPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelCbTraits(const Image *restrict image)
+static inline PixelTrait GetPixelCbTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[CbPixelChannel].traits);
 }
 
-static inline Quantum GetPixelChannel(const Image *restrict image,
-  const PixelChannel channel,const Quantum *restrict pixel)
+static inline Quantum GetPixelChannel(const Image *magick_restrict image,
+  const PixelChannel channel,const Quantum *magick_restrict pixel)
 {
   if (image->channel_map[channel].traits == UndefinedPixelTrait)
     return((Quantum) 0);
   return(pixel[image->channel_map[channel].offset]);
 }
 
-static inline PixelChannel GetPixelChannelChannel(const Image *restrict image,
-  const ssize_t offset)
+static inline PixelChannel GetPixelChannelChannel(
+  const Image *magick_restrict image,const ssize_t offset)
 {
   return(image->channel_map[offset].channel);
 }
 
-static inline ssize_t GetPixelChannelOffset(const Image *restrict image,
+static inline ssize_t GetPixelChannelOffset(const Image *magick_restrict image,
   const PixelChannel channel)
 {
   return(image->channel_map[channel].offset);
 }
 
-static inline PixelTrait GetPixelChannelTraits(const Image *restrict image,
-  const PixelChannel channel)
+static inline PixelTrait GetPixelChannelTraits(
+  const Image *magick_restrict image,const PixelChannel channel)
 {
   return(image->channel_map[channel].traits);
 }
 
-static inline size_t GetPixelChannels(const Image *restrict image)
+static inline size_t GetPixelChannels(const Image *magick_restrict image)
 {
   return(image->number_channels);
 }
 
-static inline Quantum GetPixelCr(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelCr(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[CrPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelCrTraits(const Image *restrict image)
+static inline PixelTrait GetPixelCrTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[CrPixelChannel].traits);
 }
 
-static inline Quantum GetPixelCyan(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelCyan(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[CyanPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelCyanTraits(const Image *restrict image)
+static inline PixelTrait GetPixelCyanTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[CyanPixelChannel].traits);
 }
 
-static inline Quantum GetPixelGray(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelGray(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[GrayPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelGrayTraits(const Image *restrict image)
+static inline PixelTrait GetPixelGrayTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[GrayPixelChannel].traits);
 }
 
-static inline Quantum GetPixelGreen(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelGreen(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[GreenPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelGreenTraits(const Image *restrict image)
+static inline PixelTrait GetPixelGreenTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[GreenPixelChannel].traits);
 }
 
-static inline Quantum GetPixelIndex(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelIndex(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
     return((Quantum) 0);
   return(pixel[image->channel_map[IndexPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelIndexTraits(const Image *restrict image)
+static inline PixelTrait GetPixelIndexTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[IndexPixelChannel].traits);
 }
 
 static inline MagickRealType GetPixelInfoChannel(
-  const PixelInfo *restrict pixel_info,const PixelChannel channel)
+  const PixelInfo *magick_restrict pixel_info,const PixelChannel channel)
 {
   switch (channel)
   {
@@ -221,165 +226,161 @@ static inline double PerceptibleReciprocal(const double x)
   return(sign/MagickEpsilon);
 }
 
-static inline MagickRealType GetPixelInfoLuma(const PixelInfo *restrict pixel)
+static inline MagickRealType GetPixelInfoLuma(
+  const PixelInfo *magick_restrict pixel)
 {
   MagickRealType
-    gamma,
     intensity;
 
-  gamma=1.0;
-  if (pixel->alpha_trait != UndefinedPixelTrait)
-    gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*pixel->alpha);
   if (pixel->colorspace == sRGBColorspace)
     {
-      intensity=0.212656f*gamma*pixel->red+0.715158f*gamma*pixel->green+
-        0.072186f*gamma*pixel->blue;
+      intensity=(MagickRealType) (0.212656f*pixel->red+0.715158f*pixel->green+
+        0.072186f*pixel->blue);
       return(intensity);
     }
-  intensity=0.212656f*EncodePixelGamma(gamma*pixel->red)+
-    0.715158f*EncodePixelGamma(gamma*pixel->green)+
-    0.072186f*EncodePixelGamma(gamma*pixel->blue);
+  intensity=(MagickRealType) (0.212656f*EncodePixelGamma(pixel->red)+
+    0.715158f*EncodePixelGamma(pixel->green)+
+    0.072186f*EncodePixelGamma(pixel->blue));
   return(intensity);
 }
 
 static inline MagickRealType GetPixelInfoLuminance(
-  const PixelInfo *restrict pixel)
+  const PixelInfo *magick_restrict pixel)
 {
   MagickRealType
-    gamma,
     intensity;
 
-  gamma=1.0;
-  if (pixel->alpha_trait != UndefinedPixelTrait)
-    gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*pixel->alpha);
   if (pixel->colorspace != sRGBColorspace)
     {
-      intensity=0.212656f*gamma*pixel->red+0.715158f*gamma*pixel->green+
-        0.072186f*gamma*pixel->blue;
+      intensity=(MagickRealType) (0.212656f*pixel->red+0.715158f*pixel->green+
+        0.072186f*pixel->blue);
       return(intensity);
     }
-  intensity=0.212656f*DecodePixelGamma(gamma*pixel->red)+
-    0.715158f*DecodePixelGamma(gamma*pixel->green)+
-    0.072186f*DecodePixelGamma(gamma*pixel->blue);
+  intensity=(MagickRealType) (0.212656f*DecodePixelGamma(pixel->red)+
+    0.715158f*DecodePixelGamma(pixel->green)+
+    0.072186f*DecodePixelGamma(pixel->blue));
   return(intensity);
 }
 
-static inline Quantum GetPixelL(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelL(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[LPixelChannel].offset]);
 }
 
-static inline MagickRealType GetPixelLuma(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline ssize_t GetPixelLabel(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
+{
+  return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
+}
+
+static inline MagickRealType GetPixelLuma(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   MagickRealType
-    gamma,
     intensity;
 
-  gamma=1.0;
-  if (image->alpha_trait != UndefinedPixelTrait)
-    gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*
-      pixel[image->channel_map[AlphaPixelChannel].offset]);
-  intensity=0.212656f*gamma*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.715158f*gamma*pixel[image->channel_map[GreenPixelChannel].offset]+
-    0.072186f*gamma*pixel[image->channel_map[BluePixelChannel].offset];
+  intensity=(MagickRealType) (
+    0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
+    0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
+    0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);
   return(intensity);
 }
 
-static inline MagickRealType GetPixelLuminance(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline MagickRealType GetPixelLuminance(
+  const Image *magick_restrict image,const Quantum *magick_restrict pixel)
 {
   MagickRealType
-    gamma,
     intensity;
 
-  gamma=1.0;
-  if (image->alpha_trait != UndefinedPixelTrait)
-    gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*
-      pixel[image->channel_map[AlphaPixelChannel].offset]);
   if (image->colorspace != sRGBColorspace)
     {
-      intensity=
-        0.212656f*gamma*pixel[image->channel_map[RedPixelChannel].offset]+
-        0.715158f*gamma*pixel[image->channel_map[GreenPixelChannel].offset]+
-        0.072186f*gamma*pixel[image->channel_map[BluePixelChannel].offset];
+      intensity=(MagickRealType) (
+        0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
+        0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
+        0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);
       return(intensity);
     }
-  intensity=0.212656f*DecodePixelGamma(gamma*
+  intensity=(MagickRealType) (0.212656f*DecodePixelGamma((MagickRealType)
     pixel[image->channel_map[RedPixelChannel].offset])+0.715158f*
-    DecodePixelGamma(gamma*pixel[image->channel_map[GreenPixelChannel].offset])+
-    0.072186f*DecodePixelGamma(gamma*
-    pixel[image->channel_map[BluePixelChannel].offset]);
+    DecodePixelGamma((MagickRealType)
+    pixel[image->channel_map[GreenPixelChannel].offset])+0.072186f*
+    DecodePixelGamma((MagickRealType)
+    pixel[image->channel_map[BluePixelChannel].offset]));
   return(intensity);
 }
 
-static inline Quantum GetPixelMagenta(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelMagenta(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
+static inline PixelTrait GetPixelMagentaTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[MagentaPixelChannel].traits);
 }
 
-static inline Quantum GetPixelReadMask(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelReadMask(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
     return((Quantum) QuantumRange);
   return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
 }
 
-static inline Quantum GetPixelWriteMask(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelWriteMask(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   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)
+static inline PixelTrait GetPixelReadMaskTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[ReadMaskPixelChannel].traits);
 }
 
-static inline size_t GetPixelMetaChannels(const Image *restrict image)
+static inline size_t GetPixelMetaChannels(const Image *magick_restrict image)
 {
   return(image->number_meta_channels);
 }
 
-static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
+static inline size_t GetPixelMetacontentExtent(
+  const Image *magick_restrict image)
 {
   return(image->metacontent_extent);
 }
 
-static inline Quantum GetPixelOpacity(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelOpacity(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
     return(QuantumRange-OpaqueAlpha);
   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
 }
 
-static inline Quantum GetPixelRed(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelRed(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[RedPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
+static inline PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[RedPixelChannel].traits);
 }
 
-static inline void GetPixelInfoPixel(const Image *restrict image,
-  const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
+static inline void GetPixelInfoPixel(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
 {
+  pixel_info->storage_class=image->storage_class;
   pixel_info->colorspace=image->colorspace;
   pixel_info->fuzz=image->fuzz;
+  pixel_info->depth=image->depth;
   pixel_info->red=(MagickRealType)
     pixel[image->channel_map[RedPixelChannel].offset];
   pixel_info->green=(MagickRealType)
@@ -402,32 +403,34 @@ static inline void GetPixelInfoPixel(const Image *restrict image,
   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
     pixel_info->index=(MagickRealType)
       pixel[image->channel_map[IndexPixelChannel].offset];
+  pixel_info->count=0;
 }
 
-static inline PixelTrait GetPixelTraits(const Image *restrict image,
+static inline PixelTrait GetPixelTraits(const Image *magick_restrict image,
   const PixelChannel channel)
 {
   return(image->channel_map[channel].traits);
 }
 
-static inline Quantum GetPixelY(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelY(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[YPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelYTraits(const Image *restrict image)
+static inline PixelTrait GetPixelYTraits(const Image *magick_restrict image)
 {
   return(image->channel_map[YPixelChannel].traits);
 }
 
-static inline Quantum GetPixelYellow(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline Quantum GetPixelYellow(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   return(pixel[image->channel_map[YellowPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
+static inline PixelTrait GetPixelYellowTraits(
+  const Image *magick_restrict image)
 {
   return(image->channel_map[YellowPixelChannel].traits);
 }
@@ -453,26 +456,50 @@ static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
   return(pixel == quantum ? MagickTrue : MagickFalse);
 }
 
-static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
-  const Quantum *restrict p,const PixelInfo *restrict q)
+static inline MagickBooleanType IsPixelEquivalent(
+  const Image *magick_restrict image,const Quantum *magick_restrict p,
+  const PixelInfo *magick_restrict q)
 {
   MagickRealType
-    blue,
-    green,
-    red;
-
-  red=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
-  green=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
-  blue=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
-  if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
-      (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
-      (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
-    return(MagickTrue);
-  return(MagickFalse);
+    value;
+
+  value=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
+  if ((image->alpha_trait != UndefinedPixelTrait) &&
+      (q->alpha_trait == UndefinedPixelTrait) &&
+      (AbsolutePixelValue(value-OpaqueAlpha) >= MagickEpsilon))
+    return(MagickFalse);
+  if ((q->alpha_trait != UndefinedPixelTrait) &&
+      (image->alpha_trait == UndefinedPixelTrait) &&
+      (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
+    return(MagickFalse);
+  if ((image->alpha_trait != UndefinedPixelTrait) &&
+      (q->alpha_trait != UndefinedPixelTrait))
+    {
+      if (AbsolutePixelValue(value-q->alpha) >= MagickEpsilon)
+        return(MagickFalse);
+      if (AbsolutePixelValue(value-TransparentAlpha) < MagickEpsilon)
+        return(MagickTrue);
+    }
+  value=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
+  if (AbsolutePixelValue(value-q->red) >= MagickEpsilon)
+    return(MagickFalse);
+  value=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
+  if (AbsolutePixelValue(value-q->green) >= MagickEpsilon)
+    return(MagickFalse);
+  value=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
+  if (AbsolutePixelValue(value-q->blue) >= MagickEpsilon)
+    return(MagickFalse);
+  if (image->colorspace == CMYKColorspace)
+    {
+      value=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
+      if (AbsolutePixelValue(value-q->black) >= MagickEpsilon)
+        return(MagickFalse);
+    }
+  return(MagickTrue);
 }
 
-static inline MagickBooleanType IsPixelGray(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline MagickBooleanType IsPixelGray(const Image *magick_restrict image,
+  const Quantum *magick_restrict pixel)
 {
   MagickRealType
     green_blue,
@@ -480,7 +507,8 @@ static inline MagickBooleanType IsPixelGray(const Image *restrict image,
 
   red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
     pixel[image->channel_map[GreenPixelChannel].offset];
-  green_blue=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
+  green_blue=(MagickRealType)
+    pixel[image->channel_map[GreenPixelChannel].offset]-
     pixel[image->channel_map[BluePixelChannel].offset];
   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
       (AbsolutePixelValue(green_blue) < MagickEpsilon))
@@ -489,7 +517,7 @@ static inline MagickBooleanType IsPixelGray(const Image *restrict image,
 }
 
 static inline MagickBooleanType IsPixelInfoEquivalent(
-  const PixelInfo *restrict p,const PixelInfo *restrict q)
+  const PixelInfo *magick_restrict p,const PixelInfo *magick_restrict q)
 {
   if ((p->alpha_trait != UndefinedPixelTrait) &&
       (q->alpha_trait == UndefinedPixelTrait) &&
@@ -519,8 +547,8 @@ static inline MagickBooleanType IsPixelInfoEquivalent(
   return(MagickTrue);
 }
 
-static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
-  const Quantum *restrict pixel)
+static inline MagickBooleanType IsPixelMonochrome(
+  const Image *magick_restrict image,const Quantum *magick_restrict pixel)
 {
   MagickRealType
     green_blue,
@@ -543,27 +571,21 @@ static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
 }
 
 static inline MagickBooleanType IsPixelInfoGray(
-  const PixelInfo *restrict pixel_info)
+  const PixelInfo *magick_restrict pixel)
 {
-  if ((pixel_info->colorspace != GRAYColorspace) &&
-      (pixel_info->colorspace != RGBColorspace))
-    return(MagickFalse);
-  if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
-      (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
+  if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
+      (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
     return(MagickTrue);
   return(MagickFalse);
 }
 
 static inline MagickBooleanType IsPixelInfoMonochrome(
-  const PixelInfo *restrict pixel_info)
+  const PixelInfo *magick_restrict pixel_info)
 {
   MagickRealType
     green_blue,
     red_green;
 
-  if ((pixel_info->colorspace != GRAYColorspace) &&
-      (pixel_info->colorspace != RGBColorspace))
-    return(MagickFalse);
   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
     return(MagickFalse);
@@ -575,15 +597,15 @@ static inline MagickBooleanType IsPixelInfoMonochrome(
   return(MagickFalse);
 }
 
-static inline void SetPixela(const Image *restrict image,
-  const Quantum a,Quantum *restrict pixel)
+static inline void SetPixela(const Image *magick_restrict image,
+  const Quantum a,Quantum *magick_restrict pixel)
 {
   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[aPixelChannel].offset]=a;
 }
 
-static inline void SetPixelAlpha(const Image *restrict image,
-  const Quantum alpha,Quantum *restrict pixel)
+static inline void SetPixelAlpha(const Image *magick_restrict image,
+  const Quantum alpha,Quantum *magick_restrict pixel)
 {
   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
@@ -594,21 +616,21 @@ static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
   image->channel_map[AlphaPixelChannel].traits=traits;
 }
 
-static inline void SetPixelb(const Image *restrict image,const Quantum b,
-  Quantum *restrict pixel)
+static inline void SetPixelb(const Image *magick_restrict image,
+  const Quantum b,Quantum *magick_restrict pixel)
 {
   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[bPixelChannel].offset]=b;
 }
 
-static inline void SetPixelBackgoundColor(const Image *restrict image,
-  Quantum *restrict pixel)
+static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
+  Quantum *magick_restrict pixel)
 {
   register ssize_t
     i;
 
   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-    pixel[i]=0;
+    pixel[i]=(Quantum) 0;
   pixel[image->channel_map[RedPixelChannel].offset]=
     ClampToQuantum(image->background_color.red);
   pixel[image->channel_map[GreenPixelChannel].offset]=
@@ -624,8 +646,8 @@ static inline void SetPixelBackgoundColor(const Image *restrict image,
       ClampToQuantum(image->background_color.alpha);
 }
 
-static inline void SetPixelBlack(const Image *restrict image,
-  const Quantum black,Quantum *restrict pixel)
+static inline void SetPixelBlack(const Image *magick_restrict image,
+  const Quantum black,Quantum *magick_restrict pixel)
 {
   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[BlackPixelChannel].offset]=black;
@@ -636,8 +658,8 @@ static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
   image->channel_map[BlackPixelChannel].traits=traits;
 }
 
-static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
-  Quantum *restrict pixel)
+static inline void SetPixelBlue(const Image *magick_restrict image,
+  const Quantum blue,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[BluePixelChannel].offset]=blue;
 }
@@ -647,8 +669,8 @@ static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
   image->channel_map[BluePixelChannel].traits=traits;
 }
 
-static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
-  Quantum *restrict pixel)
+static inline void SetPixelCb(const Image *magick_restrict image,
+  const Quantum cb,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[CbPixelChannel].offset]=cb;
 }
@@ -658,22 +680,26 @@ static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
   image->channel_map[CbPixelChannel].traits=traits;
 }
 
-static inline void SetPixelChannel(const Image *restrict image,
-  const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
+static inline void SetPixelChannel(const Image *magick_restrict image,
+  const PixelChannel channel,const Quantum quantum,
+  Quantum *magick_restrict pixel)
 {
   if (image->channel_map[channel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[channel].offset]=quantum;
 }
 
-static inline void SetPixelChannelAttributes(const Image *restrict image,
-  const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
+static inline void SetPixelChannelAttributes(
+  const Image *magick_restrict image,const PixelChannel channel,
+  const PixelTrait traits,const ssize_t offset)
 {
+  assert((ssize_t) channel < MaxPixelChannels);
+  assert(offset < MaxPixelChannels);
   image->channel_map[offset].channel=channel;
   image->channel_map[channel].offset=offset;
   image->channel_map[channel].traits=traits;
 }
 
-static inline void SetPixelChannelChannel(const Image *restrict image,
+static inline void SetPixelChannelChannel(const Image *magick_restrict image,
   const PixelChannel channel,const ssize_t offset)
 {
   image->channel_map[offset].channel=channel;
@@ -691,8 +717,8 @@ static inline void SetPixelChannelTraits(Image *image,
   image->channel_map[channel].traits=traits;
 }
 
-static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
-  Quantum *restrict pixel)
+static inline void SetPixelCr(const Image *magick_restrict image,
+  const Quantum cr,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[CrPixelChannel].offset]=cr;
 }
@@ -702,14 +728,14 @@ static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
   image->channel_map[CrPixelChannel].traits=traits;
 }
 
-static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
-  Quantum *restrict pixel)
+static inline void SetPixelCyan(const Image *magick_restrict image,
+  const Quantum cyan,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
 }
 
-static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
-  Quantum *restrict pixel)
+static inline void SetPixelGray(const Image *magick_restrict image,
+  const Quantum gray,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
 }
@@ -719,8 +745,8 @@ static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
   image->channel_map[GrayPixelChannel].traits=traits;
 }
 
-static inline void SetPixelGreen(const Image *restrict image,
-  const Quantum green,Quantum *restrict pixel)
+static inline void SetPixelGreen(const Image *magick_restrict image,
+  const Quantum green,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[GreenPixelChannel].offset]=green;
 }
@@ -730,8 +756,8 @@ static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
   image->channel_map[GreenPixelChannel].traits=traits;
 }
 
-static inline void SetPixelIndex(const Image *restrict image,
-  const Quantum index,Quantum *restrict pixel)
+static inline void SetPixelIndex(const Image *magick_restrict image,
+  const Quantum index,Quantum *magick_restrict pixel)
 {
   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[IndexPixelChannel].offset]=index;
@@ -742,8 +768,8 @@ static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
   image->channel_map[IndexPixelChannel].traits=traits;
 }
 
-static inline void SetPixelViaPixelInfo(const Image *restrict image,
-  const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
+static inline void SetPixelViaPixelInfo(const Image *magick_restrict image,
+  const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[RedPixelChannel].offset]=
     ClampToQuantum(pixel_info->red);
@@ -760,15 +786,15 @@ static inline void SetPixelViaPixelInfo(const Image *restrict image,
       ClampToQuantum(pixel_info->alpha);
 }
 
-static inline void SetPixelL(const Image *restrict image,const Quantum L,
-  Quantum *restrict pixel)
+static inline void SetPixelL(const Image *magick_restrict image,const Quantum L,
+  Quantum *magick_restrict pixel)
 {
   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[LPixelChannel].offset]=L;
 }
 
-static inline void SetPixelMagenta(const Image *restrict image,
-  const Quantum magenta,Quantum *restrict pixel)
+static inline void SetPixelMagenta(const Image *magick_restrict image,
+  const Quantum magenta,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
 }
@@ -778,15 +804,15 @@ static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
   image->channel_map[MagentaPixelChannel].traits=traits;
 }
 
-static inline void SetPixelReadMask(const Image *restrict image,
-  const Quantum mask,Quantum *restrict pixel)
+static inline void SetPixelReadMask(const Image *magick_restrict image,
+  const Quantum mask,Quantum *magick_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)
+static inline void SetPixelWriteMask(const Image *magick_restrict image,
+  const Quantum mask,Quantum *magick_restrict pixel)
 {
   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
@@ -797,15 +823,15 @@ 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)
+static inline void SetPixelOpacity(const Image *magick_restrict image,
+  const Quantum alpha,Quantum *magick_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)
+static inline void SetPixelRed(const Image *magick_restrict image,
+  const Quantum red,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[RedPixelChannel].offset]=red;
 }
@@ -815,8 +841,8 @@ static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
   image->channel_map[RedPixelChannel].traits=traits;
 }
 
-static inline void SetPixelYellow(const Image *restrict image,
-  const Quantum yellow,Quantum *restrict pixel)
+static inline void SetPixelYellow(const Image *magick_restrict image,
+  const Quantum yellow,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
 }
@@ -826,8 +852,8 @@ static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
   image->channel_map[YellowPixelChannel].traits=traits;
 }
 
-static inline void SetPixelY(const Image *restrict image,const Quantum y,
-  Quantum *restrict pixel)
+static inline void SetPixelY(const Image *magick_restrict image,
+  const Quantum y,Quantum *magick_restrict pixel)
 {
   pixel[image->channel_map[YPixelChannel].offset]=y;
 }