MagickCore  6.7.5
stream.c
Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                  SSSSS  TTTTT  RRRR   EEEEE   AAA   M   M                   %
00007 %                  SS       T    R   R  E      A   A  MM MM                   %
00008 %                   SSS     T    RRRR   EEE    AAAAA  M M M                   %
00009 %                     SS    T    R R    E      A   A  M   M                   %
00010 %                  SSSSS    T    R  R   EEEEE  A   A  M   M                   %
00011 %                                                                             %
00012 %                                                                             %
00013 %                       MagickCore Pixel Stream Methods                       %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                 March 2000                                  %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 %
00038 */
00039 
00040 /*
00041   Include declarations.
00042 */
00043 #include "MagickCore/studio.h"
00044 #include "MagickCore/blob.h"
00045 #include "MagickCore/blob-private.h"
00046 #include "MagickCore/cache.h"
00047 #include "MagickCore/cache-private.h"
00048 #include "MagickCore/color-private.h"
00049 #include "MagickCore/composite-private.h"
00050 #include "MagickCore/constitute.h"
00051 #include "MagickCore/exception.h"
00052 #include "MagickCore/exception-private.h"
00053 #include "MagickCore/geometry.h"
00054 #include "MagickCore/memory_.h"
00055 #include "MagickCore/pixel.h"
00056 #include "MagickCore/pixel-accessor.h"
00057 #include "MagickCore/quantum.h"
00058 #include "MagickCore/quantum-private.h"
00059 #include "MagickCore/semaphore.h"
00060 #include "MagickCore/stream.h"
00061 #include "MagickCore/stream-private.h"
00062 #include "MagickCore/string_.h"
00063 
00064 /*
00065   Typedef declaractions.
00066 */
00067 struct _StreamInfo
00068 {
00069   const ImageInfo
00070     *image_info;
00071 
00072   const Image
00073     *image;
00074 
00075   Image
00076     *stream;
00077 
00078   QuantumInfo
00079     *quantum_info;
00080 
00081   char
00082     *map;
00083 
00084   StorageType
00085     storage_type;
00086 
00087   unsigned char
00088     *pixels;
00089 
00090   RectangleInfo
00091     extract_info;
00092 
00093   ssize_t
00094     y;
00095 
00096   ExceptionInfo
00097     *exception;
00098 
00099   const void
00100     *client_data;
00101 
00102   size_t
00103     signature;
00104 };
00105 
00106 /*
00107   Declare pixel cache interfaces.
00108 */
00109 #if defined(__cplusplus) || defined(c_plusplus)
00110 extern "C" {
00111 #endif
00112 
00113 static const Quantum
00114   *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
00115     const ssize_t,const size_t,const size_t,ExceptionInfo *);
00116 
00117 static MagickBooleanType
00118   StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
00119   SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
00120 
00121 static Quantum
00122   *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
00123     const size_t,ExceptionInfo *);
00124 
00125 #if defined(__cplusplus) || defined(c_plusplus)
00126 }
00127 #endif
00128 
00129 /*
00130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00131 %                                                                             %
00132 %                                                                             %
00133 %                                                                             %
00134 +   A c q u i r e S t r e a m I n f o                                         %
00135 %                                                                             %
00136 %                                                                             %
00137 %                                                                             %
00138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00139 %
00140 %  AcquireStreamInfo() allocates the StreamInfo structure.
00141 %
00142 %  The format of the AcquireStreamInfo method is:
00143 %
00144 %      StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
00145 %        ExceptionInfo *exception)
00146 %
00147 %  A description of each parameter follows:
00148 %
00149 %    o image_info: the image info.
00150 %
00151 %    o exception: return any errors or warnings in this structure.
00152 %
00153 */
00154 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
00155   ExceptionInfo *exception)
00156 {
00157   StreamInfo
00158     *stream_info;
00159 
00160   stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
00161   if (stream_info == (StreamInfo *) NULL)
00162     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00163   (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
00164   stream_info->pixels=(unsigned char *) AcquireMagickMemory(
00165     sizeof(*stream_info->pixels));
00166   if (stream_info->pixels == (unsigned char *) NULL)
00167     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00168   stream_info->map=ConstantString("RGB");
00169   stream_info->storage_type=CharPixel;
00170   stream_info->stream=AcquireImage(image_info,exception);
00171   stream_info->signature=MagickSignature;
00172   return(stream_info);
00173 }
00174 
00175 /*
00176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00177 %                                                                             %
00178 %                                                                             %
00179 %                                                                             %
00180 +   D e s t r o y P i x e l S t r e a m                                       %
00181 %                                                                             %
00182 %                                                                             %
00183 %                                                                             %
00184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00185 %
00186 %  DestroyPixelStream() deallocates memory associated with the pixel stream.
00187 %
00188 %  The format of the DestroyPixelStream() method is:
00189 %
00190 %      void DestroyPixelStream(Image *image)
00191 %
00192 %  A description of each parameter follows:
00193 %
00194 %    o image: the image.
00195 %
00196 */
00197 
00198 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
00199 {
00200   assert(cache_info != (CacheInfo *) NULL);
00201   if (cache_info->mapped == MagickFalse)
00202     (void) RelinquishMagickMemory(cache_info->pixels);
00203   else
00204     (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
00205   cache_info->pixels=(Quantum *) NULL;
00206   cache_info->metacontent=(void *) NULL;
00207   cache_info->length=0;
00208   cache_info->mapped=MagickFalse;
00209 }
00210 
00211 static void DestroyPixelStream(Image *image)
00212 {
00213   CacheInfo
00214     *cache_info;
00215 
00216   MagickBooleanType
00217     destroy;
00218 
00219   assert(image != (Image *) NULL);
00220   assert(image->signature == MagickSignature);
00221   if (image->debug != MagickFalse)
00222     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00223   cache_info=(CacheInfo *) image->cache;
00224   assert(cache_info->signature == MagickSignature);
00225   destroy=MagickFalse;
00226   LockSemaphoreInfo(cache_info->semaphore);
00227   cache_info->reference_count--;
00228   if (cache_info->reference_count == 0)
00229     destroy=MagickTrue;
00230   UnlockSemaphoreInfo(cache_info->semaphore);
00231   if (destroy == MagickFalse)
00232     return;
00233   RelinquishStreamPixels(cache_info);
00234   if (cache_info->nexus_info != (NexusInfo **) NULL)
00235     cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
00236       cache_info->number_threads);
00237   if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
00238     DestroySemaphoreInfo(&cache_info->disk_semaphore);
00239   if (cache_info->semaphore != (SemaphoreInfo *) NULL)
00240     DestroySemaphoreInfo(&cache_info->semaphore);
00241   cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
00242 }
00243 
00244 /*
00245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00246 %                                                                             %
00247 %                                                                             %
00248 %                                                                             %
00249 +   D e s t r o y S t r e a m I n f o                                         %
00250 %                                                                             %
00251 %                                                                             %
00252 %                                                                             %
00253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00254 %
00255 %  DestroyStreamInfo() destroys memory associated with the StreamInfo
00256 %  structure.
00257 %
00258 %  The format of the DestroyStreamInfo method is:
00259 %
00260 %      StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
00261 %
00262 %  A description of each parameter follows:
00263 %
00264 %    o stream_info: the stream info.
00265 %
00266 */
00267 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
00268 {
00269   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00270   assert(stream_info != (StreamInfo *) NULL);
00271   assert(stream_info->signature == MagickSignature);
00272   if (stream_info->map != (char *) NULL)
00273     stream_info->map=DestroyString(stream_info->map);
00274   if (stream_info->pixels != (unsigned char *) NULL)
00275     stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
00276       stream_info->pixels);
00277   if (stream_info->stream != (Image *) NULL)
00278     {
00279       (void) CloseBlob(stream_info->stream);
00280       stream_info->stream=DestroyImage(stream_info->stream);
00281     }
00282   if (stream_info->quantum_info != (QuantumInfo *) NULL)
00283     stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
00284   stream_info->signature=(~MagickSignature);
00285   stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
00286   return(stream_info);
00287 }
00288 
00289 /*
00290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00291 %                                                                             %
00292 %                                                                             %
00293 %                                                                             %
00294 +   G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m         %
00295 %                                                                             %
00296 %                                                                             %
00297 %                                                                             %
00298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00299 %
00300 %  GetAuthenticMetacontentFromStream() returns the metacontent corresponding
00301 %  with the last call to QueueAuthenticPixelsStream() or
00302 %  GetAuthenticPixelsStream().
00303 %
00304 %  The format of the GetAuthenticMetacontentFromStream() method is:
00305 %
00306 %      void *GetAuthenticMetacontentFromStream(const Image *image)
00307 %
00308 %  A description of each parameter follows:
00309 %
00310 %    o image: the image.
00311 %
00312 */
00313 static void *GetAuthenticMetacontentFromStream(const Image *image)
00314 {
00315   CacheInfo
00316     *cache_info;
00317 
00318   assert(image != (Image *) NULL);
00319   assert(image->signature == MagickSignature);
00320   if (image->debug != MagickFalse)
00321     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00322   cache_info=(CacheInfo *) image->cache;
00323   assert(cache_info->signature == MagickSignature);
00324   return(cache_info->metacontent);
00325 }
00326 
00327 /*
00328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00329 %                                                                             %
00330 %                                                                             %
00331 %                                                                             %
00332 +   G e t A u t h e n t i c P i x e l S t r e a m                             %
00333 %                                                                             %
00334 %                                                                             %
00335 %                                                                             %
00336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00337 %
00338 %  GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
00339 %  cache as defined by the geometry parameters.   A pointer to the pixels is
00340 %  returned if the pixels are transferred, otherwise a NULL is returned.  For
00341 %  streams this method is a no-op.
00342 %
00343 %  The format of the GetAuthenticPixelsStream() method is:
00344 %
00345 %      Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
00346 %        const ssize_t y,const size_t columns,const size_t rows,
00347 %        ExceptionInfo *exception)
00348 %
00349 %  A description of each parameter follows:
00350 %
00351 %    o image: the image.
00352 %
00353 %    o x,y,columns,rows:  These values define the perimeter of a region of
00354 %      pixels.
00355 %
00356 %    o exception: return any errors or warnings in this structure.
00357 %
00358 */
00359 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
00360   const ssize_t y,const size_t columns,const size_t rows,
00361   ExceptionInfo *exception)
00362 {
00363   Quantum
00364     *pixels;
00365 
00366   assert(image != (Image *) NULL);
00367   assert(image->signature == MagickSignature);
00368   if (image->debug != MagickFalse)
00369     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00370   pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
00371   return(pixels);
00372 }
00373 
00374 /*
00375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00376 %                                                                             %
00377 %                                                                             %
00378 %                                                                             %
00379 +   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                       %
00380 %                                                                             %
00381 %                                                                             %
00382 %                                                                             %
00383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00384 %
00385 %  GetAuthenticPixelsFromStream() returns the pixels associated with the last
00386 %  call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
00387 %
00388 %  The format of the GetAuthenticPixelsFromStream() method is:
00389 %
00390 %      Quantum *GetAuthenticPixelsFromStream(const Image image)
00391 %
00392 %  A description of each parameter follows:
00393 %
00394 %    o image: the image.
00395 %
00396 */
00397 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
00398 {
00399   CacheInfo
00400     *cache_info;
00401 
00402   assert(image != (Image *) NULL);
00403   assert(image->signature == MagickSignature);
00404   if (image->debug != MagickFalse)
00405     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00406   cache_info=(CacheInfo *) image->cache;
00407   assert(cache_info->signature == MagickSignature);
00408   return(cache_info->pixels);
00409 }
00410 
00411 /*
00412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00413 %                                                                             %
00414 %                                                                             %
00415 %                                                                             %
00416 +   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               %
00417 %                                                                             %
00418 %                                                                             %
00419 %                                                                             %
00420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00421 %
00422 %  GetOneAuthenticPixelFromStream() returns a single pixel at the specified
00423 %  (x,y) location.  The image background color is returned if an error occurs.
00424 %
00425 %  The format of the GetOneAuthenticPixelFromStream() method is:
00426 %
00427 %      MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
00428 %        const ssize_t x,const ssize_t y,Quantum *pixel,
00429 %        ExceptionInfo *exception)
00430 %
00431 %  A description of each parameter follows:
00432 %
00433 %    o image: the image.
00434 %
00435 %    o pixel: return a pixel at the specified (x,y) location.
00436 %
00437 %    o x,y:  These values define the location of the pixel to return.
00438 %
00439 %    o exception: return any errors or warnings in this structure.
00440 %
00441 */
00442 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
00443   const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
00444 {
00445   register Quantum
00446     *q;
00447 
00448   register ssize_t
00449     i;
00450 
00451   assert(image != (Image *) NULL);
00452   assert(image->signature == MagickSignature);
00453   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
00454   q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
00455   if (q != (Quantum *) NULL)
00456     {
00457       pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
00458       pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
00459       pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
00460       pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
00461       pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
00462       return(MagickFalse);
00463     }
00464   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
00465   {
00466     PixelChannel
00467       channel;
00468 
00469     channel=GetPixelChannelMapChannel(image,i);
00470     pixel[channel]=q[i];
00471   }
00472   return(MagickTrue);
00473 }
00474 
00475 /*
00476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00477 %                                                                             %
00478 %                                                                             %
00479 %                                                                             %
00480 +   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                   %
00481 %                                                                             %
00482 %                                                                             %
00483 %                                                                             %
00484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00485 %
00486 %  GetOneVirtualPixelFromStream() returns a single pixel at the specified
00487 %  (x.y) location.  The image background color is returned if an error occurs.
00488 %
00489 %  The format of the GetOneVirtualPixelFromStream() method is:
00490 %
00491 %      MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
00492 %        const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
00493 %        const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
00494 %
00495 %  A description of each parameter follows:
00496 %
00497 %    o image: the image.
00498 %
00499 %    o virtual_pixel_method: the virtual pixel method.
00500 %
00501 %    o x,y:  These values define the location of the pixel to return.
00502 %
00503 %    o pixel: return a pixel at the specified (x,y) location.
00504 %
00505 %    o exception: return any errors or warnings in this structure.
00506 %
00507 */
00508 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
00509   const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
00510   Quantum *pixel,ExceptionInfo *exception)
00511 {
00512   const Quantum
00513     *p;
00514 
00515   register ssize_t
00516     i;
00517 
00518   assert(image != (Image *) NULL);
00519   assert(image->signature == MagickSignature);
00520   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
00521   p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
00522   if (p == (const Quantum *) NULL)
00523     {
00524       pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
00525       pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
00526       pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
00527       pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
00528       pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
00529       return(MagickFalse);
00530     }
00531   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
00532   {
00533     PixelChannel
00534       channel;
00535 
00536     channel=GetPixelChannelMapChannel(image,i);
00537     pixel[channel]=p[i];
00538   }
00539   return(MagickTrue);
00540 }
00541 
00542 /*
00543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00544 %                                                                             %
00545 %                                                                             %
00546 %                                                                             %
00547 +   G e t S t r e a m I n f o C l i e n t D a t a                             %
00548 %                                                                             %
00549 %                                                                             %
00550 %                                                                             %
00551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00552 %
00553 %  GetStreamInfoClientData() gets the stream info client data.
00554 %
00555 %  The format of the GetStreamInfoClientData method is:
00556 %
00557 %      const void *GetStreamInfoClientData(StreamInfo *stream_info)
00558 %
00559 %  A description of each parameter follows:
00560 %
00561 %    o stream_info: the stream info.
00562 %
00563 */
00564 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
00565 {
00566   assert(stream_info != (StreamInfo *) NULL);
00567   assert(stream_info->signature == MagickSignature);
00568   return(stream_info->client_data);
00569 }
00570 
00571 /*
00572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00573 %                                                                             %
00574 %                                                                             %
00575 %                                                                             %
00576 +   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                      %
00577 %                                                                             %
00578 %                                                                             %
00579 %                                                                             %
00580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00581 %
00582 %  GetVirtualPixelsStream() returns the pixels associated with the last
00583 %  call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
00584 %
00585 %  The format of the GetVirtualPixelsStream() method is:
00586 %
00587 %      const Quantum *GetVirtualPixelsStream(const Image *image)
00588 %
00589 %  A description of each parameter follows:
00590 %
00591 %    o pixels: return the pixels associated corresponding with the last call to
00592 %      QueueAuthenticPixelsStream() or GetVirtualPixelStream().
00593 %
00594 %    o image: the image.
00595 %
00596 */
00597 static const Quantum *GetVirtualPixelsStream(const Image *image)
00598 {
00599   CacheInfo
00600     *cache_info;
00601 
00602   assert(image != (Image *) NULL);
00603   assert(image->signature == MagickSignature);
00604   if (image->debug != MagickFalse)
00605     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00606   cache_info=(CacheInfo *) image->cache;
00607   assert(cache_info->signature == MagickSignature);
00608   return(cache_info->pixels);
00609 }
00610 
00611 /*
00612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00613 %                                                                             %
00614 %                                                                             %
00615 %                                                                             %
00616 +   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                     %
00617 %                                                                             %
00618 %                                                                             %
00619 %                                                                             %
00620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00621 %
00622 %  GetVirtualMetacontentFromStream() returns the associated pixel 
00623 %  channels corresponding with the last call to QueueAuthenticPixelsStream() or
00624 %  GetVirtualPixelStream().
00625 %
00626 %  The format of the GetVirtualMetacontentFromStream() method is:
00627 %
00628 %      const void *GetVirtualMetacontentFromStream(const Image *image)
00629 %
00630 %  A description of each parameter follows:
00631 %
00632 %    o image: the image.
00633 %
00634 */
00635 static const void *GetVirtualMetacontentFromStream(
00636   const Image *image)
00637 {
00638   CacheInfo
00639     *cache_info;
00640 
00641   assert(image != (Image *) NULL);
00642   assert(image->signature == MagickSignature);
00643   if (image->debug != MagickFalse)
00644     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00645   cache_info=(CacheInfo *) image->cache;
00646   assert(cache_info->signature == MagickSignature);
00647   return(cache_info->metacontent);
00648 }
00649 
00650 /*
00651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00652 %                                                                             %
00653 %                                                                             %
00654 %                                                                             %
00655 +   G e t V i r t u a l P i x e l S t r e a m                                 %
00656 %                                                                             %
00657 %                                                                             %
00658 %                                                                             %
00659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00660 %
00661 %  GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
00662 %  defined by the geometry parameters.   A pointer to the pixels is returned if
00663 %  the pixels are transferred, otherwise a NULL is returned.  For streams this
00664 %  method is a no-op.
00665 %
00666 %  The format of the GetVirtualPixelStream() method is:
00667 %
00668 %      const Quantum *GetVirtualPixelStream(const Image *image,
00669 %        const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
00670 %        const ssize_t y,const size_t columns,const size_t rows,
00671 %        ExceptionInfo *exception)
00672 %
00673 %  A description of each parameter follows:
00674 %
00675 %    o image: the image.
00676 %
00677 %    o virtual_pixel_method: the virtual pixel method.
00678 %
00679 %    o x,y,columns,rows:  These values define the perimeter of a region of
00680 %      pixels.
00681 %
00682 %    o exception: return any errors or warnings in this structure.
00683 %
00684 */
00685 
00686 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
00687   ExceptionInfo *exception)
00688 {
00689   if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
00690     return(MagickFalse);
00691   cache_info->mapped=MagickFalse;
00692   cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
00693     cache_info->length);
00694   if (cache_info->pixels == (Quantum *) NULL)
00695     {
00696       cache_info->mapped=MagickTrue;
00697       cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
00698         cache_info->length);
00699     }
00700   if (cache_info->pixels == (Quantum *) NULL)
00701     {
00702       (void) ThrowMagickException(exception,GetMagickModule(),
00703         ResourceLimitError,"MemoryAllocationFailed","`%s'",
00704         cache_info->filename);
00705       return(MagickFalse);
00706     }
00707   return(MagickTrue);
00708 }
00709 
00710 static const Quantum *GetVirtualPixelStream(const Image *image,
00711   const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
00712   const ssize_t y,const size_t columns,const size_t rows,
00713   ExceptionInfo *exception)
00714 {
00715   CacheInfo
00716     *cache_info;
00717 
00718   MagickBooleanType
00719     status;
00720 
00721   MagickSizeType
00722     number_pixels;
00723 
00724   size_t
00725     length;
00726 
00727   /*
00728     Validate pixel cache geometry.
00729   */
00730   assert(image != (const Image *) NULL);
00731   assert(image->signature == MagickSignature);
00732   if (image->debug != MagickFalse)
00733     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00734   if ((x < 0) || (y < 0) ||
00735       ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
00736       ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
00737       (columns == 0) || (rows == 0))
00738     {
00739       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
00740         "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
00741       return((Quantum *) NULL);
00742     }
00743   cache_info=(CacheInfo *) image->cache;
00744   assert(cache_info->signature == MagickSignature);
00745   /*
00746     Pixels are stored in a temporary buffer until they are synced to the cache.
00747   */
00748   number_pixels=(MagickSizeType) columns*rows;
00749   length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
00750   if (cache_info->metacontent_extent != 0)
00751     length+=number_pixels*cache_info->metacontent_extent;
00752   if (cache_info->pixels == (Quantum *) NULL)
00753     {
00754       cache_info->length=length;
00755       status=AcquireStreamPixels(cache_info,exception);
00756       if (status == MagickFalse)
00757         {
00758           cache_info->length=0;
00759           return((Quantum *) NULL);
00760         }
00761     }
00762   else
00763     if (cache_info->length != length)
00764       {
00765         RelinquishStreamPixels(cache_info);
00766         cache_info->length=length;
00767         status=AcquireStreamPixels(cache_info,exception);
00768         if (status == MagickFalse)
00769           {
00770             cache_info->length=0;
00771             return((Quantum *) NULL);
00772           }
00773       }
00774   cache_info->metacontent=(void *) NULL;
00775   if (cache_info->metacontent_extent != 0)
00776     cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
00777       cache_info->number_channels);
00778   return(cache_info->pixels);
00779 }
00780 
00781 /*
00782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00783 %                                                                             %
00784 %                                                                             %
00785 %                                                                             %
00786 +   O p e n S t r e a m                                                       %
00787 %                                                                             %
00788 %                                                                             %
00789 %                                                                             %
00790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00791 %
00792 %  OpenStream() opens a stream for writing by the StreamImage() method.
00793 %
00794 %  The format of the OpenStream method is:
00795 %
00796 %       MagickBooleanType OpenStream(const ImageInfo *image_info,
00797 %        StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
00798 %
00799 %  A description of each parameter follows:
00800 %
00801 %    o image_info: the image info.
00802 %
00803 %    o stream_info: the stream info.
00804 %
00805 %    o filename: the stream filename.
00806 %
00807 %    o exception: return any errors or warnings in this structure.
00808 %
00809 */
00810 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
00811   StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
00812 {
00813   MagickBooleanType
00814     status;
00815 
00816   (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
00817   status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
00818   return(status);
00819 }
00820 
00821 /*
00822 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00823 %                                                                             %
00824 %                                                                             %
00825 %                                                                             %
00826 +   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                       %
00827 %                                                                             %
00828 %                                                                             %
00829 %                                                                             %
00830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00831 %
00832 %  QueueAuthenticPixelsStream() allocates an area to store image pixels as
00833 %  defined by the region rectangle and returns a pointer to the area.  This
00834 %  area is subsequently transferred from the pixel cache with method
00835 %  SyncAuthenticPixelsStream().  A pointer to the pixels is returned if the
00836 %  pixels are transferred, otherwise a NULL is returned.
00837 %
00838 %  The format of the QueueAuthenticPixelsStream() method is:
00839 %
00840 %      Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
00841 %        const ssize_t y,const size_t columns,const size_t rows,
00842 %        ExceptionInfo *exception)
00843 %
00844 %  A description of each parameter follows:
00845 %
00846 %    o image: the image.
00847 %
00848 %    o x,y,columns,rows:  These values define the perimeter of a region of
00849 %      pixels.
00850 %
00851 */
00852 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
00853   const ssize_t y,const size_t columns,const size_t rows,
00854   ExceptionInfo *exception)
00855 {
00856   CacheInfo
00857     *cache_info;
00858 
00859   MagickSizeType
00860     number_pixels;
00861 
00862   size_t
00863     length;
00864 
00865   StreamHandler
00866     stream_handler;
00867 
00868   /*
00869     Validate pixel cache geometry.
00870   */
00871   assert(image != (Image *) NULL);
00872   if ((x < 0) || (y < 0) ||
00873       ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
00874       ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
00875       (columns == 0) || (rows == 0))
00876     {
00877       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
00878         "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
00879       return((Quantum *) NULL);
00880     }
00881   stream_handler=GetBlobStreamHandler(image);
00882   if (stream_handler == (StreamHandler) NULL)
00883     {
00884       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
00885         "NoStreamHandlerIsDefined","`%s'",image->filename);
00886       return((Quantum *) NULL);
00887     }
00888   cache_info=(CacheInfo *) image->cache;
00889   assert(cache_info->signature == MagickSignature);
00890   if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
00891       (image->colorspace != GetPixelCacheColorspace(image->cache)))
00892     {
00893       if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
00894         (void) stream_handler(image,(const void *) NULL,(size_t)
00895           cache_info->columns);
00896       cache_info->storage_class=image->storage_class;
00897       cache_info->colorspace=image->colorspace;
00898       cache_info->columns=image->columns;
00899       cache_info->rows=image->rows;
00900       image->cache=cache_info;
00901     }
00902   /*
00903     Pixels are stored in a temporary buffer until they are synced to the cache.
00904   */
00905   cache_info->columns=columns;
00906   cache_info->rows=rows;
00907   number_pixels=(MagickSizeType) columns*rows;
00908   length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
00909   if (cache_info->metacontent_extent != 0)
00910     length+=number_pixels*cache_info->metacontent_extent;
00911   if (cache_info->pixels == (Quantum *) NULL)
00912     {
00913       cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
00914       cache_info->length=(MagickSizeType) length;
00915     }
00916   else
00917     if (cache_info->length < (MagickSizeType) length)
00918       {
00919         cache_info->pixels=(Quantum *) ResizeMagickMemory(
00920           cache_info->pixels,length);
00921         cache_info->length=(MagickSizeType) length;
00922       }
00923   if (cache_info->pixels == (void *) NULL)
00924     return((Quantum *) NULL);
00925   cache_info->metacontent=(void *) NULL;
00926   if (cache_info->metacontent_extent != 0)
00927     cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
00928       cache_info->number_channels);
00929   return(cache_info->pixels);
00930 }
00931 
00932 /*
00933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00934 %                                                                             %
00935 %                                                                             %
00936 %                                                                             %
00937 %   R e a d S t r e a m                                                       %
00938 %                                                                             %
00939 %                                                                             %
00940 %                                                                             %
00941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00942 %
00943 %  ReadStream() makes the image pixels available to a user supplied callback
00944 %  method immediately upon reading a scanline with the ReadImage() method.
00945 %
00946 %  The format of the ReadStream() method is:
00947 %
00948 %      Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
00949 %        ExceptionInfo *exception)
00950 %
00951 %  A description of each parameter follows:
00952 %
00953 %    o image_info: the image info.
00954 %
00955 %    o stream: a callback method.
00956 %
00957 %    o exception: return any errors or warnings in this structure.
00958 %
00959 */
00960 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
00961   ExceptionInfo *exception)
00962 {
00963   CacheMethods
00964     cache_methods;
00965 
00966   Image
00967     *image;
00968 
00969   ImageInfo
00970     *read_info;
00971 
00972   /*
00973     Stream image pixels.
00974   */
00975   assert(image_info != (ImageInfo *) NULL);
00976   assert(image_info->signature == MagickSignature);
00977   if (image_info->debug != MagickFalse)
00978     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
00979       image_info->filename);
00980   assert(exception != (ExceptionInfo *) NULL);
00981   assert(exception->signature == MagickSignature);
00982   read_info=CloneImageInfo(image_info);
00983   read_info->cache=AcquirePixelCache(0);
00984   GetPixelCacheMethods(&cache_methods);
00985   cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
00986   cache_methods.get_virtual_metacontent_from_handler=
00987     GetVirtualMetacontentFromStream;
00988   cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
00989   cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
00990   cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
00991   cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
00992   cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
00993   cache_methods.get_authentic_metacontent_from_handler=
00994     GetAuthenticMetacontentFromStream;
00995   cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
00996   cache_methods.get_one_authentic_pixel_from_handler=
00997     GetOneAuthenticPixelFromStream;
00998   cache_methods.destroy_pixel_handler=DestroyPixelStream;
00999   SetPixelCacheMethods(read_info->cache,&cache_methods);
01000   read_info->stream=stream;
01001   image=ReadImage(read_info,exception);
01002   read_info=DestroyImageInfo(read_info);
01003   return(image);
01004 }
01005 
01006 /*
01007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01008 %                                                                             %
01009 %                                                                             %
01010 %                                                                             %
01011 +   S e t S t r e a m I n f o C l i e n t D a t a                             %
01012 %                                                                             %
01013 %                                                                             %
01014 %                                                                             %
01015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01016 %
01017 %  SetStreamInfoClientData() sets the stream info client data.
01018 %
01019 %  The format of the SetStreamInfoClientData method is:
01020 %
01021 %      void SetStreamInfoClientData(StreamInfo *stream_info,
01022 %        const void *client_data)
01023 %
01024 %  A description of each parameter follows:
01025 %
01026 %    o stream_info: the stream info.
01027 %
01028 %    o client_data: the client data.
01029 %
01030 */
01031 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
01032   const void *client_data)
01033 {
01034   assert(stream_info != (StreamInfo *) NULL);
01035   assert(stream_info->signature == MagickSignature);
01036   stream_info->client_data=client_data;
01037 }
01038 
01039 /*
01040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01041 %                                                                             %
01042 %                                                                             %
01043 %                                                                             %
01044 +   S e t S t r e a m I n f o M a p                                           %
01045 %                                                                             %
01046 %                                                                             %
01047 %                                                                             %
01048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01049 %
01050 %  SetStreamInfoMap() sets the stream info map member.
01051 %
01052 %  The format of the SetStreamInfoMap method is:
01053 %
01054 %      void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
01055 %
01056 %  A description of each parameter follows:
01057 %
01058 %    o stream_info: the stream info.
01059 %
01060 %    o map: the map.
01061 %
01062 */
01063 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
01064 {
01065   assert(stream_info != (StreamInfo *) NULL);
01066   assert(stream_info->signature == MagickSignature);
01067   (void) CloneString(&stream_info->map,map);
01068 }
01069 
01070 /*
01071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01072 %                                                                             %
01073 %                                                                             %
01074 %                                                                             %
01075 +   S e t S t r e a m I n f o S t o r a g e T y p e                           %
01076 %                                                                             %
01077 %                                                                             %
01078 %                                                                             %
01079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01080 %
01081 %  SetStreamInfoStorageType() sets the stream info storage type member.
01082 %
01083 %  The format of the SetStreamInfoStorageType method is:
01084 %
01085 %      void SetStreamInfoStorageType(StreamInfo *stream_info,
01086 %        const StoreageType *storage_type)
01087 %
01088 %  A description of each parameter follows:
01089 %
01090 %    o stream_info: the stream info.
01091 %
01092 %    o storage_type: the storage type.
01093 %
01094 */
01095 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
01096   const StorageType storage_type)
01097 {
01098   assert(stream_info != (StreamInfo *) NULL);
01099   assert(stream_info->signature == MagickSignature);
01100   stream_info->storage_type=storage_type;
01101 }
01102 
01103 /*
01104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01105 %                                                                             %
01106 %                                                                             %
01107 %                                                                             %
01108 +   S t r e a m I m a g e                                                     %
01109 %                                                                             %
01110 %                                                                             %
01111 %                                                                             %
01112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01113 %
01114 %  StreamImage() streams pixels from an image and writes them in a user
01115 %  defined format and storage type (e.g. RGBA as 8-bit unsigned char).
01116 %
01117 %  The format of the StreamImage() method is:
01118 %
01119 %      Image *StreamImage(const ImageInfo *image_info,
01120 %        StreamInfo *stream_info,ExceptionInfo *exception)
01121 %
01122 %  A description of each parameter follows:
01123 %
01124 %    o image_info: the image info.
01125 %
01126 %    o stream_info: the stream info.
01127 %
01128 %    o exception: return any errors or warnings in this structure.
01129 %
01130 */
01131 
01132 #if defined(__cplusplus) || defined(c_plusplus)
01133 extern "C" {
01134 #endif
01135 
01136 static size_t WriteStreamImage(const Image *image,const void *pixels,
01137   const size_t columns)
01138 {
01139   CacheInfo
01140     *cache_info;
01141 
01142   RectangleInfo
01143     extract_info;
01144 
01145   size_t
01146     length,
01147     packet_size;
01148 
01149   ssize_t
01150     count;
01151 
01152   StreamInfo
01153     *stream_info;
01154 
01155   (void) pixels;
01156   stream_info=(StreamInfo *) image->client_data;
01157   switch (stream_info->storage_type)
01158   {
01159     default: packet_size=sizeof(unsigned char); break;
01160     case CharPixel: packet_size=sizeof(unsigned char); break;
01161     case DoublePixel: packet_size=sizeof(double); break;
01162     case FloatPixel: packet_size=sizeof(float); break;
01163     case LongPixel: packet_size=sizeof(unsigned int); break;
01164     case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
01165     case QuantumPixel: packet_size=sizeof(Quantum); break;
01166     case ShortPixel: packet_size=sizeof(unsigned short); break;
01167   }
01168   cache_info=(CacheInfo *) image->cache;
01169   assert(cache_info->signature == MagickSignature);
01170   packet_size*=strlen(stream_info->map);
01171   length=packet_size*cache_info->columns*cache_info->rows;
01172   if (image != stream_info->image)
01173     {
01174       ImageInfo
01175         *write_info;
01176 
01177       /*
01178         Prepare stream for writing.
01179       */
01180       stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
01181         stream_info->pixels,length,sizeof(*stream_info->pixels));
01182       if (stream_info->pixels == (unsigned char *) NULL)
01183         return(0);
01184       stream_info->image=image;
01185       write_info=CloneImageInfo(stream_info->image_info);
01186       (void) SetImageInfo(write_info,1,stream_info->exception);
01187       if (write_info->extract != (char *) NULL)
01188         (void) ParseAbsoluteGeometry(write_info->extract,
01189           &stream_info->extract_info);
01190       stream_info->y=0;
01191       write_info=DestroyImageInfo(write_info);
01192     }
01193   extract_info=stream_info->extract_info;
01194   if ((extract_info.width == 0) || (extract_info.height == 0))
01195     {
01196       /*
01197         Write all pixels to stream.
01198       */
01199       (void) StreamImagePixels(stream_info,image,stream_info->exception);
01200       count=WriteBlob(stream_info->stream,length,stream_info->pixels);
01201       stream_info->y++;
01202       return(count == 0 ? 0 : columns);
01203     }
01204   if ((stream_info->y < extract_info.y) ||
01205       (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
01206     {
01207       stream_info->y++;
01208       return(columns);
01209     }
01210   /*
01211     Write a portion of the pixel row to the stream.
01212   */
01213   (void) StreamImagePixels(stream_info,image,stream_info->exception);
01214   length=packet_size*extract_info.width;
01215   count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
01216     extract_info.x);
01217   stream_info->y++;
01218   return(count == 0 ? 0 : columns);
01219 }
01220 
01221 #if defined(__cplusplus) || defined(c_plusplus)
01222 }
01223 #endif
01224 
01225 MagickExport Image *StreamImage(const ImageInfo *image_info,
01226   StreamInfo *stream_info,ExceptionInfo *exception)
01227 {
01228   Image
01229     *image;
01230 
01231   ImageInfo
01232     *read_info;
01233 
01234   assert(image_info != (const ImageInfo *) NULL);
01235   assert(image_info->signature == MagickSignature);
01236   if (image_info->debug != MagickFalse)
01237     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
01238       image_info->filename);
01239   assert(stream_info != (StreamInfo *) NULL);
01240   assert(stream_info->signature == MagickSignature);
01241   assert(exception != (ExceptionInfo *) NULL);
01242   read_info=CloneImageInfo(image_info);
01243   stream_info->image_info=image_info;
01244   stream_info->exception=exception;
01245   read_info->client_data=(void *) stream_info;
01246   image=ReadStream(read_info,&WriteStreamImage,exception);
01247   read_info=DestroyImageInfo(read_info);
01248   stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
01249   if (stream_info->quantum_info == (QuantumInfo *) NULL)
01250     image=DestroyImage(image);
01251   return(image);
01252 }
01253 
01254 /*
01255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01256 %                                                                             %
01257 %                                                                             %
01258 %                                                                             %
01259 +   S t r e a m I m a g e P i x e l s                                         %
01260 %                                                                             %
01261 %                                                                             %
01262 %                                                                             %
01263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01264 %
01265 %  StreamImagePixels() extracts pixel data from an image and returns it in the
01266 %  stream_info->pixels structure in the format as defined by
01267 %  stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
01268 %
01269 %  The format of the StreamImagePixels method is:
01270 %
01271 %      MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
01272 %        const Image *image,ExceptionInfo *exception)
01273 %
01274 %  A description of each parameter follows:
01275 %
01276 %    o stream_info: the stream info.
01277 %
01278 %    o image: the image.
01279 %
01280 %    o exception: return any errors or warnings in this structure.
01281 %
01282 */
01283 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
01284   const Image *image,ExceptionInfo *exception)
01285 {
01286   QuantumInfo
01287     *quantum_info;
01288 
01289   QuantumType
01290     *quantum_map;
01291 
01292   register const Quantum
01293     *p;
01294 
01295   register ssize_t
01296     i,
01297     x;
01298 
01299   size_t
01300     length;
01301 
01302   assert(stream_info != (StreamInfo *) NULL);
01303   assert(stream_info->signature == MagickSignature);
01304   assert(image != (Image *) NULL);
01305   assert(image->signature == MagickSignature);
01306   if (image->debug != MagickFalse)
01307     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
01308   length=strlen(stream_info->map);
01309   quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
01310   if (quantum_map == (QuantumType *) NULL)
01311     {
01312       (void) ThrowMagickException(exception,GetMagickModule(),
01313         ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
01314       return(MagickFalse);
01315     }
01316   for (i=0; i < (ssize_t) length; i++)
01317   {
01318     switch (stream_info->map[i])
01319     {
01320       case 'A':
01321       case 'a':
01322       {
01323         quantum_map[i]=AlphaQuantum;
01324         break;
01325       }
01326       case 'B':
01327       case 'b':
01328       {
01329         quantum_map[i]=BlueQuantum;
01330         break;
01331       }
01332       case 'C':
01333       case 'c':
01334       {
01335         quantum_map[i]=CyanQuantum;
01336         if (image->colorspace == CMYKColorspace)
01337           break;
01338         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
01339         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
01340           "ColorSeparatedImageRequired","`%s'",stream_info->map);
01341         return(MagickFalse);
01342       }
01343       case 'g':
01344       case 'G':
01345       {
01346         quantum_map[i]=GreenQuantum;
01347         break;
01348       }
01349       case 'I':
01350       case 'i':
01351       {
01352         quantum_map[i]=IndexQuantum;
01353         break;
01354       }
01355       case 'K':
01356       case 'k':
01357       {
01358         quantum_map[i]=BlackQuantum;
01359         if (image->colorspace == CMYKColorspace)
01360           break;
01361         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
01362         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
01363           "ColorSeparatedImageRequired","`%s'",stream_info->map);
01364         return(MagickFalse);
01365       }
01366       case 'M':
01367       case 'm':
01368       {
01369         quantum_map[i]=MagentaQuantum;
01370         if (image->colorspace == CMYKColorspace)
01371           break;
01372         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
01373         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
01374           "ColorSeparatedImageRequired","`%s'",stream_info->map);
01375         return(MagickFalse);
01376       }
01377       case 'o':
01378       case 'O':
01379       {
01380         quantum_map[i]=OpacityQuantum;
01381         break;
01382       }
01383       case 'P':
01384       case 'p':
01385       {
01386         quantum_map[i]=UndefinedQuantum;
01387         break;
01388       }
01389       case 'R':
01390       case 'r':
01391       {
01392         quantum_map[i]=RedQuantum;
01393         break;
01394       }
01395       case 'Y':
01396       case 'y':
01397       {
01398         quantum_map[i]=YellowQuantum;
01399         if (image->colorspace == CMYKColorspace)
01400           break;
01401         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
01402         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
01403           "ColorSeparatedImageRequired","`%s'",stream_info->map);
01404         return(MagickFalse);
01405       }
01406       default:
01407       {
01408         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
01409         (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
01410           "UnrecognizedPixelMap","`%s'",stream_info->map);
01411         return(MagickFalse);
01412       }
01413     }
01414   }
01415   quantum_info=stream_info->quantum_info;
01416   switch (stream_info->storage_type)
01417   {
01418     case CharPixel:
01419     {
01420       register unsigned char
01421         *q;
01422 
01423       q=(unsigned char *) stream_info->pixels;
01424       if (LocaleCompare(stream_info->map,"BGR") == 0)
01425         {
01426           p=GetVirtualPixelQueue(image);
01427           if (p == (const Quantum *) NULL)
01428             break;
01429           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01430           {
01431             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
01432             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
01433             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
01434             p++;
01435           }
01436           break;
01437         }
01438       if (LocaleCompare(stream_info->map,"BGRA") == 0)
01439         {
01440           p=GetVirtualPixelQueue(image);
01441           if (p == (const Quantum *) NULL)
01442             break;
01443           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01444           {
01445             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
01446             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
01447             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
01448             *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
01449             p++;
01450           }
01451           break;
01452         }
01453       if (LocaleCompare(stream_info->map,"BGRP") == 0)
01454         {
01455           p=GetVirtualPixelQueue(image);
01456           if (p == (const Quantum *) NULL)
01457             break;
01458           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01459           {
01460             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
01461             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
01462             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
01463             *q++=ScaleQuantumToChar((Quantum) 0);
01464             p++;
01465           }
01466           break;
01467         }
01468       if (LocaleCompare(stream_info->map,"I") == 0)
01469         {
01470           p=GetVirtualPixelQueue(image);
01471           if (p == (const Quantum *) NULL)
01472             break;
01473           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01474           {
01475             *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
01476             p++;
01477           }
01478           break;
01479         }
01480       if (LocaleCompare(stream_info->map,"RGB") == 0)
01481         {
01482           p=GetVirtualPixelQueue(image);
01483           if (p == (const Quantum *) NULL)
01484             break;
01485           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01486           {
01487             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
01488             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
01489             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
01490             p++;
01491           }
01492           break;
01493         }
01494       if (LocaleCompare(stream_info->map,"RGBA") == 0)
01495         {
01496           p=GetVirtualPixelQueue(image);
01497           if (p == (const Quantum *) NULL)
01498             break;
01499           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01500           {
01501             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
01502             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
01503             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
01504             *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
01505             p++;
01506           }
01507           break;
01508         }
01509       if (LocaleCompare(stream_info->map,"RGBP") == 0)
01510         {
01511           p=GetVirtualPixelQueue(image);
01512           if (p == (const Quantum *) NULL)
01513             break;
01514           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01515           {
01516             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
01517             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
01518             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
01519             *q++=ScaleQuantumToChar((Quantum) 0);
01520             p++;
01521           }
01522           break;
01523         }
01524       p=GetVirtualPixelQueue(image);
01525       if (p == (const Quantum *) NULL)
01526         break;
01527       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01528       {
01529         for (i=0; i < (ssize_t) length; i++)
01530         {
01531           *q=0;
01532           switch (quantum_map[i])
01533           {
01534             case RedQuantum:
01535             case CyanQuantum:
01536             {
01537               *q=ScaleQuantumToChar(GetPixelRed(image,p));
01538               break;
01539             }
01540             case GreenQuantum:
01541             case MagentaQuantum:
01542             {
01543               *q=ScaleQuantumToChar(GetPixelGreen(image,p));
01544               break;
01545             }
01546             case BlueQuantum:
01547             case YellowQuantum:
01548             {
01549               *q=ScaleQuantumToChar(GetPixelBlue(image,p));
01550               break;
01551             }
01552             case AlphaQuantum:
01553             {
01554               *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
01555               break;
01556             }
01557             case OpacityQuantum:
01558             {
01559               *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
01560               break;
01561             }
01562             case BlackQuantum:
01563             {
01564               if (image->colorspace == CMYKColorspace)
01565                 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
01566               break;
01567             }
01568             case IndexQuantum:
01569             {
01570               *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
01571               break;
01572             }
01573             default:
01574               break;
01575           }
01576           q++;
01577         }
01578         p++;
01579       }
01580       break;
01581     }
01582     case DoublePixel:
01583     {
01584       register double
01585         *q;
01586 
01587       q=(double *) stream_info->pixels;
01588       if (LocaleCompare(stream_info->map,"BGR") == 0)
01589         {
01590           p=GetVirtualPixelQueue(image);
01591           if (p == (const Quantum *) NULL)
01592             break;
01593           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01594           {
01595             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
01596               quantum_info->scale+quantum_info->minimum);
01597             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
01598               quantum_info->scale+quantum_info->minimum);
01599             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
01600               quantum_info->scale+quantum_info->minimum);
01601             p++;
01602           }
01603           break;
01604         }
01605       if (LocaleCompare(stream_info->map,"BGRA") == 0)
01606         {
01607           p=GetVirtualPixelQueue(image);
01608           if (p == (const Quantum *) NULL)
01609             break;
01610           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01611           {
01612             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
01613               quantum_info->scale+quantum_info->minimum);
01614             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
01615               quantum_info->scale+quantum_info->minimum);
01616             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
01617               quantum_info->scale+quantum_info->minimum);
01618             *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
01619               quantum_info->scale+quantum_info->minimum);
01620             p++;
01621           }
01622           break;
01623         }
01624       if (LocaleCompare(stream_info->map,"BGRP") == 0)
01625         {
01626           p=GetVirtualPixelQueue(image);
01627           if (p == (const Quantum *) NULL)
01628             break;
01629           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01630           {
01631             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
01632               quantum_info->scale+quantum_info->minimum);
01633             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
01634               quantum_info->scale+quantum_info->minimum);
01635             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
01636               quantum_info->scale+quantum_info->minimum);
01637             *q++=0.0;
01638             p++;
01639           }
01640           break;
01641         }
01642       if (LocaleCompare(stream_info->map,"I") == 0)
01643         {
01644           p=GetVirtualPixelQueue(image);
01645           if (p == (const Quantum *) NULL)
01646             break;
01647           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01648           {
01649             *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
01650               quantum_info->scale+quantum_info->minimum);
01651             p++;
01652           }
01653           break;
01654         }
01655       if (LocaleCompare(stream_info->map,"RGB") == 0)
01656         {
01657           p=GetVirtualPixelQueue(image);
01658           if (p == (const Quantum *) NULL)
01659             break;
01660           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01661           {
01662             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
01663               quantum_info->scale+quantum_info->minimum);
01664             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
01665               quantum_info->scale+quantum_info->minimum);
01666             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
01667               quantum_info->scale+quantum_info->minimum);
01668             p++;
01669           }
01670           break;
01671         }
01672       if (LocaleCompare(stream_info->map,"RGBA") == 0)
01673         {
01674           p=GetVirtualPixelQueue(image);
01675           if (p == (const Quantum *) NULL)
01676             break;
01677           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01678           {
01679             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
01680               quantum_info->scale+quantum_info->minimum);
01681             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
01682               quantum_info->scale+quantum_info->minimum);
01683             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
01684               quantum_info->scale+quantum_info->minimum);
01685             *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
01686               quantum_info->scale+quantum_info->minimum);
01687             p++;
01688           }
01689           break;
01690         }
01691       if (LocaleCompare(stream_info->map,"RGBP") == 0)
01692         {
01693           p=GetVirtualPixelQueue(image);
01694           if (p == (const Quantum *) NULL)
01695             break;
01696           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01697           {
01698             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
01699               quantum_info->scale+quantum_info->minimum);
01700             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
01701               quantum_info->scale+quantum_info->minimum);
01702             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
01703               quantum_info->scale+quantum_info->minimum);
01704             *q++=0.0;
01705             p++;
01706           }
01707           break;
01708         }
01709       p=GetVirtualPixelQueue(image);
01710       if (p == (const Quantum *) NULL)
01711         break;
01712       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01713       {
01714         for (i=0; i < (ssize_t) length; i++)
01715         {
01716           *q=0;
01717           switch (quantum_map[i])
01718           {
01719             case RedQuantum:
01720             case CyanQuantum:
01721             {
01722               *q=(double) ((QuantumScale*GetPixelRed(image,p))*
01723                 quantum_info->scale+quantum_info->minimum);
01724               break;
01725             }
01726             case GreenQuantum:
01727             case MagentaQuantum:
01728             {
01729               *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
01730                 quantum_info->scale+quantum_info->minimum);
01731               break;
01732             }
01733             case BlueQuantum:
01734             case YellowQuantum:
01735             {
01736               *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
01737                 quantum_info->scale+quantum_info->minimum);
01738               break;
01739             }
01740             case AlphaQuantum:
01741             {
01742               *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
01743                 quantum_info->scale+quantum_info->minimum);
01744               break;
01745             }
01746             case OpacityQuantum:
01747             {
01748               *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
01749                 quantum_info->scale+quantum_info->minimum);
01750               break;
01751             }
01752             case BlackQuantum:
01753             {
01754               if (image->colorspace == CMYKColorspace)
01755                 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
01756                   quantum_info->scale+quantum_info->minimum);
01757               break;
01758             }
01759             case IndexQuantum:
01760             {
01761               *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
01762                 quantum_info->scale+quantum_info->minimum);
01763               break;
01764             }
01765             default:
01766               *q=0;
01767           }
01768           q++;
01769         }
01770         p++;
01771       }
01772       break;
01773     }
01774     case FloatPixel:
01775     {
01776       register float
01777         *q;
01778 
01779       q=(float *) stream_info->pixels;
01780       if (LocaleCompare(stream_info->map,"BGR") == 0)
01781         {
01782           p=GetVirtualPixelQueue(image);
01783           if (p == (const Quantum *) NULL)
01784             break;
01785           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01786           {
01787             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
01788               quantum_info->scale+quantum_info->minimum);
01789             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
01790               quantum_info->scale+quantum_info->minimum);
01791             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
01792               quantum_info->scale+quantum_info->minimum);
01793             p++;
01794           }
01795           break;
01796         }
01797       if (LocaleCompare(stream_info->map,"BGRA") == 0)
01798         {
01799           p=GetVirtualPixelQueue(image);
01800           if (p == (const Quantum *) NULL)
01801             break;
01802           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01803           {
01804             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
01805               quantum_info->scale+quantum_info->minimum);
01806             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
01807               quantum_info->scale+quantum_info->minimum);
01808             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
01809               quantum_info->scale+quantum_info->minimum);
01810             *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
01811               quantum_info->scale+quantum_info->minimum);
01812             p++;
01813           }
01814           break;
01815         }
01816       if (LocaleCompare(stream_info->map,"BGRP") == 0)
01817         {
01818           p=GetVirtualPixelQueue(image);
01819           if (p == (const Quantum *) NULL)
01820             break;
01821           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01822           {
01823             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
01824               quantum_info->scale+quantum_info->minimum);
01825             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
01826               quantum_info->scale+quantum_info->minimum);
01827             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
01828               quantum_info->scale+quantum_info->minimum);
01829             *q++=0.0;
01830             p++;
01831           }
01832           break;
01833         }
01834       if (LocaleCompare(stream_info->map,"I") == 0)
01835         {
01836           p=GetVirtualPixelQueue(image);
01837           if (p == (const Quantum *) NULL)
01838             break;
01839           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01840           {
01841             *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
01842               quantum_info->scale+quantum_info->minimum);
01843             p++;
01844           }
01845           break;
01846         }
01847       if (LocaleCompare(stream_info->map,"RGB") == 0)
01848         {
01849           p=GetVirtualPixelQueue(image);
01850           if (p == (const Quantum *) NULL)
01851             break;
01852           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01853           {
01854             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
01855               quantum_info->scale+quantum_info->minimum);
01856             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
01857               quantum_info->scale+quantum_info->minimum);
01858             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
01859               quantum_info->scale+quantum_info->minimum);
01860             p++;
01861           }
01862           break;
01863         }
01864       if (LocaleCompare(stream_info->map,"RGBA") == 0)
01865         {
01866           p=GetVirtualPixelQueue(image);
01867           if (p == (const Quantum *) NULL)
01868             break;
01869           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01870           {
01871             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
01872               quantum_info->scale+quantum_info->minimum);
01873             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
01874               quantum_info->scale+quantum_info->minimum);
01875             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
01876               quantum_info->scale+quantum_info->minimum);
01877             *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
01878               quantum_info->scale+quantum_info->minimum);
01879             p++;
01880           }
01881           break;
01882         }
01883       if (LocaleCompare(stream_info->map,"RGBP") == 0)
01884         {
01885           p=GetVirtualPixelQueue(image);
01886           if (p == (const Quantum *) NULL)
01887             break;
01888           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01889           {
01890             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
01891               quantum_info->scale+quantum_info->minimum);
01892             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
01893               quantum_info->scale+quantum_info->minimum);
01894             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
01895               quantum_info->scale+quantum_info->minimum);
01896             *q++=0.0;
01897             p++;
01898           }
01899           break;
01900         }
01901       p=GetVirtualPixelQueue(image);
01902       if (p == (const Quantum *) NULL)
01903         break;
01904       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01905       {
01906         for (i=0; i < (ssize_t) length; i++)
01907         {
01908           *q=0;
01909           switch (quantum_map[i])
01910           {
01911             case RedQuantum:
01912             case CyanQuantum:
01913             {
01914               *q=(float) ((QuantumScale*GetPixelRed(image,p))*
01915                 quantum_info->scale+quantum_info->minimum);
01916               break;
01917             }
01918             case GreenQuantum:
01919             case MagentaQuantum:
01920             {
01921               *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
01922                 quantum_info->scale+quantum_info->minimum);
01923               break;
01924             }
01925             case BlueQuantum:
01926             case YellowQuantum:
01927             {
01928               *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
01929                 quantum_info->scale+quantum_info->minimum);
01930               break;
01931             }
01932             case AlphaQuantum:
01933             {
01934               *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
01935                 quantum_info->scale+quantum_info->minimum);
01936               break;
01937             }
01938             case OpacityQuantum:
01939             {
01940               *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
01941                 quantum_info->scale+quantum_info->minimum);
01942               break;
01943             }
01944             case BlackQuantum:
01945             {
01946               if (image->colorspace == CMYKColorspace)
01947                 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
01948                   quantum_info->scale+quantum_info->minimum);
01949               break;
01950             }
01951             case IndexQuantum:
01952             {
01953               *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
01954                 quantum_info->scale+quantum_info->minimum);
01955               break;
01956             }
01957             default:
01958               *q=0;
01959           }
01960           q++;
01961         }
01962         p++;
01963       }
01964       break;
01965     }
01966     case LongPixel:
01967     {
01968       register unsigned int
01969         *q;
01970 
01971       q=(unsigned int *) stream_info->pixels;
01972       if (LocaleCompare(stream_info->map,"BGR") == 0)
01973         {
01974           p=GetVirtualPixelQueue(image);
01975           if (p == (const Quantum *) NULL)
01976             break;
01977           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01978           {
01979             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
01980             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
01981             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
01982             p++;
01983           }
01984           break;
01985         }
01986       if (LocaleCompare(stream_info->map,"BGRA") == 0)
01987         {
01988           p=GetVirtualPixelQueue(image);
01989           if (p == (const Quantum *) NULL)
01990             break;
01991           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
01992           {
01993             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
01994             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
01995             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
01996             *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
01997             p++;
01998           }
01999           break;
02000         }
02001       if (LocaleCompare(stream_info->map,"BGRP") == 0)
02002         {
02003           p=GetVirtualPixelQueue(image);
02004           if (p == (const Quantum *) NULL)
02005             break;
02006           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02007           {
02008             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
02009             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
02010             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
02011             *q++=0;
02012             p++;
02013           }
02014           break;
02015         }
02016       if (LocaleCompare(stream_info->map,"I") == 0)
02017         {
02018           p=GetVirtualPixelQueue(image);
02019           if (p == (const Quantum *) NULL)
02020             break;
02021           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02022           {
02023             *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
02024             p++;
02025           }
02026           break;
02027         }
02028       if (LocaleCompare(stream_info->map,"RGB") == 0)
02029         {
02030           p=GetVirtualPixelQueue(image);
02031           if (p == (const Quantum *) NULL)
02032             break;
02033           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02034           {
02035             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
02036             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
02037             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
02038             p++;
02039           }
02040           break;
02041         }
02042       if (LocaleCompare(stream_info->map,"RGBA") == 0)
02043         {
02044           p=GetVirtualPixelQueue(image);
02045           if (p == (const Quantum *) NULL)
02046             break;
02047           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02048           {
02049             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
02050             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
02051             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
02052             *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
02053             p++;
02054           }
02055           break;
02056         }
02057       if (LocaleCompare(stream_info->map,"RGBP") == 0)
02058         {
02059           p=GetVirtualPixelQueue(image);
02060           if (p == (const Quantum *) NULL)
02061             break;
02062           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02063           {
02064             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
02065             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
02066             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
02067             *q++=0;
02068             p++;
02069           }
02070           break;
02071         }
02072       p=GetVirtualPixelQueue(image);
02073       if (p == (const Quantum *) NULL)
02074         break;
02075       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02076       {
02077         for (i=0; i < (ssize_t) length; i++)
02078         {
02079           *q=0;
02080           switch (quantum_map[i])
02081           {
02082             case RedQuantum:
02083             case CyanQuantum:
02084             {
02085               *q=ScaleQuantumToLong(GetPixelRed(image,p));
02086               break;
02087             }
02088             case GreenQuantum:
02089             case MagentaQuantum:
02090             {
02091               *q=ScaleQuantumToLong(GetPixelGreen(image,p));
02092               break;
02093             }
02094             case BlueQuantum:
02095             case YellowQuantum:
02096             {
02097               *q=ScaleQuantumToLong(GetPixelBlue(image,p));
02098               break;
02099             }
02100             case AlphaQuantum:
02101             {
02102               *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
02103               break;
02104             }
02105             case OpacityQuantum:
02106             {
02107               *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
02108               break;
02109             }
02110             case BlackQuantum:
02111             {
02112               if (image->colorspace == CMYKColorspace)
02113                 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
02114               break;
02115             }
02116             case IndexQuantum:
02117             {
02118               *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
02119               break;
02120             }
02121             default:
02122               break;
02123           }
02124           q++;
02125         }
02126         p++;
02127       }
02128       break;
02129     }
02130     case LongLongPixel:
02131     {
02132       register MagickSizeType
02133         *q;
02134 
02135       q=(MagickSizeType *) stream_info->pixels;
02136       if (LocaleCompare(stream_info->map,"BGR") == 0)
02137         {
02138           p=GetVirtualPixelQueue(image);
02139           if (p == (const Quantum *) NULL)
02140             break;
02141           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02142           {
02143             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02144             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02145             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
02146             p++;
02147           }
02148           break;
02149         }
02150       if (LocaleCompare(stream_info->map,"BGRA") == 0)
02151         {
02152           p=GetVirtualPixelQueue(image);
02153           if (p == (const Quantum *) NULL)
02154             break;
02155           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02156           {
02157             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02158             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02159             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
02160             *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
02161             p++;
02162           }
02163           break;
02164         }
02165       if (LocaleCompare(stream_info->map,"BGRP") == 0)
02166         {
02167           p=GetVirtualPixelQueue(image);
02168           if (p == (const Quantum *) NULL)
02169             break;
02170           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02171           {
02172             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02173             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02174             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
02175             *q++=0U;
02176             p++;
02177           }
02178           break;
02179         }
02180       if (LocaleCompare(stream_info->map,"I") == 0)
02181         {
02182           p=GetVirtualPixelQueue(image);
02183           if (p == (const Quantum *) NULL)
02184             break;
02185           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02186           {
02187             *q++=ScaleQuantumToLongLong(
02188               GetPixelIntensity(image,p));
02189             p++;
02190           }
02191           break;
02192         }
02193       if (LocaleCompare(stream_info->map,"RGB") == 0)
02194         {
02195           p=GetVirtualPixelQueue(image);
02196           if (p == (const Quantum *) NULL)
02197             break;
02198           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02199           {
02200             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
02201             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02202             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02203             p++;
02204           }
02205           break;
02206         }
02207       if (LocaleCompare(stream_info->map,"RGBA") == 0)
02208         {
02209           p=GetVirtualPixelQueue(image);
02210           if (p == (const Quantum *) NULL)
02211             break;
02212           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02213           {
02214             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
02215             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02216             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02217             *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
02218             p++;
02219           }
02220           break;
02221         }
02222       if (LocaleCompare(stream_info->map,"RGBP") == 0)
02223         {
02224           p=GetVirtualPixelQueue(image);
02225           if (p == (const Quantum *) NULL)
02226             break;
02227           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02228           {
02229             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
02230             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02231             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02232             *q++=0U;
02233             p++;
02234           }
02235           break;
02236         }
02237       p=GetVirtualPixelQueue(image);
02238       if (p == (const Quantum *) NULL)
02239         break;
02240       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02241       {
02242         for (i=0; i < (ssize_t) length; i++)
02243         {
02244           *q=0;
02245           switch (quantum_map[i])
02246           {
02247             case RedQuantum:
02248             case CyanQuantum:
02249             {
02250               *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
02251               break;
02252             }
02253             case GreenQuantum:
02254             case MagentaQuantum:
02255             {
02256               *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
02257               break;
02258             }
02259             case BlueQuantum:
02260             case YellowQuantum:
02261             {
02262               *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
02263               break;
02264             }
02265             case AlphaQuantum:
02266             {
02267               *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
02268               break;
02269             }
02270             case OpacityQuantum:
02271             {
02272               *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
02273               break;
02274             }
02275             case BlackQuantum:
02276             {
02277               if (image->colorspace == CMYKColorspace)
02278                 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
02279               break;
02280             }
02281             case IndexQuantum:
02282             {
02283               *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
02284               break;
02285             }
02286             default:
02287               *q=0;
02288           }
02289           q++;
02290         }
02291         p++;
02292       }
02293       break;
02294     }
02295     case QuantumPixel:
02296     {
02297       register Quantum
02298         *q;
02299 
02300       q=(Quantum *) stream_info->pixels;
02301       if (LocaleCompare(stream_info->map,"BGR") == 0)
02302         {
02303           p=GetVirtualPixelQueue(image);
02304           if (p == (const Quantum *) NULL)
02305             break;
02306           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02307           {
02308             *q++=GetPixelBlue(image,p);
02309             *q++=GetPixelGreen(image,p);
02310             *q++=GetPixelRed(image,p);
02311             p++;
02312           }
02313           break;
02314         }
02315       if (LocaleCompare(stream_info->map,"BGRA") == 0)
02316         {
02317           p=GetVirtualPixelQueue(image);
02318           if (p == (const Quantum *) NULL)
02319             break;
02320           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02321           {
02322             *q++=GetPixelBlue(image,p);
02323             *q++=GetPixelGreen(image,p);
02324             *q++=GetPixelRed(image,p);
02325             *q++=GetPixelAlpha(image,p);
02326             p++;
02327           }
02328           break;
02329         }
02330       if (LocaleCompare(stream_info->map,"BGRP") == 0)
02331         {
02332           p=GetVirtualPixelQueue(image);
02333           if (p == (const Quantum *) NULL)
02334             break;
02335           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02336           {
02337             *q++=GetPixelBlue(image,p);
02338             *q++=GetPixelGreen(image,p);
02339             *q++=GetPixelRed(image,p);
02340             *q++=0;
02341             p++;
02342           }
02343           break;
02344         }
02345       if (LocaleCompare(stream_info->map,"I") == 0)
02346         {
02347           p=GetVirtualPixelQueue(image);
02348           if (p == (const Quantum *) NULL)
02349             break;
02350           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02351           {
02352             *q++=GetPixelIntensity(image,p);
02353             p++;
02354           }
02355           break;
02356         }
02357       if (LocaleCompare(stream_info->map,"RGB") == 0)
02358         {
02359           p=GetVirtualPixelQueue(image);
02360           if (p == (const Quantum *) NULL)
02361             break;
02362           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02363           {
02364             *q++=GetPixelRed(image,p);
02365             *q++=GetPixelGreen(image,p);
02366             *q++=GetPixelBlue(image,p);
02367             p++;
02368           }
02369           break;
02370         }
02371       if (LocaleCompare(stream_info->map,"RGBA") == 0)
02372         {
02373           p=GetVirtualPixelQueue(image);
02374           if (p == (const Quantum *) NULL)
02375             break;
02376           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02377           {
02378             *q++=GetPixelRed(image,p);
02379             *q++=GetPixelGreen(image,p);
02380             *q++=GetPixelBlue(image,p);
02381             *q++=GetPixelAlpha(image,p);
02382             p++;
02383           }
02384           break;
02385         }
02386       if (LocaleCompare(stream_info->map,"RGBP") == 0)
02387         {
02388           p=GetVirtualPixelQueue(image);
02389           if (p == (const Quantum *) NULL)
02390             break;
02391           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02392           {
02393             *q++=GetPixelRed(image,p);
02394             *q++=GetPixelGreen(image,p);
02395             *q++=GetPixelBlue(image,p);
02396             *q++=0U;
02397             p++;
02398           }
02399           break;
02400         }
02401       p=GetVirtualPixelQueue(image);
02402       if (p == (const Quantum *) NULL)
02403         break;
02404       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02405       {
02406         for (i=0; i < (ssize_t) length; i++)
02407         {
02408           *q=(Quantum) 0;
02409           switch (quantum_map[i])
02410           {
02411             case RedQuantum:
02412             case CyanQuantum:
02413             {
02414               *q=GetPixelRed(image,p);
02415               break;
02416             }
02417             case GreenQuantum:
02418             case MagentaQuantum:
02419             {
02420               *q=GetPixelGreen(image,p);
02421               break;
02422             }
02423             case BlueQuantum:
02424             case YellowQuantum:
02425             {
02426               *q=GetPixelBlue(image,p);
02427               break;
02428             }
02429             case AlphaQuantum:
02430             {
02431               *q=(Quantum) (GetPixelAlpha(image,p));
02432               break;
02433             }
02434             case OpacityQuantum:
02435             {
02436               *q=GetPixelAlpha(image,p);
02437               break;
02438             }
02439             case BlackQuantum:
02440             {
02441               if (image->colorspace == CMYKColorspace)
02442                 *q=GetPixelBlack(image,p);
02443               break;
02444             }
02445             case IndexQuantum:
02446             {
02447               *q=GetPixelIntensity(image,p);
02448               break;
02449             }
02450             default:
02451               *q=0;
02452           }
02453           q++;
02454         }
02455         p++;
02456       }
02457       break;
02458     }
02459     case ShortPixel:
02460     {
02461       register unsigned short
02462         *q;
02463 
02464       q=(unsigned short *) stream_info->pixels;
02465       if (LocaleCompare(stream_info->map,"BGR") == 0)
02466         {
02467           p=GetVirtualPixelQueue(image);
02468           if (p == (const Quantum *) NULL)
02469             break;
02470           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02471           {
02472             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
02473             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
02474             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
02475             p++;
02476           }
02477           break;
02478         }
02479       if (LocaleCompare(stream_info->map,"BGRA") == 0)
02480         {
02481           p=GetVirtualPixelQueue(image);
02482           if (p == (const Quantum *) NULL)
02483             break;
02484           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02485           {
02486             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
02487             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
02488             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
02489             *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
02490             p++;
02491           }
02492           break;
02493         }
02494       if (LocaleCompare(stream_info->map,"BGRP") == 0)
02495         {
02496           p=GetVirtualPixelQueue(image);
02497             if (p == (const Quantum *) NULL)
02498             break;
02499           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02500           {
02501             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
02502             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
02503             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
02504             *q++=0;
02505             p++;
02506           }
02507           break;
02508         }
02509       if (LocaleCompare(stream_info->map,"I") == 0)
02510         {
02511           p=GetVirtualPixelQueue(image);
02512           if (p == (const Quantum *) NULL)
02513             break;
02514           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02515           {
02516             *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
02517             p++;
02518           }
02519           break;
02520         }
02521       if (LocaleCompare(stream_info->map,"RGB") == 0)
02522         {
02523           p=GetVirtualPixelQueue(image);
02524           if (p == (const Quantum *) NULL)
02525             break;
02526           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02527           {
02528             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
02529             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
02530             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
02531             p++;
02532           }
02533           break;
02534         }
02535       if (LocaleCompare(stream_info->map,"RGBA") == 0)
02536         {
02537           p=GetVirtualPixelQueue(image);
02538           if (p == (const Quantum *) NULL)
02539             break;
02540           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02541           {
02542             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
02543             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
02544             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
02545             *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
02546             p++;
02547           }
02548           break;
02549         }
02550       if (LocaleCompare(stream_info->map,"RGBP") == 0)
02551         {
02552           p=GetVirtualPixelQueue(image);
02553           if (p == (const Quantum *) NULL)
02554             break;
02555           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02556           {
02557             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
02558             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
02559             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
02560             *q++=0;
02561             p++;
02562           }
02563           break;
02564         }
02565       p=GetVirtualPixelQueue(image);
02566       if (p == (const Quantum *) NULL)
02567         break;
02568       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
02569       {
02570         for (i=0; i < (ssize_t) length; i++)
02571         {
02572           *q=0;
02573           switch (quantum_map[i])
02574           {
02575             case RedQuantum:
02576             case CyanQuantum:
02577             {
02578               *q=ScaleQuantumToShort(GetPixelRed(image,p));
02579               break;
02580             }
02581             case GreenQuantum:
02582             case MagentaQuantum:
02583             {
02584               *q=ScaleQuantumToShort(GetPixelGreen(image,p));
02585               break;
02586             }
02587             case BlueQuantum:
02588             case YellowQuantum:
02589             {
02590               *q=ScaleQuantumToShort(GetPixelBlue(image,p));
02591               break;
02592             }
02593             case AlphaQuantum:
02594             {
02595               *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
02596               break;
02597             }
02598             case OpacityQuantum:
02599             {
02600               *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
02601               break;
02602             }
02603             case BlackQuantum:
02604             {
02605               if (image->colorspace == CMYKColorspace)
02606                 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
02607               break;
02608             }
02609             case IndexQuantum:
02610             {
02611               *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
02612               break;
02613             }
02614             default:
02615               break;
02616           }
02617           q++;
02618         }
02619         p++;
02620       }
02621       break;
02622     }
02623     default:
02624     {
02625       quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
02626       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
02627         "UnrecognizedPixelMap","`%s'",stream_info->map);
02628       break;
02629     }
02630   }
02631   quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
02632   return(MagickTrue);
02633 }
02634 
02635 /*
02636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02637 %                                                                             %
02638 %                                                                             %
02639 %                                                                             %
02640 +   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                         %
02641 %                                                                             %
02642 %                                                                             %
02643 %                                                                             %
02644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02645 %
02646 %  SyncAuthenticPixelsStream() calls the user supplied callback method with
02647 %  the latest stream of pixels.
02648 %
02649 %  The format of the SyncAuthenticPixelsStream method is:
02650 %
02651 %      MagickBooleanType SyncAuthenticPixelsStream(Image *image,
02652 %        ExceptionInfo *exception)
02653 %
02654 %  A description of each parameter follows:
02655 %
02656 %    o image: the image.
02657 %
02658 %    o exception: return any errors or warnings in this structure.
02659 %
02660 */
02661 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
02662   ExceptionInfo *exception)
02663 {
02664   CacheInfo
02665     *cache_info;
02666 
02667   size_t
02668     length;
02669 
02670   StreamHandler
02671     stream_handler;
02672 
02673   assert(image != (Image *) NULL);
02674   assert(image->signature == MagickSignature);
02675   if (image->debug != MagickFalse)
02676     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
02677   cache_info=(CacheInfo *) image->cache;
02678   assert(cache_info->signature == MagickSignature);
02679   stream_handler=GetBlobStreamHandler(image);
02680   if (stream_handler == (StreamHandler) NULL)
02681     {
02682       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
02683         "NoStreamHandlerIsDefined","`%s'",image->filename);
02684       return(MagickFalse);
02685     }
02686   length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
02687   return(length == cache_info->columns ? MagickTrue : MagickFalse);
02688 }
02689 
02690 /*
02691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02692 %                                                                             %
02693 %                                                                             %
02694 %                                                                             %
02695 %   W r i t e S t r e a m                                                     %
02696 %                                                                             %
02697 %                                                                             %
02698 %                                                                             %
02699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02700 %
02701 %  WriteStream() makes the image pixels available to a user supplied callback
02702 %  method immediately upon writing pixel data with the WriteImage() method.
02703 %
02704 %  The format of the WriteStream() method is:
02705 %
02706 %      MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
02707 %        StreamHandler stream,ExceptionInfo *exception)
02708 %
02709 %  A description of each parameter follows:
02710 %
02711 %    o image_info: the image info.
02712 %
02713 %    o stream: A callback method.
02714 %
02715 %    o exception: return any errors or warnings in this structure.
02716 %
02717 */
02718 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
02719   Image *image,StreamHandler stream,ExceptionInfo *exception)
02720 {
02721   ImageInfo
02722     *write_info;
02723 
02724   MagickBooleanType
02725     status;
02726 
02727   assert(image_info != (ImageInfo *) NULL);
02728   assert(image_info->signature == MagickSignature);
02729   if (image_info->debug != MagickFalse)
02730     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
02731       image_info->filename);
02732   assert(image != (Image *) NULL);
02733   assert(image->signature == MagickSignature);
02734   write_info=CloneImageInfo(image_info);
02735   write_info->stream=stream;
02736   status=WriteImage(write_info,image,exception);
02737   write_info=DestroyImageInfo(write_info);
02738   return(status);
02739 }