% MagickCore Image Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% 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/property.h"
#include "MagickCore/quantize.h"
#include "MagickCore/random_.h"
+#include "MagickCore/resource_.h"
#include "MagickCore/segment.h"
#include "MagickCore/semaphore.h"
#include "MagickCore/signature-private.h"
#include "MagickCore/thread-private.h"
#include "MagickCore/threshold.h"
#include "MagickCore/timer.h"
+#include "MagickCore/token.h"
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
image->depth=MAGICKCORE_QUANTUM_DEPTH;
image->colorspace=sRGBColorspace;
image->rendering_intent=PerceptualIntent;
- image->gamma=0.45455;
- image->chromaticity.red_primary.x=0.6400;
- image->chromaticity.red_primary.y=0.3300;
- image->chromaticity.green_primary.x=0.3000;
- image->chromaticity.green_primary.y=0.6000;
- image->chromaticity.blue_primary.x=0.1500;
- image->chromaticity.blue_primary.y=0.0600;
- image->chromaticity.white_point.x=0.3127;
- image->chromaticity.white_point.y=0.3290;
+ image->gamma=1.000f/2.200f;
+ image->chromaticity.red_primary.x=0.6400f;
+ image->chromaticity.red_primary.y=0.3300f;
+ image->chromaticity.red_primary.z=0.0300f;
+ image->chromaticity.green_primary.x=0.3000f;
+ image->chromaticity.green_primary.y=0.6000f;
+ image->chromaticity.green_primary.z=0.1000f;
+ image->chromaticity.blue_primary.x=0.1500f;
+ image->chromaticity.blue_primary.y=0.0600f;
+ image->chromaticity.blue_primary.z=0.7900f;
+ image->chromaticity.white_point.x=0.3127f;
+ image->chromaticity.white_point.y=0.3290f;
+ image->chromaticity.white_point.z=0.3583f;
image->interlace=NoInterlace;
image->ticks_per_second=UndefinedTicksPerSecond;
image->compose=OverCompositeOp;
- image->blur=1.0;
(void) QueryColorCompliance(BackgroundColor,AllCompliance,
&image->background_color,exception);
(void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
exception);
(void) QueryColorCompliance(TransparentColor,AllCompliance,
&image->transparent_color,exception);
- image->resolution.x=DefaultResolution;
- image->resolution.y=DefaultResolution;
- image->units=PixelsPerInchResolution;
GetTimerInfo(&image->timer);
image->cache=AcquirePixelCache(0);
image->channel_mask=DefaultChannels;
image->channel_map=AcquirePixelChannelMap();
image->blob=CloneBlobInfo((BlobInfo *) NULL);
+ image->timestamp=time((time_t *) NULL);
image->debug=IsEventLogging();
image->reference_count=1;
- image->semaphore=AllocateSemaphoreInfo();
+ image->semaphore=AcquireSemaphoreInfo();
image->signature=MagickSignature;
if (image_info == (ImageInfo *) NULL)
return(image);
image->client_data=image_info->client_data;
if (image_info->cache != (void *) NULL)
ClonePixelCacheMethods(image->cache,image_info->cache);
+ /*
+ Set all global options that map to per-image settings.
+ */
(void) SyncImageSettings(image_info,image,exception);
+ /*
+ Global options that are only set for new images.
+ */
+ image->image_info=(ImageInfo *) NULL;
option=GetImageOption(image_info,"delay");
if (option != (const char *) NULL)
{
% of the image list and appends them to each other top-to-bottom if the
% stack parameter is true, otherwise left-to-right.
%
-% The current gravity setting now effects how the image is justified in the
+% The current gravity setting effects how the image is justified in the
% final image.
%
% The format of the AppendImages method is:
#define AppendImageTag "Append/Image"
CacheView
- *append_view,
- *image_view;
-
- const Image
- *image;
+ *append_view;
Image
*append_image;
MagickBooleanType
- matte,
- proceed,
status;
MagickOffsetType
n;
+ PixelTrait
+ alpha_trait;
+
RectangleInfo
geometry;
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
- image=images;
- matte=image->matte;
+ alpha_trait=images->alpha_trait;
number_images=1;
- width=image->columns;
- height=image->rows;
- next=GetNextImageInList(image);
+ width=images->columns;
+ height=images->rows;
+ next=GetNextImageInList(images);
for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
{
- if (next->matte != MagickFalse)
- matte=MagickTrue;
+ if (next->alpha_trait == BlendPixelTrait)
+ alpha_trait=BlendPixelTrait;
number_images++;
if (stack != MagickFalse)
{
/*
Append images.
*/
- append_image=CloneImage(image,width,height,MagickTrue,exception);
+ append_image=CloneImage(images,width,height,MagickTrue,exception);
if (append_image == (Image *) NULL)
return((Image *) NULL);
if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
append_image=DestroyImage(append_image);
return((Image *) NULL);
}
- append_image->matte=matte;
+ append_image->alpha_trait=alpha_trait;
(void) SetImageBackgroundColor(append_image,exception);
status=MagickTrue;
x_offset=0;
y_offset=0;
- append_view=AcquireCacheView(append_image);
+ next=images;
+ append_view=AcquireAuthenticCacheView(append_image,exception);
for (n=0; n < (MagickOffsetType) number_images; n++)
{
+ CacheView
+ *image_view;
+
+ Image
+ *image;
+
+ MagickBooleanType
+ proceed;
+
+ image=CloneImage(next,0,0,MagickTrue,exception);
+ if (image == (Image *) NULL)
+ break;
+ (void) TransformImageColorspace(image,append_image->colorspace,exception);
SetGeometry(append_image,&geometry);
GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
if (stack != MagickFalse)
x_offset-=geometry.x;
else
y_offset-=geometry.y;
- image_view=AcquireCacheView(image);
+ image_view=AcquireVirtualCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static) shared(status)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
MagickBooleanType
sync;
+ PixelInfo
+ pixel;
+
register const Quantum
*restrict p;
status=MagickFalse;
continue;
}
+ GetPixelInfo(image,&pixel);
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
- if (GetPixelMask(image,p) != 0)
+ if (GetPixelReadMask(image,p) == 0)
{
+ SetPixelBackgoundColor(append_image,q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(append_image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- PixelChannel
- channel;
-
- PixelTrait
- append_traits,
- traits;
-
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
- append_traits=GetPixelChannelMapTraits(append_image,channel);
- if ((traits == UndefinedPixelTrait) ||
- (append_traits == UndefinedPixelTrait))
- continue;
- SetPixelChannel(append_image,channel,p[i],q);
- }
+ GetPixelInfoPixel(image,p,&pixel);
+ SetPixelInfoPixel(append_image,&pixel,q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(append_image);
}
status=MagickFalse;
}
image_view=DestroyCacheView(image_view);
- proceed=SetImageProgress(image,AppendImageTag,n,number_images);
- if (proceed == MagickFalse)
- break;
if (stack == MagickFalse)
{
x_offset+=(ssize_t) image->columns;
x_offset=0;
y_offset+=(ssize_t) image->rows;
}
- image=GetNextImageInList(image);
+ image=DestroyImage(image);
+ proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
+ if (proceed == MagickFalse)
+ break;
+ next=GetNextImageInList(next);
}
append_view=DestroyCacheView(append_view);
if (status == MagickFalse)
Image
*clone_image;
- MagickRealType
+ double
scale;
size_t
clone_image->number_meta_channels=image->number_meta_channels;
clone_image->metacontent_extent=image->metacontent_extent;
clone_image->colorspace=image->colorspace;
- clone_image->mask=image->mask;
- clone_image->matte=image->matte;
+ clone_image->read_mask=image->read_mask;
+ clone_image->write_mask=image->write_mask;
+ clone_image->alpha_trait=image->alpha_trait;
clone_image->columns=image->columns;
clone_image->rows=image->rows;
clone_image->dither=image->dither;
}
clone_image->ping=image->ping;
clone_image->debug=IsEventLogging();
- clone_image->semaphore=AllocateSemaphoreInfo();
+ clone_image->semaphore=AcquireSemaphoreInfo();
if ((columns == 0) && (rows == 0))
{
if (image->montage != (char *) NULL)
clone_image->cache=ReferencePixelCache(image->cache);
return(clone_image);
}
- scale=(MagickRealType) columns/(MagickRealType) image->columns;
+ scale=(double) columns/(double) image->columns;
clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
- scale=(MagickRealType) rows/(MagickRealType) image->rows;
+ scale=(double) rows/(double) image->rows;
clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
clone_image->columns=columns;
clone_image->rows=rows;
clone_image->cache=ClonePixelCache(image->cache);
+
return(clone_image);
}
\f
% %
% %
% %
-% C o m b i n e I m a g e s %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% CombineImages() combines one or more images into a single image. The
-% grayscale value of the pixels of each image in the sequence is assigned in
-% order to the specified channels of the combined image. The typical
-% ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
-%
-% The format of the CombineImages method is:
-%
-% Image *CombineImages(const Image *image,ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o image: the image.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-
-static inline size_t MagickMin(const size_t x,const size_t y)
-{
- if (x < y)
- return(x);
- return(y);
-}
-
-MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
-{
-#define CombineImageTag "Combine/Image"
-
- CacheView
- *combine_view;
-
- Image
- *combine_image;
-
- MagickBooleanType
- status;
-
- MagickOffsetType
- progress;
-
- ssize_t
- y;
-
- /*
- Ensure the image are the same size.
- */
- assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
- combine_image=CloneImage(image,0,0,MagickTrue,exception);
- if (combine_image == (Image *) NULL)
- return((Image *) NULL);
- if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
- {
- combine_image=DestroyImage(combine_image);
- return((Image *) NULL);
- }
- if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
- combine_image->matte=MagickTrue;
- /*
- Combine images.
- */
- status=MagickTrue;
- progress=0;
- combine_view=AcquireCacheView(combine_image);
- for (y=0; y < (ssize_t) combine_image->rows; y++)
- {
- CacheView
- *image_view;
-
- const Image
- *next;
-
- Quantum
- *pixels;
-
- register const Quantum
- *restrict p;
-
- register Quantum
- *restrict q;
-
- register ssize_t
- i;
-
- if (status == MagickFalse)
- continue;
- pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
- 1,exception);
- if (pixels == (Quantum *) NULL)
- {
- status=MagickFalse;
- continue;
- }
- next=image;
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- PixelChannel
- channel;
-
- PixelTrait
- combine_traits,
- traits;
-
- register ssize_t
- x;
-
- if (next == (Image *) NULL)
- continue;
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
- combine_traits=GetPixelChannelMapTraits(combine_image,channel);
- if ((traits == UndefinedPixelTrait) ||
- (combine_traits == UndefinedPixelTrait))
- continue;
- image_view=AcquireCacheView(next);
- p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
- if (p == (const Quantum *) NULL)
- continue;
- q=pixels;
- for (x=0; x < (ssize_t) combine_image->columns; x++)
- {
- if (x < (ssize_t) image->columns)
- {
- q[i]=GetPixelGray(image,p);
- p+=GetPixelChannels(image);
- }
- q+=GetPixelChannels(combine_image);
- }
- image_view=DestroyCacheView(image_view);
- next=GetNextImageInList(next);
- if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
- status=MagickFalse;
- if (image->progress_monitor != (MagickProgressMonitor) NULL)
- {
- MagickBooleanType
- proceed;
-
- proceed=SetImageProgress(image,CombineImageTag,progress++,
- combine_image->rows);
- if (proceed == MagickFalse)
- status=MagickFalse;
- }
- }
- }
- combine_view=DestroyCacheView(combine_view);
- if (status == MagickFalse)
- combine_image=DestroyImage(combine_image);
- return(combine_image);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% D e s t r o y I m a g e %
% %
% %
image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
DestroyBlob(image);
if (image->semaphore != (SemaphoreInfo *) NULL)
- DestroySemaphoreInfo(&image->semaphore);
+ RelinquishSemaphoreInfo(&image->semaphore);
image->signature=(~MagickSignature);
image=(Image *) RelinquishMagickMemory(image);
return(image);
% %
% %
% %
-% G e t I m a g e A l p h a C h a n n e l %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
-% not activated. That is, the image is RGB rather than RGBA or CMYK rather
-% than CMYKA.
-%
-% The format of the GetImageAlphaChannel method is:
-%
-% MagickBooleanType GetImageAlphaChannel(const Image *image)
-%
-% A description of each parameter follows:
-%
-% o image: the image.
-%
-*/
-MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
-{
- assert(image != (const Image *) NULL);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- assert(image->signature == MagickSignature);
- return(image->matte);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% G e t I m a g e I n f o %
% %
% %
*/
MagickExport void GetImageInfo(ImageInfo *image_info)
{
- const char
+ char
*synchronize;
ExceptionInfo
image_info->dither=MagickTrue;
synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
if (synchronize != (const char *) NULL)
- image_info->synchronize=IsMagickTrue(synchronize);
+ {
+ image_info->synchronize=IsStringTrue(synchronize);
+ synchronize=DestroyString(synchronize);
+ }
exception=AcquireExceptionInfo();
(void) QueryColorCompliance(BackgroundColor,AllCompliance,
&image_info->background_color,exception);
if (mask_image == (Image *) NULL)
return((Image *) NULL);
status=MagickTrue;
- mask_image->colorspace=GRAYColorspace;
- mask_image->mask=MagickFalse;
- image_view=AcquireCacheView(image);
- mask_view=AcquireCacheView(mask_image);
+ (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
+ mask_image->read_mask=MagickFalse;
+ image_view=AcquireVirtualCacheView(image,exception);
+ mask_view=AcquireAuthenticCacheView(mask_image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelGray(mask_image,GetPixelMask(image,p),q);
+ SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(mask_image);
}
}
mask_view=DestroyCacheView(mask_view);
image_view=DestroyCacheView(image_view);
+ if (status == MagickFalse)
+ mask_image=DestroyImage(mask_image);
return(mask_image);
}
\f
%
% The format of the InterpretImageFilename method is:
%
-% size_t InterpretImageFilename(const ImageInfo *image_info,
-% Image *image,const char *format,int value,char *filename,
-% ExceptionInfo *exception)
+% size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
+% const char *format,int value,char *filename,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
/*
Image option.
*/
+ /* FUTURE: Compare update with code from InterpretImageProperties()
+ Note that a 'filename:' property should not need depth recursion.
+ */
if (strchr(p,']') == (char *) NULL)
break;
depth=1;
if (LocaleNCompare(pattern,"filename:",9) != 0)
break;
value=(const char *) NULL;
+#if 0
+ // FUTURE: remove this code. -- Anthony 29 Arpil 2012
+ // Removed as GetMagickProperty() will will never match a "filename:"
+ // string as this is not a 'known' image property.
+ //
if ((image_info != (const ImageInfo *) NULL) &&
(image != (const Image *) NULL))
value=GetMagickProperty(image_info,image,pattern,exception);
else
- if (image != (Image *) NULL)
- value=GetImageProperty(image,pattern,exception);
- else
- if (image_info != (ImageInfo *) NULL)
- value=GetImageOption(image_info,pattern);
+#endif
+ if (image != (Image *) NULL)
+ value=GetImageProperty(image,pattern,exception);
+ if ((value == (const char *) NULL) && (image != (Image *) NULL))
+ value=GetImageArtifact(image,pattern);
+ if ((value == (const char *) NULL) &&
+ (image_info != (ImageInfo *) NULL))
+ value=GetImageOption(image_info,pattern);
if (value == (const char *) NULL)
break;
q--;
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
status=MagickTrue;
- image_view=AcquireCacheView(image);
+ image_view=AcquireVirtualCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
- PixelInfo
- pixel;
-
register const Quantum
*p;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- PixelTrait
- traits;
-
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++)
{
- MagickRealType
+ double
pixel;
- traits=GetPixelChannelMapTraits(image,i);
+ PixelTrait
+ traits;
+
+ traits=GetPixelChannelTraits(image,(PixelChannel) i);
if (traits == UndefinedPixelTrait)
continue;
- pixel=(MagickRealType) p[i];
+ pixel=(double) p[i];
if ((pixel < 0.0) || (pixel > QuantumRange) ||
- (pixel != (QuantumAny) pixel))
+ (pixel != (double) ((QuantumAny) pixel)))
break;
}
p+=GetPixelChannels(image);
image->columns=width;
image->rows=height;
image->colorspace=background->colorspace;
- image->matte=background->matte;
+ image->alpha_trait=background->alpha_trait;
image->fuzz=background->fuzz;
image->depth=background->depth;
status=MagickTrue;
- image_view=AcquireCacheView(image);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
% %
% %
% %
-% S e p a r a t e I m a g e %
+% S e t I m a g e B a c k g r o u n d C o l o r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SeparateImage() separates a channel from the image and returns it as a
-% grayscale image.
+% SetImageBackgroundColor() initializes the image pixels to the image
+% background color. The background color is defined by the background_color
+% member of the image structure.
%
-% The format of the SeparateImage method is:
+% The format of the SetImage method is:
%
-% Image *SeparateImage(const Image *image,const ChannelType channel,
+% MagickBooleanType SetImageBackgroundColor(Image *image,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image: the image.
%
-% o channel: the image channel.
-%
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport Image *SeparateImage(const Image *image,
- const ChannelType channel_type,ExceptionInfo *exception)
+MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
+ ExceptionInfo *exception)
{
-#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
-#define SeparateImageTag "Separate/Image"
-
CacheView
- *image_view,
- *separate_view;
-
- Image
- *separate_image;
+ *image_view;
MagickBooleanType
status;
- MagickOffsetType
- progress;
-
ssize_t
y;
- /*
- Initialize spread image attributes.
- */
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
- separate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
- exception);
- if (separate_image == (Image *) NULL)
- return((Image *) NULL);
- if (SetImageStorageClass(separate_image,DirectClass,exception) == MagickFalse)
- {
- separate_image=DestroyImage(separate_image);
- return((Image *) NULL);
- }
- separate_image->colorspace=GRAYColorspace;
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+ assert(image->signature == MagickSignature);
+ if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+ return(MagickFalse);
+ if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
+ (IsGrayColorspace(image->colorspace) != MagickFalse))
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
+ if ((image->background_color.alpha_trait == BlendPixelTrait) &&
+ (image->alpha_trait != BlendPixelTrait))
+ (void) SetImageAlpha(image,OpaqueAlpha,exception);
/*
- Separate image.
+ Set image background color.
*/
status=MagickTrue;
- progress=0;
- image_view=AcquireCacheView(image);
- separate_view=AcquireCacheView(separate_image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static) shared(progress,status)
-#endif
+ image_view=AcquireAuthenticCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
- register const Quantum
- *restrict p;
-
register Quantum
*restrict q;
if (status == MagickFalse)
continue;
- p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
- q=QueueCacheViewAuthenticPixels(separate_view,0,y,separate_image->columns,1,
- exception);
- if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
+ q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+ if (q == (Quantum *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
- if (GetPixelMask(image,p) != 0)
- {
- p+=GetPixelChannels(image);
- q+=GetPixelChannels(separate_image);
- continue;
- }
- SetPixelChannel(separate_image,GrayPixelChannel,0,q);
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
- if ((traits == UndefinedPixelTrait) ||
- (GetChannelBit(channel_type,channel) == 0))
- continue;
- SetPixelChannel(separate_image,GrayPixelChannel,p[i],q);
- }
- p+=GetPixelChannels(image);
- q+=GetPixelChannels(separate_image);
+ SetPixelInfoPixel(image,&image->background_color,q);
+ q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(separate_view,exception) == MagickFalse)
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
- if (image->progress_monitor != (MagickProgressMonitor) NULL)
- {
- MagickBooleanType
- proceed;
-
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_SeparateImage)
-#endif
- proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
- status=MagickFalse;
- }
}
- separate_view=DestroyCacheView(separate_view);
image_view=DestroyCacheView(image_view);
- return(separate_image);
+ return(status);
}
\f
/*
% %
% %
% %
-% S e p a r a t e I m a g e s %
+% S e t I m a g e C h a n n e l M a s k %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SeparateImages() returns a separate grayscale image for each channel
-% specified.
+% SetImageChannelMask() sets the image channel mask from the specified channel
+% mask.
%
-% The format of the SeparateImages method is:
+% The format of the SetImageChannelMask method is:
%
-% MagickBooleanType SeparateImages(const Image *image,
-% ExceptionInfo *exception)
+% ChannelType SetImageChannelMask(Image *image,
+% const ChannelType channel_mask)
%
% A description of each parameter follows:
%
% o image: the image.
%
-% o exception: return any errors or warnings in this structure.
+% o channel_mask: the channel mask.
%
*/
-MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
+MagickExport ChannelType SetImageChannelMask(Image *image,
+ const ChannelType channel_mask)
{
- Image
- *images,
- *separate_image;
-
- register ssize_t
- i;
-
- assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- images=NewImageList();
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- PixelChannel
- channel;
+ ChannelType
+ mask;
- PixelTrait
- traits;
-
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
- if ((traits == UndefinedPixelTrait) ||
- ((traits & UpdatePixelTrait) == 0))
- continue;
- separate_image=SeparateImage(image,(ChannelType) (1 << channel),exception);
- if (separate_image != (Image *) NULL)
- AppendImageToList(&images,separate_image);
- }
- return(images);
+ mask=image->channel_mask;
+ image->channel_mask=channel_mask;
+ SetPixelChannelMask(image,channel_mask);
+ return(mask);
}
\f
/*
% %
% %
% %
-% S e t I m a g e A l p h a C h a n n e l %
+% S e t I m a g e C o l o r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
-% channel.
+% SetImageColor() set the entire image canvas to the specified color.
%
-% The format of the SetImageAlphaChannel method is:
-%
-% MagickBooleanType SetImageAlphaChannel(Image *image,
-% const AlphaChannelType alpha_type,ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o image: the image.
-%
-% o alpha_type: The alpha channel type: ActivateAlphaChannel,
-% CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
-% OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
-% TransparentAlphaChannel.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-
-static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
- const MagickRealType alpha,const Quantum *q,const MagickRealType beta,
- Quantum *composite)
-{
- MagickRealType
- Da,
- gamma,
- Sa;
-
- register ssize_t
- i;
-
- /*
- Compose pixel p over pixel q with the given alpha.
- */
- Sa=QuantumScale*alpha;
- Da=QuantumScale*beta,
- gamma=Sa*(-Da)+Sa+Da;
- gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelMapChannel(image,i);
- traits=GetPixelChannelMapTraits(image,channel);
- if (traits == UndefinedPixelTrait)
- continue;
- switch (channel)
- {
- case RedPixelChannel:
- {
- composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
- beta,(MagickRealType) p->red,alpha));
- break;
- }
- case GreenPixelChannel:
- {
- composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
- beta,(MagickRealType) p->green,alpha));
- break;
- }
- case BluePixelChannel:
- {
- composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
- beta,(MagickRealType) p->blue,alpha));
- break;
- }
- case BlackPixelChannel:
- {
- composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
- beta,(MagickRealType) p->black,alpha));
- break;
- }
- case AlphaPixelChannel:
- {
- composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
- break;
- }
- default:
- break;
- }
- }
-}
-
-MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
- const AlphaChannelType alpha_type,ExceptionInfo *exception)
-{
- MagickBooleanType
- status;
-
- assert(image != (Image *) NULL);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- assert(image->signature == MagickSignature);
- status=MagickTrue;
- switch (alpha_type)
- {
- case ActivateAlphaChannel:
- {
- image->matte=MagickTrue;
- break;
- }
- case BackgroundAlphaChannel:
- {
- CacheView
- *image_view;
-
- ssize_t
- y;
-
- /*
- Set transparent pixels to background color.
- */
- if (image->matte == MagickFalse)
- break;
- if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
- break;
- image_view=AcquireCacheView(image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status)
-#endif
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- register Quantum
- *restrict q;
-
- register ssize_t
- x;
-
- if (status == MagickFalse)
- continue;
- q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
- exception);
- if (q == (Quantum *) NULL)
- {
- status=MagickFalse;
- continue;
- }
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- if (GetPixelAlpha(image,q) == TransparentAlpha)
- SetPixelInfoPixel(image,&image->background_color,q);
- q+=GetPixelChannels(image);
- }
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- status=MagickFalse;
- }
- image_view=DestroyCacheView(image_view);
- return(status);
- }
- case CopyAlphaChannel:
- case ShapeAlphaChannel:
- {
- /*
- Copy pixel intensity to the alpha channel.
- */
- status=CompositeImage(image,IntensityCompositeOp,image,0,0,exception);
- if (alpha_type == ShapeAlphaChannel)
- (void) LevelImageColors(image,&image->background_color,
- &image->background_color,MagickTrue,exception);
- break;
- }
- case DeactivateAlphaChannel:
- {
- image->matte=MagickFalse;
- break;
- }
- case ExtractAlphaChannel:
- {
- status=CompositeImage(image,AlphaCompositeOp,image,0,0,exception);
- image->matte=MagickFalse;
- break;
- }
- case OpaqueAlphaChannel:
- {
- status=SetImageAlpha(image,OpaqueAlpha,exception);
- break;
- }
- case RemoveAlphaChannel:
- {
- CacheView
- *image_view;
-
- ssize_t
- y;
-
- /*
- Remove transparency.
- */
- if (image->matte == MagickFalse)
- break;
- if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
- break;
- image_view=AcquireCacheView(image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status)
-#endif
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- register Quantum
- *restrict q;
-
- register ssize_t
- x;
-
- if (status == MagickFalse)
- continue;
- q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
- exception);
- if (q == (Quantum *) NULL)
- {
- status=MagickFalse;
- continue;
- }
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- FlattenPixelInfo(image,&image->background_color,
- image->background_color.alpha,q,(MagickRealType)
- GetPixelAlpha(image,q),q);
- q+=GetPixelChannels(image);
- }
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- status=MagickFalse;
- }
- image_view=DestroyCacheView(image_view);
- image->matte=image->background_color.matte;
- return(status);
- }
- case SetAlphaChannel:
- {
- if (image->matte == MagickFalse)
- status=SetImageAlpha(image,OpaqueAlpha,exception);
- break;
- }
- case TransparentAlphaChannel:
- {
- status=SetImageAlpha(image,TransparentAlpha,exception);
- break;
- }
- case UndefinedAlphaChannel:
- break;
- }
- if (status == MagickFalse)
- return(status);
- return(SyncImagePixelCache(image,exception));
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-% S e t I m a g e B a c k g r o u n d C o l o r %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% SetImageBackgroundColor() initializes the image pixels to the image
-% background color. The background color is defined by the background_color
-% member of the image structure.
-%
-% The format of the SetImage method is:
-%
-% MagickBooleanType SetImageBackgroundColor(Image *image,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o image: the image.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
- ExceptionInfo *exception)
-{
- CacheView
- *image_view;
-
- MagickBooleanType
- status;
-
- ssize_t
- y;
-
- assert(image != (Image *) NULL);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- assert(image->signature == MagickSignature);
- if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
- return(MagickFalse);
- if ((image->border_color.matte != MagickFalse) &&
- (image->matte == MagickFalse))
- (void) SetImageAlpha(image,OpaqueAlpha,exception);
- /*
- Set image background color.
- */
- status=MagickTrue;
- image_view=AcquireCacheView(image);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- register Quantum
- *restrict q;
-
- register ssize_t
- x;
-
- if (status == MagickFalse)
- continue;
- q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
- if (q == (Quantum *) NULL)
- {
- status=MagickFalse;
- continue;
- }
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- SetPixelInfoPixel(image,&image->background_color,q);
- q+=GetPixelChannels(image);
- }
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- status=MagickFalse;
- }
- image_view=DestroyCacheView(image_view);
- return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-% S e t I m a g e C o l o r %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% SetImageColor() set the entire image canvas to the specified color.
-%
-% The format of the SetImageColor method is:
+% The format of the SetImageColor method is:
%
% MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
% ExeptionInfo *exception)
assert(image->signature == MagickSignature);
assert(color != (const PixelInfo *) NULL);
image->colorspace=color->colorspace;
- image->matte=color->matte;
+ image->alpha_trait=color->alpha_trait;
image->fuzz=color->fuzz;
image->depth=color->depth;
status=MagickTrue;
- image_view=AcquireCacheView(image);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
+% SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
% It is set to a type of image format based on the prefix or suffix of the
-% filename. For example, `ps:image' returns PS indicating a Postscript image.
-% JPEG is returned for this filename: `image.jpg'. The filename prefix has
+% filename. For example, 'ps:image' returns PS indicating a Postscript image.
+% JPEG is returned for this filename: 'image.jpg'. The filename prefix has
% precendence over the suffix. Use an optional index enclosed in brackets
% after a file name to specify a desired scene of a multi-resolution image
% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
*subimage='\0';
- if (frames == 0)
+ GetPathComponent(image_info->filename,SubimagePath,subimage);
+ if (*subimage != '\0')
{
- GetPathComponent(image_info->filename,SubimagePath,subimage);
- if (*subimage != '\0')
+ /*
+ Look for scene specification (e.g. img0001.pcd[4]).
+ */
+ if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
{
- /*
- Look for scene specification (e.g. img0001.pcd[4]).
- */
- if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
- {
- if (IsGeometry(subimage) != MagickFalse)
- (void) CloneString(&image_info->extract,subimage);
- }
- else
- {
- size_t
- first,
- last;
-
- (void) CloneString(&image_info->scenes,subimage);
- image_info->scene=StringToUnsignedLong(image_info->scenes);
- image_info->number_scenes=image_info->scene;
- p=image_info->scenes;
- for (q=(char *) image_info->scenes; *q != '\0'; p++)
- {
- while ((isspace((int) ((unsigned char) *p)) != 0) ||
- (*p == ','))
- p++;
- first=(size_t) strtol(p,&q,10);
- last=first;
- while (isspace((int) ((unsigned char) *q)) != 0)
- q++;
- if (*q == '-')
- last=(size_t) strtol(q+1,&q,10);
- if (first > last)
- Swap(first,last);
- if (first < image_info->scene)
- image_info->scene=first;
- if (last > image_info->number_scenes)
- image_info->number_scenes=last;
- p=q;
- }
- image_info->number_scenes-=image_info->scene-1;
- }
+ if (IsGeometry(subimage) != MagickFalse)
+ (void) CloneString(&image_info->extract,subimage);
+ }
+ else
+ {
+ size_t
+ first,
+ last;
+
+ (void) CloneString(&image_info->scenes,subimage);
+ image_info->scene=StringToUnsignedLong(image_info->scenes);
+ image_info->number_scenes=image_info->scene;
+ p=image_info->scenes;
+ for (q=(char *) image_info->scenes; *q != '\0'; p++)
+ {
+ while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
+ p++;
+ first=(size_t) strtol(p,&q,10);
+ last=first;
+ while (isspace((int) ((unsigned char) *q)) != 0)
+ q++;
+ if (*q == '-')
+ last=(size_t) strtol(q+1,&q,10);
+ if (first > last)
+ Swap(first,last);
+ if (first < image_info->scene)
+ image_info->scene=first;
+ if (last > image_info->number_scenes)
+ image_info->number_scenes=last;
+ p=q;
+ }
+ image_info->number_scenes-=image_info->scene-1;
}
}
*extension='\0';
}
(void) ResetMagickMemory(magick,0,sizeof(magick));
count=ReadBlob(image,2*MaxTextExtent,magick);
+ (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
(void) CloseBlob(image);
image=DestroyImage(image);
/*
assert(image->signature == MagickSignature);
if (mask == (const Image *) NULL)
{
- image->mask=MagickFalse;
- return(MagickTrue);
+ image->read_mask=MagickFalse;
+ return(SyncImagePixelCache(image,exception));
}
+ image->read_mask=MagickTrue;
+ if (SyncImagePixelCache(image,exception) == MagickFalse)
+ return(MagickFalse);
status=MagickTrue;
- image->mask=MagickTrue;
- image_view=AcquireCacheView(image);
- mask_view=AcquireCacheView(mask);
+ mask_view=AcquireVirtualCacheView(mask,exception);
+ image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(mask,image,1,1)
+#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelMask(image,GetPixelGray(mask,p),q);
+ SetPixelReadMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
p+=GetPixelChannels(mask);
q+=GetPixelChannels(image);
}
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
assert(image->signature == MagickSignature);
- image->matte=MagickTrue;
+ image->alpha_trait=BlendPixelTrait;
status=MagickTrue;
- image_view=AcquireCacheView(image);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
% %
% %
% %
-% S e t I m a g e T y p e %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% SetImageType() sets the type of image. Choose from these types:
-%
-% Bilevel Grayscale GrayscaleMatte
-% Palette PaletteMatte TrueColor
-% TrueColorMatte ColorSeparation ColorSeparationMatte
-% OptimizeType
-%
-% The format of the SetImageType method is:
-%
-% MagickBooleanType SetImageType(Image *image,const ImageType type,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o image: the image.
-%
-% o type: Image type.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
- ExceptionInfo *exception)
-{
- const char
- *artifact;
-
- ImageInfo
- *image_info;
-
- MagickBooleanType
- status;
-
- QuantizeInfo
- *quantize_info;
-
- assert(image != (Image *) NULL);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- assert(image->signature == MagickSignature);
- status=MagickTrue;
- image_info=AcquireImageInfo();
- image_info->dither=image->dither;
- artifact=GetImageArtifact(image,"dither");
- if (artifact != (const char *) NULL)
- (void) SetImageOption(image_info,"dither",artifact);
- switch (type)
- {
- case BilevelType:
- {
- if (IsImageMonochrome(image,exception) == MagickFalse)
- {
- quantize_info=AcquireQuantizeInfo(image_info);
- quantize_info->number_colors=2;
- quantize_info->colorspace=GRAYColorspace;
- status=QuantizeImage(quantize_info,image,exception);
- quantize_info=DestroyQuantizeInfo(quantize_info);
- }
- image->matte=MagickFalse;
- break;
- }
- case GrayscaleType:
- {
- if (IsImageGray(image,exception) == MagickFalse)
- status=TransformImageColorspace(image,GRAYColorspace,exception);
- image->matte=MagickFalse;
- break;
- }
- case GrayscaleMatteType:
- {
- if (IsImageGray(image,exception) == MagickFalse)
- status=TransformImageColorspace(image,GRAYColorspace,exception);
- if (image->matte == MagickFalse)
- (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
- break;
- }
- case PaletteType:
- {
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- if ((image->storage_class == DirectClass) || (image->colors > 256))
- {
- quantize_info=AcquireQuantizeInfo(image_info);
- quantize_info->number_colors=256;
- status=QuantizeImage(quantize_info,image,exception);
- quantize_info=DestroyQuantizeInfo(quantize_info);
- }
- image->matte=MagickFalse;
- break;
- }
- case PaletteBilevelMatteType:
- {
- ChannelType
- channel_mask;
-
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- if (image->matte == MagickFalse)
- (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
- channel_mask=SetPixelChannelMask(image,AlphaChannel);
- (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
- (void) SetPixelChannelMask(image,channel_mask);
- quantize_info=AcquireQuantizeInfo(image_info);
- status=QuantizeImage(quantize_info,image,exception);
- quantize_info=DestroyQuantizeInfo(quantize_info);
- break;
- }
- case PaletteMatteType:
- {
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- if (image->matte == MagickFalse)
- (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
- quantize_info=AcquireQuantizeInfo(image_info);
- quantize_info->colorspace=TransparentColorspace;
- status=QuantizeImage(quantize_info,image,exception);
- quantize_info=DestroyQuantizeInfo(quantize_info);
- break;
- }
- case TrueColorType:
- {
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- if (image->storage_class != DirectClass)
- status=SetImageStorageClass(image,DirectClass,exception);
- image->matte=MagickFalse;
- break;
- }
- case TrueColorMatteType:
- {
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- if (image->storage_class != DirectClass)
- status=SetImageStorageClass(image,DirectClass,exception);
- if (image->matte == MagickFalse)
- (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
- break;
- }
- case ColorSeparationType:
- {
- if (image->colorspace != CMYKColorspace)
- {
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- status=TransformImageColorspace(image,CMYKColorspace,exception);
- }
- if (image->storage_class != DirectClass)
- status=SetImageStorageClass(image,DirectClass,exception);
- image->matte=MagickFalse;
- break;
- }
- case ColorSeparationMatteType:
- {
- if (image->colorspace != CMYKColorspace)
- {
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- status=TransformImageColorspace(image,sRGBColorspace,exception);
- status=TransformImageColorspace(image,CMYKColorspace,exception);
- }
- if (image->storage_class != DirectClass)
- status=SetImageStorageClass(image,DirectClass,exception);
- if (image->matte == MagickFalse)
- status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
- break;
- }
- case OptimizeType:
- case UndefinedType:
- break;
- }
- image->type=type;
- image_info=DestroyImageInfo(image_info);
- return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% S e t I m a g e V i r t u a l P i x e l M e t h o d %
% %
% %
GravityAdjustGeometry(left_image->columns,left_image->rows,
left_image->gravity,&left_geometry);
gap=right_image->columns;
- left_view=AcquireCacheView(left_image);
- right_view=AcquireCacheView(right_image);
+ left_view=AcquireVirtualCacheView(left_image,exception);
+ right_view=AcquireVirtualCacheView(right_image,exception);
for (y=0; y < (ssize_t) smush_image->rows; y++)
{
for (x=(ssize_t) left_image->columns-1; x > 0; x--)
GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
&top_geometry);
gap=bottom_image->rows;
- top_view=AcquireCacheView(top_image);
- bottom_view=AcquireCacheView(bottom_image);
+ top_view=AcquireVirtualCacheView(top_image,exception);
+ bottom_view=AcquireVirtualCacheView(bottom_image,exception);
for (x=0; x < (ssize_t) smush_image->columns; x++)
{
for (y=(ssize_t) top_image->rows-1; y > 0; y--)
{
#define SmushImageTag "Smush/Image"
- CacheView
- *smush_view;
-
const Image
*image;
*smush_image;
MagickBooleanType
- matte,
proceed,
status;
MagickOffsetType
n;
+ PixelTrait
+ alpha_trait;
+
RectangleInfo
geometry;
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=images;
- matte=image->matte;
+ alpha_trait=image->alpha_trait;
number_images=1;
width=image->columns;
height=image->rows;
next=GetNextImageInList(image);
for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
{
- if (next->matte != MagickFalse)
- matte=MagickTrue;
+ if (next->alpha_trait == BlendPixelTrait)
+ alpha_trait=BlendPixelTrait;
number_images++;
if (stack != MagickFalse)
{
smush_image=DestroyImage(smush_image);
return((Image *) NULL);
}
- smush_image->matte=matte;
+ smush_image->alpha_trait=alpha_trait;
(void) SetImageBackgroundColor(smush_image,exception);
status=MagickTrue;
x_offset=0;
y_offset=0;
- smush_view=AcquireCacheView(smush_image);
for (n=0; n < (MagickOffsetType) number_images; n++)
{
SetGeometry(smush_image,&geometry);
x_offset-=SmushXGap(smush_image,image,offset,exception);
y_offset-=geometry.y;
}
- status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
- exception);
+ status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
+ y_offset,exception);
proceed=SetImageProgress(image,SmushImageTag,n,number_images);
if (proceed == MagickFalse)
break;
smush_image->columns=(size_t) x_offset;
else
smush_image->rows=(size_t) y_offset;
- smush_view=DestroyCacheView(smush_view);
if (status == MagickFalse)
smush_image=DestroyImage(smush_image);
return(smush_image);
if ((size_t) index < image->colors)
return(index);
*range_exception=MagickTrue;
- return(0);
+ return((Quantum) 0);
}
MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
return(MagickFalse);
range_exception=MagickFalse;
status=MagickTrue;
- image_view=AcquireCacheView(image);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(range_exception,status)
+ #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
status=MagickFalse;
}
image_view=DestroyCacheView(image_view);
- if (range_exception != MagickFalse)
+ if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
"InvalidColormapIndex","`%s'",image->filename);
return(status);
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SyncImageSettings() syncs the image_info options into per-image attributes.
+% SyncImageSettings() syncs any image_info global options into per-image
+% attributes.
+%
+% Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
+% that operations and coders can find such settings. In IMv7 if a desired
+% per-image artifact is not set, then it will directly look for a global
+% option as a fallback, as such this copy is no longer needed, only the
+% link set up.
%
% The format of the SyncImageSettings method is:
%
MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
Image *image,ExceptionInfo *exception)
{
- char
- property[MaxTextExtent];
-
const char
- *option,
- *value;
+ *option;
GeometryInfo
geometry_info;
if (option != (const char *) NULL)
(void) QueryColorCompliance(option,AllCompliance,&image->background_color,
exception);
- option=GetImageOption(image_info,"bias");
- if (option != (const char *) NULL)
- image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
option=GetImageOption(image_info,"black-point-compensation");
if (option != (const char *) NULL)
image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
if (option != (const char *) NULL)
(void) QueryColorCompliance(option,AllCompliance,&image->border_color,
exception);
+ option=GetImageOption(image_info,"channel");
+ if (option != (const char *) NULL)
+ (void) SetPixelChannelMask(image,(ChannelType)
+ ParseChannelOption(option));
/* FUTURE: do not sync compose to per-image compose setting here */
option=GetImageOption(image_info,"compose");
if (option != (const char *) NULL)
if (option != (const char *) NULL)
image->rendering_intent=(RenderingIntent) ParseCommandOption(
MagickIntentOptions,MagickFalse,option);
+ option=GetImageOption(image_info,"intensity");
+ if (option != (const char *) NULL)
+ image->intensity=(PixelIntensityMethod) ParseCommandOption(
+ MagickPixelIntensityOptions,MagickFalse,option);
option=GetImageOption(image_info,"interlace");
if (option != (const char *) NULL)
image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
image->chromaticity.white_point.y=image->chromaticity.white_point.x;
}
ResetImageOptionIterator(image_info);
- for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
+#if 0
{
- value=GetImageOption(image_info,option);
- if (value != (const char *) NULL)
- {
- (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
- (void) SetImageArtifact(image,property,value);
- }
- option=GetNextImageOption(image_info);
+ /* IMv6: Copy freeform global options into per-image artifacts, so
+ * various operations and coders can access them.
+ *
+ * This has a problem, as per-image artefacts may have been set in
+ * parenthesis, but may not be unset when parenthesis ends.
+ */
+ char
+ property[MaxTextExtent];
+
+ const char
+ *value;
+
+ for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
+ {
+ value=GetImageOption(image_info,option);
+ if (value != (const char *) NULL)
+ {
+ (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
+ (void) SetImageArtifact(image,property,value);
+ }
+ option=GetNextImageOption(image_info);
+ }
}
+#else
+ /* IMv7: pointer to allow the lookup of pre-image artefact will fallback to
+ a global option setting/define. This saves a lot of duplication of
+ global options into per-image artifacts, while ensuring only specifically
+ set per-image artifacts are preverved when parenthesis ends.
+
+ This pointer is never explictally freed, as it is only used as a back
+ reference, not as the main pointer to the image_info structure. Images
+ being removed from a image_info image list (or yet to be added to such),
+ should have this pointer reset to NULL.
+ */
+ image->image_info=image_info;
+#endif
return(MagickTrue);
}