]> granicus.if.org Git - imagemagick/blob - MagickCore/stream.c
Fixes for unused parameters.
[imagemagick] / MagickCore / stream.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                  SSSSS  TTTTT  RRRR   EEEEE   AAA   M   M                   %
7 %                  SS       T    R   R  E      A   A  MM MM                   %
8 %                   SSS     T    RRRR   EEE    AAAAA  M M M                   %
9 %                     SS    T    R R    E      A   A  M   M                   %
10 %                  SSSSS    T    R  R   EEEEE  A   A  M   M                   %
11 %                                                                             %
12 %                                                                             %
13 %                       MagickCore Pixel Stream Methods                       %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                   Cristy                                    %
17 %                                 March 2000                                  %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/cache-private.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/composite-private.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/geometry.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/memory-private.h"
56 #include "MagickCore/pixel.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/quantum.h"
59 #include "MagickCore/quantum-private.h"
60 #include "MagickCore/semaphore.h"
61 #include "MagickCore/stream.h"
62 #include "MagickCore/stream-private.h"
63 #include "MagickCore/string_.h"
64 \f
65 /*
66   Typedef declaractions.
67 */
68 struct _StreamInfo
69 {
70   const ImageInfo
71     *image_info;
72
73   const Image
74     *image;
75
76   Image
77     *stream;
78
79   QuantumInfo
80     *quantum_info;
81
82   char
83     *map;
84
85   StorageType
86     storage_type;
87
88   unsigned char
89     *pixels;
90
91   RectangleInfo
92     extract_info;
93
94   ssize_t
95     y;
96
97   ExceptionInfo
98     *exception;
99
100   const void
101     *client_data;
102
103   size_t
104     signature;
105 };
106 \f
107 /*
108   Declare pixel cache interfaces.
109 */
110 #if defined(__cplusplus) || defined(c_plusplus)
111 extern "C" {
112 #endif
113
114 static const Quantum
115   *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
116     const ssize_t,const size_t,const size_t,ExceptionInfo *);
117
118 static MagickBooleanType
119   StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
120   SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
121
122 static Quantum
123   *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
124     const size_t,ExceptionInfo *);
125
126 #if defined(__cplusplus) || defined(c_plusplus)
127 }
128 #endif
129 \f
130 /*
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 %                                                                             %
133 %                                                                             %
134 %                                                                             %
135 +   A c q u i r e S t r e a m I n f o                                         %
136 %                                                                             %
137 %                                                                             %
138 %                                                                             %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 %
141 %  AcquireStreamInfo() allocates the StreamInfo structure.
142 %
143 %  The format of the AcquireStreamInfo method is:
144 %
145 %      StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
146 %        ExceptionInfo *exception)
147 %
148 %  A description of each parameter follows:
149 %
150 %    o image_info: the image info.
151 %
152 %    o exception: return any errors or warnings in this structure.
153 %
154 */
155 MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
156   ExceptionInfo *exception)
157 {
158   StreamInfo
159     *stream_info;
160
161   stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
162   if (stream_info == (StreamInfo *) NULL)
163     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164   (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
165   stream_info->pixels=(unsigned char *) MagickAssumeAligned(
166     AcquireAlignedMemory(1,sizeof(*stream_info->pixels)));
167   if (stream_info->pixels == (unsigned char *) NULL)
168     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
169   stream_info->map=ConstantString("RGB");
170   stream_info->storage_type=CharPixel;
171   stream_info->stream=AcquireImage(image_info,exception);
172   stream_info->signature=MagickCoreSignature;
173   return(stream_info);
174 }
175 \f
176 /*
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 %                                                                             %
179 %                                                                             %
180 %                                                                             %
181 +   D e s t r o y P i x e l S t r e a m                                       %
182 %                                                                             %
183 %                                                                             %
184 %                                                                             %
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 %
187 %  DestroyPixelStream() deallocates memory associated with the pixel stream.
188 %
189 %  The format of the DestroyPixelStream() method is:
190 %
191 %      void DestroyPixelStream(Image *image)
192 %
193 %  A description of each parameter follows:
194 %
195 %    o image: the image.
196 %
197 */
198
199 static inline void RelinquishStreamPixels(CacheInfo *cache_info)
200 {
201   assert(cache_info != (CacheInfo *) NULL);
202   if (cache_info->mapped == MagickFalse)
203     (void) RelinquishAlignedMemory(cache_info->pixels);
204   else
205     (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
206   cache_info->pixels=(Quantum *) NULL;
207   cache_info->metacontent=(void *) NULL;
208   cache_info->length=0;
209   cache_info->mapped=MagickFalse;
210 }
211
212 static void DestroyPixelStream(Image *image)
213 {
214   CacheInfo
215     *cache_info;
216
217   MagickBooleanType
218     destroy;
219
220   assert(image != (Image *) NULL);
221   assert(image->signature == MagickCoreSignature);
222   if (image->debug != MagickFalse)
223     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
224   cache_info=(CacheInfo *) image->cache;
225   assert(cache_info->signature == MagickCoreSignature);
226   destroy=MagickFalse;
227   LockSemaphoreInfo(cache_info->semaphore);
228   cache_info->reference_count--;
229   if (cache_info->reference_count == 0)
230     destroy=MagickTrue;
231   UnlockSemaphoreInfo(cache_info->semaphore);
232   if (destroy == MagickFalse)
233     return;
234   RelinquishStreamPixels(cache_info);
235   if (cache_info->nexus_info != (NexusInfo **) NULL)
236     cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
237       cache_info->number_threads);
238   if (cache_info->file_semaphore != (SemaphoreInfo *) NULL)
239     RelinquishSemaphoreInfo(&cache_info->file_semaphore);
240   if (cache_info->semaphore != (SemaphoreInfo *) NULL)
241     RelinquishSemaphoreInfo(&cache_info->semaphore);
242   cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
243 }
244 \f
245 /*
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 %                                                                             %
248 %                                                                             %
249 %                                                                             %
250 +   D e s t r o y S t r e a m I n f o                                         %
251 %                                                                             %
252 %                                                                             %
253 %                                                                             %
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 %
256 %  DestroyStreamInfo() destroys memory associated with the StreamInfo
257 %  structure.
258 %
259 %  The format of the DestroyStreamInfo method is:
260 %
261 %      StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
262 %
263 %  A description of each parameter follows:
264 %
265 %    o stream_info: the stream info.
266 %
267 */
268 MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
269 {
270   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
271   assert(stream_info != (StreamInfo *) NULL);
272   assert(stream_info->signature == MagickCoreSignature);
273   if (stream_info->map != (char *) NULL)
274     stream_info->map=DestroyString(stream_info->map);
275   if (stream_info->pixels != (unsigned char *) NULL)
276     stream_info->pixels=(unsigned char *) RelinquishAlignedMemory(
277       stream_info->pixels);
278   if (stream_info->stream != (Image *) NULL)
279     {
280       (void) CloseBlob(stream_info->stream);
281       stream_info->stream=DestroyImage(stream_info->stream);
282     }
283   if (stream_info->quantum_info != (QuantumInfo *) NULL)
284     stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
285   stream_info->signature=(~MagickCoreSignature);
286   stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
287   return(stream_info);
288 }
289 \f
290 /*
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 %                                                                             %
293 %                                                                             %
294 %                                                                             %
295 +   G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m         %
296 %                                                                             %
297 %                                                                             %
298 %                                                                             %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 %
301 %  GetAuthenticMetacontentFromStream() returns the metacontent corresponding
302 %  with the last call to QueueAuthenticPixelsStream() or
303 %  GetAuthenticPixelsStream().
304 %
305 %  The format of the GetAuthenticMetacontentFromStream() method is:
306 %
307 %      void *GetAuthenticMetacontentFromStream(const Image *image)
308 %
309 %  A description of each parameter follows:
310 %
311 %    o image: the image.
312 %
313 */
314 static void *GetAuthenticMetacontentFromStream(const Image *image)
315 {
316   CacheInfo
317     *cache_info;
318
319   assert(image != (Image *) NULL);
320   assert(image->signature == MagickCoreSignature);
321   if (image->debug != MagickFalse)
322     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
323   cache_info=(CacheInfo *) image->cache;
324   assert(cache_info->signature == MagickCoreSignature);
325   return(cache_info->metacontent);
326 }
327 \f
328 /*
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 %                                                                             %
331 %                                                                             %
332 %                                                                             %
333 +   G e t A u t h e n t i c P i x e l S t r e a m                             %
334 %                                                                             %
335 %                                                                             %
336 %                                                                             %
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 %
339 %  GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
340 %  cache as defined by the geometry parameters.   A pointer to the pixels is
341 %  returned if the pixels are transferred, otherwise a NULL is returned.  For
342 %  streams this method is a no-op.
343 %
344 %  The format of the GetAuthenticPixelsStream() method is:
345 %
346 %      Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
347 %        const ssize_t y,const size_t columns,const size_t rows,
348 %        ExceptionInfo *exception)
349 %
350 %  A description of each parameter follows:
351 %
352 %    o image: the image.
353 %
354 %    o x,y,columns,rows:  These values define the perimeter of a region of
355 %      pixels.
356 %
357 %    o exception: return any errors or warnings in this structure.
358 %
359 */
360 static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
361   const ssize_t y,const size_t columns,const size_t rows,
362   ExceptionInfo *exception)
363 {
364   Quantum
365     *pixels;
366
367   assert(image != (Image *) NULL);
368   assert(image->signature == MagickCoreSignature);
369   if (image->debug != MagickFalse)
370     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
371   pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
372   return(pixels);
373 }
374 \f
375 /*
376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 %                                                                             %
378 %                                                                             %
379 %                                                                             %
380 +   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                       %
381 %                                                                             %
382 %                                                                             %
383 %                                                                             %
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 %
386 %  GetAuthenticPixelsFromStream() returns the pixels associated with the last
387 %  call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
388 %
389 %  The format of the GetAuthenticPixelsFromStream() method is:
390 %
391 %      Quantum *GetAuthenticPixelsFromStream(const Image image)
392 %
393 %  A description of each parameter follows:
394 %
395 %    o image: the image.
396 %
397 */
398 static Quantum *GetAuthenticPixelsFromStream(const Image *image)
399 {
400   CacheInfo
401     *cache_info;
402
403   assert(image != (Image *) NULL);
404   assert(image->signature == MagickCoreSignature);
405   if (image->debug != MagickFalse)
406     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
407   cache_info=(CacheInfo *) image->cache;
408   assert(cache_info->signature == MagickCoreSignature);
409   return(cache_info->pixels);
410 }
411 \f
412 /*
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 %                                                                             %
415 %                                                                             %
416 %                                                                             %
417 +   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               %
418 %                                                                             %
419 %                                                                             %
420 %                                                                             %
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 %
423 %  GetOneAuthenticPixelFromStream() returns a single pixel at the specified
424 %  (x,y) location.  The image background color is returned if an error occurs.
425 %
426 %  The format of the GetOneAuthenticPixelFromStream() method is:
427 %
428 %      MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
429 %        const ssize_t x,const ssize_t y,Quantum *pixel,
430 %        ExceptionInfo *exception)
431 %
432 %  A description of each parameter follows:
433 %
434 %    o image: the image.
435 %
436 %    o pixel: return a pixel at the specified (x,y) location.
437 %
438 %    o x,y:  These values define the location of the pixel to return.
439 %
440 %    o exception: return any errors or warnings in this structure.
441 %
442 */
443 static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
444   const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
445 {
446   register Quantum
447     *p;
448
449   register ssize_t
450     i;
451
452   assert(image != (Image *) NULL);
453   assert(image->signature == MagickCoreSignature);
454   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
455   p=GetAuthenticPixelsStream(image,x,y,1,1,exception);
456   if (p == (Quantum *) NULL)
457     {
458       pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
459       pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
460       pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
461       pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
462       pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
463       return(MagickFalse);
464     }
465   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
466   {
467     PixelChannel channel=GetPixelChannelChannel(image,i);
468     pixel[channel]=p[i];
469   }
470   return(MagickTrue);
471 }
472 \f
473 /*
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475 %                                                                             %
476 %                                                                             %
477 %                                                                             %
478 +   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                   %
479 %                                                                             %
480 %                                                                             %
481 %                                                                             %
482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 %
484 %  GetOneVirtualPixelFromStream() returns a single pixel at the specified
485 %  (x.y) location.  The image background color is returned if an error occurs.
486 %
487 %  The format of the GetOneVirtualPixelFromStream() method is:
488 %
489 %      MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
490 %        const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
491 %        const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
492 %
493 %  A description of each parameter follows:
494 %
495 %    o image: the image.
496 %
497 %    o virtual_pixel_method: the virtual pixel method.
498 %
499 %    o x,y:  These values define the location of the pixel to return.
500 %
501 %    o pixel: return a pixel at the specified (x,y) location.
502 %
503 %    o exception: return any errors or warnings in this structure.
504 %
505 */
506 static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
507   const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
508   Quantum *pixel,ExceptionInfo *exception)
509 {
510   const Quantum
511     *p;
512
513   register ssize_t
514     i;
515
516   assert(image != (Image *) NULL);
517   assert(image->signature == MagickCoreSignature);
518   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
519   p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
520   if (p == (const Quantum *) NULL)
521     {
522       pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
523       pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
524       pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
525       pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
526       pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
527       return(MagickFalse);
528     }
529   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
530   {
531     PixelChannel channel=GetPixelChannelChannel(image,i);
532     pixel[channel]=p[i];
533   }
534   return(MagickTrue);
535 }
536 \f
537 /*
538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 %                                                                             %
540 %                                                                             %
541 %                                                                             %
542 +   G e t S t r e a m I n f o C l i e n t D a t a                             %
543 %                                                                             %
544 %                                                                             %
545 %                                                                             %
546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 %
548 %  GetStreamInfoClientData() gets the stream info client data.
549 %
550 %  The format of the GetStreamInfoClientData method is:
551 %
552 %      const void *GetStreamInfoClientData(StreamInfo *stream_info)
553 %
554 %  A description of each parameter follows:
555 %
556 %    o stream_info: the stream info.
557 %
558 */
559 MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
560 {
561   assert(stream_info != (StreamInfo *) NULL);
562   assert(stream_info->signature == MagickCoreSignature);
563   return(stream_info->client_data);
564 }
565 \f
566 /*
567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
568 %                                                                             %
569 %                                                                             %
570 %                                                                             %
571 +   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                      %
572 %                                                                             %
573 %                                                                             %
574 %                                                                             %
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 %
577 %  GetVirtualPixelsStream() returns the pixels associated with the last
578 %  call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
579 %
580 %  The format of the GetVirtualPixelsStream() method is:
581 %
582 %      const Quantum *GetVirtualPixelsStream(const Image *image)
583 %
584 %  A description of each parameter follows:
585 %
586 %    o pixels: return the pixels associated corresponding with the last call to
587 %      QueueAuthenticPixelsStream() or GetVirtualPixelStream().
588 %
589 %    o image: the image.
590 %
591 */
592 static const Quantum *GetVirtualPixelsStream(const Image *image)
593 {
594   CacheInfo
595     *cache_info;
596
597   assert(image != (Image *) NULL);
598   assert(image->signature == MagickCoreSignature);
599   if (image->debug != MagickFalse)
600     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
601   cache_info=(CacheInfo *) image->cache;
602   assert(cache_info->signature == MagickCoreSignature);
603   return(cache_info->pixels);
604 }
605 \f
606 /*
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608 %                                                                             %
609 %                                                                             %
610 %                                                                             %
611 +   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                     %
612 %                                                                             %
613 %                                                                             %
614 %                                                                             %
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
616 %
617 %  GetVirtualMetacontentFromStream() returns the associated pixel channels
618 %  corresponding with the last call to QueueAuthenticPixelsStream() or
619 %  GetVirtualPixelStream().
620 %
621 %  The format of the GetVirtualMetacontentFromStream() method is:
622 %
623 %      const void *GetVirtualMetacontentFromStream(const Image *image)
624 %
625 %  A description of each parameter follows:
626 %
627 %    o image: the image.
628 %
629 */
630 static const void *GetVirtualMetacontentFromStream(const Image *image)
631 {
632   CacheInfo
633     *cache_info;
634
635   assert(image != (Image *) NULL);
636   assert(image->signature == MagickCoreSignature);
637   if (image->debug != MagickFalse)
638     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
639   cache_info=(CacheInfo *) image->cache;
640   assert(cache_info->signature == MagickCoreSignature);
641   return(cache_info->metacontent);
642 }
643 \f
644 /*
645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 %                                                                             %
647 %                                                                             %
648 %                                                                             %
649 +   G e t V i r t u a l P i x e l S t r e a m                                 %
650 %                                                                             %
651 %                                                                             %
652 %                                                                             %
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 %
655 %  GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
656 %  defined by the geometry parameters.   A pointer to the pixels is returned if
657 %  the pixels are transferred, otherwise a NULL is returned.  For streams this
658 %  method is a no-op.
659 %
660 %  The format of the GetVirtualPixelStream() method is:
661 %
662 %      const Quantum *GetVirtualPixelStream(const Image *image,
663 %        const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
664 %        const ssize_t y,const size_t columns,const size_t rows,
665 %        ExceptionInfo *exception)
666 %
667 %  A description of each parameter follows:
668 %
669 %    o image: the image.
670 %
671 %    o virtual_pixel_method: the virtual pixel method.
672 %
673 %    o x,y,columns,rows:  These values define the perimeter of a region of
674 %      pixels.
675 %
676 %    o exception: return any errors or warnings in this structure.
677 %
678 */
679
680 static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
681   ExceptionInfo *exception)
682 {
683   if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
684     return(MagickFalse);
685   cache_info->mapped=MagickFalse;
686   cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,(size_t)
687     cache_info->length);
688   if (cache_info->pixels == (Quantum *) NULL)
689     {
690       cache_info->mapped=MagickTrue;
691       cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
692         cache_info->length);
693     }
694   if (cache_info->pixels == (Quantum *) NULL)
695     {
696       (void) ThrowMagickException(exception,GetMagickModule(),
697         ResourceLimitError,"MemoryAllocationFailed","`%s'",
698         cache_info->filename);
699       return(MagickFalse);
700     }
701   return(MagickTrue);
702 }
703
704 static const Quantum *GetVirtualPixelStream(const Image *image,
705   const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
706   const ssize_t y,const size_t columns,const size_t rows,
707   ExceptionInfo *exception)
708 {
709   CacheInfo
710     *cache_info;
711
712   MagickBooleanType
713     status;
714
715   MagickSizeType
716     number_pixels;
717
718   size_t
719     length;
720
721   magick_unreferenced(virtual_pixel_method);
722
723   /*
724     Validate pixel cache geometry.
725   */
726   assert(image != (const Image *) NULL);
727   assert(image->signature == MagickCoreSignature);
728   if (image->debug != MagickFalse)
729     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
730   if ((x < 0) || (y < 0) ||
731       ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
732       ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
733       (columns == 0) || (rows == 0))
734     {
735       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
736         "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
737       return((Quantum *) NULL);
738     }
739   cache_info=(CacheInfo *) image->cache;
740   assert(cache_info->signature == MagickCoreSignature);
741   /*
742     Pixels are stored in a temporary buffer until they are synced to the cache.
743   */
744   number_pixels=(MagickSizeType) columns*rows;
745   length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
746   if (cache_info->number_channels == 0)
747     length=number_pixels*sizeof(Quantum);
748   if (cache_info->metacontent_extent != 0)
749     length+=number_pixels*cache_info->metacontent_extent;
750   if (cache_info->pixels == (Quantum *) NULL)
751     {
752       cache_info->length=length;
753       status=AcquireStreamPixels(cache_info,exception);
754       if (status == MagickFalse)
755         {
756           cache_info->length=0;
757           return((Quantum *) NULL);
758         }
759     }
760   else
761     if (cache_info->length < length)
762       {
763         RelinquishStreamPixels(cache_info);
764         cache_info->length=length;
765         status=AcquireStreamPixels(cache_info,exception);
766         if (status == MagickFalse)
767           {
768             cache_info->length=0;
769             return((Quantum *) NULL);
770           }
771       }
772   cache_info->metacontent=(void *) NULL;
773   if (cache_info->metacontent_extent != 0)
774     cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
775       cache_info->number_channels);
776   return(cache_info->pixels);
777 }
778 \f
779 /*
780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
781 %                                                                             %
782 %                                                                             %
783 %                                                                             %
784 +   O p e n S t r e a m                                                       %
785 %                                                                             %
786 %                                                                             %
787 %                                                                             %
788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
789 %
790 %  OpenStream() opens a stream for writing by the StreamImage() method.
791 %
792 %  The format of the OpenStream method is:
793 %
794 %       MagickBooleanType OpenStream(const ImageInfo *image_info,
795 %        StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
796 %
797 %  A description of each parameter follows:
798 %
799 %    o image_info: the image info.
800 %
801 %    o stream_info: the stream info.
802 %
803 %    o filename: the stream filename.
804 %
805 %    o exception: return any errors or warnings in this structure.
806 %
807 */
808 MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
809   StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
810 {
811   MagickBooleanType
812     status;
813
814   (void) CopyMagickString(stream_info->stream->filename,filename,MagickPathExtent);
815   status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
816   return(status);
817 }
818 \f
819 /*
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 %                                                                             %
822 %                                                                             %
823 %                                                                             %
824 +   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                       %
825 %                                                                             %
826 %                                                                             %
827 %                                                                             %
828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 %
830 %  QueueAuthenticPixelsStream() allocates an area to store image pixels as
831 %  defined by the region rectangle and returns a pointer to the area.  This
832 %  area is subsequently transferred from the pixel cache with method
833 %  SyncAuthenticPixelsStream().  A pointer to the pixels is returned if the
834 %  pixels are transferred, otherwise a NULL is returned.
835 %
836 %  The format of the QueueAuthenticPixelsStream() method is:
837 %
838 %      Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
839 %        const ssize_t y,const size_t columns,const size_t rows,
840 %        ExceptionInfo *exception)
841 %
842 %  A description of each parameter follows:
843 %
844 %    o image: the image.
845 %
846 %    o x,y,columns,rows:  These values define the perimeter of a region of
847 %      pixels.
848 %
849 */
850 static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
851   const ssize_t y,const size_t columns,const size_t rows,
852   ExceptionInfo *exception)
853 {
854   CacheInfo
855     *cache_info;
856
857   MagickBooleanType
858     status;
859
860   MagickSizeType
861     number_pixels;
862
863   size_t
864     length;
865
866   StreamHandler
867     stream_handler;
868
869   /*
870     Validate pixel cache geometry.
871   */
872   assert(image != (Image *) NULL);
873   if ((x < 0) || (y < 0) ||
874       ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
875       ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
876       (columns == 0) || (rows == 0))
877     {
878       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
879         "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
880       return((Quantum *) NULL);
881     }
882   stream_handler=GetBlobStreamHandler(image);
883   if (stream_handler == (StreamHandler) NULL)
884     {
885       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
886         "NoStreamHandlerIsDefined","`%s'",image->filename);
887       return((Quantum *) NULL);
888     }
889   cache_info=(CacheInfo *) image->cache;
890   assert(cache_info->signature == MagickCoreSignature);
891   if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
892       (image->colorspace != GetPixelCacheColorspace(image->cache)))
893     {
894       if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
895         (void) stream_handler(image,(const void *) NULL,(size_t)
896           cache_info->columns);
897       cache_info->storage_class=image->storage_class;
898       cache_info->colorspace=image->colorspace;
899       cache_info->columns=image->columns;
900       cache_info->rows=image->rows;
901       image->cache=cache_info;
902     }
903   /*
904     Pixels are stored in a temporary buffer until they are synced to the cache.
905   */
906   cache_info->columns=columns;
907   cache_info->rows=rows;
908   number_pixels=(MagickSizeType) columns*rows;
909   length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
910   if (cache_info->number_channels == 0)
911     length=number_pixels*sizeof(Quantum);
912   if (cache_info->metacontent_extent != 0)
913     length+=number_pixels*cache_info->metacontent_extent;
914   if (cache_info->pixels == (Quantum *) NULL)
915     {
916       cache_info->length=length;
917       status=AcquireStreamPixels(cache_info,exception);
918       if (status == MagickFalse)
919         {
920           cache_info->length=0;
921           return((Quantum *) NULL);
922         }
923     }
924   else
925     if (cache_info->length < length)
926       {
927         RelinquishStreamPixels(cache_info);
928         cache_info->length=length;
929         status=AcquireStreamPixels(cache_info,exception);
930         if (status == MagickFalse)
931           {
932             cache_info->length=0;
933             return((Quantum *) NULL);
934           }
935       }
936   cache_info->metacontent=(void *) NULL;
937   if (cache_info->metacontent_extent != 0)
938     cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
939       cache_info->number_channels);
940   return(cache_info->pixels);
941 }
942 \f
943 /*
944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
945 %                                                                             %
946 %                                                                             %
947 %                                                                             %
948 %   R e a d S t r e a m                                                       %
949 %                                                                             %
950 %                                                                             %
951 %                                                                             %
952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953 %
954 %  ReadStream() makes the image pixels available to a user supplied callback
955 %  method immediately upon reading a scanline with the ReadImage() method.
956 %
957 %  The format of the ReadStream() method is:
958 %
959 %      Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
960 %        ExceptionInfo *exception)
961 %
962 %  A description of each parameter follows:
963 %
964 %    o image_info: the image info.
965 %
966 %    o stream: a callback method.
967 %
968 %    o exception: return any errors or warnings in this structure.
969 %
970 */
971 MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
972   ExceptionInfo *exception)
973 {
974   CacheMethods
975     cache_methods;
976
977   Image
978     *image;
979
980   ImageInfo
981     *read_info;
982
983   /*
984     Stream image pixels.
985   */
986   assert(image_info != (ImageInfo *) NULL);
987   assert(image_info->signature == MagickCoreSignature);
988   if (image_info->debug != MagickFalse)
989     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
990       image_info->filename);
991   assert(exception != (ExceptionInfo *) NULL);
992   assert(exception->signature == MagickCoreSignature);
993   read_info=CloneImageInfo(image_info);
994   read_info->cache=AcquirePixelCache(0);
995   GetPixelCacheMethods(&cache_methods);
996   cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
997   cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
998   cache_methods.get_virtual_metacontent_from_handler=
999     GetVirtualMetacontentFromStream;
1000   cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
1001   cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1002   cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1003   cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1004   cache_methods.get_authentic_metacontent_from_handler=
1005     GetAuthenticMetacontentFromStream;
1006   cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1007   cache_methods.get_one_authentic_pixel_from_handler=
1008     GetOneAuthenticPixelFromStream;
1009   cache_methods.destroy_pixel_handler=DestroyPixelStream;
1010   SetPixelCacheMethods(read_info->cache,&cache_methods);
1011   read_info->stream=stream;
1012   image=ReadImage(read_info,exception);
1013   read_info=DestroyImageInfo(read_info);
1014   return(image);
1015 }
1016 \f
1017 /*
1018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1019 %                                                                             %
1020 %                                                                             %
1021 %                                                                             %
1022 +   S e t S t r e a m I n f o C l i e n t D a t a                             %
1023 %                                                                             %
1024 %                                                                             %
1025 %                                                                             %
1026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1027 %
1028 %  SetStreamInfoClientData() sets the stream info client data.
1029 %
1030 %  The format of the SetStreamInfoClientData method is:
1031 %
1032 %      void SetStreamInfoClientData(StreamInfo *stream_info,
1033 %        const void *client_data)
1034 %
1035 %  A description of each parameter follows:
1036 %
1037 %    o stream_info: the stream info.
1038 %
1039 %    o client_data: the client data.
1040 %
1041 */
1042 MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
1043   const void *client_data)
1044 {
1045   assert(stream_info != (StreamInfo *) NULL);
1046   assert(stream_info->signature == MagickCoreSignature);
1047   stream_info->client_data=client_data;
1048 }
1049 \f
1050 /*
1051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1052 %                                                                             %
1053 %                                                                             %
1054 %                                                                             %
1055 +   S e t S t r e a m I n f o M a p                                           %
1056 %                                                                             %
1057 %                                                                             %
1058 %                                                                             %
1059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060 %
1061 %  SetStreamInfoMap() sets the stream info map member.
1062 %
1063 %  The format of the SetStreamInfoMap method is:
1064 %
1065 %      void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1066 %
1067 %  A description of each parameter follows:
1068 %
1069 %    o stream_info: the stream info.
1070 %
1071 %    o map: the map.
1072 %
1073 */
1074 MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1075 {
1076   assert(stream_info != (StreamInfo *) NULL);
1077   assert(stream_info->signature == MagickCoreSignature);
1078   (void) CloneString(&stream_info->map,map);
1079 }
1080 \f
1081 /*
1082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1083 %                                                                             %
1084 %                                                                             %
1085 %                                                                             %
1086 +   S e t S t r e a m I n f o S t o r a g e T y p e                           %
1087 %                                                                             %
1088 %                                                                             %
1089 %                                                                             %
1090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091 %
1092 %  SetStreamInfoStorageType() sets the stream info storage type member.
1093 %
1094 %  The format of the SetStreamInfoStorageType method is:
1095 %
1096 %      void SetStreamInfoStorageType(StreamInfo *stream_info,
1097 %        const StoreageType *storage_type)
1098 %
1099 %  A description of each parameter follows:
1100 %
1101 %    o stream_info: the stream info.
1102 %
1103 %    o storage_type: the storage type.
1104 %
1105 */
1106 MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1107   const StorageType storage_type)
1108 {
1109   assert(stream_info != (StreamInfo *) NULL);
1110   assert(stream_info->signature == MagickCoreSignature);
1111   stream_info->storage_type=storage_type;
1112 }
1113 \f
1114 /*
1115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1116 %                                                                             %
1117 %                                                                             %
1118 %                                                                             %
1119 +   S t r e a m I m a g e                                                     %
1120 %                                                                             %
1121 %                                                                             %
1122 %                                                                             %
1123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1124 %
1125 %  StreamImage() streams pixels from an image and writes them in a user
1126 %  defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1127 %
1128 %  The format of the StreamImage() method is:
1129 %
1130 %      Image *StreamImage(const ImageInfo *image_info,
1131 %        StreamInfo *stream_info,ExceptionInfo *exception)
1132 %
1133 %  A description of each parameter follows:
1134 %
1135 %    o image_info: the image info.
1136 %
1137 %    o stream_info: the stream info.
1138 %
1139 %    o exception: return any errors or warnings in this structure.
1140 %
1141 */
1142
1143 #if defined(__cplusplus) || defined(c_plusplus)
1144 extern "C" {
1145 #endif
1146
1147 static size_t WriteStreamImage(const Image *image,const void *pixels,
1148   const size_t columns)
1149 {
1150   CacheInfo
1151     *cache_info;
1152
1153   RectangleInfo
1154     extract_info;
1155
1156   size_t
1157     length,
1158     packet_size;
1159
1160   ssize_t
1161     count;
1162
1163   StreamInfo
1164     *stream_info;
1165
1166   (void) pixels;
1167   stream_info=(StreamInfo *) image->client_data;
1168   switch (stream_info->storage_type)
1169   {
1170     default: packet_size=sizeof(unsigned char); break;
1171     case CharPixel: packet_size=sizeof(unsigned char); break;
1172     case DoublePixel: packet_size=sizeof(double); break;
1173     case FloatPixel: packet_size=sizeof(float); break;
1174     case LongPixel: packet_size=sizeof(unsigned int); break;
1175     case LongLongPixel: packet_size=sizeof(MagickSizeType); break;
1176     case QuantumPixel: packet_size=sizeof(Quantum); break;
1177     case ShortPixel: packet_size=sizeof(unsigned short); break;
1178   }
1179   cache_info=(CacheInfo *) image->cache;
1180   assert(cache_info->signature == MagickCoreSignature);
1181   packet_size*=strlen(stream_info->map);
1182   length=packet_size*cache_info->columns*cache_info->rows;
1183   if (image != stream_info->image)
1184     {
1185       ImageInfo
1186         *write_info;
1187
1188       /*
1189         Prepare stream for writing.
1190       */
1191       (void) RelinquishAlignedMemory(stream_info->pixels);
1192       stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
1193       if (stream_info->pixels == (unsigned char *) NULL)
1194         return(0);
1195       (void) ResetMagickMemory(stream_info->pixels,0,length);
1196       stream_info->image=image;
1197       write_info=CloneImageInfo(stream_info->image_info);
1198       (void) SetImageInfo(write_info,1,stream_info->exception);
1199       if (write_info->extract != (char *) NULL)
1200         (void) ParseAbsoluteGeometry(write_info->extract,
1201           &stream_info->extract_info);
1202       stream_info->y=0;
1203       write_info=DestroyImageInfo(write_info);
1204     }
1205   extract_info=stream_info->extract_info;
1206   if ((extract_info.width == 0) || (extract_info.height == 0))
1207     {
1208       /*
1209         Write all pixels to stream.
1210       */
1211       (void) StreamImagePixels(stream_info,image,stream_info->exception);
1212       count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1213       stream_info->y++;
1214       return(count == 0 ? 0 : columns);
1215     }
1216   if ((stream_info->y < extract_info.y) ||
1217       (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
1218     {
1219       stream_info->y++;
1220       return(columns);
1221     }
1222   /*
1223     Write a portion of the pixel row to the stream.
1224   */
1225   (void) StreamImagePixels(stream_info,image,stream_info->exception);
1226   length=packet_size*extract_info.width;
1227   count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1228     extract_info.x);
1229   stream_info->y++;
1230   return(count == 0 ? 0 : columns);
1231 }
1232
1233 #if defined(__cplusplus) || defined(c_plusplus)
1234 }
1235 #endif
1236
1237 MagickExport Image *StreamImage(const ImageInfo *image_info,
1238   StreamInfo *stream_info,ExceptionInfo *exception)
1239 {
1240   Image
1241     *image;
1242
1243   ImageInfo
1244     *read_info;
1245
1246   assert(image_info != (const ImageInfo *) NULL);
1247   assert(image_info->signature == MagickCoreSignature);
1248   if (image_info->debug != MagickFalse)
1249     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1250       image_info->filename);
1251   assert(stream_info != (StreamInfo *) NULL);
1252   assert(stream_info->signature == MagickCoreSignature);
1253   assert(exception != (ExceptionInfo *) NULL);
1254   read_info=CloneImageInfo(image_info);
1255   stream_info->image_info=image_info;
1256   stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
1257   stream_info->exception=exception;
1258   read_info->client_data=(void *) stream_info;
1259   image=ReadStream(read_info,&WriteStreamImage,exception);
1260   read_info=DestroyImageInfo(read_info);
1261   stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1262   stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1263   if (stream_info->quantum_info == (QuantumInfo *) NULL)
1264     image=DestroyImage(image);
1265   return(image);
1266 }
1267 \f
1268 /*
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1270 %                                                                             %
1271 %                                                                             %
1272 %                                                                             %
1273 +   S t r e a m I m a g e P i x e l s                                         %
1274 %                                                                             %
1275 %                                                                             %
1276 %                                                                             %
1277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1278 %
1279 %  StreamImagePixels() extracts pixel data from an image and returns it in the
1280 %  stream_info->pixels structure in the format as defined by
1281 %  stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1282 %
1283 %  The format of the StreamImagePixels method is:
1284 %
1285 %      MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1286 %        const Image *image,ExceptionInfo *exception)
1287 %
1288 %  A description of each parameter follows:
1289 %
1290 %    o stream_info: the stream info.
1291 %
1292 %    o image: the image.
1293 %
1294 %    o exception: return any errors or warnings in this structure.
1295 %
1296 */
1297 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1298   const Image *image,ExceptionInfo *exception)
1299 {
1300   QuantumInfo
1301     *quantum_info;
1302
1303   QuantumType
1304     *quantum_map;
1305
1306   register const Quantum
1307     *p;
1308
1309   register ssize_t
1310     i,
1311     x;
1312
1313   size_t
1314     length;
1315
1316   assert(stream_info != (StreamInfo *) NULL);
1317   assert(stream_info->signature == MagickCoreSignature);
1318   assert(image != (Image *) NULL);
1319   assert(image->signature == MagickCoreSignature);
1320   if (image->debug != MagickFalse)
1321     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1322   length=strlen(stream_info->map);
1323   quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1324   if (quantum_map == (QuantumType *) NULL)
1325     {
1326       (void) ThrowMagickException(exception,GetMagickModule(),
1327         ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1328       return(MagickFalse);
1329     }
1330   for (i=0; i < (ssize_t) length; i++)
1331   {
1332     switch (stream_info->map[i])
1333     {
1334       case 'A':
1335       case 'a':
1336       {
1337         quantum_map[i]=AlphaQuantum;
1338         break;
1339       }
1340       case 'B':
1341       case 'b':
1342       {
1343         quantum_map[i]=BlueQuantum;
1344         break;
1345       }
1346       case 'C':
1347       case 'c':
1348       {
1349         quantum_map[i]=CyanQuantum;
1350         if (image->colorspace == CMYKColorspace)
1351           break;
1352         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1353         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1354           "ColorSeparatedImageRequired","`%s'",stream_info->map);
1355         return(MagickFalse);
1356       }
1357       case 'g':
1358       case 'G':
1359       {
1360         quantum_map[i]=GreenQuantum;
1361         break;
1362       }
1363       case 'I':
1364       case 'i':
1365       {
1366         quantum_map[i]=IndexQuantum;
1367         break;
1368       }
1369       case 'K':
1370       case 'k':
1371       {
1372         quantum_map[i]=BlackQuantum;
1373         if (image->colorspace == CMYKColorspace)
1374           break;
1375         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1376         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1377           "ColorSeparatedImageRequired","`%s'",stream_info->map);
1378         return(MagickFalse);
1379       }
1380       case 'M':
1381       case 'm':
1382       {
1383         quantum_map[i]=MagentaQuantum;
1384         if (image->colorspace == CMYKColorspace)
1385           break;
1386         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1387         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1388           "ColorSeparatedImageRequired","`%s'",stream_info->map);
1389         return(MagickFalse);
1390       }
1391       case 'o':
1392       case 'O':
1393       {
1394         quantum_map[i]=OpacityQuantum;
1395         break;
1396       }
1397       case 'P':
1398       case 'p':
1399       {
1400         quantum_map[i]=UndefinedQuantum;
1401         break;
1402       }
1403       case 'R':
1404       case 'r':
1405       {
1406         quantum_map[i]=RedQuantum;
1407         break;
1408       }
1409       case 'Y':
1410       case 'y':
1411       {
1412         quantum_map[i]=YellowQuantum;
1413         if (image->colorspace == CMYKColorspace)
1414           break;
1415         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1416         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1417           "ColorSeparatedImageRequired","`%s'",stream_info->map);
1418         return(MagickFalse);
1419       }
1420       default:
1421       {
1422         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1423         (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1424           "UnrecognizedPixelMap","`%s'",stream_info->map);
1425         return(MagickFalse);
1426       }
1427     }
1428   }
1429   quantum_info=stream_info->quantum_info;
1430   switch (stream_info->storage_type)
1431   {
1432     case CharPixel:
1433     {
1434       register unsigned char
1435         *q;
1436
1437       q=(unsigned char *) stream_info->pixels;
1438       if (LocaleCompare(stream_info->map,"BGR") == 0)
1439         {
1440           p=GetAuthenticPixelQueue(image);
1441           if (p == (const Quantum *) NULL)
1442             break;
1443           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1444           {
1445             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1446             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1447             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1448             p++;
1449           }
1450           break;
1451         }
1452       if (LocaleCompare(stream_info->map,"BGRA") == 0)
1453         {
1454           p=GetAuthenticPixelQueue(image);
1455           if (p == (const Quantum *) NULL)
1456             break;
1457           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1458           {
1459             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1460             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1461             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1462             *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1463             p++;
1464           }
1465           break;
1466         }
1467       if (LocaleCompare(stream_info->map,"BGRP") == 0)
1468         {
1469           p=GetAuthenticPixelQueue(image);
1470           if (p == (const Quantum *) NULL)
1471             break;
1472           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1473           {
1474             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1475             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1476             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1477             *q++=ScaleQuantumToChar((Quantum) 0);
1478             p++;
1479           }
1480           break;
1481         }
1482       if (LocaleCompare(stream_info->map,"I") == 0)
1483         {
1484           p=GetAuthenticPixelQueue(image);
1485           if (p == (const Quantum *) NULL)
1486             break;
1487           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1488           {
1489             *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1490             p++;
1491           }
1492           break;
1493         }
1494       if (LocaleCompare(stream_info->map,"RGB") == 0)
1495         {
1496           p=GetAuthenticPixelQueue(image);
1497           if (p == (const Quantum *) NULL)
1498             break;
1499           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1500           {
1501             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1502             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1503             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1504             p++;
1505           }
1506           break;
1507         }
1508       if (LocaleCompare(stream_info->map,"RGBA") == 0)
1509         {
1510           p=GetAuthenticPixelQueue(image);
1511           if (p == (const Quantum *) NULL)
1512             break;
1513           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1514           {
1515             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1516             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1517             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1518             *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1519             p++;
1520           }
1521           break;
1522         }
1523       if (LocaleCompare(stream_info->map,"RGBP") == 0)
1524         {
1525           p=GetAuthenticPixelQueue(image);
1526           if (p == (const Quantum *) NULL)
1527             break;
1528           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1529           {
1530             *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1531             *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1532             *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1533             *q++=ScaleQuantumToChar((Quantum) 0);
1534             p++;
1535           }
1536           break;
1537         }
1538       p=GetAuthenticPixelQueue(image);
1539       if (p == (const Quantum *) NULL)
1540         break;
1541       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1542       {
1543         for (i=0; i < (ssize_t) length; i++)
1544         {
1545           *q=0;
1546           switch (quantum_map[i])
1547           {
1548             case RedQuantum:
1549             case CyanQuantum:
1550             {
1551               *q=ScaleQuantumToChar(GetPixelRed(image,p));
1552               break;
1553             }
1554             case GreenQuantum:
1555             case MagentaQuantum:
1556             {
1557               *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1558               break;
1559             }
1560             case BlueQuantum:
1561             case YellowQuantum:
1562             {
1563               *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1564               break;
1565             }
1566             case AlphaQuantum:
1567             {
1568               *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
1569               break;
1570             }
1571             case OpacityQuantum:
1572             {
1573               *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1574               break;
1575             }
1576             case BlackQuantum:
1577             {
1578               if (image->colorspace == CMYKColorspace)
1579                 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1580               break;
1581             }
1582             case IndexQuantum:
1583             {
1584               *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1585               break;
1586             }
1587             default:
1588               break;
1589           }
1590           q++;
1591         }
1592         p++;
1593       }
1594       break;
1595     }
1596     case DoublePixel:
1597     {
1598       register double
1599         *q;
1600
1601       q=(double *) stream_info->pixels;
1602       if (LocaleCompare(stream_info->map,"BGR") == 0)
1603         {
1604           p=GetAuthenticPixelQueue(image);
1605           if (p == (const Quantum *) NULL)
1606             break;
1607           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1608           {
1609             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1610               quantum_info->scale+quantum_info->minimum);
1611             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1612               quantum_info->scale+quantum_info->minimum);
1613             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1614               quantum_info->scale+quantum_info->minimum);
1615             p++;
1616           }
1617           break;
1618         }
1619       if (LocaleCompare(stream_info->map,"BGRA") == 0)
1620         {
1621           p=GetAuthenticPixelQueue(image);
1622           if (p == (const Quantum *) NULL)
1623             break;
1624           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1625           {
1626             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1627               quantum_info->scale+quantum_info->minimum);
1628             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1629               quantum_info->scale+quantum_info->minimum);
1630             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1631               quantum_info->scale+quantum_info->minimum);
1632             *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1633               quantum_info->scale+quantum_info->minimum);
1634             p++;
1635           }
1636           break;
1637         }
1638       if (LocaleCompare(stream_info->map,"BGRP") == 0)
1639         {
1640           p=GetAuthenticPixelQueue(image);
1641           if (p == (const Quantum *) NULL)
1642             break;
1643           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1644           {
1645             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1646               quantum_info->scale+quantum_info->minimum);
1647             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1648               quantum_info->scale+quantum_info->minimum);
1649             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1650               quantum_info->scale+quantum_info->minimum);
1651             *q++=0.0;
1652             p++;
1653           }
1654           break;
1655         }
1656       if (LocaleCompare(stream_info->map,"I") == 0)
1657         {
1658           p=GetAuthenticPixelQueue(image);
1659           if (p == (const Quantum *) NULL)
1660             break;
1661           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1662           {
1663             *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1664               quantum_info->scale+quantum_info->minimum);
1665             p++;
1666           }
1667           break;
1668         }
1669       if (LocaleCompare(stream_info->map,"RGB") == 0)
1670         {
1671           p=GetAuthenticPixelQueue(image);
1672           if (p == (const Quantum *) NULL)
1673             break;
1674           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1675           {
1676             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1677               quantum_info->scale+quantum_info->minimum);
1678             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1679               quantum_info->scale+quantum_info->minimum);
1680             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1681               quantum_info->scale+quantum_info->minimum);
1682             p++;
1683           }
1684           break;
1685         }
1686       if (LocaleCompare(stream_info->map,"RGBA") == 0)
1687         {
1688           p=GetAuthenticPixelQueue(image);
1689           if (p == (const Quantum *) NULL)
1690             break;
1691           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1692           {
1693             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1694               quantum_info->scale+quantum_info->minimum);
1695             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1696               quantum_info->scale+quantum_info->minimum);
1697             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1698               quantum_info->scale+quantum_info->minimum);
1699             *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1700               quantum_info->scale+quantum_info->minimum);
1701             p++;
1702           }
1703           break;
1704         }
1705       if (LocaleCompare(stream_info->map,"RGBP") == 0)
1706         {
1707           p=GetAuthenticPixelQueue(image);
1708           if (p == (const Quantum *) NULL)
1709             break;
1710           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1711           {
1712             *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
1713               quantum_info->scale+quantum_info->minimum);
1714             *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
1715               quantum_info->scale+quantum_info->minimum);
1716             *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
1717               quantum_info->scale+quantum_info->minimum);
1718             *q++=0.0;
1719             p++;
1720           }
1721           break;
1722         }
1723       p=GetAuthenticPixelQueue(image);
1724       if (p == (const Quantum *) NULL)
1725         break;
1726       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1727       {
1728         for (i=0; i < (ssize_t) length; i++)
1729         {
1730           *q=0;
1731           switch (quantum_map[i])
1732           {
1733             case RedQuantum:
1734             case CyanQuantum:
1735             {
1736               *q=(double) ((QuantumScale*GetPixelRed(image,p))*
1737                 quantum_info->scale+quantum_info->minimum);
1738               break;
1739             }
1740             case GreenQuantum:
1741             case MagentaQuantum:
1742             {
1743               *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
1744                 quantum_info->scale+quantum_info->minimum);
1745               break;
1746             }
1747             case BlueQuantum:
1748             case YellowQuantum:
1749             {
1750               *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
1751                 quantum_info->scale+quantum_info->minimum);
1752               break;
1753             }
1754             case AlphaQuantum:
1755             {
1756               *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1757                 quantum_info->scale+quantum_info->minimum);
1758               break;
1759             }
1760             case OpacityQuantum:
1761             {
1762               *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
1763                 quantum_info->scale+quantum_info->minimum);
1764               break;
1765             }
1766             case BlackQuantum:
1767             {
1768               if (image->colorspace == CMYKColorspace)
1769                 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
1770                   quantum_info->scale+quantum_info->minimum);
1771               break;
1772             }
1773             case IndexQuantum:
1774             {
1775               *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
1776                 quantum_info->scale+quantum_info->minimum);
1777               break;
1778             }
1779             default:
1780               *q=0;
1781           }
1782           q++;
1783         }
1784         p++;
1785       }
1786       break;
1787     }
1788     case FloatPixel:
1789     {
1790       register float
1791         *q;
1792
1793       q=(float *) stream_info->pixels;
1794       if (LocaleCompare(stream_info->map,"BGR") == 0)
1795         {
1796           p=GetAuthenticPixelQueue(image);
1797           if (p == (const Quantum *) NULL)
1798             break;
1799           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1800           {
1801             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1802               quantum_info->scale+quantum_info->minimum);
1803             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1804               quantum_info->scale+quantum_info->minimum);
1805             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1806               quantum_info->scale+quantum_info->minimum);
1807             p++;
1808           }
1809           break;
1810         }
1811       if (LocaleCompare(stream_info->map,"BGRA") == 0)
1812         {
1813           p=GetAuthenticPixelQueue(image);
1814           if (p == (const Quantum *) NULL)
1815             break;
1816           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1817           {
1818             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1819               quantum_info->scale+quantum_info->minimum);
1820             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1821               quantum_info->scale+quantum_info->minimum);
1822             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1823               quantum_info->scale+quantum_info->minimum);
1824             *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
1825               quantum_info->scale+quantum_info->minimum);
1826             p++;
1827           }
1828           break;
1829         }
1830       if (LocaleCompare(stream_info->map,"BGRP") == 0)
1831         {
1832           p=GetAuthenticPixelQueue(image);
1833           if (p == (const Quantum *) NULL)
1834             break;
1835           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1836           {
1837             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1838               quantum_info->scale+quantum_info->minimum);
1839             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1840               quantum_info->scale+quantum_info->minimum);
1841             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1842               quantum_info->scale+quantum_info->minimum);
1843             *q++=0.0;
1844             p++;
1845           }
1846           break;
1847         }
1848       if (LocaleCompare(stream_info->map,"I") == 0)
1849         {
1850           p=GetAuthenticPixelQueue(image);
1851           if (p == (const Quantum *) NULL)
1852             break;
1853           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1854           {
1855             *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1856               quantum_info->scale+quantum_info->minimum);
1857             p++;
1858           }
1859           break;
1860         }
1861       if (LocaleCompare(stream_info->map,"RGB") == 0)
1862         {
1863           p=GetAuthenticPixelQueue(image);
1864           if (p == (const Quantum *) NULL)
1865             break;
1866           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1867           {
1868             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1869               quantum_info->scale+quantum_info->minimum);
1870             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1871               quantum_info->scale+quantum_info->minimum);
1872             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1873               quantum_info->scale+quantum_info->minimum);
1874             p++;
1875           }
1876           break;
1877         }
1878       if (LocaleCompare(stream_info->map,"RGBA") == 0)
1879         {
1880           p=GetAuthenticPixelQueue(image);
1881           if (p == (const Quantum *) NULL)
1882             break;
1883           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1884           {
1885             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1886               quantum_info->scale+quantum_info->minimum);
1887             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1888               quantum_info->scale+quantum_info->minimum);
1889             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1890               quantum_info->scale+quantum_info->minimum);
1891             *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1892               quantum_info->scale+quantum_info->minimum);
1893             p++;
1894           }
1895           break;
1896         }
1897       if (LocaleCompare(stream_info->map,"RGBP") == 0)
1898         {
1899           p=GetAuthenticPixelQueue(image);
1900           if (p == (const Quantum *) NULL)
1901             break;
1902           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1903           {
1904             *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
1905               quantum_info->scale+quantum_info->minimum);
1906             *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
1907               quantum_info->scale+quantum_info->minimum);
1908             *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
1909               quantum_info->scale+quantum_info->minimum);
1910             *q++=0.0;
1911             p++;
1912           }
1913           break;
1914         }
1915       p=GetAuthenticPixelQueue(image);
1916       if (p == (const Quantum *) NULL)
1917         break;
1918       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1919       {
1920         for (i=0; i < (ssize_t) length; i++)
1921         {
1922           *q=0;
1923           switch (quantum_map[i])
1924           {
1925             case RedQuantum:
1926             case CyanQuantum:
1927             {
1928               *q=(float) ((QuantumScale*GetPixelRed(image,p))*
1929                 quantum_info->scale+quantum_info->minimum);
1930               break;
1931             }
1932             case GreenQuantum:
1933             case MagentaQuantum:
1934             {
1935               *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
1936                 quantum_info->scale+quantum_info->minimum);
1937               break;
1938             }
1939             case BlueQuantum:
1940             case YellowQuantum:
1941             {
1942               *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
1943                 quantum_info->scale+quantum_info->minimum);
1944               break;
1945             }
1946             case AlphaQuantum:
1947             {
1948               *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1949                 quantum_info->scale+quantum_info->minimum);
1950               break;
1951             }
1952             case OpacityQuantum:
1953             {
1954               *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
1955                 quantum_info->scale+quantum_info->minimum);
1956               break;
1957             }
1958             case BlackQuantum:
1959             {
1960               if (image->colorspace == CMYKColorspace)
1961                 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
1962                   quantum_info->scale+quantum_info->minimum);
1963               break;
1964             }
1965             case IndexQuantum:
1966             {
1967               *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
1968                 quantum_info->scale+quantum_info->minimum);
1969               break;
1970             }
1971             default:
1972               *q=0;
1973           }
1974           q++;
1975         }
1976         p++;
1977       }
1978       break;
1979     }
1980     case LongPixel:
1981     {
1982       register unsigned int
1983         *q;
1984
1985       q=(unsigned int *) stream_info->pixels;
1986       if (LocaleCompare(stream_info->map,"BGR") == 0)
1987         {
1988           p=GetAuthenticPixelQueue(image);
1989           if (p == (const Quantum *) NULL)
1990             break;
1991           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1992           {
1993             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1994             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1995             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1996             p++;
1997           }
1998           break;
1999         }
2000       if (LocaleCompare(stream_info->map,"BGRA") == 0)
2001         {
2002           p=GetAuthenticPixelQueue(image);
2003           if (p == (const Quantum *) NULL)
2004             break;
2005           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2006           {
2007             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2008             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2009             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2010             *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2011             p++;
2012           }
2013           break;
2014         }
2015       if (LocaleCompare(stream_info->map,"BGRP") == 0)
2016         {
2017           p=GetAuthenticPixelQueue(image);
2018           if (p == (const Quantum *) NULL)
2019             break;
2020           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2021           {
2022             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2023             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2024             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2025             *q++=0;
2026             p++;
2027           }
2028           break;
2029         }
2030       if (LocaleCompare(stream_info->map,"I") == 0)
2031         {
2032           p=GetAuthenticPixelQueue(image);
2033           if (p == (const Quantum *) NULL)
2034             break;
2035           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2036           {
2037             *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2038             p++;
2039           }
2040           break;
2041         }
2042       if (LocaleCompare(stream_info->map,"RGB") == 0)
2043         {
2044           p=GetAuthenticPixelQueue(image);
2045           if (p == (const Quantum *) NULL)
2046             break;
2047           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2048           {
2049             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2050             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2051             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2052             p++;
2053           }
2054           break;
2055         }
2056       if (LocaleCompare(stream_info->map,"RGBA") == 0)
2057         {
2058           p=GetAuthenticPixelQueue(image);
2059           if (p == (const Quantum *) NULL)
2060             break;
2061           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2062           {
2063             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2064             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2065             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2066             *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2067             p++;
2068           }
2069           break;
2070         }
2071       if (LocaleCompare(stream_info->map,"RGBP") == 0)
2072         {
2073           p=GetAuthenticPixelQueue(image);
2074           if (p == (const Quantum *) NULL)
2075             break;
2076           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2077           {
2078             *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2079             *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2080             *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2081             *q++=0;
2082             p++;
2083           }
2084           break;
2085         }
2086       p=GetAuthenticPixelQueue(image);
2087       if (p == (const Quantum *) NULL)
2088         break;
2089       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2090       {
2091         for (i=0; i < (ssize_t) length; i++)
2092         {
2093           *q=0;
2094           switch (quantum_map[i])
2095           {
2096             case RedQuantum:
2097             case CyanQuantum:
2098             {
2099               *q=ScaleQuantumToLong(GetPixelRed(image,p));
2100               break;
2101             }
2102             case GreenQuantum:
2103             case MagentaQuantum:
2104             {
2105               *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2106               break;
2107             }
2108             case BlueQuantum:
2109             case YellowQuantum:
2110             {
2111               *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2112               break;
2113             }
2114             case AlphaQuantum:
2115             {
2116               *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
2117               break;
2118             }
2119             case OpacityQuantum:
2120             {
2121               *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2122               break;
2123             }
2124             case BlackQuantum:
2125             {
2126               if (image->colorspace == CMYKColorspace)
2127                 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2128               break;
2129             }
2130             case IndexQuantum:
2131             {
2132               *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2133               break;
2134             }
2135             default:
2136               break;
2137           }
2138           q++;
2139         }
2140         p++;
2141       }
2142       break;
2143     }
2144     case LongLongPixel:
2145     {
2146       register MagickSizeType
2147         *q;
2148
2149       q=(MagickSizeType *) stream_info->pixels;
2150       if (LocaleCompare(stream_info->map,"BGR") == 0)
2151         {
2152           p=GetAuthenticPixelQueue(image);
2153           if (p == (const Quantum *) NULL)
2154             break;
2155           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2156           {
2157             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2158             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2159             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2160             p++;
2161           }
2162           break;
2163         }
2164       if (LocaleCompare(stream_info->map,"BGRA") == 0)
2165         {
2166           p=GetAuthenticPixelQueue(image);
2167           if (p == (const Quantum *) NULL)
2168             break;
2169           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2170           {
2171             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2172             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2173             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2174             *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2175             p++;
2176           }
2177           break;
2178         }
2179       if (LocaleCompare(stream_info->map,"BGRP") == 0)
2180         {
2181           p=GetAuthenticPixelQueue(image);
2182           if (p == (const Quantum *) NULL)
2183             break;
2184           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2185           {
2186             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2187             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2188             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2189             *q++=0U;
2190             p++;
2191           }
2192           break;
2193         }
2194       if (LocaleCompare(stream_info->map,"I") == 0)
2195         {
2196           p=GetAuthenticPixelQueue(image);
2197           if (p == (const Quantum *) NULL)
2198             break;
2199           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2200           {
2201             *q++=ScaleQuantumToLongLong(ClampToQuantum(
2202               GetPixelIntensity(image,p)));
2203             p++;
2204           }
2205           break;
2206         }
2207       if (LocaleCompare(stream_info->map,"RGB") == 0)
2208         {
2209           p=GetAuthenticPixelQueue(image);
2210           if (p == (const Quantum *) NULL)
2211             break;
2212           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2213           {
2214             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2215             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2216             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2217             p++;
2218           }
2219           break;
2220         }
2221       if (LocaleCompare(stream_info->map,"RGBA") == 0)
2222         {
2223           p=GetAuthenticPixelQueue(image);
2224           if (p == (const Quantum *) NULL)
2225             break;
2226           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2227           {
2228             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2229             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2230             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2231             *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2232             p++;
2233           }
2234           break;
2235         }
2236       if (LocaleCompare(stream_info->map,"RGBP") == 0)
2237         {
2238           p=GetAuthenticPixelQueue(image);
2239           if (p == (const Quantum *) NULL)
2240             break;
2241           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2242           {
2243             *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2244             *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2245             *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2246             *q++=0U;
2247             p++;
2248           }
2249           break;
2250         }
2251       p=GetAuthenticPixelQueue(image);
2252       if (p == (const Quantum *) NULL)
2253         break;
2254       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2255       {
2256         for (i=0; i < (ssize_t) length; i++)
2257         {
2258           *q=0;
2259           switch (quantum_map[i])
2260           {
2261             case RedQuantum:
2262             case CyanQuantum:
2263             {
2264               *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2265               break;
2266             }
2267             case GreenQuantum:
2268             case MagentaQuantum:
2269             {
2270               *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2271               break;
2272             }
2273             case BlueQuantum:
2274             case YellowQuantum:
2275             {
2276               *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2277               break;
2278             }
2279             case AlphaQuantum:
2280             {
2281               *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2282               break;
2283             }
2284             case OpacityQuantum:
2285             {
2286               *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2287               break;
2288             }
2289             case BlackQuantum:
2290             {
2291               if (image->colorspace == CMYKColorspace)
2292                 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2293               break;
2294             }
2295             case IndexQuantum:
2296             {
2297               *q=ScaleQuantumToLongLong(ClampToQuantum(
2298                 GetPixelIntensity(image,p)));
2299               break;
2300             }
2301             default:
2302               *q=0;
2303           }
2304           q++;
2305         }
2306         p++;
2307       }
2308       break;
2309     }
2310     case QuantumPixel:
2311     {
2312       register Quantum
2313         *q;
2314
2315       q=(Quantum *) stream_info->pixels;
2316       if (LocaleCompare(stream_info->map,"BGR") == 0)
2317         {
2318           p=GetAuthenticPixelQueue(image);
2319           if (p == (const Quantum *) NULL)
2320             break;
2321           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2322           {
2323             *q++=GetPixelBlue(image,p);
2324             *q++=GetPixelGreen(image,p);
2325             *q++=GetPixelRed(image,p);
2326             p++;
2327           }
2328           break;
2329         }
2330       if (LocaleCompare(stream_info->map,"BGRA") == 0)
2331         {
2332           p=GetAuthenticPixelQueue(image);
2333           if (p == (const Quantum *) NULL)
2334             break;
2335           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2336           {
2337             *q++=GetPixelBlue(image,p);
2338             *q++=GetPixelGreen(image,p);
2339             *q++=GetPixelRed(image,p);
2340             *q++=GetPixelAlpha(image,p);
2341             p++;
2342           }
2343           break;
2344         }
2345       if (LocaleCompare(stream_info->map,"BGRP") == 0)
2346         {
2347           p=GetAuthenticPixelQueue(image);
2348           if (p == (const Quantum *) NULL)
2349             break;
2350           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2351           {
2352             *q++=GetPixelBlue(image,p);
2353             *q++=GetPixelGreen(image,p);
2354             *q++=GetPixelRed(image,p);
2355             *q++=0;
2356             p++;
2357           }
2358           break;
2359         }
2360       if (LocaleCompare(stream_info->map,"I") == 0)
2361         {
2362           p=GetAuthenticPixelQueue(image);
2363           if (p == (const Quantum *) NULL)
2364             break;
2365           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2366           {
2367             *q++=ClampToQuantum(GetPixelIntensity(image,p));
2368             p++;
2369           }
2370           break;
2371         }
2372       if (LocaleCompare(stream_info->map,"RGB") == 0)
2373         {
2374           p=GetAuthenticPixelQueue(image);
2375           if (p == (const Quantum *) NULL)
2376             break;
2377           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2378           {
2379             *q++=GetPixelRed(image,p);
2380             *q++=GetPixelGreen(image,p);
2381             *q++=GetPixelBlue(image,p);
2382             p++;
2383           }
2384           break;
2385         }
2386       if (LocaleCompare(stream_info->map,"RGBA") == 0)
2387         {
2388           p=GetAuthenticPixelQueue(image);
2389           if (p == (const Quantum *) NULL)
2390             break;
2391           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2392           {
2393             *q++=GetPixelRed(image,p);
2394             *q++=GetPixelGreen(image,p);
2395             *q++=GetPixelBlue(image,p);
2396             *q++=GetPixelAlpha(image,p);
2397             p++;
2398           }
2399           break;
2400         }
2401       if (LocaleCompare(stream_info->map,"RGBP") == 0)
2402         {
2403           p=GetAuthenticPixelQueue(image);
2404           if (p == (const Quantum *) NULL)
2405             break;
2406           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2407           {
2408             *q++=GetPixelRed(image,p);
2409             *q++=GetPixelGreen(image,p);
2410             *q++=GetPixelBlue(image,p);
2411             *q++=0U;
2412             p++;
2413           }
2414           break;
2415         }
2416       p=GetAuthenticPixelQueue(image);
2417       if (p == (const Quantum *) NULL)
2418         break;
2419       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2420       {
2421         for (i=0; i < (ssize_t) length; i++)
2422         {
2423           *q=(Quantum) 0;
2424           switch (quantum_map[i])
2425           {
2426             case RedQuantum:
2427             case CyanQuantum:
2428             {
2429               *q=GetPixelRed(image,p);
2430               break;
2431             }
2432             case GreenQuantum:
2433             case MagentaQuantum:
2434             {
2435               *q=GetPixelGreen(image,p);
2436               break;
2437             }
2438             case BlueQuantum:
2439             case YellowQuantum:
2440             {
2441               *q=GetPixelBlue(image,p);
2442               break;
2443             }
2444             case AlphaQuantum:
2445             {
2446               *q=(Quantum) (GetPixelAlpha(image,p));
2447               break;
2448             }
2449             case OpacityQuantum:
2450             {
2451               *q=GetPixelAlpha(image,p);
2452               break;
2453             }
2454             case BlackQuantum:
2455             {
2456               if (image->colorspace == CMYKColorspace)
2457                 *q=GetPixelBlack(image,p);
2458               break;
2459             }
2460             case IndexQuantum:
2461             {
2462               *q=ClampToQuantum(GetPixelIntensity(image,p));
2463               break;
2464             }
2465             default:
2466               *q=0;
2467           }
2468           q++;
2469         }
2470         p++;
2471       }
2472       break;
2473     }
2474     case ShortPixel:
2475     {
2476       register unsigned short
2477         *q;
2478
2479       q=(unsigned short *) stream_info->pixels;
2480       if (LocaleCompare(stream_info->map,"BGR") == 0)
2481         {
2482           p=GetAuthenticPixelQueue(image);
2483           if (p == (const Quantum *) NULL)
2484             break;
2485           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2486           {
2487             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2488             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2489             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2490             p++;
2491           }
2492           break;
2493         }
2494       if (LocaleCompare(stream_info->map,"BGRA") == 0)
2495         {
2496           p=GetAuthenticPixelQueue(image);
2497           if (p == (const Quantum *) NULL)
2498             break;
2499           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2500           {
2501             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2502             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2503             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2504             *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2505             p++;
2506           }
2507           break;
2508         }
2509       if (LocaleCompare(stream_info->map,"BGRP") == 0)
2510         {
2511           p=GetAuthenticPixelQueue(image);
2512             if (p == (const Quantum *) NULL)
2513             break;
2514           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2515           {
2516             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2517             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2518             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2519             *q++=0;
2520             p++;
2521           }
2522           break;
2523         }
2524       if (LocaleCompare(stream_info->map,"I") == 0)
2525         {
2526           p=GetAuthenticPixelQueue(image);
2527           if (p == (const Quantum *) NULL)
2528             break;
2529           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2530           {
2531             *q++=ScaleQuantumToShort(ClampToQuantum(
2532               GetPixelIntensity(image,p)));
2533             p++;
2534           }
2535           break;
2536         }
2537       if (LocaleCompare(stream_info->map,"RGB") == 0)
2538         {
2539           p=GetAuthenticPixelQueue(image);
2540           if (p == (const Quantum *) NULL)
2541             break;
2542           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2543           {
2544             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2545             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2546             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2547             p++;
2548           }
2549           break;
2550         }
2551       if (LocaleCompare(stream_info->map,"RGBA") == 0)
2552         {
2553           p=GetAuthenticPixelQueue(image);
2554           if (p == (const Quantum *) NULL)
2555             break;
2556           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2557           {
2558             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2559             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2560             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2561             *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
2562             p++;
2563           }
2564           break;
2565         }
2566       if (LocaleCompare(stream_info->map,"RGBP") == 0)
2567         {
2568           p=GetAuthenticPixelQueue(image);
2569           if (p == (const Quantum *) NULL)
2570             break;
2571           for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2572           {
2573             *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2574             *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2575             *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2576             *q++=0;
2577             p++;
2578           }
2579           break;
2580         }
2581       p=GetAuthenticPixelQueue(image);
2582       if (p == (const Quantum *) NULL)
2583         break;
2584       for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2585       {
2586         for (i=0; i < (ssize_t) length; i++)
2587         {
2588           *q=0;
2589           switch (quantum_map[i])
2590           {
2591             case RedQuantum:
2592             case CyanQuantum:
2593             {
2594               *q=ScaleQuantumToShort(GetPixelRed(image,p));
2595               break;
2596             }
2597             case GreenQuantum:
2598             case MagentaQuantum:
2599             {
2600               *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2601               break;
2602             }
2603             case BlueQuantum:
2604             case YellowQuantum:
2605             {
2606               *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2607               break;
2608             }
2609             case AlphaQuantum:
2610             {
2611               *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2612               break;
2613             }
2614             case OpacityQuantum:
2615             {
2616               *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2617               break;
2618             }
2619             case BlackQuantum:
2620             {
2621               if (image->colorspace == CMYKColorspace)
2622                 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2623               break;
2624             }
2625             case IndexQuantum:
2626             {
2627               *q=ScaleQuantumToShort(ClampToQuantum(
2628                 GetPixelIntensity(image,p)));
2629               break;
2630             }
2631             default:
2632               break;
2633           }
2634           q++;
2635         }
2636         p++;
2637       }
2638       break;
2639     }
2640     default:
2641     {
2642       quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2643       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2644         "UnrecognizedPixelMap","`%s'",stream_info->map);
2645       break;
2646     }
2647   }
2648   quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2649   return(MagickTrue);
2650 }
2651 \f
2652 /*
2653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2654 %                                                                             %
2655 %                                                                             %
2656 %                                                                             %
2657 +   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                         %
2658 %                                                                             %
2659 %                                                                             %
2660 %                                                                             %
2661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2662 %
2663 %  SyncAuthenticPixelsStream() calls the user supplied callback method with
2664 %  the latest stream of pixels.
2665 %
2666 %  The format of the SyncAuthenticPixelsStream method is:
2667 %
2668 %      MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2669 %        ExceptionInfo *exception)
2670 %
2671 %  A description of each parameter follows:
2672 %
2673 %    o image: the image.
2674 %
2675 %    o exception: return any errors or warnings in this structure.
2676 %
2677 */
2678 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2679   ExceptionInfo *exception)
2680 {
2681   CacheInfo
2682     *cache_info;
2683
2684   size_t
2685     length;
2686
2687   StreamHandler
2688     stream_handler;
2689
2690   assert(image != (Image *) NULL);
2691   assert(image->signature == MagickCoreSignature);
2692   if (image->debug != MagickFalse)
2693     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2694   cache_info=(CacheInfo *) image->cache;
2695   assert(cache_info->signature == MagickCoreSignature);
2696   stream_handler=GetBlobStreamHandler(image);
2697   if (stream_handler == (StreamHandler) NULL)
2698     {
2699       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2700         "NoStreamHandlerIsDefined","`%s'",image->filename);
2701       return(MagickFalse);
2702     }
2703   length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2704   return(length == cache_info->columns ? MagickTrue : MagickFalse);
2705 }
2706 \f
2707 /*
2708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2709 %                                                                             %
2710 %                                                                             %
2711 %                                                                             %
2712 %   W r i t e S t r e a m                                                     %
2713 %                                                                             %
2714 %                                                                             %
2715 %                                                                             %
2716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2717 %
2718 %  WriteStream() makes the image pixels available to a user supplied callback
2719 %  method immediately upon writing pixel data with the WriteImage() method.
2720 %
2721 %  The format of the WriteStream() method is:
2722 %
2723 %      MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2724 %        StreamHandler stream,ExceptionInfo *exception)
2725 %
2726 %  A description of each parameter follows:
2727 %
2728 %    o image_info: the image info.
2729 %
2730 %    o stream: A callback method.
2731 %
2732 %    o exception: return any errors or warnings in this structure.
2733 %
2734 */
2735 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2736   Image *image,StreamHandler stream,ExceptionInfo *exception)
2737 {
2738   ImageInfo
2739     *write_info;
2740
2741   MagickBooleanType
2742     status;
2743
2744   assert(image_info != (ImageInfo *) NULL);
2745   assert(image_info->signature == MagickCoreSignature);
2746   if (image_info->debug != MagickFalse)
2747     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2748       image_info->filename);
2749   assert(image != (Image *) NULL);
2750   assert(image->signature == MagickCoreSignature);
2751   write_info=CloneImageInfo(image_info);
2752   *write_info->magick='\0';
2753   write_info->stream=stream;
2754   status=WriteImage(write_info,image,exception);
2755   write_info=DestroyImageInfo(write_info);
2756   return(status);
2757 }