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-2013 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/memory-private.h"
56 #include "MagickCore/pixel.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/quantum.h"
59 #include "MagickCore/quantum-private.h"
60 #include "MagickCore/semaphore.h"
61 #include "MagickCore/stream.h"
62 #include "MagickCore/stream-private.h"
63 #include "MagickCore/string_.h"
66 Typedef declaractions.
108 Declare pixel cache interfaces.
110 #if defined(__cplusplus) || defined(c_plusplus)
115 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
116 const ssize_t,const size_t,const size_t,ExceptionInfo *);
118 static MagickBooleanType
119 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
120 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
123 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
124 const size_t,ExceptionInfo *);
126 #if defined(__cplusplus) || defined(c_plusplus)
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 + A c q u i r e S t r e a m I n f o %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % AcquireStreamInfo() allocates the StreamInfo structure.
143 % The format of the AcquireStreamInfo method is:
145 % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
146 % ExceptionInfo *exception)
148 % A description of each parameter follows:
150 % o image_info: the image info.
152 % o exception: return any errors or warnings in this structure.
155 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
156 ExceptionInfo *exception)
161 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
162 if (stream_info == (StreamInfo *) NULL)
163 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
165 stream_info->pixels=(unsigned char *) MagickAssumeAligned(
166 AcquireAlignedMemory(1,sizeof(*stream_info->pixels)));
167 if (stream_info->pixels == (unsigned char *) NULL)
168 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
169 stream_info->map=ConstantString("RGB");
170 stream_info->storage_type=CharPixel;
171 stream_info->stream=AcquireImage(image_info,exception);
172 stream_info->signature=MagickSignature;
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 + D e s t r o y P i x e l S t r e a m %
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 % DestroyPixelStream() deallocates memory associated with the pixel stream.
189 % The format of the DestroyPixelStream() method is:
191 % void DestroyPixelStream(Image *image)
193 % A description of each parameter follows:
195 % o image: the image.
199 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
201 assert(cache_info != (CacheInfo *) NULL);
202 if (cache_info->mapped == MagickFalse)
203 (void) RelinquishAlignedMemory(cache_info->pixels);
205 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
206 cache_info->pixels=(Quantum *) NULL;
207 cache_info->metacontent=(void *) NULL;
208 cache_info->length=0;
209 cache_info->mapped=MagickFalse;
212 static void DestroyPixelStream(Image *image)
220 assert(image != (Image *) NULL);
221 assert(image->signature == MagickSignature);
222 if (image->debug != MagickFalse)
223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
224 cache_info=(CacheInfo *) image->cache;
225 assert(cache_info->signature == MagickSignature);
227 LockSemaphoreInfo(cache_info->semaphore);
228 cache_info->reference_count--;
229 if (cache_info->reference_count == 0)
231 UnlockSemaphoreInfo(cache_info->semaphore);
232 if (destroy == MagickFalse)
234 RelinquishStreamPixels(cache_info);
235 if (cache_info->nexus_info != (NexusInfo **) NULL)
236 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
237 cache_info->number_threads);
238 if (cache_info->file_semaphore != (SemaphoreInfo *) NULL)
239 DestroySemaphoreInfo(&cache_info->file_semaphore);
240 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
241 DestroySemaphoreInfo(&cache_info->semaphore);
242 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 + D e s t r o y S t r e a m I n f o %
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 % DestroyStreamInfo() destroys memory associated with the StreamInfo
259 % The format of the DestroyStreamInfo method is:
261 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
263 % A description of each parameter follows:
265 % o stream_info: the stream info.
268 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
271 assert(stream_info != (StreamInfo *) NULL);
272 assert(stream_info->signature == MagickSignature);
273 if (stream_info->map != (char *) NULL)
274 stream_info->map=DestroyString(stream_info->map);
275 if (stream_info->pixels != (unsigned char *) NULL)
276 stream_info->pixels=(unsigned char *) RelinquishAlignedMemory(
277 stream_info->pixels);
278 if (stream_info->stream != (Image *) NULL)
280 (void) CloseBlob(stream_info->stream);
281 stream_info->stream=DestroyImage(stream_info->stream);
283 if (stream_info->quantum_info != (QuantumInfo *) NULL)
284 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
285 stream_info->signature=(~MagickSignature);
286 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 + 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 %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % GetAuthenticMetacontentFromStream() returns the metacontent corresponding
302 % with the last call to QueueAuthenticPixelsStream() or
303 % GetAuthenticPixelsStream().
305 % The format of the GetAuthenticMetacontentFromStream() method is:
307 % void *GetAuthenticMetacontentFromStream(const Image *image)
309 % A description of each parameter follows:
311 % o image: the image.
314 static void *GetAuthenticMetacontentFromStream(const Image *image)
319 assert(image != (Image *) NULL);
320 assert(image->signature == MagickSignature);
321 if (image->debug != MagickFalse)
322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
323 cache_info=(CacheInfo *) image->cache;
324 assert(cache_info->signature == MagickSignature);
325 return(cache_info->metacontent);
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 + G e t A u t h e n t i c P i x e l S t r e a m %
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
340 % cache as defined by the geometry parameters. A pointer to the pixels is
341 % returned if the pixels are transferred, otherwise a NULL is returned. For
342 % streams this method is a no-op.
344 % The format of the GetAuthenticPixelsStream() method is:
346 % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
347 % const ssize_t y,const size_t columns,const size_t rows,
348 % ExceptionInfo *exception)
350 % A description of each parameter follows:
352 % o image: the image.
354 % o x,y,columns,rows: These values define the perimeter of a region of
357 % o exception: return any errors or warnings in this structure.
360 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
361 const ssize_t y,const size_t columns,const size_t rows,
362 ExceptionInfo *exception)
367 assert(image != (Image *) NULL);
368 assert(image->signature == MagickSignature);
369 if (image->debug != MagickFalse)
370 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
371 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 + 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 %
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
387 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
389 % The format of the GetAuthenticPixelsFromStream() method is:
391 % Quantum *GetAuthenticPixelsFromStream(const Image image)
393 % A description of each parameter follows:
395 % o image: the image.
398 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
403 assert(image != (Image *) NULL);
404 assert(image->signature == MagickSignature);
405 if (image->debug != MagickFalse)
406 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
407 cache_info=(CacheInfo *) image->cache;
408 assert(cache_info->signature == MagickSignature);
409 return(cache_info->pixels);
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 + 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 %
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
424 % (x,y) location. The image background color is returned if an error occurs.
426 % The format of the GetOneAuthenticPixelFromStream() method is:
428 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
429 % const ssize_t x,const ssize_t y,Quantum *pixel,
430 % ExceptionInfo *exception)
432 % A description of each parameter follows:
434 % o image: the image.
436 % o pixel: return a pixel at the specified (x,y) location.
438 % o x,y: These values define the location of the pixel to return.
440 % o exception: return any errors or warnings in this structure.
443 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
444 const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
452 assert(image != (Image *) NULL);
453 assert(image->signature == MagickSignature);
454 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
455 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
456 if (q != (Quantum *) NULL)
458 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
459 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
460 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
461 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
462 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
465 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
470 channel=GetPixelChannelChannel(image,i);
477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
481 + 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 %
485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
487 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
488 % (x.y) location. The image background color is returned if an error occurs.
490 % The format of the GetOneVirtualPixelFromStream() method is:
492 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
493 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
494 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
496 % A description of each parameter follows:
498 % o image: the image.
500 % o virtual_pixel_method: the virtual pixel method.
502 % o x,y: These values define the location of the pixel to return.
504 % o pixel: return a pixel at the specified (x,y) location.
506 % o exception: return any errors or warnings in this structure.
509 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
510 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
511 Quantum *pixel,ExceptionInfo *exception)
519 assert(image != (Image *) NULL);
520 assert(image->signature == MagickSignature);
521 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
522 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
523 if (p == (const Quantum *) NULL)
525 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
526 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
527 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
528 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
529 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
532 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
537 channel=GetPixelChannelChannel(image,i);
544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 + G e t S t r e a m I n f o C l i e n t D a t a %
552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
554 % GetStreamInfoClientData() gets the stream info client data.
556 % The format of the GetStreamInfoClientData method is:
558 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
560 % A description of each parameter follows:
562 % o stream_info: the stream info.
565 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
567 assert(stream_info != (StreamInfo *) NULL);
568 assert(stream_info->signature == MagickSignature);
569 return(stream_info->client_data);
573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 + 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 %
581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 % GetVirtualPixelsStream() returns the pixels associated with the last
584 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
586 % The format of the GetVirtualPixelsStream() method is:
588 % const Quantum *GetVirtualPixelsStream(const Image *image)
590 % A description of each parameter follows:
592 % o pixels: return the pixels associated corresponding with the last call to
593 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
595 % o image: the image.
598 static const Quantum *GetVirtualPixelsStream(const Image *image)
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->pixels);
613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 + 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 %
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % GetVirtualMetacontentFromStream() returns the associated pixel channels
624 % corresponding with the last call to QueueAuthenticPixelsStream() or
625 % GetVirtualPixelStream().
627 % The format of the GetVirtualMetacontentFromStream() method is:
629 % const void *GetVirtualMetacontentFromStream(const Image *image)
631 % A description of each parameter follows:
633 % o image: the image.
636 static const void *GetVirtualMetacontentFromStream(const Image *image)
641 assert(image != (Image *) NULL);
642 assert(image->signature == MagickSignature);
643 if (image->debug != MagickFalse)
644 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
645 cache_info=(CacheInfo *) image->cache;
646 assert(cache_info->signature == MagickSignature);
647 return(cache_info->metacontent);
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 + G e t V i r t u a l P i x e l S t r e a m %
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
662 % defined by the geometry parameters. A pointer to the pixels is returned if
663 % the pixels are transferred, otherwise a NULL is returned. For streams this
666 % The format of the GetVirtualPixelStream() method is:
668 % const Quantum *GetVirtualPixelStream(const Image *image,
669 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
670 % const ssize_t y,const size_t columns,const size_t rows,
671 % ExceptionInfo *exception)
673 % A description of each parameter follows:
675 % o image: the image.
677 % o virtual_pixel_method: the virtual pixel method.
679 % o x,y,columns,rows: These values define the perimeter of a region of
682 % o exception: return any errors or warnings in this structure.
686 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
687 ExceptionInfo *exception)
689 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
691 cache_info->mapped=MagickFalse;
692 cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,(size_t)
694 if (cache_info->pixels == (Quantum *) NULL)
696 cache_info->mapped=MagickTrue;
697 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
700 if (cache_info->pixels == (Quantum *) NULL)
702 (void) ThrowMagickException(exception,GetMagickModule(),
703 ResourceLimitError,"MemoryAllocationFailed","'%s'",
704 cache_info->filename);
710 static const Quantum *GetVirtualPixelStream(const Image *image,
711 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
712 const ssize_t y,const size_t columns,const size_t rows,
713 ExceptionInfo *exception)
728 Validate pixel cache geometry.
730 assert(image != (const Image *) NULL);
731 assert(image->signature == MagickSignature);
732 if (image->debug != MagickFalse)
733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
734 if ((x < 0) || (y < 0) ||
735 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
736 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
737 (columns == 0) || (rows == 0))
739 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
740 "ImageDoesNotContainTheStreamGeometry","'%s'",image->filename);
741 return((Quantum *) NULL);
743 cache_info=(CacheInfo *) image->cache;
744 assert(cache_info->signature == MagickSignature);
746 Pixels are stored in a temporary buffer until they are synced to the cache.
748 number_pixels=(MagickSizeType) columns*rows;
749 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
750 if (cache_info->number_channels == 0)
751 length=number_pixels*sizeof(Quantum);
752 if (cache_info->metacontent_extent != 0)
753 length+=number_pixels*cache_info->metacontent_extent;
754 if (cache_info->pixels == (Quantum *) NULL)
756 cache_info->length=length;
757 status=AcquireStreamPixels(cache_info,exception);
758 if (status == MagickFalse)
760 cache_info->length=0;
761 return((Quantum *) NULL);
765 if (cache_info->length != length)
767 RelinquishStreamPixels(cache_info);
768 cache_info->length=length;
769 status=AcquireStreamPixels(cache_info,exception);
770 if (status == MagickFalse)
772 cache_info->length=0;
773 return((Quantum *) NULL);
776 cache_info->metacontent=(void *) NULL;
777 if (cache_info->metacontent_extent != 0)
778 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
779 cache_info->number_channels);
780 return(cache_info->pixels);
784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 + O p e n S t r e a m %
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 % OpenStream() opens a stream for writing by the StreamImage() method.
796 % The format of the OpenStream method is:
798 % MagickBooleanType OpenStream(const ImageInfo *image_info,
799 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
801 % A description of each parameter follows:
803 % o image_info: the image info.
805 % o stream_info: the stream info.
807 % o filename: the stream filename.
809 % o exception: return any errors or warnings in this structure.
812 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
813 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
818 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
819 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
828 + 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 %
832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
834 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
835 % defined by the region rectangle and returns a pointer to the area. This
836 % area is subsequently transferred from the pixel cache with method
837 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
838 % pixels are transferred, otherwise a NULL is returned.
840 % The format of the QueueAuthenticPixelsStream() method is:
842 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
843 % const ssize_t y,const size_t columns,const size_t rows,
844 % ExceptionInfo *exception)
846 % A description of each parameter follows:
848 % o image: the image.
850 % o x,y,columns,rows: These values define the perimeter of a region of
854 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
855 const ssize_t y,const size_t columns,const size_t rows,
856 ExceptionInfo *exception)
874 Validate pixel cache geometry.
876 assert(image != (Image *) NULL);
877 if ((x < 0) || (y < 0) ||
878 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
879 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
880 (columns == 0) || (rows == 0))
882 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
883 "ImageDoesNotContainTheStreamGeometry","'%s'",image->filename);
884 return((Quantum *) NULL);
886 stream_handler=GetBlobStreamHandler(image);
887 if (stream_handler == (StreamHandler) NULL)
889 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
890 "NoStreamHandlerIsDefined","'%s'",image->filename);
891 return((Quantum *) NULL);
893 cache_info=(CacheInfo *) image->cache;
894 assert(cache_info->signature == MagickSignature);
895 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
896 (image->colorspace != GetPixelCacheColorspace(image->cache)))
898 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
899 (void) stream_handler(image,(const void *) NULL,(size_t)
900 cache_info->columns);
901 cache_info->storage_class=image->storage_class;
902 cache_info->colorspace=image->colorspace;
903 cache_info->columns=image->columns;
904 cache_info->rows=image->rows;
905 image->cache=cache_info;
908 Pixels are stored in a temporary buffer until they are synced to the cache.
910 cache_info->columns=columns;
911 cache_info->rows=rows;
912 number_pixels=(MagickSizeType) columns*rows;
913 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
914 if (cache_info->number_channels == 0)
915 length=number_pixels*sizeof(Quantum);
916 if (cache_info->metacontent_extent != 0)
917 length+=number_pixels*cache_info->metacontent_extent;
918 if (cache_info->pixels == (Quantum *) NULL)
920 cache_info->length=length;
921 status=AcquireStreamPixels(cache_info,exception);
922 if (status == MagickFalse)
924 cache_info->length=0;
925 return((Quantum *) NULL);
929 if (cache_info->length < length)
931 RelinquishStreamPixels(cache_info);
932 cache_info->length=length;
933 status=AcquireStreamPixels(cache_info,exception);
934 if (status == MagickFalse)
936 cache_info->length=0;
937 return((Quantum *) NULL);
940 cache_info->metacontent=(void *) NULL;
941 if (cache_info->metacontent_extent != 0)
942 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
943 cache_info->number_channels);
944 return(cache_info->pixels);
948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
952 % R e a d S t r e a m %
956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958 % ReadStream() makes the image pixels available to a user supplied callback
959 % method immediately upon reading a scanline with the ReadImage() method.
961 % The format of the ReadStream() method is:
963 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
964 % ExceptionInfo *exception)
966 % A description of each parameter follows:
968 % o image_info: the image info.
970 % o stream: a callback method.
972 % o exception: return any errors or warnings in this structure.
975 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
976 ExceptionInfo *exception)
990 assert(image_info != (ImageInfo *) NULL);
991 assert(image_info->signature == MagickSignature);
992 if (image_info->debug != MagickFalse)
993 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
994 image_info->filename);
995 assert(exception != (ExceptionInfo *) NULL);
996 assert(exception->signature == MagickSignature);
997 read_info=CloneImageInfo(image_info);
998 read_info->cache=AcquirePixelCache(0);
999 GetPixelCacheMethods(&cache_methods);
1000 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
1001 cache_methods.get_virtual_metacontent_from_handler=
1002 GetVirtualMetacontentFromStream;
1003 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
1004 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
1005 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1006 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1007 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1008 cache_methods.get_authentic_metacontent_from_handler=
1009 GetAuthenticMetacontentFromStream;
1010 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1011 cache_methods.get_one_authentic_pixel_from_handler=
1012 GetOneAuthenticPixelFromStream;
1013 cache_methods.destroy_pixel_handler=DestroyPixelStream;
1014 SetPixelCacheMethods(read_info->cache,&cache_methods);
1015 read_info->stream=stream;
1016 image=ReadImage(read_info,exception);
1017 read_info=DestroyImageInfo(read_info);
1022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1026 + S e t S t r e a m I n f o C l i e n t D a t a %
1030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1032 % SetStreamInfoClientData() sets the stream info client data.
1034 % The format of the SetStreamInfoClientData method is:
1036 % void SetStreamInfoClientData(StreamInfo *stream_info,
1037 % const void *client_data)
1039 % A description of each parameter follows:
1041 % o stream_info: the stream info.
1043 % o client_data: the client data.
1046 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1047 const void *client_data)
1049 assert(stream_info != (StreamInfo *) NULL);
1050 assert(stream_info->signature == MagickSignature);
1051 stream_info->client_data=client_data;
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 + S e t S t r e a m I n f o M a p %
1063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1065 % SetStreamInfoMap() sets the stream info map member.
1067 % The format of the SetStreamInfoMap method is:
1069 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1071 % A description of each parameter follows:
1073 % o stream_info: the stream info.
1078 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1080 assert(stream_info != (StreamInfo *) NULL);
1081 assert(stream_info->signature == MagickSignature);
1082 (void) CloneString(&stream_info->map,map);
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090 + S e t S t r e a m I n f o S t o r a g e T y p e %
1094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096 % SetStreamInfoStorageType() sets the stream info storage type member.
1098 % The format of the SetStreamInfoStorageType method is:
1100 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1101 % const StoreageType *storage_type)
1103 % A description of each parameter follows:
1105 % o stream_info: the stream info.
1107 % o storage_type: the storage type.
1110 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1111 const StorageType storage_type)
1113 assert(stream_info != (StreamInfo *) NULL);
1114 assert(stream_info->signature == MagickSignature);
1115 stream_info->storage_type=storage_type;
1119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 + S t r e a m I m a g e %
1127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1129 % StreamImage() streams pixels from an image and writes them in a user
1130 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1132 % The format of the StreamImage() method is:
1134 % Image *StreamImage(const ImageInfo *image_info,
1135 % StreamInfo *stream_info,ExceptionInfo *exception)
1137 % A description of each parameter follows:
1139 % o image_info: the image info.
1141 % o stream_info: the stream info.
1143 % o exception: return any errors or warnings in this structure.
1147 #if defined(__cplusplus) || defined(c_plusplus)
1151 static size_t WriteStreamImage(const Image *image,const void *pixels,
1152 const size_t columns)
1171 stream_info=(StreamInfo *) image->client_data;
1172 switch (stream_info->storage_type)
1174 default: packet_size=sizeof(unsigned char); break;
1175 case CharPixel: packet_size=sizeof(unsigned char); break;
1176 case DoublePixel: packet_size=sizeof(double); break;
1177 case FloatPixel: packet_size=sizeof(float); break;
1178 case LongPixel: packet_size=sizeof(unsigned int); break;
1179 case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
1180 case QuantumPixel: packet_size=sizeof(Quantum); break;
1181 case ShortPixel: packet_size=sizeof(unsigned short); break;
1183 cache_info=(CacheInfo *) image->cache;
1184 assert(cache_info->signature == MagickSignature);
1185 packet_size*=strlen(stream_info->map);
1186 length=packet_size*cache_info->columns*cache_info->rows;
1187 if (image != stream_info->image)
1193 Prepare stream for writing.
1195 (void) RelinquishAlignedMemory(stream_info->pixels);
1196 stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
1197 if (stream_info->pixels == (unsigned char *) NULL)
1199 (void) ResetMagickMemory(stream_info->pixels,0,length);
1200 stream_info->image=image;
1201 write_info=CloneImageInfo(stream_info->image_info);
1202 (void) SetImageInfo(write_info,1,stream_info->exception);
1203 if (write_info->extract != (char *) NULL)
1204 (void) ParseAbsoluteGeometry(write_info->extract,
1205 &stream_info->extract_info);
1207 write_info=DestroyImageInfo(write_info);
1209 extract_info=stream_info->extract_info;
1210 if ((extract_info.width == 0) || (extract_info.height == 0))
1213 Write all pixels to stream.
1215 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1216 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1218 return(count == 0 ? 0 : columns);
1220 if ((stream_info->y < extract_info.y) ||
1221 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1227 Write a portion of the pixel row to the stream.
1229 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1230 length=packet_size*extract_info.width;
1231 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1234 return(count == 0 ? 0 : columns);
1237 #if defined(__cplusplus) || defined(c_plusplus)
1241 MagickExport Image *StreamImage(const ImageInfo *image_info,
1242 StreamInfo *stream_info,ExceptionInfo *exception)
1250 assert(image_info != (const ImageInfo *) NULL);
1251 assert(image_info->signature == MagickSignature);
1252 if (image_info->debug != MagickFalse)
1253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1254 image_info->filename);
1255 assert(stream_info != (StreamInfo *) NULL);
1256 assert(stream_info->signature == MagickSignature);
1257 assert(exception != (ExceptionInfo *) NULL);
1258 read_info=CloneImageInfo(image_info);
1259 stream_info->image_info=image_info;
1260 stream_info->exception=exception;
1261 read_info->client_data=(void *) stream_info;
1262 image=ReadStream(read_info,&WriteStreamImage,exception);
1263 read_info=DestroyImageInfo(read_info);
1264 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1265 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1266 image=DestroyImage(image);
1271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1275 + S t r e a m I m a g e P i x e l s %
1279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1281 % StreamImagePixels() extracts pixel data from an image and returns it in the
1282 % stream_info->pixels structure in the format as defined by
1283 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1285 % The format of the StreamImagePixels method is:
1287 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1288 % const Image *image,ExceptionInfo *exception)
1290 % A description of each parameter follows:
1292 % o stream_info: the stream info.
1294 % o image: the image.
1296 % o exception: return any errors or warnings in this structure.
1299 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1300 const Image *image,ExceptionInfo *exception)
1308 register const Quantum
1318 assert(stream_info != (StreamInfo *) NULL);
1319 assert(stream_info->signature == MagickSignature);
1320 assert(image != (Image *) NULL);
1321 assert(image->signature == MagickSignature);
1322 if (image->debug != MagickFalse)
1323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1324 length=strlen(stream_info->map);
1325 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1326 if (quantum_map == (QuantumType *) NULL)
1328 (void) ThrowMagickException(exception,GetMagickModule(),
1329 ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename);
1330 return(MagickFalse);
1332 for (i=0; i < (ssize_t) length; i++)
1334 switch (stream_info->map[i])
1339 quantum_map[i]=AlphaQuantum;
1345 quantum_map[i]=BlueQuantum;
1351 quantum_map[i]=CyanQuantum;
1352 if (image->colorspace == CMYKColorspace)
1354 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1355 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1356 "ColorSeparatedImageRequired","'%s'",stream_info->map);
1357 return(MagickFalse);
1362 quantum_map[i]=GreenQuantum;
1368 quantum_map[i]=IndexQuantum;
1374 quantum_map[i]=BlackQuantum;
1375 if (image->colorspace == CMYKColorspace)
1377 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1378 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1379 "ColorSeparatedImageRequired","'%s'",stream_info->map);
1380 return(MagickFalse);
1385 quantum_map[i]=MagentaQuantum;
1386 if (image->colorspace == CMYKColorspace)
1388 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1389 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1390 "ColorSeparatedImageRequired","'%s'",stream_info->map);
1391 return(MagickFalse);
1396 quantum_map[i]=OpacityQuantum;
1402 quantum_map[i]=UndefinedQuantum;
1408 quantum_map[i]=RedQuantum;
1414 quantum_map[i]=YellowQuantum;
1415 if (image->colorspace == CMYKColorspace)
1417 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1418 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1419 "ColorSeparatedImageRequired","'%s'",stream_info->map);
1420 return(MagickFalse);
1424 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1425 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1426 "UnrecognizedPixelMap","'%s'",stream_info->map);
1427 return(MagickFalse);
1431 quantum_info=stream_info->quantum_info;
1432 switch (stream_info->storage_type)
1436 register unsigned char
1439 q=(unsigned char *) stream_info->pixels;
1440 if (LocaleCompare(stream_info->map,"BGR") == 0)
1442 p=GetAuthenticPixelQueue(image);
1443 if (p == (const Quantum *) NULL)
1445 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1447 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1448 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1449 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1454 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1456 p=GetAuthenticPixelQueue(image);
1457 if (p == (const Quantum *) NULL)
1459 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1461 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1462 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1463 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1464 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1469 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1471 p=GetAuthenticPixelQueue(image);
1472 if (p == (const Quantum *) NULL)
1474 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1476 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1477 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1478 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1479 *q++=ScaleQuantumToChar((Quantum) 0);
1484 if (LocaleCompare(stream_info->map,"I") == 0)
1486 p=GetAuthenticPixelQueue(image);
1487 if (p == (const Quantum *) NULL)
1489 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1491 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1496 if (LocaleCompare(stream_info->map,"RGB") == 0)
1498 p=GetAuthenticPixelQueue(image);
1499 if (p == (const Quantum *) NULL)
1501 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1503 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1504 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1505 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1510 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1512 p=GetAuthenticPixelQueue(image);
1513 if (p == (const Quantum *) NULL)
1515 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1517 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1518 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1519 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1520 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1525 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1527 p=GetAuthenticPixelQueue(image);
1528 if (p == (const Quantum *) NULL)
1530 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1532 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1533 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1534 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1535 *q++=ScaleQuantumToChar((Quantum) 0);
1540 p=GetAuthenticPixelQueue(image);
1541 if (p == (const Quantum *) NULL)
1543 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1545 for (i=0; i < (ssize_t) length; i++)
1548 switch (quantum_map[i])
1553 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1557 case MagentaQuantum:
1559 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1565 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1570 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1573 case OpacityQuantum:
1575 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1580 if (image->colorspace == CMYKColorspace)
1581 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1586 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1603 q=(double *) stream_info->pixels;
1604 if (LocaleCompare(stream_info->map,"BGR") == 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*GetPixelBlue(image,p))*
1612 quantum_info->scale+quantum_info->minimum);
1613 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1614 quantum_info->scale+quantum_info->minimum);
1615 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1616 quantum_info->scale+quantum_info->minimum);
1621 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1623 p=GetAuthenticPixelQueue(image);
1624 if (p == (const Quantum *) NULL)
1626 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1628 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1629 quantum_info->scale+quantum_info->minimum);
1630 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1631 quantum_info->scale+quantum_info->minimum);
1632 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1633 quantum_info->scale+quantum_info->minimum);
1634 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1635 quantum_info->scale+quantum_info->minimum);
1640 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1642 p=GetAuthenticPixelQueue(image);
1643 if (p == (const Quantum *) NULL)
1645 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1647 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1649 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1650 quantum_info->scale+quantum_info->minimum);
1651 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1652 quantum_info->scale+quantum_info->minimum);
1658 if (LocaleCompare(stream_info->map,"I") == 0)
1660 p=GetAuthenticPixelQueue(image);
1661 if (p == (const Quantum *) NULL)
1663 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1665 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1666 quantum_info->scale+quantum_info->minimum);
1671 if (LocaleCompare(stream_info->map,"RGB") == 0)
1673 p=GetAuthenticPixelQueue(image);
1674 if (p == (const Quantum *) NULL)
1676 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1678 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1679 quantum_info->scale+quantum_info->minimum);
1680 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1681 quantum_info->scale+quantum_info->minimum);
1682 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1683 quantum_info->scale+quantum_info->minimum);
1688 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1690 p=GetAuthenticPixelQueue(image);
1691 if (p == (const Quantum *) NULL)
1693 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1695 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1696 quantum_info->scale+quantum_info->minimum);
1697 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1698 quantum_info->scale+quantum_info->minimum);
1699 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1700 quantum_info->scale+quantum_info->minimum);
1701 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1702 quantum_info->scale+quantum_info->minimum);
1707 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1709 p=GetAuthenticPixelQueue(image);
1710 if (p == (const Quantum *) NULL)
1712 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1714 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1715 quantum_info->scale+quantum_info->minimum);
1716 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1717 quantum_info->scale+quantum_info->minimum);
1718 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1719 quantum_info->scale+quantum_info->minimum);
1725 p=GetAuthenticPixelQueue(image);
1726 if (p == (const Quantum *) NULL)
1728 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1730 for (i=0; i < (ssize_t) length; i++)
1733 switch (quantum_map[i])
1738 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1739 quantum_info->scale+quantum_info->minimum);
1743 case MagentaQuantum:
1745 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1746 quantum_info->scale+quantum_info->minimum);
1752 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1753 quantum_info->scale+quantum_info->minimum);
1758 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1759 quantum_info->scale+quantum_info->minimum);
1762 case OpacityQuantum:
1764 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1765 quantum_info->scale+quantum_info->minimum);
1770 if (image->colorspace == CMYKColorspace)
1771 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1772 quantum_info->scale+quantum_info->minimum);
1777 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1778 quantum_info->scale+quantum_info->minimum);
1795 q=(float *) stream_info->pixels;
1796 if (LocaleCompare(stream_info->map,"BGR") == 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*GetPixelBlue(image,p))*
1804 quantum_info->scale+quantum_info->minimum);
1805 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1806 quantum_info->scale+quantum_info->minimum);
1807 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1808 quantum_info->scale+quantum_info->minimum);
1813 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1815 p=GetAuthenticPixelQueue(image);
1816 if (p == (const Quantum *) NULL)
1818 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1820 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1821 quantum_info->scale+quantum_info->minimum);
1822 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1823 quantum_info->scale+quantum_info->minimum);
1824 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1825 quantum_info->scale+quantum_info->minimum);
1826 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1827 quantum_info->scale+quantum_info->minimum);
1832 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1834 p=GetAuthenticPixelQueue(image);
1835 if (p == (const Quantum *) NULL)
1837 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1839 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1841 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1842 quantum_info->scale+quantum_info->minimum);
1843 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1844 quantum_info->scale+quantum_info->minimum);
1850 if (LocaleCompare(stream_info->map,"I") == 0)
1852 p=GetAuthenticPixelQueue(image);
1853 if (p == (const Quantum *) NULL)
1855 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1857 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1858 quantum_info->scale+quantum_info->minimum);
1863 if (LocaleCompare(stream_info->map,"RGB") == 0)
1865 p=GetAuthenticPixelQueue(image);
1866 if (p == (const Quantum *) NULL)
1868 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1870 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1871 quantum_info->scale+quantum_info->minimum);
1872 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1873 quantum_info->scale+quantum_info->minimum);
1874 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1875 quantum_info->scale+quantum_info->minimum);
1880 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1882 p=GetAuthenticPixelQueue(image);
1883 if (p == (const Quantum *) NULL)
1885 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1887 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1888 quantum_info->scale+quantum_info->minimum);
1889 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1890 quantum_info->scale+quantum_info->minimum);
1891 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1892 quantum_info->scale+quantum_info->minimum);
1893 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1894 quantum_info->scale+quantum_info->minimum);
1899 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1901 p=GetAuthenticPixelQueue(image);
1902 if (p == (const Quantum *) NULL)
1904 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1906 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1907 quantum_info->scale+quantum_info->minimum);
1908 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1909 quantum_info->scale+quantum_info->minimum);
1910 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1911 quantum_info->scale+quantum_info->minimum);
1917 p=GetAuthenticPixelQueue(image);
1918 if (p == (const Quantum *) NULL)
1920 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1922 for (i=0; i < (ssize_t) length; i++)
1925 switch (quantum_map[i])
1930 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1931 quantum_info->scale+quantum_info->minimum);
1935 case MagentaQuantum:
1937 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1938 quantum_info->scale+quantum_info->minimum);
1944 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1945 quantum_info->scale+quantum_info->minimum);
1950 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1951 quantum_info->scale+quantum_info->minimum);
1954 case OpacityQuantum:
1956 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1957 quantum_info->scale+quantum_info->minimum);
1962 if (image->colorspace == CMYKColorspace)
1963 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1964 quantum_info->scale+quantum_info->minimum);
1969 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1970 quantum_info->scale+quantum_info->minimum);
1984 register unsigned int
1987 q=(unsigned int *) stream_info->pixels;
1988 if (LocaleCompare(stream_info->map,"BGR") == 0)
1990 p=GetAuthenticPixelQueue(image);
1991 if (p == (const Quantum *) NULL)
1993 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1995 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1996 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1997 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2002 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2004 p=GetAuthenticPixelQueue(image);
2005 if (p == (const Quantum *) NULL)
2007 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2009 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2010 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2011 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2012 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2017 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2019 p=GetAuthenticPixelQueue(image);
2020 if (p == (const Quantum *) NULL)
2022 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2024 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2025 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2026 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2032 if (LocaleCompare(stream_info->map,"I") == 0)
2034 p=GetAuthenticPixelQueue(image);
2035 if (p == (const Quantum *) NULL)
2037 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2039 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2044 if (LocaleCompare(stream_info->map,"RGB") == 0)
2046 p=GetAuthenticPixelQueue(image);
2047 if (p == (const Quantum *) NULL)
2049 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2051 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2052 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2053 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2058 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2060 p=GetAuthenticPixelQueue(image);
2061 if (p == (const Quantum *) NULL)
2063 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2065 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2066 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2067 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2068 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2073 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2075 p=GetAuthenticPixelQueue(image);
2076 if (p == (const Quantum *) NULL)
2078 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2080 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2081 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2082 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2088 p=GetAuthenticPixelQueue(image);
2089 if (p == (const Quantum *) NULL)
2091 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2093 for (i=0; i < (ssize_t) length; i++)
2096 switch (quantum_map[i])
2101 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2105 case MagentaQuantum:
2107 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2113 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2118 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2121 case OpacityQuantum:
2123 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2128 if (image->colorspace == CMYKColorspace)
2129 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2134 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2148 register MagickSizeType
2151 q=(MagickSizeType *) stream_info->pixels;
2152 if (LocaleCompare(stream_info->map,"BGR") == 0)
2154 p=GetAuthenticPixelQueue(image);
2155 if (p == (const Quantum *) NULL)
2157 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2159 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2160 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2161 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2166 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2168 p=GetAuthenticPixelQueue(image);
2169 if (p == (const Quantum *) NULL)
2171 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2173 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2174 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2175 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2176 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2181 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2183 p=GetAuthenticPixelQueue(image);
2184 if (p == (const Quantum *) NULL)
2186 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2188 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2189 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2190 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2196 if (LocaleCompare(stream_info->map,"I") == 0)
2198 p=GetAuthenticPixelQueue(image);
2199 if (p == (const Quantum *) NULL)
2201 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2203 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2204 GetPixelIntensity(image,p)));
2209 if (LocaleCompare(stream_info->map,"RGB") == 0)
2211 p=GetAuthenticPixelQueue(image);
2212 if (p == (const Quantum *) NULL)
2214 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2216 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2217 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2218 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2223 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2225 p=GetAuthenticPixelQueue(image);
2226 if (p == (const Quantum *) NULL)
2228 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2230 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2231 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2232 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2233 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2238 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2240 p=GetAuthenticPixelQueue(image);
2241 if (p == (const Quantum *) NULL)
2243 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2245 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2246 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2247 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2253 p=GetAuthenticPixelQueue(image);
2254 if (p == (const Quantum *) NULL)
2256 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2258 for (i=0; i < (ssize_t) length; i++)
2261 switch (quantum_map[i])
2266 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2270 case MagentaQuantum:
2272 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2278 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2283 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2286 case OpacityQuantum:
2288 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2293 if (image->colorspace == CMYKColorspace)
2294 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2299 *q=ScaleQuantumToLongLong(ClampToQuantum(
2300 GetPixelIntensity(image,p)));
2317 q=(Quantum *) stream_info->pixels;
2318 if (LocaleCompare(stream_info->map,"BGR") == 0)
2320 p=GetAuthenticPixelQueue(image);
2321 if (p == (const Quantum *) NULL)
2323 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2325 *q++=GetPixelBlue(image,p);
2326 *q++=GetPixelGreen(image,p);
2327 *q++=GetPixelRed(image,p);
2332 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2334 p=GetAuthenticPixelQueue(image);
2335 if (p == (const Quantum *) NULL)
2337 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2339 *q++=GetPixelBlue(image,p);
2340 *q++=GetPixelGreen(image,p);
2341 *q++=GetPixelRed(image,p);
2342 *q++=GetPixelAlpha(image,p);
2347 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2349 p=GetAuthenticPixelQueue(image);
2350 if (p == (const Quantum *) NULL)
2352 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2354 *q++=GetPixelBlue(image,p);
2355 *q++=GetPixelGreen(image,p);
2356 *q++=GetPixelRed(image,p);
2362 if (LocaleCompare(stream_info->map,"I") == 0)
2364 p=GetAuthenticPixelQueue(image);
2365 if (p == (const Quantum *) NULL)
2367 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2369 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2374 if (LocaleCompare(stream_info->map,"RGB") == 0)
2376 p=GetAuthenticPixelQueue(image);
2377 if (p == (const Quantum *) NULL)
2379 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2381 *q++=GetPixelRed(image,p);
2382 *q++=GetPixelGreen(image,p);
2383 *q++=GetPixelBlue(image,p);
2388 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2390 p=GetAuthenticPixelQueue(image);
2391 if (p == (const Quantum *) NULL)
2393 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2395 *q++=GetPixelRed(image,p);
2396 *q++=GetPixelGreen(image,p);
2397 *q++=GetPixelBlue(image,p);
2398 *q++=GetPixelAlpha(image,p);
2403 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2405 p=GetAuthenticPixelQueue(image);
2406 if (p == (const Quantum *) NULL)
2408 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2410 *q++=GetPixelRed(image,p);
2411 *q++=GetPixelGreen(image,p);
2412 *q++=GetPixelBlue(image,p);
2418 p=GetAuthenticPixelQueue(image);
2419 if (p == (const Quantum *) NULL)
2421 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2423 for (i=0; i < (ssize_t) length; i++)
2426 switch (quantum_map[i])
2431 *q=GetPixelRed(image,p);
2435 case MagentaQuantum:
2437 *q=GetPixelGreen(image,p);
2443 *q=GetPixelBlue(image,p);
2448 *q=(Quantum) (GetPixelAlpha(image,p));
2451 case OpacityQuantum:
2453 *q=GetPixelAlpha(image,p);
2458 if (image->colorspace == CMYKColorspace)
2459 *q=GetPixelBlack(image,p);
2464 *q=ClampToQuantum(GetPixelIntensity(image,p));
2478 register unsigned short
2481 q=(unsigned short *) stream_info->pixels;
2482 if (LocaleCompare(stream_info->map,"BGR") == 0)
2484 p=GetAuthenticPixelQueue(image);
2485 if (p == (const Quantum *) NULL)
2487 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2489 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2490 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2491 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2496 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2498 p=GetAuthenticPixelQueue(image);
2499 if (p == (const Quantum *) NULL)
2501 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2503 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2504 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2505 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2506 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2511 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2513 p=GetAuthenticPixelQueue(image);
2514 if (p == (const Quantum *) NULL)
2516 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2518 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2519 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2520 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2526 if (LocaleCompare(stream_info->map,"I") == 0)
2528 p=GetAuthenticPixelQueue(image);
2529 if (p == (const Quantum *) NULL)
2531 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2533 *q++=ScaleQuantumToShort(ClampToQuantum(
2534 GetPixelIntensity(image,p)));
2539 if (LocaleCompare(stream_info->map,"RGB") == 0)
2541 p=GetAuthenticPixelQueue(image);
2542 if (p == (const Quantum *) NULL)
2544 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2546 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2547 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2548 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2553 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2555 p=GetAuthenticPixelQueue(image);
2556 if (p == (const Quantum *) NULL)
2558 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2560 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2561 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2562 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2563 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2568 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2570 p=GetAuthenticPixelQueue(image);
2571 if (p == (const Quantum *) NULL)
2573 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2575 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2576 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2577 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2583 p=GetAuthenticPixelQueue(image);
2584 if (p == (const Quantum *) NULL)
2586 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2588 for (i=0; i < (ssize_t) length; i++)
2591 switch (quantum_map[i])
2596 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2600 case MagentaQuantum:
2602 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2608 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2613 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2616 case OpacityQuantum:
2618 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2623 if (image->colorspace == CMYKColorspace)
2624 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2629 *q=ScaleQuantumToShort(ClampToQuantum(
2630 GetPixelIntensity(image,p)));
2644 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2645 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2646 "UnrecognizedPixelMap","'%s'",stream_info->map);
2650 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659 + 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 %
2663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2665 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2666 % the latest stream of pixels.
2668 % The format of the SyncAuthenticPixelsStream method is:
2670 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2671 % ExceptionInfo *exception)
2673 % A description of each parameter follows:
2675 % o image: the image.
2677 % o exception: return any errors or warnings in this structure.
2680 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2681 ExceptionInfo *exception)
2692 assert(image != (Image *) NULL);
2693 assert(image->signature == MagickSignature);
2694 if (image->debug != MagickFalse)
2695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2696 cache_info=(CacheInfo *) image->cache;
2697 assert(cache_info->signature == MagickSignature);
2698 stream_handler=GetBlobStreamHandler(image);
2699 if (stream_handler == (StreamHandler) NULL)
2701 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2702 "NoStreamHandlerIsDefined","'%s'",image->filename);
2703 return(MagickFalse);
2705 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2706 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2714 % W r i t e S t r e a m %
2718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2720 % WriteStream() makes the image pixels available to a user supplied callback
2721 % method immediately upon writing pixel data with the WriteImage() method.
2723 % The format of the WriteStream() method is:
2725 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2726 % StreamHandler stream,ExceptionInfo *exception)
2728 % A description of each parameter follows:
2730 % o image_info: the image info.
2732 % o stream: A callback method.
2734 % o exception: return any errors or warnings in this structure.
2737 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2738 Image *image,StreamHandler stream,ExceptionInfo *exception)
2746 assert(image_info != (ImageInfo *) NULL);
2747 assert(image_info->signature == MagickSignature);
2748 if (image_info->debug != MagickFalse)
2749 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2750 image_info->filename);
2751 assert(image != (Image *) NULL);
2752 assert(image->signature == MagickSignature);
2753 write_info=CloneImageInfo(image_info);
2754 write_info->stream=stream;
2755 status=WriteImage(write_info,image,exception);
2756 write_info=DestroyImageInfo(write_info);