% 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 %
status;
register ssize_t
- id;
+ i;
size_t
*current_depth,
if (current_depth == (size_t *) NULL)
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
status=MagickTrue;
- for (id=0; id < (ssize_t) number_threads; id++)
- current_depth[id]=1;
+ for (i=0; i < (ssize_t) number_threads; i++)
+ current_depth[i]=1;
if ((image->storage_class == PseudoClass) && (image->alpha_trait != BlendPixelTrait))
{
- register ssize_t
- i;
-
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status) \
if ((image->colors) > 256) \
const int
id = GetOpenMPThreadId();
- if (status == MagickFalse)
- continue;
while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH)
{
- MagickStatusType
- status;
+ MagickBooleanType
+ atDepth;
QuantumAny
range;
- status=0;
+ atDepth=MagickTrue;
range=GetQuantumRange(current_depth[id]);
- if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- status&=ClampToQuantum(image->colormap[i].red) !=
- ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum(
- image->colormap[i].red),range),range);
- if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
- status&=ClampToQuantum(image->colormap[i].green) !=
- ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum(
- image->colormap[i].green),range),range);
- if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- status&=ClampToQuantum(image->colormap[i].blue) !=
- ScaleAnyToQuantum(ScaleQuantumToAny(ClampToQuantum(
- image->colormap[i].blue),range),range);
- if (status == 0)
+ 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]++;
}
}
depth=current_depth[0];
- for (id=1; id < (ssize_t) number_threads; id++)
- if (depth < current_depth[id])
- depth=current_depth[id];
+ for (i=1; i < (ssize_t) number_threads; i++)
+ if (depth < current_depth[i])
+ depth=current_depth[i];
current_depth=(size_t *) RelinquishMagickMemory(current_depth);
return(depth);
}
#if !defined(MAGICKCORE_HDRI_SUPPORT)
if (QuantumRange <= MaxMap)
{
- register ssize_t
- i;
-
size_t
*depth_map;
continue;
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
if (GetPixelReadMask(image,p) == 0)
{
p+=GetPixelChannels(image);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) ||
(channel == IndexPixelChannel) ||
- (channel == ReadMaskPixelChannel) || (channel == MetaPixelChannel))
+ (channel == ReadMaskPixelChannel) ||
+ (channel == MetaPixelChannel))
continue;
if (depth_map[ScaleQuantumToMap(p[i])] > current_depth[id])
current_depth[id]=depth_map[ScaleQuantumToMap(p[i])];
}
image_view=DestroyCacheView(image_view);
depth=current_depth[0];
- for (id=1; id < (ssize_t) number_threads; id++)
- if (depth < current_depth[id])
- depth=current_depth[id];
+ for (i=1; i < (ssize_t) number_threads; i++)
+ if (depth < current_depth[i])
+ depth=current_depth[i];
depth_map=(size_t *) RelinquishMagickMemory(depth_map);
current_depth=(size_t *) RelinquishMagickMemory(current_depth);
return(depth);
continue;
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
if (GetPixelReadMask(image,p) == 0)
{
p+=GetPixelChannels(image);
}
image_view=DestroyCacheView(image_view);
depth=current_depth[0];
- for (id=1; id < (ssize_t) number_threads; id++)
- if (depth < current_depth[id])
- depth=current_depth[id];
+ for (i=1; i < (ssize_t) number_threads; i++)
+ if (depth < current_depth[i])
+ depth=current_depth[i];
current_depth=(size_t *) RelinquishMagickMemory(current_depth);
return(depth);
}
if (type == UndefinedType)
return(MagickFalse);
((Image *) image)->colorspace=GRAYColorspace;
+ if (SyncImagePixelCache((Image *) image,exception) == MagickFalse)
+ return(MagickFalse);
((Image *) image)->type=type;
if ((type == GrayscaleType) && (image->alpha_trait == BlendPixelTrait))
((Image *) image)->type=GrayscaleMatteType;
- return(SyncImagePixelCache((Image *) image,exception));
+ return(MagickTrue);
}
\f
/*
if (type == UndefinedType)
return(MagickFalse);
((Image *) image)->colorspace=GRAYColorspace;
+ if (SyncImagePixelCache((Image *) image,exception) == MagickFalse)
+ return(MagickFalse);
((Image *) image)->type=type;
- return(SyncImagePixelCache((Image *) image,exception));
+ return(MagickTrue);
}
\f
/*
% 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);
case UndefinedType:
break;
}
- image->type=type;
image_info=DestroyImageInfo(image_info);
- return(status);
+ if (status == MagickFalse)
+ return(status);
+ image->type=type;
+ return(MagickTrue);
}