% MagickCore Get / Set Image Attributes %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% October 2002 %
% %
% %
-% 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. You may %
*/
MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception)
{
-#define IsPixelAtDepth(pixel,range) ((ClampToQuantum(pixel) == \
- ScaleAnyToQuantum(ScaleQuantumToAny(pixel,range),range)) ? MagickTrue : MagickFalse)
-
CacheView
*image_view;
while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH)
{
+ MagickBooleanType
+ atDepth;
+
QuantumAny
range;
+ atDepth=MagickTrue;
range=GetQuantumRange(current_depth[id]);
- if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- if (IsPixelAtDepth(image->colormap[i].red,range) != MagickFalse)
- break;
- if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
- if (IsPixelAtDepth(image->colormap[i].green,range) != MagickFalse)
- break;
- if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- if (IsPixelAtDepth(image->colormap[i].blue,range) != MagickFalse)
- break;
+ if ((atDepth != MagickFalse) &&
+ (GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+ if (IsPixelAtDepth(image->colormap[i].red,range) == MagickFalse)
+ atDepth=MagickFalse;
+ if ((atDepth != MagickFalse) &&
+ (GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+ if (IsPixelAtDepth(image->colormap[i].green,range) == MagickFalse)
+ atDepth=MagickFalse;
+ if ((atDepth != MagickFalse) &&
+ (GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+ if (IsPixelAtDepth(image->colormap[i].blue,range) == MagickFalse)
+ atDepth=MagickFalse;
+ if ((atDepth != MagickFalse))
+ break;
current_depth[id]++;
}
}
% o exception: return any errors or warnings in this structure.
%
*/
+
+static inline Quantum ClampPixel(const MagickRealType value)
+{
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
+ return((Quantum) value);
+#else
+ if (value < 0.0f)
+ return(0.0f);
+ if (value >= (MagickRealType) QuantumRange)
+ return((Quantum) QuantumRange);
+ return(value);
+#endif
+}
+
MagickExport MagickBooleanType SetImageDepth(Image *image,
const size_t depth,ExceptionInfo *exception)
{
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].red=(double) ScaleAnyToQuantum(ScaleQuantumToAny(
- ClampToQuantum(image->colormap[i].red),range),range);
+ ClampPixel(image->colormap[i].red),range),range);
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].green=(double) ScaleAnyToQuantum(ScaleQuantumToAny(
- ClampToQuantum(image->colormap[i].green),range),range);
+ ClampPixel(image->colormap[i].green),range),range);
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].blue=(double) ScaleAnyToQuantum(ScaleQuantumToAny(
- ClampToQuantum(image->colormap[i].blue),range),range);
+ ClampPixel(image->colormap[i].blue),range),range);
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].alpha=(double) ScaleAnyToQuantum(ScaleQuantumToAny(
- ClampToQuantum(image->colormap[i].alpha),range),range);
+ ClampPixel(image->colormap[i].alpha),range),range);
}
}
status=MagickTrue;
channel=GetPixelChannelChannel(image,i);
traits=GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) ||
- (channel == IndexPixelChannel) || (channel == ReadMaskPixelChannel))
+ (channel == IndexPixelChannel) ||
+ (channel == ReadMaskPixelChannel))
continue;
q[i]=depth_map[ScaleQuantumToMap(q[i])];
}
if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) ||
(channel == ReadMaskPixelChannel))
continue;
- q[i]=ScaleAnyToQuantum(ScaleQuantumToAny(q[i],range),range);
+ q[i]=ScaleAnyToQuantum(ScaleQuantumToAny(ClampPixel(q[i]),range),range);
}
q+=GetPixelChannels(image);
}
{
case BilevelType:
{
+ if (IsImageGray(image,exception) == MagickFalse)
+ status=TransformImageColorspace(image,GRAYColorspace,exception);
+ (void) NormalizeImage(image,exception);
if (IsImageMonochrome(image,exception) == MagickFalse)
{
quantize_info=AcquireQuantizeInfo(image_info);