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-2011 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/pixel.h"
56 #include "MagickCore/pixel-accessor.h"
57 #include "MagickCore/quantum.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/semaphore.h"
60 #include "MagickCore/stream.h"
61 #include "MagickCore/stream-private.h"
62 #include "MagickCore/string_.h"
65 Typedef declaractions.
107 Declare pixel cache interfaces.
109 #if defined(__cplusplus) || defined(c_plusplus)
114 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
115 const ssize_t,const size_t,const size_t,ExceptionInfo *);
117 static MagickBooleanType
118 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
119 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
122 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
123 const size_t,ExceptionInfo *);
125 #if defined(__cplusplus) || defined(c_plusplus)
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 + A c q u i r e S t r e a m I n f o %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % AcquireStreamInfo() allocates the StreamInfo structure.
142 % The format of the AcquireStreamInfo method is:
144 % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
145 % ExceptionInfo *exception)
147 % A description of each parameter follows:
149 % o image_info: the image info.
151 % o exception: return any errors or warnings in this structure.
154 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
155 ExceptionInfo *exception)
160 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
161 if (stream_info == (StreamInfo *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
164 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
165 sizeof(*stream_info->pixels));
166 if (stream_info->pixels == (unsigned char *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 stream_info->map=ConstantString("RGB");
169 stream_info->storage_type=CharPixel;
170 stream_info->stream=AcquireImage(image_info,exception);
171 stream_info->signature=MagickSignature;
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 + D e s t r o y P i x e l S t r e a m %
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 % DestroyPixelStream() deallocates memory associated with the pixel stream.
188 % The format of the DestroyPixelStream() method is:
190 % void DestroyPixelStream(Image *image)
192 % A description of each parameter follows:
194 % o image: the image.
198 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
200 assert(cache_info != (CacheInfo *) NULL);
201 if (cache_info->mapped == MagickFalse)
202 (void) RelinquishMagickMemory(cache_info->pixels);
204 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
205 cache_info->pixels=(Quantum *) NULL;
206 cache_info->metacontent=(void *) NULL;
207 cache_info->length=0;
208 cache_info->mapped=MagickFalse;
211 static void DestroyPixelStream(Image *image)
219 assert(image != (Image *) NULL);
220 assert(image->signature == MagickSignature);
221 if (image->debug != MagickFalse)
222 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
223 cache_info=(CacheInfo *) image->cache;
224 assert(cache_info->signature == MagickSignature);
226 LockSemaphoreInfo(cache_info->semaphore);
227 cache_info->reference_count--;
228 if (cache_info->reference_count == 0)
230 UnlockSemaphoreInfo(cache_info->semaphore);
231 if (destroy == MagickFalse)
233 RelinquishStreamPixels(cache_info);
234 if (cache_info->nexus_info != (NexusInfo **) NULL)
235 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
236 cache_info->number_threads);
237 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
238 DestroySemaphoreInfo(&cache_info->disk_semaphore);
239 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
240 DestroySemaphoreInfo(&cache_info->semaphore);
241 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 + D e s t r o y S t r e a m I n f o %
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 % DestroyStreamInfo() destroys memory associated with the StreamInfo
258 % The format of the DestroyStreamInfo method is:
260 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
262 % A description of each parameter follows:
264 % o stream_info: the stream info.
267 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
270 assert(stream_info != (StreamInfo *) NULL);
271 assert(stream_info->signature == MagickSignature);
272 if (stream_info->map != (char *) NULL)
273 stream_info->map=DestroyString(stream_info->map);
274 if (stream_info->pixels != (unsigned char *) NULL)
275 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
276 stream_info->pixels);
277 if (stream_info->stream != (Image *) NULL)
279 (void) CloseBlob(stream_info->stream);
280 stream_info->stream=DestroyImage(stream_info->stream);
282 if (stream_info->quantum_info != (QuantumInfo *) NULL)
283 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
284 stream_info->signature=(~MagickSignature);
285 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 + 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 %
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % GetAuthenticMetacontentFromStream() returns the metacontent corresponding
301 % with the last call to QueueAuthenticPixelsStream() or
302 % GetAuthenticPixelsStream().
304 % The format of the GetAuthenticMetacontentFromStream() method is:
306 % void *GetAuthenticMetacontentFromStream(const Image *image)
308 % A description of each parameter follows:
310 % o image: the image.
313 static void *GetAuthenticMetacontentFromStream(const Image *image)
318 assert(image != (Image *) NULL);
319 assert(image->signature == MagickSignature);
320 if (image->debug != MagickFalse)
321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
322 cache_info=(CacheInfo *) image->cache;
323 assert(cache_info->signature == MagickSignature);
324 return(cache_info->metacontent);
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 + G e t A u t h e n t i c P i x e l S t r e a m %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
339 % cache as defined by the geometry parameters. A pointer to the pixels is
340 % returned if the pixels are transferred, otherwise a NULL is returned. For
341 % streams this method is a no-op.
343 % The format of the GetAuthenticPixelsStream() method is:
345 % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
346 % const ssize_t y,const size_t columns,const size_t rows,
347 % ExceptionInfo *exception)
349 % A description of each parameter follows:
351 % o image: the image.
353 % o x,y,columns,rows: These values define the perimeter of a region of
356 % o exception: return any errors or warnings in this structure.
359 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
360 const ssize_t y,const size_t columns,const size_t rows,
361 ExceptionInfo *exception)
366 assert(image != (Image *) NULL);
367 assert(image->signature == MagickSignature);
368 if (image->debug != MagickFalse)
369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
370 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 + 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 %
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
386 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
388 % The format of the GetAuthenticPixelsFromStream() method is:
390 % Quantum *GetAuthenticPixelsFromStream(const Image image)
392 % A description of each parameter follows:
394 % o image: the image.
397 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
402 assert(image != (Image *) NULL);
403 assert(image->signature == MagickSignature);
404 if (image->debug != MagickFalse)
405 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
406 cache_info=(CacheInfo *) image->cache;
407 assert(cache_info->signature == MagickSignature);
408 return(cache_info->pixels);
412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 + 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 %
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
423 % (x,y) location. The image background color is returned if an error occurs.
425 % The format of the GetOneAuthenticPixelFromStream() method is:
427 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
428 % const ssize_t x,const ssize_t y,Quantum *pixel,
429 % ExceptionInfo *exception)
431 % A description of each parameter follows:
433 % o image: the image.
435 % o pixel: return a pixel at the specified (x,y) location.
437 % o x,y: These values define the location of the pixel to return.
439 % o exception: return any errors or warnings in this structure.
442 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
443 const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
451 assert(image != (Image *) NULL);
452 assert(image->signature == MagickSignature);
453 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
454 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
455 if (q != (Quantum *) NULL)
457 pixel[RedPixelChannel]=image->background_color.red;
458 pixel[GreenPixelChannel]=image->background_color.green;
459 pixel[BluePixelChannel]=image->background_color.blue;
460 pixel[AlphaPixelChannel]=image->background_color.alpha;
463 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
468 channel=GetPixelChannelMapChannel(image,i);
475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 + 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 %
483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
486 % (x.y) location. The image background color is returned if an error occurs.
488 % The format of the GetOneVirtualPixelFromStream() method is:
490 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
491 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
492 % const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
494 % A description of each parameter follows:
496 % o image: the image.
498 % o virtual_pixel_method: the virtual pixel method.
500 % o x,y: These values define the location of the pixel to return.
502 % o pixel: return a pixel at the specified (x,y) location.
504 % o exception: return any errors or warnings in this structure.
507 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
508 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
509 Quantum *pixel,ExceptionInfo *exception)
517 assert(image != (Image *) NULL);
518 assert(image->signature == MagickSignature);
519 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
520 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
521 if (p == (const Quantum *) NULL)
523 pixel[RedPixelChannel]=image->background_color.red;
524 pixel[GreenPixelChannel]=image->background_color.green;
525 pixel[BluePixelChannel]=image->background_color.blue;
526 pixel[AlphaPixelChannel]=image->background_color.alpha;
529 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
534 channel=GetPixelChannelMapChannel(image,i);
541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
545 + G e t S t r e a m I n f o C l i e n t D a t a %
549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551 % GetStreamInfoClientData() gets the stream info client data.
553 % The format of the GetStreamInfoClientData method is:
555 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
557 % A description of each parameter follows:
559 % o stream_info: the stream info.
562 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
564 assert(stream_info != (StreamInfo *) NULL);
565 assert(stream_info->signature == MagickSignature);
566 return(stream_info->client_data);
570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574 + 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 %
578 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580 % GetVirtualPixelsStream() returns the pixels associated with the last
581 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
583 % The format of the GetVirtualPixelsStream() method is:
585 % const Quantum *GetVirtualPixelsStream(const Image *image)
587 % A description of each parameter follows:
589 % o pixels: return the pixels associated corresponding with the last call to
590 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
592 % o image: the image.
595 static const Quantum *GetVirtualPixelsStream(const Image *image)
600 assert(image != (Image *) NULL);
601 assert(image->signature == MagickSignature);
602 if (image->debug != MagickFalse)
603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
604 cache_info=(CacheInfo *) image->cache;
605 assert(cache_info->signature == MagickSignature);
606 return(cache_info->pixels);
610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614 + 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 %
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620 % GetVirtualMetacontentFromStream() returns the associated pixel
621 % channels corresponding with the last call to QueueAuthenticPixelsStream() or
622 % GetVirtualPixelStream().
624 % The format of the GetVirtualMetacontentFromStream() method is:
626 % const void *GetVirtualMetacontentFromStream(const Image *image)
628 % A description of each parameter follows:
630 % o image: the image.
633 static const void *GetVirtualMetacontentFromStream(
639 assert(image != (Image *) NULL);
640 assert(image->signature == MagickSignature);
641 if (image->debug != MagickFalse)
642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
643 cache_info=(CacheInfo *) image->cache;
644 assert(cache_info->signature == MagickSignature);
645 return(cache_info->metacontent);
649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 + G e t V i r t u a l P i x e l S t r e a m %
657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
660 % defined by the geometry parameters. A pointer to the pixels is returned if
661 % the pixels are transferred, otherwise a NULL is returned. For streams this
664 % The format of the GetVirtualPixelStream() method is:
666 % const Quantum *GetVirtualPixelStream(const Image *image,
667 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
668 % const ssize_t y,const size_t columns,const size_t rows,
669 % ExceptionInfo *exception)
671 % A description of each parameter follows:
673 % o image: the image.
675 % o virtual_pixel_method: the virtual pixel method.
677 % o x,y,columns,rows: These values define the perimeter of a region of
680 % o exception: return any errors or warnings in this structure.
684 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
685 ExceptionInfo *exception)
687 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
689 cache_info->mapped=MagickFalse;
690 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
692 if (cache_info->pixels == (Quantum *) NULL)
694 cache_info->mapped=MagickTrue;
695 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
698 if (cache_info->pixels == (Quantum *) NULL)
700 (void) ThrowMagickException(exception,GetMagickModule(),
701 ResourceLimitError,"MemoryAllocationFailed","`%s'",
702 cache_info->filename);
708 static const Quantum *GetVirtualPixelStream(const Image *image,
709 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
710 const ssize_t y,const size_t columns,const size_t rows,
711 ExceptionInfo *exception)
726 Validate pixel cache geometry.
728 assert(image != (const Image *) NULL);
729 assert(image->signature == MagickSignature);
730 if (image->debug != MagickFalse)
731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
732 if ((x < 0) || (y < 0) ||
733 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
734 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
735 (columns == 0) || (rows == 0))
737 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
738 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
739 return((Quantum *) NULL);
741 cache_info=(CacheInfo *) image->cache;
742 assert(cache_info->signature == MagickSignature);
744 Pixels are stored in a temporary buffer until they are synced to the cache.
746 number_pixels=(MagickSizeType) columns*rows;
747 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
748 if (cache_info->metacontent_extent != 0)
749 length+=number_pixels*cache_info->metacontent_extent;
750 if (cache_info->pixels == (Quantum *) NULL)
752 cache_info->length=length;
753 status=AcquireStreamPixels(cache_info,exception);
754 if (status == MagickFalse)
756 cache_info->length=0;
757 return((Quantum *) NULL);
761 if (cache_info->length != length)
763 RelinquishStreamPixels(cache_info);
764 cache_info->length=length;
765 status=AcquireStreamPixels(cache_info,exception);
766 if (status == MagickFalse)
768 cache_info->length=0;
769 return((Quantum *) NULL);
772 cache_info->metacontent=(void *) NULL;
773 if (cache_info->metacontent_extent != 0)
774 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
775 cache_info->number_channels);
776 return(cache_info->pixels);
780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 + O p e n S t r e a m %
788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 % OpenStream() opens a stream for writing by the StreamImage() method.
792 % The format of the OpenStream method is:
794 % MagickBooleanType OpenStream(const ImageInfo *image_info,
795 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
797 % A description of each parameter follows:
799 % o image_info: the image info.
801 % o stream_info: the stream info.
803 % o filename: the stream filename.
805 % o exception: return any errors or warnings in this structure.
808 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
809 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
814 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
815 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824 + 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 %
828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
831 % defined by the region rectangle and returns a pointer to the area. This
832 % area is subsequently transferred from the pixel cache with method
833 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
834 % pixels are transferred, otherwise a NULL is returned.
836 % The format of the QueueAuthenticPixelsStream() method is:
838 % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
839 % const ssize_t y,const size_t columns,const size_t rows,
840 % ExceptionInfo *exception)
842 % A description of each parameter follows:
844 % o image: the image.
846 % o x,y,columns,rows: These values define the perimeter of a region of
850 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
851 const ssize_t y,const size_t columns,const size_t rows,
852 ExceptionInfo *exception)
867 Validate pixel cache geometry.
869 assert(image != (Image *) NULL);
870 if ((x < 0) || (y < 0) ||
871 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
872 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
873 (columns == 0) || (rows == 0))
875 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
876 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
877 return((Quantum *) NULL);
879 stream_handler=GetBlobStreamHandler(image);
880 if (stream_handler == (StreamHandler) NULL)
882 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
883 "NoStreamHandlerIsDefined","`%s'",image->filename);
884 return((Quantum *) NULL);
886 cache_info=(CacheInfo *) image->cache;
887 assert(cache_info->signature == MagickSignature);
888 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
889 (image->colorspace != GetPixelCacheColorspace(image->cache)))
891 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
892 (void) stream_handler(image,(const void *) NULL,(size_t)
893 cache_info->columns);
894 cache_info->storage_class=image->storage_class;
895 cache_info->colorspace=image->colorspace;
896 cache_info->columns=image->columns;
897 cache_info->rows=image->rows;
898 image->cache=cache_info;
901 Pixels are stored in a temporary buffer until they are synced to the cache.
903 cache_info->columns=columns;
904 cache_info->rows=rows;
905 number_pixels=(MagickSizeType) columns*rows;
906 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
907 if (cache_info->metacontent_extent != 0)
908 length+=number_pixels*cache_info->metacontent_extent;
909 if (cache_info->pixels == (Quantum *) NULL)
911 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
912 cache_info->length=(MagickSizeType) length;
915 if (cache_info->length < (MagickSizeType) length)
917 cache_info->pixels=(Quantum *) ResizeMagickMemory(
918 cache_info->pixels,length);
919 cache_info->length=(MagickSizeType) length;
921 if (cache_info->pixels == (void *) NULL)
922 return((Quantum *) NULL);
923 cache_info->metacontent=(void *) NULL;
924 if (cache_info->metacontent_extent != 0)
925 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
926 cache_info->number_channels);
927 return(cache_info->pixels);
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 % R e a d S t r e a m %
939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
941 % ReadStream() makes the image pixels available to a user supplied callback
942 % method immediately upon reading a scanline with the ReadImage() method.
944 % The format of the ReadStream() method is:
946 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
947 % ExceptionInfo *exception)
949 % A description of each parameter follows:
951 % o image_info: the image info.
953 % o stream: a callback method.
955 % o exception: return any errors or warnings in this structure.
958 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
959 ExceptionInfo *exception)
973 assert(image_info != (ImageInfo *) NULL);
974 assert(image_info->signature == MagickSignature);
975 if (image_info->debug != MagickFalse)
976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
977 image_info->filename);
978 assert(exception != (ExceptionInfo *) NULL);
979 assert(exception->signature == MagickSignature);
980 read_info=CloneImageInfo(image_info);
981 read_info->cache=AcquirePixelCache(0);
982 GetPixelCacheMethods(&cache_methods);
983 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
984 cache_methods.get_virtual_metacontent_from_handler=
985 GetVirtualMetacontentFromStream;
986 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
987 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
988 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
989 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
990 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
991 cache_methods.get_authentic_metacontent_from_handler=
992 GetAuthenticMetacontentFromStream;
993 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
994 cache_methods.get_one_authentic_pixel_from_handler=
995 GetOneAuthenticPixelFromStream;
996 cache_methods.destroy_pixel_handler=DestroyPixelStream;
997 SetPixelCacheMethods(read_info->cache,&cache_methods);
998 read_info->stream=stream;
999 image=ReadImage(read_info,exception);
1000 read_info=DestroyImageInfo(read_info);
1005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 + S e t S t r e a m I n f o C l i e n t D a t a %
1013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 % SetStreamInfoClientData() sets the stream info client data.
1017 % The format of the SetStreamInfoClientData method is:
1019 % void SetStreamInfoClientData(StreamInfo *stream_info,
1020 % const void *client_data)
1022 % A description of each parameter follows:
1024 % o stream_info: the stream info.
1026 % o client_data: the client data.
1029 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1030 const void *client_data)
1032 assert(stream_info != (StreamInfo *) NULL);
1033 assert(stream_info->signature == MagickSignature);
1034 stream_info->client_data=client_data;
1038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 + S e t S t r e a m I n f o M a p %
1046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 % SetStreamInfoMap() sets the stream info map member.
1050 % The format of the SetStreamInfoMap method is:
1052 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1054 % A description of each parameter follows:
1056 % o stream_info: the stream info.
1061 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1063 assert(stream_info != (StreamInfo *) NULL);
1064 assert(stream_info->signature == MagickSignature);
1065 (void) CloneString(&stream_info->map,map);
1069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1073 + S e t S t r e a m I n f o S t o r a g e T y p e %
1077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1079 % SetStreamInfoStorageType() sets the stream info storage type member.
1081 % The format of the SetStreamInfoStorageType method is:
1083 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1084 % const StoreageType *storage_type)
1086 % A description of each parameter follows:
1088 % o stream_info: the stream info.
1090 % o storage_type: the storage type.
1093 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1094 const StorageType storage_type)
1096 assert(stream_info != (StreamInfo *) NULL);
1097 assert(stream_info->signature == MagickSignature);
1098 stream_info->storage_type=storage_type;
1102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1106 + S t r e a m I m a g e %
1110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1112 % StreamImage() streams pixels from an image and writes them in a user
1113 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1115 % The format of the StreamImage() method is:
1117 % Image *StreamImage(const ImageInfo *image_info,
1118 % StreamInfo *stream_info,ExceptionInfo *exception)
1120 % A description of each parameter follows:
1122 % o image_info: the image info.
1124 % o stream_info: the stream info.
1126 % o exception: return any errors or warnings in this structure.
1130 #if defined(__cplusplus) || defined(c_plusplus)
1134 static size_t WriteStreamImage(const Image *image,const void *pixels,
1135 const size_t columns)
1154 stream_info=(StreamInfo *) image->client_data;
1155 switch (stream_info->storage_type)
1157 default: packet_size=sizeof(char); break;
1158 case CharPixel: packet_size=sizeof(char); break;
1159 case DoublePixel: packet_size=sizeof(double); break;
1160 case FloatPixel: packet_size=sizeof(float); break;
1161 case IntegerPixel: packet_size=sizeof(int); break;
1162 case LongPixel: packet_size=sizeof(ssize_t); break;
1163 case QuantumPixel: packet_size=sizeof(Quantum); break;
1164 case ShortPixel: packet_size=sizeof(unsigned short); break;
1166 cache_info=(CacheInfo *) image->cache;
1167 assert(cache_info->signature == MagickSignature);
1168 packet_size*=strlen(stream_info->map);
1169 length=packet_size*cache_info->columns*cache_info->rows;
1170 if (image != stream_info->image)
1176 Prepare stream for writing.
1178 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1179 stream_info->pixels,length,sizeof(*stream_info->pixels));
1180 if (stream_info->pixels == (unsigned char *) NULL)
1182 stream_info->image=image;
1183 write_info=CloneImageInfo(stream_info->image_info);
1184 (void) SetImageInfo(write_info,1,stream_info->exception);
1185 if (write_info->extract != (char *) NULL)
1186 (void) ParseAbsoluteGeometry(write_info->extract,
1187 &stream_info->extract_info);
1189 write_info=DestroyImageInfo(write_info);
1191 extract_info=stream_info->extract_info;
1192 if ((extract_info.width == 0) || (extract_info.height == 0))
1195 Write all pixels to stream.
1197 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1198 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1200 return(count == 0 ? 0 : columns);
1202 if ((stream_info->y < extract_info.y) ||
1203 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1209 Write a portion of the pixel row to the stream.
1211 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1212 length=packet_size*extract_info.width;
1213 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1216 return(count == 0 ? 0 : columns);
1219 #if defined(__cplusplus) || defined(c_plusplus)
1223 MagickExport Image *StreamImage(const ImageInfo *image_info,
1224 StreamInfo *stream_info,ExceptionInfo *exception)
1232 assert(image_info != (const ImageInfo *) NULL);
1233 assert(image_info->signature == MagickSignature);
1234 if (image_info->debug != MagickFalse)
1235 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1236 image_info->filename);
1237 assert(stream_info != (StreamInfo *) NULL);
1238 assert(stream_info->signature == MagickSignature);
1239 assert(exception != (ExceptionInfo *) NULL);
1240 read_info=CloneImageInfo(image_info);
1241 stream_info->image_info=image_info;
1242 stream_info->exception=exception;
1243 read_info->client_data=(void *) stream_info;
1244 image=ReadStream(read_info,&WriteStreamImage,exception);
1245 read_info=DestroyImageInfo(read_info);
1246 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1247 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1248 image=DestroyImage(image);
1253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1257 + S t r e a m I m a g e P i x e l s %
1261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1263 % StreamImagePixels() extracts pixel data from an image and returns it in the
1264 % stream_info->pixels structure in the format as defined by
1265 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1267 % The format of the StreamImagePixels method is:
1269 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1270 % const Image *image,ExceptionInfo *exception)
1272 % A description of each parameter follows:
1274 % o stream_info: the stream info.
1276 % o image: the image.
1278 % o exception: return any errors or warnings in this structure.
1281 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1282 const Image *image,ExceptionInfo *exception)
1290 register const Quantum
1300 assert(stream_info != (StreamInfo *) NULL);
1301 assert(stream_info->signature == MagickSignature);
1302 assert(image != (Image *) NULL);
1303 assert(image->signature == MagickSignature);
1304 if (image->debug != MagickFalse)
1305 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1306 length=strlen(stream_info->map);
1307 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1308 if (quantum_map == (QuantumType *) NULL)
1310 (void) ThrowMagickException(exception,GetMagickModule(),
1311 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1312 return(MagickFalse);
1314 for (i=0; i < (ssize_t) length; i++)
1316 switch (stream_info->map[i])
1321 quantum_map[i]=AlphaQuantum;
1327 quantum_map[i]=BlueQuantum;
1333 quantum_map[i]=CyanQuantum;
1334 if (image->colorspace == CMYKColorspace)
1336 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1337 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1338 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1339 return(MagickFalse);
1344 quantum_map[i]=GreenQuantum;
1350 quantum_map[i]=IndexQuantum;
1356 quantum_map[i]=BlackQuantum;
1357 if (image->colorspace == CMYKColorspace)
1359 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1360 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1361 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1362 return(MagickFalse);
1367 quantum_map[i]=MagentaQuantum;
1368 if (image->colorspace == CMYKColorspace)
1370 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1371 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1372 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1373 return(MagickFalse);
1378 quantum_map[i]=OpacityQuantum;
1384 quantum_map[i]=UndefinedQuantum;
1390 quantum_map[i]=RedQuantum;
1396 quantum_map[i]=YellowQuantum;
1397 if (image->colorspace == CMYKColorspace)
1399 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1400 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1401 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1402 return(MagickFalse);
1406 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1407 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1408 "UnrecognizedPixelMap","`%s'",stream_info->map);
1409 return(MagickFalse);
1413 quantum_info=stream_info->quantum_info;
1414 switch (stream_info->storage_type)
1418 register unsigned char
1421 q=(unsigned char *) stream_info->pixels;
1422 if (LocaleCompare(stream_info->map,"BGR") == 0)
1424 p=GetAuthenticPixelQueue(image);
1425 if (p == (const Quantum *) NULL)
1427 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1429 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1430 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1431 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1436 if (LocaleCompare(stream_info->map,"BGRA") == 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));
1446 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1451 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1453 p=GetAuthenticPixelQueue(image);
1454 if (p == (const Quantum *) NULL)
1456 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1458 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1459 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1460 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1461 *q++=ScaleQuantumToChar((Quantum) 0);
1466 if (LocaleCompare(stream_info->map,"I") == 0)
1468 p=GetAuthenticPixelQueue(image);
1469 if (p == (const Quantum *) NULL)
1471 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1473 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
1478 if (LocaleCompare(stream_info->map,"RGB") == 0)
1480 p=GetAuthenticPixelQueue(image);
1481 if (p == (const Quantum *) NULL)
1483 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1485 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1486 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1487 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1492 if (LocaleCompare(stream_info->map,"RGBA") == 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));
1502 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1507 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1509 p=GetAuthenticPixelQueue(image);
1510 if (p == (const Quantum *) NULL)
1512 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1514 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1515 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1516 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1517 *q++=ScaleQuantumToChar((Quantum) 0);
1522 p=GetAuthenticPixelQueue(image);
1523 if (p == (const Quantum *) NULL)
1525 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1527 for (i=0; i < (ssize_t) length; i++)
1530 switch (quantum_map[i])
1535 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1539 case MagentaQuantum:
1541 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1547 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1552 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1555 case OpacityQuantum:
1557 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1562 if (image->colorspace == CMYKColorspace)
1563 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1568 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
1585 q=(double *) stream_info->pixels;
1586 if (LocaleCompare(stream_info->map,"BGR") == 0)
1588 p=GetAuthenticPixelQueue(image);
1589 if (p == (const Quantum *) NULL)
1591 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1593 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1594 quantum_info->scale+quantum_info->minimum);
1595 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1596 quantum_info->scale+quantum_info->minimum);
1597 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1598 quantum_info->scale+quantum_info->minimum);
1603 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1605 p=GetAuthenticPixelQueue(image);
1606 if (p == (const Quantum *) NULL)
1608 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1610 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1611 quantum_info->scale+quantum_info->minimum);
1612 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1613 quantum_info->scale+quantum_info->minimum);
1614 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1615 quantum_info->scale+quantum_info->minimum);
1616 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1617 quantum_info->scale+quantum_info->minimum);
1622 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1624 p=GetAuthenticPixelQueue(image);
1625 if (p == (const Quantum *) NULL)
1627 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1629 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1630 quantum_info->scale+quantum_info->minimum);
1631 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1632 quantum_info->scale+quantum_info->minimum);
1633 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1634 quantum_info->scale+quantum_info->minimum);
1640 if (LocaleCompare(stream_info->map,"I") == 0)
1642 p=GetAuthenticPixelQueue(image);
1643 if (p == (const Quantum *) NULL)
1645 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1647 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1648 quantum_info->scale+quantum_info->minimum);
1653 if (LocaleCompare(stream_info->map,"RGB") == 0)
1655 p=GetAuthenticPixelQueue(image);
1656 if (p == (const Quantum *) NULL)
1658 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1660 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1661 quantum_info->scale+quantum_info->minimum);
1662 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1663 quantum_info->scale+quantum_info->minimum);
1664 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1665 quantum_info->scale+quantum_info->minimum);
1670 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1672 p=GetAuthenticPixelQueue(image);
1673 if (p == (const Quantum *) NULL)
1675 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1677 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1678 quantum_info->scale+quantum_info->minimum);
1679 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1680 quantum_info->scale+quantum_info->minimum);
1681 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1682 quantum_info->scale+quantum_info->minimum);
1683 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1684 quantum_info->scale+quantum_info->minimum);
1689 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1691 p=GetAuthenticPixelQueue(image);
1692 if (p == (const Quantum *) NULL)
1694 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1696 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1697 quantum_info->scale+quantum_info->minimum);
1698 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1699 quantum_info->scale+quantum_info->minimum);
1700 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1701 quantum_info->scale+quantum_info->minimum);
1707 p=GetAuthenticPixelQueue(image);
1708 if (p == (const Quantum *) NULL)
1710 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1712 for (i=0; i < (ssize_t) length; i++)
1715 switch (quantum_map[i])
1720 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1721 quantum_info->scale+quantum_info->minimum);
1725 case MagentaQuantum:
1727 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1728 quantum_info->scale+quantum_info->minimum);
1734 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1735 quantum_info->scale+quantum_info->minimum);
1740 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1741 quantum_info->scale+quantum_info->minimum);
1744 case OpacityQuantum:
1746 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1747 quantum_info->scale+quantum_info->minimum);
1752 if (image->colorspace == CMYKColorspace)
1753 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1754 quantum_info->scale+quantum_info->minimum);
1759 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1760 quantum_info->scale+quantum_info->minimum);
1777 q=(float *) stream_info->pixels;
1778 if (LocaleCompare(stream_info->map,"BGR") == 0)
1780 p=GetAuthenticPixelQueue(image);
1781 if (p == (const Quantum *) NULL)
1783 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1785 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1786 quantum_info->scale+quantum_info->minimum);
1787 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1788 quantum_info->scale+quantum_info->minimum);
1789 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1790 quantum_info->scale+quantum_info->minimum);
1795 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1797 p=GetAuthenticPixelQueue(image);
1798 if (p == (const Quantum *) NULL)
1800 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1802 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1803 quantum_info->scale+quantum_info->minimum);
1804 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1805 quantum_info->scale+quantum_info->minimum);
1806 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1807 quantum_info->scale+quantum_info->minimum);
1808 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1809 quantum_info->scale+quantum_info->minimum);
1814 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1816 p=GetAuthenticPixelQueue(image);
1817 if (p == (const Quantum *) NULL)
1819 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1821 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1822 quantum_info->scale+quantum_info->minimum);
1823 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1824 quantum_info->scale+quantum_info->minimum);
1825 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1826 quantum_info->scale+quantum_info->minimum);
1832 if (LocaleCompare(stream_info->map,"I") == 0)
1834 p=GetAuthenticPixelQueue(image);
1835 if (p == (const Quantum *) NULL)
1837 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1839 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1840 quantum_info->scale+quantum_info->minimum);
1845 if (LocaleCompare(stream_info->map,"RGB") == 0)
1847 p=GetAuthenticPixelQueue(image);
1848 if (p == (const Quantum *) NULL)
1850 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1852 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1853 quantum_info->scale+quantum_info->minimum);
1854 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1855 quantum_info->scale+quantum_info->minimum);
1856 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1857 quantum_info->scale+quantum_info->minimum);
1862 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1864 p=GetAuthenticPixelQueue(image);
1865 if (p == (const Quantum *) NULL)
1867 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1869 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1870 quantum_info->scale+quantum_info->minimum);
1871 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1872 quantum_info->scale+quantum_info->minimum);
1873 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1874 quantum_info->scale+quantum_info->minimum);
1875 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1876 quantum_info->scale+quantum_info->minimum);
1881 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1883 p=GetAuthenticPixelQueue(image);
1884 if (p == (const Quantum *) NULL)
1886 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1888 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1889 quantum_info->scale+quantum_info->minimum);
1890 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1891 quantum_info->scale+quantum_info->minimum);
1892 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1893 quantum_info->scale+quantum_info->minimum);
1899 p=GetAuthenticPixelQueue(image);
1900 if (p == (const Quantum *) NULL)
1902 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1904 for (i=0; i < (ssize_t) length; i++)
1907 switch (quantum_map[i])
1912 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1913 quantum_info->scale+quantum_info->minimum);
1917 case MagentaQuantum:
1919 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1920 quantum_info->scale+quantum_info->minimum);
1926 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1927 quantum_info->scale+quantum_info->minimum);
1932 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1933 quantum_info->scale+quantum_info->minimum);
1936 case OpacityQuantum:
1938 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1939 quantum_info->scale+quantum_info->minimum);
1944 if (image->colorspace == CMYKColorspace)
1945 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1946 quantum_info->scale+quantum_info->minimum);
1951 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1952 quantum_info->scale+quantum_info->minimum);
1966 register unsigned int
1969 q=(unsigned int *) stream_info->pixels;
1970 if (LocaleCompare(stream_info->map,"BGR") == 0)
1972 p=GetAuthenticPixelQueue(image);
1973 if (p == (const Quantum *) NULL)
1975 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1977 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1978 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1979 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1984 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1986 p=GetAuthenticPixelQueue(image);
1987 if (p == (const Quantum *) NULL)
1989 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1991 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1992 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1993 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1994 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1999 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2001 p=GetAuthenticPixelQueue(image);
2002 if (p == (const Quantum *) NULL)
2004 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2006 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2007 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2008 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2014 if (LocaleCompare(stream_info->map,"I") == 0)
2016 p=GetAuthenticPixelQueue(image);
2017 if (p == (const Quantum *) NULL)
2019 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2021 *q++=(unsigned int) ScaleQuantumToLong(
2022 GetPixelIntensity(image,p));
2027 if (LocaleCompare(stream_info->map,"RGB") == 0)
2029 p=GetAuthenticPixelQueue(image);
2030 if (p == (const Quantum *) NULL)
2032 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2034 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2035 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2036 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2041 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2043 p=GetAuthenticPixelQueue(image);
2044 if (p == (const Quantum *) NULL)
2046 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2048 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2049 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2050 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2051 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2052 (GetPixelAlpha(image,p)));
2057 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2059 p=GetAuthenticPixelQueue(image);
2060 if (p == (const Quantum *) NULL)
2062 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2064 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2065 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2066 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2072 p=GetAuthenticPixelQueue(image);
2073 if (p == (const Quantum *) NULL)
2075 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2077 for (i=0; i < (ssize_t) length; i++)
2080 switch (quantum_map[i])
2085 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2089 case MagentaQuantum:
2091 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2097 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2102 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
2105 case OpacityQuantum:
2107 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
2112 if (image->colorspace == CMYKColorspace)
2113 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
2119 ScaleQuantumToLong(GetPixelIntensity(image,p));
2136 q=(size_t *) stream_info->pixels;
2137 if (LocaleCompare(stream_info->map,"BGR") == 0)
2139 p=GetAuthenticPixelQueue(image);
2140 if (p == (const Quantum *) NULL)
2142 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2144 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2145 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2146 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2151 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2153 p=GetAuthenticPixelQueue(image);
2154 if (p == (const Quantum *) NULL)
2156 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2158 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2159 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2160 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2161 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2166 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2168 p=GetAuthenticPixelQueue(image);
2169 if (p == (const Quantum *) NULL)
2171 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2173 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2174 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2175 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2181 if (LocaleCompare(stream_info->map,"I") == 0)
2183 p=GetAuthenticPixelQueue(image);
2184 if (p == (const Quantum *) NULL)
2186 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2188 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
2193 if (LocaleCompare(stream_info->map,"RGB") == 0)
2195 p=GetAuthenticPixelQueue(image);
2196 if (p == (const Quantum *) NULL)
2198 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2200 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2201 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2202 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2207 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2209 p=GetAuthenticPixelQueue(image);
2210 if (p == (const Quantum *) NULL)
2212 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2214 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2215 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2216 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2217 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2222 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2224 p=GetAuthenticPixelQueue(image);
2225 if (p == (const Quantum *) NULL)
2227 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2229 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2230 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2231 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2237 p=GetAuthenticPixelQueue(image);
2238 if (p == (const Quantum *) NULL)
2240 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2242 for (i=0; i < (ssize_t) length; i++)
2245 switch (quantum_map[i])
2250 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2254 case MagentaQuantum:
2256 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2262 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2267 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2270 case OpacityQuantum:
2272 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2277 if (image->colorspace == CMYKColorspace)
2278 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2283 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
2300 q=(Quantum *) stream_info->pixels;
2301 if (LocaleCompare(stream_info->map,"BGR") == 0)
2303 p=GetAuthenticPixelQueue(image);
2304 if (p == (const Quantum *) NULL)
2306 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2308 *q++=GetPixelBlue(image,p);
2309 *q++=GetPixelGreen(image,p);
2310 *q++=GetPixelRed(image,p);
2315 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2317 p=GetAuthenticPixelQueue(image);
2318 if (p == (const Quantum *) NULL)
2320 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2322 *q++=GetPixelBlue(image,p);
2323 *q++=GetPixelGreen(image,p);
2324 *q++=GetPixelRed(image,p);
2325 *q++=(Quantum) (GetPixelAlpha(image,p));
2330 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2332 p=GetAuthenticPixelQueue(image);
2333 if (p == (const Quantum *) NULL)
2335 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2337 *q++=GetPixelBlue(image,p);
2338 *q++=GetPixelGreen(image,p);
2339 *q++=GetPixelRed(image,p);
2345 if (LocaleCompare(stream_info->map,"I") == 0)
2347 p=GetAuthenticPixelQueue(image);
2348 if (p == (const Quantum *) NULL)
2350 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2352 *q++=GetPixelIntensity(image,p);
2357 if (LocaleCompare(stream_info->map,"RGB") == 0)
2359 p=GetAuthenticPixelQueue(image);
2360 if (p == (const Quantum *) NULL)
2362 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2364 *q++=GetPixelRed(image,p);
2365 *q++=GetPixelGreen(image,p);
2366 *q++=GetPixelBlue(image,p);
2371 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2373 p=GetAuthenticPixelQueue(image);
2374 if (p == (const Quantum *) NULL)
2376 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2378 *q++=GetPixelRed(image,p);
2379 *q++=GetPixelGreen(image,p);
2380 *q++=GetPixelBlue(image,p);
2381 *q++=(Quantum) (GetPixelAlpha(image,p));
2386 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2388 p=GetAuthenticPixelQueue(image);
2389 if (p == (const Quantum *) NULL)
2391 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2393 *q++=GetPixelRed(image,p);
2394 *q++=GetPixelGreen(image,p);
2395 *q++=GetPixelBlue(image,p);
2401 p=GetAuthenticPixelQueue(image);
2402 if (p == (const Quantum *) NULL)
2404 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2406 for (i=0; i < (ssize_t) length; i++)
2409 switch (quantum_map[i])
2414 *q=GetPixelRed(image,p);
2418 case MagentaQuantum:
2420 *q=GetPixelGreen(image,p);
2426 *q=GetPixelBlue(image,p);
2431 *q=(Quantum) (GetPixelAlpha(image,p));
2434 case OpacityQuantum:
2436 *q=GetPixelAlpha(image,p);
2441 if (image->colorspace == CMYKColorspace)
2442 *q=GetPixelBlack(image,p);
2447 *q=(GetPixelIntensity(image,p));
2461 register unsigned short
2464 q=(unsigned short *) stream_info->pixels;
2465 if (LocaleCompare(stream_info->map,"BGR") == 0)
2467 p=GetAuthenticPixelQueue(image);
2468 if (p == (const Quantum *) NULL)
2470 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2472 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2473 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2474 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2479 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2481 p=GetAuthenticPixelQueue(image);
2482 if (p == (const Quantum *) NULL)
2484 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2486 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2487 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2488 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2489 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2494 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2496 p=GetAuthenticPixelQueue(image);
2497 if (p == (const Quantum *) NULL)
2499 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2501 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2502 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2503 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2509 if (LocaleCompare(stream_info->map,"I") == 0)
2511 p=GetAuthenticPixelQueue(image);
2512 if (p == (const Quantum *) NULL)
2514 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2516 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
2521 if (LocaleCompare(stream_info->map,"RGB") == 0)
2523 p=GetAuthenticPixelQueue(image);
2524 if (p == (const Quantum *) NULL)
2526 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2528 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2529 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2530 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2535 if (LocaleCompare(stream_info->map,"RGBA") == 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));
2545 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2550 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2552 p=GetAuthenticPixelQueue(image);
2553 if (p == (const Quantum *) NULL)
2555 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2557 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2558 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2559 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2565 p=GetAuthenticPixelQueue(image);
2566 if (p == (const Quantum *) NULL)
2568 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2570 for (i=0; i < (ssize_t) length; i++)
2573 switch (quantum_map[i])
2578 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2582 case MagentaQuantum:
2584 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2590 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2595 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2598 case OpacityQuantum:
2600 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2605 if (image->colorspace == CMYKColorspace)
2606 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2611 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
2625 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2626 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2627 "UnrecognizedPixelMap","`%s'",stream_info->map);
2631 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2640 + 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 %
2644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2646 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2647 % the latest stream of pixels.
2649 % The format of the SyncAuthenticPixelsStream method is:
2651 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2652 % ExceptionInfo *exception)
2654 % A description of each parameter follows:
2656 % o image: the image.
2658 % o exception: return any errors or warnings in this structure.
2661 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2662 ExceptionInfo *exception)
2673 assert(image != (Image *) NULL);
2674 assert(image->signature == MagickSignature);
2675 if (image->debug != MagickFalse)
2676 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2677 cache_info=(CacheInfo *) image->cache;
2678 assert(cache_info->signature == MagickSignature);
2679 stream_handler=GetBlobStreamHandler(image);
2680 if (stream_handler == (StreamHandler) NULL)
2682 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2683 "NoStreamHandlerIsDefined","`%s'",image->filename);
2684 return(MagickFalse);
2686 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2687 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2695 % W r i t e S t r e a m %
2699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2701 % WriteStream() makes the image pixels available to a user supplied callback
2702 % method immediately upon writing pixel data with the WriteImage() method.
2704 % The format of the WriteStream() method is:
2706 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2707 % StreamHandler stream,ExceptionInfo *exception)
2709 % A description of each parameter follows:
2711 % o image_info: the image info.
2713 % o stream: A callback method.
2715 % o exception: return any errors or warnings in this structure.
2718 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2719 Image *image,StreamHandler stream,ExceptionInfo *exception)
2727 assert(image_info != (ImageInfo *) NULL);
2728 assert(image_info->signature == MagickSignature);
2729 if (image_info->debug != MagickFalse)
2730 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2731 image_info->filename);
2732 assert(image != (Image *) NULL);
2733 assert(image->signature == MagickSignature);
2734 write_info=CloneImageInfo(image_info);
2735 write_info->stream=stream;
2736 status=WriteImage(write_info,image,exception);
2737 write_info=DestroyImageInfo(write_info);