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