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 (void) memset(quantum_map,0,length*sizeof(*quantum_map));
1395 for (i=0; i < (ssize_t) length; i++)
1397 switch (stream_info->map[i])
1402 quantum_map[i]=AlphaQuantum;
1408 quantum_map[i]=BlueQuantum;
1414 quantum_map[i]=CyanQuantum;
1415 if (image->colorspace == CMYKColorspace)
1417 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1418 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1419 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1420 return(MagickFalse);
1425 quantum_map[i]=GreenQuantum;
1431 quantum_map[i]=IndexQuantum;
1437 quantum_map[i]=BlackQuantum;
1438 if (image->colorspace == CMYKColorspace)
1440 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1441 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1442 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1443 return(MagickFalse);
1448 quantum_map[i]=MagentaQuantum;
1449 if (image->colorspace == CMYKColorspace)
1451 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1452 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1453 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1454 return(MagickFalse);
1459 quantum_map[i]=OpacityQuantum;
1465 quantum_map[i]=UndefinedQuantum;
1471 quantum_map[i]=RedQuantum;
1477 quantum_map[i]=YellowQuantum;
1478 if (image->colorspace == CMYKColorspace)
1480 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1481 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1482 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1483 return(MagickFalse);
1487 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1488 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1489 "UnrecognizedPixelMap","`%s'",stream_info->map);
1490 return(MagickFalse);
1494 quantum_info=stream_info->quantum_info;
1495 switch (stream_info->storage_type)
1499 register unsigned char
1502 q=(unsigned char *) stream_info->pixels;
1503 if (LocaleCompare(stream_info->map,"BGR") == 0)
1505 p=GetAuthenticPixelQueue(image);
1506 if (p == (const Quantum *) NULL)
1508 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1510 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1511 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1512 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1513 p+=GetPixelChannels(image);
1517 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1519 p=GetAuthenticPixelQueue(image);
1520 if (p == (const Quantum *) NULL)
1522 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1524 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1525 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1526 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1527 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1528 p+=GetPixelChannels(image);
1532 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1534 p=GetAuthenticPixelQueue(image);
1535 if (p == (const Quantum *) NULL)
1537 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1539 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1540 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1541 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1542 *q++=ScaleQuantumToChar((Quantum) 0);
1543 p+=GetPixelChannels(image);
1547 if (LocaleCompare(stream_info->map,"I") == 0)
1549 p=GetAuthenticPixelQueue(image);
1550 if (p == (const Quantum *) NULL)
1552 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1554 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1555 p+=GetPixelChannels(image);
1559 if (LocaleCompare(stream_info->map,"RGB") == 0)
1561 p=GetAuthenticPixelQueue(image);
1562 if (p == (const Quantum *) NULL)
1564 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1566 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1567 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1568 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1569 p+=GetPixelChannels(image);
1573 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1575 p=GetAuthenticPixelQueue(image);
1576 if (p == (const Quantum *) NULL)
1578 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1580 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1581 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1582 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1583 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1584 p+=GetPixelChannels(image);
1588 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1590 p=GetAuthenticPixelQueue(image);
1591 if (p == (const Quantum *) NULL)
1593 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1595 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1596 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1597 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1598 *q++=ScaleQuantumToChar((Quantum) 0);
1599 p+=GetPixelChannels(image);
1603 p=GetAuthenticPixelQueue(image);
1604 if (p == (const Quantum *) NULL)
1606 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1608 for (i=0; i < (ssize_t) length; i++)
1611 switch (quantum_map[i])
1616 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1620 case MagentaQuantum:
1622 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1628 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1633 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1636 case OpacityQuantum:
1638 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1643 if (image->colorspace == CMYKColorspace)
1644 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1649 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1657 p+=GetPixelChannels(image);
1666 q=(double *) stream_info->pixels;
1667 if (LocaleCompare(stream_info->map,"BGR") == 0)
1669 p=GetAuthenticPixelQueue(image);
1670 if (p == (const Quantum *) NULL)
1672 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1674 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1675 quantum_info->scale+quantum_info->minimum);
1676 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1677 quantum_info->scale+quantum_info->minimum);
1678 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1679 quantum_info->scale+quantum_info->minimum);
1680 p+=GetPixelChannels(image);
1684 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1686 p=GetAuthenticPixelQueue(image);
1687 if (p == (const Quantum *) NULL)
1689 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1691 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1692 quantum_info->scale+quantum_info->minimum);
1693 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1694 quantum_info->scale+quantum_info->minimum);
1695 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1696 quantum_info->scale+quantum_info->minimum);
1697 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1698 quantum_info->scale+quantum_info->minimum);
1699 p+=GetPixelChannels(image);
1703 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1705 p=GetAuthenticPixelQueue(image);
1706 if (p == (const Quantum *) NULL)
1708 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1710 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1711 quantum_info->scale+quantum_info->minimum);
1712 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1713 quantum_info->scale+quantum_info->minimum);
1714 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1715 quantum_info->scale+quantum_info->minimum);
1717 p+=GetPixelChannels(image);
1721 if (LocaleCompare(stream_info->map,"I") == 0)
1723 p=GetAuthenticPixelQueue(image);
1724 if (p == (const Quantum *) NULL)
1726 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1728 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1729 quantum_info->scale+quantum_info->minimum);
1730 p+=GetPixelChannels(image);
1734 if (LocaleCompare(stream_info->map,"RGB") == 0)
1736 p=GetAuthenticPixelQueue(image);
1737 if (p == (const Quantum *) NULL)
1739 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1741 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1742 quantum_info->scale+quantum_info->minimum);
1743 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1744 quantum_info->scale+quantum_info->minimum);
1745 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1746 quantum_info->scale+quantum_info->minimum);
1747 p+=GetPixelChannels(image);
1751 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1753 p=GetAuthenticPixelQueue(image);
1754 if (p == (const Quantum *) NULL)
1756 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1758 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1759 quantum_info->scale+quantum_info->minimum);
1760 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1761 quantum_info->scale+quantum_info->minimum);
1762 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1763 quantum_info->scale+quantum_info->minimum);
1764 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1765 quantum_info->scale+quantum_info->minimum);
1766 p+=GetPixelChannels(image);
1770 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1772 p=GetAuthenticPixelQueue(image);
1773 if (p == (const Quantum *) NULL)
1775 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1777 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1778 quantum_info->scale+quantum_info->minimum);
1779 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1780 quantum_info->scale+quantum_info->minimum);
1781 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1782 quantum_info->scale+quantum_info->minimum);
1784 p+=GetPixelChannels(image);
1788 p=GetAuthenticPixelQueue(image);
1789 if (p == (const Quantum *) NULL)
1791 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1793 for (i=0; i < (ssize_t) length; i++)
1796 switch (quantum_map[i])
1801 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1802 quantum_info->scale+quantum_info->minimum);
1806 case MagentaQuantum:
1808 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1809 quantum_info->scale+quantum_info->minimum);
1815 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1816 quantum_info->scale+quantum_info->minimum);
1821 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1822 quantum_info->scale+quantum_info->minimum);
1825 case OpacityQuantum:
1827 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1828 quantum_info->scale+quantum_info->minimum);
1833 if (image->colorspace == CMYKColorspace)
1834 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1835 quantum_info->scale+quantum_info->minimum);
1840 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1841 quantum_info->scale+quantum_info->minimum);
1849 p+=GetPixelChannels(image);
1858 q=(float *) stream_info->pixels;
1859 if (LocaleCompare(stream_info->map,"BGR") == 0)
1861 p=GetAuthenticPixelQueue(image);
1862 if (p == (const Quantum *) NULL)
1864 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1866 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1867 quantum_info->scale+quantum_info->minimum);
1868 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1869 quantum_info->scale+quantum_info->minimum);
1870 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1871 quantum_info->scale+quantum_info->minimum);
1872 p+=GetPixelChannels(image);
1876 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1878 p=GetAuthenticPixelQueue(image);
1879 if (p == (const Quantum *) NULL)
1881 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1883 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1884 quantum_info->scale+quantum_info->minimum);
1885 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1886 quantum_info->scale+quantum_info->minimum);
1887 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1888 quantum_info->scale+quantum_info->minimum);
1889 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1890 quantum_info->scale+quantum_info->minimum);
1891 p+=GetPixelChannels(image);
1895 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1897 p=GetAuthenticPixelQueue(image);
1898 if (p == (const Quantum *) NULL)
1900 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1902 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1903 quantum_info->scale+quantum_info->minimum);
1904 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1905 quantum_info->scale+quantum_info->minimum);
1906 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1907 quantum_info->scale+quantum_info->minimum);
1909 p+=GetPixelChannels(image);
1913 if (LocaleCompare(stream_info->map,"I") == 0)
1915 p=GetAuthenticPixelQueue(image);
1916 if (p == (const Quantum *) NULL)
1918 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1920 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1921 quantum_info->scale+quantum_info->minimum);
1922 p+=GetPixelChannels(image);
1926 if (LocaleCompare(stream_info->map,"RGB") == 0)
1928 p=GetAuthenticPixelQueue(image);
1929 if (p == (const Quantum *) NULL)
1931 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1933 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1934 quantum_info->scale+quantum_info->minimum);
1935 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1936 quantum_info->scale+quantum_info->minimum);
1937 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1938 quantum_info->scale+quantum_info->minimum);
1939 p+=GetPixelChannels(image);
1943 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1945 p=GetAuthenticPixelQueue(image);
1946 if (p == (const Quantum *) NULL)
1948 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1950 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1951 quantum_info->scale+quantum_info->minimum);
1952 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1953 quantum_info->scale+quantum_info->minimum);
1954 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1955 quantum_info->scale+quantum_info->minimum);
1956 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1957 quantum_info->scale+quantum_info->minimum);
1958 p+=GetPixelChannels(image);
1962 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1964 p=GetAuthenticPixelQueue(image);
1965 if (p == (const Quantum *) NULL)
1967 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1969 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1970 quantum_info->scale+quantum_info->minimum);
1971 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1972 quantum_info->scale+quantum_info->minimum);
1973 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1974 quantum_info->scale+quantum_info->minimum);
1976 p+=GetPixelChannels(image);
1980 p=GetAuthenticPixelQueue(image);
1981 if (p == (const Quantum *) NULL)
1983 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1985 for (i=0; i < (ssize_t) length; i++)
1988 switch (quantum_map[i])
1993 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1994 quantum_info->scale+quantum_info->minimum);
1998 case MagentaQuantum:
2000 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
2001 quantum_info->scale+quantum_info->minimum);
2007 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
2008 quantum_info->scale+quantum_info->minimum);
2013 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
2014 quantum_info->scale+quantum_info->minimum);
2017 case OpacityQuantum:
2019 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
2020 quantum_info->scale+quantum_info->minimum);
2025 if (image->colorspace == CMYKColorspace)
2026 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
2027 quantum_info->scale+quantum_info->minimum);
2032 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
2033 quantum_info->scale+quantum_info->minimum);
2041 p+=GetPixelChannels(image);
2047 register unsigned int
2050 q=(unsigned int *) stream_info->pixels;
2051 if (LocaleCompare(stream_info->map,"BGR") == 0)
2053 p=GetAuthenticPixelQueue(image);
2054 if (p == (const Quantum *) NULL)
2056 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2058 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2059 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2060 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2061 p+=GetPixelChannels(image);
2065 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2067 p=GetAuthenticPixelQueue(image);
2068 if (p == (const Quantum *) NULL)
2070 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2072 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2073 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2074 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2075 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2076 p+=GetPixelChannels(image);
2080 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2082 p=GetAuthenticPixelQueue(image);
2083 if (p == (const Quantum *) NULL)
2085 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2087 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2088 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2089 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2091 p+=GetPixelChannels(image);
2095 if (LocaleCompare(stream_info->map,"I") == 0)
2097 p=GetAuthenticPixelQueue(image);
2098 if (p == (const Quantum *) NULL)
2100 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2102 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2103 p+=GetPixelChannels(image);
2107 if (LocaleCompare(stream_info->map,"RGB") == 0)
2109 p=GetAuthenticPixelQueue(image);
2110 if (p == (const Quantum *) NULL)
2112 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2114 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2115 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2116 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2117 p+=GetPixelChannels(image);
2121 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2123 p=GetAuthenticPixelQueue(image);
2124 if (p == (const Quantum *) NULL)
2126 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2128 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2129 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2130 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2131 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2132 p+=GetPixelChannels(image);
2136 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2138 p=GetAuthenticPixelQueue(image);
2139 if (p == (const Quantum *) NULL)
2141 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2143 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2144 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2145 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2147 p+=GetPixelChannels(image);
2151 p=GetAuthenticPixelQueue(image);
2152 if (p == (const Quantum *) NULL)
2154 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2156 for (i=0; i < (ssize_t) length; i++)
2159 switch (quantum_map[i])
2164 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2168 case MagentaQuantum:
2170 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2176 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2181 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2184 case OpacityQuantum:
2186 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2191 if (image->colorspace == CMYKColorspace)
2192 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2197 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2205 p+=GetPixelChannels(image);
2211 register MagickSizeType
2214 q=(MagickSizeType *) stream_info->pixels;
2215 if (LocaleCompare(stream_info->map,"BGR") == 0)
2217 p=GetAuthenticPixelQueue(image);
2218 if (p == (const Quantum *) NULL)
2220 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2222 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2223 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2224 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2225 p+=GetPixelChannels(image);
2229 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2231 p=GetAuthenticPixelQueue(image);
2232 if (p == (const Quantum *) NULL)
2234 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2236 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2237 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2238 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2239 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2240 p+=GetPixelChannels(image);
2244 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2246 p=GetAuthenticPixelQueue(image);
2247 if (p == (const Quantum *) NULL)
2249 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2251 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2252 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2253 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2255 p+=GetPixelChannels(image);
2259 if (LocaleCompare(stream_info->map,"I") == 0)
2261 p=GetAuthenticPixelQueue(image);
2262 if (p == (const Quantum *) NULL)
2264 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2266 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2267 GetPixelIntensity(image,p)));
2268 p+=GetPixelChannels(image);
2272 if (LocaleCompare(stream_info->map,"RGB") == 0)
2274 p=GetAuthenticPixelQueue(image);
2275 if (p == (const Quantum *) NULL)
2277 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2279 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2280 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2281 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2282 p+=GetPixelChannels(image);
2286 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2288 p=GetAuthenticPixelQueue(image);
2289 if (p == (const Quantum *) NULL)
2291 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2293 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2294 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2295 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2296 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2297 p+=GetPixelChannels(image);
2301 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2303 p=GetAuthenticPixelQueue(image);
2304 if (p == (const Quantum *) NULL)
2306 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2308 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2309 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2310 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2312 p+=GetPixelChannels(image);
2316 p=GetAuthenticPixelQueue(image);
2317 if (p == (const Quantum *) NULL)
2319 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2321 for (i=0; i < (ssize_t) length; i++)
2324 switch (quantum_map[i])
2329 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2333 case MagentaQuantum:
2335 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2341 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2346 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2349 case OpacityQuantum:
2351 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2356 if (image->colorspace == CMYKColorspace)
2357 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2362 *q=ScaleQuantumToLongLong(ClampToQuantum(
2363 GetPixelIntensity(image,p)));
2371 p+=GetPixelChannels(image);
2380 q=(Quantum *) stream_info->pixels;
2381 if (LocaleCompare(stream_info->map,"BGR") == 0)
2383 p=GetAuthenticPixelQueue(image);
2384 if (p == (const Quantum *) NULL)
2386 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2388 *q++=GetPixelBlue(image,p);
2389 *q++=GetPixelGreen(image,p);
2390 *q++=GetPixelRed(image,p);
2391 p+=GetPixelChannels(image);
2395 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2397 p=GetAuthenticPixelQueue(image);
2398 if (p == (const Quantum *) NULL)
2400 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2402 *q++=GetPixelBlue(image,p);
2403 *q++=GetPixelGreen(image,p);
2404 *q++=GetPixelRed(image,p);
2405 *q++=GetPixelAlpha(image,p);
2406 p+=GetPixelChannels(image);
2410 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2412 p=GetAuthenticPixelQueue(image);
2413 if (p == (const Quantum *) NULL)
2415 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2417 *q++=GetPixelBlue(image,p);
2418 *q++=GetPixelGreen(image,p);
2419 *q++=GetPixelRed(image,p);
2421 p+=GetPixelChannels(image);
2425 if (LocaleCompare(stream_info->map,"I") == 0)
2427 p=GetAuthenticPixelQueue(image);
2428 if (p == (const Quantum *) NULL)
2430 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2432 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2433 p+=GetPixelChannels(image);
2437 if (LocaleCompare(stream_info->map,"RGB") == 0)
2439 p=GetAuthenticPixelQueue(image);
2440 if (p == (const Quantum *) NULL)
2442 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2444 *q++=GetPixelRed(image,p);
2445 *q++=GetPixelGreen(image,p);
2446 *q++=GetPixelBlue(image,p);
2447 p+=GetPixelChannels(image);
2451 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2453 p=GetAuthenticPixelQueue(image);
2454 if (p == (const Quantum *) NULL)
2456 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2458 *q++=GetPixelRed(image,p);
2459 *q++=GetPixelGreen(image,p);
2460 *q++=GetPixelBlue(image,p);
2461 *q++=GetPixelAlpha(image,p);
2462 p+=GetPixelChannels(image);
2466 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2468 p=GetAuthenticPixelQueue(image);
2469 if (p == (const Quantum *) NULL)
2471 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2473 *q++=GetPixelRed(image,p);
2474 *q++=GetPixelGreen(image,p);
2475 *q++=GetPixelBlue(image,p);
2477 p+=GetPixelChannels(image);
2481 p=GetAuthenticPixelQueue(image);
2482 if (p == (const Quantum *) NULL)
2484 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2486 for (i=0; i < (ssize_t) length; i++)
2489 switch (quantum_map[i])
2494 *q=GetPixelRed(image,p);
2498 case MagentaQuantum:
2500 *q=GetPixelGreen(image,p);
2506 *q=GetPixelBlue(image,p);
2511 *q=(Quantum) (GetPixelAlpha(image,p));
2514 case OpacityQuantum:
2516 *q=GetPixelAlpha(image,p);
2521 if (image->colorspace == CMYKColorspace)
2522 *q=GetPixelBlack(image,p);
2527 *q=ClampToQuantum(GetPixelIntensity(image,p));
2535 p+=GetPixelChannels(image);
2541 register unsigned short
2544 q=(unsigned short *) stream_info->pixels;
2545 if (LocaleCompare(stream_info->map,"BGR") == 0)
2547 p=GetAuthenticPixelQueue(image);
2548 if (p == (const Quantum *) NULL)
2550 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2552 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2553 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2554 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2555 p+=GetPixelChannels(image);
2559 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2561 p=GetAuthenticPixelQueue(image);
2562 if (p == (const Quantum *) NULL)
2564 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2566 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2567 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2568 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2569 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2570 p+=GetPixelChannels(image);
2574 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2576 p=GetAuthenticPixelQueue(image);
2577 if (p == (const Quantum *) NULL)
2579 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2581 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2582 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2583 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2585 p+=GetPixelChannels(image);
2589 if (LocaleCompare(stream_info->map,"I") == 0)
2591 p=GetAuthenticPixelQueue(image);
2592 if (p == (const Quantum *) NULL)
2594 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2596 *q++=ScaleQuantumToShort(ClampToQuantum(
2597 GetPixelIntensity(image,p)));
2598 p+=GetPixelChannels(image);
2602 if (LocaleCompare(stream_info->map,"RGB") == 0)
2604 p=GetAuthenticPixelQueue(image);
2605 if (p == (const Quantum *) NULL)
2607 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2609 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2610 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2611 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2612 p+=GetPixelChannels(image);
2616 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2618 p=GetAuthenticPixelQueue(image);
2619 if (p == (const Quantum *) NULL)
2621 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2623 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2624 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2625 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2626 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2627 p+=GetPixelChannels(image);
2631 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2633 p=GetAuthenticPixelQueue(image);
2634 if (p == (const Quantum *) NULL)
2636 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2638 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2639 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2640 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2642 p+=GetPixelChannels(image);
2646 p=GetAuthenticPixelQueue(image);
2647 if (p == (const Quantum *) NULL)
2649 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2651 for (i=0; i < (ssize_t) length; i++)
2654 switch (quantum_map[i])
2659 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2663 case MagentaQuantum:
2665 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2671 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2676 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2679 case OpacityQuantum:
2681 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2686 if (image->colorspace == CMYKColorspace)
2687 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2692 *q=ScaleQuantumToShort(ClampToQuantum(
2693 GetPixelIntensity(image,p)));
2701 p+=GetPixelChannels(image);
2707 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2708 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2709 "UnrecognizedPixelMap","`%s'",stream_info->map);
2713 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2722 + 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 %
2726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2728 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2729 % the latest stream of pixels.
2731 % The format of the SyncAuthenticPixelsStream method is:
2733 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2734 % ExceptionInfo *exception)
2736 % A description of each parameter follows:
2738 % o image: the image.
2740 % o exception: return any errors or warnings in this structure.
2743 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2744 ExceptionInfo *exception)
2755 assert(image != (Image *) NULL);
2756 assert(image->signature == MagickCoreSignature);
2757 if (image->debug != MagickFalse)
2758 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2759 cache_info=(CacheInfo *) image->cache;
2760 assert(cache_info->signature == MagickCoreSignature);
2761 stream_handler=GetBlobStreamHandler(image);
2762 if (stream_handler == (StreamHandler) NULL)
2764 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2765 "NoStreamHandlerIsDefined","`%s'",image->filename);
2766 return(MagickFalse);
2768 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2769 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2777 % W r i t e S t r e a m %
2781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2783 % WriteStream() makes the image pixels available to a user supplied callback
2784 % method immediately upon writing pixel data with the WriteImage() method.
2786 % The format of the WriteStream() method is:
2788 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2789 % StreamHandler stream,ExceptionInfo *exception)
2791 % A description of each parameter follows:
2793 % o image_info: the image info.
2795 % o stream: A callback method.
2797 % o exception: return any errors or warnings in this structure.
2800 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2801 Image *image,StreamHandler stream,ExceptionInfo *exception)
2809 assert(image_info != (ImageInfo *) NULL);
2810 assert(image_info->signature == MagickCoreSignature);
2811 if (image_info->debug != MagickFalse)
2812 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2813 image_info->filename);
2814 assert(image != (Image *) NULL);
2815 assert(image->signature == MagickCoreSignature);
2816 write_info=CloneImageInfo(image_info);
2817 *write_info->magick='\0';
2818 write_info->stream=stream;
2819 status=WriteImage(write_info,image,exception);
2820 write_info=DestroyImageInfo(write_info);