blob: 6b5da155c0497cddc5f0c25347fc0802e80a2892 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% SSSSS TTTTT RRRR EEEEE AAA M M %
7% SS T R R E A A MM MM %
8% SSS T RRRR EEE AAAAA M M M %
9% SS T R R E A A M M %
10% SSSSS T R R EEEEE A A M M %
11% %
12% %
13% MagickCore Pixel Stream Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
43#include "magick/studio.h"
44#include "magick/blob.h"
45#include "magick/blob-private.h"
46#include "magick/cache.h"
47#include "magick/cache-private.h"
48#include "magick/color-private.h"
49#include "magick/composite-private.h"
50#include "magick/constitute.h"
51#include "magick/exception.h"
52#include "magick/exception-private.h"
53#include "magick/geometry.h"
54#include "magick/memory_.h"
cristy46f08202010-01-10 04:04:21 +000055#include "magick/pixel.h"
cristy3ed852e2009-09-05 21:47:34 +000056#include "magick/quantum.h"
57#include "magick/quantum-private.h"
58#include "magick/semaphore.h"
59#include "magick/stream.h"
60#include "magick/stream-private.h"
61#include "magick/string_.h"
62
63/*
64 Typedef declaractions.
65*/
66struct _StreamInfo
67{
68 const ImageInfo
69 *image_info;
70
71 const Image
72 *image;
73
74 Image
75 *stream;
76
77 QuantumInfo
78 *quantum_info;
79
80 char
81 *map;
82
83 StorageType
84 storage_type;
85
86 unsigned char
87 *pixels;
88
89 RectangleInfo
90 extract_info;
91
cristybb503372010-05-27 20:51:26 +000092 ssize_t
cristy3ed852e2009-09-05 21:47:34 +000093 y;
94
95 ExceptionInfo
96 *exception;
97
98 const void
99 *client_data;
100
cristybb503372010-05-27 20:51:26 +0000101 size_t
cristy3ed852e2009-09-05 21:47:34 +0000102 signature;
103};
104
105/*
106 Declare pixel cache interfaces.
107*/
108#if defined(__cplusplus) || defined(c_plusplus)
109extern "C" {
110#endif
111
112static const PixelPacket
cristybb503372010-05-27 20:51:26 +0000113 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
114 const ssize_t,const size_t,const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000115
116static MagickBooleanType
117 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
118 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
119
120static PixelPacket
cristybb503372010-05-27 20:51:26 +0000121 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
122 const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000123
124#if defined(__cplusplus) || defined(c_plusplus)
125}
126#endif
127
128/*
129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130% %
131% %
132% %
133+ A c q u i r e S t r e a m I n f o %
134% %
135% %
136% %
137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138%
139% AcquireStreamInfo() allocates the StreamInfo structure.
140%
141% The format of the AcquireStreamInfo method is:
142%
143% StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
144%
145% A description of each parameter follows:
146%
147% o image_info: the image info.
148%
149*/
150MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
151{
152 StreamInfo
153 *stream_info;
154
cristy90823212009-12-12 20:48:33 +0000155 stream_info=(StreamInfo *) AcquireAlignedMemory(1,sizeof(*stream_info));
cristy3ed852e2009-09-05 21:47:34 +0000156 if (stream_info == (StreamInfo *) NULL)
157 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
158 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
159 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
160 sizeof(*stream_info->pixels));
161 if (stream_info->pixels == (unsigned char *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 stream_info->map=ConstantString("RGB");
164 stream_info->storage_type=CharPixel;
165 stream_info->stream=AcquireImage(image_info);
166 stream_info->signature=MagickSignature;
167 return(stream_info);
168}
169
170/*
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172% %
173% %
174% %
175+ D e s t r o y P i x e l S t r e a m %
176% %
177% %
178% %
179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180%
181% DestroyPixelStream() deallocates memory associated with the pixel stream.
182%
183% The format of the DestroyPixelStream() method is:
184%
185% void DestroyPixelStream(Image *image)
186%
187% A description of each parameter follows:
188%
189% o image: the image.
190%
191*/
192
193static inline void RelinquishStreamPixels(CacheInfo *cache_info)
194{
195 assert(cache_info != (CacheInfo *) NULL);
196 if (cache_info->mapped == MagickFalse)
197 (void) RelinquishMagickMemory(cache_info->pixels);
198 else
199 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
200 cache_info->pixels=(PixelPacket *) NULL;
201 cache_info->indexes=(IndexPacket *) NULL;
202 cache_info->length=0;
203 cache_info->mapped=MagickFalse;
204}
205
206static void DestroyPixelStream(Image *image)
207{
208 CacheInfo
209 *cache_info;
210
211 MagickBooleanType
212 destroy;
213
214 assert(image != (Image *) NULL);
215 assert(image->signature == MagickSignature);
216 if (image->debug != MagickFalse)
217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
218 cache_info=(CacheInfo *) image->cache;
219 assert(cache_info->signature == MagickSignature);
220 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000221 LockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000222 cache_info->reference_count--;
223 if (cache_info->reference_count == 0)
224 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +0000225 UnlockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000226 if (destroy == MagickFalse)
227 return;
228 RelinquishStreamPixels(cache_info);
229 if (cache_info->nexus_info != (NexusInfo **) NULL)
230 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
231 cache_info->number_threads);
232 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
233 DestroySemaphoreInfo(&cache_info->disk_semaphore);
234 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
235 DestroySemaphoreInfo(&cache_info->semaphore);
236 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
237}
238
239/*
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241% %
242% %
243% %
244+ D e s t r o y S t r e a m I n f o %
245% %
246% %
247% %
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249%
250% DestroyStreamInfo() destroys memory associated with the StreamInfo
251% structure.
252%
253% The format of the DestroyStreamInfo method is:
254%
255% StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
256%
257% A description of each parameter follows:
258%
259% o stream_info: the stream info.
260%
261*/
262MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
263{
264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
265 assert(stream_info != (StreamInfo *) NULL);
266 assert(stream_info->signature == MagickSignature);
267 if (stream_info->map != (char *) NULL)
268 stream_info->map=DestroyString(stream_info->map);
269 if (stream_info->pixels != (unsigned char *) NULL)
270 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
271 stream_info->pixels);
272 if (stream_info->stream != (Image *) NULL)
273 {
274 (void) CloseBlob(stream_info->stream);
275 stream_info->stream=DestroyImage(stream_info->stream);
276 }
277 if (stream_info->quantum_info != (QuantumInfo *) NULL)
278 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
279 stream_info->signature=(~MagickSignature);
280 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
281 return(stream_info);
282}
283
284/*
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286% %
287% %
288% %
289+ G e t A u t h e n t i c I n d e x e s F r o m S t r e a m %
290% %
291% %
292% %
293%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294%
295% GetAuthenticIndexesFromStream() returns the indexes associated with the
296% last call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
297%
298% The format of the GetAuthenticIndexesFromStream() method is:
299%
300% IndexPacket *GetAuthenticIndexesFromStream(const Image *image)
301%
302% A description of each parameter follows:
303%
304% o image: the image.
305%
306*/
307static IndexPacket *GetAuthenticIndexesFromStream(const Image *image)
308{
309 CacheInfo
310 *cache_info;
311
312 assert(image != (Image *) NULL);
313 assert(image->signature == MagickSignature);
314 if (image->debug != MagickFalse)
315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
316 cache_info=(CacheInfo *) image->cache;
317 assert(cache_info->signature == MagickSignature);
318 return(cache_info->indexes);
319}
320
321/*
322%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323% %
324% %
325% %
326+ G e t A u t h e n t i c P i x e l S t r e a m %
327% %
328% %
329% %
330%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331%
332% GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
333% cache as defined by the geometry parameters. A pointer to the pixels is
334% returned if the pixels are transferred, otherwise a NULL is returned. For
335% streams this method is a no-op.
336%
337% The format of the GetAuthenticPixelsStream() method is:
338%
cristybb503372010-05-27 20:51:26 +0000339% PixelPacket *GetAuthenticPixelsStream(Image *image,const ssize_t x,
340% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000341% ExceptionInfo *exception)
342%
343% A description of each parameter follows:
344%
345% o image: the image.
346%
347% o x,y,columns,rows: These values define the perimeter of a region of
348% pixels.
349%
350% o exception: return any errors or warnings in this structure.
351%
352*/
cristybb503372010-05-27 20:51:26 +0000353static PixelPacket *GetAuthenticPixelsStream(Image *image,const ssize_t x,
354 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000355 ExceptionInfo *exception)
356{
357 PixelPacket
358 *pixels;
359
360 assert(image != (Image *) NULL);
361 assert(image->signature == MagickSignature);
362 if (image->debug != MagickFalse)
363 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
364 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
365 return(pixels);
366}
367
368/*
369%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370% %
371% %
372% %
373+ G e t A u t h e n t i c P i x e l F r o m S t e a m %
374% %
375% %
376% %
377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378%
379% GetAuthenticPixelsFromStream() returns the pixels associated with the last
380% call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
381%
382% The format of the GetAuthenticPixelsFromStream() method is:
383%
384% PixelPacket *GetAuthenticPixelsFromStream(const Image image)
385%
386% A description of each parameter follows:
387%
388% o image: the image.
389%
390*/
391static PixelPacket *GetAuthenticPixelsFromStream(const Image *image)
392{
393 CacheInfo
394 *cache_info;
395
396 assert(image != (Image *) NULL);
397 assert(image->signature == MagickSignature);
398 if (image->debug != MagickFalse)
399 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
400 cache_info=(CacheInfo *) image->cache;
401 assert(cache_info->signature == MagickSignature);
402 return(cache_info->pixels);
403}
404
405/*
406%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407% %
408% %
409% %
410+ G e t O n e A u t h e n t i c P i x e l F r o m S t r e a m %
411% %
412% %
413% %
414%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415%
416% GetOneAuthenticPixelFromStream() returns a single pixel at the specified
417% (x,y) location. The image background color is returned if an error occurs.
418%
419% The format of the GetOneAuthenticPixelFromStream() method is:
420%
421% MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
cristycfae90a2010-10-04 14:43:33 +0000422% const ssize_t x,const ssize_t y,PixelPacket *pixel,
423% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000424%
425% A description of each parameter follows:
426%
427% o image: the image.
428%
429% o pixel: return a pixel at the specified (x,y) location.
430%
431% o x,y: These values define the location of the pixel to return.
432%
433% o exception: return any errors or warnings in this structure.
434%
435*/
436static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
cristybb503372010-05-27 20:51:26 +0000437 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000438{
439 register PixelPacket
440 *pixels;
441
442 assert(image != (Image *) NULL);
443 assert(image->signature == MagickSignature);
444 *pixel=image->background_color;
445 pixels=GetAuthenticPixelsStream(image,x,y,1,1,exception);
446 if (pixels != (PixelPacket *) NULL)
447 return(MagickFalse);
448 *pixel=(*pixels);
449 return(MagickTrue);
450}
451
452/*
453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454% %
455% %
456% %
457+ G e t O n e V i r t u a l P i x e l F r o m S t r e a m %
458% %
459% %
460% %
461%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462%
463% GetOneVirtualPixelFromStream() returns a single pixel at the specified
464% (x.y) location. The image background color is returned if an error occurs.
465%
466% The format of the GetOneVirtualPixelFromStream() method is:
467%
468% MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
cristybb503372010-05-27 20:51:26 +0000469% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
470% const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000471%
472% A description of each parameter follows:
473%
474% o image: the image.
475%
476% o virtual_pixel_method: the virtual pixel method.
477%
478% o x,y: These values define the location of the pixel to return.
479%
480% o pixel: return a pixel at the specified (x,y) location.
481%
482% o exception: return any errors or warnings in this structure.
483%
484*/
485static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000486 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +0000487 PixelPacket *pixel,ExceptionInfo *exception)
488{
489 const PixelPacket
490 *pixels;
491
492 assert(image != (Image *) NULL);
493 assert(image->signature == MagickSignature);
494 *pixel=image->background_color;
495 pixels=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
496 if (pixels != (const PixelPacket *) NULL)
497 return(MagickFalse);
498 *pixel=(*pixels);
499 return(MagickTrue);
500}
501
502/*
503%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
504% %
505% %
506% %
507+ G e t S t r e a m I n f o C l i e n t D a t a %
508% %
509% %
510% %
511%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512%
513% GetStreamInfoClientData() gets the stream info client data.
514%
515% The format of the SetStreamInfoClientData method is:
516%
517% const void *GetStreamInfoClientData(StreamInfo *stream_info)
518%
519% A description of each parameter follows:
520%
521% o stream_info: the stream info.
522%
523*/
524MagickExport const void *GetStreamInfoClientData(StreamInfo *stream_info)
525{
526 assert(stream_info != (StreamInfo *) NULL);
527 assert(stream_info->signature == MagickSignature);
528 return(stream_info->client_data);
529}
530
531/*
532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533% %
534% %
535% %
536+ G e t V i r t u a l P i x e l s F r o m S t r e a m %
537% %
538% %
539% %
540%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541%
542% GetVirtualPixelsStream() returns the pixels associated with the last
543% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
544%
545% The format of the GetVirtualPixelsStream() method is:
546%
547% const IndexPacket *GetVirtualPixelsStream(const Image *image)
548%
549% A description of each parameter follows:
550%
551% o pixels: return the pixels associated with the last call to
552% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
553%
554% o image: the image.
555%
556*/
557static const PixelPacket *GetVirtualPixelsStream(const Image *image)
558{
559 CacheInfo
560 *cache_info;
561
562 assert(image != (Image *) NULL);
563 assert(image->signature == MagickSignature);
564 if (image->debug != MagickFalse)
565 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
566 cache_info=(CacheInfo *) image->cache;
567 assert(cache_info->signature == MagickSignature);
568 return(cache_info->pixels);
569}
570
571/*
572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573% %
574% %
575% %
576+ G e t V i r t u a l I n d e x e s F r o m S t r e a m %
577% %
578% %
579% %
580%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581%
582% GetVirtualIndexesFromStream() returns the indexes associated with the last
583% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
584%
585% The format of the GetVirtualIndexesFromStream() method is:
586%
587% const IndexPacket *GetVirtualIndexesFromStream(const Image *image)
588%
589% A description of each parameter follows:
590%
591% o image: the image.
592%
593*/
594static const IndexPacket *GetVirtualIndexesFromStream(const Image *image)
595{
596 CacheInfo
597 *cache_info;
598
599 assert(image != (Image *) NULL);
600 assert(image->signature == MagickSignature);
601 if (image->debug != MagickFalse)
602 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
603 cache_info=(CacheInfo *) image->cache;
604 assert(cache_info->signature == MagickSignature);
605 return(cache_info->indexes);
606}
607
608/*
609%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
610% %
611% %
612% %
613+ G e t V i r t u a l P i x e l S t r e a m %
614% %
615% %
616% %
617%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618%
619% GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
620% defined by the geometry parameters. A pointer to the pixels is returned if
621% the pixels are transferred, otherwise a NULL is returned. For streams this
622% method is a no-op.
623%
624% The format of the GetVirtualPixelStream() method is:
625%
626% const PixelPacket *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000627% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
628% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000629% ExceptionInfo *exception)
630%
631% A description of each parameter follows:
632%
633% o image: the image.
634%
635% o virtual_pixel_method: the virtual pixel method.
636%
637% o x,y,columns,rows: These values define the perimeter of a region of
638% pixels.
639%
640% o exception: return any errors or warnings in this structure.
641%
642*/
643
644static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
645 ExceptionInfo *exception)
646{
647 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
648 return(MagickFalse);
649 cache_info->mapped=MagickFalse;
650 cache_info->pixels=(PixelPacket *) AcquireMagickMemory((size_t)
651 cache_info->length);
652 if (cache_info->pixels == (PixelPacket *) NULL)
653 {
654 cache_info->mapped=MagickTrue;
655 cache_info->pixels=(PixelPacket *) MapBlob(-1,IOMode,0,(size_t)
656 cache_info->length);
657 }
658 if (cache_info->pixels == (PixelPacket *) NULL)
659 {
660 (void) ThrowMagickException(exception,GetMagickModule(),
661 ResourceLimitError,"MemoryAllocationFailed","`%s'",
662 cache_info->filename);
663 return(MagickFalse);
664 }
665 return(MagickTrue);
666}
667
668static const PixelPacket *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000669 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
670 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000671 ExceptionInfo *exception)
672{
673 CacheInfo
674 *cache_info;
675
676 MagickBooleanType
677 status;
678
679 MagickSizeType
680 number_pixels;
681
682 size_t
683 length;
684
685 /*
686 Validate pixel cache geometry.
687 */
688 assert(image != (const Image *) NULL);
689 assert(image->signature == MagickSignature);
690 if (image->debug != MagickFalse)
691 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy5dd71882010-08-01 20:53:13 +0000692 if ((x < 0) || (y < 0) ||
693 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
694 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
695 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000696 {
697 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
698 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
699 return((PixelPacket *) NULL);
700 }
701 cache_info=(CacheInfo *) image->cache;
702 assert(cache_info->signature == MagickSignature);
703 /*
704 Pixels are stored in a temporary buffer until they are synced to the cache.
705 */
706 number_pixels=(MagickSizeType) columns*rows;
707 length=(size_t) number_pixels*sizeof(PixelPacket);
708 if ((image->storage_class == PseudoClass) ||
709 (image->colorspace == CMYKColorspace))
710 length+=number_pixels*sizeof(IndexPacket);
711 if (cache_info->pixels == (PixelPacket *) NULL)
712 {
713 cache_info->length=length;
714 status=AcquireStreamPixels(cache_info,exception);
715 if (status == MagickFalse)
716 return((PixelPacket *) NULL);
717 }
718 else
719 if (cache_info->length != length)
720 {
721 RelinquishStreamPixels(cache_info);
722 cache_info->length=length;
723 status=AcquireStreamPixels(cache_info,exception);
724 if (status == MagickFalse)
725 return((PixelPacket *) NULL);
726 }
727 cache_info->indexes=(IndexPacket *) NULL;
728 if ((image->storage_class == PseudoClass) ||
729 (image->colorspace == CMYKColorspace))
730 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
731 return(cache_info->pixels);
732}
733
734/*
735%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
736% %
737% %
738% %
739+ O p e n S t r e a m %
740% %
741% %
742% %
743%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744%
745% OpenStream() opens a stream for writing by the StreamImage() method.
746%
747% The format of the OpenStream method is:
748%
749% MagickBooleanType OpenStream(const ImageInfo *image_info,
750% StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
751%
752% A description of each parameter follows:
753%
754% o image_info: the image info.
755%
756% o stream_info: the stream info.
757%
758% o filename: the stream filename.
759%
760% o exception: return any errors or warnings in this structure.
761%
762*/
763MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
764 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
765{
766 MagickBooleanType
767 status;
768
769 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
770 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
771 return(status);
772}
773
774/*
775%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776% %
777% %
778% %
779+ 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 %
780% %
781% %
782% %
783%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784%
785% QueueAuthenticPixelsStream() allocates an area to store image pixels as
786% defined by the region rectangle and returns a pointer to the area. This
787% area is subsequently transferred from the pixel cache with method
788% SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
789% pixels are transferred, otherwise a NULL is returned.
790%
791% The format of the QueueAuthenticPixelsStream() method is:
792%
cristybb503372010-05-27 20:51:26 +0000793% PixelPacket *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
794% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000795% ExceptionInfo *exception)
796%
797% A description of each parameter follows:
798%
799% o image: the image.
800%
801% o x,y,columns,rows: These values define the perimeter of a region of
802% pixels.
803%
804*/
cristybb503372010-05-27 20:51:26 +0000805static PixelPacket *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
806 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000807 ExceptionInfo *exception)
808{
809 CacheInfo
810 *cache_info;
811
812 MagickSizeType
813 number_pixels;
814
815 size_t
816 length;
817
818 StreamHandler
819 stream_handler;
820
821 /*
822 Validate pixel cache geometry.
823 */
824 assert(image != (Image *) NULL);
cristycfae90a2010-10-04 14:43:33 +0000825 if ((x < 0) || (y < 0) ||
826 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
827 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
828 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000829 {
830 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
831 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
832 return((PixelPacket *) NULL);
833 }
834 stream_handler=GetBlobStreamHandler(image);
835 if (stream_handler == (StreamHandler) NULL)
836 {
837 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
838 "NoStreamHandlerIsDefined","`%s'",image->filename);
839 return((PixelPacket *) NULL);
840 }
841 cache_info=(CacheInfo *) image->cache;
842 assert(cache_info->signature == MagickSignature);
843 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
844 (image->colorspace != GetPixelCacheColorspace(image->cache)))
845 {
846 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
847 (void) stream_handler(image,(const void *) NULL,(size_t)
848 cache_info->columns);
849 cache_info->storage_class=image->storage_class;
850 cache_info->colorspace=image->colorspace;
851 cache_info->columns=image->columns;
852 cache_info->rows=image->rows;
853 image->cache=cache_info;
854 }
855 /*
856 Pixels are stored in a temporary buffer until they are synced to the cache.
857 */
858 cache_info->columns=columns;
859 cache_info->rows=rows;
860 number_pixels=(MagickSizeType) columns*rows;
861 length=(size_t) number_pixels*sizeof(PixelPacket);
862 if ((image->storage_class == PseudoClass) ||
863 (image->colorspace == CMYKColorspace))
864 length+=number_pixels*sizeof(IndexPacket);
865 if (cache_info->pixels == (PixelPacket *) NULL)
866 {
867 cache_info->pixels=(PixelPacket *) AcquireMagickMemory(length);
868 cache_info->length=(MagickSizeType) length;
869 }
870 else
871 if (cache_info->length < (MagickSizeType) length)
872 {
873 cache_info->pixels=(PixelPacket *) ResizeMagickMemory(
874 cache_info->pixels,length);
875 cache_info->length=(MagickSizeType) length;
876 }
877 if (cache_info->pixels == (void *) NULL)
878 return((PixelPacket *) NULL);
879 cache_info->indexes=(IndexPacket *) NULL;
880 if ((image->storage_class == PseudoClass) ||
881 (image->colorspace == CMYKColorspace))
882 cache_info->indexes=(IndexPacket *) (cache_info->pixels+number_pixels);
883 return(cache_info->pixels);
884}
885
886/*
887%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888% %
889% %
890% %
891% R e a d S t r e a m %
892% %
893% %
894% %
895%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896%
897% ReadStream() makes the image pixels available to a user supplied callback
898% method immediately upon reading a scanline with the ReadImage() method.
899%
900% The format of the ReadStream() method is:
901%
902% Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
903% ExceptionInfo *exception)
904%
905% A description of each parameter follows:
906%
907% o image_info: the image info.
908%
909% o stream: a callback method.
910%
911% o exception: return any errors or warnings in this structure.
912%
913*/
914MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
915 ExceptionInfo *exception)
916{
917 CacheMethods
918 cache_methods;
919
920 Image
921 *image;
922
923 ImageInfo
924 *read_info;
925
926 /*
927 Stream image pixels.
928 */
929 assert(image_info != (ImageInfo *) NULL);
930 assert(image_info->signature == MagickSignature);
931 if (image_info->debug != MagickFalse)
932 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
933 image_info->filename);
934 assert(exception != (ExceptionInfo *) NULL);
935 assert(exception->signature == MagickSignature);
936 read_info=CloneImageInfo(image_info);
937 read_info->cache=AcquirePixelCache(0);
938 GetPixelCacheMethods(&cache_methods);
939 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
940 cache_methods.get_virtual_indexes_from_handler=GetVirtualIndexesFromStream;
941 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
942 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
943 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
944 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
945 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
946 cache_methods.get_authentic_indexes_from_handler=
947 GetAuthenticIndexesFromStream;
948 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
949 cache_methods.get_one_authentic_pixel_from_handler=
950 GetOneAuthenticPixelFromStream;
951 cache_methods.destroy_pixel_handler=DestroyPixelStream;
952 SetPixelCacheMethods(read_info->cache,&cache_methods);
953 read_info->stream=stream;
954 image=ReadImage(read_info,exception);
955 read_info=DestroyImageInfo(read_info);
956 return(image);
957}
958
959/*
960%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
961% %
962% %
963% %
964+ S e t S t r e a m I n f o C l i e n t D a t a %
965% %
966% %
967% %
968%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
969%
970% SetStreamInfoClientData() sets the stream info client data.
971%
972% The format of the SetStreamInfoClientData method is:
973%
974% void SetStreamInfoClientData(StreamInfo *stream_info,
975% const void *client_data)
976%
977% A description of each parameter follows:
978%
979% o stream_info: the stream info.
980%
981% o client_data: the client data.
982%
983*/
984MagickExport void SetStreamInfoClientData(StreamInfo *stream_info,
985 const void *client_data)
986{
987 assert(stream_info != (StreamInfo *) NULL);
988 assert(stream_info->signature == MagickSignature);
989 stream_info->client_data=client_data;
990}
991
992/*
993%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994% %
995% %
996% %
997+ S e t S t r e a m I n f o M a p %
998% %
999% %
1000% %
1001%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002%
1003% SetStreamInfoMap() sets the stream info map member.
1004%
1005% The format of the SetStreamInfoMap method is:
1006%
1007% void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1008%
1009% A description of each parameter follows:
1010%
1011% o stream_info: the stream info.
1012%
1013% o map: the map.
1014%
1015*/
1016MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1017{
1018 assert(stream_info != (StreamInfo *) NULL);
1019 assert(stream_info->signature == MagickSignature);
1020 (void) CloneString(&stream_info->map,map);
1021}
1022
1023/*
1024%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1025% %
1026% %
1027% %
1028+ S e t S t r e a m I n f o S t o r a g e T y p e %
1029% %
1030% %
1031% %
1032%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1033%
1034% SetStreamInfoStorageType() sets the stream info storage type member.
1035%
1036% The format of the SetStreamInfoStorageType method is:
1037%
1038% void SetStreamInfoStorageType(StreamInfo *stream_info,
1039% const StoreageType *storage_type)
1040%
1041% A description of each parameter follows:
1042%
1043% o stream_info: the stream info.
1044%
1045% o storage_type: the storage type.
1046%
1047*/
1048MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1049 const StorageType storage_type)
1050{
1051 assert(stream_info != (StreamInfo *) NULL);
1052 assert(stream_info->signature == MagickSignature);
1053 stream_info->storage_type=storage_type;
1054}
1055
1056/*
1057%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058% %
1059% %
1060% %
1061+ S t r e a m I m a g e %
1062% %
1063% %
1064% %
1065%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1066%
1067% StreamImage() streams pixels from an image and writes them in a user
1068% defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1069%
1070% The format of he wStreamImage() method is:
1071%
1072% Image *StreamImage(const ImageInfo *image_info,
1073% StreamInfo *stream_info,ExceptionInfo *exception)
1074%
1075% A description of each parameter follows:
1076%
1077% o image_info: the image info.
1078%
1079% o stream_info: the stream info.
1080%
1081% o exception: return any errors or warnings in this structure.
1082%
1083*/
1084
1085#if defined(__cplusplus) || defined(c_plusplus)
1086extern "C" {
1087#endif
1088
1089static size_t WriteStreamImage(const Image *image,const void *pixels,
1090 const size_t columns)
1091{
cristye3664f42010-05-14 00:59:57 +00001092 CacheInfo
1093 *cache_info;
1094
cristy3ed852e2009-09-05 21:47:34 +00001095 RectangleInfo
1096 extract_info;
1097
1098 size_t
1099 length,
1100 packet_size;
1101
1102 ssize_t
1103 count;
1104
1105 StreamInfo
1106 *stream_info;
1107
1108 stream_info=(StreamInfo *) image->client_data;
1109 switch (stream_info->storage_type)
1110 {
1111 default: packet_size=sizeof(char); break;
1112 case CharPixel: packet_size=sizeof(char); break;
1113 case DoublePixel: packet_size=sizeof(double); break;
1114 case FloatPixel: packet_size=sizeof(float); break;
1115 case IntegerPixel: packet_size=sizeof(int); break;
cristybb503372010-05-27 20:51:26 +00001116 case LongPixel: packet_size=sizeof(ssize_t); break;
cristy3ed852e2009-09-05 21:47:34 +00001117 case QuantumPixel: packet_size=sizeof(Quantum); break;
1118 case ShortPixel: packet_size=sizeof(unsigned short); break;
1119 }
cristye3664f42010-05-14 00:59:57 +00001120 cache_info=(CacheInfo *) image->cache;
1121 assert(cache_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001122 packet_size*=strlen(stream_info->map);
cristye3664f42010-05-14 00:59:57 +00001123 length=packet_size*cache_info->columns*cache_info->rows;
cristy3ed852e2009-09-05 21:47:34 +00001124 if (image != stream_info->image)
1125 {
1126 ImageInfo
1127 *write_info;
1128
1129 /*
1130 Prepare stream for writing.
1131 */
1132 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1133 stream_info->pixels,length,sizeof(*stream_info->pixels));
cristy5dd71882010-08-01 20:53:13 +00001134 if (stream_info->pixels == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001135 return(0);
1136 stream_info->image=image;
1137 write_info=CloneImageInfo(stream_info->image_info);
cristyd965a422010-03-03 17:47:35 +00001138 (void) SetImageInfo(write_info,1,stream_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001139 if (write_info->extract != (char *) NULL)
1140 (void) ParseAbsoluteGeometry(write_info->extract,
1141 &stream_info->extract_info);
1142 stream_info->y=0;
1143 write_info=DestroyImageInfo(write_info);
1144 }
1145 extract_info=stream_info->extract_info;
1146 if ((extract_info.width == 0) ||
1147 (extract_info.height == 0))
1148 {
1149 /*
1150 Write all pixels to stream.
1151 */
1152 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1153 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1154 stream_info->y++;
1155 return(count == 0 ? 0 : columns);
1156 }
1157 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001158 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001159 {
1160 stream_info->y++;
1161 return(columns);
1162 }
1163 /*
1164 Write a portion of the pixel row to the stream.
1165 */
1166 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1167 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001168 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1169 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001170 stream_info->y++;
1171 return(count == 0 ? 0 : columns);
1172}
1173
1174#if defined(__cplusplus) || defined(c_plusplus)
1175}
1176#endif
1177
1178MagickExport Image *StreamImage(const ImageInfo *image_info,
1179 StreamInfo *stream_info,ExceptionInfo *exception)
1180{
1181 Image
1182 *image;
1183
1184 ImageInfo
1185 *read_info;
1186
1187 assert(image_info != (const ImageInfo *) NULL);
1188 assert(image_info->signature == MagickSignature);
1189 if (image_info->debug != MagickFalse)
1190 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1191 image_info->filename);
1192 assert(stream_info != (StreamInfo *) NULL);
1193 assert(stream_info->signature == MagickSignature);
1194 assert(exception != (ExceptionInfo *) NULL);
1195 read_info=CloneImageInfo(image_info);
1196 stream_info->image_info=image_info;
1197 stream_info->exception=exception;
1198 read_info->client_data=(void *) stream_info;
1199 image=ReadStream(read_info,&WriteStreamImage,exception);
1200 read_info=DestroyImageInfo(read_info);
1201 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1202 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1203 image=DestroyImage(image);
1204 return(image);
1205}
1206
1207/*
1208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1209% %
1210% %
1211% %
1212+ S t r e a m I m a g e P i x e l s %
1213% %
1214% %
1215% %
1216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1217%
1218% StreamImagePixels() extracts pixel data from an image and returns it in the
1219% stream_info->pixels structure in the format as defined by
1220% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1221%
1222% The format of the StreamImagePixels method is:
1223%
1224% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1225% const Image *image,ExceptionInfo *exception)
1226%
1227% A description of each parameter follows:
1228%
1229% o stream_info: the stream info.
1230%
1231% o image: the image.
1232%
1233% o exception: return any errors or warnings in this structure.
1234%
1235*/
1236static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1237 const Image *image,ExceptionInfo *exception)
1238{
1239 QuantumInfo
1240 *quantum_info;
1241
1242 QuantumType
1243 *quantum_map;
1244
cristybb503372010-05-27 20:51:26 +00001245 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001246 i,
1247 x;
1248
1249 register const PixelPacket
1250 *p;
1251
1252 register IndexPacket
1253 *indexes;
1254
1255 size_t
1256 length;
1257
1258 assert(stream_info != (StreamInfo *) NULL);
1259 assert(stream_info->signature == MagickSignature);
1260 assert(image != (Image *) NULL);
1261 assert(image->signature == MagickSignature);
1262 if (image->debug != MagickFalse)
1263 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1264 length=strlen(stream_info->map);
1265 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1266 if (quantum_map == (QuantumType *) NULL)
1267 {
1268 (void) ThrowMagickException(exception,GetMagickModule(),
1269 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1270 return(MagickFalse);
1271 }
cristybb503372010-05-27 20:51:26 +00001272 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001273 {
1274 switch (stream_info->map[i])
1275 {
1276 case 'A':
1277 case 'a':
1278 {
1279 quantum_map[i]=AlphaQuantum;
1280 break;
1281 }
1282 case 'B':
1283 case 'b':
1284 {
1285 quantum_map[i]=BlueQuantum;
1286 break;
1287 }
1288 case 'C':
1289 case 'c':
1290 {
1291 quantum_map[i]=CyanQuantum;
1292 if (image->colorspace == CMYKColorspace)
1293 break;
1294 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1295 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1296 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1297 return(MagickFalse);
1298 }
1299 case 'g':
1300 case 'G':
1301 {
1302 quantum_map[i]=GreenQuantum;
1303 break;
1304 }
1305 case 'I':
1306 case 'i':
1307 {
1308 quantum_map[i]=IndexQuantum;
1309 break;
1310 }
1311 case 'K':
1312 case 'k':
1313 {
1314 quantum_map[i]=BlackQuantum;
1315 if (image->colorspace == CMYKColorspace)
1316 break;
1317 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1318 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1319 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1320 return(MagickFalse);
1321 }
1322 case 'M':
1323 case 'm':
1324 {
1325 quantum_map[i]=MagentaQuantum;
1326 if (image->colorspace == CMYKColorspace)
1327 break;
1328 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1329 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1330 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1331 return(MagickFalse);
1332 }
1333 case 'o':
1334 case 'O':
1335 {
1336 quantum_map[i]=OpacityQuantum;
1337 break;
1338 }
1339 case 'P':
1340 case 'p':
1341 {
1342 quantum_map[i]=UndefinedQuantum;
1343 break;
1344 }
1345 case 'R':
1346 case 'r':
1347 {
1348 quantum_map[i]=RedQuantum;
1349 break;
1350 }
1351 case 'Y':
1352 case 'y':
1353 {
1354 quantum_map[i]=YellowQuantum;
1355 if (image->colorspace == CMYKColorspace)
1356 break;
1357 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1358 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1359 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1360 return(MagickFalse);
1361 }
1362 default:
1363 {
1364 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1365 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1366 "UnrecognizedPixelMap","`%s'",stream_info->map);
1367 return(MagickFalse);
1368 }
1369 }
1370 }
1371 quantum_info=stream_info->quantum_info;
1372 switch (stream_info->storage_type)
1373 {
1374 case CharPixel:
1375 {
1376 register unsigned char
1377 *q;
1378
1379 q=(unsigned char *) stream_info->pixels;
1380 if (LocaleCompare(stream_info->map,"BGR") == 0)
1381 {
1382 p=GetAuthenticPixelQueue(image);
1383 if (p == (const PixelPacket *) NULL)
1384 break;
cristybb503372010-05-27 20:51:26 +00001385 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001386 {
cristyce70c172010-01-07 17:15:30 +00001387 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1388 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1389 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001390 p++;
1391 }
1392 break;
1393 }
1394 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1395 {
1396 p=GetAuthenticPixelQueue(image);
1397 if (p == (const PixelPacket *) NULL)
1398 break;
cristybb503372010-05-27 20:51:26 +00001399 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001400 {
cristyce70c172010-01-07 17:15:30 +00001401 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1402 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1403 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00001404 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001405 p++;
1406 }
1407 break;
1408 }
1409 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1410 {
1411 p=GetAuthenticPixelQueue(image);
1412 if (p == (const PixelPacket *) NULL)
1413 break;
cristybb503372010-05-27 20:51:26 +00001414 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001415 {
cristyce70c172010-01-07 17:15:30 +00001416 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
1417 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1418 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001419 *q++=ScaleQuantumToChar((Quantum) 0);
1420 p++;
1421 }
1422 break;
1423 }
1424 if (LocaleCompare(stream_info->map,"I") == 0)
1425 {
1426 p=GetAuthenticPixelQueue(image);
1427 if (p == (const PixelPacket *) NULL)
1428 break;
cristybb503372010-05-27 20:51:26 +00001429 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001430 {
1431 *q++=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1432 p++;
1433 }
1434 break;
1435 }
1436 if (LocaleCompare(stream_info->map,"RGB") == 0)
1437 {
1438 p=GetAuthenticPixelQueue(image);
1439 if (p == (const PixelPacket *) NULL)
1440 break;
cristybb503372010-05-27 20:51:26 +00001441 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001442 {
cristyce70c172010-01-07 17:15:30 +00001443 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1444 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1445 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001446 p++;
1447 }
1448 break;
1449 }
1450 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1451 {
1452 p=GetAuthenticPixelQueue(image);
1453 if (p == (const PixelPacket *) NULL)
1454 break;
cristybb503372010-05-27 20:51:26 +00001455 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001456 {
cristyce70c172010-01-07 17:15:30 +00001457 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1458 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1459 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00001460 *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001461 p++;
1462 }
1463 break;
1464 }
1465 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1466 {
1467 p=GetAuthenticPixelQueue(image);
1468 if (p == (const PixelPacket *) NULL)
1469 break;
cristybb503372010-05-27 20:51:26 +00001470 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001471 {
cristyce70c172010-01-07 17:15:30 +00001472 *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
1473 *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
1474 *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001475 *q++=ScaleQuantumToChar((Quantum) 0);
1476 p++;
1477 }
1478 break;
1479 }
1480 p=GetAuthenticPixelQueue(image);
1481 if (p == (const PixelPacket *) NULL)
1482 break;
1483 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001484 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001485 {
cristybb503372010-05-27 20:51:26 +00001486 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001487 {
1488 *q=0;
1489 switch (quantum_map[i])
1490 {
1491 case RedQuantum:
1492 case CyanQuantum:
1493 {
cristyce70c172010-01-07 17:15:30 +00001494 *q=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001495 break;
1496 }
1497 case GreenQuantum:
1498 case MagentaQuantum:
1499 {
cristyce70c172010-01-07 17:15:30 +00001500 *q=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001501 break;
1502 }
1503 case BlueQuantum:
1504 case YellowQuantum:
1505 {
cristyce70c172010-01-07 17:15:30 +00001506 *q=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001507 break;
1508 }
1509 case AlphaQuantum:
1510 {
cristy46f08202010-01-10 04:04:21 +00001511 *q=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001512 break;
1513 }
1514 case OpacityQuantum:
1515 {
cristyce70c172010-01-07 17:15:30 +00001516 *q=ScaleQuantumToChar(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001517 break;
1518 }
1519 case BlackQuantum:
1520 {
1521 if (image->colorspace == CMYKColorspace)
1522 *q=ScaleQuantumToChar(indexes[x]);
1523 break;
1524 }
1525 case IndexQuantum:
1526 {
1527 *q=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1528 break;
1529 }
1530 default:
1531 break;
1532 }
1533 q++;
1534 }
1535 p++;
1536 }
1537 break;
1538 }
1539 case DoublePixel:
1540 {
1541 register double
1542 *q;
1543
1544 q=(double *) stream_info->pixels;
1545 if (LocaleCompare(stream_info->map,"BGR") == 0)
1546 {
1547 p=GetAuthenticPixelQueue(image);
1548 if (p == (const PixelPacket *) NULL)
1549 break;
cristybb503372010-05-27 20:51:26 +00001550 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001551 {
cristy46f08202010-01-10 04:04:21 +00001552 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1553 quantum_info->scale+quantum_info->minimum);
1554 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1555 quantum_info->scale+quantum_info->minimum);
1556 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1557 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001558 p++;
1559 }
1560 break;
1561 }
1562 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1563 {
1564 p=GetAuthenticPixelQueue(image);
1565 if (p == (const PixelPacket *) NULL)
1566 break;
cristybb503372010-05-27 20:51:26 +00001567 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001568 {
cristy46f08202010-01-10 04:04:21 +00001569 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1570 quantum_info->scale+quantum_info->minimum);
1571 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1572 quantum_info->scale+quantum_info->minimum);
1573 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1574 quantum_info->scale+quantum_info->minimum);
1575 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001576 quantum_info->scale+quantum_info->minimum);
1577 p++;
1578 }
1579 break;
1580 }
1581 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1582 {
1583 p=GetAuthenticPixelQueue(image);
1584 if (p == (const PixelPacket *) NULL)
1585 break;
cristybb503372010-05-27 20:51:26 +00001586 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001587 {
cristy46f08202010-01-10 04:04:21 +00001588 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1589 quantum_info->scale+quantum_info->minimum);
1590 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1591 quantum_info->scale+quantum_info->minimum);
1592 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1593 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001594 *q++=0.0;
1595 p++;
1596 }
1597 break;
1598 }
1599 if (LocaleCompare(stream_info->map,"I") == 0)
1600 {
1601 p=GetAuthenticPixelQueue(image);
1602 if (p == (const PixelPacket *) NULL)
1603 break;
cristybb503372010-05-27 20:51:26 +00001604 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001605 {
1606 *q++=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1607 quantum_info->scale+quantum_info->minimum);
1608 p++;
1609 }
1610 break;
1611 }
1612 if (LocaleCompare(stream_info->map,"RGB") == 0)
1613 {
1614 p=GetAuthenticPixelQueue(image);
1615 if (p == (const PixelPacket *) NULL)
1616 break;
cristybb503372010-05-27 20:51:26 +00001617 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001618 {
cristy46f08202010-01-10 04:04:21 +00001619 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1620 quantum_info->scale+quantum_info->minimum);
1621 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1622 quantum_info->scale+quantum_info->minimum);
1623 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1624 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001625 p++;
1626 }
1627 break;
1628 }
1629 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1630 {
1631 p=GetAuthenticPixelQueue(image);
1632 if (p == (const PixelPacket *) NULL)
1633 break;
cristybb503372010-05-27 20:51:26 +00001634 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001635 {
cristy46f08202010-01-10 04:04:21 +00001636 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1637 quantum_info->scale+quantum_info->minimum);
1638 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1639 quantum_info->scale+quantum_info->minimum);
1640 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1641 quantum_info->scale+quantum_info->minimum);
1642 *q++=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001643 quantum_info->scale+quantum_info->minimum);
1644 p++;
1645 }
1646 break;
1647 }
1648 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1649 {
1650 p=GetAuthenticPixelQueue(image);
1651 if (p == (const PixelPacket *) NULL)
1652 break;
cristybb503372010-05-27 20:51:26 +00001653 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001654 {
cristy46f08202010-01-10 04:04:21 +00001655 *q++=(double) ((QuantumScale*GetRedPixelComponent(p))*
1656 quantum_info->scale+quantum_info->minimum);
1657 *q++=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1658 quantum_info->scale+quantum_info->minimum);
1659 *q++=(double) ((QuantumScale*GetBluePixelComponent(p))*
1660 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001661 *q++=0.0;
1662 p++;
1663 }
1664 break;
1665 }
1666 p=GetAuthenticPixelQueue(image);
1667 if (p == (const PixelPacket *) NULL)
1668 break;
1669 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001670 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001671 {
cristybb503372010-05-27 20:51:26 +00001672 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001673 {
1674 *q=0;
1675 switch (quantum_map[i])
1676 {
1677 case RedQuantum:
1678 case CyanQuantum:
1679 {
cristy46f08202010-01-10 04:04:21 +00001680 *q=(double) ((QuantumScale*GetRedPixelComponent(p))*
1681 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001682 break;
1683 }
1684 case GreenQuantum:
1685 case MagentaQuantum:
1686 {
cristy46f08202010-01-10 04:04:21 +00001687 *q=(double) ((QuantumScale*GetGreenPixelComponent(p))*
1688 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001689 break;
1690 }
1691 case BlueQuantum:
1692 case YellowQuantum:
1693 {
cristy46f08202010-01-10 04:04:21 +00001694 *q=(double) ((QuantumScale*GetBluePixelComponent(p))*
1695 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001696 break;
1697 }
1698 case AlphaQuantum:
1699 {
cristy46f08202010-01-10 04:04:21 +00001700 *q=(double) ((QuantumScale*GetAlphaPixelComponent(p))*
1701 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001702 break;
1703 }
1704 case OpacityQuantum:
1705 {
cristy46f08202010-01-10 04:04:21 +00001706 *q=(double) ((QuantumScale*GetOpacityPixelComponent(p))*
1707 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001708 break;
1709 }
1710 case BlackQuantum:
1711 {
1712 if (image->colorspace == CMYKColorspace)
1713 *q=(double) ((QuantumScale*indexes[x])*quantum_info->scale+
1714 quantum_info->minimum);
1715 break;
1716 }
1717 case IndexQuantum:
1718 {
1719 *q=(double) ((QuantumScale*PixelIntensityToQuantum(p))*
1720 quantum_info->scale+quantum_info->minimum);
1721 break;
1722 }
1723 default:
1724 *q=0;
1725 }
1726 q++;
1727 }
1728 p++;
1729 }
1730 break;
1731 }
1732 case FloatPixel:
1733 {
1734 register float
1735 *q;
1736
1737 q=(float *) stream_info->pixels;
1738 if (LocaleCompare(stream_info->map,"BGR") == 0)
1739 {
1740 p=GetAuthenticPixelQueue(image);
1741 if (p == (const PixelPacket *) NULL)
1742 break;
cristybb503372010-05-27 20:51:26 +00001743 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001744 {
cristy46f08202010-01-10 04:04:21 +00001745 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1746 quantum_info->scale+quantum_info->minimum);
1747 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1748 quantum_info->scale+quantum_info->minimum);
1749 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1750 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001751 p++;
1752 }
1753 break;
1754 }
1755 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1756 {
1757 p=GetAuthenticPixelQueue(image);
1758 if (p == (const PixelPacket *) NULL)
1759 break;
cristybb503372010-05-27 20:51:26 +00001760 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001761 {
cristy46f08202010-01-10 04:04:21 +00001762 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1763 quantum_info->scale+quantum_info->minimum);
1764 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1765 quantum_info->scale+quantum_info->minimum);
1766 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1767 quantum_info->scale+quantum_info->minimum);
1768 *q++=(float) ((QuantumScale*(Quantum) (GetAlphaPixelComponent(p)))*
cristy3ed852e2009-09-05 21:47:34 +00001769 quantum_info->scale+quantum_info->minimum);
1770 p++;
1771 }
1772 break;
1773 }
1774 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1775 {
1776 p=GetAuthenticPixelQueue(image);
1777 if (p == (const PixelPacket *) NULL)
1778 break;
cristybb503372010-05-27 20:51:26 +00001779 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001780 {
cristy46f08202010-01-10 04:04:21 +00001781 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1782 quantum_info->scale+quantum_info->minimum);
1783 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1784 quantum_info->scale+quantum_info->minimum);
1785 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1786 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001787 *q++=0.0;
1788 p++;
1789 }
1790 break;
1791 }
1792 if (LocaleCompare(stream_info->map,"I") == 0)
1793 {
1794 p=GetAuthenticPixelQueue(image);
1795 if (p == (const PixelPacket *) NULL)
1796 break;
cristybb503372010-05-27 20:51:26 +00001797 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001798 {
1799 *q++=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1800 quantum_info->scale+quantum_info->minimum);
1801 p++;
1802 }
1803 break;
1804 }
1805 if (LocaleCompare(stream_info->map,"RGB") == 0)
1806 {
1807 p=GetAuthenticPixelQueue(image);
1808 if (p == (const PixelPacket *) NULL)
1809 break;
cristybb503372010-05-27 20:51:26 +00001810 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001811 {
cristy46f08202010-01-10 04:04:21 +00001812 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1813 quantum_info->scale+quantum_info->minimum);
1814 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1815 quantum_info->scale+quantum_info->minimum);
1816 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1817 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001818 p++;
1819 }
1820 break;
1821 }
1822 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1823 {
1824 p=GetAuthenticPixelQueue(image);
1825 if (p == (const PixelPacket *) NULL)
1826 break;
cristybb503372010-05-27 20:51:26 +00001827 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001828 {
cristy46f08202010-01-10 04:04:21 +00001829 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1830 quantum_info->scale+quantum_info->minimum);
1831 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1832 quantum_info->scale+quantum_info->minimum);
1833 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1834 quantum_info->scale+quantum_info->minimum);
1835 *q++=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
cristy3ed852e2009-09-05 21:47:34 +00001836 quantum_info->scale+quantum_info->minimum);
1837 p++;
1838 }
1839 break;
1840 }
1841 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1842 {
1843 p=GetAuthenticPixelQueue(image);
1844 if (p == (const PixelPacket *) NULL)
1845 break;
cristybb503372010-05-27 20:51:26 +00001846 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001847 {
cristy46f08202010-01-10 04:04:21 +00001848 *q++=(float) ((QuantumScale*GetRedPixelComponent(p))*
1849 quantum_info->scale+quantum_info->minimum);
1850 *q++=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1851 quantum_info->scale+quantum_info->minimum);
1852 *q++=(float) ((QuantumScale*GetBluePixelComponent(p))*
1853 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001854 *q++=0.0;
1855 p++;
1856 }
1857 break;
1858 }
1859 p=GetAuthenticPixelQueue(image);
1860 if (p == (const PixelPacket *) NULL)
1861 break;
1862 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00001863 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001864 {
cristybb503372010-05-27 20:51:26 +00001865 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001866 {
1867 *q=0;
1868 switch (quantum_map[i])
1869 {
1870 case RedQuantum:
1871 case CyanQuantum:
1872 {
cristy46f08202010-01-10 04:04:21 +00001873 *q=(float) ((QuantumScale*GetRedPixelComponent(p))*
1874 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001875 break;
1876 }
1877 case GreenQuantum:
1878 case MagentaQuantum:
1879 {
cristy46f08202010-01-10 04:04:21 +00001880 *q=(float) ((QuantumScale*GetGreenPixelComponent(p))*
1881 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001882 break;
1883 }
1884 case BlueQuantum:
1885 case YellowQuantum:
1886 {
cristy46f08202010-01-10 04:04:21 +00001887 *q=(float) ((QuantumScale*GetBluePixelComponent(p))*
1888 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001889 break;
1890 }
1891 case AlphaQuantum:
1892 {
cristy46f08202010-01-10 04:04:21 +00001893 *q=(float) ((QuantumScale*GetAlphaPixelComponent(p))*
1894 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001895 break;
1896 }
1897 case OpacityQuantum:
1898 {
cristy46f08202010-01-10 04:04:21 +00001899 *q=(float) ((QuantumScale*GetOpacityPixelComponent(p))*
1900 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001901 break;
1902 }
1903 case BlackQuantum:
1904 {
1905 if (image->colorspace == CMYKColorspace)
1906 *q=(float) ((QuantumScale*indexes[x])*quantum_info->scale+
1907 quantum_info->minimum);
1908 break;
1909 }
1910 case IndexQuantum:
1911 {
1912 *q=(float) ((QuantumScale*PixelIntensityToQuantum(p))*
1913 quantum_info->scale+quantum_info->minimum);
1914 break;
1915 }
1916 default:
1917 *q=0;
1918 }
1919 q++;
1920 }
1921 p++;
1922 }
1923 break;
1924 }
1925 case IntegerPixel:
1926 {
1927 register unsigned int
1928 *q;
1929
1930 q=(unsigned int *) stream_info->pixels;
1931 if (LocaleCompare(stream_info->map,"BGR") == 0)
1932 {
1933 p=GetAuthenticPixelQueue(image);
1934 if (p == (const PixelPacket *) NULL)
1935 break;
cristybb503372010-05-27 20:51:26 +00001936 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001937 {
cristyce70c172010-01-07 17:15:30 +00001938 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1939 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1940 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001941 p++;
1942 }
1943 break;
1944 }
1945 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1946 {
1947 p=GetAuthenticPixelQueue(image);
1948 if (p == (const PixelPacket *) NULL)
1949 break;
cristybb503372010-05-27 20:51:26 +00001950 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001951 {
cristyce70c172010-01-07 17:15:30 +00001952 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1953 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1954 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001955 *q++=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00001956 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001957 p++;
1958 }
1959 break;
1960 }
1961 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1962 {
1963 p=GetAuthenticPixelQueue(image);
1964 if (p == (const PixelPacket *) NULL)
1965 break;
cristybb503372010-05-27 20:51:26 +00001966 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001967 {
cristyce70c172010-01-07 17:15:30 +00001968 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
1969 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1970 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001971 *q++=0U;
1972 p++;
1973 }
1974 break;
1975 }
1976 if (LocaleCompare(stream_info->map,"I") == 0)
1977 {
1978 p=GetAuthenticPixelQueue(image);
1979 if (p == (const PixelPacket *) NULL)
1980 break;
cristybb503372010-05-27 20:51:26 +00001981 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001982 {
1983 *q++=(unsigned int) ScaleQuantumToLong(
1984 PixelIntensityToQuantum(p));
1985 p++;
1986 }
1987 break;
1988 }
1989 if (LocaleCompare(stream_info->map,"RGB") == 0)
1990 {
1991 p=GetAuthenticPixelQueue(image);
1992 if (p == (const PixelPacket *) NULL)
1993 break;
cristybb503372010-05-27 20:51:26 +00001994 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001995 {
cristyce70c172010-01-07 17:15:30 +00001996 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
1997 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
1998 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001999 p++;
2000 }
2001 break;
2002 }
2003 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2004 {
2005 p=GetAuthenticPixelQueue(image);
2006 if (p == (const PixelPacket *) NULL)
2007 break;
cristybb503372010-05-27 20:51:26 +00002008 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002009 {
cristyce70c172010-01-07 17:15:30 +00002010 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2011 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2012 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002013 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy46f08202010-01-10 04:04:21 +00002014 (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002015 p++;
2016 }
2017 break;
2018 }
2019 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2020 {
2021 p=GetAuthenticPixelQueue(image);
2022 if (p == (const PixelPacket *) NULL)
2023 break;
cristybb503372010-05-27 20:51:26 +00002024 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002025 {
cristyce70c172010-01-07 17:15:30 +00002026 *q++=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
2027 *q++=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
2028 *q++=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002029 *q++=0U;
2030 p++;
2031 }
2032 break;
2033 }
2034 p=GetAuthenticPixelQueue(image);
2035 if (p == (const PixelPacket *) NULL)
2036 break;
2037 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002038 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002039 {
cristybb503372010-05-27 20:51:26 +00002040 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002041 {
2042 *q=0;
2043 switch (quantum_map[i])
2044 {
2045 case RedQuantum:
2046 case CyanQuantum:
2047 {
cristyce70c172010-01-07 17:15:30 +00002048 *q=(unsigned int) ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002049 break;
2050 }
2051 case GreenQuantum:
2052 case MagentaQuantum:
2053 {
cristyce70c172010-01-07 17:15:30 +00002054 *q=(unsigned int) ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002055 break;
2056 }
2057 case BlueQuantum:
2058 case YellowQuantum:
2059 {
cristyce70c172010-01-07 17:15:30 +00002060 *q=(unsigned int) ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002061 break;
2062 }
2063 case AlphaQuantum:
2064 {
2065 *q=(unsigned int) ScaleQuantumToLong((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00002066 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002067 break;
2068 }
2069 case OpacityQuantum:
2070 {
cristyce70c172010-01-07 17:15:30 +00002071 *q=(unsigned int) ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002072 break;
2073 }
2074 case BlackQuantum:
2075 {
2076 if (image->colorspace == CMYKColorspace)
2077 *q=(unsigned int) ScaleQuantumToLong(indexes[x]);
2078 break;
2079 }
2080 case IndexQuantum:
2081 {
2082 *q=(unsigned int)
2083 ScaleQuantumToLong(PixelIntensityToQuantum(p));
2084 break;
2085 }
2086 default:
2087 *q=0;
2088 }
2089 q++;
2090 }
2091 p++;
2092 }
2093 break;
2094 }
2095 case LongPixel:
2096 {
cristybb503372010-05-27 20:51:26 +00002097 register size_t
cristy3ed852e2009-09-05 21:47:34 +00002098 *q;
2099
cristybb503372010-05-27 20:51:26 +00002100 q=(size_t *) stream_info->pixels;
cristy3ed852e2009-09-05 21:47:34 +00002101 if (LocaleCompare(stream_info->map,"BGR") == 0)
2102 {
2103 p=GetAuthenticPixelQueue(image);
2104 if (p == (const PixelPacket *) NULL)
2105 break;
cristybb503372010-05-27 20:51:26 +00002106 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002107 {
cristyce70c172010-01-07 17:15:30 +00002108 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2109 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2110 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002111 p++;
2112 }
2113 break;
2114 }
2115 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2116 {
2117 p=GetAuthenticPixelQueue(image);
2118 if (p == (const PixelPacket *) NULL)
2119 break;
cristybb503372010-05-27 20:51:26 +00002120 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002121 {
cristyce70c172010-01-07 17:15:30 +00002122 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2123 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2124 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002125 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002126 p++;
2127 }
2128 break;
2129 }
2130 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2131 {
2132 p=GetAuthenticPixelQueue(image);
2133 if (p == (const PixelPacket *) NULL)
2134 break;
cristybb503372010-05-27 20:51:26 +00002135 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002136 {
cristyce70c172010-01-07 17:15:30 +00002137 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
2138 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2139 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002140 *q++=0;
2141 p++;
2142 }
2143 break;
2144 }
2145 if (LocaleCompare(stream_info->map,"I") == 0)
2146 {
2147 p=GetAuthenticPixelQueue(image);
2148 if (p == (const PixelPacket *) NULL)
2149 break;
cristybb503372010-05-27 20:51:26 +00002150 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002151 {
2152 *q++=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2153 p++;
2154 }
2155 break;
2156 }
2157 if (LocaleCompare(stream_info->map,"RGB") == 0)
2158 {
2159 p=GetAuthenticPixelQueue(image);
2160 if (p == (const PixelPacket *) NULL)
2161 break;
cristybb503372010-05-27 20:51:26 +00002162 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002163 {
cristyce70c172010-01-07 17:15:30 +00002164 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2165 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2166 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002167 p++;
2168 }
2169 break;
2170 }
2171 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2172 {
2173 p=GetAuthenticPixelQueue(image);
2174 if (p == (const PixelPacket *) NULL)
2175 break;
cristybb503372010-05-27 20:51:26 +00002176 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002177 {
cristyce70c172010-01-07 17:15:30 +00002178 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2179 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2180 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002181 *q++=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002182 p++;
2183 }
2184 break;
2185 }
2186 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2187 {
2188 p=GetAuthenticPixelQueue(image);
2189 if (p == (const PixelPacket *) NULL)
2190 break;
cristybb503372010-05-27 20:51:26 +00002191 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002192 {
cristyce70c172010-01-07 17:15:30 +00002193 *q++=ScaleQuantumToLong(GetRedPixelComponent(p));
2194 *q++=ScaleQuantumToLong(GetGreenPixelComponent(p));
2195 *q++=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002196 *q++=0;
2197 p++;
2198 }
2199 break;
2200 }
2201 p=GetAuthenticPixelQueue(image);
2202 if (p == (const PixelPacket *) NULL)
2203 break;
2204 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002205 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002206 {
cristybb503372010-05-27 20:51:26 +00002207 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002208 {
2209 *q=0;
2210 switch (quantum_map[i])
2211 {
2212 case RedQuantum:
2213 case CyanQuantum:
2214 {
cristyce70c172010-01-07 17:15:30 +00002215 *q=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002216 break;
2217 }
2218 case GreenQuantum:
2219 case MagentaQuantum:
2220 {
cristyce70c172010-01-07 17:15:30 +00002221 *q=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002222 break;
2223 }
2224 case BlueQuantum:
2225 case YellowQuantum:
2226 {
cristyce70c172010-01-07 17:15:30 +00002227 *q=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002228 break;
2229 }
2230 case AlphaQuantum:
2231 {
cristy46f08202010-01-10 04:04:21 +00002232 *q=ScaleQuantumToLong((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002233 break;
2234 }
2235 case OpacityQuantum:
2236 {
cristyce70c172010-01-07 17:15:30 +00002237 *q=ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002238 break;
2239 }
2240 case BlackQuantum:
2241 {
2242 if (image->colorspace == CMYKColorspace)
2243 *q=ScaleQuantumToLong(indexes[x]);
2244 break;
2245 }
2246 case IndexQuantum:
2247 {
2248 *q=ScaleQuantumToLong(PixelIntensityToQuantum(p));
2249 break;
2250 }
2251 default:
2252 break;
2253 }
2254 q++;
2255 }
2256 p++;
2257 }
2258 break;
2259 }
2260 case QuantumPixel:
2261 {
2262 register Quantum
2263 *q;
2264
2265 q=(Quantum *) stream_info->pixels;
2266 if (LocaleCompare(stream_info->map,"BGR") == 0)
2267 {
2268 p=GetAuthenticPixelQueue(image);
2269 if (p == (const PixelPacket *) NULL)
2270 break;
cristybb503372010-05-27 20:51:26 +00002271 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002272 {
cristyce70c172010-01-07 17:15:30 +00002273 *q++=GetBluePixelComponent(p);
2274 *q++=GetGreenPixelComponent(p);
2275 *q++=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002276 p++;
2277 }
2278 break;
2279 }
2280 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2281 {
2282 p=GetAuthenticPixelQueue(image);
2283 if (p == (const PixelPacket *) NULL)
2284 break;
cristybb503372010-05-27 20:51:26 +00002285 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002286 {
cristyce70c172010-01-07 17:15:30 +00002287 *q++=GetBluePixelComponent(p);
2288 *q++=GetGreenPixelComponent(p);
2289 *q++=GetRedPixelComponent(p);
cristy46f08202010-01-10 04:04:21 +00002290 *q++=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002291 p++;
2292 }
2293 break;
2294 }
2295 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2296 {
2297 p=GetAuthenticPixelQueue(image);
2298 if (p == (const PixelPacket *) NULL)
2299 break;
cristybb503372010-05-27 20:51:26 +00002300 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002301 {
cristyce70c172010-01-07 17:15:30 +00002302 *q++=GetBluePixelComponent(p);
2303 *q++=GetGreenPixelComponent(p);
2304 *q++=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002305 *q++=0;
2306 p++;
2307 }
2308 break;
2309 }
2310 if (LocaleCompare(stream_info->map,"I") == 0)
2311 {
2312 p=GetAuthenticPixelQueue(image);
2313 if (p == (const PixelPacket *) NULL)
2314 break;
cristybb503372010-05-27 20:51:26 +00002315 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002316 {
2317 *q++=PixelIntensityToQuantum(p);
2318 p++;
2319 }
2320 break;
2321 }
2322 if (LocaleCompare(stream_info->map,"RGB") == 0)
2323 {
2324 p=GetAuthenticPixelQueue(image);
2325 if (p == (const PixelPacket *) NULL)
2326 break;
cristybb503372010-05-27 20:51:26 +00002327 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002328 {
cristyce70c172010-01-07 17:15:30 +00002329 *q++=GetRedPixelComponent(p);
2330 *q++=GetGreenPixelComponent(p);
2331 *q++=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002332 p++;
2333 }
2334 break;
2335 }
2336 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2337 {
2338 p=GetAuthenticPixelQueue(image);
2339 if (p == (const PixelPacket *) NULL)
2340 break;
cristybb503372010-05-27 20:51:26 +00002341 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002342 {
cristyce70c172010-01-07 17:15:30 +00002343 *q++=GetRedPixelComponent(p);
2344 *q++=GetGreenPixelComponent(p);
2345 *q++=GetBluePixelComponent(p);
cristy46f08202010-01-10 04:04:21 +00002346 *q++=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002347 p++;
2348 }
2349 break;
2350 }
2351 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2352 {
2353 p=GetAuthenticPixelQueue(image);
2354 if (p == (const PixelPacket *) NULL)
2355 break;
cristybb503372010-05-27 20:51:26 +00002356 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002357 {
cristyce70c172010-01-07 17:15:30 +00002358 *q++=GetRedPixelComponent(p);
2359 *q++=GetGreenPixelComponent(p);
2360 *q++=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002361 *q++=0U;
2362 p++;
2363 }
2364 break;
2365 }
2366 p=GetAuthenticPixelQueue(image);
2367 if (p == (const PixelPacket *) NULL)
2368 break;
2369 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002370 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002371 {
cristybb503372010-05-27 20:51:26 +00002372 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002373 {
2374 *q=(Quantum) 0;
2375 switch (quantum_map[i])
2376 {
2377 case RedQuantum:
2378 case CyanQuantum:
2379 {
cristyce70c172010-01-07 17:15:30 +00002380 *q=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002381 break;
2382 }
2383 case GreenQuantum:
2384 case MagentaQuantum:
2385 {
cristyce70c172010-01-07 17:15:30 +00002386 *q=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002387 break;
2388 }
2389 case BlueQuantum:
2390 case YellowQuantum:
2391 {
cristyce70c172010-01-07 17:15:30 +00002392 *q=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002393 break;
2394 }
2395 case AlphaQuantum:
2396 {
cristy46f08202010-01-10 04:04:21 +00002397 *q=(Quantum) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002398 break;
2399 }
2400 case OpacityQuantum:
2401 {
cristyce70c172010-01-07 17:15:30 +00002402 *q=GetOpacityPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002403 break;
2404 }
2405 case BlackQuantum:
2406 {
2407 if (image->colorspace == CMYKColorspace)
2408 *q=indexes[x];
2409 break;
2410 }
2411 case IndexQuantum:
2412 {
2413 *q=(PixelIntensityToQuantum(p));
2414 break;
2415 }
2416 default:
2417 *q=0;
2418 }
2419 q++;
2420 }
2421 p++;
2422 }
2423 break;
2424 }
2425 case ShortPixel:
2426 {
2427 register unsigned short
2428 *q;
2429
2430 q=(unsigned short *) stream_info->pixels;
2431 if (LocaleCompare(stream_info->map,"BGR") == 0)
2432 {
2433 p=GetAuthenticPixelQueue(image);
2434 if (p == (const PixelPacket *) NULL)
2435 break;
cristybb503372010-05-27 20:51:26 +00002436 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002437 {
cristyce70c172010-01-07 17:15:30 +00002438 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2439 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2440 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002441 p++;
2442 }
2443 break;
2444 }
2445 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2446 {
2447 p=GetAuthenticPixelQueue(image);
2448 if (p == (const PixelPacket *) NULL)
2449 break;
cristybb503372010-05-27 20:51:26 +00002450 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002451 {
cristyce70c172010-01-07 17:15:30 +00002452 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2453 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2454 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002455 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002456 p++;
2457 }
2458 break;
2459 }
2460 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2461 {
2462 p=GetAuthenticPixelQueue(image);
2463 if (p == (const PixelPacket *) NULL)
2464 break;
cristybb503372010-05-27 20:51:26 +00002465 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002466 {
cristyce70c172010-01-07 17:15:30 +00002467 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
2468 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2469 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002470 *q++=0;
2471 p++;
2472 }
2473 break;
2474 }
2475 if (LocaleCompare(stream_info->map,"I") == 0)
2476 {
2477 p=GetAuthenticPixelQueue(image);
2478 if (p == (const PixelPacket *) NULL)
2479 break;
cristybb503372010-05-27 20:51:26 +00002480 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002481 {
2482 *q++=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2483 p++;
2484 }
2485 break;
2486 }
2487 if (LocaleCompare(stream_info->map,"RGB") == 0)
2488 {
2489 p=GetAuthenticPixelQueue(image);
2490 if (p == (const PixelPacket *) NULL)
2491 break;
cristybb503372010-05-27 20:51:26 +00002492 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002493 {
cristyce70c172010-01-07 17:15:30 +00002494 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2495 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2496 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002497 p++;
2498 }
2499 break;
2500 }
2501 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2502 {
2503 p=GetAuthenticPixelQueue(image);
2504 if (p == (const PixelPacket *) NULL)
2505 break;
cristybb503372010-05-27 20:51:26 +00002506 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002507 {
cristyce70c172010-01-07 17:15:30 +00002508 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2509 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2510 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy46f08202010-01-10 04:04:21 +00002511 *q++=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002512 p++;
2513 }
2514 break;
2515 }
2516 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2517 {
2518 p=GetAuthenticPixelQueue(image);
2519 if (p == (const PixelPacket *) NULL)
2520 break;
cristybb503372010-05-27 20:51:26 +00002521 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002522 {
cristyce70c172010-01-07 17:15:30 +00002523 *q++=ScaleQuantumToShort(GetRedPixelComponent(p));
2524 *q++=ScaleQuantumToShort(GetGreenPixelComponent(p));
2525 *q++=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002526 *q++=0;
2527 p++;
2528 }
2529 break;
2530 }
2531 p=GetAuthenticPixelQueue(image);
2532 if (p == (const PixelPacket *) NULL)
2533 break;
2534 indexes=GetAuthenticIndexQueue(image);
cristybb503372010-05-27 20:51:26 +00002535 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002536 {
cristybb503372010-05-27 20:51:26 +00002537 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002538 {
2539 *q=0;
2540 switch (quantum_map[i])
2541 {
2542 case RedQuantum:
2543 case CyanQuantum:
2544 {
cristyce70c172010-01-07 17:15:30 +00002545 *q=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002546 break;
2547 }
2548 case GreenQuantum:
2549 case MagentaQuantum:
2550 {
cristyce70c172010-01-07 17:15:30 +00002551 *q=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002552 break;
2553 }
2554 case BlueQuantum:
2555 case YellowQuantum:
2556 {
cristyce70c172010-01-07 17:15:30 +00002557 *q=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002558 break;
2559 }
2560 case AlphaQuantum:
2561 {
cristy46f08202010-01-10 04:04:21 +00002562 *q=ScaleQuantumToShort((Quantum) (GetAlphaPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002563 break;
2564 }
2565 case OpacityQuantum:
2566 {
cristyce70c172010-01-07 17:15:30 +00002567 *q=ScaleQuantumToShort(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002568 break;
2569 }
2570 case BlackQuantum:
2571 {
2572 if (image->colorspace == CMYKColorspace)
2573 *q=ScaleQuantumToShort(indexes[x]);
2574 break;
2575 }
2576 case IndexQuantum:
2577 {
2578 *q=ScaleQuantumToShort(PixelIntensityToQuantum(p));
2579 break;
2580 }
2581 default:
2582 break;
2583 }
2584 q++;
2585 }
2586 p++;
2587 }
2588 break;
2589 }
2590 default:
2591 {
2592 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2593 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2594 "UnrecognizedPixelMap","`%s'",stream_info->map);
2595 break;
2596 }
2597 }
2598 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2599 return(MagickTrue);
2600}
2601
2602/*
2603%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2604% %
2605% %
2606% %
2607+ 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 %
2608% %
2609% %
2610% %
2611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2612%
2613% SyncAuthenticPixelsStream() calls the user supplied callback method with
2614% the latest stream of pixels.
2615%
2616% The format of the SyncAuthenticPixelsStream method is:
2617%
2618% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2619% ExceptionInfo *exception)
2620%
2621% A description of each parameter follows:
2622%
2623% o image: the image.
2624%
2625% o exception: return any errors or warnings in this structure.
2626%
2627*/
2628static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2629 ExceptionInfo *exception)
2630{
2631 CacheInfo
2632 *cache_info;
2633
2634 size_t
2635 length;
2636
2637 StreamHandler
2638 stream_handler;
2639
2640 assert(image != (Image *) NULL);
2641 assert(image->signature == MagickSignature);
2642 if (image->debug != MagickFalse)
2643 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2644 cache_info=(CacheInfo *) image->cache;
2645 assert(cache_info->signature == MagickSignature);
2646 stream_handler=GetBlobStreamHandler(image);
2647 if (stream_handler == (StreamHandler) NULL)
2648 {
2649 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2650 "NoStreamHandlerIsDefined","`%s'",image->filename);
2651 return(MagickFalse);
2652 }
2653 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2654 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2655}
2656
2657/*
2658%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659% %
2660% %
2661% %
2662% W r i t e S t r e a m %
2663% %
2664% %
2665% %
2666%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2667%
2668% WriteStream() makes the image pixels available to a user supplied callback
2669% method immediately upon writing pixel data with the WriteImage() method.
2670%
2671% The format of the WriteStream() method is:
2672%
2673% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2674% StreamHandler stream)
2675%
2676% A description of each parameter follows:
2677%
2678% o image_info: the image info.
2679%
2680% o stream: A callback method.
2681%
2682*/
2683MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2684 Image *image,StreamHandler stream)
2685{
2686 ImageInfo
2687 *write_info;
2688
2689 MagickBooleanType
2690 status;
2691
2692 assert(image_info != (ImageInfo *) NULL);
2693 assert(image_info->signature == MagickSignature);
2694 if (image_info->debug != MagickFalse)
2695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2696 image_info->filename);
2697 assert(image != (Image *) NULL);
2698 assert(image->signature == MagickSignature);
2699 write_info=CloneImageInfo(image_info);
2700 write_info->stream=stream;
2701 status=WriteImage(write_info,image);
2702 write_info=DestroyImageInfo(write_info);
2703 return(status);
2704}