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-2016 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=MagickCoreSignature;
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 == MagickCoreSignature);
222 if (image->debug != MagickFalse)
223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
224 cache_info=(CacheInfo *) image->cache;
225 assert(cache_info->signature == MagickCoreSignature);
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 RelinquishSemaphoreInfo(&cache_info->file_semaphore);
240 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
241 RelinquishSemaphoreInfo(&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 == MagickCoreSignature);
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=(~MagickCoreSignature);
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 == MagickCoreSignature);
321 if (image->debug != MagickFalse)
322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
323 cache_info=(CacheInfo *) image->cache;
324 assert(cache_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
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 == MagickCoreSignature);
405 if (image->debug != MagickFalse)
406 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
407 cache_info=(CacheInfo *) image->cache;
408 assert(cache_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
454 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
455 p=GetAuthenticPixelsStream(image,x,y,1,1,exception);
456 if (p == (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++)
467 PixelChannel channel=GetPixelChannelChannel(image,i);
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 + 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 %
482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
485 % (x.y) location. The image background color is returned if an error occurs.
487 % The format of the GetOneVirtualPixelFromStream() method is:
489 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
490 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
491 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
493 % A description of each parameter follows:
495 % o image: the image.
497 % o virtual_pixel_method: the virtual pixel method.
499 % o x,y: These values define the location of the pixel to return.
501 % o pixel: return a pixel at the specified (x,y) location.
503 % o exception: return any errors or warnings in this structure.
506 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
507 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
508 Quantum *pixel,ExceptionInfo *exception)
516 assert(image != (Image *) NULL);
517 assert(image->signature == MagickCoreSignature);
518 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
519 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
520 if (p == (const Quantum *) NULL)
522 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
523 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
524 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
525 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
526 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
529 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
531 PixelChannel channel=GetPixelChannelChannel(image,i);
538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 + G e t S t r e a m I n f o C l i e n t D a t a %
546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 % GetStreamInfoClientData() gets the stream info client data.
550 % The format of the GetStreamInfoClientData method is:
552 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
554 % A description of each parameter follows:
556 % o stream_info: the stream info.
559 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
561 assert(stream_info != (StreamInfo *) NULL);
562 assert(stream_info->signature == MagickCoreSignature);
563 return(stream_info->client_data);
567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571 + 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 %
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 % GetVirtualPixelsStream() returns the pixels associated with the last
578 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
580 % The format of the GetVirtualPixelsStream() method is:
582 % const Quantum *GetVirtualPixelsStream(const Image *image)
584 % A description of each parameter follows:
586 % o pixels: return the pixels associated corresponding with the last call to
587 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
589 % o image: the image.
592 static const Quantum *GetVirtualPixelsStream(const Image *image)
597 assert(image != (Image *) NULL);
598 assert(image->signature == MagickCoreSignature);
599 if (image->debug != MagickFalse)
600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
601 cache_info=(CacheInfo *) image->cache;
602 assert(cache_info->signature == MagickCoreSignature);
603 return(cache_info->pixels);
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
611 + 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 %
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 % GetVirtualMetacontentFromStream() returns the associated pixel channels
618 % corresponding with the last call to QueueAuthenticPixelsStream() or
619 % GetVirtualPixelStream().
621 % The format of the GetVirtualMetacontentFromStream() method is:
623 % const void *GetVirtualMetacontentFromStream(const Image *image)
625 % A description of each parameter follows:
627 % o image: the image.
630 static const void *GetVirtualMetacontentFromStream(const Image *image)
635 assert(image != (Image *) NULL);
636 assert(image->signature == MagickCoreSignature);
637 if (image->debug != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
639 cache_info=(CacheInfo *) image->cache;
640 assert(cache_info->signature == MagickCoreSignature);
641 return(cache_info->metacontent);
645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649 + G e t V i r t u a l P i x e l S t r e a m %
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
656 % defined by the geometry parameters. A pointer to the pixels is returned if
657 % the pixels are transferred, otherwise a NULL is returned. For streams this
660 % The format of the GetVirtualPixelStream() method is:
662 % const Quantum *GetVirtualPixelStream(const Image *image,
663 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
664 % const ssize_t y,const size_t columns,const size_t rows,
665 % ExceptionInfo *exception)
667 % A description of each parameter follows:
669 % o image: the image.
671 % o virtual_pixel_method: the virtual pixel method.
673 % o x,y,columns,rows: These values define the perimeter of a region of
676 % o exception: return any errors or warnings in this structure.
680 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
681 ExceptionInfo *exception)
683 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
685 cache_info->mapped=MagickFalse;
686 cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,(size_t)
688 if (cache_info->pixels == (Quantum *) NULL)
690 cache_info->mapped=MagickTrue;
691 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
694 if (cache_info->pixels == (Quantum *) NULL)
696 (void) ThrowMagickException(exception,GetMagickModule(),
697 ResourceLimitError,"MemoryAllocationFailed","`%s'",
698 cache_info->filename);
704 static const Quantum *GetVirtualPixelStream(const Image *image,
705 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
706 const ssize_t y,const size_t columns,const size_t rows,
707 ExceptionInfo *exception)
721 magick_unreferenced(virtual_pixel_method);
724 Validate pixel cache geometry.
726 assert(image != (const Image *) NULL);
727 assert(image->signature == MagickCoreSignature);
728 if (image->debug != MagickFalse)
729 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
730 if ((x < 0) || (y < 0) ||
731 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
732 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
733 (columns == 0) || (rows == 0))
735 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
736 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
737 return((Quantum *) NULL);
739 cache_info=(CacheInfo *) image->cache;
740 assert(cache_info->signature == MagickCoreSignature);
742 Pixels are stored in a temporary buffer until they are synced to the cache.
744 number_pixels=(MagickSizeType) columns*rows;
745 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
746 if (cache_info->number_channels == 0)
747 length=number_pixels*sizeof(Quantum);
748 if (cache_info->metacontent_extent != 0)
749 length+=number_pixels*cache_info->metacontent_extent;
750 if (cache_info->pixels == (Quantum *) NULL)
752 cache_info->length=length;
753 status=AcquireStreamPixels(cache_info,exception);
754 if (status == MagickFalse)
756 cache_info->length=0;
757 return((Quantum *) NULL);
761 if (cache_info->length < length)
763 RelinquishStreamPixels(cache_info);
764 cache_info->length=length;
765 status=AcquireStreamPixels(cache_info,exception);
766 if (status == MagickFalse)
768 cache_info->length=0;
769 return((Quantum *) NULL);
772 cache_info->metacontent=(void *) NULL;
773 if (cache_info->metacontent_extent != 0)
774 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
775 cache_info->number_channels);
776 return(cache_info->pixels);
780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 + O p e n S t r e a m %
788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 % OpenStream() opens a stream for writing by the StreamImage() method.
792 % The format of the OpenStream method is:
794 % MagickBooleanType OpenStream(const ImageInfo *image_info,
795 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
797 % A description of each parameter follows:
799 % o image_info: the image info.
801 % o stream_info: the stream info.
803 % o filename: the stream filename.
805 % o exception: return any errors or warnings in this structure.
808 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
809 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
814 (void) CopyMagickString(stream_info->stream->filename,filename,MagickPathExtent);
815 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824 + 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 %
828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
831 % defined by the region rectangle and returns a pointer to the area. This
832 % area is subsequently transferred from the pixel cache with method
833 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
834 % pixels are transferred, otherwise a NULL is returned.
836 % The format of the QueueAuthenticPixelsStream() method is:
838 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
839 % const ssize_t y,const size_t columns,const size_t rows,
840 % ExceptionInfo *exception)
842 % A description of each parameter follows:
844 % o image: the image.
846 % o x,y,columns,rows: These values define the perimeter of a region of
850 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
851 const ssize_t y,const size_t columns,const size_t rows,
852 ExceptionInfo *exception)
870 Validate pixel cache geometry.
872 assert(image != (Image *) NULL);
873 if ((x < 0) || (y < 0) ||
874 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
875 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
876 (columns == 0) || (rows == 0))
878 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
879 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
880 return((Quantum *) NULL);
882 stream_handler=GetBlobStreamHandler(image);
883 if (stream_handler == (StreamHandler) NULL)
885 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
886 "NoStreamHandlerIsDefined","`%s'",image->filename);
887 return((Quantum *) NULL);
889 cache_info=(CacheInfo *) image->cache;
890 assert(cache_info->signature == MagickCoreSignature);
891 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
892 (image->colorspace != GetPixelCacheColorspace(image->cache)))
894 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
895 (void) stream_handler(image,(const void *) NULL,(size_t)
896 cache_info->columns);
897 cache_info->storage_class=image->storage_class;
898 cache_info->colorspace=image->colorspace;
899 cache_info->columns=image->columns;
900 cache_info->rows=image->rows;
901 image->cache=cache_info;
904 Pixels are stored in a temporary buffer until they are synced to the cache.
906 cache_info->columns=columns;
907 cache_info->rows=rows;
908 number_pixels=(MagickSizeType) columns*rows;
909 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
910 if (cache_info->number_channels == 0)
911 length=number_pixels*sizeof(Quantum);
912 if (cache_info->metacontent_extent != 0)
913 length+=number_pixels*cache_info->metacontent_extent;
914 if (cache_info->pixels == (Quantum *) NULL)
916 cache_info->length=length;
917 status=AcquireStreamPixels(cache_info,exception);
918 if (status == MagickFalse)
920 cache_info->length=0;
921 return((Quantum *) NULL);
925 if (cache_info->length < length)
927 RelinquishStreamPixels(cache_info);
928 cache_info->length=length;
929 status=AcquireStreamPixels(cache_info,exception);
930 if (status == MagickFalse)
932 cache_info->length=0;
933 return((Quantum *) NULL);
936 cache_info->metacontent=(void *) NULL;
937 if (cache_info->metacontent_extent != 0)
938 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
939 cache_info->number_channels);
940 return(cache_info->pixels);
944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
948 % R e a d S t r e a m %
952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
954 % ReadStream() makes the image pixels available to a user supplied callback
955 % method immediately upon reading a scanline with the ReadImage() method.
957 % The format of the ReadStream() method is:
959 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
960 % ExceptionInfo *exception)
962 % A description of each parameter follows:
964 % o image_info: the image info.
966 % o stream: a callback method.
968 % o exception: return any errors or warnings in this structure.
971 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
972 ExceptionInfo *exception)
986 assert(image_info != (ImageInfo *) NULL);
987 assert(image_info->signature == MagickCoreSignature);
988 if (image_info->debug != MagickFalse)
989 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
990 image_info->filename);
991 assert(exception != (ExceptionInfo *) NULL);
992 assert(exception->signature == MagickCoreSignature);
993 read_info=CloneImageInfo(image_info);
994 read_info->cache=AcquirePixelCache(0);
995 GetPixelCacheMethods(&cache_methods);
996 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
997 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
998 cache_methods.get_virtual_metacontent_from_handler=
999 GetVirtualMetacontentFromStream;
1000 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
1001 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1002 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1003 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1004 cache_methods.get_authentic_metacontent_from_handler=
1005 GetAuthenticMetacontentFromStream;
1006 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1007 cache_methods.get_one_authentic_pixel_from_handler=
1008 GetOneAuthenticPixelFromStream;
1009 cache_methods.destroy_pixel_handler=DestroyPixelStream;
1010 SetPixelCacheMethods(read_info->cache,&cache_methods);
1011 read_info->stream=stream;
1012 image=ReadImage(read_info,exception);
1013 read_info=DestroyImageInfo(read_info);
1018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1022 + S e t S t r e a m I n f o C l i e n t D a t a %
1026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028 % SetStreamInfoClientData() sets the stream info client data.
1030 % The format of the SetStreamInfoClientData method is:
1032 % void SetStreamInfoClientData(StreamInfo *stream_info,
1033 % const void *client_data)
1035 % A description of each parameter follows:
1037 % o stream_info: the stream info.
1039 % o client_data: the client data.
1042 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1043 const void *client_data)
1045 assert(stream_info != (StreamInfo *) NULL);
1046 assert(stream_info->signature == MagickCoreSignature);
1047 stream_info->client_data=client_data;
1051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1055 + S e t S t r e a m I n f o M a p %
1059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061 % SetStreamInfoMap() sets the stream info map member.
1063 % The format of the SetStreamInfoMap method is:
1065 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1067 % A description of each parameter follows:
1069 % o stream_info: the stream info.
1074 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1076 assert(stream_info != (StreamInfo *) NULL);
1077 assert(stream_info->signature == MagickCoreSignature);
1078 (void) CloneString(&stream_info->map,map);
1082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1086 + S e t S t r e a m I n f o S t o r a g e T y p e %
1090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1092 % SetStreamInfoStorageType() sets the stream info storage type member.
1094 % The format of the SetStreamInfoStorageType method is:
1096 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1097 % const StoreageType *storage_type)
1099 % A description of each parameter follows:
1101 % o stream_info: the stream info.
1103 % o storage_type: the storage type.
1106 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1107 const StorageType storage_type)
1109 assert(stream_info != (StreamInfo *) NULL);
1110 assert(stream_info->signature == MagickCoreSignature);
1111 stream_info->storage_type=storage_type;
1115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1119 + S t r e a m I m a g e %
1123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1125 % StreamImage() streams pixels from an image and writes them in a user
1126 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1128 % The format of the StreamImage() method is:
1130 % Image *StreamImage(const ImageInfo *image_info,
1131 % StreamInfo *stream_info,ExceptionInfo *exception)
1133 % A description of each parameter follows:
1135 % o image_info: the image info.
1137 % o stream_info: the stream info.
1139 % o exception: return any errors or warnings in this structure.
1143 #if defined(__cplusplus) || defined(c_plusplus)
1147 static size_t WriteStreamImage(const Image *image,const void *pixels,
1148 const size_t columns)
1167 stream_info=(StreamInfo *) image->client_data;
1168 switch (stream_info->storage_type)
1170 default: packet_size=sizeof(unsigned char); break;
1171 case CharPixel: packet_size=sizeof(unsigned char); break;
1172 case DoublePixel: packet_size=sizeof(double); break;
1173 case FloatPixel: packet_size=sizeof(float); break;
1174 case LongPixel: packet_size=sizeof(unsigned int); break;
1175 case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
1176 case QuantumPixel: packet_size=sizeof(Quantum); break;
1177 case ShortPixel: packet_size=sizeof(unsigned short); break;
1179 cache_info=(CacheInfo *) image->cache;
1180 assert(cache_info->signature == MagickCoreSignature);
1181 packet_size*=strlen(stream_info->map);
1182 length=packet_size*cache_info->columns*cache_info->rows;
1183 if (image != stream_info->image)
1189 Prepare stream for writing.
1191 (void) RelinquishAlignedMemory(stream_info->pixels);
1192 stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
1193 if (stream_info->pixels == (unsigned char *) NULL)
1195 (void) ResetMagickMemory(stream_info->pixels,0,length);
1196 stream_info->image=image;
1197 write_info=CloneImageInfo(stream_info->image_info);
1198 (void) SetImageInfo(write_info,1,stream_info->exception);
1199 if (write_info->extract != (char *) NULL)
1200 (void) ParseAbsoluteGeometry(write_info->extract,
1201 &stream_info->extract_info);
1203 write_info=DestroyImageInfo(write_info);
1205 extract_info=stream_info->extract_info;
1206 if ((extract_info.width == 0) || (extract_info.height == 0))
1209 Write all pixels to stream.
1211 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1212 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1214 return(count == 0 ? 0 : columns);
1216 if ((stream_info->y < extract_info.y) ||
1217 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1223 Write a portion of the pixel row to the stream.
1225 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1226 length=packet_size*extract_info.width;
1227 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1230 return(count == 0 ? 0 : columns);
1233 #if defined(__cplusplus) || defined(c_plusplus)
1237 MagickExport Image *StreamImage(const ImageInfo *image_info,
1238 StreamInfo *stream_info,ExceptionInfo *exception)
1246 assert(image_info != (const ImageInfo *) NULL);
1247 assert(image_info->signature == MagickCoreSignature);
1248 if (image_info->debug != MagickFalse)
1249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1250 image_info->filename);
1251 assert(stream_info != (StreamInfo *) NULL);
1252 assert(stream_info->signature == MagickCoreSignature);
1253 assert(exception != (ExceptionInfo *) NULL);
1254 read_info=CloneImageInfo(image_info);
1255 stream_info->image_info=image_info;
1256 stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
1257 stream_info->exception=exception;
1258 read_info->client_data=(void *) stream_info;
1259 image=ReadStream(read_info,&WriteStreamImage,exception);
1260 read_info=DestroyImageInfo(read_info);
1261 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1262 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1263 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1264 image=DestroyImage(image);
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 + S t r e a m I m a g e P i x e l s %
1277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 % StreamImagePixels() extracts pixel data from an image and returns it in the
1280 % stream_info->pixels structure in the format as defined by
1281 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1283 % The format of the StreamImagePixels method is:
1285 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1286 % const Image *image,ExceptionInfo *exception)
1288 % A description of each parameter follows:
1290 % o stream_info: the stream info.
1292 % o image: the image.
1294 % o exception: return any errors or warnings in this structure.
1297 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1298 const Image *image,ExceptionInfo *exception)
1306 register const Quantum
1316 assert(stream_info != (StreamInfo *) NULL);
1317 assert(stream_info->signature == MagickCoreSignature);
1318 assert(image != (Image *) NULL);
1319 assert(image->signature == MagickCoreSignature);
1320 if (image->debug != MagickFalse)
1321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1322 length=strlen(stream_info->map);
1323 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1324 if (quantum_map == (QuantumType *) NULL)
1326 (void) ThrowMagickException(exception,GetMagickModule(),
1327 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1328 return(MagickFalse);
1330 for (i=0; i < (ssize_t) length; i++)
1332 switch (stream_info->map[i])
1337 quantum_map[i]=AlphaQuantum;
1343 quantum_map[i]=BlueQuantum;
1349 quantum_map[i]=CyanQuantum;
1350 if (image->colorspace == CMYKColorspace)
1352 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1353 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1354 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1355 return(MagickFalse);
1360 quantum_map[i]=GreenQuantum;
1366 quantum_map[i]=IndexQuantum;
1372 quantum_map[i]=BlackQuantum;
1373 if (image->colorspace == CMYKColorspace)
1375 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1376 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1377 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1378 return(MagickFalse);
1383 quantum_map[i]=MagentaQuantum;
1384 if (image->colorspace == CMYKColorspace)
1386 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1387 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1388 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1389 return(MagickFalse);
1394 quantum_map[i]=OpacityQuantum;
1400 quantum_map[i]=UndefinedQuantum;
1406 quantum_map[i]=RedQuantum;
1412 quantum_map[i]=YellowQuantum;
1413 if (image->colorspace == CMYKColorspace)
1415 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1416 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1417 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1418 return(MagickFalse);
1422 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1423 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1424 "UnrecognizedPixelMap","`%s'",stream_info->map);
1425 return(MagickFalse);
1429 quantum_info=stream_info->quantum_info;
1430 switch (stream_info->storage_type)
1434 register unsigned char
1437 q=(unsigned char *) stream_info->pixels;
1438 if (LocaleCompare(stream_info->map,"BGR") == 0)
1440 p=GetAuthenticPixelQueue(image);
1441 if (p == (const Quantum *) NULL)
1443 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1445 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1446 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1447 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1452 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1454 p=GetAuthenticPixelQueue(image);
1455 if (p == (const Quantum *) NULL)
1457 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1459 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1460 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1461 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1462 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1467 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1469 p=GetAuthenticPixelQueue(image);
1470 if (p == (const Quantum *) NULL)
1472 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1474 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1475 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1476 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1477 *q++=ScaleQuantumToChar((Quantum) 0);
1482 if (LocaleCompare(stream_info->map,"I") == 0)
1484 p=GetAuthenticPixelQueue(image);
1485 if (p == (const Quantum *) NULL)
1487 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1489 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1494 if (LocaleCompare(stream_info->map,"RGB") == 0)
1496 p=GetAuthenticPixelQueue(image);
1497 if (p == (const Quantum *) NULL)
1499 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1501 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1502 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1503 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1508 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1510 p=GetAuthenticPixelQueue(image);
1511 if (p == (const Quantum *) NULL)
1513 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1515 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1516 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1517 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1518 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1523 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1525 p=GetAuthenticPixelQueue(image);
1526 if (p == (const Quantum *) NULL)
1528 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1530 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1531 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1532 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1533 *q++=ScaleQuantumToChar((Quantum) 0);
1538 p=GetAuthenticPixelQueue(image);
1539 if (p == (const Quantum *) NULL)
1541 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1543 for (i=0; i < (ssize_t) length; i++)
1546 switch (quantum_map[i])
1551 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1555 case MagentaQuantum:
1557 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1563 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1568 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1571 case OpacityQuantum:
1573 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1578 if (image->colorspace == CMYKColorspace)
1579 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1584 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1601 q=(double *) stream_info->pixels;
1602 if (LocaleCompare(stream_info->map,"BGR") == 0)
1604 p=GetAuthenticPixelQueue(image);
1605 if (p == (const Quantum *) NULL)
1607 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1609 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1610 quantum_info->scale+quantum_info->minimum);
1611 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1612 quantum_info->scale+quantum_info->minimum);
1613 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1614 quantum_info->scale+quantum_info->minimum);
1619 if (LocaleCompare(stream_info->map,"BGRA") == 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*GetPixelBlue(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*GetPixelRed(image,p))*
1631 quantum_info->scale+quantum_info->minimum);
1632 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1633 quantum_info->scale+quantum_info->minimum);
1638 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1640 p=GetAuthenticPixelQueue(image);
1641 if (p == (const Quantum *) NULL)
1643 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1645 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1646 quantum_info->scale+quantum_info->minimum);
1647 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1649 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1650 quantum_info->scale+quantum_info->minimum);
1656 if (LocaleCompare(stream_info->map,"I") == 0)
1658 p=GetAuthenticPixelQueue(image);
1659 if (p == (const Quantum *) NULL)
1661 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1663 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1664 quantum_info->scale+quantum_info->minimum);
1669 if (LocaleCompare(stream_info->map,"RGB") == 0)
1671 p=GetAuthenticPixelQueue(image);
1672 if (p == (const Quantum *) NULL)
1674 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1676 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1677 quantum_info->scale+quantum_info->minimum);
1678 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1679 quantum_info->scale+quantum_info->minimum);
1680 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1681 quantum_info->scale+quantum_info->minimum);
1686 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1688 p=GetAuthenticPixelQueue(image);
1689 if (p == (const Quantum *) NULL)
1691 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1693 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1694 quantum_info->scale+quantum_info->minimum);
1695 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1696 quantum_info->scale+quantum_info->minimum);
1697 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1698 quantum_info->scale+quantum_info->minimum);
1699 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1700 quantum_info->scale+quantum_info->minimum);
1705 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1707 p=GetAuthenticPixelQueue(image);
1708 if (p == (const Quantum *) NULL)
1710 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1712 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1713 quantum_info->scale+quantum_info->minimum);
1714 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1715 quantum_info->scale+quantum_info->minimum);
1716 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1717 quantum_info->scale+quantum_info->minimum);
1723 p=GetAuthenticPixelQueue(image);
1724 if (p == (const Quantum *) NULL)
1726 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1728 for (i=0; i < (ssize_t) length; i++)
1731 switch (quantum_map[i])
1736 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1737 quantum_info->scale+quantum_info->minimum);
1741 case MagentaQuantum:
1743 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1744 quantum_info->scale+quantum_info->minimum);
1750 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1751 quantum_info->scale+quantum_info->minimum);
1756 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1757 quantum_info->scale+quantum_info->minimum);
1760 case OpacityQuantum:
1762 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1763 quantum_info->scale+quantum_info->minimum);
1768 if (image->colorspace == CMYKColorspace)
1769 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1770 quantum_info->scale+quantum_info->minimum);
1775 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1776 quantum_info->scale+quantum_info->minimum);
1793 q=(float *) stream_info->pixels;
1794 if (LocaleCompare(stream_info->map,"BGR") == 0)
1796 p=GetAuthenticPixelQueue(image);
1797 if (p == (const Quantum *) NULL)
1799 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1801 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1802 quantum_info->scale+quantum_info->minimum);
1803 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1804 quantum_info->scale+quantum_info->minimum);
1805 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1806 quantum_info->scale+quantum_info->minimum);
1811 if (LocaleCompare(stream_info->map,"BGRA") == 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*GetPixelBlue(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*GetPixelRed(image,p))*
1823 quantum_info->scale+quantum_info->minimum);
1824 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1825 quantum_info->scale+quantum_info->minimum);
1830 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1832 p=GetAuthenticPixelQueue(image);
1833 if (p == (const Quantum *) NULL)
1835 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1837 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1838 quantum_info->scale+quantum_info->minimum);
1839 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1841 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1842 quantum_info->scale+quantum_info->minimum);
1848 if (LocaleCompare(stream_info->map,"I") == 0)
1850 p=GetAuthenticPixelQueue(image);
1851 if (p == (const Quantum *) NULL)
1853 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1855 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1856 quantum_info->scale+quantum_info->minimum);
1861 if (LocaleCompare(stream_info->map,"RGB") == 0)
1863 p=GetAuthenticPixelQueue(image);
1864 if (p == (const Quantum *) NULL)
1866 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1868 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1869 quantum_info->scale+quantum_info->minimum);
1870 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1871 quantum_info->scale+quantum_info->minimum);
1872 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1873 quantum_info->scale+quantum_info->minimum);
1878 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1880 p=GetAuthenticPixelQueue(image);
1881 if (p == (const Quantum *) NULL)
1883 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1885 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1886 quantum_info->scale+quantum_info->minimum);
1887 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1888 quantum_info->scale+quantum_info->minimum);
1889 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1890 quantum_info->scale+quantum_info->minimum);
1891 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1892 quantum_info->scale+quantum_info->minimum);
1897 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1899 p=GetAuthenticPixelQueue(image);
1900 if (p == (const Quantum *) NULL)
1902 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1904 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1905 quantum_info->scale+quantum_info->minimum);
1906 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1907 quantum_info->scale+quantum_info->minimum);
1908 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1909 quantum_info->scale+quantum_info->minimum);
1915 p=GetAuthenticPixelQueue(image);
1916 if (p == (const Quantum *) NULL)
1918 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1920 for (i=0; i < (ssize_t) length; i++)
1923 switch (quantum_map[i])
1928 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1929 quantum_info->scale+quantum_info->minimum);
1933 case MagentaQuantum:
1935 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1936 quantum_info->scale+quantum_info->minimum);
1942 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1943 quantum_info->scale+quantum_info->minimum);
1948 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1949 quantum_info->scale+quantum_info->minimum);
1952 case OpacityQuantum:
1954 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1955 quantum_info->scale+quantum_info->minimum);
1960 if (image->colorspace == CMYKColorspace)
1961 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1962 quantum_info->scale+quantum_info->minimum);
1967 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1968 quantum_info->scale+quantum_info->minimum);
1982 register unsigned int
1985 q=(unsigned int *) stream_info->pixels;
1986 if (LocaleCompare(stream_info->map,"BGR") == 0)
1988 p=GetAuthenticPixelQueue(image);
1989 if (p == (const Quantum *) NULL)
1991 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1993 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1994 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1995 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2000 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2002 p=GetAuthenticPixelQueue(image);
2003 if (p == (const Quantum *) NULL)
2005 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2007 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2008 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2009 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2010 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2015 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2017 p=GetAuthenticPixelQueue(image);
2018 if (p == (const Quantum *) NULL)
2020 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2022 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2023 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2024 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2030 if (LocaleCompare(stream_info->map,"I") == 0)
2032 p=GetAuthenticPixelQueue(image);
2033 if (p == (const Quantum *) NULL)
2035 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2037 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2042 if (LocaleCompare(stream_info->map,"RGB") == 0)
2044 p=GetAuthenticPixelQueue(image);
2045 if (p == (const Quantum *) NULL)
2047 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2049 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2050 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2051 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2056 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2058 p=GetAuthenticPixelQueue(image);
2059 if (p == (const Quantum *) NULL)
2061 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2063 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2064 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2065 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2066 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2071 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2073 p=GetAuthenticPixelQueue(image);
2074 if (p == (const Quantum *) NULL)
2076 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2078 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2079 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2080 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2086 p=GetAuthenticPixelQueue(image);
2087 if (p == (const Quantum *) NULL)
2089 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2091 for (i=0; i < (ssize_t) length; i++)
2094 switch (quantum_map[i])
2099 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2103 case MagentaQuantum:
2105 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2111 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2116 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2119 case OpacityQuantum:
2121 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2126 if (image->colorspace == CMYKColorspace)
2127 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2132 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2146 register MagickSizeType
2149 q=(MagickSizeType *) stream_info->pixels;
2150 if (LocaleCompare(stream_info->map,"BGR") == 0)
2152 p=GetAuthenticPixelQueue(image);
2153 if (p == (const Quantum *) NULL)
2155 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2157 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2158 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2159 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2164 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2166 p=GetAuthenticPixelQueue(image);
2167 if (p == (const Quantum *) NULL)
2169 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2171 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2172 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2173 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2174 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2179 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2181 p=GetAuthenticPixelQueue(image);
2182 if (p == (const Quantum *) NULL)
2184 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2186 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2187 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2188 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2194 if (LocaleCompare(stream_info->map,"I") == 0)
2196 p=GetAuthenticPixelQueue(image);
2197 if (p == (const Quantum *) NULL)
2199 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2201 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2202 GetPixelIntensity(image,p)));
2207 if (LocaleCompare(stream_info->map,"RGB") == 0)
2209 p=GetAuthenticPixelQueue(image);
2210 if (p == (const Quantum *) NULL)
2212 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2214 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2215 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2216 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2221 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2223 p=GetAuthenticPixelQueue(image);
2224 if (p == (const Quantum *) NULL)
2226 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2228 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2229 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2230 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2231 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2236 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2238 p=GetAuthenticPixelQueue(image);
2239 if (p == (const Quantum *) NULL)
2241 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2243 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2244 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2245 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2251 p=GetAuthenticPixelQueue(image);
2252 if (p == (const Quantum *) NULL)
2254 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2256 for (i=0; i < (ssize_t) length; i++)
2259 switch (quantum_map[i])
2264 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2268 case MagentaQuantum:
2270 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2276 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2281 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2284 case OpacityQuantum:
2286 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2291 if (image->colorspace == CMYKColorspace)
2292 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2297 *q=ScaleQuantumToLongLong(ClampToQuantum(
2298 GetPixelIntensity(image,p)));
2315 q=(Quantum *) stream_info->pixels;
2316 if (LocaleCompare(stream_info->map,"BGR") == 0)
2318 p=GetAuthenticPixelQueue(image);
2319 if (p == (const Quantum *) NULL)
2321 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2323 *q++=GetPixelBlue(image,p);
2324 *q++=GetPixelGreen(image,p);
2325 *q++=GetPixelRed(image,p);
2330 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2332 p=GetAuthenticPixelQueue(image);
2333 if (p == (const Quantum *) NULL)
2335 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2337 *q++=GetPixelBlue(image,p);
2338 *q++=GetPixelGreen(image,p);
2339 *q++=GetPixelRed(image,p);
2340 *q++=GetPixelAlpha(image,p);
2345 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2347 p=GetAuthenticPixelQueue(image);
2348 if (p == (const Quantum *) NULL)
2350 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2352 *q++=GetPixelBlue(image,p);
2353 *q++=GetPixelGreen(image,p);
2354 *q++=GetPixelRed(image,p);
2360 if (LocaleCompare(stream_info->map,"I") == 0)
2362 p=GetAuthenticPixelQueue(image);
2363 if (p == (const Quantum *) NULL)
2365 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2367 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2372 if (LocaleCompare(stream_info->map,"RGB") == 0)
2374 p=GetAuthenticPixelQueue(image);
2375 if (p == (const Quantum *) NULL)
2377 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2379 *q++=GetPixelRed(image,p);
2380 *q++=GetPixelGreen(image,p);
2381 *q++=GetPixelBlue(image,p);
2386 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2388 p=GetAuthenticPixelQueue(image);
2389 if (p == (const Quantum *) NULL)
2391 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2393 *q++=GetPixelRed(image,p);
2394 *q++=GetPixelGreen(image,p);
2395 *q++=GetPixelBlue(image,p);
2396 *q++=GetPixelAlpha(image,p);
2401 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2403 p=GetAuthenticPixelQueue(image);
2404 if (p == (const Quantum *) NULL)
2406 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2408 *q++=GetPixelRed(image,p);
2409 *q++=GetPixelGreen(image,p);
2410 *q++=GetPixelBlue(image,p);
2416 p=GetAuthenticPixelQueue(image);
2417 if (p == (const Quantum *) NULL)
2419 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2421 for (i=0; i < (ssize_t) length; i++)
2424 switch (quantum_map[i])
2429 *q=GetPixelRed(image,p);
2433 case MagentaQuantum:
2435 *q=GetPixelGreen(image,p);
2441 *q=GetPixelBlue(image,p);
2446 *q=(Quantum) (GetPixelAlpha(image,p));
2449 case OpacityQuantum:
2451 *q=GetPixelAlpha(image,p);
2456 if (image->colorspace == CMYKColorspace)
2457 *q=GetPixelBlack(image,p);
2462 *q=ClampToQuantum(GetPixelIntensity(image,p));
2476 register unsigned short
2479 q=(unsigned short *) stream_info->pixels;
2480 if (LocaleCompare(stream_info->map,"BGR") == 0)
2482 p=GetAuthenticPixelQueue(image);
2483 if (p == (const Quantum *) NULL)
2485 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2487 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2488 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2489 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2494 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2496 p=GetAuthenticPixelQueue(image);
2497 if (p == (const Quantum *) NULL)
2499 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2501 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2502 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2503 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2504 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2509 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2511 p=GetAuthenticPixelQueue(image);
2512 if (p == (const Quantum *) NULL)
2514 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2516 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2517 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2518 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2524 if (LocaleCompare(stream_info->map,"I") == 0)
2526 p=GetAuthenticPixelQueue(image);
2527 if (p == (const Quantum *) NULL)
2529 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2531 *q++=ScaleQuantumToShort(ClampToQuantum(
2532 GetPixelIntensity(image,p)));
2537 if (LocaleCompare(stream_info->map,"RGB") == 0)
2539 p=GetAuthenticPixelQueue(image);
2540 if (p == (const Quantum *) NULL)
2542 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2544 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2545 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2546 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2551 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2553 p=GetAuthenticPixelQueue(image);
2554 if (p == (const Quantum *) NULL)
2556 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2558 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2559 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2560 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2561 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2566 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2568 p=GetAuthenticPixelQueue(image);
2569 if (p == (const Quantum *) NULL)
2571 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2573 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2574 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2575 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2581 p=GetAuthenticPixelQueue(image);
2582 if (p == (const Quantum *) NULL)
2584 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2586 for (i=0; i < (ssize_t) length; i++)
2589 switch (quantum_map[i])
2594 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2598 case MagentaQuantum:
2600 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2606 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2611 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2614 case OpacityQuantum:
2616 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2621 if (image->colorspace == CMYKColorspace)
2622 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2627 *q=ScaleQuantumToShort(ClampToQuantum(
2628 GetPixelIntensity(image,p)));
2642 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2643 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2644 "UnrecognizedPixelMap","`%s'",stream_info->map);
2648 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2657 + 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 %
2661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2663 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2664 % the latest stream of pixels.
2666 % The format of the SyncAuthenticPixelsStream method is:
2668 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2669 % ExceptionInfo *exception)
2671 % A description of each parameter follows:
2673 % o image: the image.
2675 % o exception: return any errors or warnings in this structure.
2678 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2679 ExceptionInfo *exception)
2690 assert(image != (Image *) NULL);
2691 assert(image->signature == MagickCoreSignature);
2692 if (image->debug != MagickFalse)
2693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2694 cache_info=(CacheInfo *) image->cache;
2695 assert(cache_info->signature == MagickCoreSignature);
2696 stream_handler=GetBlobStreamHandler(image);
2697 if (stream_handler == (StreamHandler) NULL)
2699 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2700 "NoStreamHandlerIsDefined","`%s'",image->filename);
2701 return(MagickFalse);
2703 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2704 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2712 % W r i t e S t r e a m %
2716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2718 % WriteStream() makes the image pixels available to a user supplied callback
2719 % method immediately upon writing pixel data with the WriteImage() method.
2721 % The format of the WriteStream() method is:
2723 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2724 % StreamHandler stream,ExceptionInfo *exception)
2726 % A description of each parameter follows:
2728 % o image_info: the image info.
2730 % o stream: A callback method.
2732 % o exception: return any errors or warnings in this structure.
2735 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2736 Image *image,StreamHandler stream,ExceptionInfo *exception)
2744 assert(image_info != (ImageInfo *) NULL);
2745 assert(image_info->signature == MagickCoreSignature);
2746 if (image_info->debug != MagickFalse)
2747 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2748 image_info->filename);
2749 assert(image != (Image *) NULL);
2750 assert(image->signature == MagickCoreSignature);
2751 write_info=CloneImageInfo(image_info);
2752 *write_info->magick='\0';
2753 write_info->stream=stream;
2754 status=WriteImage(write_info,image,exception);
2755 write_info=DestroyImageInfo(write_info);