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 long,
114 const long,const unsigned long,const unsigned long,ExceptionInfo *);
116 static MagickBooleanType
117 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
118 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
121 *QueueAuthenticPixelsStream(Image *,const long,const long,const unsigned long,
122 const unsigned long,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 long x,
340 % const long y,const unsigned long columns,const unsigned long 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 long x,
354 const long y,const unsigned long columns,const unsigned long 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 long x,const long 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 long x,const long 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 long x,
469 % const long 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 long x,const long 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 long x,
627 % const long y,const unsigned long columns,const unsigned long 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 long x,
669 const long y,const unsigned long columns,const unsigned long 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) || ((x+(long) columns) > (long) image->columns) ||
692 ((y+(long) rows) > (long) image->rows) || (columns == 0) || (rows == 0))
694 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
695 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
696 return((PixelPacket *) NULL);
698 cache_info=(CacheInfo *) image->cache;
699 assert(cache_info->signature == MagickSignature);
701 Pixels are stored in a temporary buffer until they are synced to the cache.
703 number_pixels=(MagickSizeType) columns*rows;
704 length=(size_t) number_pixels*sizeof(PixelPacket);
705 if ((image->storage_class == PseudoClass) ||
706 (image->colorspace == CMYKColorspace))
707 length+=number_pixels*sizeof(IndexPacket);
708 if (cache_info->pixels == (PixelPacket *) NULL)
710 cache_info->length=length;
711 status=AcquireStreamPixels(cache_info,exception);
712 if (status == MagickFalse)
713 return((PixelPacket *) NULL);
716 if (cache_info->length != length)
718 RelinquishStreamPixels(cache_info);
719 cache_info->length=length;
720 status=AcquireStreamPixels(cache_info,exception);
721 if (status == MagickFalse)
722 return((PixelPacket *) NULL);
724 cache_info->indexes=(IndexPacket *) NULL;
725 if ((image->storage_class == PseudoClass) ||
726 (image->colorspace == CMYKColorspace))
727 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
728 return(cache_info->pixels);
732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
736 + O p e n S t r e a m %
740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 % OpenStream() opens a stream for writing by the StreamImage() method.
744 % The format of the OpenStream method is:
746 % MagickBooleanType OpenStream(const ImageInfo *image_info,
747 % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
749 % A description of each parameter follows:
751 % o image_info: the image info.
753 % o stream_info: the stream info.
755 % o filename: the stream filename.
757 % o exception: return any errors or warnings in this structure.
760 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
761 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
766 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
767 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776 + 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 %
780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 % QueueAuthenticPixelsStream() allocates an area to store image pixels as
783 % defined by the region rectangle and returns a pointer to the area. This
784 % area is subsequently transferred from the pixel cache with method
785 % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
786 % pixels are transferred, otherwise a NULL is returned.
788 % The format of the QueueAuthenticPixelsStream() method is:
790 % PixelPacket *QueueAuthenticPixelsStream(Image *image,const long x,
791 % const long y,const unsigned long columns,const unsigned long rows,
792 % ExceptionInfo *exception)
794 % A description of each parameter follows:
796 % o image: the image.
798 % o x,y,columns,rows: These values define the perimeter of a region of
802 static PixelPacket *QueueAuthenticPixelsStream(Image *image,const long x,
803 const long y,const unsigned long columns,const unsigned long rows,
804 ExceptionInfo *exception)
819 Validate pixel cache geometry.
821 assert(image != (Image *) NULL);
822 if ((x < 0) || (y < 0) || ((x+(long) columns) > (long) image->columns) ||
823 ((y+(long) rows) > (long) image->rows) || (columns == 0) || (rows == 0))
825 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
826 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
827 return((PixelPacket *) NULL);
829 stream_handler=GetBlobStreamHandler(image);
830 if (stream_handler == (StreamHandler) NULL)
832 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
833 "NoStreamHandlerIsDefined","`%s'",image->filename);
834 return((PixelPacket *) NULL);
836 cache_info=(CacheInfo *) image->cache;
837 assert(cache_info->signature == MagickSignature);
838 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
839 (image->colorspace != GetPixelCacheColorspace(image->cache)))
841 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
842 (void) stream_handler(image,(const void *) NULL,(size_t)
843 cache_info->columns);
844 cache_info->storage_class=image->storage_class;
845 cache_info->colorspace=image->colorspace;
846 cache_info->columns=image->columns;
847 cache_info->rows=image->rows;
848 image->cache=cache_info;
851 Pixels are stored in a temporary buffer until they are synced to the cache.
853 cache_info->columns=columns;
854 cache_info->rows=rows;
855 number_pixels=(MagickSizeType) columns*rows;
856 length=(size_t) number_pixels*sizeof(PixelPacket);
857 if ((image->storage_class == PseudoClass) ||
858 (image->colorspace == CMYKColorspace))
859 length+=number_pixels*sizeof(IndexPacket);
860 if (cache_info->pixels == (PixelPacket *) NULL)
862 cache_info->pixels=(PixelPacket *) AcquireMagickMemory(length);
863 cache_info->length=(MagickSizeType) length;
866 if (cache_info->length < (MagickSizeType) length)
868 cache_info->pixels=(PixelPacket *) ResizeMagickMemory(
869 cache_info->pixels,length);
870 cache_info->length=(MagickSizeType) length;
872 if (cache_info->pixels == (void *) NULL)
873 return((PixelPacket *) NULL);
874 cache_info->indexes=(IndexPacket *) NULL;
875 if ((image->storage_class == PseudoClass) ||
876 (image->colorspace == CMYKColorspace))
877 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
878 return(cache_info->pixels);
882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
886 % R e a d S t r e a m %
890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
892 % ReadStream() makes the image pixels available to a user supplied callback
893 % method immediately upon reading a scanline with the ReadImage() method.
895 % The format of the ReadStream() method is:
897 % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
898 % ExceptionInfo *exception)
900 % A description of each parameter follows:
902 % o image_info: the image info.
904 % o stream: a callback method.
906 % o exception: return any errors or warnings in this structure.
909 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
910 ExceptionInfo *exception)
924 assert(image_info != (ImageInfo *) NULL);
925 assert(image_info->signature == MagickSignature);
926 if (image_info->debug != MagickFalse)
927 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
928 image_info->filename);
929 assert(exception != (ExceptionInfo *) NULL);
930 assert(exception->signature == MagickSignature);
931 read_info=CloneImageInfo(image_info);
932 read_info->cache=AcquirePixelCache(0);
933 GetPixelCacheMethods(&cache_methods);
934 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
935 cache_methods.get_virtual_indexes_from_handler=GetVirtualIndexesFromStream;
936 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
937 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
938 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
939 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
940 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
941 cache_methods.get_authentic_indexes_from_handler=
942 GetAuthenticIndexesFromStream;
943 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
944 cache_methods.get_one_authentic_pixel_from_handler=
945 GetOneAuthenticPixelFromStream;
946 cache_methods.destroy_pixel_handler=DestroyPixelStream;
947 SetPixelCacheMethods(read_info->cache,&cache_methods);
948 read_info->stream=stream;
949 image=ReadImage(read_info,exception);
950 read_info=DestroyImageInfo(read_info);
955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959 + S e t S t r e a m I n f o C l i e n t D a t a %
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 % SetStreamInfoClientData() sets the stream info client data.
967 % The format of the SetStreamInfoClientData method is:
969 % void SetStreamInfoClientData(StreamInfo *stream_info,
970 % const void *client_data)
972 % A description of each parameter follows:
974 % o stream_info: the stream info.
976 % o client_data: the client data.
979 MagickExport void SetStreamInfoClientData(StreamInfo *stream_info,
980 const void *client_data)
982 assert(stream_info != (StreamInfo *) NULL);
983 assert(stream_info->signature == MagickSignature);
984 stream_info->client_data=client_data;
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 + S e t S t r e a m I n f o M a p %
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
998 % SetStreamInfoMap() sets the stream info map member.
1000 % The format of the SetStreamInfoMap method is:
1002 % void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1004 % A description of each parameter follows:
1006 % o stream_info: the stream info.
1011 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1013 assert(stream_info != (StreamInfo *) NULL);
1014 assert(stream_info->signature == MagickSignature);
1015 (void) CloneString(&stream_info->map,map);
1019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1023 + S e t S t r e a m I n f o S t o r a g e T y p e %
1027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1029 % SetStreamInfoStorageType() sets the stream info storage type member.
1031 % The format of the SetStreamInfoStorageType method is:
1033 % void SetStreamInfoStorageType(StreamInfo *stream_info,
1034 % const StoreageType *storage_type)
1036 % A description of each parameter follows:
1038 % o stream_info: the stream info.
1040 % o storage_type: the storage type.
1043 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1044 const StorageType storage_type)
1046 assert(stream_info != (StreamInfo *) NULL);
1047 assert(stream_info->signature == MagickSignature);
1048 stream_info->storage_type=storage_type;
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056 + S t r e a m I m a g e %
1060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1062 % StreamImage() streams pixels from an image and writes them in a user
1063 % defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1065 % The format of he wStreamImage() method is:
1067 % Image *StreamImage(const ImageInfo *image_info,
1068 % StreamInfo *stream_info,ExceptionInfo *exception)
1070 % A description of each parameter follows:
1072 % o image_info: the image info.
1074 % o stream_info: the stream info.
1076 % o exception: return any errors or warnings in this structure.
1080 #if defined(__cplusplus) || defined(c_plusplus)
1084 static size_t WriteStreamImage(const Image *image,const void *pixels,
1085 const size_t columns)
1100 stream_info=(StreamInfo *) image->client_data;
1101 switch (stream_info->storage_type)
1103 default: packet_size=sizeof(char); break;
1104 case CharPixel: packet_size=sizeof(char); break;
1105 case DoublePixel: packet_size=sizeof(double); break;
1106 case FloatPixel: packet_size=sizeof(float); break;
1107 case IntegerPixel: packet_size=sizeof(int); break;
1108 case LongPixel: packet_size=sizeof(long); break;
1109 case QuantumPixel: packet_size=sizeof(Quantum); break;
1110 case ShortPixel: packet_size=sizeof(unsigned short); break;
1112 packet_size*=strlen(stream_info->map);
1113 length=packet_size*image->columns;
1114 if (image != stream_info->image)
1120 Prepare stream for writing.
1122 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1123 stream_info->pixels,length,sizeof(*stream_info->pixels));
1124 if (pixels == (unsigned char *) NULL)
1126 stream_info->image=image;
1127 write_info=CloneImageInfo(stream_info->image_info);
1128 (void) SetImageInfo(write_info,MagickFalse,stream_info->exception);
1129 if (write_info->extract != (char *) NULL)
1130 (void) ParseAbsoluteGeometry(write_info->extract,
1131 &stream_info->extract_info);
1133 write_info=DestroyImageInfo(write_info);
1135 extract_info=stream_info->extract_info;
1136 if ((extract_info.width == 0) ||
1137 (extract_info.height == 0))
1140 Write all pixels to stream.
1142 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1143 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1145 return(count == 0 ? 0 : columns);
1147 if ((stream_info->y < extract_info.y) ||
1148 (stream_info->y >= (long) (extract_info.y+extract_info.height)))
1154 Write a portion of the pixel row to the stream.
1156 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1157 length=packet_size*extract_info.width;
1158 count=WriteBlob(stream_info->stream,length,stream_info->pixels+
1159 packet_size*extract_info.x);
1161 return(count == 0 ? 0 : columns);
1164 #if defined(__cplusplus) || defined(c_plusplus)
1168 MagickExport Image *StreamImage(const ImageInfo *image_info,
1169 StreamInfo *stream_info,ExceptionInfo *exception)
1177 assert(image_info != (const ImageInfo *) NULL);
1178 assert(image_info->signature == MagickSignature);
1179 if (image_info->debug != MagickFalse)
1180 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1181 image_info->filename);
1182 assert(stream_info != (StreamInfo *) NULL);
1183 assert(stream_info->signature == MagickSignature);
1184 assert(exception != (ExceptionInfo *) NULL);
1185 read_info=CloneImageInfo(image_info);
1186 stream_info->image_info=image_info;
1187 stream_info->exception=exception;
1188 read_info->client_data=(void *) stream_info;
1189 image=ReadStream(read_info,&WriteStreamImage,exception);
1190 read_info=DestroyImageInfo(read_info);
1191 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1192 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1193 image=DestroyImage(image);
1198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1202 + S t r e a m I m a g e P i x e l s %
1206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1208 % StreamImagePixels() extracts pixel data from an image and returns it in the
1209 % stream_info->pixels structure in the format as defined by
1210 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1212 % The format of the StreamImagePixels method is:
1214 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1215 % const Image *image,ExceptionInfo *exception)
1217 % A description of each parameter follows:
1219 % o stream_info: the stream info.
1221 % o image: the image.
1223 % o exception: return any errors or warnings in this structure.
1226 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1227 const Image *image,ExceptionInfo *exception)
1239 register const PixelPacket
1242 register IndexPacket
1248 assert(stream_info != (StreamInfo *) NULL);
1249 assert(stream_info->signature == MagickSignature);
1250 assert(image != (Image *) NULL);
1251 assert(image->signature == MagickSignature);
1252 if (image->debug != MagickFalse)
1253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1254 length=strlen(stream_info->map);
1255 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1256 if (quantum_map == (QuantumType *) NULL)
1258 (void) ThrowMagickException(exception,GetMagickModule(),
1259 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1260 return(MagickFalse);
1262 for (i=0; i < (long) length; i++)
1264 switch (stream_info->map[i])
1269 quantum_map[i]=AlphaQuantum;
1275 quantum_map[i]=BlueQuantum;
1281 quantum_map[i]=CyanQuantum;
1282 if (image->colorspace == CMYKColorspace)
1284 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1285 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1286 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1287 return(MagickFalse);
1292 quantum_map[i]=GreenQuantum;
1298 quantum_map[i]=IndexQuantum;
1304 quantum_map[i]=BlackQuantum;
1305 if (image->colorspace == CMYKColorspace)
1307 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1308 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1309 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1310 return(MagickFalse);
1315 quantum_map[i]=MagentaQuantum;
1316 if (image->colorspace == CMYKColorspace)
1318 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1319 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1320 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1321 return(MagickFalse);
1326 quantum_map[i]=OpacityQuantum;
1332 quantum_map[i]=UndefinedQuantum;
1338 quantum_map[i]=RedQuantum;
1344 quantum_map[i]=YellowQuantum;
1345 if (image->colorspace == CMYKColorspace)
1347 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1348 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1349 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1350 return(MagickFalse);
1354 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1355 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1356 "UnrecognizedPixelMap","`%s'",stream_info->map);
1357 return(MagickFalse);
1361 quantum_info=stream_info->quantum_info;
1362 switch (stream_info->storage_type)
1366 register unsigned char
1369 q=(unsigned char *) stream_info->pixels;
1370 if (LocaleCompare(stream_info->map,"BGR") == 0)
1372 p=GetAuthenticPixelQueue(image);
1373 if (p == (const PixelPacket *) NULL)
1375 for (x=0; x < (long) GetImageExtent(image); x++)
1377 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1378 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1379 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1384 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1386 p=GetAuthenticPixelQueue(image);
1387 if (p == (const PixelPacket *) NULL)
1389 for (x=0; x < (long) GetImageExtent(image); x++)
1391 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1392 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1393 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1394 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1399 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1401 p=GetAuthenticPixelQueue(image);
1402 if (p == (const PixelPacket *) NULL)
1404 for (x=0; x < (long) GetImageExtent(image); x++)
1406 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1407 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1408 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1409 *q++=ScaleQuantumToChar((Quantum) 0);
1414 if (LocaleCompare(stream_info->map,"I") == 0)
1416 p=GetAuthenticPixelQueue(image);
1417 if (p == (const PixelPacket *) NULL)
1419 for (x=0; x < (long) GetImageExtent(image); x++)
1421 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1426 if (LocaleCompare(stream_info->map,"RGB") == 0)
1428 p=GetAuthenticPixelQueue(image);
1429 if (p == (const PixelPacket *) NULL)
1431 for (x=0; x < (long) GetImageExtent(image); x++)
1433 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1434 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1435 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1440 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1442 p=GetAuthenticPixelQueue(image);
1443 if (p == (const PixelPacket *) NULL)
1445 for (x=0; x < (long) GetImageExtent(image); x++)
1447 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1448 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1449 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1450 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1455 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1457 p=GetAuthenticPixelQueue(image);
1458 if (p == (const PixelPacket *) NULL)
1460 for (x=0; x < (long) GetImageExtent(image); x++)
1462 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1463 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1464 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1465 *q++=ScaleQuantumToChar((Quantum) 0);
1470 p=GetAuthenticPixelQueue(image);
1471 if (p == (const PixelPacket *) NULL)
1473 indexes=GetAuthenticIndexQueue(image);
1474 for (x=0; x < (long) GetImageExtent(image); x++)
1476 for (i=0; i < (long) length; i++)
1479 switch (quantum_map[i])
1484 *q=ScaleQuantumToChar(GetRedPixelComponent(p));
1488 case MagentaQuantum:
1490 *q=ScaleQuantumToChar(GetGreenPixelComponent(p));
1496 *q=ScaleQuantumToChar(GetBluePixelComponent(p));
1501 *q=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1504 case OpacityQuantum:
1506 *q=ScaleQuantumToChar(GetOpacityPixelComponent(p));
1511 if (image->colorspace == CMYKColorspace)
1512 *q=ScaleQuantumToChar(indexes[x]);
1517 *q=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1534 q=(double *) stream_info->pixels;
1535 if (LocaleCompare(stream_info->map,"BGR") == 0)
1537 p=GetAuthenticPixelQueue(image);
1538 if (p == (const PixelPacket *) NULL)
1540 for (x=0; x < (long) GetImageExtent(image); x++)
1542 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1543 quantum_info->scale+quantum_info->minimum);
1544 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1545 quantum_info->scale+quantum_info->minimum);
1546 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1547 quantum_info->scale+quantum_info->minimum);
1552 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1554 p=GetAuthenticPixelQueue(image);
1555 if (p == (const PixelPacket *) NULL)
1557 for (x=0; x < (long) GetImageExtent(image); x++)
1559 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1560 quantum_info->scale+quantum_info->minimum);
1561 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1562 quantum_info->scale+quantum_info->minimum);
1563 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1564 quantum_info->scale+quantum_info->minimum);
1565 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1566 quantum_info->scale+quantum_info->minimum);
1571 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1573 p=GetAuthenticPixelQueue(image);
1574 if (p == (const PixelPacket *) NULL)
1576 for (x=0; x < (long) GetImageExtent(image); x++)
1578 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1579 quantum_info->scale+quantum_info->minimum);
1580 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1581 quantum_info->scale+quantum_info->minimum);
1582 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1583 quantum_info->scale+quantum_info->minimum);
1589 if (LocaleCompare(stream_info->map,"I") == 0)
1591 p=GetAuthenticPixelQueue(image);
1592 if (p == (const PixelPacket *) NULL)
1594 for (x=0; x < (long) GetImageExtent(image); x++)
1596 *q++=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1597 quantum_info->scale+quantum_info->minimum);
1602 if (LocaleCompare(stream_info->map,"RGB") == 0)
1604 p=GetAuthenticPixelQueue(image);
1605 if (p == (const PixelPacket *) NULL)
1607 for (x=0; x < (long) GetImageExtent(image); x++)
1609 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1610 quantum_info->scale+quantum_info->minimum);
1611 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1612 quantum_info->scale+quantum_info->minimum);
1613 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1614 quantum_info->scale+quantum_info->minimum);
1619 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1621 p=GetAuthenticPixelQueue(image);
1622 if (p == (const PixelPacket *) NULL)
1624 for (x=0; x < (long) GetImageExtent(image); x++)
1626 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1627 quantum_info->scale+quantum_info->minimum);
1628 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1629 quantum_info->scale+quantum_info->minimum);
1630 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1631 quantum_info->scale+quantum_info->minimum);
1632 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1633 quantum_info->scale+quantum_info->minimum);
1638 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1640 p=GetAuthenticPixelQueue(image);
1641 if (p == (const PixelPacket *) NULL)
1643 for (x=0; x < (long) GetImageExtent(image); x++)
1645 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1646 quantum_info->scale+quantum_info->minimum);
1647 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1648 quantum_info->scale+quantum_info->minimum);
1649 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1650 quantum_info->scale+quantum_info->minimum);
1656 p=GetAuthenticPixelQueue(image);
1657 if (p == (const PixelPacket *) NULL)
1659 indexes=GetAuthenticIndexQueue(image);
1660 for (x=0; x < (long) GetImageExtent(image); x++)
1662 for (i=0; i < (long) length; i++)
1665 switch (quantum_map[i])
1670 *q=(double) ((QuantumScale*GetRedPixelComponent(p))*
1671 quantum_info->scale+quantum_info->minimum);
1675 case MagentaQuantum:
1677 *q=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1678 quantum_info->scale+quantum_info->minimum);
1684 *q=(double) ((QuantumScale*GetBluePixelComponent(p))*
1685 quantum_info->scale+quantum_info->minimum);
1690 *q=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1691 quantum_info->scale+quantum_info->minimum);
1694 case OpacityQuantum:
1696 *q=(double) ((QuantumScale*GetOpacityPixelComponent(p))*
1697 quantum_info->scale+quantum_info->minimum);
1702 if (image->colorspace == CMYKColorspace)
1703 *q=(double) ((QuantumScale*indexes[x])*quantum_info->scale+
1704 quantum_info->minimum);
1709 *q=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1710 quantum_info->scale+quantum_info->minimum);
1727 q=(float *) stream_info->pixels;
1728 if (LocaleCompare(stream_info->map,"BGR") == 0)
1730 p=GetAuthenticPixelQueue(image);
1731 if (p == (const PixelPacket *) NULL)
1733 for (x=0; x < (long) GetImageExtent(image); x++)
1735 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1736 quantum_info->scale+quantum_info->minimum);
1737 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1738 quantum_info->scale+quantum_info->minimum);
1739 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1740 quantum_info->scale+quantum_info->minimum);
1745 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1747 p=GetAuthenticPixelQueue(image);
1748 if (p == (const PixelPacket *) NULL)
1750 for (x=0; x < (long) GetImageExtent(image); x++)
1752 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1753 quantum_info->scale+quantum_info->minimum);
1754 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1755 quantum_info->scale+quantum_info->minimum);
1756 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1757 quantum_info->scale+quantum_info->minimum);
1758 *q++=(float) ((QuantumScale*(Quantum) (GetAlphaPixelComponent(p)))*
1759 quantum_info->scale+quantum_info->minimum);
1764 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1766 p=GetAuthenticPixelQueue(image);
1767 if (p == (const PixelPacket *) NULL)
1769 for (x=0; x < (long) GetImageExtent(image); x++)
1771 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1772 quantum_info->scale+quantum_info->minimum);
1773 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1774 quantum_info->scale+quantum_info->minimum);
1775 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1776 quantum_info->scale+quantum_info->minimum);
1782 if (LocaleCompare(stream_info->map,"I") == 0)
1784 p=GetAuthenticPixelQueue(image);
1785 if (p == (const PixelPacket *) NULL)
1787 for (x=0; x < (long) GetImageExtent(image); x++)
1789 *q++=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1790 quantum_info->scale+quantum_info->minimum);
1795 if (LocaleCompare(stream_info->map,"RGB") == 0)
1797 p=GetAuthenticPixelQueue(image);
1798 if (p == (const PixelPacket *) NULL)
1800 for (x=0; x < (long) GetImageExtent(image); x++)
1802 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1803 quantum_info->scale+quantum_info->minimum);
1804 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1805 quantum_info->scale+quantum_info->minimum);
1806 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1807 quantum_info->scale+quantum_info->minimum);
1812 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1814 p=GetAuthenticPixelQueue(image);
1815 if (p == (const PixelPacket *) NULL)
1817 for (x=0; x < (long) GetImageExtent(image); x++)
1819 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1820 quantum_info->scale+quantum_info->minimum);
1821 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1822 quantum_info->scale+quantum_info->minimum);
1823 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1824 quantum_info->scale+quantum_info->minimum);
1825 *q++=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1826 quantum_info->scale+quantum_info->minimum);
1831 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1833 p=GetAuthenticPixelQueue(image);
1834 if (p == (const PixelPacket *) NULL)
1836 for (x=0; x < (long) GetImageExtent(image); x++)
1838 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1839 quantum_info->scale+quantum_info->minimum);
1840 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1841 quantum_info->scale+quantum_info->minimum);
1842 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1843 quantum_info->scale+quantum_info->minimum);
1849 p=GetAuthenticPixelQueue(image);
1850 if (p == (const PixelPacket *) NULL)
1852 indexes=GetAuthenticIndexQueue(image);
1853 for (x=0; x < (long) GetImageExtent(image); x++)
1855 for (i=0; i < (long) length; i++)
1858 switch (quantum_map[i])
1863 *q=(float) ((QuantumScale*GetRedPixelComponent(p))*
1864 quantum_info->scale+quantum_info->minimum);
1868 case MagentaQuantum:
1870 *q=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1871 quantum_info->scale+quantum_info->minimum);
1877 *q=(float) ((QuantumScale*GetBluePixelComponent(p))*
1878 quantum_info->scale+quantum_info->minimum);
1883 *q=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1884 quantum_info->scale+quantum_info->minimum);
1887 case OpacityQuantum:
1889 *q=(float) ((QuantumScale*GetOpacityPixelComponent(p))*
1890 quantum_info->scale+quantum_info->minimum);
1895 if (image->colorspace == CMYKColorspace)
1896 *q=(float) ((QuantumScale*indexes[x])*quantum_info->scale+
1897 quantum_info->minimum);
1902 *q=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1903 quantum_info->scale+quantum_info->minimum);
1917 register unsigned int
1920 q=(unsigned int *) stream_info->pixels;
1921 if (LocaleCompare(stream_info->map,"BGR") == 0)
1923 p=GetAuthenticPixelQueue(image);
1924 if (p == (const PixelPacket *) NULL)
1926 for (x=0; x < (long) GetImageExtent(image); x++)
1928 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1929 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1930 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1935 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1937 p=GetAuthenticPixelQueue(image);
1938 if (p == (const PixelPacket *) NULL)
1940 for (x=0; x < (long) GetImageExtent(image); x++)
1942 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1943 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1944 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1945 *q++=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
1946 GetOpacityPixelComponent(p)));
1951 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1953 p=GetAuthenticPixelQueue(image);
1954 if (p == (const PixelPacket *) NULL)
1956 for (x=0; x < (long) GetImageExtent(image); x++)
1958 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1959 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1960 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1966 if (LocaleCompare(stream_info->map,"I") == 0)
1968 p=GetAuthenticPixelQueue(image);
1969 if (p == (const PixelPacket *) NULL)
1971 for (x=0; x < (long) GetImageExtent(image); x++)
1973 *q++=(unsigned int) ScaleQuantumToLong(
1974 PixelIntensityToQuantum(p));
1979 if (LocaleCompare(stream_info->map,"RGB") == 0)
1981 p=GetAuthenticPixelQueue(image);
1982 if (p == (const PixelPacket *) NULL)
1984 for (x=0; x < (long) GetImageExtent(image); x++)
1986 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1987 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1988 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1993 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1995 p=GetAuthenticPixelQueue(image);
1996 if (p == (const PixelPacket *) NULL)
1998 for (x=0; x < (long) GetImageExtent(image); x++)
2000 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2001 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2002 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2003 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2004 (GetAlphaPixelComponent(p)));
2009 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2011 p=GetAuthenticPixelQueue(image);
2012 if (p == (const PixelPacket *) NULL)
2014 for (x=0; x < (long) GetImageExtent(image); x++)
2016 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2017 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2018 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2024 p=GetAuthenticPixelQueue(image);
2025 if (p == (const PixelPacket *) NULL)
2027 indexes=GetAuthenticIndexQueue(image);
2028 for (x=0; x < (long) GetImageExtent(image); x++)
2030 for (i=0; i < (long) length; i++)
2033 switch (quantum_map[i])
2038 *q=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2042 case MagentaQuantum:
2044 *q=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2050 *q=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2055 *q=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
2056 GetOpacityPixelComponent(p)));
2059 case OpacityQuantum:
2061 *q=(unsigned int) ScaleQuantumToLong(GetOpacityPixelComponent(p));
2066 if (image->colorspace == CMYKColorspace)
2067 *q=(unsigned int) ScaleQuantumToLong(indexes[x]);
2073 ScaleQuantumToLong(PixelIntensityToQuantum(p));
2087 register unsigned long
2090 q=(unsigned long *) stream_info->pixels;
2091 if (LocaleCompare(stream_info->map,"BGR") == 0)
2093 p=GetAuthenticPixelQueue(image);
2094 if (p == (const PixelPacket *) NULL)
2096 for (x=0; x < (long) GetImageExtent(image); x++)
2098 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2099 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2100 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2105 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2107 p=GetAuthenticPixelQueue(image);
2108 if (p == (const PixelPacket *) NULL)
2110 for (x=0; x < (long) GetImageExtent(image); x++)
2112 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2113 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2114 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2115 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2120 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2122 p=GetAuthenticPixelQueue(image);
2123 if (p == (const PixelPacket *) NULL)
2125 for (x=0; x < (long) GetImageExtent(image); x++)
2127 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2128 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2129 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2135 if (LocaleCompare(stream_info->map,"I") == 0)
2137 p=GetAuthenticPixelQueue(image);
2138 if (p == (const PixelPacket *) NULL)
2140 for (x=0; x < (long) GetImageExtent(image); x++)
2142 *q++=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2147 if (LocaleCompare(stream_info->map,"RGB") == 0)
2149 p=GetAuthenticPixelQueue(image);
2150 if (p == (const PixelPacket *) NULL)
2152 for (x=0; x < (long) GetImageExtent(image); x++)
2154 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2155 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2156 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2161 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2163 p=GetAuthenticPixelQueue(image);
2164 if (p == (const PixelPacket *) NULL)
2166 for (x=0; x < (long) GetImageExtent(image); x++)
2168 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2169 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2170 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2171 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2176 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2178 p=GetAuthenticPixelQueue(image);
2179 if (p == (const PixelPacket *) NULL)
2181 for (x=0; x < (long) GetImageExtent(image); x++)
2183 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2184 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2185 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2191 p=GetAuthenticPixelQueue(image);
2192 if (p == (const PixelPacket *) NULL)
2194 indexes=GetAuthenticIndexQueue(image);
2195 for (x=0; x < (long) GetImageExtent(image); x++)
2197 for (i=0; i < (long) length; i++)
2200 switch (quantum_map[i])
2205 *q=ScaleQuantumToLong(GetRedPixelComponent(p));
2209 case MagentaQuantum:
2211 *q=ScaleQuantumToLong(GetGreenPixelComponent(p));
2217 *q=ScaleQuantumToLong(GetBluePixelComponent(p));
2222 *q=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2225 case OpacityQuantum:
2227 *q=ScaleQuantumToLong(GetOpacityPixelComponent(p));
2232 if (image->colorspace == CMYKColorspace)
2233 *q=ScaleQuantumToLong(indexes[x]);
2238 *q=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2255 q=(Quantum *) stream_info->pixels;
2256 if (LocaleCompare(stream_info->map,"BGR") == 0)
2258 p=GetAuthenticPixelQueue(image);
2259 if (p == (const PixelPacket *) NULL)
2261 for (x=0; x < (long) GetImageExtent(image); x++)
2263 *q++=GetBluePixelComponent(p);
2264 *q++=GetGreenPixelComponent(p);
2265 *q++=GetRedPixelComponent(p);
2270 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2272 p=GetAuthenticPixelQueue(image);
2273 if (p == (const PixelPacket *) NULL)
2275 for (x=0; x < (long) GetImageExtent(image); x++)
2277 *q++=GetBluePixelComponent(p);
2278 *q++=GetGreenPixelComponent(p);
2279 *q++=GetRedPixelComponent(p);
2280 *q++=(Quantum) (GetAlphaPixelComponent(p));
2285 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2287 p=GetAuthenticPixelQueue(image);
2288 if (p == (const PixelPacket *) NULL)
2290 for (x=0; x < (long) GetImageExtent(image); x++)
2292 *q++=GetBluePixelComponent(p);
2293 *q++=GetGreenPixelComponent(p);
2294 *q++=GetRedPixelComponent(p);
2300 if (LocaleCompare(stream_info->map,"I") == 0)
2302 p=GetAuthenticPixelQueue(image);
2303 if (p == (const PixelPacket *) NULL)
2305 for (x=0; x < (long) GetImageExtent(image); x++)
2307 *q++=PixelIntensityToQuantum(p);
2312 if (LocaleCompare(stream_info->map,"RGB") == 0)
2314 p=GetAuthenticPixelQueue(image);
2315 if (p == (const PixelPacket *) NULL)
2317 for (x=0; x < (long) GetImageExtent(image); x++)
2319 *q++=GetRedPixelComponent(p);
2320 *q++=GetGreenPixelComponent(p);
2321 *q++=GetBluePixelComponent(p);
2326 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2328 p=GetAuthenticPixelQueue(image);
2329 if (p == (const PixelPacket *) NULL)
2331 for (x=0; x < (long) GetImageExtent(image); x++)
2333 *q++=GetRedPixelComponent(p);
2334 *q++=GetGreenPixelComponent(p);
2335 *q++=GetBluePixelComponent(p);
2336 *q++=(Quantum) (GetAlphaPixelComponent(p));
2341 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2343 p=GetAuthenticPixelQueue(image);
2344 if (p == (const PixelPacket *) NULL)
2346 for (x=0; x < (long) GetImageExtent(image); x++)
2348 *q++=GetRedPixelComponent(p);
2349 *q++=GetGreenPixelComponent(p);
2350 *q++=GetBluePixelComponent(p);
2356 p=GetAuthenticPixelQueue(image);
2357 if (p == (const PixelPacket *) NULL)
2359 indexes=GetAuthenticIndexQueue(image);
2360 for (x=0; x < (long) GetImageExtent(image); x++)
2362 for (i=0; i < (long) length; i++)
2365 switch (quantum_map[i])
2370 *q=GetRedPixelComponent(p);
2374 case MagentaQuantum:
2376 *q=GetGreenPixelComponent(p);
2382 *q=GetBluePixelComponent(p);
2387 *q=(Quantum) (GetAlphaPixelComponent(p));
2390 case OpacityQuantum:
2392 *q=GetOpacityPixelComponent(p);
2397 if (image->colorspace == CMYKColorspace)
2403 *q=(PixelIntensityToQuantum(p));
2417 register unsigned short
2420 q=(unsigned short *) stream_info->pixels;
2421 if (LocaleCompare(stream_info->map,"BGR") == 0)
2423 p=GetAuthenticPixelQueue(image);
2424 if (p == (const PixelPacket *) NULL)
2426 for (x=0; x < (long) GetImageExtent(image); x++)
2428 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2429 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2430 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2435 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2437 p=GetAuthenticPixelQueue(image);
2438 if (p == (const PixelPacket *) NULL)
2440 for (x=0; x < (long) GetImageExtent(image); x++)
2442 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2443 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2444 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2445 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2450 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2452 p=GetAuthenticPixelQueue(image);
2453 if (p == (const PixelPacket *) NULL)
2455 for (x=0; x < (long) GetImageExtent(image); x++)
2457 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2458 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2459 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2465 if (LocaleCompare(stream_info->map,"I") == 0)
2467 p=GetAuthenticPixelQueue(image);
2468 if (p == (const PixelPacket *) NULL)
2470 for (x=0; x < (long) GetImageExtent(image); x++)
2472 *q++=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2477 if (LocaleCompare(stream_info->map,"RGB") == 0)
2479 p=GetAuthenticPixelQueue(image);
2480 if (p == (const PixelPacket *) NULL)
2482 for (x=0; x < (long) GetImageExtent(image); x++)
2484 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2485 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2486 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2491 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2493 p=GetAuthenticPixelQueue(image);
2494 if (p == (const PixelPacket *) NULL)
2496 for (x=0; x < (long) GetImageExtent(image); x++)
2498 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2499 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2500 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2501 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2506 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2508 p=GetAuthenticPixelQueue(image);
2509 if (p == (const PixelPacket *) NULL)
2511 for (x=0; x < (long) GetImageExtent(image); x++)
2513 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2514 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2515 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2521 p=GetAuthenticPixelQueue(image);
2522 if (p == (const PixelPacket *) NULL)
2524 indexes=GetAuthenticIndexQueue(image);
2525 for (x=0; x < (long) GetImageExtent(image); x++)
2527 for (i=0; i < (long) length; i++)
2530 switch (quantum_map[i])
2535 *q=ScaleQuantumToShort(GetRedPixelComponent(p));
2539 case MagentaQuantum:
2541 *q=ScaleQuantumToShort(GetGreenPixelComponent(p));
2547 *q=ScaleQuantumToShort(GetBluePixelComponent(p));
2552 *q=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2555 case OpacityQuantum:
2557 *q=ScaleQuantumToShort(GetOpacityPixelComponent(p));
2562 if (image->colorspace == CMYKColorspace)
2563 *q=ScaleQuantumToShort(indexes[x]);
2568 *q=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2582 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2583 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2584 "UnrecognizedPixelMap","`%s'",stream_info->map);
2588 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2597 + 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 %
2601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2603 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2604 % the latest stream of pixels.
2606 % The format of the SyncAuthenticPixelsStream method is:
2608 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2609 % ExceptionInfo *exception)
2611 % A description of each parameter follows:
2613 % o image: the image.
2615 % o exception: return any errors or warnings in this structure.
2618 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2619 ExceptionInfo *exception)
2630 assert(image != (Image *) NULL);
2631 assert(image->signature == MagickSignature);
2632 if (image->debug != MagickFalse)
2633 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2634 cache_info=(CacheInfo *) image->cache;
2635 assert(cache_info->signature == MagickSignature);
2636 stream_handler=GetBlobStreamHandler(image);
2637 if (stream_handler == (StreamHandler) NULL)
2639 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2640 "NoStreamHandlerIsDefined","`%s'",image->filename);
2641 return(MagickFalse);
2643 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2644 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2652 % W r i t e S t r e a m %
2656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2658 % WriteStream() makes the image pixels available to a user supplied callback
2659 % method immediately upon writing pixel data with the WriteImage() method.
2661 % The format of the WriteStream() method is:
2663 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2664 % StreamHandler stream)
2666 % A description of each parameter follows:
2668 % o image_info: the image info.
2670 % o stream: A callback method.
2673 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2674 Image *image,StreamHandler stream)
2682 assert(image_info != (ImageInfo *) NULL);
2683 assert(image_info->signature == MagickSignature);
2684 if (image_info->debug != MagickFalse)
2685 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2686 image_info->filename);
2687 assert(image != (Image *) NULL);
2688 assert(image->signature == MagickSignature);
2689 write_info=CloneImageInfo(image_info);
2690 write_info->stream=stream;
2691 status=WriteImage(write_info,image);
2692 write_info=DestroyImageInfo(write_info);