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-2017 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 *) AcquireMagickMemory(sizeof(*stream_info));
166 if (stream_info == (StreamInfo *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
169 stream_info->pixels=(unsigned char *) MagickAssumeAligned(
170 AcquireAlignedMemory(1,sizeof(*stream_info->pixels)));
171 if (stream_info->pixels == (unsigned char *) NULL)
172 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
173 stream_info->map=ConstantString("RGB");
174 stream_info->storage_type=CharPixel;
175 stream_info->stream=AcquireImage(image_info,exception);
176 stream_info->signature=MagickCoreSignature;
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 + D e s t r o y P i x e l S t r e a m %
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 % DestroyPixelStream() deallocates memory associated with the pixel stream.
193 % The format of the DestroyPixelStream() method is:
195 % void DestroyPixelStream(Image *image)
197 % A description of each parameter follows:
199 % o image: the image.
203 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
205 assert(cache_info != (CacheInfo *) NULL);
206 if (cache_info->mapped == MagickFalse)
207 (void) RelinquishAlignedMemory(cache_info->pixels);
209 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
210 cache_info->pixels=(Quantum *) NULL;
211 cache_info->metacontent=(void *) NULL;
212 cache_info->length=0;
213 cache_info->mapped=MagickFalse;
216 static void DestroyPixelStream(Image *image)
224 assert(image != (Image *) NULL);
225 assert(image->signature == MagickCoreSignature);
226 if (image->debug != MagickFalse)
227 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
228 cache_info=(CacheInfo *) image->cache;
229 assert(cache_info->signature == MagickCoreSignature);
231 LockSemaphoreInfo(cache_info->semaphore);
232 cache_info->reference_count--;
233 if (cache_info->reference_count == 0)
235 UnlockSemaphoreInfo(cache_info->semaphore);
236 if (destroy == MagickFalse)
238 RelinquishStreamPixels(cache_info);
239 if (cache_info->nexus_info != (NexusInfo **) NULL)
240 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
241 cache_info->number_threads);
242 if (cache_info->file_semaphore != (SemaphoreInfo *) NULL)
243 RelinquishSemaphoreInfo(&cache_info->file_semaphore);
244 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
245 RelinquishSemaphoreInfo(&cache_info->semaphore);
246 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 + D e s t r o y S t r e a m I n f o %
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 % DestroyStreamInfo() destroys memory associated with the StreamInfo
263 % The format of the DestroyStreamInfo method is:
265 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
267 % A description of each parameter follows:
269 % o stream_info: the stream info.
272 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
275 assert(stream_info != (StreamInfo *) NULL);
276 assert(stream_info->signature == MagickCoreSignature);
277 if (stream_info->map != (char *) NULL)
278 stream_info->map=DestroyString(stream_info->map);
279 if (stream_info->pixels != (unsigned char *) NULL)
280 stream_info->pixels=(unsigned char *) RelinquishAlignedMemory(
281 stream_info->pixels);
282 if (stream_info->stream != (Image *) NULL)
284 (void) CloseBlob(stream_info->stream);
285 stream_info->stream=DestroyImage(stream_info->stream);
287 if (stream_info->quantum_info != (QuantumInfo *) NULL)
288 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
289 stream_info->signature=(~MagickCoreSignature);
290 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 + 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 %
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 % GetAuthenticMetacontentFromStream() returns the metacontent corresponding
306 % with the last call to QueueAuthenticPixelsStream() or
307 % GetAuthenticPixelsStream().
309 % The format of the GetAuthenticMetacontentFromStream() method is:
311 % void *GetAuthenticMetacontentFromStream(const Image *image)
313 % A description of each parameter follows:
315 % o image: the image.
318 static void *GetAuthenticMetacontentFromStream(const Image *image)
323 assert(image != (Image *) NULL);
324 assert(image->signature == MagickCoreSignature);
325 if (image->debug != MagickFalse)
326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
327 cache_info=(CacheInfo *) image->cache;
328 assert(cache_info->signature == MagickCoreSignature);
329 return(cache_info->metacontent);
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 + G e t A u t h e n t i c P i x e l S t r e a m %
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
344 % cache as defined by the geometry parameters. A pointer to the pixels is
345 % returned if the pixels are transferred, otherwise a NULL is returned. For
346 % streams this method is a no-op.
348 % The format of the GetAuthenticPixelsStream() method is:
350 % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
351 % const ssize_t y,const size_t columns,const size_t rows,
352 % ExceptionInfo *exception)
354 % A description of each parameter follows:
356 % o image: the image.
358 % o x,y,columns,rows: These values define the perimeter of a region of
361 % o exception: return any errors or warnings in this structure.
364 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
365 const ssize_t y,const size_t columns,const size_t rows,
366 ExceptionInfo *exception)
371 assert(image != (Image *) NULL);
372 assert(image->signature == MagickCoreSignature);
373 if (image->debug != MagickFalse)
374 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
375 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384 + 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 %
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
391 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
393 % The format of the GetAuthenticPixelsFromStream() method is:
395 % Quantum *GetAuthenticPixelsFromStream(const Image image)
397 % A description of each parameter follows:
399 % o image: the image.
402 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
407 assert(image != (Image *) NULL);
408 assert(image->signature == MagickCoreSignature);
409 if (image->debug != MagickFalse)
410 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
411 cache_info=(CacheInfo *) image->cache;
412 assert(cache_info->signature == MagickCoreSignature);
413 return(cache_info->pixels);
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 + 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 %
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
428 % (x,y) location. The image background color is returned if an error occurs.
430 % The format of the GetOneAuthenticPixelFromStream() method is:
432 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
433 % const ssize_t x,const ssize_t y,Quantum *pixel,
434 % ExceptionInfo *exception)
436 % A description of each parameter follows:
438 % o image: the image.
440 % o pixel: return a pixel at the specified (x,y) location.
442 % o x,y: These values define the location of the pixel to return.
444 % o exception: return any errors or warnings in this structure.
447 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
448 const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
456 assert(image != (Image *) NULL);
457 assert(image->signature == MagickCoreSignature);
458 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
459 p=GetAuthenticPixelsStream(image,x,y,1,1,exception);
460 if (p == (Quantum *) NULL)
462 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
463 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
464 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
465 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
466 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
469 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
471 PixelChannel channel=GetPixelChannelChannel(image,i);
478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
482 + 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 %
486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
489 % (x.y) location. The image background color is returned if an error occurs.
491 % The format of the GetOneVirtualPixelFromStream() method is:
493 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
494 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
495 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
497 % A description of each parameter follows:
499 % o image: the image.
501 % o virtual_pixel_method: the virtual pixel method.
503 % o x,y: These values define the location of the pixel to return.
505 % o pixel: return a pixel at the specified (x,y) location.
507 % o exception: return any errors or warnings in this structure.
510 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
511 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
512 Quantum *pixel,ExceptionInfo *exception)
520 assert(image != (Image *) NULL);
521 assert(image->signature == MagickCoreSignature);
522 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
523 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
524 if (p == (const Quantum *) NULL)
526 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
527 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
528 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
529 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
530 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
533 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
535 PixelChannel channel=GetPixelChannelChannel(image,i);
542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 + G e t S t r e a m I n f o C l i e n t D a t a %
550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
552 % GetStreamInfoClientData() gets the stream info client data.
554 % The format of the GetStreamInfoClientData method is:
556 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
558 % A description of each parameter follows:
560 % o stream_info: the stream info.
563 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
565 assert(stream_info != (StreamInfo *) NULL);
566 assert(stream_info->signature == MagickCoreSignature);
567 return(stream_info->client_data);
571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 + 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 %
579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 % GetVirtualPixelsStream() returns the pixels associated with the last call to
582 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
584 % The format of the GetVirtualPixelsStream() method is:
586 % const Quantum *GetVirtualPixelsStream(const Image *image)
588 % A description of each parameter follows:
590 % o pixels: return the pixels associated corresponding with the last call to
591 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
593 % o image: the image.
596 static const Quantum *GetVirtualPixelsStream(const Image *image)
601 assert(image != (Image *) NULL);
602 assert(image->signature == MagickCoreSignature);
603 if (image->debug != MagickFalse)
604 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
605 cache_info=(CacheInfo *) image->cache;
606 assert(cache_info->signature == MagickCoreSignature);
607 return(cache_info->pixels);
611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
615 + 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 %
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 % GetVirtualMetacontentFromStream() returns the associated pixel channels
622 % corresponding with the last call to QueueAuthenticPixelsStream() or
623 % GetVirtualPixelStream().
625 % The format of the GetVirtualMetacontentFromStream() method is:
627 % const void *GetVirtualMetacontentFromStream(const Image *image)
629 % A description of each parameter follows:
631 % o image: the image.
634 static const void *GetVirtualMetacontentFromStream(const Image *image)
639 assert(image != (Image *) NULL);
640 assert(image->signature == MagickCoreSignature);
641 if (image->debug != MagickFalse)
642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
643 cache_info=(CacheInfo *) image->cache;
644 assert(cache_info->signature == MagickCoreSignature);
645 return(cache_info->metacontent);
649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 + G e t V i r t u a l P i x e l S t r e a m %
657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
660 % defined by the geometry parameters. A pointer to the pixels is returned if
661 % the pixels are transferred, otherwise a NULL is returned. For streams this
664 % The format of the GetVirtualPixelStream() method is:
666 % const Quantum *GetVirtualPixelStream(const Image *image,
667 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
668 % const ssize_t y,const size_t columns,const size_t rows,
669 % ExceptionInfo *exception)
671 % A description of each parameter follows:
673 % o image: the image.
675 % o virtual_pixel_method: the virtual pixel method.
677 % o x,y,columns,rows: These values define the perimeter of a region of
680 % o exception: return any errors or warnings in this structure.
684 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
685 ExceptionInfo *exception)
687 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
689 if (cache_anonymous_memory < 0)
695 Does the security policy require anonymous mapping for pixel cache?
697 cache_anonymous_memory=0;
698 value=GetPolicyValue("pixel-cache-memory");
699 if (value == (char *) NULL)
700 value=GetPolicyValue("cache:memory-map");
701 if (LocaleCompare(value,"anonymous") == 0)
703 #if defined(MAGICKCORE_HAVE_MMAP) && defined(MAP_ANONYMOUS)
704 cache_anonymous_memory=1;
706 (void) ThrowMagickException(exception,GetMagickModule(),
707 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn",
708 "'%s' (policy requires anonymous memory mapping)",
709 cache_info->filename);
712 value=DestroyString(value);
714 if (cache_anonymous_memory <= 0)
716 cache_info->mapped=MagickFalse;
717 cache_info->pixels=(Quantum *) MagickAssumeAligned(
718 AcquireAlignedMemory(1,(size_t) cache_info->length));
722 cache_info->mapped=MagickTrue;
723 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
726 if (cache_info->pixels == (Quantum *) NULL)
728 (void) ThrowMagickException(exception,GetMagickModule(),
729 ResourceLimitError,"MemoryAllocationFailed","`%s'",
730 cache_info->filename);
736 static const Quantum *GetVirtualPixelStream(const Image *image,
737 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
738 const ssize_t y,const size_t columns,const size_t rows,
739 ExceptionInfo *exception)
753 magick_unreferenced(virtual_pixel_method);
756 Validate pixel cache geometry.
758 assert(image != (const Image *) NULL);
759 assert(image->signature == MagickCoreSignature);
760 if (image->debug != MagickFalse)
761 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
762 if ((x < 0) || (y < 0) ||
763 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
764 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
765 (columns == 0) || (rows == 0))
767 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
768 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
769 return((Quantum *) NULL);
771 cache_info=(CacheInfo *) image->cache;
772 assert(cache_info->signature == MagickCoreSignature);
774 Pixels are stored in a temporary buffer until they are synced to the cache.
776 number_pixels=(MagickSizeType) columns*rows;
777 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
778 if (cache_info->number_channels == 0)
779 length=(size_t) number_pixels*sizeof(Quantum);
780 if (cache_info->metacontent_extent != 0)
781 length+=number_pixels*cache_info->metacontent_extent;
782 if (cache_info->pixels == (Quantum *) NULL)
784 cache_info->length=length;
785 status=AcquireStreamPixels(cache_info,exception);
786 if (status == MagickFalse)
788 cache_info->length=0;
789 return((Quantum *) NULL);
793 if (cache_info->length < length)
795 RelinquishStreamPixels(cache_info);
796 cache_info->length=length;
797 status=AcquireStreamPixels(cache_info,exception);
798 if (status == MagickFalse)
800 cache_info->length=0;
801 return((Quantum *) NULL);
804 cache_info->metacontent=(void *) NULL;
805 if (cache_info->metacontent_extent != 0)
806 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
807 cache_info->number_channels);
808 return(cache_info->pixels);
812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 + O p e n S t r e a m %
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 % OpenStream() opens a stream for writing by the StreamImage() method.
824 % The format of the OpenStream method is:
826 % MagickBooleanType OpenStream(const ImageInfo *image_info,
827 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
829 % A description of each parameter follows:
831 % o image_info: the image info.
833 % o stream_info: the stream info.
835 % o filename: the stream filename.
837 % o exception: return any errors or warnings in this structure.
840 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
841 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
846 (void) CopyMagickString(stream_info->stream->filename,filename,
848 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 + 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 %
861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
863 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
864 % defined by the region rectangle and returns a pointer to the area. This
865 % area is subsequently transferred from the pixel cache with method
866 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
867 % pixels are transferred, otherwise a NULL is returned.
869 % The format of the QueueAuthenticPixelsStream() method is:
871 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
872 % const ssize_t y,const size_t columns,const size_t rows,
873 % ExceptionInfo *exception)
875 % A description of each parameter follows:
877 % o image: the image.
879 % o x,y,columns,rows: These values define the perimeter of a region of
883 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
884 const ssize_t y,const size_t columns,const size_t rows,
885 ExceptionInfo *exception)
903 Validate pixel cache geometry.
905 assert(image != (Image *) NULL);
906 if ((x < 0) || (y < 0) ||
907 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
908 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
909 (columns == 0) || (rows == 0))
911 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
912 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
913 return((Quantum *) NULL);
915 stream_handler=GetBlobStreamHandler(image);
916 if (stream_handler == (StreamHandler) NULL)
918 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
919 "NoStreamHandlerIsDefined","`%s'",image->filename);
920 return((Quantum *) NULL);
922 cache_info=(CacheInfo *) image->cache;
923 assert(cache_info->signature == MagickCoreSignature);
924 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
925 (image->colorspace != GetPixelCacheColorspace(image->cache)))
927 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
928 (void) stream_handler(image,(const void *) NULL,(size_t)
929 cache_info->columns);
930 cache_info->storage_class=image->storage_class;
931 cache_info->colorspace=image->colorspace;
932 cache_info->columns=image->columns;
933 cache_info->rows=image->rows;
934 image->cache=cache_info;
937 Pixels are stored in a temporary buffer until they are synced to the cache.
939 cache_info->columns=columns;
940 cache_info->rows=rows;
941 number_pixels=(MagickSizeType) columns*rows;
942 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
943 if (cache_info->number_channels == 0)
944 length=(size_t) number_pixels*sizeof(Quantum);
945 if (cache_info->metacontent_extent != 0)
946 length+=number_pixels*cache_info->metacontent_extent;
947 if (cache_info->pixels == (Quantum *) NULL)
949 cache_info->length=length;
950 status=AcquireStreamPixels(cache_info,exception);
951 if (status == MagickFalse)
953 cache_info->length=0;
954 return((Quantum *) NULL);
958 if (cache_info->length < length)
960 RelinquishStreamPixels(cache_info);
961 cache_info->length=length;
962 status=AcquireStreamPixels(cache_info,exception);
963 if (status == MagickFalse)
965 cache_info->length=0;
966 return((Quantum *) NULL);
969 cache_info->metacontent=(void *) NULL;
970 if (cache_info->metacontent_extent != 0)
971 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
972 cache_info->number_channels);
973 return(cache_info->pixels);
977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 % R e a d S t r e a m %
985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
987 % ReadStream() makes the image pixels available to a user supplied callback
988 % method immediately upon reading a scanline with the ReadImage() method.
990 % The format of the ReadStream() method is:
992 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
993 % ExceptionInfo *exception)
995 % A description of each parameter follows:
997 % o image_info: the image info.
999 % o stream: a callback method.
1001 % o exception: return any errors or warnings in this structure.
1004 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
1005 ExceptionInfo *exception)
1017 Stream image pixels.
1019 assert(image_info != (ImageInfo *) NULL);
1020 assert(image_info->signature == MagickCoreSignature);
1021 if (image_info->debug != MagickFalse)
1022 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1023 image_info->filename);
1024 assert(exception != (ExceptionInfo *) NULL);
1025 assert(exception->signature == MagickCoreSignature);
1026 read_info=CloneImageInfo(image_info);
1027 read_info->cache=AcquirePixelCache(0);
1028 GetPixelCacheMethods(&cache_methods);
1029 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
1030 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
1031 cache_methods.get_virtual_metacontent_from_handler=
1032 GetVirtualMetacontentFromStream;
1033 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
1034 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1035 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1036 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1037 cache_methods.get_authentic_metacontent_from_handler=
1038 GetAuthenticMetacontentFromStream;
1039 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1040 cache_methods.get_one_authentic_pixel_from_handler=
1041 GetOneAuthenticPixelFromStream;
1042 cache_methods.destroy_pixel_handler=DestroyPixelStream;
1043 SetPixelCacheMethods(read_info->cache,&cache_methods);
1044 read_info->stream=stream;
1045 image=ReadImage(read_info,exception);
1046 if (image != (Image *) NULL)
1048 InitializePixelChannelMap(image);
1049 ResetPixelCacheChannels(image);
1051 read_info=DestroyImageInfo(read_info);
1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060 + S e t S t r e a m I n f o C l i e n t D a t a %
1064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1066 % SetStreamInfoClientData() sets the stream info client data.
1068 % The format of the SetStreamInfoClientData method is:
1070 % void SetStreamInfoClientData(StreamInfo *stream_info,
1071 % const void *client_data)
1073 % A description of each parameter follows:
1075 % o stream_info: the stream info.
1077 % o client_data: the client data.
1080 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1081 const void *client_data)
1083 assert(stream_info != (StreamInfo *) NULL);
1084 assert(stream_info->signature == MagickCoreSignature);
1085 stream_info->client_data=client_data;
1089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093 + S e t S t r e a m I n f o M a p %
1097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1099 % SetStreamInfoMap() sets the stream info map member.
1101 % The format of the SetStreamInfoMap method is:
1103 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1105 % A description of each parameter follows:
1107 % o stream_info: the stream info.
1112 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1114 assert(stream_info != (StreamInfo *) NULL);
1115 assert(stream_info->signature == MagickCoreSignature);
1116 (void) CloneString(&stream_info->map,map);
1120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1124 + S e t S t r e a m I n f o S t o r a g e T y p e %
1128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1130 % SetStreamInfoStorageType() sets the stream info storage type member.
1132 % The format of the SetStreamInfoStorageType method is:
1134 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1135 % const StoreageType *storage_type)
1137 % A description of each parameter follows:
1139 % o stream_info: the stream info.
1141 % o storage_type: the storage type.
1144 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1145 const StorageType storage_type)
1147 assert(stream_info != (StreamInfo *) NULL);
1148 assert(stream_info->signature == MagickCoreSignature);
1149 stream_info->storage_type=storage_type;
1153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 + S t r e a m I m a g e %
1161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163 % StreamImage() streams pixels from an image and writes them in a user
1164 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1166 % The format of the StreamImage() method is:
1168 % Image *StreamImage(const ImageInfo *image_info,
1169 % StreamInfo *stream_info,ExceptionInfo *exception)
1171 % A description of each parameter follows:
1173 % o image_info: the image info.
1175 % o stream_info: the stream info.
1177 % o exception: return any errors or warnings in this structure.
1181 #if defined(__cplusplus) || defined(c_plusplus)
1185 static size_t WriteStreamImage(const Image *image,const void *pixels,
1186 const size_t columns)
1205 stream_info=(StreamInfo *) image->client_data;
1206 switch (stream_info->storage_type)
1208 default: packet_size=sizeof(unsigned char); break;
1209 case CharPixel: packet_size=sizeof(unsigned char); break;
1210 case DoublePixel: packet_size=sizeof(double); break;
1211 case FloatPixel: packet_size=sizeof(float); break;
1212 case LongPixel: packet_size=sizeof(unsigned int); break;
1213 case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
1214 case QuantumPixel: packet_size=sizeof(Quantum); break;
1215 case ShortPixel: packet_size=sizeof(unsigned short); break;
1217 cache_info=(CacheInfo *) image->cache;
1218 assert(cache_info->signature == MagickCoreSignature);
1219 packet_size*=strlen(stream_info->map);
1220 length=packet_size*cache_info->columns*cache_info->rows;
1221 if (image != stream_info->image)
1227 Prepare stream for writing.
1229 (void) RelinquishAlignedMemory(stream_info->pixels);
1230 stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
1231 if (stream_info->pixels == (unsigned char *) NULL)
1233 (void) ResetMagickMemory(stream_info->pixels,0,length);
1234 stream_info->image=image;
1235 write_info=CloneImageInfo(stream_info->image_info);
1236 (void) SetImageInfo(write_info,1,stream_info->exception);
1237 if (write_info->extract != (char *) NULL)
1238 (void) ParseAbsoluteGeometry(write_info->extract,
1239 &stream_info->extract_info);
1241 write_info=DestroyImageInfo(write_info);
1243 extract_info=stream_info->extract_info;
1244 if ((extract_info.width == 0) || (extract_info.height == 0))
1247 Write all pixels to stream.
1249 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1250 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1252 return(count == 0 ? 0 : columns);
1254 if ((stream_info->y < extract_info.y) ||
1255 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1261 Write a portion of the pixel row to the stream.
1263 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1264 length=packet_size*extract_info.width;
1265 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1268 return(count == 0 ? 0 : columns);
1271 #if defined(__cplusplus) || defined(c_plusplus)
1275 MagickExport Image *StreamImage(const ImageInfo *image_info,
1276 StreamInfo *stream_info,ExceptionInfo *exception)
1284 assert(image_info != (const ImageInfo *) NULL);
1285 assert(image_info->signature == MagickCoreSignature);
1286 if (image_info->debug != MagickFalse)
1287 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1288 image_info->filename);
1289 assert(stream_info != (StreamInfo *) NULL);
1290 assert(stream_info->signature == MagickCoreSignature);
1291 assert(exception != (ExceptionInfo *) NULL);
1292 read_info=CloneImageInfo(image_info);
1293 stream_info->image_info=image_info;
1294 stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
1295 stream_info->exception=exception;
1296 read_info->client_data=(void *) stream_info;
1297 image=ReadStream(read_info,&WriteStreamImage,exception);
1298 read_info=DestroyImageInfo(read_info);
1299 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1300 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1301 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1302 image=DestroyImage(image);
1307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1311 + S t r e a m I m a g e P i x e l s %
1315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1317 % StreamImagePixels() extracts pixel data from an image and returns it in the
1318 % stream_info->pixels structure in the format as defined by
1319 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1321 % The format of the StreamImagePixels method is:
1323 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1324 % const Image *image,ExceptionInfo *exception)
1326 % A description of each parameter follows:
1328 % o stream_info: the stream info.
1330 % o image: the image.
1332 % o exception: return any errors or warnings in this structure.
1335 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1336 const Image *image,ExceptionInfo *exception)
1344 register const Quantum
1354 assert(stream_info != (StreamInfo *) NULL);
1355 assert(stream_info->signature == MagickCoreSignature);
1356 assert(image != (Image *) NULL);
1357 assert(image->signature == MagickCoreSignature);
1358 if (image->debug != MagickFalse)
1359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1360 length=strlen(stream_info->map);
1361 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1362 if (quantum_map == (QuantumType *) NULL)
1364 (void) ThrowMagickException(exception,GetMagickModule(),
1365 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1366 return(MagickFalse);
1368 for (i=0; i < (ssize_t) length; i++)
1370 switch (stream_info->map[i])
1375 quantum_map[i]=AlphaQuantum;
1381 quantum_map[i]=BlueQuantum;
1387 quantum_map[i]=CyanQuantum;
1388 if (image->colorspace == CMYKColorspace)
1390 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1391 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1392 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1393 return(MagickFalse);
1398 quantum_map[i]=GreenQuantum;
1404 quantum_map[i]=IndexQuantum;
1410 quantum_map[i]=BlackQuantum;
1411 if (image->colorspace == CMYKColorspace)
1413 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1414 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1415 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1416 return(MagickFalse);
1421 quantum_map[i]=MagentaQuantum;
1422 if (image->colorspace == CMYKColorspace)
1424 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1425 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1426 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1427 return(MagickFalse);
1432 quantum_map[i]=OpacityQuantum;
1438 quantum_map[i]=UndefinedQuantum;
1444 quantum_map[i]=RedQuantum;
1450 quantum_map[i]=YellowQuantum;
1451 if (image->colorspace == CMYKColorspace)
1453 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1454 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1455 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1456 return(MagickFalse);
1460 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1461 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1462 "UnrecognizedPixelMap","`%s'",stream_info->map);
1463 return(MagickFalse);
1467 quantum_info=stream_info->quantum_info;
1468 switch (stream_info->storage_type)
1472 register unsigned char
1475 q=(unsigned char *) stream_info->pixels;
1476 if (LocaleCompare(stream_info->map,"BGR") == 0)
1478 p=GetAuthenticPixelQueue(image);
1479 if (p == (const Quantum *) NULL)
1481 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1483 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1484 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1485 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1486 p+=GetPixelChannels(image);
1490 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1492 p=GetAuthenticPixelQueue(image);
1493 if (p == (const Quantum *) NULL)
1495 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1497 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1498 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1499 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1500 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1501 p+=GetPixelChannels(image);
1505 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1507 p=GetAuthenticPixelQueue(image);
1508 if (p == (const Quantum *) NULL)
1510 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1512 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1513 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1514 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1515 *q++=ScaleQuantumToChar((Quantum) 0);
1516 p+=GetPixelChannels(image);
1520 if (LocaleCompare(stream_info->map,"I") == 0)
1522 p=GetAuthenticPixelQueue(image);
1523 if (p == (const Quantum *) NULL)
1525 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1527 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1528 p+=GetPixelChannels(image);
1532 if (LocaleCompare(stream_info->map,"RGB") == 0)
1534 p=GetAuthenticPixelQueue(image);
1535 if (p == (const Quantum *) NULL)
1537 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1539 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1540 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1541 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1542 p+=GetPixelChannels(image);
1546 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1548 p=GetAuthenticPixelQueue(image);
1549 if (p == (const Quantum *) NULL)
1551 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1553 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1554 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1555 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1556 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1557 p+=GetPixelChannels(image);
1561 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1563 p=GetAuthenticPixelQueue(image);
1564 if (p == (const Quantum *) NULL)
1566 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1568 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1569 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1570 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1571 *q++=ScaleQuantumToChar((Quantum) 0);
1572 p+=GetPixelChannels(image);
1576 p=GetAuthenticPixelQueue(image);
1577 if (p == (const Quantum *) NULL)
1579 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1581 for (i=0; i < (ssize_t) length; i++)
1584 switch (quantum_map[i])
1589 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1593 case MagentaQuantum:
1595 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1601 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1606 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1609 case OpacityQuantum:
1611 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1616 if (image->colorspace == CMYKColorspace)
1617 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1622 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1630 p+=GetPixelChannels(image);
1639 q=(double *) stream_info->pixels;
1640 if (LocaleCompare(stream_info->map,"BGR") == 0)
1642 p=GetAuthenticPixelQueue(image);
1643 if (p == (const Quantum *) NULL)
1645 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1647 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1649 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1650 quantum_info->scale+quantum_info->minimum);
1651 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1652 quantum_info->scale+quantum_info->minimum);
1653 p+=GetPixelChannels(image);
1657 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1659 p=GetAuthenticPixelQueue(image);
1660 if (p == (const Quantum *) NULL)
1662 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1664 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1665 quantum_info->scale+quantum_info->minimum);
1666 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1667 quantum_info->scale+quantum_info->minimum);
1668 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1669 quantum_info->scale+quantum_info->minimum);
1670 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1671 quantum_info->scale+quantum_info->minimum);
1672 p+=GetPixelChannels(image);
1676 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1678 p=GetAuthenticPixelQueue(image);
1679 if (p == (const Quantum *) NULL)
1681 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1683 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1684 quantum_info->scale+quantum_info->minimum);
1685 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1686 quantum_info->scale+quantum_info->minimum);
1687 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1688 quantum_info->scale+quantum_info->minimum);
1690 p+=GetPixelChannels(image);
1694 if (LocaleCompare(stream_info->map,"I") == 0)
1696 p=GetAuthenticPixelQueue(image);
1697 if (p == (const Quantum *) NULL)
1699 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1701 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1702 quantum_info->scale+quantum_info->minimum);
1703 p+=GetPixelChannels(image);
1707 if (LocaleCompare(stream_info->map,"RGB") == 0)
1709 p=GetAuthenticPixelQueue(image);
1710 if (p == (const Quantum *) NULL)
1712 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1714 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1715 quantum_info->scale+quantum_info->minimum);
1716 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1717 quantum_info->scale+quantum_info->minimum);
1718 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1719 quantum_info->scale+quantum_info->minimum);
1720 p+=GetPixelChannels(image);
1724 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1726 p=GetAuthenticPixelQueue(image);
1727 if (p == (const Quantum *) NULL)
1729 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1731 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1732 quantum_info->scale+quantum_info->minimum);
1733 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1734 quantum_info->scale+quantum_info->minimum);
1735 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1736 quantum_info->scale+quantum_info->minimum);
1737 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1738 quantum_info->scale+quantum_info->minimum);
1739 p+=GetPixelChannels(image);
1743 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1745 p=GetAuthenticPixelQueue(image);
1746 if (p == (const Quantum *) NULL)
1748 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1750 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1751 quantum_info->scale+quantum_info->minimum);
1752 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1753 quantum_info->scale+quantum_info->minimum);
1754 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1755 quantum_info->scale+quantum_info->minimum);
1757 p+=GetPixelChannels(image);
1761 p=GetAuthenticPixelQueue(image);
1762 if (p == (const Quantum *) NULL)
1764 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1766 for (i=0; i < (ssize_t) length; i++)
1769 switch (quantum_map[i])
1774 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1775 quantum_info->scale+quantum_info->minimum);
1779 case MagentaQuantum:
1781 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1782 quantum_info->scale+quantum_info->minimum);
1788 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1789 quantum_info->scale+quantum_info->minimum);
1794 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1795 quantum_info->scale+quantum_info->minimum);
1798 case OpacityQuantum:
1800 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1801 quantum_info->scale+quantum_info->minimum);
1806 if (image->colorspace == CMYKColorspace)
1807 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1808 quantum_info->scale+quantum_info->minimum);
1813 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1814 quantum_info->scale+quantum_info->minimum);
1822 p+=GetPixelChannels(image);
1831 q=(float *) stream_info->pixels;
1832 if (LocaleCompare(stream_info->map,"BGR") == 0)
1834 p=GetAuthenticPixelQueue(image);
1835 if (p == (const Quantum *) NULL)
1837 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1839 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1841 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1842 quantum_info->scale+quantum_info->minimum);
1843 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1844 quantum_info->scale+quantum_info->minimum);
1845 p+=GetPixelChannels(image);
1849 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1851 p=GetAuthenticPixelQueue(image);
1852 if (p == (const Quantum *) NULL)
1854 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1856 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1857 quantum_info->scale+quantum_info->minimum);
1858 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1859 quantum_info->scale+quantum_info->minimum);
1860 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1861 quantum_info->scale+quantum_info->minimum);
1862 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1863 quantum_info->scale+quantum_info->minimum);
1864 p+=GetPixelChannels(image);
1868 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1870 p=GetAuthenticPixelQueue(image);
1871 if (p == (const Quantum *) NULL)
1873 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1875 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1876 quantum_info->scale+quantum_info->minimum);
1877 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1878 quantum_info->scale+quantum_info->minimum);
1879 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1880 quantum_info->scale+quantum_info->minimum);
1882 p+=GetPixelChannels(image);
1886 if (LocaleCompare(stream_info->map,"I") == 0)
1888 p=GetAuthenticPixelQueue(image);
1889 if (p == (const Quantum *) NULL)
1891 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1893 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1894 quantum_info->scale+quantum_info->minimum);
1895 p+=GetPixelChannels(image);
1899 if (LocaleCompare(stream_info->map,"RGB") == 0)
1901 p=GetAuthenticPixelQueue(image);
1902 if (p == (const Quantum *) NULL)
1904 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1906 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1907 quantum_info->scale+quantum_info->minimum);
1908 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1909 quantum_info->scale+quantum_info->minimum);
1910 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1911 quantum_info->scale+quantum_info->minimum);
1912 p+=GetPixelChannels(image);
1916 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1918 p=GetAuthenticPixelQueue(image);
1919 if (p == (const Quantum *) NULL)
1921 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1923 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1924 quantum_info->scale+quantum_info->minimum);
1925 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1926 quantum_info->scale+quantum_info->minimum);
1927 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1928 quantum_info->scale+quantum_info->minimum);
1929 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1930 quantum_info->scale+quantum_info->minimum);
1931 p+=GetPixelChannels(image);
1935 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1937 p=GetAuthenticPixelQueue(image);
1938 if (p == (const Quantum *) NULL)
1940 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1942 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1943 quantum_info->scale+quantum_info->minimum);
1944 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1945 quantum_info->scale+quantum_info->minimum);
1946 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1947 quantum_info->scale+quantum_info->minimum);
1949 p+=GetPixelChannels(image);
1953 p=GetAuthenticPixelQueue(image);
1954 if (p == (const Quantum *) NULL)
1956 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1958 for (i=0; i < (ssize_t) length; i++)
1961 switch (quantum_map[i])
1966 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1967 quantum_info->scale+quantum_info->minimum);
1971 case MagentaQuantum:
1973 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1974 quantum_info->scale+quantum_info->minimum);
1980 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1981 quantum_info->scale+quantum_info->minimum);
1986 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1987 quantum_info->scale+quantum_info->minimum);
1990 case OpacityQuantum:
1992 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1993 quantum_info->scale+quantum_info->minimum);
1998 if (image->colorspace == CMYKColorspace)
1999 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
2000 quantum_info->scale+quantum_info->minimum);
2005 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
2006 quantum_info->scale+quantum_info->minimum);
2014 p+=GetPixelChannels(image);
2020 register unsigned int
2023 q=(unsigned int *) stream_info->pixels;
2024 if (LocaleCompare(stream_info->map,"BGR") == 0)
2026 p=GetAuthenticPixelQueue(image);
2027 if (p == (const Quantum *) NULL)
2029 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2031 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2032 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2033 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2034 p+=GetPixelChannels(image);
2038 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2040 p=GetAuthenticPixelQueue(image);
2041 if (p == (const Quantum *) NULL)
2043 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2045 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2046 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2047 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2048 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2049 p+=GetPixelChannels(image);
2053 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2055 p=GetAuthenticPixelQueue(image);
2056 if (p == (const Quantum *) NULL)
2058 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2060 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2061 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2062 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2064 p+=GetPixelChannels(image);
2068 if (LocaleCompare(stream_info->map,"I") == 0)
2070 p=GetAuthenticPixelQueue(image);
2071 if (p == (const Quantum *) NULL)
2073 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2075 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2076 p+=GetPixelChannels(image);
2080 if (LocaleCompare(stream_info->map,"RGB") == 0)
2082 p=GetAuthenticPixelQueue(image);
2083 if (p == (const Quantum *) NULL)
2085 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2087 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2088 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2089 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2090 p+=GetPixelChannels(image);
2094 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2096 p=GetAuthenticPixelQueue(image);
2097 if (p == (const Quantum *) NULL)
2099 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2101 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2102 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2103 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2104 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2105 p+=GetPixelChannels(image);
2109 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2111 p=GetAuthenticPixelQueue(image);
2112 if (p == (const Quantum *) NULL)
2114 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2116 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2117 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2118 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2120 p+=GetPixelChannels(image);
2124 p=GetAuthenticPixelQueue(image);
2125 if (p == (const Quantum *) NULL)
2127 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2129 for (i=0; i < (ssize_t) length; i++)
2132 switch (quantum_map[i])
2137 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2141 case MagentaQuantum:
2143 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2149 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2154 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2157 case OpacityQuantum:
2159 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2164 if (image->colorspace == CMYKColorspace)
2165 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2170 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2178 p+=GetPixelChannels(image);
2184 register MagickSizeType
2187 q=(MagickSizeType *) stream_info->pixels;
2188 if (LocaleCompare(stream_info->map,"BGR") == 0)
2190 p=GetAuthenticPixelQueue(image);
2191 if (p == (const Quantum *) NULL)
2193 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2195 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2196 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2197 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2198 p+=GetPixelChannels(image);
2202 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2204 p=GetAuthenticPixelQueue(image);
2205 if (p == (const Quantum *) NULL)
2207 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2209 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2210 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2211 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2212 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2213 p+=GetPixelChannels(image);
2217 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2219 p=GetAuthenticPixelQueue(image);
2220 if (p == (const Quantum *) NULL)
2222 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2224 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2225 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2226 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2228 p+=GetPixelChannels(image);
2232 if (LocaleCompare(stream_info->map,"I") == 0)
2234 p=GetAuthenticPixelQueue(image);
2235 if (p == (const Quantum *) NULL)
2237 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2239 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2240 GetPixelIntensity(image,p)));
2241 p+=GetPixelChannels(image);
2245 if (LocaleCompare(stream_info->map,"RGB") == 0)
2247 p=GetAuthenticPixelQueue(image);
2248 if (p == (const Quantum *) NULL)
2250 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2252 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2253 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2254 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2255 p+=GetPixelChannels(image);
2259 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2261 p=GetAuthenticPixelQueue(image);
2262 if (p == (const Quantum *) NULL)
2264 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2266 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2267 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2268 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2269 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2270 p+=GetPixelChannels(image);
2274 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2276 p=GetAuthenticPixelQueue(image);
2277 if (p == (const Quantum *) NULL)
2279 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2281 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2282 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2283 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2285 p+=GetPixelChannels(image);
2289 p=GetAuthenticPixelQueue(image);
2290 if (p == (const Quantum *) NULL)
2292 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2294 for (i=0; i < (ssize_t) length; i++)
2297 switch (quantum_map[i])
2302 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2306 case MagentaQuantum:
2308 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2314 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2319 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2322 case OpacityQuantum:
2324 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2329 if (image->colorspace == CMYKColorspace)
2330 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2335 *q=ScaleQuantumToLongLong(ClampToQuantum(
2336 GetPixelIntensity(image,p)));
2344 p+=GetPixelChannels(image);
2353 q=(Quantum *) stream_info->pixels;
2354 if (LocaleCompare(stream_info->map,"BGR") == 0)
2356 p=GetAuthenticPixelQueue(image);
2357 if (p == (const Quantum *) NULL)
2359 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2361 *q++=GetPixelBlue(image,p);
2362 *q++=GetPixelGreen(image,p);
2363 *q++=GetPixelRed(image,p);
2364 p+=GetPixelChannels(image);
2368 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2370 p=GetAuthenticPixelQueue(image);
2371 if (p == (const Quantum *) NULL)
2373 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2375 *q++=GetPixelBlue(image,p);
2376 *q++=GetPixelGreen(image,p);
2377 *q++=GetPixelRed(image,p);
2378 *q++=GetPixelAlpha(image,p);
2379 p+=GetPixelChannels(image);
2383 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2385 p=GetAuthenticPixelQueue(image);
2386 if (p == (const Quantum *) NULL)
2388 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2390 *q++=GetPixelBlue(image,p);
2391 *q++=GetPixelGreen(image,p);
2392 *q++=GetPixelRed(image,p);
2394 p+=GetPixelChannels(image);
2398 if (LocaleCompare(stream_info->map,"I") == 0)
2400 p=GetAuthenticPixelQueue(image);
2401 if (p == (const Quantum *) NULL)
2403 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2405 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2406 p+=GetPixelChannels(image);
2410 if (LocaleCompare(stream_info->map,"RGB") == 0)
2412 p=GetAuthenticPixelQueue(image);
2413 if (p == (const Quantum *) NULL)
2415 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2417 *q++=GetPixelRed(image,p);
2418 *q++=GetPixelGreen(image,p);
2419 *q++=GetPixelBlue(image,p);
2420 p+=GetPixelChannels(image);
2424 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2426 p=GetAuthenticPixelQueue(image);
2427 if (p == (const Quantum *) NULL)
2429 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2431 *q++=GetPixelRed(image,p);
2432 *q++=GetPixelGreen(image,p);
2433 *q++=GetPixelBlue(image,p);
2434 *q++=GetPixelAlpha(image,p);
2435 p+=GetPixelChannels(image);
2439 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2441 p=GetAuthenticPixelQueue(image);
2442 if (p == (const Quantum *) NULL)
2444 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2446 *q++=GetPixelRed(image,p);
2447 *q++=GetPixelGreen(image,p);
2448 *q++=GetPixelBlue(image,p);
2450 p+=GetPixelChannels(image);
2454 p=GetAuthenticPixelQueue(image);
2455 if (p == (const Quantum *) NULL)
2457 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2459 for (i=0; i < (ssize_t) length; i++)
2462 switch (quantum_map[i])
2467 *q=GetPixelRed(image,p);
2471 case MagentaQuantum:
2473 *q=GetPixelGreen(image,p);
2479 *q=GetPixelBlue(image,p);
2484 *q=(Quantum) (GetPixelAlpha(image,p));
2487 case OpacityQuantum:
2489 *q=GetPixelAlpha(image,p);
2494 if (image->colorspace == CMYKColorspace)
2495 *q=GetPixelBlack(image,p);
2500 *q=ClampToQuantum(GetPixelIntensity(image,p));
2508 p+=GetPixelChannels(image);
2514 register unsigned short
2517 q=(unsigned short *) stream_info->pixels;
2518 if (LocaleCompare(stream_info->map,"BGR") == 0)
2520 p=GetAuthenticPixelQueue(image);
2521 if (p == (const Quantum *) NULL)
2523 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2525 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2526 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2527 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2528 p+=GetPixelChannels(image);
2532 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2534 p=GetAuthenticPixelQueue(image);
2535 if (p == (const Quantum *) NULL)
2537 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2539 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2540 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2541 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2542 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2543 p+=GetPixelChannels(image);
2547 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2549 p=GetAuthenticPixelQueue(image);
2550 if (p == (const Quantum *) NULL)
2552 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2554 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2555 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2556 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2558 p+=GetPixelChannels(image);
2562 if (LocaleCompare(stream_info->map,"I") == 0)
2564 p=GetAuthenticPixelQueue(image);
2565 if (p == (const Quantum *) NULL)
2567 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2569 *q++=ScaleQuantumToShort(ClampToQuantum(
2570 GetPixelIntensity(image,p)));
2571 p+=GetPixelChannels(image);
2575 if (LocaleCompare(stream_info->map,"RGB") == 0)
2577 p=GetAuthenticPixelQueue(image);
2578 if (p == (const Quantum *) NULL)
2580 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2582 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2583 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2584 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2585 p+=GetPixelChannels(image);
2589 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2591 p=GetAuthenticPixelQueue(image);
2592 if (p == (const Quantum *) NULL)
2594 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2596 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2597 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2598 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2599 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2600 p+=GetPixelChannels(image);
2604 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2606 p=GetAuthenticPixelQueue(image);
2607 if (p == (const Quantum *) NULL)
2609 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2611 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2612 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2613 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2615 p+=GetPixelChannels(image);
2619 p=GetAuthenticPixelQueue(image);
2620 if (p == (const Quantum *) NULL)
2622 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2624 for (i=0; i < (ssize_t) length; i++)
2627 switch (quantum_map[i])
2632 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2636 case MagentaQuantum:
2638 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2644 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2649 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2652 case OpacityQuantum:
2654 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2659 if (image->colorspace == CMYKColorspace)
2660 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2665 *q=ScaleQuantumToShort(ClampToQuantum(
2666 GetPixelIntensity(image,p)));
2674 p+=GetPixelChannels(image);
2680 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2681 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2682 "UnrecognizedPixelMap","`%s'",stream_info->map);
2686 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2695 + 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 %
2699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2701 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2702 % the latest stream of pixels.
2704 % The format of the SyncAuthenticPixelsStream method is:
2706 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2707 % ExceptionInfo *exception)
2709 % A description of each parameter follows:
2711 % o image: the image.
2713 % o exception: return any errors or warnings in this structure.
2716 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2717 ExceptionInfo *exception)
2728 assert(image != (Image *) NULL);
2729 assert(image->signature == MagickCoreSignature);
2730 if (image->debug != MagickFalse)
2731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2732 cache_info=(CacheInfo *) image->cache;
2733 assert(cache_info->signature == MagickCoreSignature);
2734 stream_handler=GetBlobStreamHandler(image);
2735 if (stream_handler == (StreamHandler) NULL)
2737 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2738 "NoStreamHandlerIsDefined","`%s'",image->filename);
2739 return(MagickFalse);
2741 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2742 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2750 % W r i t e S t r e a m %
2754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2756 % WriteStream() makes the image pixels available to a user supplied callback
2757 % method immediately upon writing pixel data with the WriteImage() method.
2759 % The format of the WriteStream() method is:
2761 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2762 % StreamHandler stream,ExceptionInfo *exception)
2764 % A description of each parameter follows:
2766 % o image_info: the image info.
2768 % o stream: A callback method.
2770 % o exception: return any errors or warnings in this structure.
2773 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2774 Image *image,StreamHandler stream,ExceptionInfo *exception)
2782 assert(image_info != (ImageInfo *) NULL);
2783 assert(image_info->signature == MagickCoreSignature);
2784 if (image_info->debug != MagickFalse)
2785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2786 image_info->filename);
2787 assert(image != (Image *) NULL);
2788 assert(image->signature == MagickCoreSignature);
2789 write_info=CloneImageInfo(image_info);
2790 *write_info->magick='\0';
2791 write_info->stream=stream;
2792 status=WriteImage(write_info,image,exception);
2793 write_info=DestroyImageInfo(write_info);