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