2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % SSSSS TTTTT RRRR EEEEE AAA M M %
7 % SS T R R E A A MM MM %
8 % SSS T RRRR EEE AAAAA M M M %
10 % SSSSS T R R EEEEE A A M M %
13 % MagickCore Pixel Stream Methods %
20 % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/cache-private.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/composite-private.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/geometry.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/memory-private.h"
56 #include "MagickCore/pixel.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/quantum.h"
59 #include "MagickCore/quantum-private.h"
60 #include "MagickCore/semaphore.h"
61 #include "MagickCore/stream.h"
62 #include "MagickCore/stream-private.h"
63 #include "MagickCore/string_.h"
66 Typedef declaractions.
108 Declare pixel cache interfaces.
110 #if defined(__cplusplus) || defined(c_plusplus)
115 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
116 const ssize_t,const size_t,const size_t,ExceptionInfo *);
118 static MagickBooleanType
119 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
120 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
123 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
124 const size_t,ExceptionInfo *);
126 #if defined(__cplusplus) || defined(c_plusplus)
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 + A c q u i r e S t r e a m I n f o %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % AcquireStreamInfo() allocates the StreamInfo structure.
143 % The format of the AcquireStreamInfo method is:
145 % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
146 % ExceptionInfo *exception)
148 % A description of each parameter follows:
150 % o image_info: the image info.
152 % o exception: return any errors or warnings in this structure.
155 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
156 ExceptionInfo *exception)
161 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
162 if (stream_info == (StreamInfo *) NULL)
163 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
165 stream_info->pixels=(unsigned char *) MagickAssumeAligned(
166 AcquireAlignedMemory(1,sizeof(*stream_info->pixels)));
167 if (stream_info->pixels == (unsigned char *) NULL)
168 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
169 stream_info->map=ConstantString("RGB");
170 stream_info->storage_type=CharPixel;
171 stream_info->stream=AcquireImage(image_info,exception);
172 stream_info->signature=MagickSignature;
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 + D e s t r o y P i x e l S t r e a m %
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 % DestroyPixelStream() deallocates memory associated with the pixel stream.
189 % The format of the DestroyPixelStream() method is:
191 % void DestroyPixelStream(Image *image)
193 % A description of each parameter follows:
195 % o image: the image.
199 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
201 assert(cache_info != (CacheInfo *) NULL);
202 if (cache_info->mapped == MagickFalse)
203 (void) RelinquishAlignedMemory(cache_info->pixels);
205 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
206 cache_info->pixels=(Quantum *) NULL;
207 cache_info->metacontent=(void *) NULL;
208 cache_info->length=0;
209 cache_info->mapped=MagickFalse;
212 static void DestroyPixelStream(Image *image)
220 assert(image != (Image *) NULL);
221 assert(image->signature == MagickSignature);
222 if (image->debug != MagickFalse)
223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
224 cache_info=(CacheInfo *) image->cache;
225 assert(cache_info->signature == MagickSignature);
227 LockSemaphoreInfo(cache_info->semaphore);
228 cache_info->reference_count--;
229 if (cache_info->reference_count == 0)
231 UnlockSemaphoreInfo(cache_info->semaphore);
232 if (destroy == MagickFalse)
234 RelinquishStreamPixels(cache_info);
235 if (cache_info->nexus_info != (NexusInfo **) NULL)
236 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
237 cache_info->number_threads);
238 if (cache_info->file_semaphore != (SemaphoreInfo *) NULL)
239 DestroySemaphoreInfo(&cache_info->file_semaphore);
240 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
241 DestroySemaphoreInfo(&cache_info->semaphore);
242 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 + D e s t r o y S t r e a m I n f o %
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 % DestroyStreamInfo() destroys memory associated with the StreamInfo
259 % The format of the DestroyStreamInfo method is:
261 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
263 % A description of each parameter follows:
265 % o stream_info: the stream info.
268 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
271 assert(stream_info != (StreamInfo *) NULL);
272 assert(stream_info->signature == MagickSignature);
273 if (stream_info->map != (char *) NULL)
274 stream_info->map=DestroyString(stream_info->map);
275 if (stream_info->pixels != (unsigned char *) NULL)
276 stream_info->pixels=(unsigned char *) RelinquishAlignedMemory(
277 stream_info->pixels);
278 if (stream_info->stream != (Image *) NULL)
280 (void) CloseBlob(stream_info->stream);
281 stream_info->stream=DestroyImage(stream_info->stream);
283 if (stream_info->quantum_info != (QuantumInfo *) NULL)
284 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
285 stream_info->signature=(~MagickSignature);
286 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 + G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % GetAuthenticMetacontentFromStream() returns the metacontent corresponding
302 % with the last call to QueueAuthenticPixelsStream() or
303 % GetAuthenticPixelsStream().
305 % The format of the GetAuthenticMetacontentFromStream() method is:
307 % void *GetAuthenticMetacontentFromStream(const Image *image)
309 % A description of each parameter follows:
311 % o image: the image.
314 static void *GetAuthenticMetacontentFromStream(const Image *image)
319 assert(image != (Image *) NULL);
320 assert(image->signature == MagickSignature);
321 if (image->debug != MagickFalse)
322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
323 cache_info=(CacheInfo *) image->cache;
324 assert(cache_info->signature == MagickSignature);
325 return(cache_info->metacontent);
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 + G e t A u t h e n t i c P i x e l S t r e a m %
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
340 % cache as defined by the geometry parameters. A pointer to the pixels is
341 % returned if the pixels are transferred, otherwise a NULL is returned. For
342 % streams this method is a no-op.
344 % The format of the GetAuthenticPixelsStream() method is:
346 % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
347 % const ssize_t y,const size_t columns,const size_t rows,
348 % ExceptionInfo *exception)
350 % A description of each parameter follows:
352 % o image: the image.
354 % o x,y,columns,rows: These values define the perimeter of a region of
357 % o exception: return any errors or warnings in this structure.
360 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
361 const ssize_t y,const size_t columns,const size_t rows,
362 ExceptionInfo *exception)
367 assert(image != (Image *) NULL);
368 assert(image->signature == MagickSignature);
369 if (image->debug != MagickFalse)
370 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
371 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 + G e t A u t h e n t i c P i x e l F r o m S t e a m %
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
387 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
389 % The format of the GetAuthenticPixelsFromStream() method is:
391 % Quantum *GetAuthenticPixelsFromStream(const Image image)
393 % A description of each parameter follows:
395 % o image: the image.
398 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
403 assert(image != (Image *) NULL);
404 assert(image->signature == MagickSignature);
405 if (image->debug != MagickFalse)
406 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
407 cache_info=(CacheInfo *) image->cache;
408 assert(cache_info->signature == MagickSignature);
409 return(cache_info->pixels);
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 + G e t O n e A u t h e n t i c P i x e l F r o m S t r e a m %
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
424 % (x,y) location. The image background color is returned if an error occurs.
426 % The format of the GetOneAuthenticPixelFromStream() method is:
428 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
429 % const ssize_t x,const ssize_t y,Quantum *pixel,
430 % ExceptionInfo *exception)
432 % A description of each parameter follows:
434 % o image: the image.
436 % o pixel: return a pixel at the specified (x,y) location.
438 % o x,y: These values define the location of the pixel to return.
440 % o exception: return any errors or warnings in this structure.
443 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
444 const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
452 assert(image != (Image *) NULL);
453 assert(image->signature == MagickSignature);
454 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
455 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
456 if (q != (Quantum *) NULL)
458 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
459 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
460 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
461 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
462 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
465 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
467 PixelChannel channel=GetPixelChannelChannel(image,i);
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 + G e t O n e V i r t u a l P i x e l F r o m S t r e a m %
482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
485 % (x.y) location. The image background color is returned if an error occurs.
487 % The format of the GetOneVirtualPixelFromStream() method is:
489 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
490 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
491 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
493 % A description of each parameter follows:
495 % o image: the image.
497 % o virtual_pixel_method: the virtual pixel method.
499 % o x,y: These values define the location of the pixel to return.
501 % o pixel: return a pixel at the specified (x,y) location.
503 % o exception: return any errors or warnings in this structure.
506 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
507 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
508 Quantum *pixel,ExceptionInfo *exception)
516 assert(image != (Image *) NULL);
517 assert(image->signature == MagickSignature);
518 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
519 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
520 if (p == (const Quantum *) NULL)
522 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
523 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
524 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
525 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
526 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
529 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
531 PixelChannel channel=GetPixelChannelChannel(image,i);
538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 + G e t S t r e a m I n f o C l i e n t D a t a %
546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 % GetStreamInfoClientData() gets the stream info client data.
550 % The format of the GetStreamInfoClientData method is:
552 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
554 % A description of each parameter follows:
556 % o stream_info: the stream info.
559 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
561 assert(stream_info != (StreamInfo *) NULL);
562 assert(stream_info->signature == MagickSignature);
563 return(stream_info->client_data);
567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571 + G e t V i r t u a l P i x e l s F r o m S t r e a m %
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 % GetVirtualPixelsStream() returns the pixels associated with the last
578 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
580 % The format of the GetVirtualPixelsStream() method is:
582 % const Quantum *GetVirtualPixelsStream(const Image *image)
584 % A description of each parameter follows:
586 % o pixels: return the pixels associated corresponding with the last call to
587 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
589 % o image: the image.
592 static const Quantum *GetVirtualPixelsStream(const Image *image)
597 assert(image != (Image *) NULL);
598 assert(image->signature == MagickSignature);
599 if (image->debug != MagickFalse)
600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
601 cache_info=(CacheInfo *) image->cache;
602 assert(cache_info->signature == MagickSignature);
603 return(cache_info->pixels);
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
611 + G e t V i r t u a l I n d e x e s F r o m S t r e a m %
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 % GetVirtualMetacontentFromStream() returns the associated pixel channels
618 % corresponding with the last call to QueueAuthenticPixelsStream() or
619 % GetVirtualPixelStream().
621 % The format of the GetVirtualMetacontentFromStream() method is:
623 % const void *GetVirtualMetacontentFromStream(const Image *image)
625 % A description of each parameter follows:
627 % o image: the image.
630 static const void *GetVirtualMetacontentFromStream(const Image *image)
635 assert(image != (Image *) NULL);
636 assert(image->signature == MagickSignature);
637 if (image->debug != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
639 cache_info=(CacheInfo *) image->cache;
640 assert(cache_info->signature == MagickSignature);
641 return(cache_info->metacontent);
645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649 + G e t V i r t u a l P i x e l S t r e a m %
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
656 % defined by the geometry parameters. A pointer to the pixels is returned if
657 % the pixels are transferred, otherwise a NULL is returned. For streams this
660 % The format of the GetVirtualPixelStream() method is:
662 % const Quantum *GetVirtualPixelStream(const Image *image,
663 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
664 % const ssize_t y,const size_t columns,const size_t rows,
665 % ExceptionInfo *exception)
667 % A description of each parameter follows:
669 % o image: the image.
671 % o virtual_pixel_method: the virtual pixel method.
673 % o x,y,columns,rows: These values define the perimeter of a region of
676 % o exception: return any errors or warnings in this structure.
680 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
681 ExceptionInfo *exception)
683 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
685 cache_info->mapped=MagickFalse;
686 cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,(size_t)
688 if (cache_info->pixels == (Quantum *) NULL)
690 cache_info->mapped=MagickTrue;
691 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
694 if (cache_info->pixels == (Quantum *) NULL)
696 (void) ThrowMagickException(exception,GetMagickModule(),
697 ResourceLimitError,"MemoryAllocationFailed","`%s'",
698 cache_info->filename);
704 static const Quantum *GetVirtualPixelStream(const Image *image,
705 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
706 const ssize_t y,const size_t columns,const size_t rows,
707 ExceptionInfo *exception)
722 Validate pixel cache geometry.
724 assert(image != (const Image *) NULL);
725 assert(image->signature == MagickSignature);
726 if (image->debug != MagickFalse)
727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
728 if ((x < 0) || (y < 0) ||
729 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
730 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
731 (columns == 0) || (rows == 0))
733 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
734 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
735 return((Quantum *) NULL);
737 cache_info=(CacheInfo *) image->cache;
738 assert(cache_info->signature == MagickSignature);
740 Pixels are stored in a temporary buffer until they are synced to the cache.
742 number_pixels=(MagickSizeType) columns*rows;
743 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
744 if (cache_info->number_channels == 0)
745 length=number_pixels*sizeof(Quantum);
746 if (cache_info->metacontent_extent != 0)
747 length+=number_pixels*cache_info->metacontent_extent;
748 if (cache_info->pixels == (Quantum *) NULL)
750 cache_info->length=length;
751 status=AcquireStreamPixels(cache_info,exception);
752 if (status == MagickFalse)
754 cache_info->length=0;
755 return((Quantum *) NULL);
759 if (cache_info->length != length)
761 RelinquishStreamPixels(cache_info);
762 cache_info->length=length;
763 status=AcquireStreamPixels(cache_info,exception);
764 if (status == MagickFalse)
766 cache_info->length=0;
767 return((Quantum *) NULL);
770 cache_info->metacontent=(void *) NULL;
771 if (cache_info->metacontent_extent != 0)
772 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
773 cache_info->number_channels);
774 return(cache_info->pixels);
778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 + O p e n S t r e a m %
786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 % OpenStream() opens a stream for writing by the StreamImage() method.
790 % The format of the OpenStream method is:
792 % MagickBooleanType OpenStream(const ImageInfo *image_info,
793 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
795 % A description of each parameter follows:
797 % o image_info: the image info.
799 % o stream_info: the stream info.
801 % o filename: the stream filename.
803 % o exception: return any errors or warnings in this structure.
806 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
807 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
812 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
813 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 + 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 %
826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
828 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
829 % defined by the region rectangle and returns a pointer to the area. This
830 % area is subsequently transferred from the pixel cache with method
831 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
832 % pixels are transferred, otherwise a NULL is returned.
834 % The format of the QueueAuthenticPixelsStream() method is:
836 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
837 % const ssize_t y,const size_t columns,const size_t rows,
838 % ExceptionInfo *exception)
840 % A description of each parameter follows:
842 % o image: the image.
844 % o x,y,columns,rows: These values define the perimeter of a region of
848 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
849 const ssize_t y,const size_t columns,const size_t rows,
850 ExceptionInfo *exception)
868 Validate pixel cache geometry.
870 assert(image != (Image *) NULL);
871 if ((x < 0) || (y < 0) ||
872 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
873 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
874 (columns == 0) || (rows == 0))
876 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
877 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
878 return((Quantum *) NULL);
880 stream_handler=GetBlobStreamHandler(image);
881 if (stream_handler == (StreamHandler) NULL)
883 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
884 "NoStreamHandlerIsDefined","`%s'",image->filename);
885 return((Quantum *) NULL);
887 cache_info=(CacheInfo *) image->cache;
888 assert(cache_info->signature == MagickSignature);
889 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
890 (image->colorspace != GetPixelCacheColorspace(image->cache)))
892 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
893 (void) stream_handler(image,(const void *) NULL,(size_t)
894 cache_info->columns);
895 cache_info->storage_class=image->storage_class;
896 cache_info->colorspace=image->colorspace;
897 cache_info->columns=image->columns;
898 cache_info->rows=image->rows;
899 image->cache=cache_info;
902 Pixels are stored in a temporary buffer until they are synced to the cache.
904 cache_info->columns=columns;
905 cache_info->rows=rows;
906 number_pixels=(MagickSizeType) columns*rows;
907 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
908 if (cache_info->number_channels == 0)
909 length=number_pixels*sizeof(Quantum);
910 if (cache_info->metacontent_extent != 0)
911 length+=number_pixels*cache_info->metacontent_extent;
912 if (cache_info->pixels == (Quantum *) NULL)
914 cache_info->length=length;
915 status=AcquireStreamPixels(cache_info,exception);
916 if (status == MagickFalse)
918 cache_info->length=0;
919 return((Quantum *) NULL);
923 if (cache_info->length < length)
925 RelinquishStreamPixels(cache_info);
926 cache_info->length=length;
927 status=AcquireStreamPixels(cache_info,exception);
928 if (status == MagickFalse)
930 cache_info->length=0;
931 return((Quantum *) NULL);
934 cache_info->metacontent=(void *) NULL;
935 if (cache_info->metacontent_extent != 0)
936 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
937 cache_info->number_channels);
938 return(cache_info->pixels);
942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
946 % R e a d S t r e a m %
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
952 % ReadStream() makes the image pixels available to a user supplied callback
953 % method immediately upon reading a scanline with the ReadImage() method.
955 % The format of the ReadStream() method is:
957 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
958 % ExceptionInfo *exception)
960 % A description of each parameter follows:
962 % o image_info: the image info.
964 % o stream: a callback method.
966 % o exception: return any errors or warnings in this structure.
969 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
970 ExceptionInfo *exception)
984 assert(image_info != (ImageInfo *) NULL);
985 assert(image_info->signature == MagickSignature);
986 if (image_info->debug != MagickFalse)
987 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
988 image_info->filename);
989 assert(exception != (ExceptionInfo *) NULL);
990 assert(exception->signature == MagickSignature);
991 read_info=CloneImageInfo(image_info);
992 read_info->cache=AcquirePixelCache(0);
993 GetPixelCacheMethods(&cache_methods);
994 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
995 cache_methods.get_virtual_metacontent_from_handler=
996 GetVirtualMetacontentFromStream;
997 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
998 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
999 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1000 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1001 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1002 cache_methods.get_authentic_metacontent_from_handler=
1003 GetAuthenticMetacontentFromStream;
1004 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1005 cache_methods.get_one_authentic_pixel_from_handler=
1006 GetOneAuthenticPixelFromStream;
1007 cache_methods.destroy_pixel_handler=DestroyPixelStream;
1008 SetPixelCacheMethods(read_info->cache,&cache_methods);
1009 read_info->stream=stream;
1010 image=ReadImage(read_info,exception);
1011 read_info=DestroyImageInfo(read_info);
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1020 + S e t S t r e a m I n f o C l i e n t D a t a %
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1026 % SetStreamInfoClientData() sets the stream info client data.
1028 % The format of the SetStreamInfoClientData method is:
1030 % void SetStreamInfoClientData(StreamInfo *stream_info,
1031 % const void *client_data)
1033 % A description of each parameter follows:
1035 % o stream_info: the stream info.
1037 % o client_data: the client data.
1040 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1041 const void *client_data)
1043 assert(stream_info != (StreamInfo *) NULL);
1044 assert(stream_info->signature == MagickSignature);
1045 stream_info->client_data=client_data;
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1053 + S e t S t r e a m I n f o M a p %
1057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 % SetStreamInfoMap() sets the stream info map member.
1061 % The format of the SetStreamInfoMap method is:
1063 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1065 % A description of each parameter follows:
1067 % o stream_info: the stream info.
1072 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1074 assert(stream_info != (StreamInfo *) NULL);
1075 assert(stream_info->signature == MagickSignature);
1076 (void) CloneString(&stream_info->map,map);
1080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1084 + S e t S t r e a m I n f o S t o r a g e T y p e %
1088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090 % SetStreamInfoStorageType() sets the stream info storage type member.
1092 % The format of the SetStreamInfoStorageType method is:
1094 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1095 % const StoreageType *storage_type)
1097 % A description of each parameter follows:
1099 % o stream_info: the stream info.
1101 % o storage_type: the storage type.
1104 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1105 const StorageType storage_type)
1107 assert(stream_info != (StreamInfo *) NULL);
1108 assert(stream_info->signature == MagickSignature);
1109 stream_info->storage_type=storage_type;
1113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 + S t r e a m I m a g e %
1121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 % StreamImage() streams pixels from an image and writes them in a user
1124 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1126 % The format of the StreamImage() method is:
1128 % Image *StreamImage(const ImageInfo *image_info,
1129 % StreamInfo *stream_info,ExceptionInfo *exception)
1131 % A description of each parameter follows:
1133 % o image_info: the image info.
1135 % o stream_info: the stream info.
1137 % o exception: return any errors or warnings in this structure.
1141 #if defined(__cplusplus) || defined(c_plusplus)
1145 static size_t WriteStreamImage(const Image *image,const void *pixels,
1146 const size_t columns)
1165 stream_info=(StreamInfo *) image->client_data;
1166 switch (stream_info->storage_type)
1168 default: packet_size=sizeof(unsigned char); break;
1169 case CharPixel: packet_size=sizeof(unsigned char); break;
1170 case DoublePixel: packet_size=sizeof(double); break;
1171 case FloatPixel: packet_size=sizeof(float); break;
1172 case LongPixel: packet_size=sizeof(unsigned int); break;
1173 case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
1174 case QuantumPixel: packet_size=sizeof(Quantum); break;
1175 case ShortPixel: packet_size=sizeof(unsigned short); break;
1177 cache_info=(CacheInfo *) image->cache;
1178 assert(cache_info->signature == MagickSignature);
1179 packet_size*=strlen(stream_info->map);
1180 length=packet_size*cache_info->columns*cache_info->rows;
1181 if (image != stream_info->image)
1187 Prepare stream for writing.
1189 (void) RelinquishAlignedMemory(stream_info->pixels);
1190 stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
1191 if (stream_info->pixels == (unsigned char *) NULL)
1193 (void) ResetMagickMemory(stream_info->pixels,0,length);
1194 stream_info->image=image;
1195 write_info=CloneImageInfo(stream_info->image_info);
1196 (void) SetImageInfo(write_info,1,stream_info->exception);
1197 if (write_info->extract != (char *) NULL)
1198 (void) ParseAbsoluteGeometry(write_info->extract,
1199 &stream_info->extract_info);
1201 write_info=DestroyImageInfo(write_info);
1203 extract_info=stream_info->extract_info;
1204 if ((extract_info.width == 0) || (extract_info.height == 0))
1207 Write all pixels to stream.
1209 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1210 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1212 return(count == 0 ? 0 : columns);
1214 if ((stream_info->y < extract_info.y) ||
1215 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1221 Write a portion of the pixel row to the stream.
1223 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1224 length=packet_size*extract_info.width;
1225 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1228 return(count == 0 ? 0 : columns);
1231 #if defined(__cplusplus) || defined(c_plusplus)
1235 MagickExport Image *StreamImage(const ImageInfo *image_info,
1236 StreamInfo *stream_info,ExceptionInfo *exception)
1244 assert(image_info != (const ImageInfo *) NULL);
1245 assert(image_info->signature == MagickSignature);
1246 if (image_info->debug != MagickFalse)
1247 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1248 image_info->filename);
1249 assert(stream_info != (StreamInfo *) NULL);
1250 assert(stream_info->signature == MagickSignature);
1251 assert(exception != (ExceptionInfo *) NULL);
1252 read_info=CloneImageInfo(image_info);
1253 stream_info->image_info=image_info;
1254 stream_info->exception=exception;
1255 read_info->client_data=(void *) stream_info;
1256 image=ReadStream(read_info,&WriteStreamImage,exception);
1257 read_info=DestroyImageInfo(read_info);
1258 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1259 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1260 image=DestroyImage(image);
1265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1269 + S t r e a m I m a g e P i x e l s %
1273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1275 % StreamImagePixels() extracts pixel data from an image and returns it in the
1276 % stream_info->pixels structure in the format as defined by
1277 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1279 % The format of the StreamImagePixels method is:
1281 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1282 % const Image *image,ExceptionInfo *exception)
1284 % A description of each parameter follows:
1286 % o stream_info: the stream info.
1288 % o image: the image.
1290 % o exception: return any errors or warnings in this structure.
1293 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1294 const Image *image,ExceptionInfo *exception)
1302 register const Quantum
1312 assert(stream_info != (StreamInfo *) NULL);
1313 assert(stream_info->signature == MagickSignature);
1314 assert(image != (Image *) NULL);
1315 assert(image->signature == MagickSignature);
1316 if (image->debug != MagickFalse)
1317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1318 length=strlen(stream_info->map);
1319 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1320 if (quantum_map == (QuantumType *) NULL)
1322 (void) ThrowMagickException(exception,GetMagickModule(),
1323 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1324 return(MagickFalse);
1326 for (i=0; i < (ssize_t) length; i++)
1328 switch (stream_info->map[i])
1333 quantum_map[i]=AlphaQuantum;
1339 quantum_map[i]=BlueQuantum;
1345 quantum_map[i]=CyanQuantum;
1346 if (image->colorspace == CMYKColorspace)
1348 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1349 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1350 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1351 return(MagickFalse);
1356 quantum_map[i]=GreenQuantum;
1362 quantum_map[i]=IndexQuantum;
1368 quantum_map[i]=BlackQuantum;
1369 if (image->colorspace == CMYKColorspace)
1371 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1372 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1373 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1374 return(MagickFalse);
1379 quantum_map[i]=MagentaQuantum;
1380 if (image->colorspace == CMYKColorspace)
1382 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1383 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1384 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1385 return(MagickFalse);
1390 quantum_map[i]=OpacityQuantum;
1396 quantum_map[i]=UndefinedQuantum;
1402 quantum_map[i]=RedQuantum;
1408 quantum_map[i]=YellowQuantum;
1409 if (image->colorspace == CMYKColorspace)
1411 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1412 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1413 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1414 return(MagickFalse);
1418 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1419 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1420 "UnrecognizedPixelMap","`%s'",stream_info->map);
1421 return(MagickFalse);
1425 quantum_info=stream_info->quantum_info;
1426 switch (stream_info->storage_type)
1430 register unsigned char
1433 q=(unsigned char *) stream_info->pixels;
1434 if (LocaleCompare(stream_info->map,"BGR") == 0)
1436 p=GetAuthenticPixelQueue(image);
1437 if (p == (const Quantum *) NULL)
1439 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1441 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1442 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1443 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1448 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1450 p=GetAuthenticPixelQueue(image);
1451 if (p == (const Quantum *) NULL)
1453 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1455 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1456 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1457 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1458 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1463 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1465 p=GetAuthenticPixelQueue(image);
1466 if (p == (const Quantum *) NULL)
1468 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1470 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1471 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1472 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1473 *q++=ScaleQuantumToChar((Quantum) 0);
1478 if (LocaleCompare(stream_info->map,"I") == 0)
1480 p=GetAuthenticPixelQueue(image);
1481 if (p == (const Quantum *) NULL)
1483 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1485 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1490 if (LocaleCompare(stream_info->map,"RGB") == 0)
1492 p=GetAuthenticPixelQueue(image);
1493 if (p == (const Quantum *) NULL)
1495 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1497 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1498 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1499 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1504 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1506 p=GetAuthenticPixelQueue(image);
1507 if (p == (const Quantum *) NULL)
1509 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1511 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1512 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1513 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1514 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1519 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1521 p=GetAuthenticPixelQueue(image);
1522 if (p == (const Quantum *) NULL)
1524 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1526 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1527 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1528 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1529 *q++=ScaleQuantumToChar((Quantum) 0);
1534 p=GetAuthenticPixelQueue(image);
1535 if (p == (const Quantum *) NULL)
1537 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1539 for (i=0; i < (ssize_t) length; i++)
1542 switch (quantum_map[i])
1547 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1551 case MagentaQuantum:
1553 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1559 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1564 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1567 case OpacityQuantum:
1569 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1574 if (image->colorspace == CMYKColorspace)
1575 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1580 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1597 q=(double *) stream_info->pixels;
1598 if (LocaleCompare(stream_info->map,"BGR") == 0)
1600 p=GetAuthenticPixelQueue(image);
1601 if (p == (const Quantum *) NULL)
1603 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1605 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1606 quantum_info->scale+quantum_info->minimum);
1607 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1608 quantum_info->scale+quantum_info->minimum);
1609 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1610 quantum_info->scale+quantum_info->minimum);
1615 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1617 p=GetAuthenticPixelQueue(image);
1618 if (p == (const Quantum *) NULL)
1620 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1622 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1623 quantum_info->scale+quantum_info->minimum);
1624 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1625 quantum_info->scale+quantum_info->minimum);
1626 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1627 quantum_info->scale+quantum_info->minimum);
1628 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1629 quantum_info->scale+quantum_info->minimum);
1634 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1636 p=GetAuthenticPixelQueue(image);
1637 if (p == (const Quantum *) NULL)
1639 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1641 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1642 quantum_info->scale+quantum_info->minimum);
1643 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1644 quantum_info->scale+quantum_info->minimum);
1645 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1646 quantum_info->scale+quantum_info->minimum);
1652 if (LocaleCompare(stream_info->map,"I") == 0)
1654 p=GetAuthenticPixelQueue(image);
1655 if (p == (const Quantum *) NULL)
1657 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1659 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1660 quantum_info->scale+quantum_info->minimum);
1665 if (LocaleCompare(stream_info->map,"RGB") == 0)
1667 p=GetAuthenticPixelQueue(image);
1668 if (p == (const Quantum *) NULL)
1670 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1672 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1673 quantum_info->scale+quantum_info->minimum);
1674 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1675 quantum_info->scale+quantum_info->minimum);
1676 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1677 quantum_info->scale+quantum_info->minimum);
1682 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1684 p=GetAuthenticPixelQueue(image);
1685 if (p == (const Quantum *) NULL)
1687 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1689 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1690 quantum_info->scale+quantum_info->minimum);
1691 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1692 quantum_info->scale+quantum_info->minimum);
1693 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1694 quantum_info->scale+quantum_info->minimum);
1695 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1696 quantum_info->scale+quantum_info->minimum);
1701 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1703 p=GetAuthenticPixelQueue(image);
1704 if (p == (const Quantum *) NULL)
1706 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1708 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1709 quantum_info->scale+quantum_info->minimum);
1710 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1711 quantum_info->scale+quantum_info->minimum);
1712 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1713 quantum_info->scale+quantum_info->minimum);
1719 p=GetAuthenticPixelQueue(image);
1720 if (p == (const Quantum *) NULL)
1722 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1724 for (i=0; i < (ssize_t) length; i++)
1727 switch (quantum_map[i])
1732 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1733 quantum_info->scale+quantum_info->minimum);
1737 case MagentaQuantum:
1739 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1740 quantum_info->scale+quantum_info->minimum);
1746 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1747 quantum_info->scale+quantum_info->minimum);
1752 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1753 quantum_info->scale+quantum_info->minimum);
1756 case OpacityQuantum:
1758 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1759 quantum_info->scale+quantum_info->minimum);
1764 if (image->colorspace == CMYKColorspace)
1765 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1766 quantum_info->scale+quantum_info->minimum);
1771 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1772 quantum_info->scale+quantum_info->minimum);
1789 q=(float *) stream_info->pixels;
1790 if (LocaleCompare(stream_info->map,"BGR") == 0)
1792 p=GetAuthenticPixelQueue(image);
1793 if (p == (const Quantum *) NULL)
1795 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1797 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1798 quantum_info->scale+quantum_info->minimum);
1799 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1800 quantum_info->scale+quantum_info->minimum);
1801 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1802 quantum_info->scale+quantum_info->minimum);
1807 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1809 p=GetAuthenticPixelQueue(image);
1810 if (p == (const Quantum *) NULL)
1812 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1814 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1815 quantum_info->scale+quantum_info->minimum);
1816 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1817 quantum_info->scale+quantum_info->minimum);
1818 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1819 quantum_info->scale+quantum_info->minimum);
1820 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1821 quantum_info->scale+quantum_info->minimum);
1826 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1828 p=GetAuthenticPixelQueue(image);
1829 if (p == (const Quantum *) NULL)
1831 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1833 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1834 quantum_info->scale+quantum_info->minimum);
1835 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1836 quantum_info->scale+quantum_info->minimum);
1837 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1838 quantum_info->scale+quantum_info->minimum);
1844 if (LocaleCompare(stream_info->map,"I") == 0)
1846 p=GetAuthenticPixelQueue(image);
1847 if (p == (const Quantum *) NULL)
1849 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1851 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1852 quantum_info->scale+quantum_info->minimum);
1857 if (LocaleCompare(stream_info->map,"RGB") == 0)
1859 p=GetAuthenticPixelQueue(image);
1860 if (p == (const Quantum *) NULL)
1862 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1864 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1865 quantum_info->scale+quantum_info->minimum);
1866 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1867 quantum_info->scale+quantum_info->minimum);
1868 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1869 quantum_info->scale+quantum_info->minimum);
1874 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1876 p=GetAuthenticPixelQueue(image);
1877 if (p == (const Quantum *) NULL)
1879 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1881 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1882 quantum_info->scale+quantum_info->minimum);
1883 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1884 quantum_info->scale+quantum_info->minimum);
1885 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1886 quantum_info->scale+quantum_info->minimum);
1887 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1888 quantum_info->scale+quantum_info->minimum);
1893 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1895 p=GetAuthenticPixelQueue(image);
1896 if (p == (const Quantum *) NULL)
1898 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1900 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1901 quantum_info->scale+quantum_info->minimum);
1902 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1903 quantum_info->scale+quantum_info->minimum);
1904 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1905 quantum_info->scale+quantum_info->minimum);
1911 p=GetAuthenticPixelQueue(image);
1912 if (p == (const Quantum *) NULL)
1914 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1916 for (i=0; i < (ssize_t) length; i++)
1919 switch (quantum_map[i])
1924 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1925 quantum_info->scale+quantum_info->minimum);
1929 case MagentaQuantum:
1931 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1932 quantum_info->scale+quantum_info->minimum);
1938 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1939 quantum_info->scale+quantum_info->minimum);
1944 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1945 quantum_info->scale+quantum_info->minimum);
1948 case OpacityQuantum:
1950 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1951 quantum_info->scale+quantum_info->minimum);
1956 if (image->colorspace == CMYKColorspace)
1957 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1958 quantum_info->scale+quantum_info->minimum);
1963 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1964 quantum_info->scale+quantum_info->minimum);
1978 register unsigned int
1981 q=(unsigned int *) stream_info->pixels;
1982 if (LocaleCompare(stream_info->map,"BGR") == 0)
1984 p=GetAuthenticPixelQueue(image);
1985 if (p == (const Quantum *) NULL)
1987 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1989 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1990 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1991 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1996 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1998 p=GetAuthenticPixelQueue(image);
1999 if (p == (const Quantum *) NULL)
2001 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2003 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2004 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2005 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2006 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2011 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2013 p=GetAuthenticPixelQueue(image);
2014 if (p == (const Quantum *) NULL)
2016 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2018 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2019 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2020 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2026 if (LocaleCompare(stream_info->map,"I") == 0)
2028 p=GetAuthenticPixelQueue(image);
2029 if (p == (const Quantum *) NULL)
2031 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2033 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2038 if (LocaleCompare(stream_info->map,"RGB") == 0)
2040 p=GetAuthenticPixelQueue(image);
2041 if (p == (const Quantum *) NULL)
2043 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2045 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2046 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2047 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2052 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2054 p=GetAuthenticPixelQueue(image);
2055 if (p == (const Quantum *) NULL)
2057 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2059 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2060 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2061 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2062 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2067 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2069 p=GetAuthenticPixelQueue(image);
2070 if (p == (const Quantum *) NULL)
2072 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2074 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2075 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2076 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2082 p=GetAuthenticPixelQueue(image);
2083 if (p == (const Quantum *) NULL)
2085 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2087 for (i=0; i < (ssize_t) length; i++)
2090 switch (quantum_map[i])
2095 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2099 case MagentaQuantum:
2101 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2107 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2112 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2115 case OpacityQuantum:
2117 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2122 if (image->colorspace == CMYKColorspace)
2123 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2128 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2142 register MagickSizeType
2145 q=(MagickSizeType *) stream_info->pixels;
2146 if (LocaleCompare(stream_info->map,"BGR") == 0)
2148 p=GetAuthenticPixelQueue(image);
2149 if (p == (const Quantum *) NULL)
2151 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2153 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2154 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2155 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2160 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2162 p=GetAuthenticPixelQueue(image);
2163 if (p == (const Quantum *) NULL)
2165 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2167 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2168 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2169 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2170 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2175 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2177 p=GetAuthenticPixelQueue(image);
2178 if (p == (const Quantum *) NULL)
2180 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2182 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2183 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2184 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2190 if (LocaleCompare(stream_info->map,"I") == 0)
2192 p=GetAuthenticPixelQueue(image);
2193 if (p == (const Quantum *) NULL)
2195 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2197 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2198 GetPixelIntensity(image,p)));
2203 if (LocaleCompare(stream_info->map,"RGB") == 0)
2205 p=GetAuthenticPixelQueue(image);
2206 if (p == (const Quantum *) NULL)
2208 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2210 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2211 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2212 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2217 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2219 p=GetAuthenticPixelQueue(image);
2220 if (p == (const Quantum *) NULL)
2222 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2224 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2225 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2226 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2227 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2232 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2234 p=GetAuthenticPixelQueue(image);
2235 if (p == (const Quantum *) NULL)
2237 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2239 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2240 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2241 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2247 p=GetAuthenticPixelQueue(image);
2248 if (p == (const Quantum *) NULL)
2250 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2252 for (i=0; i < (ssize_t) length; i++)
2255 switch (quantum_map[i])
2260 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2264 case MagentaQuantum:
2266 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2272 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2277 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2280 case OpacityQuantum:
2282 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2287 if (image->colorspace == CMYKColorspace)
2288 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2293 *q=ScaleQuantumToLongLong(ClampToQuantum(
2294 GetPixelIntensity(image,p)));
2311 q=(Quantum *) stream_info->pixels;
2312 if (LocaleCompare(stream_info->map,"BGR") == 0)
2314 p=GetAuthenticPixelQueue(image);
2315 if (p == (const Quantum *) NULL)
2317 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2319 *q++=GetPixelBlue(image,p);
2320 *q++=GetPixelGreen(image,p);
2321 *q++=GetPixelRed(image,p);
2326 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2328 p=GetAuthenticPixelQueue(image);
2329 if (p == (const Quantum *) NULL)
2331 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2333 *q++=GetPixelBlue(image,p);
2334 *q++=GetPixelGreen(image,p);
2335 *q++=GetPixelRed(image,p);
2336 *q++=GetPixelAlpha(image,p);
2341 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2343 p=GetAuthenticPixelQueue(image);
2344 if (p == (const Quantum *) NULL)
2346 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2348 *q++=GetPixelBlue(image,p);
2349 *q++=GetPixelGreen(image,p);
2350 *q++=GetPixelRed(image,p);
2356 if (LocaleCompare(stream_info->map,"I") == 0)
2358 p=GetAuthenticPixelQueue(image);
2359 if (p == (const Quantum *) NULL)
2361 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2363 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2368 if (LocaleCompare(stream_info->map,"RGB") == 0)
2370 p=GetAuthenticPixelQueue(image);
2371 if (p == (const Quantum *) NULL)
2373 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2375 *q++=GetPixelRed(image,p);
2376 *q++=GetPixelGreen(image,p);
2377 *q++=GetPixelBlue(image,p);
2382 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2384 p=GetAuthenticPixelQueue(image);
2385 if (p == (const Quantum *) NULL)
2387 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2389 *q++=GetPixelRed(image,p);
2390 *q++=GetPixelGreen(image,p);
2391 *q++=GetPixelBlue(image,p);
2392 *q++=GetPixelAlpha(image,p);
2397 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2399 p=GetAuthenticPixelQueue(image);
2400 if (p == (const Quantum *) NULL)
2402 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2404 *q++=GetPixelRed(image,p);
2405 *q++=GetPixelGreen(image,p);
2406 *q++=GetPixelBlue(image,p);
2412 p=GetAuthenticPixelQueue(image);
2413 if (p == (const Quantum *) NULL)
2415 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2417 for (i=0; i < (ssize_t) length; i++)
2420 switch (quantum_map[i])
2425 *q=GetPixelRed(image,p);
2429 case MagentaQuantum:
2431 *q=GetPixelGreen(image,p);
2437 *q=GetPixelBlue(image,p);
2442 *q=(Quantum) (GetPixelAlpha(image,p));
2445 case OpacityQuantum:
2447 *q=GetPixelAlpha(image,p);
2452 if (image->colorspace == CMYKColorspace)
2453 *q=GetPixelBlack(image,p);
2458 *q=ClampToQuantum(GetPixelIntensity(image,p));
2472 register unsigned short
2475 q=(unsigned short *) stream_info->pixels;
2476 if (LocaleCompare(stream_info->map,"BGR") == 0)
2478 p=GetAuthenticPixelQueue(image);
2479 if (p == (const Quantum *) NULL)
2481 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2483 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2484 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2485 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2490 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2492 p=GetAuthenticPixelQueue(image);
2493 if (p == (const Quantum *) NULL)
2495 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2497 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2498 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2499 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2500 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2505 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2507 p=GetAuthenticPixelQueue(image);
2508 if (p == (const Quantum *) NULL)
2510 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2512 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2513 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2514 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2520 if (LocaleCompare(stream_info->map,"I") == 0)
2522 p=GetAuthenticPixelQueue(image);
2523 if (p == (const Quantum *) NULL)
2525 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2527 *q++=ScaleQuantumToShort(ClampToQuantum(
2528 GetPixelIntensity(image,p)));
2533 if (LocaleCompare(stream_info->map,"RGB") == 0)
2535 p=GetAuthenticPixelQueue(image);
2536 if (p == (const Quantum *) NULL)
2538 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2540 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2541 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2542 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2547 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2549 p=GetAuthenticPixelQueue(image);
2550 if (p == (const Quantum *) NULL)
2552 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2554 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2555 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2556 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2557 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2562 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2564 p=GetAuthenticPixelQueue(image);
2565 if (p == (const Quantum *) NULL)
2567 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2569 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2570 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2571 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2577 p=GetAuthenticPixelQueue(image);
2578 if (p == (const Quantum *) NULL)
2580 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2582 for (i=0; i < (ssize_t) length; i++)
2585 switch (quantum_map[i])
2590 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2594 case MagentaQuantum:
2596 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2602 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2607 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2610 case OpacityQuantum:
2612 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2617 if (image->colorspace == CMYKColorspace)
2618 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2623 *q=ScaleQuantumToShort(ClampToQuantum(
2624 GetPixelIntensity(image,p)));
2638 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2639 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2640 "UnrecognizedPixelMap","`%s'",stream_info->map);
2644 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2653 + 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 %
2657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2660 % the latest stream of pixels.
2662 % The format of the SyncAuthenticPixelsStream method is:
2664 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2665 % ExceptionInfo *exception)
2667 % A description of each parameter follows:
2669 % o image: the image.
2671 % o exception: return any errors or warnings in this structure.
2674 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2675 ExceptionInfo *exception)
2686 assert(image != (Image *) NULL);
2687 assert(image->signature == MagickSignature);
2688 if (image->debug != MagickFalse)
2689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2690 cache_info=(CacheInfo *) image->cache;
2691 assert(cache_info->signature == MagickSignature);
2692 stream_handler=GetBlobStreamHandler(image);
2693 if (stream_handler == (StreamHandler) NULL)
2695 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2696 "NoStreamHandlerIsDefined","`%s'",image->filename);
2697 return(MagickFalse);
2699 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2700 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2708 % W r i t e S t r e a m %
2712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2714 % WriteStream() makes the image pixels available to a user supplied callback
2715 % method immediately upon writing pixel data with the WriteImage() method.
2717 % The format of the WriteStream() method is:
2719 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2720 % StreamHandler stream,ExceptionInfo *exception)
2722 % A description of each parameter follows:
2724 % o image_info: the image info.
2726 % o stream: A callback method.
2728 % o exception: return any errors or warnings in this structure.
2731 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2732 Image *image,StreamHandler stream,ExceptionInfo *exception)
2740 assert(image_info != (ImageInfo *) NULL);
2741 assert(image_info->signature == MagickSignature);
2742 if (image_info->debug != MagickFalse)
2743 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2744 image_info->filename);
2745 assert(image != (Image *) NULL);
2746 assert(image->signature == MagickSignature);
2747 write_info=CloneImageInfo(image_info);
2748 write_info->stream=stream;
2749 status=WriteImage(write_info,image,exception);
2750 write_info=DestroyImageInfo(write_info);