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 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
498 if (p == (const Quantum *) NULL)
500 GetPixelPacket(image,p,pixel);
501 if (image->colorspace == CMYKColorspace)
502 pixel->black=GetPixelBlack(image,p);
507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511 + G e t S t r e a m I n f o C l i e n t D a t a %
515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
517 % GetStreamInfoClientData() gets the stream info client data.
519 % The format of the GetStreamInfoClientData method is:
521 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
523 % A description of each parameter follows:
525 % o stream_info: the stream info.
528 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
530 assert(stream_info != (StreamInfo *) NULL);
531 assert(stream_info->signature == MagickSignature);
532 return(stream_info->client_data);
536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
540 + 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 %
544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 % GetVirtualPixelsStream() returns the pixels associated with the last
547 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
549 % The format of the GetVirtualPixelsStream() method is:
551 % const Quantum *GetVirtualPixelsStream(const Image *image)
553 % A description of each parameter follows:
555 % o pixels: return the pixels associated corresponding with the last call to
556 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
558 % o image: the image.
561 static const Quantum *GetVirtualPixelsStream(const Image *image)
566 assert(image != (Image *) NULL);
567 assert(image->signature == MagickSignature);
568 if (image->debug != MagickFalse)
569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
570 cache_info=(CacheInfo *) image->cache;
571 assert(cache_info->signature == MagickSignature);
572 return(cache_info->pixels);
576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580 + 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 %
584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
586 % GetVirtualMetacontentFromStream() returns the associated pixel
587 % channels corresponding with the last call to QueueAuthenticPixelsStream() or
588 % GetVirtualPixelStream().
590 % The format of the GetVirtualMetacontentFromStream() method is:
592 % const void *GetVirtualMetacontentFromStream(const Image *image)
594 % A description of each parameter follows:
596 % o image: the image.
599 static const void *GetVirtualMetacontentFromStream(
605 assert(image != (Image *) NULL);
606 assert(image->signature == MagickSignature);
607 if (image->debug != MagickFalse)
608 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
609 cache_info=(CacheInfo *) image->cache;
610 assert(cache_info->signature == MagickSignature);
611 return(cache_info->metacontent);
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 + G e t V i r t u a l P i x e l S t r e a m %
623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
626 % defined by the geometry parameters. A pointer to the pixels is returned if
627 % the pixels are transferred, otherwise a NULL is returned. For streams this
630 % The format of the GetVirtualPixelStream() method is:
632 % const Quantum *GetVirtualPixelStream(const Image *image,
633 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
634 % const ssize_t y,const size_t columns,const size_t rows,
635 % ExceptionInfo *exception)
637 % A description of each parameter follows:
639 % o image: the image.
641 % o virtual_pixel_method: the virtual pixel method.
643 % o x,y,columns,rows: These values define the perimeter of a region of
646 % o exception: return any errors or warnings in this structure.
650 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
651 ExceptionInfo *exception)
653 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
655 cache_info->mapped=MagickFalse;
656 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
658 if (cache_info->pixels == (Quantum *) NULL)
660 cache_info->mapped=MagickTrue;
661 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
664 if (cache_info->pixels == (Quantum *) NULL)
666 (void) ThrowMagickException(exception,GetMagickModule(),
667 ResourceLimitError,"MemoryAllocationFailed","`%s'",
668 cache_info->filename);
674 static const Quantum *GetVirtualPixelStream(const Image *image,
675 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
676 const ssize_t y,const size_t columns,const size_t rows,
677 ExceptionInfo *exception)
692 Validate pixel cache geometry.
694 assert(image != (const Image *) NULL);
695 assert(image->signature == MagickSignature);
696 if (image->debug != MagickFalse)
697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
698 if ((x < 0) || (y < 0) ||
699 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
700 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
701 (columns == 0) || (rows == 0))
703 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
704 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
705 return((Quantum *) NULL);
707 cache_info=(CacheInfo *) image->cache;
708 assert(cache_info->signature == MagickSignature);
710 Pixels are stored in a temporary buffer until they are synced to the cache.
712 number_pixels=(MagickSizeType) columns*rows;
713 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
714 if (cache_info->metacontent_extent != 0)
715 length+=number_pixels*cache_info->metacontent_extent;
716 if (cache_info->pixels == (Quantum *) NULL)
718 cache_info->length=length;
719 status=AcquireStreamPixels(cache_info,exception);
720 if (status == MagickFalse)
722 cache_info->length=0;
723 return((Quantum *) NULL);
727 if (cache_info->length != length)
729 RelinquishStreamPixels(cache_info);
730 cache_info->length=length;
731 status=AcquireStreamPixels(cache_info,exception);
732 if (status == MagickFalse)
734 cache_info->length=0;
735 return((Quantum *) NULL);
738 cache_info->metacontent=(void *) NULL;
739 if (cache_info->metacontent_extent != 0)
740 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
741 cache_info->number_channels);
742 return(cache_info->pixels);
746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 + O p e n S t r e a m %
754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
756 % OpenStream() opens a stream for writing by the StreamImage() method.
758 % The format of the OpenStream method is:
760 % MagickBooleanType OpenStream(const ImageInfo *image_info,
761 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
763 % A description of each parameter follows:
765 % o image_info: the image info.
767 % o stream_info: the stream info.
769 % o filename: the stream filename.
771 % o exception: return any errors or warnings in this structure.
774 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
775 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
780 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
781 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 + 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 %
794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
797 % defined by the region rectangle and returns a pointer to the area. This
798 % area is subsequently transferred from the pixel cache with method
799 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
800 % pixels are transferred, otherwise a NULL is returned.
802 % The format of the QueueAuthenticPixelsStream() method is:
804 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
805 % const ssize_t y,const size_t columns,const size_t rows,
806 % ExceptionInfo *exception)
808 % A description of each parameter follows:
810 % o image: the image.
812 % o x,y,columns,rows: These values define the perimeter of a region of
816 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
817 const ssize_t y,const size_t columns,const size_t rows,
818 ExceptionInfo *exception)
833 Validate pixel cache geometry.
835 assert(image != (Image *) NULL);
836 if ((x < 0) || (y < 0) ||
837 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
838 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
839 (columns == 0) || (rows == 0))
841 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
842 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
843 return((Quantum *) NULL);
845 stream_handler=GetBlobStreamHandler(image);
846 if (stream_handler == (StreamHandler) NULL)
848 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
849 "NoStreamHandlerIsDefined","`%s'",image->filename);
850 return((Quantum *) NULL);
852 cache_info=(CacheInfo *) image->cache;
853 assert(cache_info->signature == MagickSignature);
854 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
855 (image->colorspace != GetPixelCacheColorspace(image->cache)))
857 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
858 (void) stream_handler(image,(const void *) NULL,(size_t)
859 cache_info->columns);
860 cache_info->storage_class=image->storage_class;
861 cache_info->colorspace=image->colorspace;
862 cache_info->columns=image->columns;
863 cache_info->rows=image->rows;
864 image->cache=cache_info;
867 Pixels are stored in a temporary buffer until they are synced to the cache.
869 cache_info->columns=columns;
870 cache_info->rows=rows;
871 number_pixels=(MagickSizeType) columns*rows;
872 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
873 if (cache_info->metacontent_extent != 0)
874 length+=number_pixels*cache_info->metacontent_extent;
875 if (cache_info->pixels == (Quantum *) NULL)
877 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
878 cache_info->length=(MagickSizeType) length;
881 if (cache_info->length < (MagickSizeType) length)
883 cache_info->pixels=(Quantum *) ResizeMagickMemory(
884 cache_info->pixels,length);
885 cache_info->length=(MagickSizeType) length;
887 if (cache_info->pixels == (void *) NULL)
888 return((Quantum *) NULL);
889 cache_info->metacontent=(void *) NULL;
890 if (cache_info->metacontent_extent != 0)
891 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
892 cache_info->number_channels);
893 return(cache_info->pixels);
897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
901 % R e a d S t r e a m %
905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
907 % ReadStream() makes the image pixels available to a user supplied callback
908 % method immediately upon reading a scanline with the ReadImage() method.
910 % The format of the ReadStream() method is:
912 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
913 % ExceptionInfo *exception)
915 % A description of each parameter follows:
917 % o image_info: the image info.
919 % o stream: a callback method.
921 % o exception: return any errors or warnings in this structure.
924 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
925 ExceptionInfo *exception)
939 assert(image_info != (ImageInfo *) NULL);
940 assert(image_info->signature == MagickSignature);
941 if (image_info->debug != MagickFalse)
942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
943 image_info->filename);
944 assert(exception != (ExceptionInfo *) NULL);
945 assert(exception->signature == MagickSignature);
946 read_info=CloneImageInfo(image_info);
947 read_info->cache=AcquirePixelCache(0);
948 GetPixelCacheMethods(&cache_methods);
949 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
950 cache_methods.get_virtual_metacontent_from_handler=
951 GetVirtualMetacontentFromStream;
952 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
953 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
954 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
955 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
956 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
957 cache_methods.get_authentic_metacontent_from_handler=
958 GetAuthenticMetacontentFromStream;
959 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
960 cache_methods.get_one_authentic_pixel_from_handler=
961 GetOneAuthenticPixelFromStream;
962 cache_methods.destroy_pixel_handler=DestroyPixelStream;
963 SetPixelCacheMethods(read_info->cache,&cache_methods);
964 read_info->stream=stream;
965 image=ReadImage(read_info,exception);
966 read_info=DestroyImageInfo(read_info);
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975 + S e t S t r e a m I n f o C l i e n t D a t a %
979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 % SetStreamInfoClientData() sets the stream info client data.
983 % The format of the SetStreamInfoClientData method is:
985 % void SetStreamInfoClientData(StreamInfo *stream_info,
986 % const void *client_data)
988 % A description of each parameter follows:
990 % o stream_info: the stream info.
992 % o client_data: the client data.
995 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
996 const void *client_data)
998 assert(stream_info != (StreamInfo *) NULL);
999 assert(stream_info->signature == MagickSignature);
1000 stream_info->client_data=client_data;
1004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008 + S e t S t r e a m I n f o M a p %
1012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 % SetStreamInfoMap() sets the stream info map member.
1016 % The format of the SetStreamInfoMap method is:
1018 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1020 % A description of each parameter follows:
1022 % o stream_info: the stream info.
1027 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1029 assert(stream_info != (StreamInfo *) NULL);
1030 assert(stream_info->signature == MagickSignature);
1031 (void) CloneString(&stream_info->map,map);
1035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039 + S e t S t r e a m I n f o S t o r a g e T y p e %
1043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045 % SetStreamInfoStorageType() sets the stream info storage type member.
1047 % The format of the SetStreamInfoStorageType method is:
1049 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1050 % const StoreageType *storage_type)
1052 % A description of each parameter follows:
1054 % o stream_info: the stream info.
1056 % o storage_type: the storage type.
1059 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1060 const StorageType storage_type)
1062 assert(stream_info != (StreamInfo *) NULL);
1063 assert(stream_info->signature == MagickSignature);
1064 stream_info->storage_type=storage_type;
1068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1072 + S t r e a m I m a g e %
1076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1078 % StreamImage() streams pixels from an image and writes them in a user
1079 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1081 % The format of the StreamImage() method is:
1083 % Image *StreamImage(const ImageInfo *image_info,
1084 % StreamInfo *stream_info,ExceptionInfo *exception)
1086 % A description of each parameter follows:
1088 % o image_info: the image info.
1090 % o stream_info: the stream info.
1092 % o exception: return any errors or warnings in this structure.
1096 #if defined(__cplusplus) || defined(c_plusplus)
1100 static size_t WriteStreamImage(const Image *image,const void *pixels,
1101 const size_t columns)
1120 stream_info=(StreamInfo *) image->client_data;
1121 switch (stream_info->storage_type)
1123 default: packet_size=sizeof(char); break;
1124 case CharPixel: packet_size=sizeof(char); break;
1125 case DoublePixel: packet_size=sizeof(double); break;
1126 case FloatPixel: packet_size=sizeof(float); break;
1127 case IntegerPixel: packet_size=sizeof(int); break;
1128 case LongPixel: packet_size=sizeof(ssize_t); break;
1129 case QuantumPixel: packet_size=sizeof(Quantum); break;
1130 case ShortPixel: packet_size=sizeof(unsigned short); break;
1132 cache_info=(CacheInfo *) image->cache;
1133 assert(cache_info->signature == MagickSignature);
1134 packet_size*=strlen(stream_info->map);
1135 length=packet_size*cache_info->columns*cache_info->rows;
1136 if (image != stream_info->image)
1142 Prepare stream for writing.
1144 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1145 stream_info->pixels,length,sizeof(*stream_info->pixels));
1146 if (stream_info->pixels == (unsigned char *) NULL)
1148 stream_info->image=image;
1149 write_info=CloneImageInfo(stream_info->image_info);
1150 (void) SetImageInfo(write_info,1,stream_info->exception);
1151 if (write_info->extract != (char *) NULL)
1152 (void) ParseAbsoluteGeometry(write_info->extract,
1153 &stream_info->extract_info);
1155 write_info=DestroyImageInfo(write_info);
1157 extract_info=stream_info->extract_info;
1158 if ((extract_info.width == 0) || (extract_info.height == 0))
1161 Write all pixels to stream.
1163 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1164 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1166 return(count == 0 ? 0 : columns);
1168 if ((stream_info->y < extract_info.y) ||
1169 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1175 Write a portion of the pixel row to the stream.
1177 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1178 length=packet_size*extract_info.width;
1179 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1182 return(count == 0 ? 0 : columns);
1185 #if defined(__cplusplus) || defined(c_plusplus)
1189 MagickExport Image *StreamImage(const ImageInfo *image_info,
1190 StreamInfo *stream_info,ExceptionInfo *exception)
1198 assert(image_info != (const ImageInfo *) NULL);
1199 assert(image_info->signature == MagickSignature);
1200 if (image_info->debug != MagickFalse)
1201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1202 image_info->filename);
1203 assert(stream_info != (StreamInfo *) NULL);
1204 assert(stream_info->signature == MagickSignature);
1205 assert(exception != (ExceptionInfo *) NULL);
1206 read_info=CloneImageInfo(image_info);
1207 stream_info->image_info=image_info;
1208 stream_info->exception=exception;
1209 read_info->client_data=(void *) stream_info;
1210 image=ReadStream(read_info,&WriteStreamImage,exception);
1211 read_info=DestroyImageInfo(read_info);
1212 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1213 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1214 image=DestroyImage(image);
1219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1223 + S t r e a m I m a g e P i x e l s %
1227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1229 % StreamImagePixels() extracts pixel data from an image and returns it in the
1230 % stream_info->pixels structure in the format as defined by
1231 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1233 % The format of the StreamImagePixels method is:
1235 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1236 % const Image *image,ExceptionInfo *exception)
1238 % A description of each parameter follows:
1240 % o stream_info: the stream info.
1242 % o image: the image.
1244 % o exception: return any errors or warnings in this structure.
1247 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1248 const Image *image,ExceptionInfo *exception)
1256 register const Quantum
1266 assert(stream_info != (StreamInfo *) NULL);
1267 assert(stream_info->signature == MagickSignature);
1268 assert(image != (Image *) NULL);
1269 assert(image->signature == MagickSignature);
1270 if (image->debug != MagickFalse)
1271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1272 length=strlen(stream_info->map);
1273 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1274 if (quantum_map == (QuantumType *) NULL)
1276 (void) ThrowMagickException(exception,GetMagickModule(),
1277 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1278 return(MagickFalse);
1280 for (i=0; i < (ssize_t) length; i++)
1282 switch (stream_info->map[i])
1287 quantum_map[i]=AlphaQuantum;
1293 quantum_map[i]=BlueQuantum;
1299 quantum_map[i]=CyanQuantum;
1300 if (image->colorspace == CMYKColorspace)
1302 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1303 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1304 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1305 return(MagickFalse);
1310 quantum_map[i]=GreenQuantum;
1316 quantum_map[i]=IndexQuantum;
1322 quantum_map[i]=BlackQuantum;
1323 if (image->colorspace == CMYKColorspace)
1325 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1326 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1327 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1328 return(MagickFalse);
1333 quantum_map[i]=MagentaQuantum;
1334 if (image->colorspace == CMYKColorspace)
1336 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1337 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1338 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1339 return(MagickFalse);
1344 quantum_map[i]=OpacityQuantum;
1350 quantum_map[i]=UndefinedQuantum;
1356 quantum_map[i]=RedQuantum;
1362 quantum_map[i]=YellowQuantum;
1363 if (image->colorspace == CMYKColorspace)
1365 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1366 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1367 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1368 return(MagickFalse);
1372 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1373 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1374 "UnrecognizedPixelMap","`%s'",stream_info->map);
1375 return(MagickFalse);
1379 quantum_info=stream_info->quantum_info;
1380 switch (stream_info->storage_type)
1384 register unsigned char
1387 q=(unsigned char *) stream_info->pixels;
1388 if (LocaleCompare(stream_info->map,"BGR") == 0)
1390 p=GetAuthenticPixelQueue(image);
1391 if (p == (const Quantum *) NULL)
1393 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1395 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1396 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1397 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1402 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1404 p=GetAuthenticPixelQueue(image);
1405 if (p == (const Quantum *) NULL)
1407 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1409 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1410 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1411 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1412 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1417 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1419 p=GetAuthenticPixelQueue(image);
1420 if (p == (const Quantum *) NULL)
1422 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1424 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1425 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1426 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1427 *q++=ScaleQuantumToChar((Quantum) 0);
1432 if (LocaleCompare(stream_info->map,"I") == 0)
1434 p=GetAuthenticPixelQueue(image);
1435 if (p == (const Quantum *) NULL)
1437 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1439 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
1444 if (LocaleCompare(stream_info->map,"RGB") == 0)
1446 p=GetAuthenticPixelQueue(image);
1447 if (p == (const Quantum *) NULL)
1449 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1451 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1452 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1453 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1458 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1460 p=GetAuthenticPixelQueue(image);
1461 if (p == (const Quantum *) NULL)
1463 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1465 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1466 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1467 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1468 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1473 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1475 p=GetAuthenticPixelQueue(image);
1476 if (p == (const Quantum *) NULL)
1478 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1480 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1481 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1482 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1483 *q++=ScaleQuantumToChar((Quantum) 0);
1488 p=GetAuthenticPixelQueue(image);
1489 if (p == (const Quantum *) NULL)
1491 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1493 for (i=0; i < (ssize_t) length; i++)
1496 switch (quantum_map[i])
1501 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1505 case MagentaQuantum:
1507 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1513 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1518 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1521 case OpacityQuantum:
1523 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1528 if (image->colorspace == CMYKColorspace)
1529 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1534 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
1551 q=(double *) stream_info->pixels;
1552 if (LocaleCompare(stream_info->map,"BGR") == 0)
1554 p=GetAuthenticPixelQueue(image);
1555 if (p == (const Quantum *) NULL)
1557 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1559 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1560 quantum_info->scale+quantum_info->minimum);
1561 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1562 quantum_info->scale+quantum_info->minimum);
1563 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1564 quantum_info->scale+quantum_info->minimum);
1569 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1571 p=GetAuthenticPixelQueue(image);
1572 if (p == (const Quantum *) NULL)
1574 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1576 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1577 quantum_info->scale+quantum_info->minimum);
1578 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1579 quantum_info->scale+quantum_info->minimum);
1580 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1581 quantum_info->scale+quantum_info->minimum);
1582 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1583 quantum_info->scale+quantum_info->minimum);
1588 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1590 p=GetAuthenticPixelQueue(image);
1591 if (p == (const Quantum *) NULL)
1593 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1595 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1596 quantum_info->scale+quantum_info->minimum);
1597 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1598 quantum_info->scale+quantum_info->minimum);
1599 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1600 quantum_info->scale+quantum_info->minimum);
1606 if (LocaleCompare(stream_info->map,"I") == 0)
1608 p=GetAuthenticPixelQueue(image);
1609 if (p == (const Quantum *) NULL)
1611 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1613 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1614 quantum_info->scale+quantum_info->minimum);
1619 if (LocaleCompare(stream_info->map,"RGB") == 0)
1621 p=GetAuthenticPixelQueue(image);
1622 if (p == (const Quantum *) NULL)
1624 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1626 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1627 quantum_info->scale+quantum_info->minimum);
1628 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1629 quantum_info->scale+quantum_info->minimum);
1630 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1631 quantum_info->scale+quantum_info->minimum);
1636 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1638 p=GetAuthenticPixelQueue(image);
1639 if (p == (const Quantum *) NULL)
1641 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1643 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1644 quantum_info->scale+quantum_info->minimum);
1645 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1646 quantum_info->scale+quantum_info->minimum);
1647 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1649 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1650 quantum_info->scale+quantum_info->minimum);
1655 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1657 p=GetAuthenticPixelQueue(image);
1658 if (p == (const Quantum *) NULL)
1660 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1662 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1663 quantum_info->scale+quantum_info->minimum);
1664 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1665 quantum_info->scale+quantum_info->minimum);
1666 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1667 quantum_info->scale+quantum_info->minimum);
1673 p=GetAuthenticPixelQueue(image);
1674 if (p == (const Quantum *) NULL)
1676 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1678 for (i=0; i < (ssize_t) length; i++)
1681 switch (quantum_map[i])
1686 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1687 quantum_info->scale+quantum_info->minimum);
1691 case MagentaQuantum:
1693 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1694 quantum_info->scale+quantum_info->minimum);
1700 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1701 quantum_info->scale+quantum_info->minimum);
1706 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1707 quantum_info->scale+quantum_info->minimum);
1710 case OpacityQuantum:
1712 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1713 quantum_info->scale+quantum_info->minimum);
1718 if (image->colorspace == CMYKColorspace)
1719 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1720 quantum_info->scale+quantum_info->minimum);
1725 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1726 quantum_info->scale+quantum_info->minimum);
1743 q=(float *) stream_info->pixels;
1744 if (LocaleCompare(stream_info->map,"BGR") == 0)
1746 p=GetAuthenticPixelQueue(image);
1747 if (p == (const Quantum *) NULL)
1749 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1751 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1752 quantum_info->scale+quantum_info->minimum);
1753 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1754 quantum_info->scale+quantum_info->minimum);
1755 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1756 quantum_info->scale+quantum_info->minimum);
1761 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1763 p=GetAuthenticPixelQueue(image);
1764 if (p == (const Quantum *) NULL)
1766 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1768 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1769 quantum_info->scale+quantum_info->minimum);
1770 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1771 quantum_info->scale+quantum_info->minimum);
1772 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1773 quantum_info->scale+quantum_info->minimum);
1774 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1775 quantum_info->scale+quantum_info->minimum);
1780 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1782 p=GetAuthenticPixelQueue(image);
1783 if (p == (const Quantum *) NULL)
1785 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1787 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1788 quantum_info->scale+quantum_info->minimum);
1789 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1790 quantum_info->scale+quantum_info->minimum);
1791 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1792 quantum_info->scale+quantum_info->minimum);
1798 if (LocaleCompare(stream_info->map,"I") == 0)
1800 p=GetAuthenticPixelQueue(image);
1801 if (p == (const Quantum *) NULL)
1803 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1805 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1806 quantum_info->scale+quantum_info->minimum);
1811 if (LocaleCompare(stream_info->map,"RGB") == 0)
1813 p=GetAuthenticPixelQueue(image);
1814 if (p == (const Quantum *) NULL)
1816 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1818 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1819 quantum_info->scale+quantum_info->minimum);
1820 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1821 quantum_info->scale+quantum_info->minimum);
1822 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1823 quantum_info->scale+quantum_info->minimum);
1828 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1830 p=GetAuthenticPixelQueue(image);
1831 if (p == (const Quantum *) NULL)
1833 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1835 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1836 quantum_info->scale+quantum_info->minimum);
1837 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1838 quantum_info->scale+quantum_info->minimum);
1839 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1841 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1842 quantum_info->scale+quantum_info->minimum);
1847 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1849 p=GetAuthenticPixelQueue(image);
1850 if (p == (const Quantum *) NULL)
1852 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1854 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1855 quantum_info->scale+quantum_info->minimum);
1856 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1857 quantum_info->scale+quantum_info->minimum);
1858 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1859 quantum_info->scale+quantum_info->minimum);
1865 p=GetAuthenticPixelQueue(image);
1866 if (p == (const Quantum *) NULL)
1868 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1870 for (i=0; i < (ssize_t) length; i++)
1873 switch (quantum_map[i])
1878 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1879 quantum_info->scale+quantum_info->minimum);
1883 case MagentaQuantum:
1885 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1886 quantum_info->scale+quantum_info->minimum);
1892 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1893 quantum_info->scale+quantum_info->minimum);
1898 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1899 quantum_info->scale+quantum_info->minimum);
1902 case OpacityQuantum:
1904 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1905 quantum_info->scale+quantum_info->minimum);
1910 if (image->colorspace == CMYKColorspace)
1911 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1912 quantum_info->scale+quantum_info->minimum);
1917 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1918 quantum_info->scale+quantum_info->minimum);
1932 register unsigned int
1935 q=(unsigned int *) stream_info->pixels;
1936 if (LocaleCompare(stream_info->map,"BGR") == 0)
1938 p=GetAuthenticPixelQueue(image);
1939 if (p == (const Quantum *) NULL)
1941 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1943 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1944 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1945 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1950 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1952 p=GetAuthenticPixelQueue(image);
1953 if (p == (const Quantum *) NULL)
1955 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1957 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1958 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1959 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1960 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1965 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1967 p=GetAuthenticPixelQueue(image);
1968 if (p == (const Quantum *) NULL)
1970 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1972 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1973 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1974 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1980 if (LocaleCompare(stream_info->map,"I") == 0)
1982 p=GetAuthenticPixelQueue(image);
1983 if (p == (const Quantum *) NULL)
1985 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1987 *q++=(unsigned int) ScaleQuantumToLong(
1988 GetPixelIntensity(image,p));
1993 if (LocaleCompare(stream_info->map,"RGB") == 0)
1995 p=GetAuthenticPixelQueue(image);
1996 if (p == (const Quantum *) NULL)
1998 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2000 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2001 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2002 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2007 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2009 p=GetAuthenticPixelQueue(image);
2010 if (p == (const Quantum *) NULL)
2012 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2014 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2015 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2016 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2017 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2018 (GetPixelAlpha(image,p)));
2023 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2025 p=GetAuthenticPixelQueue(image);
2026 if (p == (const Quantum *) NULL)
2028 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2030 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2031 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2032 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2038 p=GetAuthenticPixelQueue(image);
2039 if (p == (const Quantum *) NULL)
2041 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2043 for (i=0; i < (ssize_t) length; i++)
2046 switch (quantum_map[i])
2051 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2055 case MagentaQuantum:
2057 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2063 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2068 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
2071 case OpacityQuantum:
2073 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
2078 if (image->colorspace == CMYKColorspace)
2079 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
2085 ScaleQuantumToLong(GetPixelIntensity(image,p));
2102 q=(size_t *) stream_info->pixels;
2103 if (LocaleCompare(stream_info->map,"BGR") == 0)
2105 p=GetAuthenticPixelQueue(image);
2106 if (p == (const Quantum *) NULL)
2108 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2110 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2111 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2112 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2117 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2119 p=GetAuthenticPixelQueue(image);
2120 if (p == (const Quantum *) NULL)
2122 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2124 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2125 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2126 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2127 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2132 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2134 p=GetAuthenticPixelQueue(image);
2135 if (p == (const Quantum *) NULL)
2137 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2139 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2140 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2141 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2147 if (LocaleCompare(stream_info->map,"I") == 0)
2149 p=GetAuthenticPixelQueue(image);
2150 if (p == (const Quantum *) NULL)
2152 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2154 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
2159 if (LocaleCompare(stream_info->map,"RGB") == 0)
2161 p=GetAuthenticPixelQueue(image);
2162 if (p == (const Quantum *) NULL)
2164 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2166 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2167 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2168 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2173 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2175 p=GetAuthenticPixelQueue(image);
2176 if (p == (const Quantum *) NULL)
2178 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2180 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2181 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2182 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2183 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2188 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2190 p=GetAuthenticPixelQueue(image);
2191 if (p == (const Quantum *) NULL)
2193 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2195 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2196 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2197 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2203 p=GetAuthenticPixelQueue(image);
2204 if (p == (const Quantum *) NULL)
2206 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2208 for (i=0; i < (ssize_t) length; i++)
2211 switch (quantum_map[i])
2216 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2220 case MagentaQuantum:
2222 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2228 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2233 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2236 case OpacityQuantum:
2238 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2243 if (image->colorspace == CMYKColorspace)
2244 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2249 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
2266 q=(Quantum *) stream_info->pixels;
2267 if (LocaleCompare(stream_info->map,"BGR") == 0)
2269 p=GetAuthenticPixelQueue(image);
2270 if (p == (const Quantum *) NULL)
2272 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2274 *q++=GetPixelBlue(image,p);
2275 *q++=GetPixelGreen(image,p);
2276 *q++=GetPixelRed(image,p);
2281 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2283 p=GetAuthenticPixelQueue(image);
2284 if (p == (const Quantum *) NULL)
2286 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2288 *q++=GetPixelBlue(image,p);
2289 *q++=GetPixelGreen(image,p);
2290 *q++=GetPixelRed(image,p);
2291 *q++=(Quantum) (GetPixelAlpha(image,p));
2296 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2298 p=GetAuthenticPixelQueue(image);
2299 if (p == (const Quantum *) NULL)
2301 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2303 *q++=GetPixelBlue(image,p);
2304 *q++=GetPixelGreen(image,p);
2305 *q++=GetPixelRed(image,p);
2311 if (LocaleCompare(stream_info->map,"I") == 0)
2313 p=GetAuthenticPixelQueue(image);
2314 if (p == (const Quantum *) NULL)
2316 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2318 *q++=GetPixelIntensity(image,p);
2323 if (LocaleCompare(stream_info->map,"RGB") == 0)
2325 p=GetAuthenticPixelQueue(image);
2326 if (p == (const Quantum *) NULL)
2328 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2330 *q++=GetPixelRed(image,p);
2331 *q++=GetPixelGreen(image,p);
2332 *q++=GetPixelBlue(image,p);
2337 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2339 p=GetAuthenticPixelQueue(image);
2340 if (p == (const Quantum *) NULL)
2342 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2344 *q++=GetPixelRed(image,p);
2345 *q++=GetPixelGreen(image,p);
2346 *q++=GetPixelBlue(image,p);
2347 *q++=(Quantum) (GetPixelAlpha(image,p));
2352 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2354 p=GetAuthenticPixelQueue(image);
2355 if (p == (const Quantum *) NULL)
2357 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2359 *q++=GetPixelRed(image,p);
2360 *q++=GetPixelGreen(image,p);
2361 *q++=GetPixelBlue(image,p);
2367 p=GetAuthenticPixelQueue(image);
2368 if (p == (const Quantum *) NULL)
2370 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2372 for (i=0; i < (ssize_t) length; i++)
2375 switch (quantum_map[i])
2380 *q=GetPixelRed(image,p);
2384 case MagentaQuantum:
2386 *q=GetPixelGreen(image,p);
2392 *q=GetPixelBlue(image,p);
2397 *q=(Quantum) (GetPixelAlpha(image,p));
2400 case OpacityQuantum:
2402 *q=GetPixelAlpha(image,p);
2407 if (image->colorspace == CMYKColorspace)
2408 *q=GetPixelBlack(image,p);
2413 *q=(GetPixelIntensity(image,p));
2427 register unsigned short
2430 q=(unsigned short *) stream_info->pixels;
2431 if (LocaleCompare(stream_info->map,"BGR") == 0)
2433 p=GetAuthenticPixelQueue(image);
2434 if (p == (const Quantum *) NULL)
2436 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2438 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2439 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2440 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2445 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2447 p=GetAuthenticPixelQueue(image);
2448 if (p == (const Quantum *) NULL)
2450 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2452 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2453 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2454 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2455 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2460 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2462 p=GetAuthenticPixelQueue(image);
2463 if (p == (const Quantum *) NULL)
2465 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2467 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2468 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2469 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2475 if (LocaleCompare(stream_info->map,"I") == 0)
2477 p=GetAuthenticPixelQueue(image);
2478 if (p == (const Quantum *) NULL)
2480 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2482 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
2487 if (LocaleCompare(stream_info->map,"RGB") == 0)
2489 p=GetAuthenticPixelQueue(image);
2490 if (p == (const Quantum *) NULL)
2492 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2494 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2495 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2496 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2501 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2503 p=GetAuthenticPixelQueue(image);
2504 if (p == (const Quantum *) NULL)
2506 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2508 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2509 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2510 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2511 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2516 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2518 p=GetAuthenticPixelQueue(image);
2519 if (p == (const Quantum *) NULL)
2521 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2523 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2524 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2525 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2531 p=GetAuthenticPixelQueue(image);
2532 if (p == (const Quantum *) NULL)
2534 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2536 for (i=0; i < (ssize_t) length; i++)
2539 switch (quantum_map[i])
2544 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2548 case MagentaQuantum:
2550 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2556 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2561 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2564 case OpacityQuantum:
2566 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2571 if (image->colorspace == CMYKColorspace)
2572 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2577 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
2591 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2592 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2593 "UnrecognizedPixelMap","`%s'",stream_info->map);
2597 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2606 + 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 %
2610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2612 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2613 % the latest stream of pixels.
2615 % The format of the SyncAuthenticPixelsStream method is:
2617 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2618 % ExceptionInfo *exception)
2620 % A description of each parameter follows:
2622 % o image: the image.
2624 % o exception: return any errors or warnings in this structure.
2627 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2628 ExceptionInfo *exception)
2639 assert(image != (Image *) NULL);
2640 assert(image->signature == MagickSignature);
2641 if (image->debug != MagickFalse)
2642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2643 cache_info=(CacheInfo *) image->cache;
2644 assert(cache_info->signature == MagickSignature);
2645 stream_handler=GetBlobStreamHandler(image);
2646 if (stream_handler == (StreamHandler) NULL)
2648 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2649 "NoStreamHandlerIsDefined","`%s'",image->filename);
2650 return(MagickFalse);
2652 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2653 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2661 % W r i t e S t r e a m %
2665 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2667 % WriteStream() makes the image pixels available to a user supplied callback
2668 % method immediately upon writing pixel data with the WriteImage() method.
2670 % The format of the WriteStream() method is:
2672 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2673 % StreamHandler stream)
2675 % A description of each parameter follows:
2677 % o image_info: the image info.
2679 % o stream: A callback method.
2682 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2683 Image *image,StreamHandler stream)
2691 assert(image_info != (ImageInfo *) NULL);
2692 assert(image_info->signature == MagickSignature);
2693 if (image_info->debug != MagickFalse)
2694 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2695 image_info->filename);
2696 assert(image != (Image *) NULL);
2697 assert(image->signature == MagickSignature);
2698 write_info=CloneImageInfo(image_info);
2699 write_info->stream=stream;
2700 status=WriteImage(write_info,image,&image->exception);
2701 write_info=DestroyImageInfo(write_info);