43#include "MagickCore/studio.h"
44#include "MagickCore/cache-private.h"
45#include "MagickCore/channel.h"
46#include "MagickCore/colorspace-private.h"
47#include "MagickCore/composite-private.h"
48#include "MagickCore/enhance.h"
49#include "MagickCore/image.h"
50#include "MagickCore/list.h"
51#include "MagickCore/log.h"
52#include "MagickCore/monitor.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/option.h"
55#include "MagickCore/pixel-accessor.h"
56#include "MagickCore/resource_.h"
57#include "MagickCore/string-private.h"
58#include "MagickCore/thread-private.h"
59#include "MagickCore/token.h"
60#include "MagickCore/utility.h"
61#include "MagickCore/version.h"
116static MagickBooleanType ChannelImage(
Image *destination_image,
117 const PixelChannel destination_channel,
const ChannelFx channel_op,
118 const Image *source_image,
const PixelChannel source_channel,
138 height=MagickMin(source_image->rows,destination_image->rows);
139 width=MagickMin(source_image->columns,destination_image->columns);
140 source_view=AcquireVirtualCacheView(source_image,exception);
141 destination_view=AcquireAuthenticCacheView(destination_image,exception);
142#if defined(MAGICKCORE_OPENMP_SUPPORT)
143 #pragma omp parallel for schedule(static) shared(status) \
144 magick_number_threads(source_image,source_image,height,4)
146 for (y=0; y < (ssize_t) height; y++)
161 if (status == MagickFalse)
163 p=GetCacheViewVirtualPixels(source_view,0,y,source_image->columns,1,
165 q=GetCacheViewAuthenticPixels(destination_view,0,y,
166 destination_image->columns,1,exception);
167 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
172 destination_traits=GetPixelChannelTraits(destination_image,
173 destination_channel);
174 source_traits=GetPixelChannelTraits(source_image,source_channel);
175 if ((destination_traits == UndefinedPixelTrait) ||
176 (source_traits == UndefinedPixelTrait))
178 for (x=0; x < (ssize_t) width; x++)
180 if (channel_op == AssignChannelOp)
181 SetPixelChannel(destination_image,destination_channel,pixel,q);
183 SetPixelChannel(destination_image,destination_channel,
184 GetPixelChannel(source_image,source_channel,p),q);
185 p+=GetPixelChannels(source_image);
186 q+=GetPixelChannels(destination_image);
188 if (SyncCacheViewAuthenticPixels(destination_view,exception) == MagickFalse)
191 destination_view=DestroyCacheView(destination_view);
192 source_view=DestroyCacheView(source_view);
196MagickExport
Image *ChannelFxImage(
const Image *image,
const char *expression,
199#define ChannelFxImageTag "ChannelFx/Image"
202 channel_op = ExtractChannelOp;
208 token[MagickPathExtent] =
"";
227 destination_channel = RedPixelChannel;
232 assert(image != (
Image *) NULL);
233 assert(image->signature == MagickCoreSignature);
234 if (IsEventLogging() != MagickFalse)
235 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
237 assert(exception->signature == MagickCoreSignature);
240 destination_image=CloneImage(image,0,0,MagickTrue,exception);
241 if (destination_image == (
Image *) NULL)
242 return((
Image *) NULL);
243 if (expression == (
const char *) NULL)
244 return(destination_image);
245 status=SetImageStorageClass(destination_image,DirectClass,exception);
246 if (status == MagickFalse)
248 destination_image=GetLastImageInList(destination_image);
249 return((
Image *) NULL);
251 channel_mask=destination_image->channel_mask;
252 (void) GetNextToken(p,&p,MagickPathExtent,token);
253 while (*token !=
'\0')
268 (void) GetNextToken(p,&p,MagickPathExtent,token);
273 if (GetNextImageInList(source_image) != (
Image *) NULL)
274 source_image=GetNextImageInList(source_image);
275 (void) GetNextToken(p,&p,MagickPathExtent,token);
283 (void) SetPixelChannelMask(destination_image,channel_mask);
284 if ((channel_op == ExtractChannelOp) && (channels == 1))
286 (void) SetPixelMetaChannels(destination_image,0,exception);
287 (void) SetImageColorspace(destination_image,GRAYColorspace,
290 canvas=CloneImage(source_image,0,0,MagickTrue,exception);
291 if (canvas == (
Image *) NULL)
293 destination_image=DestroyImageList(destination_image);
294 return(destination_image);
296 AppendImageToList(&destination_image,canvas);
297 destination_image=GetLastImageInList(destination_image);
298 status=SetImageStorageClass(destination_image,DirectClass,exception);
299 if (status == MagickFalse)
301 destination_image=GetLastImageInList(destination_image);
302 return((
Image *) NULL);
304 (void) GetNextToken(p,&p,MagickPathExtent,token);
306 destination_channel=RedPixelChannel;
307 channel_mask=destination_image->channel_mask;
313 i=ParsePixelChannelOption(token);
314 source_channel=(PixelChannel) i;
315 traits=GetPixelChannelTraits(source_image,source_channel);
316 if (traits == UndefinedPixelTrait)
318 (void) ThrowMagickException(exception,GetMagickModule(),
319 CorruptImageError,
"MissingImageChannel",
"`%s'",token);
320 destination_image=DestroyImageList(destination_image);
321 return(destination_image);
323 channel_op=ExtractChannelOp;
324 (void) GetNextToken(p,&p,MagickPathExtent,token);
327 channel_op=ExchangeChannelOp;
328 (void) GetNextToken(p,&p,MagickPathExtent,token);
332 if (channel_op != ExchangeChannelOp)
333 channel_op=AssignChannelOp;
334 (void) GetNextToken(p,&p,MagickPathExtent,token);
338 if (channel_op != ExchangeChannelOp)
339 channel_op=TransferChannelOp;
340 (void) GetNextToken(p,&p,MagickPathExtent,token);
344 case AssignChannelOp:
345 case ExchangeChannelOp:
346 case TransferChannelOp:
348 if (channel_op == AssignChannelOp)
349 pixel=StringToDoubleInterval(token,(
double) QuantumRange+1.0);
352 i=ParsePixelChannelOption(token);
353 if (LocaleCompare(token,
"alpha") == 0)
354 destination_image->alpha_trait=BlendPixelTrait;
357 (void) ThrowMagickException(exception,GetMagickModule(),
358 OptionError,
"UnrecognizedChannelType",
"`%s'",token);
359 destination_image=DestroyImageList(destination_image);
360 return(destination_image);
363 destination_channel=(PixelChannel) i;
364 if (image->colorspace != UndefinedColorspace)
365 switch (destination_channel)
367 case RedPixelChannel:
368 case GreenPixelChannel:
369 case BluePixelChannel:
370 case BlackPixelChannel:
371 case AlphaPixelChannel:
372 case IndexPixelChannel:
374 case CompositeMaskPixelChannel:
376 destination_image->channels=(ChannelType)
377 (destination_image->channels | CompositeMaskChannel);
380 case ReadMaskPixelChannel:
382 destination_image->channels=(ChannelType)
383 (destination_image->channels | ReadMaskChannel);
386 case WriteMaskPixelChannel:
388 destination_image->channels=(ChannelType)
389 (destination_image->channels | WriteMaskChannel);
392 case MetaPixelChannels:
395 traits=GetPixelChannelTraits(destination_image,
396 destination_channel);
397 if (traits != UndefinedPixelTrait)
399 (void) SetPixelMetaChannels(destination_image,
400 GetPixelMetaChannels(destination_image)+1,exception);
401 traits=GetPixelChannelTraits(destination_image,
402 destination_channel);
403 if (traits == UndefinedPixelTrait)
405 (void) ThrowMagickException(exception,GetMagickModule(),
406 CorruptImageError,
"MissingImageChannel",
"`%s'",token);
407 destination_image=DestroyImageList(destination_image);
408 return(destination_image);
413 channel_mask=(ChannelType) (channel_mask |
414 (MagickLLConstant(1) << ParseChannelOption(token)));
415 (void) GetNextToken(p,&p,MagickPathExtent,token);
421 status=ChannelImage(destination_image,destination_channel,channel_op,
422 source_image,source_channel,ClampToQuantum(pixel),exception);
423 if (status == MagickFalse)
425 destination_image=DestroyImageList(destination_image);
429 if (channel_op == ExchangeChannelOp)
431 status=ChannelImage(destination_image,source_channel,channel_op,
432 source_image,destination_channel,ClampToQuantum(pixel),exception);
433 if (status == MagickFalse)
435 destination_image=DestroyImageList(destination_image);
442 case ExtractChannelOp:
444 channel_mask=(ChannelType) (channel_mask |
445 (MagickLLConstant(1) << destination_channel));
446 destination_channel=(PixelChannel) (destination_channel+1);
452 status=SetImageProgress(source_image,ChannelFxImageTag,p-expression,
454 if (status == MagickFalse)
457 if (destination_image == (
Image *) NULL)
458 return(destination_image);
459 (void) SetPixelChannelMask(destination_image,channel_mask);
460 if ((channel_op == ExtractChannelOp) && (channels == 1))
462 (void) SetPixelMetaChannels(destination_image,0,exception);
463 (void) SetImageColorspace(destination_image,GRAYColorspace,exception);
465 return(GetFirstImageInList(destination_image));
498MagickExport
Image *CombineImages(
const Image *image,
501#define CombineImageTag "Combine/Image"
521 assert(image != (
const Image *) NULL);
522 assert(image->signature == MagickCoreSignature);
523 if (IsEventLogging() != MagickFalse)
524 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
526 assert(exception->signature == MagickCoreSignature);
527 combine_image=CloneImage(image,0,0,MagickTrue,exception);
528 if (combine_image == (
Image *) NULL)
529 return((
Image *) NULL);
530 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
532 combine_image=DestroyImage(combine_image);
533 return((
Image *) NULL);
535 if (colorspace != UndefinedColorspace)
536 (void) SetImageColorspace(combine_image,colorspace,exception);
538 if (fabs(image->gamma-1.0) <= MagickEpsilon)
539 (void) SetImageColorspace(combine_image,RGBColorspace,exception);
541 (
void) SetImageColorspace(combine_image,sRGBColorspace,exception);
542 switch (combine_image->colorspace)
544 case UndefinedColorspace:
547 if (GetImageListLength(image) > 3)
548 combine_image->alpha_trait=BlendPixelTrait;
551 case LinearGRAYColorspace:
554 if (GetImageListLength(image) > 1)
555 combine_image->alpha_trait=BlendPixelTrait;
560 if (GetImageListLength(image) > 4)
561 combine_image->alpha_trait=BlendPixelTrait;
572 combine_view=AcquireAuthenticCacheView(combine_image,exception);
573#if defined(MAGICKCORE_OPENMP_SUPPORT)
574 #pragma omp parallel for schedule(static) shared(progress,status) \
575 magick_number_threads(combine_image,combine_image,combine_image->rows,4)
577 for (y=0; y < (ssize_t) combine_image->rows; y++)
595 if (status == MagickFalse)
597 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
599 if (pixels == (Quantum *) NULL)
605 for (i=0; i < (ssize_t) GetPixelChannels(combine_image); i++)
610 PixelChannel channel = GetPixelChannelChannel(combine_image,i);
611 PixelTrait traits = GetPixelChannelTraits(combine_image,channel);
612 if (traits == UndefinedPixelTrait)
614 if (next == (
Image *) NULL)
616 image_view=AcquireVirtualCacheView(next,exception);
617 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
618 if (p == (
const Quantum *) NULL)
621 for (x=0; x < (ssize_t) combine_image->columns; x++)
623 if (x < (ssize_t) next->columns)
625 q[i]=GetPixelIntensity(next,p);
626 p+=GetPixelChannels(next);
628 q+=GetPixelChannels(combine_image);
630 image_view=DestroyCacheView(image_view);
631 next=GetNextImageInList(next);
633 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
635 if (image->progress_monitor != (MagickProgressMonitor) NULL)
640#if defined(MAGICKCORE_OPENMP_SUPPORT)
644 proceed=SetImageProgress(image,CombineImageTag,progress,
645 combine_image->rows);
646 if (proceed == MagickFalse)
650 combine_view=DestroyCacheView(combine_view);
651 if (status == MagickFalse)
652 combine_image=DestroyImage(combine_image);
653 return(combine_image);
680MagickExport MagickBooleanType GetImageAlphaChannel(
const Image *image)
682 assert(image != (
const Image *) NULL);
683 if (IsEventLogging() != MagickFalse)
684 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
685 assert(image->signature == MagickCoreSignature);
686 return(image->alpha_trait != UndefinedPixelTrait ? MagickTrue : MagickFalse);
717MagickExport
Image *SeparateImage(
const Image *image,
720#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
721#define SeparateImageTag "Separate/Image"
742 assert(image != (
Image *) NULL);
743 assert(image->signature == MagickCoreSignature);
744 if (IsEventLogging() != MagickFalse)
745 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
747 assert(exception->signature == MagickCoreSignature);
748 separate_image=CloneImage(image,0,0,MagickTrue,exception);
749 if (separate_image == (
Image *) NULL)
750 return((
Image *) NULL);
751 if (SetImageStorageClass(separate_image,DirectClass,exception) == MagickFalse)
753 separate_image=DestroyImage(separate_image);
754 return((
Image *) NULL);
756 separate_image->alpha_trait=UndefinedPixelTrait;
757 (void) SetImageColorspace(separate_image,GRAYColorspace,exception);
758 separate_image->gamma=image->gamma;
764 image_view=AcquireVirtualCacheView(image,exception);
765 separate_view=AcquireAuthenticCacheView(separate_image,exception);
766#if defined(MAGICKCORE_OPENMP_SUPPORT)
767 #pragma omp parallel for schedule(static) shared(progress,status) \
768 magick_number_threads(image,image,image->rows,2)
770 for (y=0; y < (ssize_t) image->rows; y++)
781 if (status == MagickFalse)
783 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
784 q=QueueCacheViewAuthenticPixels(separate_view,0,y,separate_image->columns,1,
786 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
791 for (x=0; x < (ssize_t) image->columns; x++)
796 SetPixelChannel(separate_image,GrayPixelChannel,(Quantum) 0,q);
797 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
799 PixelChannel channel = GetPixelChannelChannel(image,i);
800 PixelTrait traits = GetPixelChannelTraits(image,channel);
801 if ((traits == UndefinedPixelTrait) ||
802 (GetChannelBit(channel_type,channel) == 0))
804 SetPixelChannel(separate_image,GrayPixelChannel,p[i],q);
806 p+=GetPixelChannels(image);
807 q+=GetPixelChannels(separate_image);
809 if (SyncCacheViewAuthenticPixels(separate_view,exception) == MagickFalse)
811 if (image->progress_monitor != (MagickProgressMonitor) NULL)
816#if defined(MAGICKCORE_OPENMP_SUPPORT)
820 proceed=SetImageProgress(image,SeparateImageTag,progress,image->rows);
821 if (proceed == MagickFalse)
825 separate_view=DestroyCacheView(separate_view);
826 image_view=DestroyCacheView(image_view);
827 (void) SetImageChannelMask(separate_image,AllChannels);
828 if (status == MagickFalse)
829 separate_image=DestroyImage(separate_image);
830 return(separate_image);
867 assert(image != (
Image *) NULL);
868 assert(image->signature == MagickCoreSignature);
869 if (IsEventLogging() != MagickFalse)
870 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
871 images=NewImageList();
872 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
874 PixelChannel channel = GetPixelChannelChannel(image,i);
875 PixelTrait traits = GetPixelChannelTraits(image,channel);
876 if ((traits == UndefinedPixelTrait) || ((traits & UpdatePixelTrait) == 0))
878 separate_image=SeparateImage(image,(ChannelType)
879 (MagickLLConstant(1) << channel),exception);
880 if (separate_image != (
Image *) NULL)
881 AppendImageToList(&images,separate_image);
883 if (images == (
Image *) NULL)
884 images=SeparateImage(image,UndefinedChannel,exception);
921static inline void FlattenPixelInfo(
const Image *image,
const PixelInfo *p,
922 const double alpha,
const Quantum *q,
const double beta,Quantum *composite)
935 Sa=QuantumScale*alpha;
936 Da=QuantumScale*beta,
937 gamma=Sa*(-Da)+Sa+Da;
938 gamma=PerceptibleReciprocal(gamma);
939 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
941 PixelChannel channel = GetPixelChannelChannel(image,i);
942 PixelTrait traits = GetPixelChannelTraits(image,channel);
943 if (traits == UndefinedPixelTrait)
947 case RedPixelChannel:
949 composite[i]=ClampToQuantum(gamma*MagickOver_((
double) q[i],beta,
950 (
double) p->red,alpha));
953 case GreenPixelChannel:
955 composite[i]=ClampToQuantum(gamma*MagickOver_((
double) q[i],beta,
956 (
double) p->green,alpha));
959 case BluePixelChannel:
961 composite[i]=ClampToQuantum(gamma*MagickOver_((
double) q[i],beta,
962 (
double) p->blue,alpha));
965 case BlackPixelChannel:
967 composite[i]=ClampToQuantum(gamma*MagickOver_((
double) q[i],beta,
968 (
double) p->black,alpha));
971 case AlphaPixelChannel:
973 composite[i]=ClampToQuantum((
double) QuantumRange*(Sa*(-Da)+Sa+Da));
982MagickExport MagickBooleanType SetImageAlphaChannel(
Image *image,
983 const AlphaChannelOption alpha_type,
ExceptionInfo *exception)
994 assert(image != (
Image *) NULL);
995 if (IsEventLogging() != MagickFalse)
996 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
997 assert(image->signature == MagickCoreSignature);
1001 case ActivateAlphaChannel:
1003 if ((image->alpha_trait & BlendPixelTrait) != 0)
1005 image->alpha_trait=BlendPixelTrait;
1008 case AssociateAlphaChannel:
1013 status=SetImageStorageClass(image,DirectClass,exception);
1014 if (status == MagickFalse)
1016 image_view=AcquireAuthenticCacheView(image,exception);
1017#if defined(MAGICKCORE_OPENMP_SUPPORT)
1018 #pragma omp parallel for schedule(static) shared(status) \
1019 magick_number_threads(image,image,image->rows,2)
1021 for (y=0; y < (ssize_t) image->rows; y++)
1029 if (status == MagickFalse)
1031 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
1033 if (q == (Quantum *) NULL)
1038 for (x=0; x < (ssize_t) image->columns; x++)
1046 gamma=QuantumScale*(double) GetPixelAlpha(image,q);
1047 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1049 PixelChannel channel = GetPixelChannelChannel(image,i);
1050 PixelTrait traits = GetPixelChannelTraits(image,channel);
1051 if (channel == AlphaPixelChannel)
1053 if ((traits & UpdatePixelTrait) == 0)
1055 q[i]=ClampToQuantum(gamma*(
double) q[i]);
1057 q+=GetPixelChannels(image);
1059 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1062 image_view=DestroyCacheView(image_view);
1063 image->alpha_trait=CopyPixelTrait;
1066 case BackgroundAlphaChannel:
1071 if ((image->alpha_trait & BlendPixelTrait) == 0)
1073 status=SetImageStorageClass(image,DirectClass,exception);
1074 if (status == MagickFalse)
1076 image_view=AcquireAuthenticCacheView(image,exception);
1077#if defined(MAGICKCORE_OPENMP_SUPPORT)
1078 #pragma omp parallel for schedule(static) shared(status) \
1079 magick_number_threads(image,image,image->rows,2)
1081 for (y=0; y < (ssize_t) image->rows; y++)
1089 if (status == MagickFalse)
1091 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
1093 if (q == (Quantum *) NULL)
1098 for (x=0; x < (ssize_t) image->columns; x++)
1100 if (GetPixelAlpha(image,q) == TransparentAlpha)
1102 SetPixelViaPixelInfo(image,&image->background_color,q);
1103 SetPixelChannel(image,AlphaPixelChannel,TransparentAlpha,q);
1105 q+=GetPixelChannels(image);
1107 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1110 image_view=DestroyCacheView(image_view);
1113 case CopyAlphaChannel:
1115 image->alpha_trait=UpdatePixelTrait;
1116 status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
1120 case DeactivateAlphaChannel:
1122 if ((image->alpha_trait & BlendPixelTrait) == 0)
1123 status=SetImageAlpha(image,OpaqueAlpha,exception);
1124 image->alpha_trait=CopyPixelTrait;
1127 case DisassociateAlphaChannel:
1132 status=SetImageStorageClass(image,DirectClass,exception);
1133 if (status == MagickFalse)
1135 image->alpha_trait=BlendPixelTrait;
1136 image_view=AcquireAuthenticCacheView(image,exception);
1137#if defined(MAGICKCORE_OPENMP_SUPPORT)
1138 #pragma omp parallel for schedule(static) shared(status) \
1139 magick_number_threads(image,image,image->rows,2)
1141 for (y=0; y < (ssize_t) image->rows; y++)
1149 if (status == MagickFalse)
1151 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
1153 if (q == (Quantum *) NULL)
1158 for (x=0; x < (ssize_t) image->columns; x++)
1167 Sa=QuantumScale*(double) GetPixelAlpha(image,q);
1168 gamma=PerceptibleReciprocal(Sa);
1169 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1171 PixelChannel channel = GetPixelChannelChannel(image,i);
1172 PixelTrait traits = GetPixelChannelTraits(image,channel);
1173 if (channel == AlphaPixelChannel)
1175 if ((traits & UpdatePixelTrait) == 0)
1177 q[i]=ClampToQuantum(gamma*(
double) q[i]);
1179 q+=GetPixelChannels(image);
1181 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1184 image_view=DestroyCacheView(image_view);
1185 image->alpha_trait=UndefinedPixelTrait;
1188 case DiscreteAlphaChannel:
1190 if ((image->alpha_trait & BlendPixelTrait) == 0)
1191 status=SetImageAlpha(image,OpaqueAlpha,exception);
1192 image->alpha_trait=UpdatePixelTrait;
1195 case ExtractAlphaChannel:
1197 status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
1199 image->alpha_trait=UndefinedPixelTrait;
1202 case OffAlphaChannel:
1204 if ((image->alpha_trait & BlendPixelTrait) == 0)
1206 image->alpha_trait=UndefinedPixelTrait;
1209 case OffIfOpaqueAlphaChannel:
1212 opaque = MagickTrue;
1217 if ((image->alpha_trait & BlendPixelTrait) == 0)
1219 image_view=AcquireVirtualCacheView(image,exception);
1220#if defined(MAGICKCORE_OPENMP_SUPPORT)
1221 #pragma omp parallel for schedule(static) shared(opaque,status) \
1222 magick_number_threads(image,image,image->rows,2)
1224 for (y=0; y < (ssize_t) image->rows; y++)
1232 if ((status == MagickFalse) || (opaque == MagickFalse))
1234 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1235 if (p == (
const Quantum *) NULL)
1240 for (x=0; x < (ssize_t) image->columns; x++)
1242 if (GetPixelAlpha(image,p) != OpaqueAlpha)
1247 p+=GetPixelChannels(image);
1250 image_view=DestroyCacheView(image_view);
1251 if (opaque != MagickFalse)
1252 image->alpha_trait=UndefinedPixelTrait;
1255 case OnAlphaChannel:
1257 if ((image->alpha_trait & BlendPixelTrait) == 0)
1258 status=SetImageAlpha(image,OpaqueAlpha,exception);
1259 image->alpha_trait=BlendPixelTrait;
1262 case OpaqueAlphaChannel:
1264 status=SetImageAlpha(image,OpaqueAlpha,exception);
1267 case RemoveAlphaChannel:
1272 if ((image->alpha_trait & BlendPixelTrait) == 0)
1274 status=SetImageStorageClass(image,DirectClass,exception);
1275 if (status == MagickFalse)
1277 image_view=AcquireAuthenticCacheView(image,exception);
1278#if defined(MAGICKCORE_OPENMP_SUPPORT)
1279 #pragma omp parallel for schedule(static) shared(status) \
1280 magick_number_threads(image,image,image->rows,2)
1282 for (y=0; y < (ssize_t) image->rows; y++)
1290 if (status == MagickFalse)
1292 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
1294 if (q == (Quantum *) NULL)
1299 for (x=0; x < (ssize_t) image->columns; x++)
1301 FlattenPixelInfo(image,&image->background_color,
1302 image->background_color.alpha,q,(
double) GetPixelAlpha(image,q),q);
1303 q+=GetPixelChannels(image);
1305 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1308 image_view=DestroyCacheView(image_view);
1309 image->alpha_trait=image->background_color.alpha_trait;
1312 case SetAlphaChannel:
1314 if ((image->alpha_trait & BlendPixelTrait) == 0)
1315 status=SetImageAlpha(image,OpaqueAlpha,exception);
1318 case ShapeAlphaChannel:
1326 ConformPixelInfo(image,&image->background_color,&background,exception);
1327 background.alpha_trait=BlendPixelTrait;
1328 image->alpha_trait=BlendPixelTrait;
1329 status=SetImageStorageClass(image,DirectClass,exception);
1330 if (status == MagickFalse)
1332 image_view=AcquireAuthenticCacheView(image,exception);
1333#if defined(MAGICKCORE_OPENMP_SUPPORT)
1334 #pragma omp parallel for schedule(static) shared(status) \
1335 magick_number_threads(image,image,image->rows,2)
1337 for (y=0; y < (ssize_t) image->rows; y++)
1348 if (status == MagickFalse)
1350 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
1352 if (q == (Quantum *) NULL)
1358 for (x=0; x < (ssize_t) image->columns; x++)
1360 pixel.alpha=GetPixelIntensity(image,q);
1361 SetPixelViaPixelInfo(image,&pixel,q);
1362 q+=GetPixelChannels(image);
1364 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1367 image_view=DestroyCacheView(image_view);
1370 case TransparentAlphaChannel:
1372 status=SetImageAlpha(image,TransparentAlpha,exception);
1375 case UndefinedAlphaChannel:
1378 if (status == MagickFalse)
1380 (void) SetPixelChannelMask(image,image->channel_mask);
1381 return(SyncImagePixelCache(image,exception));