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)
1103 stream_info=(StreamInfo *) image->client_data;
1104 switch (stream_info->storage_type)
1106 default: packet_size=sizeof(char); break;
1107 case CharPixel: packet_size=sizeof(char); break;
1108 case DoublePixel: packet_size=sizeof(double); break;
1109 case FloatPixel: packet_size=sizeof(float); break;
1110 case IntegerPixel: packet_size=sizeof(int); break;
1111 case LongPixel: packet_size=sizeof(long); break;
1112 case QuantumPixel: packet_size=sizeof(Quantum); break;
1113 case ShortPixel: packet_size=sizeof(unsigned short); break;
1115 cache_info=(CacheInfo *) image->cache;
1116 assert(cache_info->signature == MagickSignature);
1117 packet_size*=strlen(stream_info->map);
1118 length=packet_size*cache_info->columns*cache_info->rows;
1119 if (image != stream_info->image)
1125 Prepare stream for writing.
1127 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1128 stream_info->pixels,length,sizeof(*stream_info->pixels));
1129 if (pixels == (unsigned char *) NULL)
1131 stream_info->image=image;
1132 write_info=CloneImageInfo(stream_info->image_info);
1133 (void) SetImageInfo(write_info,1,stream_info->exception);
1134 if (write_info->extract != (char *) NULL)
1135 (void) ParseAbsoluteGeometry(write_info->extract,
1136 &stream_info->extract_info);
1138 write_info=DestroyImageInfo(write_info);
1140 extract_info=stream_info->extract_info;
1141 if ((extract_info.width == 0) ||
1142 (extract_info.height == 0))
1145 Write all pixels to stream.
1147 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1148 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1150 return(count == 0 ? 0 : columns);
1152 if ((stream_info->y < extract_info.y) ||
1153 (stream_info->y >= (long) (extract_info.y+extract_info.height)))
1159 Write a portion of the pixel row to the stream.
1161 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1162 length=packet_size*extract_info.width;
1163 count=WriteBlob(stream_info->stream,length,stream_info->pixels+
1164 packet_size*extract_info.x);
1166 return(count == 0 ? 0 : columns);
1169 #if defined(__cplusplus) || defined(c_plusplus)
1173 MagickExport Image *StreamImage(const ImageInfo *image_info,
1174 StreamInfo *stream_info,ExceptionInfo *exception)
1182 assert(image_info != (const ImageInfo *) NULL);
1183 assert(image_info->signature == MagickSignature);
1184 if (image_info->debug != MagickFalse)
1185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1186 image_info->filename);
1187 assert(stream_info != (StreamInfo *) NULL);
1188 assert(stream_info->signature == MagickSignature);
1189 assert(exception != (ExceptionInfo *) NULL);
1190 read_info=CloneImageInfo(image_info);
1191 stream_info->image_info=image_info;
1192 stream_info->exception=exception;
1193 read_info->client_data=(void *) stream_info;
1194 image=ReadStream(read_info,&WriteStreamImage,exception);
1195 read_info=DestroyImageInfo(read_info);
1196 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1197 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1198 image=DestroyImage(image);
1203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1207 + S t r e a m I m a g e P i x e l s %
1211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1213 % StreamImagePixels() extracts pixel data from an image and returns it in the
1214 % stream_info->pixels structure in the format as defined by
1215 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1217 % The format of the StreamImagePixels method is:
1219 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1220 % const Image *image,ExceptionInfo *exception)
1222 % A description of each parameter follows:
1224 % o stream_info: the stream info.
1226 % o image: the image.
1228 % o exception: return any errors or warnings in this structure.
1231 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1232 const Image *image,ExceptionInfo *exception)
1244 register const PixelPacket
1247 register IndexPacket
1253 assert(stream_info != (StreamInfo *) NULL);
1254 assert(stream_info->signature == MagickSignature);
1255 assert(image != (Image *) NULL);
1256 assert(image->signature == MagickSignature);
1257 if (image->debug != MagickFalse)
1258 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1259 length=strlen(stream_info->map);
1260 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1261 if (quantum_map == (QuantumType *) NULL)
1263 (void) ThrowMagickException(exception,GetMagickModule(),
1264 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1265 return(MagickFalse);
1267 for (i=0; i < (long) length; i++)
1269 switch (stream_info->map[i])
1274 quantum_map[i]=AlphaQuantum;
1280 quantum_map[i]=BlueQuantum;
1286 quantum_map[i]=CyanQuantum;
1287 if (image->colorspace == CMYKColorspace)
1289 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1290 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1291 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1292 return(MagickFalse);
1297 quantum_map[i]=GreenQuantum;
1303 quantum_map[i]=IndexQuantum;
1309 quantum_map[i]=BlackQuantum;
1310 if (image->colorspace == CMYKColorspace)
1312 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1313 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1314 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1315 return(MagickFalse);
1320 quantum_map[i]=MagentaQuantum;
1321 if (image->colorspace == CMYKColorspace)
1323 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1324 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1325 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1326 return(MagickFalse);
1331 quantum_map[i]=OpacityQuantum;
1337 quantum_map[i]=UndefinedQuantum;
1343 quantum_map[i]=RedQuantum;
1349 quantum_map[i]=YellowQuantum;
1350 if (image->colorspace == CMYKColorspace)
1352 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1353 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1354 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1355 return(MagickFalse);
1359 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1360 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1361 "UnrecognizedPixelMap","`%s'",stream_info->map);
1362 return(MagickFalse);
1366 quantum_info=stream_info->quantum_info;
1367 switch (stream_info->storage_type)
1371 register unsigned char
1374 q=(unsigned char *) stream_info->pixels;
1375 if (LocaleCompare(stream_info->map,"BGR") == 0)
1377 p=GetAuthenticPixelQueue(image);
1378 if (p == (const PixelPacket *) NULL)
1380 for (x=0; x < (long) GetImageExtent(image); x++)
1382 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1383 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1384 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1389 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1391 p=GetAuthenticPixelQueue(image);
1392 if (p == (const PixelPacket *) NULL)
1394 for (x=0; x < (long) GetImageExtent(image); x++)
1396 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1397 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1398 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1399 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1404 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1406 p=GetAuthenticPixelQueue(image);
1407 if (p == (const PixelPacket *) NULL)
1409 for (x=0; x < (long) GetImageExtent(image); x++)
1411 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1412 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1413 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1414 *q++=ScaleQuantumToChar((Quantum) 0);
1419 if (LocaleCompare(stream_info->map,"I") == 0)
1421 p=GetAuthenticPixelQueue(image);
1422 if (p == (const PixelPacket *) NULL)
1424 for (x=0; x < (long) GetImageExtent(image); x++)
1426 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1431 if (LocaleCompare(stream_info->map,"RGB") == 0)
1433 p=GetAuthenticPixelQueue(image);
1434 if (p == (const PixelPacket *) NULL)
1436 for (x=0; x < (long) GetImageExtent(image); x++)
1438 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1439 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1440 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1445 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1447 p=GetAuthenticPixelQueue(image);
1448 if (p == (const PixelPacket *) NULL)
1450 for (x=0; x < (long) GetImageExtent(image); x++)
1452 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1453 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1454 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1455 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1460 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1462 p=GetAuthenticPixelQueue(image);
1463 if (p == (const PixelPacket *) NULL)
1465 for (x=0; x < (long) GetImageExtent(image); x++)
1467 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1468 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1469 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1470 *q++=ScaleQuantumToChar((Quantum) 0);
1475 p=GetAuthenticPixelQueue(image);
1476 if (p == (const PixelPacket *) NULL)
1478 indexes=GetAuthenticIndexQueue(image);
1479 for (x=0; x < (long) GetImageExtent(image); x++)
1481 for (i=0; i < (long) length; i++)
1484 switch (quantum_map[i])
1489 *q=ScaleQuantumToChar(GetRedPixelComponent(p));
1493 case MagentaQuantum:
1495 *q=ScaleQuantumToChar(GetGreenPixelComponent(p));
1501 *q=ScaleQuantumToChar(GetBluePixelComponent(p));
1506 *q=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
1509 case OpacityQuantum:
1511 *q=ScaleQuantumToChar(GetOpacityPixelComponent(p));
1516 if (image->colorspace == CMYKColorspace)
1517 *q=ScaleQuantumToChar(indexes[x]);
1522 *q=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1539 q=(double *) stream_info->pixels;
1540 if (LocaleCompare(stream_info->map,"BGR") == 0)
1542 p=GetAuthenticPixelQueue(image);
1543 if (p == (const PixelPacket *) NULL)
1545 for (x=0; x < (long) GetImageExtent(image); x++)
1547 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1548 quantum_info->scale+quantum_info->minimum);
1549 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1550 quantum_info->scale+quantum_info->minimum);
1551 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1552 quantum_info->scale+quantum_info->minimum);
1557 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1559 p=GetAuthenticPixelQueue(image);
1560 if (p == (const PixelPacket *) NULL)
1562 for (x=0; x < (long) GetImageExtent(image); x++)
1564 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1565 quantum_info->scale+quantum_info->minimum);
1566 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1567 quantum_info->scale+quantum_info->minimum);
1568 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1569 quantum_info->scale+quantum_info->minimum);
1570 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1571 quantum_info->scale+quantum_info->minimum);
1576 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1578 p=GetAuthenticPixelQueue(image);
1579 if (p == (const PixelPacket *) NULL)
1581 for (x=0; x < (long) GetImageExtent(image); x++)
1583 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1584 quantum_info->scale+quantum_info->minimum);
1585 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1586 quantum_info->scale+quantum_info->minimum);
1587 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1588 quantum_info->scale+quantum_info->minimum);
1594 if (LocaleCompare(stream_info->map,"I") == 0)
1596 p=GetAuthenticPixelQueue(image);
1597 if (p == (const PixelPacket *) NULL)
1599 for (x=0; x < (long) GetImageExtent(image); x++)
1601 *q++=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1602 quantum_info->scale+quantum_info->minimum);
1607 if (LocaleCompare(stream_info->map,"RGB") == 0)
1609 p=GetAuthenticPixelQueue(image);
1610 if (p == (const PixelPacket *) NULL)
1612 for (x=0; x < (long) GetImageExtent(image); x++)
1614 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1615 quantum_info->scale+quantum_info->minimum);
1616 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1617 quantum_info->scale+quantum_info->minimum);
1618 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1619 quantum_info->scale+quantum_info->minimum);
1624 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1626 p=GetAuthenticPixelQueue(image);
1627 if (p == (const PixelPacket *) NULL)
1629 for (x=0; x < (long) GetImageExtent(image); x++)
1631 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1632 quantum_info->scale+quantum_info->minimum);
1633 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1634 quantum_info->scale+quantum_info->minimum);
1635 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1636 quantum_info->scale+quantum_info->minimum);
1637 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1638 quantum_info->scale+quantum_info->minimum);
1643 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1645 p=GetAuthenticPixelQueue(image);
1646 if (p == (const PixelPacket *) NULL)
1648 for (x=0; x < (long) GetImageExtent(image); x++)
1650 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1651 quantum_info->scale+quantum_info->minimum);
1652 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1653 quantum_info->scale+quantum_info->minimum);
1654 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1655 quantum_info->scale+quantum_info->minimum);
1661 p=GetAuthenticPixelQueue(image);
1662 if (p == (const PixelPacket *) NULL)
1664 indexes=GetAuthenticIndexQueue(image);
1665 for (x=0; x < (long) GetImageExtent(image); x++)
1667 for (i=0; i < (long) length; i++)
1670 switch (quantum_map[i])
1675 *q=(double) ((QuantumScale*GetRedPixelComponent(p))*
1676 quantum_info->scale+quantum_info->minimum);
1680 case MagentaQuantum:
1682 *q=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1683 quantum_info->scale+quantum_info->minimum);
1689 *q=(double) ((QuantumScale*GetBluePixelComponent(p))*
1690 quantum_info->scale+quantum_info->minimum);
1695 *q=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1696 quantum_info->scale+quantum_info->minimum);
1699 case OpacityQuantum:
1701 *q=(double) ((QuantumScale*GetOpacityPixelComponent(p))*
1702 quantum_info->scale+quantum_info->minimum);
1707 if (image->colorspace == CMYKColorspace)
1708 *q=(double) ((QuantumScale*indexes[x])*quantum_info->scale+
1709 quantum_info->minimum);
1714 *q=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1715 quantum_info->scale+quantum_info->minimum);
1732 q=(float *) stream_info->pixels;
1733 if (LocaleCompare(stream_info->map,"BGR") == 0)
1735 p=GetAuthenticPixelQueue(image);
1736 if (p == (const PixelPacket *) NULL)
1738 for (x=0; x < (long) GetImageExtent(image); x++)
1740 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1741 quantum_info->scale+quantum_info->minimum);
1742 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1743 quantum_info->scale+quantum_info->minimum);
1744 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1745 quantum_info->scale+quantum_info->minimum);
1750 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1752 p=GetAuthenticPixelQueue(image);
1753 if (p == (const PixelPacket *) NULL)
1755 for (x=0; x < (long) GetImageExtent(image); x++)
1757 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1758 quantum_info->scale+quantum_info->minimum);
1759 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1760 quantum_info->scale+quantum_info->minimum);
1761 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1762 quantum_info->scale+quantum_info->minimum);
1763 *q++=(float) ((QuantumScale*(Quantum) (GetAlphaPixelComponent(p)))*
1764 quantum_info->scale+quantum_info->minimum);
1769 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1771 p=GetAuthenticPixelQueue(image);
1772 if (p == (const PixelPacket *) NULL)
1774 for (x=0; x < (long) GetImageExtent(image); x++)
1776 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1777 quantum_info->scale+quantum_info->minimum);
1778 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1779 quantum_info->scale+quantum_info->minimum);
1780 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1781 quantum_info->scale+quantum_info->minimum);
1787 if (LocaleCompare(stream_info->map,"I") == 0)
1789 p=GetAuthenticPixelQueue(image);
1790 if (p == (const PixelPacket *) NULL)
1792 for (x=0; x < (long) GetImageExtent(image); x++)
1794 *q++=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1795 quantum_info->scale+quantum_info->minimum);
1800 if (LocaleCompare(stream_info->map,"RGB") == 0)
1802 p=GetAuthenticPixelQueue(image);
1803 if (p == (const PixelPacket *) NULL)
1805 for (x=0; x < (long) GetImageExtent(image); x++)
1807 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1808 quantum_info->scale+quantum_info->minimum);
1809 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1810 quantum_info->scale+quantum_info->minimum);
1811 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1812 quantum_info->scale+quantum_info->minimum);
1817 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1819 p=GetAuthenticPixelQueue(image);
1820 if (p == (const PixelPacket *) NULL)
1822 for (x=0; x < (long) GetImageExtent(image); x++)
1824 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1825 quantum_info->scale+quantum_info->minimum);
1826 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1827 quantum_info->scale+quantum_info->minimum);
1828 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1829 quantum_info->scale+quantum_info->minimum);
1830 *q++=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1831 quantum_info->scale+quantum_info->minimum);
1836 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1838 p=GetAuthenticPixelQueue(image);
1839 if (p == (const PixelPacket *) NULL)
1841 for (x=0; x < (long) GetImageExtent(image); x++)
1843 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1844 quantum_info->scale+quantum_info->minimum);
1845 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1846 quantum_info->scale+quantum_info->minimum);
1847 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1848 quantum_info->scale+quantum_info->minimum);
1854 p=GetAuthenticPixelQueue(image);
1855 if (p == (const PixelPacket *) NULL)
1857 indexes=GetAuthenticIndexQueue(image);
1858 for (x=0; x < (long) GetImageExtent(image); x++)
1860 for (i=0; i < (long) length; i++)
1863 switch (quantum_map[i])
1868 *q=(float) ((QuantumScale*GetRedPixelComponent(p))*
1869 quantum_info->scale+quantum_info->minimum);
1873 case MagentaQuantum:
1875 *q=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1876 quantum_info->scale+quantum_info->minimum);
1882 *q=(float) ((QuantumScale*GetBluePixelComponent(p))*
1883 quantum_info->scale+quantum_info->minimum);
1888 *q=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1889 quantum_info->scale+quantum_info->minimum);
1892 case OpacityQuantum:
1894 *q=(float) ((QuantumScale*GetOpacityPixelComponent(p))*
1895 quantum_info->scale+quantum_info->minimum);
1900 if (image->colorspace == CMYKColorspace)
1901 *q=(float) ((QuantumScale*indexes[x])*quantum_info->scale+
1902 quantum_info->minimum);
1907 *q=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1908 quantum_info->scale+quantum_info->minimum);
1922 register unsigned int
1925 q=(unsigned int *) stream_info->pixels;
1926 if (LocaleCompare(stream_info->map,"BGR") == 0)
1928 p=GetAuthenticPixelQueue(image);
1929 if (p == (const PixelPacket *) NULL)
1931 for (x=0; x < (long) GetImageExtent(image); x++)
1933 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1934 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1935 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1940 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1942 p=GetAuthenticPixelQueue(image);
1943 if (p == (const PixelPacket *) NULL)
1945 for (x=0; x < (long) GetImageExtent(image); x++)
1947 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1948 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1949 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1950 *q++=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
1951 GetOpacityPixelComponent(p)));
1956 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1958 p=GetAuthenticPixelQueue(image);
1959 if (p == (const PixelPacket *) NULL)
1961 for (x=0; x < (long) GetImageExtent(image); x++)
1963 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1964 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1965 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1971 if (LocaleCompare(stream_info->map,"I") == 0)
1973 p=GetAuthenticPixelQueue(image);
1974 if (p == (const PixelPacket *) NULL)
1976 for (x=0; x < (long) GetImageExtent(image); x++)
1978 *q++=(unsigned int) ScaleQuantumToLong(
1979 PixelIntensityToQuantum(p));
1984 if (LocaleCompare(stream_info->map,"RGB") == 0)
1986 p=GetAuthenticPixelQueue(image);
1987 if (p == (const PixelPacket *) NULL)
1989 for (x=0; x < (long) GetImageExtent(image); x++)
1991 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1992 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1993 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1998 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2000 p=GetAuthenticPixelQueue(image);
2001 if (p == (const PixelPacket *) NULL)
2003 for (x=0; x < (long) GetImageExtent(image); x++)
2005 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2006 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2007 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2008 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2009 (GetAlphaPixelComponent(p)));
2014 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2016 p=GetAuthenticPixelQueue(image);
2017 if (p == (const PixelPacket *) NULL)
2019 for (x=0; x < (long) GetImageExtent(image); x++)
2021 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2022 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2023 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2029 p=GetAuthenticPixelQueue(image);
2030 if (p == (const PixelPacket *) NULL)
2032 indexes=GetAuthenticIndexQueue(image);
2033 for (x=0; x < (long) GetImageExtent(image); x++)
2035 for (i=0; i < (long) length; i++)
2038 switch (quantum_map[i])
2043 *q=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2047 case MagentaQuantum:
2049 *q=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2055 *q=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
2060 *q=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
2061 GetOpacityPixelComponent(p)));
2064 case OpacityQuantum:
2066 *q=(unsigned int) ScaleQuantumToLong(GetOpacityPixelComponent(p));
2071 if (image->colorspace == CMYKColorspace)
2072 *q=(unsigned int) ScaleQuantumToLong(indexes[x]);
2078 ScaleQuantumToLong(PixelIntensityToQuantum(p));
2092 register unsigned long
2095 q=(unsigned long *) stream_info->pixels;
2096 if (LocaleCompare(stream_info->map,"BGR") == 0)
2098 p=GetAuthenticPixelQueue(image);
2099 if (p == (const PixelPacket *) NULL)
2101 for (x=0; x < (long) GetImageExtent(image); x++)
2103 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2104 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2105 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2110 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2112 p=GetAuthenticPixelQueue(image);
2113 if (p == (const PixelPacket *) NULL)
2115 for (x=0; x < (long) GetImageExtent(image); x++)
2117 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2118 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2119 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2120 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2125 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2127 p=GetAuthenticPixelQueue(image);
2128 if (p == (const PixelPacket *) NULL)
2130 for (x=0; x < (long) GetImageExtent(image); x++)
2132 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2133 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2134 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2140 if (LocaleCompare(stream_info->map,"I") == 0)
2142 p=GetAuthenticPixelQueue(image);
2143 if (p == (const PixelPacket *) NULL)
2145 for (x=0; x < (long) GetImageExtent(image); x++)
2147 *q++=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2152 if (LocaleCompare(stream_info->map,"RGB") == 0)
2154 p=GetAuthenticPixelQueue(image);
2155 if (p == (const PixelPacket *) NULL)
2157 for (x=0; x < (long) GetImageExtent(image); x++)
2159 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2160 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2161 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2166 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2168 p=GetAuthenticPixelQueue(image);
2169 if (p == (const PixelPacket *) NULL)
2171 for (x=0; x < (long) GetImageExtent(image); x++)
2173 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2174 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2175 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2176 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2181 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2183 p=GetAuthenticPixelQueue(image);
2184 if (p == (const PixelPacket *) NULL)
2186 for (x=0; x < (long) GetImageExtent(image); x++)
2188 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2189 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2190 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2196 p=GetAuthenticPixelQueue(image);
2197 if (p == (const PixelPacket *) NULL)
2199 indexes=GetAuthenticIndexQueue(image);
2200 for (x=0; x < (long) GetImageExtent(image); x++)
2202 for (i=0; i < (long) length; i++)
2205 switch (quantum_map[i])
2210 *q=ScaleQuantumToLong(GetRedPixelComponent(p));
2214 case MagentaQuantum:
2216 *q=ScaleQuantumToLong(GetGreenPixelComponent(p));
2222 *q=ScaleQuantumToLong(GetBluePixelComponent(p));
2227 *q=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
2230 case OpacityQuantum:
2232 *q=ScaleQuantumToLong(GetOpacityPixelComponent(p));
2237 if (image->colorspace == CMYKColorspace)
2238 *q=ScaleQuantumToLong(indexes[x]);
2243 *q=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2260 q=(Quantum *) stream_info->pixels;
2261 if (LocaleCompare(stream_info->map,"BGR") == 0)
2263 p=GetAuthenticPixelQueue(image);
2264 if (p == (const PixelPacket *) NULL)
2266 for (x=0; x < (long) GetImageExtent(image); x++)
2268 *q++=GetBluePixelComponent(p);
2269 *q++=GetGreenPixelComponent(p);
2270 *q++=GetRedPixelComponent(p);
2275 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2277 p=GetAuthenticPixelQueue(image);
2278 if (p == (const PixelPacket *) NULL)
2280 for (x=0; x < (long) GetImageExtent(image); x++)
2282 *q++=GetBluePixelComponent(p);
2283 *q++=GetGreenPixelComponent(p);
2284 *q++=GetRedPixelComponent(p);
2285 *q++=(Quantum) (GetAlphaPixelComponent(p));
2290 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2292 p=GetAuthenticPixelQueue(image);
2293 if (p == (const PixelPacket *) NULL)
2295 for (x=0; x < (long) GetImageExtent(image); x++)
2297 *q++=GetBluePixelComponent(p);
2298 *q++=GetGreenPixelComponent(p);
2299 *q++=GetRedPixelComponent(p);
2305 if (LocaleCompare(stream_info->map,"I") == 0)
2307 p=GetAuthenticPixelQueue(image);
2308 if (p == (const PixelPacket *) NULL)
2310 for (x=0; x < (long) GetImageExtent(image); x++)
2312 *q++=PixelIntensityToQuantum(p);
2317 if (LocaleCompare(stream_info->map,"RGB") == 0)
2319 p=GetAuthenticPixelQueue(image);
2320 if (p == (const PixelPacket *) NULL)
2322 for (x=0; x < (long) GetImageExtent(image); x++)
2324 *q++=GetRedPixelComponent(p);
2325 *q++=GetGreenPixelComponent(p);
2326 *q++=GetBluePixelComponent(p);
2331 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2333 p=GetAuthenticPixelQueue(image);
2334 if (p == (const PixelPacket *) NULL)
2336 for (x=0; x < (long) GetImageExtent(image); x++)
2338 *q++=GetRedPixelComponent(p);
2339 *q++=GetGreenPixelComponent(p);
2340 *q++=GetBluePixelComponent(p);
2341 *q++=(Quantum) (GetAlphaPixelComponent(p));
2346 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2348 p=GetAuthenticPixelQueue(image);
2349 if (p == (const PixelPacket *) NULL)
2351 for (x=0; x < (long) GetImageExtent(image); x++)
2353 *q++=GetRedPixelComponent(p);
2354 *q++=GetGreenPixelComponent(p);
2355 *q++=GetBluePixelComponent(p);
2361 p=GetAuthenticPixelQueue(image);
2362 if (p == (const PixelPacket *) NULL)
2364 indexes=GetAuthenticIndexQueue(image);
2365 for (x=0; x < (long) GetImageExtent(image); x++)
2367 for (i=0; i < (long) length; i++)
2370 switch (quantum_map[i])
2375 *q=GetRedPixelComponent(p);
2379 case MagentaQuantum:
2381 *q=GetGreenPixelComponent(p);
2387 *q=GetBluePixelComponent(p);
2392 *q=(Quantum) (GetAlphaPixelComponent(p));
2395 case OpacityQuantum:
2397 *q=GetOpacityPixelComponent(p);
2402 if (image->colorspace == CMYKColorspace)
2408 *q=(PixelIntensityToQuantum(p));
2422 register unsigned short
2425 q=(unsigned short *) stream_info->pixels;
2426 if (LocaleCompare(stream_info->map,"BGR") == 0)
2428 p=GetAuthenticPixelQueue(image);
2429 if (p == (const PixelPacket *) NULL)
2431 for (x=0; x < (long) GetImageExtent(image); x++)
2433 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2434 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2435 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2440 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2442 p=GetAuthenticPixelQueue(image);
2443 if (p == (const PixelPacket *) NULL)
2445 for (x=0; x < (long) GetImageExtent(image); x++)
2447 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2448 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2449 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2450 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2455 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2457 p=GetAuthenticPixelQueue(image);
2458 if (p == (const PixelPacket *) NULL)
2460 for (x=0; x < (long) GetImageExtent(image); x++)
2462 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2463 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2464 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2470 if (LocaleCompare(stream_info->map,"I") == 0)
2472 p=GetAuthenticPixelQueue(image);
2473 if (p == (const PixelPacket *) NULL)
2475 for (x=0; x < (long) GetImageExtent(image); x++)
2477 *q++=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2482 if (LocaleCompare(stream_info->map,"RGB") == 0)
2484 p=GetAuthenticPixelQueue(image);
2485 if (p == (const PixelPacket *) NULL)
2487 for (x=0; x < (long) GetImageExtent(image); x++)
2489 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2490 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2491 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2496 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2498 p=GetAuthenticPixelQueue(image);
2499 if (p == (const PixelPacket *) NULL)
2501 for (x=0; x < (long) GetImageExtent(image); x++)
2503 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2504 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2505 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2506 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2511 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2513 p=GetAuthenticPixelQueue(image);
2514 if (p == (const PixelPacket *) NULL)
2516 for (x=0; x < (long) GetImageExtent(image); x++)
2518 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2519 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2520 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2526 p=GetAuthenticPixelQueue(image);
2527 if (p == (const PixelPacket *) NULL)
2529 indexes=GetAuthenticIndexQueue(image);
2530 for (x=0; x < (long) GetImageExtent(image); x++)
2532 for (i=0; i < (long) length; i++)
2535 switch (quantum_map[i])
2540 *q=ScaleQuantumToShort(GetRedPixelComponent(p));
2544 case MagentaQuantum:
2546 *q=ScaleQuantumToShort(GetGreenPixelComponent(p));
2552 *q=ScaleQuantumToShort(GetBluePixelComponent(p));
2557 *q=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
2560 case OpacityQuantum:
2562 *q=ScaleQuantumToShort(GetOpacityPixelComponent(p));
2567 if (image->colorspace == CMYKColorspace)
2568 *q=ScaleQuantumToShort(indexes[x]);
2573 *q=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2587 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2588 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2589 "UnrecognizedPixelMap","`%s'",stream_info->map);
2593 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2602 + 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 %
2606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2608 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2609 % the latest stream of pixels.
2611 % The format of the SyncAuthenticPixelsStream method is:
2613 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2614 % ExceptionInfo *exception)
2616 % A description of each parameter follows:
2618 % o image: the image.
2620 % o exception: return any errors or warnings in this structure.
2623 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2624 ExceptionInfo *exception)
2635 assert(image != (Image *) NULL);
2636 assert(image->signature == MagickSignature);
2637 if (image->debug != MagickFalse)
2638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2639 cache_info=(CacheInfo *) image->cache;
2640 assert(cache_info->signature == MagickSignature);
2641 stream_handler=GetBlobStreamHandler(image);
2642 if (stream_handler == (StreamHandler) NULL)
2644 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2645 "NoStreamHandlerIsDefined","`%s'",image->filename);
2646 return(MagickFalse);
2648 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2649 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2657 % W r i t e S t r e a m %
2661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2663 % WriteStream() makes the image pixels available to a user supplied callback
2664 % method immediately upon writing pixel data with the WriteImage() method.
2666 % The format of the WriteStream() method is:
2668 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2669 % StreamHandler stream)
2671 % A description of each parameter follows:
2673 % o image_info: the image info.
2675 % o stream: A callback method.
2678 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2679 Image *image,StreamHandler stream)
2687 assert(image_info != (ImageInfo *) NULL);
2688 assert(image_info->signature == MagickSignature);
2689 if (image_info->debug != MagickFalse)
2690 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2691 image_info->filename);
2692 assert(image != (Image *) NULL);
2693 assert(image->signature == MagickSignature);
2694 write_info=CloneImageInfo(image_info);
2695 write_info->stream=stream;
2696 status=WriteImage(write_info,image);
2697 write_info=DestroyImageInfo(write_info);