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-2010 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 "magick/studio.h"
44 #include "magick/blob.h"
45 #include "magick/blob-private.h"
46 #include "magick/cache.h"
47 #include "magick/cache-private.h"
48 #include "magick/color-private.h"
49 #include "magick/composite-private.h"
50 #include "magick/constitute.h"
51 #include "magick/exception.h"
52 #include "magick/exception-private.h"
53 #include "magick/geometry.h"
54 #include "magick/memory_.h"
55 #include "magick/pixel.h"
56 #include "magick/quantum.h"
57 #include "magick/quantum-private.h"
58 #include "magick/semaphore.h"
59 #include "magick/stream.h"
60 #include "magick/stream-private.h"
61 #include "magick/string_.h"
64 Typedef declaractions.
106 Declare pixel cache interfaces.
108 #if defined(__cplusplus) || defined(c_plusplus)
112 static const PixelPacket
113 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
114 const ssize_t,const size_t,const size_t,ExceptionInfo *);
116 static MagickBooleanType
117 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
118 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
121 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
122 const size_t,ExceptionInfo *);
124 #if defined(__cplusplus) || defined(c_plusplus)
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 + A c q u i r e S t r e a m I n f o %
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % AcquireStreamInfo() allocates the StreamInfo structure.
141 % The format of the AcquireStreamInfo method is:
143 % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
145 % A description of each parameter follows:
147 % o image_info: the image info.
150 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
155 stream_info=(StreamInfo *) AcquireAlignedMemory(1,sizeof(*stream_info));
156 if (stream_info == (StreamInfo *) NULL)
157 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
158 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
159 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
160 sizeof(*stream_info->pixels));
161 if (stream_info->pixels == (unsigned char *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 stream_info->map=ConstantString("RGB");
164 stream_info->storage_type=CharPixel;
165 stream_info->stream=AcquireImage(image_info);
166 stream_info->signature=MagickSignature;
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 + D e s t r o y P i x e l S t r e a m %
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 % DestroyPixelStream() deallocates memory associated with the pixel stream.
183 % The format of the DestroyPixelStream() method is:
185 % void DestroyPixelStream(Image *image)
187 % A description of each parameter follows:
189 % o image: the image.
193 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
195 assert(cache_info != (CacheInfo *) NULL);
196 if (cache_info->mapped == MagickFalse)
197 (void) RelinquishMagickMemory(cache_info->pixels);
199 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
200 cache_info->pixels=(PixelPacket *) NULL;
201 cache_info->indexes=(IndexPacket *) NULL;
202 cache_info->length=0;
203 cache_info->mapped=MagickFalse;
206 static void DestroyPixelStream(Image *image)
214 assert(image != (Image *) NULL);
215 assert(image->signature == MagickSignature);
216 if (image->debug != MagickFalse)
217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
218 cache_info=(CacheInfo *) image->cache;
219 assert(cache_info->signature == MagickSignature);
221 LockSemaphoreInfo(cache_info->semaphore);
222 cache_info->reference_count--;
223 if (cache_info->reference_count == 0)
225 UnlockSemaphoreInfo(cache_info->semaphore);
226 if (destroy == MagickFalse)
228 RelinquishStreamPixels(cache_info);
229 if (cache_info->nexus_info != (NexusInfo **) NULL)
230 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
231 cache_info->number_threads);
232 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
233 DestroySemaphoreInfo(&cache_info->disk_semaphore);
234 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
235 DestroySemaphoreInfo(&cache_info->semaphore);
236 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 + D e s t r o y S t r e a m I n f o %
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % DestroyStreamInfo() destroys memory associated with the StreamInfo
253 % The format of the DestroyStreamInfo method is:
255 % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
257 % A description of each parameter follows:
259 % o stream_info: the stream info.
262 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
265 assert(stream_info != (StreamInfo *) NULL);
266 assert(stream_info->signature == MagickSignature);
267 if (stream_info->map != (char *) NULL)
268 stream_info->map=DestroyString(stream_info->map);
269 if (stream_info->pixels != (unsigned char *) NULL)
270 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
271 stream_info->pixels);
272 if (stream_info->stream != (Image *) NULL)
274 (void) CloseBlob(stream_info->stream);
275 stream_info->stream=DestroyImage(stream_info->stream);
277 if (stream_info->quantum_info != (QuantumInfo *) NULL)
278 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
279 stream_info->signature=(~MagickSignature);
280 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 + G e t A u t h e n t i c I n d e x e s F r o m S t r e a m %
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % GetAuthenticIndexesFromStream() returns the indexes associated with the
296 % last call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
298 % The format of the GetAuthenticIndexesFromStream() method is:
300 % IndexPacket *GetAuthenticIndexesFromStream(const Image *image)
302 % A description of each parameter follows:
304 % o image: the image.
307 static IndexPacket *GetAuthenticIndexesFromStream(const Image *image)
312 assert(image != (Image *) NULL);
313 assert(image->signature == MagickSignature);
314 if (image->debug != MagickFalse)
315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
316 cache_info=(CacheInfo *) image->cache;
317 assert(cache_info->signature == MagickSignature);
318 return(cache_info->indexes);
322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 + G e t A u t h e n t i c P i x e l S t r e a m %
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
333 % cache as defined by the geometry parameters. A pointer to the pixels is
334 % returned if the pixels are transferred, otherwise a NULL is returned. For
335 % streams this method is a no-op.
337 % The format of the GetAuthenticPixelsStream() method is:
339 % PixelPacket *GetAuthenticPixelsStream(Image *image,const ssize_t x,
340 % const ssize_t y,const size_t columns,const size_t rows,
341 % ExceptionInfo *exception)
343 % A description of each parameter follows:
345 % o image: the image.
347 % o x,y,columns,rows: These values define the perimeter of a region of
350 % o exception: return any errors or warnings in this structure.
353 static PixelPacket *GetAuthenticPixelsStream(Image *image,const ssize_t x,
354 const ssize_t y,const size_t columns,const size_t rows,
355 ExceptionInfo *exception)
360 assert(image != (Image *) NULL);
361 assert(image->signature == MagickSignature);
362 if (image->debug != MagickFalse)
363 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
364 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 + 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 %
377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % GetAuthenticPixelsFromStream() returns the pixels associated with the last
380 % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
382 % The format of the GetAuthenticPixelsFromStream() method is:
384 % PixelPacket *GetAuthenticPixelsFromStream(const Image image)
386 % A description of each parameter follows:
388 % o image: the image.
391 static PixelPacket *GetAuthenticPixelsFromStream(const Image *image)
396 assert(image != (Image *) NULL);
397 assert(image->signature == MagickSignature);
398 if (image->debug != MagickFalse)
399 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
400 cache_info=(CacheInfo *) image->cache;
401 assert(cache_info->signature == MagickSignature);
402 return(cache_info->pixels);
406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 + 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 %
414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 % GetOneAuthenticPixelFromStream() returns a single pixel at the specified
417 % (x,y) location. The image background color is returned if an error occurs.
419 % The format of the GetOneAuthenticPixelFromStream() method is:
421 % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
422 % const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
424 % A description of each parameter follows:
426 % o image: the image.
428 % o pixel: return a pixel at the specified (x,y) location.
430 % o x,y: These values define the location of the pixel to return.
432 % o exception: return any errors or warnings in this structure.
435 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
436 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
441 assert(image != (Image *) NULL);
442 assert(image->signature == MagickSignature);
443 *pixel=image->background_color;
444 pixels=GetAuthenticPixelsStream(image,x,y,1,1,exception);
445 if (pixels != (PixelPacket *) NULL)
452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 + 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 %
460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 % GetOneVirtualPixelFromStream() returns a single pixel at the specified
463 % (x.y) location. The image background color is returned if an error occurs.
465 % The format of the GetOneVirtualPixelFromStream() method is:
467 % MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
468 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
469 % const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
471 % A description of each parameter follows:
473 % o image: the image.
475 % o virtual_pixel_method: the virtual pixel method.
477 % o x,y: These values define the location of the pixel to return.
479 % o pixel: return a pixel at the specified (x,y) location.
481 % o exception: return any errors or warnings in this structure.
484 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
485 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
486 PixelPacket *pixel,ExceptionInfo *exception)
491 assert(image != (Image *) NULL);
492 assert(image->signature == MagickSignature);
493 *pixel=image->background_color;
494 pixels=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
495 if (pixels != (const PixelPacket *) NULL)
502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 + G e t S t r e a m I n f o C l i e n t D a t a %
510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512 % GetStreamInfoClientData() gets the stream info client data.
514 % The format of the SetStreamInfoClientData method is:
516 % const void *GetStreamInfoClientData(StreamInfo *stream_info)
518 % A description of each parameter follows:
520 % o stream_info: the stream info.
523 MagickExport const void *GetStreamInfoClientData(StreamInfo *stream_info)
525 assert(stream_info != (StreamInfo *) NULL);
526 assert(stream_info->signature == MagickSignature);
527 return(stream_info->client_data);
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535 + 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 %
539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 % GetVirtualPixelsStream() returns the pixels associated with the last
542 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
544 % The format of the GetVirtualPixelsStream() method is:
546 % const IndexPacket *GetVirtualPixelsStream(const Image *image)
548 % A description of each parameter follows:
550 % o pixels: return the pixels associated with the last call to
551 % QueueAuthenticPixelsStream() or GetVirtualPixelStream().
553 % o image: the image.
556 static const PixelPacket *GetVirtualPixelsStream(const Image *image)
561 assert(image != (Image *) NULL);
562 assert(image->signature == MagickSignature);
563 if (image->debug != MagickFalse)
564 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
565 cache_info=(CacheInfo *) image->cache;
566 assert(cache_info->signature == MagickSignature);
567 return(cache_info->pixels);
571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 + 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 %
579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 % GetVirtualIndexesFromStream() returns the indexes associated with the last
582 % call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
584 % The format of the GetVirtualIndexesFromStream() method is:
586 % const IndexPacket *GetVirtualIndexesFromStream(const Image *image)
588 % A description of each parameter follows:
590 % o image: the image.
593 static const IndexPacket *GetVirtualIndexesFromStream(const Image *image)
598 assert(image != (Image *) NULL);
599 assert(image->signature == MagickSignature);
600 if (image->debug != MagickFalse)
601 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
602 cache_info=(CacheInfo *) image->cache;
603 assert(cache_info->signature == MagickSignature);
604 return(cache_info->indexes);
608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
612 + G e t V i r t u a l P i x e l S t r e a m %
616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618 % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
619 % defined by the geometry parameters. A pointer to the pixels is returned if
620 % the pixels are transferred, otherwise a NULL is returned. For streams this
623 % The format of the GetVirtualPixelStream() method is:
625 % const PixelPacket *GetVirtualPixelStream(const Image *image,
626 % const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
627 % const ssize_t y,const size_t columns,const size_t rows,
628 % ExceptionInfo *exception)
630 % A description of each parameter follows:
632 % o image: the image.
634 % o virtual_pixel_method: the virtual pixel method.
636 % o x,y,columns,rows: These values define the perimeter of a region of
639 % o exception: return any errors or warnings in this structure.
643 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
644 ExceptionInfo *exception)
646 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
648 cache_info->mapped=MagickFalse;
649 cache_info->pixels=(PixelPacket *) AcquireMagickMemory((size_t)
651 if (cache_info->pixels == (PixelPacket *) NULL)
653 cache_info->mapped=MagickTrue;
654 cache_info->pixels=(PixelPacket *) MapBlob(-1,IOMode,0,(size_t)
657 if (cache_info->pixels == (PixelPacket *) NULL)
659 (void) ThrowMagickException(exception,GetMagickModule(),
660 ResourceLimitError,"MemoryAllocationFailed","`%s'",
661 cache_info->filename);
667 static const PixelPacket *GetVirtualPixelStream(const Image *image,
668 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
669 const ssize_t y,const size_t columns,const size_t rows,
670 ExceptionInfo *exception)
685 Validate pixel cache geometry.
687 assert(image != (const Image *) NULL);
688 assert(image->signature == MagickSignature);
689 if (image->debug != MagickFalse)
690 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
691 if ((x < 0) || (y < 0) ||
692 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
693 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
694 (columns == 0) || (rows == 0))
696 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
697 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
698 return((PixelPacket *) NULL);
700 cache_info=(CacheInfo *) image->cache;
701 assert(cache_info->signature == MagickSignature);
703 Pixels are stored in a temporary buffer until they are synced to the cache.
705 number_pixels=(MagickSizeType) columns*rows;
706 length=(size_t) number_pixels*sizeof(PixelPacket);
707 if ((image->storage_class == PseudoClass) ||
708 (image->colorspace == CMYKColorspace))
709 length+=number_pixels*sizeof(IndexPacket);
710 if (cache_info->pixels == (PixelPacket *) NULL)
712 cache_info->length=length;
713 status=AcquireStreamPixels(cache_info,exception);
714 if (status == MagickFalse)
715 return((PixelPacket *) NULL);
718 if (cache_info->length != length)
720 RelinquishStreamPixels(cache_info);
721 cache_info->length=length;
722 status=AcquireStreamPixels(cache_info,exception);
723 if (status == MagickFalse)
724 return((PixelPacket *) NULL);
726 cache_info->indexes=(IndexPacket *) NULL;
727 if ((image->storage_class == PseudoClass) ||
728 (image->colorspace == CMYKColorspace))
729 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
730 return(cache_info->pixels);
734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
738 + O p e n S t r e a m %
742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 % OpenStream() opens a stream for writing by the StreamImage() method.
746 % The format of the OpenStream method is:
748 % MagickBooleanType OpenStream(const ImageInfo *image_info,
749 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
751 % A description of each parameter follows:
753 % o image_info: the image info.
755 % o stream_info: the stream info.
757 % o filename: the stream filename.
759 % o exception: return any errors or warnings in this structure.
762 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
763 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
768 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
769 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
778 + 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 %
782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
785 % defined by the region rectangle and returns a pointer to the area. This
786 % area is subsequently transferred from the pixel cache with method
787 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
788 % pixels are transferred, otherwise a NULL is returned.
790 % The format of the QueueAuthenticPixelsStream() method is:
792 % PixelPacket *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
793 % const ssize_t y,const size_t columns,const size_t rows,
794 % ExceptionInfo *exception)
796 % A description of each parameter follows:
798 % o image: the image.
800 % o x,y,columns,rows: These values define the perimeter of a region of
804 static PixelPacket *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
805 const ssize_t y,const size_t columns,const size_t rows,
806 ExceptionInfo *exception)
821 Validate pixel cache geometry.
823 assert(image != (Image *) NULL);
824 if ((x < 0) || (y < 0) || ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
825 ((y+(ssize_t) rows) > (ssize_t) image->rows) || (columns == 0) || (rows == 0))
827 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
828 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
829 return((PixelPacket *) NULL);
831 stream_handler=GetBlobStreamHandler(image);
832 if (stream_handler == (StreamHandler) NULL)
834 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
835 "NoStreamHandlerIsDefined","`%s'",image->filename);
836 return((PixelPacket *) NULL);
838 cache_info=(CacheInfo *) image->cache;
839 assert(cache_info->signature == MagickSignature);
840 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
841 (image->colorspace != GetPixelCacheColorspace(image->cache)))
843 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
844 (void) stream_handler(image,(const void *) NULL,(size_t)
845 cache_info->columns);
846 cache_info->storage_class=image->storage_class;
847 cache_info->colorspace=image->colorspace;
848 cache_info->columns=image->columns;
849 cache_info->rows=image->rows;
850 image->cache=cache_info;
853 Pixels are stored in a temporary buffer until they are synced to the cache.
855 cache_info->columns=columns;
856 cache_info->rows=rows;
857 number_pixels=(MagickSizeType) columns*rows;
858 length=(size_t) number_pixels*sizeof(PixelPacket);
859 if ((image->storage_class == PseudoClass) ||
860 (image->colorspace == CMYKColorspace))
861 length+=number_pixels*sizeof(IndexPacket);
862 if (cache_info->pixels == (PixelPacket *) NULL)
864 cache_info->pixels=(PixelPacket *) AcquireMagickMemory(length);
865 cache_info->length=(MagickSizeType) length;
868 if (cache_info->length < (MagickSizeType) length)
870 cache_info->pixels=(PixelPacket *) ResizeMagickMemory(
871 cache_info->pixels,length);
872 cache_info->length=(MagickSizeType) length;
874 if (cache_info->pixels == (void *) NULL)
875 return((PixelPacket *) NULL);
876 cache_info->indexes=(IndexPacket *) NULL;
877 if ((image->storage_class == PseudoClass) ||
878 (image->colorspace == CMYKColorspace))
879 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
880 return(cache_info->pixels);
884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888 % R e a d S t r e a m %
892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 % ReadStream() makes the image pixels available to a user supplied callback
895 % method immediately upon reading a scanline with the ReadImage() method.
897 % The format of the ReadStream() method is:
899 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
900 % ExceptionInfo *exception)
902 % A description of each parameter follows:
904 % o image_info: the image info.
906 % o stream: a callback method.
908 % o exception: return any errors or warnings in this structure.
911 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
912 ExceptionInfo *exception)
926 assert(image_info != (ImageInfo *) NULL);
927 assert(image_info->signature == MagickSignature);
928 if (image_info->debug != MagickFalse)
929 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
930 image_info->filename);
931 assert(exception != (ExceptionInfo *) NULL);
932 assert(exception->signature == MagickSignature);
933 read_info=CloneImageInfo(image_info);
934 read_info->cache=AcquirePixelCache(0);
935 GetPixelCacheMethods(&cache_methods);
936 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
937 cache_methods.get_virtual_indexes_from_handler=GetVirtualIndexesFromStream;
938 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
939 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
940 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
941 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
942 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
943 cache_methods.get_authentic_indexes_from_handler=
944 GetAuthenticIndexesFromStream;
945 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
946 cache_methods.get_one_authentic_pixel_from_handler=
947 GetOneAuthenticPixelFromStream;
948 cache_methods.destroy_pixel_handler=DestroyPixelStream;
949 SetPixelCacheMethods(read_info->cache,&cache_methods);
950 read_info->stream=stream;
951 image=ReadImage(read_info,exception);
952 read_info=DestroyImageInfo(read_info);
957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
961 + S e t S t r e a m I n f o C l i e n t D a t a %
965 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 % SetStreamInfoClientData() sets the stream info client data.
969 % The format of the SetStreamInfoClientData method is:
971 % void SetStreamInfoClientData(StreamInfo *stream_info,
972 % const void *client_data)
974 % A description of each parameter follows:
976 % o stream_info: the stream info.
978 % o client_data: the client data.
981 MagickExport void SetStreamInfoClientData(StreamInfo *stream_info,
982 const void *client_data)
984 assert(stream_info != (StreamInfo *) NULL);
985 assert(stream_info->signature == MagickSignature);
986 stream_info->client_data=client_data;
990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 + S e t S t r e a m I n f o M a p %
998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 % SetStreamInfoMap() sets the stream info map member.
1002 % The format of the SetStreamInfoMap method is:
1004 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1006 % A description of each parameter follows:
1008 % o stream_info: the stream info.
1013 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1015 assert(stream_info != (StreamInfo *) NULL);
1016 assert(stream_info->signature == MagickSignature);
1017 (void) CloneString(&stream_info->map,map);
1021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1025 + S e t S t r e a m I n f o S t o r a g e T y p e %
1029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1031 % SetStreamInfoStorageType() sets the stream info storage type member.
1033 % The format of the SetStreamInfoStorageType method is:
1035 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1036 % const StoreageType *storage_type)
1038 % A description of each parameter follows:
1040 % o stream_info: the stream info.
1042 % o storage_type: the storage type.
1045 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1046 const StorageType storage_type)
1048 assert(stream_info != (StreamInfo *) NULL);
1049 assert(stream_info->signature == MagickSignature);
1050 stream_info->storage_type=storage_type;
1054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 + S t r e a m I m a g e %
1062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 % StreamImage() streams pixels from an image and writes them in a user
1065 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1067 % The format of he wStreamImage() method is:
1069 % Image *StreamImage(const ImageInfo *image_info,
1070 % StreamInfo *stream_info,ExceptionInfo *exception)
1072 % A description of each parameter follows:
1074 % o image_info: the image info.
1076 % o stream_info: the stream info.
1078 % o exception: return any errors or warnings in this structure.
1082 #if defined(__cplusplus) || defined(c_plusplus)
1086 static size_t WriteStreamImage(const Image *image,const void *pixels,
1087 const size_t columns)
1105 stream_info=(StreamInfo *) image->client_data;
1106 switch (stream_info->storage_type)
1108 default: packet_size=sizeof(char); break;
1109 case CharPixel: packet_size=sizeof(char); break;
1110 case DoublePixel: packet_size=sizeof(double); break;
1111 case FloatPixel: packet_size=sizeof(float); break;
1112 case IntegerPixel: packet_size=sizeof(int); break;
1113 case LongPixel: packet_size=sizeof(ssize_t); break;
1114 case QuantumPixel: packet_size=sizeof(Quantum); break;
1115 case ShortPixel: packet_size=sizeof(unsigned short); break;
1117 cache_info=(CacheInfo *) image->cache;
1118 assert(cache_info->signature == MagickSignature);
1119 packet_size*=strlen(stream_info->map);
1120 length=packet_size*cache_info->columns*cache_info->rows;
1121 if (image != stream_info->image)
1127 Prepare stream for writing.
1129 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1130 stream_info->pixels,length,sizeof(*stream_info->pixels));
1131 if (stream_info->pixels == (unsigned char *) NULL)
1133 stream_info->image=image;
1134 write_info=CloneImageInfo(stream_info->image_info);
1135 (void) SetImageInfo(write_info,1,stream_info->exception);
1136 if (write_info->extract != (char *) NULL)
1137 (void) ParseAbsoluteGeometry(write_info->extract,
1138 &stream_info->extract_info);
1140 write_info=DestroyImageInfo(write_info);
1142 extract_info=stream_info->extract_info;
1143 if ((extract_info.width == 0) ||
1144 (extract_info.height == 0))
1147 Write all pixels to stream.
1149 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1150 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1152 return(count == 0 ? 0 : columns);
1154 if ((stream_info->y < extract_info.y) ||
1155 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1161 Write a portion of the pixel row to the stream.
1163 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1164 length=packet_size*extract_info.width;
1165 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1168 return(count == 0 ? 0 : columns);
1171 #if defined(__cplusplus) || defined(c_plusplus)
1175 MagickExport Image *StreamImage(const ImageInfo *image_info,
1176 StreamInfo *stream_info,ExceptionInfo *exception)
1184 assert(image_info != (const ImageInfo *) NULL);
1185 assert(image_info->signature == MagickSignature);
1186 if (image_info->debug != MagickFalse)
1187 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1188 image_info->filename);
1189 assert(stream_info != (StreamInfo *) NULL);
1190 assert(stream_info->signature == MagickSignature);
1191 assert(exception != (ExceptionInfo *) NULL);
1192 read_info=CloneImageInfo(image_info);
1193 stream_info->image_info=image_info;
1194 stream_info->exception=exception;
1195 read_info->client_data=(void *) stream_info;
1196 image=ReadStream(read_info,&WriteStreamImage,exception);
1197 read_info=DestroyImageInfo(read_info);
1198 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1199 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1200 image=DestroyImage(image);
1205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1209 + S t r e a m I m a g e P i x e l s %
1213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1215 % StreamImagePixels() extracts pixel data from an image and returns it in the
1216 % stream_info->pixels structure in the format as defined by
1217 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1219 % The format of the StreamImagePixels method is:
1221 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1222 % const Image *image,ExceptionInfo *exception)
1224 % A description of each parameter follows:
1226 % o stream_info: the stream info.
1228 % o image: the image.
1230 % o exception: return any errors or warnings in this structure.
1233 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1234 const Image *image,ExceptionInfo *exception)
1246 register const PixelPacket
1249 register IndexPacket
1255 assert(stream_info != (StreamInfo *) NULL);
1256 assert(stream_info->signature == MagickSignature);
1257 assert(image != (Image *) NULL);
1258 assert(image->signature == MagickSignature);
1259 if (image->debug != MagickFalse)
1260 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1261 length=strlen(stream_info->map);
1262 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1263 if (quantum_map == (QuantumType *) NULL)
1265 (void) ThrowMagickException(exception,GetMagickModule(),
1266 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1267 return(MagickFalse);
1269 for (i=0; i < (ssize_t) length; i++)
1271 switch (stream_info->map[i])
1276 quantum_map[i]=AlphaQuantum;
1282 quantum_map[i]=BlueQuantum;
1288 quantum_map[i]=CyanQuantum;
1289 if (image->colorspace == CMYKColorspace)
1291 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1292 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1293 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1294 return(MagickFalse);
1299 quantum_map[i]=GreenQuantum;
1305 quantum_map[i]=IndexQuantum;
1311 quantum_map[i]=BlackQuantum;
1312 if (image->colorspace == CMYKColorspace)
1314 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1315 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1316 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1317 return(MagickFalse);
1322 quantum_map[i]=MagentaQuantum;
1323 if (image->colorspace == CMYKColorspace)
1325 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1326 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1327 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1328 return(MagickFalse);
1333 quantum_map[i]=OpacityQuantum;
1339 quantum_map[i]=UndefinedQuantum;
1345 quantum_map[i]=RedQuantum;
1351 quantum_map[i]=YellowQuantum;
1352 if (image->colorspace == CMYKColorspace)
1354 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1355 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1356 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1357 return(MagickFalse);
1361 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1362 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1363 "UnrecognizedPixelMap","`%s'",stream_info->map);
1364 return(MagickFalse);
1368 quantum_info=stream_info->quantum_info;
1369 switch (stream_info->storage_type)
1373 register unsigned char
1376 q=(unsigned char *) stream_info->pixels;
1377 if (LocaleCompare(stream_info->map,"BGR") == 0)
1379 p=GetAuthenticPixelQueue(image);
1380 if (p == (const PixelPacket *) NULL)
1382 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1384 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1385 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1386 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1391 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1393 p=GetAuthenticPixelQueue(image);
1394 if (p == (const PixelPacket *) NULL)
1396 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1398 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1399 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1400 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1401 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1406 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1408 p=GetAuthenticPixelQueue(image);
1409 if (p == (const PixelPacket *) NULL)
1411 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1413 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1414 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1415 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1416 *q++=ScaleQuantumToChar((Quantum) 0);
1421 if (LocaleCompare(stream_info->map,"I") == 0)
1423 p=GetAuthenticPixelQueue(image);
1424 if (p == (const PixelPacket *) NULL)
1426 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1428 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1433 if (LocaleCompare(stream_info->map,"RGB") == 0)
1435 p=GetAuthenticPixelQueue(image);
1436 if (p == (const PixelPacket *) NULL)
1438 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1440 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1441 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1442 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1447 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1449 p=GetAuthenticPixelQueue(image);
1450 if (p == (const PixelPacket *) NULL)
1452 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1454 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1455 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1456 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1457 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1462 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1464 p=GetAuthenticPixelQueue(image);
1465 if (p == (const PixelPacket *) NULL)
1467 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1469 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1470 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1471 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1472 *q++=ScaleQuantumToChar((Quantum) 0);
1477 p=GetAuthenticPixelQueue(image);
1478 if (p == (const PixelPacket *) NULL)
1480 indexes=GetAuthenticIndexQueue(image);
1481 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1483 for (i=0; i < (ssize_t) length; i++)
1486 switch (quantum_map[i])
1491 *q=ScaleQuantumToChar(GetRedPixelComponent(p));
1495 case MagentaQuantum:
1497 *q=ScaleQuantumToChar(GetGreenPixelComponent(p));
1503 *q=ScaleQuantumToChar(GetBluePixelComponent(p));
1508 *q=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1511 case OpacityQuantum:
1513 *q=ScaleQuantumToChar(GetOpacityPixelComponent(p));
1518 if (image->colorspace == CMYKColorspace)
1519 *q=ScaleQuantumToChar(indexes[x]);
1524 *q=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1541 q=(double *) stream_info->pixels;
1542 if (LocaleCompare(stream_info->map,"BGR") == 0)
1544 p=GetAuthenticPixelQueue(image);
1545 if (p == (const PixelPacket *) NULL)
1547 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1549 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1550 quantum_info->scale+quantum_info->minimum);
1551 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1552 quantum_info->scale+quantum_info->minimum);
1553 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1554 quantum_info->scale+quantum_info->minimum);
1559 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1561 p=GetAuthenticPixelQueue(image);
1562 if (p == (const PixelPacket *) NULL)
1564 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1566 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1567 quantum_info->scale+quantum_info->minimum);
1568 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1569 quantum_info->scale+quantum_info->minimum);
1570 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1571 quantum_info->scale+quantum_info->minimum);
1572 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1573 quantum_info->scale+quantum_info->minimum);
1578 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1580 p=GetAuthenticPixelQueue(image);
1581 if (p == (const PixelPacket *) NULL)
1583 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1585 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1586 quantum_info->scale+quantum_info->minimum);
1587 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1588 quantum_info->scale+quantum_info->minimum);
1589 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1590 quantum_info->scale+quantum_info->minimum);
1596 if (LocaleCompare(stream_info->map,"I") == 0)
1598 p=GetAuthenticPixelQueue(image);
1599 if (p == (const PixelPacket *) NULL)
1601 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1603 *q++=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1604 quantum_info->scale+quantum_info->minimum);
1609 if (LocaleCompare(stream_info->map,"RGB") == 0)
1611 p=GetAuthenticPixelQueue(image);
1612 if (p == (const PixelPacket *) NULL)
1614 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1616 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1617 quantum_info->scale+quantum_info->minimum);
1618 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1619 quantum_info->scale+quantum_info->minimum);
1620 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1621 quantum_info->scale+quantum_info->minimum);
1626 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1628 p=GetAuthenticPixelQueue(image);
1629 if (p == (const PixelPacket *) NULL)
1631 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1633 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1634 quantum_info->scale+quantum_info->minimum);
1635 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1636 quantum_info->scale+quantum_info->minimum);
1637 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1638 quantum_info->scale+quantum_info->minimum);
1639 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1640 quantum_info->scale+quantum_info->minimum);
1645 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1647 p=GetAuthenticPixelQueue(image);
1648 if (p == (const PixelPacket *) NULL)
1650 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1652 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1653 quantum_info->scale+quantum_info->minimum);
1654 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1655 quantum_info->scale+quantum_info->minimum);
1656 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1657 quantum_info->scale+quantum_info->minimum);
1663 p=GetAuthenticPixelQueue(image);
1664 if (p == (const PixelPacket *) NULL)
1666 indexes=GetAuthenticIndexQueue(image);
1667 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1669 for (i=0; i < (ssize_t) length; i++)
1672 switch (quantum_map[i])
1677 *q=(double) ((QuantumScale*GetRedPixelComponent(p))*
1678 quantum_info->scale+quantum_info->minimum);
1682 case MagentaQuantum:
1684 *q=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1685 quantum_info->scale+quantum_info->minimum);
1691 *q=(double) ((QuantumScale*GetBluePixelComponent(p))*
1692 quantum_info->scale+quantum_info->minimum);
1697 *q=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1698 quantum_info->scale+quantum_info->minimum);
1701 case OpacityQuantum:
1703 *q=(double) ((QuantumScale*GetOpacityPixelComponent(p))*
1704 quantum_info->scale+quantum_info->minimum);
1709 if (image->colorspace == CMYKColorspace)
1710 *q=(double) ((QuantumScale*indexes[x])*quantum_info->scale+
1711 quantum_info->minimum);
1716 *q=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1717 quantum_info->scale+quantum_info->minimum);
1734 q=(float *) stream_info->pixels;
1735 if (LocaleCompare(stream_info->map,"BGR") == 0)
1737 p=GetAuthenticPixelQueue(image);
1738 if (p == (const PixelPacket *) NULL)
1740 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1742 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1743 quantum_info->scale+quantum_info->minimum);
1744 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1745 quantum_info->scale+quantum_info->minimum);
1746 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1747 quantum_info->scale+quantum_info->minimum);
1752 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1754 p=GetAuthenticPixelQueue(image);
1755 if (p == (const PixelPacket *) NULL)
1757 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1759 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1760 quantum_info->scale+quantum_info->minimum);
1761 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1762 quantum_info->scale+quantum_info->minimum);
1763 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1764 quantum_info->scale+quantum_info->minimum);
1765 *q++=(float) ((QuantumScale*(Quantum) (GetAlphaPixelComponent(p)))*
1766 quantum_info->scale+quantum_info->minimum);
1771 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1773 p=GetAuthenticPixelQueue(image);
1774 if (p == (const PixelPacket *) NULL)
1776 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1778 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1779 quantum_info->scale+quantum_info->minimum);
1780 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1781 quantum_info->scale+quantum_info->minimum);
1782 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1783 quantum_info->scale+quantum_info->minimum);
1789 if (LocaleCompare(stream_info->map,"I") == 0)
1791 p=GetAuthenticPixelQueue(image);
1792 if (p == (const PixelPacket *) NULL)
1794 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1796 *q++=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1797 quantum_info->scale+quantum_info->minimum);
1802 if (LocaleCompare(stream_info->map,"RGB") == 0)
1804 p=GetAuthenticPixelQueue(image);
1805 if (p == (const PixelPacket *) NULL)
1807 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1809 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1810 quantum_info->scale+quantum_info->minimum);
1811 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1812 quantum_info->scale+quantum_info->minimum);
1813 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1814 quantum_info->scale+quantum_info->minimum);
1819 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1821 p=GetAuthenticPixelQueue(image);
1822 if (p == (const PixelPacket *) NULL)
1824 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1826 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1827 quantum_info->scale+quantum_info->minimum);
1828 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1829 quantum_info->scale+quantum_info->minimum);
1830 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1831 quantum_info->scale+quantum_info->minimum);
1832 *q++=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1833 quantum_info->scale+quantum_info->minimum);
1838 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1840 p=GetAuthenticPixelQueue(image);
1841 if (p == (const PixelPacket *) NULL)
1843 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1845 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1846 quantum_info->scale+quantum_info->minimum);
1847 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1848 quantum_info->scale+quantum_info->minimum);
1849 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1850 quantum_info->scale+quantum_info->minimum);
1856 p=GetAuthenticPixelQueue(image);
1857 if (p == (const PixelPacket *) NULL)
1859 indexes=GetAuthenticIndexQueue(image);
1860 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1862 for (i=0; i < (ssize_t) length; i++)
1865 switch (quantum_map[i])
1870 *q=(float) ((QuantumScale*GetRedPixelComponent(p))*
1871 quantum_info->scale+quantum_info->minimum);
1875 case MagentaQuantum:
1877 *q=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1878 quantum_info->scale+quantum_info->minimum);
1884 *q=(float) ((QuantumScale*GetBluePixelComponent(p))*
1885 quantum_info->scale+quantum_info->minimum);
1890 *q=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1891 quantum_info->scale+quantum_info->minimum);
1894 case OpacityQuantum:
1896 *q=(float) ((QuantumScale*GetOpacityPixelComponent(p))*
1897 quantum_info->scale+quantum_info->minimum);
1902 if (image->colorspace == CMYKColorspace)
1903 *q=(float) ((QuantumScale*indexes[x])*quantum_info->scale+
1904 quantum_info->minimum);
1909 *q=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1910 quantum_info->scale+quantum_info->minimum);
1924 register unsigned int
1927 q=(unsigned int *) stream_info->pixels;
1928 if (LocaleCompare(stream_info->map,"BGR") == 0)
1930 p=GetAuthenticPixelQueue(image);
1931 if (p == (const PixelPacket *) NULL)
1933 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1935 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1936 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1937 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1942 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1944 p=GetAuthenticPixelQueue(image);
1945 if (p == (const PixelPacket *) NULL)
1947 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1949 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1950 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1951 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1952 *q++=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
1953 GetOpacityPixelComponent(p)));
1958 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1960 p=GetAuthenticPixelQueue(image);
1961 if (p == (const PixelPacket *) NULL)
1963 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1965 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1966 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1967 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1973 if (LocaleCompare(stream_info->map,"I") == 0)
1975 p=GetAuthenticPixelQueue(image);
1976 if (p == (const PixelPacket *) NULL)
1978 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1980 *q++=(unsigned int) ScaleQuantumToLong(
1981 PixelIntensityToQuantum(p));
1986 if (LocaleCompare(stream_info->map,"RGB") == 0)
1988 p=GetAuthenticPixelQueue(image);
1989 if (p == (const PixelPacket *) NULL)
1991 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1993 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1994 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1995 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2000 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2002 p=GetAuthenticPixelQueue(image);
2003 if (p == (const PixelPacket *) NULL)
2005 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2007 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2008 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2009 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2010 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2011 (GetAlphaPixelComponent(p)));
2016 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2018 p=GetAuthenticPixelQueue(image);
2019 if (p == (const PixelPacket *) NULL)
2021 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2023 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2024 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2025 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2031 p=GetAuthenticPixelQueue(image);
2032 if (p == (const PixelPacket *) NULL)
2034 indexes=GetAuthenticIndexQueue(image);
2035 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2037 for (i=0; i < (ssize_t) length; i++)
2040 switch (quantum_map[i])
2045 *q=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2049 case MagentaQuantum:
2051 *q=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2057 *q=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2062 *q=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
2063 GetOpacityPixelComponent(p)));
2066 case OpacityQuantum:
2068 *q=(unsigned int) ScaleQuantumToLong(GetOpacityPixelComponent(p));
2073 if (image->colorspace == CMYKColorspace)
2074 *q=(unsigned int) ScaleQuantumToLong(indexes[x]);
2080 ScaleQuantumToLong(PixelIntensityToQuantum(p));
2097 q=(size_t *) stream_info->pixels;
2098 if (LocaleCompare(stream_info->map,"BGR") == 0)
2100 p=GetAuthenticPixelQueue(image);
2101 if (p == (const PixelPacket *) NULL)
2103 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2105 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2106 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2107 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2112 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2114 p=GetAuthenticPixelQueue(image);
2115 if (p == (const PixelPacket *) NULL)
2117 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2119 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2120 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2121 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2122 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2127 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2129 p=GetAuthenticPixelQueue(image);
2130 if (p == (const PixelPacket *) NULL)
2132 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2134 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2135 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2136 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2142 if (LocaleCompare(stream_info->map,"I") == 0)
2144 p=GetAuthenticPixelQueue(image);
2145 if (p == (const PixelPacket *) NULL)
2147 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2149 *q++=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2154 if (LocaleCompare(stream_info->map,"RGB") == 0)
2156 p=GetAuthenticPixelQueue(image);
2157 if (p == (const PixelPacket *) NULL)
2159 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2161 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2162 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2163 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2168 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2170 p=GetAuthenticPixelQueue(image);
2171 if (p == (const PixelPacket *) NULL)
2173 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2175 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2176 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2177 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2178 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2183 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2185 p=GetAuthenticPixelQueue(image);
2186 if (p == (const PixelPacket *) NULL)
2188 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2190 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2191 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2192 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2198 p=GetAuthenticPixelQueue(image);
2199 if (p == (const PixelPacket *) NULL)
2201 indexes=GetAuthenticIndexQueue(image);
2202 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2204 for (i=0; i < (ssize_t) length; i++)
2207 switch (quantum_map[i])
2212 *q=ScaleQuantumToLong(GetRedPixelComponent(p));
2216 case MagentaQuantum:
2218 *q=ScaleQuantumToLong(GetGreenPixelComponent(p));
2224 *q=ScaleQuantumToLong(GetBluePixelComponent(p));
2229 *q=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2232 case OpacityQuantum:
2234 *q=ScaleQuantumToLong(GetOpacityPixelComponent(p));
2239 if (image->colorspace == CMYKColorspace)
2240 *q=ScaleQuantumToLong(indexes[x]);
2245 *q=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2262 q=(Quantum *) stream_info->pixels;
2263 if (LocaleCompare(stream_info->map,"BGR") == 0)
2265 p=GetAuthenticPixelQueue(image);
2266 if (p == (const PixelPacket *) NULL)
2268 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2270 *q++=GetBluePixelComponent(p);
2271 *q++=GetGreenPixelComponent(p);
2272 *q++=GetRedPixelComponent(p);
2277 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2279 p=GetAuthenticPixelQueue(image);
2280 if (p == (const PixelPacket *) NULL)
2282 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2284 *q++=GetBluePixelComponent(p);
2285 *q++=GetGreenPixelComponent(p);
2286 *q++=GetRedPixelComponent(p);
2287 *q++=(Quantum) (GetAlphaPixelComponent(p));
2292 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2294 p=GetAuthenticPixelQueue(image);
2295 if (p == (const PixelPacket *) NULL)
2297 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2299 *q++=GetBluePixelComponent(p);
2300 *q++=GetGreenPixelComponent(p);
2301 *q++=GetRedPixelComponent(p);
2307 if (LocaleCompare(stream_info->map,"I") == 0)
2309 p=GetAuthenticPixelQueue(image);
2310 if (p == (const PixelPacket *) NULL)
2312 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2314 *q++=PixelIntensityToQuantum(p);
2319 if (LocaleCompare(stream_info->map,"RGB") == 0)
2321 p=GetAuthenticPixelQueue(image);
2322 if (p == (const PixelPacket *) NULL)
2324 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2326 *q++=GetRedPixelComponent(p);
2327 *q++=GetGreenPixelComponent(p);
2328 *q++=GetBluePixelComponent(p);
2333 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2335 p=GetAuthenticPixelQueue(image);
2336 if (p == (const PixelPacket *) NULL)
2338 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2340 *q++=GetRedPixelComponent(p);
2341 *q++=GetGreenPixelComponent(p);
2342 *q++=GetBluePixelComponent(p);
2343 *q++=(Quantum) (GetAlphaPixelComponent(p));
2348 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2350 p=GetAuthenticPixelQueue(image);
2351 if (p == (const PixelPacket *) NULL)
2353 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2355 *q++=GetRedPixelComponent(p);
2356 *q++=GetGreenPixelComponent(p);
2357 *q++=GetBluePixelComponent(p);
2363 p=GetAuthenticPixelQueue(image);
2364 if (p == (const PixelPacket *) NULL)
2366 indexes=GetAuthenticIndexQueue(image);
2367 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2369 for (i=0; i < (ssize_t) length; i++)
2372 switch (quantum_map[i])
2377 *q=GetRedPixelComponent(p);
2381 case MagentaQuantum:
2383 *q=GetGreenPixelComponent(p);
2389 *q=GetBluePixelComponent(p);
2394 *q=(Quantum) (GetAlphaPixelComponent(p));
2397 case OpacityQuantum:
2399 *q=GetOpacityPixelComponent(p);
2404 if (image->colorspace == CMYKColorspace)
2410 *q=(PixelIntensityToQuantum(p));
2424 register unsigned short
2427 q=(unsigned short *) stream_info->pixels;
2428 if (LocaleCompare(stream_info->map,"BGR") == 0)
2430 p=GetAuthenticPixelQueue(image);
2431 if (p == (const PixelPacket *) NULL)
2433 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2435 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2436 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2437 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2442 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2444 p=GetAuthenticPixelQueue(image);
2445 if (p == (const PixelPacket *) NULL)
2447 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2449 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2450 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2451 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2452 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2457 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2459 p=GetAuthenticPixelQueue(image);
2460 if (p == (const PixelPacket *) NULL)
2462 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2464 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2465 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2466 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2472 if (LocaleCompare(stream_info->map,"I") == 0)
2474 p=GetAuthenticPixelQueue(image);
2475 if (p == (const PixelPacket *) NULL)
2477 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2479 *q++=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2484 if (LocaleCompare(stream_info->map,"RGB") == 0)
2486 p=GetAuthenticPixelQueue(image);
2487 if (p == (const PixelPacket *) NULL)
2489 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2491 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2492 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2493 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2498 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2500 p=GetAuthenticPixelQueue(image);
2501 if (p == (const PixelPacket *) NULL)
2503 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2505 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2506 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2507 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2508 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2513 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2515 p=GetAuthenticPixelQueue(image);
2516 if (p == (const PixelPacket *) NULL)
2518 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2520 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2521 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2522 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2528 p=GetAuthenticPixelQueue(image);
2529 if (p == (const PixelPacket *) NULL)
2531 indexes=GetAuthenticIndexQueue(image);
2532 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2534 for (i=0; i < (ssize_t) length; i++)
2537 switch (quantum_map[i])
2542 *q=ScaleQuantumToShort(GetRedPixelComponent(p));
2546 case MagentaQuantum:
2548 *q=ScaleQuantumToShort(GetGreenPixelComponent(p));
2554 *q=ScaleQuantumToShort(GetBluePixelComponent(p));
2559 *q=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2562 case OpacityQuantum:
2564 *q=ScaleQuantumToShort(GetOpacityPixelComponent(p));
2569 if (image->colorspace == CMYKColorspace)
2570 *q=ScaleQuantumToShort(indexes[x]);
2575 *q=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2589 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2590 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2591 "UnrecognizedPixelMap","`%s'",stream_info->map);
2595 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2604 + 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 %
2608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2610 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2611 % the latest stream of pixels.
2613 % The format of the SyncAuthenticPixelsStream method is:
2615 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2616 % ExceptionInfo *exception)
2618 % A description of each parameter follows:
2620 % o image: the image.
2622 % o exception: return any errors or warnings in this structure.
2625 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2626 ExceptionInfo *exception)
2637 assert(image != (Image *) NULL);
2638 assert(image->signature == MagickSignature);
2639 if (image->debug != MagickFalse)
2640 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2641 cache_info=(CacheInfo *) image->cache;
2642 assert(cache_info->signature == MagickSignature);
2643 stream_handler=GetBlobStreamHandler(image);
2644 if (stream_handler == (StreamHandler) NULL)
2646 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2647 "NoStreamHandlerIsDefined","`%s'",image->filename);
2648 return(MagickFalse);
2650 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2651 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659 % W r i t e S t r e a m %
2663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2665 % WriteStream() makes the image pixels available to a user supplied callback
2666 % method immediately upon writing pixel data with the WriteImage() method.
2668 % The format of the WriteStream() method is:
2670 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2671 % StreamHandler stream)
2673 % A description of each parameter follows:
2675 % o image_info: the image info.
2677 % o stream: A callback method.
2680 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2681 Image *image,StreamHandler stream)
2689 assert(image_info != (ImageInfo *) NULL);
2690 assert(image_info->signature == MagickSignature);
2691 if (image_info->debug != MagickFalse)
2692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2693 image_info->filename);
2694 assert(image != (Image *) NULL);
2695 assert(image->signature == MagickSignature);
2696 write_info=CloneImageInfo(image_info);
2697 write_info->stream=stream;
2698 status=WriteImage(write_info,image);
2699 write_info=DestroyImageInfo(write_info);