]> granicus.if.org Git - imagemagick/blob - coders/viff.c
(no commit message)
[imagemagick] / coders / viff.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                        V   V  IIIII  FFFFF  FFFFF                           %
7 %                        V   V    I    F      F                               %
8 %                        V   V    I    FFF    FFF                             %
9 %                         V V     I    F      F                               %
10 %                          V    IIIII  F      F                               %
11 %                                                                             %
12 %                                                                             %
13 %                Read/Write Khoros Visualization Image Format                 %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2011 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/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colormap.h"
50 #include "MagickCore/colorspace.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/image.h"
54 #include "MagickCore/image-private.h"
55 #include "MagickCore/list.h"
56 #include "MagickCore/magick.h"
57 #include "MagickCore/memory_.h"
58 #include "MagickCore/monitor.h"
59 #include "MagickCore/monitor-private.h"
60 #include "MagickCore/pixel-accessor.h"
61 #include "MagickCore/property.h"
62 #include "MagickCore/quantum-private.h"
63 #include "MagickCore/static.h"
64 #include "MagickCore/string_.h"
65 #include "MagickCore/module.h"
66 \f
67 /*
68   Forward declarations.
69 */
70 static MagickBooleanType
71   WriteVIFFImage(const ImageInfo *,Image *);
72 \f
73 /*
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %                                                                             %
76 %                                                                             %
77 %                                                                             %
78 %   I s V I F F                                                               %
79 %                                                                             %
80 %                                                                             %
81 %                                                                             %
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 %
84 %  IsVIFF() returns MagickTrue if the image format type, identified by the
85 %  magick string, is VIFF.
86 %
87 %  The format of the IsVIFF method is:
88 %
89 %      MagickBooleanType IsVIFF(const unsigned char *magick,const size_t length)
90 %
91 %  A description of each parameter follows:
92 %
93 %    o magick: compare image format pattern against these bytes.
94 %
95 %    o length: Specifies the length of the magick string.
96 %
97 */
98 static MagickBooleanType IsVIFF(const unsigned char *magick,const size_t length)
99 {
100   if (length < 2)
101     return(MagickFalse);
102   if (memcmp(magick,"\253\001",2) == 0)
103     return(MagickTrue);
104   return(MagickFalse);
105 }
106 \f
107 /*
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %                                                                             %
110 %                                                                             %
111 %                                                                             %
112 %   R e a d V I F F I m a g e                                                 %
113 %                                                                             %
114 %                                                                             %
115 %                                                                             %
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 %
118 %  ReadVIFFImage() reads a Khoros Visualization image file and returns
119 %  it.  It allocates the memory necessary for the new Image structure and
120 %  returns a pointer to the new image.
121 %
122 %  The format of the ReadVIFFImage method is:
123 %
124 %      Image *ReadVIFFImage(const ImageInfo *image_info,
125 %        ExceptionInfo *exception)
126 %
127 %  A description of each parameter follows:
128 %
129 %    o image: Method ReadVIFFImage returns a pointer to the image after
130 %      reading.  A null image is returned if there is a memory shortage or if
131 %      the image cannot be read.
132 %
133 %    o image_info: the image info.
134 %
135 %    o exception: return any errors or warnings in this structure.
136 %
137 */
138 static Image *ReadVIFFImage(const ImageInfo *image_info,
139   ExceptionInfo *exception)
140 {
141 #define VFF_CM_genericRGB  15
142 #define VFF_CM_ntscRGB  1
143 #define VFF_CM_NONE  0
144 #define VFF_DEP_DECORDER  0x4
145 #define VFF_DEP_NSORDER  0x8
146 #define VFF_DES_RAW  0
147 #define VFF_LOC_IMPLICIT  1
148 #define VFF_MAPTYP_NONE  0
149 #define VFF_MAPTYP_1_BYTE  1
150 #define VFF_MAPTYP_2_BYTE  2
151 #define VFF_MAPTYP_4_BYTE  4
152 #define VFF_MAPTYP_FLOAT  5
153 #define VFF_MAPTYP_DOUBLE  7
154 #define VFF_MS_NONE  0
155 #define VFF_MS_ONEPERBAND  1
156 #define VFF_MS_SHARED  3
157 #define VFF_TYP_BIT  0
158 #define VFF_TYP_1_BYTE  1
159 #define VFF_TYP_2_BYTE  2
160 #define VFF_TYP_4_BYTE  4
161 #define VFF_TYP_FLOAT  5
162 #define VFF_TYP_DOUBLE  9
163
164   typedef struct _ViffInfo
165   {
166     unsigned char
167       identifier,
168       file_type,
169       release,
170       version,
171       machine_dependency,
172       reserve[3];
173
174     char
175       comment[512];
176
177     unsigned int
178       rows,
179       columns,
180       subrows;
181
182     int
183       x_offset,
184       y_offset;
185
186     float
187       x_bits_per_pixel,
188       y_bits_per_pixel;
189
190     unsigned int
191       location_type,
192       location_dimension,
193       number_of_images,
194       number_data_bands,
195       data_storage_type,
196       data_encode_scheme,
197       map_scheme,
198       map_storage_type,
199       map_rows,
200       map_columns,
201       map_subrows,
202       map_enable,
203       maps_per_cycle,
204       color_space_model;
205   } ViffInfo;
206
207   double
208     min_value,
209     scale_factor,
210     value;
211
212   Image
213     *image;
214
215   int
216     bit;
217
218   MagickBooleanType
219     status;
220
221   MagickSizeType
222     number_pixels;
223
224   register ssize_t
225     x;
226
227   register Quantum
228     *q;
229
230   register ssize_t
231     i;
232
233   register unsigned char
234     *p;
235
236   size_t
237     bytes_per_pixel,
238     lsb_first,
239     max_packets,
240     quantum;
241
242   ssize_t
243     count,
244     y;
245
246   unsigned char
247     buffer[7],
248     *viff_pixels;
249
250   ViffInfo
251     viff_info;
252
253   /*
254     Open image file.
255   */
256   assert(image_info != (const ImageInfo *) NULL);
257   assert(image_info->signature == MagickSignature);
258   if (image_info->debug != MagickFalse)
259     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
260       image_info->filename);
261   assert(exception != (ExceptionInfo *) NULL);
262   assert(exception->signature == MagickSignature);
263   image=AcquireImage(image_info);
264   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
265   if (status == MagickFalse)
266     {
267       image=DestroyImageList(image);
268       return((Image *) NULL);
269     }
270   /*
271     Read VIFF header (1024 bytes).
272   */
273   count=ReadBlob(image,1,&viff_info.identifier);
274   do
275   {
276     /*
277       Verify VIFF identifier.
278     */
279     if ((count == 0) || ((unsigned char) viff_info.identifier != 0xab))
280       ThrowReaderException(CorruptImageError,"NotAVIFFImage");
281     /*
282       Initialize VIFF image.
283     */
284     count=ReadBlob(image,7,buffer);
285     viff_info.file_type=buffer[0];
286     viff_info.release=buffer[1];
287     viff_info.version=buffer[2];
288     viff_info.machine_dependency=buffer[3];
289     count=ReadBlob(image,512,(unsigned char *) viff_info.comment);
290     viff_info.comment[511]='\0';
291     if (strlen(viff_info.comment) > 4)
292       (void) SetImageProperty(image,"comment",viff_info.comment);
293     if ((viff_info.machine_dependency == VFF_DEP_DECORDER) ||
294         (viff_info.machine_dependency == VFF_DEP_NSORDER))
295       {
296         viff_info.rows=ReadBlobLSBLong(image);
297         viff_info.columns=ReadBlobLSBLong(image);
298         viff_info.subrows=ReadBlobLSBLong(image);
299         viff_info.x_offset=(int) ReadBlobLSBLong(image);
300         viff_info.y_offset=(int) ReadBlobLSBLong(image);
301         viff_info.x_bits_per_pixel=(float) ReadBlobLSBLong(image);
302         viff_info.y_bits_per_pixel=(float) ReadBlobLSBLong(image);
303         viff_info.location_type=ReadBlobLSBLong(image);
304         viff_info.location_dimension=ReadBlobLSBLong(image);
305         viff_info.number_of_images=ReadBlobLSBLong(image);
306         viff_info.number_data_bands=ReadBlobLSBLong(image);
307         viff_info.data_storage_type=ReadBlobLSBLong(image);
308         viff_info.data_encode_scheme=ReadBlobLSBLong(image);
309         viff_info.map_scheme=ReadBlobLSBLong(image);
310         viff_info.map_storage_type=ReadBlobLSBLong(image);
311         viff_info.map_rows=ReadBlobLSBLong(image);
312         viff_info.map_columns=ReadBlobLSBLong(image);
313         viff_info.map_subrows=ReadBlobLSBLong(image);
314         viff_info.map_enable=ReadBlobLSBLong(image);
315         viff_info.maps_per_cycle=ReadBlobLSBLong(image);
316         viff_info.color_space_model=ReadBlobLSBLong(image);
317       }
318     else
319       {
320         viff_info.rows=ReadBlobMSBLong(image);
321         viff_info.columns=ReadBlobMSBLong(image);
322         viff_info.subrows=ReadBlobMSBLong(image);
323         viff_info.x_offset=(int) ReadBlobMSBLong(image);
324         viff_info.y_offset=(int) ReadBlobMSBLong(image);
325         viff_info.x_bits_per_pixel=(float) ReadBlobMSBLong(image);
326         viff_info.y_bits_per_pixel=(float) ReadBlobMSBLong(image);
327         viff_info.location_type=ReadBlobMSBLong(image);
328         viff_info.location_dimension=ReadBlobMSBLong(image);
329         viff_info.number_of_images=ReadBlobMSBLong(image);
330         viff_info.number_data_bands=ReadBlobMSBLong(image);
331         viff_info.data_storage_type=ReadBlobMSBLong(image);
332         viff_info.data_encode_scheme=ReadBlobMSBLong(image);
333         viff_info.map_scheme=ReadBlobMSBLong(image);
334         viff_info.map_storage_type=ReadBlobMSBLong(image);
335         viff_info.map_rows=ReadBlobMSBLong(image);
336         viff_info.map_columns=ReadBlobMSBLong(image);
337         viff_info.map_subrows=ReadBlobMSBLong(image);
338         viff_info.map_enable=ReadBlobMSBLong(image);
339         viff_info.maps_per_cycle=ReadBlobMSBLong(image);
340         viff_info.color_space_model=ReadBlobMSBLong(image);
341       }
342     for (i=0; i < 420; i++)
343       (void) ReadBlobByte(image);
344     image->columns=viff_info.rows;
345     image->rows=viff_info.columns;
346     image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL :
347       MAGICKCORE_QUANTUM_DEPTH;
348     /*
349       Verify that we can read this VIFF image.
350     */
351     number_pixels=(MagickSizeType) viff_info.columns*viff_info.rows;
352     if (number_pixels != (size_t) number_pixels)
353       ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
354     if (number_pixels == 0)
355       ThrowReaderException(CoderError,"ImageColumnOrRowSizeIsNotSupported");
356     if ((viff_info.number_data_bands < 1) || (viff_info.number_data_bands > 4))
357       ThrowReaderException(CorruptImageError,"ImproperImageHeader");
358     if ((viff_info.data_storage_type != VFF_TYP_BIT) &&
359         (viff_info.data_storage_type != VFF_TYP_1_BYTE) &&
360         (viff_info.data_storage_type != VFF_TYP_2_BYTE) &&
361         (viff_info.data_storage_type != VFF_TYP_4_BYTE) &&
362         (viff_info.data_storage_type != VFF_TYP_FLOAT) &&
363         (viff_info.data_storage_type != VFF_TYP_DOUBLE))
364       ThrowReaderException(CoderError,"DataStorageTypeIsNotSupported");
365     if (viff_info.data_encode_scheme != VFF_DES_RAW)
366       ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported");
367     if ((viff_info.map_storage_type != VFF_MAPTYP_NONE) &&
368         (viff_info.map_storage_type != VFF_MAPTYP_1_BYTE) &&
369         (viff_info.map_storage_type != VFF_MAPTYP_2_BYTE) &&
370         (viff_info.map_storage_type != VFF_MAPTYP_4_BYTE) &&
371         (viff_info.map_storage_type != VFF_MAPTYP_FLOAT) &&
372         (viff_info.map_storage_type != VFF_MAPTYP_DOUBLE))
373       ThrowReaderException(CoderError,"MapStorageTypeIsNotSupported");
374     if ((viff_info.color_space_model != VFF_CM_NONE) &&
375         (viff_info.color_space_model != VFF_CM_ntscRGB) &&
376         (viff_info.color_space_model != VFF_CM_genericRGB))
377       ThrowReaderException(CoderError,"ColorspaceModelIsNotSupported");
378     if (viff_info.location_type != VFF_LOC_IMPLICIT)
379       ThrowReaderException(CoderError,"LocationTypeIsNotSupported");
380     if (viff_info.number_of_images != 1)
381       ThrowReaderException(CoderError,"NumberOfImagesIsNotSupported");
382     if (viff_info.map_rows == 0)
383       viff_info.map_scheme=VFF_MS_NONE;
384     switch ((int) viff_info.map_scheme)
385     {
386       case VFF_MS_NONE:
387       {
388         if (viff_info.number_data_bands < 3)
389           {
390             /*
391               Create linear color ramp.
392             */
393             image->colors=image->depth <= 8 ? 256UL : 65536UL;
394             if (viff_info.data_storage_type == VFF_TYP_BIT)
395               image->colors=2;
396             if (AcquireImageColormap(image,image->colors) == MagickFalse)
397               ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
398           }
399         break;
400       }
401       case VFF_MS_ONEPERBAND:
402       case VFF_MS_SHARED:
403       {
404         unsigned char
405           *viff_colormap;
406
407         /*
408           Allocate VIFF colormap.
409         */
410         switch ((int) viff_info.map_storage_type)
411         {
412           case VFF_MAPTYP_1_BYTE: bytes_per_pixel=1; break;
413           case VFF_MAPTYP_2_BYTE: bytes_per_pixel=2; break;
414           case VFF_MAPTYP_4_BYTE: bytes_per_pixel=4; break;
415           case VFF_MAPTYP_FLOAT: bytes_per_pixel=4; break;
416           case VFF_MAPTYP_DOUBLE: bytes_per_pixel=8; break;
417           default: bytes_per_pixel=1; break;
418         }
419         image->colors=viff_info.map_columns;
420         if (AcquireImageColormap(image,image->colors) == MagickFalse)
421           ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
422         viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
423           viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap));
424         if (viff_colormap == (unsigned char *) NULL)
425           ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
426         /*
427           Read VIFF raster colormap.
428         */
429         count=ReadBlob(image,bytes_per_pixel*image->colors*viff_info.map_rows,
430           viff_colormap);
431         lsb_first=1;
432         if (*(char *) &lsb_first &&
433             ((viff_info.machine_dependency != VFF_DEP_DECORDER) &&
434              (viff_info.machine_dependency != VFF_DEP_NSORDER)))
435           switch ((int) viff_info.map_storage_type)
436           {
437             case VFF_MAPTYP_2_BYTE:
438             {
439               MSBOrderShort(viff_colormap,(bytes_per_pixel*image->colors*
440                 viff_info.map_rows));
441               break;
442             }
443             case VFF_MAPTYP_4_BYTE:
444             case VFF_MAPTYP_FLOAT:
445             {
446               MSBOrderLong(viff_colormap,(bytes_per_pixel*image->colors*
447                 viff_info.map_rows));
448               break;
449             }
450             default: break;
451           }
452         for (i=0; i < (ssize_t) (viff_info.map_rows*image->colors); i++)
453         {
454           switch ((int) viff_info.map_storage_type)
455           {
456             case VFF_MAPTYP_2_BYTE: value=1.0*((short *) viff_colormap)[i]; break;
457             case VFF_MAPTYP_4_BYTE: value=1.0*((int *) viff_colormap)[i]; break;
458             case VFF_MAPTYP_FLOAT: value=((float *) viff_colormap)[i]; break;
459             case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break;
460             default: value=1.0*viff_colormap[i]; break;
461           }
462           if (i < (ssize_t) image->colors)
463             {
464               image->colormap[i].red=ScaleCharToQuantum((unsigned char) value);
465               image->colormap[i].green=
466                 ScaleCharToQuantum((unsigned char) value);
467               image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value);
468             }
469           else
470             if (i < (ssize_t) (2*image->colors))
471               image->colormap[i % image->colors].green=
472                 ScaleCharToQuantum((unsigned char) value);
473             else
474               if (i < (ssize_t) (3*image->colors))
475                 image->colormap[i % image->colors].blue=
476                   ScaleCharToQuantum((unsigned char) value);
477         }
478         viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap);
479         break;
480       }
481       default:
482         ThrowReaderException(CoderError,"ColormapTypeNotSupported");
483     }
484     /*
485       Initialize image structure.
486     */
487     image->matte=viff_info.number_data_bands == 4 ? MagickTrue : MagickFalse;
488     image->storage_class=
489       (viff_info.number_data_bands < 3 ? PseudoClass : DirectClass);
490     image->columns=viff_info.rows;
491     image->rows=viff_info.columns;
492     if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
493       if (image->scene >= (image_info->scene+image_info->number_scenes-1))
494         break;
495     /*
496       Allocate VIFF pixels.
497     */
498     switch ((int) viff_info.data_storage_type)
499     {
500       case VFF_TYP_2_BYTE: bytes_per_pixel=2; break;
501       case VFF_TYP_4_BYTE: bytes_per_pixel=4; break;
502       case VFF_TYP_FLOAT: bytes_per_pixel=4; break;
503       case VFF_TYP_DOUBLE: bytes_per_pixel=8; break;
504       default: bytes_per_pixel=1; break;
505     }
506     if (viff_info.data_storage_type == VFF_TYP_BIT)
507       max_packets=((image->columns+7UL) >> 3UL)*image->rows;
508     else
509       max_packets=(size_t) (number_pixels*viff_info.number_data_bands);
510     viff_pixels=(unsigned char *) AcquireQuantumMemory(max_packets,
511       bytes_per_pixel*sizeof(*viff_pixels));
512     if (viff_pixels == (unsigned char *) NULL)
513       ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
514     count=ReadBlob(image,bytes_per_pixel*max_packets,viff_pixels);
515     lsb_first=1;
516     if (*(char *) &lsb_first &&
517         ((viff_info.machine_dependency != VFF_DEP_DECORDER) &&
518          (viff_info.machine_dependency != VFF_DEP_NSORDER)))
519       switch ((int) viff_info.data_storage_type)
520       {
521         case VFF_TYP_2_BYTE:
522         {
523           MSBOrderShort(viff_pixels,bytes_per_pixel*max_packets);
524           break;
525         }
526         case VFF_TYP_4_BYTE:
527         case VFF_TYP_FLOAT:
528         {
529           MSBOrderLong(viff_pixels,bytes_per_pixel*max_packets);
530           break;
531         }
532         default: break;
533       }
534     min_value=0.0;
535     scale_factor=1.0;
536     if ((viff_info.data_storage_type != VFF_TYP_1_BYTE) &&
537         (viff_info.map_scheme == VFF_MS_NONE))
538       {
539         double
540           max_value;
541
542         /*
543           Determine scale factor.
544         */
545         switch ((int) viff_info.data_storage_type)
546         {
547           case VFF_TYP_2_BYTE: value=1.0*((short *) viff_pixels)[0]; break;
548           case VFF_TYP_4_BYTE: value=1.0*((int *) viff_pixels)[0]; break;
549           case VFF_TYP_FLOAT: value=((float *) viff_pixels)[0]; break;
550           case VFF_TYP_DOUBLE: value=((double *) viff_pixels)[0]; break;
551           default: value=1.0*viff_pixels[0]; break;
552         }
553         max_value=value;
554         min_value=value;
555         for (i=0; i < (ssize_t) max_packets; i++)
556         {
557           switch ((int) viff_info.data_storage_type)
558           {
559             case VFF_TYP_2_BYTE: value=1.0*((short *) viff_pixels)[i]; break;
560             case VFF_TYP_4_BYTE: value=1.0*((int *) viff_pixels)[i]; break;
561             case VFF_TYP_FLOAT: value=((float *) viff_pixels)[i]; break;
562             case VFF_TYP_DOUBLE: value=((double *) viff_pixels)[i]; break;
563             default: value=1.0*viff_pixels[i]; break;
564           }
565           if (value > max_value)
566             max_value=value;
567           else
568             if (value < min_value)
569               min_value=value;
570         }
571         if ((min_value == 0) && (max_value == 0))
572           scale_factor=0;
573         else
574           if (min_value == max_value)
575             {
576               scale_factor=(MagickRealType) QuantumRange/min_value;
577               min_value=0;
578             }
579           else
580             scale_factor=(MagickRealType) QuantumRange/(max_value-min_value);
581       }
582     /*
583       Convert pixels to Quantum size.
584     */
585     p=(unsigned char *) viff_pixels;
586     for (i=0; i < (ssize_t) max_packets; i++)
587     {
588       switch ((int) viff_info.data_storage_type)
589       {
590         case VFF_TYP_2_BYTE: value=1.0*((short *) viff_pixels)[i]; break;
591         case VFF_TYP_4_BYTE: value=1.0*((int *) viff_pixels)[i]; break;
592         case VFF_TYP_FLOAT: value=((float *) viff_pixels)[i]; break;
593         case VFF_TYP_DOUBLE: value=((double *) viff_pixels)[i]; break;
594         default: value=1.0*viff_pixels[i]; break;
595       }
596       if (viff_info.map_scheme == VFF_MS_NONE)
597         {
598           value=(value-min_value)*scale_factor;
599           if (value > QuantumRange)
600             value=QuantumRange;
601           else
602             if (value < 0)
603               value=0;
604         }
605       *p=(unsigned char) value;
606       p++;
607     }
608     /*
609       Convert VIFF raster image to pixel packets.
610     */
611     p=(unsigned char *) viff_pixels;
612     if (viff_info.data_storage_type == VFF_TYP_BIT)
613       {
614         /*
615           Convert bitmap scanline.
616         */
617         (void) SetImageType(image,BilevelType);
618         (void) SetImageType(image,PaletteType);
619         for (y=0; y < (ssize_t) image->rows; y++)
620         {
621           q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
622           if (q == (const Quantum *) NULL)
623             break;
624           for (x=0; x < (ssize_t) (image->columns-7); x+=8)
625           {
626             for (bit=0; bit < 8; bit++)
627             {
628               if (GetPixelIntensity(image,q) < ((MagickRealType) QuantumRange/2.0))
629                 {
630                   quantum=(size_t) GetPixelIndex(image,q);
631                   quantum|=0x01;
632                   SetPixelIndex(image,quantum,q);
633                 }
634               q+=GetPixelChannels(image);
635             }
636             p++;
637           }
638           if ((image->columns % 8) != 0)
639             {
640               for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
641                 if (GetPixelIntensity(image,q) < ((MagickRealType) QuantumRange/2.0))
642                   {
643                     quantum=(size_t) GetPixelIndex(image,q);
644                     quantum|=0x01;
645                     SetPixelIndex(image,quantum,q);
646                     q+=GetPixelChannels(image);
647                   }
648               p++;
649             }
650           if (SyncAuthenticPixels(image,exception) == MagickFalse)
651             break;
652           if (image->previous == (Image *) NULL)
653             {
654               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
655                 image->rows);
656               if (status == MagickFalse)
657                 break;
658             }
659         }
660       }
661     else
662       if (image->storage_class == PseudoClass)
663         for (y=0; y < (ssize_t) image->rows; y++)
664         {
665           q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
666           if (q == (const Quantum *) NULL)
667             break;
668           for (x=0; x < (ssize_t) image->columns; x++)
669           {
670             SetPixelIndex(image,*p++,q);
671             q+=GetPixelChannels(image);
672           }
673           if (SyncAuthenticPixels(image,exception) == MagickFalse)
674             break;
675           if (image->previous == (Image *) NULL)
676             {
677               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
678                 image->rows);
679               if (status == MagickFalse)
680                 break;
681             }
682         }
683       else
684         {
685           /*
686             Convert DirectColor scanline.
687           */
688           number_pixels=(MagickSizeType) image->columns*image->rows;
689           for (y=0; y < (ssize_t) image->rows; y++)
690           {
691             q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
692             if (q == (const Quantum *) NULL)
693               break;
694             for (x=0; x < (ssize_t) image->columns; x++)
695             {
696               SetPixelRed(image,ScaleCharToQuantum(*p),q);
697               SetPixelGreen(image,ScaleCharToQuantum(*(p+number_pixels)),q);
698               SetPixelBlue(image,ScaleCharToQuantum(*(p+2*number_pixels)),q);
699               if (image->colors != 0)
700                 {
701                   SetPixelRed(image,image->colormap[(ssize_t)
702                     GetPixelRed(image,q)].red,q);
703                   SetPixelGreen(image,image->colormap[(ssize_t)
704                     GetPixelGreen(image,q)].green,q);
705                   SetPixelBlue(image,image->colormap[(ssize_t)
706                     GetPixelBlue(image,q)].blue,q);
707                 }
708               SetPixelAlpha(image,image->matte != MagickFalse ?
709                 ScaleCharToQuantum(*(p+number_pixels*3)) : OpaqueAlpha,q);
710               p++;
711               q+=GetPixelChannels(image);
712             }
713             if (SyncAuthenticPixels(image,exception) == MagickFalse)
714               break;
715             if (image->previous == (Image *) NULL)
716               {
717                 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
718                 image->rows);
719                 if (status == MagickFalse)
720                   break;
721               }
722           }
723         }
724     viff_pixels=(unsigned char *) RelinquishMagickMemory(viff_pixels);
725     if (image->storage_class == PseudoClass)
726       (void) SyncImage(image);
727     if (EOFBlob(image) != MagickFalse)
728       {
729         ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
730           image->filename);
731         break;
732       }
733     /*
734       Proceed to next image.
735     */
736     if (image_info->number_scenes != 0)
737       if (image->scene >= (image_info->scene+image_info->number_scenes-1))
738         break;
739     count=ReadBlob(image,1,&viff_info.identifier);
740     if ((count != 0) && (viff_info.identifier == 0xab))
741       {
742         /*
743           Allocate next image structure.
744         */
745         AcquireNextImage(image_info,image);
746         if (GetNextImageInList(image) == (Image *) NULL)
747           {
748             image=DestroyImageList(image);
749             return((Image *) NULL);
750           }
751         image=SyncNextImageInList(image);
752         status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
753           GetBlobSize(image));
754         if (status == MagickFalse)
755           break;
756       }
757   } while ((count != 0) && (viff_info.identifier == 0xab));
758   (void) CloseBlob(image);
759   return(GetFirstImageInList(image));
760 }
761 \f
762 /*
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 %                                                                             %
765 %                                                                             %
766 %                                                                             %
767 %   R e g i s t e r V I F F I m a g e                                         %
768 %                                                                             %
769 %                                                                             %
770 %                                                                             %
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
772 %
773 %  RegisterVIFFImage() adds properties for the VIFF image format to
774 %  the list of supported formats.  The properties include the image format
775 %  tag, a method to read and/or write the format, whether the format
776 %  supports the saving of more than one frame to the same file or blob,
777 %  whether the format supports native in-memory I/O, and a brief
778 %  description of the format.
779 %
780 %  The format of the RegisterVIFFImage method is:
781 %
782 %      size_t RegisterVIFFImage(void)
783 %
784 */
785 ModuleExport size_t RegisterVIFFImage(void)
786 {
787   MagickInfo
788     *entry;
789
790   entry=SetMagickInfo("VIFF");
791   entry->decoder=(DecodeImageHandler *) ReadVIFFImage;
792   entry->encoder=(EncodeImageHandler *) WriteVIFFImage;
793   entry->magick=(IsImageFormatHandler *) IsVIFF;
794   entry->description=ConstantString("Khoros Visualization image");
795   entry->module=ConstantString("VIFF");
796   (void) RegisterMagickInfo(entry);
797   entry=SetMagickInfo("XV");
798   entry->decoder=(DecodeImageHandler *) ReadVIFFImage;
799   entry->encoder=(EncodeImageHandler *) WriteVIFFImage;
800   entry->description=ConstantString("Khoros Visualization image");
801   entry->module=ConstantString("VIFF");
802   (void) RegisterMagickInfo(entry);
803   return(MagickImageCoderSignature);
804 }
805 \f
806 /*
807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
808 %                                                                             %
809 %                                                                             %
810 %                                                                             %
811 %   U n r e g i s t e r V I F F I m a g e                                     %
812 %                                                                             %
813 %                                                                             %
814 %                                                                             %
815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 %
817 %  UnregisterVIFFImage() removes format registrations made by the
818 %  VIFF module from the list of supported formats.
819 %
820 %  The format of the UnregisterVIFFImage method is:
821 %
822 %      UnregisterVIFFImage(void)
823 %
824 */
825 ModuleExport void UnregisterVIFFImage(void)
826 {
827   (void) UnregisterMagickInfo("VIFF");
828   (void) UnregisterMagickInfo("XV");
829 }
830 \f
831 /*
832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
833 %                                                                             %
834 %                                                                             %
835 %                                                                             %
836 %   W r i t e V I F F I m a g e                                               %
837 %                                                                             %
838 %                                                                             %
839 %                                                                             %
840 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
841 %
842 %  WriteVIFFImage() writes an image to a file in the VIFF image format.
843 %
844 %  The format of the WriteVIFFImage method is:
845 %
846 %      MagickBooleanType WriteVIFFImage(const ImageInfo *image_info,
847 %        Image *image)
848 %
849 %  A description of each parameter follows.
850 %
851 %    o image_info: the image info.
852 %
853 %    o image:  The image.
854 %
855 */
856
857 static inline size_t MagickMin(const size_t x,const size_t y)
858 {
859   if (x < y)
860     return(x);
861   return(y);
862 }
863
864 static MagickBooleanType WriteVIFFImage(const ImageInfo *image_info,
865   Image *image)
866 {
867 #define VFF_CM_genericRGB  15
868 #define VFF_CM_NONE  0
869 #define VFF_DEP_IEEEORDER  0x2
870 #define VFF_DES_RAW  0
871 #define VFF_LOC_IMPLICIT  1
872 #define VFF_MAPTYP_NONE  0
873 #define VFF_MAPTYP_1_BYTE  1
874 #define VFF_MS_NONE  0
875 #define VFF_MS_ONEPERBAND  1
876 #define VFF_TYP_BIT  0
877 #define VFF_TYP_1_BYTE  1
878
879   typedef struct _ViffInfo
880   {
881     char
882       identifier,
883       file_type,
884       release,
885       version,
886       machine_dependency,
887       reserve[3],
888       comment[512];
889
890     size_t
891       rows,
892       columns,
893       subrows;
894
895     int
896       x_offset,
897       y_offset;
898
899     unsigned int
900       x_bits_per_pixel,
901       y_bits_per_pixel,
902       location_type,
903       location_dimension,
904       number_of_images,
905       number_data_bands,
906       data_storage_type,
907       data_encode_scheme,
908       map_scheme,
909       map_storage_type,
910       map_rows,
911       map_columns,
912       map_subrows,
913       map_enable,
914       maps_per_cycle,
915       color_space_model;
916   } ViffInfo;
917
918   const char
919     *value;
920
921   MagickBooleanType
922     status;
923
924   MagickOffsetType
925     scene;
926
927   MagickSizeType
928     number_pixels,
929     packets;
930
931   register const Quantum
932     *p;
933
934   register ssize_t
935     x;
936
937   register ssize_t
938     i;
939
940   register unsigned char
941     *q;
942
943   ssize_t
944     y;
945
946   unsigned char
947     buffer[8],
948     *viff_pixels;
949
950   ViffInfo
951     viff_info;
952
953   /*
954     Open output image file.
955   */
956   assert(image_info != (const ImageInfo *) NULL);
957   assert(image_info->signature == MagickSignature);
958   assert(image != (Image *) NULL);
959   assert(image->signature == MagickSignature);
960   if (image->debug != MagickFalse)
961     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
962   status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
963   if (status == MagickFalse)
964     return(status);
965   (void) ResetMagickMemory(&viff_info,0,sizeof(ViffInfo));
966   scene=0;
967   do
968   {
969     /*
970       Initialize VIFF image structure.
971     */
972     if (image->colorspace != RGBColorspace)
973       (void) TransformImageColorspace(image,RGBColorspace);
974     if (IsImageGray(image,&image->exception) != MagickFalse)
975       (void) SetImageStorageClass(image,DirectClass);
976     viff_info.identifier=(char) 0xab;
977     viff_info.file_type=1;
978     viff_info.release=1;
979     viff_info.version=3;
980     viff_info.machine_dependency=VFF_DEP_IEEEORDER;  /* IEEE byte ordering */
981     *viff_info.comment='\0';
982     value=GetImageProperty(image,"comment");
983     if (value != (const char *) NULL)
984       (void) CopyMagickString(viff_info.comment,value,MagickMin(strlen(value),
985         511)+1);
986     viff_info.rows=image->columns;
987     viff_info.columns=image->rows;
988     viff_info.subrows=0;
989     viff_info.x_offset=(~0);
990     viff_info.y_offset=(~0);
991     viff_info.x_bits_per_pixel=0;
992     viff_info.y_bits_per_pixel=0;
993     viff_info.location_type=VFF_LOC_IMPLICIT;
994     viff_info.location_dimension=0;
995     viff_info.number_of_images=1;
996     viff_info.data_encode_scheme=VFF_DES_RAW;
997     viff_info.map_scheme=VFF_MS_NONE;
998     viff_info.map_storage_type=VFF_MAPTYP_NONE;
999     viff_info.map_rows=0;
1000     viff_info.map_columns=0;
1001     viff_info.map_subrows=0;
1002     viff_info.map_enable=1;  /* no colormap */
1003     viff_info.maps_per_cycle=0;
1004     number_pixels=(MagickSizeType) image->columns*image->rows;
1005     if (image->storage_class == DirectClass)
1006       {
1007         /*
1008           Full color VIFF raster.
1009         */
1010         viff_info.number_data_bands=image->matte ? 4UL : 3UL;
1011         viff_info.color_space_model=VFF_CM_genericRGB;
1012         viff_info.data_storage_type=VFF_TYP_1_BYTE;
1013         packets=viff_info.number_data_bands*number_pixels;
1014       }
1015     else
1016       {
1017         viff_info.number_data_bands=1;
1018         viff_info.color_space_model=VFF_CM_NONE;
1019         viff_info.data_storage_type=VFF_TYP_1_BYTE;
1020         packets=number_pixels;
1021         if (IsImageGray(image,&image->exception) == MagickFalse)
1022           {
1023             /*
1024               Colormapped VIFF raster.
1025             */
1026             viff_info.map_scheme=VFF_MS_ONEPERBAND;
1027             viff_info.map_storage_type=VFF_MAPTYP_1_BYTE;
1028             viff_info.map_rows=3;
1029             viff_info.map_columns=(unsigned int) image->colors;
1030           }
1031         else
1032           if (image->colors <= 2)
1033             {
1034               /*
1035                 Monochrome VIFF raster.
1036               */
1037               viff_info.data_storage_type=VFF_TYP_BIT;
1038               packets=((image->columns+7) >> 3)*image->rows;
1039             }
1040       }
1041     /*
1042       Write VIFF image header (pad to 1024 bytes).
1043     */
1044     buffer[0]=(unsigned char) viff_info.identifier;
1045     buffer[1]=(unsigned char) viff_info.file_type;
1046     buffer[2]=(unsigned char) viff_info.release;
1047     buffer[3]=(unsigned char) viff_info.version;
1048     buffer[4]=(unsigned char) viff_info.machine_dependency;
1049     buffer[5]=(unsigned char) viff_info.reserve[0];
1050     buffer[6]=(unsigned char) viff_info.reserve[1];
1051     buffer[7]=(unsigned char) viff_info.reserve[2];
1052     (void) WriteBlob(image,8,buffer);
1053     (void) WriteBlob(image,512,(unsigned char *) viff_info.comment);
1054     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.rows);
1055     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.columns);
1056     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.subrows);
1057     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.x_offset);
1058     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.y_offset);
1059     viff_info.x_bits_per_pixel=1U*(63 << 24) | (128 << 16);
1060     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.x_bits_per_pixel);
1061     viff_info.y_bits_per_pixel=1U*(63 << 24) | (128 << 16);
1062     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.y_bits_per_pixel);
1063     (void) WriteBlobMSBLong(image,viff_info.location_type);
1064     (void) WriteBlobMSBLong(image,viff_info.location_dimension);
1065     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.number_of_images);
1066     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.number_data_bands);
1067     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.data_storage_type);
1068     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.data_encode_scheme);
1069     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_scheme);
1070     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_storage_type);
1071     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_rows);
1072     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_columns);
1073     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_subrows);
1074     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_enable);
1075     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.maps_per_cycle);
1076     (void) WriteBlobMSBLong(image,(unsigned int) viff_info.color_space_model);
1077     for (i=0; i < 420; i++)
1078       (void) WriteBlobByte(image,'\0');
1079     /*
1080       Convert MIFF to VIFF raster pixels.
1081     */
1082     viff_pixels=(unsigned char *) AcquireQuantumMemory((size_t) packets,
1083       sizeof(*viff_pixels));
1084     if (viff_pixels == (unsigned char *) NULL)
1085       ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1086     q=viff_pixels;
1087     if (image->storage_class == DirectClass)
1088       {
1089         /*
1090           Convert DirectClass packet to VIFF RGB pixel.
1091         */
1092         number_pixels=(MagickSizeType) image->columns*image->rows;
1093         for (y=0; y < (ssize_t) image->rows; y++)
1094         {
1095           p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1096           if (p == (const Quantum *) NULL)
1097             break;
1098           for (x=0; x < (ssize_t) image->columns; x++)
1099           {
1100             *q=ScaleQuantumToChar(GetPixelRed(image,p));
1101             *(q+number_pixels)=ScaleQuantumToChar(GetPixelGreen(image,p));
1102             *(q+number_pixels*2)=ScaleQuantumToChar(GetPixelBlue(image,p));
1103             if (image->matte != MagickFalse)
1104               *(q+number_pixels*3)=ScaleQuantumToChar((Quantum)
1105                 (GetPixelAlpha(image,p)));
1106             p+=GetPixelChannels(image);
1107             q++;
1108           }
1109           if (image->previous == (Image *) NULL)
1110             {
1111               status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1112                 image->rows);
1113               if (status == MagickFalse)
1114                 break;
1115             }
1116         }
1117       }
1118     else
1119       if (IsImageGray(image,&image->exception) == MagickFalse)
1120         {
1121           unsigned char
1122             *viff_colormap;
1123
1124           /*
1125             Dump colormap to file.
1126           */
1127           viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
1128             3*sizeof(*viff_colormap));
1129           if (viff_colormap == (unsigned char *) NULL)
1130             ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1131           q=viff_colormap;
1132           for (i=0; i < (ssize_t) image->colors; i++)
1133             *q++=ScaleQuantumToChar(image->colormap[i].red);
1134           for (i=0; i < (ssize_t) image->colors; i++)
1135             *q++=ScaleQuantumToChar(image->colormap[i].green);
1136           for (i=0; i < (ssize_t) image->colors; i++)
1137             *q++=ScaleQuantumToChar(image->colormap[i].blue);
1138           (void) WriteBlob(image,3*image->colors,viff_colormap);
1139           viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap);
1140           /*
1141             Convert PseudoClass packet to VIFF colormapped pixels.
1142           */
1143           q=viff_pixels;
1144           for (y=0; y < (ssize_t) image->rows; y++)
1145           {
1146             p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1147             if (p == (const Quantum *) NULL)
1148               break;
1149             for (x=0; x < (ssize_t) image->columns; x++)
1150             {
1151               *q++=(unsigned char) GetPixelIndex(image,p);
1152               p+=GetPixelChannels(image);
1153             }
1154             if (image->previous == (Image *) NULL)
1155               {
1156                 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1157                 image->rows);
1158                 if (status == MagickFalse)
1159                   break;
1160               }
1161           }
1162         }
1163       else
1164         if (image->colors <= 2)
1165           {
1166             ssize_t
1167               x,
1168               y;
1169
1170             register unsigned char
1171               bit,
1172               byte;
1173
1174             /*
1175               Convert PseudoClass image to a VIFF monochrome image.
1176             */
1177             (void) SetImageType(image,BilevelType);
1178             for (y=0; y < (ssize_t) image->rows; y++)
1179             {
1180               p=GetVirtualPixels(image,0,y,image->columns,1,
1181                 &image->exception);
1182               if (p == (const Quantum *) NULL)
1183                 break;
1184               bit=0;
1185               byte=0;
1186               for (x=0; x < (ssize_t) image->columns; x++)
1187               {
1188                 byte>>=1;
1189                 if (GetPixelIntensity(image,p) < ((MagickRealType) QuantumRange/2.0))
1190                   byte|=0x80;
1191                 bit++;
1192                 if (bit == 8)
1193                   {
1194                     *q++=byte;
1195                     bit=0;
1196                     byte=0;
1197                   }
1198                 p+=GetPixelChannels(image);
1199               }
1200               if (bit != 0)
1201                 *q++=byte >> (8-bit);
1202               if (image->previous == (Image *) NULL)
1203                 {
1204                   status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1205                     y,image->rows);
1206                   if (status == MagickFalse)
1207                     break;
1208                 }
1209             }
1210           }
1211         else
1212           {
1213             /*
1214               Convert PseudoClass packet to VIFF grayscale pixel.
1215             */
1216             for (y=0; y < (ssize_t) image->rows; y++)
1217             {
1218               p=GetVirtualPixels(image,0,y,image->columns,1,
1219                 &image->exception);
1220               if (p == (const Quantum *) NULL)
1221                 break;
1222               for (x=0; x < (ssize_t) image->columns; x++)
1223               {
1224                 *q++=(unsigned char) GetPixelIntensity(image,p);
1225                 p+=GetPixelChannels(image);
1226               }
1227               if (image->previous == (Image *) NULL)
1228                 {
1229                   status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
1230                     y,image->rows);
1231                   if (status == MagickFalse)
1232                     break;
1233                 }
1234             }
1235           }
1236     (void) WriteBlob(image,(size_t) packets,viff_pixels);
1237     viff_pixels=(unsigned char *) RelinquishMagickMemory(viff_pixels);
1238     if (GetNextImageInList(image) == (Image *) NULL)
1239       break;
1240     image=SyncNextImageInList(image);
1241     status=SetImageProgress(image,SaveImagesTag,scene++,
1242       GetImageListLength(image));
1243     if (status == MagickFalse)
1244       break;
1245   } while (image_info->adjoin != MagickFalse);
1246   (void) CloseBlob(image);
1247   return(MagickTrue);
1248 }