]> granicus.if.org Git - imagemagick/blob - coders/dib.c
Remove --enable-zero-configuration as per https://github.com/ImageMagick/ImageMagick...
[imagemagick] / coders / dib.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                            DDDD   IIIII  BBBB                               %
7 %                            D   D    I    B   B                              %
8 %                            D   D    I    BBBB                               %
9 %                            D   D    I    B   B                              %
10 %                            DDDD   IIIII  BBBB                               %
11 %                                                                             %
12 %                                                                             %
13 %                   Read/Write Windows DIB Image Format                       %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                   Cristy                                    %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2017 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 %    https://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/colormap-private.h"
51 #include "MagickCore/colorspace.h"
52 #include "MagickCore/colorspace-private.h"
53 #include "MagickCore/draw.h"
54 #include "MagickCore/exception.h"
55 #include "MagickCore/exception-private.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/image-private.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/log.h"
61 #include "MagickCore/magick.h"
62 #include "MagickCore/memory_.h"
63 #include "MagickCore/monitor.h"
64 #include "MagickCore/monitor-private.h"
65 #include "MagickCore/pixel-accessor.h"
66 #include "MagickCore/quantum-private.h"
67 #include "MagickCore/static.h"
68 #include "MagickCore/string_.h"
69 #include "MagickCore/module.h"
70 #include "MagickCore/transform.h"
71 \f
72 /*
73   Typedef declarations.
74 */
75 typedef struct _DIBInfo
76 {
77   size_t
78     size;
79
80   ssize_t
81     width,
82     height;
83
84   unsigned short
85     planes,
86     bits_per_pixel;
87
88   size_t
89     compression,
90     image_size,
91     x_pixels,
92     y_pixels,
93     number_colors,
94     red_mask,
95     green_mask,
96     blue_mask,
97     alpha_mask,
98     colors_important;
99
100   ssize_t
101     colorspace;
102
103   PointInfo
104     red_primary,
105     green_primary,
106     blue_primary,
107     gamma_scale;
108 } DIBInfo;
109 \f
110 /*
111   Forward declarations.
112 */
113 static MagickBooleanType
114   WriteDIBImage(const ImageInfo *,Image *,ExceptionInfo *);
115 \f
116 /*
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 %                                                                             %
119 %                                                                             %
120 %                                                                             %
121 %   D e c o d e I m a g e                                                     %
122 %                                                                             %
123 %                                                                             %
124 %                                                                             %
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 %
127 %  DecodeImage unpacks the packed image pixels into runlength-encoded
128 %  pixel packets.
129 %
130 %  The format of the DecodeImage method is:
131 %
132 %      MagickBooleanType DecodeImage(Image *image,
133 %        const MagickBooleanType compression,unsigned char *pixels)
134 %
135 %  A description of each parameter follows:
136 %
137 %    o image: the address of a structure of type Image.
138 %
139 %    o compression:  A value of 1 means the compressed pixels are runlength
140 %      encoded for a 256-color bitmap.  A value of 2 means a 16-color bitmap.
141 %
142 %    o pixels:  The address of a byte (8 bits) array of pixel data created by
143 %      the decoding process.
144 %
145 */
146 static MagickBooleanType DecodeImage(Image *image,
147   const MagickBooleanType compression,unsigned char *pixels)
148 {
149 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
150 #define BI_RGB  0
151 #define BI_RLE8  1
152 #define BI_RLE4  2
153 #define BI_BITFIELDS  3
154 #undef BI_JPEG
155 #define BI_JPEG  4
156 #undef BI_PNG
157 #define BI_PNG  5
158 #endif
159
160   int
161     count;
162
163   ssize_t
164     y;
165
166   register ssize_t
167     i,
168     x;
169
170   register unsigned char
171     *p,
172     *q;
173
174   unsigned char
175     byte;
176
177   assert(image != (Image *) NULL);
178   assert(image->signature == MagickCoreSignature);
179   if (image->debug != MagickFalse)
180     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
181   assert(pixels != (unsigned char *) NULL);
182   (void) ResetMagickMemory(pixels,0,(size_t) image->columns*image->rows*
183     sizeof(*pixels));
184   byte=0;
185   x=0;
186   p=pixels;
187   q=pixels+(size_t) image->columns*image->rows;
188   for (y=0; y < (ssize_t) image->rows; )
189   {
190     if ((p < pixels) || (p >= q))
191       break;
192     count=ReadBlobByte(image);
193     if (count == EOF)
194       break;
195     if (count != 0)
196       {
197         count=(int) MagickMin((size_t) count,(size_t) (q-p));
198         /*
199           Encoded mode.
200         */
201         byte=(unsigned char) ReadBlobByte(image);
202         if (compression == BI_RLE8)
203           {
204             for (i=0; i < count; i++)
205               *p++=(unsigned char) byte;
206           }
207         else
208           {
209             for (i=0; i < count; i++)
210               *p++=(unsigned char)
211                 ((i & 0x01) != 0 ? (byte & 0x0f) : ((byte >> 4) & 0x0f));
212           }
213         x+=count;
214       }
215     else
216       {
217         /*
218           Escape mode.
219         */
220         count=ReadBlobByte(image);
221         if (count == 0x01)
222           return(MagickTrue);
223         switch (count)
224         {
225           case 0x00:
226           {
227             /*
228               End of line.
229             */
230             x=0;
231             y++;
232             p=pixels+y*image->columns;
233             break;
234           }
235           case 0x02:
236           {
237             /*
238               Delta mode.
239             */
240             x+=ReadBlobByte(image);
241             y+=ReadBlobByte(image);
242             p=pixels+y*image->columns+x;
243             break;
244           }
245           default:
246           {
247             /*
248               Absolute mode.
249             */
250             count=(int) MagickMin((size_t) count,(size_t) (q-p));
251             if (compression == BI_RLE8)
252               for (i=0; i < count; i++)
253                 *p++=(unsigned char) ReadBlobByte(image);
254             else
255               for (i=0; i < count; i++)
256               {
257                 if ((i & 0x01) == 0)
258                   byte=(unsigned char) ReadBlobByte(image);
259                 *p++=(unsigned char)
260                   ((i & 0x01) != 0 ? (byte & 0x0f) : ((byte >> 4) & 0x0f));
261               }
262             x+=count;
263             /*
264               Read pad byte.
265             */
266             if (compression == BI_RLE8)
267               {
268                 if ((count & 0x01) != 0)
269                   (void) ReadBlobByte(image);
270               }
271             else
272               if (((count & 0x03) == 1) || ((count & 0x03) == 2))
273                 (void) ReadBlobByte(image);
274             break;
275           }
276         }
277       }
278     if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
279       break;
280   }
281   (void) ReadBlobByte(image);  /* end of line */
282   (void) ReadBlobByte(image);
283   return(MagickTrue);
284 }
285 \f
286 /*
287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 %                                                                             %
289 %                                                                             %
290 %                                                                             %
291 %   E n c o d e I m a g e                                                     %
292 %                                                                             %
293 %                                                                             %
294 %                                                                             %
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 %
297 %  EncodeImage compresses pixels using a runlength encoded format.
298 %
299 %  The format of the EncodeImage method is:
300 %
301 %    static MagickBooleanType EncodeImage(Image *image,
302 %      const size_t bytes_per_line,const unsigned char *pixels,
303 %      unsigned char *compressed_pixels)
304 %
305 %  A description of each parameter follows:
306 %
307 %    o image:  The image.
308 %
309 %    o bytes_per_line: the number of bytes in a scanline of compressed pixels
310 %
311 %    o pixels:  The address of a byte (8 bits) array of pixel data created by
312 %      the compression process.
313 %
314 %    o compressed_pixels:  The address of a byte (8 bits) array of compressed
315 %      pixel data.
316 %
317 */
318 static size_t EncodeImage(Image *image,const size_t bytes_per_line,
319   const unsigned char *pixels,unsigned char *compressed_pixels)
320 {
321   ssize_t
322     y;
323
324   register const unsigned char
325     *p;
326
327   register ssize_t
328     i,
329     x;
330
331   register unsigned char
332     *q;
333
334   /*
335     Runlength encode pixels.
336   */
337   assert(image != (Image *) NULL);
338   assert(image->signature == MagickCoreSignature);
339   if (image->debug != MagickFalse)
340     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
341   assert(pixels != (const unsigned char *) NULL);
342   assert(compressed_pixels != (unsigned char *) NULL);
343   p=pixels;
344   q=compressed_pixels;
345   i=0;
346   for (y=0; y < (ssize_t) image->rows; y++)
347   {
348     for (x=0; x < (ssize_t) bytes_per_line; x+=i)
349     {
350       /*
351         Determine runlength.
352       */
353       for (i=1; ((x+i) < (ssize_t) bytes_per_line); i++)
354         if ((*(p+i) != *p) || (i == 255))
355           break;
356       *q++=(unsigned char) i;
357       *q++=(*p);
358       p+=i;
359     }
360     /*
361       End of line.
362     */
363     *q++=0x00;
364     *q++=0x00;
365     if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
366       break;
367   }
368   /*
369     End of bitmap.
370   */
371   *q++=0;
372   *q++=0x01;
373   return((size_t) (q-compressed_pixels));
374 }
375 \f
376 /*
377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378 %                                                                             %
379 %                                                                             %
380 %                                                                             %
381 %   I s D I B                                                                 %
382 %                                                                             %
383 %                                                                             %
384 %                                                                             %
385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 %
387 %  IsDIB() returns MagickTrue if the image format type, identified by the
388 %  magick string, is DIB.
389 %
390 %  The format of the IsDIB method is:
391 %
392 %      MagickBooleanType IsDIB(const unsigned char *magick,const size_t length)
393 %
394 %  A description of each parameter follows:
395 %
396 %    o magick: compare image format pattern against these bytes.
397 %
398 %    o length: Specifies the length of the magick string.
399 %
400 */
401 static MagickBooleanType IsDIB(const unsigned char *magick,const size_t length)
402 {
403   if (length < 2)
404     return(MagickFalse);
405   if (memcmp(magick,"\050\000",2) == 0)
406     return(MagickTrue);
407   return(MagickFalse);
408 }
409 \f
410 /*
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412 %                                                                             %
413 %                                                                             %
414 %                                                                             %
415 %   R e a d D I B I m a g e                                                   %
416 %                                                                             %
417 %                                                                             %
418 %                                                                             %
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 %
421 %  ReadDIBImage() reads a Microsoft Windows bitmap image file and
422 %  returns it.  It allocates the memory necessary for the new Image structure
423 %  and returns a pointer to the new image.
424 %
425 %  The format of the ReadDIBImage method is:
426 %
427 %      image=ReadDIBImage(image_info)
428 %
429 %  A description of each parameter follows:
430 %
431 %    o image_info: the image info.
432 %
433 %    o exception: return any errors or warnings in this structure.
434 %
435 */
436 static Image *ReadDIBImage(const ImageInfo *image_info,ExceptionInfo *exception)
437 {
438   DIBInfo
439     dib_info;
440
441   Image
442     *image;
443
444   MagickBooleanType
445     status;
446
447   MemoryInfo
448     *pixel_info;
449
450   Quantum
451     index;
452
453   register ssize_t
454     x;
455
456   register Quantum
457     *q;
458
459   register ssize_t
460     i;
461
462   register unsigned char
463     *p;
464
465   size_t
466     bytes_per_line,
467     length;
468
469   ssize_t
470     bit,
471     count,
472     y;
473
474
475   unsigned char
476     *pixels;
477
478   /*
479     Open image file.
480   */
481   assert(image_info != (const ImageInfo *) NULL);
482   assert(image_info->signature == MagickCoreSignature);
483   if (image_info->debug != MagickFalse)
484     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
485       image_info->filename);
486   assert(exception != (ExceptionInfo *) NULL);
487   assert(exception->signature == MagickCoreSignature);
488   image=AcquireImage(image_info,exception);
489   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
490   if (status == MagickFalse)
491     {
492       image=DestroyImageList(image);
493       return((Image *) NULL);
494     }
495   /*
496     Determine if this a DIB file.
497   */
498   (void) ResetMagickMemory(&dib_info,0,sizeof(dib_info));
499   dib_info.size=ReadBlobLSBLong(image);
500   if (dib_info.size != 40)
501     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
502   /*
503     Microsoft Windows 3.X DIB image file.
504   */
505   dib_info.width=ReadBlobLSBSignedLong(image);
506   dib_info.height=ReadBlobLSBSignedLong(image);
507   dib_info.planes=ReadBlobLSBShort(image);
508   dib_info.bits_per_pixel=ReadBlobLSBShort(image);
509   if (dib_info.bits_per_pixel > 32)
510     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
511   dib_info.compression=ReadBlobLSBLong(image);
512   dib_info.image_size=ReadBlobLSBLong(image);
513   dib_info.x_pixels=ReadBlobLSBLong(image);
514   dib_info.y_pixels=ReadBlobLSBLong(image);
515   dib_info.number_colors=ReadBlobLSBLong(image);
516   dib_info.colors_important=ReadBlobLSBLong(image);
517   if ((dib_info.bits_per_pixel != 1) && (dib_info.bits_per_pixel != 4) &&
518       (dib_info.bits_per_pixel != 8) && (dib_info.bits_per_pixel != 16) &&
519       (dib_info.bits_per_pixel != 24) && (dib_info.bits_per_pixel != 32))
520     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
521   if ((dib_info.compression == BI_BITFIELDS) &&
522       ((dib_info.bits_per_pixel == 16) || (dib_info.bits_per_pixel == 32)))
523     {
524       dib_info.red_mask=ReadBlobLSBLong(image);
525       dib_info.green_mask=ReadBlobLSBLong(image);
526       dib_info.blue_mask=ReadBlobLSBLong(image);
527     }
528   if (EOFBlob(image) != MagickFalse)
529     ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
530   if (dib_info.width <= 0)
531     ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
532   if (dib_info.height == 0)
533     ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
534   if (dib_info.planes != 1)
535     ThrowReaderException(CorruptImageError,"StaticPlanesValueNotEqualToOne");
536   if ((dib_info.bits_per_pixel != 1) && (dib_info.bits_per_pixel != 4) &&
537       (dib_info.bits_per_pixel != 8) && (dib_info.bits_per_pixel != 16) &&
538       (dib_info.bits_per_pixel != 24) && (dib_info.bits_per_pixel != 32))
539     ThrowReaderException(CorruptImageError,"UnrecognizedBitsPerPixel");
540   if (dib_info.bits_per_pixel < 16 &&
541       dib_info.number_colors > (size_t) (1UL << dib_info.bits_per_pixel))
542     ThrowReaderException(CorruptImageError,"UnrecognizedNumberOfColors");
543   if ((dib_info.compression == 1) && (dib_info.bits_per_pixel != 8))
544     ThrowReaderException(CorruptImageError,"UnrecognizedBitsPerPixel");
545   if ((dib_info.compression == 2) && (dib_info.bits_per_pixel != 4))
546     ThrowReaderException(CorruptImageError,"UnrecognizedBitsPerPixel");
547   if ((dib_info.compression == 3) && (dib_info.bits_per_pixel < 16))
548     ThrowReaderException(CorruptImageError,"UnrecognizedBitsPerPixel");
549   switch (dib_info.compression)
550   {
551     case BI_RGB:
552     case BI_RLE8:
553     case BI_RLE4:
554     case BI_BITFIELDS:
555       break;
556     case BI_JPEG:
557       ThrowReaderException(CoderError,"JPEGCompressNotSupported");
558     case BI_PNG:
559       ThrowReaderException(CoderError,"PNGCompressNotSupported");
560     default:
561       ThrowReaderException(CorruptImageError,"UnrecognizedImageCompression");
562   }
563   image->columns=(size_t) MagickAbsoluteValue(dib_info.width);
564   image->rows=(size_t) MagickAbsoluteValue(dib_info.height);
565   image->depth=8;
566   image->alpha_trait=dib_info.bits_per_pixel == 32 ? BlendPixelTrait :
567     UndefinedPixelTrait;
568   if ((dib_info.number_colors > 256) || (dib_info.colors_important > 256))
569     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
570   if ((dib_info.number_colors != 0) || (dib_info.bits_per_pixel < 16))
571     {
572       size_t
573         one;
574
575       image->storage_class=PseudoClass;
576       image->colors=dib_info.number_colors;
577       one=1;
578       if (image->colors == 0)
579         image->colors=one << dib_info.bits_per_pixel;
580     }
581   if (image_info->size)
582     {
583       RectangleInfo
584         geometry;
585
586       MagickStatusType
587         flags;
588
589       flags=ParseAbsoluteGeometry(image_info->size,&geometry);
590       if (flags & WidthValue)
591         if ((geometry.width != 0) && (geometry.width < image->columns))
592           image->columns=geometry.width;
593       if (flags & HeightValue)
594         if ((geometry.height != 0) && (geometry.height < image->rows))
595           image->rows=geometry.height;
596     }
597   status=SetImageExtent(image,image->columns,image->rows,exception);
598   if (status == MagickFalse)
599     return(DestroyImageList(image));
600   if (image->storage_class == PseudoClass)
601     {
602       size_t
603         packet_size;
604
605       unsigned char
606         *dib_colormap;
607
608       /*
609         Read DIB raster colormap.
610       */
611       if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
612         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
613       length=(size_t) image->colors;
614       dib_colormap=(unsigned char *) AcquireQuantumMemory(length,
615         4*sizeof(*dib_colormap));
616       if (dib_colormap == (unsigned char *) NULL)
617         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
618       packet_size=4;
619       count=ReadBlob(image,packet_size*image->colors,dib_colormap);
620       if (count != (ssize_t) (packet_size*image->colors))
621         {
622           dib_colormap=(unsigned char *) RelinquishMagickMemory(dib_colormap);
623           ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
624         }
625       p=dib_colormap;
626       for (i=0; i < (ssize_t) image->colors; i++)
627       {
628         image->colormap[i].blue=ScaleCharToQuantum(*p++);
629         image->colormap[i].green=ScaleCharToQuantum(*p++);
630         image->colormap[i].red=ScaleCharToQuantum(*p++);
631         if (packet_size == 4)
632           p++;
633       }
634       dib_colormap=(unsigned char *) RelinquishMagickMemory(dib_colormap);
635     }
636   /*
637     Read image data.
638   */
639   if (dib_info.compression == BI_RLE4)
640     dib_info.bits_per_pixel<<=1;
641   bytes_per_line=4*((image->columns*dib_info.bits_per_pixel+31)/32);
642   length=bytes_per_line*image->rows;
643   pixel_info=AcquireVirtualMemory((size_t) image->rows,MagickMax(
644     bytes_per_line,image->columns+256UL)*sizeof(*pixels));
645   if (pixel_info == (MemoryInfo *) NULL)
646     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
647   pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info);
648   if ((dib_info.compression == BI_RGB) ||
649       (dib_info.compression == BI_BITFIELDS))
650     {
651       count=ReadBlob(image,length,pixels);
652       if (count != (ssize_t) (length))
653         {
654           pixel_info=RelinquishVirtualMemory(pixel_info);
655           ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
656         }
657     }
658   else
659     {
660       /*
661         Convert run-length encoded raster pixels.
662       */
663       status=DecodeImage(image,dib_info.compression ? MagickTrue : MagickFalse,
664         pixels);
665       if (status == MagickFalse)
666         {
667           pixel_info=RelinquishVirtualMemory(pixel_info);
668           ThrowReaderException(CorruptImageError,
669             "UnableToRunlengthDecodeImage");
670         }
671     }
672   /*
673     Initialize image structure.
674   */
675   image->units=PixelsPerCentimeterResolution;
676   image->resolution.x=(double) dib_info.x_pixels/100.0;
677   image->resolution.y=(double) dib_info.y_pixels/100.0;
678   /*
679     Convert DIB raster image to pixel packets.
680   */
681   switch (dib_info.bits_per_pixel)
682   {
683     case 1:
684     {
685       /*
686         Convert bitmap scanline.
687       */
688       for (y=(ssize_t) image->rows-1; y >= 0; y--)
689       {
690         p=pixels+(image->rows-y-1)*bytes_per_line;
691         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
692         if (q == (Quantum *) NULL)
693           break;
694         for (x=0; x < ((ssize_t) image->columns-7); x+=8)
695         {
696           for (bit=0; bit < 8; bit++)
697           {
698             index=(Quantum) ((*p) & (0x80 >> bit) ? 0x01 : 0x00);
699             SetPixelIndex(image,index,q);
700             q+=GetPixelChannels(image);
701           }
702           p++;
703         }
704         if ((image->columns % 8) != 0)
705           {
706             for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
707             {
708               index=(Quantum) ((*p) & (0x80 >> bit) ? 0x01 : 0x00);
709               SetPixelIndex(image,index,q);
710               q+=GetPixelChannels(image);
711             }
712             p++;
713           }
714         if (SyncAuthenticPixels(image,exception) == MagickFalse)
715           break;
716         if (image->previous == (Image *) NULL)
717           {
718             status=SetImageProgress(image,LoadImageTag,image->rows-y-1,
719               image->rows);
720             if (status == MagickFalse)
721               break;
722           }
723       }
724       (void) SyncImage(image,exception);
725       break;
726     }
727     case 4:
728     {
729       /*
730         Convert PseudoColor scanline.
731       */
732       for (y=(ssize_t) image->rows-1; y >= 0; y--)
733       {
734         p=pixels+(image->rows-y-1)*bytes_per_line;
735         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
736         if (q == (Quantum *) NULL)
737           break;
738         for (x=0; x < ((ssize_t) image->columns-1); x+=2)
739         {
740           index=ConstrainColormapIndex(image,(*p >> 4) & 0xf,exception);
741           SetPixelIndex(image,index,q);
742           q+=GetPixelChannels(image);
743           index=ConstrainColormapIndex(image,*p & 0xf,exception);
744           SetPixelIndex(image,index,q);
745           p++;
746           q+=GetPixelChannels(image);
747         }
748         if ((image->columns % 2) != 0)
749           {
750             index=ConstrainColormapIndex(image,(*p >> 4) & 0xf,exception);
751             SetPixelIndex(image,index,q);
752             q+=GetPixelChannels(image);
753             p++;
754           }
755         if (SyncAuthenticPixels(image,exception) == MagickFalse)
756           break;
757         if (image->previous == (Image *) NULL)
758           {
759             status=SetImageProgress(image,LoadImageTag,image->rows-y-1,
760               image->rows);
761             if (status == MagickFalse)
762               break;
763           }
764       }
765       (void) SyncImage(image,exception);
766       break;
767     }
768     case 8:
769     {
770       /*
771         Convert PseudoColor scanline.
772       */
773       if ((dib_info.compression == BI_RLE8) ||
774           (dib_info.compression == BI_RLE4))
775         bytes_per_line=image->columns;
776       for (y=(ssize_t) image->rows-1; y >= 0; y--)
777       {
778         p=pixels+(image->rows-y-1)*bytes_per_line;
779         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
780         if (q == (Quantum *) NULL)
781           break;
782         for (x=0; x < (ssize_t) image->columns; x++)
783         {
784           index=ConstrainColormapIndex(image,*p,exception);
785           SetPixelIndex(image,index,q);
786           p++;
787           q+=GetPixelChannels(image);
788         }
789         if (SyncAuthenticPixels(image,exception) == MagickFalse)
790           break;
791         if (image->previous == (Image *) NULL)
792           {
793             status=SetImageProgress(image,LoadImageTag,image->rows-y-1,
794               image->rows);
795             if (status == MagickFalse)
796               break;
797           }
798       }
799       (void) SyncImage(image,exception);
800       break;
801     }
802     case 16:
803     {
804       unsigned short
805         word;
806
807       /*
808         Convert PseudoColor scanline.
809       */
810       image->storage_class=DirectClass;
811       if (dib_info.compression == BI_RLE8)
812         bytes_per_line=2*image->columns;
813       for (y=(ssize_t) image->rows-1; y >= 0; y--)
814       {
815         p=pixels+(image->rows-y-1)*bytes_per_line;
816         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
817         if (q == (Quantum *) NULL)
818           break;
819         for (x=0; x < (ssize_t) image->columns; x++)
820         {
821           word=(*p++);
822           word|=(*p++ << 8);
823           if (dib_info.red_mask == 0)
824             {
825               SetPixelRed(image,ScaleCharToQuantum(ScaleColor5to8(
826                 (unsigned char) ((word >> 10) & 0x1f))),q);
827               SetPixelGreen(image,ScaleCharToQuantum(ScaleColor5to8(
828                 (unsigned char) ((word >> 5) & 0x1f))),q);
829               SetPixelBlue(image,ScaleCharToQuantum(ScaleColor5to8(
830                 (unsigned char) (word & 0x1f))),q);
831             }
832           else
833             {
834               SetPixelRed(image,ScaleCharToQuantum(ScaleColor5to8(
835                 (unsigned char) ((word >> 11) & 0x1f))),q);
836               SetPixelGreen(image,ScaleCharToQuantum(ScaleColor6to8(
837                 (unsigned char) ((word >> 5) & 0x3f))),q);
838               SetPixelBlue(image,ScaleCharToQuantum(ScaleColor5to8(
839                 (unsigned char) (word & 0x1f))),q);
840             }
841           q+=GetPixelChannels(image);
842         }
843         if (SyncAuthenticPixels(image,exception) == MagickFalse)
844           break;
845         if (image->previous == (Image *) NULL)
846           {
847             status=SetImageProgress(image,LoadImageTag,image->rows-y-1,
848               image->rows);
849             if (status == MagickFalse)
850               break;
851           }
852       }
853       break;
854     }
855     case 24:
856     case 32:
857     {
858       /*
859         Convert DirectColor scanline.
860       */
861       for (y=(ssize_t) image->rows-1; y >= 0; y--)
862       {
863         p=pixels+(image->rows-y-1)*bytes_per_line;
864         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
865         if (q == (Quantum *) NULL)
866           break;
867         for (x=0; x < (ssize_t) image->columns; x++)
868         {
869           SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
870           SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
871           SetPixelRed(image,ScaleCharToQuantum(*p++),q);
872           if (image->alpha_trait != UndefinedPixelTrait)
873             SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
874           q+=GetPixelChannels(image);
875         }
876         if (SyncAuthenticPixels(image,exception) == MagickFalse)
877           break;
878         if (image->previous == (Image *) NULL)
879           {
880             status=SetImageProgress(image,LoadImageTag,image->rows-y-1,
881               image->rows);
882             if (status == MagickFalse)
883               break;
884           }
885       }
886       break;
887     }
888     default:
889       pixel_info=RelinquishVirtualMemory(pixel_info);
890       ThrowReaderException(CorruptImageError,"ImproperImageHeader");
891   }
892   pixel_info=RelinquishVirtualMemory(pixel_info);
893   if (EOFBlob(image) != MagickFalse)
894     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
895       image->filename);
896   if (dib_info.height < 0)
897     {
898       Image
899         *flipped_image;
900
901       /*
902         Correct image orientation.
903       */
904       flipped_image=FlipImage(image,exception);
905       if (flipped_image != (Image *) NULL)
906         {
907           DuplicateBlob(flipped_image,image);
908           image=DestroyImage(image);
909           image=flipped_image;
910         }
911     }
912   (void) CloseBlob(image);
913   return(GetFirstImageInList(image));
914 }
915 \f
916 /*
917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
918 %                                                                             %
919 %                                                                             %
920 %                                                                             %
921 %   R e g i s t e r D I B I m a g e                                           %
922 %                                                                             %
923 %                                                                             %
924 %                                                                             %
925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
926 %
927 %  RegisterDIBImage() adds attributes for the DIB image format to
928 %  the list of supported formats.  The attributes include the image format
929 %  tag, a method to read and/or write the format, whether the format
930 %  supports the saving of more than one frame to the same file or blob,
931 %  whether the format supports native in-memory I/O, and a brief
932 %  description of the format.
933 %
934 %  The format of the RegisterDIBImage method is:
935 %
936 %      size_t RegisterDIBImage(void)
937 %
938 */
939 ModuleExport size_t RegisterDIBImage(void)
940 {
941   MagickInfo
942     *entry;
943
944   entry=AcquireMagickInfo("DIB","DIB",
945     "Microsoft Windows 3.X Packed Device-Independent Bitmap");
946   entry->decoder=(DecodeImageHandler *) ReadDIBImage;
947   entry->encoder=(EncodeImageHandler *) WriteDIBImage;
948   entry->magick=(IsImageFormatHandler *) IsDIB;
949   entry->flags^=CoderAdjoinFlag;
950   entry->flags|=CoderStealthFlag;
951   (void) RegisterMagickInfo(entry);
952   return(MagickImageCoderSignature);
953 }
954 \f
955 /*
956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
957 %                                                                             %
958 %                                                                             %
959 %                                                                             %
960 %   U n r e g i s t e r D I B I m a g e                                       %
961 %                                                                             %
962 %                                                                             %
963 %                                                                             %
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 %
966 %  UnregisterDIBImage() removes format registrations made by the
967 %  DIB module from the list of supported formats.
968 %
969 %  The format of the UnregisterDIBImage method is:
970 %
971 %      UnregisterDIBImage(void)
972 %
973 */
974 ModuleExport void UnregisterDIBImage(void)
975 {
976   (void) UnregisterMagickInfo("DIB");
977 }
978 \f
979 /*
980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 %                                                                             %
982 %                                                                             %
983 %                                                                             %
984 %   W r i t e D I B I m a g e                                                 %
985 %                                                                             %
986 %                                                                             %
987 %                                                                             %
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 %
990 %  WriteDIBImage() writes an image in Microsoft Windows bitmap encoded
991 %  image format.
992 %
993 %  The format of the WriteDIBImage method is:
994 %
995 %      MagickBooleanType WriteDIBImage(const ImageInfo *image_info,
996 %        Image *image,ExceptionInfo *exception)
997 %
998 %  A description of each parameter follows.
999 %
1000 %    o image_info: the image info.
1001 %
1002 %    o image:  The image.
1003 %
1004 %    o exception: return any errors or warnings in this structure.
1005 %
1006 */
1007 static MagickBooleanType WriteDIBImage(const ImageInfo *image_info,Image *image,
1008   ExceptionInfo *exception)
1009 {
1010   DIBInfo
1011     dib_info;
1012
1013   MagickBooleanType
1014     status;
1015
1016   register const Quantum
1017     *p;
1018
1019   register ssize_t
1020     i,
1021     x;
1022
1023   register unsigned char
1024     *q;
1025
1026   size_t
1027     bytes_per_line;
1028
1029   ssize_t
1030     y;
1031
1032   unsigned char
1033     *dib_data,
1034     *pixels;
1035
1036   /*
1037     Open output image file.
1038   */
1039   assert(image_info != (const ImageInfo *) NULL);
1040   assert(image_info->signature == MagickCoreSignature);
1041   assert(image != (Image *) NULL);
1042   assert(image->signature == MagickCoreSignature);
1043   if (image->debug != MagickFalse)
1044     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1045   assert(exception != (ExceptionInfo *) NULL);
1046   assert(exception->signature == MagickCoreSignature);
1047   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1048   if (status == MagickFalse)
1049     return(status);
1050   /*
1051     Initialize DIB raster file header.
1052   */
1053   (void) TransformImageColorspace(image,sRGBColorspace,exception);
1054   if (image->storage_class == DirectClass)
1055     {
1056       /*
1057         Full color DIB raster.
1058       */
1059       dib_info.number_colors=0;
1060       dib_info.bits_per_pixel=(unsigned short) (image->alpha_trait ? 32 : 24);
1061     }
1062   else
1063     {
1064       /*
1065         Colormapped DIB raster.
1066       */
1067       dib_info.bits_per_pixel=8;
1068       if (image_info->depth > 8)
1069         dib_info.bits_per_pixel=16;
1070       if (SetImageMonochrome(image,exception) != MagickFalse)
1071         dib_info.bits_per_pixel=1;
1072       dib_info.number_colors=(dib_info.bits_per_pixel == 16) ? 0 :
1073         (1UL << dib_info.bits_per_pixel);
1074     }
1075   bytes_per_line=4*((image->columns*dib_info.bits_per_pixel+31)/32);
1076   dib_info.size=40;
1077   dib_info.width=(ssize_t) image->columns;
1078   dib_info.height=(ssize_t) image->rows;
1079   dib_info.planes=1;
1080   dib_info.compression=(size_t) (dib_info.bits_per_pixel == 16 ?
1081     BI_BITFIELDS : BI_RGB);
1082   dib_info.image_size=bytes_per_line*image->rows;
1083   dib_info.x_pixels=75*39;
1084   dib_info.y_pixels=75*39;
1085   switch (image->units)
1086   {
1087     case UndefinedResolution:
1088     case PixelsPerInchResolution:
1089     {
1090       dib_info.x_pixels=(size_t) (100.0*image->resolution.x/2.54);
1091       dib_info.y_pixels=(size_t) (100.0*image->resolution.y/2.54);
1092       break;
1093     }
1094     case PixelsPerCentimeterResolution:
1095     {
1096       dib_info.x_pixels=(size_t) (100.0*image->resolution.x);
1097       dib_info.y_pixels=(size_t) (100.0*image->resolution.y);
1098       break;
1099     }
1100   }
1101   dib_info.colors_important=dib_info.number_colors;
1102   /*
1103     Convert MIFF to DIB raster pixels.
1104   */
1105   pixels=(unsigned char *) AcquireQuantumMemory(dib_info.image_size,
1106     sizeof(*pixels));
1107   if (pixels == (unsigned char *) NULL)
1108     ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1109   (void) ResetMagickMemory(pixels,0,dib_info.image_size);
1110   switch (dib_info.bits_per_pixel)
1111   {
1112     case 1:
1113     {
1114       register unsigned char
1115         bit,
1116         byte;
1117
1118       /*
1119         Convert PseudoClass image to a DIB monochrome image.
1120       */
1121       for (y=0; y < (ssize_t) image->rows; y++)
1122       {
1123         p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1124         if (p == (const Quantum *) NULL)
1125           break;
1126         q=pixels+(image->rows-y-1)*bytes_per_line;
1127         bit=0;
1128         byte=0;
1129         for (x=0; x < (ssize_t) image->columns; x++)
1130         {
1131           byte<<=1;
1132           byte|=GetPixelIndex(image,p) != 0 ? 0x01 : 0x00;
1133           bit++;
1134           if (bit == 8)
1135             {
1136               *q++=byte;
1137               bit=0;
1138               byte=0;
1139             }
1140            p+=GetPixelChannels(image);
1141          }
1142          if (bit != 0)
1143            {
1144              *q++=(unsigned char) (byte << (8-bit));
1145              x++;
1146            }
1147         for (x=(ssize_t) (image->columns+7)/8; x < (ssize_t) bytes_per_line; x++)
1148           *q++=0x00;
1149         status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1150           image->rows);
1151         if (status == MagickFalse)
1152           break;
1153       }
1154       break;
1155     }
1156     case 8:
1157     {
1158       /*
1159         Convert PseudoClass packet to DIB pixel.
1160       */
1161       for (y=0; y < (ssize_t) image->rows; y++)
1162       {
1163         p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1164         if (p == (const Quantum *) NULL)
1165           break;
1166         q=pixels+(image->rows-y-1)*bytes_per_line;
1167         for (x=0; x < (ssize_t) image->columns; x++)
1168         {
1169           *q++=(unsigned char) GetPixelIndex(image,p);
1170           p+=GetPixelChannels(image);
1171         }
1172         for ( ; x < (ssize_t) bytes_per_line; x++)
1173           *q++=0x00;
1174         status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1175           image->rows);
1176         if (status == MagickFalse)
1177           break;
1178       }
1179       break;
1180     }
1181     case 16:
1182     {
1183       unsigned short
1184         word;
1185       /*
1186         Convert PseudoClass packet to DIB pixel.
1187       */
1188       for (y=0; y < (ssize_t) image->rows; y++)
1189       {
1190         p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1191         if (p == (const Quantum *) NULL)
1192           break;
1193         q=pixels+(image->rows-y-1)*bytes_per_line;
1194         for (x=0; x < (ssize_t) image->columns; x++)
1195         {
1196           word=(unsigned short) ((ScaleColor8to5((unsigned char)
1197             ScaleQuantumToChar(GetPixelRed(image,p))) << 11) | (ScaleColor8to6(
1198             (unsigned char) ScaleQuantumToChar(GetPixelGreen(image,p))) << 5) |
1199             (ScaleColor8to5((unsigned char) ScaleQuantumToChar((unsigned char)
1200             GetPixelBlue(image,p)) << 0)));
1201           *q++=(unsigned char)(word & 0xff);
1202           *q++=(unsigned char)(word >> 8);
1203           p+=GetPixelChannels(image);
1204         }
1205         for (x=(ssize_t) (2*image->columns); x < (ssize_t) bytes_per_line; x++)
1206           *q++=0x00;
1207         status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1208           image->rows);
1209         if (status == MagickFalse)
1210           break;
1211       }
1212       break;
1213     }
1214     case 24:
1215     case 32:
1216     {
1217       /*
1218         Convert DirectClass packet to DIB RGB pixel.
1219       */
1220       for (y=0; y < (ssize_t) image->rows; y++)
1221       {
1222         p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1223         if (p == (const Quantum *) NULL)
1224           break;
1225         q=pixels+(image->rows-y-1)*bytes_per_line;
1226         for (x=0; x < (ssize_t) image->columns; x++)
1227         {
1228           *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1229           *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1230           *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1231           if (image->alpha_trait != UndefinedPixelTrait)
1232             *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1233           p+=GetPixelChannels(image);
1234         }
1235         if (dib_info.bits_per_pixel == 24)
1236           for (x=(ssize_t) (3*image->columns); x < (ssize_t) bytes_per_line; x++)
1237             *q++=0x00;
1238         status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1239           image->rows);
1240         if (status == MagickFalse)
1241           break;
1242       }
1243       break;
1244     }
1245   }
1246   if (dib_info.bits_per_pixel == 8)
1247     if (image_info->compression != NoCompression)
1248       {
1249         size_t
1250           length;
1251
1252         /*
1253           Convert run-length encoded raster pixels.
1254         */
1255         length=2UL*(bytes_per_line+2UL)+2UL;
1256         dib_data=(unsigned char *) AcquireQuantumMemory(length,
1257           (image->rows+2UL)*sizeof(*dib_data));
1258         if (dib_data == (unsigned char *) NULL)
1259           {
1260             pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1261             ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1262           }
1263         dib_info.image_size=(size_t) EncodeImage(image,bytes_per_line,
1264           pixels,dib_data);
1265         pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1266         pixels=dib_data;
1267         dib_info.compression = BI_RLE8;
1268       }
1269   /*
1270     Write DIB header.
1271   */
1272   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.size);
1273   (void) WriteBlobLSBLong(image,dib_info.width);
1274   (void) WriteBlobLSBLong(image,(unsigned short) dib_info.height);
1275   (void) WriteBlobLSBShort(image,(unsigned short) dib_info.planes);
1276   (void) WriteBlobLSBShort(image,dib_info.bits_per_pixel);
1277   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.compression);
1278   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.image_size);
1279   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.x_pixels);
1280   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.y_pixels);
1281   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.number_colors);
1282   (void) WriteBlobLSBLong(image,(unsigned int) dib_info.colors_important);
1283   if (image->storage_class == PseudoClass)
1284     {
1285       if (dib_info.bits_per_pixel <= 8)
1286         {
1287           unsigned char
1288             *dib_colormap;
1289
1290           /*
1291             Dump colormap to file.
1292           */
1293           dib_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
1294             (1UL << dib_info.bits_per_pixel),4*sizeof(*dib_colormap));
1295           if (dib_colormap == (unsigned char *) NULL)
1296             ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1297           q=dib_colormap;
1298           for (i=0; i < (ssize_t) MagickMin(image->colors,dib_info.number_colors); i++)
1299           {
1300             *q++=ScaleQuantumToChar(image->colormap[i].blue);
1301             *q++=ScaleQuantumToChar(image->colormap[i].green);
1302             *q++=ScaleQuantumToChar(image->colormap[i].red);
1303             *q++=(Quantum) 0x0;
1304           }
1305           for ( ; i < (ssize_t) (1L << dib_info.bits_per_pixel); i++)
1306           {
1307             *q++=(Quantum) 0x0;
1308             *q++=(Quantum) 0x0;
1309             *q++=(Quantum) 0x0;
1310             *q++=(Quantum) 0x0;
1311           }
1312           (void) WriteBlob(image,(size_t) (4*(1 << dib_info.bits_per_pixel)),
1313             dib_colormap);
1314           dib_colormap=(unsigned char *) RelinquishMagickMemory(dib_colormap);
1315         }
1316       else
1317         if ((dib_info.bits_per_pixel == 16) &&
1318             (dib_info.compression == BI_BITFIELDS))
1319           {
1320             (void) WriteBlobLSBLong(image,0xf800);
1321             (void) WriteBlobLSBLong(image,0x07e0);
1322             (void) WriteBlobLSBLong(image,0x001f);
1323           }
1324     }
1325   (void) WriteBlob(image,dib_info.image_size,pixels);
1326   pixels=(unsigned char *) RelinquishMagickMemory(pixels);
1327   (void) CloseBlob(image);
1328   return(MagickTrue);
1329 }