blob: ee3a483f147bdbcd198b0fe3ce0f522d9acc0c5d [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% SSSSS TTTTT RRRR EEEEE AAA M M %
7% SS T R R E A A MM MM %
8% SSS T RRRR EEE AAAAA M M M %
9% SS T R R E A A M M %
10% SSSSS T R R EEEEE A A M M %
11% %
12% %
13% MagickCore Pixel Stream Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/cache-private.h"
48#include "MagickCore/color-private.h"
49#include "MagickCore/composite-private.h"
50#include "MagickCore/constitute.h"
51#include "MagickCore/exception.h"
52#include "MagickCore/exception-private.h"
53#include "MagickCore/geometry.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/pixel.h"
56#include "MagickCore/pixel-accessor.h"
57#include "MagickCore/quantum.h"
58#include "MagickCore/quantum-private.h"
59#include "MagickCore/semaphore.h"
60#include "MagickCore/stream.h"
61#include "MagickCore/stream-private.h"
62#include "MagickCore/string_.h"
cristy3ed852e2009-09-05 21:47:34 +000063
64/*
65 Typedef declaractions.
66*/
67struct _StreamInfo
68{
69 const ImageInfo
70 *image_info;
71
72 const Image
73 *image;
74
75 Image
76 *stream;
77
78 QuantumInfo
79 *quantum_info;
80
81 char
82 *map;
83
84 StorageType
85 storage_type;
86
87 unsigned char
88 *pixels;
89
90 RectangleInfo
91 extract_info;
92
cristybb503372010-05-27 20:51:26 +000093 ssize_t
cristy3ed852e2009-09-05 21:47:34 +000094 y;
95
96 ExceptionInfo
97 *exception;
98
99 const void
100 *client_data;
101
cristybb503372010-05-27 20:51:26 +0000102 size_t
cristy3ed852e2009-09-05 21:47:34 +0000103 signature;
104};
105
106/*
107 Declare pixel cache interfaces.
108*/
109#if defined(__cplusplus) || defined(c_plusplus)
110extern "C" {
111#endif
112
cristy4c08aed2011-07-01 19:47:50 +0000113static const Quantum
cristybb503372010-05-27 20:51:26 +0000114 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
115 const ssize_t,const size_t,const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000116
117static MagickBooleanType
118 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
119 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
120
cristy4c08aed2011-07-01 19:47:50 +0000121static Quantum
cristybb503372010-05-27 20:51:26 +0000122 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
123 const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000124
125#if defined(__cplusplus) || defined(c_plusplus)
126}
127#endif
128
129/*
130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131% %
132% %
133% %
134+ A c q u i r e S t r e a m I n f o %
135% %
136% %
137% %
138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139%
140% AcquireStreamInfo() allocates the StreamInfo structure.
141%
142% The format of the AcquireStreamInfo method is:
143%
144% StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
145%
146% A description of each parameter follows:
147%
148% o image_info: the image info.
149%
150*/
151MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
152{
153 StreamInfo
154 *stream_info;
155
cristy73bd4a52010-10-05 11:24:23 +0000156 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
cristy3ed852e2009-09-05 21:47:34 +0000157 if (stream_info == (StreamInfo *) NULL)
158 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
159 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
160 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
161 sizeof(*stream_info->pixels));
162 if (stream_info->pixels == (unsigned char *) NULL)
163 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164 stream_info->map=ConstantString("RGB");
165 stream_info->storage_type=CharPixel;
166 stream_info->stream=AcquireImage(image_info);
167 stream_info->signature=MagickSignature;
168 return(stream_info);
169}
170
171/*
172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173% %
174% %
175% %
176+ D e s t r o y P i x e l S t r e a m %
177% %
178% %
179% %
180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181%
182% DestroyPixelStream() deallocates memory associated with the pixel stream.
183%
184% The format of the DestroyPixelStream() method is:
185%
186% void DestroyPixelStream(Image *image)
187%
188% A description of each parameter follows:
189%
190% o image: the image.
191%
192*/
193
194static inline void RelinquishStreamPixels(CacheInfo *cache_info)
195{
196 assert(cache_info != (CacheInfo *) NULL);
197 if (cache_info->mapped == MagickFalse)
198 (void) RelinquishMagickMemory(cache_info->pixels);
199 else
200 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000201 cache_info->pixels=(Quantum *) NULL;
202 cache_info->metacontent=(void *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000203 cache_info->length=0;
204 cache_info->mapped=MagickFalse;
205}
206
207static void DestroyPixelStream(Image *image)
208{
209 CacheInfo
210 *cache_info;
211
212 MagickBooleanType
213 destroy;
214
215 assert(image != (Image *) NULL);
216 assert(image->signature == MagickSignature);
217 if (image->debug != MagickFalse)
218 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
219 cache_info=(CacheInfo *) image->cache;
220 assert(cache_info->signature == MagickSignature);
221 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000222 LockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000223 cache_info->reference_count--;
224 if (cache_info->reference_count == 0)
225 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +0000226 UnlockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000227 if (destroy == MagickFalse)
228 return;
229 RelinquishStreamPixels(cache_info);
230 if (cache_info->nexus_info != (NexusInfo **) NULL)
231 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
232 cache_info->number_threads);
233 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
234 DestroySemaphoreInfo(&cache_info->disk_semaphore);
235 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
236 DestroySemaphoreInfo(&cache_info->semaphore);
237 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
245+ D e s t r o y S t r e a m I n f o %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
251% DestroyStreamInfo() destroys memory associated with the StreamInfo
252% structure.
253%
254% The format of the DestroyStreamInfo method is:
255%
256% StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
257%
258% A description of each parameter follows:
259%
260% o stream_info: the stream info.
261%
262*/
263MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
264{
265 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
266 assert(stream_info != (StreamInfo *) NULL);
267 assert(stream_info->signature == MagickSignature);
268 if (stream_info->map != (char *) NULL)
269 stream_info->map=DestroyString(stream_info->map);
270 if (stream_info->pixels != (unsigned char *) NULL)
271 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
272 stream_info->pixels);
273 if (stream_info->stream != (Image *) NULL)
274 {
275 (void) CloseBlob(stream_info->stream);
276 stream_info->stream=DestroyImage(stream_info->stream);
277 }
278 if (stream_info->quantum_info != (QuantumInfo *) NULL)
279 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
280 stream_info->signature=(~MagickSignature);
281 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
282 return(stream_info);
283}
284
285/*
286%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287% %
288% %
289% %
cristy4c08aed2011-07-01 19:47:50 +0000290+ G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m %
cristy3ed852e2009-09-05 21:47:34 +0000291% %
292% %
293% %
294%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295%
cristy4c08aed2011-07-01 19:47:50 +0000296% GetAuthenticMetacontentFromStream() returns the metacontent corresponding
297% with the last call to QueueAuthenticPixelsStream() or
298% GetAuthenticPixelsStream().
cristy3ed852e2009-09-05 21:47:34 +0000299%
cristy4c08aed2011-07-01 19:47:50 +0000300% The format of the GetAuthenticMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000301%
cristy4c08aed2011-07-01 19:47:50 +0000302% void *GetAuthenticMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000303%
304% A description of each parameter follows:
305%
306% o image: the image.
307%
308*/
cristy4c08aed2011-07-01 19:47:50 +0000309static void *GetAuthenticMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000310{
311 CacheInfo
312 *cache_info;
313
314 assert(image != (Image *) NULL);
315 assert(image->signature == MagickSignature);
316 if (image->debug != MagickFalse)
317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
318 cache_info=(CacheInfo *) image->cache;
319 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000320 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000321}
322
323/*
324%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325% %
326% %
327% %
328+ G e t A u t h e n t i c P i x e l S t r e a m %
329% %
330% %
331% %
332%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333%
334% GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
335% cache as defined by the geometry parameters. A pointer to the pixels is
336% returned if the pixels are transferred, otherwise a NULL is returned. For
337% streams this method is a no-op.
338%
339% The format of the GetAuthenticPixelsStream() method is:
340%
cristy4c08aed2011-07-01 19:47:50 +0000341% Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000342% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000343% ExceptionInfo *exception)
344%
345% A description of each parameter follows:
346%
347% o image: the image.
348%
349% o x,y,columns,rows: These values define the perimeter of a region of
350% pixels.
351%
352% o exception: return any errors or warnings in this structure.
353%
354*/
cristy4c08aed2011-07-01 19:47:50 +0000355static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000356 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000357 ExceptionInfo *exception)
358{
cristy4c08aed2011-07-01 19:47:50 +0000359 Quantum
cristy3ed852e2009-09-05 21:47:34 +0000360 *pixels;
361
362 assert(image != (Image *) NULL);
363 assert(image->signature == MagickSignature);
364 if (image->debug != MagickFalse)
365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
366 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
367 return(pixels);
368}
369
370/*
371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372% %
373% %
374% %
375+ 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 %
376% %
377% %
378% %
379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380%
381% GetAuthenticPixelsFromStream() returns the pixels associated with the last
382% call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
383%
384% The format of the GetAuthenticPixelsFromStream() method is:
385%
cristy4c08aed2011-07-01 19:47:50 +0000386% Quantum *GetAuthenticPixelsFromStream(const Image image)
cristy3ed852e2009-09-05 21:47:34 +0000387%
388% A description of each parameter follows:
389%
390% o image: the image.
391%
392*/
cristy4c08aed2011-07-01 19:47:50 +0000393static Quantum *GetAuthenticPixelsFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000394{
395 CacheInfo
396 *cache_info;
397
398 assert(image != (Image *) NULL);
399 assert(image->signature == MagickSignature);
400 if (image->debug != MagickFalse)
401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
402 cache_info=(CacheInfo *) image->cache;
403 assert(cache_info->signature == MagickSignature);
404 return(cache_info->pixels);
405}
406
407/*
408%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409% %
410% %
411% %
412+ 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 %
413% %
414% %
415% %
416%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417%
418% GetOneAuthenticPixelFromStream() returns a single pixel at the specified
419% (x,y) location. The image background color is returned if an error occurs.
420%
421% The format of the GetOneAuthenticPixelFromStream() method is:
422%
423% MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
cristycfae90a2010-10-04 14:43:33 +0000424% const ssize_t x,const ssize_t y,PixelPacket *pixel,
425% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000426%
427% A description of each parameter follows:
428%
429% o image: the image.
430%
431% o pixel: return a pixel at the specified (x,y) location.
432%
433% o x,y: These values define the location of the pixel to return.
434%
435% o exception: return any errors or warnings in this structure.
436%
437*/
438static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
cristybb503372010-05-27 20:51:26 +0000439 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000440{
cristy4c08aed2011-07-01 19:47:50 +0000441 register Quantum
442 *q;
cristy3ed852e2009-09-05 21:47:34 +0000443
444 assert(image != (Image *) NULL);
445 assert(image->signature == MagickSignature);
446 *pixel=image->background_color;
cristy4c08aed2011-07-01 19:47:50 +0000447 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
448 if (q != (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000449 return(MagickFalse);
cristy4c08aed2011-07-01 19:47:50 +0000450 GetPixelPacket(image,q,pixel);
cristy3ed852e2009-09-05 21:47:34 +0000451 return(MagickTrue);
452}
453
454/*
455%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456% %
457% %
458% %
459+ 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 %
460% %
461% %
462% %
463%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464%
465% GetOneVirtualPixelFromStream() returns a single pixel at the specified
466% (x.y) location. The image background color is returned if an error occurs.
467%
468% The format of the GetOneVirtualPixelFromStream() method is:
469%
470% MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
cristybb503372010-05-27 20:51:26 +0000471% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
472% const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000473%
474% A description of each parameter follows:
475%
476% o image: the image.
477%
478% o virtual_pixel_method: the virtual pixel method.
479%
480% o x,y: These values define the location of the pixel to return.
481%
482% o pixel: return a pixel at the specified (x,y) location.
483%
484% o exception: return any errors or warnings in this structure.
485%
486*/
487static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000488 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +0000489 PixelPacket *pixel,ExceptionInfo *exception)
490{
cristy4c08aed2011-07-01 19:47:50 +0000491 const Quantum
492 *q;
cristy3ed852e2009-09-05 21:47:34 +0000493
494 assert(image != (Image *) NULL);
495 assert(image->signature == MagickSignature);
496 *pixel=image->background_color;
cristy4c08aed2011-07-01 19:47:50 +0000497 q=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
498 if (q != (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000499 return(MagickFalse);
cristy4c08aed2011-07-01 19:47:50 +0000500 GetPixelPacket(image,q,pixel);
cristy3ed852e2009-09-05 21:47:34 +0000501 return(MagickTrue);
502}
503
504/*
505%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506% %
507% %
508% %
509+ G e t S t r e a m I n f o C l i e n t D a t a %
510% %
511% %
512% %
513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
514%
515% GetStreamInfoClientData() gets the stream info client data.
516%
517% The format of the SetStreamInfoClientData method is:
518%
519% const void *GetStreamInfoClientData(StreamInfo *stream_info)
520%
521% A description of each parameter follows:
522%
523% o stream_info: the stream info.
524%
525*/
526MagickExport const void *GetStreamInfoClientData(StreamInfo *stream_info)
527{
528 assert(stream_info != (StreamInfo *) NULL);
529 assert(stream_info->signature == MagickSignature);
530 return(stream_info->client_data);
531}
532
533/*
534%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535% %
536% %
537% %
538+ 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 %
539% %
540% %
541% %
542%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
543%
544% GetVirtualPixelsStream() returns the pixels associated with the last
545% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
546%
547% The format of the GetVirtualPixelsStream() method is:
548%
cristy4c08aed2011-07-01 19:47:50 +0000549% const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000550%
551% A description of each parameter follows:
552%
cristy4c08aed2011-07-01 19:47:50 +0000553% o pixels: return the pixels associated corresponding with the last call to
cristy3ed852e2009-09-05 21:47:34 +0000554% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
555%
556% o image: the image.
557%
558*/
cristy4c08aed2011-07-01 19:47:50 +0000559static const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000560{
561 CacheInfo
562 *cache_info;
563
564 assert(image != (Image *) NULL);
565 assert(image->signature == MagickSignature);
566 if (image->debug != MagickFalse)
567 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
568 cache_info=(CacheInfo *) image->cache;
569 assert(cache_info->signature == MagickSignature);
570 return(cache_info->pixels);
571}
572
573/*
574%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575% %
576% %
577% %
578+ 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 %
579% %
580% %
581% %
582%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583%
cristy4c08aed2011-07-01 19:47:50 +0000584% GetVirtualMetacontentFromStream() returns the associated pixel
585% channels corresponding with the last call to QueueAuthenticPixelsStream() or
586% GetVirtualPixelStream().
cristy3ed852e2009-09-05 21:47:34 +0000587%
cristy4c08aed2011-07-01 19:47:50 +0000588% The format of the GetVirtualMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000589%
cristy4c08aed2011-07-01 19:47:50 +0000590% const void *GetVirtualMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000591%
592% A description of each parameter follows:
593%
594% o image: the image.
595%
596*/
cristy4c08aed2011-07-01 19:47:50 +0000597static const void *GetVirtualMetacontentFromStream(
598 const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000599{
600 CacheInfo
601 *cache_info;
602
603 assert(image != (Image *) NULL);
604 assert(image->signature == MagickSignature);
605 if (image->debug != MagickFalse)
606 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
607 cache_info=(CacheInfo *) image->cache;
608 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000609 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000610}
611
612/*
613%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614% %
615% %
616% %
617+ G e t V i r t u a l P i x e l S t r e a m %
618% %
619% %
620% %
621%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622%
623% GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
624% defined by the geometry parameters. A pointer to the pixels is returned if
625% the pixels are transferred, otherwise a NULL is returned. For streams this
626% method is a no-op.
627%
628% The format of the GetVirtualPixelStream() method is:
629%
cristy4c08aed2011-07-01 19:47:50 +0000630% const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000631% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
632% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000633% ExceptionInfo *exception)
634%
635% A description of each parameter follows:
636%
637% o image: the image.
638%
639% o virtual_pixel_method: the virtual pixel method.
640%
641% o x,y,columns,rows: These values define the perimeter of a region of
642% pixels.
643%
644% o exception: return any errors or warnings in this structure.
645%
646*/
647
648static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
649 ExceptionInfo *exception)
650{
651 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
652 return(MagickFalse);
653 cache_info->mapped=MagickFalse;
cristy4c08aed2011-07-01 19:47:50 +0000654 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
cristy3ed852e2009-09-05 21:47:34 +0000655 cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000656 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000657 {
658 cache_info->mapped=MagickTrue;
cristy4c08aed2011-07-01 19:47:50 +0000659 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
cristy3ed852e2009-09-05 21:47:34 +0000660 cache_info->length);
661 }
cristy4c08aed2011-07-01 19:47:50 +0000662 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000663 {
664 (void) ThrowMagickException(exception,GetMagickModule(),
665 ResourceLimitError,"MemoryAllocationFailed","`%s'",
666 cache_info->filename);
667 return(MagickFalse);
668 }
669 return(MagickTrue);
670}
671
cristy4c08aed2011-07-01 19:47:50 +0000672static const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000673 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
674 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000675 ExceptionInfo *exception)
676{
677 CacheInfo
678 *cache_info;
679
680 MagickBooleanType
681 status;
682
683 MagickSizeType
684 number_pixels;
685
686 size_t
687 length;
688
689 /*
690 Validate pixel cache geometry.
691 */
692 assert(image != (const Image *) NULL);
693 assert(image->signature == MagickSignature);
694 if (image->debug != MagickFalse)
695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy5dd71882010-08-01 20:53:13 +0000696 if ((x < 0) || (y < 0) ||
697 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
698 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
699 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000700 {
701 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
702 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000703 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000704 }
705 cache_info=(CacheInfo *) image->cache;
706 assert(cache_info->signature == MagickSignature);
707 /*
708 Pixels are stored in a temporary buffer until they are synced to the cache.
709 */
710 number_pixels=(MagickSizeType) columns*rows;
cristy4c08aed2011-07-01 19:47:50 +0000711 length=(size_t) number_pixels*cache_info->pixel_channels*sizeof(Quantum);
712 if (cache_info->metacontent_extent != 0)
713 length+=number_pixels*cache_info->metacontent_extent;
714 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000715 {
716 cache_info->length=length;
717 status=AcquireStreamPixels(cache_info,exception);
718 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000719 {
720 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000721 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000722 }
cristy3ed852e2009-09-05 21:47:34 +0000723 }
724 else
725 if (cache_info->length != length)
726 {
727 RelinquishStreamPixels(cache_info);
728 cache_info->length=length;
729 status=AcquireStreamPixels(cache_info,exception);
730 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000731 {
732 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000733 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000734 }
cristy3ed852e2009-09-05 21:47:34 +0000735 }
cristy4c08aed2011-07-01 19:47:50 +0000736 cache_info->metacontent=(void *) NULL;
737 if (cache_info->metacontent_extent != 0)
738 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
739 cache_info->pixel_channels);
cristy3ed852e2009-09-05 21:47:34 +0000740 return(cache_info->pixels);
741}
742
743/*
744%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
745% %
746% %
747% %
748+ O p e n S t r e a m %
749% %
750% %
751% %
752%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753%
754% OpenStream() opens a stream for writing by the StreamImage() method.
755%
756% The format of the OpenStream method is:
757%
758% MagickBooleanType OpenStream(const ImageInfo *image_info,
759% StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
760%
761% A description of each parameter follows:
762%
763% o image_info: the image info.
764%
765% o stream_info: the stream info.
766%
767% o filename: the stream filename.
768%
769% o exception: return any errors or warnings in this structure.
770%
771*/
772MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
773 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
774{
775 MagickBooleanType
776 status;
777
778 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
779 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
780 return(status);
781}
782
783/*
784%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
785% %
786% %
787% %
788+ 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 %
789% %
790% %
791% %
792%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793%
794% QueueAuthenticPixelsStream() allocates an area to store image pixels as
795% defined by the region rectangle and returns a pointer to the area. This
796% area is subsequently transferred from the pixel cache with method
797% SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
798% pixels are transferred, otherwise a NULL is returned.
799%
800% The format of the QueueAuthenticPixelsStream() method is:
801%
cristy4c08aed2011-07-01 19:47:50 +0000802% Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000803% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000804% ExceptionInfo *exception)
805%
806% A description of each parameter follows:
807%
808% o image: the image.
809%
810% o x,y,columns,rows: These values define the perimeter of a region of
811% pixels.
812%
813*/
cristy4c08aed2011-07-01 19:47:50 +0000814static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000815 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000816 ExceptionInfo *exception)
817{
818 CacheInfo
819 *cache_info;
820
821 MagickSizeType
822 number_pixels;
823
824 size_t
825 length;
826
827 StreamHandler
828 stream_handler;
829
830 /*
831 Validate pixel cache geometry.
832 */
833 assert(image != (Image *) NULL);
cristycfae90a2010-10-04 14:43:33 +0000834 if ((x < 0) || (y < 0) ||
835 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
836 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
837 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000838 {
839 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
840 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000841 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000842 }
843 stream_handler=GetBlobStreamHandler(image);
844 if (stream_handler == (StreamHandler) NULL)
845 {
846 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
847 "NoStreamHandlerIsDefined","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000848 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000849 }
850 cache_info=(CacheInfo *) image->cache;
851 assert(cache_info->signature == MagickSignature);
852 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
853 (image->colorspace != GetPixelCacheColorspace(image->cache)))
854 {
855 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
856 (void) stream_handler(image,(const void *) NULL,(size_t)
857 cache_info->columns);
858 cache_info->storage_class=image->storage_class;
859 cache_info->colorspace=image->colorspace;
860 cache_info->columns=image->columns;
861 cache_info->rows=image->rows;
862 image->cache=cache_info;
863 }
864 /*
865 Pixels are stored in a temporary buffer until they are synced to the cache.
866 */
867 cache_info->columns=columns;
868 cache_info->rows=rows;
869 number_pixels=(MagickSizeType) columns*rows;
cristy4c08aed2011-07-01 19:47:50 +0000870 length=(size_t) number_pixels*cache_info->pixel_channels*sizeof(Quantum);
871 if (cache_info->metacontent_extent != 0)
872 length+=number_pixels*cache_info->metacontent_extent;
873 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000874 {
cristy4c08aed2011-07-01 19:47:50 +0000875 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
cristy3ed852e2009-09-05 21:47:34 +0000876 cache_info->length=(MagickSizeType) length;
877 }
878 else
879 if (cache_info->length < (MagickSizeType) length)
880 {
cristy4c08aed2011-07-01 19:47:50 +0000881 cache_info->pixels=(Quantum *) ResizeMagickMemory(
cristy3ed852e2009-09-05 21:47:34 +0000882 cache_info->pixels,length);
883 cache_info->length=(MagickSizeType) length;
884 }
885 if (cache_info->pixels == (void *) NULL)
cristy4c08aed2011-07-01 19:47:50 +0000886 return((Quantum *) NULL);
887 cache_info->metacontent=(void *) NULL;
888 if (cache_info->metacontent_extent != 0)
889 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
890 cache_info->pixel_channels);
cristy3ed852e2009-09-05 21:47:34 +0000891 return(cache_info->pixels);
892}
893
894/*
895%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896% %
897% %
898% %
899% R e a d S t r e a m %
900% %
901% %
902% %
903%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904%
905% ReadStream() makes the image pixels available to a user supplied callback
906% method immediately upon reading a scanline with the ReadImage() method.
907%
908% The format of the ReadStream() method is:
909%
910% Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
911% ExceptionInfo *exception)
912%
913% A description of each parameter follows:
914%
915% o image_info: the image info.
916%
917% o stream: a callback method.
918%
919% o exception: return any errors or warnings in this structure.
920%
921*/
922MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
923 ExceptionInfo *exception)
924{
925 CacheMethods
926 cache_methods;
927
928 Image
929 *image;
930
931 ImageInfo
932 *read_info;
933
934 /*
935 Stream image pixels.
936 */
937 assert(image_info != (ImageInfo *) NULL);
938 assert(image_info->signature == MagickSignature);
939 if (image_info->debug != MagickFalse)
940 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
941 image_info->filename);
942 assert(exception != (ExceptionInfo *) NULL);
943 assert(exception->signature == MagickSignature);
944 read_info=CloneImageInfo(image_info);
945 read_info->cache=AcquirePixelCache(0);
946 GetPixelCacheMethods(&cache_methods);
947 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
cristy4c08aed2011-07-01 19:47:50 +0000948 cache_methods.get_virtual_metacontent_from_handler=
949 GetVirtualMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000950 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
951 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
952 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
953 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
954 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
cristy4c08aed2011-07-01 19:47:50 +0000955 cache_methods.get_authentic_metacontent_from_handler=
956 GetAuthenticMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000957 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
958 cache_methods.get_one_authentic_pixel_from_handler=
959 GetOneAuthenticPixelFromStream;
960 cache_methods.destroy_pixel_handler=DestroyPixelStream;
961 SetPixelCacheMethods(read_info->cache,&cache_methods);
962 read_info->stream=stream;
963 image=ReadImage(read_info,exception);
964 read_info=DestroyImageInfo(read_info);
965 return(image);
966}
967
968/*
969%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
970% %
971% %
972% %
973+ S e t S t r e a m I n f o C l i e n t D a t a %
974% %
975% %
976% %
977%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
978%
979% SetStreamInfoClientData() sets the stream info client data.
980%
981% The format of the SetStreamInfoClientData method is:
982%
983% void SetStreamInfoClientData(StreamInfo *stream_info,
984% const void *client_data)
985%
986% A description of each parameter follows:
987%
988% o stream_info: the stream info.
989%
990% o client_data: the client data.
991%
992*/
993MagickExport void SetStreamInfoClientData(StreamInfo *stream_info,
994 const void *client_data)
995{
996 assert(stream_info != (StreamInfo *) NULL);
997 assert(stream_info->signature == MagickSignature);
998 stream_info->client_data=client_data;
999}
1000
1001/*
1002%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003% %
1004% %
1005% %
1006+ S e t S t r e a m I n f o M a p %
1007% %
1008% %
1009% %
1010%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1011%
1012% SetStreamInfoMap() sets the stream info map member.
1013%
1014% The format of the SetStreamInfoMap method is:
1015%
1016% void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1017%
1018% A description of each parameter follows:
1019%
1020% o stream_info: the stream info.
1021%
1022% o map: the map.
1023%
1024*/
1025MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1026{
1027 assert(stream_info != (StreamInfo *) NULL);
1028 assert(stream_info->signature == MagickSignature);
1029 (void) CloneString(&stream_info->map,map);
1030}
1031
1032/*
1033%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1034% %
1035% %
1036% %
1037+ S e t S t r e a m I n f o S t o r a g e T y p e %
1038% %
1039% %
1040% %
1041%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042%
1043% SetStreamInfoStorageType() sets the stream info storage type member.
1044%
1045% The format of the SetStreamInfoStorageType method is:
1046%
1047% void SetStreamInfoStorageType(StreamInfo *stream_info,
1048% const StoreageType *storage_type)
1049%
1050% A description of each parameter follows:
1051%
1052% o stream_info: the stream info.
1053%
1054% o storage_type: the storage type.
1055%
1056*/
1057MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1058 const StorageType storage_type)
1059{
1060 assert(stream_info != (StreamInfo *) NULL);
1061 assert(stream_info->signature == MagickSignature);
1062 stream_info->storage_type=storage_type;
1063}
1064
1065/*
1066%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1067% %
1068% %
1069% %
1070+ S t r e a m I m a g e %
1071% %
1072% %
1073% %
1074%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1075%
1076% StreamImage() streams pixels from an image and writes them in a user
1077% defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1078%
cristyd212bd02011-02-13 17:08:57 +00001079% The format of the StreamImage() method is:
cristy3ed852e2009-09-05 21:47:34 +00001080%
1081% Image *StreamImage(const ImageInfo *image_info,
1082% StreamInfo *stream_info,ExceptionInfo *exception)
1083%
1084% A description of each parameter follows:
1085%
1086% o image_info: the image info.
1087%
1088% o stream_info: the stream info.
1089%
1090% o exception: return any errors or warnings in this structure.
1091%
1092*/
1093
1094#if defined(__cplusplus) || defined(c_plusplus)
1095extern "C" {
1096#endif
1097
1098static size_t WriteStreamImage(const Image *image,const void *pixels,
1099 const size_t columns)
1100{
cristye3664f42010-05-14 00:59:57 +00001101 CacheInfo
1102 *cache_info;
1103
cristy3ed852e2009-09-05 21:47:34 +00001104 RectangleInfo
1105 extract_info;
1106
1107 size_t
1108 length,
1109 packet_size;
1110
1111 ssize_t
1112 count;
1113
1114 StreamInfo
1115 *stream_info;
1116
cristy654fdaf2011-02-24 15:24:33 +00001117 (void) pixels;
cristy3ed852e2009-09-05 21:47:34 +00001118 stream_info=(StreamInfo *) image->client_data;
1119 switch (stream_info->storage_type)
1120 {
1121 default: packet_size=sizeof(char); break;
1122 case CharPixel: packet_size=sizeof(char); break;
1123 case DoublePixel: packet_size=sizeof(double); break;
1124 case FloatPixel: packet_size=sizeof(float); break;
1125 case IntegerPixel: packet_size=sizeof(int); break;
cristybb503372010-05-27 20:51:26 +00001126 case LongPixel: packet_size=sizeof(ssize_t); break;
cristy3ed852e2009-09-05 21:47:34 +00001127 case QuantumPixel: packet_size=sizeof(Quantum); break;
1128 case ShortPixel: packet_size=sizeof(unsigned short); break;
1129 }
cristye3664f42010-05-14 00:59:57 +00001130 cache_info=(CacheInfo *) image->cache;
1131 assert(cache_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001132 packet_size*=strlen(stream_info->map);
cristye3664f42010-05-14 00:59:57 +00001133 length=packet_size*cache_info->columns*cache_info->rows;
cristy3ed852e2009-09-05 21:47:34 +00001134 if (image != stream_info->image)
1135 {
1136 ImageInfo
1137 *write_info;
1138
1139 /*
1140 Prepare stream for writing.
1141 */
1142 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1143 stream_info->pixels,length,sizeof(*stream_info->pixels));
cristy5dd71882010-08-01 20:53:13 +00001144 if (stream_info->pixels == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001145 return(0);
1146 stream_info->image=image;
1147 write_info=CloneImageInfo(stream_info->image_info);
cristyd965a422010-03-03 17:47:35 +00001148 (void) SetImageInfo(write_info,1,stream_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001149 if (write_info->extract != (char *) NULL)
1150 (void) ParseAbsoluteGeometry(write_info->extract,
1151 &stream_info->extract_info);
1152 stream_info->y=0;
1153 write_info=DestroyImageInfo(write_info);
1154 }
1155 extract_info=stream_info->extract_info;
cristyd212bd02011-02-13 17:08:57 +00001156 if ((extract_info.width == 0) || (extract_info.height == 0))
cristy3ed852e2009-09-05 21:47:34 +00001157 {
1158 /*
1159 Write all pixels to stream.
1160 */
1161 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1162 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1163 stream_info->y++;
1164 return(count == 0 ? 0 : columns);
1165 }
1166 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001167 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001168 {
1169 stream_info->y++;
1170 return(columns);
1171 }
1172 /*
1173 Write a portion of the pixel row to the stream.
1174 */
1175 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1176 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001177 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1178 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001179 stream_info->y++;
1180 return(count == 0 ? 0 : columns);
1181}
1182
1183#if defined(__cplusplus) || defined(c_plusplus)
1184}
1185#endif
1186
1187MagickExport Image *StreamImage(const ImageInfo *image_info,
1188 StreamInfo *stream_info,ExceptionInfo *exception)
1189{
1190 Image
1191 *image;
1192
1193 ImageInfo
1194 *read_info;
1195
1196 assert(image_info != (const ImageInfo *) NULL);
1197 assert(image_info->signature == MagickSignature);
1198 if (image_info->debug != MagickFalse)
1199 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1200 image_info->filename);
1201 assert(stream_info != (StreamInfo *) NULL);
1202 assert(stream_info->signature == MagickSignature);
1203 assert(exception != (ExceptionInfo *) NULL);
1204 read_info=CloneImageInfo(image_info);
1205 stream_info->image_info=image_info;
1206 stream_info->exception=exception;
1207 read_info->client_data=(void *) stream_info;
1208 image=ReadStream(read_info,&WriteStreamImage,exception);
1209 read_info=DestroyImageInfo(read_info);
1210 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1211 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1212 image=DestroyImage(image);
1213 return(image);
1214}
1215
1216/*
1217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1218% %
1219% %
1220% %
1221+ S t r e a m I m a g e P i x e l s %
1222% %
1223% %
1224% %
1225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1226%
1227% StreamImagePixels() extracts pixel data from an image and returns it in the
1228% stream_info->pixels structure in the format as defined by
1229% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1230%
1231% The format of the StreamImagePixels method is:
1232%
1233% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1234% const Image *image,ExceptionInfo *exception)
1235%
1236% A description of each parameter follows:
1237%
1238% o stream_info: the stream info.
1239%
1240% o image: the image.
1241%
1242% o exception: return any errors or warnings in this structure.
1243%
1244*/
1245static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1246 const Image *image,ExceptionInfo *exception)
1247{
1248 QuantumInfo
1249 *quantum_info;
1250
1251 QuantumType
1252 *quantum_map;
1253
cristy4c08aed2011-07-01 19:47:50 +00001254 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001255 *p;
1256
cristyd212bd02011-02-13 17:08:57 +00001257 register ssize_t
1258 i,
1259 x;
1260
cristy3ed852e2009-09-05 21:47:34 +00001261 size_t
1262 length;
1263
1264 assert(stream_info != (StreamInfo *) NULL);
1265 assert(stream_info->signature == MagickSignature);
1266 assert(image != (Image *) NULL);
1267 assert(image->signature == MagickSignature);
1268 if (image->debug != MagickFalse)
1269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1270 length=strlen(stream_info->map);
1271 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1272 if (quantum_map == (QuantumType *) NULL)
1273 {
1274 (void) ThrowMagickException(exception,GetMagickModule(),
1275 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1276 return(MagickFalse);
1277 }
cristybb503372010-05-27 20:51:26 +00001278 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001279 {
1280 switch (stream_info->map[i])
1281 {
1282 case 'A':
1283 case 'a':
1284 {
1285 quantum_map[i]=AlphaQuantum;
1286 break;
1287 }
1288 case 'B':
1289 case 'b':
1290 {
1291 quantum_map[i]=BlueQuantum;
1292 break;
1293 }
1294 case 'C':
1295 case 'c':
1296 {
1297 quantum_map[i]=CyanQuantum;
1298 if (image->colorspace == CMYKColorspace)
1299 break;
1300 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1301 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1302 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1303 return(MagickFalse);
1304 }
1305 case 'g':
1306 case 'G':
1307 {
1308 quantum_map[i]=GreenQuantum;
1309 break;
1310 }
1311 case 'I':
1312 case 'i':
1313 {
1314 quantum_map[i]=IndexQuantum;
1315 break;
1316 }
1317 case 'K':
1318 case 'k':
1319 {
1320 quantum_map[i]=BlackQuantum;
1321 if (image->colorspace == CMYKColorspace)
1322 break;
1323 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1324 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1325 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1326 return(MagickFalse);
1327 }
1328 case 'M':
1329 case 'm':
1330 {
1331 quantum_map[i]=MagentaQuantum;
1332 if (image->colorspace == CMYKColorspace)
1333 break;
1334 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1335 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1336 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1337 return(MagickFalse);
1338 }
1339 case 'o':
1340 case 'O':
1341 {
1342 quantum_map[i]=OpacityQuantum;
1343 break;
1344 }
1345 case 'P':
1346 case 'p':
1347 {
1348 quantum_map[i]=UndefinedQuantum;
1349 break;
1350 }
1351 case 'R':
1352 case 'r':
1353 {
1354 quantum_map[i]=RedQuantum;
1355 break;
1356 }
1357 case 'Y':
1358 case 'y':
1359 {
1360 quantum_map[i]=YellowQuantum;
1361 if (image->colorspace == CMYKColorspace)
1362 break;
1363 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1364 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1365 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1366 return(MagickFalse);
1367 }
1368 default:
1369 {
1370 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1371 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1372 "UnrecognizedPixelMap","`%s'",stream_info->map);
1373 return(MagickFalse);
1374 }
1375 }
1376 }
1377 quantum_info=stream_info->quantum_info;
1378 switch (stream_info->storage_type)
1379 {
1380 case CharPixel:
1381 {
1382 register unsigned char
1383 *q;
1384
1385 q=(unsigned char *) stream_info->pixels;
1386 if (LocaleCompare(stream_info->map,"BGR") == 0)
1387 {
1388 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001389 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001390 break;
cristybb503372010-05-27 20:51:26 +00001391 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001392 {
cristy4c08aed2011-07-01 19:47:50 +00001393 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1394 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1395 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001396 p++;
1397 }
1398 break;
1399 }
1400 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1401 {
1402 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001403 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001404 break;
cristybb503372010-05-27 20:51:26 +00001405 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001406 {
cristy4c08aed2011-07-01 19:47:50 +00001407 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1408 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1409 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1410 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001411 p++;
1412 }
1413 break;
1414 }
1415 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1416 {
1417 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001418 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001419 break;
cristybb503372010-05-27 20:51:26 +00001420 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001421 {
cristy4c08aed2011-07-01 19:47:50 +00001422 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1423 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1424 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001425 *q++=ScaleQuantumToChar((Quantum) 0);
1426 p++;
1427 }
1428 break;
1429 }
1430 if (LocaleCompare(stream_info->map,"I") == 0)
1431 {
1432 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001433 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001434 break;
cristybb503372010-05-27 20:51:26 +00001435 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001436 {
cristy4c08aed2011-07-01 19:47:50 +00001437 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001438 p++;
1439 }
1440 break;
1441 }
1442 if (LocaleCompare(stream_info->map,"RGB") == 0)
1443 {
1444 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001445 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001446 break;
cristybb503372010-05-27 20:51:26 +00001447 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001448 {
cristy4c08aed2011-07-01 19:47:50 +00001449 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1450 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1451 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001452 p++;
1453 }
1454 break;
1455 }
1456 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1457 {
1458 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001459 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001460 break;
cristybb503372010-05-27 20:51:26 +00001461 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001462 {
cristy4c08aed2011-07-01 19:47:50 +00001463 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1464 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1465 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1466 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001467 p++;
1468 }
1469 break;
1470 }
1471 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1472 {
1473 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001474 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001475 break;
cristybb503372010-05-27 20:51:26 +00001476 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001477 {
cristy4c08aed2011-07-01 19:47:50 +00001478 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1479 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1480 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001481 *q++=ScaleQuantumToChar((Quantum) 0);
1482 p++;
1483 }
1484 break;
1485 }
1486 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001487 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001488 break;
cristybb503372010-05-27 20:51:26 +00001489 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001490 {
cristybb503372010-05-27 20:51:26 +00001491 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001492 {
1493 *q=0;
1494 switch (quantum_map[i])
1495 {
1496 case RedQuantum:
1497 case CyanQuantum:
1498 {
cristy4c08aed2011-07-01 19:47:50 +00001499 *q=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001500 break;
1501 }
1502 case GreenQuantum:
1503 case MagentaQuantum:
1504 {
cristy4c08aed2011-07-01 19:47:50 +00001505 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001506 break;
1507 }
1508 case BlueQuantum:
1509 case YellowQuantum:
1510 {
cristy4c08aed2011-07-01 19:47:50 +00001511 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001512 break;
1513 }
1514 case AlphaQuantum:
1515 {
cristy4c08aed2011-07-01 19:47:50 +00001516 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001517 break;
1518 }
1519 case OpacityQuantum:
1520 {
cristy4c08aed2011-07-01 19:47:50 +00001521 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001522 break;
1523 }
1524 case BlackQuantum:
1525 {
1526 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001527 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001528 break;
1529 }
1530 case IndexQuantum:
1531 {
cristy4c08aed2011-07-01 19:47:50 +00001532 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001533 break;
1534 }
1535 default:
1536 break;
1537 }
1538 q++;
1539 }
1540 p++;
1541 }
1542 break;
1543 }
1544 case DoublePixel:
1545 {
1546 register double
1547 *q;
1548
1549 q=(double *) stream_info->pixels;
1550 if (LocaleCompare(stream_info->map,"BGR") == 0)
1551 {
1552 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001553 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001554 break;
cristybb503372010-05-27 20:51:26 +00001555 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001556 {
cristy4c08aed2011-07-01 19:47:50 +00001557 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001558 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001559 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001560 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001561 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001562 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001563 p++;
1564 }
1565 break;
1566 }
1567 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1568 {
1569 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001570 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001571 break;
cristybb503372010-05-27 20:51:26 +00001572 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001573 {
cristy4c08aed2011-07-01 19:47:50 +00001574 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001575 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001576 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001577 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001578 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001579 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001580 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001581 quantum_info->scale+quantum_info->minimum);
1582 p++;
1583 }
1584 break;
1585 }
1586 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1587 {
1588 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001589 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001590 break;
cristybb503372010-05-27 20:51:26 +00001591 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001592 {
cristy4c08aed2011-07-01 19:47:50 +00001593 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001594 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001595 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001596 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001597 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001598 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001599 *q++=0.0;
1600 p++;
1601 }
1602 break;
1603 }
1604 if (LocaleCompare(stream_info->map,"I") == 0)
1605 {
1606 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001607 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001608 break;
cristybb503372010-05-27 20:51:26 +00001609 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001610 {
cristy4c08aed2011-07-01 19:47:50 +00001611 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001612 quantum_info->scale+quantum_info->minimum);
1613 p++;
1614 }
1615 break;
1616 }
1617 if (LocaleCompare(stream_info->map,"RGB") == 0)
1618 {
1619 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001620 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001621 break;
cristybb503372010-05-27 20:51:26 +00001622 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001623 {
cristy4c08aed2011-07-01 19:47:50 +00001624 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001625 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001626 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001627 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001628 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001629 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001630 p++;
1631 }
1632 break;
1633 }
1634 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1635 {
1636 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001637 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001638 break;
cristybb503372010-05-27 20:51:26 +00001639 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001640 {
cristy4c08aed2011-07-01 19:47:50 +00001641 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001642 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001643 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001644 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001645 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001646 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001647 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001648 quantum_info->scale+quantum_info->minimum);
1649 p++;
1650 }
1651 break;
1652 }
1653 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1654 {
1655 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001656 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001657 break;
cristybb503372010-05-27 20:51:26 +00001658 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001659 {
cristy4c08aed2011-07-01 19:47:50 +00001660 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001661 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001662 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001663 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001664 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001665 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001666 *q++=0.0;
1667 p++;
1668 }
1669 break;
1670 }
1671 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001672 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001673 break;
cristybb503372010-05-27 20:51:26 +00001674 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001675 {
cristybb503372010-05-27 20:51:26 +00001676 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001677 {
1678 *q=0;
1679 switch (quantum_map[i])
1680 {
1681 case RedQuantum:
1682 case CyanQuantum:
1683 {
cristy4c08aed2011-07-01 19:47:50 +00001684 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001685 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001686 break;
1687 }
1688 case GreenQuantum:
1689 case MagentaQuantum:
1690 {
cristy4c08aed2011-07-01 19:47:50 +00001691 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001692 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001693 break;
1694 }
1695 case BlueQuantum:
1696 case YellowQuantum:
1697 {
cristy4c08aed2011-07-01 19:47:50 +00001698 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001699 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001700 break;
1701 }
1702 case AlphaQuantum:
1703 {
cristy4c08aed2011-07-01 19:47:50 +00001704 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001705 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001706 break;
1707 }
1708 case OpacityQuantum:
1709 {
cristy4c08aed2011-07-01 19:47:50 +00001710 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001711 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001712 break;
1713 }
1714 case BlackQuantum:
1715 {
1716 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001717 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001718 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001719 break;
1720 }
1721 case IndexQuantum:
1722 {
cristy4c08aed2011-07-01 19:47:50 +00001723 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001724 quantum_info->scale+quantum_info->minimum);
1725 break;
1726 }
1727 default:
1728 *q=0;
1729 }
1730 q++;
1731 }
1732 p++;
1733 }
1734 break;
1735 }
1736 case FloatPixel:
1737 {
1738 register float
1739 *q;
1740
1741 q=(float *) stream_info->pixels;
1742 if (LocaleCompare(stream_info->map,"BGR") == 0)
1743 {
1744 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001745 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001746 break;
cristybb503372010-05-27 20:51:26 +00001747 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001748 {
cristy4c08aed2011-07-01 19:47:50 +00001749 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001750 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001751 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001752 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001753 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001754 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001755 p++;
1756 }
1757 break;
1758 }
1759 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1760 {
1761 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001762 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001763 break;
cristybb503372010-05-27 20:51:26 +00001764 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001765 {
cristy4c08aed2011-07-01 19:47:50 +00001766 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001767 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001768 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001769 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001770 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001771 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001772 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
cristy3ed852e2009-09-05 21:47:34 +00001773 quantum_info->scale+quantum_info->minimum);
1774 p++;
1775 }
1776 break;
1777 }
1778 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1779 {
1780 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001781 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001782 break;
cristybb503372010-05-27 20:51:26 +00001783 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001784 {
cristy4c08aed2011-07-01 19:47:50 +00001785 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001786 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001787 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001788 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001789 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001790 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001791 *q++=0.0;
1792 p++;
1793 }
1794 break;
1795 }
1796 if (LocaleCompare(stream_info->map,"I") == 0)
1797 {
1798 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001799 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001800 break;
cristybb503372010-05-27 20:51:26 +00001801 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001802 {
cristy4c08aed2011-07-01 19:47:50 +00001803 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001804 quantum_info->scale+quantum_info->minimum);
1805 p++;
1806 }
1807 break;
1808 }
1809 if (LocaleCompare(stream_info->map,"RGB") == 0)
1810 {
1811 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001812 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001813 break;
cristybb503372010-05-27 20:51:26 +00001814 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001815 {
cristy4c08aed2011-07-01 19:47:50 +00001816 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001817 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001818 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001819 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001820 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001821 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001822 p++;
1823 }
1824 break;
1825 }
1826 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1827 {
1828 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001829 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001830 break;
cristybb503372010-05-27 20:51:26 +00001831 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001832 {
cristy4c08aed2011-07-01 19:47:50 +00001833 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001834 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001835 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001836 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001837 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001838 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001839 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001840 quantum_info->scale+quantum_info->minimum);
1841 p++;
1842 }
1843 break;
1844 }
1845 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1846 {
1847 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001848 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001849 break;
cristybb503372010-05-27 20:51:26 +00001850 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001851 {
cristy4c08aed2011-07-01 19:47:50 +00001852 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001853 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001854 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001855 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001856 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001857 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001858 *q++=0.0;
1859 p++;
1860 }
1861 break;
1862 }
1863 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001864 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001865 break;
cristybb503372010-05-27 20:51:26 +00001866 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001867 {
cristybb503372010-05-27 20:51:26 +00001868 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001869 {
1870 *q=0;
1871 switch (quantum_map[i])
1872 {
1873 case RedQuantum:
1874 case CyanQuantum:
1875 {
cristy4c08aed2011-07-01 19:47:50 +00001876 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001877 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001878 break;
1879 }
1880 case GreenQuantum:
1881 case MagentaQuantum:
1882 {
cristy4c08aed2011-07-01 19:47:50 +00001883 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001884 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001885 break;
1886 }
1887 case BlueQuantum:
1888 case YellowQuantum:
1889 {
cristy4c08aed2011-07-01 19:47:50 +00001890 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001891 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001892 break;
1893 }
1894 case AlphaQuantum:
1895 {
cristy4c08aed2011-07-01 19:47:50 +00001896 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001897 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001898 break;
1899 }
1900 case OpacityQuantum:
1901 {
cristy4c08aed2011-07-01 19:47:50 +00001902 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001903 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001904 break;
1905 }
1906 case BlackQuantum:
1907 {
1908 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001909 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001910 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001911 break;
1912 }
1913 case IndexQuantum:
1914 {
cristy4c08aed2011-07-01 19:47:50 +00001915 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001916 quantum_info->scale+quantum_info->minimum);
1917 break;
1918 }
1919 default:
1920 *q=0;
1921 }
1922 q++;
1923 }
1924 p++;
1925 }
1926 break;
1927 }
1928 case IntegerPixel:
1929 {
1930 register unsigned int
1931 *q;
1932
1933 q=(unsigned int *) stream_info->pixels;
1934 if (LocaleCompare(stream_info->map,"BGR") == 0)
1935 {
1936 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001937 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001938 break;
cristybb503372010-05-27 20:51:26 +00001939 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001940 {
cristy4c08aed2011-07-01 19:47:50 +00001941 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1942 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1943 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001944 p++;
1945 }
1946 break;
1947 }
1948 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1949 {
1950 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001951 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001952 break;
cristybb503372010-05-27 20:51:26 +00001953 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001954 {
cristy4c08aed2011-07-01 19:47:50 +00001955 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1956 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1957 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1958 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001959 p++;
1960 }
1961 break;
1962 }
1963 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1964 {
1965 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001966 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001967 break;
cristybb503372010-05-27 20:51:26 +00001968 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001969 {
cristy4c08aed2011-07-01 19:47:50 +00001970 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1971 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1972 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001973 *q++=0U;
1974 p++;
1975 }
1976 break;
1977 }
1978 if (LocaleCompare(stream_info->map,"I") == 0)
1979 {
1980 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001981 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001982 break;
cristybb503372010-05-27 20:51:26 +00001983 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001984 {
1985 *q++=(unsigned int) ScaleQuantumToLong(
cristy4c08aed2011-07-01 19:47:50 +00001986 GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001987 p++;
1988 }
1989 break;
1990 }
1991 if (LocaleCompare(stream_info->map,"RGB") == 0)
1992 {
1993 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001994 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001995 break;
cristybb503372010-05-27 20:51:26 +00001996 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001997 {
cristy4c08aed2011-07-01 19:47:50 +00001998 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1999 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2000 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002001 p++;
2002 }
2003 break;
2004 }
2005 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2006 {
2007 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002008 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002009 break;
cristybb503372010-05-27 20:51:26 +00002010 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002011 {
cristy4c08aed2011-07-01 19:47:50 +00002012 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2013 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2014 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002015 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002016 (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002017 p++;
2018 }
2019 break;
2020 }
2021 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2022 {
2023 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002024 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002025 break;
cristybb503372010-05-27 20:51:26 +00002026 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002027 {
cristy4c08aed2011-07-01 19:47:50 +00002028 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2029 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2030 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002031 *q++=0U;
2032 p++;
2033 }
2034 break;
2035 }
2036 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002037 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002038 break;
cristybb503372010-05-27 20:51:26 +00002039 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002040 {
cristybb503372010-05-27 20:51:26 +00002041 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002042 {
2043 *q=0;
2044 switch (quantum_map[i])
2045 {
2046 case RedQuantum:
2047 case CyanQuantum:
2048 {
cristy4c08aed2011-07-01 19:47:50 +00002049 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002050 break;
2051 }
2052 case GreenQuantum:
2053 case MagentaQuantum:
2054 {
cristy4c08aed2011-07-01 19:47:50 +00002055 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002056 break;
2057 }
2058 case BlueQuantum:
2059 case YellowQuantum:
2060 {
cristy4c08aed2011-07-01 19:47:50 +00002061 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002062 break;
2063 }
2064 case AlphaQuantum:
2065 {
cristy4c08aed2011-07-01 19:47:50 +00002066 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002067 break;
2068 }
2069 case OpacityQuantum:
2070 {
cristy4c08aed2011-07-01 19:47:50 +00002071 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002072 break;
2073 }
2074 case BlackQuantum:
2075 {
2076 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002077 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002078 break;
2079 }
2080 case IndexQuantum:
2081 {
2082 *q=(unsigned int)
cristy4c08aed2011-07-01 19:47:50 +00002083 ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002084 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);
cristy4c08aed2011-07-01 19:47:50 +00002104 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002105 break;
cristybb503372010-05-27 20:51:26 +00002106 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002107 {
cristy4c08aed2011-07-01 19:47:50 +00002108 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2109 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2110 *q++=ScaleQuantumToLong(GetPixelRed(image,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);
cristy4c08aed2011-07-01 19:47:50 +00002118 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002119 break;
cristybb503372010-05-27 20:51:26 +00002120 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002121 {
cristy4c08aed2011-07-01 19:47:50 +00002122 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2123 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2124 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2125 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,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);
cristy4c08aed2011-07-01 19:47:50 +00002133 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002134 break;
cristybb503372010-05-27 20:51:26 +00002135 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002136 {
cristy4c08aed2011-07-01 19:47:50 +00002137 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2138 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2139 *q++=ScaleQuantumToLong(GetPixelRed(image,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);
cristy4c08aed2011-07-01 19:47:50 +00002148 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002149 break;
cristybb503372010-05-27 20:51:26 +00002150 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002151 {
cristy4c08aed2011-07-01 19:47:50 +00002152 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002153 p++;
2154 }
2155 break;
2156 }
2157 if (LocaleCompare(stream_info->map,"RGB") == 0)
2158 {
2159 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002160 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002161 break;
cristybb503372010-05-27 20:51:26 +00002162 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002163 {
cristy4c08aed2011-07-01 19:47:50 +00002164 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2165 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2166 *q++=ScaleQuantumToLong(GetPixelBlue(image,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);
cristy4c08aed2011-07-01 19:47:50 +00002174 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002175 break;
cristybb503372010-05-27 20:51:26 +00002176 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002177 {
cristy4c08aed2011-07-01 19:47:50 +00002178 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2179 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2180 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2181 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,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);
cristy4c08aed2011-07-01 19:47:50 +00002189 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002190 break;
cristybb503372010-05-27 20:51:26 +00002191 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002192 {
cristy4c08aed2011-07-01 19:47:50 +00002193 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2194 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2195 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002196 *q++=0;
2197 p++;
2198 }
2199 break;
2200 }
2201 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002202 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002203 break;
cristybb503372010-05-27 20:51:26 +00002204 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002205 {
cristybb503372010-05-27 20:51:26 +00002206 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002207 {
2208 *q=0;
2209 switch (quantum_map[i])
2210 {
2211 case RedQuantum:
2212 case CyanQuantum:
2213 {
cristy4c08aed2011-07-01 19:47:50 +00002214 *q=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002215 break;
2216 }
2217 case GreenQuantum:
2218 case MagentaQuantum:
2219 {
cristy4c08aed2011-07-01 19:47:50 +00002220 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002221 break;
2222 }
2223 case BlueQuantum:
2224 case YellowQuantum:
2225 {
cristy4c08aed2011-07-01 19:47:50 +00002226 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002227 break;
2228 }
2229 case AlphaQuantum:
2230 {
cristy4c08aed2011-07-01 19:47:50 +00002231 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002232 break;
2233 }
2234 case OpacityQuantum:
2235 {
cristy4c08aed2011-07-01 19:47:50 +00002236 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002237 break;
2238 }
2239 case BlackQuantum:
2240 {
2241 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002242 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002243 break;
2244 }
2245 case IndexQuantum:
2246 {
cristy4c08aed2011-07-01 19:47:50 +00002247 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002248 break;
2249 }
2250 default:
2251 break;
2252 }
2253 q++;
2254 }
2255 p++;
2256 }
2257 break;
2258 }
2259 case QuantumPixel:
2260 {
2261 register Quantum
2262 *q;
2263
2264 q=(Quantum *) stream_info->pixels;
2265 if (LocaleCompare(stream_info->map,"BGR") == 0)
2266 {
2267 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002268 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002269 break;
cristybb503372010-05-27 20:51:26 +00002270 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002271 {
cristy4c08aed2011-07-01 19:47:50 +00002272 *q++=GetPixelBlue(image,p);
2273 *q++=GetPixelGreen(image,p);
2274 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002275 p++;
2276 }
2277 break;
2278 }
2279 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2280 {
2281 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002282 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002283 break;
cristybb503372010-05-27 20:51:26 +00002284 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002285 {
cristy4c08aed2011-07-01 19:47:50 +00002286 *q++=GetPixelBlue(image,p);
2287 *q++=GetPixelGreen(image,p);
2288 *q++=GetPixelRed(image,p);
2289 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002290 p++;
2291 }
2292 break;
2293 }
2294 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2295 {
2296 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002297 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002298 break;
cristybb503372010-05-27 20:51:26 +00002299 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002300 {
cristy4c08aed2011-07-01 19:47:50 +00002301 *q++=GetPixelBlue(image,p);
2302 *q++=GetPixelGreen(image,p);
2303 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002304 *q++=0;
2305 p++;
2306 }
2307 break;
2308 }
2309 if (LocaleCompare(stream_info->map,"I") == 0)
2310 {
2311 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002312 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002313 break;
cristybb503372010-05-27 20:51:26 +00002314 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002315 {
cristy4c08aed2011-07-01 19:47:50 +00002316 *q++=GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002317 p++;
2318 }
2319 break;
2320 }
2321 if (LocaleCompare(stream_info->map,"RGB") == 0)
2322 {
2323 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002324 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002325 break;
cristybb503372010-05-27 20:51:26 +00002326 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002327 {
cristy4c08aed2011-07-01 19:47:50 +00002328 *q++=GetPixelRed(image,p);
2329 *q++=GetPixelGreen(image,p);
2330 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002331 p++;
2332 }
2333 break;
2334 }
2335 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2336 {
2337 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002338 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002339 break;
cristybb503372010-05-27 20:51:26 +00002340 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002341 {
cristy4c08aed2011-07-01 19:47:50 +00002342 *q++=GetPixelRed(image,p);
2343 *q++=GetPixelGreen(image,p);
2344 *q++=GetPixelBlue(image,p);
2345 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002346 p++;
2347 }
2348 break;
2349 }
2350 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2351 {
2352 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002353 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002354 break;
cristybb503372010-05-27 20:51:26 +00002355 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002356 {
cristy4c08aed2011-07-01 19:47:50 +00002357 *q++=GetPixelRed(image,p);
2358 *q++=GetPixelGreen(image,p);
2359 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002360 *q++=0U;
2361 p++;
2362 }
2363 break;
2364 }
2365 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002366 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002367 break;
cristybb503372010-05-27 20:51:26 +00002368 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002369 {
cristybb503372010-05-27 20:51:26 +00002370 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002371 {
2372 *q=(Quantum) 0;
2373 switch (quantum_map[i])
2374 {
2375 case RedQuantum:
2376 case CyanQuantum:
2377 {
cristy4c08aed2011-07-01 19:47:50 +00002378 *q=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002379 break;
2380 }
2381 case GreenQuantum:
2382 case MagentaQuantum:
2383 {
cristy4c08aed2011-07-01 19:47:50 +00002384 *q=GetPixelGreen(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002385 break;
2386 }
2387 case BlueQuantum:
2388 case YellowQuantum:
2389 {
cristy4c08aed2011-07-01 19:47:50 +00002390 *q=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002391 break;
2392 }
2393 case AlphaQuantum:
2394 {
cristy4c08aed2011-07-01 19:47:50 +00002395 *q=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002396 break;
2397 }
2398 case OpacityQuantum:
2399 {
cristy4c08aed2011-07-01 19:47:50 +00002400 *q=GetPixelAlpha(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002401 break;
2402 }
2403 case BlackQuantum:
2404 {
2405 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002406 *q=GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002407 break;
2408 }
2409 case IndexQuantum:
2410 {
cristy4c08aed2011-07-01 19:47:50 +00002411 *q=(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002412 break;
2413 }
2414 default:
2415 *q=0;
2416 }
2417 q++;
2418 }
2419 p++;
2420 }
2421 break;
2422 }
2423 case ShortPixel:
2424 {
2425 register unsigned short
2426 *q;
2427
2428 q=(unsigned short *) stream_info->pixels;
2429 if (LocaleCompare(stream_info->map,"BGR") == 0)
2430 {
2431 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002432 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002433 break;
cristybb503372010-05-27 20:51:26 +00002434 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002435 {
cristy4c08aed2011-07-01 19:47:50 +00002436 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2437 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2438 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002439 p++;
2440 }
2441 break;
2442 }
2443 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2444 {
2445 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002446 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002447 break;
cristybb503372010-05-27 20:51:26 +00002448 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002449 {
cristy4c08aed2011-07-01 19:47:50 +00002450 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2451 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2452 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2453 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002454 p++;
2455 }
2456 break;
2457 }
2458 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2459 {
2460 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002461 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002462 break;
cristybb503372010-05-27 20:51:26 +00002463 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002464 {
cristy4c08aed2011-07-01 19:47:50 +00002465 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2466 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2467 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002468 *q++=0;
2469 p++;
2470 }
2471 break;
2472 }
2473 if (LocaleCompare(stream_info->map,"I") == 0)
2474 {
2475 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002476 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002477 break;
cristybb503372010-05-27 20:51:26 +00002478 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002479 {
cristy4c08aed2011-07-01 19:47:50 +00002480 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002481 p++;
2482 }
2483 break;
2484 }
2485 if (LocaleCompare(stream_info->map,"RGB") == 0)
2486 {
2487 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002488 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002489 break;
cristybb503372010-05-27 20:51:26 +00002490 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002491 {
cristy4c08aed2011-07-01 19:47:50 +00002492 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2493 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2494 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002495 p++;
2496 }
2497 break;
2498 }
2499 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2500 {
2501 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002502 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002503 break;
cristybb503372010-05-27 20:51:26 +00002504 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002505 {
cristy4c08aed2011-07-01 19:47:50 +00002506 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2507 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2508 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2509 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002510 p++;
2511 }
2512 break;
2513 }
2514 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2515 {
2516 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002517 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002518 break;
cristybb503372010-05-27 20:51:26 +00002519 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002520 {
cristy4c08aed2011-07-01 19:47:50 +00002521 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2522 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2523 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002524 *q++=0;
2525 p++;
2526 }
2527 break;
2528 }
2529 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002530 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002531 break;
cristybb503372010-05-27 20:51:26 +00002532 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002533 {
cristybb503372010-05-27 20:51:26 +00002534 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002535 {
2536 *q=0;
2537 switch (quantum_map[i])
2538 {
2539 case RedQuantum:
2540 case CyanQuantum:
2541 {
cristy4c08aed2011-07-01 19:47:50 +00002542 *q=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002543 break;
2544 }
2545 case GreenQuantum:
2546 case MagentaQuantum:
2547 {
cristy4c08aed2011-07-01 19:47:50 +00002548 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002549 break;
2550 }
2551 case BlueQuantum:
2552 case YellowQuantum:
2553 {
cristy4c08aed2011-07-01 19:47:50 +00002554 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002555 break;
2556 }
2557 case AlphaQuantum:
2558 {
cristy4c08aed2011-07-01 19:47:50 +00002559 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002560 break;
2561 }
2562 case OpacityQuantum:
2563 {
cristy4c08aed2011-07-01 19:47:50 +00002564 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002565 break;
2566 }
2567 case BlackQuantum:
2568 {
2569 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002570 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002571 break;
2572 }
2573 case IndexQuantum:
2574 {
cristy4c08aed2011-07-01 19:47:50 +00002575 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002576 break;
2577 }
2578 default:
2579 break;
2580 }
2581 q++;
2582 }
2583 p++;
2584 }
2585 break;
2586 }
2587 default:
2588 {
2589 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2590 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2591 "UnrecognizedPixelMap","`%s'",stream_info->map);
2592 break;
2593 }
2594 }
2595 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2596 return(MagickTrue);
2597}
2598
2599/*
2600%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2601% %
2602% %
2603% %
2604+ 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 %
2605% %
2606% %
2607% %
2608%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2609%
2610% SyncAuthenticPixelsStream() calls the user supplied callback method with
2611% the latest stream of pixels.
2612%
2613% The format of the SyncAuthenticPixelsStream method is:
2614%
2615% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2616% ExceptionInfo *exception)
2617%
2618% A description of each parameter follows:
2619%
2620% o image: the image.
2621%
2622% o exception: return any errors or warnings in this structure.
2623%
2624*/
2625static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2626 ExceptionInfo *exception)
2627{
2628 CacheInfo
2629 *cache_info;
2630
2631 size_t
2632 length;
2633
2634 StreamHandler
2635 stream_handler;
2636
2637 assert(image != (Image *) NULL);
2638 assert(image->signature == MagickSignature);
2639 if (image->debug != MagickFalse)
2640 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2641 cache_info=(CacheInfo *) image->cache;
2642 assert(cache_info->signature == MagickSignature);
2643 stream_handler=GetBlobStreamHandler(image);
2644 if (stream_handler == (StreamHandler) NULL)
2645 {
2646 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2647 "NoStreamHandlerIsDefined","`%s'",image->filename);
2648 return(MagickFalse);
2649 }
2650 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2651 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2652}
2653
2654/*
2655%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2656% %
2657% %
2658% %
2659% W r i t e S t r e a m %
2660% %
2661% %
2662% %
2663%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2664%
2665% WriteStream() makes the image pixels available to a user supplied callback
2666% method immediately upon writing pixel data with the WriteImage() method.
2667%
2668% The format of the WriteStream() method is:
2669%
2670% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2671% StreamHandler stream)
2672%
2673% A description of each parameter follows:
2674%
2675% o image_info: the image info.
2676%
2677% o stream: A callback method.
2678%
2679*/
2680MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2681 Image *image,StreamHandler stream)
2682{
2683 ImageInfo
2684 *write_info;
2685
2686 MagickBooleanType
2687 status;
2688
2689 assert(image_info != (ImageInfo *) NULL);
2690 assert(image_info->signature == MagickSignature);
2691 if (image_info->debug != MagickFalse)
2692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2693 image_info->filename);
2694 assert(image != (Image *) NULL);
2695 assert(image->signature == MagickSignature);
2696 write_info=CloneImageInfo(image_info);
2697 write_info->stream=stream;
2698 status=WriteImage(write_info,image);
2699 write_info=DestroyImageInfo(write_info);
2700 return(status);
2701}