blob: 38edadb01194f256fd23106d8d16a744471d0883 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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
cristy73bd4a52010-10-05 11:24:23 +0000155 stream_info=(StreamInfo *) AcquireMagickMemory(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%
cristyd212bd02011-02-13 17:08:57 +00001076% The format of the StreamImage() method is:
cristy3ed852e2009-09-05 21:47:34 +00001077%
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;
cristyd212bd02011-02-13 17:08:57 +00001152 if ((extract_info.width == 0) || (extract_info.height == 0))
cristy3ed852e2009-09-05 21:47:34 +00001153 {
1154 /*
1155 Write all pixels to stream.
1156 */
1157 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1158 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1159 stream_info->y++;
1160 return(count == 0 ? 0 : columns);
1161 }
1162 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001163 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001164 {
1165 stream_info->y++;
1166 return(columns);
1167 }
1168 /*
1169 Write a portion of the pixel row to the stream.
1170 */
1171 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1172 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001173 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1174 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001175 stream_info->y++;
1176 return(count == 0 ? 0 : columns);
1177}
1178
1179#if defined(__cplusplus) || defined(c_plusplus)
1180}
1181#endif
1182
1183MagickExport Image *StreamImage(const ImageInfo *image_info,
1184 StreamInfo *stream_info,ExceptionInfo *exception)
1185{
1186 Image
1187 *image;
1188
1189 ImageInfo
1190 *read_info;
1191
1192 assert(image_info != (const ImageInfo *) NULL);
1193 assert(image_info->signature == MagickSignature);
1194 if (image_info->debug != MagickFalse)
1195 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1196 image_info->filename);
1197 assert(stream_info != (StreamInfo *) NULL);
1198 assert(stream_info->signature == MagickSignature);
1199 assert(exception != (ExceptionInfo *) NULL);
1200 read_info=CloneImageInfo(image_info);
1201 stream_info->image_info=image_info;
1202 stream_info->exception=exception;
1203 read_info->client_data=(void *) stream_info;
1204 image=ReadStream(read_info,&WriteStreamImage,exception);
1205 read_info=DestroyImageInfo(read_info);
1206 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1207 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1208 image=DestroyImage(image);
1209 return(image);
1210}
1211
1212/*
1213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1214% %
1215% %
1216% %
1217+ S t r e a m I m a g e P i x e l s %
1218% %
1219% %
1220% %
1221%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1222%
1223% StreamImagePixels() extracts pixel data from an image and returns it in the
1224% stream_info->pixels structure in the format as defined by
1225% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1226%
1227% The format of the StreamImagePixels method is:
1228%
1229% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1230% const Image *image,ExceptionInfo *exception)
1231%
1232% A description of each parameter follows:
1233%
1234% o stream_info: the stream info.
1235%
1236% o image: the image.
1237%
1238% o exception: return any errors or warnings in this structure.
1239%
1240*/
1241static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1242 const Image *image,ExceptionInfo *exception)
1243{
1244 QuantumInfo
1245 *quantum_info;
1246
1247 QuantumType
1248 *quantum_map;
1249
cristy3ed852e2009-09-05 21:47:34 +00001250 register const PixelPacket
1251 *p;
1252
1253 register IndexPacket
1254 *indexes;
1255
cristyd212bd02011-02-13 17:08:57 +00001256 register ssize_t
1257 i,
1258 x;
1259
cristy3ed852e2009-09-05 21:47:34 +00001260 size_t
1261 length;
1262
1263 assert(stream_info != (StreamInfo *) NULL);
1264 assert(stream_info->signature == MagickSignature);
1265 assert(image != (Image *) NULL);
1266 assert(image->signature == MagickSignature);
1267 if (image->debug != MagickFalse)
1268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1269 length=strlen(stream_info->map);
1270 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1271 if (quantum_map == (QuantumType *) NULL)
1272 {
1273 (void) ThrowMagickException(exception,GetMagickModule(),
1274 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1275 return(MagickFalse);
1276 }
cristybb503372010-05-27 20:51:26 +00001277 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001278 {
1279 switch (stream_info->map[i])
1280 {
1281 case 'A':
1282 case 'a':
1283 {
1284 quantum_map[i]=AlphaQuantum;
1285 break;
1286 }
1287 case 'B':
1288 case 'b':
1289 {
1290 quantum_map[i]=BlueQuantum;
1291 break;
1292 }
1293 case 'C':
1294 case 'c':
1295 {
1296 quantum_map[i]=CyanQuantum;
1297 if (image->colorspace == CMYKColorspace)
1298 break;
1299 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1300 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1301 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1302 return(MagickFalse);
1303 }
1304 case 'g':
1305 case 'G':
1306 {
1307 quantum_map[i]=GreenQuantum;
1308 break;
1309 }
1310 case 'I':
1311 case 'i':
1312 {
1313 quantum_map[i]=IndexQuantum;
1314 break;
1315 }
1316 case 'K':
1317 case 'k':
1318 {
1319 quantum_map[i]=BlackQuantum;
1320 if (image->colorspace == CMYKColorspace)
1321 break;
1322 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1323 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1324 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1325 return(MagickFalse);
1326 }
1327 case 'M':
1328 case 'm':
1329 {
1330 quantum_map[i]=MagentaQuantum;
1331 if (image->colorspace == CMYKColorspace)
1332 break;
1333 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1334 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1335 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1336 return(MagickFalse);
1337 }
1338 case 'o':
1339 case 'O':
1340 {
1341 quantum_map[i]=OpacityQuantum;
1342 break;
1343 }
1344 case 'P':
1345 case 'p':
1346 {
1347 quantum_map[i]=UndefinedQuantum;
1348 break;
1349 }
1350 case 'R':
1351 case 'r':
1352 {
1353 quantum_map[i]=RedQuantum;
1354 break;
1355 }
1356 case 'Y':
1357 case 'y':
1358 {
1359 quantum_map[i]=YellowQuantum;
1360 if (image->colorspace == CMYKColorspace)
1361 break;
1362 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1363 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1364 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1365 return(MagickFalse);
1366 }
1367 default:
1368 {
1369 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1370 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1371 "UnrecognizedPixelMap","`%s'",stream_info->map);
1372 return(MagickFalse);
1373 }
1374 }
1375 }
1376 quantum_info=stream_info->quantum_info;
1377 switch (stream_info->storage_type)
1378 {
1379 case CharPixel:
1380 {
1381 register unsigned char
1382 *q;
1383
1384 q=(unsigned char *) stream_info->pixels;
1385 if (LocaleCompare(stream_info->map,"BGR") == 0)
1386 {
1387 p=GetAuthenticPixelQueue(image);
1388 if (p == (const PixelPacket *) NULL)
1389 break;
cristybb503372010-05-27 20:51:26 +00001390 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001391 {
cristyce70c172010-01-07 17:15:30 +00001392 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1393 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1394 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001395 p++;
1396 }
1397 break;
1398 }
1399 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1400 {
1401 p=GetAuthenticPixelQueue(image);
1402 if (p == (const PixelPacket *) NULL)
1403 break;
cristybb503372010-05-27 20:51:26 +00001404 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001405 {
cristyce70c172010-01-07 17:15:30 +00001406 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1407 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1408 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00001409 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001410 p++;
1411 }
1412 break;
1413 }
1414 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1415 {
1416 p=GetAuthenticPixelQueue(image);
1417 if (p == (const PixelPacket *) NULL)
1418 break;
cristybb503372010-05-27 20:51:26 +00001419 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001420 {
cristyce70c172010-01-07 17:15:30 +00001421 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1422 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1423 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001424 *q++=ScaleQuantumToChar((Quantum) 0);
1425 p++;
1426 }
1427 break;
1428 }
1429 if (LocaleCompare(stream_info->map,"I") == 0)
1430 {
1431 p=GetAuthenticPixelQueue(image);
1432 if (p == (const PixelPacket *) NULL)
1433 break;
cristybb503372010-05-27 20:51:26 +00001434 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001435 {
1436 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1437 p++;
1438 }
1439 break;
1440 }
1441 if (LocaleCompare(stream_info->map,"RGB") == 0)
1442 {
1443 p=GetAuthenticPixelQueue(image);
1444 if (p == (const PixelPacket *) NULL)
1445 break;
cristybb503372010-05-27 20:51:26 +00001446 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001447 {
cristyce70c172010-01-07 17:15:30 +00001448 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1449 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1450 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001451 p++;
1452 }
1453 break;
1454 }
1455 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1456 {
1457 p=GetAuthenticPixelQueue(image);
1458 if (p == (const PixelPacket *) NULL)
1459 break;
cristybb503372010-05-27 20:51:26 +00001460 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001461 {
cristyce70c172010-01-07 17:15:30 +00001462 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1463 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1464 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00001465 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001466 p++;
1467 }
1468 break;
1469 }
1470 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1471 {
1472 p=GetAuthenticPixelQueue(image);
1473 if (p == (const PixelPacket *) NULL)
1474 break;
cristybb503372010-05-27 20:51:26 +00001475 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001476 {
cristyce70c172010-01-07 17:15:30 +00001477 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1478 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1479 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001480 *q++=ScaleQuantumToChar((Quantum) 0);
1481 p++;
1482 }
1483 break;
1484 }
1485 p=GetAuthenticPixelQueue(image);
1486 if (p == (const PixelPacket *) NULL)
1487 break;
1488 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001489 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001490 {
cristybb503372010-05-27 20:51:26 +00001491 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001492 {
1493 *q=0;
1494 switch (quantum_map[i])
1495 {
1496 case RedQuantum:
1497 case CyanQuantum:
1498 {
cristyce70c172010-01-07 17:15:30 +00001499 *q=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001500 break;
1501 }
1502 case GreenQuantum:
1503 case MagentaQuantum:
1504 {
cristyce70c172010-01-07 17:15:30 +00001505 *q=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001506 break;
1507 }
1508 case BlueQuantum:
1509 case YellowQuantum:
1510 {
cristyce70c172010-01-07 17:15:30 +00001511 *q=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001512 break;
1513 }
1514 case AlphaQuantum:
1515 {
cristy46f08202010-01-10 04:04:21 +00001516 *q=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001517 break;
1518 }
1519 case OpacityQuantum:
1520 {
cristyce70c172010-01-07 17:15:30 +00001521 *q=ScaleQuantumToChar(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001522 break;
1523 }
1524 case BlackQuantum:
1525 {
1526 if (image->colorspace == CMYKColorspace)
1527 *q=ScaleQuantumToChar(indexes[x]);
1528 break;
1529 }
1530 case IndexQuantum:
1531 {
1532 *q=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1533 break;
1534 }
1535 default:
1536 break;
1537 }
1538 q++;
1539 }
1540 p++;
1541 }
1542 break;
1543 }
1544 case DoublePixel:
1545 {
1546 register double
1547 *q;
1548
1549 q=(double *) stream_info->pixels;
1550 if (LocaleCompare(stream_info->map,"BGR") == 0)
1551 {
1552 p=GetAuthenticPixelQueue(image);
1553 if (p == (const PixelPacket *) NULL)
1554 break;
cristybb503372010-05-27 20:51:26 +00001555 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001556 {
cristy46f08202010-01-10 04:04:21 +00001557 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1558 quantum_info->scale+quantum_info->minimum);
1559 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1560 quantum_info->scale+quantum_info->minimum);
1561 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1562 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001563 p++;
1564 }
1565 break;
1566 }
1567 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1568 {
1569 p=GetAuthenticPixelQueue(image);
1570 if (p == (const PixelPacket *) NULL)
1571 break;
cristybb503372010-05-27 20:51:26 +00001572 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001573 {
cristy46f08202010-01-10 04:04:21 +00001574 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1575 quantum_info->scale+quantum_info->minimum);
1576 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1577 quantum_info->scale+quantum_info->minimum);
1578 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1579 quantum_info->scale+quantum_info->minimum);
1580 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001581 quantum_info->scale+quantum_info->minimum);
1582 p++;
1583 }
1584 break;
1585 }
1586 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1587 {
1588 p=GetAuthenticPixelQueue(image);
1589 if (p == (const PixelPacket *) NULL)
1590 break;
cristybb503372010-05-27 20:51:26 +00001591 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001592 {
cristy46f08202010-01-10 04:04:21 +00001593 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1594 quantum_info->scale+quantum_info->minimum);
1595 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1596 quantum_info->scale+quantum_info->minimum);
1597 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1598 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001599 *q++=0.0;
1600 p++;
1601 }
1602 break;
1603 }
1604 if (LocaleCompare(stream_info->map,"I") == 0)
1605 {
1606 p=GetAuthenticPixelQueue(image);
1607 if (p == (const PixelPacket *) NULL)
1608 break;
cristybb503372010-05-27 20:51:26 +00001609 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001610 {
1611 *q++=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1612 quantum_info->scale+quantum_info->minimum);
1613 p++;
1614 }
1615 break;
1616 }
1617 if (LocaleCompare(stream_info->map,"RGB") == 0)
1618 {
1619 p=GetAuthenticPixelQueue(image);
1620 if (p == (const PixelPacket *) NULL)
1621 break;
cristybb503372010-05-27 20:51:26 +00001622 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001623 {
cristy46f08202010-01-10 04:04:21 +00001624 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1625 quantum_info->scale+quantum_info->minimum);
1626 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1627 quantum_info->scale+quantum_info->minimum);
1628 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1629 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001630 p++;
1631 }
1632 break;
1633 }
1634 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1635 {
1636 p=GetAuthenticPixelQueue(image);
1637 if (p == (const PixelPacket *) NULL)
1638 break;
cristybb503372010-05-27 20:51:26 +00001639 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001640 {
cristy46f08202010-01-10 04:04:21 +00001641 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1642 quantum_info->scale+quantum_info->minimum);
1643 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1644 quantum_info->scale+quantum_info->minimum);
1645 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1646 quantum_info->scale+quantum_info->minimum);
1647 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001648 quantum_info->scale+quantum_info->minimum);
1649 p++;
1650 }
1651 break;
1652 }
1653 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1654 {
1655 p=GetAuthenticPixelQueue(image);
1656 if (p == (const PixelPacket *) NULL)
1657 break;
cristybb503372010-05-27 20:51:26 +00001658 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001659 {
cristy46f08202010-01-10 04:04:21 +00001660 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1661 quantum_info->scale+quantum_info->minimum);
1662 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1663 quantum_info->scale+quantum_info->minimum);
1664 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1665 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001666 *q++=0.0;
1667 p++;
1668 }
1669 break;
1670 }
1671 p=GetAuthenticPixelQueue(image);
1672 if (p == (const PixelPacket *) NULL)
1673 break;
1674 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001675 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001676 {
cristybb503372010-05-27 20:51:26 +00001677 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001678 {
1679 *q=0;
1680 switch (quantum_map[i])
1681 {
1682 case RedQuantum:
1683 case CyanQuantum:
1684 {
cristy46f08202010-01-10 04:04:21 +00001685 *q=(double) ((QuantumScale*GetRedPixelComponent(p))*
1686 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001687 break;
1688 }
1689 case GreenQuantum:
1690 case MagentaQuantum:
1691 {
cristy46f08202010-01-10 04:04:21 +00001692 *q=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1693 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001694 break;
1695 }
1696 case BlueQuantum:
1697 case YellowQuantum:
1698 {
cristy46f08202010-01-10 04:04:21 +00001699 *q=(double) ((QuantumScale*GetBluePixelComponent(p))*
1700 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001701 break;
1702 }
1703 case AlphaQuantum:
1704 {
cristy46f08202010-01-10 04:04:21 +00001705 *q=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1706 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001707 break;
1708 }
1709 case OpacityQuantum:
1710 {
cristy46f08202010-01-10 04:04:21 +00001711 *q=(double) ((QuantumScale*GetOpacityPixelComponent(p))*
1712 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001713 break;
1714 }
1715 case BlackQuantum:
1716 {
1717 if (image->colorspace == CMYKColorspace)
1718 *q=(double) ((QuantumScale*indexes[x])*quantum_info->scale+
1719 quantum_info->minimum);
1720 break;
1721 }
1722 case IndexQuantum:
1723 {
1724 *q=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1725 quantum_info->scale+quantum_info->minimum);
1726 break;
1727 }
1728 default:
1729 *q=0;
1730 }
1731 q++;
1732 }
1733 p++;
1734 }
1735 break;
1736 }
1737 case FloatPixel:
1738 {
1739 register float
1740 *q;
1741
1742 q=(float *) stream_info->pixels;
1743 if (LocaleCompare(stream_info->map,"BGR") == 0)
1744 {
1745 p=GetAuthenticPixelQueue(image);
1746 if (p == (const PixelPacket *) NULL)
1747 break;
cristybb503372010-05-27 20:51:26 +00001748 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001749 {
cristy46f08202010-01-10 04:04:21 +00001750 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1751 quantum_info->scale+quantum_info->minimum);
1752 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1753 quantum_info->scale+quantum_info->minimum);
1754 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1755 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001756 p++;
1757 }
1758 break;
1759 }
1760 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1761 {
1762 p=GetAuthenticPixelQueue(image);
1763 if (p == (const PixelPacket *) NULL)
1764 break;
cristybb503372010-05-27 20:51:26 +00001765 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001766 {
cristy46f08202010-01-10 04:04:21 +00001767 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1768 quantum_info->scale+quantum_info->minimum);
1769 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1770 quantum_info->scale+quantum_info->minimum);
1771 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1772 quantum_info->scale+quantum_info->minimum);
1773 *q++=(float) ((QuantumScale*(Quantum) (GetAlphaPixelComponent(p)))*
cristy3ed852e2009-09-05 21:47:34 +00001774 quantum_info->scale+quantum_info->minimum);
1775 p++;
1776 }
1777 break;
1778 }
1779 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1780 {
1781 p=GetAuthenticPixelQueue(image);
1782 if (p == (const PixelPacket *) NULL)
1783 break;
cristybb503372010-05-27 20:51:26 +00001784 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001785 {
cristy46f08202010-01-10 04:04:21 +00001786 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1787 quantum_info->scale+quantum_info->minimum);
1788 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1789 quantum_info->scale+quantum_info->minimum);
1790 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1791 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001792 *q++=0.0;
1793 p++;
1794 }
1795 break;
1796 }
1797 if (LocaleCompare(stream_info->map,"I") == 0)
1798 {
1799 p=GetAuthenticPixelQueue(image);
1800 if (p == (const PixelPacket *) NULL)
1801 break;
cristybb503372010-05-27 20:51:26 +00001802 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001803 {
1804 *q++=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1805 quantum_info->scale+quantum_info->minimum);
1806 p++;
1807 }
1808 break;
1809 }
1810 if (LocaleCompare(stream_info->map,"RGB") == 0)
1811 {
1812 p=GetAuthenticPixelQueue(image);
1813 if (p == (const PixelPacket *) NULL)
1814 break;
cristybb503372010-05-27 20:51:26 +00001815 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001816 {
cristy46f08202010-01-10 04:04:21 +00001817 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1818 quantum_info->scale+quantum_info->minimum);
1819 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1820 quantum_info->scale+quantum_info->minimum);
1821 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1822 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001823 p++;
1824 }
1825 break;
1826 }
1827 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1828 {
1829 p=GetAuthenticPixelQueue(image);
1830 if (p == (const PixelPacket *) NULL)
1831 break;
cristybb503372010-05-27 20:51:26 +00001832 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001833 {
cristy46f08202010-01-10 04:04:21 +00001834 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1835 quantum_info->scale+quantum_info->minimum);
1836 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1837 quantum_info->scale+quantum_info->minimum);
1838 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1839 quantum_info->scale+quantum_info->minimum);
1840 *q++=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001841 quantum_info->scale+quantum_info->minimum);
1842 p++;
1843 }
1844 break;
1845 }
1846 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1847 {
1848 p=GetAuthenticPixelQueue(image);
1849 if (p == (const PixelPacket *) NULL)
1850 break;
cristybb503372010-05-27 20:51:26 +00001851 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001852 {
cristy46f08202010-01-10 04:04:21 +00001853 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1854 quantum_info->scale+quantum_info->minimum);
1855 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1856 quantum_info->scale+quantum_info->minimum);
1857 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1858 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001859 *q++=0.0;
1860 p++;
1861 }
1862 break;
1863 }
1864 p=GetAuthenticPixelQueue(image);
1865 if (p == (const PixelPacket *) NULL)
1866 break;
1867 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001868 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001869 {
cristybb503372010-05-27 20:51:26 +00001870 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001871 {
1872 *q=0;
1873 switch (quantum_map[i])
1874 {
1875 case RedQuantum:
1876 case CyanQuantum:
1877 {
cristy46f08202010-01-10 04:04:21 +00001878 *q=(float) ((QuantumScale*GetRedPixelComponent(p))*
1879 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001880 break;
1881 }
1882 case GreenQuantum:
1883 case MagentaQuantum:
1884 {
cristy46f08202010-01-10 04:04:21 +00001885 *q=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1886 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001887 break;
1888 }
1889 case BlueQuantum:
1890 case YellowQuantum:
1891 {
cristy46f08202010-01-10 04:04:21 +00001892 *q=(float) ((QuantumScale*GetBluePixelComponent(p))*
1893 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001894 break;
1895 }
1896 case AlphaQuantum:
1897 {
cristy46f08202010-01-10 04:04:21 +00001898 *q=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1899 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001900 break;
1901 }
1902 case OpacityQuantum:
1903 {
cristy46f08202010-01-10 04:04:21 +00001904 *q=(float) ((QuantumScale*GetOpacityPixelComponent(p))*
1905 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001906 break;
1907 }
1908 case BlackQuantum:
1909 {
1910 if (image->colorspace == CMYKColorspace)
1911 *q=(float) ((QuantumScale*indexes[x])*quantum_info->scale+
1912 quantum_info->minimum);
1913 break;
1914 }
1915 case IndexQuantum:
1916 {
1917 *q=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1918 quantum_info->scale+quantum_info->minimum);
1919 break;
1920 }
1921 default:
1922 *q=0;
1923 }
1924 q++;
1925 }
1926 p++;
1927 }
1928 break;
1929 }
1930 case IntegerPixel:
1931 {
1932 register unsigned int
1933 *q;
1934
1935 q=(unsigned int *) stream_info->pixels;
1936 if (LocaleCompare(stream_info->map,"BGR") == 0)
1937 {
1938 p=GetAuthenticPixelQueue(image);
1939 if (p == (const PixelPacket *) NULL)
1940 break;
cristybb503372010-05-27 20:51:26 +00001941 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001942 {
cristyce70c172010-01-07 17:15:30 +00001943 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1944 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1945 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001946 p++;
1947 }
1948 break;
1949 }
1950 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1951 {
1952 p=GetAuthenticPixelQueue(image);
1953 if (p == (const PixelPacket *) NULL)
1954 break;
cristybb503372010-05-27 20:51:26 +00001955 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001956 {
cristyce70c172010-01-07 17:15:30 +00001957 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1958 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1959 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001960 *q++=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00001961 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001962 p++;
1963 }
1964 break;
1965 }
1966 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1967 {
1968 p=GetAuthenticPixelQueue(image);
1969 if (p == (const PixelPacket *) NULL)
1970 break;
cristybb503372010-05-27 20:51:26 +00001971 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001972 {
cristyce70c172010-01-07 17:15:30 +00001973 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1974 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1975 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001976 *q++=0U;
1977 p++;
1978 }
1979 break;
1980 }
1981 if (LocaleCompare(stream_info->map,"I") == 0)
1982 {
1983 p=GetAuthenticPixelQueue(image);
1984 if (p == (const PixelPacket *) NULL)
1985 break;
cristybb503372010-05-27 20:51:26 +00001986 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001987 {
1988 *q++=(unsigned int) ScaleQuantumToLong(
1989 PixelIntensityToQuantum(p));
1990 p++;
1991 }
1992 break;
1993 }
1994 if (LocaleCompare(stream_info->map,"RGB") == 0)
1995 {
1996 p=GetAuthenticPixelQueue(image);
1997 if (p == (const PixelPacket *) NULL)
1998 break;
cristybb503372010-05-27 20:51:26 +00001999 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002000 {
cristyce70c172010-01-07 17:15:30 +00002001 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2002 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2003 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002004 p++;
2005 }
2006 break;
2007 }
2008 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2009 {
2010 p=GetAuthenticPixelQueue(image);
2011 if (p == (const PixelPacket *) NULL)
2012 break;
cristybb503372010-05-27 20:51:26 +00002013 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002014 {
cristyce70c172010-01-07 17:15:30 +00002015 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2016 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2017 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002018 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy46f08202010-01-10 04:04:21 +00002019 (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002020 p++;
2021 }
2022 break;
2023 }
2024 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2025 {
2026 p=GetAuthenticPixelQueue(image);
2027 if (p == (const PixelPacket *) NULL)
2028 break;
cristybb503372010-05-27 20:51:26 +00002029 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002030 {
cristyce70c172010-01-07 17:15:30 +00002031 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2032 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2033 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002034 *q++=0U;
2035 p++;
2036 }
2037 break;
2038 }
2039 p=GetAuthenticPixelQueue(image);
2040 if (p == (const PixelPacket *) NULL)
2041 break;
2042 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002043 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002044 {
cristybb503372010-05-27 20:51:26 +00002045 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002046 {
2047 *q=0;
2048 switch (quantum_map[i])
2049 {
2050 case RedQuantum:
2051 case CyanQuantum:
2052 {
cristyce70c172010-01-07 17:15:30 +00002053 *q=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002054 break;
2055 }
2056 case GreenQuantum:
2057 case MagentaQuantum:
2058 {
cristyce70c172010-01-07 17:15:30 +00002059 *q=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002060 break;
2061 }
2062 case BlueQuantum:
2063 case YellowQuantum:
2064 {
cristyce70c172010-01-07 17:15:30 +00002065 *q=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002066 break;
2067 }
2068 case AlphaQuantum:
2069 {
2070 *q=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00002071 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002072 break;
2073 }
2074 case OpacityQuantum:
2075 {
cristyce70c172010-01-07 17:15:30 +00002076 *q=(unsigned int) ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002077 break;
2078 }
2079 case BlackQuantum:
2080 {
2081 if (image->colorspace == CMYKColorspace)
2082 *q=(unsigned int) ScaleQuantumToLong(indexes[x]);
2083 break;
2084 }
2085 case IndexQuantum:
2086 {
2087 *q=(unsigned int)
2088 ScaleQuantumToLong(PixelIntensityToQuantum(p));
2089 break;
2090 }
2091 default:
2092 *q=0;
2093 }
2094 q++;
2095 }
2096 p++;
2097 }
2098 break;
2099 }
2100 case LongPixel:
2101 {
cristybb503372010-05-27 20:51:26 +00002102 register size_t
cristy3ed852e2009-09-05 21:47:34 +00002103 *q;
2104
cristybb503372010-05-27 20:51:26 +00002105 q=(size_t *) stream_info->pixels;
cristy3ed852e2009-09-05 21:47:34 +00002106 if (LocaleCompare(stream_info->map,"BGR") == 0)
2107 {
2108 p=GetAuthenticPixelQueue(image);
2109 if (p == (const PixelPacket *) NULL)
2110 break;
cristybb503372010-05-27 20:51:26 +00002111 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002112 {
cristyce70c172010-01-07 17:15:30 +00002113 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2114 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2115 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002116 p++;
2117 }
2118 break;
2119 }
2120 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2121 {
2122 p=GetAuthenticPixelQueue(image);
2123 if (p == (const PixelPacket *) NULL)
2124 break;
cristybb503372010-05-27 20:51:26 +00002125 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002126 {
cristyce70c172010-01-07 17:15:30 +00002127 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2128 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2129 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002130 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002131 p++;
2132 }
2133 break;
2134 }
2135 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2136 {
2137 p=GetAuthenticPixelQueue(image);
2138 if (p == (const PixelPacket *) NULL)
2139 break;
cristybb503372010-05-27 20:51:26 +00002140 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002141 {
cristyce70c172010-01-07 17:15:30 +00002142 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2143 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2144 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002145 *q++=0;
2146 p++;
2147 }
2148 break;
2149 }
2150 if (LocaleCompare(stream_info->map,"I") == 0)
2151 {
2152 p=GetAuthenticPixelQueue(image);
2153 if (p == (const PixelPacket *) NULL)
2154 break;
cristybb503372010-05-27 20:51:26 +00002155 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002156 {
2157 *q++=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2158 p++;
2159 }
2160 break;
2161 }
2162 if (LocaleCompare(stream_info->map,"RGB") == 0)
2163 {
2164 p=GetAuthenticPixelQueue(image);
2165 if (p == (const PixelPacket *) NULL)
2166 break;
cristybb503372010-05-27 20:51:26 +00002167 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002168 {
cristyce70c172010-01-07 17:15:30 +00002169 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2170 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2171 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002172 p++;
2173 }
2174 break;
2175 }
2176 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2177 {
2178 p=GetAuthenticPixelQueue(image);
2179 if (p == (const PixelPacket *) NULL)
2180 break;
cristybb503372010-05-27 20:51:26 +00002181 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002182 {
cristyce70c172010-01-07 17:15:30 +00002183 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2184 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2185 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002186 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002187 p++;
2188 }
2189 break;
2190 }
2191 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2192 {
2193 p=GetAuthenticPixelQueue(image);
2194 if (p == (const PixelPacket *) NULL)
2195 break;
cristybb503372010-05-27 20:51:26 +00002196 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002197 {
cristyce70c172010-01-07 17:15:30 +00002198 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2199 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2200 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002201 *q++=0;
2202 p++;
2203 }
2204 break;
2205 }
2206 p=GetAuthenticPixelQueue(image);
2207 if (p == (const PixelPacket *) NULL)
2208 break;
2209 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002210 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002211 {
cristybb503372010-05-27 20:51:26 +00002212 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002213 {
2214 *q=0;
2215 switch (quantum_map[i])
2216 {
2217 case RedQuantum:
2218 case CyanQuantum:
2219 {
cristyce70c172010-01-07 17:15:30 +00002220 *q=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002221 break;
2222 }
2223 case GreenQuantum:
2224 case MagentaQuantum:
2225 {
cristyce70c172010-01-07 17:15:30 +00002226 *q=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002227 break;
2228 }
2229 case BlueQuantum:
2230 case YellowQuantum:
2231 {
cristyce70c172010-01-07 17:15:30 +00002232 *q=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002233 break;
2234 }
2235 case AlphaQuantum:
2236 {
cristy46f08202010-01-10 04:04:21 +00002237 *q=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002238 break;
2239 }
2240 case OpacityQuantum:
2241 {
cristyce70c172010-01-07 17:15:30 +00002242 *q=ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002243 break;
2244 }
2245 case BlackQuantum:
2246 {
2247 if (image->colorspace == CMYKColorspace)
2248 *q=ScaleQuantumToLong(indexes[x]);
2249 break;
2250 }
2251 case IndexQuantum:
2252 {
2253 *q=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2254 break;
2255 }
2256 default:
2257 break;
2258 }
2259 q++;
2260 }
2261 p++;
2262 }
2263 break;
2264 }
2265 case QuantumPixel:
2266 {
2267 register Quantum
2268 *q;
2269
2270 q=(Quantum *) stream_info->pixels;
2271 if (LocaleCompare(stream_info->map,"BGR") == 0)
2272 {
2273 p=GetAuthenticPixelQueue(image);
2274 if (p == (const PixelPacket *) NULL)
2275 break;
cristybb503372010-05-27 20:51:26 +00002276 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002277 {
cristyce70c172010-01-07 17:15:30 +00002278 *q++=GetBluePixelComponent(p);
2279 *q++=GetGreenPixelComponent(p);
2280 *q++=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002281 p++;
2282 }
2283 break;
2284 }
2285 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2286 {
2287 p=GetAuthenticPixelQueue(image);
2288 if (p == (const PixelPacket *) NULL)
2289 break;
cristybb503372010-05-27 20:51:26 +00002290 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002291 {
cristyce70c172010-01-07 17:15:30 +00002292 *q++=GetBluePixelComponent(p);
2293 *q++=GetGreenPixelComponent(p);
2294 *q++=GetRedPixelComponent(p);
cristy46f08202010-01-10 04:04:21 +00002295 *q++=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002296 p++;
2297 }
2298 break;
2299 }
2300 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2301 {
2302 p=GetAuthenticPixelQueue(image);
2303 if (p == (const PixelPacket *) NULL)
2304 break;
cristybb503372010-05-27 20:51:26 +00002305 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002306 {
cristyce70c172010-01-07 17:15:30 +00002307 *q++=GetBluePixelComponent(p);
2308 *q++=GetGreenPixelComponent(p);
2309 *q++=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002310 *q++=0;
2311 p++;
2312 }
2313 break;
2314 }
2315 if (LocaleCompare(stream_info->map,"I") == 0)
2316 {
2317 p=GetAuthenticPixelQueue(image);
2318 if (p == (const PixelPacket *) NULL)
2319 break;
cristybb503372010-05-27 20:51:26 +00002320 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002321 {
2322 *q++=PixelIntensityToQuantum(p);
2323 p++;
2324 }
2325 break;
2326 }
2327 if (LocaleCompare(stream_info->map,"RGB") == 0)
2328 {
2329 p=GetAuthenticPixelQueue(image);
2330 if (p == (const PixelPacket *) NULL)
2331 break;
cristybb503372010-05-27 20:51:26 +00002332 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002333 {
cristyce70c172010-01-07 17:15:30 +00002334 *q++=GetRedPixelComponent(p);
2335 *q++=GetGreenPixelComponent(p);
2336 *q++=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002337 p++;
2338 }
2339 break;
2340 }
2341 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2342 {
2343 p=GetAuthenticPixelQueue(image);
2344 if (p == (const PixelPacket *) NULL)
2345 break;
cristybb503372010-05-27 20:51:26 +00002346 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002347 {
cristyce70c172010-01-07 17:15:30 +00002348 *q++=GetRedPixelComponent(p);
2349 *q++=GetGreenPixelComponent(p);
2350 *q++=GetBluePixelComponent(p);
cristy46f08202010-01-10 04:04:21 +00002351 *q++=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002352 p++;
2353 }
2354 break;
2355 }
2356 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2357 {
2358 p=GetAuthenticPixelQueue(image);
2359 if (p == (const PixelPacket *) NULL)
2360 break;
cristybb503372010-05-27 20:51:26 +00002361 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002362 {
cristyce70c172010-01-07 17:15:30 +00002363 *q++=GetRedPixelComponent(p);
2364 *q++=GetGreenPixelComponent(p);
2365 *q++=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002366 *q++=0U;
2367 p++;
2368 }
2369 break;
2370 }
2371 p=GetAuthenticPixelQueue(image);
2372 if (p == (const PixelPacket *) NULL)
2373 break;
2374 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002375 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002376 {
cristybb503372010-05-27 20:51:26 +00002377 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002378 {
2379 *q=(Quantum) 0;
2380 switch (quantum_map[i])
2381 {
2382 case RedQuantum:
2383 case CyanQuantum:
2384 {
cristyce70c172010-01-07 17:15:30 +00002385 *q=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002386 break;
2387 }
2388 case GreenQuantum:
2389 case MagentaQuantum:
2390 {
cristyce70c172010-01-07 17:15:30 +00002391 *q=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002392 break;
2393 }
2394 case BlueQuantum:
2395 case YellowQuantum:
2396 {
cristyce70c172010-01-07 17:15:30 +00002397 *q=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002398 break;
2399 }
2400 case AlphaQuantum:
2401 {
cristy46f08202010-01-10 04:04:21 +00002402 *q=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002403 break;
2404 }
2405 case OpacityQuantum:
2406 {
cristyce70c172010-01-07 17:15:30 +00002407 *q=GetOpacityPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002408 break;
2409 }
2410 case BlackQuantum:
2411 {
2412 if (image->colorspace == CMYKColorspace)
2413 *q=indexes[x];
2414 break;
2415 }
2416 case IndexQuantum:
2417 {
2418 *q=(PixelIntensityToQuantum(p));
2419 break;
2420 }
2421 default:
2422 *q=0;
2423 }
2424 q++;
2425 }
2426 p++;
2427 }
2428 break;
2429 }
2430 case ShortPixel:
2431 {
2432 register unsigned short
2433 *q;
2434
2435 q=(unsigned short *) stream_info->pixels;
2436 if (LocaleCompare(stream_info->map,"BGR") == 0)
2437 {
2438 p=GetAuthenticPixelQueue(image);
2439 if (p == (const PixelPacket *) NULL)
2440 break;
cristybb503372010-05-27 20:51:26 +00002441 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002442 {
cristyce70c172010-01-07 17:15:30 +00002443 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2444 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2445 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002446 p++;
2447 }
2448 break;
2449 }
2450 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2451 {
2452 p=GetAuthenticPixelQueue(image);
2453 if (p == (const PixelPacket *) NULL)
2454 break;
cristybb503372010-05-27 20:51:26 +00002455 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002456 {
cristyce70c172010-01-07 17:15:30 +00002457 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2458 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2459 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002460 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002461 p++;
2462 }
2463 break;
2464 }
2465 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2466 {
2467 p=GetAuthenticPixelQueue(image);
2468 if (p == (const PixelPacket *) NULL)
2469 break;
cristybb503372010-05-27 20:51:26 +00002470 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002471 {
cristyce70c172010-01-07 17:15:30 +00002472 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2473 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2474 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002475 *q++=0;
2476 p++;
2477 }
2478 break;
2479 }
2480 if (LocaleCompare(stream_info->map,"I") == 0)
2481 {
2482 p=GetAuthenticPixelQueue(image);
2483 if (p == (const PixelPacket *) NULL)
2484 break;
cristybb503372010-05-27 20:51:26 +00002485 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002486 {
2487 *q++=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2488 p++;
2489 }
2490 break;
2491 }
2492 if (LocaleCompare(stream_info->map,"RGB") == 0)
2493 {
2494 p=GetAuthenticPixelQueue(image);
2495 if (p == (const PixelPacket *) NULL)
2496 break;
cristybb503372010-05-27 20:51:26 +00002497 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002498 {
cristyce70c172010-01-07 17:15:30 +00002499 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2500 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2501 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002502 p++;
2503 }
2504 break;
2505 }
2506 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2507 {
2508 p=GetAuthenticPixelQueue(image);
2509 if (p == (const PixelPacket *) NULL)
2510 break;
cristybb503372010-05-27 20:51:26 +00002511 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002512 {
cristyce70c172010-01-07 17:15:30 +00002513 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2514 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2515 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002516 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002517 p++;
2518 }
2519 break;
2520 }
2521 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2522 {
2523 p=GetAuthenticPixelQueue(image);
2524 if (p == (const PixelPacket *) NULL)
2525 break;
cristybb503372010-05-27 20:51:26 +00002526 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002527 {
cristyce70c172010-01-07 17:15:30 +00002528 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2529 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2530 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002531 *q++=0;
2532 p++;
2533 }
2534 break;
2535 }
2536 p=GetAuthenticPixelQueue(image);
2537 if (p == (const PixelPacket *) NULL)
2538 break;
2539 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002540 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002541 {
cristybb503372010-05-27 20:51:26 +00002542 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002543 {
2544 *q=0;
2545 switch (quantum_map[i])
2546 {
2547 case RedQuantum:
2548 case CyanQuantum:
2549 {
cristyce70c172010-01-07 17:15:30 +00002550 *q=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002551 break;
2552 }
2553 case GreenQuantum:
2554 case MagentaQuantum:
2555 {
cristyce70c172010-01-07 17:15:30 +00002556 *q=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002557 break;
2558 }
2559 case BlueQuantum:
2560 case YellowQuantum:
2561 {
cristyce70c172010-01-07 17:15:30 +00002562 *q=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002563 break;
2564 }
2565 case AlphaQuantum:
2566 {
cristy46f08202010-01-10 04:04:21 +00002567 *q=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002568 break;
2569 }
2570 case OpacityQuantum:
2571 {
cristyce70c172010-01-07 17:15:30 +00002572 *q=ScaleQuantumToShort(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002573 break;
2574 }
2575 case BlackQuantum:
2576 {
2577 if (image->colorspace == CMYKColorspace)
2578 *q=ScaleQuantumToShort(indexes[x]);
2579 break;
2580 }
2581 case IndexQuantum:
2582 {
2583 *q=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2584 break;
2585 }
2586 default:
2587 break;
2588 }
2589 q++;
2590 }
2591 p++;
2592 }
2593 break;
2594 }
2595 default:
2596 {
2597 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2598 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2599 "UnrecognizedPixelMap","`%s'",stream_info->map);
2600 break;
2601 }
2602 }
2603 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2604 return(MagickTrue);
2605}
2606
2607/*
2608%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2609% %
2610% %
2611% %
2612+ 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 %
2613% %
2614% %
2615% %
2616%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2617%
2618% SyncAuthenticPixelsStream() calls the user supplied callback method with
2619% the latest stream of pixels.
2620%
2621% The format of the SyncAuthenticPixelsStream method is:
2622%
2623% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2624% ExceptionInfo *exception)
2625%
2626% A description of each parameter follows:
2627%
2628% o image: the image.
2629%
2630% o exception: return any errors or warnings in this structure.
2631%
2632*/
2633static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2634 ExceptionInfo *exception)
2635{
2636 CacheInfo
2637 *cache_info;
2638
2639 size_t
2640 length;
2641
2642 StreamHandler
2643 stream_handler;
2644
2645 assert(image != (Image *) NULL);
2646 assert(image->signature == MagickSignature);
2647 if (image->debug != MagickFalse)
2648 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2649 cache_info=(CacheInfo *) image->cache;
2650 assert(cache_info->signature == MagickSignature);
2651 stream_handler=GetBlobStreamHandler(image);
2652 if (stream_handler == (StreamHandler) NULL)
2653 {
2654 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2655 "NoStreamHandlerIsDefined","`%s'",image->filename);
2656 return(MagickFalse);
2657 }
2658 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2659 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2660}
2661
2662/*
2663%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2664% %
2665% %
2666% %
2667% W r i t e S t r e a m %
2668% %
2669% %
2670% %
2671%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2672%
2673% WriteStream() makes the image pixels available to a user supplied callback
2674% method immediately upon writing pixel data with the WriteImage() method.
2675%
2676% The format of the WriteStream() method is:
2677%
2678% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2679% StreamHandler stream)
2680%
2681% A description of each parameter follows:
2682%
2683% o image_info: the image info.
2684%
2685% o stream: A callback method.
2686%
2687*/
2688MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2689 Image *image,StreamHandler stream)
2690{
2691 ImageInfo
2692 *write_info;
2693
2694 MagickBooleanType
2695 status;
2696
2697 assert(image_info != (ImageInfo *) NULL);
2698 assert(image_info->signature == MagickSignature);
2699 if (image_info->debug != MagickFalse)
2700 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2701 image_info->filename);
2702 assert(image != (Image *) NULL);
2703 assert(image->signature == MagickSignature);
2704 write_info=CloneImageInfo(image_info);
2705 write_info->stream=stream;
2706 status=WriteImage(write_info,image);
2707 write_info=DestroyImageInfo(write_info);
2708 return(status);
2709}