blob: ac1af83a752b4eec2a09ddba17b1ca7b85ee1f40 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% John Cristy %
17% March 2000 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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% http://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 "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"
cristy46f08202010-01-10 04:04:21 +000055#include "magick/pixel.h"
cristy3ed852e2009-09-05 21:47:34 +000056#include "magick/quantum.h"
57#include "magick/quantum-private.h"
58#include "magick/semaphore.h"
59#include "magick/stream.h"
60#include "magick/stream-private.h"
61#include "magick/string_.h"
62
63/*
64 Typedef declaractions.
65*/
66struct _StreamInfo
67{
68 const ImageInfo
69 *image_info;
70
71 const Image
72 *image;
73
74 Image
75 *stream;
76
77 QuantumInfo
78 *quantum_info;
79
80 char
81 *map;
82
83 StorageType
84 storage_type;
85
86 unsigned char
87 *pixels;
88
89 RectangleInfo
90 extract_info;
91
cristybb503372010-05-27 20:51:26 +000092 ssize_t
cristy3ed852e2009-09-05 21:47:34 +000093 y;
94
95 ExceptionInfo
96 *exception;
97
98 const void
99 *client_data;
100
cristybb503372010-05-27 20:51:26 +0000101 size_t
cristy3ed852e2009-09-05 21:47:34 +0000102 signature;
103};
104
105/*
106 Declare pixel cache interfaces.
107*/
108#if defined(__cplusplus) || defined(c_plusplus)
109extern "C" {
110#endif
111
112static const PixelPacket
cristybb503372010-05-27 20:51:26 +0000113 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
114 const ssize_t,const size_t,const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000115
116static MagickBooleanType
117 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
118 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
119
120static PixelPacket
cristybb503372010-05-27 20:51:26 +0000121 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
122 const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000123
124#if defined(__cplusplus) || defined(c_plusplus)
125}
126#endif
127
128/*
129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130% %
131% %
132% %
133+ A c q u i r e S t r e a m I n f o %
134% %
135% %
136% %
137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138%
139% AcquireStreamInfo() allocates the StreamInfo structure.
140%
141% The format of the AcquireStreamInfo method is:
142%
143% StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
144%
145% A description of each parameter follows:
146%
147% o image_info: the image info.
148%
149*/
150MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
151{
152 StreamInfo
153 *stream_info;
154
cristyb41ee102010-10-04 16:46:15 +0000155 stream_info=(StreamInfo *) AcquireQuantumMemory(1,sizeof(*stream_info));
cristy3ed852e2009-09-05 21:47:34 +0000156 if (stream_info == (StreamInfo *) NULL)
157 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
158 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
159 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
160 sizeof(*stream_info->pixels));
161 if (stream_info->pixels == (unsigned char *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 stream_info->map=ConstantString("RGB");
164 stream_info->storage_type=CharPixel;
165 stream_info->stream=AcquireImage(image_info);
166 stream_info->signature=MagickSignature;
167 return(stream_info);
168}
169
170/*
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172% %
173% %
174% %
175+ D e s t r o y P i x e l S t r e a m %
176% %
177% %
178% %
179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180%
181% DestroyPixelStream() deallocates memory associated with the pixel stream.
182%
183% The format of the DestroyPixelStream() method is:
184%
185% void DestroyPixelStream(Image *image)
186%
187% A description of each parameter follows:
188%
189% o image: the image.
190%
191*/
192
193static inline void RelinquishStreamPixels(CacheInfo *cache_info)
194{
195 assert(cache_info != (CacheInfo *) NULL);
196 if (cache_info->mapped == MagickFalse)
197 (void) RelinquishMagickMemory(cache_info->pixels);
198 else
199 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
200 cache_info->pixels=(PixelPacket *) NULL;
201 cache_info->indexes=(IndexPacket *) NULL;
202 cache_info->length=0;
203 cache_info->mapped=MagickFalse;
204}
205
206static void DestroyPixelStream(Image *image)
207{
208 CacheInfo
209 *cache_info;
210
211 MagickBooleanType
212 destroy;
213
214 assert(image != (Image *) NULL);
215 assert(image->signature == MagickSignature);
216 if (image->debug != MagickFalse)
217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
218 cache_info=(CacheInfo *) image->cache;
219 assert(cache_info->signature == MagickSignature);
220 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000221 LockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000222 cache_info->reference_count--;
223 if (cache_info->reference_count == 0)
224 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +0000225 UnlockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000226 if (destroy == MagickFalse)
227 return;
228 RelinquishStreamPixels(cache_info);
229 if (cache_info->nexus_info != (NexusInfo **) NULL)
230 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
231 cache_info->number_threads);
232 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
233 DestroySemaphoreInfo(&cache_info->disk_semaphore);
234 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
235 DestroySemaphoreInfo(&cache_info->semaphore);
236 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
237}
238
239/*
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241% %
242% %
243% %
244+ D e s t r o y S t r e a m I n f o %
245% %
246% %
247% %
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249%
250% DestroyStreamInfo() destroys memory associated with the StreamInfo
251% structure.
252%
253% The format of the DestroyStreamInfo method is:
254%
255% StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
256%
257% A description of each parameter follows:
258%
259% o stream_info: the stream info.
260%
261*/
262MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
263{
264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
265 assert(stream_info != (StreamInfo *) NULL);
266 assert(stream_info->signature == MagickSignature);
267 if (stream_info->map != (char *) NULL)
268 stream_info->map=DestroyString(stream_info->map);
269 if (stream_info->pixels != (unsigned char *) NULL)
270 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
271 stream_info->pixels);
272 if (stream_info->stream != (Image *) NULL)
273 {
274 (void) CloseBlob(stream_info->stream);
275 stream_info->stream=DestroyImage(stream_info->stream);
276 }
277 if (stream_info->quantum_info != (QuantumInfo *) NULL)
278 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
279 stream_info->signature=(~MagickSignature);
280 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
281 return(stream_info);
282}
283
284/*
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286% %
287% %
288% %
289+ 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 %
290% %
291% %
292% %
293%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294%
295% GetAuthenticIndexesFromStream() returns the indexes associated with the
296% last call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
297%
298% The format of the GetAuthenticIndexesFromStream() method is:
299%
300% IndexPacket *GetAuthenticIndexesFromStream(const Image *image)
301%
302% A description of each parameter follows:
303%
304% o image: the image.
305%
306*/
307static IndexPacket *GetAuthenticIndexesFromStream(const Image *image)
308{
309 CacheInfo
310 *cache_info;
311
312 assert(image != (Image *) NULL);
313 assert(image->signature == MagickSignature);
314 if (image->debug != MagickFalse)
315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
316 cache_info=(CacheInfo *) image->cache;
317 assert(cache_info->signature == MagickSignature);
318 return(cache_info->indexes);
319}
320
321/*
322%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323% %
324% %
325% %
326+ G e t A u t h e n t i c P i x e l S t r e a m %
327% %
328% %
329% %
330%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331%
332% GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
333% cache as defined by the geometry parameters. A pointer to the pixels is
334% returned if the pixels are transferred, otherwise a NULL is returned. For
335% streams this method is a no-op.
336%
337% The format of the GetAuthenticPixelsStream() method is:
338%
cristybb503372010-05-27 20:51:26 +0000339% PixelPacket *GetAuthenticPixelsStream(Image *image,const ssize_t x,
340% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000341% ExceptionInfo *exception)
342%
343% A description of each parameter follows:
344%
345% o image: the image.
346%
347% o x,y,columns,rows: These values define the perimeter of a region of
348% pixels.
349%
350% o exception: return any errors or warnings in this structure.
351%
352*/
cristybb503372010-05-27 20:51:26 +0000353static PixelPacket *GetAuthenticPixelsStream(Image *image,const ssize_t x,
354 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000355 ExceptionInfo *exception)
356{
357 PixelPacket
358 *pixels;
359
360 assert(image != (Image *) NULL);
361 assert(image->signature == MagickSignature);
362 if (image->debug != MagickFalse)
363 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
364 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
365 return(pixels);
366}
367
368/*
369%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370% %
371% %
372% %
373+ 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 %
374% %
375% %
376% %
377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378%
379% GetAuthenticPixelsFromStream() returns the pixels associated with the last
380% call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
381%
382% The format of the GetAuthenticPixelsFromStream() method is:
383%
384% PixelPacket *GetAuthenticPixelsFromStream(const Image image)
385%
386% A description of each parameter follows:
387%
388% o image: the image.
389%
390*/
391static PixelPacket *GetAuthenticPixelsFromStream(const Image *image)
392{
393 CacheInfo
394 *cache_info;
395
396 assert(image != (Image *) NULL);
397 assert(image->signature == MagickSignature);
398 if (image->debug != MagickFalse)
399 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
400 cache_info=(CacheInfo *) image->cache;
401 assert(cache_info->signature == MagickSignature);
402 return(cache_info->pixels);
403}
404
405/*
406%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407% %
408% %
409% %
410+ 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 %
411% %
412% %
413% %
414%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415%
416% GetOneAuthenticPixelFromStream() returns a single pixel at the specified
417% (x,y) location. The image background color is returned if an error occurs.
418%
419% The format of the GetOneAuthenticPixelFromStream() method is:
420%
421% MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
cristycfae90a2010-10-04 14:43:33 +0000422% const ssize_t x,const ssize_t y,PixelPacket *pixel,
423% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000424%
425% A description of each parameter follows:
426%
427% o image: the image.
428%
429% o pixel: return a pixel at the specified (x,y) location.
430%
431% o x,y: These values define the location of the pixel to return.
432%
433% o exception: return any errors or warnings in this structure.
434%
435*/
436static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
cristybb503372010-05-27 20:51:26 +0000437 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000438{
439 register PixelPacket
440 *pixels;
441
442 assert(image != (Image *) NULL);
443 assert(image->signature == MagickSignature);
444 *pixel=image->background_color;
445 pixels=GetAuthenticPixelsStream(image,x,y,1,1,exception);
446 if (pixels != (PixelPacket *) NULL)
447 return(MagickFalse);
448 *pixel=(*pixels);
449 return(MagickTrue);
450}
451
452/*
453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454% %
455% %
456% %
457+ 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 %
458% %
459% %
460% %
461%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462%
463% GetOneVirtualPixelFromStream() returns a single pixel at the specified
464% (x.y) location. The image background color is returned if an error occurs.
465%
466% The format of the GetOneVirtualPixelFromStream() method is:
467%
468% MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
cristybb503372010-05-27 20:51:26 +0000469% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
470% const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000471%
472% A description of each parameter follows:
473%
474% o image: the image.
475%
476% o virtual_pixel_method: the virtual pixel method.
477%
478% o x,y: These values define the location of the pixel to return.
479%
480% o pixel: return a pixel at the specified (x,y) location.
481%
482% o exception: return any errors or warnings in this structure.
483%
484*/
485static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000486 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +0000487 PixelPacket *pixel,ExceptionInfo *exception)
488{
489 const PixelPacket
490 *pixels;
491
492 assert(image != (Image *) NULL);
493 assert(image->signature == MagickSignature);
494 *pixel=image->background_color;
495 pixels=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
496 if (pixels != (const PixelPacket *) NULL)
497 return(MagickFalse);
498 *pixel=(*pixels);
499 return(MagickTrue);
500}
501
502/*
503%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
504% %
505% %
506% %
507+ G e t S t r e a m I n f o C l i e n t D a t a %
508% %
509% %
510% %
511%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512%
513% GetStreamInfoClientData() gets the stream info client data.
514%
515% The format of the SetStreamInfoClientData method is:
516%
517% const void *GetStreamInfoClientData(StreamInfo *stream_info)
518%
519% A description of each parameter follows:
520%
521% o stream_info: the stream info.
522%
523*/
524MagickExport const void *GetStreamInfoClientData(StreamInfo *stream_info)
525{
526 assert(stream_info != (StreamInfo *) NULL);
527 assert(stream_info->signature == MagickSignature);
528 return(stream_info->client_data);
529}
530
531/*
532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533% %
534% %
535% %
536+ 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 %
537% %
538% %
539% %
540%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541%
542% GetVirtualPixelsStream() returns the pixels associated with the last
543% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
544%
545% The format of the GetVirtualPixelsStream() method is:
546%
547% const IndexPacket *GetVirtualPixelsStream(const Image *image)
548%
549% A description of each parameter follows:
550%
551% o pixels: return the pixels associated with the last call to
552% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
553%
554% o image: the image.
555%
556*/
557static const PixelPacket *GetVirtualPixelsStream(const Image *image)
558{
559 CacheInfo
560 *cache_info;
561
562 assert(image != (Image *) NULL);
563 assert(image->signature == MagickSignature);
564 if (image->debug != MagickFalse)
565 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
566 cache_info=(CacheInfo *) image->cache;
567 assert(cache_info->signature == MagickSignature);
568 return(cache_info->pixels);
569}
570
571/*
572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573% %
574% %
575% %
576+ 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 %
577% %
578% %
579% %
580%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581%
582% GetVirtualIndexesFromStream() returns the indexes associated with the last
583% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
584%
585% The format of the GetVirtualIndexesFromStream() method is:
586%
587% const IndexPacket *GetVirtualIndexesFromStream(const Image *image)
588%
589% A description of each parameter follows:
590%
591% o image: the image.
592%
593*/
594static const IndexPacket *GetVirtualIndexesFromStream(const Image *image)
595{
596 CacheInfo
597 *cache_info;
598
599 assert(image != (Image *) NULL);
600 assert(image->signature == MagickSignature);
601 if (image->debug != MagickFalse)
602 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
603 cache_info=(CacheInfo *) image->cache;
604 assert(cache_info->signature == MagickSignature);
605 return(cache_info->indexes);
606}
607
608/*
609%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
610% %
611% %
612% %
613+ G e t V i r t u a l P i x e l S t r e a m %
614% %
615% %
616% %
617%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618%
619% GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
620% defined by the geometry parameters. A pointer to the pixels is returned if
621% the pixels are transferred, otherwise a NULL is returned. For streams this
622% method is a no-op.
623%
624% The format of the GetVirtualPixelStream() method is:
625%
626% const PixelPacket *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000627% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
628% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000629% ExceptionInfo *exception)
630%
631% A description of each parameter follows:
632%
633% o image: the image.
634%
635% o virtual_pixel_method: the virtual pixel method.
636%
637% o x,y,columns,rows: These values define the perimeter of a region of
638% pixels.
639%
640% o exception: return any errors or warnings in this structure.
641%
642*/
643
644static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
645 ExceptionInfo *exception)
646{
647 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
648 return(MagickFalse);
649 cache_info->mapped=MagickFalse;
650 cache_info->pixels=(PixelPacket *) AcquireMagickMemory((size_t)
651 cache_info->length);
652 if (cache_info->pixels == (PixelPacket *) NULL)
653 {
654 cache_info->mapped=MagickTrue;
655 cache_info->pixels=(PixelPacket *) MapBlob(-1,IOMode,0,(size_t)
656 cache_info->length);
657 }
658 if (cache_info->pixels == (PixelPacket *) NULL)
659 {
660 (void) ThrowMagickException(exception,GetMagickModule(),
661 ResourceLimitError,"MemoryAllocationFailed","`%s'",
662 cache_info->filename);
663 return(MagickFalse);
664 }
665 return(MagickTrue);
666}
667
668static const PixelPacket *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000669 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
670 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000671 ExceptionInfo *exception)
672{
673 CacheInfo
674 *cache_info;
675
676 MagickBooleanType
677 status;
678
679 MagickSizeType
680 number_pixels;
681
682 size_t
683 length;
684
685 /*
686 Validate pixel cache geometry.
687 */
688 assert(image != (const Image *) NULL);
689 assert(image->signature == MagickSignature);
690 if (image->debug != MagickFalse)
691 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy5dd71882010-08-01 20:53:13 +0000692 if ((x < 0) || (y < 0) ||
693 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
694 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
695 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000696 {
697 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
698 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
699 return((PixelPacket *) NULL);
700 }
701 cache_info=(CacheInfo *) image->cache;
702 assert(cache_info->signature == MagickSignature);
703 /*
704 Pixels are stored in a temporary buffer until they are synced to the cache.
705 */
cristy33503f52010-10-04 17:32:27 +0000706 cache_info->active_index_channel=((image->storage_class == PseudoClass) ||
707 (image->colorspace == CMYKColorspace)) ? MagickTrue : MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000708 number_pixels=(MagickSizeType) columns*rows;
709 length=(size_t) number_pixels*sizeof(PixelPacket);
cristy33503f52010-10-04 17:32:27 +0000710 if (cache_info->active_index_channel != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000711 length+=number_pixels*sizeof(IndexPacket);
712 if (cache_info->pixels == (PixelPacket *) NULL)
713 {
714 cache_info->length=length;
715 status=AcquireStreamPixels(cache_info,exception);
716 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000717 {
718 cache_info->length=0;
719 return((PixelPacket *) NULL);
720 }
cristy3ed852e2009-09-05 21:47:34 +0000721 }
722 else
723 if (cache_info->length != length)
724 {
725 RelinquishStreamPixels(cache_info);
726 cache_info->length=length;
727 status=AcquireStreamPixels(cache_info,exception);
728 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000729 {
730 cache_info->length=0;
731 return((PixelPacket *) NULL);
732 }
cristy3ed852e2009-09-05 21:47:34 +0000733 }
734 cache_info->indexes=(IndexPacket *) NULL;
cristy33503f52010-10-04 17:32:27 +0000735 if (cache_info->active_index_channel != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000736 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
737 return(cache_info->pixels);
738}
739
740/*
741%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742% %
743% %
744% %
745+ O p e n S t r e a m %
746% %
747% %
748% %
749%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750%
751% OpenStream() opens a stream for writing by the StreamImage() method.
752%
753% The format of the OpenStream method is:
754%
755% MagickBooleanType OpenStream(const ImageInfo *image_info,
756% StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
757%
758% A description of each parameter follows:
759%
760% o image_info: the image info.
761%
762% o stream_info: the stream info.
763%
764% o filename: the stream filename.
765%
766% o exception: return any errors or warnings in this structure.
767%
768*/
769MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
770 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
771{
772 MagickBooleanType
773 status;
774
775 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
776 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
777 return(status);
778}
779
780/*
781%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782% %
783% %
784% %
785+ 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 %
786% %
787% %
788% %
789%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790%
791% QueueAuthenticPixelsStream() allocates an area to store image pixels as
792% defined by the region rectangle and returns a pointer to the area. This
793% area is subsequently transferred from the pixel cache with method
794% SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
795% pixels are transferred, otherwise a NULL is returned.
796%
797% The format of the QueueAuthenticPixelsStream() method is:
798%
cristybb503372010-05-27 20:51:26 +0000799% PixelPacket *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
800% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000801% ExceptionInfo *exception)
802%
803% A description of each parameter follows:
804%
805% o image: the image.
806%
807% o x,y,columns,rows: These values define the perimeter of a region of
808% pixels.
809%
810*/
cristybb503372010-05-27 20:51:26 +0000811static PixelPacket *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
812 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000813 ExceptionInfo *exception)
814{
815 CacheInfo
816 *cache_info;
817
818 MagickSizeType
819 number_pixels;
820
821 size_t
822 length;
823
824 StreamHandler
825 stream_handler;
826
827 /*
828 Validate pixel cache geometry.
829 */
830 assert(image != (Image *) NULL);
cristycfae90a2010-10-04 14:43:33 +0000831 if ((x < 0) || (y < 0) ||
832 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
833 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
834 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000835 {
836 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
837 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
838 return((PixelPacket *) NULL);
839 }
840 stream_handler=GetBlobStreamHandler(image);
841 if (stream_handler == (StreamHandler) NULL)
842 {
843 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
844 "NoStreamHandlerIsDefined","`%s'",image->filename);
845 return((PixelPacket *) NULL);
846 }
847 cache_info=(CacheInfo *) image->cache;
848 assert(cache_info->signature == MagickSignature);
849 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
850 (image->colorspace != GetPixelCacheColorspace(image->cache)))
851 {
852 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
853 (void) stream_handler(image,(const void *) NULL,(size_t)
854 cache_info->columns);
855 cache_info->storage_class=image->storage_class;
856 cache_info->colorspace=image->colorspace;
857 cache_info->columns=image->columns;
858 cache_info->rows=image->rows;
859 image->cache=cache_info;
860 }
861 /*
862 Pixels are stored in a temporary buffer until they are synced to the cache.
863 */
cristy33503f52010-10-04 17:32:27 +0000864 cache_info->active_index_channel=((image->storage_class == PseudoClass) ||
865 (image->colorspace == CMYKColorspace)) ? MagickTrue : MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000866 cache_info->columns=columns;
867 cache_info->rows=rows;
868 number_pixels=(MagickSizeType) columns*rows;
869 length=(size_t) number_pixels*sizeof(PixelPacket);
cristy33503f52010-10-04 17:32:27 +0000870 if (cache_info->active_index_channel != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000871 length+=number_pixels*sizeof(IndexPacket);
872 if (cache_info->pixels == (PixelPacket *) NULL)
873 {
874 cache_info->pixels=(PixelPacket *) AcquireMagickMemory(length);
875 cache_info->length=(MagickSizeType) length;
876 }
877 else
878 if (cache_info->length < (MagickSizeType) length)
879 {
880 cache_info->pixels=(PixelPacket *) ResizeMagickMemory(
881 cache_info->pixels,length);
882 cache_info->length=(MagickSizeType) length;
883 }
884 if (cache_info->pixels == (void *) NULL)
885 return((PixelPacket *) NULL);
886 cache_info->indexes=(IndexPacket *) NULL;
cristy33503f52010-10-04 17:32:27 +0000887 if (cache_info->active_index_channel != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000888 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
889 return(cache_info->pixels);
890}
891
892/*
893%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894% %
895% %
896% %
897% R e a d S t r e a m %
898% %
899% %
900% %
901%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
902%
903% ReadStream() makes the image pixels available to a user supplied callback
904% method immediately upon reading a scanline with the ReadImage() method.
905%
906% The format of the ReadStream() method is:
907%
908% Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
909% ExceptionInfo *exception)
910%
911% A description of each parameter follows:
912%
913% o image_info: the image info.
914%
915% o stream: a callback method.
916%
917% o exception: return any errors or warnings in this structure.
918%
919*/
920MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
921 ExceptionInfo *exception)
922{
923 CacheMethods
924 cache_methods;
925
926 Image
927 *image;
928
929 ImageInfo
930 *read_info;
931
932 /*
933 Stream image pixels.
934 */
935 assert(image_info != (ImageInfo *) NULL);
936 assert(image_info->signature == MagickSignature);
937 if (image_info->debug != MagickFalse)
938 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
939 image_info->filename);
940 assert(exception != (ExceptionInfo *) NULL);
941 assert(exception->signature == MagickSignature);
942 read_info=CloneImageInfo(image_info);
943 read_info->cache=AcquirePixelCache(0);
944 GetPixelCacheMethods(&cache_methods);
945 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
946 cache_methods.get_virtual_indexes_from_handler=GetVirtualIndexesFromStream;
947 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
948 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
949 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
950 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
951 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
952 cache_methods.get_authentic_indexes_from_handler=
953 GetAuthenticIndexesFromStream;
954 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
955 cache_methods.get_one_authentic_pixel_from_handler=
956 GetOneAuthenticPixelFromStream;
957 cache_methods.destroy_pixel_handler=DestroyPixelStream;
958 SetPixelCacheMethods(read_info->cache,&cache_methods);
959 read_info->stream=stream;
960 image=ReadImage(read_info,exception);
961 read_info=DestroyImageInfo(read_info);
962 return(image);
963}
964
965/*
966%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967% %
968% %
969% %
970+ S e t S t r e a m I n f o C l i e n t D a t a %
971% %
972% %
973% %
974%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975%
976% SetStreamInfoClientData() sets the stream info client data.
977%
978% The format of the SetStreamInfoClientData method is:
979%
980% void SetStreamInfoClientData(StreamInfo *stream_info,
981% const void *client_data)
982%
983% A description of each parameter follows:
984%
985% o stream_info: the stream info.
986%
987% o client_data: the client data.
988%
989*/
990MagickExport void SetStreamInfoClientData(StreamInfo *stream_info,
991 const void *client_data)
992{
993 assert(stream_info != (StreamInfo *) NULL);
994 assert(stream_info->signature == MagickSignature);
995 stream_info->client_data=client_data;
996}
997
998/*
999%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000% %
1001% %
1002% %
1003+ S e t S t r e a m I n f o M a p %
1004% %
1005% %
1006% %
1007%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008%
1009% SetStreamInfoMap() sets the stream info map member.
1010%
1011% The format of the SetStreamInfoMap method is:
1012%
1013% void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1014%
1015% A description of each parameter follows:
1016%
1017% o stream_info: the stream info.
1018%
1019% o map: the map.
1020%
1021*/
1022MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1023{
1024 assert(stream_info != (StreamInfo *) NULL);
1025 assert(stream_info->signature == MagickSignature);
1026 (void) CloneString(&stream_info->map,map);
1027}
1028
1029/*
1030%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1031% %
1032% %
1033% %
1034+ S e t S t r e a m I n f o S t o r a g e T y p e %
1035% %
1036% %
1037% %
1038%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039%
1040% SetStreamInfoStorageType() sets the stream info storage type member.
1041%
1042% The format of the SetStreamInfoStorageType method is:
1043%
1044% void SetStreamInfoStorageType(StreamInfo *stream_info,
1045% const StoreageType *storage_type)
1046%
1047% A description of each parameter follows:
1048%
1049% o stream_info: the stream info.
1050%
1051% o storage_type: the storage type.
1052%
1053*/
1054MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1055 const StorageType storage_type)
1056{
1057 assert(stream_info != (StreamInfo *) NULL);
1058 assert(stream_info->signature == MagickSignature);
1059 stream_info->storage_type=storage_type;
1060}
1061
1062/*
1063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064% %
1065% %
1066% %
1067+ S t r e a m I m a g e %
1068% %
1069% %
1070% %
1071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1072%
1073% StreamImage() streams pixels from an image and writes them in a user
1074% defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1075%
1076% The format of he wStreamImage() method is:
1077%
1078% Image *StreamImage(const ImageInfo *image_info,
1079% StreamInfo *stream_info,ExceptionInfo *exception)
1080%
1081% A description of each parameter follows:
1082%
1083% o image_info: the image info.
1084%
1085% o stream_info: the stream info.
1086%
1087% o exception: return any errors or warnings in this structure.
1088%
1089*/
1090
1091#if defined(__cplusplus) || defined(c_plusplus)
1092extern "C" {
1093#endif
1094
1095static size_t WriteStreamImage(const Image *image,const void *pixels,
1096 const size_t columns)
1097{
cristye3664f42010-05-14 00:59:57 +00001098 CacheInfo
1099 *cache_info;
1100
cristy3ed852e2009-09-05 21:47:34 +00001101 RectangleInfo
1102 extract_info;
1103
1104 size_t
1105 length,
1106 packet_size;
1107
1108 ssize_t
1109 count;
1110
1111 StreamInfo
1112 *stream_info;
1113
1114 stream_info=(StreamInfo *) image->client_data;
1115 switch (stream_info->storage_type)
1116 {
1117 default: packet_size=sizeof(char); break;
1118 case CharPixel: packet_size=sizeof(char); break;
1119 case DoublePixel: packet_size=sizeof(double); break;
1120 case FloatPixel: packet_size=sizeof(float); break;
1121 case IntegerPixel: packet_size=sizeof(int); break;
cristybb503372010-05-27 20:51:26 +00001122 case LongPixel: packet_size=sizeof(ssize_t); break;
cristy3ed852e2009-09-05 21:47:34 +00001123 case QuantumPixel: packet_size=sizeof(Quantum); break;
1124 case ShortPixel: packet_size=sizeof(unsigned short); break;
1125 }
cristye3664f42010-05-14 00:59:57 +00001126 cache_info=(CacheInfo *) image->cache;
1127 assert(cache_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001128 packet_size*=strlen(stream_info->map);
cristye3664f42010-05-14 00:59:57 +00001129 length=packet_size*cache_info->columns*cache_info->rows;
cristy3ed852e2009-09-05 21:47:34 +00001130 if (image != stream_info->image)
1131 {
1132 ImageInfo
1133 *write_info;
1134
1135 /*
1136 Prepare stream for writing.
1137 */
1138 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1139 stream_info->pixels,length,sizeof(*stream_info->pixels));
cristy5dd71882010-08-01 20:53:13 +00001140 if (stream_info->pixels == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001141 return(0);
1142 stream_info->image=image;
1143 write_info=CloneImageInfo(stream_info->image_info);
cristyd965a422010-03-03 17:47:35 +00001144 (void) SetImageInfo(write_info,1,stream_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001145 if (write_info->extract != (char *) NULL)
1146 (void) ParseAbsoluteGeometry(write_info->extract,
1147 &stream_info->extract_info);
1148 stream_info->y=0;
1149 write_info=DestroyImageInfo(write_info);
1150 }
1151 extract_info=stream_info->extract_info;
1152 if ((extract_info.width == 0) ||
1153 (extract_info.height == 0))
1154 {
1155 /*
1156 Write all pixels to stream.
1157 */
1158 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1159 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1160 stream_info->y++;
1161 return(count == 0 ? 0 : columns);
1162 }
1163 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001164 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001165 {
1166 stream_info->y++;
1167 return(columns);
1168 }
1169 /*
1170 Write a portion of the pixel row to the stream.
1171 */
1172 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1173 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001174 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1175 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001176 stream_info->y++;
1177 return(count == 0 ? 0 : columns);
1178}
1179
1180#if defined(__cplusplus) || defined(c_plusplus)
1181}
1182#endif
1183
1184MagickExport Image *StreamImage(const ImageInfo *image_info,
1185 StreamInfo *stream_info,ExceptionInfo *exception)
1186{
1187 Image
1188 *image;
1189
1190 ImageInfo
1191 *read_info;
1192
1193 assert(image_info != (const ImageInfo *) NULL);
1194 assert(image_info->signature == MagickSignature);
1195 if (image_info->debug != MagickFalse)
1196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1197 image_info->filename);
1198 assert(stream_info != (StreamInfo *) NULL);
1199 assert(stream_info->signature == MagickSignature);
1200 assert(exception != (ExceptionInfo *) NULL);
1201 read_info=CloneImageInfo(image_info);
1202 stream_info->image_info=image_info;
1203 stream_info->exception=exception;
1204 read_info->client_data=(void *) stream_info;
1205 image=ReadStream(read_info,&WriteStreamImage,exception);
1206 read_info=DestroyImageInfo(read_info);
1207 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1208 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1209 image=DestroyImage(image);
1210 return(image);
1211}
1212
1213/*
1214%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1215% %
1216% %
1217% %
1218+ S t r e a m I m a g e P i x e l s %
1219% %
1220% %
1221% %
1222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1223%
1224% StreamImagePixels() extracts pixel data from an image and returns it in the
1225% stream_info->pixels structure in the format as defined by
1226% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1227%
1228% The format of the StreamImagePixels method is:
1229%
1230% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1231% const Image *image,ExceptionInfo *exception)
1232%
1233% A description of each parameter follows:
1234%
1235% o stream_info: the stream info.
1236%
1237% o image: the image.
1238%
1239% o exception: return any errors or warnings in this structure.
1240%
1241*/
1242static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1243 const Image *image,ExceptionInfo *exception)
1244{
1245 QuantumInfo
1246 *quantum_info;
1247
1248 QuantumType
1249 *quantum_map;
1250
cristybb503372010-05-27 20:51:26 +00001251 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001252 i,
1253 x;
1254
1255 register const PixelPacket
1256 *p;
1257
1258 register IndexPacket
1259 *indexes;
1260
1261 size_t
1262 length;
1263
1264 assert(stream_info != (StreamInfo *) NULL);
1265 assert(stream_info->signature == MagickSignature);
1266 assert(image != (Image *) NULL);
1267 assert(image->signature == MagickSignature);
1268 if (image->debug != MagickFalse)
1269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1270 length=strlen(stream_info->map);
1271 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1272 if (quantum_map == (QuantumType *) NULL)
1273 {
1274 (void) ThrowMagickException(exception,GetMagickModule(),
1275 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1276 return(MagickFalse);
1277 }
cristybb503372010-05-27 20:51:26 +00001278 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001279 {
1280 switch (stream_info->map[i])
1281 {
1282 case 'A':
1283 case 'a':
1284 {
1285 quantum_map[i]=AlphaQuantum;
1286 break;
1287 }
1288 case 'B':
1289 case 'b':
1290 {
1291 quantum_map[i]=BlueQuantum;
1292 break;
1293 }
1294 case 'C':
1295 case 'c':
1296 {
1297 quantum_map[i]=CyanQuantum;
1298 if (image->colorspace == CMYKColorspace)
1299 break;
1300 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1301 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1302 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1303 return(MagickFalse);
1304 }
1305 case 'g':
1306 case 'G':
1307 {
1308 quantum_map[i]=GreenQuantum;
1309 break;
1310 }
1311 case 'I':
1312 case 'i':
1313 {
1314 quantum_map[i]=IndexQuantum;
1315 break;
1316 }
1317 case 'K':
1318 case 'k':
1319 {
1320 quantum_map[i]=BlackQuantum;
1321 if (image->colorspace == CMYKColorspace)
1322 break;
1323 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1324 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1325 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1326 return(MagickFalse);
1327 }
1328 case 'M':
1329 case 'm':
1330 {
1331 quantum_map[i]=MagentaQuantum;
1332 if (image->colorspace == CMYKColorspace)
1333 break;
1334 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1335 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1336 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1337 return(MagickFalse);
1338 }
1339 case 'o':
1340 case 'O':
1341 {
1342 quantum_map[i]=OpacityQuantum;
1343 break;
1344 }
1345 case 'P':
1346 case 'p':
1347 {
1348 quantum_map[i]=UndefinedQuantum;
1349 break;
1350 }
1351 case 'R':
1352 case 'r':
1353 {
1354 quantum_map[i]=RedQuantum;
1355 break;
1356 }
1357 case 'Y':
1358 case 'y':
1359 {
1360 quantum_map[i]=YellowQuantum;
1361 if (image->colorspace == CMYKColorspace)
1362 break;
1363 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1364 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1365 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1366 return(MagickFalse);
1367 }
1368 default:
1369 {
1370 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1371 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1372 "UnrecognizedPixelMap","`%s'",stream_info->map);
1373 return(MagickFalse);
1374 }
1375 }
1376 }
1377 quantum_info=stream_info->quantum_info;
1378 switch (stream_info->storage_type)
1379 {
1380 case CharPixel:
1381 {
1382 register unsigned char
1383 *q;
1384
1385 q=(unsigned char *) stream_info->pixels;
1386 if (LocaleCompare(stream_info->map,"BGR") == 0)
1387 {
1388 p=GetAuthenticPixelQueue(image);
1389 if (p == (const PixelPacket *) NULL)
1390 break;
cristybb503372010-05-27 20:51:26 +00001391 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001392 {
cristyce70c172010-01-07 17:15:30 +00001393 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1394 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1395 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001396 p++;
1397 }
1398 break;
1399 }
1400 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1401 {
1402 p=GetAuthenticPixelQueue(image);
1403 if (p == (const PixelPacket *) NULL)
1404 break;
cristybb503372010-05-27 20:51:26 +00001405 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001406 {
cristyce70c172010-01-07 17:15:30 +00001407 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1408 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1409 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00001410 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001411 p++;
1412 }
1413 break;
1414 }
1415 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1416 {
1417 p=GetAuthenticPixelQueue(image);
1418 if (p == (const PixelPacket *) NULL)
1419 break;
cristybb503372010-05-27 20:51:26 +00001420 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001421 {
cristyce70c172010-01-07 17:15:30 +00001422 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1423 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1424 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001425 *q++=ScaleQuantumToChar((Quantum) 0);
1426 p++;
1427 }
1428 break;
1429 }
1430 if (LocaleCompare(stream_info->map,"I") == 0)
1431 {
1432 p=GetAuthenticPixelQueue(image);
1433 if (p == (const PixelPacket *) NULL)
1434 break;
cristybb503372010-05-27 20:51:26 +00001435 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001436 {
1437 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1438 p++;
1439 }
1440 break;
1441 }
1442 if (LocaleCompare(stream_info->map,"RGB") == 0)
1443 {
1444 p=GetAuthenticPixelQueue(image);
1445 if (p == (const PixelPacket *) NULL)
1446 break;
cristybb503372010-05-27 20:51:26 +00001447 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001448 {
cristyce70c172010-01-07 17:15:30 +00001449 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1450 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1451 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001452 p++;
1453 }
1454 break;
1455 }
1456 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1457 {
1458 p=GetAuthenticPixelQueue(image);
1459 if (p == (const PixelPacket *) NULL)
1460 break;
cristybb503372010-05-27 20:51:26 +00001461 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001462 {
cristyce70c172010-01-07 17:15:30 +00001463 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1464 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1465 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00001466 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001467 p++;
1468 }
1469 break;
1470 }
1471 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1472 {
1473 p=GetAuthenticPixelQueue(image);
1474 if (p == (const PixelPacket *) NULL)
1475 break;
cristybb503372010-05-27 20:51:26 +00001476 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001477 {
cristyce70c172010-01-07 17:15:30 +00001478 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1479 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1480 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001481 *q++=ScaleQuantumToChar((Quantum) 0);
1482 p++;
1483 }
1484 break;
1485 }
1486 p=GetAuthenticPixelQueue(image);
1487 if (p == (const PixelPacket *) NULL)
1488 break;
1489 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001490 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001491 {
cristybb503372010-05-27 20:51:26 +00001492 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001493 {
1494 *q=0;
1495 switch (quantum_map[i])
1496 {
1497 case RedQuantum:
1498 case CyanQuantum:
1499 {
cristyce70c172010-01-07 17:15:30 +00001500 *q=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001501 break;
1502 }
1503 case GreenQuantum:
1504 case MagentaQuantum:
1505 {
cristyce70c172010-01-07 17:15:30 +00001506 *q=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001507 break;
1508 }
1509 case BlueQuantum:
1510 case YellowQuantum:
1511 {
cristyce70c172010-01-07 17:15:30 +00001512 *q=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001513 break;
1514 }
1515 case AlphaQuantum:
1516 {
cristy46f08202010-01-10 04:04:21 +00001517 *q=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001518 break;
1519 }
1520 case OpacityQuantum:
1521 {
cristyce70c172010-01-07 17:15:30 +00001522 *q=ScaleQuantumToChar(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001523 break;
1524 }
1525 case BlackQuantum:
1526 {
1527 if (image->colorspace == CMYKColorspace)
1528 *q=ScaleQuantumToChar(indexes[x]);
1529 break;
1530 }
1531 case IndexQuantum:
1532 {
1533 *q=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1534 break;
1535 }
1536 default:
1537 break;
1538 }
1539 q++;
1540 }
1541 p++;
1542 }
1543 break;
1544 }
1545 case DoublePixel:
1546 {
1547 register double
1548 *q;
1549
1550 q=(double *) stream_info->pixels;
1551 if (LocaleCompare(stream_info->map,"BGR") == 0)
1552 {
1553 p=GetAuthenticPixelQueue(image);
1554 if (p == (const PixelPacket *) NULL)
1555 break;
cristybb503372010-05-27 20:51:26 +00001556 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001557 {
cristy46f08202010-01-10 04:04:21 +00001558 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1559 quantum_info->scale+quantum_info->minimum);
1560 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1561 quantum_info->scale+quantum_info->minimum);
1562 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1563 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001564 p++;
1565 }
1566 break;
1567 }
1568 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1569 {
1570 p=GetAuthenticPixelQueue(image);
1571 if (p == (const PixelPacket *) NULL)
1572 break;
cristybb503372010-05-27 20:51:26 +00001573 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001574 {
cristy46f08202010-01-10 04:04:21 +00001575 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1576 quantum_info->scale+quantum_info->minimum);
1577 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1578 quantum_info->scale+quantum_info->minimum);
1579 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1580 quantum_info->scale+quantum_info->minimum);
1581 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001582 quantum_info->scale+quantum_info->minimum);
1583 p++;
1584 }
1585 break;
1586 }
1587 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1588 {
1589 p=GetAuthenticPixelQueue(image);
1590 if (p == (const PixelPacket *) NULL)
1591 break;
cristybb503372010-05-27 20:51:26 +00001592 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001593 {
cristy46f08202010-01-10 04:04:21 +00001594 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1595 quantum_info->scale+quantum_info->minimum);
1596 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1597 quantum_info->scale+quantum_info->minimum);
1598 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1599 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001600 *q++=0.0;
1601 p++;
1602 }
1603 break;
1604 }
1605 if (LocaleCompare(stream_info->map,"I") == 0)
1606 {
1607 p=GetAuthenticPixelQueue(image);
1608 if (p == (const PixelPacket *) NULL)
1609 break;
cristybb503372010-05-27 20:51:26 +00001610 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001611 {
1612 *q++=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1613 quantum_info->scale+quantum_info->minimum);
1614 p++;
1615 }
1616 break;
1617 }
1618 if (LocaleCompare(stream_info->map,"RGB") == 0)
1619 {
1620 p=GetAuthenticPixelQueue(image);
1621 if (p == (const PixelPacket *) NULL)
1622 break;
cristybb503372010-05-27 20:51:26 +00001623 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001624 {
cristy46f08202010-01-10 04:04:21 +00001625 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1626 quantum_info->scale+quantum_info->minimum);
1627 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1628 quantum_info->scale+quantum_info->minimum);
1629 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1630 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001631 p++;
1632 }
1633 break;
1634 }
1635 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1636 {
1637 p=GetAuthenticPixelQueue(image);
1638 if (p == (const PixelPacket *) NULL)
1639 break;
cristybb503372010-05-27 20:51:26 +00001640 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001641 {
cristy46f08202010-01-10 04:04:21 +00001642 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1643 quantum_info->scale+quantum_info->minimum);
1644 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1645 quantum_info->scale+quantum_info->minimum);
1646 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1647 quantum_info->scale+quantum_info->minimum);
1648 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001649 quantum_info->scale+quantum_info->minimum);
1650 p++;
1651 }
1652 break;
1653 }
1654 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1655 {
1656 p=GetAuthenticPixelQueue(image);
1657 if (p == (const PixelPacket *) NULL)
1658 break;
cristybb503372010-05-27 20:51:26 +00001659 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001660 {
cristy46f08202010-01-10 04:04:21 +00001661 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1662 quantum_info->scale+quantum_info->minimum);
1663 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1664 quantum_info->scale+quantum_info->minimum);
1665 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1666 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001667 *q++=0.0;
1668 p++;
1669 }
1670 break;
1671 }
1672 p=GetAuthenticPixelQueue(image);
1673 if (p == (const PixelPacket *) NULL)
1674 break;
1675 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001676 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001677 {
cristybb503372010-05-27 20:51:26 +00001678 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001679 {
1680 *q=0;
1681 switch (quantum_map[i])
1682 {
1683 case RedQuantum:
1684 case CyanQuantum:
1685 {
cristy46f08202010-01-10 04:04:21 +00001686 *q=(double) ((QuantumScale*GetRedPixelComponent(p))*
1687 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001688 break;
1689 }
1690 case GreenQuantum:
1691 case MagentaQuantum:
1692 {
cristy46f08202010-01-10 04:04:21 +00001693 *q=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1694 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001695 break;
1696 }
1697 case BlueQuantum:
1698 case YellowQuantum:
1699 {
cristy46f08202010-01-10 04:04:21 +00001700 *q=(double) ((QuantumScale*GetBluePixelComponent(p))*
1701 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001702 break;
1703 }
1704 case AlphaQuantum:
1705 {
cristy46f08202010-01-10 04:04:21 +00001706 *q=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1707 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001708 break;
1709 }
1710 case OpacityQuantum:
1711 {
cristy46f08202010-01-10 04:04:21 +00001712 *q=(double) ((QuantumScale*GetOpacityPixelComponent(p))*
1713 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001714 break;
1715 }
1716 case BlackQuantum:
1717 {
1718 if (image->colorspace == CMYKColorspace)
1719 *q=(double) ((QuantumScale*indexes[x])*quantum_info->scale+
1720 quantum_info->minimum);
1721 break;
1722 }
1723 case IndexQuantum:
1724 {
1725 *q=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1726 quantum_info->scale+quantum_info->minimum);
1727 break;
1728 }
1729 default:
1730 *q=0;
1731 }
1732 q++;
1733 }
1734 p++;
1735 }
1736 break;
1737 }
1738 case FloatPixel:
1739 {
1740 register float
1741 *q;
1742
1743 q=(float *) stream_info->pixels;
1744 if (LocaleCompare(stream_info->map,"BGR") == 0)
1745 {
1746 p=GetAuthenticPixelQueue(image);
1747 if (p == (const PixelPacket *) NULL)
1748 break;
cristybb503372010-05-27 20:51:26 +00001749 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001750 {
cristy46f08202010-01-10 04:04:21 +00001751 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1752 quantum_info->scale+quantum_info->minimum);
1753 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1754 quantum_info->scale+quantum_info->minimum);
1755 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1756 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001757 p++;
1758 }
1759 break;
1760 }
1761 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1762 {
1763 p=GetAuthenticPixelQueue(image);
1764 if (p == (const PixelPacket *) NULL)
1765 break;
cristybb503372010-05-27 20:51:26 +00001766 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001767 {
cristy46f08202010-01-10 04:04:21 +00001768 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1769 quantum_info->scale+quantum_info->minimum);
1770 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1771 quantum_info->scale+quantum_info->minimum);
1772 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1773 quantum_info->scale+quantum_info->minimum);
1774 *q++=(float) ((QuantumScale*(Quantum) (GetAlphaPixelComponent(p)))*
cristy3ed852e2009-09-05 21:47:34 +00001775 quantum_info->scale+quantum_info->minimum);
1776 p++;
1777 }
1778 break;
1779 }
1780 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1781 {
1782 p=GetAuthenticPixelQueue(image);
1783 if (p == (const PixelPacket *) NULL)
1784 break;
cristybb503372010-05-27 20:51:26 +00001785 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001786 {
cristy46f08202010-01-10 04:04:21 +00001787 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1788 quantum_info->scale+quantum_info->minimum);
1789 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1790 quantum_info->scale+quantum_info->minimum);
1791 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1792 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001793 *q++=0.0;
1794 p++;
1795 }
1796 break;
1797 }
1798 if (LocaleCompare(stream_info->map,"I") == 0)
1799 {
1800 p=GetAuthenticPixelQueue(image);
1801 if (p == (const PixelPacket *) NULL)
1802 break;
cristybb503372010-05-27 20:51:26 +00001803 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001804 {
1805 *q++=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1806 quantum_info->scale+quantum_info->minimum);
1807 p++;
1808 }
1809 break;
1810 }
1811 if (LocaleCompare(stream_info->map,"RGB") == 0)
1812 {
1813 p=GetAuthenticPixelQueue(image);
1814 if (p == (const PixelPacket *) NULL)
1815 break;
cristybb503372010-05-27 20:51:26 +00001816 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001817 {
cristy46f08202010-01-10 04:04:21 +00001818 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1819 quantum_info->scale+quantum_info->minimum);
1820 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1821 quantum_info->scale+quantum_info->minimum);
1822 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1823 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001824 p++;
1825 }
1826 break;
1827 }
1828 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1829 {
1830 p=GetAuthenticPixelQueue(image);
1831 if (p == (const PixelPacket *) NULL)
1832 break;
cristybb503372010-05-27 20:51:26 +00001833 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001834 {
cristy46f08202010-01-10 04:04:21 +00001835 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1836 quantum_info->scale+quantum_info->minimum);
1837 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1838 quantum_info->scale+quantum_info->minimum);
1839 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1840 quantum_info->scale+quantum_info->minimum);
1841 *q++=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001842 quantum_info->scale+quantum_info->minimum);
1843 p++;
1844 }
1845 break;
1846 }
1847 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1848 {
1849 p=GetAuthenticPixelQueue(image);
1850 if (p == (const PixelPacket *) NULL)
1851 break;
cristybb503372010-05-27 20:51:26 +00001852 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001853 {
cristy46f08202010-01-10 04:04:21 +00001854 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1855 quantum_info->scale+quantum_info->minimum);
1856 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1857 quantum_info->scale+quantum_info->minimum);
1858 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1859 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001860 *q++=0.0;
1861 p++;
1862 }
1863 break;
1864 }
1865 p=GetAuthenticPixelQueue(image);
1866 if (p == (const PixelPacket *) NULL)
1867 break;
1868 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001869 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001870 {
cristybb503372010-05-27 20:51:26 +00001871 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001872 {
1873 *q=0;
1874 switch (quantum_map[i])
1875 {
1876 case RedQuantum:
1877 case CyanQuantum:
1878 {
cristy46f08202010-01-10 04:04:21 +00001879 *q=(float) ((QuantumScale*GetRedPixelComponent(p))*
1880 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001881 break;
1882 }
1883 case GreenQuantum:
1884 case MagentaQuantum:
1885 {
cristy46f08202010-01-10 04:04:21 +00001886 *q=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1887 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001888 break;
1889 }
1890 case BlueQuantum:
1891 case YellowQuantum:
1892 {
cristy46f08202010-01-10 04:04:21 +00001893 *q=(float) ((QuantumScale*GetBluePixelComponent(p))*
1894 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001895 break;
1896 }
1897 case AlphaQuantum:
1898 {
cristy46f08202010-01-10 04:04:21 +00001899 *q=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1900 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001901 break;
1902 }
1903 case OpacityQuantum:
1904 {
cristy46f08202010-01-10 04:04:21 +00001905 *q=(float) ((QuantumScale*GetOpacityPixelComponent(p))*
1906 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001907 break;
1908 }
1909 case BlackQuantum:
1910 {
1911 if (image->colorspace == CMYKColorspace)
1912 *q=(float) ((QuantumScale*indexes[x])*quantum_info->scale+
1913 quantum_info->minimum);
1914 break;
1915 }
1916 case IndexQuantum:
1917 {
1918 *q=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1919 quantum_info->scale+quantum_info->minimum);
1920 break;
1921 }
1922 default:
1923 *q=0;
1924 }
1925 q++;
1926 }
1927 p++;
1928 }
1929 break;
1930 }
1931 case IntegerPixel:
1932 {
1933 register unsigned int
1934 *q;
1935
1936 q=(unsigned int *) stream_info->pixels;
1937 if (LocaleCompare(stream_info->map,"BGR") == 0)
1938 {
1939 p=GetAuthenticPixelQueue(image);
1940 if (p == (const PixelPacket *) NULL)
1941 break;
cristybb503372010-05-27 20:51:26 +00001942 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001943 {
cristyce70c172010-01-07 17:15:30 +00001944 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1945 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1946 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001947 p++;
1948 }
1949 break;
1950 }
1951 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1952 {
1953 p=GetAuthenticPixelQueue(image);
1954 if (p == (const PixelPacket *) NULL)
1955 break;
cristybb503372010-05-27 20:51:26 +00001956 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001957 {
cristyce70c172010-01-07 17:15:30 +00001958 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1959 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1960 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001961 *q++=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00001962 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001963 p++;
1964 }
1965 break;
1966 }
1967 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1968 {
1969 p=GetAuthenticPixelQueue(image);
1970 if (p == (const PixelPacket *) NULL)
1971 break;
cristybb503372010-05-27 20:51:26 +00001972 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001973 {
cristyce70c172010-01-07 17:15:30 +00001974 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1975 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1976 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001977 *q++=0U;
1978 p++;
1979 }
1980 break;
1981 }
1982 if (LocaleCompare(stream_info->map,"I") == 0)
1983 {
1984 p=GetAuthenticPixelQueue(image);
1985 if (p == (const PixelPacket *) NULL)
1986 break;
cristybb503372010-05-27 20:51:26 +00001987 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001988 {
1989 *q++=(unsigned int) ScaleQuantumToLong(
1990 PixelIntensityToQuantum(p));
1991 p++;
1992 }
1993 break;
1994 }
1995 if (LocaleCompare(stream_info->map,"RGB") == 0)
1996 {
1997 p=GetAuthenticPixelQueue(image);
1998 if (p == (const PixelPacket *) NULL)
1999 break;
cristybb503372010-05-27 20:51:26 +00002000 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002001 {
cristyce70c172010-01-07 17:15:30 +00002002 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2003 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2004 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002005 p++;
2006 }
2007 break;
2008 }
2009 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2010 {
2011 p=GetAuthenticPixelQueue(image);
2012 if (p == (const PixelPacket *) NULL)
2013 break;
cristybb503372010-05-27 20:51:26 +00002014 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002015 {
cristyce70c172010-01-07 17:15:30 +00002016 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2017 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2018 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002019 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy46f08202010-01-10 04:04:21 +00002020 (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002021 p++;
2022 }
2023 break;
2024 }
2025 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2026 {
2027 p=GetAuthenticPixelQueue(image);
2028 if (p == (const PixelPacket *) NULL)
2029 break;
cristybb503372010-05-27 20:51:26 +00002030 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002031 {
cristyce70c172010-01-07 17:15:30 +00002032 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2033 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2034 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002035 *q++=0U;
2036 p++;
2037 }
2038 break;
2039 }
2040 p=GetAuthenticPixelQueue(image);
2041 if (p == (const PixelPacket *) NULL)
2042 break;
2043 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002044 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002045 {
cristybb503372010-05-27 20:51:26 +00002046 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002047 {
2048 *q=0;
2049 switch (quantum_map[i])
2050 {
2051 case RedQuantum:
2052 case CyanQuantum:
2053 {
cristyce70c172010-01-07 17:15:30 +00002054 *q=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002055 break;
2056 }
2057 case GreenQuantum:
2058 case MagentaQuantum:
2059 {
cristyce70c172010-01-07 17:15:30 +00002060 *q=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002061 break;
2062 }
2063 case BlueQuantum:
2064 case YellowQuantum:
2065 {
cristyce70c172010-01-07 17:15:30 +00002066 *q=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002067 break;
2068 }
2069 case AlphaQuantum:
2070 {
2071 *q=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00002072 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002073 break;
2074 }
2075 case OpacityQuantum:
2076 {
cristyce70c172010-01-07 17:15:30 +00002077 *q=(unsigned int) ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002078 break;
2079 }
2080 case BlackQuantum:
2081 {
2082 if (image->colorspace == CMYKColorspace)
2083 *q=(unsigned int) ScaleQuantumToLong(indexes[x]);
2084 break;
2085 }
2086 case IndexQuantum:
2087 {
2088 *q=(unsigned int)
2089 ScaleQuantumToLong(PixelIntensityToQuantum(p));
2090 break;
2091 }
2092 default:
2093 *q=0;
2094 }
2095 q++;
2096 }
2097 p++;
2098 }
2099 break;
2100 }
2101 case LongPixel:
2102 {
cristybb503372010-05-27 20:51:26 +00002103 register size_t
cristy3ed852e2009-09-05 21:47:34 +00002104 *q;
2105
cristybb503372010-05-27 20:51:26 +00002106 q=(size_t *) stream_info->pixels;
cristy3ed852e2009-09-05 21:47:34 +00002107 if (LocaleCompare(stream_info->map,"BGR") == 0)
2108 {
2109 p=GetAuthenticPixelQueue(image);
2110 if (p == (const PixelPacket *) NULL)
2111 break;
cristybb503372010-05-27 20:51:26 +00002112 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002113 {
cristyce70c172010-01-07 17:15:30 +00002114 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2115 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2116 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002117 p++;
2118 }
2119 break;
2120 }
2121 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2122 {
2123 p=GetAuthenticPixelQueue(image);
2124 if (p == (const PixelPacket *) NULL)
2125 break;
cristybb503372010-05-27 20:51:26 +00002126 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002127 {
cristyce70c172010-01-07 17:15:30 +00002128 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2129 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2130 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002131 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002132 p++;
2133 }
2134 break;
2135 }
2136 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2137 {
2138 p=GetAuthenticPixelQueue(image);
2139 if (p == (const PixelPacket *) NULL)
2140 break;
cristybb503372010-05-27 20:51:26 +00002141 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002142 {
cristyce70c172010-01-07 17:15:30 +00002143 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2144 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2145 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002146 *q++=0;
2147 p++;
2148 }
2149 break;
2150 }
2151 if (LocaleCompare(stream_info->map,"I") == 0)
2152 {
2153 p=GetAuthenticPixelQueue(image);
2154 if (p == (const PixelPacket *) NULL)
2155 break;
cristybb503372010-05-27 20:51:26 +00002156 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002157 {
2158 *q++=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2159 p++;
2160 }
2161 break;
2162 }
2163 if (LocaleCompare(stream_info->map,"RGB") == 0)
2164 {
2165 p=GetAuthenticPixelQueue(image);
2166 if (p == (const PixelPacket *) NULL)
2167 break;
cristybb503372010-05-27 20:51:26 +00002168 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002169 {
cristyce70c172010-01-07 17:15:30 +00002170 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2171 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2172 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002173 p++;
2174 }
2175 break;
2176 }
2177 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2178 {
2179 p=GetAuthenticPixelQueue(image);
2180 if (p == (const PixelPacket *) NULL)
2181 break;
cristybb503372010-05-27 20:51:26 +00002182 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002183 {
cristyce70c172010-01-07 17:15:30 +00002184 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2185 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2186 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002187 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002188 p++;
2189 }
2190 break;
2191 }
2192 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2193 {
2194 p=GetAuthenticPixelQueue(image);
2195 if (p == (const PixelPacket *) NULL)
2196 break;
cristybb503372010-05-27 20:51:26 +00002197 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002198 {
cristyce70c172010-01-07 17:15:30 +00002199 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2200 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2201 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002202 *q++=0;
2203 p++;
2204 }
2205 break;
2206 }
2207 p=GetAuthenticPixelQueue(image);
2208 if (p == (const PixelPacket *) NULL)
2209 break;
2210 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002211 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002212 {
cristybb503372010-05-27 20:51:26 +00002213 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002214 {
2215 *q=0;
2216 switch (quantum_map[i])
2217 {
2218 case RedQuantum:
2219 case CyanQuantum:
2220 {
cristyce70c172010-01-07 17:15:30 +00002221 *q=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002222 break;
2223 }
2224 case GreenQuantum:
2225 case MagentaQuantum:
2226 {
cristyce70c172010-01-07 17:15:30 +00002227 *q=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002228 break;
2229 }
2230 case BlueQuantum:
2231 case YellowQuantum:
2232 {
cristyce70c172010-01-07 17:15:30 +00002233 *q=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002234 break;
2235 }
2236 case AlphaQuantum:
2237 {
cristy46f08202010-01-10 04:04:21 +00002238 *q=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002239 break;
2240 }
2241 case OpacityQuantum:
2242 {
cristyce70c172010-01-07 17:15:30 +00002243 *q=ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002244 break;
2245 }
2246 case BlackQuantum:
2247 {
2248 if (image->colorspace == CMYKColorspace)
2249 *q=ScaleQuantumToLong(indexes[x]);
2250 break;
2251 }
2252 case IndexQuantum:
2253 {
2254 *q=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2255 break;
2256 }
2257 default:
2258 break;
2259 }
2260 q++;
2261 }
2262 p++;
2263 }
2264 break;
2265 }
2266 case QuantumPixel:
2267 {
2268 register Quantum
2269 *q;
2270
2271 q=(Quantum *) stream_info->pixels;
2272 if (LocaleCompare(stream_info->map,"BGR") == 0)
2273 {
2274 p=GetAuthenticPixelQueue(image);
2275 if (p == (const PixelPacket *) NULL)
2276 break;
cristybb503372010-05-27 20:51:26 +00002277 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002278 {
cristyce70c172010-01-07 17:15:30 +00002279 *q++=GetBluePixelComponent(p);
2280 *q++=GetGreenPixelComponent(p);
2281 *q++=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002282 p++;
2283 }
2284 break;
2285 }
2286 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2287 {
2288 p=GetAuthenticPixelQueue(image);
2289 if (p == (const PixelPacket *) NULL)
2290 break;
cristybb503372010-05-27 20:51:26 +00002291 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002292 {
cristyce70c172010-01-07 17:15:30 +00002293 *q++=GetBluePixelComponent(p);
2294 *q++=GetGreenPixelComponent(p);
2295 *q++=GetRedPixelComponent(p);
cristy46f08202010-01-10 04:04:21 +00002296 *q++=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002297 p++;
2298 }
2299 break;
2300 }
2301 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2302 {
2303 p=GetAuthenticPixelQueue(image);
2304 if (p == (const PixelPacket *) NULL)
2305 break;
cristybb503372010-05-27 20:51:26 +00002306 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002307 {
cristyce70c172010-01-07 17:15:30 +00002308 *q++=GetBluePixelComponent(p);
2309 *q++=GetGreenPixelComponent(p);
2310 *q++=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002311 *q++=0;
2312 p++;
2313 }
2314 break;
2315 }
2316 if (LocaleCompare(stream_info->map,"I") == 0)
2317 {
2318 p=GetAuthenticPixelQueue(image);
2319 if (p == (const PixelPacket *) NULL)
2320 break;
cristybb503372010-05-27 20:51:26 +00002321 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002322 {
2323 *q++=PixelIntensityToQuantum(p);
2324 p++;
2325 }
2326 break;
2327 }
2328 if (LocaleCompare(stream_info->map,"RGB") == 0)
2329 {
2330 p=GetAuthenticPixelQueue(image);
2331 if (p == (const PixelPacket *) NULL)
2332 break;
cristybb503372010-05-27 20:51:26 +00002333 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002334 {
cristyce70c172010-01-07 17:15:30 +00002335 *q++=GetRedPixelComponent(p);
2336 *q++=GetGreenPixelComponent(p);
2337 *q++=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002338 p++;
2339 }
2340 break;
2341 }
2342 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2343 {
2344 p=GetAuthenticPixelQueue(image);
2345 if (p == (const PixelPacket *) NULL)
2346 break;
cristybb503372010-05-27 20:51:26 +00002347 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002348 {
cristyce70c172010-01-07 17:15:30 +00002349 *q++=GetRedPixelComponent(p);
2350 *q++=GetGreenPixelComponent(p);
2351 *q++=GetBluePixelComponent(p);
cristy46f08202010-01-10 04:04:21 +00002352 *q++=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002353 p++;
2354 }
2355 break;
2356 }
2357 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2358 {
2359 p=GetAuthenticPixelQueue(image);
2360 if (p == (const PixelPacket *) NULL)
2361 break;
cristybb503372010-05-27 20:51:26 +00002362 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002363 {
cristyce70c172010-01-07 17:15:30 +00002364 *q++=GetRedPixelComponent(p);
2365 *q++=GetGreenPixelComponent(p);
2366 *q++=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002367 *q++=0U;
2368 p++;
2369 }
2370 break;
2371 }
2372 p=GetAuthenticPixelQueue(image);
2373 if (p == (const PixelPacket *) NULL)
2374 break;
2375 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002376 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002377 {
cristybb503372010-05-27 20:51:26 +00002378 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002379 {
2380 *q=(Quantum) 0;
2381 switch (quantum_map[i])
2382 {
2383 case RedQuantum:
2384 case CyanQuantum:
2385 {
cristyce70c172010-01-07 17:15:30 +00002386 *q=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002387 break;
2388 }
2389 case GreenQuantum:
2390 case MagentaQuantum:
2391 {
cristyce70c172010-01-07 17:15:30 +00002392 *q=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002393 break;
2394 }
2395 case BlueQuantum:
2396 case YellowQuantum:
2397 {
cristyce70c172010-01-07 17:15:30 +00002398 *q=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002399 break;
2400 }
2401 case AlphaQuantum:
2402 {
cristy46f08202010-01-10 04:04:21 +00002403 *q=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002404 break;
2405 }
2406 case OpacityQuantum:
2407 {
cristyce70c172010-01-07 17:15:30 +00002408 *q=GetOpacityPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002409 break;
2410 }
2411 case BlackQuantum:
2412 {
2413 if (image->colorspace == CMYKColorspace)
2414 *q=indexes[x];
2415 break;
2416 }
2417 case IndexQuantum:
2418 {
2419 *q=(PixelIntensityToQuantum(p));
2420 break;
2421 }
2422 default:
2423 *q=0;
2424 }
2425 q++;
2426 }
2427 p++;
2428 }
2429 break;
2430 }
2431 case ShortPixel:
2432 {
2433 register unsigned short
2434 *q;
2435
2436 q=(unsigned short *) stream_info->pixels;
2437 if (LocaleCompare(stream_info->map,"BGR") == 0)
2438 {
2439 p=GetAuthenticPixelQueue(image);
2440 if (p == (const PixelPacket *) NULL)
2441 break;
cristybb503372010-05-27 20:51:26 +00002442 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002443 {
cristyce70c172010-01-07 17:15:30 +00002444 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2445 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2446 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002447 p++;
2448 }
2449 break;
2450 }
2451 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2452 {
2453 p=GetAuthenticPixelQueue(image);
2454 if (p == (const PixelPacket *) NULL)
2455 break;
cristybb503372010-05-27 20:51:26 +00002456 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002457 {
cristyce70c172010-01-07 17:15:30 +00002458 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2459 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2460 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002461 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002462 p++;
2463 }
2464 break;
2465 }
2466 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2467 {
2468 p=GetAuthenticPixelQueue(image);
2469 if (p == (const PixelPacket *) NULL)
2470 break;
cristybb503372010-05-27 20:51:26 +00002471 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002472 {
cristyce70c172010-01-07 17:15:30 +00002473 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2474 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2475 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002476 *q++=0;
2477 p++;
2478 }
2479 break;
2480 }
2481 if (LocaleCompare(stream_info->map,"I") == 0)
2482 {
2483 p=GetAuthenticPixelQueue(image);
2484 if (p == (const PixelPacket *) NULL)
2485 break;
cristybb503372010-05-27 20:51:26 +00002486 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002487 {
2488 *q++=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2489 p++;
2490 }
2491 break;
2492 }
2493 if (LocaleCompare(stream_info->map,"RGB") == 0)
2494 {
2495 p=GetAuthenticPixelQueue(image);
2496 if (p == (const PixelPacket *) NULL)
2497 break;
cristybb503372010-05-27 20:51:26 +00002498 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002499 {
cristyce70c172010-01-07 17:15:30 +00002500 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2501 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2502 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002503 p++;
2504 }
2505 break;
2506 }
2507 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2508 {
2509 p=GetAuthenticPixelQueue(image);
2510 if (p == (const PixelPacket *) NULL)
2511 break;
cristybb503372010-05-27 20:51:26 +00002512 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002513 {
cristyce70c172010-01-07 17:15:30 +00002514 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2515 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2516 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002517 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002518 p++;
2519 }
2520 break;
2521 }
2522 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2523 {
2524 p=GetAuthenticPixelQueue(image);
2525 if (p == (const PixelPacket *) NULL)
2526 break;
cristybb503372010-05-27 20:51:26 +00002527 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002528 {
cristyce70c172010-01-07 17:15:30 +00002529 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2530 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2531 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002532 *q++=0;
2533 p++;
2534 }
2535 break;
2536 }
2537 p=GetAuthenticPixelQueue(image);
2538 if (p == (const PixelPacket *) NULL)
2539 break;
2540 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002541 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002542 {
cristybb503372010-05-27 20:51:26 +00002543 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002544 {
2545 *q=0;
2546 switch (quantum_map[i])
2547 {
2548 case RedQuantum:
2549 case CyanQuantum:
2550 {
cristyce70c172010-01-07 17:15:30 +00002551 *q=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002552 break;
2553 }
2554 case GreenQuantum:
2555 case MagentaQuantum:
2556 {
cristyce70c172010-01-07 17:15:30 +00002557 *q=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002558 break;
2559 }
2560 case BlueQuantum:
2561 case YellowQuantum:
2562 {
cristyce70c172010-01-07 17:15:30 +00002563 *q=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002564 break;
2565 }
2566 case AlphaQuantum:
2567 {
cristy46f08202010-01-10 04:04:21 +00002568 *q=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002569 break;
2570 }
2571 case OpacityQuantum:
2572 {
cristyce70c172010-01-07 17:15:30 +00002573 *q=ScaleQuantumToShort(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002574 break;
2575 }
2576 case BlackQuantum:
2577 {
2578 if (image->colorspace == CMYKColorspace)
2579 *q=ScaleQuantumToShort(indexes[x]);
2580 break;
2581 }
2582 case IndexQuantum:
2583 {
2584 *q=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2585 break;
2586 }
2587 default:
2588 break;
2589 }
2590 q++;
2591 }
2592 p++;
2593 }
2594 break;
2595 }
2596 default:
2597 {
2598 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2600 "UnrecognizedPixelMap","`%s'",stream_info->map);
2601 break;
2602 }
2603 }
2604 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2605 return(MagickTrue);
2606}
2607
2608/*
2609%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2610% %
2611% %
2612% %
2613+ 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 %
2614% %
2615% %
2616% %
2617%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2618%
2619% SyncAuthenticPixelsStream() calls the user supplied callback method with
2620% the latest stream of pixels.
2621%
2622% The format of the SyncAuthenticPixelsStream method is:
2623%
2624% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2625% ExceptionInfo *exception)
2626%
2627% A description of each parameter follows:
2628%
2629% o image: the image.
2630%
2631% o exception: return any errors or warnings in this structure.
2632%
2633*/
2634static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2635 ExceptionInfo *exception)
2636{
2637 CacheInfo
2638 *cache_info;
2639
2640 size_t
2641 length;
2642
2643 StreamHandler
2644 stream_handler;
2645
2646 assert(image != (Image *) NULL);
2647 assert(image->signature == MagickSignature);
2648 if (image->debug != MagickFalse)
2649 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2650 cache_info=(CacheInfo *) image->cache;
2651 assert(cache_info->signature == MagickSignature);
2652 stream_handler=GetBlobStreamHandler(image);
2653 if (stream_handler == (StreamHandler) NULL)
2654 {
2655 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2656 "NoStreamHandlerIsDefined","`%s'",image->filename);
2657 return(MagickFalse);
2658 }
2659 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2660 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2661}
2662
2663/*
2664%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2665% %
2666% %
2667% %
2668% W r i t e S t r e a m %
2669% %
2670% %
2671% %
2672%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2673%
2674% WriteStream() makes the image pixels available to a user supplied callback
2675% method immediately upon writing pixel data with the WriteImage() method.
2676%
2677% The format of the WriteStream() method is:
2678%
2679% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2680% StreamHandler stream)
2681%
2682% A description of each parameter follows:
2683%
2684% o image_info: the image info.
2685%
2686% o stream: A callback method.
2687%
2688*/
2689MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2690 Image *image,StreamHandler stream)
2691{
2692 ImageInfo
2693 *write_info;
2694
2695 MagickBooleanType
2696 status;
2697
2698 assert(image_info != (ImageInfo *) NULL);
2699 assert(image_info->signature == MagickSignature);
2700 if (image_info->debug != MagickFalse)
2701 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2702 image_info->filename);
2703 assert(image != (Image *) NULL);
2704 assert(image->signature == MagickSignature);
2705 write_info=CloneImageInfo(image_info);
2706 write_info->stream=stream;
2707 status=WriteImage(write_info,image);
2708 write_info=DestroyImageInfo(write_info);
2709 return(status);
2710}