2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write X Windows System Window Dump Format %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/color-private.h"
47 #include "MagickCore/colormap.h"
48 #include "MagickCore/colormap-private.h"
49 #include "MagickCore/colorspace.h"
50 #include "MagickCore/colorspace-private.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 #if defined(MAGICKCORE_X11_DELEGATE)
67 #include "MagickCore/xwindow-private.h"
69 #include <X11/XWDFile.h>
78 #if defined(MAGICKCORE_X11_DELEGATE)
79 static MagickBooleanType
80 WriteXWDImage(const ImageInfo *,Image *,ExceptionInfo *);
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 % IsXWD() returns MagickTrue if the image format type, identified by the
95 % magick string, is XWD.
97 % The format of the IsXWD method is:
99 % MagickBooleanType IsXWD(const unsigned char *magick,const size_t length)
101 % A description of each parameter follows:
103 % o magick: compare image format pattern against these bytes.
105 % o length: Specifies the length of the magick string.
108 static MagickBooleanType IsXWD(const unsigned char *magick,const size_t length)
112 if (memcmp(magick+1,"\000\000",2) == 0)
114 if (memcmp(magick+4,"\007\000\000",3) == 0)
116 if (memcmp(magick+5,"\000\000\007",3) == 0)
122 #if defined(MAGICKCORE_X11_DELEGATE)
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 % R e a d X W D I m a g e %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 % ReadXWDImage() reads an X Window System window dump image file and
135 % returns it. It allocates the memory necessary for the new Image structure
136 % and returns a pointer to the new image.
138 % The format of the ReadXWDImage method is:
140 % Image *ReadXWDImage(const ImageInfo *image_info,ExceptionInfo *exception)
142 % A description of each parameter follows:
144 % o image_info: the image info.
146 % o exception: return any errors or warnings in this structure.
150 static Image *ReadXWDImage(const ImageInfo *image_info,ExceptionInfo *exception)
152 #define CheckOverflowException(length,width,height) \
153 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
205 assert(image_info != (const ImageInfo *) NULL);
206 assert(image_info->signature == MagickSignature);
207 if (image_info->debug != MagickFalse)
208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
209 image_info->filename);
210 assert(exception != (ExceptionInfo *) NULL);
211 assert(exception->signature == MagickSignature);
212 image=AcquireImage(image_info,exception);
213 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
214 if (status == MagickFalse)
216 image=DestroyImageList(image);
217 return((Image *) NULL);
220 Read in header information.
222 count=ReadBlob(image,sz_XWDheader,(unsigned char *) &header);
224 ThrowReaderException(CorruptImageError,"UnableToReadImageHeader");
225 image->columns=header.pixmap_width;
226 image->rows=header.pixmap_height;
229 Ensure the header byte-order is most-significant byte first.
232 if ((int) (*(char *) &lsb_first) != 0)
233 MSBOrderLong((unsigned char *) &header,sz_XWDheader);
235 Check to see if the dump file is in the proper format.
237 if (header.file_version != XWD_FILE_VERSION)
238 ThrowReaderException(CorruptImageError,"FileFormatVersionMismatch");
239 if (header.header_size < sz_XWDheader)
240 ThrowReaderException(CorruptImageError,"CorruptImage");
241 length=(size_t) header.header_size-sz_XWDheader;
242 comment=(char *) AcquireQuantumMemory(length+1,sizeof(*comment));
243 if (comment == (char *) NULL)
244 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
245 count=ReadBlob(image,length,(unsigned char *) comment);
246 comment[length]='\0';
247 (void) SetImageProperty(image,"comment",comment,exception);
248 comment=DestroyString(comment);
249 if (count != (ssize_t) length)
250 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
252 Initialize the X image.
254 ximage=(XImage *) AcquireMagickMemory(sizeof(*ximage));
255 if (ximage == (XImage *) NULL)
256 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
257 ximage->depth=(int) header.pixmap_depth;
258 ximage->format=(int) header.pixmap_format;
259 ximage->xoffset=(int) header.xoffset;
260 ximage->data=(char *) NULL;
261 ximage->width=(int) header.pixmap_width;
262 ximage->height=(int) header.pixmap_height;
263 ximage->bitmap_pad=(int) header.bitmap_pad;
264 ximage->bytes_per_line=(int) header.bytes_per_line;
265 ximage->byte_order=(int) header.byte_order;
266 ximage->bitmap_unit=(int) header.bitmap_unit;
267 ximage->bitmap_bit_order=(int) header.bitmap_bit_order;
268 ximage->bits_per_pixel=(int) header.bits_per_pixel;
269 ximage->red_mask=header.red_mask;
270 ximage->green_mask=header.green_mask;
271 ximage->blue_mask=header.blue_mask;
272 if ((ximage->depth < 0) || (ximage->width < 0) || (ximage->height < 0) ||
273 (ximage->bitmap_pad < 0) || (ximage->bytes_per_line < 0))
274 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
275 if ((ximage->bits_per_pixel > 32) || (ximage->bitmap_unit > 32))
276 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
277 x_status=XInitImage(ximage);
279 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
283 authentic_colormap=MagickFalse;
284 colors=(XColor *) NULL;
285 if (header.ncolors != 0)
290 length=(size_t) header.ncolors;
291 colors=(XColor *) AcquireQuantumMemory(length,sizeof(*colors));
292 if (colors == (XColor *) NULL)
293 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
294 for (i=0; i < (ssize_t) header.ncolors; i++)
296 count=ReadBlob(image,sz_XWDColor,(unsigned char *) &color);
298 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
299 colors[i].pixel=color.pixel;
300 colors[i].red=color.red;
301 colors[i].green=color.green;
302 colors[i].blue=color.blue;
303 colors[i].flags=(char) color.flags;
304 if (color.flags != 0)
305 authentic_colormap=MagickTrue;
308 Ensure the header byte-order is most-significant byte first.
311 if ((int) (*(char *) &lsb_first) != 0)
312 for (i=0; i < (ssize_t) header.ncolors; i++)
314 MSBOrderLong((unsigned char *) &colors[i].pixel,
315 sizeof(colors[i].pixel));
316 MSBOrderShort((unsigned char *) &colors[i].red,3*
317 sizeof(colors[i].red));
321 Allocate the pixel buffer.
323 length=(size_t) ximage->bytes_per_line*ximage->height;
324 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
325 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
326 if (ximage->format != ZPixmap)
332 length*=ximage->depth;
333 if (CheckOverflowException(length,extent,ximage->depth))
334 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
336 ximage->data=(char *) AcquireQuantumMemory(length,sizeof(*ximage->data));
337 if (ximage->data == (char *) NULL)
338 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
339 count=ReadBlob(image,length,(unsigned char *) ximage->data);
341 ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
343 Convert image to MIFF format.
345 image->columns=(size_t) ximage->width;
346 image->rows=(size_t) ximage->height;
347 if ((colors == (XColor *) NULL) || (ximage->red_mask != 0) ||
348 (ximage->green_mask != 0) || (ximage->blue_mask != 0))
349 image->storage_class=DirectClass;
351 image->storage_class=PseudoClass;
352 image->colors=header.ncolors;
353 if (image_info->ping == MagickFalse)
354 switch (image->storage_class)
371 Determine shift and mask for red, green, and blue.
373 red_mask=ximage->red_mask;
375 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
380 green_mask=ximage->green_mask;
382 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
387 blue_mask=ximage->blue_mask;
389 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
395 Convert X image to DirectClass packets.
397 if ((image->colors != 0) && (authentic_colormap != MagickFalse))
398 for (y=0; y < (ssize_t) image->rows; y++)
400 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
401 if (q == (Quantum *) NULL)
403 for (x=0; x < (ssize_t) image->columns; x++)
405 pixel=XGetPixel(ximage,(int) x,(int) y);
406 index=(Quantum) ((pixel >> red_shift) & red_mask);
407 SetPixelRed(image,ScaleShortToQuantum(
408 colors[(ssize_t) index].red),q);
409 index=(Quantum) ((pixel >> green_shift) & green_mask);
410 SetPixelGreen(image,ScaleShortToQuantum(
411 colors[(ssize_t) index].green),q);
412 index=(Quantum) ((pixel >> blue_shift) & blue_mask);
413 SetPixelBlue(image,ScaleShortToQuantum(
414 colors[(ssize_t) index].blue),q);
415 q+=GetPixelChannels(image);
417 if (SyncAuthenticPixels(image,exception) == MagickFalse)
419 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
421 if (status == MagickFalse)
425 for (y=0; y < (ssize_t) image->rows; y++)
427 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
428 if (q == (Quantum *) NULL)
430 for (x=0; x < (ssize_t) image->columns; x++)
432 pixel=XGetPixel(ximage,(int) x,(int) y);
433 color=(pixel >> red_shift) & red_mask;
434 color=(color*65535UL)/red_mask;
435 SetPixelRed(image,ScaleShortToQuantum((unsigned short)
437 color=(pixel >> green_shift) & green_mask;
438 color=(color*65535UL)/green_mask;
439 SetPixelGreen(image,ScaleShortToQuantum((unsigned short)
441 color=(pixel >> blue_shift) & blue_mask;
442 color=(color*65535UL)/blue_mask;
443 SetPixelBlue(image,ScaleShortToQuantum((unsigned short)
445 q+=GetPixelChannels(image);
447 if (SyncAuthenticPixels(image,exception) == MagickFalse)
449 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
451 if (status == MagickFalse)
459 Convert X image to PseudoClass packets.
461 if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
462 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
463 for (i=0; i < (ssize_t) image->colors; i++)
465 image->colormap[i].red=ScaleShortToQuantum(colors[i].red);
466 image->colormap[i].green=ScaleShortToQuantum(colors[i].green);
467 image->colormap[i].blue=ScaleShortToQuantum(colors[i].blue);
469 for (y=0; y < (ssize_t) image->rows; y++)
471 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
472 if (q == (Quantum *) NULL)
474 for (x=0; x < (ssize_t) image->columns; x++)
476 index=ConstrainColormapIndex(image,XGetPixel(ximage,(int) x,
478 SetPixelIndex(image,index,q);
479 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
480 q+=GetPixelChannels(image);
482 if (SyncAuthenticPixels(image,exception) == MagickFalse)
484 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
486 if (status == MagickFalse)
493 Free image and colormap.
495 if (header.ncolors != 0)
496 colors=(XColor *) RelinquishMagickMemory(colors);
497 ximage->data=DestroyString(ximage->data);
498 ximage=(XImage *) RelinquishMagickMemory(ximage);
499 if (EOFBlob(image) != MagickFalse)
500 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
502 (void) CloseBlob(image);
503 return(GetFirstImageInList(image));
508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512 % R e g i s t e r X W D I m a g e %
516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518 % RegisterXWDImage() adds properties for the XWD image format to
519 % the list of supported formats. The properties include the image format
520 % tag, a method to read and/or write the format, whether the format
521 % supports the saving of more than one frame to the same file or blob,
522 % whether the format supports native in-memory I/O, and a brief
523 % description of the format.
525 % The format of the RegisterXWDImage method is:
527 % size_t RegisterXWDImage(void)
530 ModuleExport size_t RegisterXWDImage(void)
535 entry=SetMagickInfo("XWD");
536 #if defined(MAGICKCORE_X11_DELEGATE)
537 entry->decoder=(DecodeImageHandler *) ReadXWDImage;
538 entry->encoder=(EncodeImageHandler *) WriteXWDImage;
540 entry->magick=(IsImageFormatHandler *) IsXWD;
541 entry->adjoin=MagickFalse;
542 entry->description=ConstantString("X Windows system window dump (color)");
543 entry->module=ConstantString("XWD");
544 (void) RegisterMagickInfo(entry);
545 return(MagickImageCoderSignature);
549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 % U n r e g i s t e r X W D I m a g e %
557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
559 % UnregisterXWDImage() removes format registrations made by the
560 % XWD module from the list of supported formats.
562 % The format of the UnregisterXWDImage method is:
564 % UnregisterXWDImage(void)
567 ModuleExport void UnregisterXWDImage(void)
569 (void) UnregisterMagickInfo("XWD");
572 #if defined(MAGICKCORE_X11_DELEGATE)
574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
578 % W r i t e X W D I m a g e %
582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584 % WriteXWDImage() writes an image to a file in X window dump
587 % The format of the WriteXWDImage method is:
589 % MagickBooleanType WriteXWDImage(const ImageInfo *image_info,
590 % Image *image,ExceptionInfo *exception)
592 % A description of each parameter follows.
594 % o image_info: the image info.
596 % o image: The image.
598 % o exception: return any errors or warnings in this structure.
601 static MagickBooleanType WriteXWDImage(const ImageInfo *image_info,Image *image,
602 ExceptionInfo *exception)
610 register const Quantum
619 register unsigned char
639 Open output image file.
641 assert(image_info != (const ImageInfo *) NULL);
642 assert(image_info->signature == MagickSignature);
643 assert(image != (Image *) NULL);
644 assert(image->signature == MagickSignature);
645 if (image->debug != MagickFalse)
646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
647 assert(exception != (ExceptionInfo *) NULL);
648 assert(exception->signature == MagickSignature);
649 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
650 if (status == MagickFalse)
652 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
653 (void) TransformImageColorspace(image,sRGBColorspace,exception);
655 Initialize XWD file header.
657 (void) ResetMagickMemory(&xwd_info,0,sizeof(xwd_info));
658 xwd_info.header_size=(CARD32) sz_XWDheader;
659 value=GetImageProperty(image,"comment",exception);
660 if (value != (const char *) NULL)
661 xwd_info.header_size+=(CARD32) strlen(value);
662 xwd_info.header_size++;
663 xwd_info.file_version=(CARD32) XWD_FILE_VERSION;
664 xwd_info.pixmap_format=(CARD32) ZPixmap;
665 xwd_info.pixmap_depth=(CARD32) (image->storage_class == DirectClass ? 24 : 8);
666 xwd_info.pixmap_width=(CARD32) image->columns;
667 xwd_info.pixmap_height=(CARD32) image->rows;
668 xwd_info.xoffset=(CARD32) 0;
669 xwd_info.byte_order=(CARD32) MSBFirst;
670 xwd_info.bitmap_unit=(CARD32) (image->storage_class == DirectClass ? 32 : 8);
671 xwd_info.bitmap_bit_order=(CARD32) MSBFirst;
672 xwd_info.bitmap_pad=(CARD32) (image->storage_class == DirectClass ? 32 : 8);
673 bits_per_pixel=(size_t) (image->storage_class == DirectClass ? 24 : 8);
674 xwd_info.bits_per_pixel=(CARD32) bits_per_pixel;
675 bytes_per_line=(CARD32) ((((xwd_info.bits_per_pixel*
676 xwd_info.pixmap_width)+((xwd_info.bitmap_pad)-1))/
677 (xwd_info.bitmap_pad))*((xwd_info.bitmap_pad) >> 3));
678 xwd_info.bytes_per_line=(CARD32) bytes_per_line;
679 xwd_info.visual_class=(CARD32)
680 (image->storage_class == DirectClass ? DirectColor : PseudoColor);
681 xwd_info.red_mask=(CARD32)
682 (image->storage_class == DirectClass ? 0xff0000 : 0);
683 xwd_info.green_mask=(CARD32)
684 (image->storage_class == DirectClass ? 0xff00 : 0);
685 xwd_info.blue_mask=(CARD32) (image->storage_class == DirectClass ? 0xff : 0);
686 xwd_info.bits_per_rgb=(CARD32) (image->storage_class == DirectClass ? 24 : 8);
687 xwd_info.colormap_entries=(CARD32)
688 (image->storage_class == DirectClass ? 256 : image->colors);
689 xwd_info.ncolors=(unsigned int)
690 (image->storage_class == DirectClass ? 0 : image->colors);
691 xwd_info.window_width=(CARD32) image->columns;
692 xwd_info.window_height=(CARD32) image->rows;
695 xwd_info.window_bdrwidth=(CARD32) 0;
700 if ((int) (*(char *) &lsb_first) != 0)
701 MSBOrderLong((unsigned char *) &xwd_info,sizeof(xwd_info));
702 (void) WriteBlob(image,sz_XWDheader,(unsigned char *) &xwd_info);
703 if (value != (const char *) NULL)
704 (void) WriteBlob(image,strlen(value),(unsigned char *) value);
705 (void) WriteBlob(image,1,(const unsigned char *) "\0");
706 if (image->storage_class == PseudoClass)
715 Dump colormap to file.
717 (void) ResetMagickMemory(&color,0,sizeof(color));
718 colors=(XColor *) AcquireQuantumMemory((size_t) image->colors,
720 if (colors == (XColor *) NULL)
721 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
722 for (i=0; i < (ssize_t) image->colors; i++)
724 colors[i].pixel=(size_t) i;
725 colors[i].red=ScaleQuantumToShort(image->colormap[i].red);
726 colors[i].green=ScaleQuantumToShort(image->colormap[i].green);
727 colors[i].blue=ScaleQuantumToShort(image->colormap[i].blue);
728 colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
730 if ((int) (*(char *) &lsb_first) != 0)
732 MSBOrderLong((unsigned char *) &colors[i].pixel,
733 sizeof(colors[i].pixel));
734 MSBOrderShort((unsigned char *) &colors[i].red,
735 3*sizeof(colors[i].red));
738 for (i=0; i < (ssize_t) image->colors; i++)
740 color.pixel=(CARD32) colors[i].pixel;
741 color.red=colors[i].red;
742 color.green=colors[i].green;
743 color.blue=colors[i].blue;
744 color.flags=(CARD8) colors[i].flags;
745 (void) WriteBlob(image,sz_XWDColor,(unsigned char *) &color);
747 colors=(XColor *) RelinquishMagickMemory(colors);
750 Allocate memory for pixels.
752 length=3*bytes_per_line;
753 if (image->storage_class == PseudoClass)
754 length=bytes_per_line;
755 pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
756 if (pixels == (unsigned char *) NULL)
757 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
758 (void) ResetMagickMemory(pixels,0,length);
760 Convert MIFF to XWD raster pixels.
762 scanline_pad=(bytes_per_line-((image->columns*bits_per_pixel) >> 3));
763 for (y=0; y < (ssize_t) image->rows; y++)
765 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
766 if (p == (const Quantum *) NULL)
769 if (image->storage_class == PseudoClass)
771 for (x=0; x < (ssize_t) image->columns; x++)
773 *q++=(unsigned char) GetPixelIndex(image,p);
774 p+=GetPixelChannels(image);
778 for (x=0; x < (ssize_t) image->columns; x++)
780 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
781 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
782 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
783 p+=GetPixelChannels(image);
785 for (x=0; x < (ssize_t) scanline_pad; x++)
787 (void) WriteBlob(image,(size_t) (q-pixels),pixels);
788 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
790 if (status == MagickFalse)
793 pixels=(unsigned char *) RelinquishMagickMemory(pixels);
794 (void) CloseBlob(image);