2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % CCCC H H AAA N N N N EEEEE L %
7 % C H H A A NN N NN N E L %
8 % C HHHHH AAAAA N N N N N N RRR L %
9 % C H H A A N NN N NN E L %
10 % CCCC H H A A N N N N EEEEE LLLLL %
13 % MagickCore Image Channel Methods %
20 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/cache-private.h"
45 #include "MagickCore/colorspace-private.h"
46 #include "MagickCore/composite-private.h"
47 #include "MagickCore/enhance.h"
48 #include "MagickCore/image.h"
49 #include "MagickCore/list.h"
50 #include "MagickCore/log.h"
51 #include "MagickCore/monitor.h"
52 #include "MagickCore/monitor-private.h"
53 #include "MagickCore/option.h"
54 #include "MagickCore/pixel-accessor.h"
55 #include "MagickCore/pixel-private.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"
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 % C h a n n e l F x I m a g e %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 % ChannelFxImage() applies a channel expression to the specified image. The
75 % expression consists of one or more channels, either mnemonic or numeric (e.g.
76 % red, 1), separated by actions as follows:
78 % <=> exchange two channels (e.g. red<=>blue)
79 % => copy one channel to another channel (e.g. red=>green)
80 % = assign a constant value to a channel (e.g. red=50%)
81 % , write new image channels in the specified order (e.g. red, green)
82 % | add a new output image for the next set of channel operations
83 % ; move to the next input image for the source of channel data
85 % For example, to create 3 grayscale images from the red, green, and blue
86 % channels of an image, use:
88 % -channel-fx "red; green; blue"
90 % A channel without an operation symbol implies separate (i.e, semicolon).
92 % The format of the ChannelFxImage method is:
94 % Image *ChannelFxImage(const Image *image,const char *expression,
95 % ExceptionInfo *exception)
97 % A description of each parameter follows:
101 % o expression: A channel expression.
103 % o exception: return any errors or warnings in this structure.
115 static inline size_t MagickMin(const size_t x,const size_t y)
122 static MagickBooleanType ChannelImage(Image *destination_image,
123 const PixelChannel destination_channel,const ChannelFx channel_op,
124 const Image *source_image,const PixelChannel source_channel,
125 const Quantum pixel,ExceptionInfo *exception)
142 source_view=AcquireVirtualCacheView(source_image,exception);
143 destination_view=AcquireAuthenticCacheView(destination_image,exception);
144 height=MagickMin(source_image->rows,destination_image->rows);
145 width=MagickMin(source_image->columns,destination_image->columns);
146 #if defined(MAGICKCORE_OPENMP_SUPPORT)
147 #pragma omp parallel for schedule(static,4) shared(status) \
148 magick_threads(source_image,source_image,height,1)
150 for (y=0; y < (ssize_t) height; y++)
156 register const Quantum
165 if (status == MagickFalse)
167 p=GetCacheViewVirtualPixels(source_view,0,y,source_image->columns,1,
169 q=GetCacheViewAuthenticPixels(destination_view,0,y,
170 destination_image->columns,1,exception);
171 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
176 destination_traits=GetPixelChannelTraits(destination_image,
177 destination_channel);
178 source_traits=GetPixelChannelTraits(source_image,source_channel);
179 if ((destination_traits == UndefinedPixelTrait) ||
180 (source_traits == UndefinedPixelTrait))
182 for (x=0; x < (ssize_t) width; x++)
184 if (channel_op == AssignChannelOp)
185 SetPixelChannel(destination_image,destination_channel,pixel,q);
187 SetPixelChannel(destination_image,destination_channel,
188 GetPixelChannel(source_image,source_channel,p),q);
189 p+=GetPixelChannels(source_image);
190 q+=GetPixelChannels(destination_image);
192 if (SyncCacheViewAuthenticPixels(destination_view,exception) == MagickFalse)
195 destination_view=DestroyCacheView(destination_view);
196 source_view=DestroyCacheView(source_view);
200 MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
201 ExceptionInfo *exception)
203 #define ChannelFxImageTag "ChannelFx/Image"
212 token[MaxTextExtent];
236 assert(image != (Image *) NULL);
237 assert(image->signature == MagickSignature);
238 if (image->debug != MagickFalse)
239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
240 assert(exception != (ExceptionInfo *) NULL);
241 assert(exception->signature == MagickSignature);
243 destination_image=CloneImage(source_image,0,0,MagickTrue,exception);
244 if (destination_image == (Image *) NULL)
245 return((Image *) NULL);
246 if (expression == (const char *) NULL)
247 return(destination_image);
248 destination_channel=RedPixelChannel;
249 channel_mask=UndefinedChannel;
251 p=(char *) expression;
252 GetMagickToken(p,&p,token);
253 channel_op=ExtractChannelOp;
254 for (channels=0; *token != '\0'; )
260 Interpret channel expression.
266 GetMagickToken(p,&p,token);
271 if (GetNextImageInList(source_image) != (Image *) NULL)
272 source_image=GetNextImageInList(source_image);
274 source_image=GetFirstImageInList(source_image);
275 GetMagickToken(p,&p,token);
283 SetPixelChannelMask(destination_image,channel_mask);
284 if ((channel_op == ExtractChannelOp) && (channels == 1))
285 (void) SetImageColorspace(destination_image,GRAYColorspace,exception);
286 status=SetImageStorageClass(destination_image,DirectClass,exception);
287 if (status == MagickFalse)
289 destination_image=DestroyImageList(destination_image);
290 return(destination_image);
292 canvas=CloneImage(source_image,0,0,MagickTrue,exception);
293 if (canvas == (Image *) NULL)
295 destination_image=DestroyImageList(destination_image);
296 return(destination_image);
298 AppendImageToList(&destination_image,canvas);
299 destination_image=GetLastImageInList(destination_image);
300 GetMagickToken(p,&p,token);
302 destination_channel=RedPixelChannel;
303 channel_mask=UndefinedChannel;
309 i=ParsePixelChannelOption(token);
312 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
313 "UnrecognizedChannelType","`%s'",token);
314 destination_image=DestroyImageList(destination_image);
315 return(destination_image);
317 source_channel=(PixelChannel) i;
318 channel_op=ExtractChannelOp;
319 GetMagickToken(p,&p,token);
322 channel_op=ExchangeChannelOp;
323 GetMagickToken(p,&p,token);
327 if (channel_op != ExchangeChannelOp)
328 channel_op=AssignChannelOp;
329 GetMagickToken(p,&p,token);
333 if (channel_op != ExchangeChannelOp)
334 channel_op=TransferChannelOp;
335 GetMagickToken(p,&p,token);
339 case AssignChannelOp:
341 pixel=StringToDoubleInterval(token,(double) QuantumRange+1.0);
342 GetMagickToken(p,&p,token);
345 case ExchangeChannelOp:
346 case TransferChannelOp:
348 i=ParsePixelChannelOption(token);
351 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
352 "UnrecognizedChannelType","`%s'",token);
353 destination_image=DestroyImageList(destination_image);
354 return(destination_image);
356 destination_channel=(PixelChannel) i;
357 switch (destination_channel)
359 case RedPixelChannel:
360 case GreenPixelChannel:
361 case BluePixelChannel:
362 case BlackPixelChannel:
363 case IndexPixelChannel:
365 case AlphaPixelChannel:
367 destination_image->alpha_trait=BlendPixelTrait;
370 case ReadMaskPixelChannel:
372 destination_image->read_mask=MagickTrue;
375 case WriteMaskPixelChannel:
377 destination_image->write_mask=MagickTrue;
380 case MetaPixelChannel:
383 (void) SetPixelMetaChannels(destination_image,(size_t) (i-
384 GetPixelChannels(destination_image)+1),exception);
388 channel_mask=(ChannelType) (channel_mask | ParseChannelOption(token));
389 if (((channels >= 1) || (destination_channel >= 1)) &&
390 (IsGrayColorspace(destination_image->colorspace) != MagickFalse))
391 (void) SetImageColorspace(destination_image,sRGBColorspace,exception);
392 GetMagickToken(p,&p,token);
398 status=ChannelImage(destination_image,destination_channel,channel_op,
399 source_image,source_channel,ClampToQuantum(pixel),exception);
400 if (status == MagickFalse)
402 destination_image=DestroyImageList(destination_image);
406 if (channel_op == ExchangeChannelOp)
408 status=ChannelImage(destination_image,source_channel,channel_op,
409 source_image,destination_channel,ClampToQuantum(pixel),exception);
410 if (status == MagickFalse)
412 destination_image=DestroyImageList(destination_image);
419 case ExtractChannelOp:
421 channel_mask=(ChannelType) (channel_mask | (1 << destination_channel));
422 destination_channel=(PixelChannel) (destination_channel+1);
428 status=SetImageProgress(source_image,ChannelFxImageTag,p-expression,
430 if (status == MagickFalse)
433 SetPixelChannelMask(destination_image,channel_mask);
434 if ((channel_op == ExtractChannelOp) && (channels == 1))
435 (void) SetImageColorspace(destination_image,GRAYColorspace,exception);
436 status=SetImageStorageClass(destination_image,DirectClass,exception);
437 if (status == MagickFalse)
439 destination_image=GetLastImageInList(destination_image);
440 return((Image *) NULL);
442 return(GetFirstImageInList(destination_image));
446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 % C o m b i n e I m a g e s %
454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 % CombineImages() combines one or more images into a single image. The
457 % grayscale value of the pixels of each image in the sequence is assigned in
458 % order to the specified channels of the combined image. The typical
459 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
461 % The format of the CombineImages method is:
463 % Image *CombineImages(const Image *images,const ColorspaceType colorspace,
464 % ExceptionInfo *exception)
466 % A description of each parameter follows:
468 % o images: the image sequence.
470 % o colorspace: the image colorspace.
472 % o exception: return any errors or warnings in this structure.
475 MagickExport Image *CombineImages(const Image *image,
476 const ColorspaceType colorspace,ExceptionInfo *exception)
478 #define CombineImageTag "Combine/Image"
496 Ensure the image are the same size.
498 assert(image != (const Image *) NULL);
499 assert(image->signature == MagickSignature);
500 if (image->debug != MagickFalse)
501 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
502 assert(exception != (ExceptionInfo *) NULL);
503 assert(exception->signature == MagickSignature);
504 combine_image=CloneImage(image,0,0,MagickTrue,exception);
505 if (combine_image == (Image *) NULL)
506 return((Image *) NULL);
507 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
509 combine_image=DestroyImage(combine_image);
510 return((Image *) NULL);
512 (void) SetImageColorspace(combine_image,colorspace,exception);
513 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
514 combine_image->alpha_trait=BlendPixelTrait;
520 combine_view=AcquireAuthenticCacheView(combine_image,exception);
521 for (y=0; y < (ssize_t) combine_image->rows; y++)
532 register const Quantum
541 if (status == MagickFalse)
543 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
545 if (pixels == (Quantum *) NULL)
551 for (i=0; i < (ssize_t) GetPixelChannels(combine_image); i++)
556 PixelChannel channel=GetPixelChannelChannel(combine_image,i);
557 PixelTrait traits=GetPixelChannelTraits(combine_image,channel);
558 if (traits == UndefinedPixelTrait)
560 if (next == (Image *) NULL)
562 image_view=AcquireVirtualCacheView(next,exception);
563 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
564 if (p == (const Quantum *) NULL)
567 for (x=0; x < (ssize_t) combine_image->columns; x++)
569 if (x < (ssize_t) next->columns)
571 q[i]=GetPixelGray(next,p);
572 p+=GetPixelChannels(next);
574 q+=GetPixelChannels(combine_image);
576 image_view=DestroyCacheView(image_view);
577 next=GetNextImageInList(next);
579 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
581 if (image->progress_monitor != (MagickProgressMonitor) NULL)
586 proceed=SetImageProgress(image,CombineImageTag,progress++,
587 combine_image->rows);
588 if (proceed == MagickFalse)
592 combine_view=DestroyCacheView(combine_view);
593 if (status == MagickFalse)
594 combine_image=DestroyImage(combine_image);
595 return(combine_image);
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 % G e t I m a g e A l p h a C h a n n e l %
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
610 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
613 % The format of the GetImageAlphaChannel method is:
615 % MagickBooleanType GetImageAlphaChannel(const Image *image)
617 % A description of each parameter follows:
619 % o image: the image.
622 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
624 assert(image != (const Image *) NULL);
625 if (image->debug != MagickFalse)
626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
627 assert(image->signature == MagickSignature);
628 return(image->alpha_trait == BlendPixelTrait ? MagickTrue : MagickFalse);
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636 % S e p a r a t e I m a g e %
640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
642 % SeparateImage() separates a channel from the image and returns it as a
645 % The format of the SeparateImage method is:
647 % Image *SeparateImage(const Image *image,const ChannelType channel,
648 % ExceptionInfo *exception)
650 % A description of each parameter follows:
652 % o image: the image.
654 % o channel: the image channel.
656 % o exception: return any errors or warnings in this structure.
659 MagickExport Image *SeparateImage(const Image *image,
660 const ChannelType channel_type,ExceptionInfo *exception)
662 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
663 #define SeparateImageTag "Separate/Image"
682 Initialize separate image attributes.
684 assert(image != (Image *) NULL);
685 assert(image->signature == MagickSignature);
686 if (image->debug != MagickFalse)
687 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
688 assert(exception != (ExceptionInfo *) NULL);
689 assert(exception->signature == MagickSignature);
690 separate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
692 if (separate_image == (Image *) NULL)
693 return((Image *) NULL);
694 if (SetImageStorageClass(separate_image,DirectClass,exception) == MagickFalse)
696 separate_image=DestroyImage(separate_image);
697 return((Image *) NULL);
699 (void) SetImageColorspace(separate_image,GRAYColorspace,exception);
700 separate_image->alpha_trait=UndefinedPixelTrait;
706 image_view=AcquireVirtualCacheView(image,exception);
707 separate_view=AcquireAuthenticCacheView(separate_image,exception);
708 #if defined(MAGICKCORE_OPENMP_SUPPORT)
709 #pragma omp parallel for schedule(static,4) shared(progress,status) \
710 magick_threads(image,image,image->rows,1)
712 for (y=0; y < (ssize_t) image->rows; y++)
714 register const Quantum
723 if (status == MagickFalse)
725 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
726 q=QueueCacheViewAuthenticPixels(separate_view,0,y,separate_image->columns,1,
728 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
733 for (x=0; x < (ssize_t) image->columns; x++)
738 if (GetPixelReadMask(image,p) == 0)
740 SetPixelBackgoundColor(separate_image,q);
741 p+=GetPixelChannels(image);
742 q+=GetPixelChannels(separate_image);
745 SetPixelChannel(separate_image,GrayPixelChannel,0,q);
746 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
748 PixelChannel channel=GetPixelChannelChannel(image,i);
749 PixelTrait traits=GetPixelChannelTraits(image,channel);
750 if ((traits == UndefinedPixelTrait) ||
751 (GetChannelBit(channel_type,channel) == 0))
753 SetPixelChannel(separate_image,GrayPixelChannel,p[i],q);
755 p+=GetPixelChannels(image);
756 q+=GetPixelChannels(separate_image);
758 if (SyncCacheViewAuthenticPixels(separate_view,exception) == MagickFalse)
760 if (image->progress_monitor != (MagickProgressMonitor) NULL)
765 #if defined(MAGICKCORE_OPENMP_SUPPORT)
766 #pragma omp critical (MagickCore_SeparateImage)
768 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
769 if (proceed == MagickFalse)
773 separate_view=DestroyCacheView(separate_view);
774 image_view=DestroyCacheView(image_view);
775 if (status == MagickFalse)
776 separate_image=DestroyImage(separate_image);
777 return(separate_image);
781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
785 % S e p a r a t e I m a g e s %
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 % SeparateImages() returns a separate grayscale image for each channel
794 % The format of the SeparateImages method is:
796 % Image *SeparateImages(const Image *image,ExceptionInfo *exception)
798 % A description of each parameter follows:
800 % o image: the image.
802 % o exception: return any errors or warnings in this structure.
805 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
814 assert(image != (Image *) NULL);
815 assert(image->signature == MagickSignature);
816 if (image->debug != MagickFalse)
817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
818 images=NewImageList();
819 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
821 PixelChannel channel=GetPixelChannelChannel(image,i);
822 PixelTrait traits=GetPixelChannelTraits(image,channel);
823 if ((traits == UndefinedPixelTrait) ||
824 ((traits & UpdatePixelTrait) == 0))
826 separate_image=SeparateImage(image,(ChannelType) (1 << channel),exception);
827 if (separate_image != (Image *) NULL)
828 AppendImageToList(&images,separate_image);
830 if (images == (Image *) NULL)
831 images=SeparateImage(image,UndefinedChannel,exception);
836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
840 % S e t I m a g e A l p h a C h a n n e l %
844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
849 % The format of the SetImageAlphaChannel method is:
851 % MagickBooleanType SetImageAlphaChannel(Image *image,
852 % const AlphaChannelOption alpha_type,ExceptionInfo *exception)
854 % A description of each parameter follows:
856 % o image: the image.
858 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
859 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
860 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
861 % TransparentAlphaChannel.
863 % o exception: return any errors or warnings in this structure.
867 static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
868 const double alpha,const Quantum *q,const double beta,
880 Compose pixel p over pixel q with the given alpha.
882 Sa=QuantumScale*alpha;
883 Da=QuantumScale*beta,
884 gamma=Sa*(-Da)+Sa+Da;
885 gamma=PerceptibleReciprocal(gamma);
886 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
888 PixelChannel channel=GetPixelChannelChannel(image,i);
889 PixelTrait traits=GetPixelChannelTraits(image,channel);
890 if (traits == UndefinedPixelTrait)
894 case RedPixelChannel:
896 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
897 (double) p->red,alpha));
900 case GreenPixelChannel:
902 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
903 (double) p->green,alpha));
906 case BluePixelChannel:
908 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
909 (double) p->blue,alpha));
912 case BlackPixelChannel:
914 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
915 (double) p->black,alpha));
918 case AlphaPixelChannel:
920 composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
929 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
930 const AlphaChannelOption alpha_type,ExceptionInfo *exception)
935 assert(image != (Image *) NULL);
936 if (image->debug != MagickFalse)
937 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
938 assert(image->signature == MagickSignature);
942 case ActivateAlphaChannel:
944 image->alpha_trait=BlendPixelTrait;
947 case BackgroundAlphaChannel:
956 Set transparent pixels to background color.
958 if (image->alpha_trait != BlendPixelTrait)
960 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
962 image_view=AcquireAuthenticCacheView(image,exception);
963 #if defined(MAGICKCORE_OPENMP_SUPPORT)
964 #pragma omp parallel for schedule(static,4) shared(status) \
965 magick_threads(image,image,image->rows,1)
967 for (y=0; y < (ssize_t) image->rows; y++)
975 if (status == MagickFalse)
977 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
979 if (q == (Quantum *) NULL)
984 for (x=0; x < (ssize_t) image->columns; x++)
986 if (GetPixelAlpha(image,q) == TransparentAlpha)
988 SetPixelInfoPixel(image,&image->background_color,q);
989 SetPixelChannel(image,AlphaPixelChannel,TransparentAlpha,q);
991 q+=GetPixelChannels(image);
993 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
996 image_view=DestroyCacheView(image_view);
999 case CopyAlphaChannel:
1000 case ShapeAlphaChannel:
1003 Copy pixel intensity to the alpha channel.
1005 status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
1007 if (alpha_type == ShapeAlphaChannel)
1008 (void) LevelImageColors(image,&image->background_color,
1009 &image->background_color,MagickTrue,exception);
1012 case DeactivateAlphaChannel:
1014 image->alpha_trait=CopyPixelTrait;
1017 case ExtractAlphaChannel:
1019 status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
1021 image->alpha_trait=CopyPixelTrait;
1024 case OpaqueAlphaChannel:
1026 status=SetImageAlpha(image,OpaqueAlpha,exception);
1029 case RemoveAlphaChannel:
1038 Remove transparency.
1040 if (image->alpha_trait != BlendPixelTrait)
1042 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1044 image_view=AcquireAuthenticCacheView(image,exception);
1045 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1046 #pragma omp parallel for schedule(static,4) shared(status) \
1047 magick_threads(image,image,image->rows,1)
1049 for (y=0; y < (ssize_t) image->rows; y++)
1057 if (status == MagickFalse)
1059 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
1061 if (q == (Quantum *) NULL)
1066 for (x=0; x < (ssize_t) image->columns; x++)
1068 FlattenPixelInfo(image,&image->background_color,
1069 image->background_color.alpha,q,(double)
1070 GetPixelAlpha(image,q),q);
1071 q+=GetPixelChannels(image);
1073 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1076 image_view=DestroyCacheView(image_view);
1077 image->alpha_trait=image->background_color.alpha_trait;
1080 case SetAlphaChannel:
1082 if (image->alpha_trait != BlendPixelTrait)
1083 status=SetImageAlpha(image,OpaqueAlpha,exception);
1086 case TransparentAlphaChannel:
1088 status=SetImageAlpha(image,TransparentAlpha,exception);
1091 case UndefinedAlphaChannel:
1094 if (status == MagickFalse)
1096 return(SyncImagePixelCache(image,exception));