% MagickCore Get / Set Image Attributes %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% October 2002 %
% %
% %
-% Copyright 1999-2012 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 %
#include "MagickCore/blob.h"
#include "MagickCore/blob-private.h"
#include "MagickCore/cache.h"
+#include "MagickCore/cache-private.h"
#include "MagickCore/cache-view.h"
+#include "MagickCore/channel.h"
#include "MagickCore/client.h"
#include "MagickCore/color.h"
#include "MagickCore/color-private.h"
GetPixelInfo(image,&zero);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
image_view=DestroyCacheView(image_view);
if ((bounds.width == 0) || (bounds.height == 0))
(void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
- "GeometryDoesNotContainImage","'%s'",image->filename);
+ "GeometryDoesNotContainImage","`%s'",image->filename);
else
{
bounds.width-=(bounds.x-1);
status;
register ssize_t
- id;
+ i;
size_t
*current_depth,
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- number_threads=GetMagickResourceLimit(ThreadResource);
+ number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
current_depth=(size_t *) AcquireQuantumMemory(number_threads,
sizeof(*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;
- if ((image->storage_class == PseudoClass) && (image->matte == MagickFalse))
+ 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) shared(status) \
+ #pragma omp parallel for schedule(static,4) shared(status) \
if ((image->colors) > 256) \
num_threads(GetMagickResourceLimit(ThreadResource))
#endif
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;
}
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
continue;
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
- if (GetPixelMask(image,p) != 0)
+ if (GetPixelReadMask(image,p) == 0)
{
p+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) ||
- (channel == IndexPixelChannel) || (channel == MaskPixelChannel))
+ (channel == IndexPixelChannel) ||
+ (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);
*/
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
continue;
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
- if (GetPixelMask(image,p) != 0)
+ if (GetPixelReadMask(image,p) == 0)
{
p+=GetPixelChannels(image);
continue;
PixelTrait
traits;
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
+ channel=GetPixelChannelChannel(image,i);
+ traits=GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) ||
- (channel == MaskPixelChannel))
+ (channel == ReadMaskPixelChannel))
continue;
while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH)
{
}
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);
}
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->colorspace == CMYKColorspace)
{
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
return(ColorSeparationType);
return(ColorSeparationMatteType);
}
return(BilevelType);
if (IsImageGray(image,exception) != MagickFalse)
{
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
return(GrayscaleMatteType);
return(GrayscaleType);
}
if (IsPaletteImage(image,exception) != MagickFalse)
{
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
return(PaletteMatteType);
return(PaletteType);
}
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
return(TrueColorMatteType);
return(TrueColorType);
}
(image->type == GrayscaleMatteType))
return(MagickTrue);
if ((IsGrayColorspace(image->colorspace) == MagickFalse) &&
- (IsRGBColorspace(image->colorspace) == MagickFalse))
+ (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse))
return(MagickFalse);
type=BilevelType;
image_view=AcquireVirtualCacheView(image,exception);
image_view=DestroyCacheView(image_view);
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->matte != MagickFalse))
+ if ((type == GrayscaleType) && (image->alpha_trait == BlendPixelTrait))
((Image *) image)->type=GrayscaleMatteType;
return(MagickTrue);
}
if (image->type == BilevelType)
return(MagickTrue);
if ((IsGrayColorspace(image->colorspace) == MagickFalse) &&
- (IsRGBColorspace(image->colorspace) == MagickFalse))
+ (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse))
return(MagickFalse);
type=BilevelType;
image_view=AcquireVirtualCacheView(image,exception);
image_view=DestroyCacheView(image_view);
if (type == UndefinedType)
return(MagickFalse);
+ ((Image *) image)->colorspace=GRAYColorspace;
+ if (SyncImagePixelCache((Image *) image,exception) == MagickFalse)
+ return(MagickFalse);
((Image *) image)->type=type;
return(MagickTrue);
}
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
return(MagickTrue);
image_view=AcquireVirtualCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
% 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)
{
i;
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static) shared(status) \
- dynamic_number_threads(image,image->columns,1,1)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,1,1)
#endif
for (i=0; i < (ssize_t) image->colors; i++)
{
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;
range);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
PixelTrait
traits;
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
+ channel=GetPixelChannelChannel(image,i);
+ traits=GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) ||
- (channel == IndexPixelChannel) || (channel == MaskPixelChannel))
+ (channel == IndexPixelChannel) ||
+ (channel == ReadMaskPixelChannel))
continue;
q[i]=depth_map[ScaleQuantumToMap(q[i])];
}
*/
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
PixelTrait
traits;
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
+ channel=GetPixelChannelChannel(image,i);
+ traits=GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) ||
- (channel == MaskPixelChannel))
+ (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);
status=QuantizeImage(quantize_info,image,exception);
quantize_info=DestroyQuantizeInfo(quantize_info);
}
- image->matte=MagickFalse;
+ image->alpha_trait=UndefinedPixelTrait;
break;
}
case GrayscaleType:
{
if (IsImageGray(image,exception) == MagickFalse)
status=TransformImageColorspace(image,GRAYColorspace,exception);
- image->matte=MagickFalse;
+ image->alpha_trait=UndefinedPixelTrait;
break;
}
case GrayscaleMatteType:
{
if (IsImageGray(image,exception) == MagickFalse)
status=TransformImageColorspace(image,GRAYColorspace,exception);
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
break;
}
status=QuantizeImage(quantize_info,image,exception);
quantize_info=DestroyQuantizeInfo(quantize_info);
}
- image->matte=MagickFalse;
+ image->alpha_trait=UndefinedPixelTrait;
break;
}
case PaletteBilevelMatteType:
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
status=TransformImageColorspace(image,sRGBColorspace,exception);
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
- channel_mask=SetPixelChannelMask(image,AlphaChannel);
+ channel_mask=SetImageChannelMask(image,AlphaChannel);
(void) BilevelImage(image,(double) QuantumRange/2.0,exception);
- (void) SetPixelChannelMask(image,channel_mask);
+ (void) SetImageChannelMask(image,channel_mask);
quantize_info=AcquireQuantizeInfo(image_info);
status=QuantizeImage(quantize_info,image,exception);
quantize_info=DestroyQuantizeInfo(quantize_info);
{
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
status=TransformImageColorspace(image,sRGBColorspace,exception);
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
quantize_info=AcquireQuantizeInfo(image_info);
quantize_info->colorspace=TransparentColorspace;
status=TransformImageColorspace(image,sRGBColorspace,exception);
if (image->storage_class != DirectClass)
status=SetImageStorageClass(image,DirectClass,exception);
- image->matte=MagickFalse;
+ image->alpha_trait=UndefinedPixelTrait;
break;
}
case TrueColorMatteType:
status=TransformImageColorspace(image,sRGBColorspace,exception);
if (image->storage_class != DirectClass)
status=SetImageStorageClass(image,DirectClass,exception);
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
break;
}
}
if (image->storage_class != DirectClass)
status=SetImageStorageClass(image,DirectClass,exception);
- image->matte=MagickFalse;
+ image->alpha_trait=UndefinedPixelTrait;
break;
}
case ColorSeparationMatteType:
}
if (image->storage_class != DirectClass)
status=SetImageStorageClass(image,DirectClass,exception);
- if (image->matte == MagickFalse)
+ if (image->alpha_trait != BlendPixelTrait)
status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
break;
}
case UndefinedType:
break;
}
- image->type=type;
image_info=DestroyImageInfo(image_info);
- return(status);
+ if (status == MagickFalse)
+ return(status);
+ image->type=type;
+ return(MagickTrue);
}