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-2018 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 % https://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/policy.h"
59 #include "MagickCore/quantum.h"
60 #include "MagickCore/quantum-private.h"
61 #include "MagickCore/semaphore.h"
62 #include "MagickCore/stream.h"
63 #include "MagickCore/stream-private.h"
64 #include "MagickCore/string_.h"
67 Typedef declaractions.
109 Declare pixel cache interfaces.
111 #if defined(__cplusplus) || defined(c_plusplus)
116 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
117 const ssize_t,const size_t,const size_t,ExceptionInfo *);
119 static MagickBooleanType
120 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
121 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
124 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
125 const size_t,ExceptionInfo *);
127 #if defined(__cplusplus) || defined(c_plusplus)
132 cache_anonymous_memory = (-1);
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 + A c q u i r e S t r e a m I n f o %
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % AcquireStreamInfo() allocates the StreamInfo structure.
147 % The format of the AcquireStreamInfo method is:
149 % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
150 % ExceptionInfo *exception)
152 % A description of each parameter follows:
154 % o image_info: the image info.
156 % o exception: return any errors or warnings in this structure.
159 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
160 ExceptionInfo *exception)
165 stream_info=(StreamInfo *) AcquireCriticalMemory(sizeof(*stream_info));
166 (void) memset(stream_info,0,sizeof(*stream_info));
167 stream_info->pixels=(unsigned char *) MagickAssumeAligned(
168 AcquireAlignedMemory(1,sizeof(*stream_info->pixels)));
169 if (stream_info->pixels == (unsigned char *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 stream_info->map=ConstantString("RGB");
172 stream_info->storage_type=CharPixel;
173 stream_info->stream=AcquireImage(image_info,exception);
174 stream_info->signature=MagickCoreSignature;
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 + D e s t r o y P i x e l S t r e a m %
187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 % DestroyPixelStream() deallocates memory associated with the pixel stream.
191 % The format of the DestroyPixelStream() method is:
193 % void DestroyPixelStream(Image *image)
195 % A description of each parameter follows:
197 % o image: the image.
201 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
203 assert(cache_info != (CacheInfo *) NULL);
204 if (cache_info->mapped == MagickFalse)
205 (void) RelinquishAlignedMemory(cache_info->pixels);
207 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
208 cache_info->pixels=(Quantum *) NULL;
209 cache_info->metacontent=(void *) NULL;
210 cache_info->length=0;
211 cache_info->mapped=MagickFalse;
214 static void DestroyPixelStream(Image *image)
222 assert(image != (Image *) NULL);
223 assert(image->signature == MagickCoreSignature);
224 if (image->debug != MagickFalse)
225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
226 cache_info=(CacheInfo *) image->cache;
227 assert(cache_info->signature == MagickCoreSignature);
229 LockSemaphoreInfo(cache_info->semaphore);
230 cache_info->reference_count--;
231 if (cache_info->reference_count == 0)
233 UnlockSemaphoreInfo(cache_info->semaphore);
234 if (destroy == MagickFalse)
236 RelinquishStreamPixels(cache_info);
237 if (cache_info->nexus_info != (NexusInfo **) NULL)
238 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
239 cache_info->number_threads);
240 if (cache_info->file_semaphore != (SemaphoreInfo *) NULL)
241 RelinquishSemaphoreInfo(&cache_info->file_semaphore);
242 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
243 RelinquishSemaphoreInfo(&cache_info->semaphore);
244 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 + D e s t r o y S t r e a m I n f o %
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % DestroyStreamInfo() destroys memory associated with the StreamInfo
261 % The format of the DestroyStreamInfo method is:
263 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
265 % A description of each parameter follows:
267 % o stream_info: the stream info.
270 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
272 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
273 assert(stream_info != (StreamInfo *) NULL);
274 assert(stream_info->signature == MagickCoreSignature);
275 if (stream_info->map != (char *) NULL)
276 stream_info->map=DestroyString(stream_info->map);
277 if (stream_info->pixels != (unsigned char *) NULL)
278 stream_info->pixels=(unsigned char *) RelinquishAlignedMemory(
279 stream_info->pixels);
280 if (stream_info->stream != (Image *) NULL)
282 (void) CloseBlob(stream_info->stream);
283 stream_info->stream=DestroyImage(stream_info->stream);
285 if (stream_info->quantum_info != (QuantumInfo *) NULL)
286 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
287 stream_info->signature=(~MagickCoreSignature);
288 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 + 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 %
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % GetAuthenticMetacontentFromStream() returns the metacontent corresponding
304 % with the last call to QueueAuthenticPixelsStream() or
305 % GetAuthenticPixelsStream().
307 % The format of the GetAuthenticMetacontentFromStream() method is:
309 % void *GetAuthenticMetacontentFromStream(const Image *image)
311 % A description of each parameter follows:
313 % o image: the image.
316 static void *GetAuthenticMetacontentFromStream(const Image *image)
321 assert(image != (Image *) NULL);
322 assert(image->signature == MagickCoreSignature);
323 if (image->debug != MagickFalse)
324 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
325 cache_info=(CacheInfo *) image->cache;
326 assert(cache_info->signature == MagickCoreSignature);
327 return(cache_info->metacontent);
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 + G e t A u t h e n t i c P i x e l S t r e a m %
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
342 % cache as defined by the geometry parameters. A pointer to the pixels is
343 % returned if the pixels are transferred, otherwise a NULL is returned. For
344 % streams this method is a no-op.
346 % The format of the GetAuthenticPixelsStream() method is:
348 % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
349 % const ssize_t y,const size_t columns,const size_t rows,
350 % ExceptionInfo *exception)
352 % A description of each parameter follows:
354 % o image: the image.
356 % o x,y,columns,rows: These values define the perimeter of a region of
359 % o exception: return any errors or warnings in this structure.
362 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
363 const ssize_t y,const size_t columns,const size_t rows,
364 ExceptionInfo *exception)
369 assert(image != (Image *) NULL);
370 assert(image->signature == MagickCoreSignature);
371 if (image->debug != MagickFalse)
372 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
373 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382 + 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 %
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
389 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
391 % The format of the GetAuthenticPixelsFromStream() method is:
393 % Quantum *GetAuthenticPixelsFromStream(const Image image)
395 % A description of each parameter follows:
397 % o image: the image.
400 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
405 assert(image != (Image *) NULL);
406 assert(image->signature == MagickCoreSignature);
407 if (image->debug != MagickFalse)
408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
409 cache_info=(CacheInfo *) image->cache;
410 assert(cache_info->signature == MagickCoreSignature);
411 return(cache_info->pixels);
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 + 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 %
423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
426 % (x,y) location. The image background color is returned if an error occurs.
428 % The format of the GetOneAuthenticPixelFromStream() method is:
430 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
431 % const ssize_t x,const ssize_t y,Quantum *pixel,
432 % ExceptionInfo *exception)
434 % A description of each parameter follows:
436 % o image: the image.
438 % o pixel: return a pixel at the specified (x,y) location.
440 % o x,y: These values define the location of the pixel to return.
442 % o exception: return any errors or warnings in this structure.
445 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
446 const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
454 assert(image != (Image *) NULL);
455 assert(image->signature == MagickCoreSignature);
456 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
457 p=GetAuthenticPixelsStream(image,x,y,1,1,exception);
458 if (p == (Quantum *) NULL)
460 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
461 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
462 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
463 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
464 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
467 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
469 PixelChannel channel = GetPixelChannelChannel(image,i);
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 + 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 %
484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
487 % (x.y) location. The image background color is returned if an error occurs.
489 % The format of the GetOneVirtualPixelFromStream() method is:
491 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
492 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
493 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
495 % A description of each parameter follows:
497 % o image: the image.
499 % o virtual_pixel_method: the virtual pixel method.
501 % o x,y: These values define the location of the pixel to return.
503 % o pixel: return a pixel at the specified (x,y) location.
505 % o exception: return any errors or warnings in this structure.
508 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
509 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
510 Quantum *pixel,ExceptionInfo *exception)
518 assert(image != (Image *) NULL);
519 assert(image->signature == MagickCoreSignature);
520 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
521 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
522 if (p == (const Quantum *) NULL)
524 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
525 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
526 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
527 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
528 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
531 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
533 PixelChannel channel = GetPixelChannelChannel(image,i);
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
544 + G e t S t r e a m I n f o C l i e n t D a t a %
548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550 % GetStreamInfoClientData() gets the stream info client data.
552 % The format of the GetStreamInfoClientData method is:
554 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
556 % A description of each parameter follows:
558 % o stream_info: the stream info.
561 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
563 assert(stream_info != (StreamInfo *) NULL);
564 assert(stream_info->signature == MagickCoreSignature);
565 return(stream_info->client_data);
569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573 + 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 %
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579 % GetVirtualPixelsStream() returns the pixels associated with the last call to
580 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
582 % The format of the GetVirtualPixelsStream() method is:
584 % const Quantum *GetVirtualPixelsStream(const Image *image)
586 % A description of each parameter follows:
588 % o pixels: return the pixels associated corresponding with the last call to
589 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
591 % o image: the image.
594 static const Quantum *GetVirtualPixelsStream(const Image *image)
599 assert(image != (Image *) NULL);
600 assert(image->signature == MagickCoreSignature);
601 if (image->debug != MagickFalse)
602 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
603 cache_info=(CacheInfo *) image->cache;
604 assert(cache_info->signature == MagickCoreSignature);
605 return(cache_info->pixels);
609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
613 + 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 %
617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 % GetVirtualMetacontentFromStream() returns the associated pixel channels
620 % corresponding with the last call to QueueAuthenticPixelsStream() or
621 % GetVirtualPixelStream().
623 % The format of the GetVirtualMetacontentFromStream() method is:
625 % const void *GetVirtualMetacontentFromStream(const Image *image)
627 % A description of each parameter follows:
629 % o image: the image.
632 static const void *GetVirtualMetacontentFromStream(const Image *image)
637 assert(image != (Image *) NULL);
638 assert(image->signature == MagickCoreSignature);
639 if (image->debug != MagickFalse)
640 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
641 cache_info=(CacheInfo *) image->cache;
642 assert(cache_info->signature == MagickCoreSignature);
643 return(cache_info->metacontent);
647 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651 + G e t V i r t u a l P i x e l S t r e a m %
655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
658 % defined by the geometry parameters. A pointer to the pixels is returned if
659 % the pixels are transferred, otherwise a NULL is returned. For streams this
662 % The format of the GetVirtualPixelStream() method is:
664 % const Quantum *GetVirtualPixelStream(const Image *image,
665 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
666 % const ssize_t y,const size_t columns,const size_t rows,
667 % ExceptionInfo *exception)
669 % A description of each parameter follows:
671 % o image: the image.
673 % o virtual_pixel_method: the virtual pixel method.
675 % o x,y,columns,rows: These values define the perimeter of a region of
678 % o exception: return any errors or warnings in this structure.
682 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
683 ExceptionInfo *exception)
685 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
687 if (cache_anonymous_memory < 0)
693 Does the security policy require anonymous mapping for pixel cache?
695 cache_anonymous_memory=0;
696 value=GetPolicyValue("pixel-cache-memory");
697 if (value == (char *) NULL)
698 value=GetPolicyValue("cache:memory-map");
699 if (LocaleCompare(value,"anonymous") == 0)
701 #if defined(MAGICKCORE_HAVE_MMAP) && defined(MAP_ANONYMOUS)
702 cache_anonymous_memory=1;
704 (void) ThrowMagickException(exception,GetMagickModule(),
705 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn",
706 "'%s' (policy requires anonymous memory mapping)",
707 cache_info->filename);
710 value=DestroyString(value);
712 if (cache_anonymous_memory <= 0)
714 cache_info->mapped=MagickFalse;
715 cache_info->pixels=(Quantum *) MagickAssumeAligned(
716 AcquireAlignedMemory(1,(size_t) cache_info->length));
720 cache_info->mapped=MagickTrue;
721 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
724 if (cache_info->pixels == (Quantum *) NULL)
726 (void) ThrowMagickException(exception,GetMagickModule(),
727 ResourceLimitError,"MemoryAllocationFailed","`%s'",
728 cache_info->filename);
734 static const Quantum *GetVirtualPixelStream(const Image *image,
735 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
736 const ssize_t y,const size_t columns,const size_t rows,
737 ExceptionInfo *exception)
751 magick_unreferenced(virtual_pixel_method);
754 Validate pixel cache geometry.
756 assert(image != (const Image *) NULL);
757 assert(image->signature == MagickCoreSignature);
758 if (image->debug != MagickFalse)
759 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
760 if ((x < 0) || (y < 0) ||
761 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
762 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
763 (columns == 0) || (rows == 0))
765 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
766 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
767 return((Quantum *) NULL);
769 cache_info=(CacheInfo *) image->cache;
770 assert(cache_info->signature == MagickCoreSignature);
772 Pixels are stored in a temporary buffer until they are synced to the cache.
774 number_pixels=(MagickSizeType) columns*rows;
775 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
776 if (cache_info->number_channels == 0)
777 length=(size_t) number_pixels*sizeof(Quantum);
778 if (cache_info->metacontent_extent != 0)
779 length+=number_pixels*cache_info->metacontent_extent;
780 if (cache_info->pixels == (Quantum *) NULL)
782 cache_info->length=length;
783 status=AcquireStreamPixels(cache_info,exception);
784 if (status == MagickFalse)
786 cache_info->length=0;
787 return((Quantum *) NULL);
791 if (cache_info->length < length)
793 RelinquishStreamPixels(cache_info);
794 cache_info->length=length;
795 status=AcquireStreamPixels(cache_info,exception);
796 if (status == MagickFalse)
798 cache_info->length=0;
799 return((Quantum *) NULL);
802 cache_info->metacontent=(void *) NULL;
803 if (cache_info->metacontent_extent != 0)
804 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
805 cache_info->number_channels);
806 return(cache_info->pixels);
810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
814 + O p e n S t r e a m %
818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820 % OpenStream() opens a stream for writing by the StreamImage() method.
822 % The format of the OpenStream method is:
824 % MagickBooleanType OpenStream(const ImageInfo *image_info,
825 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
827 % A description of each parameter follows:
829 % o image_info: the image info.
831 % o stream_info: the stream info.
833 % o filename: the stream filename.
835 % o exception: return any errors or warnings in this structure.
838 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
839 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
844 (void) CopyMagickString(stream_info->stream->filename,filename,
846 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
855 + 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 %
859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
861 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
862 % defined by the region rectangle and returns a pointer to the area. This
863 % area is subsequently transferred from the pixel cache with method
864 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
865 % pixels are transferred, otherwise a NULL is returned.
867 % The format of the QueueAuthenticPixelsStream() method is:
869 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
870 % const ssize_t y,const size_t columns,const size_t rows,
871 % ExceptionInfo *exception)
873 % A description of each parameter follows:
875 % o image: the image.
877 % o x,y,columns,rows: These values define the perimeter of a region of
881 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
882 const ssize_t y,const size_t columns,const size_t rows,
883 ExceptionInfo *exception)
901 Validate pixel cache geometry.
903 assert(image != (Image *) NULL);
904 if ((x < 0) || (y < 0) ||
905 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
906 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
907 (columns == 0) || (rows == 0))
909 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
910 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
911 return((Quantum *) NULL);
913 stream_handler=GetBlobStreamHandler(image);
914 if (stream_handler == (StreamHandler) NULL)
916 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
917 "NoStreamHandlerIsDefined","`%s'",image->filename);
918 return((Quantum *) NULL);
920 cache_info=(CacheInfo *) image->cache;
921 assert(cache_info->signature == MagickCoreSignature);
922 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
923 (image->colorspace != GetPixelCacheColorspace(image->cache)))
925 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
926 (void) stream_handler(image,(const void *) NULL,(size_t)
927 cache_info->columns);
928 cache_info->storage_class=image->storage_class;
929 cache_info->colorspace=image->colorspace;
930 cache_info->columns=image->columns;
931 cache_info->rows=image->rows;
932 image->cache=cache_info;
935 Pixels are stored in a temporary buffer until they are synced to the cache.
937 cache_info->columns=columns;
938 cache_info->rows=rows;
939 number_pixels=(MagickSizeType) columns*rows;
940 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
941 if (cache_info->number_channels == 0)
942 length=(size_t) number_pixels*sizeof(Quantum);
943 if (cache_info->metacontent_extent != 0)
944 length+=number_pixels*cache_info->metacontent_extent;
945 if (cache_info->pixels == (Quantum *) NULL)
947 cache_info->length=length;
948 status=AcquireStreamPixels(cache_info,exception);
949 if (status == MagickFalse)
951 cache_info->length=0;
952 return((Quantum *) NULL);
956 if (cache_info->length < length)
958 RelinquishStreamPixels(cache_info);
959 cache_info->length=length;
960 status=AcquireStreamPixels(cache_info,exception);
961 if (status == MagickFalse)
963 cache_info->length=0;
964 return((Quantum *) NULL);
967 cache_info->metacontent=(void *) NULL;
968 if (cache_info->metacontent_extent != 0)
969 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
970 cache_info->number_channels);
971 return(cache_info->pixels);
975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 % R e a d S t r e a m %
983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
985 % ReadStream() makes the image pixels available to a user supplied callback
986 % method immediately upon reading a scanline with the ReadImage() method.
988 % The format of the ReadStream() method is:
990 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
991 % ExceptionInfo *exception)
993 % A description of each parameter follows:
995 % o image_info: the image info.
997 % o stream: a callback method.
999 % o exception: return any errors or warnings in this structure.
1002 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
1003 ExceptionInfo *exception)
1015 Stream image pixels.
1017 assert(image_info != (ImageInfo *) NULL);
1018 assert(image_info->signature == MagickCoreSignature);
1019 if (image_info->debug != MagickFalse)
1020 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1021 image_info->filename);
1022 assert(exception != (ExceptionInfo *) NULL);
1023 assert(exception->signature == MagickCoreSignature);
1024 read_info=CloneImageInfo(image_info);
1025 read_info->cache=AcquirePixelCache(0);
1026 GetPixelCacheMethods(&cache_methods);
1027 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
1028 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
1029 cache_methods.get_virtual_metacontent_from_handler=
1030 GetVirtualMetacontentFromStream;
1031 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
1032 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1033 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1034 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1035 cache_methods.get_authentic_metacontent_from_handler=
1036 GetAuthenticMetacontentFromStream;
1037 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1038 cache_methods.get_one_authentic_pixel_from_handler=
1039 GetOneAuthenticPixelFromStream;
1040 cache_methods.destroy_pixel_handler=DestroyPixelStream;
1041 SetPixelCacheMethods(read_info->cache,&cache_methods);
1042 read_info->stream=stream;
1043 image=ReadImage(read_info,exception);
1044 if (image != (Image *) NULL)
1046 InitializePixelChannelMap(image);
1047 ResetPixelCacheChannels(image);
1049 read_info=DestroyImageInfo(read_info);
1054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 + R e s e t S t r e a m A n o n y m o u s M e m o r y %
1062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 % ResetStreamAnonymousMemory() resets the anonymous_memory value.
1066 % The format of the ResetStreamAnonymousMemory method is:
1068 % void ResetStreamAnonymousMemory(void)
1071 MagickPrivate void ResetStreamAnonymousMemory(void)
1073 cache_anonymous_memory=0;
1077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 + S e t S t r e a m I n f o C l i e n t D a t a %
1085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % SetStreamInfoClientData() sets the stream info client data.
1089 % The format of the SetStreamInfoClientData method is:
1091 % void SetStreamInfoClientData(StreamInfo *stream_info,
1092 % const void *client_data)
1094 % A description of each parameter follows:
1096 % o stream_info: the stream info.
1098 % o client_data: the client data.
1101 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1102 const void *client_data)
1104 assert(stream_info != (StreamInfo *) NULL);
1105 assert(stream_info->signature == MagickCoreSignature);
1106 stream_info->client_data=client_data;
1110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1114 + S e t S t r e a m I n f o M a p %
1118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1120 % SetStreamInfoMap() sets the stream info map member.
1122 % The format of the SetStreamInfoMap method is:
1124 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1126 % A description of each parameter follows:
1128 % o stream_info: the stream info.
1133 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1135 assert(stream_info != (StreamInfo *) NULL);
1136 assert(stream_info->signature == MagickCoreSignature);
1137 (void) CloneString(&stream_info->map,map);
1141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1145 + S e t S t r e a m I n f o S t o r a g e T y p e %
1149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1151 % SetStreamInfoStorageType() sets the stream info storage type member.
1153 % The format of the SetStreamInfoStorageType method is:
1155 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1156 % const StoreageType *storage_type)
1158 % A description of each parameter follows:
1160 % o stream_info: the stream info.
1162 % o storage_type: the storage type.
1165 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1166 const StorageType storage_type)
1168 assert(stream_info != (StreamInfo *) NULL);
1169 assert(stream_info->signature == MagickCoreSignature);
1170 stream_info->storage_type=storage_type;
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1178 + S t r e a m I m a g e %
1182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1184 % StreamImage() streams pixels from an image and writes them in a user
1185 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1187 % The format of the StreamImage() method is:
1189 % Image *StreamImage(const ImageInfo *image_info,
1190 % StreamInfo *stream_info,ExceptionInfo *exception)
1192 % A description of each parameter follows:
1194 % o image_info: the image info.
1196 % o stream_info: the stream info.
1198 % o exception: return any errors or warnings in this structure.
1202 #if defined(__cplusplus) || defined(c_plusplus)
1206 static size_t WriteStreamImage(const Image *image,const void *pixels,
1207 const size_t columns)
1226 stream_info=(StreamInfo *) image->client_data;
1227 switch (stream_info->storage_type)
1229 default: packet_size=sizeof(unsigned char); break;
1230 case CharPixel: packet_size=sizeof(unsigned char); break;
1231 case DoublePixel: packet_size=sizeof(double); break;
1232 case FloatPixel: packet_size=sizeof(float); break;
1233 case LongPixel: packet_size=sizeof(unsigned int); break;
1234 case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
1235 case QuantumPixel: packet_size=sizeof(Quantum); break;
1236 case ShortPixel: packet_size=sizeof(unsigned short); break;
1238 cache_info=(CacheInfo *) image->cache;
1239 assert(cache_info->signature == MagickCoreSignature);
1240 packet_size*=strlen(stream_info->map);
1241 length=packet_size*cache_info->columns*cache_info->rows;
1242 if (image != stream_info->image)
1248 Prepare stream for writing.
1250 (void) RelinquishAlignedMemory(stream_info->pixels);
1251 stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
1252 if (stream_info->pixels == (unsigned char *) NULL)
1254 (void) memset(stream_info->pixels,0,length);
1255 stream_info->image=image;
1256 write_info=CloneImageInfo(stream_info->image_info);
1257 (void) SetImageInfo(write_info,1,stream_info->exception);
1258 if (write_info->extract != (char *) NULL)
1259 (void) ParseAbsoluteGeometry(write_info->extract,
1260 &stream_info->extract_info);
1262 write_info=DestroyImageInfo(write_info);
1264 extract_info=stream_info->extract_info;
1265 if ((extract_info.width == 0) || (extract_info.height == 0))
1268 Write all pixels to stream.
1270 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1271 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1273 return(count == 0 ? 0 : columns);
1275 if ((stream_info->y < extract_info.y) ||
1276 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1282 Write a portion of the pixel row to the stream.
1284 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1285 length=packet_size*extract_info.width;
1286 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1289 return(count == 0 ? 0 : columns);
1292 #if defined(__cplusplus) || defined(c_plusplus)
1296 MagickExport Image *StreamImage(const ImageInfo *image_info,
1297 StreamInfo *stream_info,ExceptionInfo *exception)
1305 assert(image_info != (const ImageInfo *) NULL);
1306 assert(image_info->signature == MagickCoreSignature);
1307 if (image_info->debug != MagickFalse)
1308 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1309 image_info->filename);
1310 assert(stream_info != (StreamInfo *) NULL);
1311 assert(stream_info->signature == MagickCoreSignature);
1312 assert(exception != (ExceptionInfo *) NULL);
1313 read_info=CloneImageInfo(image_info);
1314 stream_info->image_info=image_info;
1315 stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
1316 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1318 read_info=DestroyImageInfo(read_info);
1319 return((Image *) NULL);
1321 stream_info->exception=exception;
1322 read_info->client_data=(void *) stream_info;
1323 image=ReadStream(read_info,&WriteStreamImage,exception);
1324 read_info=DestroyImageInfo(read_info);
1325 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1326 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1327 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1328 image=DestroyImage(image);
1333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337 + S t r e a m I m a g e P i x e l s %
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1343 % StreamImagePixels() extracts pixel data from an image and returns it in the
1344 % stream_info->pixels structure in the format as defined by
1345 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1347 % The format of the StreamImagePixels method is:
1349 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1350 % const Image *image,ExceptionInfo *exception)
1352 % A description of each parameter follows:
1354 % o stream_info: the stream info.
1356 % o image: the image.
1358 % o exception: return any errors or warnings in this structure.
1361 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1362 const Image *image,ExceptionInfo *exception)
1370 register const Quantum
1380 assert(stream_info != (StreamInfo *) NULL);
1381 assert(stream_info->signature == MagickCoreSignature);
1382 assert(image != (Image *) NULL);
1383 assert(image->signature == MagickCoreSignature);
1384 if (image->debug != MagickFalse)
1385 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1386 length=strlen(stream_info->map);
1387 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1388 if (quantum_map == (QuantumType *) NULL)
1390 (void) ThrowMagickException(exception,GetMagickModule(),
1391 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1392 return(MagickFalse);
1394 for (i=0; i < (ssize_t) length; i++)
1396 switch (stream_info->map[i])
1401 quantum_map[i]=AlphaQuantum;
1407 quantum_map[i]=BlueQuantum;
1413 quantum_map[i]=CyanQuantum;
1414 if (image->colorspace == CMYKColorspace)
1416 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1417 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1418 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1419 return(MagickFalse);
1424 quantum_map[i]=GreenQuantum;
1430 quantum_map[i]=IndexQuantum;
1436 quantum_map[i]=BlackQuantum;
1437 if (image->colorspace == CMYKColorspace)
1439 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1440 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1441 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1442 return(MagickFalse);
1447 quantum_map[i]=MagentaQuantum;
1448 if (image->colorspace == CMYKColorspace)
1450 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1451 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1452 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1453 return(MagickFalse);
1458 quantum_map[i]=OpacityQuantum;
1464 quantum_map[i]=UndefinedQuantum;
1470 quantum_map[i]=RedQuantum;
1476 quantum_map[i]=YellowQuantum;
1477 if (image->colorspace == CMYKColorspace)
1479 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1480 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1481 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1482 return(MagickFalse);
1486 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1487 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1488 "UnrecognizedPixelMap","`%s'",stream_info->map);
1489 return(MagickFalse);
1493 quantum_info=stream_info->quantum_info;
1494 switch (stream_info->storage_type)
1498 register unsigned char
1501 q=(unsigned char *) stream_info->pixels;
1502 if (LocaleCompare(stream_info->map,"BGR") == 0)
1504 p=GetAuthenticPixelQueue(image);
1505 if (p == (const Quantum *) NULL)
1507 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1509 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1510 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1511 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1512 p+=GetPixelChannels(image);
1516 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1518 p=GetAuthenticPixelQueue(image);
1519 if (p == (const Quantum *) NULL)
1521 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1523 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1524 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1525 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1526 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1527 p+=GetPixelChannels(image);
1531 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1533 p=GetAuthenticPixelQueue(image);
1534 if (p == (const Quantum *) NULL)
1536 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1538 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1539 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1540 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1541 *q++=ScaleQuantumToChar((Quantum) 0);
1542 p+=GetPixelChannels(image);
1546 if (LocaleCompare(stream_info->map,"I") == 0)
1548 p=GetAuthenticPixelQueue(image);
1549 if (p == (const Quantum *) NULL)
1551 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1553 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1554 p+=GetPixelChannels(image);
1558 if (LocaleCompare(stream_info->map,"RGB") == 0)
1560 p=GetAuthenticPixelQueue(image);
1561 if (p == (const Quantum *) NULL)
1563 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1565 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1566 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1567 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1568 p+=GetPixelChannels(image);
1572 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1574 p=GetAuthenticPixelQueue(image);
1575 if (p == (const Quantum *) NULL)
1577 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1579 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1580 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1581 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1582 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1583 p+=GetPixelChannels(image);
1587 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1589 p=GetAuthenticPixelQueue(image);
1590 if (p == (const Quantum *) NULL)
1592 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1594 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1595 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1596 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1597 *q++=ScaleQuantumToChar((Quantum) 0);
1598 p+=GetPixelChannels(image);
1602 p=GetAuthenticPixelQueue(image);
1603 if (p == (const Quantum *) NULL)
1605 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1607 for (i=0; i < (ssize_t) length; i++)
1610 switch (quantum_map[i])
1615 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1619 case MagentaQuantum:
1621 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1627 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1632 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1635 case OpacityQuantum:
1637 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1642 if (image->colorspace == CMYKColorspace)
1643 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1648 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1656 p+=GetPixelChannels(image);
1665 q=(double *) stream_info->pixels;
1666 if (LocaleCompare(stream_info->map,"BGR") == 0)
1668 p=GetAuthenticPixelQueue(image);
1669 if (p == (const Quantum *) NULL)
1671 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1673 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1674 quantum_info->scale+quantum_info->minimum);
1675 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1676 quantum_info->scale+quantum_info->minimum);
1677 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1678 quantum_info->scale+quantum_info->minimum);
1679 p+=GetPixelChannels(image);
1683 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1685 p=GetAuthenticPixelQueue(image);
1686 if (p == (const Quantum *) NULL)
1688 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1690 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1691 quantum_info->scale+quantum_info->minimum);
1692 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1693 quantum_info->scale+quantum_info->minimum);
1694 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1695 quantum_info->scale+quantum_info->minimum);
1696 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1697 quantum_info->scale+quantum_info->minimum);
1698 p+=GetPixelChannels(image);
1702 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1704 p=GetAuthenticPixelQueue(image);
1705 if (p == (const Quantum *) NULL)
1707 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1709 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1710 quantum_info->scale+quantum_info->minimum);
1711 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1712 quantum_info->scale+quantum_info->minimum);
1713 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1714 quantum_info->scale+quantum_info->minimum);
1716 p+=GetPixelChannels(image);
1720 if (LocaleCompare(stream_info->map,"I") == 0)
1722 p=GetAuthenticPixelQueue(image);
1723 if (p == (const Quantum *) NULL)
1725 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1727 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1728 quantum_info->scale+quantum_info->minimum);
1729 p+=GetPixelChannels(image);
1733 if (LocaleCompare(stream_info->map,"RGB") == 0)
1735 p=GetAuthenticPixelQueue(image);
1736 if (p == (const Quantum *) NULL)
1738 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1740 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1741 quantum_info->scale+quantum_info->minimum);
1742 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1743 quantum_info->scale+quantum_info->minimum);
1744 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1745 quantum_info->scale+quantum_info->minimum);
1746 p+=GetPixelChannels(image);
1750 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1752 p=GetAuthenticPixelQueue(image);
1753 if (p == (const Quantum *) NULL)
1755 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1757 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1758 quantum_info->scale+quantum_info->minimum);
1759 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1760 quantum_info->scale+quantum_info->minimum);
1761 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1762 quantum_info->scale+quantum_info->minimum);
1763 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1764 quantum_info->scale+quantum_info->minimum);
1765 p+=GetPixelChannels(image);
1769 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1771 p=GetAuthenticPixelQueue(image);
1772 if (p == (const Quantum *) NULL)
1774 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1776 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1777 quantum_info->scale+quantum_info->minimum);
1778 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1779 quantum_info->scale+quantum_info->minimum);
1780 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1781 quantum_info->scale+quantum_info->minimum);
1783 p+=GetPixelChannels(image);
1787 p=GetAuthenticPixelQueue(image);
1788 if (p == (const Quantum *) NULL)
1790 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1792 for (i=0; i < (ssize_t) length; i++)
1795 switch (quantum_map[i])
1800 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1801 quantum_info->scale+quantum_info->minimum);
1805 case MagentaQuantum:
1807 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1808 quantum_info->scale+quantum_info->minimum);
1814 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1815 quantum_info->scale+quantum_info->minimum);
1820 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1821 quantum_info->scale+quantum_info->minimum);
1824 case OpacityQuantum:
1826 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1827 quantum_info->scale+quantum_info->minimum);
1832 if (image->colorspace == CMYKColorspace)
1833 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1834 quantum_info->scale+quantum_info->minimum);
1839 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1848 p+=GetPixelChannels(image);
1857 q=(float *) stream_info->pixels;
1858 if (LocaleCompare(stream_info->map,"BGR") == 0)
1860 p=GetAuthenticPixelQueue(image);
1861 if (p == (const Quantum *) NULL)
1863 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1865 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1866 quantum_info->scale+quantum_info->minimum);
1867 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1868 quantum_info->scale+quantum_info->minimum);
1869 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1870 quantum_info->scale+quantum_info->minimum);
1871 p+=GetPixelChannels(image);
1875 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1877 p=GetAuthenticPixelQueue(image);
1878 if (p == (const Quantum *) NULL)
1880 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1882 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1883 quantum_info->scale+quantum_info->minimum);
1884 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1885 quantum_info->scale+quantum_info->minimum);
1886 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1887 quantum_info->scale+quantum_info->minimum);
1888 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1889 quantum_info->scale+quantum_info->minimum);
1890 p+=GetPixelChannels(image);
1894 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1896 p=GetAuthenticPixelQueue(image);
1897 if (p == (const Quantum *) NULL)
1899 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1901 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1902 quantum_info->scale+quantum_info->minimum);
1903 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1904 quantum_info->scale+quantum_info->minimum);
1905 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1906 quantum_info->scale+quantum_info->minimum);
1908 p+=GetPixelChannels(image);
1912 if (LocaleCompare(stream_info->map,"I") == 0)
1914 p=GetAuthenticPixelQueue(image);
1915 if (p == (const Quantum *) NULL)
1917 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1919 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1920 quantum_info->scale+quantum_info->minimum);
1921 p+=GetPixelChannels(image);
1925 if (LocaleCompare(stream_info->map,"RGB") == 0)
1927 p=GetAuthenticPixelQueue(image);
1928 if (p == (const Quantum *) NULL)
1930 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1932 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1933 quantum_info->scale+quantum_info->minimum);
1934 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1935 quantum_info->scale+quantum_info->minimum);
1936 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1937 quantum_info->scale+quantum_info->minimum);
1938 p+=GetPixelChannels(image);
1942 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1944 p=GetAuthenticPixelQueue(image);
1945 if (p == (const Quantum *) NULL)
1947 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1949 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1950 quantum_info->scale+quantum_info->minimum);
1951 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1952 quantum_info->scale+quantum_info->minimum);
1953 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1954 quantum_info->scale+quantum_info->minimum);
1955 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1956 quantum_info->scale+quantum_info->minimum);
1957 p+=GetPixelChannels(image);
1961 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1963 p=GetAuthenticPixelQueue(image);
1964 if (p == (const Quantum *) NULL)
1966 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1968 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1969 quantum_info->scale+quantum_info->minimum);
1970 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1971 quantum_info->scale+quantum_info->minimum);
1972 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1973 quantum_info->scale+quantum_info->minimum);
1975 p+=GetPixelChannels(image);
1979 p=GetAuthenticPixelQueue(image);
1980 if (p == (const Quantum *) NULL)
1982 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1984 for (i=0; i < (ssize_t) length; i++)
1987 switch (quantum_map[i])
1992 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1993 quantum_info->scale+quantum_info->minimum);
1997 case MagentaQuantum:
1999 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
2000 quantum_info->scale+quantum_info->minimum);
2006 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
2007 quantum_info->scale+quantum_info->minimum);
2012 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
2013 quantum_info->scale+quantum_info->minimum);
2016 case OpacityQuantum:
2018 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
2019 quantum_info->scale+quantum_info->minimum);
2024 if (image->colorspace == CMYKColorspace)
2025 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
2026 quantum_info->scale+quantum_info->minimum);
2031 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
2032 quantum_info->scale+quantum_info->minimum);
2040 p+=GetPixelChannels(image);
2046 register unsigned int
2049 q=(unsigned int *) stream_info->pixels;
2050 if (LocaleCompare(stream_info->map,"BGR") == 0)
2052 p=GetAuthenticPixelQueue(image);
2053 if (p == (const Quantum *) NULL)
2055 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2057 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2058 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2059 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2060 p+=GetPixelChannels(image);
2064 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2066 p=GetAuthenticPixelQueue(image);
2067 if (p == (const Quantum *) NULL)
2069 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2071 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2072 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2073 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2074 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2075 p+=GetPixelChannels(image);
2079 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2081 p=GetAuthenticPixelQueue(image);
2082 if (p == (const Quantum *) NULL)
2084 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2086 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2087 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2088 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2090 p+=GetPixelChannels(image);
2094 if (LocaleCompare(stream_info->map,"I") == 0)
2096 p=GetAuthenticPixelQueue(image);
2097 if (p == (const Quantum *) NULL)
2099 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2101 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2102 p+=GetPixelChannels(image);
2106 if (LocaleCompare(stream_info->map,"RGB") == 0)
2108 p=GetAuthenticPixelQueue(image);
2109 if (p == (const Quantum *) NULL)
2111 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2113 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2114 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2115 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2116 p+=GetPixelChannels(image);
2120 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2122 p=GetAuthenticPixelQueue(image);
2123 if (p == (const Quantum *) NULL)
2125 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2127 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2128 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2129 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2130 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2131 p+=GetPixelChannels(image);
2135 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2137 p=GetAuthenticPixelQueue(image);
2138 if (p == (const Quantum *) NULL)
2140 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2142 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2143 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2144 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2146 p+=GetPixelChannels(image);
2150 p=GetAuthenticPixelQueue(image);
2151 if (p == (const Quantum *) NULL)
2153 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2155 for (i=0; i < (ssize_t) length; i++)
2158 switch (quantum_map[i])
2163 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2167 case MagentaQuantum:
2169 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2175 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2180 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2183 case OpacityQuantum:
2185 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2190 if (image->colorspace == CMYKColorspace)
2191 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2196 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2204 p+=GetPixelChannels(image);
2210 register MagickSizeType
2213 q=(MagickSizeType *) stream_info->pixels;
2214 if (LocaleCompare(stream_info->map,"BGR") == 0)
2216 p=GetAuthenticPixelQueue(image);
2217 if (p == (const Quantum *) NULL)
2219 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2221 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2222 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2223 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2224 p+=GetPixelChannels(image);
2228 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2230 p=GetAuthenticPixelQueue(image);
2231 if (p == (const Quantum *) NULL)
2233 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2235 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2236 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2237 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2238 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2239 p+=GetPixelChannels(image);
2243 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2245 p=GetAuthenticPixelQueue(image);
2246 if (p == (const Quantum *) NULL)
2248 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2250 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2251 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2252 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2254 p+=GetPixelChannels(image);
2258 if (LocaleCompare(stream_info->map,"I") == 0)
2260 p=GetAuthenticPixelQueue(image);
2261 if (p == (const Quantum *) NULL)
2263 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2265 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2266 GetPixelIntensity(image,p)));
2267 p+=GetPixelChannels(image);
2271 if (LocaleCompare(stream_info->map,"RGB") == 0)
2273 p=GetAuthenticPixelQueue(image);
2274 if (p == (const Quantum *) NULL)
2276 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2278 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2279 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2280 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2281 p+=GetPixelChannels(image);
2285 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2287 p=GetAuthenticPixelQueue(image);
2288 if (p == (const Quantum *) NULL)
2290 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2292 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2293 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2294 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2295 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2296 p+=GetPixelChannels(image);
2300 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2302 p=GetAuthenticPixelQueue(image);
2303 if (p == (const Quantum *) NULL)
2305 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2307 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2308 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2309 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2311 p+=GetPixelChannels(image);
2315 p=GetAuthenticPixelQueue(image);
2316 if (p == (const Quantum *) NULL)
2318 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2320 for (i=0; i < (ssize_t) length; i++)
2323 switch (quantum_map[i])
2328 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2332 case MagentaQuantum:
2334 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2340 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2345 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2348 case OpacityQuantum:
2350 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2355 if (image->colorspace == CMYKColorspace)
2356 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2361 *q=ScaleQuantumToLongLong(ClampToQuantum(
2362 GetPixelIntensity(image,p)));
2370 p+=GetPixelChannels(image);
2379 q=(Quantum *) stream_info->pixels;
2380 if (LocaleCompare(stream_info->map,"BGR") == 0)
2382 p=GetAuthenticPixelQueue(image);
2383 if (p == (const Quantum *) NULL)
2385 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2387 *q++=GetPixelBlue(image,p);
2388 *q++=GetPixelGreen(image,p);
2389 *q++=GetPixelRed(image,p);
2390 p+=GetPixelChannels(image);
2394 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2396 p=GetAuthenticPixelQueue(image);
2397 if (p == (const Quantum *) NULL)
2399 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2401 *q++=GetPixelBlue(image,p);
2402 *q++=GetPixelGreen(image,p);
2403 *q++=GetPixelRed(image,p);
2404 *q++=GetPixelAlpha(image,p);
2405 p+=GetPixelChannels(image);
2409 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2411 p=GetAuthenticPixelQueue(image);
2412 if (p == (const Quantum *) NULL)
2414 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2416 *q++=GetPixelBlue(image,p);
2417 *q++=GetPixelGreen(image,p);
2418 *q++=GetPixelRed(image,p);
2420 p+=GetPixelChannels(image);
2424 if (LocaleCompare(stream_info->map,"I") == 0)
2426 p=GetAuthenticPixelQueue(image);
2427 if (p == (const Quantum *) NULL)
2429 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2431 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2432 p+=GetPixelChannels(image);
2436 if (LocaleCompare(stream_info->map,"RGB") == 0)
2438 p=GetAuthenticPixelQueue(image);
2439 if (p == (const Quantum *) NULL)
2441 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2443 *q++=GetPixelRed(image,p);
2444 *q++=GetPixelGreen(image,p);
2445 *q++=GetPixelBlue(image,p);
2446 p+=GetPixelChannels(image);
2450 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2452 p=GetAuthenticPixelQueue(image);
2453 if (p == (const Quantum *) NULL)
2455 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2457 *q++=GetPixelRed(image,p);
2458 *q++=GetPixelGreen(image,p);
2459 *q++=GetPixelBlue(image,p);
2460 *q++=GetPixelAlpha(image,p);
2461 p+=GetPixelChannels(image);
2465 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2467 p=GetAuthenticPixelQueue(image);
2468 if (p == (const Quantum *) NULL)
2470 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2472 *q++=GetPixelRed(image,p);
2473 *q++=GetPixelGreen(image,p);
2474 *q++=GetPixelBlue(image,p);
2476 p+=GetPixelChannels(image);
2480 p=GetAuthenticPixelQueue(image);
2481 if (p == (const Quantum *) NULL)
2483 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2485 for (i=0; i < (ssize_t) length; i++)
2488 switch (quantum_map[i])
2493 *q=GetPixelRed(image,p);
2497 case MagentaQuantum:
2499 *q=GetPixelGreen(image,p);
2505 *q=GetPixelBlue(image,p);
2510 *q=(Quantum) (GetPixelAlpha(image,p));
2513 case OpacityQuantum:
2515 *q=GetPixelAlpha(image,p);
2520 if (image->colorspace == CMYKColorspace)
2521 *q=GetPixelBlack(image,p);
2526 *q=ClampToQuantum(GetPixelIntensity(image,p));
2534 p+=GetPixelChannels(image);
2540 register unsigned short
2543 q=(unsigned short *) stream_info->pixels;
2544 if (LocaleCompare(stream_info->map,"BGR") == 0)
2546 p=GetAuthenticPixelQueue(image);
2547 if (p == (const Quantum *) NULL)
2549 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2551 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2552 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2553 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2554 p+=GetPixelChannels(image);
2558 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2560 p=GetAuthenticPixelQueue(image);
2561 if (p == (const Quantum *) NULL)
2563 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2565 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2566 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2567 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2568 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2569 p+=GetPixelChannels(image);
2573 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2575 p=GetAuthenticPixelQueue(image);
2576 if (p == (const Quantum *) NULL)
2578 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2580 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2581 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2582 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2584 p+=GetPixelChannels(image);
2588 if (LocaleCompare(stream_info->map,"I") == 0)
2590 p=GetAuthenticPixelQueue(image);
2591 if (p == (const Quantum *) NULL)
2593 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2595 *q++=ScaleQuantumToShort(ClampToQuantum(
2596 GetPixelIntensity(image,p)));
2597 p+=GetPixelChannels(image);
2601 if (LocaleCompare(stream_info->map,"RGB") == 0)
2603 p=GetAuthenticPixelQueue(image);
2604 if (p == (const Quantum *) NULL)
2606 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2608 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2609 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2610 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2611 p+=GetPixelChannels(image);
2615 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2617 p=GetAuthenticPixelQueue(image);
2618 if (p == (const Quantum *) NULL)
2620 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2622 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2623 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2624 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2625 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2626 p+=GetPixelChannels(image);
2630 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2632 p=GetAuthenticPixelQueue(image);
2633 if (p == (const Quantum *) NULL)
2635 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2637 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2638 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2639 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2641 p+=GetPixelChannels(image);
2645 p=GetAuthenticPixelQueue(image);
2646 if (p == (const Quantum *) NULL)
2648 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2650 for (i=0; i < (ssize_t) length; i++)
2653 switch (quantum_map[i])
2658 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2662 case MagentaQuantum:
2664 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2670 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2675 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2678 case OpacityQuantum:
2680 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2685 if (image->colorspace == CMYKColorspace)
2686 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2691 *q=ScaleQuantumToShort(ClampToQuantum(
2692 GetPixelIntensity(image,p)));
2700 p+=GetPixelChannels(image);
2706 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2707 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2708 "UnrecognizedPixelMap","`%s'",stream_info->map);
2712 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2721 + 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 %
2725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2727 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2728 % the latest stream of pixels.
2730 % The format of the SyncAuthenticPixelsStream method is:
2732 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2733 % ExceptionInfo *exception)
2735 % A description of each parameter follows:
2737 % o image: the image.
2739 % o exception: return any errors or warnings in this structure.
2742 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2743 ExceptionInfo *exception)
2754 assert(image != (Image *) NULL);
2755 assert(image->signature == MagickCoreSignature);
2756 if (image->debug != MagickFalse)
2757 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2758 cache_info=(CacheInfo *) image->cache;
2759 assert(cache_info->signature == MagickCoreSignature);
2760 stream_handler=GetBlobStreamHandler(image);
2761 if (stream_handler == (StreamHandler) NULL)
2763 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2764 "NoStreamHandlerIsDefined","`%s'",image->filename);
2765 return(MagickFalse);
2767 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2768 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2776 % W r i t e S t r e a m %
2780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2782 % WriteStream() makes the image pixels available to a user supplied callback
2783 % method immediately upon writing pixel data with the WriteImage() method.
2785 % The format of the WriteStream() method is:
2787 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2788 % StreamHandler stream,ExceptionInfo *exception)
2790 % A description of each parameter follows:
2792 % o image_info: the image info.
2794 % o stream: A callback method.
2796 % o exception: return any errors or warnings in this structure.
2799 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2800 Image *image,StreamHandler stream,ExceptionInfo *exception)
2808 assert(image_info != (ImageInfo *) NULL);
2809 assert(image_info->signature == MagickCoreSignature);
2810 if (image_info->debug != MagickFalse)
2811 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2812 image_info->filename);
2813 assert(image != (Image *) NULL);
2814 assert(image->signature == MagickCoreSignature);
2815 write_info=CloneImageInfo(image_info);
2816 *write_info->magick='\0';
2817 write_info->stream=stream;
2818 status=WriteImage(write_info,image,exception);
2819 write_info=DestroyImageInfo(write_info);