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