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