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