]> granicus.if.org Git - imagemagick/blob - MagickCore/channel.c
(no commit message)
[imagemagick] / MagickCore / channel.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
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               %
11 %                                                                             %
12 %                                                                             %
13 %                      MagickCore Image Channel Methods                       %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                               December 2003                                 %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
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.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/colorspace-private.h"
45 #include "MagickCore/image.h"
46 #include "MagickCore/list.h"
47 #include "MagickCore/log.h"
48 #include "MagickCore/monitor.h"
49 #include "MagickCore/monitor-private.h"
50 #include "MagickCore/option.h"
51 #include "MagickCore/pixel-accessor.h"
52 #include "MagickCore/resource_.h"
53 #include "MagickCore/string-private.h"
54 #include "MagickCore/thread-private.h"
55 #include "MagickCore/token.h"
56 #include "MagickCore/utility.h"
57 #include "MagickCore/version.h"
58 \f
59 /*
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %                                                                             %
62 %                                                                             %
63 %                                                                             %
64 %     C h a n n e l F x I m a g e                                             %
65 %                                                                             %
66 %                                                                             %
67 %                                                                             %
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %
70 %  ChannelFxImage() applies a channel expression to the specified image.  The
71 %  expression consists of one or more channels, either mnemonic or numeric (e.g.
72 %  red, 1), separated by actions as follows:
73 %
74 %    <=>     exchange two channels (e.g. red<=>blue)
75 %    =>      copy one channel to another channel (e.g. red=>green)
76 %    =       assign a constant value to a channel (e.g. red=50%)
77 %    ,       write new image channels in the specified order (e.g. red, green)
78 %    |       add a new output image for the next set of channel operations
79 %    ;       move to the next input image for the source of channel data
80 %
81 %  For example, to create 3 grayscale images from the red, green, and blue
82 %  channels of an image, use:
83 %
84 %    -channel-fx "red; green; blue"
85 %
86 %  A channel without an operation symbol implies separate (i.e, semicolon).
87 %
88 %  The format of the ChannelFxImage method is:
89 %
90 %      Image *ChannelFxImage(const Image *image,const char *expression,
91 %        ExceptionInfo *exception)
92 %
93 %  A description of each parameter follows:
94 %
95 %    o image: the image.
96 %
97 %    o expression: A channel expression.
98 %
99 %    o exception: return any errors or warnings in this structure.
100 %
101 */
102
103 typedef enum
104 {
105   ExtractChannelOp,
106   AssignChannelOp,
107   ExchangeChannelOp,
108   TransferChannelOp
109 } ChannelFx;
110
111 static inline size_t MagickMin(const size_t x,const size_t y)
112 {
113   if (x < y)
114     return(x);
115   return(y);
116 }
117
118 static MagickBooleanType ChannelImage(Image *destination_image,
119   const PixelChannel destination_channel,const ChannelFx channel_op,
120   const Image *source_image,const PixelChannel source_channel,
121   const Quantum pixel,ExceptionInfo *exception)
122 {
123   CacheView
124     *source_view,
125     *destination_view;
126
127   MagickBooleanType
128     status;
129
130   size_t
131     height,
132     width;
133
134   ssize_t
135     y;
136
137   status=MagickTrue;
138   source_view=AcquireVirtualCacheView(source_image,exception);
139   destination_view=AcquireAuthenticCacheView(destination_image,exception);
140   height=MagickMin(source_image->rows,destination_image->rows);
141   width=MagickMin(source_image->columns,destination_image->columns);
142 #if defined(MAGICKCORE_OPENMP_SUPPORT)
143   #pragma omp parallel for schedule(static,4) shared(status) \
144     magick_threads(source_image,source_image,height,1)
145 #endif
146   for (y=0; y < (ssize_t) height; y++)
147   {
148     PixelTrait
149       destination_traits,
150       source_traits;
151
152     register const Quantum
153       *restrict p;
154
155     register Quantum
156       *restrict q;
157
158     register ssize_t
159       x;
160
161     if (status == MagickFalse)
162       continue;
163     p=GetCacheViewVirtualPixels(source_view,0,y,source_image->columns,1,
164       exception);
165     q=GetCacheViewAuthenticPixels(destination_view,0,y,
166       destination_image->columns,1,exception);
167     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
168       {
169         status=MagickFalse;
170         continue;
171       }
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))
177       continue;
178     for (x=0; x < (ssize_t) width; x++)
179     {
180       if (channel_op == AssignChannelOp)
181         SetPixelChannel(destination_image,destination_channel,pixel,q);
182       else
183         SetPixelChannel(destination_image,destination_channel,
184           GetPixelChannel(source_image,source_channel,p),q);
185       p+=GetPixelChannels(source_image);
186       q+=GetPixelChannels(destination_image);
187     }
188     if (SyncCacheViewAuthenticPixels(destination_view,exception) == MagickFalse)
189       status=MagickFalse;
190   }
191   destination_view=DestroyCacheView(destination_view);
192   source_view=DestroyCacheView(source_view);
193   return(status);
194 }
195
196 MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
197   ExceptionInfo *exception)
198 {
199 #define ChannelFxImageTag  "ChannelFx/Image"
200
201   ChannelFx
202     channel_op;
203
204   ChannelType
205     channel_mask;
206
207   char
208     token[MaxTextExtent];
209
210   const char
211     *p;
212
213   const Image
214     *source_image;
215
216   double
217     pixel;
218
219   Image
220     *destination_image;
221
222   MagickBooleanType
223     status;
224
225   PixelChannel
226     source_channel,
227     destination_channel;
228
229   ssize_t
230     channels;
231
232   assert(image != (Image *) NULL);
233   assert(image->signature == MagickSignature);
234   if (image->debug != MagickFalse)
235     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
236   assert(exception != (ExceptionInfo *) NULL);
237   assert(exception->signature == MagickSignature);
238   source_image=image;
239   destination_image=CloneImage(source_image,0,0,MagickTrue,exception);
240   if (destination_image == (Image *) NULL)
241     return((Image *) NULL);
242   if (expression == (const char *) NULL)
243     return(destination_image);
244   destination_channel=RedPixelChannel;
245   channel_mask=UndefinedChannel;
246   pixel=0.0;
247   p=(char *) expression;
248   GetMagickToken(p,&p,token);
249   channel_op=ExtractChannelOp;
250   for (channels=0; *token != '\0'; )
251   {
252     MagickBooleanType
253       delete_channel;
254
255     ssize_t
256       i;
257
258     /*
259       Interpret channel expression.
260     */
261     delete_channel=MagickFalse;
262     switch (*token)
263     {
264       case '~':
265       {
266         delete_channel=MagickTrue;
267         GetMagickToken(p,&p,token);
268         break;
269       }
270       case ',':
271       {
272         destination_channel=(PixelChannel) ((ssize_t) destination_channel+1);
273         GetMagickToken(p,&p,token);
274         break;
275       }
276       case '|':
277       {
278         if (GetNextImageInList(source_image) != (Image *) NULL)
279           source_image=GetNextImageInList(source_image);
280         else
281           source_image=GetFirstImageInList(source_image);
282         GetMagickToken(p,&p,token);
283         break;
284       }
285       case ';':
286       {
287         Image
288           *canvas;
289
290         SetPixelChannelMask(destination_image,channel_mask);
291         if ((channel_op == ExtractChannelOp) && (channels == 1))
292           (void) SetImageColorspace(destination_image,GRAYColorspace,exception);
293         status=SetImageStorageClass(destination_image,DirectClass,exception);
294         if (status == MagickFalse)
295           {
296             destination_image=DestroyImageList(destination_image);
297             return(destination_image);
298           }
299         canvas=CloneImage(source_image,0,0,MagickTrue,exception);
300         if (canvas == (Image *) NULL)
301           {
302             destination_image=DestroyImageList(destination_image);
303             return(destination_image);
304           }
305         AppendImageToList(&destination_image,canvas);
306         destination_image=GetLastImageInList(destination_image);
307         GetMagickToken(p,&p,token);
308         channels=0;
309         destination_channel=RedPixelChannel;
310         channel_mask=UndefinedChannel;
311         break;
312       }
313       default:
314         break;
315     }
316     i=ParsePixelChannelOption(token);
317     if (i < 0)
318       {
319         (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
320           "UnrecognizedChannelType","`%s'",token);
321         destination_image=DestroyImageList(destination_image);
322         return(destination_image);
323       }
324     source_channel=(PixelChannel) i;
325     channel_op=ExtractChannelOp;
326     GetMagickToken(p,&p,token);
327     if (*token == '<')
328       {
329         channel_op=ExchangeChannelOp;
330         GetMagickToken(p,&p,token);
331       }
332     if (*token == '=')
333       {
334         if (channel_op != ExchangeChannelOp)
335           channel_op=AssignChannelOp;
336         GetMagickToken(p,&p,token);
337       }
338     if (*token == '>')
339       {
340         if (channel_op != ExchangeChannelOp)
341           channel_op=TransferChannelOp;
342         GetMagickToken(p,&p,token);
343       }
344     switch (channel_op)
345     {
346       case AssignChannelOp:
347       {
348         pixel=StringToDoubleInterval(token,(double) QuantumRange+1.0);
349         GetMagickToken(p,&p,token);
350         break;
351       }
352       case ExchangeChannelOp:
353       case TransferChannelOp:
354       {
355         i=ParsePixelChannelOption(token);
356         if (i < 0)
357           {
358             (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
359               "UnrecognizedChannelType","`%s'",token);
360             destination_image=DestroyImageList(destination_image);
361             return(destination_image);
362           }
363         destination_channel=(PixelChannel) i;
364         switch (destination_channel)
365         {
366           case AlphaPixelChannel:
367           {
368             destination_image->alpha_trait=BlendPixelTrait;
369             break;
370           }
371           case ReadMaskPixelChannel:
372           {
373             destination_image->read_mask=MagickTrue;
374             break;
375           }
376           case WriteMaskPixelChannel:
377           {
378             destination_image->write_mask=MagickTrue;
379             break;
380           }
381           default:
382             break;
383         }
384         channel_mask=(ChannelType) (channel_mask | ParseChannelOption(token));
385         if (((channels >= 1)  || (destination_channel >= 1)) &&
386             (IsGrayColorspace(destination_image->colorspace) != MagickFalse))
387           (void) SetImageColorspace(destination_image,sRGBColorspace,exception);
388         if (i >= (ssize_t) GetPixelChannels(destination_image))
389           (void) SetPixelMetaChannels(destination_image,(size_t) (i-
390             GetPixelChannels(destination_image)+1),exception);
391         GetMagickToken(p,&p,token);
392         break;
393       }
394       default:
395         break;
396     }
397     status=ChannelImage(destination_image,destination_channel,channel_op,
398       source_image,source_channel,ClampToQuantum(pixel),exception);
399     if (status == MagickFalse)
400       {
401         destination_image=DestroyImageList(destination_image);
402         break;
403       }
404     channels++;
405     if (channel_op == ExchangeChannelOp)
406       {
407         status=ChannelImage(destination_image,source_channel,channel_op,
408           source_image,destination_channel,ClampToQuantum(pixel),exception);
409         if (status == MagickFalse)
410           {
411             destination_image=DestroyImageList(destination_image);
412             break;
413           }
414         channels++;
415       }
416     switch (channel_op)
417     {
418       case ExtractChannelOp:
419       {
420         if (delete_channel == MagickFalse)
421           channel_mask=(ChannelType) (channel_mask &~
422             (1 << destination_channel));
423         else
424           channel_mask=(ChannelType) (channel_mask |
425             (1 << destination_channel));
426         destination_channel=(PixelChannel) (destination_channel+1);
427         break;
428       }
429       default:
430         break;
431     }
432     status=SetImageProgress(source_image,ChannelFxImageTag,p-expression,
433       strlen(expression));
434     if (status == MagickFalse)
435       break;
436   }
437   SetPixelChannelMask(destination_image,channel_mask);
438   if ((channel_op == ExtractChannelOp) && (channels == 1))
439     (void) SetImageColorspace(destination_image,GRAYColorspace,exception);
440   status=SetImageStorageClass(destination_image,DirectClass,exception);
441   if (status == MagickFalse)
442     {
443       destination_image=GetLastImageInList(destination_image);
444       return((Image *) NULL);
445     }
446   return(GetFirstImageInList(destination_image));
447 }
448 \f
449 /*
450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451 %                                                                             %
452 %                                                                             %
453 %                                                                             %
454 %     C o m b i n e I m a g e s                                               %
455 %                                                                             %
456 %                                                                             %
457 %                                                                             %
458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 %
460 %  CombineImages() combines one or more images into a single image.  The
461 %  grayscale value of the pixels of each image in the sequence is assigned in
462 %  order to the specified channels of the combined image.   The typical
463 %  ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
464 %
465 %  The format of the CombineImages method is:
466 %
467 %      Image *CombineImages(const Image *images,const ColorspaceType colorspace,
468 %        ExceptionInfo *exception)
469 %
470 %  A description of each parameter follows:
471 %
472 %    o images: the image sequence.
473 %
474 %    o colorspace: the image colorspace.
475 %
476 %    o exception: return any errors or warnings in this structure.
477 %
478 */
479 MagickExport Image *CombineImages(const Image *image,
480   const ColorspaceType colorspace,ExceptionInfo *exception)
481 {
482 #define CombineImageTag  "Combine/Image"
483
484   CacheView
485     *combine_view;
486
487   Image
488     *combine_image;
489
490   MagickBooleanType
491     status;
492
493   MagickOffsetType
494     progress;
495
496   ssize_t
497     y;
498
499   /*
500     Ensure the image are the same size.
501   */
502   assert(image != (const Image *) NULL);
503   assert(image->signature == MagickSignature);
504   if (image->debug != MagickFalse)
505     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
506   assert(exception != (ExceptionInfo *) NULL);
507   assert(exception->signature == MagickSignature);
508   combine_image=CloneImage(image,0,0,MagickTrue,exception);
509   if (combine_image == (Image *) NULL)
510     return((Image *) NULL);
511   if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
512     {
513       combine_image=DestroyImage(combine_image);
514       return((Image *) NULL);
515     }
516   (void) SetImageColorspace(combine_image,colorspace,exception);
517   if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
518     combine_image->alpha_trait=BlendPixelTrait;
519   /*
520     Combine images.
521   */
522   status=MagickTrue;
523   progress=0;
524   combine_view=AcquireAuthenticCacheView(combine_image,exception);
525   for (y=0; y < (ssize_t) combine_image->rows; y++)
526   {
527     CacheView
528       *image_view;
529
530     const Image
531       *next;
532
533     Quantum
534       *pixels;
535
536     register const Quantum
537       *restrict p;
538
539     register Quantum
540       *restrict q;
541
542     register ssize_t
543       i;
544
545     if (status == MagickFalse)
546       continue;
547     pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
548       1,exception);
549     if (pixels == (Quantum *) NULL)
550       {
551         status=MagickFalse;
552         continue;
553       }
554     next=image;
555     for (i=0; i < (ssize_t) GetPixelChannels(combine_image); i++)
556     {
557       register ssize_t
558         x;
559
560       PixelChannel channel=GetPixelChannelChannel(combine_image,i);
561       PixelTrait traits=GetPixelChannelTraits(combine_image,channel);
562       if (traits == UndefinedPixelTrait)
563         continue;
564       if (next == (Image *) NULL)
565         continue;
566       image_view=AcquireVirtualCacheView(next,exception);
567       p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
568       if (p == (const Quantum *) NULL)
569         continue;
570       q=pixels;
571       for (x=0; x < (ssize_t) combine_image->columns; x++)
572       {
573         if (x < (ssize_t) next->columns)
574           {
575             q[i]=GetPixelGray(next,p);
576             p+=GetPixelChannels(next);
577           }
578         q+=GetPixelChannels(combine_image);
579       }
580       image_view=DestroyCacheView(image_view);
581       next=GetNextImageInList(next);
582     }
583     if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
584       status=MagickFalse;
585     if (image->progress_monitor != (MagickProgressMonitor) NULL)
586       {
587         MagickBooleanType
588           proceed;
589
590         proceed=SetImageProgress(image,CombineImageTag,progress++,
591           combine_image->rows);
592         if (proceed == MagickFalse)
593           status=MagickFalse;
594       }
595   }
596   combine_view=DestroyCacheView(combine_view);
597   if (status == MagickFalse)
598     combine_image=DestroyImage(combine_image);
599   return(combine_image);
600 }
601 \f
602 /*
603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
604 %                                                                             %
605 %                                                                             %
606 %                                                                             %
607 %     S e p a r a t e I m a g e                                               %
608 %                                                                             %
609 %                                                                             %
610 %                                                                             %
611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
612 %
613 %  SeparateImage() separates a channel from the image and returns it as a
614 %  grayscale image.
615 %
616 %  The format of the SeparateImage method is:
617 %
618 %      Image *SeparateImage(const Image *image,const ChannelType channel,
619 %        ExceptionInfo *exception)
620 %
621 %  A description of each parameter follows:
622 %
623 %    o image: the image.
624 %
625 %    o channel: the image channel.
626 %
627 %    o exception: return any errors or warnings in this structure.
628 %
629 */
630 MagickExport Image *SeparateImage(const Image *image,
631   const ChannelType channel_type,ExceptionInfo *exception)
632 {
633 #define GetChannelBit(mask,bit)  (((size_t) (mask) >> (size_t) (bit)) & 0x01)
634 #define SeparateImageTag  "Separate/Image"
635
636   CacheView
637     *image_view,
638     *separate_view;
639
640   Image
641     *separate_image;
642
643   MagickBooleanType
644     status;
645
646   MagickOffsetType
647     progress;
648
649   ssize_t
650     y;
651
652   /*
653     Initialize separate image attributes.
654   */
655   assert(image != (Image *) NULL);
656   assert(image->signature == MagickSignature);
657   if (image->debug != MagickFalse)
658     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
659   assert(exception != (ExceptionInfo *) NULL);
660   assert(exception->signature == MagickSignature);
661   separate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
662     exception);
663   if (separate_image == (Image *) NULL)
664     return((Image *) NULL);
665   if (SetImageStorageClass(separate_image,DirectClass,exception) == MagickFalse)
666     {
667       separate_image=DestroyImage(separate_image);
668       return((Image *) NULL);
669     }
670   (void) SetImageColorspace(separate_image,GRAYColorspace,exception);
671   separate_image->alpha_trait=UndefinedPixelTrait;
672   /*
673     Separate image.
674   */
675   status=MagickTrue;
676   progress=0;
677   image_view=AcquireVirtualCacheView(image,exception);
678   separate_view=AcquireAuthenticCacheView(separate_image,exception);
679 #if defined(MAGICKCORE_OPENMP_SUPPORT)
680   #pragma omp parallel for schedule(static,4) shared(progress,status) \
681     magick_threads(image,image,image->rows,1)
682 #endif
683   for (y=0; y < (ssize_t) image->rows; y++)
684   {
685     register const Quantum
686       *restrict p;
687
688     register Quantum
689       *restrict q;
690
691     register ssize_t
692       x;
693
694     if (status == MagickFalse)
695       continue;
696     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
697     q=QueueCacheViewAuthenticPixels(separate_view,0,y,separate_image->columns,1,
698       exception);
699     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
700       {
701         status=MagickFalse;
702         continue;
703       }
704     for (x=0; x < (ssize_t) image->columns; x++)
705     {
706       register ssize_t
707         i;
708
709       if (GetPixelReadMask(image,p) == 0)
710         {
711           p+=GetPixelChannels(image);
712           q+=GetPixelChannels(separate_image);
713           continue;
714         }
715       SetPixelChannel(separate_image,GrayPixelChannel,0,q);
716       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
717       {
718         PixelChannel channel=GetPixelChannelChannel(image,i);
719         PixelTrait traits=GetPixelChannelTraits(image,channel);
720         if ((traits == UndefinedPixelTrait) ||
721             (GetChannelBit(channel_type,channel) == 0))
722           continue;
723         SetPixelChannel(separate_image,GrayPixelChannel,p[i],q);
724       }
725       p+=GetPixelChannels(image);
726       q+=GetPixelChannels(separate_image);
727     }
728     if (SyncCacheViewAuthenticPixels(separate_view,exception) == MagickFalse)
729       status=MagickFalse;
730     if (image->progress_monitor != (MagickProgressMonitor) NULL)
731       {
732         MagickBooleanType
733           proceed;
734
735 #if defined(MAGICKCORE_OPENMP_SUPPORT)
736         #pragma omp critical (MagickCore_SeparateImage)
737 #endif
738         proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
739         if (proceed == MagickFalse)
740           status=MagickFalse;
741       }
742   }
743   separate_view=DestroyCacheView(separate_view);
744   image_view=DestroyCacheView(image_view);
745   if (status == MagickFalse)
746     separate_image=DestroyImage(separate_image);
747   return(separate_image);
748 }
749 \f
750 /*
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
752 %                                                                             %
753 %                                                                             %
754 %                                                                             %
755 %     S e p a r a t e I m a g e s                                             %
756 %                                                                             %
757 %                                                                             %
758 %                                                                             %
759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
760 %
761 %  SeparateImages() returns a separate grayscale image for each channel
762 %  specified.
763 %
764 %  The format of the SeparateImages method is:
765 %
766 %      Image *SeparateImages(const Image *image,ExceptionInfo *exception)
767 %
768 %  A description of each parameter follows:
769 %
770 %    o image: the image.
771 %
772 %    o exception: return any errors or warnings in this structure.
773 %
774 */
775 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
776 {
777   Image
778     *images,
779     *separate_image;
780
781   register ssize_t
782     i;
783
784   assert(image != (Image *) NULL);
785   assert(image->signature == MagickSignature);
786   if (image->debug != MagickFalse)
787     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
788   images=NewImageList();
789   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
790   {
791     PixelChannel channel=GetPixelChannelChannel(image,i);
792     PixelTrait traits=GetPixelChannelTraits(image,channel);
793     if ((traits == UndefinedPixelTrait) ||
794         ((traits & UpdatePixelTrait) == 0))
795       continue;
796     separate_image=SeparateImage(image,(ChannelType) (1 << channel),exception);
797     if (separate_image != (Image *) NULL)
798       AppendImageToList(&images,separate_image);
799   }
800   if (images == (Image *) NULL)
801     images=SeparateImage(image,UndefinedChannel,exception);
802   return(images);
803 }