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