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-2015 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 RelinquishSemaphoreInfo(&cache_info->file_semaphore);
240 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
241 RelinquishSemaphoreInfo(&cache_info->semaphore);
242 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 + D e s t r o y S t r e a m I n f o %
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 % DestroyStreamInfo() destroys memory associated with the StreamInfo
259 % The format of the DestroyStreamInfo method is:
261 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
263 % A description of each parameter follows:
265 % o stream_info: the stream info.
268 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
271 assert(stream_info != (StreamInfo *) NULL);
272 assert(stream_info->signature == 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 p=GetAuthenticPixelsStream(image,x,y,1,1,exception);
456 if (p == (Quantum *) NULL)
458 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
459 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
460 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
461 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
462 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
465 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
467 PixelChannel channel=GetPixelChannelChannel(image,i);
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 + G e t O n e V i r t u a l P i x e l F r o m S t r e a m %
482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
485 % (x.y) location. The image background color is returned if an error occurs.
487 % The format of the GetOneVirtualPixelFromStream() method is:
489 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
490 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
491 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
493 % A description of each parameter follows:
495 % o image: the image.
497 % o virtual_pixel_method: the virtual pixel method.
499 % o x,y: These values define the location of the pixel to return.
501 % o pixel: return a pixel at the specified (x,y) location.
503 % o exception: return any errors or warnings in this structure.
506 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
507 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
508 Quantum *pixel,ExceptionInfo *exception)
516 assert(image != (Image *) NULL);
517 assert(image->signature == 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->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
1255 stream_info->exception=exception;
1256 read_info->client_data=(void *) stream_info;
1257 image=ReadStream(read_info,&WriteStreamImage,exception);
1258 read_info=DestroyImageInfo(read_info);
1259 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1260 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1261 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1262 image=DestroyImage(image);
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 + S t r e a m I m a g e P i x e l s %
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1277 % StreamImagePixels() extracts pixel data from an image and returns it in the
1278 % stream_info->pixels structure in the format as defined by
1279 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1281 % The format of the StreamImagePixels method is:
1283 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1284 % const Image *image,ExceptionInfo *exception)
1286 % A description of each parameter follows:
1288 % o stream_info: the stream info.
1290 % o image: the image.
1292 % o exception: return any errors or warnings in this structure.
1295 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1296 const Image *image,ExceptionInfo *exception)
1304 register const Quantum
1314 assert(stream_info != (StreamInfo *) NULL);
1315 assert(stream_info->signature == MagickSignature);
1316 assert(image != (Image *) NULL);
1317 assert(image->signature == MagickSignature);
1318 if (image->debug != MagickFalse)
1319 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1320 length=strlen(stream_info->map);
1321 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1322 if (quantum_map == (QuantumType *) NULL)
1324 (void) ThrowMagickException(exception,GetMagickModule(),
1325 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1326 return(MagickFalse);
1328 for (i=0; i < (ssize_t) length; i++)
1330 switch (stream_info->map[i])
1335 quantum_map[i]=AlphaQuantum;
1341 quantum_map[i]=BlueQuantum;
1347 quantum_map[i]=CyanQuantum;
1348 if (image->colorspace == CMYKColorspace)
1350 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1351 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1352 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1353 return(MagickFalse);
1358 quantum_map[i]=GreenQuantum;
1364 quantum_map[i]=IndexQuantum;
1370 quantum_map[i]=BlackQuantum;
1371 if (image->colorspace == CMYKColorspace)
1373 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1374 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1375 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1376 return(MagickFalse);
1381 quantum_map[i]=MagentaQuantum;
1382 if (image->colorspace == CMYKColorspace)
1384 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1385 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1386 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1387 return(MagickFalse);
1392 quantum_map[i]=OpacityQuantum;
1398 quantum_map[i]=UndefinedQuantum;
1404 quantum_map[i]=RedQuantum;
1410 quantum_map[i]=YellowQuantum;
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);
1420 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1421 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1422 "UnrecognizedPixelMap","`%s'",stream_info->map);
1423 return(MagickFalse);
1427 quantum_info=stream_info->quantum_info;
1428 switch (stream_info->storage_type)
1432 register unsigned char
1435 q=(unsigned char *) stream_info->pixels;
1436 if (LocaleCompare(stream_info->map,"BGR") == 0)
1438 p=GetAuthenticPixelQueue(image);
1439 if (p == (const Quantum *) NULL)
1441 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1443 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1444 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1445 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1450 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1452 p=GetAuthenticPixelQueue(image);
1453 if (p == (const Quantum *) NULL)
1455 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1457 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1458 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1459 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1460 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1465 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1467 p=GetAuthenticPixelQueue(image);
1468 if (p == (const Quantum *) NULL)
1470 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1472 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1473 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1474 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1475 *q++=ScaleQuantumToChar((Quantum) 0);
1480 if (LocaleCompare(stream_info->map,"I") == 0)
1482 p=GetAuthenticPixelQueue(image);
1483 if (p == (const Quantum *) NULL)
1485 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1487 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1492 if (LocaleCompare(stream_info->map,"RGB") == 0)
1494 p=GetAuthenticPixelQueue(image);
1495 if (p == (const Quantum *) NULL)
1497 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1499 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1500 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1501 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1506 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1508 p=GetAuthenticPixelQueue(image);
1509 if (p == (const Quantum *) NULL)
1511 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1513 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1514 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1515 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1516 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1521 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1523 p=GetAuthenticPixelQueue(image);
1524 if (p == (const Quantum *) NULL)
1526 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1528 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1529 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1530 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1531 *q++=ScaleQuantumToChar((Quantum) 0);
1536 p=GetAuthenticPixelQueue(image);
1537 if (p == (const Quantum *) NULL)
1539 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1541 for (i=0; i < (ssize_t) length; i++)
1544 switch (quantum_map[i])
1549 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1553 case MagentaQuantum:
1555 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1561 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1566 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1569 case OpacityQuantum:
1571 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1576 if (image->colorspace == CMYKColorspace)
1577 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1582 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1599 q=(double *) stream_info->pixels;
1600 if (LocaleCompare(stream_info->map,"BGR") == 0)
1602 p=GetAuthenticPixelQueue(image);
1603 if (p == (const Quantum *) NULL)
1605 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1607 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1608 quantum_info->scale+quantum_info->minimum);
1609 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1610 quantum_info->scale+quantum_info->minimum);
1611 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1612 quantum_info->scale+quantum_info->minimum);
1617 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1619 p=GetAuthenticPixelQueue(image);
1620 if (p == (const Quantum *) NULL)
1622 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1624 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1625 quantum_info->scale+quantum_info->minimum);
1626 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1627 quantum_info->scale+quantum_info->minimum);
1628 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1629 quantum_info->scale+quantum_info->minimum);
1630 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1631 quantum_info->scale+quantum_info->minimum);
1636 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1638 p=GetAuthenticPixelQueue(image);
1639 if (p == (const Quantum *) NULL)
1641 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1643 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1644 quantum_info->scale+quantum_info->minimum);
1645 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1646 quantum_info->scale+quantum_info->minimum);
1647 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1654 if (LocaleCompare(stream_info->map,"I") == 0)
1656 p=GetAuthenticPixelQueue(image);
1657 if (p == (const Quantum *) NULL)
1659 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1661 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1662 quantum_info->scale+quantum_info->minimum);
1667 if (LocaleCompare(stream_info->map,"RGB") == 0)
1669 p=GetAuthenticPixelQueue(image);
1670 if (p == (const Quantum *) NULL)
1672 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1674 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1675 quantum_info->scale+quantum_info->minimum);
1676 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1677 quantum_info->scale+quantum_info->minimum);
1678 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1679 quantum_info->scale+quantum_info->minimum);
1684 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1686 p=GetAuthenticPixelQueue(image);
1687 if (p == (const Quantum *) NULL)
1689 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1691 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1692 quantum_info->scale+quantum_info->minimum);
1693 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1694 quantum_info->scale+quantum_info->minimum);
1695 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1696 quantum_info->scale+quantum_info->minimum);
1697 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1698 quantum_info->scale+quantum_info->minimum);
1703 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1705 p=GetAuthenticPixelQueue(image);
1706 if (p == (const Quantum *) NULL)
1708 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1710 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1711 quantum_info->scale+quantum_info->minimum);
1712 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1713 quantum_info->scale+quantum_info->minimum);
1714 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1715 quantum_info->scale+quantum_info->minimum);
1721 p=GetAuthenticPixelQueue(image);
1722 if (p == (const Quantum *) NULL)
1724 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1726 for (i=0; i < (ssize_t) length; i++)
1729 switch (quantum_map[i])
1734 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1735 quantum_info->scale+quantum_info->minimum);
1739 case MagentaQuantum:
1741 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1742 quantum_info->scale+quantum_info->minimum);
1748 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1749 quantum_info->scale+quantum_info->minimum);
1754 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1755 quantum_info->scale+quantum_info->minimum);
1758 case OpacityQuantum:
1760 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1761 quantum_info->scale+quantum_info->minimum);
1766 if (image->colorspace == CMYKColorspace)
1767 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1768 quantum_info->scale+quantum_info->minimum);
1773 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1774 quantum_info->scale+quantum_info->minimum);
1791 q=(float *) stream_info->pixels;
1792 if (LocaleCompare(stream_info->map,"BGR") == 0)
1794 p=GetAuthenticPixelQueue(image);
1795 if (p == (const Quantum *) NULL)
1797 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1799 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1800 quantum_info->scale+quantum_info->minimum);
1801 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1802 quantum_info->scale+quantum_info->minimum);
1803 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1804 quantum_info->scale+quantum_info->minimum);
1809 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1811 p=GetAuthenticPixelQueue(image);
1812 if (p == (const Quantum *) NULL)
1814 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1816 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1817 quantum_info->scale+quantum_info->minimum);
1818 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1819 quantum_info->scale+quantum_info->minimum);
1820 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1821 quantum_info->scale+quantum_info->minimum);
1822 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1823 quantum_info->scale+quantum_info->minimum);
1828 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1830 p=GetAuthenticPixelQueue(image);
1831 if (p == (const Quantum *) NULL)
1833 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1835 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1836 quantum_info->scale+quantum_info->minimum);
1837 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1838 quantum_info->scale+quantum_info->minimum);
1839 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1846 if (LocaleCompare(stream_info->map,"I") == 0)
1848 p=GetAuthenticPixelQueue(image);
1849 if (p == (const Quantum *) NULL)
1851 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1853 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1854 quantum_info->scale+quantum_info->minimum);
1859 if (LocaleCompare(stream_info->map,"RGB") == 0)
1861 p=GetAuthenticPixelQueue(image);
1862 if (p == (const Quantum *) NULL)
1864 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1866 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1867 quantum_info->scale+quantum_info->minimum);
1868 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1869 quantum_info->scale+quantum_info->minimum);
1870 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1871 quantum_info->scale+quantum_info->minimum);
1876 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1878 p=GetAuthenticPixelQueue(image);
1879 if (p == (const Quantum *) NULL)
1881 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1883 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1884 quantum_info->scale+quantum_info->minimum);
1885 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1886 quantum_info->scale+quantum_info->minimum);
1887 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1888 quantum_info->scale+quantum_info->minimum);
1889 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1890 quantum_info->scale+quantum_info->minimum);
1895 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1897 p=GetAuthenticPixelQueue(image);
1898 if (p == (const Quantum *) NULL)
1900 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1902 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1903 quantum_info->scale+quantum_info->minimum);
1904 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1905 quantum_info->scale+quantum_info->minimum);
1906 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1907 quantum_info->scale+quantum_info->minimum);
1913 p=GetAuthenticPixelQueue(image);
1914 if (p == (const Quantum *) NULL)
1916 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1918 for (i=0; i < (ssize_t) length; i++)
1921 switch (quantum_map[i])
1926 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1927 quantum_info->scale+quantum_info->minimum);
1931 case MagentaQuantum:
1933 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1934 quantum_info->scale+quantum_info->minimum);
1940 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1941 quantum_info->scale+quantum_info->minimum);
1946 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1947 quantum_info->scale+quantum_info->minimum);
1950 case OpacityQuantum:
1952 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1953 quantum_info->scale+quantum_info->minimum);
1958 if (image->colorspace == CMYKColorspace)
1959 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1960 quantum_info->scale+quantum_info->minimum);
1965 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1966 quantum_info->scale+quantum_info->minimum);
1980 register unsigned int
1983 q=(unsigned int *) stream_info->pixels;
1984 if (LocaleCompare(stream_info->map,"BGR") == 0)
1986 p=GetAuthenticPixelQueue(image);
1987 if (p == (const Quantum *) NULL)
1989 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1991 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1992 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1993 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1998 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2000 p=GetAuthenticPixelQueue(image);
2001 if (p == (const Quantum *) NULL)
2003 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2005 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2006 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2007 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2008 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2013 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2015 p=GetAuthenticPixelQueue(image);
2016 if (p == (const Quantum *) NULL)
2018 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2020 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2021 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2022 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2028 if (LocaleCompare(stream_info->map,"I") == 0)
2030 p=GetAuthenticPixelQueue(image);
2031 if (p == (const Quantum *) NULL)
2033 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2035 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2040 if (LocaleCompare(stream_info->map,"RGB") == 0)
2042 p=GetAuthenticPixelQueue(image);
2043 if (p == (const Quantum *) NULL)
2045 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2047 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2048 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2049 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2054 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2056 p=GetAuthenticPixelQueue(image);
2057 if (p == (const Quantum *) NULL)
2059 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2061 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2062 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2063 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2064 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2069 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2071 p=GetAuthenticPixelQueue(image);
2072 if (p == (const Quantum *) NULL)
2074 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2076 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2077 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2078 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2084 p=GetAuthenticPixelQueue(image);
2085 if (p == (const Quantum *) NULL)
2087 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2089 for (i=0; i < (ssize_t) length; i++)
2092 switch (quantum_map[i])
2097 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2101 case MagentaQuantum:
2103 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2109 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2114 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2117 case OpacityQuantum:
2119 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2124 if (image->colorspace == CMYKColorspace)
2125 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2130 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2144 register MagickSizeType
2147 q=(MagickSizeType *) stream_info->pixels;
2148 if (LocaleCompare(stream_info->map,"BGR") == 0)
2150 p=GetAuthenticPixelQueue(image);
2151 if (p == (const Quantum *) NULL)
2153 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2155 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2156 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2157 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2162 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2164 p=GetAuthenticPixelQueue(image);
2165 if (p == (const Quantum *) NULL)
2167 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2169 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2170 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2171 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2172 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2177 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2179 p=GetAuthenticPixelQueue(image);
2180 if (p == (const Quantum *) NULL)
2182 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2184 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2185 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2186 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2192 if (LocaleCompare(stream_info->map,"I") == 0)
2194 p=GetAuthenticPixelQueue(image);
2195 if (p == (const Quantum *) NULL)
2197 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2199 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2200 GetPixelIntensity(image,p)));
2205 if (LocaleCompare(stream_info->map,"RGB") == 0)
2207 p=GetAuthenticPixelQueue(image);
2208 if (p == (const Quantum *) NULL)
2210 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2212 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2213 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2214 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2219 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2221 p=GetAuthenticPixelQueue(image);
2222 if (p == (const Quantum *) NULL)
2224 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2226 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2227 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2228 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2229 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2234 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2236 p=GetAuthenticPixelQueue(image);
2237 if (p == (const Quantum *) NULL)
2239 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2241 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2242 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2243 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2249 p=GetAuthenticPixelQueue(image);
2250 if (p == (const Quantum *) NULL)
2252 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2254 for (i=0; i < (ssize_t) length; i++)
2257 switch (quantum_map[i])
2262 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2266 case MagentaQuantum:
2268 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2274 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2279 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2282 case OpacityQuantum:
2284 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2289 if (image->colorspace == CMYKColorspace)
2290 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2295 *q=ScaleQuantumToLongLong(ClampToQuantum(
2296 GetPixelIntensity(image,p)));
2313 q=(Quantum *) stream_info->pixels;
2314 if (LocaleCompare(stream_info->map,"BGR") == 0)
2316 p=GetAuthenticPixelQueue(image);
2317 if (p == (const Quantum *) NULL)
2319 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2321 *q++=GetPixelBlue(image,p);
2322 *q++=GetPixelGreen(image,p);
2323 *q++=GetPixelRed(image,p);
2328 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2330 p=GetAuthenticPixelQueue(image);
2331 if (p == (const Quantum *) NULL)
2333 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2335 *q++=GetPixelBlue(image,p);
2336 *q++=GetPixelGreen(image,p);
2337 *q++=GetPixelRed(image,p);
2338 *q++=GetPixelAlpha(image,p);
2343 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2345 p=GetAuthenticPixelQueue(image);
2346 if (p == (const Quantum *) NULL)
2348 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2350 *q++=GetPixelBlue(image,p);
2351 *q++=GetPixelGreen(image,p);
2352 *q++=GetPixelRed(image,p);
2358 if (LocaleCompare(stream_info->map,"I") == 0)
2360 p=GetAuthenticPixelQueue(image);
2361 if (p == (const Quantum *) NULL)
2363 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2365 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2370 if (LocaleCompare(stream_info->map,"RGB") == 0)
2372 p=GetAuthenticPixelQueue(image);
2373 if (p == (const Quantum *) NULL)
2375 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2377 *q++=GetPixelRed(image,p);
2378 *q++=GetPixelGreen(image,p);
2379 *q++=GetPixelBlue(image,p);
2384 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2386 p=GetAuthenticPixelQueue(image);
2387 if (p == (const Quantum *) NULL)
2389 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2391 *q++=GetPixelRed(image,p);
2392 *q++=GetPixelGreen(image,p);
2393 *q++=GetPixelBlue(image,p);
2394 *q++=GetPixelAlpha(image,p);
2399 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2401 p=GetAuthenticPixelQueue(image);
2402 if (p == (const Quantum *) NULL)
2404 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2406 *q++=GetPixelRed(image,p);
2407 *q++=GetPixelGreen(image,p);
2408 *q++=GetPixelBlue(image,p);
2414 p=GetAuthenticPixelQueue(image);
2415 if (p == (const Quantum *) NULL)
2417 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2419 for (i=0; i < (ssize_t) length; i++)
2422 switch (quantum_map[i])
2427 *q=GetPixelRed(image,p);
2431 case MagentaQuantum:
2433 *q=GetPixelGreen(image,p);
2439 *q=GetPixelBlue(image,p);
2444 *q=(Quantum) (GetPixelAlpha(image,p));
2447 case OpacityQuantum:
2449 *q=GetPixelAlpha(image,p);
2454 if (image->colorspace == CMYKColorspace)
2455 *q=GetPixelBlack(image,p);
2460 *q=ClampToQuantum(GetPixelIntensity(image,p));
2474 register unsigned short
2477 q=(unsigned short *) stream_info->pixels;
2478 if (LocaleCompare(stream_info->map,"BGR") == 0)
2480 p=GetAuthenticPixelQueue(image);
2481 if (p == (const Quantum *) NULL)
2483 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2485 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2486 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2487 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2492 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2494 p=GetAuthenticPixelQueue(image);
2495 if (p == (const Quantum *) NULL)
2497 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2499 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2500 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2501 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2502 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2507 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2509 p=GetAuthenticPixelQueue(image);
2510 if (p == (const Quantum *) NULL)
2512 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2514 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2515 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2516 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2522 if (LocaleCompare(stream_info->map,"I") == 0)
2524 p=GetAuthenticPixelQueue(image);
2525 if (p == (const Quantum *) NULL)
2527 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2529 *q++=ScaleQuantumToShort(ClampToQuantum(
2530 GetPixelIntensity(image,p)));
2535 if (LocaleCompare(stream_info->map,"RGB") == 0)
2537 p=GetAuthenticPixelQueue(image);
2538 if (p == (const Quantum *) NULL)
2540 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2542 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2543 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2544 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2549 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2551 p=GetAuthenticPixelQueue(image);
2552 if (p == (const Quantum *) NULL)
2554 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2556 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2557 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2558 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2559 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2564 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2566 p=GetAuthenticPixelQueue(image);
2567 if (p == (const Quantum *) NULL)
2569 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2571 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2572 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2573 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2579 p=GetAuthenticPixelQueue(image);
2580 if (p == (const Quantum *) NULL)
2582 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2584 for (i=0; i < (ssize_t) length; i++)
2587 switch (quantum_map[i])
2592 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2596 case MagentaQuantum:
2598 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2604 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2609 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2612 case OpacityQuantum:
2614 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2619 if (image->colorspace == CMYKColorspace)
2620 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2625 *q=ScaleQuantumToShort(ClampToQuantum(
2626 GetPixelIntensity(image,p)));
2640 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2641 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2642 "UnrecognizedPixelMap","`%s'",stream_info->map);
2646 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2655 + 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 %
2659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2661 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2662 % the latest stream of pixels.
2664 % The format of the SyncAuthenticPixelsStream method is:
2666 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2667 % ExceptionInfo *exception)
2669 % A description of each parameter follows:
2671 % o image: the image.
2673 % o exception: return any errors or warnings in this structure.
2676 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2677 ExceptionInfo *exception)
2688 assert(image != (Image *) NULL);
2689 assert(image->signature == MagickSignature);
2690 if (image->debug != MagickFalse)
2691 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2692 cache_info=(CacheInfo *) image->cache;
2693 assert(cache_info->signature == MagickSignature);
2694 stream_handler=GetBlobStreamHandler(image);
2695 if (stream_handler == (StreamHandler) NULL)
2697 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2698 "NoStreamHandlerIsDefined","`%s'",image->filename);
2699 return(MagickFalse);
2701 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2702 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2710 % W r i t e S t r e a m %
2714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2716 % WriteStream() makes the image pixels available to a user supplied callback
2717 % method immediately upon writing pixel data with the WriteImage() method.
2719 % The format of the WriteStream() method is:
2721 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2722 % StreamHandler stream,ExceptionInfo *exception)
2724 % A description of each parameter follows:
2726 % o image_info: the image info.
2728 % o stream: A callback method.
2730 % o exception: return any errors or warnings in this structure.
2733 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2734 Image *image,StreamHandler stream,ExceptionInfo *exception)
2742 assert(image_info != (ImageInfo *) NULL);
2743 assert(image_info->signature == MagickSignature);
2744 if (image_info->debug != MagickFalse)
2745 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2746 image_info->filename);
2747 assert(image != (Image *) NULL);
2748 assert(image->signature == MagickSignature);
2749 write_info=CloneImageInfo(image_info);
2750 *write_info->magick='\0';
2751 write_info->stream=stream;
2752 status=WriteImage(write_info,image,exception);
2753 write_info=DestroyImageInfo(write_info);