blob: aa302d4c4c1d25a2f8a5007d3b95926131eef20c [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,
cristy2ed42f62011-10-02 19:49:57 +0000428% const ssize_t x,const ssize_t y,Quantum *pixel,
cristycfae90a2010-10-04 14:43:33 +0000429% 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,
cristy2ed42f62011-10-02 19:49:57 +0000443 const ssize_t x,const ssize_t y,Quantum *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
cristy2ed42f62011-10-02 19:49:57 +0000448 register ssize_t
449 i;
450
cristy3ed852e2009-09-05 21:47:34 +0000451 assert(image != (Image *) NULL);
452 assert(image->signature == MagickSignature);
cristy2ed42f62011-10-02 19:49:57 +0000453 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
cristy4c08aed2011-07-01 19:47:50 +0000454 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
455 if (q != (Quantum *) NULL)
cristy2ed42f62011-10-02 19:49:57 +0000456 {
457 pixel[RedPixelChannel]=image->background_color.red;
458 pixel[GreenPixelChannel]=image->background_color.green;
459 pixel[BluePixelChannel]=image->background_color.blue;
460 pixel[AlphaPixelChannel]=image->background_color.alpha;
461 return(MagickFalse);
462 }
463 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
464 {
465 PixelChannel
466 channel;
467
468 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
469 pixel[channel]=q[i];
470 }
cristy3ed852e2009-09-05 21:47:34 +0000471 return(MagickTrue);
472}
473
474/*
475%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476% %
477% %
478% %
479+ 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 %
480% %
481% %
482% %
483%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484%
485% GetOneVirtualPixelFromStream() returns a single pixel at the specified
486% (x.y) location. The image background color is returned if an error occurs.
487%
488% The format of the GetOneVirtualPixelFromStream() method is:
489%
490% MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
cristybb503372010-05-27 20:51:26 +0000491% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
cristy2ed42f62011-10-02 19:49:57 +0000492% const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000493%
494% A description of each parameter follows:
495%
496% o image: the image.
497%
498% o virtual_pixel_method: the virtual pixel method.
499%
500% o x,y: These values define the location of the pixel to return.
501%
502% o pixel: return a pixel at the specified (x,y) location.
503%
504% o exception: return any errors or warnings in this structure.
505%
506*/
507static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000508 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
cristy2ed42f62011-10-02 19:49:57 +0000509 Quantum *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000510{
cristy4c08aed2011-07-01 19:47:50 +0000511 const Quantum
cristy01cdc902011-08-31 01:05:44 +0000512 *p;
cristy3ed852e2009-09-05 21:47:34 +0000513
cristy2ed42f62011-10-02 19:49:57 +0000514 register ssize_t
515 i;
516
cristy3ed852e2009-09-05 21:47:34 +0000517 assert(image != (Image *) NULL);
518 assert(image->signature == MagickSignature);
cristy2ed42f62011-10-02 19:49:57 +0000519 (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
cristy01cdc902011-08-31 01:05:44 +0000520 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
521 if (p == (const Quantum *) NULL)
cristy2ed42f62011-10-02 19:49:57 +0000522 {
523 pixel[RedPixelChannel]=image->background_color.red;
524 pixel[GreenPixelChannel]=image->background_color.green;
525 pixel[BluePixelChannel]=image->background_color.blue;
526 pixel[AlphaPixelChannel]=image->background_color.alpha;
527 return(MagickFalse);
528 }
529 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
530 {
531 PixelChannel
532 channel;
533
534 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
535 pixel[channel]=p[i];
536 }
cristy3ed852e2009-09-05 21:47:34 +0000537 return(MagickTrue);
538}
539
540/*
541%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542% %
543% %
544% %
545+ G e t S t r e a m I n f o C l i e n t D a t a %
546% %
547% %
548% %
549%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550%
551% GetStreamInfoClientData() gets the stream info client data.
552%
cristy7832dc22011-09-05 01:21:53 +0000553% The format of the GetStreamInfoClientData method is:
cristy3ed852e2009-09-05 21:47:34 +0000554%
555% const void *GetStreamInfoClientData(StreamInfo *stream_info)
556%
557% A description of each parameter follows:
558%
559% o stream_info: the stream info.
560%
561*/
cristy7832dc22011-09-05 01:21:53 +0000562MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
cristy3ed852e2009-09-05 21:47:34 +0000563{
564 assert(stream_info != (StreamInfo *) NULL);
565 assert(stream_info->signature == MagickSignature);
566 return(stream_info->client_data);
567}
568
569/*
570%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571% %
572% %
573% %
574+ 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 %
575% %
576% %
577% %
578%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579%
580% GetVirtualPixelsStream() returns the pixels associated with the last
581% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
582%
583% The format of the GetVirtualPixelsStream() method is:
584%
cristy4c08aed2011-07-01 19:47:50 +0000585% const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000586%
587% A description of each parameter follows:
588%
cristy4c08aed2011-07-01 19:47:50 +0000589% o pixels: return the pixels associated corresponding with the last call to
cristy3ed852e2009-09-05 21:47:34 +0000590% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
591%
592% o image: the image.
593%
594*/
cristy4c08aed2011-07-01 19:47:50 +0000595static const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000596{
597 CacheInfo
598 *cache_info;
599
600 assert(image != (Image *) NULL);
601 assert(image->signature == MagickSignature);
602 if (image->debug != MagickFalse)
603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
604 cache_info=(CacheInfo *) image->cache;
605 assert(cache_info->signature == MagickSignature);
606 return(cache_info->pixels);
607}
608
609/*
610%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
611% %
612% %
613% %
614+ 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 %
615% %
616% %
617% %
618%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619%
cristy4c08aed2011-07-01 19:47:50 +0000620% GetVirtualMetacontentFromStream() returns the associated pixel
621% channels corresponding with the last call to QueueAuthenticPixelsStream() or
622% GetVirtualPixelStream().
cristy3ed852e2009-09-05 21:47:34 +0000623%
cristy4c08aed2011-07-01 19:47:50 +0000624% The format of the GetVirtualMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000625%
cristy4c08aed2011-07-01 19:47:50 +0000626% const void *GetVirtualMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000627%
628% A description of each parameter follows:
629%
630% o image: the image.
631%
632*/
cristy4c08aed2011-07-01 19:47:50 +0000633static const void *GetVirtualMetacontentFromStream(
634 const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000635{
636 CacheInfo
637 *cache_info;
638
639 assert(image != (Image *) NULL);
640 assert(image->signature == MagickSignature);
641 if (image->debug != MagickFalse)
642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
643 cache_info=(CacheInfo *) image->cache;
644 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000645 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000646}
647
648/*
649%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650% %
651% %
652% %
653+ G e t V i r t u a l P i x e l S t r e a m %
654% %
655% %
656% %
657%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658%
659% GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
660% defined by the geometry parameters. A pointer to the pixels is returned if
661% the pixels are transferred, otherwise a NULL is returned. For streams this
662% method is a no-op.
663%
664% The format of the GetVirtualPixelStream() method is:
665%
cristy4c08aed2011-07-01 19:47:50 +0000666% const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000667% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
668% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000669% ExceptionInfo *exception)
670%
671% A description of each parameter follows:
672%
673% o image: the image.
674%
675% o virtual_pixel_method: the virtual pixel method.
676%
677% o x,y,columns,rows: These values define the perimeter of a region of
678% pixels.
679%
680% o exception: return any errors or warnings in this structure.
681%
682*/
683
684static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
685 ExceptionInfo *exception)
686{
687 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
688 return(MagickFalse);
689 cache_info->mapped=MagickFalse;
cristy4c08aed2011-07-01 19:47:50 +0000690 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
cristy3ed852e2009-09-05 21:47:34 +0000691 cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000692 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000693 {
694 cache_info->mapped=MagickTrue;
cristy4c08aed2011-07-01 19:47:50 +0000695 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
cristy3ed852e2009-09-05 21:47:34 +0000696 cache_info->length);
697 }
cristy4c08aed2011-07-01 19:47:50 +0000698 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000699 {
700 (void) ThrowMagickException(exception,GetMagickModule(),
701 ResourceLimitError,"MemoryAllocationFailed","`%s'",
702 cache_info->filename);
703 return(MagickFalse);
704 }
705 return(MagickTrue);
706}
707
cristy4c08aed2011-07-01 19:47:50 +0000708static const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000709 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
710 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000711 ExceptionInfo *exception)
712{
713 CacheInfo
714 *cache_info;
715
716 MagickBooleanType
717 status;
718
719 MagickSizeType
720 number_pixels;
721
722 size_t
723 length;
724
725 /*
726 Validate pixel cache geometry.
727 */
728 assert(image != (const Image *) NULL);
729 assert(image->signature == MagickSignature);
730 if (image->debug != MagickFalse)
731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy5dd71882010-08-01 20:53:13 +0000732 if ((x < 0) || (y < 0) ||
733 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
734 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
735 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000736 {
737 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
738 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000739 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000740 }
741 cache_info=(CacheInfo *) image->cache;
742 assert(cache_info->signature == MagickSignature);
743 /*
744 Pixels are stored in a temporary buffer until they are synced to the cache.
745 */
746 number_pixels=(MagickSizeType) columns*rows;
cristyed231572011-07-14 02:18:59 +0000747 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
cristy4c08aed2011-07-01 19:47:50 +0000748 if (cache_info->metacontent_extent != 0)
749 length+=number_pixels*cache_info->metacontent_extent;
750 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000751 {
752 cache_info->length=length;
753 status=AcquireStreamPixels(cache_info,exception);
754 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000755 {
756 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000757 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000758 }
cristy3ed852e2009-09-05 21:47:34 +0000759 }
760 else
761 if (cache_info->length != length)
762 {
763 RelinquishStreamPixels(cache_info);
764 cache_info->length=length;
765 status=AcquireStreamPixels(cache_info,exception);
766 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000767 {
768 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000769 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000770 }
cristy3ed852e2009-09-05 21:47:34 +0000771 }
cristy4c08aed2011-07-01 19:47:50 +0000772 cache_info->metacontent=(void *) NULL;
773 if (cache_info->metacontent_extent != 0)
774 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
cristyed231572011-07-14 02:18:59 +0000775 cache_info->number_channels);
cristy3ed852e2009-09-05 21:47:34 +0000776 return(cache_info->pixels);
777}
778
779/*
780%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
781% %
782% %
783% %
784+ O p e n S t r e a m %
785% %
786% %
787% %
788%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
789%
790% OpenStream() opens a stream for writing by the StreamImage() method.
791%
792% The format of the OpenStream method is:
793%
794% MagickBooleanType OpenStream(const ImageInfo *image_info,
795% StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
796%
797% A description of each parameter follows:
798%
799% o image_info: the image info.
800%
801% o stream_info: the stream info.
802%
803% o filename: the stream filename.
804%
805% o exception: return any errors or warnings in this structure.
806%
807*/
808MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
809 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
810{
811 MagickBooleanType
812 status;
813
814 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
815 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
816 return(status);
817}
818
819/*
820%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821% %
822% %
823% %
824+ 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 %
825% %
826% %
827% %
828%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829%
830% QueueAuthenticPixelsStream() allocates an area to store image pixels as
831% defined by the region rectangle and returns a pointer to the area. This
832% area is subsequently transferred from the pixel cache with method
833% SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
834% pixels are transferred, otherwise a NULL is returned.
835%
836% The format of the QueueAuthenticPixelsStream() method is:
837%
cristy4c08aed2011-07-01 19:47:50 +0000838% Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000839% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000840% ExceptionInfo *exception)
841%
842% A description of each parameter follows:
843%
844% o image: the image.
845%
846% o x,y,columns,rows: These values define the perimeter of a region of
847% pixels.
848%
849*/
cristy4c08aed2011-07-01 19:47:50 +0000850static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000851 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000852 ExceptionInfo *exception)
853{
854 CacheInfo
855 *cache_info;
856
857 MagickSizeType
858 number_pixels;
859
860 size_t
861 length;
862
863 StreamHandler
864 stream_handler;
865
866 /*
867 Validate pixel cache geometry.
868 */
869 assert(image != (Image *) NULL);
cristycfae90a2010-10-04 14:43:33 +0000870 if ((x < 0) || (y < 0) ||
871 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
872 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
873 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000874 {
875 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
876 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000877 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000878 }
879 stream_handler=GetBlobStreamHandler(image);
880 if (stream_handler == (StreamHandler) NULL)
881 {
882 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
883 "NoStreamHandlerIsDefined","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000884 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000885 }
886 cache_info=(CacheInfo *) image->cache;
887 assert(cache_info->signature == MagickSignature);
888 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
889 (image->colorspace != GetPixelCacheColorspace(image->cache)))
890 {
891 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
892 (void) stream_handler(image,(const void *) NULL,(size_t)
893 cache_info->columns);
894 cache_info->storage_class=image->storage_class;
895 cache_info->colorspace=image->colorspace;
896 cache_info->columns=image->columns;
897 cache_info->rows=image->rows;
898 image->cache=cache_info;
899 }
900 /*
901 Pixels are stored in a temporary buffer until they are synced to the cache.
902 */
903 cache_info->columns=columns;
904 cache_info->rows=rows;
905 number_pixels=(MagickSizeType) columns*rows;
cristyed231572011-07-14 02:18:59 +0000906 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
cristy4c08aed2011-07-01 19:47:50 +0000907 if (cache_info->metacontent_extent != 0)
908 length+=number_pixels*cache_info->metacontent_extent;
909 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000910 {
cristy4c08aed2011-07-01 19:47:50 +0000911 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
cristy3ed852e2009-09-05 21:47:34 +0000912 cache_info->length=(MagickSizeType) length;
913 }
914 else
915 if (cache_info->length < (MagickSizeType) length)
916 {
cristy4c08aed2011-07-01 19:47:50 +0000917 cache_info->pixels=(Quantum *) ResizeMagickMemory(
cristy3ed852e2009-09-05 21:47:34 +0000918 cache_info->pixels,length);
919 cache_info->length=(MagickSizeType) length;
920 }
921 if (cache_info->pixels == (void *) NULL)
cristy4c08aed2011-07-01 19:47:50 +0000922 return((Quantum *) NULL);
923 cache_info->metacontent=(void *) NULL;
924 if (cache_info->metacontent_extent != 0)
925 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
cristyed231572011-07-14 02:18:59 +0000926 cache_info->number_channels);
cristy3ed852e2009-09-05 21:47:34 +0000927 return(cache_info->pixels);
928}
929
930/*
931%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932% %
933% %
934% %
935% R e a d S t r e a m %
936% %
937% %
938% %
939%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940%
941% ReadStream() makes the image pixels available to a user supplied callback
942% method immediately upon reading a scanline with the ReadImage() method.
943%
944% The format of the ReadStream() method is:
945%
946% Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
947% ExceptionInfo *exception)
948%
949% A description of each parameter follows:
950%
951% o image_info: the image info.
952%
953% o stream: a callback method.
954%
955% o exception: return any errors or warnings in this structure.
956%
957*/
958MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
959 ExceptionInfo *exception)
960{
961 CacheMethods
962 cache_methods;
963
964 Image
965 *image;
966
967 ImageInfo
968 *read_info;
969
970 /*
971 Stream image pixels.
972 */
973 assert(image_info != (ImageInfo *) NULL);
974 assert(image_info->signature == MagickSignature);
975 if (image_info->debug != MagickFalse)
976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
977 image_info->filename);
978 assert(exception != (ExceptionInfo *) NULL);
979 assert(exception->signature == MagickSignature);
980 read_info=CloneImageInfo(image_info);
981 read_info->cache=AcquirePixelCache(0);
982 GetPixelCacheMethods(&cache_methods);
983 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
cristy4c08aed2011-07-01 19:47:50 +0000984 cache_methods.get_virtual_metacontent_from_handler=
985 GetVirtualMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000986 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
987 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
988 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
989 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
990 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
cristy4c08aed2011-07-01 19:47:50 +0000991 cache_methods.get_authentic_metacontent_from_handler=
992 GetAuthenticMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000993 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
994 cache_methods.get_one_authentic_pixel_from_handler=
995 GetOneAuthenticPixelFromStream;
996 cache_methods.destroy_pixel_handler=DestroyPixelStream;
997 SetPixelCacheMethods(read_info->cache,&cache_methods);
998 read_info->stream=stream;
999 image=ReadImage(read_info,exception);
1000 read_info=DestroyImageInfo(read_info);
1001 return(image);
1002}
1003
1004/*
1005%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006% %
1007% %
1008% %
1009+ S e t S t r e a m I n f o C l i e n t D a t a %
1010% %
1011% %
1012% %
1013%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014%
1015% SetStreamInfoClientData() sets the stream info client data.
1016%
1017% The format of the SetStreamInfoClientData method is:
1018%
1019% void SetStreamInfoClientData(StreamInfo *stream_info,
1020% const void *client_data)
1021%
1022% A description of each parameter follows:
1023%
1024% o stream_info: the stream info.
1025%
1026% o client_data: the client data.
1027%
1028*/
cristy7832dc22011-09-05 01:21:53 +00001029MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
cristy3ed852e2009-09-05 21:47:34 +00001030 const void *client_data)
1031{
1032 assert(stream_info != (StreamInfo *) NULL);
1033 assert(stream_info->signature == MagickSignature);
1034 stream_info->client_data=client_data;
1035}
1036
1037/*
1038%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039% %
1040% %
1041% %
1042+ S e t S t r e a m I n f o M a p %
1043% %
1044% %
1045% %
1046%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047%
1048% SetStreamInfoMap() sets the stream info map member.
1049%
1050% The format of the SetStreamInfoMap method is:
1051%
1052% void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1053%
1054% A description of each parameter follows:
1055%
1056% o stream_info: the stream info.
1057%
1058% o map: the map.
1059%
1060*/
1061MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1062{
1063 assert(stream_info != (StreamInfo *) NULL);
1064 assert(stream_info->signature == MagickSignature);
1065 (void) CloneString(&stream_info->map,map);
1066}
1067
1068/*
1069%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1070% %
1071% %
1072% %
1073+ S e t S t r e a m I n f o S t o r a g e T y p e %
1074% %
1075% %
1076% %
1077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1078%
1079% SetStreamInfoStorageType() sets the stream info storage type member.
1080%
1081% The format of the SetStreamInfoStorageType method is:
1082%
1083% void SetStreamInfoStorageType(StreamInfo *stream_info,
1084% const StoreageType *storage_type)
1085%
1086% A description of each parameter follows:
1087%
1088% o stream_info: the stream info.
1089%
1090% o storage_type: the storage type.
1091%
1092*/
1093MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1094 const StorageType storage_type)
1095{
1096 assert(stream_info != (StreamInfo *) NULL);
1097 assert(stream_info->signature == MagickSignature);
1098 stream_info->storage_type=storage_type;
1099}
1100
1101/*
1102%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1103% %
1104% %
1105% %
1106+ S t r e a m I m a g e %
1107% %
1108% %
1109% %
1110%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111%
1112% StreamImage() streams pixels from an image and writes them in a user
1113% defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1114%
cristyd212bd02011-02-13 17:08:57 +00001115% The format of the StreamImage() method is:
cristy3ed852e2009-09-05 21:47:34 +00001116%
1117% Image *StreamImage(const ImageInfo *image_info,
1118% StreamInfo *stream_info,ExceptionInfo *exception)
1119%
1120% A description of each parameter follows:
1121%
1122% o image_info: the image info.
1123%
1124% o stream_info: the stream info.
1125%
1126% o exception: return any errors or warnings in this structure.
1127%
1128*/
1129
1130#if defined(__cplusplus) || defined(c_plusplus)
1131extern "C" {
1132#endif
1133
1134static size_t WriteStreamImage(const Image *image,const void *pixels,
1135 const size_t columns)
1136{
cristye3664f42010-05-14 00:59:57 +00001137 CacheInfo
1138 *cache_info;
1139
cristy3ed852e2009-09-05 21:47:34 +00001140 RectangleInfo
1141 extract_info;
1142
1143 size_t
1144 length,
1145 packet_size;
1146
1147 ssize_t
1148 count;
1149
1150 StreamInfo
1151 *stream_info;
1152
cristy654fdaf2011-02-24 15:24:33 +00001153 (void) pixels;
cristy3ed852e2009-09-05 21:47:34 +00001154 stream_info=(StreamInfo *) image->client_data;
1155 switch (stream_info->storage_type)
1156 {
1157 default: packet_size=sizeof(char); break;
1158 case CharPixel: packet_size=sizeof(char); break;
1159 case DoublePixel: packet_size=sizeof(double); break;
1160 case FloatPixel: packet_size=sizeof(float); break;
1161 case IntegerPixel: packet_size=sizeof(int); break;
cristybb503372010-05-27 20:51:26 +00001162 case LongPixel: packet_size=sizeof(ssize_t); break;
cristy3ed852e2009-09-05 21:47:34 +00001163 case QuantumPixel: packet_size=sizeof(Quantum); break;
1164 case ShortPixel: packet_size=sizeof(unsigned short); break;
1165 }
cristye3664f42010-05-14 00:59:57 +00001166 cache_info=(CacheInfo *) image->cache;
1167 assert(cache_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001168 packet_size*=strlen(stream_info->map);
cristye3664f42010-05-14 00:59:57 +00001169 length=packet_size*cache_info->columns*cache_info->rows;
cristy3ed852e2009-09-05 21:47:34 +00001170 if (image != stream_info->image)
1171 {
1172 ImageInfo
1173 *write_info;
1174
1175 /*
1176 Prepare stream for writing.
1177 */
1178 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1179 stream_info->pixels,length,sizeof(*stream_info->pixels));
cristy5dd71882010-08-01 20:53:13 +00001180 if (stream_info->pixels == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001181 return(0);
1182 stream_info->image=image;
1183 write_info=CloneImageInfo(stream_info->image_info);
cristyd965a422010-03-03 17:47:35 +00001184 (void) SetImageInfo(write_info,1,stream_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001185 if (write_info->extract != (char *) NULL)
1186 (void) ParseAbsoluteGeometry(write_info->extract,
1187 &stream_info->extract_info);
1188 stream_info->y=0;
1189 write_info=DestroyImageInfo(write_info);
1190 }
1191 extract_info=stream_info->extract_info;
cristyd212bd02011-02-13 17:08:57 +00001192 if ((extract_info.width == 0) || (extract_info.height == 0))
cristy3ed852e2009-09-05 21:47:34 +00001193 {
1194 /*
1195 Write all pixels to stream.
1196 */
1197 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1198 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1199 stream_info->y++;
1200 return(count == 0 ? 0 : columns);
1201 }
1202 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001203 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001204 {
1205 stream_info->y++;
1206 return(columns);
1207 }
1208 /*
1209 Write a portion of the pixel row to the stream.
1210 */
1211 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1212 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001213 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1214 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001215 stream_info->y++;
1216 return(count == 0 ? 0 : columns);
1217}
1218
1219#if defined(__cplusplus) || defined(c_plusplus)
1220}
1221#endif
1222
1223MagickExport Image *StreamImage(const ImageInfo *image_info,
1224 StreamInfo *stream_info,ExceptionInfo *exception)
1225{
1226 Image
1227 *image;
1228
1229 ImageInfo
1230 *read_info;
1231
1232 assert(image_info != (const ImageInfo *) NULL);
1233 assert(image_info->signature == MagickSignature);
1234 if (image_info->debug != MagickFalse)
1235 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1236 image_info->filename);
1237 assert(stream_info != (StreamInfo *) NULL);
1238 assert(stream_info->signature == MagickSignature);
1239 assert(exception != (ExceptionInfo *) NULL);
1240 read_info=CloneImageInfo(image_info);
1241 stream_info->image_info=image_info;
1242 stream_info->exception=exception;
1243 read_info->client_data=(void *) stream_info;
1244 image=ReadStream(read_info,&WriteStreamImage,exception);
1245 read_info=DestroyImageInfo(read_info);
1246 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1247 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1248 image=DestroyImage(image);
1249 return(image);
1250}
1251
1252/*
1253%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1254% %
1255% %
1256% %
1257+ S t r e a m I m a g e P i x e l s %
1258% %
1259% %
1260% %
1261%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1262%
1263% StreamImagePixels() extracts pixel data from an image and returns it in the
1264% stream_info->pixels structure in the format as defined by
1265% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1266%
1267% The format of the StreamImagePixels method is:
1268%
1269% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1270% const Image *image,ExceptionInfo *exception)
1271%
1272% A description of each parameter follows:
1273%
1274% o stream_info: the stream info.
1275%
1276% o image: the image.
1277%
1278% o exception: return any errors or warnings in this structure.
1279%
1280*/
1281static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1282 const Image *image,ExceptionInfo *exception)
1283{
1284 QuantumInfo
1285 *quantum_info;
1286
1287 QuantumType
1288 *quantum_map;
1289
cristy4c08aed2011-07-01 19:47:50 +00001290 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001291 *p;
1292
cristyd212bd02011-02-13 17:08:57 +00001293 register ssize_t
1294 i,
1295 x;
1296
cristy3ed852e2009-09-05 21:47:34 +00001297 size_t
1298 length;
1299
1300 assert(stream_info != (StreamInfo *) NULL);
1301 assert(stream_info->signature == MagickSignature);
1302 assert(image != (Image *) NULL);
1303 assert(image->signature == MagickSignature);
1304 if (image->debug != MagickFalse)
1305 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1306 length=strlen(stream_info->map);
1307 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1308 if (quantum_map == (QuantumType *) NULL)
1309 {
1310 (void) ThrowMagickException(exception,GetMagickModule(),
1311 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1312 return(MagickFalse);
1313 }
cristybb503372010-05-27 20:51:26 +00001314 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001315 {
1316 switch (stream_info->map[i])
1317 {
1318 case 'A':
1319 case 'a':
1320 {
1321 quantum_map[i]=AlphaQuantum;
1322 break;
1323 }
1324 case 'B':
1325 case 'b':
1326 {
1327 quantum_map[i]=BlueQuantum;
1328 break;
1329 }
1330 case 'C':
1331 case 'c':
1332 {
1333 quantum_map[i]=CyanQuantum;
1334 if (image->colorspace == CMYKColorspace)
1335 break;
1336 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1337 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1338 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1339 return(MagickFalse);
1340 }
1341 case 'g':
1342 case 'G':
1343 {
1344 quantum_map[i]=GreenQuantum;
1345 break;
1346 }
1347 case 'I':
1348 case 'i':
1349 {
1350 quantum_map[i]=IndexQuantum;
1351 break;
1352 }
1353 case 'K':
1354 case 'k':
1355 {
1356 quantum_map[i]=BlackQuantum;
1357 if (image->colorspace == CMYKColorspace)
1358 break;
1359 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1360 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1361 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1362 return(MagickFalse);
1363 }
1364 case 'M':
1365 case 'm':
1366 {
1367 quantum_map[i]=MagentaQuantum;
1368 if (image->colorspace == CMYKColorspace)
1369 break;
1370 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1371 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1372 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1373 return(MagickFalse);
1374 }
1375 case 'o':
1376 case 'O':
1377 {
1378 quantum_map[i]=OpacityQuantum;
1379 break;
1380 }
1381 case 'P':
1382 case 'p':
1383 {
1384 quantum_map[i]=UndefinedQuantum;
1385 break;
1386 }
1387 case 'R':
1388 case 'r':
1389 {
1390 quantum_map[i]=RedQuantum;
1391 break;
1392 }
1393 case 'Y':
1394 case 'y':
1395 {
1396 quantum_map[i]=YellowQuantum;
1397 if (image->colorspace == CMYKColorspace)
1398 break;
1399 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1400 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1401 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1402 return(MagickFalse);
1403 }
1404 default:
1405 {
1406 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1407 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1408 "UnrecognizedPixelMap","`%s'",stream_info->map);
1409 return(MagickFalse);
1410 }
1411 }
1412 }
1413 quantum_info=stream_info->quantum_info;
1414 switch (stream_info->storage_type)
1415 {
1416 case CharPixel:
1417 {
1418 register unsigned char
1419 *q;
1420
1421 q=(unsigned char *) stream_info->pixels;
1422 if (LocaleCompare(stream_info->map,"BGR") == 0)
1423 {
1424 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001425 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001426 break;
cristybb503372010-05-27 20:51:26 +00001427 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001428 {
cristy4c08aed2011-07-01 19:47:50 +00001429 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1430 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1431 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001432 p++;
1433 }
1434 break;
1435 }
1436 if (LocaleCompare(stream_info->map,"BGRA") == 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(GetPixelBlue(image,p));
1444 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1445 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1446 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001447 p++;
1448 }
1449 break;
1450 }
1451 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1452 {
1453 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001454 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001455 break;
cristybb503372010-05-27 20:51:26 +00001456 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001457 {
cristy4c08aed2011-07-01 19:47:50 +00001458 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1459 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1460 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001461 *q++=ScaleQuantumToChar((Quantum) 0);
1462 p++;
1463 }
1464 break;
1465 }
1466 if (LocaleCompare(stream_info->map,"I") == 0)
1467 {
1468 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001469 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001470 break;
cristybb503372010-05-27 20:51:26 +00001471 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001472 {
cristy4c08aed2011-07-01 19:47:50 +00001473 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001474 p++;
1475 }
1476 break;
1477 }
1478 if (LocaleCompare(stream_info->map,"RGB") == 0)
1479 {
1480 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001481 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001482 break;
cristybb503372010-05-27 20:51:26 +00001483 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001484 {
cristy4c08aed2011-07-01 19:47:50 +00001485 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1486 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1487 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001488 p++;
1489 }
1490 break;
1491 }
1492 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1493 {
1494 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001495 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001496 break;
cristybb503372010-05-27 20:51:26 +00001497 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001498 {
cristy4c08aed2011-07-01 19:47:50 +00001499 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1500 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1501 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1502 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001503 p++;
1504 }
1505 break;
1506 }
1507 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1508 {
1509 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001510 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001511 break;
cristybb503372010-05-27 20:51:26 +00001512 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001513 {
cristy4c08aed2011-07-01 19:47:50 +00001514 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1515 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1516 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001517 *q++=ScaleQuantumToChar((Quantum) 0);
1518 p++;
1519 }
1520 break;
1521 }
1522 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001523 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001524 break;
cristybb503372010-05-27 20:51:26 +00001525 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001526 {
cristybb503372010-05-27 20:51:26 +00001527 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001528 {
1529 *q=0;
1530 switch (quantum_map[i])
1531 {
1532 case RedQuantum:
1533 case CyanQuantum:
1534 {
cristy4c08aed2011-07-01 19:47:50 +00001535 *q=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001536 break;
1537 }
1538 case GreenQuantum:
1539 case MagentaQuantum:
1540 {
cristy4c08aed2011-07-01 19:47:50 +00001541 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001542 break;
1543 }
1544 case BlueQuantum:
1545 case YellowQuantum:
1546 {
cristy4c08aed2011-07-01 19:47:50 +00001547 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001548 break;
1549 }
1550 case AlphaQuantum:
1551 {
cristy4c08aed2011-07-01 19:47:50 +00001552 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001553 break;
1554 }
1555 case OpacityQuantum:
1556 {
cristy4c08aed2011-07-01 19:47:50 +00001557 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001558 break;
1559 }
1560 case BlackQuantum:
1561 {
1562 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001563 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001564 break;
1565 }
1566 case IndexQuantum:
1567 {
cristy4c08aed2011-07-01 19:47:50 +00001568 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001569 break;
1570 }
1571 default:
1572 break;
1573 }
1574 q++;
1575 }
1576 p++;
1577 }
1578 break;
1579 }
1580 case DoublePixel:
1581 {
1582 register double
1583 *q;
1584
1585 q=(double *) stream_info->pixels;
1586 if (LocaleCompare(stream_info->map,"BGR") == 0)
1587 {
1588 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001589 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001590 break;
cristybb503372010-05-27 20:51:26 +00001591 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001592 {
cristy4c08aed2011-07-01 19:47:50 +00001593 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001594 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001595 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001596 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001597 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001598 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001599 p++;
1600 }
1601 break;
1602 }
1603 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1604 {
1605 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001606 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001607 break;
cristybb503372010-05-27 20:51:26 +00001608 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001609 {
cristy4c08aed2011-07-01 19:47:50 +00001610 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001611 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001612 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001613 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001614 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001615 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001616 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001617 quantum_info->scale+quantum_info->minimum);
1618 p++;
1619 }
1620 break;
1621 }
1622 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1623 {
1624 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001625 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001626 break;
cristybb503372010-05-27 20:51:26 +00001627 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001628 {
cristy4c08aed2011-07-01 19:47:50 +00001629 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001630 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001631 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001632 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001633 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001634 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001635 *q++=0.0;
1636 p++;
1637 }
1638 break;
1639 }
1640 if (LocaleCompare(stream_info->map,"I") == 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*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001648 quantum_info->scale+quantum_info->minimum);
1649 p++;
1650 }
1651 break;
1652 }
1653 if (LocaleCompare(stream_info->map,"RGB") == 0)
1654 {
1655 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001656 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001657 break;
cristybb503372010-05-27 20:51:26 +00001658 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001659 {
cristy4c08aed2011-07-01 19:47:50 +00001660 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001661 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001662 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001663 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001664 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001665 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001666 p++;
1667 }
1668 break;
1669 }
1670 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1671 {
1672 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001673 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001674 break;
cristybb503372010-05-27 20:51:26 +00001675 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001676 {
cristy4c08aed2011-07-01 19:47:50 +00001677 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001678 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001679 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001680 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001681 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001682 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001683 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001684 quantum_info->scale+quantum_info->minimum);
1685 p++;
1686 }
1687 break;
1688 }
1689 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1690 {
1691 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001692 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001693 break;
cristybb503372010-05-27 20:51:26 +00001694 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001695 {
cristy4c08aed2011-07-01 19:47:50 +00001696 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001697 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001698 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001699 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001700 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001701 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001702 *q++=0.0;
1703 p++;
1704 }
1705 break;
1706 }
1707 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001708 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001709 break;
cristybb503372010-05-27 20:51:26 +00001710 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001711 {
cristybb503372010-05-27 20:51:26 +00001712 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001713 {
1714 *q=0;
1715 switch (quantum_map[i])
1716 {
1717 case RedQuantum:
1718 case CyanQuantum:
1719 {
cristy4c08aed2011-07-01 19:47:50 +00001720 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001721 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001722 break;
1723 }
1724 case GreenQuantum:
1725 case MagentaQuantum:
1726 {
cristy4c08aed2011-07-01 19:47:50 +00001727 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001728 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001729 break;
1730 }
1731 case BlueQuantum:
1732 case YellowQuantum:
1733 {
cristy4c08aed2011-07-01 19:47:50 +00001734 *q=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001735 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001736 break;
1737 }
1738 case AlphaQuantum:
1739 {
cristy4c08aed2011-07-01 19:47:50 +00001740 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001741 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001742 break;
1743 }
1744 case OpacityQuantum:
1745 {
cristy4c08aed2011-07-01 19:47:50 +00001746 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001747 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001748 break;
1749 }
1750 case BlackQuantum:
1751 {
1752 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001753 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001754 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001755 break;
1756 }
1757 case IndexQuantum:
1758 {
cristy4c08aed2011-07-01 19:47:50 +00001759 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001760 quantum_info->scale+quantum_info->minimum);
1761 break;
1762 }
1763 default:
1764 *q=0;
1765 }
1766 q++;
1767 }
1768 p++;
1769 }
1770 break;
1771 }
1772 case FloatPixel:
1773 {
1774 register float
1775 *q;
1776
1777 q=(float *) stream_info->pixels;
1778 if (LocaleCompare(stream_info->map,"BGR") == 0)
1779 {
1780 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001781 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001782 break;
cristybb503372010-05-27 20:51:26 +00001783 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001784 {
cristy4c08aed2011-07-01 19:47:50 +00001785 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001786 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001787 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001788 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001789 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001790 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001791 p++;
1792 }
1793 break;
1794 }
1795 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1796 {
1797 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001798 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001799 break;
cristybb503372010-05-27 20:51:26 +00001800 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001801 {
cristy4c08aed2011-07-01 19:47:50 +00001802 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001803 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001804 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001805 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001806 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001807 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001808 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
cristy3ed852e2009-09-05 21:47:34 +00001809 quantum_info->scale+quantum_info->minimum);
1810 p++;
1811 }
1812 break;
1813 }
1814 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1815 {
1816 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001817 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001818 break;
cristybb503372010-05-27 20:51:26 +00001819 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001820 {
cristy4c08aed2011-07-01 19:47:50 +00001821 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001822 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001823 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001824 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001825 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001826 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001827 *q++=0.0;
1828 p++;
1829 }
1830 break;
1831 }
1832 if (LocaleCompare(stream_info->map,"I") == 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*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001840 quantum_info->scale+quantum_info->minimum);
1841 p++;
1842 }
1843 break;
1844 }
1845 if (LocaleCompare(stream_info->map,"RGB") == 0)
1846 {
1847 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001848 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001849 break;
cristybb503372010-05-27 20:51:26 +00001850 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001851 {
cristy4c08aed2011-07-01 19:47:50 +00001852 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001853 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001854 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001855 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001856 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001857 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001858 p++;
1859 }
1860 break;
1861 }
1862 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1863 {
1864 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001865 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001866 break;
cristybb503372010-05-27 20:51:26 +00001867 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001868 {
cristy4c08aed2011-07-01 19:47:50 +00001869 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001870 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001871 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001872 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001873 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001874 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001875 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001876 quantum_info->scale+quantum_info->minimum);
1877 p++;
1878 }
1879 break;
1880 }
1881 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1882 {
1883 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001884 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001885 break;
cristybb503372010-05-27 20:51:26 +00001886 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001887 {
cristy4c08aed2011-07-01 19:47:50 +00001888 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001889 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001890 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001891 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001892 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001893 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001894 *q++=0.0;
1895 p++;
1896 }
1897 break;
1898 }
1899 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001900 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001901 break;
cristybb503372010-05-27 20:51:26 +00001902 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001903 {
cristybb503372010-05-27 20:51:26 +00001904 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001905 {
1906 *q=0;
1907 switch (quantum_map[i])
1908 {
1909 case RedQuantum:
1910 case CyanQuantum:
1911 {
cristy4c08aed2011-07-01 19:47:50 +00001912 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001913 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001914 break;
1915 }
1916 case GreenQuantum:
1917 case MagentaQuantum:
1918 {
cristy4c08aed2011-07-01 19:47:50 +00001919 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001920 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001921 break;
1922 }
1923 case BlueQuantum:
1924 case YellowQuantum:
1925 {
cristy4c08aed2011-07-01 19:47:50 +00001926 *q=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001927 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001928 break;
1929 }
1930 case AlphaQuantum:
1931 {
cristy4c08aed2011-07-01 19:47:50 +00001932 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001933 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001934 break;
1935 }
1936 case OpacityQuantum:
1937 {
cristy4c08aed2011-07-01 19:47:50 +00001938 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001939 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001940 break;
1941 }
1942 case BlackQuantum:
1943 {
1944 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001945 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001946 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001947 break;
1948 }
1949 case IndexQuantum:
1950 {
cristy4c08aed2011-07-01 19:47:50 +00001951 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001952 quantum_info->scale+quantum_info->minimum);
1953 break;
1954 }
1955 default:
1956 *q=0;
1957 }
1958 q++;
1959 }
1960 p++;
1961 }
1962 break;
1963 }
1964 case IntegerPixel:
1965 {
1966 register unsigned int
1967 *q;
1968
1969 q=(unsigned int *) stream_info->pixels;
1970 if (LocaleCompare(stream_info->map,"BGR") == 0)
1971 {
1972 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001973 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001974 break;
cristybb503372010-05-27 20:51:26 +00001975 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001976 {
cristy4c08aed2011-07-01 19:47:50 +00001977 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1978 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1979 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001980 p++;
1981 }
1982 break;
1983 }
1984 if (LocaleCompare(stream_info->map,"BGRA") == 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 {
cristy4c08aed2011-07-01 19:47:50 +00001991 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1992 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1993 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1994 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001995 p++;
1996 }
1997 break;
1998 }
1999 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2000 {
2001 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002002 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002003 break;
cristybb503372010-05-27 20:51:26 +00002004 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002005 {
cristy4c08aed2011-07-01 19:47:50 +00002006 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
2007 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2008 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002009 *q++=0U;
2010 p++;
2011 }
2012 break;
2013 }
2014 if (LocaleCompare(stream_info->map,"I") == 0)
2015 {
2016 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002017 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002018 break;
cristybb503372010-05-27 20:51:26 +00002019 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002020 {
2021 *q++=(unsigned int) ScaleQuantumToLong(
cristy4c08aed2011-07-01 19:47:50 +00002022 GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002023 p++;
2024 }
2025 break;
2026 }
2027 if (LocaleCompare(stream_info->map,"RGB") == 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 p++;
2038 }
2039 break;
2040 }
2041 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2042 {
2043 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002044 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002045 break;
cristybb503372010-05-27 20:51:26 +00002046 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002047 {
cristy4c08aed2011-07-01 19:47:50 +00002048 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2049 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2050 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002051 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002052 (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002053 p++;
2054 }
2055 break;
2056 }
2057 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2058 {
2059 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002060 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002061 break;
cristybb503372010-05-27 20:51:26 +00002062 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002063 {
cristy4c08aed2011-07-01 19:47:50 +00002064 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2065 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2066 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002067 *q++=0U;
2068 p++;
2069 }
2070 break;
2071 }
2072 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002073 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002074 break;
cristybb503372010-05-27 20:51:26 +00002075 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002076 {
cristybb503372010-05-27 20:51:26 +00002077 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002078 {
2079 *q=0;
2080 switch (quantum_map[i])
2081 {
2082 case RedQuantum:
2083 case CyanQuantum:
2084 {
cristy4c08aed2011-07-01 19:47:50 +00002085 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002086 break;
2087 }
2088 case GreenQuantum:
2089 case MagentaQuantum:
2090 {
cristy4c08aed2011-07-01 19:47:50 +00002091 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002092 break;
2093 }
2094 case BlueQuantum:
2095 case YellowQuantum:
2096 {
cristy4c08aed2011-07-01 19:47:50 +00002097 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002098 break;
2099 }
2100 case AlphaQuantum:
2101 {
cristy4c08aed2011-07-01 19:47:50 +00002102 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002103 break;
2104 }
2105 case OpacityQuantum:
2106 {
cristy4c08aed2011-07-01 19:47:50 +00002107 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002108 break;
2109 }
2110 case BlackQuantum:
2111 {
2112 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002113 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002114 break;
2115 }
2116 case IndexQuantum:
2117 {
2118 *q=(unsigned int)
cristy4c08aed2011-07-01 19:47:50 +00002119 ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002120 break;
2121 }
2122 default:
2123 *q=0;
2124 }
2125 q++;
2126 }
2127 p++;
2128 }
2129 break;
2130 }
2131 case LongPixel:
2132 {
cristybb503372010-05-27 20:51:26 +00002133 register size_t
cristy3ed852e2009-09-05 21:47:34 +00002134 *q;
2135
cristybb503372010-05-27 20:51:26 +00002136 q=(size_t *) stream_info->pixels;
cristy3ed852e2009-09-05 21:47:34 +00002137 if (LocaleCompare(stream_info->map,"BGR") == 0)
2138 {
2139 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002140 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002141 break;
cristybb503372010-05-27 20:51:26 +00002142 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002143 {
cristy4c08aed2011-07-01 19:47:50 +00002144 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2145 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2146 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002147 p++;
2148 }
2149 break;
2150 }
2151 if (LocaleCompare(stream_info->map,"BGRA") == 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(GetPixelBlue(image,p));
2159 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2160 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2161 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002162 p++;
2163 }
2164 break;
2165 }
2166 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2167 {
2168 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002169 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002170 break;
cristybb503372010-05-27 20:51:26 +00002171 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002172 {
cristy4c08aed2011-07-01 19:47:50 +00002173 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2174 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2175 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002176 *q++=0;
2177 p++;
2178 }
2179 break;
2180 }
2181 if (LocaleCompare(stream_info->map,"I") == 0)
2182 {
2183 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002184 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002185 break;
cristybb503372010-05-27 20:51:26 +00002186 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002187 {
cristy4c08aed2011-07-01 19:47:50 +00002188 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002189 p++;
2190 }
2191 break;
2192 }
2193 if (LocaleCompare(stream_info->map,"RGB") == 0)
2194 {
2195 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002196 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002197 break;
cristybb503372010-05-27 20:51:26 +00002198 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002199 {
cristy4c08aed2011-07-01 19:47:50 +00002200 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2201 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2202 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002203 p++;
2204 }
2205 break;
2206 }
2207 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2208 {
2209 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002210 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002211 break;
cristybb503372010-05-27 20:51:26 +00002212 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002213 {
cristy4c08aed2011-07-01 19:47:50 +00002214 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2215 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2216 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2217 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002218 p++;
2219 }
2220 break;
2221 }
2222 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2223 {
2224 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002225 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002226 break;
cristybb503372010-05-27 20:51:26 +00002227 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002228 {
cristy4c08aed2011-07-01 19:47:50 +00002229 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2230 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2231 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002232 *q++=0;
2233 p++;
2234 }
2235 break;
2236 }
2237 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002238 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002239 break;
cristybb503372010-05-27 20:51:26 +00002240 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002241 {
cristybb503372010-05-27 20:51:26 +00002242 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002243 {
2244 *q=0;
2245 switch (quantum_map[i])
2246 {
2247 case RedQuantum:
2248 case CyanQuantum:
2249 {
cristy4c08aed2011-07-01 19:47:50 +00002250 *q=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002251 break;
2252 }
2253 case GreenQuantum:
2254 case MagentaQuantum:
2255 {
cristy4c08aed2011-07-01 19:47:50 +00002256 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002257 break;
2258 }
2259 case BlueQuantum:
2260 case YellowQuantum:
2261 {
cristy4c08aed2011-07-01 19:47:50 +00002262 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002263 break;
2264 }
2265 case AlphaQuantum:
2266 {
cristy4c08aed2011-07-01 19:47:50 +00002267 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002268 break;
2269 }
2270 case OpacityQuantum:
2271 {
cristy4c08aed2011-07-01 19:47:50 +00002272 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002273 break;
2274 }
2275 case BlackQuantum:
2276 {
2277 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002278 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002279 break;
2280 }
2281 case IndexQuantum:
2282 {
cristy4c08aed2011-07-01 19:47:50 +00002283 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002284 break;
2285 }
2286 default:
2287 break;
2288 }
2289 q++;
2290 }
2291 p++;
2292 }
2293 break;
2294 }
2295 case QuantumPixel:
2296 {
2297 register Quantum
2298 *q;
2299
2300 q=(Quantum *) stream_info->pixels;
2301 if (LocaleCompare(stream_info->map,"BGR") == 0)
2302 {
2303 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002304 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002305 break;
cristybb503372010-05-27 20:51:26 +00002306 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002307 {
cristy4c08aed2011-07-01 19:47:50 +00002308 *q++=GetPixelBlue(image,p);
2309 *q++=GetPixelGreen(image,p);
2310 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002311 p++;
2312 }
2313 break;
2314 }
2315 if (LocaleCompare(stream_info->map,"BGRA") == 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++=GetPixelBlue(image,p);
2323 *q++=GetPixelGreen(image,p);
2324 *q++=GetPixelRed(image,p);
2325 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002326 p++;
2327 }
2328 break;
2329 }
2330 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2331 {
2332 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002333 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002334 break;
cristybb503372010-05-27 20:51:26 +00002335 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002336 {
cristy4c08aed2011-07-01 19:47:50 +00002337 *q++=GetPixelBlue(image,p);
2338 *q++=GetPixelGreen(image,p);
2339 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002340 *q++=0;
2341 p++;
2342 }
2343 break;
2344 }
2345 if (LocaleCompare(stream_info->map,"I") == 0)
2346 {
2347 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002348 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002349 break;
cristybb503372010-05-27 20:51:26 +00002350 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002351 {
cristy4c08aed2011-07-01 19:47:50 +00002352 *q++=GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002353 p++;
2354 }
2355 break;
2356 }
2357 if (LocaleCompare(stream_info->map,"RGB") == 0)
2358 {
2359 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002360 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002361 break;
cristybb503372010-05-27 20:51:26 +00002362 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002363 {
cristy4c08aed2011-07-01 19:47:50 +00002364 *q++=GetPixelRed(image,p);
2365 *q++=GetPixelGreen(image,p);
2366 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002367 p++;
2368 }
2369 break;
2370 }
2371 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2372 {
2373 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002374 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002375 break;
cristybb503372010-05-27 20:51:26 +00002376 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002377 {
cristy4c08aed2011-07-01 19:47:50 +00002378 *q++=GetPixelRed(image,p);
2379 *q++=GetPixelGreen(image,p);
2380 *q++=GetPixelBlue(image,p);
2381 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002382 p++;
2383 }
2384 break;
2385 }
2386 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2387 {
2388 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002389 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002390 break;
cristybb503372010-05-27 20:51:26 +00002391 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002392 {
cristy4c08aed2011-07-01 19:47:50 +00002393 *q++=GetPixelRed(image,p);
2394 *q++=GetPixelGreen(image,p);
2395 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002396 *q++=0U;
2397 p++;
2398 }
2399 break;
2400 }
2401 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002402 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002403 break;
cristybb503372010-05-27 20:51:26 +00002404 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002405 {
cristybb503372010-05-27 20:51:26 +00002406 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002407 {
2408 *q=(Quantum) 0;
2409 switch (quantum_map[i])
2410 {
2411 case RedQuantum:
2412 case CyanQuantum:
2413 {
cristy4c08aed2011-07-01 19:47:50 +00002414 *q=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002415 break;
2416 }
2417 case GreenQuantum:
2418 case MagentaQuantum:
2419 {
cristy4c08aed2011-07-01 19:47:50 +00002420 *q=GetPixelGreen(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002421 break;
2422 }
2423 case BlueQuantum:
2424 case YellowQuantum:
2425 {
cristy4c08aed2011-07-01 19:47:50 +00002426 *q=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002427 break;
2428 }
2429 case AlphaQuantum:
2430 {
cristy4c08aed2011-07-01 19:47:50 +00002431 *q=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002432 break;
2433 }
2434 case OpacityQuantum:
2435 {
cristy4c08aed2011-07-01 19:47:50 +00002436 *q=GetPixelAlpha(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002437 break;
2438 }
2439 case BlackQuantum:
2440 {
2441 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002442 *q=GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002443 break;
2444 }
2445 case IndexQuantum:
2446 {
cristy4c08aed2011-07-01 19:47:50 +00002447 *q=(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002448 break;
2449 }
2450 default:
2451 *q=0;
2452 }
2453 q++;
2454 }
2455 p++;
2456 }
2457 break;
2458 }
2459 case ShortPixel:
2460 {
2461 register unsigned short
2462 *q;
2463
2464 q=(unsigned short *) stream_info->pixels;
2465 if (LocaleCompare(stream_info->map,"BGR") == 0)
2466 {
2467 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002468 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002469 break;
cristybb503372010-05-27 20:51:26 +00002470 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002471 {
cristy4c08aed2011-07-01 19:47:50 +00002472 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2473 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2474 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002475 p++;
2476 }
2477 break;
2478 }
2479 if (LocaleCompare(stream_info->map,"BGRA") == 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(GetPixelBlue(image,p));
2487 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2488 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2489 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002490 p++;
2491 }
2492 break;
2493 }
2494 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2495 {
2496 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002497 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002498 break;
cristybb503372010-05-27 20:51:26 +00002499 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002500 {
cristy4c08aed2011-07-01 19:47:50 +00002501 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2502 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2503 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002504 *q++=0;
2505 p++;
2506 }
2507 break;
2508 }
2509 if (LocaleCompare(stream_info->map,"I") == 0)
2510 {
2511 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002512 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002513 break;
cristybb503372010-05-27 20:51:26 +00002514 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002515 {
cristy4c08aed2011-07-01 19:47:50 +00002516 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002517 p++;
2518 }
2519 break;
2520 }
2521 if (LocaleCompare(stream_info->map,"RGB") == 0)
2522 {
2523 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002524 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002525 break;
cristybb503372010-05-27 20:51:26 +00002526 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002527 {
cristy4c08aed2011-07-01 19:47:50 +00002528 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2529 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2530 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002531 p++;
2532 }
2533 break;
2534 }
2535 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2536 {
2537 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002538 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002539 break;
cristybb503372010-05-27 20:51:26 +00002540 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002541 {
cristy4c08aed2011-07-01 19:47:50 +00002542 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2543 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2544 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2545 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002546 p++;
2547 }
2548 break;
2549 }
2550 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2551 {
2552 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002553 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002554 break;
cristybb503372010-05-27 20:51:26 +00002555 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002556 {
cristy4c08aed2011-07-01 19:47:50 +00002557 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2558 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2559 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002560 *q++=0;
2561 p++;
2562 }
2563 break;
2564 }
2565 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002566 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002567 break;
cristybb503372010-05-27 20:51:26 +00002568 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002569 {
cristybb503372010-05-27 20:51:26 +00002570 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002571 {
2572 *q=0;
2573 switch (quantum_map[i])
2574 {
2575 case RedQuantum:
2576 case CyanQuantum:
2577 {
cristy4c08aed2011-07-01 19:47:50 +00002578 *q=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002579 break;
2580 }
2581 case GreenQuantum:
2582 case MagentaQuantum:
2583 {
cristy4c08aed2011-07-01 19:47:50 +00002584 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002585 break;
2586 }
2587 case BlueQuantum:
2588 case YellowQuantum:
2589 {
cristy4c08aed2011-07-01 19:47:50 +00002590 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002591 break;
2592 }
2593 case AlphaQuantum:
2594 {
cristy4c08aed2011-07-01 19:47:50 +00002595 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002596 break;
2597 }
2598 case OpacityQuantum:
2599 {
cristy4c08aed2011-07-01 19:47:50 +00002600 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002601 break;
2602 }
2603 case BlackQuantum:
2604 {
2605 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002606 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002607 break;
2608 }
2609 case IndexQuantum:
2610 {
cristy4c08aed2011-07-01 19:47:50 +00002611 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002612 break;
2613 }
2614 default:
2615 break;
2616 }
2617 q++;
2618 }
2619 p++;
2620 }
2621 break;
2622 }
2623 default:
2624 {
2625 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2626 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2627 "UnrecognizedPixelMap","`%s'",stream_info->map);
2628 break;
2629 }
2630 }
2631 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2632 return(MagickTrue);
2633}
2634
2635/*
2636%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2637% %
2638% %
2639% %
2640+ 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 %
2641% %
2642% %
2643% %
2644%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2645%
2646% SyncAuthenticPixelsStream() calls the user supplied callback method with
2647% the latest stream of pixels.
2648%
2649% The format of the SyncAuthenticPixelsStream method is:
2650%
2651% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2652% ExceptionInfo *exception)
2653%
2654% A description of each parameter follows:
2655%
2656% o image: the image.
2657%
2658% o exception: return any errors or warnings in this structure.
2659%
2660*/
2661static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2662 ExceptionInfo *exception)
2663{
2664 CacheInfo
2665 *cache_info;
2666
2667 size_t
2668 length;
2669
2670 StreamHandler
2671 stream_handler;
2672
2673 assert(image != (Image *) NULL);
2674 assert(image->signature == MagickSignature);
2675 if (image->debug != MagickFalse)
2676 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2677 cache_info=(CacheInfo *) image->cache;
2678 assert(cache_info->signature == MagickSignature);
2679 stream_handler=GetBlobStreamHandler(image);
2680 if (stream_handler == (StreamHandler) NULL)
2681 {
2682 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2683 "NoStreamHandlerIsDefined","`%s'",image->filename);
2684 return(MagickFalse);
2685 }
2686 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2687 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2688}
2689
2690/*
2691%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2692% %
2693% %
2694% %
2695% W r i t e S t r e a m %
2696% %
2697% %
2698% %
2699%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2700%
2701% WriteStream() makes the image pixels available to a user supplied callback
2702% method immediately upon writing pixel data with the WriteImage() method.
2703%
2704% The format of the WriteStream() method is:
2705%
2706% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2707% StreamHandler stream)
2708%
2709% A description of each parameter follows:
2710%
2711% o image_info: the image info.
2712%
2713% o stream: A callback method.
2714%
2715*/
2716MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2717 Image *image,StreamHandler stream)
2718{
2719 ImageInfo
2720 *write_info;
2721
2722 MagickBooleanType
2723 status;
2724
2725 assert(image_info != (ImageInfo *) NULL);
2726 assert(image_info->signature == MagickSignature);
2727 if (image_info->debug != MagickFalse)
2728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2729 image_info->filename);
2730 assert(image != (Image *) NULL);
2731 assert(image->signature == MagickSignature);
2732 write_info=CloneImageInfo(image_info);
2733 write_info->stream=stream;
cristy6f9e0d32011-08-28 16:32:09 +00002734 status=WriteImage(write_info,image,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +00002735 write_info=DestroyImageInfo(write_info);
2736 return(status);
2737}