blob: 2e75164ff7dff68d1b655ae6a8be2e742f16f20c [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% SSSSS TTTTT RRRR EEEEE AAA M M %
7% SS T R R E A A MM MM %
8% SSS T RRRR EEE AAAAA M M M %
9% SS T R R E A A M M %
10% SSSSS T R R EEEEE A A M M %
11% %
12% %
13% MagickCore Pixel Stream Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/cache-private.h"
48#include "MagickCore/color-private.h"
49#include "MagickCore/composite-private.h"
50#include "MagickCore/constitute.h"
51#include "MagickCore/exception.h"
52#include "MagickCore/exception-private.h"
53#include "MagickCore/geometry.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/pixel.h"
56#include "MagickCore/pixel-accessor.h"
57#include "MagickCore/quantum.h"
58#include "MagickCore/quantum-private.h"
59#include "MagickCore/semaphore.h"
60#include "MagickCore/stream.h"
61#include "MagickCore/stream-private.h"
62#include "MagickCore/string_.h"
cristy3ed852e2009-09-05 21:47:34 +000063
64/*
65 Typedef declaractions.
66*/
67struct _StreamInfo
68{
69 const ImageInfo
70 *image_info;
71
72 const Image
73 *image;
74
75 Image
76 *stream;
77
78 QuantumInfo
79 *quantum_info;
80
81 char
82 *map;
83
84 StorageType
85 storage_type;
86
87 unsigned char
88 *pixels;
89
90 RectangleInfo
91 extract_info;
92
cristybb503372010-05-27 20:51:26 +000093 ssize_t
cristy3ed852e2009-09-05 21:47:34 +000094 y;
95
96 ExceptionInfo
97 *exception;
98
99 const void
100 *client_data;
101
cristybb503372010-05-27 20:51:26 +0000102 size_t
cristy3ed852e2009-09-05 21:47:34 +0000103 signature;
104};
105
106/*
107 Declare pixel cache interfaces.
108*/
109#if defined(__cplusplus) || defined(c_plusplus)
110extern "C" {
111#endif
112
cristy4c08aed2011-07-01 19:47:50 +0000113static const Quantum
cristybb503372010-05-27 20:51:26 +0000114 *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t,
115 const ssize_t,const size_t,const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000116
117static MagickBooleanType
118 StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *),
119 SyncAuthenticPixelsStream(Image *,ExceptionInfo *);
120
cristy4c08aed2011-07-01 19:47:50 +0000121static Quantum
cristybb503372010-05-27 20:51:26 +0000122 *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t,
123 const size_t,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000124
125#if defined(__cplusplus) || defined(c_plusplus)
126}
127#endif
128
129/*
130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131% %
132% %
133% %
134+ A c q u i r e S t r e a m I n f o %
135% %
136% %
137% %
138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139%
140% AcquireStreamInfo() allocates the StreamInfo structure.
141%
142% The format of the AcquireStreamInfo method is:
143%
144% StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
145%
146% A description of each parameter follows:
147%
148% o image_info: the image info.
149%
150*/
151MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info)
152{
153 StreamInfo
154 *stream_info;
155
cristy73bd4a52010-10-05 11:24:23 +0000156 stream_info=(StreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
cristy3ed852e2009-09-05 21:47:34 +0000157 if (stream_info == (StreamInfo *) NULL)
158 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
159 (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
160 stream_info->pixels=(unsigned char *) AcquireMagickMemory(
161 sizeof(*stream_info->pixels));
162 if (stream_info->pixels == (unsigned char *) NULL)
163 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164 stream_info->map=ConstantString("RGB");
165 stream_info->storage_type=CharPixel;
166 stream_info->stream=AcquireImage(image_info);
167 stream_info->signature=MagickSignature;
168 return(stream_info);
169}
170
171/*
172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173% %
174% %
175% %
176+ D e s t r o y P i x e l S t r e a m %
177% %
178% %
179% %
180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181%
182% DestroyPixelStream() deallocates memory associated with the pixel stream.
183%
184% The format of the DestroyPixelStream() method is:
185%
186% void DestroyPixelStream(Image *image)
187%
188% A description of each parameter follows:
189%
190% o image: the image.
191%
192*/
193
194static inline void RelinquishStreamPixels(CacheInfo *cache_info)
195{
196 assert(cache_info != (CacheInfo *) NULL);
197 if (cache_info->mapped == MagickFalse)
198 (void) RelinquishMagickMemory(cache_info->pixels);
199 else
200 (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000201 cache_info->pixels=(Quantum *) NULL;
202 cache_info->metacontent=(void *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000203 cache_info->length=0;
204 cache_info->mapped=MagickFalse;
205}
206
207static void DestroyPixelStream(Image *image)
208{
209 CacheInfo
210 *cache_info;
211
212 MagickBooleanType
213 destroy;
214
215 assert(image != (Image *) NULL);
216 assert(image->signature == MagickSignature);
217 if (image->debug != MagickFalse)
218 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
219 cache_info=(CacheInfo *) image->cache;
220 assert(cache_info->signature == MagickSignature);
221 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +0000222 LockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000223 cache_info->reference_count--;
224 if (cache_info->reference_count == 0)
225 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +0000226 UnlockSemaphoreInfo(cache_info->semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000227 if (destroy == MagickFalse)
228 return;
229 RelinquishStreamPixels(cache_info);
230 if (cache_info->nexus_info != (NexusInfo **) NULL)
231 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
232 cache_info->number_threads);
233 if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL)
234 DestroySemaphoreInfo(&cache_info->disk_semaphore);
235 if (cache_info->semaphore != (SemaphoreInfo *) NULL)
236 DestroySemaphoreInfo(&cache_info->semaphore);
237 cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
245+ D e s t r o y S t r e a m I n f o %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
251% DestroyStreamInfo() destroys memory associated with the StreamInfo
252% structure.
253%
254% The format of the DestroyStreamInfo method is:
255%
256% StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
257%
258% A description of each parameter follows:
259%
260% o stream_info: the stream info.
261%
262*/
263MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info)
264{
265 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
266 assert(stream_info != (StreamInfo *) NULL);
267 assert(stream_info->signature == MagickSignature);
268 if (stream_info->map != (char *) NULL)
269 stream_info->map=DestroyString(stream_info->map);
270 if (stream_info->pixels != (unsigned char *) NULL)
271 stream_info->pixels=(unsigned char *) RelinquishMagickMemory(
272 stream_info->pixels);
273 if (stream_info->stream != (Image *) NULL)
274 {
275 (void) CloseBlob(stream_info->stream);
276 stream_info->stream=DestroyImage(stream_info->stream);
277 }
278 if (stream_info->quantum_info != (QuantumInfo *) NULL)
279 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
280 stream_info->signature=(~MagickSignature);
281 stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info);
282 return(stream_info);
283}
284
285/*
286%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287% %
288% %
289% %
cristy4c08aed2011-07-01 19:47:50 +0000290+ G e t A u t h e n t i c M e t a c o n t e n t F r o m S t r e a m %
cristy3ed852e2009-09-05 21:47:34 +0000291% %
292% %
293% %
294%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295%
cristy4c08aed2011-07-01 19:47:50 +0000296% GetAuthenticMetacontentFromStream() returns the metacontent corresponding
297% with the last call to QueueAuthenticPixelsStream() or
298% GetAuthenticPixelsStream().
cristy3ed852e2009-09-05 21:47:34 +0000299%
cristy4c08aed2011-07-01 19:47:50 +0000300% The format of the GetAuthenticMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000301%
cristy4c08aed2011-07-01 19:47:50 +0000302% void *GetAuthenticMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000303%
304% A description of each parameter follows:
305%
306% o image: the image.
307%
308*/
cristy4c08aed2011-07-01 19:47:50 +0000309static void *GetAuthenticMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000310{
311 CacheInfo
312 *cache_info;
313
314 assert(image != (Image *) NULL);
315 assert(image->signature == MagickSignature);
316 if (image->debug != MagickFalse)
317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
318 cache_info=(CacheInfo *) image->cache;
319 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000320 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000321}
322
323/*
324%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325% %
326% %
327% %
328+ G e t A u t h e n t i c P i x e l S t r e a m %
329% %
330% %
331% %
332%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333%
334% GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel
335% cache as defined by the geometry parameters. A pointer to the pixels is
336% returned if the pixels are transferred, otherwise a NULL is returned. For
337% streams this method is a no-op.
338%
339% The format of the GetAuthenticPixelsStream() method is:
340%
cristy4c08aed2011-07-01 19:47:50 +0000341% Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000342% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000343% ExceptionInfo *exception)
344%
345% A description of each parameter follows:
346%
347% o image: the image.
348%
349% o x,y,columns,rows: These values define the perimeter of a region of
350% pixels.
351%
352% o exception: return any errors or warnings in this structure.
353%
354*/
cristy4c08aed2011-07-01 19:47:50 +0000355static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000356 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000357 ExceptionInfo *exception)
358{
cristy4c08aed2011-07-01 19:47:50 +0000359 Quantum
cristy3ed852e2009-09-05 21:47:34 +0000360 *pixels;
361
362 assert(image != (Image *) NULL);
363 assert(image->signature == MagickSignature);
364 if (image->debug != MagickFalse)
365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
366 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
367 return(pixels);
368}
369
370/*
371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372% %
373% %
374% %
375+ G e t A u t h e n t i c P i x e l F r o m S t e a m %
376% %
377% %
378% %
379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380%
381% GetAuthenticPixelsFromStream() returns the pixels associated with the last
382% call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream().
383%
384% The format of the GetAuthenticPixelsFromStream() method is:
385%
cristy4c08aed2011-07-01 19:47:50 +0000386% Quantum *GetAuthenticPixelsFromStream(const Image image)
cristy3ed852e2009-09-05 21:47:34 +0000387%
388% A description of each parameter follows:
389%
390% o image: the image.
391%
392*/
cristy4c08aed2011-07-01 19:47:50 +0000393static Quantum *GetAuthenticPixelsFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000394{
395 CacheInfo
396 *cache_info;
397
398 assert(image != (Image *) NULL);
399 assert(image->signature == MagickSignature);
400 if (image->debug != MagickFalse)
401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
402 cache_info=(CacheInfo *) image->cache;
403 assert(cache_info->signature == MagickSignature);
404 return(cache_info->pixels);
405}
406
407/*
408%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409% %
410% %
411% %
412+ G e t O n e A u t h e n t i c P i x e l F r o m S t r e a m %
413% %
414% %
415% %
416%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417%
418% GetOneAuthenticPixelFromStream() returns a single pixel at the specified
419% (x,y) location. The image background color is returned if an error occurs.
420%
421% The format of the GetOneAuthenticPixelFromStream() method is:
422%
423% MagickBooleanType GetOneAuthenticPixelFromStream(const Image image,
cristycfae90a2010-10-04 14:43:33 +0000424% const ssize_t x,const ssize_t y,PixelPacket *pixel,
425% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000426%
427% A description of each parameter follows:
428%
429% o image: the image.
430%
431% o pixel: return a pixel at the specified (x,y) location.
432%
433% o x,y: These values define the location of the pixel to return.
434%
435% o exception: return any errors or warnings in this structure.
436%
437*/
438static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image,
cristybb503372010-05-27 20:51:26 +0000439 const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000440{
cristy4c08aed2011-07-01 19:47:50 +0000441 register Quantum
442 *q;
cristy3ed852e2009-09-05 21:47:34 +0000443
444 assert(image != (Image *) NULL);
445 assert(image->signature == MagickSignature);
446 *pixel=image->background_color;
cristy4c08aed2011-07-01 19:47:50 +0000447 q=GetAuthenticPixelsStream(image,x,y,1,1,exception);
448 if (q != (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000449 return(MagickFalse);
cristy4c08aed2011-07-01 19:47:50 +0000450 GetPixelPacket(image,q,pixel);
cristy3ed852e2009-09-05 21:47:34 +0000451 return(MagickTrue);
452}
453
454/*
455%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456% %
457% %
458% %
459+ G e t O n e V i r t u a l P i x e l F r o m S t r e a m %
460% %
461% %
462% %
463%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464%
465% GetOneVirtualPixelFromStream() returns a single pixel at the specified
466% (x.y) location. The image background color is returned if an error occurs.
467%
468% The format of the GetOneVirtualPixelFromStream() method is:
469%
470% MagickBooleanType GetOneVirtualPixelFromStream(const Image image,
cristybb503372010-05-27 20:51:26 +0000471% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
472% const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000473%
474% A description of each parameter follows:
475%
476% o image: the image.
477%
478% o virtual_pixel_method: the virtual pixel method.
479%
480% o x,y: These values define the location of the pixel to return.
481%
482% o pixel: return a pixel at the specified (x,y) location.
483%
484% o exception: return any errors or warnings in this structure.
485%
486*/
487static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000488 const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +0000489 PixelPacket *pixel,ExceptionInfo *exception)
490{
cristy4c08aed2011-07-01 19:47:50 +0000491 const Quantum
cristy01cdc902011-08-31 01:05:44 +0000492 *p;
cristy3ed852e2009-09-05 21:47:34 +0000493
494 assert(image != (Image *) NULL);
495 assert(image->signature == MagickSignature);
496 *pixel=image->background_color;
cristy01cdc902011-08-31 01:05:44 +0000497 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
498 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000499 return(MagickFalse);
cristy01cdc902011-08-31 01:05:44 +0000500 GetPixelPacket(image,p,pixel);
501 if (image->colorspace == CMYKColorspace)
502 pixel->black=GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000503 return(MagickTrue);
504}
505
506/*
507%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508% %
509% %
510% %
511+ G e t S t r e a m I n f o C l i e n t D a t a %
512% %
513% %
514% %
515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516%
517% GetStreamInfoClientData() gets the stream info client data.
518%
cristy7832dc22011-09-05 01:21:53 +0000519% The format of the GetStreamInfoClientData method is:
cristy3ed852e2009-09-05 21:47:34 +0000520%
521% const void *GetStreamInfoClientData(StreamInfo *stream_info)
522%
523% A description of each parameter follows:
524%
525% o stream_info: the stream info.
526%
527*/
cristy7832dc22011-09-05 01:21:53 +0000528MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info)
cristy3ed852e2009-09-05 21:47:34 +0000529{
530 assert(stream_info != (StreamInfo *) NULL);
531 assert(stream_info->signature == MagickSignature);
532 return(stream_info->client_data);
533}
534
535/*
536%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537% %
538% %
539% %
540+ 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 %
541% %
542% %
543% %
544%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
545%
546% GetVirtualPixelsStream() returns the pixels associated with the last
547% call to QueueAuthenticPixelsStream() or GetVirtualPixelStream().
548%
549% The format of the GetVirtualPixelsStream() method is:
550%
cristy4c08aed2011-07-01 19:47:50 +0000551% const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000552%
553% A description of each parameter follows:
554%
cristy4c08aed2011-07-01 19:47:50 +0000555% o pixels: return the pixels associated corresponding with the last call to
cristy3ed852e2009-09-05 21:47:34 +0000556% QueueAuthenticPixelsStream() or GetVirtualPixelStream().
557%
558% o image: the image.
559%
560*/
cristy4c08aed2011-07-01 19:47:50 +0000561static const Quantum *GetVirtualPixelsStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000562{
563 CacheInfo
564 *cache_info;
565
566 assert(image != (Image *) NULL);
567 assert(image->signature == MagickSignature);
568 if (image->debug != MagickFalse)
569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
570 cache_info=(CacheInfo *) image->cache;
571 assert(cache_info->signature == MagickSignature);
572 return(cache_info->pixels);
573}
574
575/*
576%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577% %
578% %
579% %
580+ 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 %
581% %
582% %
583% %
584%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
585%
cristy4c08aed2011-07-01 19:47:50 +0000586% GetVirtualMetacontentFromStream() returns the associated pixel
587% channels corresponding with the last call to QueueAuthenticPixelsStream() or
588% GetVirtualPixelStream().
cristy3ed852e2009-09-05 21:47:34 +0000589%
cristy4c08aed2011-07-01 19:47:50 +0000590% The format of the GetVirtualMetacontentFromStream() method is:
cristy3ed852e2009-09-05 21:47:34 +0000591%
cristy4c08aed2011-07-01 19:47:50 +0000592% const void *GetVirtualMetacontentFromStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000593%
594% A description of each parameter follows:
595%
596% o image: the image.
597%
598*/
cristy4c08aed2011-07-01 19:47:50 +0000599static const void *GetVirtualMetacontentFromStream(
600 const Image *image)
cristy3ed852e2009-09-05 21:47:34 +0000601{
602 CacheInfo
603 *cache_info;
604
605 assert(image != (Image *) NULL);
606 assert(image->signature == MagickSignature);
607 if (image->debug != MagickFalse)
608 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
609 cache_info=(CacheInfo *) image->cache;
610 assert(cache_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +0000611 return(cache_info->metacontent);
cristy3ed852e2009-09-05 21:47:34 +0000612}
613
614/*
615%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
616% %
617% %
618% %
619+ G e t V i r t u a l P i x e l S t r e a m %
620% %
621% %
622% %
623%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624%
625% GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as
626% defined by the geometry parameters. A pointer to the pixels is returned if
627% the pixels are transferred, otherwise a NULL is returned. For streams this
628% method is a no-op.
629%
630% The format of the GetVirtualPixelStream() method is:
631%
cristy4c08aed2011-07-01 19:47:50 +0000632% const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000633% const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
634% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000635% ExceptionInfo *exception)
636%
637% A description of each parameter follows:
638%
639% o image: the image.
640%
641% o virtual_pixel_method: the virtual pixel method.
642%
643% o x,y,columns,rows: These values define the perimeter of a region of
644% pixels.
645%
646% o exception: return any errors or warnings in this structure.
647%
648*/
649
650static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
651 ExceptionInfo *exception)
652{
653 if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length))
654 return(MagickFalse);
655 cache_info->mapped=MagickFalse;
cristy4c08aed2011-07-01 19:47:50 +0000656 cache_info->pixels=(Quantum *) AcquireMagickMemory((size_t)
cristy3ed852e2009-09-05 21:47:34 +0000657 cache_info->length);
cristy4c08aed2011-07-01 19:47:50 +0000658 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000659 {
660 cache_info->mapped=MagickTrue;
cristy4c08aed2011-07-01 19:47:50 +0000661 cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
cristy3ed852e2009-09-05 21:47:34 +0000662 cache_info->length);
663 }
cristy4c08aed2011-07-01 19:47:50 +0000664 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000665 {
666 (void) ThrowMagickException(exception,GetMagickModule(),
667 ResourceLimitError,"MemoryAllocationFailed","`%s'",
668 cache_info->filename);
669 return(MagickFalse);
670 }
671 return(MagickTrue);
672}
673
cristy4c08aed2011-07-01 19:47:50 +0000674static const Quantum *GetVirtualPixelStream(const Image *image,
cristybb503372010-05-27 20:51:26 +0000675 const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x,
676 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000677 ExceptionInfo *exception)
678{
679 CacheInfo
680 *cache_info;
681
682 MagickBooleanType
683 status;
684
685 MagickSizeType
686 number_pixels;
687
688 size_t
689 length;
690
691 /*
692 Validate pixel cache geometry.
693 */
694 assert(image != (const Image *) NULL);
695 assert(image->signature == MagickSignature);
696 if (image->debug != MagickFalse)
697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy5dd71882010-08-01 20:53:13 +0000698 if ((x < 0) || (y < 0) ||
699 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
700 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
701 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000702 {
703 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
704 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000705 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000706 }
707 cache_info=(CacheInfo *) image->cache;
708 assert(cache_info->signature == MagickSignature);
709 /*
710 Pixels are stored in a temporary buffer until they are synced to the cache.
711 */
712 number_pixels=(MagickSizeType) columns*rows;
cristyed231572011-07-14 02:18:59 +0000713 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
cristy4c08aed2011-07-01 19:47:50 +0000714 if (cache_info->metacontent_extent != 0)
715 length+=number_pixels*cache_info->metacontent_extent;
716 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000717 {
718 cache_info->length=length;
719 status=AcquireStreamPixels(cache_info,exception);
720 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000721 {
722 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000723 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000724 }
cristy3ed852e2009-09-05 21:47:34 +0000725 }
726 else
727 if (cache_info->length != length)
728 {
729 RelinquishStreamPixels(cache_info);
730 cache_info->length=length;
731 status=AcquireStreamPixels(cache_info,exception);
732 if (status == MagickFalse)
cristy33503f52010-10-04 17:32:27 +0000733 {
734 cache_info->length=0;
cristy4c08aed2011-07-01 19:47:50 +0000735 return((Quantum *) NULL);
cristy33503f52010-10-04 17:32:27 +0000736 }
cristy3ed852e2009-09-05 21:47:34 +0000737 }
cristy4c08aed2011-07-01 19:47:50 +0000738 cache_info->metacontent=(void *) NULL;
739 if (cache_info->metacontent_extent != 0)
740 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
cristyed231572011-07-14 02:18:59 +0000741 cache_info->number_channels);
cristy3ed852e2009-09-05 21:47:34 +0000742 return(cache_info->pixels);
743}
744
745/*
746%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747% %
748% %
749% %
750+ O p e n S t r e a m %
751% %
752% %
753% %
754%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755%
756% OpenStream() opens a stream for writing by the StreamImage() method.
757%
758% The format of the OpenStream method is:
759%
760% MagickBooleanType OpenStream(const ImageInfo *image_info,
761% StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
762%
763% A description of each parameter follows:
764%
765% o image_info: the image info.
766%
767% o stream_info: the stream info.
768%
769% o filename: the stream filename.
770%
771% o exception: return any errors or warnings in this structure.
772%
773*/
774MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info,
775 StreamInfo *stream_info,const char *filename,ExceptionInfo *exception)
776{
777 MagickBooleanType
778 status;
779
780 (void) CopyMagickString(stream_info->stream->filename,filename,MaxTextExtent);
781 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
782 return(status);
783}
784
785/*
786%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
787% %
788% %
789% %
790+ 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 %
791% %
792% %
793% %
794%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795%
796% QueueAuthenticPixelsStream() allocates an area to store image pixels as
797% defined by the region rectangle and returns a pointer to the area. This
798% area is subsequently transferred from the pixel cache with method
799% SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the
800% pixels are transferred, otherwise a NULL is returned.
801%
802% The format of the QueueAuthenticPixelsStream() method is:
803%
cristy4c08aed2011-07-01 19:47:50 +0000804% Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000805% const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000806% ExceptionInfo *exception)
807%
808% A description of each parameter follows:
809%
810% o image: the image.
811%
812% o x,y,columns,rows: These values define the perimeter of a region of
813% pixels.
814%
815*/
cristy4c08aed2011-07-01 19:47:50 +0000816static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
cristybb503372010-05-27 20:51:26 +0000817 const ssize_t y,const size_t columns,const size_t rows,
cristy3ed852e2009-09-05 21:47:34 +0000818 ExceptionInfo *exception)
819{
820 CacheInfo
821 *cache_info;
822
823 MagickSizeType
824 number_pixels;
825
826 size_t
827 length;
828
829 StreamHandler
830 stream_handler;
831
832 /*
833 Validate pixel cache geometry.
834 */
835 assert(image != (Image *) NULL);
cristycfae90a2010-10-04 14:43:33 +0000836 if ((x < 0) || (y < 0) ||
837 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
838 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
839 (columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000840 {
841 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
842 "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000843 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000844 }
845 stream_handler=GetBlobStreamHandler(image);
846 if (stream_handler == (StreamHandler) NULL)
847 {
848 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
849 "NoStreamHandlerIsDefined","`%s'",image->filename);
cristy4c08aed2011-07-01 19:47:50 +0000850 return((Quantum *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000851 }
852 cache_info=(CacheInfo *) image->cache;
853 assert(cache_info->signature == MagickSignature);
854 if ((image->storage_class != GetPixelCacheStorageClass(image->cache)) ||
855 (image->colorspace != GetPixelCacheColorspace(image->cache)))
856 {
857 if (GetPixelCacheStorageClass(image->cache) == UndefinedClass)
858 (void) stream_handler(image,(const void *) NULL,(size_t)
859 cache_info->columns);
860 cache_info->storage_class=image->storage_class;
861 cache_info->colorspace=image->colorspace;
862 cache_info->columns=image->columns;
863 cache_info->rows=image->rows;
864 image->cache=cache_info;
865 }
866 /*
867 Pixels are stored in a temporary buffer until they are synced to the cache.
868 */
869 cache_info->columns=columns;
870 cache_info->rows=rows;
871 number_pixels=(MagickSizeType) columns*rows;
cristyed231572011-07-14 02:18:59 +0000872 length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
cristy4c08aed2011-07-01 19:47:50 +0000873 if (cache_info->metacontent_extent != 0)
874 length+=number_pixels*cache_info->metacontent_extent;
875 if (cache_info->pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000876 {
cristy4c08aed2011-07-01 19:47:50 +0000877 cache_info->pixels=(Quantum *) AcquireMagickMemory(length);
cristy3ed852e2009-09-05 21:47:34 +0000878 cache_info->length=(MagickSizeType) length;
879 }
880 else
881 if (cache_info->length < (MagickSizeType) length)
882 {
cristy4c08aed2011-07-01 19:47:50 +0000883 cache_info->pixels=(Quantum *) ResizeMagickMemory(
cristy3ed852e2009-09-05 21:47:34 +0000884 cache_info->pixels,length);
885 cache_info->length=(MagickSizeType) length;
886 }
887 if (cache_info->pixels == (void *) NULL)
cristy4c08aed2011-07-01 19:47:50 +0000888 return((Quantum *) NULL);
889 cache_info->metacontent=(void *) NULL;
890 if (cache_info->metacontent_extent != 0)
891 cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
cristyed231572011-07-14 02:18:59 +0000892 cache_info->number_channels);
cristy3ed852e2009-09-05 21:47:34 +0000893 return(cache_info->pixels);
894}
895
896/*
897%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
898% %
899% %
900% %
901% R e a d S t r e a m %
902% %
903% %
904% %
905%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906%
907% ReadStream() makes the image pixels available to a user supplied callback
908% method immediately upon reading a scanline with the ReadImage() method.
909%
910% The format of the ReadStream() method is:
911%
912% Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
913% ExceptionInfo *exception)
914%
915% A description of each parameter follows:
916%
917% o image_info: the image info.
918%
919% o stream: a callback method.
920%
921% o exception: return any errors or warnings in this structure.
922%
923*/
924MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream,
925 ExceptionInfo *exception)
926{
927 CacheMethods
928 cache_methods;
929
930 Image
931 *image;
932
933 ImageInfo
934 *read_info;
935
936 /*
937 Stream image pixels.
938 */
939 assert(image_info != (ImageInfo *) NULL);
940 assert(image_info->signature == MagickSignature);
941 if (image_info->debug != MagickFalse)
942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
943 image_info->filename);
944 assert(exception != (ExceptionInfo *) NULL);
945 assert(exception->signature == MagickSignature);
946 read_info=CloneImageInfo(image_info);
947 read_info->cache=AcquirePixelCache(0);
948 GetPixelCacheMethods(&cache_methods);
949 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
cristy4c08aed2011-07-01 19:47:50 +0000950 cache_methods.get_virtual_metacontent_from_handler=
951 GetVirtualMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000952 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
953 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
954 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
955 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
956 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
cristy4c08aed2011-07-01 19:47:50 +0000957 cache_methods.get_authentic_metacontent_from_handler=
958 GetAuthenticMetacontentFromStream;
cristy3ed852e2009-09-05 21:47:34 +0000959 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
960 cache_methods.get_one_authentic_pixel_from_handler=
961 GetOneAuthenticPixelFromStream;
962 cache_methods.destroy_pixel_handler=DestroyPixelStream;
963 SetPixelCacheMethods(read_info->cache,&cache_methods);
964 read_info->stream=stream;
965 image=ReadImage(read_info,exception);
966 read_info=DestroyImageInfo(read_info);
967 return(image);
968}
969
970/*
971%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
972% %
973% %
974% %
975+ S e t S t r e a m I n f o C l i e n t D a t a %
976% %
977% %
978% %
979%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
980%
981% SetStreamInfoClientData() sets the stream info client data.
982%
983% The format of the SetStreamInfoClientData method is:
984%
985% void SetStreamInfoClientData(StreamInfo *stream_info,
986% const void *client_data)
987%
988% A description of each parameter follows:
989%
990% o stream_info: the stream info.
991%
992% o client_data: the client data.
993%
994*/
cristy7832dc22011-09-05 01:21:53 +0000995MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info,
cristy3ed852e2009-09-05 21:47:34 +0000996 const void *client_data)
997{
998 assert(stream_info != (StreamInfo *) NULL);
999 assert(stream_info->signature == MagickSignature);
1000 stream_info->client_data=client_data;
1001}
1002
1003/*
1004%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005% %
1006% %
1007% %
1008+ S e t S t r e a m I n f o M a p %
1009% %
1010% %
1011% %
1012%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013%
1014% SetStreamInfoMap() sets the stream info map member.
1015%
1016% The format of the SetStreamInfoMap method is:
1017%
1018% void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1019%
1020% A description of each parameter follows:
1021%
1022% o stream_info: the stream info.
1023%
1024% o map: the map.
1025%
1026*/
1027MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map)
1028{
1029 assert(stream_info != (StreamInfo *) NULL);
1030 assert(stream_info->signature == MagickSignature);
1031 (void) CloneString(&stream_info->map,map);
1032}
1033
1034/*
1035%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1036% %
1037% %
1038% %
1039+ S e t S t r e a m I n f o S t o r a g e T y p e %
1040% %
1041% %
1042% %
1043%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044%
1045% SetStreamInfoStorageType() sets the stream info storage type member.
1046%
1047% The format of the SetStreamInfoStorageType method is:
1048%
1049% void SetStreamInfoStorageType(StreamInfo *stream_info,
1050% const StoreageType *storage_type)
1051%
1052% A description of each parameter follows:
1053%
1054% o stream_info: the stream info.
1055%
1056% o storage_type: the storage type.
1057%
1058*/
1059MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info,
1060 const StorageType storage_type)
1061{
1062 assert(stream_info != (StreamInfo *) NULL);
1063 assert(stream_info->signature == MagickSignature);
1064 stream_info->storage_type=storage_type;
1065}
1066
1067/*
1068%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069% %
1070% %
1071% %
1072+ S t r e a m I m a g e %
1073% %
1074% %
1075% %
1076%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077%
1078% StreamImage() streams pixels from an image and writes them in a user
1079% defined format and storage type (e.g. RGBA as 8-bit unsigned char).
1080%
cristyd212bd02011-02-13 17:08:57 +00001081% The format of the StreamImage() method is:
cristy3ed852e2009-09-05 21:47:34 +00001082%
1083% Image *StreamImage(const ImageInfo *image_info,
1084% StreamInfo *stream_info,ExceptionInfo *exception)
1085%
1086% A description of each parameter follows:
1087%
1088% o image_info: the image info.
1089%
1090% o stream_info: the stream info.
1091%
1092% o exception: return any errors or warnings in this structure.
1093%
1094*/
1095
1096#if defined(__cplusplus) || defined(c_plusplus)
1097extern "C" {
1098#endif
1099
1100static size_t WriteStreamImage(const Image *image,const void *pixels,
1101 const size_t columns)
1102{
cristye3664f42010-05-14 00:59:57 +00001103 CacheInfo
1104 *cache_info;
1105
cristy3ed852e2009-09-05 21:47:34 +00001106 RectangleInfo
1107 extract_info;
1108
1109 size_t
1110 length,
1111 packet_size;
1112
1113 ssize_t
1114 count;
1115
1116 StreamInfo
1117 *stream_info;
1118
cristy654fdaf2011-02-24 15:24:33 +00001119 (void) pixels;
cristy3ed852e2009-09-05 21:47:34 +00001120 stream_info=(StreamInfo *) image->client_data;
1121 switch (stream_info->storage_type)
1122 {
1123 default: packet_size=sizeof(char); break;
1124 case CharPixel: packet_size=sizeof(char); break;
1125 case DoublePixel: packet_size=sizeof(double); break;
1126 case FloatPixel: packet_size=sizeof(float); break;
1127 case IntegerPixel: packet_size=sizeof(int); break;
cristybb503372010-05-27 20:51:26 +00001128 case LongPixel: packet_size=sizeof(ssize_t); break;
cristy3ed852e2009-09-05 21:47:34 +00001129 case QuantumPixel: packet_size=sizeof(Quantum); break;
1130 case ShortPixel: packet_size=sizeof(unsigned short); break;
1131 }
cristye3664f42010-05-14 00:59:57 +00001132 cache_info=(CacheInfo *) image->cache;
1133 assert(cache_info->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001134 packet_size*=strlen(stream_info->map);
cristye3664f42010-05-14 00:59:57 +00001135 length=packet_size*cache_info->columns*cache_info->rows;
cristy3ed852e2009-09-05 21:47:34 +00001136 if (image != stream_info->image)
1137 {
1138 ImageInfo
1139 *write_info;
1140
1141 /*
1142 Prepare stream for writing.
1143 */
1144 stream_info->pixels=(unsigned char *) ResizeQuantumMemory(
1145 stream_info->pixels,length,sizeof(*stream_info->pixels));
cristy5dd71882010-08-01 20:53:13 +00001146 if (stream_info->pixels == (unsigned char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001147 return(0);
1148 stream_info->image=image;
1149 write_info=CloneImageInfo(stream_info->image_info);
cristyd965a422010-03-03 17:47:35 +00001150 (void) SetImageInfo(write_info,1,stream_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001151 if (write_info->extract != (char *) NULL)
1152 (void) ParseAbsoluteGeometry(write_info->extract,
1153 &stream_info->extract_info);
1154 stream_info->y=0;
1155 write_info=DestroyImageInfo(write_info);
1156 }
1157 extract_info=stream_info->extract_info;
cristyd212bd02011-02-13 17:08:57 +00001158 if ((extract_info.width == 0) || (extract_info.height == 0))
cristy3ed852e2009-09-05 21:47:34 +00001159 {
1160 /*
1161 Write all pixels to stream.
1162 */
1163 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1164 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1165 stream_info->y++;
1166 return(count == 0 ? 0 : columns);
1167 }
1168 if ((stream_info->y < extract_info.y) ||
cristybb503372010-05-27 20:51:26 +00001169 (stream_info->y >= (ssize_t) (extract_info.y+extract_info.height)))
cristy3ed852e2009-09-05 21:47:34 +00001170 {
1171 stream_info->y++;
1172 return(columns);
1173 }
1174 /*
1175 Write a portion of the pixel row to the stream.
1176 */
1177 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1178 length=packet_size*extract_info.width;
cristy5dd71882010-08-01 20:53:13 +00001179 count=WriteBlob(stream_info->stream,length,stream_info->pixels+packet_size*
1180 extract_info.x);
cristy3ed852e2009-09-05 21:47:34 +00001181 stream_info->y++;
1182 return(count == 0 ? 0 : columns);
1183}
1184
1185#if defined(__cplusplus) || defined(c_plusplus)
1186}
1187#endif
1188
1189MagickExport Image *StreamImage(const ImageInfo *image_info,
1190 StreamInfo *stream_info,ExceptionInfo *exception)
1191{
1192 Image
1193 *image;
1194
1195 ImageInfo
1196 *read_info;
1197
1198 assert(image_info != (const ImageInfo *) NULL);
1199 assert(image_info->signature == MagickSignature);
1200 if (image_info->debug != MagickFalse)
1201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1202 image_info->filename);
1203 assert(stream_info != (StreamInfo *) NULL);
1204 assert(stream_info->signature == MagickSignature);
1205 assert(exception != (ExceptionInfo *) NULL);
1206 read_info=CloneImageInfo(image_info);
1207 stream_info->image_info=image_info;
1208 stream_info->exception=exception;
1209 read_info->client_data=(void *) stream_info;
1210 image=ReadStream(read_info,&WriteStreamImage,exception);
1211 read_info=DestroyImageInfo(read_info);
1212 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1213 if (stream_info->quantum_info == (QuantumInfo *) NULL)
1214 image=DestroyImage(image);
1215 return(image);
1216}
1217
1218/*
1219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1220% %
1221% %
1222% %
1223+ S t r e a m I m a g e P i x e l s %
1224% %
1225% %
1226% %
1227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228%
1229% StreamImagePixels() extracts pixel data from an image and returns it in the
1230% stream_info->pixels structure in the format as defined by
1231% stream_info->quantum_info->map and stream_info->quantum_info->storage_type.
1232%
1233% The format of the StreamImagePixels method is:
1234%
1235% MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1236% const Image *image,ExceptionInfo *exception)
1237%
1238% A description of each parameter follows:
1239%
1240% o stream_info: the stream info.
1241%
1242% o image: the image.
1243%
1244% o exception: return any errors or warnings in this structure.
1245%
1246*/
1247static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
1248 const Image *image,ExceptionInfo *exception)
1249{
1250 QuantumInfo
1251 *quantum_info;
1252
1253 QuantumType
1254 *quantum_map;
1255
cristy4c08aed2011-07-01 19:47:50 +00001256 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001257 *p;
1258
cristyd212bd02011-02-13 17:08:57 +00001259 register ssize_t
1260 i,
1261 x;
1262
cristy3ed852e2009-09-05 21:47:34 +00001263 size_t
1264 length;
1265
1266 assert(stream_info != (StreamInfo *) NULL);
1267 assert(stream_info->signature == MagickSignature);
1268 assert(image != (Image *) NULL);
1269 assert(image->signature == MagickSignature);
1270 if (image->debug != MagickFalse)
1271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1272 length=strlen(stream_info->map);
1273 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1274 if (quantum_map == (QuantumType *) NULL)
1275 {
1276 (void) ThrowMagickException(exception,GetMagickModule(),
1277 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1278 return(MagickFalse);
1279 }
cristybb503372010-05-27 20:51:26 +00001280 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001281 {
1282 switch (stream_info->map[i])
1283 {
1284 case 'A':
1285 case 'a':
1286 {
1287 quantum_map[i]=AlphaQuantum;
1288 break;
1289 }
1290 case 'B':
1291 case 'b':
1292 {
1293 quantum_map[i]=BlueQuantum;
1294 break;
1295 }
1296 case 'C':
1297 case 'c':
1298 {
1299 quantum_map[i]=CyanQuantum;
1300 if (image->colorspace == CMYKColorspace)
1301 break;
1302 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1303 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1304 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1305 return(MagickFalse);
1306 }
1307 case 'g':
1308 case 'G':
1309 {
1310 quantum_map[i]=GreenQuantum;
1311 break;
1312 }
1313 case 'I':
1314 case 'i':
1315 {
1316 quantum_map[i]=IndexQuantum;
1317 break;
1318 }
1319 case 'K':
1320 case 'k':
1321 {
1322 quantum_map[i]=BlackQuantum;
1323 if (image->colorspace == CMYKColorspace)
1324 break;
1325 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1326 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1327 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1328 return(MagickFalse);
1329 }
1330 case 'M':
1331 case 'm':
1332 {
1333 quantum_map[i]=MagentaQuantum;
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 'o':
1342 case 'O':
1343 {
1344 quantum_map[i]=OpacityQuantum;
1345 break;
1346 }
1347 case 'P':
1348 case 'p':
1349 {
1350 quantum_map[i]=UndefinedQuantum;
1351 break;
1352 }
1353 case 'R':
1354 case 'r':
1355 {
1356 quantum_map[i]=RedQuantum;
1357 break;
1358 }
1359 case 'Y':
1360 case 'y':
1361 {
1362 quantum_map[i]=YellowQuantum;
1363 if (image->colorspace == CMYKColorspace)
1364 break;
1365 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1366 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1367 "ColorSeparatedImageRequired","`%s'",stream_info->map);
1368 return(MagickFalse);
1369 }
1370 default:
1371 {
1372 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1373 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1374 "UnrecognizedPixelMap","`%s'",stream_info->map);
1375 return(MagickFalse);
1376 }
1377 }
1378 }
1379 quantum_info=stream_info->quantum_info;
1380 switch (stream_info->storage_type)
1381 {
1382 case CharPixel:
1383 {
1384 register unsigned char
1385 *q;
1386
1387 q=(unsigned char *) stream_info->pixels;
1388 if (LocaleCompare(stream_info->map,"BGR") == 0)
1389 {
1390 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001391 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001392 break;
cristybb503372010-05-27 20:51:26 +00001393 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001394 {
cristy4c08aed2011-07-01 19:47:50 +00001395 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1396 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1397 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001398 p++;
1399 }
1400 break;
1401 }
1402 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1403 {
1404 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001405 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001406 break;
cristybb503372010-05-27 20:51:26 +00001407 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001408 {
cristy4c08aed2011-07-01 19:47:50 +00001409 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1410 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1411 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1412 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001413 p++;
1414 }
1415 break;
1416 }
1417 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1418 {
1419 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001420 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001421 break;
cristybb503372010-05-27 20:51:26 +00001422 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001423 {
cristy4c08aed2011-07-01 19:47:50 +00001424 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1425 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1426 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001427 *q++=ScaleQuantumToChar((Quantum) 0);
1428 p++;
1429 }
1430 break;
1431 }
1432 if (LocaleCompare(stream_info->map,"I") == 0)
1433 {
1434 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001435 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001436 break;
cristybb503372010-05-27 20:51:26 +00001437 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001438 {
cristy4c08aed2011-07-01 19:47:50 +00001439 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001440 p++;
1441 }
1442 break;
1443 }
1444 if (LocaleCompare(stream_info->map,"RGB") == 0)
1445 {
1446 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001447 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001448 break;
cristybb503372010-05-27 20:51:26 +00001449 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001450 {
cristy4c08aed2011-07-01 19:47:50 +00001451 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1452 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1453 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001454 p++;
1455 }
1456 break;
1457 }
1458 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1459 {
1460 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001461 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001462 break;
cristybb503372010-05-27 20:51:26 +00001463 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001464 {
cristy4c08aed2011-07-01 19:47:50 +00001465 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1466 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1467 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1468 *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001469 p++;
1470 }
1471 break;
1472 }
1473 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1474 {
1475 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001476 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001477 break;
cristybb503372010-05-27 20:51:26 +00001478 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001479 {
cristy4c08aed2011-07-01 19:47:50 +00001480 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1481 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1482 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001483 *q++=ScaleQuantumToChar((Quantum) 0);
1484 p++;
1485 }
1486 break;
1487 }
1488 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001489 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001490 break;
cristybb503372010-05-27 20:51:26 +00001491 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001492 {
cristybb503372010-05-27 20:51:26 +00001493 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001494 {
1495 *q=0;
1496 switch (quantum_map[i])
1497 {
1498 case RedQuantum:
1499 case CyanQuantum:
1500 {
cristy4c08aed2011-07-01 19:47:50 +00001501 *q=ScaleQuantumToChar(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001502 break;
1503 }
1504 case GreenQuantum:
1505 case MagentaQuantum:
1506 {
cristy4c08aed2011-07-01 19:47:50 +00001507 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001508 break;
1509 }
1510 case BlueQuantum:
1511 case YellowQuantum:
1512 {
cristy4c08aed2011-07-01 19:47:50 +00001513 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001514 break;
1515 }
1516 case AlphaQuantum:
1517 {
cristy4c08aed2011-07-01 19:47:50 +00001518 *q=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00001519 break;
1520 }
1521 case OpacityQuantum:
1522 {
cristy4c08aed2011-07-01 19:47:50 +00001523 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001524 break;
1525 }
1526 case BlackQuantum:
1527 {
1528 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001529 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001530 break;
1531 }
1532 case IndexQuantum:
1533 {
cristy4c08aed2011-07-01 19:47:50 +00001534 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001535 break;
1536 }
1537 default:
1538 break;
1539 }
1540 q++;
1541 }
1542 p++;
1543 }
1544 break;
1545 }
1546 case DoublePixel:
1547 {
1548 register double
1549 *q;
1550
1551 q=(double *) stream_info->pixels;
1552 if (LocaleCompare(stream_info->map,"BGR") == 0)
1553 {
1554 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001555 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001556 break;
cristybb503372010-05-27 20:51:26 +00001557 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001558 {
cristy4c08aed2011-07-01 19:47:50 +00001559 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001560 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001561 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001562 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001563 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001564 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001565 p++;
1566 }
1567 break;
1568 }
1569 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1570 {
1571 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001572 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001573 break;
cristybb503372010-05-27 20:51:26 +00001574 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001575 {
cristy4c08aed2011-07-01 19:47:50 +00001576 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001577 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001578 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001579 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001580 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001581 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001582 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001583 quantum_info->scale+quantum_info->minimum);
1584 p++;
1585 }
1586 break;
1587 }
1588 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1589 {
1590 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001591 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001592 break;
cristybb503372010-05-27 20:51:26 +00001593 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001594 {
cristy4c08aed2011-07-01 19:47:50 +00001595 *q++=(double) ((QuantumScale*GetPixelBlue(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*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001598 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001599 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001600 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001601 *q++=0.0;
1602 p++;
1603 }
1604 break;
1605 }
1606 if (LocaleCompare(stream_info->map,"I") == 0)
1607 {
1608 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001609 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001610 break;
cristybb503372010-05-27 20:51:26 +00001611 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001612 {
cristy4c08aed2011-07-01 19:47:50 +00001613 *q++=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001614 quantum_info->scale+quantum_info->minimum);
1615 p++;
1616 }
1617 break;
1618 }
1619 if (LocaleCompare(stream_info->map,"RGB") == 0)
1620 {
1621 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001622 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001623 break;
cristybb503372010-05-27 20:51:26 +00001624 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001625 {
cristy4c08aed2011-07-01 19:47:50 +00001626 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001627 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001628 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001629 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001630 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001631 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001632 p++;
1633 }
1634 break;
1635 }
1636 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1637 {
1638 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001639 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001640 break;
cristybb503372010-05-27 20:51:26 +00001641 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001642 {
cristy4c08aed2011-07-01 19:47:50 +00001643 *q++=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001644 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001645 *q++=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001646 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001647 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001648 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001649 *q++=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001650 quantum_info->scale+quantum_info->minimum);
1651 p++;
1652 }
1653 break;
1654 }
1655 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1656 {
1657 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001658 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001659 break;
cristybb503372010-05-27 20:51:26 +00001660 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001661 {
cristy4c08aed2011-07-01 19:47:50 +00001662 *q++=(double) ((QuantumScale*GetPixelRed(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*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001665 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001666 *q++=(double) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001667 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001668 *q++=0.0;
1669 p++;
1670 }
1671 break;
1672 }
1673 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001674 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001675 break;
cristybb503372010-05-27 20:51:26 +00001676 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001677 {
cristybb503372010-05-27 20:51:26 +00001678 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001679 {
1680 *q=0;
1681 switch (quantum_map[i])
1682 {
1683 case RedQuantum:
1684 case CyanQuantum:
1685 {
cristy4c08aed2011-07-01 19:47:50 +00001686 *q=(double) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001687 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001688 break;
1689 }
1690 case GreenQuantum:
1691 case MagentaQuantum:
1692 {
cristy4c08aed2011-07-01 19:47:50 +00001693 *q=(double) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001694 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001695 break;
1696 }
1697 case BlueQuantum:
1698 case YellowQuantum:
1699 {
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 break;
1703 }
1704 case AlphaQuantum:
1705 {
cristy4c08aed2011-07-01 19:47:50 +00001706 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001707 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001708 break;
1709 }
1710 case OpacityQuantum:
1711 {
cristy4c08aed2011-07-01 19:47:50 +00001712 *q=(double) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001713 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001714 break;
1715 }
1716 case BlackQuantum:
1717 {
1718 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001719 *q=(double) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001720 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001721 break;
1722 }
1723 case IndexQuantum:
1724 {
cristy4c08aed2011-07-01 19:47:50 +00001725 *q=(double) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001726 quantum_info->scale+quantum_info->minimum);
1727 break;
1728 }
1729 default:
1730 *q=0;
1731 }
1732 q++;
1733 }
1734 p++;
1735 }
1736 break;
1737 }
1738 case FloatPixel:
1739 {
1740 register float
1741 *q;
1742
1743 q=(float *) stream_info->pixels;
1744 if (LocaleCompare(stream_info->map,"BGR") == 0)
1745 {
1746 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001747 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001748 break;
cristybb503372010-05-27 20:51:26 +00001749 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001750 {
cristy4c08aed2011-07-01 19:47:50 +00001751 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001752 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001753 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001754 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001755 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001756 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001757 p++;
1758 }
1759 break;
1760 }
1761 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1762 {
1763 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001764 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001765 break;
cristybb503372010-05-27 20:51:26 +00001766 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001767 {
cristy4c08aed2011-07-01 19:47:50 +00001768 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001769 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001770 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001771 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001772 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001773 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001774 *q++=(float) ((QuantumScale*(Quantum) (GetPixelAlpha(image,p)))*
cristy3ed852e2009-09-05 21:47:34 +00001775 quantum_info->scale+quantum_info->minimum);
1776 p++;
1777 }
1778 break;
1779 }
1780 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1781 {
1782 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001783 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001784 break;
cristybb503372010-05-27 20:51:26 +00001785 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001786 {
cristy4c08aed2011-07-01 19:47:50 +00001787 *q++=(float) ((QuantumScale*GetPixelBlue(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*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001790 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001791 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001792 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001793 *q++=0.0;
1794 p++;
1795 }
1796 break;
1797 }
1798 if (LocaleCompare(stream_info->map,"I") == 0)
1799 {
1800 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001801 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001802 break;
cristybb503372010-05-27 20:51:26 +00001803 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001804 {
cristy4c08aed2011-07-01 19:47:50 +00001805 *q++=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001806 quantum_info->scale+quantum_info->minimum);
1807 p++;
1808 }
1809 break;
1810 }
1811 if (LocaleCompare(stream_info->map,"RGB") == 0)
1812 {
1813 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001814 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001815 break;
cristybb503372010-05-27 20:51:26 +00001816 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001817 {
cristy4c08aed2011-07-01 19:47:50 +00001818 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001819 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001820 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001821 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001822 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001823 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001824 p++;
1825 }
1826 break;
1827 }
1828 if (LocaleCompare(stream_info->map,"RGBA") == 0)
1829 {
1830 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001831 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001832 break;
cristybb503372010-05-27 20:51:26 +00001833 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001834 {
cristy4c08aed2011-07-01 19:47:50 +00001835 *q++=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001836 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001837 *q++=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001838 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001839 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001840 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001841 *q++=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001842 quantum_info->scale+quantum_info->minimum);
1843 p++;
1844 }
1845 break;
1846 }
1847 if (LocaleCompare(stream_info->map,"RGBP") == 0)
1848 {
1849 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001850 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001851 break;
cristybb503372010-05-27 20:51:26 +00001852 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001853 {
cristy4c08aed2011-07-01 19:47:50 +00001854 *q++=(float) ((QuantumScale*GetPixelRed(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*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001857 quantum_info->scale+quantum_info->minimum);
cristy4c08aed2011-07-01 19:47:50 +00001858 *q++=(float) ((QuantumScale*GetPixelBlue(image,p))*
cristy46f08202010-01-10 04:04:21 +00001859 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001860 *q++=0.0;
1861 p++;
1862 }
1863 break;
1864 }
1865 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001866 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001867 break;
cristybb503372010-05-27 20:51:26 +00001868 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001869 {
cristybb503372010-05-27 20:51:26 +00001870 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00001871 {
1872 *q=0;
1873 switch (quantum_map[i])
1874 {
1875 case RedQuantum:
1876 case CyanQuantum:
1877 {
cristy4c08aed2011-07-01 19:47:50 +00001878 *q=(float) ((QuantumScale*GetPixelRed(image,p))*
cristy46f08202010-01-10 04:04:21 +00001879 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001880 break;
1881 }
1882 case GreenQuantum:
1883 case MagentaQuantum:
1884 {
cristy4c08aed2011-07-01 19:47:50 +00001885 *q=(float) ((QuantumScale*GetPixelGreen(image,p))*
cristy46f08202010-01-10 04:04:21 +00001886 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001887 break;
1888 }
1889 case BlueQuantum:
1890 case YellowQuantum:
1891 {
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 break;
1895 }
1896 case AlphaQuantum:
1897 {
cristy4c08aed2011-07-01 19:47:50 +00001898 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001899 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001900 break;
1901 }
1902 case OpacityQuantum:
1903 {
cristy4c08aed2011-07-01 19:47:50 +00001904 *q=(float) ((QuantumScale*GetPixelAlpha(image,p))*
cristy46f08202010-01-10 04:04:21 +00001905 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001906 break;
1907 }
1908 case BlackQuantum:
1909 {
1910 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001911 *q=(float) ((QuantumScale*GetPixelBlack(image,p))*
cristyfba5a8b2011-05-03 17:12:12 +00001912 quantum_info->scale+quantum_info->minimum);
cristy3ed852e2009-09-05 21:47:34 +00001913 break;
1914 }
1915 case IndexQuantum:
1916 {
cristy4c08aed2011-07-01 19:47:50 +00001917 *q=(float) ((QuantumScale*GetPixelIntensity(image,p))*
cristy3ed852e2009-09-05 21:47:34 +00001918 quantum_info->scale+quantum_info->minimum);
1919 break;
1920 }
1921 default:
1922 *q=0;
1923 }
1924 q++;
1925 }
1926 p++;
1927 }
1928 break;
1929 }
1930 case IntegerPixel:
1931 {
1932 register unsigned int
1933 *q;
1934
1935 q=(unsigned int *) stream_info->pixels;
1936 if (LocaleCompare(stream_info->map,"BGR") == 0)
1937 {
1938 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001939 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001940 break;
cristybb503372010-05-27 20:51:26 +00001941 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001942 {
cristy4c08aed2011-07-01 19:47:50 +00001943 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1944 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1945 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001946 p++;
1947 }
1948 break;
1949 }
1950 if (LocaleCompare(stream_info->map,"BGRA") == 0)
1951 {
1952 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001953 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001954 break;
cristybb503372010-05-27 20:51:26 +00001955 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001956 {
cristy4c08aed2011-07-01 19:47:50 +00001957 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1958 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1959 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1960 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001961 p++;
1962 }
1963 break;
1964 }
1965 if (LocaleCompare(stream_info->map,"BGRP") == 0)
1966 {
1967 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001968 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001969 break;
cristybb503372010-05-27 20:51:26 +00001970 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001971 {
cristy4c08aed2011-07-01 19:47:50 +00001972 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1973 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1974 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001975 *q++=0U;
1976 p++;
1977 }
1978 break;
1979 }
1980 if (LocaleCompare(stream_info->map,"I") == 0)
1981 {
1982 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001983 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001984 break;
cristybb503372010-05-27 20:51:26 +00001985 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001986 {
1987 *q++=(unsigned int) ScaleQuantumToLong(
cristy4c08aed2011-07-01 19:47:50 +00001988 GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00001989 p++;
1990 }
1991 break;
1992 }
1993 if (LocaleCompare(stream_info->map,"RGB") == 0)
1994 {
1995 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00001996 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001997 break;
cristybb503372010-05-27 20:51:26 +00001998 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00001999 {
cristy4c08aed2011-07-01 19:47:50 +00002000 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2001 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2002 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002003 p++;
2004 }
2005 break;
2006 }
2007 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2008 {
2009 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002010 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002011 break;
cristybb503372010-05-27 20:51:26 +00002012 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002013 {
cristy4c08aed2011-07-01 19:47:50 +00002014 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2015 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2016 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002017 *q++=(unsigned int) ScaleQuantumToLong((Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002018 (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002019 p++;
2020 }
2021 break;
2022 }
2023 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2024 {
2025 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002026 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002027 break;
cristybb503372010-05-27 20:51:26 +00002028 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002029 {
cristy4c08aed2011-07-01 19:47:50 +00002030 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
2031 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
2032 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002033 *q++=0U;
2034 p++;
2035 }
2036 break;
2037 }
2038 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002039 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002040 break;
cristybb503372010-05-27 20:51:26 +00002041 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002042 {
cristybb503372010-05-27 20:51:26 +00002043 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002044 {
2045 *q=0;
2046 switch (quantum_map[i])
2047 {
2048 case RedQuantum:
2049 case CyanQuantum:
2050 {
cristy4c08aed2011-07-01 19:47:50 +00002051 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002052 break;
2053 }
2054 case GreenQuantum:
2055 case MagentaQuantum:
2056 {
cristy4c08aed2011-07-01 19:47:50 +00002057 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002058 break;
2059 }
2060 case BlueQuantum:
2061 case YellowQuantum:
2062 {
cristy4c08aed2011-07-01 19:47:50 +00002063 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002064 break;
2065 }
2066 case AlphaQuantum:
2067 {
cristy4c08aed2011-07-01 19:47:50 +00002068 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002069 break;
2070 }
2071 case OpacityQuantum:
2072 {
cristy4c08aed2011-07-01 19:47:50 +00002073 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002074 break;
2075 }
2076 case BlackQuantum:
2077 {
2078 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002079 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002080 break;
2081 }
2082 case IndexQuantum:
2083 {
2084 *q=(unsigned int)
cristy4c08aed2011-07-01 19:47:50 +00002085 ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002086 break;
2087 }
2088 default:
2089 *q=0;
2090 }
2091 q++;
2092 }
2093 p++;
2094 }
2095 break;
2096 }
2097 case LongPixel:
2098 {
cristybb503372010-05-27 20:51:26 +00002099 register size_t
cristy3ed852e2009-09-05 21:47:34 +00002100 *q;
2101
cristybb503372010-05-27 20:51:26 +00002102 q=(size_t *) stream_info->pixels;
cristy3ed852e2009-09-05 21:47:34 +00002103 if (LocaleCompare(stream_info->map,"BGR") == 0)
2104 {
2105 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002106 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002107 break;
cristybb503372010-05-27 20:51:26 +00002108 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002109 {
cristy4c08aed2011-07-01 19:47:50 +00002110 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2111 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2112 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002113 p++;
2114 }
2115 break;
2116 }
2117 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2118 {
2119 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002120 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002121 break;
cristybb503372010-05-27 20:51:26 +00002122 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002123 {
cristy4c08aed2011-07-01 19:47:50 +00002124 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2125 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2126 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2127 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002128 p++;
2129 }
2130 break;
2131 }
2132 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2133 {
2134 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002135 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002136 break;
cristybb503372010-05-27 20:51:26 +00002137 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002138 {
cristy4c08aed2011-07-01 19:47:50 +00002139 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2140 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2141 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002142 *q++=0;
2143 p++;
2144 }
2145 break;
2146 }
2147 if (LocaleCompare(stream_info->map,"I") == 0)
2148 {
2149 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002150 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002151 break;
cristybb503372010-05-27 20:51:26 +00002152 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002153 {
cristy4c08aed2011-07-01 19:47:50 +00002154 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002155 p++;
2156 }
2157 break;
2158 }
2159 if (LocaleCompare(stream_info->map,"RGB") == 0)
2160 {
2161 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002162 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002163 break;
cristybb503372010-05-27 20:51:26 +00002164 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002165 {
cristy4c08aed2011-07-01 19:47:50 +00002166 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2167 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2168 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002169 p++;
2170 }
2171 break;
2172 }
2173 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2174 {
2175 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002176 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002177 break;
cristybb503372010-05-27 20:51:26 +00002178 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002179 {
cristy4c08aed2011-07-01 19:47:50 +00002180 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2181 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2182 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2183 *q++=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002184 p++;
2185 }
2186 break;
2187 }
2188 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2189 {
2190 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002191 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002192 break;
cristybb503372010-05-27 20:51:26 +00002193 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002194 {
cristy4c08aed2011-07-01 19:47:50 +00002195 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2196 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2197 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002198 *q++=0;
2199 p++;
2200 }
2201 break;
2202 }
2203 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002204 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002205 break;
cristybb503372010-05-27 20:51:26 +00002206 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002207 {
cristybb503372010-05-27 20:51:26 +00002208 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002209 {
2210 *q=0;
2211 switch (quantum_map[i])
2212 {
2213 case RedQuantum:
2214 case CyanQuantum:
2215 {
cristy4c08aed2011-07-01 19:47:50 +00002216 *q=ScaleQuantumToLong(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002217 break;
2218 }
2219 case GreenQuantum:
2220 case MagentaQuantum:
2221 {
cristy4c08aed2011-07-01 19:47:50 +00002222 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002223 break;
2224 }
2225 case BlueQuantum:
2226 case YellowQuantum:
2227 {
cristy4c08aed2011-07-01 19:47:50 +00002228 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002229 break;
2230 }
2231 case AlphaQuantum:
2232 {
cristy4c08aed2011-07-01 19:47:50 +00002233 *q=ScaleQuantumToLong((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002234 break;
2235 }
2236 case OpacityQuantum:
2237 {
cristy4c08aed2011-07-01 19:47:50 +00002238 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002239 break;
2240 }
2241 case BlackQuantum:
2242 {
2243 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002244 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002245 break;
2246 }
2247 case IndexQuantum:
2248 {
cristy4c08aed2011-07-01 19:47:50 +00002249 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002250 break;
2251 }
2252 default:
2253 break;
2254 }
2255 q++;
2256 }
2257 p++;
2258 }
2259 break;
2260 }
2261 case QuantumPixel:
2262 {
2263 register Quantum
2264 *q;
2265
2266 q=(Quantum *) stream_info->pixels;
2267 if (LocaleCompare(stream_info->map,"BGR") == 0)
2268 {
2269 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002270 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002271 break;
cristybb503372010-05-27 20:51:26 +00002272 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002273 {
cristy4c08aed2011-07-01 19:47:50 +00002274 *q++=GetPixelBlue(image,p);
2275 *q++=GetPixelGreen(image,p);
2276 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002277 p++;
2278 }
2279 break;
2280 }
2281 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2282 {
2283 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002284 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002285 break;
cristybb503372010-05-27 20:51:26 +00002286 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002287 {
cristy4c08aed2011-07-01 19:47:50 +00002288 *q++=GetPixelBlue(image,p);
2289 *q++=GetPixelGreen(image,p);
2290 *q++=GetPixelRed(image,p);
2291 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002292 p++;
2293 }
2294 break;
2295 }
2296 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2297 {
2298 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002299 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002300 break;
cristybb503372010-05-27 20:51:26 +00002301 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002302 {
cristy4c08aed2011-07-01 19:47:50 +00002303 *q++=GetPixelBlue(image,p);
2304 *q++=GetPixelGreen(image,p);
2305 *q++=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002306 *q++=0;
2307 p++;
2308 }
2309 break;
2310 }
2311 if (LocaleCompare(stream_info->map,"I") == 0)
2312 {
2313 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002314 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002315 break;
cristybb503372010-05-27 20:51:26 +00002316 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002317 {
cristy4c08aed2011-07-01 19:47:50 +00002318 *q++=GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002319 p++;
2320 }
2321 break;
2322 }
2323 if (LocaleCompare(stream_info->map,"RGB") == 0)
2324 {
2325 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002326 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002327 break;
cristybb503372010-05-27 20:51:26 +00002328 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002329 {
cristy4c08aed2011-07-01 19:47:50 +00002330 *q++=GetPixelRed(image,p);
2331 *q++=GetPixelGreen(image,p);
2332 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002333 p++;
2334 }
2335 break;
2336 }
2337 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2338 {
2339 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002340 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002341 break;
cristybb503372010-05-27 20:51:26 +00002342 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002343 {
cristy4c08aed2011-07-01 19:47:50 +00002344 *q++=GetPixelRed(image,p);
2345 *q++=GetPixelGreen(image,p);
2346 *q++=GetPixelBlue(image,p);
2347 *q++=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002348 p++;
2349 }
2350 break;
2351 }
2352 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2353 {
2354 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002355 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002356 break;
cristybb503372010-05-27 20:51:26 +00002357 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002358 {
cristy4c08aed2011-07-01 19:47:50 +00002359 *q++=GetPixelRed(image,p);
2360 *q++=GetPixelGreen(image,p);
2361 *q++=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002362 *q++=0U;
2363 p++;
2364 }
2365 break;
2366 }
2367 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002368 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002369 break;
cristybb503372010-05-27 20:51:26 +00002370 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002371 {
cristybb503372010-05-27 20:51:26 +00002372 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002373 {
2374 *q=(Quantum) 0;
2375 switch (quantum_map[i])
2376 {
2377 case RedQuantum:
2378 case CyanQuantum:
2379 {
cristy4c08aed2011-07-01 19:47:50 +00002380 *q=GetPixelRed(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002381 break;
2382 }
2383 case GreenQuantum:
2384 case MagentaQuantum:
2385 {
cristy4c08aed2011-07-01 19:47:50 +00002386 *q=GetPixelGreen(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002387 break;
2388 }
2389 case BlueQuantum:
2390 case YellowQuantum:
2391 {
cristy4c08aed2011-07-01 19:47:50 +00002392 *q=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002393 break;
2394 }
2395 case AlphaQuantum:
2396 {
cristy4c08aed2011-07-01 19:47:50 +00002397 *q=(Quantum) (GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002398 break;
2399 }
2400 case OpacityQuantum:
2401 {
cristy4c08aed2011-07-01 19:47:50 +00002402 *q=GetPixelAlpha(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002403 break;
2404 }
2405 case BlackQuantum:
2406 {
2407 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002408 *q=GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +00002409 break;
2410 }
2411 case IndexQuantum:
2412 {
cristy4c08aed2011-07-01 19:47:50 +00002413 *q=(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002414 break;
2415 }
2416 default:
2417 *q=0;
2418 }
2419 q++;
2420 }
2421 p++;
2422 }
2423 break;
2424 }
2425 case ShortPixel:
2426 {
2427 register unsigned short
2428 *q;
2429
2430 q=(unsigned short *) stream_info->pixels;
2431 if (LocaleCompare(stream_info->map,"BGR") == 0)
2432 {
2433 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002434 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002435 break;
cristybb503372010-05-27 20:51:26 +00002436 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002437 {
cristy4c08aed2011-07-01 19:47:50 +00002438 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2439 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2440 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002441 p++;
2442 }
2443 break;
2444 }
2445 if (LocaleCompare(stream_info->map,"BGRA") == 0)
2446 {
2447 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002448 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002449 break;
cristybb503372010-05-27 20:51:26 +00002450 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002451 {
cristy4c08aed2011-07-01 19:47:50 +00002452 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2453 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2454 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2455 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002456 p++;
2457 }
2458 break;
2459 }
2460 if (LocaleCompare(stream_info->map,"BGRP") == 0)
2461 {
2462 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002463 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002464 break;
cristybb503372010-05-27 20:51:26 +00002465 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002466 {
cristy4c08aed2011-07-01 19:47:50 +00002467 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2468 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2469 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002470 *q++=0;
2471 p++;
2472 }
2473 break;
2474 }
2475 if (LocaleCompare(stream_info->map,"I") == 0)
2476 {
2477 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002478 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002479 break;
cristybb503372010-05-27 20:51:26 +00002480 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002481 {
cristy4c08aed2011-07-01 19:47:50 +00002482 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002483 p++;
2484 }
2485 break;
2486 }
2487 if (LocaleCompare(stream_info->map,"RGB") == 0)
2488 {
2489 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002490 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002491 break;
cristybb503372010-05-27 20:51:26 +00002492 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002493 {
cristy4c08aed2011-07-01 19:47:50 +00002494 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2495 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2496 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002497 p++;
2498 }
2499 break;
2500 }
2501 if (LocaleCompare(stream_info->map,"RGBA") == 0)
2502 {
2503 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002504 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002505 break;
cristybb503372010-05-27 20:51:26 +00002506 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002507 {
cristy4c08aed2011-07-01 19:47:50 +00002508 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2509 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2510 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2511 *q++=ScaleQuantumToShort((Quantum) (GetPixelAlpha(image,p)));
cristy3ed852e2009-09-05 21:47:34 +00002512 p++;
2513 }
2514 break;
2515 }
2516 if (LocaleCompare(stream_info->map,"RGBP") == 0)
2517 {
2518 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002519 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002520 break;
cristybb503372010-05-27 20:51:26 +00002521 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002522 {
cristy4c08aed2011-07-01 19:47:50 +00002523 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2524 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2525 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002526 *q++=0;
2527 p++;
2528 }
2529 break;
2530 }
2531 p=GetAuthenticPixelQueue(image);
cristy4c08aed2011-07-01 19:47:50 +00002532 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002533 break;
cristybb503372010-05-27 20:51:26 +00002534 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
cristy3ed852e2009-09-05 21:47:34 +00002535 {
cristybb503372010-05-27 20:51:26 +00002536 for (i=0; i < (ssize_t) length; i++)
cristy3ed852e2009-09-05 21:47:34 +00002537 {
2538 *q=0;
2539 switch (quantum_map[i])
2540 {
2541 case RedQuantum:
2542 case CyanQuantum:
2543 {
cristy4c08aed2011-07-01 19:47:50 +00002544 *q=ScaleQuantumToShort(GetPixelRed(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002545 break;
2546 }
2547 case GreenQuantum:
2548 case MagentaQuantum:
2549 {
cristy4c08aed2011-07-01 19:47:50 +00002550 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002551 break;
2552 }
2553 case BlueQuantum:
2554 case YellowQuantum:
2555 {
cristy4c08aed2011-07-01 19:47:50 +00002556 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002557 break;
2558 }
2559 case AlphaQuantum:
2560 {
cristy4c08aed2011-07-01 19:47:50 +00002561 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002562 break;
2563 }
2564 case OpacityQuantum:
2565 {
cristy4c08aed2011-07-01 19:47:50 +00002566 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002567 break;
2568 }
2569 case BlackQuantum:
2570 {
2571 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00002572 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002573 break;
2574 }
2575 case IndexQuantum:
2576 {
cristy4c08aed2011-07-01 19:47:50 +00002577 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristy3ed852e2009-09-05 21:47:34 +00002578 break;
2579 }
2580 default:
2581 break;
2582 }
2583 q++;
2584 }
2585 p++;
2586 }
2587 break;
2588 }
2589 default:
2590 {
2591 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2592 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2593 "UnrecognizedPixelMap","`%s'",stream_info->map);
2594 break;
2595 }
2596 }
2597 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2598 return(MagickTrue);
2599}
2600
2601/*
2602%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2603% %
2604% %
2605% %
2606+ 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 %
2607% %
2608% %
2609% %
2610%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2611%
2612% SyncAuthenticPixelsStream() calls the user supplied callback method with
2613% the latest stream of pixels.
2614%
2615% The format of the SyncAuthenticPixelsStream method is:
2616%
2617% MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2618% ExceptionInfo *exception)
2619%
2620% A description of each parameter follows:
2621%
2622% o image: the image.
2623%
2624% o exception: return any errors or warnings in this structure.
2625%
2626*/
2627static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
2628 ExceptionInfo *exception)
2629{
2630 CacheInfo
2631 *cache_info;
2632
2633 size_t
2634 length;
2635
2636 StreamHandler
2637 stream_handler;
2638
2639 assert(image != (Image *) NULL);
2640 assert(image->signature == MagickSignature);
2641 if (image->debug != MagickFalse)
2642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2643 cache_info=(CacheInfo *) image->cache;
2644 assert(cache_info->signature == MagickSignature);
2645 stream_handler=GetBlobStreamHandler(image);
2646 if (stream_handler == (StreamHandler) NULL)
2647 {
2648 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2649 "NoStreamHandlerIsDefined","`%s'",image->filename);
2650 return(MagickFalse);
2651 }
2652 length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);
2653 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2654}
2655
2656/*
2657%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2658% %
2659% %
2660% %
2661% W r i t e S t r e a m %
2662% %
2663% %
2664% %
2665%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2666%
2667% WriteStream() makes the image pixels available to a user supplied callback
2668% method immediately upon writing pixel data with the WriteImage() method.
2669%
2670% The format of the WriteStream() method is:
2671%
2672% MagickBooleanType WriteStream(const ImageInfo *image_info,Image *,
2673% StreamHandler stream)
2674%
2675% A description of each parameter follows:
2676%
2677% o image_info: the image info.
2678%
2679% o stream: A callback method.
2680%
2681*/
2682MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info,
2683 Image *image,StreamHandler stream)
2684{
2685 ImageInfo
2686 *write_info;
2687
2688 MagickBooleanType
2689 status;
2690
2691 assert(image_info != (ImageInfo *) NULL);
2692 assert(image_info->signature == MagickSignature);
2693 if (image_info->debug != MagickFalse)
2694 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2695 image_info->filename);
2696 assert(image != (Image *) NULL);
2697 assert(image->signature == MagickSignature);
2698 write_info=CloneImageInfo(image_info);
2699 write_info->stream=stream;
cristy6f9e0d32011-08-28 16:32:09 +00002700 status=WriteImage(write_info,image,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +00002701 write_info=DestroyImageInfo(write_info);
2702 return(status);
2703}