2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % SSSSS TTTTT RRRR EEEEE AAA M M %
7 % SS T R R E A A MM MM %
8 % SSS T RRRR EEE AAAAA M M M %
10 % SSSSS T R R EEEEE A A M M %
13 % MagickCore Pixel Stream Methods %
20 % Copyright 1999-2011 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/cache-private.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/composite-private.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/geometry.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/pixel.h"
56 #include "MagickCore/pixel-accessor.h"
57 #include "MagickCore/quantum.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/semaphore.h"
60 #include "MagickCore/stream.h"
61 #include "MagickCore/stream-private.h"
62 #include "MagickCore/string_.h"
65 Typedef declaractions.
107 Declare pixel cache interfaces.
109 #if defined(__cplusplus) || defined(c_plusplus)
114 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
115 const ssize_t,const size_t,const size_t,ExceptionInfo *);
117 static MagickBooleanType
118 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
119 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
122 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
123 const size_t,ExceptionInfo *);
125 #if defined(__cplusplus) || defined(c_plusplus)
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 + A c q u i r e S t r e a m I n f o %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % AcquireStreamInfo() allocates the StreamInfo structure.
142 % The format of the AcquireStreamInfo method is:
144 % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
146 % A description of each parameter follows:
148 % o image_info: the image info.
151 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
156 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
157 if (stream_info == (StreamInfo *) NULL)
158 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
159 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
160 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
161 sizeof(*stream_info->pixels));
162 if (stream_info->pixels == (unsigned char *) NULL)
163 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164 stream_info->map=ConstantString("RGB");
165 stream_info->storage_type=CharPixel;
166 stream_info->stream=AcquireImage(image_info);
167 stream_info->signature=MagickSignature;
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 + D e s t r o y P i x e l S t r e a m %
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % DestroyPixelStream() deallocates memory associated with the pixel stream.
184 % The format of the DestroyPixelStream() method is:
186 % void DestroyPixelStream(Image *image)
188 % A description of each parameter follows:
190 % o image: the image.
194 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
196 assert(cache_info != (CacheInfo *) NULL);
197 if (cache_info->mapped == MagickFalse)
198 (void) RelinquishMagickMemory(cache_info->pixels);
200 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
201 cache_info->pixels=(Quantum *) NULL;
202 cache_info->metacontent=(void *) NULL;
203 cache_info->length=0;
204 cache_info->mapped=MagickFalse;
207 static void DestroyPixelStream(Image *image)
215 assert(image != (Image *) NULL);
216 assert(image->signature == MagickSignature);
217 if (image->debug != MagickFalse)
218 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
219 cache_info=(CacheInfo *) image->cache;
220 assert(cache_info->signature == MagickSignature);
222 LockSemaphoreInfo(cache_info->semaphore);
223 cache_info->reference_count--;
224 if (cache_info->reference_count == 0)
226 UnlockSemaphoreInfo(cache_info->semaphore);
227 if (destroy == MagickFalse)
229 RelinquishStreamPixels(cache_info);
230 if (cache_info->nexus_info != (NexusInfo **) NULL)
231 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
232 cache_info->number_threads);
233 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
234 DestroySemaphoreInfo(&cache_info->disk_semaphore);
235 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
236 DestroySemaphoreInfo(&cache_info->semaphore);
237 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 + D e s t r o y S t r e a m I n f o %
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 % DestroyStreamInfo() destroys memory associated with the StreamInfo
254 % The format of the DestroyStreamInfo method is:
256 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
258 % A description of each parameter follows:
260 % o stream_info: the stream info.
263 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
265 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
266 assert(stream_info != (StreamInfo *) NULL);
267 assert(stream_info->signature == MagickSignature);
268 if (stream_info->map != (char *) NULL)
269 stream_info->map=DestroyString(stream_info->map);
270 if (stream_info->pixels != (unsigned char *) NULL)
271 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
272 stream_info->pixels);
273 if (stream_info->stream != (Image *) NULL)
275 (void) CloseBlob(stream_info->stream);
276 stream_info->stream=DestroyImage(stream_info->stream);
278 if (stream_info->quantum_info != (QuantumInfo *) NULL)
279 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
280 stream_info->signature=(~MagickSignature);
281 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 + G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m %
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 % GetAuthenticMetacontentFromStream() returns the metacontent corresponding
297 % with the last call to QueueAuthenticPixelsStream() or
298 % GetAuthenticPixelsStream().
300 % The format of the GetAuthenticMetacontentFromStream() method is:
302 % void *GetAuthenticMetacontentFromStream(const Image *image)
304 % A description of each parameter follows:
306 % o image: the image.
309 static void *GetAuthenticMetacontentFromStream(const Image *image)
314 assert(image != (Image *) NULL);
315 assert(image->signature == MagickSignature);
316 if (image->debug != MagickFalse)
317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
318 cache_info=(CacheInfo *) image->cache;
319 assert(cache_info->signature == MagickSignature);
320 return(cache_info->metacontent);
324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 + G e t A u t h e n t i c P i x e l S t r e a m %
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
335 % cache as defined by the geometry parameters. A pointer to the pixels is
336 % returned if the pixels are transferred, otherwise a NULL is returned. For
337 % streams this method is a no-op.
339 % The format of the GetAuthenticPixelsStream() method is:
341 % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
342 % const ssize_t y,const size_t columns,const size_t rows,
343 % ExceptionInfo *exception)
345 % A description of each parameter follows:
347 % o image: the image.
349 % o x,y,columns,rows: These values define the perimeter of a region of
352 % o exception: return any errors or warnings in this structure.
355 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
356 const ssize_t y,const size_t columns,const size_t rows,
357 ExceptionInfo *exception)
362 assert(image != (Image *) NULL);
363 assert(image->signature == MagickSignature);
364 if (image->debug != MagickFalse)
365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
366 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 + G e t A u t h e n t i c P i x e l F r o m S t e a m %
379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
382 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
384 % The format of the GetAuthenticPixelsFromStream() method is:
386 % Quantum *GetAuthenticPixelsFromStream(const Image image)
388 % A description of each parameter follows:
390 % o image: the image.
393 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
398 assert(image != (Image *) NULL);
399 assert(image->signature == MagickSignature);
400 if (image->debug != MagickFalse)
401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
402 cache_info=(CacheInfo *) image->cache;
403 assert(cache_info->signature == MagickSignature);
404 return(cache_info->pixels);
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412 + G e t O n e A u t h e n t i c P i x e l F r o m S t r e a m %
416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
419 % (x,y) location. The image background color is returned if an error occurs.
421 % The format of the GetOneAuthenticPixelFromStream() method is:
423 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
424 % const ssize_t x,const ssize_t y,PixelPacket *pixel,
425 % ExceptionInfo *exception)
427 % A description of each parameter follows:
429 % o image: the image.
431 % o pixel: return a pixel at the specified (x,y) location.
433 % o x,y: These values define the location of the pixel to return.
435 % o exception: return any errors or warnings in this structure.
438 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
439 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
444 assert(image != (Image *) NULL);
445 assert(image->signature == MagickSignature);
446 *pixel=image->background_color;
447 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
448 if (q != (Quantum *) NULL)
450 GetPixelPacket(image,q,pixel);
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 + G e t O n e V i r t u a l P i x e l F r o m S t r e a m %
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
466 % (x.y) location. The image background color is returned if an error occurs.
468 % The format of the GetOneVirtualPixelFromStream() method is:
470 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
471 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
472 % const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
474 % A description of each parameter follows:
476 % o image: the image.
478 % o virtual_pixel_method: the virtual pixel method.
480 % o x,y: These values define the location of the pixel to return.
482 % o pixel: return a pixel at the specified (x,y) location.
484 % o exception: return any errors or warnings in this structure.
487 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
488 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
489 PixelPacket *pixel,ExceptionInfo *exception)
494 assert(image != (Image *) NULL);
495 assert(image->signature == MagickSignature);
496 *pixel=image->background_color;
497 q=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
498 if (q != (const Quantum *) NULL)
500 GetPixelPacket(image,q,pixel);
505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 + G e t S t r e a m I n f o C l i e n t D a t a %
513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
515 % GetStreamInfoClientData() gets the stream info client data.
517 % The format of the SetStreamInfoClientData method is:
519 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
521 % A description of each parameter follows:
523 % o stream_info: the stream info.
526 MagickExport const void *GetStreamInfoClientData(StreamInfo *stream_info)
528 assert(stream_info != (StreamInfo *) NULL);
529 assert(stream_info->signature == MagickSignature);
530 return(stream_info->client_data);
534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
538 + G e t V i r t u a l P i x e l s F r o m S t r e a m %
542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
544 % GetVirtualPixelsStream() returns the pixels associated with the last
545 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
547 % The format of the GetVirtualPixelsStream() method is:
549 % const Quantum *GetVirtualPixelsStream(const Image *image)
551 % A description of each parameter follows:
553 % o pixels: return the pixels associated corresponding with the last call to
554 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
556 % o image: the image.
559 static const Quantum *GetVirtualPixelsStream(const Image *image)
564 assert(image != (Image *) NULL);
565 assert(image->signature == MagickSignature);
566 if (image->debug != MagickFalse)
567 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
568 cache_info=(CacheInfo *) image->cache;
569 assert(cache_info->signature == MagickSignature);
570 return(cache_info->pixels);
574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
578 + G e t V i r t u a l I n d e x e s F r o m S t r e a m %
582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584 % GetVirtualMetacontentFromStream() returns the associated pixel
585 % channels corresponding with the last call to QueueAuthenticPixelsStream() or
586 % GetVirtualPixelStream().
588 % The format of the GetVirtualMetacontentFromStream() method is:
590 % const void *GetVirtualMetacontentFromStream(const Image *image)
592 % A description of each parameter follows:
594 % o image: the image.
597 static const void *GetVirtualMetacontentFromStream(
603 assert(image != (Image *) NULL);
604 assert(image->signature == MagickSignature);
605 if (image->debug != MagickFalse)
606 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
607 cache_info=(CacheInfo *) image->cache;
608 assert(cache_info->signature == MagickSignature);
609 return(cache_info->metacontent);
613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 + G e t V i r t u a l P i x e l S t r e a m %
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
624 % defined by the geometry parameters. A pointer to the pixels is returned if
625 % the pixels are transferred, otherwise a NULL is returned. For streams this
628 % The format of the GetVirtualPixelStream() method is:
630 % const Quantum *GetVirtualPixelStream(const Image *image,
631 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
632 % const ssize_t y,const size_t columns,const size_t rows,
633 % ExceptionInfo *exception)
635 % A description of each parameter follows:
637 % o image: the image.
639 % o virtual_pixel_method: the virtual pixel method.
641 % o x,y,columns,rows: These values define the perimeter of a region of
644 % o exception: return any errors or warnings in this structure.
648 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
649 ExceptionInfo *exception)
651 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
653 cache_info->mapped=MagickFalse;
654 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
656 if (cache_info->pixels == (Quantum *) NULL)
658 cache_info->mapped=MagickTrue;
659 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
662 if (cache_info->pixels == (Quantum *) NULL)
664 (void) ThrowMagickException(exception,GetMagickModule(),
665 ResourceLimitError,"MemoryAllocationFailed","`%s'",
666 cache_info->filename);
672 static const Quantum *GetVirtualPixelStream(const Image *image,
673 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
674 const ssize_t y,const size_t columns,const size_t rows,
675 ExceptionInfo *exception)
690 Validate pixel cache geometry.
692 assert(image != (const Image *) NULL);
693 assert(image->signature == MagickSignature);
694 if (image->debug != MagickFalse)
695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
696 if ((x < 0) || (y < 0) ||
697 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
698 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
699 (columns == 0) || (rows == 0))
701 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
702 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
703 return((Quantum *) NULL);
705 cache_info=(CacheInfo *) image->cache;
706 assert(cache_info->signature == MagickSignature);
708 Pixels are stored in a temporary buffer until they are synced to the cache.
710 number_pixels=(MagickSizeType) columns*rows;
711 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
712 if (cache_info->metacontent_extent != 0)
713 length+=number_pixels*cache_info->metacontent_extent;
714 if (cache_info->pixels == (Quantum *) NULL)
716 cache_info->length=length;
717 status=AcquireStreamPixels(cache_info,exception);
718 if (status == MagickFalse)
720 cache_info->length=0;
721 return((Quantum *) NULL);
725 if (cache_info->length != length)
727 RelinquishStreamPixels(cache_info);
728 cache_info->length=length;
729 status=AcquireStreamPixels(cache_info,exception);
730 if (status == MagickFalse)
732 cache_info->length=0;
733 return((Quantum *) NULL);
736 cache_info->metacontent=(void *) NULL;
737 if (cache_info->metacontent_extent != 0)
738 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
739 cache_info->number_channels);
740 return(cache_info->pixels);
744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
748 + O p e n S t r e a m %
752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
754 % OpenStream() opens a stream for writing by the StreamImage() method.
756 % The format of the OpenStream method is:
758 % MagickBooleanType OpenStream(const ImageInfo *image_info,
759 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
761 % A description of each parameter follows:
763 % o image_info: the image info.
765 % o stream_info: the stream info.
767 % o filename: the stream filename.
769 % o exception: return any errors or warnings in this structure.
772 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
773 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
778 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
779 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 + Q u e u e A u t h e n t i c P i x e l s S t r e a m %
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
795 % defined by the region rectangle and returns a pointer to the area. This
796 % area is subsequently transferred from the pixel cache with method
797 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
798 % pixels are transferred, otherwise a NULL is returned.
800 % The format of the QueueAuthenticPixelsStream() method is:
802 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
803 % const ssize_t y,const size_t columns,const size_t rows,
804 % ExceptionInfo *exception)
806 % A description of each parameter follows:
808 % o image: the image.
810 % o x,y,columns,rows: These values define the perimeter of a region of
814 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
815 const ssize_t y,const size_t columns,const size_t rows,
816 ExceptionInfo *exception)
831 Validate pixel cache geometry.
833 assert(image != (Image *) NULL);
834 if ((x < 0) || (y < 0) ||
835 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
836 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
837 (columns == 0) || (rows == 0))
839 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
840 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
841 return((Quantum *) NULL);
843 stream_handler=GetBlobStreamHandler(image);
844 if (stream_handler == (StreamHandler) NULL)
846 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
847 "NoStreamHandlerIsDefined","`%s'",image->filename);
848 return((Quantum *) NULL);
850 cache_info=(CacheInfo *) image->cache;
851 assert(cache_info->signature == MagickSignature);
852 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
853 (image->colorspace != GetPixelCacheColorspace(image->cache)))
855 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
856 (void) stream_handler(image,(const void *) NULL,(size_t)
857 cache_info->columns);
858 cache_info->storage_class=image->storage_class;
859 cache_info->colorspace=image->colorspace;
860 cache_info->columns=image->columns;
861 cache_info->rows=image->rows;
862 image->cache=cache_info;
865 Pixels are stored in a temporary buffer until they are synced to the cache.
867 cache_info->columns=columns;
868 cache_info->rows=rows;
869 number_pixels=(MagickSizeType) columns*rows;
870 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
871 if (cache_info->metacontent_extent != 0)
872 length+=number_pixels*cache_info->metacontent_extent;
873 if (cache_info->pixels == (Quantum *) NULL)
875 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
876 cache_info->length=(MagickSizeType) length;
879 if (cache_info->length < (MagickSizeType) length)
881 cache_info->pixels=(Quantum *) ResizeMagickMemory(
882 cache_info->pixels,length);
883 cache_info->length=(MagickSizeType) length;
885 if (cache_info->pixels == (void *) NULL)
886 return((Quantum *) NULL);
887 cache_info->metacontent=(void *) NULL;
888 if (cache_info->metacontent_extent != 0)
889 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
890 cache_info->number_channels);
891 return(cache_info->pixels);
895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899 % R e a d S t r e a m %
903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
905 % ReadStream() makes the image pixels available to a user supplied callback
906 % method immediately upon reading a scanline with the ReadImage() method.
908 % The format of the ReadStream() method is:
910 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
911 % ExceptionInfo *exception)
913 % A description of each parameter follows:
915 % o image_info: the image info.
917 % o stream: a callback method.
919 % o exception: return any errors or warnings in this structure.
922 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
923 ExceptionInfo *exception)
937 assert(image_info != (ImageInfo *) NULL);
938 assert(image_info->signature == MagickSignature);
939 if (image_info->debug != MagickFalse)
940 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
941 image_info->filename);
942 assert(exception != (ExceptionInfo *) NULL);
943 assert(exception->signature == MagickSignature);
944 read_info=CloneImageInfo(image_info);
945 read_info->cache=AcquirePixelCache(0);
946 GetPixelCacheMethods(&cache_methods);
947 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
948 cache_methods.get_virtual_metacontent_from_handler=
949 GetVirtualMetacontentFromStream;
950 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
951 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
952 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
953 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
954 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
955 cache_methods.get_authentic_metacontent_from_handler=
956 GetAuthenticMetacontentFromStream;
957 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
958 cache_methods.get_one_authentic_pixel_from_handler=
959 GetOneAuthenticPixelFromStream;
960 cache_methods.destroy_pixel_handler=DestroyPixelStream;
961 SetPixelCacheMethods(read_info->cache,&cache_methods);
962 read_info->stream=stream;
963 image=ReadImage(read_info,exception);
964 read_info=DestroyImageInfo(read_info);
969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 + S e t S t r e a m I n f o C l i e n t D a t a %
977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 % SetStreamInfoClientData() sets the stream info client data.
981 % The format of the SetStreamInfoClientData method is:
983 % void SetStreamInfoClientData(StreamInfo *stream_info,
984 % const void *client_data)
986 % A description of each parameter follows:
988 % o stream_info: the stream info.
990 % o client_data: the client data.
993 MagickExport void SetStreamInfoClientData(StreamInfo *stream_info,
994 const void *client_data)
996 assert(stream_info != (StreamInfo *) NULL);
997 assert(stream_info->signature == MagickSignature);
998 stream_info->client_data=client_data;
1002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 + S e t S t r e a m I n f o M a p %
1010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1012 % SetStreamInfoMap() sets the stream info map member.
1014 % The format of the SetStreamInfoMap method is:
1016 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1018 % A description of each parameter follows:
1020 % o stream_info: the stream info.
1025 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1027 assert(stream_info != (StreamInfo *) NULL);
1028 assert(stream_info->signature == MagickSignature);
1029 (void) CloneString(&stream_info->map,map);
1033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1037 + S e t S t r e a m I n f o S t o r a g e T y p e %
1041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043 % SetStreamInfoStorageType() sets the stream info storage type member.
1045 % The format of the SetStreamInfoStorageType method is:
1047 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1048 % const StoreageType *storage_type)
1050 % A description of each parameter follows:
1052 % o stream_info: the stream info.
1054 % o storage_type: the storage type.
1057 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1058 const StorageType storage_type)
1060 assert(stream_info != (StreamInfo *) NULL);
1061 assert(stream_info->signature == MagickSignature);
1062 stream_info->storage_type=storage_type;
1066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1070 + S t r e a m I m a g e %
1074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1076 % StreamImage() streams pixels from an image and writes them in a user
1077 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1079 % The format of the StreamImage() method is:
1081 % Image *StreamImage(const ImageInfo *image_info,
1082 % StreamInfo *stream_info,ExceptionInfo *exception)
1084 % A description of each parameter follows:
1086 % o image_info: the image info.
1088 % o stream_info: the stream info.
1090 % o exception: return any errors or warnings in this structure.
1094 #if defined(__cplusplus) || defined(c_plusplus)
1098 static size_t WriteStreamImage(const Image *image,const void *pixels,
1099 const size_t columns)
1118 stream_info=(StreamInfo *) image->client_data;
1119 switch (stream_info->storage_type)
1121 default: packet_size=sizeof(char); break;
1122 case CharPixel: packet_size=sizeof(char); break;
1123 case DoublePixel: packet_size=sizeof(double); break;
1124 case FloatPixel: packet_size=sizeof(float); break;
1125 case IntegerPixel: packet_size=sizeof(int); break;
1126 case LongPixel: packet_size=sizeof(ssize_t); break;
1127 case QuantumPixel: packet_size=sizeof(Quantum); break;
1128 case ShortPixel: packet_size=sizeof(unsigned short); break;
1130 cache_info=(CacheInfo *) image->cache;
1131 assert(cache_info->signature == MagickSignature);
1132 packet_size*=strlen(stream_info->map);
1133 length=packet_size*cache_info->columns*cache_info->rows;
1134 if (image != stream_info->image)
1140 Prepare stream for writing.
1142 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1143 stream_info->pixels,length,sizeof(*stream_info->pixels));
1144 if (stream_info->pixels == (unsigned char *) NULL)
1146 stream_info->image=image;
1147 write_info=CloneImageInfo(stream_info->image_info);
1148 (void) SetImageInfo(write_info,1,stream_info->exception);
1149 if (write_info->extract != (char *) NULL)
1150 (void) ParseAbsoluteGeometry(write_info->extract,
1151 &stream_info->extract_info);
1153 write_info=DestroyImageInfo(write_info);
1155 extract_info=stream_info->extract_info;
1156 if ((extract_info.width == 0) || (extract_info.height == 0))
1159 Write all pixels to stream.
1161 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1162 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1164 return(count == 0 ? 0 : columns);
1166 if ((stream_info->y < extract_info.y) ||
1167 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1173 Write a portion of the pixel row to the stream.
1175 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1176 length=packet_size*extract_info.width;
1177 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1180 return(count == 0 ? 0 : columns);
1183 #if defined(__cplusplus) || defined(c_plusplus)
1187 MagickExport Image *StreamImage(const ImageInfo *image_info,
1188 StreamInfo *stream_info,ExceptionInfo *exception)
1196 assert(image_info != (const ImageInfo *) NULL);
1197 assert(image_info->signature == MagickSignature);
1198 if (image_info->debug != MagickFalse)
1199 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1200 image_info->filename);
1201 assert(stream_info != (StreamInfo *) NULL);
1202 assert(stream_info->signature == MagickSignature);
1203 assert(exception != (ExceptionInfo *) NULL);
1204 read_info=CloneImageInfo(image_info);
1205 stream_info->image_info=image_info;
1206 stream_info->exception=exception;
1207 read_info->client_data=(void *) stream_info;
1208 image=ReadStream(read_info,&WriteStreamImage,exception);
1209 read_info=DestroyImageInfo(read_info);
1210 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1211 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1212 image=DestroyImage(image);
1217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1221 + S t r e a m I m a g e P i x e l s %
1225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1227 % StreamImagePixels() extracts pixel data from an image and returns it in the
1228 % stream_info->pixels structure in the format as defined by
1229 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1231 % The format of the StreamImagePixels method is:
1233 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1234 % const Image *image,ExceptionInfo *exception)
1236 % A description of each parameter follows:
1238 % o stream_info: the stream info.
1240 % o image: the image.
1242 % o exception: return any errors or warnings in this structure.
1245 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1246 const Image *image,ExceptionInfo *exception)
1254 register const Quantum
1264 assert(stream_info != (StreamInfo *) NULL);
1265 assert(stream_info->signature == MagickSignature);
1266 assert(image != (Image *) NULL);
1267 assert(image->signature == MagickSignature);
1268 if (image->debug != MagickFalse)
1269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1270 length=strlen(stream_info->map);
1271 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1272 if (quantum_map == (QuantumType *) NULL)
1274 (void) ThrowMagickException(exception,GetMagickModule(),
1275 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1276 return(MagickFalse);
1278 for (i=0; i < (ssize_t) length; i++)
1280 switch (stream_info->map[i])
1285 quantum_map[i]=AlphaQuantum;
1291 quantum_map[i]=BlueQuantum;
1297 quantum_map[i]=CyanQuantum;
1298 if (image->colorspace == CMYKColorspace)
1300 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1301 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1302 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1303 return(MagickFalse);
1308 quantum_map[i]=GreenQuantum;
1314 quantum_map[i]=IndexQuantum;
1320 quantum_map[i]=BlackQuantum;
1321 if (image->colorspace == CMYKColorspace)
1323 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1324 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1325 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1326 return(MagickFalse);
1331 quantum_map[i]=MagentaQuantum;
1332 if (image->colorspace == CMYKColorspace)
1334 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1335 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1336 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1337 return(MagickFalse);
1342 quantum_map[i]=OpacityQuantum;
1348 quantum_map[i]=UndefinedQuantum;
1354 quantum_map[i]=RedQuantum;
1360 quantum_map[i]=YellowQuantum;
1361 if (image->colorspace == CMYKColorspace)
1363 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1364 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1365 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1366 return(MagickFalse);
1370 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1371 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1372 "UnrecognizedPixelMap","`%s'",stream_info->map);
1373 return(MagickFalse);
1377 quantum_info=stream_info->quantum_info;
1378 switch (stream_info->storage_type)
1382 register unsigned char
1385 q=(unsigned char *) stream_info->pixels;
1386 if (LocaleCompare(stream_info->map,"BGR") == 0)
1388 p=GetAuthenticPixelQueue(image);
1389 if (p == (const Quantum *) NULL)
1391 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1393 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1394 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1395 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1400 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1402 p=GetAuthenticPixelQueue(image);
1403 if (p == (const Quantum *) NULL)
1405 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1407 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1408 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1409 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1410 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1415 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1417 p=GetAuthenticPixelQueue(image);
1418 if (p == (const Quantum *) NULL)
1420 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1422 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1423 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1424 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1425 *q++=ScaleQuantumToChar((Quantum) 0);
1430 if (LocaleCompare(stream_info->map,"I") == 0)
1432 p=GetAuthenticPixelQueue(image);
1433 if (p == (const Quantum *) NULL)
1435 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1437 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
1442 if (LocaleCompare(stream_info->map,"RGB") == 0)
1444 p=GetAuthenticPixelQueue(image);
1445 if (p == (const Quantum *) NULL)
1447 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1449 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1450 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1451 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1456 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1458 p=GetAuthenticPixelQueue(image);
1459 if (p == (const Quantum *) NULL)
1461 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1463 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1464 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1465 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1466 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1471 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1473 p=GetAuthenticPixelQueue(image);
1474 if (p == (const Quantum *) NULL)
1476 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1478 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1479 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1480 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1481 *q++=ScaleQuantumToChar((Quantum) 0);
1486 p=GetAuthenticPixelQueue(image);
1487 if (p == (const Quantum *) NULL)
1489 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1491 for (i=0; i < (ssize_t) length; i++)
1494 switch (quantum_map[i])
1499 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1503 case MagentaQuantum:
1505 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1511 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1516 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1519 case OpacityQuantum:
1521 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1526 if (image->colorspace == CMYKColorspace)
1527 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1532 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
1549 q=(double *) stream_info->pixels;
1550 if (LocaleCompare(stream_info->map,"BGR") == 0)
1552 p=GetAuthenticPixelQueue(image);
1553 if (p == (const Quantum *) NULL)
1555 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1557 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1558 quantum_info->scale+quantum_info->minimum);
1559 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1560 quantum_info->scale+quantum_info->minimum);
1561 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1562 quantum_info->scale+quantum_info->minimum);
1567 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1569 p=GetAuthenticPixelQueue(image);
1570 if (p == (const Quantum *) NULL)
1572 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1574 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1575 quantum_info->scale+quantum_info->minimum);
1576 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1577 quantum_info->scale+quantum_info->minimum);
1578 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1579 quantum_info->scale+quantum_info->minimum);
1580 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1581 quantum_info->scale+quantum_info->minimum);
1586 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1588 p=GetAuthenticPixelQueue(image);
1589 if (p == (const Quantum *) NULL)
1591 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1593 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1594 quantum_info->scale+quantum_info->minimum);
1595 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1596 quantum_info->scale+quantum_info->minimum);
1597 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1598 quantum_info->scale+quantum_info->minimum);
1604 if (LocaleCompare(stream_info->map,"I") == 0)
1606 p=GetAuthenticPixelQueue(image);
1607 if (p == (const Quantum *) NULL)
1609 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1611 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1612 quantum_info->scale+quantum_info->minimum);
1617 if (LocaleCompare(stream_info->map,"RGB") == 0)
1619 p=GetAuthenticPixelQueue(image);
1620 if (p == (const Quantum *) NULL)
1622 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1624 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1625 quantum_info->scale+quantum_info->minimum);
1626 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1627 quantum_info->scale+quantum_info->minimum);
1628 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1629 quantum_info->scale+quantum_info->minimum);
1634 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1636 p=GetAuthenticPixelQueue(image);
1637 if (p == (const Quantum *) NULL)
1639 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1641 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1642 quantum_info->scale+quantum_info->minimum);
1643 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1644 quantum_info->scale+quantum_info->minimum);
1645 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1646 quantum_info->scale+quantum_info->minimum);
1647 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1653 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1655 p=GetAuthenticPixelQueue(image);
1656 if (p == (const Quantum *) NULL)
1658 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1660 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1661 quantum_info->scale+quantum_info->minimum);
1662 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1663 quantum_info->scale+quantum_info->minimum);
1664 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1665 quantum_info->scale+quantum_info->minimum);
1671 p=GetAuthenticPixelQueue(image);
1672 if (p == (const Quantum *) NULL)
1674 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1676 for (i=0; i < (ssize_t) length; i++)
1679 switch (quantum_map[i])
1684 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1685 quantum_info->scale+quantum_info->minimum);
1689 case MagentaQuantum:
1691 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1692 quantum_info->scale+quantum_info->minimum);
1698 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1699 quantum_info->scale+quantum_info->minimum);
1704 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1705 quantum_info->scale+quantum_info->minimum);
1708 case OpacityQuantum:
1710 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1711 quantum_info->scale+quantum_info->minimum);
1716 if (image->colorspace == CMYKColorspace)
1717 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1718 quantum_info->scale+quantum_info->minimum);
1723 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1724 quantum_info->scale+quantum_info->minimum);
1741 q=(float *) stream_info->pixels;
1742 if (LocaleCompare(stream_info->map,"BGR") == 0)
1744 p=GetAuthenticPixelQueue(image);
1745 if (p == (const Quantum *) NULL)
1747 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1749 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1750 quantum_info->scale+quantum_info->minimum);
1751 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1752 quantum_info->scale+quantum_info->minimum);
1753 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1754 quantum_info->scale+quantum_info->minimum);
1759 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1761 p=GetAuthenticPixelQueue(image);
1762 if (p == (const Quantum *) NULL)
1764 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1766 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1767 quantum_info->scale+quantum_info->minimum);
1768 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1769 quantum_info->scale+quantum_info->minimum);
1770 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1771 quantum_info->scale+quantum_info->minimum);
1772 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1773 quantum_info->scale+quantum_info->minimum);
1778 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1780 p=GetAuthenticPixelQueue(image);
1781 if (p == (const Quantum *) NULL)
1783 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1785 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1786 quantum_info->scale+quantum_info->minimum);
1787 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1788 quantum_info->scale+quantum_info->minimum);
1789 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1790 quantum_info->scale+quantum_info->minimum);
1796 if (LocaleCompare(stream_info->map,"I") == 0)
1798 p=GetAuthenticPixelQueue(image);
1799 if (p == (const Quantum *) NULL)
1801 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1803 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1804 quantum_info->scale+quantum_info->minimum);
1809 if (LocaleCompare(stream_info->map,"RGB") == 0)
1811 p=GetAuthenticPixelQueue(image);
1812 if (p == (const Quantum *) NULL)
1814 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1816 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1817 quantum_info->scale+quantum_info->minimum);
1818 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1819 quantum_info->scale+quantum_info->minimum);
1820 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1821 quantum_info->scale+quantum_info->minimum);
1826 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1828 p=GetAuthenticPixelQueue(image);
1829 if (p == (const Quantum *) NULL)
1831 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1833 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1834 quantum_info->scale+quantum_info->minimum);
1835 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1836 quantum_info->scale+quantum_info->minimum);
1837 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1838 quantum_info->scale+quantum_info->minimum);
1839 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1845 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1847 p=GetAuthenticPixelQueue(image);
1848 if (p == (const Quantum *) NULL)
1850 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1852 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1853 quantum_info->scale+quantum_info->minimum);
1854 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1855 quantum_info->scale+quantum_info->minimum);
1856 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1857 quantum_info->scale+quantum_info->minimum);
1863 p=GetAuthenticPixelQueue(image);
1864 if (p == (const Quantum *) NULL)
1866 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1868 for (i=0; i < (ssize_t) length; i++)
1871 switch (quantum_map[i])
1876 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1877 quantum_info->scale+quantum_info->minimum);
1881 case MagentaQuantum:
1883 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1884 quantum_info->scale+quantum_info->minimum);
1890 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1891 quantum_info->scale+quantum_info->minimum);
1896 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1897 quantum_info->scale+quantum_info->minimum);
1900 case OpacityQuantum:
1902 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1903 quantum_info->scale+quantum_info->minimum);
1908 if (image->colorspace == CMYKColorspace)
1909 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1910 quantum_info->scale+quantum_info->minimum);
1915 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1916 quantum_info->scale+quantum_info->minimum);
1930 register unsigned int
1933 q=(unsigned int *) stream_info->pixels;
1934 if (LocaleCompare(stream_info->map,"BGR") == 0)
1936 p=GetAuthenticPixelQueue(image);
1937 if (p == (const Quantum *) NULL)
1939 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1941 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1942 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1943 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1948 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1950 p=GetAuthenticPixelQueue(image);
1951 if (p == (const Quantum *) NULL)
1953 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1955 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1956 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1957 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1958 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1963 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1965 p=GetAuthenticPixelQueue(image);
1966 if (p == (const Quantum *) NULL)
1968 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1970 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1971 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1972 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1978 if (LocaleCompare(stream_info->map,"I") == 0)
1980 p=GetAuthenticPixelQueue(image);
1981 if (p == (const Quantum *) NULL)
1983 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1985 *q++=(unsigned int) ScaleQuantumToLong(
1986 GetPixelIntensity(image,p));
1991 if (LocaleCompare(stream_info->map,"RGB") == 0)
1993 p=GetAuthenticPixelQueue(image);
1994 if (p == (const Quantum *) NULL)
1996 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1998 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1999 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2000 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2005 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2007 p=GetAuthenticPixelQueue(image);
2008 if (p == (const Quantum *) NULL)
2010 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2012 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2013 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2014 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2015 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2016 (GetPixelAlpha(image,p)));
2021 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2023 p=GetAuthenticPixelQueue(image);
2024 if (p == (const Quantum *) NULL)
2026 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2028 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2029 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2030 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2036 p=GetAuthenticPixelQueue(image);
2037 if (p == (const Quantum *) NULL)
2039 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2041 for (i=0; i < (ssize_t) length; i++)
2044 switch (quantum_map[i])
2049 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2053 case MagentaQuantum:
2055 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2061 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2066 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
2069 case OpacityQuantum:
2071 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
2076 if (image->colorspace == CMYKColorspace)
2077 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
2083 ScaleQuantumToLong(GetPixelIntensity(image,p));
2100 q=(size_t *) stream_info->pixels;
2101 if (LocaleCompare(stream_info->map,"BGR") == 0)
2103 p=GetAuthenticPixelQueue(image);
2104 if (p == (const Quantum *) NULL)
2106 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2108 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2109 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2110 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2115 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2117 p=GetAuthenticPixelQueue(image);
2118 if (p == (const Quantum *) NULL)
2120 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2122 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2123 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2124 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2125 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2130 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2132 p=GetAuthenticPixelQueue(image);
2133 if (p == (const Quantum *) NULL)
2135 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2137 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2138 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2139 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2145 if (LocaleCompare(stream_info->map,"I") == 0)
2147 p=GetAuthenticPixelQueue(image);
2148 if (p == (const Quantum *) NULL)
2150 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2152 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
2157 if (LocaleCompare(stream_info->map,"RGB") == 0)
2159 p=GetAuthenticPixelQueue(image);
2160 if (p == (const Quantum *) NULL)
2162 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2164 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2165 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2166 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2171 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2173 p=GetAuthenticPixelQueue(image);
2174 if (p == (const Quantum *) NULL)
2176 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2178 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2179 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2180 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2181 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2186 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2188 p=GetAuthenticPixelQueue(image);
2189 if (p == (const Quantum *) NULL)
2191 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2193 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2194 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2195 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2201 p=GetAuthenticPixelQueue(image);
2202 if (p == (const Quantum *) NULL)
2204 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2206 for (i=0; i < (ssize_t) length; i++)
2209 switch (quantum_map[i])
2214 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2218 case MagentaQuantum:
2220 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2226 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2231 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2234 case OpacityQuantum:
2236 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2241 if (image->colorspace == CMYKColorspace)
2242 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2247 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
2264 q=(Quantum *) stream_info->pixels;
2265 if (LocaleCompare(stream_info->map,"BGR") == 0)
2267 p=GetAuthenticPixelQueue(image);
2268 if (p == (const Quantum *) NULL)
2270 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2272 *q++=GetPixelBlue(image,p);
2273 *q++=GetPixelGreen(image,p);
2274 *q++=GetPixelRed(image,p);
2279 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2281 p=GetAuthenticPixelQueue(image);
2282 if (p == (const Quantum *) NULL)
2284 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2286 *q++=GetPixelBlue(image,p);
2287 *q++=GetPixelGreen(image,p);
2288 *q++=GetPixelRed(image,p);
2289 *q++=(Quantum) (GetPixelAlpha(image,p));
2294 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2296 p=GetAuthenticPixelQueue(image);
2297 if (p == (const Quantum *) NULL)
2299 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2301 *q++=GetPixelBlue(image,p);
2302 *q++=GetPixelGreen(image,p);
2303 *q++=GetPixelRed(image,p);
2309 if (LocaleCompare(stream_info->map,"I") == 0)
2311 p=GetAuthenticPixelQueue(image);
2312 if (p == (const Quantum *) NULL)
2314 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2316 *q++=GetPixelIntensity(image,p);
2321 if (LocaleCompare(stream_info->map,"RGB") == 0)
2323 p=GetAuthenticPixelQueue(image);
2324 if (p == (const Quantum *) NULL)
2326 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2328 *q++=GetPixelRed(image,p);
2329 *q++=GetPixelGreen(image,p);
2330 *q++=GetPixelBlue(image,p);
2335 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2337 p=GetAuthenticPixelQueue(image);
2338 if (p == (const Quantum *) NULL)
2340 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2342 *q++=GetPixelRed(image,p);
2343 *q++=GetPixelGreen(image,p);
2344 *q++=GetPixelBlue(image,p);
2345 *q++=(Quantum) (GetPixelAlpha(image,p));
2350 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2352 p=GetAuthenticPixelQueue(image);
2353 if (p == (const Quantum *) NULL)
2355 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2357 *q++=GetPixelRed(image,p);
2358 *q++=GetPixelGreen(image,p);
2359 *q++=GetPixelBlue(image,p);
2365 p=GetAuthenticPixelQueue(image);
2366 if (p == (const Quantum *) NULL)
2368 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2370 for (i=0; i < (ssize_t) length; i++)
2373 switch (quantum_map[i])
2378 *q=GetPixelRed(image,p);
2382 case MagentaQuantum:
2384 *q=GetPixelGreen(image,p);
2390 *q=GetPixelBlue(image,p);
2395 *q=(Quantum) (GetPixelAlpha(image,p));
2398 case OpacityQuantum:
2400 *q=GetPixelAlpha(image,p);
2405 if (image->colorspace == CMYKColorspace)
2406 *q=GetPixelBlack(image,p);
2411 *q=(GetPixelIntensity(image,p));
2425 register unsigned short
2428 q=(unsigned short *) stream_info->pixels;
2429 if (LocaleCompare(stream_info->map,"BGR") == 0)
2431 p=GetAuthenticPixelQueue(image);
2432 if (p == (const Quantum *) NULL)
2434 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2436 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2437 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2438 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2443 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2445 p=GetAuthenticPixelQueue(image);
2446 if (p == (const Quantum *) NULL)
2448 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2450 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2451 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2452 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2453 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2458 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2460 p=GetAuthenticPixelQueue(image);
2461 if (p == (const Quantum *) NULL)
2463 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2465 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2466 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2467 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2473 if (LocaleCompare(stream_info->map,"I") == 0)
2475 p=GetAuthenticPixelQueue(image);
2476 if (p == (const Quantum *) NULL)
2478 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2480 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
2485 if (LocaleCompare(stream_info->map,"RGB") == 0)
2487 p=GetAuthenticPixelQueue(image);
2488 if (p == (const Quantum *) NULL)
2490 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2492 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2493 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2494 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2499 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2501 p=GetAuthenticPixelQueue(image);
2502 if (p == (const Quantum *) NULL)
2504 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2506 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2507 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2508 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2509 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2514 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2516 p=GetAuthenticPixelQueue(image);
2517 if (p == (const Quantum *) NULL)
2519 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2521 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2522 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2523 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2529 p=GetAuthenticPixelQueue(image);
2530 if (p == (const Quantum *) NULL)
2532 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2534 for (i=0; i < (ssize_t) length; i++)
2537 switch (quantum_map[i])
2542 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2546 case MagentaQuantum:
2548 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2554 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2559 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2562 case OpacityQuantum:
2564 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2569 if (image->colorspace == CMYKColorspace)
2570 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2575 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
2589 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2590 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2591 "UnrecognizedPixelMap","`%s'",stream_info->map);
2595 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2604 + S y n c A u t h e n t i c P i x e l s S t r e a m %
2608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2610 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2611 % the latest stream of pixels.
2613 % The format of the SyncAuthenticPixelsStream method is:
2615 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2616 % ExceptionInfo *exception)
2618 % A description of each parameter follows:
2620 % o image: the image.
2622 % o exception: return any errors or warnings in this structure.
2625 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2626 ExceptionInfo *exception)
2637 assert(image != (Image *) NULL);
2638 assert(image->signature == MagickSignature);
2639 if (image->debug != MagickFalse)
2640 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2641 cache_info=(CacheInfo *) image->cache;
2642 assert(cache_info->signature == MagickSignature);
2643 stream_handler=GetBlobStreamHandler(image);
2644 if (stream_handler == (StreamHandler) NULL)
2646 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2647 "NoStreamHandlerIsDefined","`%s'",image->filename);
2648 return(MagickFalse);
2650 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2651 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659 % W r i t e S t r e a m %
2663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2665 % WriteStream() makes the image pixels available to a user supplied callback
2666 % method immediately upon writing pixel data with the WriteImage() method.
2668 % The format of the WriteStream() method is:
2670 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2671 % StreamHandler stream)
2673 % A description of each parameter follows:
2675 % o image_info: the image info.
2677 % o stream: A callback method.
2680 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2681 Image *image,StreamHandler stream)
2689 assert(image_info != (ImageInfo *) NULL);
2690 assert(image_info->signature == MagickSignature);
2691 if (image_info->debug != MagickFalse)
2692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2693 image_info->filename);
2694 assert(image != (Image *) NULL);
2695 assert(image->signature == MagickSignature);
2696 write_info=CloneImageInfo(image_info);
2697 write_info->stream=stream;
2698 status=WriteImage(write_info,image,&image->exception);
2699 write_info=DestroyImageInfo(write_info);