blob: bc0c380fdfc49ecb1388c05f084add7589f97efe [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%
cristy9950d572011-10-01 18:22:35 +0000144% StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
145% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000146%
147% A description of each parameter follows:
148%
149% o image_info: the image info.
150%
cristy9950d572011-10-01 18:22:35 +0000151% o exception: return any errors or warnings in this structure.
152%
cristy3ed852e2009-09-05 21:47:34 +0000153*/
cristy9950d572011-10-01 18:22:35 +0000154MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info,
155 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000156{
157 StreamInfo
158 *stream_info;
159
cristy73bd4a52010-10-05 11:24:23 +0000160 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
cristy3ed852e2009-09-05 21:47:34 +0000161 if (stream_info == (StreamInfo *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
164 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
165 sizeof(*stream_info->pixels));
166 if (stream_info->pixels == (unsigned char *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 stream_info->map=ConstantString("RGB");
169 stream_info->storage_type=CharPixel;
cristy9950d572011-10-01 18:22:35 +0000170 stream_info->stream=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000171 stream_info->signature=MagickSignature;
172 return(stream_info);
173}
174
175/*
176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177% %
178% %
179% %
180+ D e s t r o y P i x e l S t r e a m %
181% %
182% %
183% %
184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185%
186% DestroyPixelStream() deallocates memory associated with the pixel stream.
187%
188% The format of the DestroyPixelStream() method is:
189%
190% void DestroyPixelStream(Image *image)
191%
192% A description of each parameter follows:
193%
194% o image: the image.
195%
196*/
197
198static inline void RelinquishStreamPixels(CacheInfo *cache_info)
199{
200 assert(cache_info != (CacheInfo *) NULL);
201 if (cache_info->mapped == MagickFalse)
202 (void) RelinquishMagickMemory(cache_info->pixels);
203 else
204 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000205 cache_info->pixels=(Quantum *) NULL;
206 cache_info->metacontent=(void *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000207 cache_info->length=0;
208 cache_info->mapped=MagickFalse;
209}
210
211static void DestroyPixelStream(Image *image)
212{
213 CacheInfo
214 *cache_info;
215
216 MagickBooleanType
217 destroy;
218
219 assert(image != (Image *) NULL);
220 assert(image->signature == MagickSignature);
221 if (image->debug != MagickFalse)
222 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
223 cache_info=(CacheInfo *) image->cache;
224 assert(cache_info->signature == MagickSignature);
225 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000226 LockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000227 cache_info->reference_count--;
228 if (cache_info->reference_count == 0)
229 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +0000230 UnlockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000231 if (destroy == MagickFalse)
232 return;
233 RelinquishStreamPixels(cache_info);
234 if (cache_info->nexus_info != (NexusInfo **) NULL)
235 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
236 cache_info->number_threads);
237 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
238 DestroySemaphoreInfo(&cache_info->disk_semaphore);
239 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
240 DestroySemaphoreInfo(&cache_info->semaphore);
241 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
242}
243
244/*
245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246% %
247% %
248% %
249+ D e s t r o y S t r e a m I n f o %
250% %
251% %
252% %
253%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254%
255% DestroyStreamInfo() destroys memory associated with the StreamInfo
256% structure.
257%
258% The format of the DestroyStreamInfo method is:
259%
260% StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
261%
262% A description of each parameter follows:
263%
264% o stream_info: the stream info.
265%
266*/
267MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
268{
269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
270 assert(stream_info != (StreamInfo *) NULL);
271 assert(stream_info->signature == MagickSignature);
272 if (stream_info->map != (char *) NULL)
273 stream_info->map=DestroyString(stream_info->map);
274 if (stream_info->pixels != (unsigned char *) NULL)
275 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
276 stream_info->pixels);
277 if (stream_info->stream != (Image *) NULL)
278 {
279 (void) CloseBlob(stream_info->stream);
280 stream_info->stream=DestroyImage(stream_info->stream);
281 }
282 if (stream_info->quantum_info != (QuantumInfo *) NULL)
283 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
284 stream_info->signature=(~MagickSignature);
285 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
286 return(stream_info);
287}
288
289/*
290%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291% %
292% %
293% %
cristy4c08aed2011-07-01 19:47:50 +0000294+ 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 +0000295% %
296% %
297% %
298%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299%
cristy4c08aed2011-07-01 19:47:50 +0000300% GetAuthenticMetacontentFromStream() returns the metacontent corresponding
301% with the last call to QueueAuthenticPixelsStream() or
302% GetAuthenticPixelsStream().
cristy3ed852e2009-09-05 21:47:34 +0000303%
cristy4c08aed2011-07-01 19:47:50 +0000304% The format of the GetAuthenticMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000305%
cristy4c08aed2011-07-01 19:47:50 +0000306% void *GetAuthenticMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000307%
308% A description of each parameter follows:
309%
310% o image: the image.
311%
312*/
cristy4c08aed2011-07-01 19:47:50 +0000313static void *GetAuthenticMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000314{
315 CacheInfo
316 *cache_info;
317
318 assert(image != (Image *) NULL);
319 assert(image->signature == MagickSignature);
320 if (image->debug != MagickFalse)
321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
322 cache_info=(CacheInfo *) image->cache;
323 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000324 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000325}
326
327/*
328%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329% %
330% %
331% %
332+ G e t A u t h e n t i c P i x e l S t r e a m %
333% %
334% %
335% %
336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337%
338% GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
339% cache as defined by the geometry parameters. A pointer to the pixels is
340% returned if the pixels are transferred, otherwise a NULL is returned. For
341% streams this method is a no-op.
342%
343% The format of the GetAuthenticPixelsStream() method is:
344%
cristy4c08aed2011-07-01 19:47:50 +0000345% Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000346% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000347% ExceptionInfo *exception)
348%
349% A description of each parameter follows:
350%
351% o image: the image.
352%
353% o x,y,columns,rows: These values define the perimeter of a region of
354% pixels.
355%
356% o exception: return any errors or warnings in this structure.
357%
358*/
cristy4c08aed2011-07-01 19:47:50 +0000359static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000360 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000361 ExceptionInfo *exception)
362{
cristy4c08aed2011-07-01 19:47:50 +0000363 Quantum
cristy3ed852e2009-09-05 21:47:34 +0000364 *pixels;
365
366 assert(image != (Image *) NULL);
367 assert(image->signature == MagickSignature);
368 if (image->debug != MagickFalse)
369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
370 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
371 return(pixels);
372}
373
374/*
375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376% %
377% %
378% %
379+ 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 %
380% %
381% %
382% %
383%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384%
385% GetAuthenticPixelsFromStream() returns the pixels associated with the last
386% call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
387%
388% The format of the GetAuthenticPixelsFromStream() method is:
389%
cristy4c08aed2011-07-01 19:47:50 +0000390% Quantum *GetAuthenticPixelsFromStream(const Image image)
cristy3ed852e2009-09-05 21:47:34 +0000391%
392% A description of each parameter follows:
393%
394% o image: the image.
395%
396*/
cristy4c08aed2011-07-01 19:47:50 +0000397static Quantum *GetAuthenticPixelsFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000398{
399 CacheInfo
400 *cache_info;
401
402 assert(image != (Image *) NULL);
403 assert(image->signature == MagickSignature);
404 if (image->debug != MagickFalse)
405 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
406 cache_info=(CacheInfo *) image->cache;
407 assert(cache_info->signature == MagickSignature);
408 return(cache_info->pixels);
409}
410
411/*
412%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413% %
414% %
415% %
416+ 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 %
417% %
418% %
419% %
420%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421%
422% GetOneAuthenticPixelFromStream() returns a single pixel at the specified
423% (x,y) location. The image background color is returned if an error occurs.
424%
425% The format of the GetOneAuthenticPixelFromStream() method is:
426%
427% MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
cristycfae90a2010-10-04 14:43:33 +0000428% const ssize_t x,const ssize_t y,PixelPacket *pixel,
429% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000430%
431% A description of each parameter follows:
432%
433% o image: the image.
434%
435% o pixel: return a pixel at the specified (x,y) location.
436%
437% o x,y: These values define the location of the pixel to return.
438%
439% o exception: return any errors or warnings in this structure.
440%
441*/
442static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
cristybb503372010-05-27 20:51:26 +0000443 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000444{
cristy4c08aed2011-07-01 19:47:50 +0000445 register Quantum
446 *q;
cristy3ed852e2009-09-05 21:47:34 +0000447
448 assert(image != (Image *) NULL);
449 assert(image->signature == MagickSignature);
450 *pixel=image->background_color;
cristy4c08aed2011-07-01 19:47:50 +0000451 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
452 if (q != (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000453 return(MagickFalse);
cristy4c08aed2011-07-01 19:47:50 +0000454 GetPixelPacket(image,q,pixel);
cristy3ed852e2009-09-05 21:47:34 +0000455 return(MagickTrue);
456}
457
458/*
459%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460% %
461% %
462% %
463+ 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 %
464% %
465% %
466% %
467%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468%
469% GetOneVirtualPixelFromStream() returns a single pixel at the specified
470% (x.y) location. The image background color is returned if an error occurs.
471%
472% The format of the GetOneVirtualPixelFromStream() method is:
473%
474% MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
cristybb503372010-05-27 20:51:26 +0000475% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
476% const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000477%
478% A description of each parameter follows:
479%
480% o image: the image.
481%
482% o virtual_pixel_method: the virtual pixel method.
483%
484% o x,y: These values define the location of the pixel to return.
485%
486% o pixel: return a pixel at the specified (x,y) location.
487%
488% o exception: return any errors or warnings in this structure.
489%
490*/
491static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000492 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +0000493 PixelPacket *pixel,ExceptionInfo *exception)
494{
cristy4c08aed2011-07-01 19:47:50 +0000495 const Quantum
cristy01cdc902011-08-31 01:05:44 +0000496 *p;
cristy3ed852e2009-09-05 21:47:34 +0000497
498 assert(image != (Image *) NULL);
499 assert(image->signature == MagickSignature);
500 *pixel=image->background_color;
cristy01cdc902011-08-31 01:05:44 +0000501 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
502 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000503 return(MagickFalse);
cristy01cdc902011-08-31 01:05:44 +0000504 GetPixelPacket(image,p,pixel);
505 if (image->colorspace == CMYKColorspace)
506 pixel->black=GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000507 return(MagickTrue);
508}
509
510/*
511%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512% %
513% %
514% %
515+ G e t S t r e a m I n f o C l i e n t D a t a %
516% %
517% %
518% %
519%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520%
521% GetStreamInfoClientData() gets the stream info client data.
522%
cristy7832dc22011-09-05 01:21:53 +0000523% The format of the GetStreamInfoClientData method is:
cristy3ed852e2009-09-05 21:47:34 +0000524%
525% const void *GetStreamInfoClientData(StreamInfo *stream_info)
526%
527% A description of each parameter follows:
528%
529% o stream_info: the stream info.
530%
531*/
cristy7832dc22011-09-05 01:21:53 +0000532MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
cristy3ed852e2009-09-05 21:47:34 +0000533{
534 assert(stream_info != (StreamInfo *) NULL);
535 assert(stream_info->signature == MagickSignature);
536 return(stream_info->client_data);
537}
538
539/*
540%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541% %
542% %
543% %
544+ 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 %
545% %
546% %
547% %
548%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549%
550% GetVirtualPixelsStream() returns the pixels associated with the last
551% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
552%
553% The format of the GetVirtualPixelsStream() method is:
554%
cristy4c08aed2011-07-01 19:47:50 +0000555% const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000556%
557% A description of each parameter follows:
558%
cristy4c08aed2011-07-01 19:47:50 +0000559% o pixels: return the pixels associated corresponding with the last call to
cristy3ed852e2009-09-05 21:47:34 +0000560% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
561%
562% o image: the image.
563%
564*/
cristy4c08aed2011-07-01 19:47:50 +0000565static const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000566{
567 CacheInfo
568 *cache_info;
569
570 assert(image != (Image *) NULL);
571 assert(image->signature == MagickSignature);
572 if (image->debug != MagickFalse)
573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
574 cache_info=(CacheInfo *) image->cache;
575 assert(cache_info->signature == MagickSignature);
576 return(cache_info->pixels);
577}
578
579/*
580%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581% %
582% %
583% %
584+ 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 %
585% %
586% %
587% %
588%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589%
cristy4c08aed2011-07-01 19:47:50 +0000590% GetVirtualMetacontentFromStream() returns the associated pixel
591% channels corresponding with the last call to QueueAuthenticPixelsStream() or
592% GetVirtualPixelStream().
cristy3ed852e2009-09-05 21:47:34 +0000593%
cristy4c08aed2011-07-01 19:47:50 +0000594% The format of the GetVirtualMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000595%
cristy4c08aed2011-07-01 19:47:50 +0000596% const void *GetVirtualMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000597%
598% A description of each parameter follows:
599%
600% o image: the image.
601%
602*/
cristy4c08aed2011-07-01 19:47:50 +0000603static const void *GetVirtualMetacontentFromStream(
604 const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000605{
606 CacheInfo
607 *cache_info;
608
609 assert(image != (Image *) NULL);
610 assert(image->signature == MagickSignature);
611 if (image->debug != MagickFalse)
612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
613 cache_info=(CacheInfo *) image->cache;
614 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000615 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000616}
617
618/*
619%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620% %
621% %
622% %
623+ G e t V i r t u a l P i x e l S t r e a m %
624% %
625% %
626% %
627%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628%
629% GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
630% defined by the geometry parameters. A pointer to the pixels is returned if
631% the pixels are transferred, otherwise a NULL is returned. For streams this
632% method is a no-op.
633%
634% The format of the GetVirtualPixelStream() method is:
635%
cristy4c08aed2011-07-01 19:47:50 +0000636% const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000637% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
638% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000639% ExceptionInfo *exception)
640%
641% A description of each parameter follows:
642%
643% o image: the image.
644%
645% o virtual_pixel_method: the virtual pixel method.
646%
647% o x,y,columns,rows: These values define the perimeter of a region of
648% pixels.
649%
650% o exception: return any errors or warnings in this structure.
651%
652*/
653
654static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
655 ExceptionInfo *exception)
656{
657 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
658 return(MagickFalse);
659 cache_info->mapped=MagickFalse;
cristy4c08aed2011-07-01 19:47:50 +0000660 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
cristy3ed852e2009-09-05 21:47:34 +0000661 cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000662 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000663 {
664 cache_info->mapped=MagickTrue;
cristy4c08aed2011-07-01 19:47:50 +0000665 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
cristy3ed852e2009-09-05 21:47:34 +0000666 cache_info->length);
667 }
cristy4c08aed2011-07-01 19:47:50 +0000668 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000669 {
670 (void) ThrowMagickException(exception,GetMagickModule(),
671 ResourceLimitError,"MemoryAllocationFailed","`%s'",
672 cache_info->filename);
673 return(MagickFalse);
674 }
675 return(MagickTrue);
676}
677
cristy4c08aed2011-07-01 19:47:50 +0000678static const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000679 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
680 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000681 ExceptionInfo *exception)
682{
683 CacheInfo
684 *cache_info;
685
686 MagickBooleanType
687 status;
688
689 MagickSizeType
690 number_pixels;
691
692 size_t
693 length;
694
695 /*
696 Validate pixel cache geometry.
697 */
698 assert(image != (const Image *) NULL);
699 assert(image->signature == MagickSignature);
700 if (image->debug != MagickFalse)
701 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy5dd71882010-08-01 20:53:13 +0000702 if ((x < 0) || (y < 0) ||
703 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
704 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
705 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000706 {
707 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
708 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000709 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000710 }
711 cache_info=(CacheInfo *) image->cache;
712 assert(cache_info->signature == MagickSignature);
713 /*
714 Pixels are stored in a temporary buffer until they are synced to the cache.
715 */
716 number_pixels=(MagickSizeType) columns*rows;
cristyed231572011-07-14 02:18:59 +0000717 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
cristy4c08aed2011-07-01 19:47:50 +0000718 if (cache_info->metacontent_extent != 0)
719 length+=number_pixels*cache_info->metacontent_extent;
720 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000721 {
722 cache_info->length=length;
723 status=AcquireStreamPixels(cache_info,exception);
724 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000725 {
726 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000727 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000728 }
cristy3ed852e2009-09-05 21:47:34 +0000729 }
730 else
731 if (cache_info->length != length)
732 {
733 RelinquishStreamPixels(cache_info);
734 cache_info->length=length;
735 status=AcquireStreamPixels(cache_info,exception);
736 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000737 {
738 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000739 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000740 }
cristy3ed852e2009-09-05 21:47:34 +0000741 }
cristy4c08aed2011-07-01 19:47:50 +0000742 cache_info->metacontent=(void *) NULL;
743 if (cache_info->metacontent_extent != 0)
744 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
cristyed231572011-07-14 02:18:59 +0000745 cache_info->number_channels);
cristy3ed852e2009-09-05 21:47:34 +0000746 return(cache_info->pixels);
747}
748
749/*
750%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751% %
752% %
753% %
754+ O p e n S t r e a m %
755% %
756% %
757% %
758%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759%
760% OpenStream() opens a stream for writing by the StreamImage() method.
761%
762% The format of the OpenStream method is:
763%
764% MagickBooleanType OpenStream(const ImageInfo *image_info,
765% StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
766%
767% A description of each parameter follows:
768%
769% o image_info: the image info.
770%
771% o stream_info: the stream info.
772%
773% o filename: the stream filename.
774%
775% o exception: return any errors or warnings in this structure.
776%
777*/
778MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
779 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
780{
781 MagickBooleanType
782 status;
783
784 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
785 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
786 return(status);
787}
788
789/*
790%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791% %
792% %
793% %
794+ 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 %
795% %
796% %
797% %
798%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
799%
800% QueueAuthenticPixelsStream() allocates an area to store image pixels as
801% defined by the region rectangle and returns a pointer to the area. This
802% area is subsequently transferred from the pixel cache with method
803% SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
804% pixels are transferred, otherwise a NULL is returned.
805%
806% The format of the QueueAuthenticPixelsStream() method is:
807%
cristy4c08aed2011-07-01 19:47:50 +0000808% Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000809% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000810% ExceptionInfo *exception)
811%
812% A description of each parameter follows:
813%
814% o image: the image.
815%
816% o x,y,columns,rows: These values define the perimeter of a region of
817% pixels.
818%
819*/
cristy4c08aed2011-07-01 19:47:50 +0000820static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000821 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000822 ExceptionInfo *exception)
823{
824 CacheInfo
825 *cache_info;
826
827 MagickSizeType
828 number_pixels;
829
830 size_t
831 length;
832
833 StreamHandler
834 stream_handler;
835
836 /*
837 Validate pixel cache geometry.
838 */
839 assert(image != (Image *) NULL);
cristycfae90a2010-10-04 14:43:33 +0000840 if ((x < 0) || (y < 0) ||
841 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
842 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
843 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000844 {
845 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
846 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000847 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000848 }
849 stream_handler=GetBlobStreamHandler(image);
850 if (stream_handler == (StreamHandler) NULL)
851 {
852 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
853 "NoStreamHandlerIsDefined","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000854 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000855 }
856 cache_info=(CacheInfo *) image->cache;
857 assert(cache_info->signature == MagickSignature);
858 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
859 (image->colorspace != GetPixelCacheColorspace(image->cache)))
860 {
861 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
862 (void) stream_handler(image,(const void *) NULL,(size_t)
863 cache_info->columns);
864 cache_info->storage_class=image->storage_class;
865 cache_info->colorspace=image->colorspace;
866 cache_info->columns=image->columns;
867 cache_info->rows=image->rows;
868 image->cache=cache_info;
869 }
870 /*
871 Pixels are stored in a temporary buffer until they are synced to the cache.
872 */
873 cache_info->columns=columns;
874 cache_info->rows=rows;
875 number_pixels=(MagickSizeType) columns*rows;
cristyed231572011-07-14 02:18:59 +0000876 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
cristy4c08aed2011-07-01 19:47:50 +0000877 if (cache_info->metacontent_extent != 0)
878 length+=number_pixels*cache_info->metacontent_extent;
879 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000880 {
cristy4c08aed2011-07-01 19:47:50 +0000881 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
cristy3ed852e2009-09-05 21:47:34 +0000882 cache_info->length=(MagickSizeType) length;
883 }
884 else
885 if (cache_info->length < (MagickSizeType) length)
886 {
cristy4c08aed2011-07-01 19:47:50 +0000887 cache_info->pixels=(Quantum *) ResizeMagickMemory(
cristy3ed852e2009-09-05 21:47:34 +0000888 cache_info->pixels,length);
889 cache_info->length=(MagickSizeType) length;
890 }
891 if (cache_info->pixels == (void *) NULL)
cristy4c08aed2011-07-01 19:47:50 +0000892 return((Quantum *) NULL);
893 cache_info->metacontent=(void *) NULL;
894 if (cache_info->metacontent_extent != 0)
895 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
cristyed231572011-07-14 02:18:59 +0000896 cache_info->number_channels);
cristy3ed852e2009-09-05 21:47:34 +0000897 return(cache_info->pixels);
898}
899
900/*
901%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
902% %
903% %
904% %
905% R e a d S t r e a m %
906% %
907% %
908% %
909%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
910%
911% ReadStream() makes the image pixels available to a user supplied callback
912% method immediately upon reading a scanline with the ReadImage() method.
913%
914% The format of the ReadStream() method is:
915%
916% Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
917% ExceptionInfo *exception)
918%
919% A description of each parameter follows:
920%
921% o image_info: the image info.
922%
923% o stream: a callback method.
924%
925% o exception: return any errors or warnings in this structure.
926%
927*/
928MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
929 ExceptionInfo *exception)
930{
931 CacheMethods
932 cache_methods;
933
934 Image
935 *image;
936
937 ImageInfo
938 *read_info;
939
940 /*
941 Stream image pixels.
942 */
943 assert(image_info != (ImageInfo *) NULL);
944 assert(image_info->signature == MagickSignature);
945 if (image_info->debug != MagickFalse)
946 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
947 image_info->filename);
948 assert(exception != (ExceptionInfo *) NULL);
949 assert(exception->signature == MagickSignature);
950 read_info=CloneImageInfo(image_info);
951 read_info->cache=AcquirePixelCache(0);
952 GetPixelCacheMethods(&cache_methods);
953 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
cristy4c08aed2011-07-01 19:47:50 +0000954 cache_methods.get_virtual_metacontent_from_handler=
955 GetVirtualMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000956 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
957 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
958 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
959 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
960 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
cristy4c08aed2011-07-01 19:47:50 +0000961 cache_methods.get_authentic_metacontent_from_handler=
962 GetAuthenticMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000963 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
964 cache_methods.get_one_authentic_pixel_from_handler=
965 GetOneAuthenticPixelFromStream;
966 cache_methods.destroy_pixel_handler=DestroyPixelStream;
967 SetPixelCacheMethods(read_info->cache,&cache_methods);
968 read_info->stream=stream;
969 image=ReadImage(read_info,exception);
970 read_info=DestroyImageInfo(read_info);
971 return(image);
972}
973
974/*
975%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976% %
977% %
978% %
979+ S e t S t r e a m I n f o C l i e n t D a t a %
980% %
981% %
982% %
983%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
984%
985% SetStreamInfoClientData() sets the stream info client data.
986%
987% The format of the SetStreamInfoClientData method is:
988%
989% void SetStreamInfoClientData(StreamInfo *stream_info,
990% const void *client_data)
991%
992% A description of each parameter follows:
993%
994% o stream_info: the stream info.
995%
996% o client_data: the client data.
997%
998*/
cristy7832dc22011-09-05 01:21:53 +0000999MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
cristy3ed852e2009-09-05 21:47:34 +00001000 const void *client_data)
1001{
1002 assert(stream_info != (StreamInfo *) NULL);
1003 assert(stream_info->signature == MagickSignature);
1004 stream_info->client_data=client_data;
1005}
1006
1007/*
1008%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009% %
1010% %
1011% %
1012+ S e t S t r e a m I n f o M a p %
1013% %
1014% %
1015% %
1016%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017%
1018% SetStreamInfoMap() sets the stream info map member.
1019%
1020% The format of the SetStreamInfoMap method is:
1021%
1022% void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1023%
1024% A description of each parameter follows:
1025%
1026% o stream_info: the stream info.
1027%
1028% o map: the map.
1029%
1030*/
1031MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1032{
1033 assert(stream_info != (StreamInfo *) NULL);
1034 assert(stream_info->signature == MagickSignature);
1035 (void) CloneString(&stream_info->map,map);
1036}
1037
1038/*
1039%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040% %
1041% %
1042% %
1043+ S e t S t r e a m I n f o S t o r a g e T y p e %
1044% %
1045% %
1046% %
1047%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048%
1049% SetStreamInfoStorageType() sets the stream info storage type member.
1050%
1051% The format of the SetStreamInfoStorageType method is:
1052%
1053% void SetStreamInfoStorageType(StreamInfo *stream_info,
1054% const StoreageType *storage_type)
1055%
1056% A description of each parameter follows:
1057%
1058% o stream_info: the stream info.
1059%
1060% o storage_type: the storage type.
1061%
1062*/
1063MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1064 const StorageType storage_type)
1065{
1066 assert(stream_info != (StreamInfo *) NULL);
1067 assert(stream_info->signature == MagickSignature);
1068 stream_info->storage_type=storage_type;
1069}
1070
1071/*
1072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1073% %
1074% %
1075% %
1076+ S t r e a m I m a g e %
1077% %
1078% %
1079% %
1080%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081%
1082% StreamImage() streams pixels from an image and writes them in a user
1083% defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1084%
cristyd212bd02011-02-13 17:08:57 +00001085% The format of the StreamImage() method is:
cristy3ed852e2009-09-05 21:47:34 +00001086%
1087% Image *StreamImage(const ImageInfo *image_info,
1088% StreamInfo *stream_info,ExceptionInfo *exception)
1089%
1090% A description of each parameter follows:
1091%
1092% o image_info: the image info.
1093%
1094% o stream_info: the stream info.
1095%
1096% o exception: return any errors or warnings in this structure.
1097%
1098*/
1099
1100#if defined(__cplusplus) || defined(c_plusplus)
1101extern "C" {
1102#endif
1103
1104static size_t WriteStreamImage(const Image *image,const void *pixels,
1105 const size_t columns)
1106{
cristye3664f42010-05-14 00:59:57 +00001107 CacheInfo
1108 *cache_info;
1109
cristy3ed852e2009-09-05 21:47:34 +00001110 RectangleInfo
1111 extract_info;
1112
1113 size_t
1114 length,
1115 packet_size;
1116
1117 ssize_t
1118 count;
1119
1120 StreamInfo
1121 *stream_info;
1122
cristy654fdaf2011-02-24 15:24:33 +00001123 (void) pixels;
cristy3ed852e2009-09-05 21:47:34 +00001124 stream_info=(StreamInfo *) image->client_data;
1125 switch (stream_info->storage_type)
1126 {
1127 default: packet_size=sizeof(char); break;
1128 case CharPixel: packet_size=sizeof(char); break;
1129 case DoublePixel: packet_size=sizeof(double); break;
1130 case FloatPixel: packet_size=sizeof(float); break;
1131 case IntegerPixel: packet_size=sizeof(int); break;
cristybb503372010-05-27 20:51:26 +00001132 case LongPixel: packet_size=sizeof(ssize_t); break;
cristy3ed852e2009-09-05 21:47:34 +00001133 case QuantumPixel: packet_size=sizeof(Quantum); break;
1134 case ShortPixel: packet_size=sizeof(unsigned short); break;
1135 }
cristye3664f42010-05-14 00:59:57 +00001136 cache_info=(CacheInfo *) image->cache;
1137 assert(cache_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001138 packet_size*=strlen(stream_info->map);
cristye3664f42010-05-14 00:59:57 +00001139 length=packet_size*cache_info->columns*cache_info->rows;
cristy3ed852e2009-09-05 21:47:34 +00001140 if (image != stream_info->image)
1141 {
1142 ImageInfo
1143 *write_info;
1144
1145 /*
1146 Prepare stream for writing.
1147 */
1148 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1149 stream_info->pixels,length,sizeof(*stream_info->pixels));
cristy5dd71882010-08-01 20:53:13 +00001150 if (stream_info->pixels == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001151 return(0);
1152 stream_info->image=image;
1153 write_info=CloneImageInfo(stream_info->image_info);
cristyd965a422010-03-03 17:47:35 +00001154 (void) SetImageInfo(write_info,1,stream_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001155 if (write_info->extract != (char *) NULL)
1156 (void) ParseAbsoluteGeometry(write_info->extract,
1157 &stream_info->extract_info);
1158 stream_info->y=0;
1159 write_info=DestroyImageInfo(write_info);
1160 }
1161 extract_info=stream_info->extract_info;
cristyd212bd02011-02-13 17:08:57 +00001162 if ((extract_info.width == 0) || (extract_info.height == 0))
cristy3ed852e2009-09-05 21:47:34 +00001163 {
1164 /*
1165 Write all pixels to stream.
1166 */
1167 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1168 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1169 stream_info->y++;
1170 return(count == 0 ? 0 : columns);
1171 }
1172 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001173 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001174 {
1175 stream_info->y++;
1176 return(columns);
1177 }
1178 /*
1179 Write a portion of the pixel row to the stream.
1180 */
1181 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1182 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001183 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1184 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001185 stream_info->y++;
1186 return(count == 0 ? 0 : columns);
1187}
1188
1189#if defined(__cplusplus) || defined(c_plusplus)
1190}
1191#endif
1192
1193MagickExport Image *StreamImage(const ImageInfo *image_info,
1194 StreamInfo *stream_info,ExceptionInfo *exception)
1195{
1196 Image
1197 *image;
1198
1199 ImageInfo
1200 *read_info;
1201
1202 assert(image_info != (const ImageInfo *) NULL);
1203 assert(image_info->signature == MagickSignature);
1204 if (image_info->debug != MagickFalse)
1205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1206 image_info->filename);
1207 assert(stream_info != (StreamInfo *) NULL);
1208 assert(stream_info->signature == MagickSignature);
1209 assert(exception != (ExceptionInfo *) NULL);
1210 read_info=CloneImageInfo(image_info);
1211 stream_info->image_info=image_info;
1212 stream_info->exception=exception;
1213 read_info->client_data=(void *) stream_info;
1214 image=ReadStream(read_info,&WriteStreamImage,exception);
1215 read_info=DestroyImageInfo(read_info);
1216 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1217 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1218 image=DestroyImage(image);
1219 return(image);
1220}
1221
1222/*
1223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224% %
1225% %
1226% %
1227+ S t r e a m I m a g e P i x e l s %
1228% %
1229% %
1230% %
1231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1232%
1233% StreamImagePixels() extracts pixel data from an image and returns it in the
1234% stream_info->pixels structure in the format as defined by
1235% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1236%
1237% The format of the StreamImagePixels method is:
1238%
1239% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1240% const Image *image,ExceptionInfo *exception)
1241%
1242% A description of each parameter follows:
1243%
1244% o stream_info: the stream info.
1245%
1246% o image: the image.
1247%
1248% o exception: return any errors or warnings in this structure.
1249%
1250*/
1251static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1252 const Image *image,ExceptionInfo *exception)
1253{
1254 QuantumInfo
1255 *quantum_info;
1256
1257 QuantumType
1258 *quantum_map;
1259
cristy4c08aed2011-07-01 19:47:50 +00001260 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001261 *p;
1262
cristyd212bd02011-02-13 17:08:57 +00001263 register ssize_t
1264 i,
1265 x;
1266
cristy3ed852e2009-09-05 21:47:34 +00001267 size_t
1268 length;
1269
1270 assert(stream_info != (StreamInfo *) NULL);
1271 assert(stream_info->signature == MagickSignature);
1272 assert(image != (Image *) NULL);
1273 assert(image->signature == MagickSignature);
1274 if (image->debug != MagickFalse)
1275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1276 length=strlen(stream_info->map);
1277 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1278 if (quantum_map == (QuantumType *) NULL)
1279 {
1280 (void) ThrowMagickException(exception,GetMagickModule(),
1281 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1282 return(MagickFalse);
1283 }
cristybb503372010-05-27 20:51:26 +00001284 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001285 {
1286 switch (stream_info->map[i])
1287 {
1288 case 'A':
1289 case 'a':
1290 {
1291 quantum_map[i]=AlphaQuantum;
1292 break;
1293 }
1294 case 'B':
1295 case 'b':
1296 {
1297 quantum_map[i]=BlueQuantum;
1298 break;
1299 }
1300 case 'C':
1301 case 'c':
1302 {
1303 quantum_map[i]=CyanQuantum;
1304 if (image->colorspace == CMYKColorspace)
1305 break;
1306 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1307 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1308 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1309 return(MagickFalse);
1310 }
1311 case 'g':
1312 case 'G':
1313 {
1314 quantum_map[i]=GreenQuantum;
1315 break;
1316 }
1317 case 'I':
1318 case 'i':
1319 {
1320 quantum_map[i]=IndexQuantum;
1321 break;
1322 }
1323 case 'K':
1324 case 'k':
1325 {
1326 quantum_map[i]=BlackQuantum;
1327 if (image->colorspace == CMYKColorspace)
1328 break;
1329 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1330 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1331 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1332 return(MagickFalse);
1333 }
1334 case 'M':
1335 case 'm':
1336 {
1337 quantum_map[i]=MagentaQuantum;
1338 if (image->colorspace == CMYKColorspace)
1339 break;
1340 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1341 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1342 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1343 return(MagickFalse);
1344 }
1345 case 'o':
1346 case 'O':
1347 {
1348 quantum_map[i]=OpacityQuantum;
1349 break;
1350 }
1351 case 'P':
1352 case 'p':
1353 {
1354 quantum_map[i]=UndefinedQuantum;
1355 break;
1356 }
1357 case 'R':
1358 case 'r':
1359 {
1360 quantum_map[i]=RedQuantum;
1361 break;
1362 }
1363 case 'Y':
1364 case 'y':
1365 {
1366 quantum_map[i]=YellowQuantum;
1367 if (image->colorspace == CMYKColorspace)
1368 break;
1369 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1370 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1371 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1372 return(MagickFalse);
1373 }
1374 default:
1375 {
1376 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1377 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1378 "UnrecognizedPixelMap","`%s'",stream_info->map);
1379 return(MagickFalse);
1380 }
1381 }
1382 }
1383 quantum_info=stream_info->quantum_info;
1384 switch (stream_info->storage_type)
1385 {
1386 case CharPixel:
1387 {
1388 register unsigned char
1389 *q;
1390
1391 q=(unsigned char *) stream_info->pixels;
1392 if (LocaleCompare(stream_info->map,"BGR") == 0)
1393 {
1394 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001395 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001396 break;
cristybb503372010-05-27 20:51:26 +00001397 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001398 {
cristy4c08aed2011-07-01 19:47:50 +00001399 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1400 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1401 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001402 p++;
1403 }
1404 break;
1405 }
1406 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1407 {
1408 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001409 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001410 break;
cristybb503372010-05-27 20:51:26 +00001411 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001412 {
cristy4c08aed2011-07-01 19:47:50 +00001413 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1414 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1415 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1416 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001417 p++;
1418 }
1419 break;
1420 }
1421 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1422 {
1423 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001424 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001425 break;
cristybb503372010-05-27 20:51:26 +00001426 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001427 {
cristy4c08aed2011-07-01 19:47:50 +00001428 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1429 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1430 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001431 *q++=ScaleQuantumToChar((Quantum) 0);
1432 p++;
1433 }
1434 break;
1435 }
1436 if (LocaleCompare(stream_info->map,"I") == 0)
1437 {
1438 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001439 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001440 break;
cristybb503372010-05-27 20:51:26 +00001441 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001442 {
cristy4c08aed2011-07-01 19:47:50 +00001443 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001444 p++;
1445 }
1446 break;
1447 }
1448 if (LocaleCompare(stream_info->map,"RGB") == 0)
1449 {
1450 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001451 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001452 break;
cristybb503372010-05-27 20:51:26 +00001453 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001454 {
cristy4c08aed2011-07-01 19:47:50 +00001455 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1456 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1457 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001458 p++;
1459 }
1460 break;
1461 }
1462 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1463 {
1464 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001465 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001466 break;
cristybb503372010-05-27 20:51:26 +00001467 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001468 {
cristy4c08aed2011-07-01 19:47:50 +00001469 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1470 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1471 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1472 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001473 p++;
1474 }
1475 break;
1476 }
1477 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1478 {
1479 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001480 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001481 break;
cristybb503372010-05-27 20:51:26 +00001482 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001483 {
cristy4c08aed2011-07-01 19:47:50 +00001484 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1485 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1486 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001487 *q++=ScaleQuantumToChar((Quantum) 0);
1488 p++;
1489 }
1490 break;
1491 }
1492 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001493 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001494 break;
cristybb503372010-05-27 20:51:26 +00001495 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001496 {
cristybb503372010-05-27 20:51:26 +00001497 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001498 {
1499 *q=0;
1500 switch (quantum_map[i])
1501 {
1502 case RedQuantum:
1503 case CyanQuantum:
1504 {
cristy4c08aed2011-07-01 19:47:50 +00001505 *q=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001506 break;
1507 }
1508 case GreenQuantum:
1509 case MagentaQuantum:
1510 {
cristy4c08aed2011-07-01 19:47:50 +00001511 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001512 break;
1513 }
1514 case BlueQuantum:
1515 case YellowQuantum:
1516 {
cristy4c08aed2011-07-01 19:47:50 +00001517 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001518 break;
1519 }
1520 case AlphaQuantum:
1521 {
cristy4c08aed2011-07-01 19:47:50 +00001522 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001523 break;
1524 }
1525 case OpacityQuantum:
1526 {
cristy4c08aed2011-07-01 19:47:50 +00001527 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001528 break;
1529 }
1530 case BlackQuantum:
1531 {
1532 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001533 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001534 break;
1535 }
1536 case IndexQuantum:
1537 {
cristy4c08aed2011-07-01 19:47:50 +00001538 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001539 break;
1540 }
1541 default:
1542 break;
1543 }
1544 q++;
1545 }
1546 p++;
1547 }
1548 break;
1549 }
1550 case DoublePixel:
1551 {
1552 register double
1553 *q;
1554
1555 q=(double *) stream_info->pixels;
1556 if (LocaleCompare(stream_info->map,"BGR") == 0)
1557 {
1558 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001559 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001560 break;
cristybb503372010-05-27 20:51:26 +00001561 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001562 {
cristy4c08aed2011-07-01 19:47:50 +00001563 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001564 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001565 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001566 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001567 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001568 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001569 p++;
1570 }
1571 break;
1572 }
1573 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1574 {
1575 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001576 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001577 break;
cristybb503372010-05-27 20:51:26 +00001578 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001579 {
cristy4c08aed2011-07-01 19:47:50 +00001580 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001581 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001582 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001583 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001584 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001585 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001586 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001587 quantum_info->scale+quantum_info->minimum);
1588 p++;
1589 }
1590 break;
1591 }
1592 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1593 {
1594 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001595 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001596 break;
cristybb503372010-05-27 20:51:26 +00001597 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001598 {
cristy4c08aed2011-07-01 19:47:50 +00001599 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001600 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001601 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001602 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001603 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001604 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001605 *q++=0.0;
1606 p++;
1607 }
1608 break;
1609 }
1610 if (LocaleCompare(stream_info->map,"I") == 0)
1611 {
1612 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001613 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001614 break;
cristybb503372010-05-27 20:51:26 +00001615 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001616 {
cristy4c08aed2011-07-01 19:47:50 +00001617 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001618 quantum_info->scale+quantum_info->minimum);
1619 p++;
1620 }
1621 break;
1622 }
1623 if (LocaleCompare(stream_info->map,"RGB") == 0)
1624 {
1625 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001626 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001627 break;
cristybb503372010-05-27 20:51:26 +00001628 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001629 {
cristy4c08aed2011-07-01 19:47:50 +00001630 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001631 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001632 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001633 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001634 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001635 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001636 p++;
1637 }
1638 break;
1639 }
1640 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1641 {
1642 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001643 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001644 break;
cristybb503372010-05-27 20:51:26 +00001645 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001646 {
cristy4c08aed2011-07-01 19:47:50 +00001647 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001648 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001649 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001650 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001651 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001652 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001653 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001654 quantum_info->scale+quantum_info->minimum);
1655 p++;
1656 }
1657 break;
1658 }
1659 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1660 {
1661 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001662 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001663 break;
cristybb503372010-05-27 20:51:26 +00001664 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001665 {
cristy4c08aed2011-07-01 19:47:50 +00001666 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001667 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001668 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001669 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001670 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001671 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001672 *q++=0.0;
1673 p++;
1674 }
1675 break;
1676 }
1677 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001678 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001679 break;
cristybb503372010-05-27 20:51:26 +00001680 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001681 {
cristybb503372010-05-27 20:51:26 +00001682 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001683 {
1684 *q=0;
1685 switch (quantum_map[i])
1686 {
1687 case RedQuantum:
1688 case CyanQuantum:
1689 {
cristy4c08aed2011-07-01 19:47:50 +00001690 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001691 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001692 break;
1693 }
1694 case GreenQuantum:
1695 case MagentaQuantum:
1696 {
cristy4c08aed2011-07-01 19:47:50 +00001697 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001698 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001699 break;
1700 }
1701 case BlueQuantum:
1702 case YellowQuantum:
1703 {
cristy4c08aed2011-07-01 19:47:50 +00001704 *q=(double) ((QuantumScale*GetPixelBlue(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 AlphaQuantum:
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 OpacityQuantum:
1715 {
cristy4c08aed2011-07-01 19:47:50 +00001716 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001717 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001718 break;
1719 }
1720 case BlackQuantum:
1721 {
1722 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001723 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001724 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001725 break;
1726 }
1727 case IndexQuantum:
1728 {
cristy4c08aed2011-07-01 19:47:50 +00001729 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001730 quantum_info->scale+quantum_info->minimum);
1731 break;
1732 }
1733 default:
1734 *q=0;
1735 }
1736 q++;
1737 }
1738 p++;
1739 }
1740 break;
1741 }
1742 case FloatPixel:
1743 {
1744 register float
1745 *q;
1746
1747 q=(float *) stream_info->pixels;
1748 if (LocaleCompare(stream_info->map,"BGR") == 0)
1749 {
1750 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001751 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001752 break;
cristybb503372010-05-27 20:51:26 +00001753 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001754 {
cristy4c08aed2011-07-01 19:47:50 +00001755 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001756 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001757 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001758 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001759 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001760 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001761 p++;
1762 }
1763 break;
1764 }
1765 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1766 {
1767 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001768 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001769 break;
cristybb503372010-05-27 20:51:26 +00001770 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001771 {
cristy4c08aed2011-07-01 19:47:50 +00001772 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001773 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001774 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001775 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001776 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001777 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001778 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
cristy3ed852e2009-09-05 21:47:34 +00001779 quantum_info->scale+quantum_info->minimum);
1780 p++;
1781 }
1782 break;
1783 }
1784 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1785 {
1786 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001787 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001788 break;
cristybb503372010-05-27 20:51:26 +00001789 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001790 {
cristy4c08aed2011-07-01 19:47:50 +00001791 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001792 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001793 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001794 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001795 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001796 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001797 *q++=0.0;
1798 p++;
1799 }
1800 break;
1801 }
1802 if (LocaleCompare(stream_info->map,"I") == 0)
1803 {
1804 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001805 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001806 break;
cristybb503372010-05-27 20:51:26 +00001807 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001808 {
cristy4c08aed2011-07-01 19:47:50 +00001809 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001810 quantum_info->scale+quantum_info->minimum);
1811 p++;
1812 }
1813 break;
1814 }
1815 if (LocaleCompare(stream_info->map,"RGB") == 0)
1816 {
1817 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001818 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001819 break;
cristybb503372010-05-27 20:51:26 +00001820 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001821 {
cristy4c08aed2011-07-01 19:47:50 +00001822 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001823 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001824 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001825 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001826 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001827 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001828 p++;
1829 }
1830 break;
1831 }
1832 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1833 {
1834 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001835 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001836 break;
cristybb503372010-05-27 20:51:26 +00001837 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001838 {
cristy4c08aed2011-07-01 19:47:50 +00001839 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001840 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001841 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001842 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001843 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001844 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001845 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001846 quantum_info->scale+quantum_info->minimum);
1847 p++;
1848 }
1849 break;
1850 }
1851 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1852 {
1853 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001854 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001855 break;
cristybb503372010-05-27 20:51:26 +00001856 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001857 {
cristy4c08aed2011-07-01 19:47:50 +00001858 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001859 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001860 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001861 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001862 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001863 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001864 *q++=0.0;
1865 p++;
1866 }
1867 break;
1868 }
1869 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001870 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001871 break;
cristybb503372010-05-27 20:51:26 +00001872 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001873 {
cristybb503372010-05-27 20:51:26 +00001874 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001875 {
1876 *q=0;
1877 switch (quantum_map[i])
1878 {
1879 case RedQuantum:
1880 case CyanQuantum:
1881 {
cristy4c08aed2011-07-01 19:47:50 +00001882 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001883 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001884 break;
1885 }
1886 case GreenQuantum:
1887 case MagentaQuantum:
1888 {
cristy4c08aed2011-07-01 19:47:50 +00001889 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001890 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001891 break;
1892 }
1893 case BlueQuantum:
1894 case YellowQuantum:
1895 {
cristy4c08aed2011-07-01 19:47:50 +00001896 *q=(float) ((QuantumScale*GetPixelBlue(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 AlphaQuantum:
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 OpacityQuantum:
1907 {
cristy4c08aed2011-07-01 19:47:50 +00001908 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001909 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001910 break;
1911 }
1912 case BlackQuantum:
1913 {
1914 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001915 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001916 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001917 break;
1918 }
1919 case IndexQuantum:
1920 {
cristy4c08aed2011-07-01 19:47:50 +00001921 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001922 quantum_info->scale+quantum_info->minimum);
1923 break;
1924 }
1925 default:
1926 *q=0;
1927 }
1928 q++;
1929 }
1930 p++;
1931 }
1932 break;
1933 }
1934 case IntegerPixel:
1935 {
1936 register unsigned int
1937 *q;
1938
1939 q=(unsigned int *) stream_info->pixels;
1940 if (LocaleCompare(stream_info->map,"BGR") == 0)
1941 {
1942 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001943 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001944 break;
cristybb503372010-05-27 20:51:26 +00001945 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001946 {
cristy4c08aed2011-07-01 19:47:50 +00001947 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1948 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1949 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001950 p++;
1951 }
1952 break;
1953 }
1954 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1955 {
1956 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001957 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001958 break;
cristybb503372010-05-27 20:51:26 +00001959 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001960 {
cristy4c08aed2011-07-01 19:47:50 +00001961 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1962 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1963 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1964 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001965 p++;
1966 }
1967 break;
1968 }
1969 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1970 {
1971 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001972 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001973 break;
cristybb503372010-05-27 20:51:26 +00001974 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001975 {
cristy4c08aed2011-07-01 19:47:50 +00001976 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1977 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1978 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001979 *q++=0U;
1980 p++;
1981 }
1982 break;
1983 }
1984 if (LocaleCompare(stream_info->map,"I") == 0)
1985 {
1986 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001987 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001988 break;
cristybb503372010-05-27 20:51:26 +00001989 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001990 {
1991 *q++=(unsigned int) ScaleQuantumToLong(
cristy4c08aed2011-07-01 19:47:50 +00001992 GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001993 p++;
1994 }
1995 break;
1996 }
1997 if (LocaleCompare(stream_info->map,"RGB") == 0)
1998 {
1999 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002000 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002001 break;
cristybb503372010-05-27 20:51:26 +00002002 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002003 {
cristy4c08aed2011-07-01 19:47:50 +00002004 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2005 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2006 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002007 p++;
2008 }
2009 break;
2010 }
2011 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2012 {
2013 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002014 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002015 break;
cristybb503372010-05-27 20:51:26 +00002016 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002017 {
cristy4c08aed2011-07-01 19:47:50 +00002018 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2019 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2020 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002021 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002022 (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002023 p++;
2024 }
2025 break;
2026 }
2027 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2028 {
2029 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002030 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002031 break;
cristybb503372010-05-27 20:51:26 +00002032 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002033 {
cristy4c08aed2011-07-01 19:47:50 +00002034 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2035 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2036 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002037 *q++=0U;
2038 p++;
2039 }
2040 break;
2041 }
2042 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002043 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002044 break;
cristybb503372010-05-27 20:51:26 +00002045 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002046 {
cristybb503372010-05-27 20:51:26 +00002047 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002048 {
2049 *q=0;
2050 switch (quantum_map[i])
2051 {
2052 case RedQuantum:
2053 case CyanQuantum:
2054 {
cristy4c08aed2011-07-01 19:47:50 +00002055 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002056 break;
2057 }
2058 case GreenQuantum:
2059 case MagentaQuantum:
2060 {
cristy4c08aed2011-07-01 19:47:50 +00002061 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002062 break;
2063 }
2064 case BlueQuantum:
2065 case YellowQuantum:
2066 {
cristy4c08aed2011-07-01 19:47:50 +00002067 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002068 break;
2069 }
2070 case AlphaQuantum:
2071 {
cristy4c08aed2011-07-01 19:47:50 +00002072 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002073 break;
2074 }
2075 case OpacityQuantum:
2076 {
cristy4c08aed2011-07-01 19:47:50 +00002077 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002078 break;
2079 }
2080 case BlackQuantum:
2081 {
2082 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002083 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002084 break;
2085 }
2086 case IndexQuantum:
2087 {
2088 *q=(unsigned int)
cristy4c08aed2011-07-01 19:47:50 +00002089 ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002090 break;
2091 }
2092 default:
2093 *q=0;
2094 }
2095 q++;
2096 }
2097 p++;
2098 }
2099 break;
2100 }
2101 case LongPixel:
2102 {
cristybb503372010-05-27 20:51:26 +00002103 register size_t
cristy3ed852e2009-09-05 21:47:34 +00002104 *q;
2105
cristybb503372010-05-27 20:51:26 +00002106 q=(size_t *) stream_info->pixels;
cristy3ed852e2009-09-05 21:47:34 +00002107 if (LocaleCompare(stream_info->map,"BGR") == 0)
2108 {
2109 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002110 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002111 break;
cristybb503372010-05-27 20:51:26 +00002112 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002113 {
cristy4c08aed2011-07-01 19:47:50 +00002114 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2115 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2116 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002117 p++;
2118 }
2119 break;
2120 }
2121 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2122 {
2123 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002124 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002125 break;
cristybb503372010-05-27 20:51:26 +00002126 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002127 {
cristy4c08aed2011-07-01 19:47:50 +00002128 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2129 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2130 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2131 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002132 p++;
2133 }
2134 break;
2135 }
2136 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2137 {
2138 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002139 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002140 break;
cristybb503372010-05-27 20:51:26 +00002141 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002142 {
cristy4c08aed2011-07-01 19:47:50 +00002143 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2144 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2145 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002146 *q++=0;
2147 p++;
2148 }
2149 break;
2150 }
2151 if (LocaleCompare(stream_info->map,"I") == 0)
2152 {
2153 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002154 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002155 break;
cristybb503372010-05-27 20:51:26 +00002156 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002157 {
cristy4c08aed2011-07-01 19:47:50 +00002158 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002159 p++;
2160 }
2161 break;
2162 }
2163 if (LocaleCompare(stream_info->map,"RGB") == 0)
2164 {
2165 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002166 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002167 break;
cristybb503372010-05-27 20:51:26 +00002168 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002169 {
cristy4c08aed2011-07-01 19:47:50 +00002170 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2171 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2172 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002173 p++;
2174 }
2175 break;
2176 }
2177 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2178 {
2179 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002180 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002181 break;
cristybb503372010-05-27 20:51:26 +00002182 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002183 {
cristy4c08aed2011-07-01 19:47:50 +00002184 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2185 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2186 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2187 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002188 p++;
2189 }
2190 break;
2191 }
2192 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2193 {
2194 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002195 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002196 break;
cristybb503372010-05-27 20:51:26 +00002197 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002198 {
cristy4c08aed2011-07-01 19:47:50 +00002199 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2200 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2201 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002202 *q++=0;
2203 p++;
2204 }
2205 break;
2206 }
2207 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002208 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002209 break;
cristybb503372010-05-27 20:51:26 +00002210 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002211 {
cristybb503372010-05-27 20:51:26 +00002212 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002213 {
2214 *q=0;
2215 switch (quantum_map[i])
2216 {
2217 case RedQuantum:
2218 case CyanQuantum:
2219 {
cristy4c08aed2011-07-01 19:47:50 +00002220 *q=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002221 break;
2222 }
2223 case GreenQuantum:
2224 case MagentaQuantum:
2225 {
cristy4c08aed2011-07-01 19:47:50 +00002226 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002227 break;
2228 }
2229 case BlueQuantum:
2230 case YellowQuantum:
2231 {
cristy4c08aed2011-07-01 19:47:50 +00002232 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002233 break;
2234 }
2235 case AlphaQuantum:
2236 {
cristy4c08aed2011-07-01 19:47:50 +00002237 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002238 break;
2239 }
2240 case OpacityQuantum:
2241 {
cristy4c08aed2011-07-01 19:47:50 +00002242 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002243 break;
2244 }
2245 case BlackQuantum:
2246 {
2247 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002248 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002249 break;
2250 }
2251 case IndexQuantum:
2252 {
cristy4c08aed2011-07-01 19:47:50 +00002253 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002254 break;
2255 }
2256 default:
2257 break;
2258 }
2259 q++;
2260 }
2261 p++;
2262 }
2263 break;
2264 }
2265 case QuantumPixel:
2266 {
2267 register Quantum
2268 *q;
2269
2270 q=(Quantum *) stream_info->pixels;
2271 if (LocaleCompare(stream_info->map,"BGR") == 0)
2272 {
2273 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002274 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002275 break;
cristybb503372010-05-27 20:51:26 +00002276 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002277 {
cristy4c08aed2011-07-01 19:47:50 +00002278 *q++=GetPixelBlue(image,p);
2279 *q++=GetPixelGreen(image,p);
2280 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002281 p++;
2282 }
2283 break;
2284 }
2285 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2286 {
2287 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002288 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002289 break;
cristybb503372010-05-27 20:51:26 +00002290 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002291 {
cristy4c08aed2011-07-01 19:47:50 +00002292 *q++=GetPixelBlue(image,p);
2293 *q++=GetPixelGreen(image,p);
2294 *q++=GetPixelRed(image,p);
2295 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002296 p++;
2297 }
2298 break;
2299 }
2300 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2301 {
2302 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002303 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002304 break;
cristybb503372010-05-27 20:51:26 +00002305 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002306 {
cristy4c08aed2011-07-01 19:47:50 +00002307 *q++=GetPixelBlue(image,p);
2308 *q++=GetPixelGreen(image,p);
2309 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002310 *q++=0;
2311 p++;
2312 }
2313 break;
2314 }
2315 if (LocaleCompare(stream_info->map,"I") == 0)
2316 {
2317 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002318 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002319 break;
cristybb503372010-05-27 20:51:26 +00002320 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002321 {
cristy4c08aed2011-07-01 19:47:50 +00002322 *q++=GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002323 p++;
2324 }
2325 break;
2326 }
2327 if (LocaleCompare(stream_info->map,"RGB") == 0)
2328 {
2329 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002330 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002331 break;
cristybb503372010-05-27 20:51:26 +00002332 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002333 {
cristy4c08aed2011-07-01 19:47:50 +00002334 *q++=GetPixelRed(image,p);
2335 *q++=GetPixelGreen(image,p);
2336 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002337 p++;
2338 }
2339 break;
2340 }
2341 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2342 {
2343 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002344 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002345 break;
cristybb503372010-05-27 20:51:26 +00002346 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002347 {
cristy4c08aed2011-07-01 19:47:50 +00002348 *q++=GetPixelRed(image,p);
2349 *q++=GetPixelGreen(image,p);
2350 *q++=GetPixelBlue(image,p);
2351 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002352 p++;
2353 }
2354 break;
2355 }
2356 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2357 {
2358 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002359 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002360 break;
cristybb503372010-05-27 20:51:26 +00002361 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002362 {
cristy4c08aed2011-07-01 19:47:50 +00002363 *q++=GetPixelRed(image,p);
2364 *q++=GetPixelGreen(image,p);
2365 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002366 *q++=0U;
2367 p++;
2368 }
2369 break;
2370 }
2371 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002372 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002373 break;
cristybb503372010-05-27 20:51:26 +00002374 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002375 {
cristybb503372010-05-27 20:51:26 +00002376 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002377 {
2378 *q=(Quantum) 0;
2379 switch (quantum_map[i])
2380 {
2381 case RedQuantum:
2382 case CyanQuantum:
2383 {
cristy4c08aed2011-07-01 19:47:50 +00002384 *q=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002385 break;
2386 }
2387 case GreenQuantum:
2388 case MagentaQuantum:
2389 {
cristy4c08aed2011-07-01 19:47:50 +00002390 *q=GetPixelGreen(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002391 break;
2392 }
2393 case BlueQuantum:
2394 case YellowQuantum:
2395 {
cristy4c08aed2011-07-01 19:47:50 +00002396 *q=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002397 break;
2398 }
2399 case AlphaQuantum:
2400 {
cristy4c08aed2011-07-01 19:47:50 +00002401 *q=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002402 break;
2403 }
2404 case OpacityQuantum:
2405 {
cristy4c08aed2011-07-01 19:47:50 +00002406 *q=GetPixelAlpha(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002407 break;
2408 }
2409 case BlackQuantum:
2410 {
2411 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002412 *q=GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002413 break;
2414 }
2415 case IndexQuantum:
2416 {
cristy4c08aed2011-07-01 19:47:50 +00002417 *q=(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002418 break;
2419 }
2420 default:
2421 *q=0;
2422 }
2423 q++;
2424 }
2425 p++;
2426 }
2427 break;
2428 }
2429 case ShortPixel:
2430 {
2431 register unsigned short
2432 *q;
2433
2434 q=(unsigned short *) stream_info->pixels;
2435 if (LocaleCompare(stream_info->map,"BGR") == 0)
2436 {
2437 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002438 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002439 break;
cristybb503372010-05-27 20:51:26 +00002440 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002441 {
cristy4c08aed2011-07-01 19:47:50 +00002442 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2443 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2444 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002445 p++;
2446 }
2447 break;
2448 }
2449 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2450 {
2451 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002452 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002453 break;
cristybb503372010-05-27 20:51:26 +00002454 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002455 {
cristy4c08aed2011-07-01 19:47:50 +00002456 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2457 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2458 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2459 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002460 p++;
2461 }
2462 break;
2463 }
2464 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2465 {
2466 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002467 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002468 break;
cristybb503372010-05-27 20:51:26 +00002469 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002470 {
cristy4c08aed2011-07-01 19:47:50 +00002471 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2472 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2473 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002474 *q++=0;
2475 p++;
2476 }
2477 break;
2478 }
2479 if (LocaleCompare(stream_info->map,"I") == 0)
2480 {
2481 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002482 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002483 break;
cristybb503372010-05-27 20:51:26 +00002484 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002485 {
cristy4c08aed2011-07-01 19:47:50 +00002486 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002487 p++;
2488 }
2489 break;
2490 }
2491 if (LocaleCompare(stream_info->map,"RGB") == 0)
2492 {
2493 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002494 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002495 break;
cristybb503372010-05-27 20:51:26 +00002496 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002497 {
cristy4c08aed2011-07-01 19:47:50 +00002498 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2499 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2500 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002501 p++;
2502 }
2503 break;
2504 }
2505 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2506 {
2507 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002508 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002509 break;
cristybb503372010-05-27 20:51:26 +00002510 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002511 {
cristy4c08aed2011-07-01 19:47:50 +00002512 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2513 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2514 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2515 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002516 p++;
2517 }
2518 break;
2519 }
2520 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2521 {
2522 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002523 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002524 break;
cristybb503372010-05-27 20:51:26 +00002525 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002526 {
cristy4c08aed2011-07-01 19:47:50 +00002527 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2528 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2529 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002530 *q++=0;
2531 p++;
2532 }
2533 break;
2534 }
2535 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002536 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002537 break;
cristybb503372010-05-27 20:51:26 +00002538 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002539 {
cristybb503372010-05-27 20:51:26 +00002540 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002541 {
2542 *q=0;
2543 switch (quantum_map[i])
2544 {
2545 case RedQuantum:
2546 case CyanQuantum:
2547 {
cristy4c08aed2011-07-01 19:47:50 +00002548 *q=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002549 break;
2550 }
2551 case GreenQuantum:
2552 case MagentaQuantum:
2553 {
cristy4c08aed2011-07-01 19:47:50 +00002554 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002555 break;
2556 }
2557 case BlueQuantum:
2558 case YellowQuantum:
2559 {
cristy4c08aed2011-07-01 19:47:50 +00002560 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002561 break;
2562 }
2563 case AlphaQuantum:
2564 {
cristy4c08aed2011-07-01 19:47:50 +00002565 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002566 break;
2567 }
2568 case OpacityQuantum:
2569 {
cristy4c08aed2011-07-01 19:47:50 +00002570 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002571 break;
2572 }
2573 case BlackQuantum:
2574 {
2575 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002576 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002577 break;
2578 }
2579 case IndexQuantum:
2580 {
cristy4c08aed2011-07-01 19:47:50 +00002581 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002582 break;
2583 }
2584 default:
2585 break;
2586 }
2587 q++;
2588 }
2589 p++;
2590 }
2591 break;
2592 }
2593 default:
2594 {
2595 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2596 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2597 "UnrecognizedPixelMap","`%s'",stream_info->map);
2598 break;
2599 }
2600 }
2601 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2602 return(MagickTrue);
2603}
2604
2605/*
2606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2607% %
2608% %
2609% %
2610+ 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 %
2611% %
2612% %
2613% %
2614%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2615%
2616% SyncAuthenticPixelsStream() calls the user supplied callback method with
2617% the latest stream of pixels.
2618%
2619% The format of the SyncAuthenticPixelsStream method is:
2620%
2621% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2622% ExceptionInfo *exception)
2623%
2624% A description of each parameter follows:
2625%
2626% o image: the image.
2627%
2628% o exception: return any errors or warnings in this structure.
2629%
2630*/
2631static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2632 ExceptionInfo *exception)
2633{
2634 CacheInfo
2635 *cache_info;
2636
2637 size_t
2638 length;
2639
2640 StreamHandler
2641 stream_handler;
2642
2643 assert(image != (Image *) NULL);
2644 assert(image->signature == MagickSignature);
2645 if (image->debug != MagickFalse)
2646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2647 cache_info=(CacheInfo *) image->cache;
2648 assert(cache_info->signature == MagickSignature);
2649 stream_handler=GetBlobStreamHandler(image);
2650 if (stream_handler == (StreamHandler) NULL)
2651 {
2652 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2653 "NoStreamHandlerIsDefined","`%s'",image->filename);
2654 return(MagickFalse);
2655 }
2656 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2657 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2658}
2659
2660/*
2661%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2662% %
2663% %
2664% %
2665% W r i t e S t r e a m %
2666% %
2667% %
2668% %
2669%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2670%
2671% WriteStream() makes the image pixels available to a user supplied callback
2672% method immediately upon writing pixel data with the WriteImage() method.
2673%
2674% The format of the WriteStream() method is:
2675%
2676% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2677% StreamHandler stream)
2678%
2679% A description of each parameter follows:
2680%
2681% o image_info: the image info.
2682%
2683% o stream: A callback method.
2684%
2685*/
2686MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2687 Image *image,StreamHandler stream)
2688{
2689 ImageInfo
2690 *write_info;
2691
2692 MagickBooleanType
2693 status;
2694
2695 assert(image_info != (ImageInfo *) NULL);
2696 assert(image_info->signature == MagickSignature);
2697 if (image_info->debug != MagickFalse)
2698 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2699 image_info->filename);
2700 assert(image != (Image *) NULL);
2701 assert(image->signature == MagickSignature);
2702 write_info=CloneImageInfo(image_info);
2703 write_info->stream=stream;
cristy6f9e0d32011-08-28 16:32:09 +00002704 status=WriteImage(write_info,image,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +00002705 write_info=DestroyImageInfo(write_info);
2706 return(status);
2707}