/src/imagemagick/MagickCore/stream.c
Line | Count | Source |
1 | | /* |
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 | | % Cristy % |
17 | | % March 2000 % |
18 | | % % |
19 | | % % |
20 | | % Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization % |
21 | | % 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 | | % https://imagemagick.org/script/license.php % |
27 | | % % |
28 | | % Unless required by applicable law or agreed to in writing, software % |
29 | | % distributed under the License is distributed on an "AS IS" BASIS, % |
30 | | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
31 | | % See the License for the specific language governing permissions and % |
32 | | % limitations under the License. % |
33 | | % % |
34 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
35 | | % |
36 | | % |
37 | | % |
38 | | */ |
39 | | |
40 | | /* |
41 | | Include declarations. |
42 | | */ |
43 | | #include "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/memory-private.h" |
56 | | #include "MagickCore/pixel.h" |
57 | | #include "MagickCore/pixel-accessor.h" |
58 | | #include "MagickCore/pixel-private.h" |
59 | | #include "MagickCore/policy.h" |
60 | | #include "MagickCore/quantum.h" |
61 | | #include "MagickCore/quantum-private.h" |
62 | | #include "MagickCore/semaphore.h" |
63 | | #include "MagickCore/stream.h" |
64 | | #include "MagickCore/stream-private.h" |
65 | | #include "MagickCore/string_.h" |
66 | | |
67 | | /* |
68 | | Typedef declarations. |
69 | | */ |
70 | | struct _StreamInfo |
71 | | { |
72 | | const ImageInfo |
73 | | *image_info; |
74 | | |
75 | | const Image |
76 | | *image; |
77 | | |
78 | | Image |
79 | | *stream; |
80 | | |
81 | | QuantumInfo |
82 | | *quantum_info; |
83 | | |
84 | | char |
85 | | *map; |
86 | | |
87 | | StorageType |
88 | | storage_type; |
89 | | |
90 | | unsigned char |
91 | | *pixels; |
92 | | |
93 | | RectangleInfo |
94 | | extract_info; |
95 | | |
96 | | ssize_t |
97 | | y; |
98 | | |
99 | | ExceptionInfo |
100 | | *exception; |
101 | | |
102 | | const void |
103 | | *client_data; |
104 | | |
105 | | size_t |
106 | | signature; |
107 | | }; |
108 | | |
109 | | /* |
110 | | Declare pixel cache interfaces. |
111 | | */ |
112 | | #if defined(__cplusplus) || defined(c_plusplus) |
113 | | extern "C" { |
114 | | #endif |
115 | | |
116 | | static const Quantum |
117 | | *GetVirtualPixelStream(const Image *,const VirtualPixelMethod,const ssize_t, |
118 | | const ssize_t,const size_t,const size_t,ExceptionInfo *); |
119 | | |
120 | | static MagickBooleanType |
121 | | StreamImagePixels(const StreamInfo *,const Image *,ExceptionInfo *), |
122 | | SyncAuthenticPixelsStream(Image *,ExceptionInfo *); |
123 | | |
124 | | static Quantum |
125 | | *QueueAuthenticPixelsStream(Image *,const ssize_t,const ssize_t,const size_t, |
126 | | const size_t,ExceptionInfo *); |
127 | | |
128 | | #if defined(__cplusplus) || defined(c_plusplus) |
129 | | } |
130 | | #endif |
131 | | |
132 | | /* |
133 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
134 | | % % |
135 | | % % |
136 | | % % |
137 | | + A c q u i r e S t r e a m I n f o % |
138 | | % % |
139 | | % % |
140 | | % % |
141 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
142 | | % |
143 | | % AcquireStreamInfo() allocates the StreamInfo structure. |
144 | | % |
145 | | % The format of the AcquireStreamInfo method is: |
146 | | % |
147 | | % StreamInfo *AcquireStreamInfo(const ImageInfo *image_info, |
148 | | % ExceptionInfo *exception) |
149 | | % |
150 | | % A description of each parameter follows: |
151 | | % |
152 | | % o image_info: the image info. |
153 | | % |
154 | | % o exception: return any errors or warnings in this structure. |
155 | | % |
156 | | */ |
157 | | MagickExport StreamInfo *AcquireStreamInfo(const ImageInfo *image_info, |
158 | | ExceptionInfo *exception) |
159 | 0 | { |
160 | 0 | StreamInfo |
161 | 0 | *stream_info; |
162 | |
|
163 | 0 | stream_info=(StreamInfo *) AcquireCriticalMemory(sizeof(*stream_info)); |
164 | 0 | (void) memset(stream_info,0,sizeof(*stream_info)); |
165 | 0 | stream_info->pixels=(unsigned char *) MagickAssumeAligned( |
166 | 0 | AcquireAlignedMemory(1,sizeof(*stream_info->pixels))); |
167 | 0 | if (stream_info->pixels == (unsigned char *) NULL) |
168 | 0 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
169 | 0 | stream_info->map=ConstantString("RGB"); |
170 | 0 | stream_info->storage_type=CharPixel; |
171 | 0 | stream_info->stream=AcquireImage(image_info,exception); |
172 | 0 | stream_info->signature=MagickCoreSignature; |
173 | 0 | return(stream_info); |
174 | 0 | } |
175 | | |
176 | | /* |
177 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
178 | | % % |
179 | | % % |
180 | | % % |
181 | | + D e s t r o y P i x e l S t r e a m % |
182 | | % % |
183 | | % % |
184 | | % % |
185 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
186 | | % |
187 | | % DestroyPixelStream() deallocates memory associated with the pixel stream. |
188 | | % |
189 | | % The format of the DestroyPixelStream() method is: |
190 | | % |
191 | | % void DestroyPixelStream(Image *image) |
192 | | % |
193 | | % A description of each parameter follows: |
194 | | % |
195 | | % o image: the image. |
196 | | % |
197 | | */ |
198 | | |
199 | | static inline void RelinquishStreamPixels(CacheInfo *cache_info) |
200 | 56.3k | { |
201 | 56.3k | assert(cache_info != (CacheInfo *) NULL); |
202 | 56.3k | if (cache_info->pixels != (Quantum *) NULL) |
203 | 7.57k | { |
204 | 7.57k | if (cache_info->mapped == MagickFalse) |
205 | 7.57k | cache_info->pixels=(Quantum *) RelinquishAlignedMemory( |
206 | 7.57k | cache_info->pixels); |
207 | 0 | else |
208 | 0 | { |
209 | 0 | (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length); |
210 | 0 | cache_info->pixels=(Quantum *) NULL; |
211 | 0 | } |
212 | 7.57k | } |
213 | 56.3k | cache_info->mapped=MagickFalse; |
214 | 56.3k | cache_info->metacontent=(void *) NULL; |
215 | 56.3k | cache_info->length=0; |
216 | 56.3k | } |
217 | | |
218 | | static void DestroyPixelStream(Image *image) |
219 | 56.5k | { |
220 | 56.5k | CacheInfo |
221 | 56.5k | *cache_info; |
222 | | |
223 | 56.5k | MagickBooleanType |
224 | 56.5k | destroy; |
225 | | |
226 | 56.5k | assert(image != (Image *) NULL); |
227 | 56.5k | assert(image->signature == MagickCoreSignature); |
228 | 56.5k | if (IsEventLogging() != MagickFalse) |
229 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
230 | 56.5k | cache_info=(CacheInfo *) image->cache; |
231 | 56.5k | assert(cache_info->signature == MagickCoreSignature); |
232 | 56.5k | destroy=MagickFalse; |
233 | 56.5k | LockSemaphoreInfo(cache_info->semaphore); |
234 | 56.5k | cache_info->reference_count--; |
235 | 56.5k | if (cache_info->reference_count == 0) |
236 | 56.3k | destroy=MagickTrue; |
237 | 56.5k | UnlockSemaphoreInfo(cache_info->semaphore); |
238 | 56.5k | if (destroy == MagickFalse) |
239 | 166 | return; |
240 | 56.3k | RelinquishStreamPixels(cache_info); |
241 | 56.3k | if (cache_info->nexus_info != (NexusInfo **) NULL) |
242 | 56.3k | cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info, |
243 | 56.3k | cache_info->number_threads); |
244 | 56.3k | if (cache_info->file_semaphore != (SemaphoreInfo *) NULL) |
245 | 56.3k | RelinquishSemaphoreInfo(&cache_info->file_semaphore); |
246 | 56.3k | if (cache_info->semaphore != (SemaphoreInfo *) NULL) |
247 | 56.3k | RelinquishSemaphoreInfo(&cache_info->semaphore); |
248 | 56.3k | cache_info=(CacheInfo *) RelinquishAlignedMemory(cache_info); |
249 | 56.3k | } |
250 | | |
251 | | /* |
252 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
253 | | % % |
254 | | % % |
255 | | % % |
256 | | + D e s t r o y S t r e a m I n f o % |
257 | | % % |
258 | | % % |
259 | | % % |
260 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
261 | | % |
262 | | % DestroyStreamInfo() destroys memory associated with the StreamInfo |
263 | | % structure. |
264 | | % |
265 | | % The format of the DestroyStreamInfo method is: |
266 | | % |
267 | | % StreamInfo *DestroyStreamInfo(StreamInfo *stream_info) |
268 | | % |
269 | | % A description of each parameter follows: |
270 | | % |
271 | | % o stream_info: the stream info. |
272 | | % |
273 | | */ |
274 | | MagickExport StreamInfo *DestroyStreamInfo(StreamInfo *stream_info) |
275 | 0 | { |
276 | 0 | assert(stream_info != (StreamInfo *) NULL); |
277 | 0 | assert(stream_info->signature == MagickCoreSignature); |
278 | 0 | if (IsEventLogging() != MagickFalse) |
279 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
280 | 0 | if (stream_info->map != (char *) NULL) |
281 | 0 | stream_info->map=DestroyString(stream_info->map); |
282 | 0 | if (stream_info->pixels != (unsigned char *) NULL) |
283 | 0 | stream_info->pixels=(unsigned char *) RelinquishAlignedMemory( |
284 | 0 | stream_info->pixels); |
285 | 0 | if (stream_info->stream != (Image *) NULL) |
286 | 0 | { |
287 | 0 | (void) CloseBlob(stream_info->stream); |
288 | 0 | stream_info->stream=DestroyImage(stream_info->stream); |
289 | 0 | } |
290 | 0 | if (stream_info->quantum_info != (QuantumInfo *) NULL) |
291 | 0 | stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info); |
292 | 0 | stream_info->signature=(~MagickCoreSignature); |
293 | 0 | stream_info=(StreamInfo *) RelinquishMagickMemory(stream_info); |
294 | 0 | return(stream_info); |
295 | 0 | } |
296 | | |
297 | | /* |
298 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
299 | | % % |
300 | | % % |
301 | | % % |
302 | | + 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 % |
303 | | % % |
304 | | % % |
305 | | % % |
306 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
307 | | % |
308 | | % GetAuthenticMetacontentFromStream() returns the metacontent corresponding |
309 | | % with the last call to QueueAuthenticPixelsStream() or |
310 | | % GetAuthenticPixelsStream(). |
311 | | % |
312 | | % The format of the GetAuthenticMetacontentFromStream() method is: |
313 | | % |
314 | | % void *GetAuthenticMetacontentFromStream(const Image *image) |
315 | | % |
316 | | % A description of each parameter follows: |
317 | | % |
318 | | % o image: the image. |
319 | | % |
320 | | */ |
321 | | static void *GetAuthenticMetacontentFromStream(const Image *image) |
322 | 0 | { |
323 | 0 | CacheInfo |
324 | 0 | *cache_info; |
325 | |
|
326 | 0 | assert(image != (Image *) NULL); |
327 | 0 | assert(image->signature == MagickCoreSignature); |
328 | 0 | if (IsEventLogging() != MagickFalse) |
329 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
330 | 0 | cache_info=(CacheInfo *) image->cache; |
331 | 0 | assert(cache_info->signature == MagickCoreSignature); |
332 | 0 | return(cache_info->metacontent); |
333 | 0 | } |
334 | | |
335 | | /* |
336 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
337 | | % % |
338 | | % % |
339 | | % % |
340 | | + G e t A u t h e n t i c P i x e l S t r e a m % |
341 | | % % |
342 | | % % |
343 | | % % |
344 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
345 | | % |
346 | | % GetAuthenticPixelsStream() gets pixels from the in-memory or disk pixel |
347 | | % cache as defined by the geometry parameters. A pointer to the pixels is |
348 | | % returned if the pixels are transferred, otherwise a NULL is returned. For |
349 | | % streams this method is a no-op. |
350 | | % |
351 | | % The format of the GetAuthenticPixelsStream() method is: |
352 | | % |
353 | | % Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x, |
354 | | % const ssize_t y,const size_t columns,const size_t rows, |
355 | | % ExceptionInfo *exception) |
356 | | % |
357 | | % A description of each parameter follows: |
358 | | % |
359 | | % o image: the image. |
360 | | % |
361 | | % o x,y,columns,rows: These values define the perimeter of a region of |
362 | | % pixels. |
363 | | % |
364 | | % o exception: return any errors or warnings in this structure. |
365 | | % |
366 | | */ |
367 | | static Quantum *GetAuthenticPixelsStream(Image *image,const ssize_t x, |
368 | | const ssize_t y,const size_t columns,const size_t rows, |
369 | | ExceptionInfo *exception) |
370 | 12.8k | { |
371 | 12.8k | Quantum |
372 | 12.8k | *pixels; |
373 | | |
374 | 12.8k | assert(image != (Image *) NULL); |
375 | 12.8k | assert(image->signature == MagickCoreSignature); |
376 | 12.8k | if (IsEventLogging() != MagickFalse) |
377 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
378 | 12.8k | pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception); |
379 | 12.8k | return(pixels); |
380 | 12.8k | } |
381 | | |
382 | | /* |
383 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
384 | | % % |
385 | | % % |
386 | | % % |
387 | | + 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 % |
388 | | % % |
389 | | % % |
390 | | % % |
391 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
392 | | % |
393 | | % GetAuthenticPixelsFromStream() returns the pixels associated with the last |
394 | | % call to QueueAuthenticPixelsStream() or GetAuthenticPixelsStream(). |
395 | | % |
396 | | % The format of the GetAuthenticPixelsFromStream() method is: |
397 | | % |
398 | | % Quantum *GetAuthenticPixelsFromStream(const Image image) |
399 | | % |
400 | | % A description of each parameter follows: |
401 | | % |
402 | | % o image: the image. |
403 | | % |
404 | | */ |
405 | | static Quantum *GetAuthenticPixelsFromStream(const Image *image) |
406 | 66.2k | { |
407 | 66.2k | CacheInfo |
408 | 66.2k | *cache_info; |
409 | | |
410 | 66.2k | assert(image != (Image *) NULL); |
411 | 66.2k | assert(image->signature == MagickCoreSignature); |
412 | 66.2k | if (IsEventLogging() != MagickFalse) |
413 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
414 | 66.2k | cache_info=(CacheInfo *) image->cache; |
415 | 66.2k | assert(cache_info->signature == MagickCoreSignature); |
416 | 66.2k | return(cache_info->pixels); |
417 | 66.2k | } |
418 | | |
419 | | /* |
420 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
421 | | % % |
422 | | % % |
423 | | % % |
424 | | + 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 % |
425 | | % % |
426 | | % % |
427 | | % % |
428 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
429 | | % |
430 | | % GetOneAuthenticPixelFromStream() returns a single pixel at the specified |
431 | | % (x,y) location. The image background color is returned if an error occurs. |
432 | | % |
433 | | % The format of the GetOneAuthenticPixelFromStream() method is: |
434 | | % |
435 | | % MagickBooleanType GetOneAuthenticPixelFromStream(const Image image, |
436 | | % const ssize_t x,const ssize_t y,Quantum *pixel, |
437 | | % ExceptionInfo *exception) |
438 | | % |
439 | | % A description of each parameter follows: |
440 | | % |
441 | | % o image: the image. |
442 | | % |
443 | | % o pixel: return a pixel at the specified (x,y) location. |
444 | | % |
445 | | % o x,y: These values define the location of the pixel to return. |
446 | | % |
447 | | % o exception: return any errors or warnings in this structure. |
448 | | % |
449 | | */ |
450 | | static MagickBooleanType GetOneAuthenticPixelFromStream(Image *image, |
451 | | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
452 | 0 | { |
453 | 0 | Quantum |
454 | 0 | *p; |
455 | |
|
456 | 0 | ssize_t |
457 | 0 | i; |
458 | |
|
459 | 0 | assert(image != (Image *) NULL); |
460 | 0 | assert(image->signature == MagickCoreSignature); |
461 | 0 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
462 | 0 | p=GetAuthenticPixelsStream(image,x,y,1,1,exception); |
463 | 0 | if (p == (Quantum *) NULL) |
464 | 0 | { |
465 | 0 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
466 | 0 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
467 | 0 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
468 | 0 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
469 | 0 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
470 | 0 | return(MagickFalse); |
471 | 0 | } |
472 | 0 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
473 | 0 | { |
474 | 0 | PixelChannel channel = GetPixelChannelChannel(image,i); |
475 | 0 | pixel[channel]=p[i]; |
476 | 0 | } |
477 | 0 | return(MagickTrue); |
478 | 0 | } |
479 | | |
480 | | /* |
481 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
482 | | % % |
483 | | % % |
484 | | % % |
485 | | + 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 % |
486 | | % % |
487 | | % % |
488 | | % % |
489 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
490 | | % |
491 | | % GetOneVirtualPixelFromStream() returns a single pixel at the specified |
492 | | % (x.y) location. The image background color is returned if an error occurs. |
493 | | % |
494 | | % The format of the GetOneVirtualPixelFromStream() method is: |
495 | | % |
496 | | % MagickBooleanType GetOneVirtualPixelFromStream(const Image image, |
497 | | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
498 | | % const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
499 | | % |
500 | | % A description of each parameter follows: |
501 | | % |
502 | | % o image: the image. |
503 | | % |
504 | | % o virtual_pixel_method: the virtual pixel method. |
505 | | % |
506 | | % o x,y: These values define the location of the pixel to return. |
507 | | % |
508 | | % o pixel: return a pixel at the specified (x,y) location. |
509 | | % |
510 | | % o exception: return any errors or warnings in this structure. |
511 | | % |
512 | | */ |
513 | | static MagickBooleanType GetOneVirtualPixelFromStream(const Image *image, |
514 | | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
515 | | Quantum *pixel,ExceptionInfo *exception) |
516 | 0 | { |
517 | 0 | const Quantum |
518 | 0 | *p; |
519 | |
|
520 | 0 | ssize_t |
521 | 0 | i; |
522 | |
|
523 | 0 | assert(image != (Image *) NULL); |
524 | 0 | assert(image->signature == MagickCoreSignature); |
525 | 0 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
526 | 0 | p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception); |
527 | 0 | if (p == (const Quantum *) NULL) |
528 | 0 | { |
529 | 0 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
530 | 0 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
531 | 0 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
532 | 0 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
533 | 0 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
534 | 0 | return(MagickFalse); |
535 | 0 | } |
536 | 0 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
537 | 0 | { |
538 | 0 | PixelChannel channel = GetPixelChannelChannel(image,i); |
539 | 0 | pixel[channel]=p[i]; |
540 | 0 | } |
541 | 0 | return(MagickTrue); |
542 | 0 | } |
543 | | |
544 | | /* |
545 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
546 | | % % |
547 | | % % |
548 | | % % |
549 | | + G e t S t r e a m I n f o C l i e n t D a t a % |
550 | | % % |
551 | | % % |
552 | | % % |
553 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
554 | | % |
555 | | % GetStreamInfoClientData() gets the stream info client data. |
556 | | % |
557 | | % The format of the GetStreamInfoClientData method is: |
558 | | % |
559 | | % const void *GetStreamInfoClientData(StreamInfo *stream_info) |
560 | | % |
561 | | % A description of each parameter follows: |
562 | | % |
563 | | % o stream_info: the stream info. |
564 | | % |
565 | | */ |
566 | | MagickPrivate const void *GetStreamInfoClientData(StreamInfo *stream_info) |
567 | 0 | { |
568 | 0 | assert(stream_info != (StreamInfo *) NULL); |
569 | 0 | assert(stream_info->signature == MagickCoreSignature); |
570 | 0 | return(stream_info->client_data); |
571 | 0 | } |
572 | | |
573 | | /* |
574 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
575 | | % % |
576 | | % % |
577 | | % % |
578 | | + 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 % |
579 | | % % |
580 | | % % |
581 | | % % |
582 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
583 | | % |
584 | | % GetVirtualPixelsStream() returns the pixels associated with the last call to |
585 | | % QueueAuthenticPixelsStream() or GetVirtualPixelStream(). |
586 | | % |
587 | | % The format of the GetVirtualPixelsStream() method is: |
588 | | % |
589 | | % const Quantum *GetVirtualPixelsStream(const Image *image) |
590 | | % |
591 | | % A description of each parameter follows: |
592 | | % |
593 | | % o pixels: return the pixels associated corresponding with the last call to |
594 | | % QueueAuthenticPixelsStream() or GetVirtualPixelStream(). |
595 | | % |
596 | | % o image: the image. |
597 | | % |
598 | | */ |
599 | | static const Quantum *GetVirtualPixelsStream(const Image *image) |
600 | 0 | { |
601 | 0 | CacheInfo |
602 | 0 | *cache_info; |
603 | |
|
604 | 0 | assert(image != (Image *) NULL); |
605 | 0 | assert(image->signature == MagickCoreSignature); |
606 | 0 | if (IsEventLogging() != MagickFalse) |
607 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
608 | 0 | cache_info=(CacheInfo *) image->cache; |
609 | 0 | assert(cache_info->signature == MagickCoreSignature); |
610 | 0 | return(cache_info->pixels); |
611 | 0 | } |
612 | | |
613 | | /* |
614 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
615 | | % % |
616 | | % % |
617 | | % % |
618 | | + 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 % |
619 | | % % |
620 | | % % |
621 | | % % |
622 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
623 | | % |
624 | | % GetVirtualMetacontentFromStream() returns the associated pixel channels |
625 | | % corresponding with the last call to QueueAuthenticPixelsStream() or |
626 | | % GetVirtualPixelStream(). |
627 | | % |
628 | | % The format of the GetVirtualMetacontentFromStream() method is: |
629 | | % |
630 | | % const void *GetVirtualMetacontentFromStream(const Image *image) |
631 | | % |
632 | | % A description of each parameter follows: |
633 | | % |
634 | | % o image: the image. |
635 | | % |
636 | | */ |
637 | | static const void *GetVirtualMetacontentFromStream(const Image *image) |
638 | 0 | { |
639 | 0 | CacheInfo |
640 | 0 | *cache_info; |
641 | |
|
642 | 0 | assert(image != (Image *) NULL); |
643 | 0 | assert(image->signature == MagickCoreSignature); |
644 | 0 | if (IsEventLogging() != MagickFalse) |
645 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
646 | 0 | cache_info=(CacheInfo *) image->cache; |
647 | 0 | assert(cache_info->signature == MagickCoreSignature); |
648 | 0 | return(cache_info->metacontent); |
649 | 0 | } |
650 | | |
651 | | /* |
652 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
653 | | % % |
654 | | % % |
655 | | % % |
656 | | + G e t V i r t u a l P i x e l S t r e a m % |
657 | | % % |
658 | | % % |
659 | | % % |
660 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
661 | | % |
662 | | % GetVirtualPixelStream() gets pixels from the in-memory or disk pixel cache as |
663 | | % defined by the geometry parameters. A pointer to the pixels is returned if |
664 | | % the pixels are transferred, otherwise a NULL is returned. For streams this |
665 | | % method is a no-op. |
666 | | % |
667 | | % The format of the GetVirtualPixelStream() method is: |
668 | | % |
669 | | % const Quantum *GetVirtualPixelStream(const Image *image, |
670 | | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
671 | | % const ssize_t y,const size_t columns,const size_t rows, |
672 | | % ExceptionInfo *exception) |
673 | | % |
674 | | % A description of each parameter follows: |
675 | | % |
676 | | % o image: the image. |
677 | | % |
678 | | % o virtual_pixel_method: the virtual pixel method. |
679 | | % |
680 | | % o x,y,columns,rows: These values define the perimeter of a region of |
681 | | % pixels. |
682 | | % |
683 | | % o exception: return any errors or warnings in this structure. |
684 | | % |
685 | | */ |
686 | | |
687 | | static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info, |
688 | | ExceptionInfo *exception) |
689 | 7.57k | { |
690 | 7.57k | if (cache_info->length != (MagickSizeType) ((size_t) cache_info->length)) |
691 | 0 | return(MagickFalse); |
692 | 7.57k | cache_info->pixels=(Quantum *) MagickAssumeAligned(AcquireAlignedMemory(1, |
693 | 7.57k | (size_t) cache_info->length)); |
694 | 7.57k | if (cache_info->pixels != (Quantum *) NULL) |
695 | 7.57k | (void) memset(cache_info->pixels,0,(size_t) cache_info->length); |
696 | 0 | else |
697 | 0 | { |
698 | 0 | (void) ThrowMagickException(exception,GetMagickModule(), |
699 | 0 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
700 | 0 | cache_info->filename); |
701 | 0 | return(MagickFalse); |
702 | 0 | } |
703 | 7.57k | return(MagickTrue); |
704 | 7.57k | } |
705 | | |
706 | | static const Quantum *GetVirtualPixelStream(const Image *image, |
707 | | const VirtualPixelMethod magick_unused(virtual_pixel_method),const ssize_t x, |
708 | | const ssize_t y,const size_t columns,const size_t rows, |
709 | | ExceptionInfo *exception) |
710 | 0 | { |
711 | 0 | CacheInfo |
712 | 0 | *cache_info; |
713 | |
|
714 | 0 | MagickBooleanType |
715 | 0 | status; |
716 | |
|
717 | 0 | MagickSizeType |
718 | 0 | number_pixels; |
719 | |
|
720 | 0 | size_t |
721 | 0 | length; |
722 | |
|
723 | 0 | magick_unreferenced(virtual_pixel_method); |
724 | | |
725 | | /* |
726 | | Validate pixel cache geometry. |
727 | | */ |
728 | 0 | assert(image != (const Image *) NULL); |
729 | 0 | assert(image->signature == MagickCoreSignature); |
730 | 0 | if (IsEventLogging() != MagickFalse) |
731 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
732 | 0 | if ((x < 0) || (y < 0) || |
733 | 0 | ((x+(ssize_t) columns) > (ssize_t) image->columns) || |
734 | 0 | ((y+(ssize_t) rows) > (ssize_t) image->rows) || |
735 | 0 | (columns == 0) || (rows == 0)) |
736 | 0 | { |
737 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
738 | 0 | "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename); |
739 | 0 | return((Quantum *) NULL); |
740 | 0 | } |
741 | 0 | cache_info=(CacheInfo *) image->cache; |
742 | 0 | assert(cache_info->signature == MagickCoreSignature); |
743 | | /* |
744 | | Pixels are stored in a temporary buffer until they are synced to the cache. |
745 | | */ |
746 | 0 | number_pixels=(MagickSizeType) columns*rows; |
747 | 0 | length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum); |
748 | 0 | if (cache_info->number_channels == 0) |
749 | 0 | length=(size_t) number_pixels*sizeof(Quantum); |
750 | 0 | if (cache_info->metacontent_extent != 0) |
751 | 0 | length+=(size_t) number_pixels*cache_info->metacontent_extent; |
752 | 0 | if (cache_info->pixels == (Quantum *) NULL) |
753 | 0 | { |
754 | 0 | cache_info->length=length; |
755 | 0 | status=AcquireStreamPixels(cache_info,exception); |
756 | 0 | if (status == MagickFalse) |
757 | 0 | { |
758 | 0 | cache_info->length=0; |
759 | 0 | return((Quantum *) NULL); |
760 | 0 | } |
761 | 0 | } |
762 | 0 | else |
763 | 0 | if (cache_info->length < length) |
764 | 0 | { |
765 | 0 | RelinquishStreamPixels(cache_info); |
766 | 0 | cache_info->length=length; |
767 | 0 | status=AcquireStreamPixels(cache_info,exception); |
768 | 0 | if (status == MagickFalse) |
769 | 0 | { |
770 | 0 | cache_info->length=0; |
771 | 0 | return((Quantum *) NULL); |
772 | 0 | } |
773 | 0 | } |
774 | 0 | cache_info->metacontent=(void *) NULL; |
775 | 0 | if (cache_info->metacontent_extent != 0) |
776 | 0 | cache_info->metacontent=(void *) (cache_info->pixels+number_pixels* |
777 | 0 | cache_info->number_channels); |
778 | 0 | return(cache_info->pixels); |
779 | 0 | } |
780 | | |
781 | | /* |
782 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
783 | | % % |
784 | | % % |
785 | | % % |
786 | | + O p e n S t r e a m % |
787 | | % % |
788 | | % % |
789 | | % % |
790 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
791 | | % |
792 | | % OpenStream() opens a stream for writing by the StreamImage() method. |
793 | | % |
794 | | % The format of the OpenStream method is: |
795 | | % |
796 | | % MagickBooleanType OpenStream(const ImageInfo *image_info, |
797 | | % StreamInfo *stream_info,const char *filename,ExceptionInfo *exception) |
798 | | % |
799 | | % A description of each parameter follows: |
800 | | % |
801 | | % o image_info: the image info. |
802 | | % |
803 | | % o stream_info: the stream info. |
804 | | % |
805 | | % o filename: the stream filename. |
806 | | % |
807 | | % o exception: return any errors or warnings in this structure. |
808 | | % |
809 | | */ |
810 | | MagickExport MagickBooleanType OpenStream(const ImageInfo *image_info, |
811 | | StreamInfo *stream_info,const char *filename,ExceptionInfo *exception) |
812 | 0 | { |
813 | 0 | MagickBooleanType |
814 | 0 | status; |
815 | |
|
816 | 0 | (void) CopyMagickString(stream_info->stream->filename,filename, |
817 | 0 | MagickPathExtent); |
818 | 0 | status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception); |
819 | 0 | return(status); |
820 | 0 | } |
821 | | |
822 | | /* |
823 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
824 | | % % |
825 | | % % |
826 | | % % |
827 | | + 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 % |
828 | | % % |
829 | | % % |
830 | | % % |
831 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
832 | | % |
833 | | % QueueAuthenticPixelsStream() allocates an area to store image pixels as |
834 | | % defined by the region rectangle and returns a pointer to the area. This |
835 | | % area is subsequently transferred from the pixel cache with method |
836 | | % SyncAuthenticPixelsStream(). A pointer to the pixels is returned if the |
837 | | % pixels are transferred, otherwise a NULL is returned. |
838 | | % |
839 | | % The format of the QueueAuthenticPixelsStream() method is: |
840 | | % |
841 | | % Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, |
842 | | % const ssize_t y,const size_t columns,const size_t rows, |
843 | | % ExceptionInfo *exception) |
844 | | % |
845 | | % A description of each parameter follows: |
846 | | % |
847 | | % o image: the image. |
848 | | % |
849 | | % o x,y,columns,rows: These values define the perimeter of a region of |
850 | | % pixels. |
851 | | % |
852 | | */ |
853 | | |
854 | | static inline MagickBooleanType ValidatePixelCacheMorphology( |
855 | | const Image *magick_restrict image) |
856 | 2.14M | { |
857 | 2.14M | const CacheInfo |
858 | 2.14M | *magick_restrict cache_info; |
859 | | |
860 | 2.14M | const PixelChannelMap |
861 | 2.14M | *magick_restrict p, |
862 | 2.14M | *magick_restrict q; |
863 | | |
864 | | /* |
865 | | Does the image match the pixel cache morphology? |
866 | | */ |
867 | 2.14M | cache_info=(CacheInfo *) image->cache; |
868 | 2.14M | p=image->channel_map; |
869 | 2.14M | q=cache_info->channel_map; |
870 | 2.14M | if ((image->storage_class != cache_info->storage_class) || |
871 | 2.14M | (image->colorspace != cache_info->colorspace) || |
872 | 2.14M | (image->alpha_trait != cache_info->alpha_trait) || |
873 | 2.14M | (image->channels != cache_info->channels) || |
874 | 2.14M | (image->columns != cache_info->columns) || |
875 | 2.14M | (image->rows != cache_info->rows) || |
876 | 7.34k | (image->number_channels != cache_info->number_channels) || |
877 | 7.34k | (memcmp(p,q,image->number_channels*sizeof(*p)) != 0) || |
878 | 7.34k | (image->metacontent_extent != cache_info->metacontent_extent) || |
879 | 7.34k | (cache_info->nexus_info == (NexusInfo **) NULL)) |
880 | 2.14M | return(MagickFalse); |
881 | 7.34k | return(MagickTrue); |
882 | 2.14M | } |
883 | | |
884 | | static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, |
885 | | const ssize_t y,const size_t columns,const size_t rows, |
886 | | ExceptionInfo *exception) |
887 | 2.14M | { |
888 | 2.14M | CacheInfo |
889 | 2.14M | *cache_info; |
890 | | |
891 | 2.14M | MagickBooleanType |
892 | 2.14M | status; |
893 | | |
894 | 2.14M | MagickSizeType |
895 | 2.14M | number_pixels; |
896 | | |
897 | 2.14M | size_t |
898 | 2.14M | length; |
899 | | |
900 | 2.14M | StreamHandler |
901 | 2.14M | stream_handler; |
902 | | |
903 | | /* |
904 | | Validate pixel cache geometry. |
905 | | */ |
906 | 2.14M | assert(image != (Image *) NULL); |
907 | 2.14M | if ((image->columns == 0) || (image->rows == 0) || (x < 0) || |
908 | 2.14M | (y < 0) || (x >= (ssize_t) image->columns) || |
909 | 2.14M | (y >= (ssize_t) image->rows)) |
910 | 1.54k | { |
911 | 1.54k | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
912 | 1.54k | "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename); |
913 | 1.54k | return((Quantum *) NULL); |
914 | 1.54k | } |
915 | 2.14M | stream_handler=GetBlobStreamHandler(image); |
916 | 2.14M | if (stream_handler == (StreamHandler) NULL) |
917 | 0 | { |
918 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
919 | 0 | "NoStreamHandlerIsDefined","`%s'",image->filename); |
920 | 0 | return((Quantum *) NULL); |
921 | 0 | } |
922 | 2.14M | cache_info=(CacheInfo *) image->cache; |
923 | 2.14M | assert(cache_info->signature == MagickCoreSignature); |
924 | 2.14M | if (ValidatePixelCacheMorphology(image) == MagickFalse) |
925 | 2.14M | { |
926 | 2.14M | if (cache_info->storage_class == UndefinedClass) |
927 | 0 | (void) stream_handler(image,(const void *) NULL,(size_t) |
928 | 0 | cache_info->columns); |
929 | 2.14M | cache_info->storage_class=image->storage_class; |
930 | 2.14M | cache_info->colorspace=image->colorspace; |
931 | 2.14M | cache_info->alpha_trait=image->alpha_trait; |
932 | 2.14M | cache_info->channels=image->channels; |
933 | 2.14M | cache_info->columns=image->columns; |
934 | 2.14M | cache_info->rows=image->rows; |
935 | 2.14M | cache_info->number_channels=image->number_channels; |
936 | 2.14M | status=ResetPixelChannelMap(image,exception); |
937 | 2.14M | if (status == MagickFalse) |
938 | 0 | return((Quantum *) NULL); |
939 | 2.14M | ResetPixelCacheChannels(image); |
940 | 2.14M | image->cache=cache_info; |
941 | 2.14M | } |
942 | | /* |
943 | | Pixels are stored in a temporary buffer until they are synced to the cache. |
944 | | */ |
945 | 2.14M | cache_info->columns=columns; |
946 | 2.14M | cache_info->rows=rows; |
947 | 2.14M | number_pixels=(MagickSizeType) columns*rows; |
948 | 2.14M | length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum); |
949 | 2.14M | if (cache_info->number_channels == 0) |
950 | 0 | length=(size_t) number_pixels*sizeof(Quantum); |
951 | 2.14M | if (cache_info->metacontent_extent != 0) |
952 | 0 | length+=(size_t) number_pixels*cache_info->metacontent_extent; |
953 | 2.14M | if (cache_info->pixels == (Quantum *) NULL) |
954 | 7.57k | { |
955 | 7.57k | cache_info->length=length; |
956 | 7.57k | status=AcquireStreamPixels(cache_info,exception); |
957 | 7.57k | if (status == MagickFalse) |
958 | 0 | { |
959 | 0 | cache_info->length=0; |
960 | 0 | return((Quantum *) NULL); |
961 | 0 | } |
962 | 7.57k | } |
963 | 2.14M | else |
964 | 2.14M | if (cache_info->length < length) |
965 | 0 | { |
966 | 0 | RelinquishStreamPixels(cache_info); |
967 | 0 | cache_info->length=length; |
968 | 0 | status=AcquireStreamPixels(cache_info,exception); |
969 | 0 | if (status == MagickFalse) |
970 | 0 | { |
971 | 0 | cache_info->length=0; |
972 | 0 | return((Quantum *) NULL); |
973 | 0 | } |
974 | 0 | } |
975 | 2.14M | cache_info->metacontent=(void *) NULL; |
976 | 2.14M | if (cache_info->metacontent_extent != 0) |
977 | 0 | cache_info->metacontent=(void *) (cache_info->pixels+number_pixels* |
978 | 0 | cache_info->number_channels); |
979 | 2.14M | return(cache_info->pixels); |
980 | 2.14M | } |
981 | | |
982 | | /* |
983 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
984 | | % % |
985 | | % % |
986 | | % % |
987 | | % R e a d S t r e a m % |
988 | | % % |
989 | | % % |
990 | | % % |
991 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
992 | | % |
993 | | % ReadStream() makes the image pixels available to a user supplied callback |
994 | | % method immediately upon reading a scanline with the ReadImage() method. |
995 | | % |
996 | | % The format of the ReadStream() method is: |
997 | | % |
998 | | % Image *ReadStream(const ImageInfo *image_info,StreamHandler stream, |
999 | | % ExceptionInfo *exception) |
1000 | | % |
1001 | | % A description of each parameter follows: |
1002 | | % |
1003 | | % o image_info: the image info. |
1004 | | % |
1005 | | % o stream: a callback method. |
1006 | | % |
1007 | | % o exception: return any errors or warnings in this structure. |
1008 | | % |
1009 | | */ |
1010 | | MagickExport Image *ReadStream(const ImageInfo *image_info,StreamHandler stream, |
1011 | | ExceptionInfo *exception) |
1012 | 30.7k | { |
1013 | 30.7k | CacheMethods |
1014 | 30.7k | cache_methods; |
1015 | | |
1016 | 30.7k | Image |
1017 | 30.7k | *image; |
1018 | | |
1019 | 30.7k | ImageInfo |
1020 | 30.7k | *read_info; |
1021 | | |
1022 | | /* |
1023 | | Stream image pixels. |
1024 | | */ |
1025 | 30.7k | assert(image_info != (ImageInfo *) NULL); |
1026 | 30.7k | assert(image_info->signature == MagickCoreSignature); |
1027 | 30.7k | assert(exception != (ExceptionInfo *) NULL); |
1028 | 30.7k | assert(exception->signature == MagickCoreSignature); |
1029 | 30.7k | if (IsEventLogging() != MagickFalse) |
1030 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
1031 | 0 | image_info->filename); |
1032 | 30.7k | read_info=CloneImageInfo(image_info); |
1033 | 30.7k | read_info->cache=AcquirePixelCache(0); |
1034 | 30.7k | GetPixelCacheMethods(&cache_methods); |
1035 | 30.7k | cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream; |
1036 | 30.7k | cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream; |
1037 | 30.7k | cache_methods.get_virtual_metacontent_from_handler= |
1038 | 30.7k | GetVirtualMetacontentFromStream; |
1039 | 30.7k | cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream; |
1040 | 30.7k | cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream; |
1041 | 30.7k | cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream; |
1042 | 30.7k | cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream; |
1043 | 30.7k | cache_methods.get_authentic_metacontent_from_handler= |
1044 | 30.7k | GetAuthenticMetacontentFromStream; |
1045 | 30.7k | cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream; |
1046 | 30.7k | cache_methods.get_one_authentic_pixel_from_handler= |
1047 | 30.7k | GetOneAuthenticPixelFromStream; |
1048 | 30.7k | cache_methods.destroy_pixel_handler=DestroyPixelStream; |
1049 | 30.7k | SetPixelCacheMethods(read_info->cache,&cache_methods); |
1050 | 30.7k | read_info->stream=stream; |
1051 | 30.7k | image=ReadImage(read_info,exception); |
1052 | 30.7k | read_info=DestroyImageInfo(read_info); |
1053 | 30.7k | if (image != (Image *) NULL) |
1054 | 8.18k | { |
1055 | 8.18k | MagickBooleanType status = ResetPixelChannelMap(image,exception); |
1056 | 8.18k | if (status == MagickFalse) |
1057 | 2 | return(DestroyImage(image)); |
1058 | 8.17k | ResetPixelCacheChannels(image); |
1059 | 8.17k | } |
1060 | 30.7k | return(image); |
1061 | 30.7k | } |
1062 | | |
1063 | | /* |
1064 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1065 | | % % |
1066 | | % % |
1067 | | % % |
1068 | | + R e s e t S t r e a m A n o n y m o u s M e m o r y % |
1069 | | % % |
1070 | | % % |
1071 | | % % |
1072 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1073 | | % |
1074 | | % ResetStreamAnonymousMemory() resets the anonymous_memory value. |
1075 | | % |
1076 | | % The format of the ResetStreamAnonymousMemory method is: |
1077 | | % |
1078 | | % void ResetStreamAnonymousMemory(void) |
1079 | | % |
1080 | | */ |
1081 | | MagickPrivate void ResetStreamAnonymousMemory(void) |
1082 | 294 | { |
1083 | 294 | } |
1084 | | |
1085 | | /* |
1086 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1087 | | % % |
1088 | | % % |
1089 | | % % |
1090 | | + S e t S t r e a m I n f o C l i e n t D a t a % |
1091 | | % % |
1092 | | % % |
1093 | | % % |
1094 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1095 | | % |
1096 | | % SetStreamInfoClientData() sets the stream info client data. |
1097 | | % |
1098 | | % The format of the SetStreamInfoClientData method is: |
1099 | | % |
1100 | | % void SetStreamInfoClientData(StreamInfo *stream_info, |
1101 | | % const void *client_data) |
1102 | | % |
1103 | | % A description of each parameter follows: |
1104 | | % |
1105 | | % o stream_info: the stream info. |
1106 | | % |
1107 | | % o client_data: the client data. |
1108 | | % |
1109 | | */ |
1110 | | MagickPrivate void SetStreamInfoClientData(StreamInfo *stream_info, |
1111 | | const void *client_data) |
1112 | 0 | { |
1113 | 0 | assert(stream_info != (StreamInfo *) NULL); |
1114 | 0 | assert(stream_info->signature == MagickCoreSignature); |
1115 | 0 | stream_info->client_data=client_data; |
1116 | 0 | } |
1117 | | |
1118 | | /* |
1119 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1120 | | % % |
1121 | | % % |
1122 | | % % |
1123 | | + S e t S t r e a m I n f o M a p % |
1124 | | % % |
1125 | | % % |
1126 | | % % |
1127 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1128 | | % |
1129 | | % SetStreamInfoMap() sets the stream info map member. |
1130 | | % |
1131 | | % The format of the SetStreamInfoMap method is: |
1132 | | % |
1133 | | % void SetStreamInfoMap(StreamInfo *stream_info,const char *map) |
1134 | | % |
1135 | | % A description of each parameter follows: |
1136 | | % |
1137 | | % o stream_info: the stream info. |
1138 | | % |
1139 | | % o map: the map. |
1140 | | % |
1141 | | */ |
1142 | | MagickExport void SetStreamInfoMap(StreamInfo *stream_info,const char *map) |
1143 | 0 | { |
1144 | 0 | assert(stream_info != (StreamInfo *) NULL); |
1145 | 0 | assert(stream_info->signature == MagickCoreSignature); |
1146 | 0 | (void) CloneString(&stream_info->map,map); |
1147 | 0 | } |
1148 | | |
1149 | | /* |
1150 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1151 | | % % |
1152 | | % % |
1153 | | % % |
1154 | | + S e t S t r e a m I n f o S t o r a g e T y p e % |
1155 | | % % |
1156 | | % % |
1157 | | % % |
1158 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1159 | | % |
1160 | | % SetStreamInfoStorageType() sets the stream info storage type member. |
1161 | | % |
1162 | | % The format of the SetStreamInfoStorageType method is: |
1163 | | % |
1164 | | % void SetStreamInfoStorageType(StreamInfo *stream_info, |
1165 | | % const StorageType *storage_type) |
1166 | | % |
1167 | | % A description of each parameter follows: |
1168 | | % |
1169 | | % o stream_info: the stream info. |
1170 | | % |
1171 | | % o storage_type: the storage type. |
1172 | | % |
1173 | | */ |
1174 | | MagickExport void SetStreamInfoStorageType(StreamInfo *stream_info, |
1175 | | const StorageType storage_type) |
1176 | 0 | { |
1177 | 0 | assert(stream_info != (StreamInfo *) NULL); |
1178 | 0 | assert(stream_info->signature == MagickCoreSignature); |
1179 | 0 | stream_info->storage_type=storage_type; |
1180 | 0 | } |
1181 | | |
1182 | | /* |
1183 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1184 | | % % |
1185 | | % % |
1186 | | % % |
1187 | | + S t r e a m I m a g e % |
1188 | | % % |
1189 | | % % |
1190 | | % % |
1191 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1192 | | % |
1193 | | % StreamImage() streams pixels from an image and writes them in a user |
1194 | | % defined format and storage type (e.g. RGBA as 8-bit unsigned char). |
1195 | | % |
1196 | | % The format of the StreamImage() method is: |
1197 | | % |
1198 | | % Image *StreamImage(const ImageInfo *image_info, |
1199 | | % StreamInfo *stream_info,ExceptionInfo *exception) |
1200 | | % |
1201 | | % A description of each parameter follows: |
1202 | | % |
1203 | | % o image_info: the image info. |
1204 | | % |
1205 | | % o stream_info: the stream info. |
1206 | | % |
1207 | | % o exception: return any errors or warnings in this structure. |
1208 | | % |
1209 | | */ |
1210 | | |
1211 | | #if defined(__cplusplus) || defined(c_plusplus) |
1212 | | extern "C" { |
1213 | | #endif |
1214 | | |
1215 | | static size_t WriteStreamImage(const Image *image,const void *pixels, |
1216 | | const size_t columns) |
1217 | 0 | { |
1218 | 0 | CacheInfo |
1219 | 0 | *cache_info; |
1220 | |
|
1221 | 0 | RectangleInfo |
1222 | 0 | extract_info; |
1223 | |
|
1224 | 0 | size_t |
1225 | 0 | length, |
1226 | 0 | packet_size; |
1227 | |
|
1228 | 0 | ssize_t |
1229 | 0 | count; |
1230 | |
|
1231 | 0 | StreamInfo |
1232 | 0 | *stream_info; |
1233 | |
|
1234 | 0 | (void) pixels; |
1235 | 0 | stream_info=(StreamInfo *) image->client_data; |
1236 | 0 | switch (stream_info->storage_type) |
1237 | 0 | { |
1238 | 0 | default: packet_size=sizeof(unsigned char); break; |
1239 | 0 | case CharPixel: packet_size=sizeof(unsigned char); break; |
1240 | 0 | case DoublePixel: packet_size=sizeof(double); break; |
1241 | 0 | case FloatPixel: packet_size=sizeof(float); break; |
1242 | 0 | case LongPixel: packet_size=sizeof(unsigned int); break; |
1243 | 0 | case LongLongPixel: packet_size=sizeof(MagickSizeType); break; |
1244 | 0 | case QuantumPixel: packet_size=sizeof(Quantum); break; |
1245 | 0 | case ShortPixel: packet_size=sizeof(unsigned short); break; |
1246 | 0 | } |
1247 | 0 | cache_info=(CacheInfo *) image->cache; |
1248 | 0 | assert(cache_info->signature == MagickCoreSignature); |
1249 | 0 | packet_size*=strlen(stream_info->map); |
1250 | 0 | length=packet_size*cache_info->columns*cache_info->rows; |
1251 | 0 | if (image != stream_info->image) |
1252 | 0 | { |
1253 | 0 | ImageInfo |
1254 | 0 | *write_info; |
1255 | | |
1256 | | /* |
1257 | | Prepare stream for writing. |
1258 | | */ |
1259 | 0 | (void) RelinquishAlignedMemory(stream_info->pixels); |
1260 | 0 | stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length); |
1261 | 0 | if (stream_info->pixels == (unsigned char *) NULL) |
1262 | 0 | return(0); |
1263 | 0 | (void) memset(stream_info->pixels,0,length); |
1264 | 0 | stream_info->image=image; |
1265 | 0 | write_info=CloneImageInfo(stream_info->image_info); |
1266 | 0 | (void) SetImageInfo(write_info,1,stream_info->exception); |
1267 | 0 | if (write_info->extract != (char *) NULL) |
1268 | 0 | (void) ParseAbsoluteGeometry(write_info->extract, |
1269 | 0 | &stream_info->extract_info); |
1270 | 0 | stream_info->y=0; |
1271 | 0 | write_info=DestroyImageInfo(write_info); |
1272 | 0 | } |
1273 | 0 | extract_info=stream_info->extract_info; |
1274 | 0 | if ((extract_info.width == 0) || (extract_info.height == 0)) |
1275 | 0 | { |
1276 | | /* |
1277 | | Write all pixels to stream. |
1278 | | */ |
1279 | 0 | (void) StreamImagePixels(stream_info,image,stream_info->exception); |
1280 | 0 | count=WriteBlob(stream_info->stream,length,stream_info->pixels); |
1281 | 0 | stream_info->y++; |
1282 | 0 | return(count == 0 ? 0 : columns); |
1283 | 0 | } |
1284 | 0 | if ((stream_info->y < extract_info.y) || |
1285 | 0 | (stream_info->y >= (extract_info.y+(ssize_t) extract_info.height))) |
1286 | 0 | { |
1287 | 0 | stream_info->y++; |
1288 | 0 | return(columns); |
1289 | 0 | } |
1290 | | /* |
1291 | | Write a portion of the pixel row to the stream. |
1292 | | */ |
1293 | 0 | (void) StreamImagePixels(stream_info,image,stream_info->exception); |
1294 | 0 | length=packet_size*extract_info.width; |
1295 | 0 | count=WriteBlob(stream_info->stream,length,stream_info->pixels+(ssize_t) |
1296 | 0 | packet_size*extract_info.x); |
1297 | 0 | stream_info->y++; |
1298 | 0 | return(count == 0 ? 0 : columns); |
1299 | 0 | } |
1300 | | |
1301 | | #if defined(__cplusplus) || defined(c_plusplus) |
1302 | | } |
1303 | | #endif |
1304 | | |
1305 | | MagickExport Image *StreamImage(const ImageInfo *image_info, |
1306 | | StreamInfo *stream_info,ExceptionInfo *exception) |
1307 | 0 | { |
1308 | 0 | Image |
1309 | 0 | *image; |
1310 | |
|
1311 | 0 | ImageInfo |
1312 | 0 | *read_info; |
1313 | |
|
1314 | 0 | assert(image_info != (const ImageInfo *) NULL); |
1315 | 0 | assert(image_info->signature == MagickCoreSignature); |
1316 | 0 | assert(stream_info != (StreamInfo *) NULL); |
1317 | 0 | assert(stream_info->signature == MagickCoreSignature); |
1318 | 0 | assert(exception != (ExceptionInfo *) NULL); |
1319 | 0 | if (IsEventLogging() != MagickFalse) |
1320 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
1321 | 0 | image_info->filename); |
1322 | 0 | read_info=CloneImageInfo(image_info); |
1323 | 0 | stream_info->image_info=image_info; |
1324 | 0 | if (stream_info->quantum_info == (QuantumInfo *) NULL) |
1325 | 0 | stream_info->quantum_info=AcquireQuantumInfo(image_info,(Image *) NULL); |
1326 | 0 | if (stream_info->quantum_info == (QuantumInfo *) NULL) |
1327 | 0 | { |
1328 | 0 | read_info=DestroyImageInfo(read_info); |
1329 | 0 | return((Image *) NULL); |
1330 | 0 | } |
1331 | 0 | stream_info->exception=exception; |
1332 | 0 | read_info->client_data=(void *) stream_info; |
1333 | 0 | image=ReadStream(read_info,&WriteStreamImage,exception); |
1334 | 0 | read_info=DestroyImageInfo(read_info); |
1335 | 0 | stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info); |
1336 | 0 | stream_info->quantum_info=AcquireQuantumInfo(image_info,image); |
1337 | 0 | if (stream_info->quantum_info == (QuantumInfo *) NULL) |
1338 | 0 | image=DestroyImage(image); |
1339 | 0 | return(image); |
1340 | 0 | } |
1341 | | |
1342 | | /* |
1343 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1344 | | % % |
1345 | | % % |
1346 | | % % |
1347 | | + S t r e a m I m a g e P i x e l s % |
1348 | | % % |
1349 | | % % |
1350 | | % % |
1351 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1352 | | % |
1353 | | % StreamImagePixels() extracts pixel data from an image and returns it in the |
1354 | | % stream_info->pixels structure in the format as defined by |
1355 | | % stream_info->quantum_info->map and stream_info->quantum_info->storage_type. |
1356 | | % |
1357 | | % The format of the StreamImagePixels method is: |
1358 | | % |
1359 | | % MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, |
1360 | | % const Image *image,ExceptionInfo *exception) |
1361 | | % |
1362 | | % A description of each parameter follows: |
1363 | | % |
1364 | | % o stream_info: the stream info. |
1365 | | % |
1366 | | % o image: the image. |
1367 | | % |
1368 | | % o exception: return any errors or warnings in this structure. |
1369 | | % |
1370 | | */ |
1371 | | static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, |
1372 | | const Image *image,ExceptionInfo *exception) |
1373 | 0 | { |
1374 | 0 | QuantumInfo |
1375 | 0 | *quantum_info; |
1376 | |
|
1377 | 0 | QuantumType |
1378 | 0 | *quantum_map; |
1379 | |
|
1380 | 0 | const Quantum |
1381 | 0 | *p; |
1382 | |
|
1383 | 0 | ssize_t |
1384 | 0 | i, |
1385 | 0 | x; |
1386 | |
|
1387 | 0 | size_t |
1388 | 0 | length; |
1389 | |
|
1390 | 0 | assert(stream_info != (StreamInfo *) NULL); |
1391 | 0 | assert(stream_info->signature == MagickCoreSignature); |
1392 | 0 | assert(image != (Image *) NULL); |
1393 | 0 | assert(image->signature == MagickCoreSignature); |
1394 | 0 | if (IsEventLogging() != MagickFalse) |
1395 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
1396 | 0 | length=strlen(stream_info->map); |
1397 | 0 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
1398 | 0 | if (quantum_map == (QuantumType *) NULL) |
1399 | 0 | { |
1400 | 0 | (void) ThrowMagickException(exception,GetMagickModule(), |
1401 | 0 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
1402 | 0 | return(MagickFalse); |
1403 | 0 | } |
1404 | 0 | (void) memset(quantum_map,0,length*sizeof(*quantum_map)); |
1405 | 0 | for (i=0; i < (ssize_t) length; i++) |
1406 | 0 | { |
1407 | 0 | switch (stream_info->map[i]) |
1408 | 0 | { |
1409 | 0 | case 'A': |
1410 | 0 | case 'a': |
1411 | 0 | { |
1412 | 0 | quantum_map[i]=AlphaQuantum; |
1413 | 0 | break; |
1414 | 0 | } |
1415 | 0 | case 'B': |
1416 | 0 | case 'b': |
1417 | 0 | { |
1418 | 0 | quantum_map[i]=BlueQuantum; |
1419 | 0 | break; |
1420 | 0 | } |
1421 | 0 | case 'C': |
1422 | 0 | case 'c': |
1423 | 0 | { |
1424 | 0 | quantum_map[i]=CyanQuantum; |
1425 | 0 | if (image->colorspace == CMYKColorspace) |
1426 | 0 | break; |
1427 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
1428 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1429 | 0 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
1430 | 0 | return(MagickFalse); |
1431 | 0 | } |
1432 | 0 | case 'g': |
1433 | 0 | case 'G': |
1434 | 0 | { |
1435 | 0 | quantum_map[i]=GreenQuantum; |
1436 | 0 | break; |
1437 | 0 | } |
1438 | 0 | case 'I': |
1439 | 0 | case 'i': |
1440 | 0 | { |
1441 | 0 | quantum_map[i]=IndexQuantum; |
1442 | 0 | break; |
1443 | 0 | } |
1444 | 0 | case 'K': |
1445 | 0 | case 'k': |
1446 | 0 | { |
1447 | 0 | quantum_map[i]=BlackQuantum; |
1448 | 0 | if (image->colorspace == CMYKColorspace) |
1449 | 0 | break; |
1450 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
1451 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1452 | 0 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
1453 | 0 | return(MagickFalse); |
1454 | 0 | } |
1455 | 0 | case 'M': |
1456 | 0 | case 'm': |
1457 | 0 | { |
1458 | 0 | quantum_map[i]=MagentaQuantum; |
1459 | 0 | if (image->colorspace == CMYKColorspace) |
1460 | 0 | break; |
1461 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
1462 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1463 | 0 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
1464 | 0 | return(MagickFalse); |
1465 | 0 | } |
1466 | 0 | case 'o': |
1467 | 0 | case 'O': |
1468 | 0 | { |
1469 | 0 | quantum_map[i]=OpacityQuantum; |
1470 | 0 | break; |
1471 | 0 | } |
1472 | 0 | case 'P': |
1473 | 0 | case 'p': |
1474 | 0 | { |
1475 | 0 | quantum_map[i]=UndefinedQuantum; |
1476 | 0 | break; |
1477 | 0 | } |
1478 | 0 | case 'R': |
1479 | 0 | case 'r': |
1480 | 0 | { |
1481 | 0 | quantum_map[i]=RedQuantum; |
1482 | 0 | break; |
1483 | 0 | } |
1484 | 0 | case 'Y': |
1485 | 0 | case 'y': |
1486 | 0 | { |
1487 | 0 | quantum_map[i]=YellowQuantum; |
1488 | 0 | if (image->colorspace == CMYKColorspace) |
1489 | 0 | break; |
1490 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
1491 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
1492 | 0 | "ColorSeparatedImageRequired","`%s'",stream_info->map); |
1493 | 0 | return(MagickFalse); |
1494 | 0 | } |
1495 | 0 | default: |
1496 | 0 | { |
1497 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
1498 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
1499 | 0 | "UnrecognizedPixelMap","`%s'",stream_info->map); |
1500 | 0 | return(MagickFalse); |
1501 | 0 | } |
1502 | 0 | } |
1503 | 0 | } |
1504 | 0 | quantum_info=stream_info->quantum_info; |
1505 | 0 | switch (stream_info->storage_type) |
1506 | 0 | { |
1507 | 0 | case CharPixel: |
1508 | 0 | { |
1509 | 0 | unsigned char |
1510 | 0 | *q; |
1511 | |
|
1512 | 0 | q=(unsigned char *) stream_info->pixels; |
1513 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
1514 | 0 | { |
1515 | 0 | p=GetAuthenticPixelQueue(image); |
1516 | 0 | if (p == (const Quantum *) NULL) |
1517 | 0 | break; |
1518 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1519 | 0 | { |
1520 | 0 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1521 | 0 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1522 | 0 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
1523 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1524 | 0 | } |
1525 | 0 | break; |
1526 | 0 | } |
1527 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
1528 | 0 | { |
1529 | 0 | p=GetAuthenticPixelQueue(image); |
1530 | 0 | if (p == (const Quantum *) NULL) |
1531 | 0 | break; |
1532 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1533 | 0 | { |
1534 | 0 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1535 | 0 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1536 | 0 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
1537 | 0 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
1538 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1539 | 0 | } |
1540 | 0 | break; |
1541 | 0 | } |
1542 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
1543 | 0 | { |
1544 | 0 | p=GetAuthenticPixelQueue(image); |
1545 | 0 | if (p == (const Quantum *) NULL) |
1546 | 0 | break; |
1547 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1548 | 0 | { |
1549 | 0 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1550 | 0 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1551 | 0 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
1552 | 0 | *q++=ScaleQuantumToChar((Quantum) 0); |
1553 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1554 | 0 | } |
1555 | 0 | break; |
1556 | 0 | } |
1557 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
1558 | 0 | { |
1559 | 0 | p=GetAuthenticPixelQueue(image); |
1560 | 0 | if (p == (const Quantum *) NULL) |
1561 | 0 | break; |
1562 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1563 | 0 | { |
1564 | 0 | *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p))); |
1565 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1566 | 0 | } |
1567 | 0 | break; |
1568 | 0 | } |
1569 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
1570 | 0 | { |
1571 | 0 | p=GetAuthenticPixelQueue(image); |
1572 | 0 | if (p == (const Quantum *) NULL) |
1573 | 0 | break; |
1574 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1575 | 0 | { |
1576 | 0 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
1577 | 0 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1578 | 0 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1579 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1580 | 0 | } |
1581 | 0 | break; |
1582 | 0 | } |
1583 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
1584 | 0 | { |
1585 | 0 | p=GetAuthenticPixelQueue(image); |
1586 | 0 | if (p == (const Quantum *) NULL) |
1587 | 0 | break; |
1588 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1589 | 0 | { |
1590 | 0 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
1591 | 0 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1592 | 0 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1593 | 0 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
1594 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1595 | 0 | } |
1596 | 0 | break; |
1597 | 0 | } |
1598 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
1599 | 0 | { |
1600 | 0 | p=GetAuthenticPixelQueue(image); |
1601 | 0 | if (p == (const Quantum *) NULL) |
1602 | 0 | break; |
1603 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1604 | 0 | { |
1605 | 0 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
1606 | 0 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1607 | 0 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1608 | 0 | *q++=ScaleQuantumToChar((Quantum) 0); |
1609 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1610 | 0 | } |
1611 | 0 | break; |
1612 | 0 | } |
1613 | 0 | p=GetAuthenticPixelQueue(image); |
1614 | 0 | if (p == (const Quantum *) NULL) |
1615 | 0 | break; |
1616 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1617 | 0 | { |
1618 | 0 | for (i=0; i < (ssize_t) length; i++) |
1619 | 0 | { |
1620 | 0 | *q=0; |
1621 | 0 | switch (quantum_map[i]) |
1622 | 0 | { |
1623 | 0 | case RedQuantum: |
1624 | 0 | case CyanQuantum: |
1625 | 0 | { |
1626 | 0 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
1627 | 0 | break; |
1628 | 0 | } |
1629 | 0 | case GreenQuantum: |
1630 | 0 | case MagentaQuantum: |
1631 | 0 | { |
1632 | 0 | *q=ScaleQuantumToChar(GetPixelGreen(image,p)); |
1633 | 0 | break; |
1634 | 0 | } |
1635 | 0 | case BlueQuantum: |
1636 | 0 | case YellowQuantum: |
1637 | 0 | { |
1638 | 0 | *q=ScaleQuantumToChar(GetPixelBlue(image,p)); |
1639 | 0 | break; |
1640 | 0 | } |
1641 | 0 | case AlphaQuantum: |
1642 | 0 | { |
1643 | 0 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
1644 | 0 | break; |
1645 | 0 | } |
1646 | 0 | case OpacityQuantum: |
1647 | 0 | { |
1648 | 0 | *q=ScaleQuantumToChar(GetPixelOpacity(image,p)); |
1649 | 0 | break; |
1650 | 0 | } |
1651 | 0 | case BlackQuantum: |
1652 | 0 | { |
1653 | 0 | if (image->colorspace == CMYKColorspace) |
1654 | 0 | *q=ScaleQuantumToChar(GetPixelBlack(image,p)); |
1655 | 0 | break; |
1656 | 0 | } |
1657 | 0 | case IndexQuantum: |
1658 | 0 | { |
1659 | 0 | *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p))); |
1660 | 0 | break; |
1661 | 0 | } |
1662 | 0 | default: |
1663 | 0 | break; |
1664 | 0 | } |
1665 | 0 | q++; |
1666 | 0 | } |
1667 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1668 | 0 | } |
1669 | 0 | break; |
1670 | 0 | } |
1671 | 0 | case DoublePixel: |
1672 | 0 | { |
1673 | 0 | double |
1674 | 0 | *q; |
1675 | |
|
1676 | 0 | q=(double *) stream_info->pixels; |
1677 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
1678 | 0 | { |
1679 | 0 | p=GetAuthenticPixelQueue(image); |
1680 | 0 | if (p == (const Quantum *) NULL) |
1681 | 0 | break; |
1682 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1683 | 0 | { |
1684 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1685 | 0 | quantum_info->scale+quantum_info->minimum); |
1686 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1687 | 0 | quantum_info->scale+quantum_info->minimum); |
1688 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1689 | 0 | quantum_info->scale+quantum_info->minimum); |
1690 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1691 | 0 | } |
1692 | 0 | break; |
1693 | 0 | } |
1694 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
1695 | 0 | { |
1696 | 0 | p=GetAuthenticPixelQueue(image); |
1697 | 0 | if (p == (const Quantum *) NULL) |
1698 | 0 | break; |
1699 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1700 | 0 | { |
1701 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1702 | 0 | quantum_info->scale+quantum_info->minimum); |
1703 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1704 | 0 | quantum_info->scale+quantum_info->minimum); |
1705 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1706 | 0 | quantum_info->scale+quantum_info->minimum); |
1707 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelAlpha(image,p))* |
1708 | 0 | quantum_info->scale+quantum_info->minimum); |
1709 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1710 | 0 | } |
1711 | 0 | break; |
1712 | 0 | } |
1713 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
1714 | 0 | { |
1715 | 0 | p=GetAuthenticPixelQueue(image); |
1716 | 0 | if (p == (const Quantum *) NULL) |
1717 | 0 | break; |
1718 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1719 | 0 | { |
1720 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1721 | 0 | quantum_info->scale+quantum_info->minimum); |
1722 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1723 | 0 | quantum_info->scale+quantum_info->minimum); |
1724 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1725 | 0 | quantum_info->scale+quantum_info->minimum); |
1726 | 0 | *q++=0.0; |
1727 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1728 | 0 | } |
1729 | 0 | break; |
1730 | 0 | } |
1731 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
1732 | 0 | { |
1733 | 0 | p=GetAuthenticPixelQueue(image); |
1734 | 0 | if (p == (const Quantum *) NULL) |
1735 | 0 | break; |
1736 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1737 | 0 | { |
1738 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelIntensity(image,p))* |
1739 | 0 | quantum_info->scale+quantum_info->minimum); |
1740 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1741 | 0 | } |
1742 | 0 | break; |
1743 | 0 | } |
1744 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
1745 | 0 | { |
1746 | 0 | p=GetAuthenticPixelQueue(image); |
1747 | 0 | if (p == (const Quantum *) NULL) |
1748 | 0 | break; |
1749 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1750 | 0 | { |
1751 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1752 | 0 | quantum_info->scale+quantum_info->minimum); |
1753 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1754 | 0 | quantum_info->scale+quantum_info->minimum); |
1755 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1756 | 0 | quantum_info->scale+quantum_info->minimum); |
1757 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1758 | 0 | } |
1759 | 0 | break; |
1760 | 0 | } |
1761 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
1762 | 0 | { |
1763 | 0 | p=GetAuthenticPixelQueue(image); |
1764 | 0 | if (p == (const Quantum *) NULL) |
1765 | 0 | break; |
1766 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1767 | 0 | { |
1768 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1769 | 0 | quantum_info->scale+quantum_info->minimum); |
1770 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1771 | 0 | quantum_info->scale+quantum_info->minimum); |
1772 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1773 | 0 | quantum_info->scale+quantum_info->minimum); |
1774 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelAlpha(image,p))* |
1775 | 0 | quantum_info->scale+quantum_info->minimum); |
1776 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1777 | 0 | } |
1778 | 0 | break; |
1779 | 0 | } |
1780 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
1781 | 0 | { |
1782 | 0 | p=GetAuthenticPixelQueue(image); |
1783 | 0 | if (p == (const Quantum *) NULL) |
1784 | 0 | break; |
1785 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1786 | 0 | { |
1787 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1788 | 0 | quantum_info->scale+quantum_info->minimum); |
1789 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1790 | 0 | quantum_info->scale+quantum_info->minimum); |
1791 | 0 | *q++=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1792 | 0 | quantum_info->scale+quantum_info->minimum); |
1793 | 0 | *q++=0.0; |
1794 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1795 | 0 | } |
1796 | 0 | break; |
1797 | 0 | } |
1798 | 0 | p=GetAuthenticPixelQueue(image); |
1799 | 0 | if (p == (const Quantum *) NULL) |
1800 | 0 | break; |
1801 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1802 | 0 | { |
1803 | 0 | for (i=0; i < (ssize_t) length; i++) |
1804 | 0 | { |
1805 | 0 | *q=0; |
1806 | 0 | switch (quantum_map[i]) |
1807 | 0 | { |
1808 | 0 | case RedQuantum: |
1809 | 0 | case CyanQuantum: |
1810 | 0 | { |
1811 | 0 | *q=(double) ((QuantumScale*(double) GetPixelRed(image,p))* |
1812 | 0 | quantum_info->scale+quantum_info->minimum); |
1813 | 0 | break; |
1814 | 0 | } |
1815 | 0 | case GreenQuantum: |
1816 | 0 | case MagentaQuantum: |
1817 | 0 | { |
1818 | 0 | *q=(double) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1819 | 0 | quantum_info->scale+quantum_info->minimum); |
1820 | 0 | break; |
1821 | 0 | } |
1822 | 0 | case BlueQuantum: |
1823 | 0 | case YellowQuantum: |
1824 | 0 | { |
1825 | 0 | *q=(double) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1826 | 0 | quantum_info->scale+quantum_info->minimum); |
1827 | 0 | break; |
1828 | 0 | } |
1829 | 0 | case AlphaQuantum: |
1830 | 0 | { |
1831 | 0 | *q=(double) ((QuantumScale*(double) GetPixelAlpha(image,p))* |
1832 | 0 | quantum_info->scale+quantum_info->minimum); |
1833 | 0 | break; |
1834 | 0 | } |
1835 | 0 | case OpacityQuantum: |
1836 | 0 | { |
1837 | 0 | *q=(double) ((QuantumScale*(double) GetPixelOpacity(image,p))* |
1838 | 0 | quantum_info->scale+quantum_info->minimum); |
1839 | 0 | break; |
1840 | 0 | } |
1841 | 0 | case BlackQuantum: |
1842 | 0 | { |
1843 | 0 | if (image->colorspace == CMYKColorspace) |
1844 | 0 | *q=(double) ((QuantumScale*(double) GetPixelBlack(image,p))* |
1845 | 0 | quantum_info->scale+quantum_info->minimum); |
1846 | 0 | break; |
1847 | 0 | } |
1848 | 0 | case IndexQuantum: |
1849 | 0 | { |
1850 | 0 | *q=(double) ((QuantumScale*(double) GetPixelIntensity(image,p))* |
1851 | 0 | quantum_info->scale+quantum_info->minimum); |
1852 | 0 | break; |
1853 | 0 | } |
1854 | 0 | default: |
1855 | 0 | *q=0; |
1856 | 0 | } |
1857 | 0 | q++; |
1858 | 0 | } |
1859 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1860 | 0 | } |
1861 | 0 | break; |
1862 | 0 | } |
1863 | 0 | case FloatPixel: |
1864 | 0 | { |
1865 | 0 | float |
1866 | 0 | *q; |
1867 | |
|
1868 | 0 | q=(float *) stream_info->pixels; |
1869 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
1870 | 0 | { |
1871 | 0 | p=GetAuthenticPixelQueue(image); |
1872 | 0 | if (p == (const Quantum *) NULL) |
1873 | 0 | break; |
1874 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1875 | 0 | { |
1876 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1877 | 0 | quantum_info->scale+quantum_info->minimum); |
1878 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1879 | 0 | quantum_info->scale+quantum_info->minimum); |
1880 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
1881 | 0 | quantum_info->scale+quantum_info->minimum); |
1882 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1883 | 0 | } |
1884 | 0 | break; |
1885 | 0 | } |
1886 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
1887 | 0 | { |
1888 | 0 | p=GetAuthenticPixelQueue(image); |
1889 | 0 | if (p == (const Quantum *) NULL) |
1890 | 0 | break; |
1891 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1892 | 0 | { |
1893 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1894 | 0 | quantum_info->scale+quantum_info->minimum); |
1895 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1896 | 0 | quantum_info->scale+quantum_info->minimum); |
1897 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
1898 | 0 | quantum_info->scale+quantum_info->minimum); |
1899 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelAlpha(image,p))* |
1900 | 0 | quantum_info->scale+quantum_info->minimum); |
1901 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1902 | 0 | } |
1903 | 0 | break; |
1904 | 0 | } |
1905 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
1906 | 0 | { |
1907 | 0 | p=GetAuthenticPixelQueue(image); |
1908 | 0 | if (p == (const Quantum *) NULL) |
1909 | 0 | break; |
1910 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1911 | 0 | { |
1912 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1913 | 0 | quantum_info->scale+quantum_info->minimum); |
1914 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1915 | 0 | quantum_info->scale+quantum_info->minimum); |
1916 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
1917 | 0 | quantum_info->scale+quantum_info->minimum); |
1918 | 0 | *q++=0.0; |
1919 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1920 | 0 | } |
1921 | 0 | break; |
1922 | 0 | } |
1923 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
1924 | 0 | { |
1925 | 0 | p=GetAuthenticPixelQueue(image); |
1926 | 0 | if (p == (const Quantum *) NULL) |
1927 | 0 | break; |
1928 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1929 | 0 | { |
1930 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelIntensity(image,p))* |
1931 | 0 | quantum_info->scale+quantum_info->minimum); |
1932 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1933 | 0 | } |
1934 | 0 | break; |
1935 | 0 | } |
1936 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
1937 | 0 | { |
1938 | 0 | p=GetAuthenticPixelQueue(image); |
1939 | 0 | if (p == (const Quantum *) NULL) |
1940 | 0 | break; |
1941 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1942 | 0 | { |
1943 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
1944 | 0 | quantum_info->scale+quantum_info->minimum); |
1945 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1946 | 0 | quantum_info->scale+quantum_info->minimum); |
1947 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1948 | 0 | quantum_info->scale+quantum_info->minimum); |
1949 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1950 | 0 | } |
1951 | 0 | break; |
1952 | 0 | } |
1953 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
1954 | 0 | { |
1955 | 0 | p=GetAuthenticPixelQueue(image); |
1956 | 0 | if (p == (const Quantum *) NULL) |
1957 | 0 | break; |
1958 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1959 | 0 | { |
1960 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
1961 | 0 | quantum_info->scale+quantum_info->minimum); |
1962 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1963 | 0 | quantum_info->scale+quantum_info->minimum); |
1964 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1965 | 0 | quantum_info->scale+quantum_info->minimum); |
1966 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelAlpha(image,p))* |
1967 | 0 | quantum_info->scale+quantum_info->minimum); |
1968 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1969 | 0 | } |
1970 | 0 | break; |
1971 | 0 | } |
1972 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
1973 | 0 | { |
1974 | 0 | p=GetAuthenticPixelQueue(image); |
1975 | 0 | if (p == (const Quantum *) NULL) |
1976 | 0 | break; |
1977 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1978 | 0 | { |
1979 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
1980 | 0 | quantum_info->scale+quantum_info->minimum); |
1981 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
1982 | 0 | quantum_info->scale+quantum_info->minimum); |
1983 | 0 | *q++=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
1984 | 0 | quantum_info->scale+quantum_info->minimum); |
1985 | 0 | *q++=0.0; |
1986 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
1987 | 0 | } |
1988 | 0 | break; |
1989 | 0 | } |
1990 | 0 | p=GetAuthenticPixelQueue(image); |
1991 | 0 | if (p == (const Quantum *) NULL) |
1992 | 0 | break; |
1993 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
1994 | 0 | { |
1995 | 0 | for (i=0; i < (ssize_t) length; i++) |
1996 | 0 | { |
1997 | 0 | *q=0; |
1998 | 0 | switch (quantum_map[i]) |
1999 | 0 | { |
2000 | 0 | case RedQuantum: |
2001 | 0 | case CyanQuantum: |
2002 | 0 | { |
2003 | 0 | *q=(float) ((QuantumScale*(double) GetPixelRed(image,p))* |
2004 | 0 | quantum_info->scale+quantum_info->minimum); |
2005 | 0 | break; |
2006 | 0 | } |
2007 | 0 | case GreenQuantum: |
2008 | 0 | case MagentaQuantum: |
2009 | 0 | { |
2010 | 0 | *q=(float) ((QuantumScale*(double) GetPixelGreen(image,p))* |
2011 | 0 | quantum_info->scale+quantum_info->minimum); |
2012 | 0 | break; |
2013 | 0 | } |
2014 | 0 | case BlueQuantum: |
2015 | 0 | case YellowQuantum: |
2016 | 0 | { |
2017 | 0 | *q=(float) ((QuantumScale*(double) GetPixelBlue(image,p))* |
2018 | 0 | quantum_info->scale+quantum_info->minimum); |
2019 | 0 | break; |
2020 | 0 | } |
2021 | 0 | case AlphaQuantum: |
2022 | 0 | { |
2023 | 0 | *q=(float) ((QuantumScale*(double) GetPixelAlpha(image,p))* |
2024 | 0 | quantum_info->scale+quantum_info->minimum); |
2025 | 0 | break; |
2026 | 0 | } |
2027 | 0 | case OpacityQuantum: |
2028 | 0 | { |
2029 | 0 | *q=(float) ((QuantumScale*(double) GetPixelOpacity(image,p))* |
2030 | 0 | quantum_info->scale+quantum_info->minimum); |
2031 | 0 | break; |
2032 | 0 | } |
2033 | 0 | case BlackQuantum: |
2034 | 0 | { |
2035 | 0 | if (image->colorspace == CMYKColorspace) |
2036 | 0 | *q=(float) ((QuantumScale*(double) GetPixelBlack(image,p))* |
2037 | 0 | quantum_info->scale+quantum_info->minimum); |
2038 | 0 | break; |
2039 | 0 | } |
2040 | 0 | case IndexQuantum: |
2041 | 0 | { |
2042 | 0 | *q=(float) ((QuantumScale*(double) GetPixelIntensity(image,p))* |
2043 | 0 | quantum_info->scale+quantum_info->minimum); |
2044 | 0 | break; |
2045 | 0 | } |
2046 | 0 | default: |
2047 | 0 | *q=0; |
2048 | 0 | } |
2049 | 0 | q++; |
2050 | 0 | } |
2051 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2052 | 0 | } |
2053 | 0 | break; |
2054 | 0 | } |
2055 | 0 | case LongPixel: |
2056 | 0 | { |
2057 | 0 | unsigned int |
2058 | 0 | *q; |
2059 | |
|
2060 | 0 | q=(unsigned int *) stream_info->pixels; |
2061 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
2062 | 0 | { |
2063 | 0 | p=GetAuthenticPixelQueue(image); |
2064 | 0 | if (p == (const Quantum *) NULL) |
2065 | 0 | break; |
2066 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2067 | 0 | { |
2068 | 0 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2069 | 0 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2070 | 0 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
2071 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2072 | 0 | } |
2073 | 0 | break; |
2074 | 0 | } |
2075 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
2076 | 0 | { |
2077 | 0 | p=GetAuthenticPixelQueue(image); |
2078 | 0 | if (p == (const Quantum *) NULL) |
2079 | 0 | break; |
2080 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2081 | 0 | { |
2082 | 0 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2083 | 0 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2084 | 0 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
2085 | 0 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
2086 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2087 | 0 | } |
2088 | 0 | break; |
2089 | 0 | } |
2090 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
2091 | 0 | { |
2092 | 0 | p=GetAuthenticPixelQueue(image); |
2093 | 0 | if (p == (const Quantum *) NULL) |
2094 | 0 | break; |
2095 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2096 | 0 | { |
2097 | 0 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2098 | 0 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2099 | 0 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
2100 | 0 | *q++=0; |
2101 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2102 | 0 | } |
2103 | 0 | break; |
2104 | 0 | } |
2105 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
2106 | 0 | { |
2107 | 0 | p=GetAuthenticPixelQueue(image); |
2108 | 0 | if (p == (const Quantum *) NULL) |
2109 | 0 | break; |
2110 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2111 | 0 | { |
2112 | 0 | *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p))); |
2113 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2114 | 0 | } |
2115 | 0 | break; |
2116 | 0 | } |
2117 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
2118 | 0 | { |
2119 | 0 | p=GetAuthenticPixelQueue(image); |
2120 | 0 | if (p == (const Quantum *) NULL) |
2121 | 0 | break; |
2122 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2123 | 0 | { |
2124 | 0 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
2125 | 0 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2126 | 0 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2127 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2128 | 0 | } |
2129 | 0 | break; |
2130 | 0 | } |
2131 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
2132 | 0 | { |
2133 | 0 | p=GetAuthenticPixelQueue(image); |
2134 | 0 | if (p == (const Quantum *) NULL) |
2135 | 0 | break; |
2136 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2137 | 0 | { |
2138 | 0 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
2139 | 0 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2140 | 0 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2141 | 0 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
2142 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2143 | 0 | } |
2144 | 0 | break; |
2145 | 0 | } |
2146 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
2147 | 0 | { |
2148 | 0 | p=GetAuthenticPixelQueue(image); |
2149 | 0 | if (p == (const Quantum *) NULL) |
2150 | 0 | break; |
2151 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2152 | 0 | { |
2153 | 0 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
2154 | 0 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2155 | 0 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2156 | 0 | *q++=0; |
2157 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2158 | 0 | } |
2159 | 0 | break; |
2160 | 0 | } |
2161 | 0 | p=GetAuthenticPixelQueue(image); |
2162 | 0 | if (p == (const Quantum *) NULL) |
2163 | 0 | break; |
2164 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2165 | 0 | { |
2166 | 0 | for (i=0; i < (ssize_t) length; i++) |
2167 | 0 | { |
2168 | 0 | *q=0; |
2169 | 0 | switch (quantum_map[i]) |
2170 | 0 | { |
2171 | 0 | case RedQuantum: |
2172 | 0 | case CyanQuantum: |
2173 | 0 | { |
2174 | 0 | *q=ScaleQuantumToLong(GetPixelRed(image,p)); |
2175 | 0 | break; |
2176 | 0 | } |
2177 | 0 | case GreenQuantum: |
2178 | 0 | case MagentaQuantum: |
2179 | 0 | { |
2180 | 0 | *q=ScaleQuantumToLong(GetPixelGreen(image,p)); |
2181 | 0 | break; |
2182 | 0 | } |
2183 | 0 | case BlueQuantum: |
2184 | 0 | case YellowQuantum: |
2185 | 0 | { |
2186 | 0 | *q=ScaleQuantumToLong(GetPixelBlue(image,p)); |
2187 | 0 | break; |
2188 | 0 | } |
2189 | 0 | case AlphaQuantum: |
2190 | 0 | { |
2191 | 0 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
2192 | 0 | break; |
2193 | 0 | } |
2194 | 0 | case OpacityQuantum: |
2195 | 0 | { |
2196 | 0 | *q=ScaleQuantumToLong(GetPixelOpacity(image,p)); |
2197 | 0 | break; |
2198 | 0 | } |
2199 | 0 | case BlackQuantum: |
2200 | 0 | { |
2201 | 0 | if (image->colorspace == CMYKColorspace) |
2202 | 0 | *q=ScaleQuantumToLong(GetPixelBlack(image,p)); |
2203 | 0 | break; |
2204 | 0 | } |
2205 | 0 | case IndexQuantum: |
2206 | 0 | { |
2207 | 0 | *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p))); |
2208 | 0 | break; |
2209 | 0 | } |
2210 | 0 | default: |
2211 | 0 | break; |
2212 | 0 | } |
2213 | 0 | q++; |
2214 | 0 | } |
2215 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2216 | 0 | } |
2217 | 0 | break; |
2218 | 0 | } |
2219 | 0 | case LongLongPixel: |
2220 | 0 | { |
2221 | 0 | MagickSizeType |
2222 | 0 | *q; |
2223 | |
|
2224 | 0 | q=(MagickSizeType *) stream_info->pixels; |
2225 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
2226 | 0 | { |
2227 | 0 | p=GetAuthenticPixelQueue(image); |
2228 | 0 | if (p == (const Quantum *) NULL) |
2229 | 0 | break; |
2230 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2231 | 0 | { |
2232 | 0 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2233 | 0 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2234 | 0 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2235 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2236 | 0 | } |
2237 | 0 | break; |
2238 | 0 | } |
2239 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
2240 | 0 | { |
2241 | 0 | p=GetAuthenticPixelQueue(image); |
2242 | 0 | if (p == (const Quantum *) NULL) |
2243 | 0 | break; |
2244 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2245 | 0 | { |
2246 | 0 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2247 | 0 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2248 | 0 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2249 | 0 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
2250 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2251 | 0 | } |
2252 | 0 | break; |
2253 | 0 | } |
2254 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
2255 | 0 | { |
2256 | 0 | p=GetAuthenticPixelQueue(image); |
2257 | 0 | if (p == (const Quantum *) NULL) |
2258 | 0 | break; |
2259 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2260 | 0 | { |
2261 | 0 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2262 | 0 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2263 | 0 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2264 | 0 | *q++=0U; |
2265 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2266 | 0 | } |
2267 | 0 | break; |
2268 | 0 | } |
2269 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
2270 | 0 | { |
2271 | 0 | p=GetAuthenticPixelQueue(image); |
2272 | 0 | if (p == (const Quantum *) NULL) |
2273 | 0 | break; |
2274 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2275 | 0 | { |
2276 | 0 | *q++=ScaleQuantumToLongLong(ClampToQuantum( |
2277 | 0 | GetPixelIntensity(image,p))); |
2278 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2279 | 0 | } |
2280 | 0 | break; |
2281 | 0 | } |
2282 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
2283 | 0 | { |
2284 | 0 | p=GetAuthenticPixelQueue(image); |
2285 | 0 | if (p == (const Quantum *) NULL) |
2286 | 0 | break; |
2287 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2288 | 0 | { |
2289 | 0 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2290 | 0 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2291 | 0 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2292 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2293 | 0 | } |
2294 | 0 | break; |
2295 | 0 | } |
2296 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
2297 | 0 | { |
2298 | 0 | p=GetAuthenticPixelQueue(image); |
2299 | 0 | if (p == (const Quantum *) NULL) |
2300 | 0 | break; |
2301 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2302 | 0 | { |
2303 | 0 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2304 | 0 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2305 | 0 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2306 | 0 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
2307 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2308 | 0 | } |
2309 | 0 | break; |
2310 | 0 | } |
2311 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
2312 | 0 | { |
2313 | 0 | p=GetAuthenticPixelQueue(image); |
2314 | 0 | if (p == (const Quantum *) NULL) |
2315 | 0 | break; |
2316 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2317 | 0 | { |
2318 | 0 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2319 | 0 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2320 | 0 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2321 | 0 | *q++=0U; |
2322 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2323 | 0 | } |
2324 | 0 | break; |
2325 | 0 | } |
2326 | 0 | p=GetAuthenticPixelQueue(image); |
2327 | 0 | if (p == (const Quantum *) NULL) |
2328 | 0 | break; |
2329 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2330 | 0 | { |
2331 | 0 | for (i=0; i < (ssize_t) length; i++) |
2332 | 0 | { |
2333 | 0 | *q=0; |
2334 | 0 | switch (quantum_map[i]) |
2335 | 0 | { |
2336 | 0 | case RedQuantum: |
2337 | 0 | case CyanQuantum: |
2338 | 0 | { |
2339 | 0 | *q=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
2340 | 0 | break; |
2341 | 0 | } |
2342 | 0 | case GreenQuantum: |
2343 | 0 | case MagentaQuantum: |
2344 | 0 | { |
2345 | 0 | *q=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
2346 | 0 | break; |
2347 | 0 | } |
2348 | 0 | case BlueQuantum: |
2349 | 0 | case YellowQuantum: |
2350 | 0 | { |
2351 | 0 | *q=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
2352 | 0 | break; |
2353 | 0 | } |
2354 | 0 | case AlphaQuantum: |
2355 | 0 | { |
2356 | 0 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
2357 | 0 | break; |
2358 | 0 | } |
2359 | 0 | case OpacityQuantum: |
2360 | 0 | { |
2361 | 0 | *q=ScaleQuantumToLongLong(GetPixelOpacity(image,p)); |
2362 | 0 | break; |
2363 | 0 | } |
2364 | 0 | case BlackQuantum: |
2365 | 0 | { |
2366 | 0 | if (image->colorspace == CMYKColorspace) |
2367 | 0 | *q=ScaleQuantumToLongLong(GetPixelBlack(image,p)); |
2368 | 0 | break; |
2369 | 0 | } |
2370 | 0 | case IndexQuantum: |
2371 | 0 | { |
2372 | 0 | *q=ScaleQuantumToLongLong(ClampToQuantum( |
2373 | 0 | GetPixelIntensity(image,p))); |
2374 | 0 | break; |
2375 | 0 | } |
2376 | 0 | default: |
2377 | 0 | *q=0; |
2378 | 0 | } |
2379 | 0 | q++; |
2380 | 0 | } |
2381 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2382 | 0 | } |
2383 | 0 | break; |
2384 | 0 | } |
2385 | 0 | case QuantumPixel: |
2386 | 0 | { |
2387 | 0 | Quantum |
2388 | 0 | *q; |
2389 | |
|
2390 | 0 | q=(Quantum *) stream_info->pixels; |
2391 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
2392 | 0 | { |
2393 | 0 | p=GetAuthenticPixelQueue(image); |
2394 | 0 | if (p == (const Quantum *) NULL) |
2395 | 0 | break; |
2396 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2397 | 0 | { |
2398 | 0 | *q++=GetPixelBlue(image,p); |
2399 | 0 | *q++=GetPixelGreen(image,p); |
2400 | 0 | *q++=GetPixelRed(image,p); |
2401 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2402 | 0 | } |
2403 | 0 | break; |
2404 | 0 | } |
2405 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
2406 | 0 | { |
2407 | 0 | p=GetAuthenticPixelQueue(image); |
2408 | 0 | if (p == (const Quantum *) NULL) |
2409 | 0 | break; |
2410 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2411 | 0 | { |
2412 | 0 | *q++=GetPixelBlue(image,p); |
2413 | 0 | *q++=GetPixelGreen(image,p); |
2414 | 0 | *q++=GetPixelRed(image,p); |
2415 | 0 | *q++=GetPixelAlpha(image,p); |
2416 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2417 | 0 | } |
2418 | 0 | break; |
2419 | 0 | } |
2420 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
2421 | 0 | { |
2422 | 0 | p=GetAuthenticPixelQueue(image); |
2423 | 0 | if (p == (const Quantum *) NULL) |
2424 | 0 | break; |
2425 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2426 | 0 | { |
2427 | 0 | *q++=GetPixelBlue(image,p); |
2428 | 0 | *q++=GetPixelGreen(image,p); |
2429 | 0 | *q++=GetPixelRed(image,p); |
2430 | 0 | *q++=(Quantum) 0; |
2431 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2432 | 0 | } |
2433 | 0 | break; |
2434 | 0 | } |
2435 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
2436 | 0 | { |
2437 | 0 | p=GetAuthenticPixelQueue(image); |
2438 | 0 | if (p == (const Quantum *) NULL) |
2439 | 0 | break; |
2440 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2441 | 0 | { |
2442 | 0 | *q++=ClampToQuantum(GetPixelIntensity(image,p)); |
2443 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2444 | 0 | } |
2445 | 0 | break; |
2446 | 0 | } |
2447 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
2448 | 0 | { |
2449 | 0 | p=GetAuthenticPixelQueue(image); |
2450 | 0 | if (p == (const Quantum *) NULL) |
2451 | 0 | break; |
2452 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2453 | 0 | { |
2454 | 0 | *q++=GetPixelRed(image,p); |
2455 | 0 | *q++=GetPixelGreen(image,p); |
2456 | 0 | *q++=GetPixelBlue(image,p); |
2457 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2458 | 0 | } |
2459 | 0 | break; |
2460 | 0 | } |
2461 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
2462 | 0 | { |
2463 | 0 | p=GetAuthenticPixelQueue(image); |
2464 | 0 | if (p == (const Quantum *) NULL) |
2465 | 0 | break; |
2466 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2467 | 0 | { |
2468 | 0 | *q++=GetPixelRed(image,p); |
2469 | 0 | *q++=GetPixelGreen(image,p); |
2470 | 0 | *q++=GetPixelBlue(image,p); |
2471 | 0 | *q++=GetPixelAlpha(image,p); |
2472 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2473 | 0 | } |
2474 | 0 | break; |
2475 | 0 | } |
2476 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
2477 | 0 | { |
2478 | 0 | p=GetAuthenticPixelQueue(image); |
2479 | 0 | if (p == (const Quantum *) NULL) |
2480 | 0 | break; |
2481 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2482 | 0 | { |
2483 | 0 | *q++=GetPixelRed(image,p); |
2484 | 0 | *q++=GetPixelGreen(image,p); |
2485 | 0 | *q++=GetPixelBlue(image,p); |
2486 | 0 | *q++=(Quantum) 0; |
2487 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2488 | 0 | } |
2489 | 0 | break; |
2490 | 0 | } |
2491 | 0 | p=GetAuthenticPixelQueue(image); |
2492 | 0 | if (p == (const Quantum *) NULL) |
2493 | 0 | break; |
2494 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2495 | 0 | { |
2496 | 0 | for (i=0; i < (ssize_t) length; i++) |
2497 | 0 | { |
2498 | 0 | *q=(Quantum) 0; |
2499 | 0 | switch (quantum_map[i]) |
2500 | 0 | { |
2501 | 0 | case RedQuantum: |
2502 | 0 | case CyanQuantum: |
2503 | 0 | { |
2504 | 0 | *q=GetPixelRed(image,p); |
2505 | 0 | break; |
2506 | 0 | } |
2507 | 0 | case GreenQuantum: |
2508 | 0 | case MagentaQuantum: |
2509 | 0 | { |
2510 | 0 | *q=GetPixelGreen(image,p); |
2511 | 0 | break; |
2512 | 0 | } |
2513 | 0 | case BlueQuantum: |
2514 | 0 | case YellowQuantum: |
2515 | 0 | { |
2516 | 0 | *q=GetPixelBlue(image,p); |
2517 | 0 | break; |
2518 | 0 | } |
2519 | 0 | case AlphaQuantum: |
2520 | 0 | { |
2521 | 0 | *q=GetPixelAlpha(image,p); |
2522 | 0 | break; |
2523 | 0 | } |
2524 | 0 | case OpacityQuantum: |
2525 | 0 | { |
2526 | 0 | *q=GetPixelOpacity(image,p); |
2527 | 0 | break; |
2528 | 0 | } |
2529 | 0 | case BlackQuantum: |
2530 | 0 | { |
2531 | 0 | if (image->colorspace == CMYKColorspace) |
2532 | 0 | *q=GetPixelBlack(image,p); |
2533 | 0 | break; |
2534 | 0 | } |
2535 | 0 | case IndexQuantum: |
2536 | 0 | { |
2537 | 0 | *q=ClampToQuantum(GetPixelIntensity(image,p)); |
2538 | 0 | break; |
2539 | 0 | } |
2540 | 0 | default: |
2541 | 0 | *q=(Quantum) 0; |
2542 | 0 | } |
2543 | 0 | q++; |
2544 | 0 | } |
2545 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2546 | 0 | } |
2547 | 0 | break; |
2548 | 0 | } |
2549 | 0 | case ShortPixel: |
2550 | 0 | { |
2551 | 0 | unsigned short |
2552 | 0 | *q; |
2553 | |
|
2554 | 0 | q=(unsigned short *) stream_info->pixels; |
2555 | 0 | if (LocaleCompare(stream_info->map,"BGR") == 0) |
2556 | 0 | { |
2557 | 0 | p=GetAuthenticPixelQueue(image); |
2558 | 0 | if (p == (const Quantum *) NULL) |
2559 | 0 | break; |
2560 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2561 | 0 | { |
2562 | 0 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2563 | 0 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2564 | 0 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
2565 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2566 | 0 | } |
2567 | 0 | break; |
2568 | 0 | } |
2569 | 0 | if (LocaleCompare(stream_info->map,"BGRA") == 0) |
2570 | 0 | { |
2571 | 0 | p=GetAuthenticPixelQueue(image); |
2572 | 0 | if (p == (const Quantum *) NULL) |
2573 | 0 | break; |
2574 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2575 | 0 | { |
2576 | 0 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2577 | 0 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2578 | 0 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
2579 | 0 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
2580 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2581 | 0 | } |
2582 | 0 | break; |
2583 | 0 | } |
2584 | 0 | if (LocaleCompare(stream_info->map,"BGRP") == 0) |
2585 | 0 | { |
2586 | 0 | p=GetAuthenticPixelQueue(image); |
2587 | 0 | if (p == (const Quantum *) NULL) |
2588 | 0 | break; |
2589 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2590 | 0 | { |
2591 | 0 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2592 | 0 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2593 | 0 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
2594 | 0 | *q++=0; |
2595 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2596 | 0 | } |
2597 | 0 | break; |
2598 | 0 | } |
2599 | 0 | if (LocaleCompare(stream_info->map,"I") == 0) |
2600 | 0 | { |
2601 | 0 | p=GetAuthenticPixelQueue(image); |
2602 | 0 | if (p == (const Quantum *) NULL) |
2603 | 0 | break; |
2604 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2605 | 0 | { |
2606 | 0 | *q++=ScaleQuantumToShort(ClampToQuantum( |
2607 | 0 | GetPixelIntensity(image,p))); |
2608 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2609 | 0 | } |
2610 | 0 | break; |
2611 | 0 | } |
2612 | 0 | if (LocaleCompare(stream_info->map,"RGB") == 0) |
2613 | 0 | { |
2614 | 0 | p=GetAuthenticPixelQueue(image); |
2615 | 0 | if (p == (const Quantum *) NULL) |
2616 | 0 | break; |
2617 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2618 | 0 | { |
2619 | 0 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
2620 | 0 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2621 | 0 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2622 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2623 | 0 | } |
2624 | 0 | break; |
2625 | 0 | } |
2626 | 0 | if (LocaleCompare(stream_info->map,"RGBA") == 0) |
2627 | 0 | { |
2628 | 0 | p=GetAuthenticPixelQueue(image); |
2629 | 0 | if (p == (const Quantum *) NULL) |
2630 | 0 | break; |
2631 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2632 | 0 | { |
2633 | 0 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
2634 | 0 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2635 | 0 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2636 | 0 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
2637 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2638 | 0 | } |
2639 | 0 | break; |
2640 | 0 | } |
2641 | 0 | if (LocaleCompare(stream_info->map,"RGBP") == 0) |
2642 | 0 | { |
2643 | 0 | p=GetAuthenticPixelQueue(image); |
2644 | 0 | if (p == (const Quantum *) NULL) |
2645 | 0 | break; |
2646 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2647 | 0 | { |
2648 | 0 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
2649 | 0 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2650 | 0 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2651 | 0 | *q++=0; |
2652 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2653 | 0 | } |
2654 | 0 | break; |
2655 | 0 | } |
2656 | 0 | p=GetAuthenticPixelQueue(image); |
2657 | 0 | if (p == (const Quantum *) NULL) |
2658 | 0 | break; |
2659 | 0 | for (x=0; x < (ssize_t) GetImageExtent(image); x++) |
2660 | 0 | { |
2661 | 0 | for (i=0; i < (ssize_t) length; i++) |
2662 | 0 | { |
2663 | 0 | *q=0; |
2664 | 0 | switch (quantum_map[i]) |
2665 | 0 | { |
2666 | 0 | case RedQuantum: |
2667 | 0 | case CyanQuantum: |
2668 | 0 | { |
2669 | 0 | *q=ScaleQuantumToShort(GetPixelRed(image,p)); |
2670 | 0 | break; |
2671 | 0 | } |
2672 | 0 | case GreenQuantum: |
2673 | 0 | case MagentaQuantum: |
2674 | 0 | { |
2675 | 0 | *q=ScaleQuantumToShort(GetPixelGreen(image,p)); |
2676 | 0 | break; |
2677 | 0 | } |
2678 | 0 | case BlueQuantum: |
2679 | 0 | case YellowQuantum: |
2680 | 0 | { |
2681 | 0 | *q=ScaleQuantumToShort(GetPixelBlue(image,p)); |
2682 | 0 | break; |
2683 | 0 | } |
2684 | 0 | case AlphaQuantum: |
2685 | 0 | { |
2686 | 0 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
2687 | 0 | break; |
2688 | 0 | } |
2689 | 0 | case OpacityQuantum: |
2690 | 0 | { |
2691 | 0 | *q=ScaleQuantumToShort(GetPixelOpacity(image,p)); |
2692 | 0 | break; |
2693 | 0 | } |
2694 | 0 | case BlackQuantum: |
2695 | 0 | { |
2696 | 0 | if (image->colorspace == CMYKColorspace) |
2697 | 0 | *q=ScaleQuantumToShort(GetPixelBlack(image,p)); |
2698 | 0 | break; |
2699 | 0 | } |
2700 | 0 | case IndexQuantum: |
2701 | 0 | { |
2702 | 0 | *q=ScaleQuantumToShort(ClampToQuantum( |
2703 | 0 | GetPixelIntensity(image,p))); |
2704 | 0 | break; |
2705 | 0 | } |
2706 | 0 | default: |
2707 | 0 | break; |
2708 | 0 | } |
2709 | 0 | q++; |
2710 | 0 | } |
2711 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2712 | 0 | } |
2713 | 0 | break; |
2714 | 0 | } |
2715 | 0 | default: |
2716 | 0 | { |
2717 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
2718 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
2719 | 0 | "UnrecognizedPixelMap","`%s'",stream_info->map); |
2720 | 0 | break; |
2721 | 0 | } |
2722 | 0 | } |
2723 | 0 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
2724 | 0 | return(MagickTrue); |
2725 | 0 | } |
2726 | | |
2727 | | /* |
2728 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2729 | | % % |
2730 | | % % |
2731 | | % % |
2732 | | + 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 % |
2733 | | % % |
2734 | | % % |
2735 | | % % |
2736 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2737 | | % |
2738 | | % SyncAuthenticPixelsStream() calls the user supplied callback method with |
2739 | | % the latest stream of pixels. |
2740 | | % |
2741 | | % The format of the SyncAuthenticPixelsStream method is: |
2742 | | % |
2743 | | % MagickBooleanType SyncAuthenticPixelsStream(Image *image, |
2744 | | % ExceptionInfo *exception) |
2745 | | % |
2746 | | % A description of each parameter follows: |
2747 | | % |
2748 | | % o image: the image. |
2749 | | % |
2750 | | % o exception: return any errors or warnings in this structure. |
2751 | | % |
2752 | | */ |
2753 | | static MagickBooleanType SyncAuthenticPixelsStream(Image *image, |
2754 | | ExceptionInfo *exception) |
2755 | 2.14M | { |
2756 | 2.14M | CacheInfo |
2757 | 2.14M | *cache_info; |
2758 | | |
2759 | 2.14M | size_t |
2760 | 2.14M | length; |
2761 | | |
2762 | 2.14M | StreamHandler |
2763 | 2.14M | stream_handler; |
2764 | | |
2765 | 2.14M | assert(image != (Image *) NULL); |
2766 | 2.14M | assert(image->signature == MagickCoreSignature); |
2767 | 2.14M | if (IsEventLogging() != MagickFalse) |
2768 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
2769 | 2.14M | cache_info=(CacheInfo *) image->cache; |
2770 | 2.14M | assert(cache_info->signature == MagickCoreSignature); |
2771 | 2.14M | stream_handler=GetBlobStreamHandler(image); |
2772 | 2.14M | if (stream_handler == (StreamHandler) NULL) |
2773 | 0 | { |
2774 | 0 | (void) ThrowMagickException(exception,GetMagickModule(),StreamError, |
2775 | 0 | "NoStreamHandlerIsDefined","`%s'",image->filename); |
2776 | 0 | return(MagickFalse); |
2777 | 0 | } |
2778 | 2.14M | length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns); |
2779 | 2.14M | return(length == cache_info->columns ? MagickTrue : MagickFalse); |
2780 | 2.14M | } |
2781 | | |
2782 | | /* |
2783 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2784 | | % % |
2785 | | % % |
2786 | | % % |
2787 | | % W r i t e S t r e a m % |
2788 | | % % |
2789 | | % % |
2790 | | % % |
2791 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2792 | | % |
2793 | | % WriteStream() makes the image pixels available to a user supplied callback |
2794 | | % method immediately upon writing pixel data with the WriteImage() method. |
2795 | | % |
2796 | | % The format of the WriteStream() method is: |
2797 | | % |
2798 | | % MagickBooleanType WriteStream(const ImageInfo *image_info,Image *, |
2799 | | % StreamHandler stream,ExceptionInfo *exception) |
2800 | | % |
2801 | | % A description of each parameter follows: |
2802 | | % |
2803 | | % o image_info: the image info. |
2804 | | % |
2805 | | % o stream: A callback method. |
2806 | | % |
2807 | | % o exception: return any errors or warnings in this structure. |
2808 | | % |
2809 | | */ |
2810 | | MagickExport MagickBooleanType WriteStream(const ImageInfo *image_info, |
2811 | | Image *image,StreamHandler stream,ExceptionInfo *exception) |
2812 | 0 | { |
2813 | 0 | ImageInfo |
2814 | 0 | *write_info; |
2815 | |
|
2816 | 0 | MagickBooleanType |
2817 | 0 | status; |
2818 | |
|
2819 | 0 | assert(image_info != (ImageInfo *) NULL); |
2820 | 0 | assert(image_info->signature == MagickCoreSignature); |
2821 | 0 | if (IsEventLogging() != MagickFalse) |
2822 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
2823 | 0 | image_info->filename); |
2824 | 0 | assert(image != (Image *) NULL); |
2825 | 0 | assert(image->signature == MagickCoreSignature); |
2826 | 0 | write_info=CloneImageInfo(image_info); |
2827 | 0 | *write_info->magick='\0'; |
2828 | 0 | write_info->stream=stream; |
2829 | 0 | status=WriteImage(write_info,image,exception); |
2830 | 0 | write_info=DestroyImageInfo(write_info); |
2831 | 0 | return(status); |
2832 | 0 | } |