]> granicus.if.org Git - imagemagick/blob - coders/rgb.c
(no commit message)
[imagemagick] / coders / rgb.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                            RRRR    GGGG  BBBB                               %
7 %                            R   R  G      B   B                              %
8 %                            RRRR   G  GG  BBBB                               %
9 %                            R R    G   G  B   B                              %
10 %                            R  R    GGG   BBBB                               %
11 %                                                                             %
12 %                                                                             %
13 %                     Read/Write Raw RGB Image Format                         %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2008 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 \f
39 /*
40   Include declarations.
41 */
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/colorspace.h"
47 #include "MagickCore/colorspace-private.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/exception.h"
50 #include "MagickCore/exception-private.h"
51 #include "MagickCore/image.h"
52 #include "MagickCore/image-private.h"
53 #include "MagickCore/list.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/monitor.h"
57 #include "MagickCore/monitor-private.h"
58 #include "MagickCore/pixel-accessor.h"
59 #include "MagickCore/quantum-private.h"
60 #include "MagickCore/static.h"
61 #include "MagickCore/statistic.h"
62 #include "MagickCore/string_.h"
63 #include "MagickCore/module.h"
64 #include "MagickCore/utility.h"
65 \f
66 /*
67   Forward declarations.
68 */
69 static MagickBooleanType
70   WriteRGBImage(const ImageInfo *,Image *,ExceptionInfo *);
71 \f
72 /*
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %                                                                             %
75 %                                                                             %
76 %                                                                             %
77 %   R e a d R G B I m a g e                                                   %
78 %                                                                             %
79 %                                                                             %
80 %                                                                             %
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 %
83 %  ReadRGBImage() reads an image of raw RGB, RGBA, or RGBO samples and returns
84 %  it.  It allocates the memory necessary for the new Image structure and
85 %  returns a pointer to the new image.
86 %
87 %  The format of the ReadRGBImage method is:
88 %
89 %      Image *ReadRGBImage(const ImageInfo *image_info,
90 %        ExceptionInfo *exception)
91 %
92 %  A description of each parameter follows:
93 %
94 %    o image_info: the image info.
95 %
96 %    o exception: return any errors or warnings in this structure.
97 %
98 */
99 static Image *ReadRGBImage(const ImageInfo *image_info,
100   ExceptionInfo *exception)
101 {
102   Image
103     *canvas_image,
104     *image;
105
106   MagickBooleanType
107     status;
108
109   MagickOffsetType
110     scene;
111
112   QuantumInfo
113     *quantum_info;
114
115   QuantumType
116     quantum_type;
117
118   register ssize_t
119     i;
120
121   size_t
122     length;
123
124   ssize_t
125     count,
126     y;
127
128   unsigned char
129     *pixels;
130
131   /*
132     Open image file.
133   */
134   assert(image_info != (const ImageInfo *) NULL);
135   assert(image_info->signature == MagickSignature);
136   if (image_info->debug != MagickFalse)
137     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
138       image_info->filename);
139   assert(exception != (ExceptionInfo *) NULL);
140   assert(exception->signature == MagickSignature);
141   image=AcquireImage(image_info);
142   if ((image->columns == 0) || (image->rows == 0))
143     ThrowReaderException(OptionError,"MustSpecifyImageSize");
144   image->colorspace=RGBColorspace;
145   if (image_info->interlace != PartitionInterlace)
146     {
147       status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
148       if (status == MagickFalse)
149         {
150           image=DestroyImageList(image);
151           return((Image *) NULL);
152         }
153       if (DiscardBlobBytes(image,image->offset) == MagickFalse)
154         ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
155           image->filename);
156     }
157   /*
158     Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
159   */
160   canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
161     exception);
162   (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
163   quantum_info=AcquireQuantumInfo(image_info,canvas_image);
164   if (quantum_info == (QuantumInfo *) NULL)
165     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
166   pixels=GetQuantumPixels(quantum_info);
167   quantum_type=RGBQuantum;
168   if (LocaleCompare(image_info->magick,"RGBA") == 0)
169     {
170       quantum_type=RGBAQuantum;
171       image->matte=MagickTrue;
172     }
173   if (LocaleCompare(image_info->magick,"RGBO") == 0)
174     {
175       quantum_type=RGBOQuantum;
176       image->matte=MagickTrue;
177     }
178   if (image_info->number_scenes != 0)
179     while (image->scene < image_info->scene)
180     {
181       /*
182         Skip to next image.
183       */
184       image->scene++;
185       length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
186       for (y=0; y < (ssize_t) image->rows; y++)
187       {
188         count=ReadBlob(image,length,pixels);
189         if (count != (ssize_t) length)
190           break;
191       }
192     }
193   count=0;
194   length=0;
195   scene=0;
196   do
197   {
198     /*
199       Read pixels to virtual canvas image then push to image.
200     */
201     if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
202       if (image->scene >= (image_info->scene+image_info->number_scenes-1))
203         break;
204     image->colorspace=RGBColorspace;
205     switch (image_info->interlace)
206     {
207       case NoInterlace:
208       default:
209       {
210         /*
211           No interlacing:  RGBRGBRGBRGBRGBRGB...
212         */
213         if (scene == 0)
214           {
215             length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
216             count=ReadBlob(image,length,pixels);
217           }
218         for (y=0; y < (ssize_t) image->extract_info.height; y++)
219         {
220           register const Quantum
221             *restrict p;
222
223           register Quantum
224             *restrict q;
225
226           register ssize_t
227             x;
228
229           if (count != (ssize_t) length)
230             {
231               ThrowFileException(exception,CorruptImageError,
232                 "UnexpectedEndOfFile",image->filename);
233               break;
234             }
235           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
236             exception);
237           if (q == (Quantum *) NULL)
238             break;
239           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
240             quantum_info,quantum_type,pixels,exception);
241           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
242             break;
243           if (((y-image->extract_info.y) >= 0) && 
244               ((y-image->extract_info.y) < (ssize_t) image->rows))
245             {
246               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
247                 canvas_image->columns,1,exception);
248               q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
249                 image->columns,1,exception);
250               if ((p == (const Quantum *) NULL) ||
251                   (q == (Quantum *) NULL))
252                 break;
253               for (x=0; x < (ssize_t) image->columns; x++)
254               {
255                 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
256                 SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
257                 SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
258                 SetPixelAlpha(image,OpaqueAlpha,q);
259                 if (image->matte != MagickFalse)
260                   SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
261                 p+=GetPixelChannels(canvas_image);
262                 q+=GetPixelChannels(image);
263               }
264               if (SyncAuthenticPixels(image,exception) == MagickFalse)
265                 break;
266             }
267           if (image->previous == (Image *) NULL)
268             {
269               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
270                 image->rows);
271               if (status == MagickFalse)
272                 break;
273             }
274           count=ReadBlob(image,length,pixels);
275         }
276         break;
277       }
278       case LineInterlace:
279       {
280         static QuantumType
281           quantum_types[4] =
282           {
283             RedQuantum,
284             GreenQuantum,
285             BlueQuantum,
286             AlphaQuantum
287           };
288
289         /*
290           Line interlacing:  RRR...GGG...BBB...RRR...GGG...BBB...
291         */
292         if (LocaleCompare(image_info->magick,"RGBO") == 0)
293           quantum_types[3]=OpacityQuantum;
294         if (scene == 0)
295           {
296             length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
297             count=ReadBlob(image,length,pixels);
298           }
299         for (y=0; y < (ssize_t) image->extract_info.height; y++)
300         {
301           register const Quantum
302             *restrict p;
303
304           register Quantum
305             *restrict q;
306
307           register ssize_t
308             x;
309
310           if (count != (ssize_t) length)
311             {
312               ThrowFileException(exception,CorruptImageError,
313                 "UnexpectedEndOfFile",image->filename);
314               break;
315             }
316           for (i=0; i < (ssize_t) (image->matte != MagickFalse ? 4 : 3); i++)
317           {
318             quantum_type=quantum_types[i];
319             q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
320               exception);
321             if (q == (Quantum *) NULL)
322               break;
323             length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
324               quantum_info,quantum_type,pixels,exception);
325             if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
326               break;
327             if (((y-image->extract_info.y) >= 0) && 
328                 ((y-image->extract_info.y) < (ssize_t) image->rows))
329               {
330                 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
331                   0,canvas_image->columns,1,exception);
332                 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
333                   image->columns,1,exception);
334                 if ((p == (const Quantum *) NULL) ||
335                     (q == (Quantum *) NULL))
336                   break;
337                 for (x=0; x < (ssize_t) image->columns; x++)
338                 {
339                   switch (quantum_type)
340                   {
341                     case RedQuantum:
342                     {
343                       SetPixelRed(image,GetPixelRed(canvas_image,p),q);
344                       break;
345                     }
346                     case GreenQuantum:
347                     {
348                       SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
349                       break;
350                     }
351                     case BlueQuantum:
352                     {
353                       SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
354                       break;
355                     }
356                     case OpacityQuantum:
357                     {
358                       SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
359                       break;
360                     }
361                     case AlphaQuantum:
362                     {
363                       SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
364                       break;
365                     }
366                     default:
367                       break;
368                   }
369                   p+=GetPixelChannels(canvas_image);
370                   q+=GetPixelChannels(image);
371                 }
372                 if (SyncAuthenticPixels(image,exception) == MagickFalse)
373                   break;
374               }
375             count=ReadBlob(image,length,pixels);
376           }
377           if (image->previous == (Image *) NULL)
378             {
379               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
380                 image->rows);
381               if (status == MagickFalse)
382                 break;
383             }
384         }
385         break;
386       }
387       case PlaneInterlace:
388       {
389         /*
390           Plane interlacing:  RRRRRR...GGGGGG...BBBBBB...
391         */
392         if (scene == 0)
393           {
394             length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
395             count=ReadBlob(image,length,pixels);
396           }
397         for (y=0; y < (ssize_t) image->extract_info.height; y++)
398         {
399           register const Quantum
400             *restrict p;
401
402           register Quantum
403             *restrict q;
404
405           register ssize_t
406             x;
407
408           if (count != (ssize_t) length)
409             {
410               ThrowFileException(exception,CorruptImageError,
411                 "UnexpectedEndOfFile",image->filename);
412               break;
413             }
414           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
415             exception);
416           if (q == (Quantum *) NULL)
417             break;
418           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
419             quantum_info,RedQuantum,pixels,exception);
420           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
421             break;
422           if (((y-image->extract_info.y) >= 0) && 
423               ((y-image->extract_info.y) < (ssize_t) image->rows))
424             {
425               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
426                 canvas_image->columns,1,exception);
427               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
428                 image->columns,1,exception);
429               if ((p == (const Quantum *) NULL) ||
430                   (q == (Quantum *) NULL))
431                 break;
432               for (x=0; x < (ssize_t) image->columns; x++)
433               {
434                 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
435                 p+=GetPixelChannels(canvas_image);
436                 q+=GetPixelChannels(image);
437               }
438               if (SyncAuthenticPixels(image,exception) == MagickFalse)
439                 break;
440             }
441           count=ReadBlob(image,length,pixels);
442         }
443         if (image->previous == (Image *) NULL)
444           {
445             status=SetImageProgress(image,LoadImageTag,1,6);
446             if (status == MagickFalse)
447               break;
448           }
449         for (y=0; y < (ssize_t) image->extract_info.height; y++)
450         {
451           register const Quantum
452             *restrict p;
453
454           register Quantum
455             *restrict q;
456
457           register ssize_t
458             x;
459
460           if (count != (ssize_t) length)
461             {
462               ThrowFileException(exception,CorruptImageError,
463                 "UnexpectedEndOfFile",image->filename);
464               break;
465             }
466           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
467             exception);
468           if (q == (Quantum *) NULL)
469             break;
470           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
471             quantum_info,GreenQuantum,pixels,exception);
472           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
473             break;
474           if (((y-image->extract_info.y) >= 0) && 
475               ((y-image->extract_info.y) < (ssize_t) image->rows))
476             {
477               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
478                 canvas_image->columns,1,exception);
479               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
480                 image->columns,1,exception);
481               if ((p == (const Quantum *) NULL) ||
482                   (q == (Quantum *) NULL))
483                 break;
484               for (x=0; x < (ssize_t) image->columns; x++)
485               {
486                 SetPixelGreen(image,
487                   GetPixelGreen(canvas_image,p),q);
488                 p+=GetPixelChannels(canvas_image);
489                 q+=GetPixelChannels(image);
490               }
491               if (SyncAuthenticPixels(image,exception) == MagickFalse)
492                 break;
493            }
494           count=ReadBlob(image,length,pixels);
495         }
496         if (image->previous == (Image *) NULL)
497           {
498             status=SetImageProgress(image,LoadImageTag,2,6);
499             if (status == MagickFalse)
500               break;
501           }
502         for (y=0; y < (ssize_t) image->extract_info.height; y++)
503         {
504           register const Quantum
505             *restrict p;
506
507           register Quantum
508             *restrict q;
509
510           register ssize_t
511             x;
512
513           if (count != (ssize_t) length)
514             {
515               ThrowFileException(exception,CorruptImageError,
516                 "UnexpectedEndOfFile",image->filename);
517               break;
518             }
519           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
520             exception);
521           if (q == (Quantum *) NULL)
522             break;
523           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
524             quantum_info,BlueQuantum,pixels,exception);
525           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
526             break;
527           if (((y-image->extract_info.y) >= 0) && 
528               ((y-image->extract_info.y) < (ssize_t) image->rows))
529             {
530               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
531                 canvas_image->columns,1,exception);
532               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
533                 image->columns,1,exception);
534               if ((p == (const Quantum *) NULL) ||
535                   (q == (Quantum *) NULL))
536                 break;
537               for (x=0; x < (ssize_t) image->columns; x++)
538               {
539                 SetPixelBlue(image,
540                   GetPixelBlue(canvas_image,p),q);
541                 p+=GetPixelChannels(canvas_image);
542                 q+=GetPixelChannels(image);
543               }
544               if (SyncAuthenticPixels(image,exception) == MagickFalse)
545                 break;
546             }
547           count=ReadBlob(image,length,pixels);
548         }
549         if (image->previous == (Image *) NULL)
550           {
551             status=SetImageProgress(image,LoadImageTag,3,6);
552             if (status == MagickFalse)
553               break;
554           }
555         if (image->previous == (Image *) NULL)
556           {
557             status=SetImageProgress(image,LoadImageTag,4,6);
558             if (status == MagickFalse)
559               break;
560           }
561         if (image->matte != MagickFalse)
562           {
563             for (y=0; y < (ssize_t) image->extract_info.height; y++)
564             {
565               register const Quantum
566                 *restrict p;
567
568               register Quantum
569                 *restrict q;
570
571               register ssize_t
572                 x;
573
574               if (count != (ssize_t) length)
575                 {
576                   ThrowFileException(exception,CorruptImageError,
577                     "UnexpectedEndOfFile",image->filename);
578                   break;
579                 }
580               q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
581                 exception);
582               if (q == (Quantum *) NULL)
583                 break;
584               length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
585                 quantum_info,AlphaQuantum,pixels,exception);
586               if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
587                 break;
588               if (((y-image->extract_info.y) >= 0) && 
589                   ((y-image->extract_info.y) < (ssize_t) image->rows))
590                 {
591                   p=GetVirtualPixels(canvas_image,
592                     canvas_image->extract_info.x,0,canvas_image->columns,1,
593                     exception);
594                   q=GetAuthenticPixels(image,0,y-image->extract_info.y,
595                     image->columns,1,exception);
596                   if ((p == (const Quantum *) NULL) ||
597                       (q == (Quantum *) NULL))
598                     break;
599                   for (x=0; x < (ssize_t) image->columns; x++)
600                   {
601                     SetPixelAlpha(image,
602                       GetPixelAlpha(canvas_image,p),q);
603                     p+=GetPixelChannels(canvas_image);
604                     q+=GetPixelChannels(image);
605                   }
606                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
607                     break;
608                 }
609               count=ReadBlob(image,length,pixels);
610             }
611             if (image->previous == (Image *) NULL)
612               {
613                 status=SetImageProgress(image,LoadImageTag,5,6);
614                 if (status == MagickFalse)
615                   break;
616               }
617           }
618         if (image->previous == (Image *) NULL)
619           {
620             status=SetImageProgress(image,LoadImageTag,6,6);
621             if (status == MagickFalse)
622               break;
623           }
624         break;
625       }
626       case PartitionInterlace:
627       {
628         /*
629           Partition interlacing:  RRRRRR..., GGGGGG..., BBBBBB...
630         */
631         AppendImageFormat("R",image->filename);
632         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
633         if (status == MagickFalse)
634           {
635             canvas_image=DestroyImageList(canvas_image);
636             image=DestroyImageList(image);
637             return((Image *) NULL);
638           }
639         if (DiscardBlobBytes(image,image->offset) == MagickFalse)
640           ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
641             image->filename);
642         length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
643         for (i=0; i < (ssize_t) scene; i++)
644           for (y=0; y < (ssize_t) image->extract_info.height; y++)
645             if (ReadBlob(image,length,pixels) != (ssize_t) length)
646               {
647                 ThrowFileException(exception,CorruptImageError,
648                   "UnexpectedEndOfFile",image->filename);
649                 break;
650               }
651         count=ReadBlob(image,length,pixels);
652         for (y=0; y < (ssize_t) image->extract_info.height; y++)
653         {
654           register const Quantum
655             *restrict p;
656
657           register Quantum
658             *restrict q;
659
660           register ssize_t
661             x;
662
663           if (count != (ssize_t) length)
664             {
665               ThrowFileException(exception,CorruptImageError,
666                 "UnexpectedEndOfFile",image->filename);
667               break;
668             }
669           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
670             exception);
671           if (q == (Quantum *) NULL)
672             break;
673           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
674             quantum_info,RedQuantum,pixels,exception);
675           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
676             break;
677           if (((y-image->extract_info.y) >= 0) && 
678               ((y-image->extract_info.y) < (ssize_t) image->rows))
679             {
680               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
681                 canvas_image->columns,1,exception);
682               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
683                 image->columns,1,exception);
684               if ((p == (const Quantum *) NULL) ||
685                   (q == (Quantum *) NULL))
686                 break;
687               for (x=0; x < (ssize_t) image->columns; x++)
688               {
689                 SetPixelRed(image,GetPixelRed(canvas_image,p),q);
690                 p+=GetPixelChannels(canvas_image);
691                 q+=GetPixelChannels(image);
692               }
693               if (SyncAuthenticPixels(image,exception) == MagickFalse)
694                 break;
695             }
696           count=ReadBlob(image,length,pixels);
697         }
698         if (image->previous == (Image *) NULL)
699           {
700             status=SetImageProgress(image,LoadImageTag,1,5);
701             if (status == MagickFalse)
702               break;
703           }
704         (void) CloseBlob(image);
705         AppendImageFormat("G",image->filename);
706         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
707         if (status == MagickFalse)
708           {
709             canvas_image=DestroyImageList(canvas_image);
710             image=DestroyImageList(image);
711             return((Image *) NULL);
712           }
713         length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
714         for (i=0; i < (ssize_t) scene; i++)
715           for (y=0; y < (ssize_t) image->extract_info.height; y++)
716             if (ReadBlob(image,length,pixels) != (ssize_t) length)
717               {
718                 ThrowFileException(exception,CorruptImageError,
719                   "UnexpectedEndOfFile",image->filename);
720                 break;
721               }
722         count=ReadBlob(image,length,pixels);
723         for (y=0; y < (ssize_t) image->extract_info.height; y++)
724         {
725           register const Quantum
726             *restrict p;
727
728           register Quantum
729             *restrict q;
730
731           register ssize_t
732             x;
733
734           if (count != (ssize_t) length)
735             {
736               ThrowFileException(exception,CorruptImageError,
737                 "UnexpectedEndOfFile",image->filename);
738               break;
739             }
740           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
741             exception);
742           if (q == (Quantum *) NULL)
743             break;
744           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
745             quantum_info,GreenQuantum,pixels,exception);
746           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
747             break;
748           if (((y-image->extract_info.y) >= 0) && 
749               ((y-image->extract_info.y) < (ssize_t) image->rows))
750             {
751               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
752                 canvas_image->columns,1,exception);
753               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
754                 image->columns,1,exception);
755               if ((p == (const Quantum *) NULL) ||
756                   (q == (Quantum *) NULL))
757                 break;
758               for (x=0; x < (ssize_t) image->columns; x++)
759               {
760                 SetPixelGreen(image,
761                   GetPixelGreen(canvas_image,p),q);
762                 p+=GetPixelChannels(canvas_image);
763                 q+=GetPixelChannels(image);
764               }
765               if (SyncAuthenticPixels(image,exception) == MagickFalse)
766                 break;
767            }
768           count=ReadBlob(image,length,pixels);
769         }
770         if (image->previous == (Image *) NULL)
771           {
772             status=SetImageProgress(image,LoadImageTag,2,5);
773             if (status == MagickFalse)
774               break;
775           }
776         (void) CloseBlob(image);
777         AppendImageFormat("B",image->filename);
778         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
779         if (status == MagickFalse)
780           {
781             canvas_image=DestroyImageList(canvas_image);
782             image=DestroyImageList(image);
783             return((Image *) NULL);
784           }
785         length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
786         for (i=0; i < (ssize_t) scene; i++)
787           for (y=0; y < (ssize_t) image->extract_info.height; y++)
788             if (ReadBlob(image,length,pixels) != (ssize_t) length)
789               {
790                 ThrowFileException(exception,CorruptImageError,
791                   "UnexpectedEndOfFile",image->filename);
792                 break;
793               }
794         count=ReadBlob(image,length,pixels);
795         for (y=0; y < (ssize_t) image->extract_info.height; y++)
796         {
797           register const Quantum
798             *restrict p;
799
800           register Quantum
801             *restrict q;
802
803           register ssize_t
804             x;
805
806           if (count != (ssize_t) length)
807             {
808               ThrowFileException(exception,CorruptImageError,
809                 "UnexpectedEndOfFile",image->filename);
810               break;
811             }
812           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
813             exception);
814           if (q == (Quantum *) NULL)
815             break;
816           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
817             quantum_info,BlueQuantum,pixels,exception);
818           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
819             break;
820           if (((y-image->extract_info.y) >= 0) && 
821               ((y-image->extract_info.y) < (ssize_t) image->rows))
822             {
823               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
824                 canvas_image->columns,1,exception);
825               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
826                 image->columns,1,exception);
827               if ((p == (const Quantum *) NULL) ||
828                   (q == (Quantum *) NULL))
829                 break;
830               for (x=0; x < (ssize_t) image->columns; x++)
831               {
832                 SetPixelBlue(image,
833                   GetPixelBlue(canvas_image,p),q);
834                 p+=GetPixelChannels(canvas_image);
835                 q+=GetPixelChannels(image);
836               }
837               if (SyncAuthenticPixels(image,exception) == MagickFalse)
838                 break;
839            }
840           count=ReadBlob(image,length,pixels);
841         }
842         if (image->previous == (Image *) NULL)
843           {
844             status=SetImageProgress(image,LoadImageTag,3,5);
845             if (status == MagickFalse)
846               break;
847           }
848         if (image->matte != MagickFalse)
849           {
850             (void) CloseBlob(image);
851             AppendImageFormat("A",image->filename);
852             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
853             if (status == MagickFalse)
854               {
855                 canvas_image=DestroyImageList(canvas_image);
856                 image=DestroyImageList(image);
857                 return((Image *) NULL);
858               }
859             length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
860             for (i=0; i < (ssize_t) scene; i++)
861               for (y=0; y < (ssize_t) image->extract_info.height; y++)
862                 if (ReadBlob(image,length,pixels) != (ssize_t) length)
863                   {
864                     ThrowFileException(exception,CorruptImageError,
865                       "UnexpectedEndOfFile",image->filename);
866                     break;
867                   }
868             count=ReadBlob(image,length,pixels);
869             for (y=0; y < (ssize_t) image->extract_info.height; y++)
870             {
871               register const Quantum
872                 *restrict p;
873
874               register Quantum
875                 *restrict q;
876
877               register ssize_t
878                 x;
879
880               if (count != (ssize_t) length)
881                 {
882                   ThrowFileException(exception,CorruptImageError,
883                     "UnexpectedEndOfFile",image->filename);
884                   break;
885                 }
886               q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
887                 exception);
888               if (q == (Quantum *) NULL)
889                 break;
890               length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
891                 quantum_info,BlueQuantum,pixels,exception);
892               if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
893                 break;
894               if (((y-image->extract_info.y) >= 0) && 
895                   ((y-image->extract_info.y) < (ssize_t) image->rows))
896                 {
897                   p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
898                     0,canvas_image->columns,1,exception);
899                   q=GetAuthenticPixels(image,0,y-image->extract_info.y,
900                     image->columns,1,exception);
901                   if ((p == (const Quantum *) NULL) ||
902                       (q == (Quantum *) NULL))
903                     break;
904                   for (x=0; x < (ssize_t) image->columns; x++)
905                   {
906                     SetPixelAlpha(image,
907                       GetPixelAlpha(canvas_image,p),q);
908                     p+=GetPixelChannels(canvas_image);
909                     q+=GetPixelChannels(image);
910                   }
911                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
912                     break;
913                }
914               count=ReadBlob(image,length,pixels);
915             }
916             if (image->previous == (Image *) NULL)
917               {
918                 status=SetImageProgress(image,LoadImageTag,4,5);
919                 if (status == MagickFalse)
920                   break;
921               }
922           }
923         (void) CloseBlob(image);
924         if (image->previous == (Image *) NULL)
925           {
926             status=SetImageProgress(image,LoadImageTag,5,5);
927             if (status == MagickFalse)
928               break;
929           }
930         break;
931       }
932     }
933     SetQuantumImageType(image,quantum_type);
934     /*
935       Proceed to next image.
936     */
937     if (image_info->number_scenes != 0)
938       if (image->scene >= (image_info->scene+image_info->number_scenes-1))
939         break;
940     if (count == (ssize_t) length)
941       {
942         /*
943           Allocate next image structure.
944         */
945         AcquireNextImage(image_info,image);
946         if (GetNextImageInList(image) == (Image *) NULL)
947           {
948             image=DestroyImageList(image);
949             return((Image *) NULL);
950           }
951         image=SyncNextImageInList(image);
952         status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
953           GetBlobSize(image));
954         if (status == MagickFalse)
955           break;
956       }
957     scene++;
958   } while (count == (ssize_t) length);
959   quantum_info=DestroyQuantumInfo(quantum_info);
960   InheritException(&image->exception,&canvas_image->exception);
961   canvas_image=DestroyImage(canvas_image);
962   (void) CloseBlob(image);
963   return(GetFirstImageInList(image));
964 }
965 \f
966 /*
967 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 %                                                                             %
969 %                                                                             %
970 %                                                                             %
971 %   R e g i s t e r R G B I m a g e                                           %
972 %                                                                             %
973 %                                                                             %
974 %                                                                             %
975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 %
977 %  RegisterRGBImage() adds attributes for the RGB image format to
978 %  the list of supported formats.  The attributes include the image format
979 %  tag, a method to read and/or write the format, whether the format
980 %  supports the saving of more than one frame to the same file or blob,
981 %  whether the format supports native in-memory I/O, and a brief
982 %  description of the format.
983 %
984 %  The format of the RegisterRGBImage method is:
985 %
986 %      size_t RegisterRGBImage(void)
987 %
988 */
989 ModuleExport size_t RegisterRGBImage(void)
990 {
991   MagickInfo
992     *entry;
993
994   entry=SetMagickInfo("RGB");
995   entry->decoder=(DecodeImageHandler *) ReadRGBImage;
996   entry->encoder=(EncodeImageHandler *) WriteRGBImage;
997   entry->raw=MagickTrue;
998   entry->endian_support=MagickTrue;
999   entry->description=ConstantString("Raw red, green, and blue samples");
1000   entry->module=ConstantString("RGB");
1001   (void) RegisterMagickInfo(entry);
1002   entry=SetMagickInfo("RGBA");
1003   entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1004   entry->encoder=(EncodeImageHandler *) WriteRGBImage;
1005   entry->raw=MagickTrue;
1006   entry->endian_support=MagickTrue;
1007   entry->description=ConstantString("Raw red, green, blue, and alpha samples");
1008   entry->module=ConstantString("RGB");
1009   (void) RegisterMagickInfo(entry);
1010   entry=SetMagickInfo("RGBO");
1011   entry->decoder=(DecodeImageHandler *) ReadRGBImage;
1012   entry->encoder=(EncodeImageHandler *) WriteRGBImage;
1013   entry->raw=MagickTrue;
1014   entry->endian_support=MagickTrue;
1015   entry->description=ConstantString("Raw red, green, blue, and opacity samples");
1016   entry->module=ConstantString("RGB");
1017   (void) RegisterMagickInfo(entry);
1018   return(MagickImageCoderSignature);
1019 }
1020 \f
1021 /*
1022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1023 %                                                                             %
1024 %                                                                             %
1025 %                                                                             %
1026 %   U n r e g i s t e r R G B I m a g e                                       %
1027 %                                                                             %
1028 %                                                                             %
1029 %                                                                             %
1030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1031 %
1032 %  UnregisterRGBImage() removes format registrations made by the RGB module
1033 %  from the list of supported formats.
1034 %
1035 %  The format of the UnregisterRGBImage method is:
1036 %
1037 %      UnregisterRGBImage(void)
1038 %
1039 */
1040 ModuleExport void UnregisterRGBImage(void)
1041 {
1042   (void) UnregisterMagickInfo("RGBO");
1043   (void) UnregisterMagickInfo("RGBA");
1044   (void) UnregisterMagickInfo("RGB");
1045 }
1046 \f
1047 /*
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049 %                                                                             %
1050 %                                                                             %
1051 %                                                                             %
1052 %   W r i t e R G B I m a g e                                                 %
1053 %                                                                             %
1054 %                                                                             %
1055 %                                                                             %
1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1057 %
1058 %  WriteRGBImage() writes an image to a file in the RGB, RGBA, or RGBO
1059 %  rasterfile format.
1060 %
1061 %  The format of the WriteRGBImage method is:
1062 %
1063 %      MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1064 %        Image *image,ExceptionInfo *exception)
1065 %
1066 %  A description of each parameter follows.
1067 %
1068 %    o image_info: the image info.
1069 %
1070 %    o image:  The image.
1071 %
1072 %    o exception: return any errors or warnings in this structure.
1073 %
1074 */
1075 static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
1076   Image *image,ExceptionInfo *exception)
1077 {
1078   MagickBooleanType
1079     status;
1080
1081   MagickOffsetType
1082     scene;
1083
1084   QuantumInfo
1085     *quantum_info;
1086
1087   QuantumType
1088     quantum_type;
1089
1090   size_t
1091     length;
1092
1093   ssize_t
1094     count,
1095     y;
1096
1097   unsigned char
1098     *pixels;
1099
1100   /*
1101     Allocate memory for pixels.
1102   */
1103   assert(image_info != (const ImageInfo *) NULL);
1104   assert(image_info->signature == MagickSignature);
1105   assert(image != (Image *) NULL);
1106   assert(image->signature == MagickSignature);
1107   if (image->debug != MagickFalse)
1108     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1109   if (image_info->interlace != PartitionInterlace)
1110     {
1111       /*
1112         Open output image file.
1113       */
1114       assert(exception != (ExceptionInfo *) NULL);
1115   assert(exception->signature == MagickSignature);
1116   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1117       if (status == MagickFalse)
1118         return(status);
1119     }
1120   quantum_type=RGBQuantum;
1121   if (LocaleCompare(image_info->magick,"RGBA") == 0)
1122     {
1123       quantum_type=RGBAQuantum;
1124       image->matte=MagickTrue;
1125     }
1126   if (LocaleCompare(image_info->magick,"RGBO") == 0)
1127     {
1128       quantum_type=RGBOQuantum;
1129       image->matte=MagickTrue;
1130     }
1131   scene=0;
1132   do
1133   {
1134     /*
1135       Convert MIFF to RGB raster pixels.
1136     */
1137     if (IsRGBColorspace(image->colorspace) == MagickFalse)
1138       (void) TransformImageColorspace(image,RGBColorspace);
1139     if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
1140         (image->matte == MagickFalse))
1141       (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
1142     quantum_info=AcquireQuantumInfo(image_info,image);
1143     if (quantum_info == (QuantumInfo *) NULL)
1144       ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1145     pixels=GetQuantumPixels(quantum_info);
1146     switch (image_info->interlace)
1147     {
1148       case NoInterlace:
1149       default:
1150       {
1151         /*
1152           No interlacing:  RGBRGBRGBRGBRGBRGB...
1153         */
1154         for (y=0; y < (ssize_t) image->rows; y++)
1155         {
1156           register const Quantum
1157             *restrict p;
1158
1159           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1160           if (p == (const Quantum *) NULL)
1161             break;
1162           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1163             quantum_type,pixels,exception);
1164           count=WriteBlob(image,length,pixels);
1165           if (count != (ssize_t) length)
1166             break;
1167           if (image->previous == (Image *) NULL)
1168             {
1169               status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1170                 image->rows);
1171               if (status == MagickFalse)
1172                 break;
1173             }
1174         }
1175         break;
1176       }
1177       case LineInterlace:
1178       {
1179         /*
1180           Line interlacing:  RRR...GGG...BBB...RRR...GGG...BBB...
1181         */
1182         for (y=0; y < (ssize_t) image->rows; y++)
1183         {
1184           register const Quantum
1185             *restrict p;
1186
1187           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1188           if (p == (const Quantum *) NULL)
1189             break;
1190           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1191             RedQuantum,pixels,exception);
1192           count=WriteBlob(image,length,pixels);
1193           if (count != (ssize_t) length)
1194             break;
1195           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1196             GreenQuantum,pixels,exception);
1197           count=WriteBlob(image,length,pixels);
1198           if (count != (ssize_t) length)
1199             break;
1200           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1201             BlueQuantum,pixels,exception);
1202           count=WriteBlob(image,length,pixels);
1203           if (count != (ssize_t) length)
1204             break;
1205           if (quantum_type == RGBAQuantum)
1206             {
1207               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1208                 AlphaQuantum,pixels,exception);
1209               count=WriteBlob(image,length,pixels);
1210               if (count != (ssize_t) length)
1211                 break;
1212             }
1213           if (quantum_type == RGBOQuantum)
1214             {
1215               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1216                 OpacityQuantum,pixels,exception);
1217               count=WriteBlob(image,length,pixels);
1218               if (count != (ssize_t) length)
1219                 break;
1220             }
1221           if (image->previous == (Image *) NULL)
1222             {
1223               status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1224                 image->rows);
1225               if (status == MagickFalse)
1226                 break;
1227             }
1228         }
1229         break;
1230       }
1231       case PlaneInterlace:
1232       {
1233         /*
1234           Plane interlacing:  RRRRRR...GGGGGG...BBBBBB...
1235         */
1236         for (y=0; y < (ssize_t) image->rows; y++)
1237         {
1238           register const Quantum
1239             *restrict p;
1240
1241           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1242           if (p == (const Quantum *) NULL)
1243             break;
1244           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1245             RedQuantum,pixels,exception);
1246           count=WriteBlob(image,length,pixels);
1247           if (count != (ssize_t) length)
1248             break;
1249         }
1250         if (image->previous == (Image *) NULL)
1251           {
1252             status=SetImageProgress(image,SaveImageTag,1,6);
1253             if (status == MagickFalse)
1254               break;
1255           }
1256         for (y=0; y < (ssize_t) image->rows; y++)
1257         {
1258           register const Quantum
1259             *restrict p;
1260
1261           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1262           if (p == (const Quantum *) NULL)
1263             break;
1264           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1265             GreenQuantum,pixels,exception);
1266           count=WriteBlob(image,length,pixels);
1267           if (count != (ssize_t) length)
1268             break;
1269         }
1270         if (image->previous == (Image *) NULL)
1271           {
1272             status=SetImageProgress(image,SaveImageTag,2,6);
1273             if (status == MagickFalse)
1274               break;
1275           }
1276         for (y=0; y < (ssize_t) image->rows; y++)
1277         {
1278           register const Quantum
1279             *restrict p;
1280
1281           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1282           if (p == (const Quantum *) NULL)
1283             break;
1284           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1285             BlueQuantum,pixels,exception);
1286           count=WriteBlob(image,length,pixels);
1287           if (count != (ssize_t) length)
1288             break;
1289         }
1290         if (image->previous == (Image *) NULL)
1291           {
1292             status=SetImageProgress(image,SaveImageTag,3,6);
1293             if (status == MagickFalse)
1294               break;
1295           }
1296         if (quantum_type == RGBAQuantum)
1297           {
1298             for (y=0; y < (ssize_t) image->rows; y++)
1299             {
1300               register const Quantum
1301                 *restrict p;
1302
1303               p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1304               if (p == (const Quantum *) NULL)
1305                 break;
1306               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1307                 AlphaQuantum,pixels,exception);
1308               count=WriteBlob(image,length,pixels);
1309               if (count != (ssize_t) length)
1310               break;
1311             }
1312             if (image->previous == (Image *) NULL)
1313               {
1314                 status=SetImageProgress(image,SaveImageTag,5,6);
1315                 if (status == MagickFalse)
1316                   break;
1317               }
1318           }
1319         if (image_info->interlace == PartitionInterlace)
1320           (void) CopyMagickString(image->filename,image_info->filename,
1321             MaxTextExtent);
1322         if (image->previous == (Image *) NULL)
1323           {
1324             status=SetImageProgress(image,SaveImageTag,6,6);
1325             if (status == MagickFalse)
1326               break;
1327           }
1328         break;
1329       }
1330       case PartitionInterlace:
1331       {
1332         /*
1333           Partition interlacing:  RRRRRR..., GGGGGG..., BBBBBB...
1334         */
1335         AppendImageFormat("R",image->filename);
1336         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1337           AppendBinaryBlobMode,exception);
1338         if (status == MagickFalse)
1339           return(status);
1340         for (y=0; y < (ssize_t) image->rows; y++)
1341         {
1342           register const Quantum
1343             *restrict p;
1344
1345           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1346           if (p == (const Quantum *) NULL)
1347             break;
1348           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1349             RedQuantum,pixels,exception);
1350           count=WriteBlob(image,length,pixels);
1351           if (count != (ssize_t) length)
1352             break;
1353         }
1354         if (image->previous == (Image *) NULL)
1355           {
1356             status=SetImageProgress(image,SaveImageTag,1,6);
1357             if (status == MagickFalse)
1358               break;
1359           }
1360         (void) CloseBlob(image);
1361         AppendImageFormat("G",image->filename);
1362         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1363           AppendBinaryBlobMode,exception);
1364         if (status == MagickFalse)
1365           return(status);
1366         for (y=0; y < (ssize_t) image->rows; y++)
1367         {
1368           register const Quantum
1369             *restrict p;
1370
1371           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1372           if (p == (const Quantum *) NULL)
1373             break;
1374           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1375             GreenQuantum,pixels,exception);
1376           count=WriteBlob(image,length,pixels);
1377           if (count != (ssize_t) length)
1378             break;
1379         }
1380         if (image->previous == (Image *) NULL)
1381           {
1382             status=SetImageProgress(image,SaveImageTag,2,6);
1383             if (status == MagickFalse)
1384               break;
1385           }
1386         (void) CloseBlob(image);
1387         AppendImageFormat("B",image->filename);
1388         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1389           AppendBinaryBlobMode,exception);
1390         if (status == MagickFalse)
1391           return(status);
1392         for (y=0; y < (ssize_t) image->rows; y++)
1393         {
1394           register const Quantum
1395             *restrict p;
1396
1397           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1398           if (p == (const Quantum *) NULL)
1399             break;
1400           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1401             BlueQuantum,pixels,exception);
1402           count=WriteBlob(image,length,pixels);
1403           if (count != (ssize_t) length)
1404             break;
1405         }
1406         if (image->previous == (Image *) NULL)
1407           {
1408             status=SetImageProgress(image,SaveImageTag,3,6);
1409             if (status == MagickFalse)
1410               break;
1411           }
1412         (void) CloseBlob(image);
1413         if (quantum_type == RGBAQuantum)
1414           {
1415             (void) CloseBlob(image);
1416             AppendImageFormat("A",image->filename);
1417             status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
1418               AppendBinaryBlobMode,exception);
1419             if (status == MagickFalse)
1420               return(status);
1421             for (y=0; y < (ssize_t) image->rows; y++)
1422             {
1423               register const Quantum
1424                 *restrict p;
1425
1426               p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1427               if (p == (const Quantum *) NULL)
1428                 break;
1429               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1430                 AlphaQuantum,pixels,exception);
1431               count=WriteBlob(image,length,pixels);
1432               if (count != (ssize_t) length)
1433                 break;
1434             }
1435             if (image->previous == (Image *) NULL)
1436               {
1437                 status=SetImageProgress(image,SaveImageTag,5,6);
1438                 if (status == MagickFalse)
1439                   break;
1440               }
1441           }
1442         (void) CloseBlob(image);
1443         (void) CopyMagickString(image->filename,image_info->filename,
1444           MaxTextExtent);
1445         if (image->previous == (Image *) NULL)
1446           {
1447             status=SetImageProgress(image,SaveImageTag,6,6);
1448             if (status == MagickFalse)
1449               break;
1450           }
1451         break;
1452       }
1453     }
1454     quantum_info=DestroyQuantumInfo(quantum_info);
1455     if (GetNextImageInList(image) == (Image *) NULL)
1456       break;
1457     image=SyncNextImageInList(image);
1458     status=SetImageProgress(image,SaveImagesTag,scene++,
1459       GetImageListLength(image));
1460     if (status == MagickFalse)
1461       break;
1462   } while (image_info->adjoin != MagickFalse);
1463   (void) CloseBlob(image);
1464   return(MagickTrue);
1465 }