MagickCore  6.9.13-15
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  stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL);
1265  if (stream_info->quantum_info == (QuantumInfo *) NULL)
1266  {
1267  read_info=DestroyImageInfo(read_info);
1268  return((Image *) NULL);
1269  }
1270  stream_info->exception=exception;
1271  read_info->client_data=(void *) stream_info;
1272  image=ReadStream(read_info,&WriteStreamImage,exception);
1273  read_info=DestroyImageInfo(read_info);
1274  stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1275  stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1276  if (stream_info->quantum_info == (QuantumInfo *) NULL)
1277  image=DestroyImage(image);
1278  return(image);
1279 }
1280 ␌
1281 /*
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 % %
1284 % %
1285 % %
1286 + S t r e a m I m a g e P i x e l s %
1287 % %
1288 % %
1289 % %
1290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 %
1292 % StreamImagePixels() extracts pixel data from an image and returns it in the
1293 % stream_info->pixels structure in the format as defined by
1294 % stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1295 %
1296 % The format of the StreamImagePixels method is:
1297 %
1298 % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1299 % const Image *image,ExceptionInfo *exception)
1300 %
1301 % A description of each parameter follows:
1302 %
1303 % o stream_info: the stream info.
1304 %
1305 % o image: the image.
1306 %
1307 % o exception: return any errors or warnings in this structure.
1308 %
1309 */
1310 static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1311  const Image *image,ExceptionInfo *exception)
1312 {
1313  QuantumInfo
1314  *quantum_info;
1315 
1316  QuantumType
1317  *quantum_map;
1318 
1319  const IndexPacket
1320  *indexes;
1321 
1322  const PixelPacket
1323  *p;
1324 
1325  ssize_t
1326  i,
1327  x;
1328 
1329  size_t
1330  length;
1331 
1332  assert(stream_info != (StreamInfo *) NULL);
1333  assert(stream_info->signature == MagickCoreSignature);
1334  assert(image != (Image *) NULL);
1335  assert(image->signature == MagickCoreSignature);
1336  if (IsEventLogging() != MagickFalse)
1337  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1338  length=strlen(stream_info->map);
1339  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1340  if (quantum_map == (QuantumType *) NULL)
1341  {
1342  (void) ThrowMagickException(exception,GetMagickModule(),
1343  ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1344  return(MagickFalse);
1345  }
1346  (void) memset(quantum_map,0,length*sizeof(*quantum_map));
1347  for (i=0; i < (ssize_t) length; i++)
1348  {
1349  switch (stream_info->map[i])
1350  {
1351  case 'A':
1352  case 'a':
1353  {
1354  quantum_map[i]=AlphaQuantum;
1355  break;
1356  }
1357  case 'B':
1358  case 'b':
1359  {
1360  quantum_map[i]=BlueQuantum;
1361  break;
1362  }
1363  case 'C':
1364  case 'c':
1365  {
1366  quantum_map[i]=CyanQuantum;
1367  if (image->colorspace == CMYKColorspace)
1368  break;
1369  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1370  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1371  "ColorSeparatedImageRequired","`%s'",stream_info->map);
1372  return(MagickFalse);
1373  }
1374  case 'g':
1375  case 'G':
1376  {
1377  quantum_map[i]=GreenQuantum;
1378  break;
1379  }
1380  case 'I':
1381  case 'i':
1382  {
1383  quantum_map[i]=IndexQuantum;
1384  break;
1385  }
1386  case 'K':
1387  case 'k':
1388  {
1389  quantum_map[i]=BlackQuantum;
1390  if (image->colorspace == CMYKColorspace)
1391  break;
1392  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1393  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1394  "ColorSeparatedImageRequired","`%s'",stream_info->map);
1395  return(MagickFalse);
1396  }
1397  case 'M':
1398  case 'm':
1399  {
1400  quantum_map[i]=MagentaQuantum;
1401  if (image->colorspace == CMYKColorspace)
1402  break;
1403  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1404  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1405  "ColorSeparatedImageRequired","`%s'",stream_info->map);
1406  return(MagickFalse);
1407  }
1408  case 'o':
1409  case 'O':
1410  {
1411  quantum_map[i]=OpacityQuantum;
1412  break;
1413  }
1414  case 'P':
1415  case 'p':
1416  {
1417  quantum_map[i]=UndefinedQuantum;
1418  break;
1419  }
1420  case 'R':
1421  case 'r':
1422  {
1423  quantum_map[i]=RedQuantum;
1424  break;
1425  }
1426  case 'Y':
1427  case 'y':
1428  {
1429  quantum_map[i]=YellowQuantum;
1430  if (image->colorspace == CMYKColorspace)
1431  break;
1432  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1433  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1434  "ColorSeparatedImageRequired","`%s'",stream_info->map);
1435  return(MagickFalse);
1436  }
1437  default:
1438  {
1439  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1440  (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1441  "UnrecognizedPixelMap","`%s'",stream_info->map);
1442  return(MagickFalse);
1443  }
1444  }
1445  }
1446  quantum_info=stream_info->quantum_info;
1447  switch (stream_info->storage_type)
1448  {
1449  case CharPixel:
1450  {
1451  unsigned char
1452  *q;
1453 
1454  q=(unsigned char *) stream_info->pixels;
1455  if (LocaleCompare(stream_info->map,"BGR") == 0)
1456  {
1457  p=GetAuthenticPixelQueue(image);
1458  if (p == (const PixelPacket *) NULL)
1459  break;
1460  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1461  {
1462  *q++=ScaleQuantumToChar(GetPixelBlue(p));
1463  *q++=ScaleQuantumToChar(GetPixelGreen(p));
1464  *q++=ScaleQuantumToChar(GetPixelRed(p));
1465  p++;
1466  }
1467  break;
1468  }
1469  if (LocaleCompare(stream_info->map,"BGRA") == 0)
1470  {
1471  p=GetAuthenticPixelQueue(image);
1472  if (p == (const PixelPacket *) NULL)
1473  break;
1474  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1475  {
1476  *q++=ScaleQuantumToChar(GetPixelBlue(p));
1477  *q++=ScaleQuantumToChar(GetPixelGreen(p));
1478  *q++=ScaleQuantumToChar(GetPixelRed(p));
1479  *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(p)));
1480  p++;
1481  }
1482  break;
1483  }
1484  if (LocaleCompare(stream_info->map,"BGRP") == 0)
1485  {
1486  p=GetAuthenticPixelQueue(image);
1487  if (p == (const PixelPacket *) NULL)
1488  break;
1489  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1490  {
1491  *q++=ScaleQuantumToChar(GetPixelBlue(p));
1492  *q++=ScaleQuantumToChar(GetPixelGreen(p));
1493  *q++=ScaleQuantumToChar(GetPixelRed(p));
1494  *q++=ScaleQuantumToChar((Quantum) 0);
1495  p++;
1496  }
1497  break;
1498  }
1499  if (LocaleCompare(stream_info->map,"I") == 0)
1500  {
1501  p=GetAuthenticPixelQueue(image);
1502  if (p == (const PixelPacket *) NULL)
1503  break;
1504  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1505  {
1506  *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1507  p++;
1508  }
1509  break;
1510  }
1511  if (LocaleCompare(stream_info->map,"RGB") == 0)
1512  {
1513  p=GetAuthenticPixelQueue(image);
1514  if (p == (const PixelPacket *) NULL)
1515  break;
1516  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1517  {
1518  *q++=ScaleQuantumToChar(GetPixelRed(p));
1519  *q++=ScaleQuantumToChar(GetPixelGreen(p));
1520  *q++=ScaleQuantumToChar(GetPixelBlue(p));
1521  p++;
1522  }
1523  break;
1524  }
1525  if (LocaleCompare(stream_info->map,"RGBA") == 0)
1526  {
1527  p=GetAuthenticPixelQueue(image);
1528  if (p == (const PixelPacket *) NULL)
1529  break;
1530  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1531  {
1532  *q++=ScaleQuantumToChar(GetPixelRed(p));
1533  *q++=ScaleQuantumToChar(GetPixelGreen(p));
1534  *q++=ScaleQuantumToChar(GetPixelBlue(p));
1535  *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(p)));
1536  p++;
1537  }
1538  break;
1539  }
1540  if (LocaleCompare(stream_info->map,"RGBP") == 0)
1541  {
1542  p=GetAuthenticPixelQueue(image);
1543  if (p == (const PixelPacket *) NULL)
1544  break;
1545  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1546  {
1547  *q++=ScaleQuantumToChar(GetPixelRed(p));
1548  *q++=ScaleQuantumToChar(GetPixelGreen(p));
1549  *q++=ScaleQuantumToChar(GetPixelBlue(p));
1550  *q++=ScaleQuantumToChar((Quantum) 0);
1551  p++;
1552  }
1553  break;
1554  }
1555  p=GetAuthenticPixelQueue(image);
1556  if (p == (const PixelPacket *) NULL)
1557  break;
1558  indexes=GetVirtualIndexQueue(image);
1559  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1560  {
1561  for (i=0; i < (ssize_t) length; i++)
1562  {
1563  *q=0;
1564  switch (quantum_map[i])
1565  {
1566  case RedQuantum:
1567  case CyanQuantum:
1568  {
1569  *q=ScaleQuantumToChar(GetPixelRed(p));
1570  break;
1571  }
1572  case GreenQuantum:
1573  case MagentaQuantum:
1574  {
1575  *q=ScaleQuantumToChar(GetPixelGreen(p));
1576  break;
1577  }
1578  case BlueQuantum:
1579  case YellowQuantum:
1580  {
1581  *q=ScaleQuantumToChar(GetPixelBlue(p));
1582  break;
1583  }
1584  case AlphaQuantum:
1585  {
1586  *q=ScaleQuantumToChar(GetPixelAlpha(p));
1587  break;
1588  }
1589  case OpacityQuantum:
1590  {
1591  *q=ScaleQuantumToChar(GetPixelOpacity(p));
1592  break;
1593  }
1594  case BlackQuantum:
1595  {
1596  if (image->colorspace == CMYKColorspace)
1597  *q=ScaleQuantumToChar(GetPixelIndex(indexes+x));
1598  break;
1599  }
1600  case IndexQuantum:
1601  {
1602  *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1603  break;
1604  }
1605  default:
1606  break;
1607  }
1608  q++;
1609  }
1610  p++;
1611  }
1612  break;
1613  }
1614  case DoublePixel:
1615  {
1616  double
1617  *q;
1618 
1619  q=(double *) stream_info->pixels;
1620  if (LocaleCompare(stream_info->map,"BGR") == 0)
1621  {
1622  p=GetAuthenticPixelQueue(image);
1623  if (p == (const PixelPacket *) NULL)
1624  break;
1625  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1626  {
1627  *q++=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1628  quantum_info->scale+quantum_info->minimum);
1629  *q++=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1630  quantum_info->scale+quantum_info->minimum);
1631  *q++=(double) ((QuantumScale*(double) GetPixelRed(p))*
1632  quantum_info->scale+quantum_info->minimum);
1633  p++;
1634  }
1635  break;
1636  }
1637  if (LocaleCompare(stream_info->map,"BGRA") == 0)
1638  {
1639  p=GetAuthenticPixelQueue(image);
1640  if (p == (const PixelPacket *) NULL)
1641  break;
1642  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1643  {
1644  *q++=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1645  quantum_info->scale+quantum_info->minimum);
1646  *q++=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1647  quantum_info->scale+quantum_info->minimum);
1648  *q++=(double) ((QuantumScale*(double) GetPixelRed(p))*
1649  quantum_info->scale+quantum_info->minimum);
1650  *q++=(double) ((QuantumScale*(double) GetPixelAlpha(p))*
1651  quantum_info->scale+quantum_info->minimum);
1652  p++;
1653  }
1654  break;
1655  }
1656  if (LocaleCompare(stream_info->map,"BGRP") == 0)
1657  {
1658  p=GetAuthenticPixelQueue(image);
1659  if (p == (const PixelPacket *) NULL)
1660  break;
1661  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1662  {
1663  *q++=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1664  quantum_info->scale+quantum_info->minimum);
1665  *q++=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1666  quantum_info->scale+quantum_info->minimum);
1667  *q++=(double) ((QuantumScale*(double) GetPixelRed(p))*
1668  quantum_info->scale+quantum_info->minimum);
1669  *q++=0.0;
1670  p++;
1671  }
1672  break;
1673  }
1674  if (LocaleCompare(stream_info->map,"I") == 0)
1675  {
1676  p=GetAuthenticPixelQueue(image);
1677  if (p == (const PixelPacket *) NULL)
1678  break;
1679  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1680  {
1681  *q++=(double) ((QuantumScale*(double) GetPixelIntensity(image,p))*
1682  quantum_info->scale+quantum_info->minimum);
1683  p++;
1684  }
1685  break;
1686  }
1687  if (LocaleCompare(stream_info->map,"RGB") == 0)
1688  {
1689  p=GetAuthenticPixelQueue(image);
1690  if (p == (const PixelPacket *) NULL)
1691  break;
1692  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1693  {
1694  *q++=(double) ((QuantumScale*(double) GetPixelRed(p))*
1695  quantum_info->scale+quantum_info->minimum);
1696  *q++=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1697  quantum_info->scale+quantum_info->minimum);
1698  *q++=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1699  quantum_info->scale+quantum_info->minimum);
1700  p++;
1701  }
1702  break;
1703  }
1704  if (LocaleCompare(stream_info->map,"RGBA") == 0)
1705  {
1706  p=GetAuthenticPixelQueue(image);
1707  if (p == (const PixelPacket *) NULL)
1708  break;
1709  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1710  {
1711  *q++=(double) ((QuantumScale*(double) GetPixelRed(p))*
1712  quantum_info->scale+quantum_info->minimum);
1713  *q++=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1714  quantum_info->scale+quantum_info->minimum);
1715  *q++=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1716  quantum_info->scale+quantum_info->minimum);
1717  *q++=(double) ((QuantumScale*(double) GetPixelAlpha(p))*
1718  quantum_info->scale+quantum_info->minimum);
1719  p++;
1720  }
1721  break;
1722  }
1723  if (LocaleCompare(stream_info->map,"RGBP") == 0)
1724  {
1725  p=GetAuthenticPixelQueue(image);
1726  if (p == (const PixelPacket *) NULL)
1727  break;
1728  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1729  {
1730  *q++=(double) ((QuantumScale*(double) GetPixelRed(p))*
1731  quantum_info->scale+quantum_info->minimum);
1732  *q++=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1733  quantum_info->scale+quantum_info->minimum);
1734  *q++=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1735  quantum_info->scale+quantum_info->minimum);
1736  *q++=0.0;
1737  p++;
1738  }
1739  break;
1740  }
1741  p=GetAuthenticPixelQueue(image);
1742  if (p == (const PixelPacket *) NULL)
1743  break;
1744  indexes=GetVirtualIndexQueue(image);
1745  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1746  {
1747  for (i=0; i < (ssize_t) length; i++)
1748  {
1749  *q=0;
1750  switch (quantum_map[i])
1751  {
1752  case RedQuantum:
1753  case CyanQuantum:
1754  {
1755  *q=(double) ((QuantumScale*(double) GetPixelRed(p))*
1756  quantum_info->scale+quantum_info->minimum);
1757  break;
1758  }
1759  case GreenQuantum:
1760  case MagentaQuantum:
1761  {
1762  *q=(double) ((QuantumScale*(double) GetPixelGreen(p))*
1763  quantum_info->scale+quantum_info->minimum);
1764  break;
1765  }
1766  case BlueQuantum:
1767  case YellowQuantum:
1768  {
1769  *q=(double) ((QuantumScale*(double) GetPixelBlue(p))*
1770  quantum_info->scale+quantum_info->minimum);
1771  break;
1772  }
1773  case AlphaQuantum:
1774  {
1775  *q=(double) ((QuantumScale*(double) GetPixelAlpha(p))*
1776  quantum_info->scale+quantum_info->minimum);
1777  break;
1778  }
1779  case OpacityQuantum:
1780  {
1781  *q=(double) ((QuantumScale*(double) GetPixelOpacity(p))*
1782  quantum_info->scale+quantum_info->minimum);
1783  break;
1784  }
1785  case BlackQuantum:
1786  {
1787  if (image->colorspace == CMYKColorspace)
1788  *q=(double) ((QuantumScale*(double) GetPixelIndex(indexes+x))*
1789  quantum_info->scale+quantum_info->minimum);
1790  break;
1791  }
1792  case IndexQuantum:
1793  {
1794  *q=(double) ((QuantumScale*(double) GetPixelIntensity(image,p))*
1795  quantum_info->scale+quantum_info->minimum);
1796  break;
1797  }
1798  default:
1799  *q=0;
1800  }
1801  q++;
1802  }
1803  p++;
1804  }
1805  break;
1806  }
1807  case FloatPixel:
1808  {
1809  float
1810  *q;
1811 
1812  q=(float *) stream_info->pixels;
1813  if (LocaleCompare(stream_info->map,"BGR") == 0)
1814  {
1815  p=GetAuthenticPixelQueue(image);
1816  if (p == (const PixelPacket *) NULL)
1817  break;
1818  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1819  {
1820  *q++=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1821  quantum_info->scale+quantum_info->minimum);
1822  *q++=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1823  quantum_info->scale+quantum_info->minimum);
1824  *q++=(float) ((QuantumScale*(double) GetPixelRed(p))*
1825  quantum_info->scale+quantum_info->minimum);
1826  p++;
1827  }
1828  break;
1829  }
1830  if (LocaleCompare(stream_info->map,"BGRA") == 0)
1831  {
1832  p=GetAuthenticPixelQueue(image);
1833  if (p == (const PixelPacket *) NULL)
1834  break;
1835  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1836  {
1837  *q++=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1838  quantum_info->scale+quantum_info->minimum);
1839  *q++=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1840  quantum_info->scale+quantum_info->minimum);
1841  *q++=(float) ((QuantumScale*(double) GetPixelRed(p))*
1842  quantum_info->scale+quantum_info->minimum);
1843  *q++=(float) ((QuantumScale*(double) GetPixelAlpha(p))*
1844  quantum_info->scale+quantum_info->minimum);
1845  p++;
1846  }
1847  break;
1848  }
1849  if (LocaleCompare(stream_info->map,"BGRP") == 0)
1850  {
1851  p=GetAuthenticPixelQueue(image);
1852  if (p == (const PixelPacket *) NULL)
1853  break;
1854  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1855  {
1856  *q++=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1857  quantum_info->scale+quantum_info->minimum);
1858  *q++=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1859  quantum_info->scale+quantum_info->minimum);
1860  *q++=(float) ((QuantumScale*(double) GetPixelRed(p))*
1861  quantum_info->scale+quantum_info->minimum);
1862  *q++=0.0;
1863  p++;
1864  }
1865  break;
1866  }
1867  if (LocaleCompare(stream_info->map,"I") == 0)
1868  {
1869  p=GetAuthenticPixelQueue(image);
1870  if (p == (const PixelPacket *) NULL)
1871  break;
1872  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1873  {
1874  *q++=(float) ((QuantumScale*(double) GetPixelIntensity(image,p))*
1875  quantum_info->scale+quantum_info->minimum);
1876  p++;
1877  }
1878  break;
1879  }
1880  if (LocaleCompare(stream_info->map,"RGB") == 0)
1881  {
1882  p=GetAuthenticPixelQueue(image);
1883  if (p == (const PixelPacket *) NULL)
1884  break;
1885  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1886  {
1887  *q++=(float) ((QuantumScale*(double) GetPixelRed(p))*
1888  quantum_info->scale+quantum_info->minimum);
1889  *q++=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1890  quantum_info->scale+quantum_info->minimum);
1891  *q++=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1892  quantum_info->scale+quantum_info->minimum);
1893  p++;
1894  }
1895  break;
1896  }
1897  if (LocaleCompare(stream_info->map,"RGBA") == 0)
1898  {
1899  p=GetAuthenticPixelQueue(image);
1900  if (p == (const PixelPacket *) NULL)
1901  break;
1902  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1903  {
1904  *q++=(float) ((QuantumScale*(double) GetPixelRed(p))*
1905  quantum_info->scale+quantum_info->minimum);
1906  *q++=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1907  quantum_info->scale+quantum_info->minimum);
1908  *q++=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1909  quantum_info->scale+quantum_info->minimum);
1910  *q++=(float) ((QuantumScale*(double) GetPixelAlpha(p))*
1911  quantum_info->scale+quantum_info->minimum);
1912  p++;
1913  }
1914  break;
1915  }
1916  if (LocaleCompare(stream_info->map,"RGBP") == 0)
1917  {
1918  p=GetAuthenticPixelQueue(image);
1919  if (p == (const PixelPacket *) NULL)
1920  break;
1921  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1922  {
1923  *q++=(float) ((QuantumScale*(double) GetPixelRed(p))*
1924  quantum_info->scale+quantum_info->minimum);
1925  *q++=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1926  quantum_info->scale+quantum_info->minimum);
1927  *q++=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1928  quantum_info->scale+quantum_info->minimum);
1929  *q++=0.0;
1930  p++;
1931  }
1932  break;
1933  }
1934  p=GetAuthenticPixelQueue(image);
1935  if (p == (const PixelPacket *) NULL)
1936  break;
1937  indexes=GetVirtualIndexQueue(image);
1938  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1939  {
1940  for (i=0; i < (ssize_t) length; i++)
1941  {
1942  *q=0;
1943  switch (quantum_map[i])
1944  {
1945  case RedQuantum:
1946  case CyanQuantum:
1947  {
1948  *q=(float) ((QuantumScale*(double) GetPixelRed(p))*
1949  quantum_info->scale+quantum_info->minimum);
1950  break;
1951  }
1952  case GreenQuantum:
1953  case MagentaQuantum:
1954  {
1955  *q=(float) ((QuantumScale*(double) GetPixelGreen(p))*
1956  quantum_info->scale+quantum_info->minimum);
1957  break;
1958  }
1959  case BlueQuantum:
1960  case YellowQuantum:
1961  {
1962  *q=(float) ((QuantumScale*(double) GetPixelBlue(p))*
1963  quantum_info->scale+quantum_info->minimum);
1964  break;
1965  }
1966  case AlphaQuantum:
1967  {
1968  *q=(float) ((QuantumScale*(double) GetPixelAlpha(p))*
1969  quantum_info->scale+quantum_info->minimum);
1970  break;
1971  }
1972  case OpacityQuantum:
1973  {
1974  *q=(float) ((QuantumScale*(double) GetPixelOpacity(p))*
1975  quantum_info->scale+quantum_info->minimum);
1976  break;
1977  }
1978  case BlackQuantum:
1979  {
1980  if (image->colorspace == CMYKColorspace)
1981  *q=(float) ((QuantumScale*(double) GetPixelIndex(indexes+x))*
1982  quantum_info->scale+quantum_info->minimum);
1983  break;
1984  }
1985  case IndexQuantum:
1986  {
1987  *q=(float) ((QuantumScale*(double) GetPixelIntensity(image,p))*
1988  quantum_info->scale+quantum_info->minimum);
1989  break;
1990  }
1991  default:
1992  *q=0;
1993  }
1994  q++;
1995  }
1996  p++;
1997  }
1998  break;
1999  }
2000  case IntegerPixel:
2001  {
2002  unsigned int
2003  *q;
2004 
2005  q=(unsigned int *) stream_info->pixels;
2006  if (LocaleCompare(stream_info->map,"BGR") == 0)
2007  {
2008  p=GetAuthenticPixelQueue(image);
2009  if (p == (const PixelPacket *) NULL)
2010  break;
2011  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2012  {
2013  *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2014  *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2015  *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2016  p++;
2017  }
2018  break;
2019  }
2020  if (LocaleCompare(stream_info->map,"BGRA") == 0)
2021  {
2022  p=GetAuthenticPixelQueue(image);
2023  if (p == (const PixelPacket *) NULL)
2024  break;
2025  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2026  {
2027  *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2028  *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2029  *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2030  *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(p));
2031  p++;
2032  }
2033  break;
2034  }
2035  if (LocaleCompare(stream_info->map,"BGRP") == 0)
2036  {
2037  p=GetAuthenticPixelQueue(image);
2038  if (p == (const PixelPacket *) NULL)
2039  break;
2040  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2041  {
2042  *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2043  *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2044  *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2045  *q++=0U;
2046  p++;
2047  }
2048  break;
2049  }
2050  if (LocaleCompare(stream_info->map,"I") == 0)
2051  {
2052  p=GetAuthenticPixelQueue(image);
2053  if (p == (const PixelPacket *) NULL)
2054  break;
2055  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2056  {
2057  *q++=(unsigned int) ScaleQuantumToLong(ClampToQuantum(
2058  GetPixelIntensity(image,p)));
2059  p++;
2060  }
2061  break;
2062  }
2063  if (LocaleCompare(stream_info->map,"RGB") == 0)
2064  {
2065  p=GetAuthenticPixelQueue(image);
2066  if (p == (const PixelPacket *) NULL)
2067  break;
2068  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2069  {
2070  *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2071  *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2072  *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2073  p++;
2074  }
2075  break;
2076  }
2077  if (LocaleCompare(stream_info->map,"RGBA") == 0)
2078  {
2079  p=GetAuthenticPixelQueue(image);
2080  if (p == (const PixelPacket *) NULL)
2081  break;
2082  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2083  {
2084  *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2085  *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2086  *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2087  *q++=(unsigned int) ScaleQuantumToLong((Quantum)
2088  (GetPixelAlpha(p)));
2089  p++;
2090  }
2091  break;
2092  }
2093  if (LocaleCompare(stream_info->map,"RGBP") == 0)
2094  {
2095  p=GetAuthenticPixelQueue(image);
2096  if (p == (const PixelPacket *) NULL)
2097  break;
2098  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2099  {
2100  *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2101  *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2102  *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2103  *q++=0U;
2104  p++;
2105  }
2106  break;
2107  }
2108  p=GetAuthenticPixelQueue(image);
2109  if (p == (const PixelPacket *) NULL)
2110  break;
2111  indexes=GetVirtualIndexQueue(image);
2112  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2113  {
2114  for (i=0; i < (ssize_t) length; i++)
2115  {
2116  *q=0;
2117  switch (quantum_map[i])
2118  {
2119  case RedQuantum:
2120  case CyanQuantum:
2121  {
2122  *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(p));
2123  break;
2124  }
2125  case GreenQuantum:
2126  case MagentaQuantum:
2127  {
2128  *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(p));
2129  break;
2130  }
2131  case BlueQuantum:
2132  case YellowQuantum:
2133  {
2134  *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(p));
2135  break;
2136  }
2137  case AlphaQuantum:
2138  {
2139  *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(p));
2140  break;
2141  }
2142  case OpacityQuantum:
2143  {
2144  *q=(unsigned int) ScaleQuantumToLong(GetPixelOpacity(p));
2145  break;
2146  }
2147  case BlackQuantum:
2148  {
2149  if (image->colorspace == CMYKColorspace)
2150  *q=(unsigned int) ScaleQuantumToLong(GetPixelIndex(
2151  indexes+x));
2152  break;
2153  }
2154  case IndexQuantum:
2155  {
2156  *q=(unsigned int) ScaleQuantumToLong(ClampToQuantum(
2157  GetPixelIntensity(image,p)));
2158  break;
2159  }
2160  default:
2161  *q=0;
2162  }
2163  q++;
2164  }
2165  p++;
2166  }
2167  break;
2168  }
2169  case LongPixel:
2170  {
2171  size_t
2172  *q;
2173 
2174  q=(size_t *) stream_info->pixels;
2175  if (LocaleCompare(stream_info->map,"BGR") == 0)
2176  {
2177  p=GetAuthenticPixelQueue(image);
2178  if (p == (const PixelPacket *) NULL)
2179  break;
2180  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2181  {
2182  *q++=ScaleQuantumToLong(GetPixelBlue(p));
2183  *q++=ScaleQuantumToLong(GetPixelGreen(p));
2184  *q++=ScaleQuantumToLong(GetPixelRed(p));
2185  p++;
2186  }
2187  break;
2188  }
2189  if (LocaleCompare(stream_info->map,"BGRA") == 0)
2190  {
2191  p=GetAuthenticPixelQueue(image);
2192  if (p == (const PixelPacket *) NULL)
2193  break;
2194  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2195  {
2196  *q++=ScaleQuantumToLong(GetPixelBlue(p));
2197  *q++=ScaleQuantumToLong(GetPixelGreen(p));
2198  *q++=ScaleQuantumToLong(GetPixelRed(p));
2199  *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(p)));
2200  p++;
2201  }
2202  break;
2203  }
2204  if (LocaleCompare(stream_info->map,"BGRP") == 0)
2205  {
2206  p=GetAuthenticPixelQueue(image);
2207  if (p == (const PixelPacket *) NULL)
2208  break;
2209  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2210  {
2211  *q++=ScaleQuantumToLong(GetPixelBlue(p));
2212  *q++=ScaleQuantumToLong(GetPixelGreen(p));
2213  *q++=ScaleQuantumToLong(GetPixelRed(p));
2214  *q++=0;
2215  p++;
2216  }
2217  break;
2218  }
2219  if (LocaleCompare(stream_info->map,"I") == 0)
2220  {
2221  p=GetAuthenticPixelQueue(image);
2222  if (p == (const PixelPacket *) NULL)
2223  break;
2224  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2225  {
2226  *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2227  p++;
2228  }
2229  break;
2230  }
2231  if (LocaleCompare(stream_info->map,"RGB") == 0)
2232  {
2233  p=GetAuthenticPixelQueue(image);
2234  if (p == (const PixelPacket *) NULL)
2235  break;
2236  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2237  {
2238  *q++=ScaleQuantumToLong(GetPixelRed(p));
2239  *q++=ScaleQuantumToLong(GetPixelGreen(p));
2240  *q++=ScaleQuantumToLong(GetPixelBlue(p));
2241  p++;
2242  }
2243  break;
2244  }
2245  if (LocaleCompare(stream_info->map,"RGBA") == 0)
2246  {
2247  p=GetAuthenticPixelQueue(image);
2248  if (p == (const PixelPacket *) NULL)
2249  break;
2250  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2251  {
2252  *q++=ScaleQuantumToLong(GetPixelRed(p));
2253  *q++=ScaleQuantumToLong(GetPixelGreen(p));
2254  *q++=ScaleQuantumToLong(GetPixelBlue(p));
2255  *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(p)));
2256  p++;
2257  }
2258  break;
2259  }
2260  if (LocaleCompare(stream_info->map,"RGBP") == 0)
2261  {
2262  p=GetAuthenticPixelQueue(image);
2263  if (p == (const PixelPacket *) NULL)
2264  break;
2265  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2266  {
2267  *q++=ScaleQuantumToLong(GetPixelRed(p));
2268  *q++=ScaleQuantumToLong(GetPixelGreen(p));
2269  *q++=ScaleQuantumToLong(GetPixelBlue(p));
2270  *q++=0;
2271  p++;
2272  }
2273  break;
2274  }
2275  p=GetAuthenticPixelQueue(image);
2276  if (p == (const PixelPacket *) NULL)
2277  break;
2278  indexes=GetVirtualIndexQueue(image);
2279  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2280  {
2281  for (i=0; i < (ssize_t) length; i++)
2282  {
2283  *q=0;
2284  switch (quantum_map[i])
2285  {
2286  case RedQuantum:
2287  case CyanQuantum:
2288  {
2289  *q=ScaleQuantumToLong(GetPixelRed(p));
2290  break;
2291  }
2292  case GreenQuantum:
2293  case MagentaQuantum:
2294  {
2295  *q=ScaleQuantumToLong(GetPixelGreen(p));
2296  break;
2297  }
2298  case BlueQuantum:
2299  case YellowQuantum:
2300  {
2301  *q=ScaleQuantumToLong(GetPixelBlue(p));
2302  break;
2303  }
2304  case AlphaQuantum:
2305  {
2306  *q=ScaleQuantumToLong(GetPixelAlpha(p));
2307  break;
2308  }
2309  case OpacityQuantum:
2310  {
2311  *q=ScaleQuantumToLong(GetPixelOpacity(p));
2312  break;
2313  }
2314  case BlackQuantum:
2315  {
2316  if (image->colorspace == CMYKColorspace)
2317  *q=ScaleQuantumToLong(GetPixelIndex(indexes+x));
2318  break;
2319  }
2320  case IndexQuantum:
2321  {
2322  *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2323  break;
2324  }
2325  default:
2326  break;
2327  }
2328  q++;
2329  }
2330  p++;
2331  }
2332  break;
2333  }
2334  case QuantumPixel:
2335  {
2336  Quantum
2337  *q;
2338 
2339  q=(Quantum *) stream_info->pixels;
2340  if (LocaleCompare(stream_info->map,"BGR") == 0)
2341  {
2342  p=GetAuthenticPixelQueue(image);
2343  if (p == (const PixelPacket *) NULL)
2344  break;
2345  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2346  {
2347  *q++=GetPixelBlue(p);
2348  *q++=GetPixelGreen(p);
2349  *q++=GetPixelRed(p);
2350  p++;
2351  }
2352  break;
2353  }
2354  if (LocaleCompare(stream_info->map,"BGRA") == 0)
2355  {
2356  p=GetAuthenticPixelQueue(image);
2357  if (p == (const PixelPacket *) NULL)
2358  break;
2359  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2360  {
2361  *q++=GetPixelBlue(p);
2362  *q++=GetPixelGreen(p);
2363  *q++=GetPixelRed(p);
2364  *q++=(Quantum) (GetPixelAlpha(p));
2365  p++;
2366  }
2367  break;
2368  }
2369  if (LocaleCompare(stream_info->map,"BGRP") == 0)
2370  {
2371  p=GetAuthenticPixelQueue(image);
2372  if (p == (const PixelPacket *) NULL)
2373  break;
2374  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2375  {
2376  *q++=GetPixelBlue(p);
2377  *q++=GetPixelGreen(p);
2378  *q++=GetPixelRed(p);
2379  *q++=0;
2380  p++;
2381  }
2382  break;
2383  }
2384  if (LocaleCompare(stream_info->map,"I") == 0)
2385  {
2386  p=GetAuthenticPixelQueue(image);
2387  if (p == (const PixelPacket *) NULL)
2388  break;
2389  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2390  {
2391  *q++=ClampToQuantum(GetPixelIntensity(image,p));
2392  p++;
2393  }
2394  break;
2395  }
2396  if (LocaleCompare(stream_info->map,"RGB") == 0)
2397  {
2398  p=GetAuthenticPixelQueue(image);
2399  if (p == (const PixelPacket *) NULL)
2400  break;
2401  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2402  {
2403  *q++=GetPixelRed(p);
2404  *q++=GetPixelGreen(p);
2405  *q++=GetPixelBlue(p);
2406  p++;
2407  }
2408  break;
2409  }
2410  if (LocaleCompare(stream_info->map,"RGBA") == 0)
2411  {
2412  p=GetAuthenticPixelQueue(image);
2413  if (p == (const PixelPacket *) NULL)
2414  break;
2415  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2416  {
2417  *q++=GetPixelRed(p);
2418  *q++=GetPixelGreen(p);
2419  *q++=GetPixelBlue(p);
2420  *q++=(Quantum) (GetPixelAlpha(p));
2421  p++;
2422  }
2423  break;
2424  }
2425  if (LocaleCompare(stream_info->map,"RGBP") == 0)
2426  {
2427  p=GetAuthenticPixelQueue(image);
2428  if (p == (const PixelPacket *) NULL)
2429  break;
2430  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2431  {
2432  *q++=GetPixelRed(p);
2433  *q++=GetPixelGreen(p);
2434  *q++=GetPixelBlue(p);
2435  *q++=0U;
2436  p++;
2437  }
2438  break;
2439  }
2440  p=GetAuthenticPixelQueue(image);
2441  if (p == (const PixelPacket *) NULL)
2442  break;
2443  indexes=GetVirtualIndexQueue(image);
2444  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2445  {
2446  for (i=0; i < (ssize_t) length; i++)
2447  {
2448  *q=(Quantum) 0;
2449  switch (quantum_map[i])
2450  {
2451  case RedQuantum:
2452  case CyanQuantum:
2453  {
2454  *q=GetPixelRed(p);
2455  break;
2456  }
2457  case GreenQuantum:
2458  case MagentaQuantum:
2459  {
2460  *q=GetPixelGreen(p);
2461  break;
2462  }
2463  case BlueQuantum:
2464  case YellowQuantum:
2465  {
2466  *q=GetPixelBlue(p);
2467  break;
2468  }
2469  case AlphaQuantum:
2470  {
2471  *q=GetPixelAlpha(p);
2472  break;
2473  }
2474  case OpacityQuantum:
2475  {
2476  *q=GetPixelOpacity(p);
2477  break;
2478  }
2479  case BlackQuantum:
2480  {
2481  if (image->colorspace == CMYKColorspace)
2482  *q=GetPixelIndex(indexes+x);
2483  break;
2484  }
2485  case IndexQuantum:
2486  {
2487  *q=ClampToQuantum(GetPixelIntensity(image,p));
2488  break;
2489  }
2490  default:
2491  *q=0;
2492  }
2493  q++;
2494  }
2495  p++;
2496  }
2497  break;
2498  }
2499  case ShortPixel:
2500  {
2501  unsigned short
2502  *q;
2503 
2504  q=(unsigned short *) stream_info->pixels;
2505  if (LocaleCompare(stream_info->map,"BGR") == 0)
2506  {
2507  p=GetAuthenticPixelQueue(image);
2508  if (p == (const PixelPacket *) NULL)
2509  break;
2510  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2511  {
2512  *q++=ScaleQuantumToShort(GetPixelBlue(p));
2513  *q++=ScaleQuantumToShort(GetPixelGreen(p));
2514  *q++=ScaleQuantumToShort(GetPixelRed(p));
2515  p++;
2516  }
2517  break;
2518  }
2519  if (LocaleCompare(stream_info->map,"BGRA") == 0)
2520  {
2521  p=GetAuthenticPixelQueue(image);
2522  if (p == (const PixelPacket *) NULL)
2523  break;
2524  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2525  {
2526  *q++=ScaleQuantumToShort(GetPixelBlue(p));
2527  *q++=ScaleQuantumToShort(GetPixelGreen(p));
2528  *q++=ScaleQuantumToShort(GetPixelRed(p));
2529  *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(p)));
2530  p++;
2531  }
2532  break;
2533  }
2534  if (LocaleCompare(stream_info->map,"BGRP") == 0)
2535  {
2536  p=GetAuthenticPixelQueue(image);
2537  if (p == (const PixelPacket *) NULL)
2538  break;
2539  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2540  {
2541  *q++=ScaleQuantumToShort(GetPixelBlue(p));
2542  *q++=ScaleQuantumToShort(GetPixelGreen(p));
2543  *q++=ScaleQuantumToShort(GetPixelRed(p));
2544  *q++=0;
2545  p++;
2546  }
2547  break;
2548  }
2549  if (LocaleCompare(stream_info->map,"I") == 0)
2550  {
2551  p=GetAuthenticPixelQueue(image);
2552  if (p == (const PixelPacket *) NULL)
2553  break;
2554  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2555  {
2556  *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,
2557  p)));
2558  p++;
2559  }
2560  break;
2561  }
2562  if (LocaleCompare(stream_info->map,"RGB") == 0)
2563  {
2564  p=GetAuthenticPixelQueue(image);
2565  if (p == (const PixelPacket *) NULL)
2566  break;
2567  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2568  {
2569  *q++=ScaleQuantumToShort(GetPixelRed(p));
2570  *q++=ScaleQuantumToShort(GetPixelGreen(p));
2571  *q++=ScaleQuantumToShort(GetPixelBlue(p));
2572  p++;
2573  }
2574  break;
2575  }
2576  if (LocaleCompare(stream_info->map,"RGBA") == 0)
2577  {
2578  p=GetAuthenticPixelQueue(image);
2579  if (p == (const PixelPacket *) NULL)
2580  break;
2581  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2582  {
2583  *q++=ScaleQuantumToShort(GetPixelRed(p));
2584  *q++=ScaleQuantumToShort(GetPixelGreen(p));
2585  *q++=ScaleQuantumToShort(GetPixelBlue(p));
2586  *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(p)));
2587  p++;
2588  }
2589  break;
2590  }
2591  if (LocaleCompare(stream_info->map,"RGBP") == 0)
2592  {
2593  p=GetAuthenticPixelQueue(image);
2594  if (p == (const PixelPacket *) NULL)
2595  break;
2596  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2597  {
2598  *q++=ScaleQuantumToShort(GetPixelRed(p));
2599  *q++=ScaleQuantumToShort(GetPixelGreen(p));
2600  *q++=ScaleQuantumToShort(GetPixelBlue(p));
2601  *q++=0;
2602  p++;
2603  }
2604  break;
2605  }
2606  p=GetAuthenticPixelQueue(image);
2607  if (p == (const PixelPacket *) NULL)
2608  break;
2609  indexes=GetVirtualIndexQueue(image);
2610  for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2611  {
2612  for (i=0; i < (ssize_t) length; i++)
2613  {
2614  *q=0;
2615  switch (quantum_map[i])
2616  {
2617  case RedQuantum:
2618  case CyanQuantum:
2619  {
2620  *q=ScaleQuantumToShort(GetPixelRed(p));
2621  break;
2622  }
2623  case GreenQuantum:
2624  case MagentaQuantum:
2625  {
2626  *q=ScaleQuantumToShort(GetPixelGreen(p));
2627  break;
2628  }
2629  case BlueQuantum:
2630  case YellowQuantum:
2631  {
2632  *q=ScaleQuantumToShort(GetPixelBlue(p));
2633  break;
2634  }
2635  case AlphaQuantum:
2636  {
2637  *q=ScaleQuantumToShort(GetPixelAlpha(p));
2638  break;
2639  }
2640  case OpacityQuantum:
2641  {
2642  *q=ScaleQuantumToShort(GetPixelOpacity(p));
2643  break;
2644  }
2645  case BlackQuantum:
2646  {
2647  if (image->colorspace == CMYKColorspace)
2648  *q=ScaleQuantumToShort(GetPixelIndex(indexes+x));
2649  break;
2650  }
2651  case IndexQuantum:
2652  {
2653  *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,
2654  p)));
2655  break;
2656  }
2657  default:
2658  break;
2659  }
2660  q++;
2661  }
2662  p++;
2663  }
2664  break;
2665  }
2666  default:
2667  {
2668  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2669  (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2670  "UnrecognizedPixelMap","`%s'",stream_info->map);
2671  break;
2672  }
2673  }
2674  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2675  return(MagickTrue);
2676 }
2677 ␌
2678 /*
2679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2680 % %
2681 % %
2682 % %
2683 + 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 %
2684 % %
2685 % %
2686 % %
2687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2688 %
2689 % SyncAuthenticPixelsStream() calls the user supplied callback method with
2690 % the latest stream of pixels.
2691 %
2692 % The format of the SyncAuthenticPixelsStream method is:
2693 %
2694 % MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2695 % ExceptionInfo *exception)
2696 %
2697 % A description of each parameter follows:
2698 %
2699 % o image: the image.
2700 %
2701 % o exception: return any errors or warnings in this structure.
2702 %
2703 */
2704 static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2705  ExceptionInfo *exception)
2706 {
2707  CacheInfo
2708  *cache_info;
2709 
2710  size_t
2711  length;
2712 
2713  StreamHandler
2714  stream_handler;
2715 
2716  assert(image != (Image *) NULL);
2717  assert(image->signature == MagickCoreSignature);
2718  if (IsEventLogging() != MagickFalse)
2719  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2720  cache_info=(CacheInfo *) image->cache;
2721  assert(cache_info->signature == MagickCoreSignature);
2722  stream_handler=GetBlobStreamHandler(image);
2723  if (stream_handler == (StreamHandler) NULL)
2724  {
2725  (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2726  "NoStreamHandlerIsDefined","`%s'",image->filename);
2727  return(MagickFalse);
2728  }
2729  length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2730  return(length == cache_info->columns ? MagickTrue : MagickFalse);
2731 }
2732 ␌
2733 /*
2734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2735 % %
2736 % %
2737 % %
2738 % W r i t e S t r e a m %
2739 % %
2740 % %
2741 % %
2742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2743 %
2744 % WriteStream() makes the image pixels available to a user supplied callback
2745 % method immediately upon writing pixel data with the WriteImage() method.
2746 %
2747 % The format of the WriteStream() method is:
2748 %
2749 % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2750 % StreamHandler stream)
2751 %
2752 % A description of each parameter follows:
2753 %
2754 % o image_info: the image info.
2755 %
2756 % o stream: A callback method.
2757 %
2758 */
2759 MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2760  Image *image,StreamHandler stream)
2761 {
2762  ImageInfo
2763  *write_info;
2764 
2765  MagickBooleanType
2766  status;
2767 
2768  assert(image_info != (ImageInfo *) NULL);
2769  assert(image_info->signature == MagickCoreSignature);
2770  assert(image != (Image *) NULL);
2771  assert(image->signature == MagickCoreSignature);
2772  if (IsEventLogging() != MagickFalse)
2773  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2774  image_info->filename);
2775  write_info=CloneImageInfo(image_info);
2776  *write_info->magick='\0';
2777  write_info->stream=stream;
2778  status=WriteImage(write_info,image);
2779  write_info=DestroyImageInfo(write_info);
2780  return(status);
2781 }
Definition: image.h:134