blob: 2bc36aace246aa267c6343ccef508012ca70ffbe [file] [log] [blame]
cristy4c08aed2011-07-01 19:47:50 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% PPPP IIIII X X EEEEE L %
7% P P I X X E L %
8% PPPP I X EEE L %
9% P I X X E L %
10% P IIIII X X EEEEE LLLLL %
11% %
12% MagickCore Methods to Import/Export Pixels %
13% %
14% Software Design %
15% John Cristy %
16% October 1998 %
17% %
18% %
19% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% http://www.imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35%
36*/
37
38/*
39 Include declarations.
40*/
41#include "MagickCore/studio.h"
42#include "MagickCore/property.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/color-private.h"
46#include "MagickCore/draw.h"
47#include "MagickCore/exception.h"
48#include "MagickCore/exception-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/constitute.h"
51#include "MagickCore/delegate.h"
52#include "MagickCore/geometry.h"
53#include "MagickCore/image-private.h"
54#include "MagickCore/list.h"
55#include "MagickCore/magick.h"
56#include "MagickCore/memory_.h"
57#include "MagickCore/monitor.h"
58#include "MagickCore/option.h"
59#include "MagickCore/pixel.h"
60#include "MagickCore/pixel-accessor.h"
61#include "MagickCore/quantum.h"
62#include "MagickCore/quantum-private.h"
63#include "MagickCore/resource_.h"
64#include "MagickCore/semaphore.h"
65#include "MagickCore/statistic.h"
66#include "MagickCore/stream.h"
67#include "MagickCore/string_.h"
68#include "MagickCore/transform.h"
69#include "MagickCore/utility.h"
70
cristy146a62b2011-10-23 23:40:46 +000071#define LogPixelChannels(image) \
72{ \
73 register ssize_t \
74 i; \
75 \
76 (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
77 image->filename,(double) image->number_channels); \
78 for (i=0; i < (ssize_t) image->number_channels; i++) \
79 { \
80 char \
81 traits[MaxTextExtent]; \
82 \
83 const char \
84 *channel; \
85 \
cristye2a912b2011-12-05 20:02:07 +000086 switch (GetPixelChannelMapChannel(image,i)) \
cristy146a62b2011-10-23 23:40:46 +000087 { \
88 case RedPixelChannel: \
89 { \
90 channel="red"; \
91 if (image->colorspace == CMYKColorspace) \
92 channel="cyan"; \
93 if (image->colorspace == GRAYColorspace) \
94 channel="gray"; \
95 break; \
96 } \
97 case GreenPixelChannel: \
98 { \
99 channel="green"; \
100 if (image->colorspace == CMYKColorspace) \
101 channel="magenta"; \
102 break; \
103 } \
104 case BluePixelChannel: \
105 { \
106 channel="blue"; \
107 if (image->colorspace == CMYKColorspace) \
108 channel="yellow"; \
109 break; \
110 } \
111 case BlackPixelChannel: \
112 { \
113 channel="black"; \
114 if (image->storage_class == PseudoClass) \
115 channel="index"; \
116 break; \
117 } \
cristye2a912b2011-12-05 20:02:07 +0000118 case IndexPixelChannel: \
119 { \
120 channel="index"; \
121 break; \
122 } \
cristy146a62b2011-10-23 23:40:46 +0000123 case AlphaPixelChannel: \
124 { \
125 channel="alpha"; \
126 break; \
127 } \
128 case MaskPixelChannel: \
129 { \
130 channel="mask"; \
131 break; \
132 } \
cristye2a912b2011-12-05 20:02:07 +0000133 case MetaPixelChannel: \
cristy146a62b2011-10-23 23:40:46 +0000134 { \
cristye2a912b2011-12-05 20:02:07 +0000135 channel="meta"; \
136 break; \
cristy146a62b2011-10-23 23:40:46 +0000137 } \
cristye2a912b2011-12-05 20:02:07 +0000138 default: \
139 channel="undefined"; \
cristy146a62b2011-10-23 23:40:46 +0000140 } \
141 *traits='\0'; \
cristye2a912b2011-12-05 20:02:07 +0000142 if ((GetPixelChannelMapTraits(image,i) & UpdatePixelTrait) != 0) \
cristy146a62b2011-10-23 23:40:46 +0000143 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
cristye2a912b2011-12-05 20:02:07 +0000144 if ((GetPixelChannelMapTraits(image,i) & BlendPixelTrait) != 0) \
cristy146a62b2011-10-23 23:40:46 +0000145 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
cristye2a912b2011-12-05 20:02:07 +0000146 if ((GetPixelChannelMapTraits(image,i) & CopyPixelTrait) != 0) \
cristy146a62b2011-10-23 23:40:46 +0000147 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
148 if (*traits == '\0') \
149 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
150 traits[strlen(traits)-1]='\0'; \
151 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
152 (double) i,channel,traits); \
153 } \
154}
155
156/*
cristy4c08aed2011-07-01 19:47:50 +0000157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158% %
159% %
160% %
cristyed231572011-07-14 02:18:59 +0000161+ A c q u i r e P i x e l C h a n n e l M a p %
cristy4c08aed2011-07-01 19:47:50 +0000162% %
163% %
164% %
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166%
cristyed231572011-07-14 02:18:59 +0000167% AcquirePixelChannelMap() acquires a pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000168%
cristyed231572011-07-14 02:18:59 +0000169% The format of the AcquirePixelChannelMap() method is:
cristy4c08aed2011-07-01 19:47:50 +0000170%
cristybd5a96c2011-08-21 00:04:26 +0000171% PixelChannelMap *AcquirePixelChannelMap(void)
cristy4c08aed2011-07-01 19:47:50 +0000172%
173*/
cristybd5a96c2011-08-21 00:04:26 +0000174MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
cristy4c08aed2011-07-01 19:47:50 +0000175{
cristyed231572011-07-14 02:18:59 +0000176 PixelChannelMap
cristybd5a96c2011-08-21 00:04:26 +0000177 *channel_map;
cristy4c08aed2011-07-01 19:47:50 +0000178
179 register ssize_t
180 i;
181
cristybd5a96c2011-08-21 00:04:26 +0000182 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
183 sizeof(*channel_map));
184 if (channel_map == (PixelChannelMap *) NULL)
cristy4c08aed2011-07-01 19:47:50 +0000185 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristybd5a96c2011-08-21 00:04:26 +0000186 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
187 for (i=0; i < MaxPixelChannels; i++)
188 channel_map[i].channel=(PixelChannel) i;
cristyed231572011-07-14 02:18:59 +0000189 return(channel_map);
cristy4c08aed2011-07-01 19:47:50 +0000190}
191
192/*
193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194% %
195% %
196% %
cristyed231572011-07-14 02:18:59 +0000197+ C l o n e P i x e l C h a n n e l M a p %
cristy4c08aed2011-07-01 19:47:50 +0000198% %
199% %
200% %
201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202%
cristyed231572011-07-14 02:18:59 +0000203% ClonePixelChannelMap() clones a pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000204%
cristyed231572011-07-14 02:18:59 +0000205% The format of the ClonePixelChannelMap() method is:
cristy4c08aed2011-07-01 19:47:50 +0000206%
cristybd5a96c2011-08-21 00:04:26 +0000207% PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000208%
209% A description of each parameter follows:
210%
cristyed231572011-07-14 02:18:59 +0000211% o channel_map: the pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000212%
213*/
cristybd5a96c2011-08-21 00:04:26 +0000214MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000215{
cristyed231572011-07-14 02:18:59 +0000216 PixelChannelMap
cristybd5a96c2011-08-21 00:04:26 +0000217 *clone_map;
cristy4c08aed2011-07-01 19:47:50 +0000218
cristybd5a96c2011-08-21 00:04:26 +0000219 assert(channel_map != (PixelChannelMap *) NULL);
cristyed231572011-07-14 02:18:59 +0000220 clone_map=AcquirePixelChannelMap();
cristybd5a96c2011-08-21 00:04:26 +0000221 if (clone_map == (PixelChannelMap *) NULL)
222 return((PixelChannelMap *) NULL);
223 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
224 sizeof(*channel_map));
cristy4c08aed2011-07-01 19:47:50 +0000225 return(clone_map);
226}
227
228/*
229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230% %
231% %
232% %
233+ C l o n e P i x e l I n f o %
234% %
235% %
236% %
237%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238%
239% ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
240% pixel info is NULL, a new one.
241%
242% The format of the ClonePixelInfo method is:
243%
244% PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
245%
246% A description of each parameter follows:
247%
248% o pixel_info: the pixel info.
249%
250*/
251MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
252{
253 PixelInfo
254 *pixel_info;
255
cristya64b85d2011-09-14 01:02:31 +0000256 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
cristy4c08aed2011-07-01 19:47:50 +0000257 if (pixel_info == (PixelInfo *) NULL)
258 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
259 *pixel_info=(*pixel);
260 return(pixel_info);
261}
262
263/*
264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265% %
266% %
267% %
cristyed231572011-07-14 02:18:59 +0000268+ D e s t r o y P i x e l C h a n n e l M a p %
cristy4c08aed2011-07-01 19:47:50 +0000269% %
270% %
271% %
272%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273%
cristyed231572011-07-14 02:18:59 +0000274% DestroyPixelChannelMap() deallocates memory associated with the pixel
275% channel map.
cristy4c08aed2011-07-01 19:47:50 +0000276%
cristyed231572011-07-14 02:18:59 +0000277% The format of the DestroyPixelChannelMap() method is:
cristy4c08aed2011-07-01 19:47:50 +0000278%
cristybd5a96c2011-08-21 00:04:26 +0000279% PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000280%
281% A description of each parameter follows:
282%
cristyed231572011-07-14 02:18:59 +0000283% o channel_map: the pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000284%
285*/
cristybd5a96c2011-08-21 00:04:26 +0000286MagickExport PixelChannelMap *DestroyPixelChannelMap(
287 PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000288{
cristybd5a96c2011-08-21 00:04:26 +0000289 assert(channel_map != (PixelChannelMap *) NULL);
290 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
291 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
cristy4c08aed2011-07-01 19:47:50 +0000292}
293
294/*
295%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296% %
297% %
298% %
299% E x p o r t I m a g e P i x e l s %
300% %
301% %
302% %
303%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304%
305% ExportImagePixels() extracts pixel data from an image and returns it to you.
306% The method returns MagickTrue on success otherwise MagickFalse if an error is
307% encountered. The data is returned as char, short int, int, ssize_t, float,
308% or double in the order specified by map.
309%
310% Suppose you want to extract the first scanline of a 640x480 image as
311% character data in red-green-blue order:
312%
313% ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
314%
315% The format of the ExportImagePixels method is:
316%
317% MagickBooleanType ExportImagePixels(const Image *image,
318% const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
319% const size_t rows,const char *map,const StorageType type,
320% void *pixels,ExceptionInfo *exception)
321%
322% A description of each parameter follows:
323%
324% o image: the image.
325%
326% o x_offset,y_offset,columns,rows: These values define the perimeter
327% of a region of pixels you want to extract.
328%
329% o map: This string reflects the expected ordering of the pixel array.
330% It can be any combination or order of R = red, G = green, B = blue,
331% A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
332% Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
333% P = pad.
334%
335% o type: Define the data type of the pixels. Float and double types are
336% normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
337% types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel,
338% QuantumPixel, or ShortPixel.
339%
340% o pixels: This array of values contain the pixel components as defined by
341% map and type. You must preallocate this array where the expected
342% length varies depending on the values of width, height, map, and type.
343%
344% o exception: return any errors or warnings in this structure.
345%
346*/
347MagickExport MagickBooleanType ExportImagePixels(const Image *image,
348 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
349 const size_t rows,const char *map,const StorageType type,void *pixels,
350 ExceptionInfo *exception)
351{
352 QuantumType
353 *quantum_map;
354
355 register ssize_t
356 i,
357 x;
358
359 register const Quantum
360 *p;
361
362 size_t
363 length;
364
365 ssize_t
366 y;
367
368 assert(image != (Image *) NULL);
369 assert(image->signature == MagickSignature);
370 if (image->debug != MagickFalse)
371 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
372 length=strlen(map);
373 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
374 if (quantum_map == (QuantumType *) NULL)
375 {
376 (void) ThrowMagickException(exception,GetMagickModule(),
377 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
378 return(MagickFalse);
379 }
380 for (i=0; i < (ssize_t) length; i++)
381 {
382 switch (map[i])
383 {
384 case 'A':
385 case 'a':
386 {
387 quantum_map[i]=AlphaQuantum;
388 break;
389 }
390 case 'B':
391 case 'b':
392 {
393 quantum_map[i]=BlueQuantum;
394 break;
395 }
396 case 'C':
397 case 'c':
398 {
399 quantum_map[i]=CyanQuantum;
400 if (image->colorspace == CMYKColorspace)
401 break;
402 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
403 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
404 "ColorSeparatedImageRequired","`%s'",map);
405 return(MagickFalse);
406 }
407 case 'g':
408 case 'G':
409 {
410 quantum_map[i]=GreenQuantum;
411 break;
412 }
413 case 'I':
414 case 'i':
415 {
416 quantum_map[i]=IndexQuantum;
417 break;
418 }
419 case 'K':
420 case 'k':
421 {
422 quantum_map[i]=BlackQuantum;
423 if (image->colorspace == CMYKColorspace)
424 break;
425 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
426 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
427 "ColorSeparatedImageRequired","`%s'",map);
428 return(MagickFalse);
429 }
430 case 'M':
431 case 'm':
432 {
433 quantum_map[i]=MagentaQuantum;
434 if (image->colorspace == CMYKColorspace)
435 break;
436 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
437 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
438 "ColorSeparatedImageRequired","`%s'",map);
439 return(MagickFalse);
440 }
441 case 'o':
442 case 'O':
443 {
444 quantum_map[i]=OpacityQuantum;
445 break;
446 }
447 case 'P':
448 case 'p':
449 {
450 quantum_map[i]=UndefinedQuantum;
451 break;
452 }
453 case 'R':
454 case 'r':
455 {
456 quantum_map[i]=RedQuantum;
457 break;
458 }
459 case 'Y':
460 case 'y':
461 {
462 quantum_map[i]=YellowQuantum;
463 if (image->colorspace == CMYKColorspace)
464 break;
465 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
466 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
467 "ColorSeparatedImageRequired","`%s'",map);
468 return(MagickFalse);
469 }
470 default:
471 {
472 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
473 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
474 "UnrecognizedPixelMap","`%s'",map);
475 return(MagickFalse);
476 }
477 }
478 }
479 switch (type)
480 {
481 case CharPixel:
482 {
483 register unsigned char
484 *q;
485
486 q=(unsigned char *) pixels;
487 if (LocaleCompare(map,"BGR") == 0)
488 {
489 for (y=0; y < (ssize_t) rows; y++)
490 {
491 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
492 if (p == (const Quantum *) NULL)
493 break;
494 for (x=0; x < (ssize_t) columns; x++)
495 {
496 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
497 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
498 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +0000499 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000500 }
501 }
502 break;
503 }
504 if (LocaleCompare(map,"BGRA") == 0)
505 {
506 for (y=0; y < (ssize_t) rows; y++)
507 {
508 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
509 if (p == (const Quantum *) NULL)
510 break;
511 for (x=0; x < (ssize_t) columns; x++)
512 {
513 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
514 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
515 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
516 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000517 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000518 }
519 }
520 break;
521 }
522 if (LocaleCompare(map,"BGRP") == 0)
523 {
524 for (y=0; y < (ssize_t) rows; y++)
525 {
526 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
527 if (p == (const Quantum *) NULL)
528 break;
529 for (x=0; x < (ssize_t) columns; x++)
530 {
531 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
532 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
533 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
534 *q++=ScaleQuantumToChar((Quantum) 0);
cristyed231572011-07-14 02:18:59 +0000535 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000536 }
537 }
538 break;
539 }
540 if (LocaleCompare(map,"I") == 0)
541 {
542 for (y=0; y < (ssize_t) rows; y++)
543 {
544 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
545 if (p == (const Quantum *) NULL)
546 break;
547 for (x=0; x < (ssize_t) columns; x++)
548 {
549 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000550 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000551 }
552 }
553 break;
554 }
555 if (LocaleCompare(map,"RGB") == 0)
556 {
557 for (y=0; y < (ssize_t) rows; y++)
558 {
559 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
560 if (p == (const Quantum *) NULL)
561 break;
562 for (x=0; x < (ssize_t) columns; x++)
563 {
564 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
565 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
566 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000567 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000568 }
569 }
570 break;
571 }
572 if (LocaleCompare(map,"RGBA") == 0)
573 {
574 for (y=0; y < (ssize_t) rows; y++)
575 {
576 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
577 if (p == (const Quantum *) NULL)
578 break;
579 for (x=0; x < (ssize_t) columns; x++)
580 {
581 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
582 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
583 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
584 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000585 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000586 }
587 }
588 break;
589 }
590 if (LocaleCompare(map,"RGBP") == 0)
591 {
592 for (y=0; y < (ssize_t) rows; y++)
593 {
594 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
595 if (p == (const Quantum *) NULL)
596 break;
597 for (x=0; x < (ssize_t) columns; x++)
598 {
599 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
600 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
601 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
602 *q++=ScaleQuantumToChar((Quantum) 0);
cristyed231572011-07-14 02:18:59 +0000603 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000604 }
605 }
606 break;
607 }
608 for (y=0; y < (ssize_t) rows; y++)
609 {
610 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
611 if (p == (const Quantum *) NULL)
612 break;
613 for (x=0; x < (ssize_t) columns; x++)
614 {
615 for (i=0; i < (ssize_t) length; i++)
616 {
617 *q=0;
618 switch (quantum_map[i])
619 {
620 case RedQuantum:
621 case CyanQuantum:
622 {
623 *q=ScaleQuantumToChar(GetPixelRed(image,p));
624 break;
625 }
626 case GreenQuantum:
627 case MagentaQuantum:
628 {
629 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
630 break;
631 }
632 case BlueQuantum:
633 case YellowQuantum:
634 {
635 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
636 break;
637 }
638 case AlphaQuantum:
639 {
640 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
641 break;
642 }
643 case OpacityQuantum:
644 {
645 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
646 break;
647 }
648 case BlackQuantum:
649 {
650 if (image->colorspace == CMYKColorspace)
651 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
652 break;
653 }
654 case IndexQuantum:
655 {
656 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
657 break;
658 }
659 default:
660 break;
661 }
662 q++;
663 }
cristyed231572011-07-14 02:18:59 +0000664 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000665 }
666 }
667 break;
668 }
669 case DoublePixel:
670 {
671 register double
672 *q;
673
674 q=(double *) pixels;
675 if (LocaleCompare(map,"BGR") == 0)
676 {
677 for (y=0; y < (ssize_t) rows; y++)
678 {
679 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
680 if (p == (const Quantum *) NULL)
681 break;
682 for (x=0; x < (ssize_t) columns; x++)
683 {
684 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
685 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
686 *q++=(double) (QuantumScale*GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +0000687 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000688 }
689 }
690 break;
691 }
692 if (LocaleCompare(map,"BGRA") == 0)
693 {
694 for (y=0; y < (ssize_t) rows; y++)
695 {
696 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
697 if (p == (const Quantum *) NULL)
698 break;
699 for (x=0; x < (ssize_t) columns; x++)
700 {
701 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
702 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
703 *q++=(double) (QuantumScale*GetPixelRed(image,p));
704 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000705 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000706 }
707 }
708 break;
709 }
710 if (LocaleCompare(map,"BGRP") == 0)
711 {
712 for (y=0; y < (ssize_t) rows; y++)
713 {
714 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
715 if (p == (const Quantum *) NULL)
716 break;
717 for (x=0; x < (ssize_t) columns; x++)
718 {
719 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
720 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
721 *q++=(double) (QuantumScale*GetPixelRed(image,p));
722 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000723 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000724 }
725 }
726 break;
727 }
728 if (LocaleCompare(map,"I") == 0)
729 {
730 for (y=0; y < (ssize_t) rows; y++)
731 {
732 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
733 if (p == (const Quantum *) NULL)
734 break;
735 for (x=0; x < (ssize_t) columns; x++)
736 {
737 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000738 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000739 }
740 }
741 break;
742 }
743 if (LocaleCompare(map,"RGB") == 0)
744 {
745 for (y=0; y < (ssize_t) rows; y++)
746 {
747 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
748 if (p == (const Quantum *) NULL)
749 break;
750 for (x=0; x < (ssize_t) columns; x++)
751 {
752 *q++=(double) (QuantumScale*GetPixelRed(image,p));
753 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
754 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000755 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000756 }
757 }
758 break;
759 }
760 if (LocaleCompare(map,"RGBA") == 0)
761 {
762 for (y=0; y < (ssize_t) rows; y++)
763 {
764 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
765 if (p == (const Quantum *) NULL)
766 break;
767 for (x=0; x < (ssize_t) columns; x++)
768 {
769 *q++=(double) (QuantumScale*GetPixelRed(image,p));
770 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
771 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
772 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000773 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000774 }
775 }
776 break;
777 }
778 if (LocaleCompare(map,"RGBP") == 0)
779 {
780 for (y=0; y < (ssize_t) rows; y++)
781 {
782 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
783 if (p == (const Quantum *) NULL)
784 break;
785 for (x=0; x < (ssize_t) columns; x++)
786 {
787 *q++=(double) (QuantumScale*GetPixelRed(image,p));
788 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
789 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
790 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000791 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000792 }
793 }
794 break;
795 }
796 for (y=0; y < (ssize_t) rows; y++)
797 {
798 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
799 if (p == (const Quantum *) NULL)
800 break;
801 for (x=0; x < (ssize_t) columns; x++)
802 {
803 for (i=0; i < (ssize_t) length; i++)
804 {
805 *q=0;
806 switch (quantum_map[i])
807 {
808 case RedQuantum:
809 case CyanQuantum:
810 {
811 *q=(double) (QuantumScale*GetPixelRed(image,p));
812 break;
813 }
814 case GreenQuantum:
815 case MagentaQuantum:
816 {
817 *q=(double) (QuantumScale*GetPixelGreen(image,p));
818 break;
819 }
820 case BlueQuantum:
821 case YellowQuantum:
822 {
823 *q=(double) (QuantumScale*GetPixelBlue(image,p));
824 break;
825 }
826 case AlphaQuantum:
827 {
828 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
829 break;
830 }
831 case OpacityQuantum:
832 {
833 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
834 break;
835 }
836 case BlackQuantum:
837 {
838 if (image->colorspace == CMYKColorspace)
839 *q=(double) (QuantumScale*
840 GetPixelBlack(image,p));
841 break;
842 }
843 case IndexQuantum:
844 {
845 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
846 break;
847 }
848 default:
849 *q=0;
850 }
851 q++;
852 }
cristyed231572011-07-14 02:18:59 +0000853 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000854 }
855 }
856 break;
857 }
858 case FloatPixel:
859 {
860 register float
861 *q;
862
863 q=(float *) pixels;
864 if (LocaleCompare(map,"BGR") == 0)
865 {
866 for (y=0; y < (ssize_t) rows; y++)
867 {
868 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
869 if (p == (const Quantum *) NULL)
870 break;
871 for (x=0; x < (ssize_t) columns; x++)
872 {
873 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
874 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
875 *q++=(float) (QuantumScale*GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +0000876 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000877 }
878 }
879 break;
880 }
881 if (LocaleCompare(map,"BGRA") == 0)
882 {
883 for (y=0; y < (ssize_t) rows; y++)
884 {
885 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
886 if (p == (const Quantum *) NULL)
887 break;
888 for (x=0; x < (ssize_t) columns; x++)
889 {
890 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
891 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
892 *q++=(float) (QuantumScale*GetPixelRed(image,p));
893 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000894 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000895 }
896 }
897 break;
898 }
899 if (LocaleCompare(map,"BGRP") == 0)
900 {
901 for (y=0; y < (ssize_t) rows; y++)
902 {
903 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
904 if (p == (const Quantum *) NULL)
905 break;
906 for (x=0; x < (ssize_t) columns; x++)
907 {
908 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
909 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
910 *q++=(float) (QuantumScale*GetPixelRed(image,p));
911 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000912 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000913 }
914 }
915 break;
916 }
917 if (LocaleCompare(map,"I") == 0)
918 {
919 for (y=0; y < (ssize_t) rows; y++)
920 {
921 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
922 if (p == (const Quantum *) NULL)
923 break;
924 for (x=0; x < (ssize_t) columns; x++)
925 {
926 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000927 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000928 }
929 }
930 break;
931 }
932 if (LocaleCompare(map,"RGB") == 0)
933 {
934 for (y=0; y < (ssize_t) rows; y++)
935 {
936 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
937 if (p == (const Quantum *) NULL)
938 break;
939 for (x=0; x < (ssize_t) columns; x++)
940 {
941 *q++=(float) (QuantumScale*GetPixelRed(image,p));
942 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
943 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000944 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000945 }
946 }
947 break;
948 }
949 if (LocaleCompare(map,"RGBA") == 0)
950 {
951 for (y=0; y < (ssize_t) rows; y++)
952 {
953 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
954 if (p == (const Quantum *) NULL)
955 break;
956 for (x=0; x < (ssize_t) columns; x++)
957 {
958 *q++=(float) (QuantumScale*GetPixelRed(image,p));
959 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
960 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
961 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000962 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000963 }
964 }
965 break;
966 }
967 if (LocaleCompare(map,"RGBP") == 0)
968 {
969 for (y=0; y < (ssize_t) rows; y++)
970 {
971 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
972 if (p == (const Quantum *) NULL)
973 break;
974 for (x=0; x < (ssize_t) columns; x++)
975 {
976 *q++=(float) (QuantumScale*GetPixelRed(image,p));
977 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
978 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
979 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000980 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000981 }
982 }
983 break;
984 }
985 for (y=0; y < (ssize_t) rows; y++)
986 {
987 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
988 if (p == (const Quantum *) NULL)
989 break;
990 for (x=0; x < (ssize_t) columns; x++)
991 {
992 for (i=0; i < (ssize_t) length; i++)
993 {
994 *q=0;
995 switch (quantum_map[i])
996 {
997 case RedQuantum:
998 case CyanQuantum:
999 {
1000 *q=(float) (QuantumScale*GetPixelRed(image,p));
1001 break;
1002 }
1003 case GreenQuantum:
1004 case MagentaQuantum:
1005 {
1006 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1007 break;
1008 }
1009 case BlueQuantum:
1010 case YellowQuantum:
1011 {
1012 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1013 break;
1014 }
1015 case AlphaQuantum:
1016 {
1017 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1018 break;
1019 }
1020 case OpacityQuantum:
1021 {
1022 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1023 break;
1024 }
1025 case BlackQuantum:
1026 {
1027 if (image->colorspace == CMYKColorspace)
1028 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1029 break;
1030 }
1031 case IndexQuantum:
1032 {
1033 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1034 break;
1035 }
1036 default:
1037 *q=0;
1038 }
1039 q++;
1040 }
cristyed231572011-07-14 02:18:59 +00001041 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001042 }
1043 }
1044 break;
1045 }
1046 case IntegerPixel:
1047 {
1048 register unsigned int
1049 *q;
1050
1051 q=(unsigned int *) pixels;
1052 if (LocaleCompare(map,"BGR") == 0)
1053 {
1054 for (y=0; y < (ssize_t) rows; y++)
1055 {
1056 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1057 if (p == (const Quantum *) NULL)
1058 break;
1059 for (x=0; x < (ssize_t) columns; x++)
1060 {
1061 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1062 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1063 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +00001064 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001065 }
1066 }
1067 break;
1068 }
1069 if (LocaleCompare(map,"BGRA") == 0)
1070 {
1071 for (y=0; y < (ssize_t) rows; y++)
1072 {
1073 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1074 if (p == (const Quantum *) NULL)
1075 break;
1076 for (x=0; x < (ssize_t) columns; x++)
1077 {
1078 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1079 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1080 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1081 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001082 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001083 }
1084 }
1085 break;
1086 }
1087 if (LocaleCompare(map,"BGRP") == 0)
1088 {
1089 for (y=0; y < (ssize_t) rows; y++)
1090 {
1091 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1092 if (p == (const Quantum *) NULL)
1093 break;
1094 for (x=0; x < (ssize_t) columns; x++)
1095 {
1096 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1097 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1098 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1099 *q++=0U;
cristyed231572011-07-14 02:18:59 +00001100 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001101 }
1102 }
1103 break;
1104 }
1105 if (LocaleCompare(map,"I") == 0)
1106 {
1107 for (y=0; y < (ssize_t) rows; y++)
1108 {
1109 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1110 if (p == (const Quantum *) NULL)
1111 break;
1112 for (x=0; x < (ssize_t) columns; x++)
1113 {
1114 *q++=(unsigned int) ScaleQuantumToLong(
1115 GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +00001116 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001117 }
1118 }
1119 break;
1120 }
1121 if (LocaleCompare(map,"RGB") == 0)
1122 {
1123 for (y=0; y < (ssize_t) rows; y++)
1124 {
1125 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1126 if (p == (const Quantum *) NULL)
1127 break;
1128 for (x=0; x < (ssize_t) columns; x++)
1129 {
1130 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1131 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1132 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +00001133 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001134 }
1135 }
1136 break;
1137 }
1138 if (LocaleCompare(map,"RGBA") == 0)
1139 {
1140 for (y=0; y < (ssize_t) rows; y++)
1141 {
1142 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1143 if (p == (const Quantum *) NULL)
1144 break;
1145 for (x=0; x < (ssize_t) columns; x++)
1146 {
1147 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1148 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1149 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1150 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001151 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001152 }
1153 }
1154 break;
1155 }
1156 if (LocaleCompare(map,"RGBP") == 0)
1157 {
1158 for (y=0; y < (ssize_t) rows; y++)
1159 {
1160 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1161 if (p == (const Quantum *) NULL)
1162 break;
1163 for (x=0; x < (ssize_t) columns; x++)
1164 {
1165 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1166 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1167 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1168 *q++=0U;
cristyed231572011-07-14 02:18:59 +00001169 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001170 }
1171 }
1172 break;
1173 }
1174 for (y=0; y < (ssize_t) rows; y++)
1175 {
1176 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1177 if (p == (const Quantum *) NULL)
1178 break;
1179 for (x=0; x < (ssize_t) columns; x++)
1180 {
1181 for (i=0; i < (ssize_t) length; i++)
1182 {
1183 *q=0;
1184 switch (quantum_map[i])
1185 {
1186 case RedQuantum:
1187 case CyanQuantum:
1188 {
1189 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1190 break;
1191 }
1192 case GreenQuantum:
1193 case MagentaQuantum:
1194 {
1195 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1196 break;
1197 }
1198 case BlueQuantum:
1199 case YellowQuantum:
1200 {
1201 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1202 break;
1203 }
1204 case AlphaQuantum:
1205 {
1206 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1207 break;
1208 }
1209 case OpacityQuantum:
1210 {
1211 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1212 break;
1213 }
1214 case BlackQuantum:
1215 {
1216 if (image->colorspace == CMYKColorspace)
1217 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
1218 break;
1219 }
1220 case IndexQuantum:
1221 {
1222 *q=(unsigned int) ScaleQuantumToLong(
1223 GetPixelIntensity(image,p));
1224 break;
1225 }
1226 default:
1227 *q=0;
1228 }
1229 q++;
1230 }
cristyed231572011-07-14 02:18:59 +00001231 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001232 }
1233 }
1234 break;
1235 }
1236 case LongPixel:
1237 {
1238 register size_t
1239 *q;
1240
1241 q=(size_t *) pixels;
1242 if (LocaleCompare(map,"BGR") == 0)
1243 {
1244 for (y=0; y < (ssize_t) rows; y++)
1245 {
1246 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1247 if (p == (const Quantum *) NULL)
1248 break;
1249 for (x=0; x < (ssize_t) columns; x++)
1250 {
1251 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1252 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1253 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +00001254 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001255 }
1256 }
1257 break;
1258 }
1259 if (LocaleCompare(map,"BGRA") == 0)
1260 {
1261 for (y=0; y < (ssize_t) rows; y++)
1262 {
1263 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1264 if (p == (const Quantum *) NULL)
1265 break;
1266 for (x=0; x < (ssize_t) columns; x++)
1267 {
1268 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1269 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1270 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1271 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001272 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001273 }
1274 }
1275 break;
1276 }
1277 if (LocaleCompare(map,"BGRP") == 0)
1278 {
1279 for (y=0; y < (ssize_t) rows; y++)
1280 {
1281 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1282 if (p == (const Quantum *) NULL)
1283 break;
1284 for (x=0; x < (ssize_t) columns; x++)
1285 {
1286 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1287 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1288 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1289 *q++=0;
cristyed231572011-07-14 02:18:59 +00001290 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001291 }
1292 }
1293 break;
1294 }
1295 if (LocaleCompare(map,"I") == 0)
1296 {
1297 for (y=0; y < (ssize_t) rows; y++)
1298 {
1299 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1300 if (p == (const Quantum *) NULL)
1301 break;
1302 for (x=0; x < (ssize_t) columns; x++)
1303 {
1304 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +00001305 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001306 }
1307 }
1308 break;
1309 }
1310 if (LocaleCompare(map,"RGB") == 0)
1311 {
1312 for (y=0; y < (ssize_t) rows; y++)
1313 {
1314 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1315 if (p == (const Quantum *) NULL)
1316 break;
1317 for (x=0; x < (ssize_t) columns; x++)
1318 {
1319 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1320 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1321 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +00001322 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001323 }
1324 }
1325 break;
1326 }
1327 if (LocaleCompare(map,"RGBA") == 0)
1328 {
1329 for (y=0; y < (ssize_t) rows; y++)
1330 {
1331 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1332 if (p == (const Quantum *) NULL)
1333 break;
1334 for (x=0; x < (ssize_t) columns; x++)
1335 {
1336 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1337 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1338 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1339 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001340 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001341 }
1342 }
1343 break;
1344 }
1345 if (LocaleCompare(map,"RGBP") == 0)
1346 {
1347 for (y=0; y < (ssize_t) rows; y++)
1348 {
1349 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1350 if (p == (const Quantum *) NULL)
1351 break;
1352 for (x=0; x < (ssize_t) columns; x++)
1353 {
1354 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1355 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1356 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1357 *q++=0;
cristyed231572011-07-14 02:18:59 +00001358 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001359 }
1360 }
1361 break;
1362 }
1363 for (y=0; y < (ssize_t) rows; y++)
1364 {
1365 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1366 if (p == (const Quantum *) NULL)
1367 break;
1368 for (x=0; x < (ssize_t) columns; x++)
1369 {
1370 for (i=0; i < (ssize_t) length; i++)
1371 {
1372 *q=0;
1373 switch (quantum_map[i])
1374 {
1375 case RedQuantum:
1376 case CyanQuantum:
1377 {
1378 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1379 break;
1380 }
1381 case GreenQuantum:
1382 case MagentaQuantum:
1383 {
1384 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1385 break;
1386 }
1387 case BlueQuantum:
1388 case YellowQuantum:
1389 {
1390 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1391 break;
1392 }
1393 case AlphaQuantum:
1394 {
1395 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1396 break;
1397 }
1398 case OpacityQuantum:
1399 {
1400 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1401 break;
1402 }
1403 case BlackQuantum:
1404 {
1405 if (image->colorspace == CMYKColorspace)
1406 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1407 break;
1408 }
1409 case IndexQuantum:
1410 {
1411 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1412 break;
1413 }
1414 default:
1415 break;
1416 }
1417 q++;
1418 }
cristyed231572011-07-14 02:18:59 +00001419 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001420 }
1421 }
1422 break;
1423 }
1424 case QuantumPixel:
1425 {
1426 register Quantum
1427 *q;
1428
1429 q=(Quantum *) pixels;
1430 if (LocaleCompare(map,"BGR") == 0)
1431 {
1432 for (y=0; y < (ssize_t) rows; y++)
1433 {
1434 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1435 if (p == (const Quantum *) NULL)
1436 break;
1437 for (x=0; x < (ssize_t) columns; x++)
1438 {
1439 *q++=GetPixelBlue(image,p);
1440 *q++=GetPixelGreen(image,p);
1441 *q++=GetPixelRed(image,p);
cristyed231572011-07-14 02:18:59 +00001442 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001443 }
1444 }
1445 break;
1446 }
1447 if (LocaleCompare(map,"BGRA") == 0)
1448 {
1449 for (y=0; y < (ssize_t) rows; y++)
1450 {
1451 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1452 if (p == (const Quantum *) NULL)
1453 break;
1454 for (x=0; x < (ssize_t) columns; x++)
1455 {
1456 *q++=GetPixelBlue(image,p);
1457 *q++=GetPixelGreen(image,p);
1458 *q++=GetPixelRed(image,p);
1459 *q++=(Quantum) (GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001460 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001461 }
1462 }
1463 break;
1464 }
1465 if (LocaleCompare(map,"BGRP") == 0)
1466 {
1467 for (y=0; y < (ssize_t) rows; y++)
1468 {
1469 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1470 if (p == (const Quantum *) NULL)
1471 break;
1472 for (x=0; x < (ssize_t) columns; x++)
1473 {
1474 *q++=GetPixelBlue(image,p);
1475 *q++=GetPixelGreen(image,p);
1476 *q++=GetPixelRed(image,p);
1477 *q++=(Quantum) 0;
cristyed231572011-07-14 02:18:59 +00001478 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001479 }
1480 }
1481 break;
1482 }
1483 if (LocaleCompare(map,"I") == 0)
1484 {
1485 for (y=0; y < (ssize_t) rows; y++)
1486 {
1487 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1488 if (p == (const Quantum *) NULL)
1489 break;
1490 for (x=0; x < (ssize_t) columns; x++)
1491 {
1492 *q++=GetPixelIntensity(image,p);
cristyed231572011-07-14 02:18:59 +00001493 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001494 }
1495 }
1496 break;
1497 }
1498 if (LocaleCompare(map,"RGB") == 0)
1499 {
1500 for (y=0; y < (ssize_t) rows; y++)
1501 {
1502 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1503 if (p == (const Quantum *) NULL)
1504 break;
1505 for (x=0; x < (ssize_t) columns; x++)
1506 {
1507 *q++=GetPixelRed(image,p);
1508 *q++=GetPixelGreen(image,p);
1509 *q++=GetPixelBlue(image,p);
cristyed231572011-07-14 02:18:59 +00001510 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001511 }
1512 }
1513 break;
1514 }
1515 if (LocaleCompare(map,"RGBA") == 0)
1516 {
1517 for (y=0; y < (ssize_t) rows; y++)
1518 {
1519 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1520 if (p == (const Quantum *) NULL)
1521 break;
1522 for (x=0; x < (ssize_t) columns; x++)
1523 {
1524 *q++=GetPixelRed(image,p);
1525 *q++=GetPixelGreen(image,p);
1526 *q++=GetPixelBlue(image,p);
1527 *q++=(Quantum) (GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001528 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001529 }
1530 }
1531 break;
1532 }
1533 if (LocaleCompare(map,"RGBP") == 0)
1534 {
1535 for (y=0; y < (ssize_t) rows; y++)
1536 {
1537 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1538 if (p == (const Quantum *) NULL)
1539 break;
1540 for (x=0; x < (ssize_t) columns; x++)
1541 {
1542 *q++=GetPixelRed(image,p);
1543 *q++=GetPixelGreen(image,p);
1544 *q++=GetPixelBlue(image,p);
1545 *q++=(Quantum) 0;
cristyed231572011-07-14 02:18:59 +00001546 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001547 }
1548 }
1549 break;
1550 }
1551 for (y=0; y < (ssize_t) rows; y++)
1552 {
1553 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1554 if (p == (const Quantum *) NULL)
1555 break;
1556 for (x=0; x < (ssize_t) columns; x++)
1557 {
1558 for (i=0; i < (ssize_t) length; i++)
1559 {
1560 *q=(Quantum) 0;
1561 switch (quantum_map[i])
1562 {
1563 case RedQuantum:
1564 case CyanQuantum:
1565 {
1566 *q=GetPixelRed(image,p);
1567 break;
1568 }
1569 case GreenQuantum:
1570 case MagentaQuantum:
1571 {
1572 *q=GetPixelGreen(image,p);
1573 break;
1574 }
1575 case BlueQuantum:
1576 case YellowQuantum:
1577 {
1578 *q=GetPixelBlue(image,p);
1579 break;
1580 }
1581 case AlphaQuantum:
1582 {
1583 *q=(Quantum) (GetPixelAlpha(image,p));
1584 break;
1585 }
1586 case OpacityQuantum:
1587 {
1588 *q=GetPixelAlpha(image,p);
1589 break;
1590 }
1591 case BlackQuantum:
1592 {
1593 if (image->colorspace == CMYKColorspace)
1594 *q=GetPixelBlack(image,p);
1595 break;
1596 }
1597 case IndexQuantum:
1598 {
1599 *q=(GetPixelIntensity(image,p));
1600 break;
1601 }
1602 default:
1603 *q=(Quantum) 0;
1604 }
1605 q++;
1606 }
cristyed231572011-07-14 02:18:59 +00001607 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001608 }
1609 }
1610 break;
1611 }
1612 case ShortPixel:
1613 {
1614 register unsigned short
1615 *q;
1616
1617 q=(unsigned short *) pixels;
1618 if (LocaleCompare(map,"BGR") == 0)
1619 {
1620 for (y=0; y < (ssize_t) rows; y++)
1621 {
1622 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1623 if (p == (const Quantum *) NULL)
1624 break;
1625 for (x=0; x < (ssize_t) columns; x++)
1626 {
1627 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1628 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1629 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +00001630 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001631 }
1632 }
1633 break;
1634 }
1635 if (LocaleCompare(map,"BGRA") == 0)
1636 {
1637 for (y=0; y < (ssize_t) rows; y++)
1638 {
1639 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1640 if (p == (const Quantum *) NULL)
1641 break;
1642 for (x=0; x < (ssize_t) columns; x++)
1643 {
1644 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1645 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1646 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1647 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001648 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001649 }
1650 }
1651 break;
1652 }
1653 if (LocaleCompare(map,"BGRP") == 0)
1654 {
1655 for (y=0; y < (ssize_t) rows; y++)
1656 {
1657 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1658 if (p == (const Quantum *) NULL)
1659 break;
1660 for (x=0; x < (ssize_t) columns; x++)
1661 {
1662 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1663 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1664 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1665 *q++=0;
cristyed231572011-07-14 02:18:59 +00001666 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001667 }
1668 }
1669 break;
1670 }
1671 if (LocaleCompare(map,"I") == 0)
1672 {
1673 for (y=0; y < (ssize_t) rows; y++)
1674 {
1675 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1676 if (p == (const Quantum *) NULL)
1677 break;
1678 for (x=0; x < (ssize_t) columns; x++)
1679 {
1680 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +00001681 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001682 }
1683 }
1684 break;
1685 }
1686 if (LocaleCompare(map,"RGB") == 0)
1687 {
1688 for (y=0; y < (ssize_t) rows; y++)
1689 {
1690 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1691 if (p == (const Quantum *) NULL)
1692 break;
1693 for (x=0; x < (ssize_t) columns; x++)
1694 {
1695 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1696 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1697 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +00001698 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001699 }
1700 }
1701 break;
1702 }
1703 if (LocaleCompare(map,"RGBA") == 0)
1704 {
1705 for (y=0; y < (ssize_t) rows; y++)
1706 {
1707 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1708 if (p == (const Quantum *) NULL)
1709 break;
1710 for (x=0; x < (ssize_t) columns; x++)
1711 {
1712 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1713 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1714 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1715 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001716 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001717 }
1718 }
1719 break;
1720 }
1721 if (LocaleCompare(map,"RGBP") == 0)
1722 {
1723 for (y=0; y < (ssize_t) rows; y++)
1724 {
1725 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1726 if (p == (const Quantum *) NULL)
1727 break;
1728 for (x=0; x < (ssize_t) columns; x++)
1729 {
1730 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1731 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1732 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1733 *q++=0;
cristyed231572011-07-14 02:18:59 +00001734 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001735 }
1736 }
1737 break;
1738 }
1739 for (y=0; y < (ssize_t) rows; y++)
1740 {
1741 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1742 if (p == (const Quantum *) NULL)
1743 break;
1744 for (x=0; x < (ssize_t) columns; x++)
1745 {
1746 for (i=0; i < (ssize_t) length; i++)
1747 {
1748 *q=0;
1749 switch (quantum_map[i])
1750 {
1751 case RedQuantum:
1752 case CyanQuantum:
1753 {
1754 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1755 break;
1756 }
1757 case GreenQuantum:
1758 case MagentaQuantum:
1759 {
1760 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1761 break;
1762 }
1763 case BlueQuantum:
1764 case YellowQuantum:
1765 {
1766 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1767 break;
1768 }
1769 case AlphaQuantum:
1770 {
1771 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1772 break;
1773 }
1774 case OpacityQuantum:
1775 {
1776 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1777 break;
1778 }
1779 case BlackQuantum:
1780 {
1781 if (image->colorspace == CMYKColorspace)
1782 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1783 break;
1784 }
1785 case IndexQuantum:
1786 {
1787 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1788 break;
1789 }
1790 default:
1791 break;
1792 }
1793 q++;
1794 }
cristyed231572011-07-14 02:18:59 +00001795 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001796 }
1797 }
1798 break;
1799 }
1800 default:
1801 {
1802 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1803 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1804 "UnrecognizedPixelMap","`%s'",map);
1805 break;
1806 }
1807 }
1808 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1809 return(MagickTrue);
1810}
1811
1812/*
1813%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1814% %
1815% %
1816% %
cristyaa8634f2011-10-01 13:25:12 +00001817% G e t P i x e l I n f o %
cristy4c08aed2011-07-01 19:47:50 +00001818% %
1819% %
1820% %
1821%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1822%
1823% GetPixelInfo() initializes the PixelInfo structure.
1824%
1825% The format of the GetPixelInfo method is:
1826%
1827% GetPixelInfo(const Image *image,PixelInfo *pixel)
1828%
1829% A description of each parameter follows:
1830%
1831% o image: the image.
1832%
cristy101ab702011-10-13 13:06:32 +00001833% o pixel: Specifies a pointer to a PixelInfo structure.
cristy4c08aed2011-07-01 19:47:50 +00001834%
1835*/
cristyaa8634f2011-10-01 13:25:12 +00001836MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
cristy4c08aed2011-07-01 19:47:50 +00001837{
1838 pixel->storage_class=DirectClass;
1839 pixel->colorspace=RGBColorspace;
1840 pixel->matte=MagickFalse;
1841 pixel->fuzz=0.0;
1842 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1843 pixel->red=0.0;
1844 pixel->green=0.0;
1845 pixel->blue=0.0;
1846 pixel->black=0.0;
1847 pixel->alpha=(MagickRealType) OpaqueAlpha;
1848 pixel->index=0.0;
1849 if (image == (const Image *) NULL)
1850 return;
1851 pixel->storage_class=image->storage_class;
1852 pixel->colorspace=image->colorspace;
1853 pixel->matte=image->matte;
1854 pixel->depth=image->depth;
1855 pixel->fuzz=image->fuzz;
1856}
1857
1858/*
1859%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1860% %
1861% %
1862% %
1863% I m p o r t I m a g e P i x e l s %
1864% %
1865% %
1866% %
1867%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1868%
1869% ImportImagePixels() accepts pixel data and stores in the image at the
1870% location you specify. The method returns MagickTrue on success otherwise
1871% MagickFalse if an error is encountered. The pixel data can be either char,
1872% short int, int, ssize_t, float, or double in the order specified by map.
1873%
1874% Suppose your want to upload the first scanline of a 640x480 image from
1875% character data in red-green-blue order:
1876%
1877% ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
1878%
1879% The format of the ImportImagePixels method is:
1880%
1881% MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset,
1882% const ssize_t y_offset,const size_t columns,
1883% const size_t rows,const char *map,const StorageType type,
cristy018f07f2011-09-04 21:15:19 +00001884% const void *pixels,ExceptionInfo *exception)
cristy4c08aed2011-07-01 19:47:50 +00001885%
1886% A description of each parameter follows:
1887%
1888% o image: the image.
1889%
1890% o x_offset,y_offset,columns,rows: These values define the perimeter
1891% of a region of pixels you want to define.
1892%
1893% o map: This string reflects the expected ordering of the pixel array.
1894% It can be any combination or order of R = red, G = green, B = blue,
1895% A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
1896% Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
1897% P = pad.
1898%
1899% o type: Define the data type of the pixels. Float and double types are
1900% normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
1901% types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
1902% DoublePixel.
1903%
1904% o pixels: This array of values contain the pixel components as defined by
1905% map and type. You must preallocate this array where the expected
1906% length varies depending on the values of width, height, map, and type.
1907%
cristy018f07f2011-09-04 21:15:19 +00001908% o exception: return any errors or warnings in this structure.
1909%
cristy4c08aed2011-07-01 19:47:50 +00001910*/
1911MagickExport MagickBooleanType ImportImagePixels(Image *image,
1912 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
1913 const size_t rows,const char *map,const StorageType type,
cristy018f07f2011-09-04 21:15:19 +00001914 const void *pixels,ExceptionInfo *exception)
cristy4c08aed2011-07-01 19:47:50 +00001915{
cristy4c08aed2011-07-01 19:47:50 +00001916 QuantumType
1917 *quantum_map;
1918
1919 register Quantum
1920 *q;
1921
1922 register ssize_t
1923 i,
1924 x;
1925
1926 size_t
1927 length;
1928
1929 ssize_t
1930 y;
1931
1932 /*
1933 Allocate image structure.
1934 */
1935 assert(image != (Image *) NULL);
1936 assert(image->signature == MagickSignature);
1937 if (image->debug != MagickFalse)
1938 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1939 length=strlen(map);
1940 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1941 if (quantum_map == (QuantumType *) NULL)
1942 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1943 image->filename);
1944 for (i=0; i < (ssize_t) length; i++)
1945 {
1946 switch (map[i])
1947 {
1948 case 'a':
1949 case 'A':
1950 {
1951 quantum_map[i]=AlphaQuantum;
1952 image->matte=MagickTrue;
1953 break;
1954 }
1955 case 'B':
1956 case 'b':
1957 {
1958 quantum_map[i]=BlueQuantum;
1959 break;
1960 }
1961 case 'C':
1962 case 'c':
1963 {
1964 quantum_map[i]=CyanQuantum;
cristy63240882011-08-05 19:05:27 +00001965 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00001966 break;
1967 }
1968 case 'g':
1969 case 'G':
1970 {
1971 quantum_map[i]=GreenQuantum;
1972 break;
1973 }
1974 case 'K':
1975 case 'k':
1976 {
1977 quantum_map[i]=BlackQuantum;
cristy63240882011-08-05 19:05:27 +00001978 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00001979 break;
1980 }
1981 case 'I':
1982 case 'i':
1983 {
1984 quantum_map[i]=IndexQuantum;
1985 break;
1986 }
1987 case 'm':
1988 case 'M':
1989 {
1990 quantum_map[i]=MagentaQuantum;
cristy63240882011-08-05 19:05:27 +00001991 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00001992 break;
1993 }
1994 case 'O':
1995 case 'o':
1996 {
1997 quantum_map[i]=OpacityQuantum;
1998 image->matte=MagickTrue;
1999 break;
2000 }
2001 case 'P':
2002 case 'p':
2003 {
2004 quantum_map[i]=UndefinedQuantum;
2005 break;
2006 }
2007 case 'R':
2008 case 'r':
2009 {
2010 quantum_map[i]=RedQuantum;
2011 break;
2012 }
2013 case 'Y':
2014 case 'y':
2015 {
2016 quantum_map[i]=YellowQuantum;
cristy63240882011-08-05 19:05:27 +00002017 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00002018 break;
2019 }
2020 default:
2021 {
2022 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
cristy63240882011-08-05 19:05:27 +00002023 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2024 "UnrecognizedPixelMap","`%s'",map);
cristy4c08aed2011-07-01 19:47:50 +00002025 return(MagickFalse);
2026 }
2027 }
2028 }
cristy63240882011-08-05 19:05:27 +00002029 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00002030 return(MagickFalse);
2031 /*
2032 Transfer the pixels from the pixel datarray to the image.
2033 */
cristy4c08aed2011-07-01 19:47:50 +00002034 switch (type)
2035 {
2036 case CharPixel:
2037 {
2038 register const unsigned char
2039 *p;
2040
2041 p=(const unsigned char *) pixels;
2042 if (LocaleCompare(map,"BGR") == 0)
2043 {
2044 for (y=0; y < (ssize_t) rows; y++)
2045 {
2046 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2047 if (q == (Quantum *) NULL)
2048 break;
2049 for (x=0; x < (ssize_t) columns; x++)
2050 {
2051 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2052 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2053 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002054 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002055 }
2056 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2057 break;
2058 }
2059 break;
2060 }
2061 if (LocaleCompare(map,"BGRA") == 0)
2062 {
2063 for (y=0; y < (ssize_t) rows; y++)
2064 {
2065 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2066 if (q == (Quantum *) NULL)
2067 break;
2068 for (x=0; x < (ssize_t) columns; x++)
2069 {
2070 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2071 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2072 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2073 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002074 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002075 }
2076 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2077 break;
2078 }
2079 break;
2080 }
2081 if (LocaleCompare(map,"BGRO") == 0)
2082 {
2083 for (y=0; y < (ssize_t) rows; y++)
2084 {
2085 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2086 if (q == (Quantum *) NULL)
2087 break;
2088 for (x=0; x < (ssize_t) columns; x++)
2089 {
2090 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2091 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2092 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2093 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002094 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002095 }
2096 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2097 break;
2098 }
2099 break;
2100 }
2101 if (LocaleCompare(map,"BGRP") == 0)
2102 {
2103 for (y=0; y < (ssize_t) rows; y++)
2104 {
2105 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2106 if (q == (Quantum *) NULL)
2107 break;
2108 for (x=0; x < (ssize_t) columns; x++)
2109 {
2110 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2111 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2112 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2113 p++;
cristyed231572011-07-14 02:18:59 +00002114 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002115 }
2116 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2117 break;
2118 }
2119 break;
2120 }
2121 if (LocaleCompare(map,"I") == 0)
2122 {
2123 for (y=0; y < (ssize_t) rows; y++)
2124 {
2125 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2126 if (q == (Quantum *) NULL)
2127 break;
2128 for (x=0; x < (ssize_t) columns; x++)
2129 {
2130 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2131 SetPixelGreen(image,GetPixelRed(image,q),q);
2132 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00002133 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002134 }
2135 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2136 break;
2137 }
2138 break;
2139 }
2140 if (LocaleCompare(map,"RGB") == 0)
2141 {
2142 for (y=0; y < (ssize_t) rows; y++)
2143 {
2144 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2145 if (q == (Quantum *) NULL)
2146 break;
2147 for (x=0; x < (ssize_t) columns; x++)
2148 {
2149 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2150 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2151 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002152 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002153 }
2154 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2155 break;
2156 }
2157 break;
2158 }
2159 if (LocaleCompare(map,"RGBA") == 0)
2160 {
2161 for (y=0; y < (ssize_t) rows; y++)
2162 {
2163 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2164 if (q == (Quantum *) NULL)
2165 break;
2166 for (x=0; x < (ssize_t) columns; x++)
2167 {
2168 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2169 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2170 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2171 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002172 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002173 }
2174 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2175 break;
2176 }
2177 break;
2178 }
2179 if (LocaleCompare(map,"RGBO") == 0)
2180 {
2181 for (y=0; y < (ssize_t) rows; y++)
2182 {
2183 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2184 if (q == (Quantum *) NULL)
2185 break;
2186 for (x=0; x < (ssize_t) columns; x++)
2187 {
2188 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2189 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2190 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2191 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002192 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002193 }
2194 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2195 break;
2196 }
2197 break;
2198 }
2199 if (LocaleCompare(map,"RGBP") == 0)
2200 {
2201 for (y=0; y < (ssize_t) rows; y++)
2202 {
2203 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2204 if (q == (Quantum *) NULL)
2205 break;
2206 for (x=0; x < (ssize_t) columns; x++)
2207 {
2208 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2209 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2210 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2211 p++;
cristyed231572011-07-14 02:18:59 +00002212 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002213 }
2214 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2215 break;
2216 }
2217 break;
2218 }
2219 for (y=0; y < (ssize_t) rows; y++)
2220 {
2221 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2222 if (q == (Quantum *) NULL)
2223 break;
2224 for (x=0; x < (ssize_t) columns; x++)
2225 {
2226 for (i=0; i < (ssize_t) length; i++)
2227 {
2228 switch (quantum_map[i])
2229 {
2230 case RedQuantum:
2231 case CyanQuantum:
2232 {
2233 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2234 break;
2235 }
2236 case GreenQuantum:
2237 case MagentaQuantum:
2238 {
2239 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2240 break;
2241 }
2242 case BlueQuantum:
2243 case YellowQuantum:
2244 {
2245 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2246 break;
2247 }
2248 case AlphaQuantum:
2249 {
2250 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2251 break;
2252 }
2253 case OpacityQuantum:
2254 {
2255 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2256 break;
2257 }
2258 case BlackQuantum:
2259 {
2260 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2261 break;
2262 }
2263 case IndexQuantum:
2264 {
2265 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2266 SetPixelGreen(image,GetPixelRed(image,q),q);
2267 SetPixelBlue(image,GetPixelRed(image,q),q);
2268 break;
2269 }
2270 default:
2271 break;
2272 }
2273 p++;
2274 }
cristyed231572011-07-14 02:18:59 +00002275 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002276 }
2277 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2278 break;
2279 }
2280 break;
2281 }
2282 case DoublePixel:
2283 {
2284 register const double
2285 *p;
2286
2287 p=(const double *) pixels;
2288 if (LocaleCompare(map,"BGR") == 0)
2289 {
2290 for (y=0; y < (ssize_t) rows; y++)
2291 {
2292 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2293 if (q == (Quantum *) NULL)
2294 break;
2295 for (x=0; x < (ssize_t) columns; x++)
2296 {
2297 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2298 (*p)),q);
2299 p++;
2300 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2301 (*p)),q);
2302 p++;
2303 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2304 (*p)),q);
2305 p++;
cristyed231572011-07-14 02:18:59 +00002306 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002307 }
2308 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2309 break;
2310 }
2311 break;
2312 }
2313 if (LocaleCompare(map,"BGRA") == 0)
2314 {
2315 for (y=0; y < (ssize_t) rows; y++)
2316 {
2317 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2318 if (q == (Quantum *) NULL)
2319 break;
2320 for (x=0; x < (ssize_t) columns; x++)
2321 {
2322 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2323 (*p)),q);
2324 p++;
2325 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2326 (*p)),q);
2327 p++;
2328 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2329 (*p)),q);
2330 p++;
2331 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2332 (*p)),q);
2333 p++;
cristyed231572011-07-14 02:18:59 +00002334 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002335 }
2336 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2337 break;
2338 }
2339 break;
2340 }
2341 if (LocaleCompare(map,"BGRP") == 0)
2342 {
2343 for (y=0; y < (ssize_t) rows; y++)
2344 {
2345 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2346 if (q == (Quantum *) NULL)
2347 break;
2348 for (x=0; x < (ssize_t) columns; x++)
2349 {
2350 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2351 (*p)),q);
2352 p++;
2353 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2354 (*p)),q);
2355 p++;
2356 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2357 (*p)),q);
2358 p++;
2359 p++;
cristyed231572011-07-14 02:18:59 +00002360 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002361 }
2362 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2363 break;
2364 }
2365 break;
2366 }
2367 if (LocaleCompare(map,"I") == 0)
2368 {
2369 for (y=0; y < (ssize_t) rows; y++)
2370 {
2371 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2372 if (q == (Quantum *) NULL)
2373 break;
2374 for (x=0; x < (ssize_t) columns; x++)
2375 {
2376 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2377 (*p)),q);
2378 SetPixelGreen(image,GetPixelRed(image,q),q);
2379 SetPixelBlue(image,GetPixelRed(image,q),q);
2380 p++;
cristyed231572011-07-14 02:18:59 +00002381 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002382 }
2383 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2384 break;
2385 }
2386 break;
2387 }
2388 if (LocaleCompare(map,"RGB") == 0)
2389 {
2390 for (y=0; y < (ssize_t) rows; y++)
2391 {
2392 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2393 if (q == (Quantum *) NULL)
2394 break;
2395 for (x=0; x < (ssize_t) columns; x++)
2396 {
2397 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2398 (*p)),q);
2399 p++;
2400 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2401 (*p)),q);
2402 p++;
2403 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2404 (*p)),q);
2405 p++;
cristyed231572011-07-14 02:18:59 +00002406 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002407 }
2408 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2409 break;
2410 }
2411 break;
2412 }
2413 if (LocaleCompare(map,"RGBA") == 0)
2414 {
2415 for (y=0; y < (ssize_t) rows; y++)
2416 {
2417 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2418 if (q == (Quantum *) NULL)
2419 break;
2420 for (x=0; x < (ssize_t) columns; x++)
2421 {
2422 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2423 (*p)),q);
2424 p++;
2425 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2426 (*p)),q);
2427 p++;
2428 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2429 (*p)),q);
2430 p++;
2431 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2432 (*p)),q);
2433 p++;
cristyed231572011-07-14 02:18:59 +00002434 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002435 }
2436 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2437 break;
2438 }
2439 break;
2440 }
2441 if (LocaleCompare(map,"RGBP") == 0)
2442 {
2443 for (y=0; y < (ssize_t) rows; y++)
2444 {
2445 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2446 if (q == (Quantum *) NULL)
2447 break;
2448 for (x=0; x < (ssize_t) columns; x++)
2449 {
2450 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2451 (*p)),q);
2452 p++;
2453 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2454 (*p)),q);
2455 p++;
2456 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2457 (*p)),q);
2458 p++;
cristyed231572011-07-14 02:18:59 +00002459 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002460 }
2461 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2462 break;
2463 }
2464 break;
2465 }
2466 for (y=0; y < (ssize_t) rows; y++)
2467 {
2468 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2469 if (q == (Quantum *) NULL)
2470 break;
2471 for (x=0; x < (ssize_t) columns; x++)
2472 {
2473 for (i=0; i < (ssize_t) length; i++)
2474 {
2475 switch (quantum_map[i])
2476 {
2477 case RedQuantum:
2478 case CyanQuantum:
2479 {
2480 SetPixelRed(image,ClampToQuantum((MagickRealType)
2481 QuantumRange*(*p)),q);
2482 break;
2483 }
2484 case GreenQuantum:
2485 case MagentaQuantum:
2486 {
2487 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2488 QuantumRange*(*p)),q);
2489 break;
2490 }
2491 case BlueQuantum:
2492 case YellowQuantum:
2493 {
2494 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2495 QuantumRange*(*p)),q);
2496 break;
2497 }
2498 case AlphaQuantum:
2499 {
2500 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2501 QuantumRange*(*p)),q);
2502 break;
2503 }
2504 case OpacityQuantum:
2505 {
2506 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2507 QuantumRange*(*p)),q);
2508 break;
2509 }
2510 case BlackQuantum:
2511 {
2512 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2513 QuantumRange*(*p)),q);
2514 break;
2515 }
2516 case IndexQuantum:
2517 {
2518 SetPixelRed(image,ClampToQuantum((MagickRealType)
2519 QuantumRange*(*p)),q);
2520 SetPixelGreen(image,GetPixelRed(image,q),q);
2521 SetPixelBlue(image,GetPixelRed(image,q),q);
2522 break;
2523 }
2524 default:
2525 break;
2526 }
2527 p++;
2528 }
cristyed231572011-07-14 02:18:59 +00002529 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002530 }
2531 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2532 break;
2533 }
2534 break;
2535 }
2536 case FloatPixel:
2537 {
2538 register const float
2539 *p;
2540
2541 p=(const float *) pixels;
2542 if (LocaleCompare(map,"BGR") == 0)
2543 {
2544 for (y=0; y < (ssize_t) rows; y++)
2545 {
2546 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2547 if (q == (Quantum *) NULL)
2548 break;
2549 for (x=0; x < (ssize_t) columns; x++)
2550 {
2551 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2552 (*p)),q);
2553 p++;
2554 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2555 (*p)),q);
2556 p++;
2557 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2558 (*p)),q);
2559 p++;
cristyed231572011-07-14 02:18:59 +00002560 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002561 }
2562 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2563 break;
2564 }
2565 break;
2566 }
2567 if (LocaleCompare(map,"BGRA") == 0)
2568 {
2569 for (y=0; y < (ssize_t) rows; y++)
2570 {
2571 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2572 if (q == (Quantum *) NULL)
2573 break;
2574 for (x=0; x < (ssize_t) columns; x++)
2575 {
2576 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2577 (*p)),q);
2578 p++;
2579 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2580 (*p)),q);
2581 p++;
2582 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2583 (*p)),q);
2584 p++;
2585 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2586 (*p)),q);
2587 p++;
cristyed231572011-07-14 02:18:59 +00002588 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002589 }
2590 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2591 break;
2592 }
2593 break;
2594 }
2595 if (LocaleCompare(map,"BGRP") == 0)
2596 {
2597 for (y=0; y < (ssize_t) rows; y++)
2598 {
2599 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2600 if (q == (Quantum *) NULL)
2601 break;
2602 for (x=0; x < (ssize_t) columns; x++)
2603 {
2604 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2605 (*p)),q);
2606 p++;
2607 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2608 (*p)),q);
2609 p++;
2610 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2611 (*p)),q);
2612 p++;
2613 p++;
cristyed231572011-07-14 02:18:59 +00002614 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002615 }
2616 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2617 break;
2618 }
2619 break;
2620 }
2621 if (LocaleCompare(map,"I") == 0)
2622 {
2623 for (y=0; y < (ssize_t) rows; y++)
2624 {
2625 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2626 if (q == (Quantum *) NULL)
2627 break;
2628 for (x=0; x < (ssize_t) columns; x++)
2629 {
2630 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2631 (*p)),q);
2632 SetPixelGreen(image,GetPixelRed(image,q),q);
2633 SetPixelBlue(image,GetPixelRed(image,q),q);
2634 p++;
cristyed231572011-07-14 02:18:59 +00002635 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002636 }
2637 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2638 break;
2639 }
2640 break;
2641 }
2642 if (LocaleCompare(map,"RGB") == 0)
2643 {
2644 for (y=0; y < (ssize_t) rows; y++)
2645 {
2646 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2647 if (q == (Quantum *) NULL)
2648 break;
2649 for (x=0; x < (ssize_t) columns; x++)
2650 {
2651 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2652 (*p)),q);
2653 p++;
2654 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2655 (*p)),q);
2656 p++;
2657 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2658 (*p)),q);
2659 p++;
cristyed231572011-07-14 02:18:59 +00002660 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002661 }
2662 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2663 break;
2664 }
2665 break;
2666 }
2667 if (LocaleCompare(map,"RGBA") == 0)
2668 {
2669 for (y=0; y < (ssize_t) rows; y++)
2670 {
2671 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2672 if (q == (Quantum *) NULL)
2673 break;
2674 for (x=0; x < (ssize_t) columns; x++)
2675 {
2676 SetPixelRed(image,ClampToQuantum((MagickRealType)
2677 QuantumRange*(*p)),q);
2678 p++;
2679 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2680 (*p)),q);
2681 p++;
2682 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2683 (*p)),q);
2684 p++;
2685 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2686 (*p)),q);
2687 p++;
cristyed231572011-07-14 02:18:59 +00002688 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002689 }
2690 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2691 break;
2692 }
2693 break;
2694 }
2695 if (LocaleCompare(map,"RGBP") == 0)
2696 {
2697 for (y=0; y < (ssize_t) rows; y++)
2698 {
2699 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2700 if (q == (Quantum *) NULL)
2701 break;
2702 for (x=0; x < (ssize_t) columns; x++)
2703 {
2704 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2705 (*p)),q);
2706 p++;
2707 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2708 (*p)),q);
2709 p++;
2710 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2711 (*p)),q);
2712 p++;
cristyed231572011-07-14 02:18:59 +00002713 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002714 }
2715 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2716 break;
2717 }
2718 break;
2719 }
2720 for (y=0; y < (ssize_t) rows; y++)
2721 {
2722 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2723 if (q == (Quantum *) NULL)
2724 break;
2725 for (x=0; x < (ssize_t) columns; x++)
2726 {
2727 for (i=0; i < (ssize_t) length; i++)
2728 {
2729 switch (quantum_map[i])
2730 {
2731 case RedQuantum:
2732 case CyanQuantum:
2733 {
2734 SetPixelRed(image,ClampToQuantum((MagickRealType)
2735 QuantumRange*(*p)),q);
2736 break;
2737 }
2738 case GreenQuantum:
2739 case MagentaQuantum:
2740 {
2741 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2742 QuantumRange*(*p)),q);
2743 break;
2744 }
2745 case BlueQuantum:
2746 case YellowQuantum:
2747 {
2748 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2749 QuantumRange*(*p)),q);
2750 break;
2751 }
2752 case AlphaQuantum:
2753 {
2754 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2755 QuantumRange*(*p)),q);
2756 break;
2757 }
2758 case OpacityQuantum:
2759 {
2760 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2761 QuantumRange*(*p)),q);
2762 break;
2763 }
2764 case BlackQuantum:
2765 {
2766 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2767 QuantumRange*(*p)),q);
2768 break;
2769 }
2770 case IndexQuantum:
2771 {
2772 SetPixelRed(image,ClampToQuantum((MagickRealType)
2773 QuantumRange*(*p)),q);
2774 SetPixelGreen(image,GetPixelRed(image,q),q);
2775 SetPixelBlue(image,GetPixelRed(image,q),q);
2776 break;
2777 }
2778 default:
2779 break;
2780 }
2781 p++;
2782 }
cristyed231572011-07-14 02:18:59 +00002783 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002784 }
2785 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2786 break;
2787 }
2788 break;
2789 }
2790 case IntegerPixel:
2791 {
2792 register const unsigned int
2793 *p;
2794
2795 p=(const unsigned int *) pixels;
2796 if (LocaleCompare(map,"BGR") == 0)
2797 {
2798 for (y=0; y < (ssize_t) rows; y++)
2799 {
2800 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2801 if (q == (Quantum *) NULL)
2802 break;
2803 for (x=0; x < (ssize_t) columns; x++)
2804 {
2805 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2806 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2807 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002808 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002809 }
2810 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2811 break;
2812 }
2813 break;
2814 }
2815 if (LocaleCompare(map,"BGRA") == 0)
2816 {
2817 for (y=0; y < (ssize_t) rows; y++)
2818 {
2819 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2820 if (q == (Quantum *) NULL)
2821 break;
2822 for (x=0; x < (ssize_t) columns; x++)
2823 {
2824 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2825 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2826 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2827 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002828 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002829 }
2830 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2831 break;
2832 }
2833 break;
2834 }
2835 if (LocaleCompare(map,"BGRP") == 0)
2836 {
2837 for (y=0; y < (ssize_t) rows; y++)
2838 {
2839 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2840 if (q == (Quantum *) NULL)
2841 break;
2842 for (x=0; x < (ssize_t) columns; x++)
2843 {
2844 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2845 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2846 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2847 p++;
cristyed231572011-07-14 02:18:59 +00002848 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002849 }
2850 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2851 break;
2852 }
2853 break;
2854 }
2855 if (LocaleCompare(map,"I") == 0)
2856 {
2857 for (y=0; y < (ssize_t) rows; y++)
2858 {
2859 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2860 if (q == (Quantum *) NULL)
2861 break;
2862 for (x=0; x < (ssize_t) columns; x++)
2863 {
2864 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2865 SetPixelGreen(image,GetPixelRed(image,q),q);
2866 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00002867 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002868 }
2869 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2870 break;
2871 }
2872 break;
2873 }
2874 if (LocaleCompare(map,"RGB") == 0)
2875 {
2876 for (y=0; y < (ssize_t) rows; y++)
2877 {
2878 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2879 if (q == (Quantum *) NULL)
2880 break;
2881 for (x=0; x < (ssize_t) columns; x++)
2882 {
2883 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2884 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2885 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002886 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002887 }
2888 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2889 break;
2890 }
2891 break;
2892 }
2893 if (LocaleCompare(map,"RGBA") == 0)
2894 {
2895 for (y=0; y < (ssize_t) rows; y++)
2896 {
2897 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2898 if (q == (Quantum *) NULL)
2899 break;
2900 for (x=0; x < (ssize_t) columns; x++)
2901 {
2902 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2903 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2904 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2905 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002906 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002907 }
2908 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2909 break;
2910 }
2911 break;
2912 }
2913 if (LocaleCompare(map,"RGBP") == 0)
2914 {
2915 for (y=0; y < (ssize_t) rows; y++)
2916 {
2917 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2918 if (q == (Quantum *) NULL)
2919 break;
2920 for (x=0; x < (ssize_t) columns; x++)
2921 {
2922 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2923 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2924 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2925 p++;
cristyed231572011-07-14 02:18:59 +00002926 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002927 }
2928 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2929 break;
2930 }
2931 break;
2932 }
2933 for (y=0; y < (ssize_t) rows; y++)
2934 {
2935 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2936 if (q == (Quantum *) NULL)
2937 break;
2938 for (x=0; x < (ssize_t) columns; x++)
2939 {
2940 for (i=0; i < (ssize_t) length; i++)
2941 {
2942 switch (quantum_map[i])
2943 {
2944 case RedQuantum:
2945 case CyanQuantum:
2946 {
2947 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2948 break;
2949 }
2950 case GreenQuantum:
2951 case MagentaQuantum:
2952 {
2953 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
2954 break;
2955 }
2956 case BlueQuantum:
2957 case YellowQuantum:
2958 {
2959 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
2960 break;
2961 }
2962 case AlphaQuantum:
2963 {
2964 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2965 break;
2966 }
2967 case OpacityQuantum:
2968 {
2969 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2970 break;
2971 }
2972 case BlackQuantum:
2973 {
2974 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
2975 break;
2976 }
2977 case IndexQuantum:
2978 {
2979 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2980 SetPixelGreen(image,GetPixelRed(image,q),q);
2981 SetPixelBlue(image,GetPixelRed(image,q),q);
2982 break;
2983 }
2984 default:
2985 break;
2986 }
2987 p++;
2988 }
cristyed231572011-07-14 02:18:59 +00002989 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002990 }
2991 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2992 break;
2993 }
2994 break;
2995 }
2996 case LongPixel:
2997 {
2998 register const unsigned int
2999 *p;
3000
3001 p=(const unsigned int *) pixels;
3002 if (LocaleCompare(map,"BGR") == 0)
3003 {
3004 for (y=0; y < (ssize_t) rows; y++)
3005 {
3006 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3007 if (q == (Quantum *) NULL)
3008 break;
3009 for (x=0; x < (ssize_t) columns; x++)
3010 {
3011 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3012 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3013 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003014 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003015 }
3016 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3017 break;
3018 }
3019 break;
3020 }
3021 if (LocaleCompare(map,"BGRA") == 0)
3022 {
3023 for (y=0; y < (ssize_t) rows; y++)
3024 {
3025 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3026 if (q == (Quantum *) NULL)
3027 break;
3028 for (x=0; x < (ssize_t) columns; x++)
3029 {
3030 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3031 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3032 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3033 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003034 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003035 }
3036 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3037 break;
3038 }
3039 break;
3040 }
3041 if (LocaleCompare(map,"BGRP") == 0)
3042 {
3043 for (y=0; y < (ssize_t) rows; y++)
3044 {
3045 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3046 if (q == (Quantum *) NULL)
3047 break;
3048 for (x=0; x < (ssize_t) columns; x++)
3049 {
3050 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3051 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3052 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3053 p++;
cristyed231572011-07-14 02:18:59 +00003054 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003055 }
3056 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3057 break;
3058 }
3059 break;
3060 }
3061 if (LocaleCompare(map,"I") == 0)
3062 {
3063 for (y=0; y < (ssize_t) rows; y++)
3064 {
3065 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3066 if (q == (Quantum *) NULL)
3067 break;
3068 for (x=0; x < (ssize_t) columns; x++)
3069 {
3070 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3071 SetPixelGreen(image,GetPixelRed(image,q),q);
3072 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00003073 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003074 }
3075 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3076 break;
3077 }
3078 break;
3079 }
3080 if (LocaleCompare(map,"RGB") == 0)
3081 {
3082 for (y=0; y < (ssize_t) rows; y++)
3083 {
3084 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3085 if (q == (Quantum *) NULL)
3086 break;
3087 for (x=0; x < (ssize_t) columns; x++)
3088 {
3089 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3090 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3091 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003092 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003093 }
3094 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3095 break;
3096 }
3097 break;
3098 }
3099 if (LocaleCompare(map,"RGBA") == 0)
3100 {
3101 for (y=0; y < (ssize_t) rows; y++)
3102 {
3103 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3104 if (q == (Quantum *) NULL)
3105 break;
3106 for (x=0; x < (ssize_t) columns; x++)
3107 {
3108 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3109 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3110 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3111 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003112 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003113 }
3114 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3115 break;
3116 }
3117 break;
3118 }
3119 if (LocaleCompare(map,"RGBP") == 0)
3120 {
3121 for (y=0; y < (ssize_t) rows; y++)
3122 {
3123 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3124 if (q == (Quantum *) NULL)
3125 break;
3126 for (x=0; x < (ssize_t) columns; x++)
3127 {
3128 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3129 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3130 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3131 p++;
cristyed231572011-07-14 02:18:59 +00003132 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003133 }
3134 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3135 break;
3136 }
3137 break;
3138 }
3139 for (y=0; y < (ssize_t) rows; y++)
3140 {
3141 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3142 if (q == (Quantum *) NULL)
3143 break;
3144 for (x=0; x < (ssize_t) columns; x++)
3145 {
3146 for (i=0; i < (ssize_t) length; i++)
3147 {
3148 switch (quantum_map[i])
3149 {
3150 case RedQuantum:
3151 case CyanQuantum:
3152 {
3153 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3154 break;
3155 }
3156 case GreenQuantum:
3157 case MagentaQuantum:
3158 {
3159 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3160 break;
3161 }
3162 case BlueQuantum:
3163 case YellowQuantum:
3164 {
3165 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3166 break;
3167 }
3168 case AlphaQuantum:
3169 {
3170 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3171 break;
3172 }
3173 case OpacityQuantum:
3174 {
3175 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3176 break;
3177 }
3178 case BlackQuantum:
3179 {
3180 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3181 break;
3182 }
3183 case IndexQuantum:
3184 {
3185 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3186 SetPixelGreen(image,GetPixelRed(image,q),q);
3187 SetPixelBlue(image,GetPixelRed(image,q),q);
3188 break;
3189 }
3190 default:
3191 break;
3192 }
3193 p++;
3194 }
cristyed231572011-07-14 02:18:59 +00003195 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003196 }
3197 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3198 break;
3199 }
3200 break;
3201 }
3202 case QuantumPixel:
3203 {
3204 register const Quantum
3205 *p;
3206
3207 p=(const Quantum *) pixels;
3208 if (LocaleCompare(map,"BGR") == 0)
3209 {
3210 for (y=0; y < (ssize_t) rows; y++)
3211 {
3212 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3213 if (q == (Quantum *) NULL)
3214 break;
3215 for (x=0; x < (ssize_t) columns; x++)
3216 {
3217 SetPixelBlue(image,*p++,q);
3218 SetPixelGreen(image,*p++,q);
3219 SetPixelRed(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003220 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003221 }
3222 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3223 break;
3224 }
3225 break;
3226 }
3227 if (LocaleCompare(map,"BGRA") == 0)
3228 {
3229 for (y=0; y < (ssize_t) rows; y++)
3230 {
3231 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3232 if (q == (Quantum *) NULL)
3233 break;
3234 for (x=0; x < (ssize_t) columns; x++)
3235 {
3236 SetPixelBlue(image,*p++,q);
3237 SetPixelGreen(image,*p++,q);
3238 SetPixelRed(image,*p++,q);
3239 SetPixelAlpha(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003240 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003241 }
3242 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3243 break;
3244 }
3245 break;
3246 }
3247 if (LocaleCompare(map,"BGRP") == 0)
3248 {
3249 for (y=0; y < (ssize_t) rows; y++)
3250 {
3251 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3252 if (q == (Quantum *) NULL)
3253 break;
3254 for (x=0; x < (ssize_t) columns; x++)
3255 {
3256 SetPixelBlue(image,*p++,q);
3257 SetPixelGreen(image,*p++,q);
3258 SetPixelRed(image,*p++,q);
3259 p++;
cristyed231572011-07-14 02:18:59 +00003260 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003261 }
3262 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3263 break;
3264 }
3265 break;
3266 }
3267 if (LocaleCompare(map,"I") == 0)
3268 {
3269 for (y=0; y < (ssize_t) rows; y++)
3270 {
3271 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3272 if (q == (Quantum *) NULL)
3273 break;
3274 for (x=0; x < (ssize_t) columns; x++)
3275 {
3276 SetPixelRed(image,*p++,q);
3277 SetPixelGreen(image,GetPixelRed(image,q),q);
3278 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00003279 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003280 }
3281 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3282 break;
3283 }
3284 break;
3285 }
3286 if (LocaleCompare(map,"RGB") == 0)
3287 {
3288 for (y=0; y < (ssize_t) rows; y++)
3289 {
3290 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3291 if (q == (Quantum *) NULL)
3292 break;
3293 for (x=0; x < (ssize_t) columns; x++)
3294 {
3295 SetPixelRed(image,*p++,q);
3296 SetPixelGreen(image,*p++,q);
3297 SetPixelBlue(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003298 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003299 }
3300 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3301 break;
3302 }
3303 break;
3304 }
3305 if (LocaleCompare(map,"RGBA") == 0)
3306 {
3307 for (y=0; y < (ssize_t) rows; y++)
3308 {
3309 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3310 if (q == (Quantum *) NULL)
3311 break;
3312 for (x=0; x < (ssize_t) columns; x++)
3313 {
3314 SetPixelRed(image,*p++,q);
3315 SetPixelGreen(image,*p++,q);
3316 SetPixelBlue(image,*p++,q);
3317 SetPixelAlpha(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003318 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003319 }
3320 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3321 break;
3322 }
3323 break;
3324 }
3325 if (LocaleCompare(map,"RGBP") == 0)
3326 {
3327 for (y=0; y < (ssize_t) rows; y++)
3328 {
3329 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3330 if (q == (Quantum *) NULL)
3331 break;
3332 for (x=0; x < (ssize_t) columns; x++)
3333 {
3334 SetPixelRed(image,*p++,q);
3335 SetPixelGreen(image,*p++,q);
3336 SetPixelBlue(image,*p++,q);
3337 p++;
cristyed231572011-07-14 02:18:59 +00003338 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003339 }
3340 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3341 break;
3342 }
3343 break;
3344 }
3345 for (y=0; y < (ssize_t) rows; y++)
3346 {
3347 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3348 if (q == (Quantum *) NULL)
3349 break;
3350 for (x=0; x < (ssize_t) columns; x++)
3351 {
3352 for (i=0; i < (ssize_t) length; i++)
3353 {
3354 switch (quantum_map[i])
3355 {
3356 case RedQuantum:
3357 case CyanQuantum:
3358 {
3359 SetPixelRed(image,*p,q);
3360 break;
3361 }
3362 case GreenQuantum:
3363 case MagentaQuantum:
3364 {
3365 SetPixelGreen(image,*p,q);
3366 break;
3367 }
3368 case BlueQuantum:
3369 case YellowQuantum:
3370 {
3371 SetPixelBlue(image,*p,q);
3372 break;
3373 }
3374 case AlphaQuantum:
3375 {
3376 SetPixelAlpha(image,*p,q);
3377 break;
3378 }
3379 case OpacityQuantum:
3380 {
3381 SetPixelAlpha(image,*p,q);
3382 break;
3383 }
3384 case BlackQuantum:
3385 {
3386 SetPixelBlack(image,*p,q);
3387 break;
3388 }
3389 case IndexQuantum:
3390 {
3391 SetPixelRed(image,*p,q);
3392 SetPixelGreen(image,GetPixelRed(image,q),q);
3393 SetPixelBlue(image,GetPixelRed(image,q),q);
3394 break;
3395 }
3396 default:
3397 break;
3398 }
3399 p++;
3400 }
cristyed231572011-07-14 02:18:59 +00003401 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003402 }
3403 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3404 break;
3405 }
3406 break;
3407 }
3408 case ShortPixel:
3409 {
3410 register const unsigned short
3411 *p;
3412
3413 p=(const unsigned short *) pixels;
3414 if (LocaleCompare(map,"BGR") == 0)
3415 {
3416 for (y=0; y < (ssize_t) rows; y++)
3417 {
3418 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3419 if (q == (Quantum *) NULL)
3420 break;
3421 for (x=0; x < (ssize_t) columns; x++)
3422 {
3423 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3424 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3425 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003426 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003427 }
3428 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3429 break;
3430 }
3431 break;
3432 }
3433 if (LocaleCompare(map,"BGRA") == 0)
3434 {
3435 for (y=0; y < (ssize_t) rows; y++)
3436 {
3437 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3438 if (q == (Quantum *) NULL)
3439 break;
3440 for (x=0; x < (ssize_t) columns; x++)
3441 {
3442 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3443 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3444 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3445 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003446 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003447 }
3448 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3449 break;
3450 }
3451 break;
3452 }
3453 if (LocaleCompare(map,"BGRP") == 0)
3454 {
3455 for (y=0; y < (ssize_t) rows; y++)
3456 {
3457 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3458 if (q == (Quantum *) NULL)
3459 break;
3460 for (x=0; x < (ssize_t) columns; x++)
3461 {
3462 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3463 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3464 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3465 p++;
cristyed231572011-07-14 02:18:59 +00003466 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003467 }
3468 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3469 break;
3470 }
3471 break;
3472 }
3473 if (LocaleCompare(map,"I") == 0)
3474 {
3475 for (y=0; y < (ssize_t) rows; y++)
3476 {
3477 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3478 if (q == (Quantum *) NULL)
3479 break;
3480 for (x=0; x < (ssize_t) columns; x++)
3481 {
3482 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3483 SetPixelGreen(image,GetPixelRed(image,q),q);
3484 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00003485 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003486 }
3487 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3488 break;
3489 }
3490 break;
3491 }
3492 if (LocaleCompare(map,"RGB") == 0)
3493 {
3494 for (y=0; y < (ssize_t) rows; y++)
3495 {
3496 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3497 if (q == (Quantum *) NULL)
3498 break;
3499 for (x=0; x < (ssize_t) columns; x++)
3500 {
3501 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3502 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3503 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003504 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003505 }
3506 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3507 break;
3508 }
3509 break;
3510 }
3511 if (LocaleCompare(map,"RGBA") == 0)
3512 {
3513 for (y=0; y < (ssize_t) rows; y++)
3514 {
3515 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3516 if (q == (Quantum *) NULL)
3517 break;
3518 for (x=0; x < (ssize_t) columns; x++)
3519 {
3520 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3521 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3522 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3523 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003524 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003525 }
3526 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3527 break;
3528 }
3529 break;
3530 }
3531 if (LocaleCompare(map,"RGBP") == 0)
3532 {
3533 for (y=0; y < (ssize_t) rows; y++)
3534 {
3535 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3536 if (q == (Quantum *) NULL)
3537 break;
3538 for (x=0; x < (ssize_t) columns; x++)
3539 {
3540 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3541 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3542 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3543 p++;
cristyed231572011-07-14 02:18:59 +00003544 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003545 }
3546 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3547 break;
3548 }
3549 break;
3550 }
3551 for (y=0; y < (ssize_t) rows; y++)
3552 {
3553 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3554 if (q == (Quantum *) NULL)
3555 break;
3556 for (x=0; x < (ssize_t) columns; x++)
3557 {
3558 for (i=0; i < (ssize_t) length; i++)
3559 {
3560 switch (quantum_map[i])
3561 {
3562 case RedQuantum:
3563 case CyanQuantum:
3564 {
3565 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3566 break;
3567 }
3568 case GreenQuantum:
3569 case MagentaQuantum:
3570 {
3571 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3572 break;
3573 }
3574 case BlueQuantum:
3575 case YellowQuantum:
3576 {
3577 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3578 break;
3579 }
3580 case AlphaQuantum:
3581 {
3582 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3583 break;
3584 }
3585 case OpacityQuantum:
3586 {
3587 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3588 break;
3589 }
3590 case BlackQuantum:
3591 {
3592 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3593 break;
3594 }
3595 case IndexQuantum:
3596 {
3597 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3598 SetPixelGreen(image,GetPixelRed(image,q),q);
3599 SetPixelBlue(image,GetPixelRed(image,q),q);
3600 break;
3601 }
3602 default:
3603 break;
3604 }
3605 p++;
3606 }
cristyed231572011-07-14 02:18:59 +00003607 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003608 }
3609 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3610 break;
3611 }
3612 break;
3613 }
3614 default:
3615 {
3616 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
cristyc82a27b2011-10-21 01:07:16 +00003617 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3618 "UnrecognizedPixelMap","`%s'",map);
cristy4c08aed2011-07-01 19:47:50 +00003619 break;
3620 }
3621 }
3622 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3623 return(MagickTrue);
3624}
3625
3626/*
3627%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3628% %
3629% %
3630% %
cristybd5a96c2011-08-21 00:04:26 +00003631+ I n i t i a l i z e P i x e l C h a n n e l M a p %
3632% %
3633% %
3634% %
3635%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3636%
3637% InitializePixelChannelMap() defines the standard pixel component map.
3638%
3639% The format of the InitializePixelChannelMap() method is:
3640%
3641% void InitializePixelChannelMap(Image *image)
3642%
3643% A description of each parameter follows:
3644%
3645% o image: the image.
3646%
3647*/
cristye2a912b2011-12-05 20:02:07 +00003648MagickExport void InitializePixelChannelMap(Image *image)
cristy77c30f52011-10-24 18:56:57 +00003649{
cristye2a912b2011-12-05 20:02:07 +00003650 PixelTrait
3651 trait;
3652
cristy77c30f52011-10-24 18:56:57 +00003653 register ssize_t
3654 i;
3655
3656 size_t
3657 n;
3658
3659 assert(image != (Image *) NULL);
3660 assert(image->signature == MagickSignature);
cristye2a912b2011-12-05 20:02:07 +00003661 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3662 sizeof(*image->channel_map));
3663 trait=UpdatePixelTrait;
3664 if (image->matte != MagickFalse)
cristy61f18ad2011-12-08 21:12:37 +00003665 trait=(PixelTrait) (trait | BlendPixelTrait);
cristy77c30f52011-10-24 18:56:57 +00003666 n=0;
cristye2a912b2011-12-05 20:02:07 +00003667 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3668 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3669 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3670if (0)
cristy77c30f52011-10-24 18:56:57 +00003671 if (image->colorspace == GRAYColorspace)
3672 {
3673 n=0;
cristye2a912b2011-12-05 20:02:07 +00003674 SetPixelChannelMap(image,RedPixelChannel,trait,n);
3675 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3676 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
cristy77c30f52011-10-24 18:56:57 +00003677 }
3678 if (image->colorspace == CMYKColorspace)
cristye2a912b2011-12-05 20:02:07 +00003679 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
cristy77c30f52011-10-24 18:56:57 +00003680 if (image->matte != MagickFalse)
cristye2a912b2011-12-05 20:02:07 +00003681 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3682 if (image->storage_class == PseudoClass)
3683 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3684 assert((n+image->number_meta_channels) < MaxPixelChannels);
3685 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
cristy61f18ad2011-12-08 21:12:37 +00003686 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
cristye2a912b2011-12-05 20:02:07 +00003687 n++);
cristy77c30f52011-10-24 18:56:57 +00003688 image->number_channels=n;
3689 if (image->debug != MagickFalse)
3690 LogPixelChannels(image);
3691 (void) SetPixelChannelMask(image,image->channel_mask);
3692}
cristybd5a96c2011-08-21 00:04:26 +00003693
3694/*
3695%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3696% %
3697% %
3698% %
cristya085a432011-07-30 01:39:32 +00003699% I n t e r p o l a t e P i x e l C h a n n e l %
3700% %
3701% %
3702% %
3703%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3704%
cristy884f6002011-07-31 00:51:45 +00003705% InterpolatePixelChannel() applies a pixel interpolation method between a
3706% floating point coordinate and the pixels surrounding that coordinate. No
3707% pixel area resampling, or scaling of the result is performed.
cristya085a432011-07-30 01:39:32 +00003708%
3709% The format of the InterpolatePixelChannel method is:
3710%
3711% MagickBooleanType InterpolatePixelChannel(const Image *image,
cristy444eda62011-08-10 02:07:46 +00003712% const CacheView *image_view,const PixelChannel channel,
cristy5c4e2582011-09-11 19:21:03 +00003713% const PixelInterpolateMethod method,const double x,const double y,
cristya085a432011-07-30 01:39:32 +00003714% double *pixel,ExceptionInfo *exception)
3715%
3716% A description of each parameter follows:
3717%
3718% o image: the image.
3719%
3720% o image_view: the image view.
3721%
3722% o channel: the pixel channel to interpolate.
3723%
3724% o method: the pixel color interpolation method.
3725%
3726% o x,y: A double representing the current (x,y) position of the pixel.
3727%
3728% o pixel: return the interpolated pixel here.
3729%
3730% o exception: return any errors or warnings in this structure.
3731%
3732*/
cristy94ea1632011-07-30 20:40:25 +00003733
cristy884f6002011-07-31 00:51:45 +00003734static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3735{
3736 if (x > y)
3737 return(x);
3738 return(y);
3739}
3740
3741static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3742{
3743 MagickRealType
3744 alpha,
3745 gamma;
3746
3747 alpha=MagickMax(x+2.0,0.0);
3748 gamma=1.0*alpha*alpha*alpha;
3749 alpha=MagickMax(x+1.0,0.0);
3750 gamma-=4.0*alpha*alpha*alpha;
3751 alpha=MagickMax(x+0.0,0.0);
3752 gamma+=6.0*alpha*alpha*alpha;
3753 alpha=MagickMax(x-1.0,0.0);
3754 gamma-=4.0*alpha*alpha*alpha;
3755 return(gamma/6.0);
3756}
3757
cristy94ea1632011-07-30 20:40:25 +00003758static inline double MeshInterpolate(const PointInfo *delta,const double p,
3759 const double x,const double y)
3760{
3761 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
3762}
3763
cristy884f6002011-07-31 00:51:45 +00003764static inline ssize_t NearestNeighbor(const MagickRealType x)
3765{
3766 if (x >= 0.0)
3767 return((ssize_t) (x+0.5));
3768 return((ssize_t) (x-0.5));
3769}
3770
cristya085a432011-07-30 01:39:32 +00003771MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
3772 const CacheView *image_view,const PixelChannel channel,
cristy5c4e2582011-09-11 19:21:03 +00003773 const PixelInterpolateMethod method,const double x,const double y,
cristya085a432011-07-30 01:39:32 +00003774 double *pixel,ExceptionInfo *exception)
3775{
3776 MagickBooleanType
3777 status;
3778
cristy94ea1632011-07-30 20:40:25 +00003779 MagickRealType
3780 alpha[16],
cristy884f6002011-07-31 00:51:45 +00003781 gamma,
3782 pixels[16];
cristy94ea1632011-07-30 20:40:25 +00003783
3784 PixelTrait
3785 traits;
3786
cristy94ea1632011-07-30 20:40:25 +00003787 register const Quantum
3788 *p;
3789
3790 register ssize_t
3791 i;
3792
cristya085a432011-07-30 01:39:32 +00003793 ssize_t
3794 x_offset,
3795 y_offset;
3796
3797 assert(image != (Image *) NULL);
3798 assert(image != (Image *) NULL);
3799 assert(image->signature == MagickSignature);
3800 assert(image_view != (CacheView *) NULL);
3801 status=MagickTrue;
cristy884f6002011-07-31 00:51:45 +00003802 *pixel=0.0;
cristy94ea1632011-07-30 20:40:25 +00003803 traits=GetPixelChannelMapTraits(image,channel);
cristya085a432011-07-30 01:39:32 +00003804 x_offset=(ssize_t) floor(x);
3805 y_offset=(ssize_t) floor(y);
3806 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
3807 {
cristy884f6002011-07-31 00:51:45 +00003808 case AverageInterpolatePixel:
3809 {
3810 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3811 exception);
3812 if (p == (const Quantum *) NULL)
3813 {
3814 status=MagickFalse;
3815 break;
3816 }
cristy222b19c2011-08-04 01:35:11 +00003817 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00003818 for (i=0; i < 16; i++)
3819 {
3820 alpha[i]=1.0;
3821 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3822 }
3823 else
3824 for (i=0; i < 16; i++)
3825 {
3826 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3827 GetPixelChannels(image));
3828 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3829 }
3830 for (i=0; i < 16; i++)
3831 {
3832 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
3833 *pixel+=gamma*0.0625*pixels[i];
3834 }
3835 break;
3836 }
3837 case BicubicInterpolatePixel:
3838 {
3839 MagickRealType
3840 u[4],
3841 v[4];
3842
3843 PointInfo
3844 delta;
3845
3846 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3847 exception);
3848 if (p == (const Quantum *) NULL)
3849 {
3850 status=MagickFalse;
3851 break;
3852 }
cristy222b19c2011-08-04 01:35:11 +00003853 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00003854 for (i=0; i < 16; i++)
3855 {
3856 alpha[i]=1.0;
3857 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3858 }
3859 else
3860 for (i=0; i < 16; i++)
3861 {
3862 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3863 GetPixelChannels(image));
3864 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3865 }
3866 delta.x=x-x_offset;
3867 delta.y=y-y_offset;
3868 for (i=0; i < 4; i++)
3869 {
3870 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
3871 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
3872 u[2]=pixels[4*i+2]-pixels[4*i+0];
3873 u[3]=pixels[4*i+1];
3874 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
3875 u[2])+u[3];
3876 }
3877 u[0]=(v[3]-v[2])-(v[0]-v[1]);
3878 u[1]=(v[0]-v[1])-u[0];
3879 u[2]=v[2]-v[0];
3880 u[3]=v[1];
3881 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
3882 u[2])+u[3];
3883 break;
3884 }
3885 case BilinearInterpolatePixel:
cristy94ea1632011-07-30 20:40:25 +00003886 default:
cristya085a432011-07-30 01:39:32 +00003887 {
cristy94ea1632011-07-30 20:40:25 +00003888 PointInfo
3889 delta,
cristy884f6002011-07-31 00:51:45 +00003890 epsilon;
3891
3892 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3893 if (p == (const Quantum *) NULL)
3894 {
3895 status=MagickFalse;
3896 break;
3897 }
cristy222b19c2011-08-04 01:35:11 +00003898 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00003899 for (i=0; i < 4; i++)
3900 {
3901 alpha[i]=1.0;
3902 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3903 }
3904 else
3905 for (i=0; i < 4; i++)
3906 {
3907 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3908 GetPixelChannels(image));
3909 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3910 }
3911 delta.x=x-x_offset;
3912 delta.y=y-y_offset;
3913 epsilon.x=1.0-delta.x;
3914 epsilon.y=1.0-delta.y;
3915 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
3916 (epsilon.x*alpha[2]+delta.x*alpha[3])));
3917 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3918 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
3919 (epsilon.x*pixels[2]+delta.x*pixels[3]));
3920 break;
3921 }
3922 case FilterInterpolatePixel:
3923 {
3924 CacheView
3925 *filter_view;
3926
3927 Image
3928 *excerpt_image,
3929 *filter_image;
3930
3931 RectangleInfo
3932 geometry;
3933
3934 geometry.width=4L;
3935 geometry.height=4L;
3936 geometry.x=x_offset-1;
3937 geometry.y=y_offset-1;
3938 excerpt_image=ExcerptImage(image,&geometry,exception);
3939 if (excerpt_image == (Image *) NULL)
3940 {
3941 status=MagickFalse;
3942 break;
3943 }
3944 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
3945 exception);
3946 excerpt_image=DestroyImage(excerpt_image);
3947 if (filter_image == (Image *) NULL)
3948 break;
3949 filter_view=AcquireCacheView(filter_image);
3950 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
3951 if (p == (const Quantum *) NULL)
3952 status=MagickFalse;
3953 else
cristy0beccfa2011-09-25 20:47:53 +00003954 *pixel=(double) GetPixelChannel(image,channel,p);
cristy884f6002011-07-31 00:51:45 +00003955 filter_view=DestroyCacheView(filter_view);
3956 filter_image=DestroyImage(filter_image);
3957 break;
3958 }
3959 case IntegerInterpolatePixel:
3960 {
3961 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
3962 if (p == (const Quantum *) NULL)
3963 {
3964 status=MagickFalse;
3965 break;
3966 }
cristy0beccfa2011-09-25 20:47:53 +00003967 *pixel=(double) GetPixelChannel(image,channel,p);
cristy884f6002011-07-31 00:51:45 +00003968 break;
3969 }
3970 case NearestNeighborInterpolatePixel:
3971 {
3972 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
3973 NearestNeighbor(y),1,1,exception);
3974 if (p == (const Quantum *) NULL)
3975 {
3976 status=MagickFalse;
3977 break;
3978 }
cristy0beccfa2011-09-25 20:47:53 +00003979 *pixel=(double) GetPixelChannel(image,channel,p);
cristy884f6002011-07-31 00:51:45 +00003980 break;
3981 }
3982 case MeshInterpolatePixel:
3983 {
3984 PointInfo
3985 delta,
cristy94ea1632011-07-30 20:40:25 +00003986 luminance;
3987
3988 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3989 if (p == (const Quantum *) NULL)
3990 {
3991 status=MagickFalse;
3992 break;
3993 }
cristy222b19c2011-08-04 01:35:11 +00003994 if ((traits & BlendPixelTrait) == 0)
cristy94ea1632011-07-30 20:40:25 +00003995 for (i=0; i < 4; i++)
3996 {
3997 alpha[i]=1.0;
cristy884f6002011-07-31 00:51:45 +00003998 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
cristy94ea1632011-07-30 20:40:25 +00003999 }
4000 else
4001 for (i=0; i < 4; i++)
4002 {
4003 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4004 GetPixelChannels(image));
4005 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4006 }
cristy884f6002011-07-31 00:51:45 +00004007 delta.x=x-x_offset;
4008 delta.y=y-y_offset;
4009 luminance.x=GetPixelLuminance(image,p)-(double)
4010 GetPixelLuminance(image,p+3*GetPixelChannels(image));
cristy28474bf2011-09-11 23:32:52 +00004011 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
cristy884f6002011-07-31 00:51:45 +00004012 GetPixelLuminance(image,p+2*GetPixelChannels(image));
cristy94ea1632011-07-30 20:40:25 +00004013 if (fabs(luminance.x) < fabs(luminance.y))
4014 {
4015 /*
4016 Diagonal 0-3 NW-SE.
4017 */
4018 if (delta.x <= delta.y)
4019 {
4020 /*
4021 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4022 */
4023 delta.y=1.0-delta.y;
4024 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4025 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4026 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4027 pixels[0]);
4028 }
4029 else
4030 {
4031 /*
4032 Top-right triangle (pixel: 1, diagonal: 0-3).
4033 */
4034 delta.x=1.0-delta.x;
4035 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4036 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4037 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4038 pixels[3]);
4039 }
4040 }
4041 else
4042 {
4043 /*
4044 Diagonal 1-2 NE-SW.
4045 */
4046 if (delta.x <= (1.0-delta.y))
4047 {
4048 /*
4049 Top-left triangle (pixel: 0, diagonal: 1-2).
4050 */
4051 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4052 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4053 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4054 pixels[2]);
4055 }
4056 else
4057 {
4058 /*
4059 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4060 */
4061 delta.x=1.0-delta.x;
4062 delta.y=1.0-delta.y;
4063 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4064 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4065 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4066 pixels[1]);
4067 }
4068 }
cristya085a432011-07-30 01:39:32 +00004069 break;
4070 }
cristy884f6002011-07-31 00:51:45 +00004071 case SplineInterpolatePixel:
4072 {
4073 MagickRealType
4074 dx,
4075 dy;
4076
4077 PointInfo
4078 delta;
4079
4080 ssize_t
4081 j,
4082 n;
4083
4084 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4085 exception);
4086 if (p == (const Quantum *) NULL)
4087 {
4088 status=MagickFalse;
4089 break;
4090 }
cristy222b19c2011-08-04 01:35:11 +00004091 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00004092 for (i=0; i < 16; i++)
4093 {
4094 alpha[i]=1.0;
4095 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4096 }
4097 else
4098 for (i=0; i < 16; i++)
4099 {
4100 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4101 GetPixelChannels(image));
4102 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4103 }
4104 delta.x=x-x_offset;
4105 delta.y=y-y_offset;
4106 n=0;
4107 for (i=(-1); i < 3L; i++)
4108 {
4109 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4110 for (j=(-1); j < 3L; j++)
4111 {
4112 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4113 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4114 *pixel+=gamma*dx*dy*pixels[n];
4115 n++;
4116 }
4117 }
4118 break;
4119 }
cristya085a432011-07-30 01:39:32 +00004120 }
4121 return(status);
4122}
4123
4124/*
4125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4126% %
4127% %
4128% %
cristy5c4e2582011-09-11 19:21:03 +00004129% I n t e r p o l a t e P i x e l C h a n n e l s %
4130% %
4131% %
4132% %
4133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4134%
4135% InterpolatePixelChannels() applies a pixel interpolation method between a
4136% floating point coordinate and the pixels surrounding that coordinate. No
4137% pixel area resampling, or scaling of the result is performed.
4138%
4139% The format of the InterpolatePixelChannels method is:
4140%
4141% MagickBooleanType InterpolatePixelChannels(const Image *source,
4142% const CacheView *source_view,const Image *destination,
4143% const PixelInterpolateMethod method,const double x,const double y,
4144% Quantum *pixel,ExceptionInfo *exception)
4145%
4146% A description of each parameter follows:
4147%
4148% o source: the source.
4149%
4150% o source_view: the source view.
4151%
4152% o destination: the destination image.
4153%
4154% o method: the pixel color interpolation method.
4155%
4156% o x,y: A double representing the current (x,y) position of the pixel.
4157%
4158% o pixel: return the interpolated pixel here.
4159%
4160% o exception: return any errors or warnings in this structure.
4161%
4162*/
4163MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4164 const CacheView *source_view,const Image *destination,
4165 const PixelInterpolateMethod method,const double x,const double y,
4166 Quantum *pixel,ExceptionInfo *exception)
4167{
4168 MagickBooleanType
4169 status;
4170
4171 MagickRealType
4172 alpha[16],
4173 gamma,
4174 pixels[16];
4175
4176 PixelChannel
4177 channel;
4178
4179 PixelTrait
4180 destination_traits,
4181 traits;
4182
4183 register const Quantum
4184 *p;
4185
4186 register ssize_t
4187 i;
4188
4189 ssize_t
4190 x_offset,
4191 y_offset;
4192
4193 assert(source != (Image *) NULL);
4194 assert(source != (Image *) NULL);
4195 assert(source->signature == MagickSignature);
4196 assert(source_view != (CacheView *) NULL);
4197 status=MagickTrue;
4198 x_offset=(ssize_t) floor(x);
4199 y_offset=(ssize_t) floor(y);
4200 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4201 {
4202 case AverageInterpolatePixel:
4203 {
4204 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4205 exception);
4206 if (p == (const Quantum *) NULL)
4207 {
4208 status=MagickFalse;
4209 break;
4210 }
4211 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4212 {
4213 double
4214 sum;
4215
4216 register ssize_t
4217 j;
4218
cristye2a912b2011-12-05 20:02:07 +00004219 traits=GetPixelChannelMapTraits(source,i);
4220 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004221 destination_traits=GetPixelChannelMapTraits(destination,channel);
4222 if ((traits == UndefinedPixelTrait) ||
4223 (destination_traits == UndefinedPixelTrait))
4224 continue;
4225 for (j=0; j < 16; j++)
4226 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4227 if ((traits & BlendPixelTrait) == 0)
4228 {
4229 for (j=0; j < 16; j++)
4230 pixel[channel]+=0.0625*pixels[j];
4231 continue;
4232 }
4233 sum=0.0;
4234 for (j=0; j < 16; j++)
4235 {
4236 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4237 GetPixelChannels(source));
4238 pixels[j]*=alpha[j];
4239 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4240 sum+=gamma*0.0625*pixels[j];
4241 }
4242 pixel[channel]=ClampToQuantum(sum);
4243 }
4244 break;
4245 }
4246 case BicubicInterpolatePixel:
4247 {
4248 MagickRealType
4249 u[4],
4250 v[4];
4251
4252 PointInfo
4253 delta;
4254
4255 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4256 exception);
4257 if (p == (const Quantum *) NULL)
4258 {
4259 status=MagickFalse;
4260 break;
4261 }
4262 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4263 {
4264 register ssize_t
4265 j;
4266
cristye2a912b2011-12-05 20:02:07 +00004267 traits=GetPixelChannelMapTraits(source,i);
4268 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004269 destination_traits=GetPixelChannelMapTraits(destination,channel);
4270 if ((traits == UndefinedPixelTrait) ||
4271 (destination_traits == UndefinedPixelTrait))
4272 continue;
4273 if ((traits & BlendPixelTrait) == 0)
4274 for (j=0; j < 16; j++)
4275 {
4276 alpha[j]=1.0;
4277 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4278 }
4279 else
4280 for (j=0; j < 16; j++)
4281 {
4282 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4283 GetPixelChannels(source));
4284 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4285 }
4286 delta.x=x-x_offset;
4287 delta.y=y-y_offset;
4288 for (j=0; j < 4; j++)
4289 {
4290 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4291 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4292 u[2]=pixels[4*j+2]-pixels[4*j+0];
4293 u[3]=pixels[4*j+1];
4294 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4295 u[2])+u[3];
4296 }
4297 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4298 u[1]=(v[0]-v[1])-u[0];
4299 u[2]=v[2]-v[0];
4300 u[3]=v[1];
4301 pixel[channel]=ClampToQuantum((delta.y*delta.y*delta.y*u[0])+(delta.y*
4302 delta.y*u[1])+(delta.y*u[2])+u[3]);
4303 }
4304 break;
4305 }
4306 case BilinearInterpolatePixel:
4307 default:
4308 {
4309 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4310 if (p == (const Quantum *) NULL)
4311 {
4312 status=MagickFalse;
4313 break;
4314 }
4315 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4316 {
4317 PointInfo
4318 delta,
4319 epsilon;
4320
cristye2a912b2011-12-05 20:02:07 +00004321 traits=GetPixelChannelMapTraits(source,i);
4322 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004323 destination_traits=GetPixelChannelMapTraits(destination,channel);
4324 if ((traits == UndefinedPixelTrait) ||
4325 (destination_traits == UndefinedPixelTrait))
4326 continue;
4327 delta.x=x-x_offset;
4328 delta.y=y-y_offset;
4329 epsilon.x=1.0-delta.x;
4330 epsilon.y=1.0-delta.y;
cristy28474bf2011-09-11 23:32:52 +00004331 pixels[0]=(MagickRealType) p[i];
4332 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
cristy5c4e2582011-09-11 19:21:03 +00004333 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4334 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4335 if ((traits & BlendPixelTrait) == 0)
4336 {
4337 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4338 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4339 pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
4340 delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*
4341 pixels[3])));
4342 continue;
4343 }
cristy28474bf2011-09-11 23:32:52 +00004344 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4345 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
cristy5c4e2582011-09-11 19:21:03 +00004346 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4347 GetPixelChannels(source));
4348 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4349 GetPixelChannels(source));
4350 pixels[0]*=alpha[0];
4351 pixels[1]*=alpha[1];
4352 pixels[2]*=alpha[2];
4353 pixels[3]*=alpha[3];
4354 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4355 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4356 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4357 pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
4358 delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*pixels[3])));
4359 }
4360 break;
4361 }
4362 case FilterInterpolatePixel:
4363 {
4364 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4365 {
4366 CacheView
4367 *filter_view;
4368
4369 Image
4370 *excerpt_source,
4371 *filter_source;
4372
4373 RectangleInfo
4374 geometry;
4375
cristye2a912b2011-12-05 20:02:07 +00004376 traits=GetPixelChannelMapTraits(source,i);
4377 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004378 destination_traits=GetPixelChannelMapTraits(destination,channel);
4379 if ((traits == UndefinedPixelTrait) ||
4380 (destination_traits == UndefinedPixelTrait))
4381 continue;
4382 geometry.width=4L;
4383 geometry.height=4L;
4384 geometry.x=x_offset-1;
4385 geometry.y=y_offset-1;
4386 excerpt_source=ExcerptImage(source,&geometry,exception);
4387 if (excerpt_source == (Image *) NULL)
4388 {
4389 status=MagickFalse;
4390 continue;
4391 }
4392 filter_source=ResizeImage(excerpt_source,1,1,source->filter,
4393 source->blur,exception);
4394 excerpt_source=DestroyImage(excerpt_source);
4395 if (filter_source == (Image *) NULL)
4396 continue;
4397 filter_view=AcquireCacheView(filter_source);
4398 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4399 if (p == (const Quantum *) NULL)
4400 status=MagickFalse;
4401 else
4402 pixel[channel]=p[i];
4403 filter_view=DestroyCacheView(filter_view);
4404 filter_source=DestroyImage(filter_source);
4405 }
4406 break;
4407 }
4408 case IntegerInterpolatePixel:
4409 {
4410 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4411 if (p == (const Quantum *) NULL)
4412 {
4413 status=MagickFalse;
4414 break;
4415 }
4416 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4417 {
cristye2a912b2011-12-05 20:02:07 +00004418 traits=GetPixelChannelMapTraits(source,i);
4419 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004420 destination_traits=GetPixelChannelMapTraits(destination,channel);
4421 if ((traits == UndefinedPixelTrait) ||
4422 (destination_traits == UndefinedPixelTrait))
4423 continue;
4424 pixel[channel]=p[i];
4425 }
4426 break;
4427 }
4428 case NearestNeighborInterpolatePixel:
4429 {
4430 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4431 NearestNeighbor(y),1,1,exception);
4432 if (p == (const Quantum *) NULL)
4433 {
4434 status=MagickFalse;
4435 break;
4436 }
4437 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4438 {
cristye2a912b2011-12-05 20:02:07 +00004439 traits=GetPixelChannelMapTraits(source,i);
4440 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004441 destination_traits=GetPixelChannelMapTraits(destination,channel);
4442 if ((traits == UndefinedPixelTrait) ||
4443 (destination_traits == UndefinedPixelTrait))
4444 continue;
4445 pixel[channel]=p[i];
4446 }
4447 break;
4448 }
4449 case MeshInterpolatePixel:
4450 {
4451 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4452 if (p == (const Quantum *) NULL)
4453 {
4454 status=MagickFalse;
4455 break;
4456 }
4457 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4458 {
4459 PointInfo
4460 delta,
4461 luminance;
4462
cristye2a912b2011-12-05 20:02:07 +00004463 traits=GetPixelChannelMapTraits(source,i);
4464 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004465 destination_traits=GetPixelChannelMapTraits(destination,channel);
4466 if ((traits == UndefinedPixelTrait) ||
4467 (destination_traits == UndefinedPixelTrait))
4468 continue;
cristy28474bf2011-09-11 23:32:52 +00004469 pixels[0]=(MagickRealType) p[i];
4470 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
cristy5c4e2582011-09-11 19:21:03 +00004471 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4472 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4473 if ((traits & BlendPixelTrait) == 0)
4474 {
4475 alpha[0]=1.0;
4476 alpha[1]=1.0;
4477 alpha[2]=1.0;
4478 alpha[3]=1.0;
4479 }
4480 else
4481 {
cristy28474bf2011-09-11 23:32:52 +00004482 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4483 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
cristy5c4e2582011-09-11 19:21:03 +00004484 GetPixelChannels(source));
4485 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4486 GetPixelChannels(source));
4487 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4488 GetPixelChannels(source));
4489 }
4490 delta.x=x-x_offset;
4491 delta.y=y-y_offset;
4492 luminance.x=GetPixelLuminance(source,p)-(double)
4493 GetPixelLuminance(source,p+3*GetPixelChannels(source));
cristy28474bf2011-09-11 23:32:52 +00004494 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
cristy5c4e2582011-09-11 19:21:03 +00004495 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4496 if (fabs(luminance.x) < fabs(luminance.y))
4497 {
4498 /*
4499 Diagonal 0-3 NW-SE.
4500 */
4501 if (delta.x <= delta.y)
4502 {
4503 /*
4504 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4505 */
4506 delta.y=1.0-delta.y;
4507 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4508 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4509 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4510 pixels[2],pixels[3],pixels[0]));
4511 }
4512 else
4513 {
4514 /*
4515 Top-right triangle (pixel: 1, diagonal: 0-3).
4516 */
4517 delta.x=1.0-delta.x;
4518 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4519 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4520 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4521 pixels[1],pixels[0],pixels[3]));
4522 }
4523 }
4524 else
4525 {
4526 /*
4527 Diagonal 1-2 NE-SW.
4528 */
4529 if (delta.x <= (1.0-delta.y))
4530 {
4531 /*
4532 Top-left triangle (pixel: 0, diagonal: 1-2).
4533 */
4534 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4535 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4536 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4537 pixels[0],pixels[1],pixels[2]));
4538 }
4539 else
4540 {
4541 /*
4542 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4543 */
4544 delta.x=1.0-delta.x;
4545 delta.y=1.0-delta.y;
4546 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4547 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4548 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4549 pixels[3],pixels[2],pixels[1]));
4550 }
4551 }
4552 }
4553 break;
4554 }
4555 case SplineInterpolatePixel:
4556 {
4557 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4558 exception);
4559 if (p == (const Quantum *) NULL)
4560 {
4561 status=MagickFalse;
4562 break;
4563 }
4564 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4565 {
4566 double
4567 sum;
4568
4569 MagickRealType
4570 dx,
4571 dy;
4572
4573 PointInfo
4574 delta;
4575
4576 register ssize_t
4577 j;
4578
4579 ssize_t
4580 k,
4581 n;
4582
cristye2a912b2011-12-05 20:02:07 +00004583 traits=GetPixelChannelMapTraits(source,i);
4584 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004585 destination_traits=GetPixelChannelMapTraits(destination,channel);
4586 if ((traits == UndefinedPixelTrait) ||
4587 (destination_traits == UndefinedPixelTrait))
4588 continue;
4589 if ((traits & BlendPixelTrait) == 0)
4590 for (j=0; j < 16; j++)
4591 {
4592 alpha[j]=1.0;
4593 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4594 }
4595 else
4596 for (j=0; j < 16; j++)
4597 {
4598 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4599 GetPixelChannels(source));
4600 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4601 }
4602 delta.x=x-x_offset;
4603 delta.y=y-y_offset;
4604 sum=0.0;
4605 n=0;
4606 for (j=(-1); j < 3L; j++)
4607 {
4608 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4609 for (k=(-1); k < 3L; k++)
4610 {
4611 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4612 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4613 alpha[n]);
4614 sum+=gamma*dx*dy*pixels[n];
4615 n++;
4616 }
4617 }
4618 pixel[channel]=ClampToQuantum(sum);
4619 }
4620 break;
4621 }
4622 }
4623 return(status);
4624}
4625
4626/*
4627%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4628% %
4629% %
4630% %
cristy9075cdb2011-07-30 01:06:23 +00004631% I n t e r p o l a t e P i x e l I n f o %
cristy4c08aed2011-07-01 19:47:50 +00004632% %
4633% %
4634% %
4635%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4636%
cristy884f6002011-07-31 00:51:45 +00004637% InterpolatePixelInfo() applies a pixel interpolation method between a
4638% floating point coordinate and the pixels surrounding that coordinate. No
4639% pixel area resampling, or scaling of the result is performed.
cristy4c08aed2011-07-01 19:47:50 +00004640%
4641% The format of the InterpolatePixelInfo method is:
4642%
4643% MagickBooleanType InterpolatePixelInfo(const Image *image,
cristy5c4e2582011-09-11 19:21:03 +00004644% const CacheView *image_view,const PixelInterpolateMethod method,
cristy4c08aed2011-07-01 19:47:50 +00004645% const double x,const double y,PixelInfo *pixel,
4646% ExceptionInfo *exception)
4647%
4648% A description of each parameter follows:
4649%
4650% o image: the image.
4651%
4652% o image_view: the image view.
4653%
4654% o method: the pixel color interpolation method.
4655%
4656% o x,y: A double representing the current (x,y) position of the pixel.
4657%
4658% o pixel: return the interpolated pixel here.
4659%
4660% o exception: return any errors or warnings in this structure.
4661%
4662*/
4663
4664static inline void AlphaBlendPixelInfo(const Image *image,
4665 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4666{
4667 if (image->matte == MagickFalse)
4668 {
4669 *alpha=1.0;
4670 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4671 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4672 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4673 pixel_info->black=0.0;
4674 if (image->colorspace == CMYKColorspace)
4675 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4676 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4677 return;
4678 }
4679 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4680 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4681 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4682 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4683 pixel_info->black=0.0;
4684 if (image->colorspace == CMYKColorspace)
4685 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4686 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4687}
4688
4689static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4690 PixelInfo *pixel)
4691{
4692 MagickRealType
4693 dx2,
4694 p,
4695 q,
4696 r,
4697 s;
4698
4699 dx2=dx*dx;
4700 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4701 q=(pixels[0].red-pixels[1].red)-p;
4702 r=pixels[2].red-pixels[0].red;
4703 s=pixels[1].red;
4704 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4705 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4706 q=(pixels[0].green-pixels[1].green)-p;
4707 r=pixels[2].green-pixels[0].green;
4708 s=pixels[1].green;
4709 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4710 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4711 q=(pixels[0].blue-pixels[1].blue)-p;
4712 r=pixels[2].blue-pixels[0].blue;
4713 s=pixels[1].blue;
4714 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4715 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4716 q=(pixels[0].alpha-pixels[1].alpha)-p;
4717 r=pixels[2].alpha-pixels[0].alpha;
4718 s=pixels[1].alpha;
4719 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4720 if (pixel->colorspace == CMYKColorspace)
4721 {
4722 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4723 q=(pixels[0].black-pixels[1].black)-p;
4724 r=pixels[2].black-pixels[0].black;
4725 s=pixels[1].black;
4726 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4727 }
4728}
4729
cristy4c08aed2011-07-01 19:47:50 +00004730MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
cristy5c4e2582011-09-11 19:21:03 +00004731 const CacheView *image_view,const PixelInterpolateMethod method,
cristy4c08aed2011-07-01 19:47:50 +00004732 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
4733{
4734 MagickBooleanType
4735 status;
4736
cristy4c08aed2011-07-01 19:47:50 +00004737 MagickRealType
4738 alpha[16],
4739 gamma;
4740
cristy865d58d2011-07-09 00:44:52 +00004741 PixelInfo
4742 pixels[16];
4743
cristy4c08aed2011-07-01 19:47:50 +00004744 register const Quantum
4745 *p;
4746
4747 register ssize_t
4748 i;
4749
4750 ssize_t
4751 x_offset,
4752 y_offset;
4753
4754 assert(image != (Image *) NULL);
4755 assert(image->signature == MagickSignature);
4756 assert(image_view != (CacheView *) NULL);
4757 status=MagickTrue;
4758 x_offset=(ssize_t) floor(x);
4759 y_offset=(ssize_t) floor(y);
4760 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4761 {
4762 case AverageInterpolatePixel:
4763 {
4764 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4765 exception);
4766 if (p == (const Quantum *) NULL)
4767 {
4768 status=MagickFalse;
4769 break;
4770 }
cristy5ce8df82011-07-07 14:52:23 +00004771 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004772 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004773 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4774 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4775 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4776 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4777 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4778 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4779 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4780 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4781 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
cristy865d58d2011-07-09 00:44:52 +00004782 10);
cristyed231572011-07-14 02:18:59 +00004783 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
cristy865d58d2011-07-09 00:44:52 +00004784 11);
cristyed231572011-07-14 02:18:59 +00004785 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
cristy865d58d2011-07-09 00:44:52 +00004786 12);
cristyed231572011-07-14 02:18:59 +00004787 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
cristy865d58d2011-07-09 00:44:52 +00004788 13);
cristyed231572011-07-14 02:18:59 +00004789 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
cristy865d58d2011-07-09 00:44:52 +00004790 14);
cristyed231572011-07-14 02:18:59 +00004791 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
cristy865d58d2011-07-09 00:44:52 +00004792 15);
cristy4c08aed2011-07-01 19:47:50 +00004793 pixel->red=0.0;
4794 pixel->green=0.0;
4795 pixel->blue=0.0;
cristy4c08aed2011-07-01 19:47:50 +00004796 pixel->black=0.0;
cristy865d58d2011-07-09 00:44:52 +00004797 pixel->alpha=0.0;
cristy4c08aed2011-07-01 19:47:50 +00004798 for (i=0; i < 16L; i++)
4799 {
4800 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4801 pixel->red+=gamma*0.0625*pixels[i].red;
4802 pixel->green+=gamma*0.0625*pixels[i].green;
4803 pixel->blue+=gamma*0.0625*pixels[i].blue;
cristy4c08aed2011-07-01 19:47:50 +00004804 if (image->colorspace == CMYKColorspace)
4805 pixel->black+=gamma*0.0625*pixels[i].black;
cristy865d58d2011-07-09 00:44:52 +00004806 pixel->alpha+=0.0625*pixels[i].alpha;
cristy4c08aed2011-07-01 19:47:50 +00004807 }
4808 break;
4809 }
4810 case BicubicInterpolatePixel:
4811 {
4812 PixelInfo
4813 u[4];
4814
4815 PointInfo
4816 delta;
4817
4818 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4819 exception);
4820 if (p == (const Quantum *) NULL)
4821 {
4822 status=MagickFalse;
4823 break;
4824 }
cristy5ce8df82011-07-07 14:52:23 +00004825 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004826 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004827 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4828 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4829 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4830 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4831 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4832 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4833 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4834 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4835 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
cristy865d58d2011-07-09 00:44:52 +00004836 10);
cristyed231572011-07-14 02:18:59 +00004837 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
cristy865d58d2011-07-09 00:44:52 +00004838 11);
cristyed231572011-07-14 02:18:59 +00004839 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
cristy865d58d2011-07-09 00:44:52 +00004840 12);
cristyed231572011-07-14 02:18:59 +00004841 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
cristy865d58d2011-07-09 00:44:52 +00004842 13);
cristyed231572011-07-14 02:18:59 +00004843 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
cristy865d58d2011-07-09 00:44:52 +00004844 14);
cristyed231572011-07-14 02:18:59 +00004845 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
cristy865d58d2011-07-09 00:44:52 +00004846 15);
cristy4c08aed2011-07-01 19:47:50 +00004847 delta.x=x-x_offset;
4848 delta.y=y-y_offset;
4849 for (i=0; i < 4L; i++)
4850 BicubicInterpolate(pixels+4*i,delta.x,u+i);
4851 BicubicInterpolate(u,delta.y,pixel);
4852 break;
4853 }
4854 case BilinearInterpolatePixel:
4855 default:
4856 {
4857 PointInfo
4858 delta,
4859 epsilon;
4860
4861 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4862 if (p == (const Quantum *) NULL)
4863 {
4864 status=MagickFalse;
4865 break;
4866 }
cristy5ce8df82011-07-07 14:52:23 +00004867 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004868 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004869 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4870 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
cristy4c08aed2011-07-01 19:47:50 +00004871 delta.x=x-x_offset;
4872 delta.y=y-y_offset;
4873 epsilon.x=1.0-delta.x;
4874 epsilon.y=1.0-delta.y;
4875 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4876 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4877 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4878 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
4879 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
4880 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
4881 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
4882 pixels[3].green));
4883 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
4884 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
4885 pixels[3].blue));
cristy4c08aed2011-07-01 19:47:50 +00004886 if (image->colorspace == CMYKColorspace)
4887 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
4888 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
4889 pixels[3].black));
cristy884f6002011-07-31 00:51:45 +00004890 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4891 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristy865d58d2011-07-09 00:44:52 +00004892 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
4893 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
4894 pixels[3].alpha));
cristy4c08aed2011-07-01 19:47:50 +00004895 break;
4896 }
4897 case FilterInterpolatePixel:
4898 {
4899 CacheView
4900 *filter_view;
4901
4902 Image
4903 *excerpt_image,
4904 *filter_image;
4905
4906 RectangleInfo
4907 geometry;
4908
4909 geometry.width=4L;
4910 geometry.height=4L;
4911 geometry.x=x_offset-1;
4912 geometry.y=y_offset-1;
4913 excerpt_image=ExcerptImage(image,&geometry,exception);
4914 if (excerpt_image == (Image *) NULL)
4915 {
4916 status=MagickFalse;
4917 break;
4918 }
4919 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
4920 exception);
4921 excerpt_image=DestroyImage(excerpt_image);
4922 if (filter_image == (Image *) NULL)
4923 break;
4924 filter_view=AcquireCacheView(filter_image);
4925 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4926 if (p != (const Quantum *) NULL)
cristy803640d2011-11-17 02:11:32 +00004927 GetPixelInfoPixel(image,p,pixel);
cristy4c08aed2011-07-01 19:47:50 +00004928 filter_view=DestroyCacheView(filter_view);
4929 filter_image=DestroyImage(filter_image);
4930 break;
4931 }
4932 case IntegerInterpolatePixel:
4933 {
4934 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4935 if (p == (const Quantum *) NULL)
4936 {
4937 status=MagickFalse;
4938 break;
4939 }
cristy803640d2011-11-17 02:11:32 +00004940 GetPixelInfoPixel(image,p,pixel);
cristy4c08aed2011-07-01 19:47:50 +00004941 break;
4942 }
4943 case MeshInterpolatePixel:
4944 {
4945 PointInfo
4946 delta,
4947 luminance;
4948
cristy94ea1632011-07-30 20:40:25 +00004949 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
cristy4c08aed2011-07-01 19:47:50 +00004950 if (p == (const Quantum *) NULL)
4951 {
4952 status=MagickFalse;
4953 break;
4954 }
cristy94ea1632011-07-30 20:40:25 +00004955 delta.x=x-x_offset;
4956 delta.y=y-y_offset;
cristy884f6002011-07-31 00:51:45 +00004957 luminance.x=GetPixelLuminance(image,p)-(double)
cristy94ea1632011-07-30 20:40:25 +00004958 GetPixelLuminance(image,p+3*GetPixelChannels(image));
cristy28474bf2011-09-11 23:32:52 +00004959 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
cristy94ea1632011-07-30 20:40:25 +00004960 GetPixelLuminance(image,p+2*GetPixelChannels(image));
cristy5ce8df82011-07-07 14:52:23 +00004961 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004962 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004963 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4964 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
cristy4c08aed2011-07-01 19:47:50 +00004965 if (fabs(luminance.x) < fabs(luminance.y))
4966 {
4967 /*
4968 Diagonal 0-3 NW-SE.
4969 */
4970 if (delta.x <= delta.y)
4971 {
4972 /*
cristy94ea1632011-07-30 20:40:25 +00004973 Bottom-left triangle (pixel: 2, diagonal: 0-3).
cristy4c08aed2011-07-01 19:47:50 +00004974 */
4975 delta.y=1.0-delta.y;
4976 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4977 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4978 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
4979 pixels[3].red,pixels[0].red);
4980 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
4981 pixels[3].green,pixels[0].green);
4982 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
4983 pixels[3].blue,pixels[0].blue);
cristy4c08aed2011-07-01 19:47:50 +00004984 if (image->colorspace == CMYKColorspace)
4985 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
4986 pixels[3].black,pixels[0].black);
cristy94ea1632011-07-30 20:40:25 +00004987 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00004988 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
4989 pixels[3].alpha,pixels[0].alpha);
cristy4c08aed2011-07-01 19:47:50 +00004990 }
4991 else
4992 {
4993 /*
cristy94ea1632011-07-30 20:40:25 +00004994 Top-right triangle (pixel:1 , diagonal: 0-3).
cristy4c08aed2011-07-01 19:47:50 +00004995 */
4996 delta.x=1.0-delta.x;
4997 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4998 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4999 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5000 pixels[0].red,pixels[3].red);
5001 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5002 pixels[0].green,pixels[3].green);
5003 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5004 pixels[0].blue,pixels[3].blue);
cristy4c08aed2011-07-01 19:47:50 +00005005 if (image->colorspace == CMYKColorspace)
5006 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5007 pixels[0].black,pixels[3].black);
cristy94ea1632011-07-30 20:40:25 +00005008 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00005009 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5010 pixels[0].alpha,pixels[3].alpha);
cristy4c08aed2011-07-01 19:47:50 +00005011 }
5012 }
5013 else
5014 {
5015 /*
5016 Diagonal 1-2 NE-SW.
5017 */
5018 if (delta.x <= (1.0-delta.y))
5019 {
5020 /*
cristy94ea1632011-07-30 20:40:25 +00005021 Top-left triangle (pixel: 0, diagonal: 1-2).
cristy4c08aed2011-07-01 19:47:50 +00005022 */
5023 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5024 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5025 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5026 pixels[1].red,pixels[2].red);
5027 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5028 pixels[1].green,pixels[2].green);
5029 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5030 pixels[1].blue,pixels[2].blue);
cristy4c08aed2011-07-01 19:47:50 +00005031 if (image->colorspace == CMYKColorspace)
5032 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5033 pixels[1].black,pixels[2].black);
cristy94ea1632011-07-30 20:40:25 +00005034 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00005035 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5036 pixels[1].alpha,pixels[2].alpha);
cristy4c08aed2011-07-01 19:47:50 +00005037 }
5038 else
5039 {
5040 /*
5041 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5042 */
5043 delta.x=1.0-delta.x;
5044 delta.y=1.0-delta.y;
5045 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5046 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5047 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5048 pixels[2].red,pixels[1].red);
5049 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5050 pixels[2].green,pixels[1].green);
5051 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5052 pixels[2].blue,pixels[1].blue);
cristy4c08aed2011-07-01 19:47:50 +00005053 if (image->colorspace == CMYKColorspace)
5054 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5055 pixels[2].black,pixels[1].black);
cristy94ea1632011-07-30 20:40:25 +00005056 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00005057 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5058 pixels[2].alpha,pixels[1].alpha);
cristy4c08aed2011-07-01 19:47:50 +00005059 }
5060 }
5061 break;
5062 }
5063 case NearestNeighborInterpolatePixel:
5064 {
5065 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5066 NearestNeighbor(y),1,1,exception);
5067 if (p == (const Quantum *) NULL)
5068 {
5069 status=MagickFalse;
5070 break;
5071 }
cristy803640d2011-11-17 02:11:32 +00005072 GetPixelInfoPixel(image,p,pixel);
cristy4c08aed2011-07-01 19:47:50 +00005073 break;
5074 }
5075 case SplineInterpolatePixel:
5076 {
5077 MagickRealType
5078 dx,
5079 dy;
5080
5081 PointInfo
5082 delta;
5083
5084 ssize_t
5085 j,
5086 n;
5087
5088 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5089 exception);
5090 if (p == (const Quantum *) NULL)
5091 {
5092 status=MagickFalse;
5093 break;
5094 }
cristy5ce8df82011-07-07 14:52:23 +00005095 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00005096 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00005097 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5098 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5099 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5100 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5101 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5102 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5103 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5104 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5105 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
cristy865d58d2011-07-09 00:44:52 +00005106 10);
cristyed231572011-07-14 02:18:59 +00005107 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
cristy865d58d2011-07-09 00:44:52 +00005108 11);
cristyed231572011-07-14 02:18:59 +00005109 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
cristy865d58d2011-07-09 00:44:52 +00005110 12);
cristyed231572011-07-14 02:18:59 +00005111 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
cristy865d58d2011-07-09 00:44:52 +00005112 13);
cristyed231572011-07-14 02:18:59 +00005113 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
cristy865d58d2011-07-09 00:44:52 +00005114 14);
cristyed231572011-07-14 02:18:59 +00005115 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
cristy865d58d2011-07-09 00:44:52 +00005116 15);
cristy4c08aed2011-07-01 19:47:50 +00005117 pixel->red=0.0;
5118 pixel->green=0.0;
5119 pixel->blue=0.0;
cristy4c08aed2011-07-01 19:47:50 +00005120 pixel->black=0.0;
cristy865d58d2011-07-09 00:44:52 +00005121 pixel->alpha=0.0;
cristy4c08aed2011-07-01 19:47:50 +00005122 delta.x=x-x_offset;
5123 delta.y=y-y_offset;
5124 n=0;
5125 for (i=(-1); i < 3L; i++)
5126 {
5127 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5128 for (j=(-1); j < 3L; j++)
5129 {
5130 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5131 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5132 pixel->red+=gamma*dx*dy*pixels[n].red;
5133 pixel->green+=gamma*dx*dy*pixels[n].green;
5134 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5135 if (image->colorspace == CMYKColorspace)
5136 pixel->black+=gamma*dx*dy*pixels[n].black;
5137 pixel->alpha+=dx*dy*pixels[n].alpha;
5138 n++;
5139 }
5140 }
5141 break;
5142 }
5143 }
5144 return(status);
5145}
5146
5147/*
5148%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5149% %
5150% %
5151% %
5152+ I s F u z z y E q u i v a l e n c e P i x e l %
5153% %
5154% %
5155% %
5156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5157%
5158% IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5159% pixels is less than the specified distance in a linear three (or four)u
5160% dimensional color space.
5161%
5162% The format of the IsFuzzyEquivalencePixel method is:
5163%
5164% void IsFuzzyEquivalencePixel(const Image *image,const Quantum *p,
5165% const Quantum *q)
5166%
5167% A description of each parameter follows:
5168%
5169% o image: the image.
5170%
5171% o p: Pixel p.
5172%
5173% o q: Pixel q.
5174%
5175*/
5176MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
5177 const Quantum *p,const Quantum *q)
5178{
5179 MagickRealType
5180 fuzz,
5181 pixel;
5182
5183 register MagickRealType
5184 distance,
5185 scale;
5186
cristy5f95f4f2011-10-23 01:01:01 +00005187 fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5188 image->fuzz,(MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005189 scale=1.0;
5190 distance=0.0;
5191 if (image->matte != MagickFalse)
5192 {
5193 /*
5194 Transparencies are involved - set alpha distance
5195 */
5196 pixel=(MagickRealType) ((image->matte != MagickFalse ?
5197 GetPixelAlpha(image,p) : OpaqueAlpha)-(image->matte != MagickFalse ?
5198 GetPixelAlpha(image,q) : OpaqueAlpha));
5199 distance=pixel*pixel;
5200 if (distance > fuzz)
5201 return(MagickFalse);
5202 /*
5203 Generate a alpha scaling factor to generate a 4D cone on colorspace
5204 Note that if one color is transparent, distance has no color component.
5205 */
5206 scale=QuantumScale*GetPixelAlpha(image,p);
5207 scale*=QuantumScale*GetPixelAlpha(image,q);
5208 if (scale <= MagickEpsilon)
5209 return(MagickTrue);
5210 }
5211 /*
5212 RGB or CMY color cube
5213 */
5214 distance*=3.0; /* rescale appropriately */
5215 fuzz*=3.0;
5216 pixel=GetPixelRed(image,p)-(MagickRealType) GetPixelRed(image,q);
5217 if ((image->colorspace == HSLColorspace) ||
5218 (image->colorspace == HSBColorspace) ||
5219 (image->colorspace == HWBColorspace))
5220 {
5221 /*
5222 Compute an arc distance for hue. It should be a vector angle of
5223 'S'/'W' length with 'L'/'B' forming appropriate cones.
5224 */
5225 if (fabs((double) pixel) > (QuantumRange/2))
5226 pixel-=QuantumRange;
5227 pixel*=2;
5228 }
5229 distance+=scale*pixel*pixel;
5230 if (distance > fuzz)
5231 return(MagickFalse);
5232 pixel=GetPixelGreen(image,p)-(MagickRealType) GetPixelGreen(image,q);
5233 distance+=scale*pixel*pixel;
5234 if (distance > fuzz)
5235 return(MagickFalse);
5236 pixel=GetPixelBlue(image,p)-(MagickRealType) GetPixelBlue(image,q);
5237 distance+=scale*pixel*pixel;
5238 if (distance > fuzz)
5239 return(MagickFalse);
5240 return(MagickTrue);
5241}
5242
5243/*
5244%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5245% %
5246% %
5247% %
5248+ I s F u z z y E q u i v a l e n c e P i x e l I n f o %
5249% %
5250% %
5251% %
5252%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5253%
5254% IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5255% colors is less than the specified distance in a linear three (or four)
5256% dimensional color space.
5257%
cristy5f95f4f2011-10-23 01:01:01 +00005258% This implements the equivalent of:
5259% fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
cristy4c08aed2011-07-01 19:47:50 +00005260%
5261% Which produces a multi-dimensional cone for that colorspace along the
5262% transparency vector.
5263%
cristy5f95f4f2011-10-23 01:01:01 +00005264% For example for an RGB:
cristy4c08aed2011-07-01 19:47:50 +00005265% color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5266%
5267% See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5268%
5269% Hue colorspace distances need more work. Hue is not a distance, it is an
5270% angle!
5271%
5272% A check that q is in the same color space as p should be made and the
5273% appropriate mapping made. -- Anthony Thyssen 8 December 2010
5274%
5275% The format of the IsFuzzyEquivalencePixelInfo method is:
5276%
5277% MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5278% const PixelInfo *q)
5279%
5280% A description of each parameter follows:
5281%
5282% o p: Pixel p.
5283%
5284% o q: Pixel q.
5285%
5286*/
5287MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5288 const PixelInfo *q)
5289{
5290 MagickRealType
5291 fuzz,
5292 pixel;
5293
5294 register MagickRealType
5295 scale,
5296 distance;
5297
5298 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5299 return(IsPixelInfoEquivalent(p,q));
5300 if (p->fuzz == 0.0)
cristy5f95f4f2011-10-23 01:01:01 +00005301 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5302 (MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005303 else if (q->fuzz == 0.0)
cristy5f95f4f2011-10-23 01:01:01 +00005304 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5305 (MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005306 else
cristy5f95f4f2011-10-23 01:01:01 +00005307 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5308 (MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005309 scale=1.0;
5310 distance=0.0;
5311 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5312 {
5313 /*
5314 Transparencies are involved - set alpha distance.
5315 */
5316 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5317 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5318 distance=pixel*pixel;
5319 if (distance > fuzz)
5320 return(MagickFalse);
5321 /*
5322 Generate a alpha scaling factor to generate a 4D cone on colorspace.
cristy5f95f4f2011-10-23 01:01:01 +00005323 If one color is transparent, distance has no color component.
cristy4c08aed2011-07-01 19:47:50 +00005324 */
5325 if (p->matte != MagickFalse)
5326 scale=(QuantumScale*p->alpha);
5327 if (q->matte != MagickFalse)
5328 scale*=(QuantumScale*q->alpha);
5329 if (scale <= MagickEpsilon )
5330 return(MagickTrue);
5331 }
5332 /*
5333 CMYK create a CMY cube with a multi-dimensional cone toward black.
5334 */
5335 if (p->colorspace == CMYKColorspace)
5336 {
5337 pixel=p->black-q->black;
5338 distance+=pixel*pixel*scale;
5339 if (distance > fuzz)
5340 return(MagickFalse);
5341 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5342 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5343 }
5344 /*
5345 RGB or CMY color cube.
5346 */
5347 distance*=3.0; /* rescale appropriately */
5348 fuzz*=3.0;
5349 pixel=p->red-q->red;
5350 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5351 (p->colorspace == HWBColorspace))
5352 {
cristy5f95f4f2011-10-23 01:01:01 +00005353 /*
5354 This calculates a arc distance for hue-- it should be a vector angle
5355 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5356 words this is a hack - Anthony.
cristy4c08aed2011-07-01 19:47:50 +00005357 */
5358 if (fabs((double) pixel) > (QuantumRange/2))
5359 pixel-=QuantumRange;
5360 pixel*=2;
5361 }
5362 distance+=pixel*pixel*scale;
5363 if (distance > fuzz)
5364 return(MagickFalse);
5365 pixel=p->green-q->green;
5366 distance+=pixel*pixel*scale;
5367 if (distance > fuzz)
5368 return(MagickFalse);
5369 pixel=p->blue-q->blue;
5370 distance+=pixel*pixel*scale;
5371 if (distance > fuzz)
5372 return(MagickFalse);
5373 return(MagickTrue);
5374}
5375
5376/*
5377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5378% %
5379% %
5380% %
cristye2a912b2011-12-05 20:02:07 +00005381% S e t P i x e l C h a n n e l M a p M a s k %
cristy2b9582a2011-07-04 17:38:56 +00005382% %
5383% %
5384% %
5385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5386%
cristye2a912b2011-12-05 20:02:07 +00005387% SetPixelChannelMapMask() sets the pixel channel map from the specified
5388% channel mask.
cristy2b9582a2011-07-04 17:38:56 +00005389%
cristye2a912b2011-12-05 20:02:07 +00005390% The format of the SetPixelChannelMapMask method is:
cristy2b9582a2011-07-04 17:38:56 +00005391%
cristye2a912b2011-12-05 20:02:07 +00005392% void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005393%
5394% A description of each parameter follows:
5395%
5396% o image: the image.
5397%
cristy44261462011-08-09 13:34:47 +00005398% o mask: the channel mask.
cristy2b9582a2011-07-04 17:38:56 +00005399%
5400*/
cristye2a912b2011-12-05 20:02:07 +00005401MagickExport void SetPixelChannelMapMask(Image *image,
cristy07a67852011-08-26 13:25:03 +00005402 const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005403{
cristy6a917d62011-08-24 17:31:30 +00005404#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
cristydafd2872011-07-24 22:06:13 +00005405
cristy2b9582a2011-07-04 17:38:56 +00005406 register ssize_t
5407 i;
5408
cristy3c309812011-11-08 02:40:43 +00005409 image->channel_mask=channel_mask;
cristydafd2872011-07-24 22:06:13 +00005410 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristye2a912b2011-12-05 20:02:07 +00005411 {
5412 PixelChannel
5413 channel;
5414
5415 channel=GetPixelChannelMapChannel(image,i);
5416 SetPixelChannelMapTraits(image,channel,
5417 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
cristy3fac9ec2011-11-17 18:04:39 +00005418 image->matte == MagickFalse ? UpdatePixelTrait : (PixelTrait)
5419 (UpdatePixelTrait | BlendPixelTrait));
cristye2a912b2011-12-05 20:02:07 +00005420 }
cristy1685e722011-09-06 00:04:19 +00005421 if (image->storage_class == PseudoClass)
5422 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
cristy6dcb9b82011-10-23 23:21:25 +00005423 if (image->debug != MagickFalse)
5424 LogPixelChannels(image);
cristy2b9582a2011-07-04 17:38:56 +00005425}
5426
5427/*
5428%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5429% %
5430% %
5431% %
cristybd5a96c2011-08-21 00:04:26 +00005432% S e t P i x e l C h a n n e l M a s k %
cristy2b9582a2011-07-04 17:38:56 +00005433% %
5434% %
5435% %
5436%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5437%
cristy5f95f4f2011-10-23 01:01:01 +00005438% SetPixelChannelMask() sets the pixel channel mask from the specified channel
5439% mask.
cristy2b9582a2011-07-04 17:38:56 +00005440%
cristybd5a96c2011-08-21 00:04:26 +00005441% The format of the SetPixelChannelMask method is:
cristy2b9582a2011-07-04 17:38:56 +00005442%
cristybd5a96c2011-08-21 00:04:26 +00005443% ChannelType SetPixelChannelMask(Image *image,
5444% const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005445%
5446% A description of each parameter follows:
5447%
5448% o image: the image.
5449%
cristybd5a96c2011-08-21 00:04:26 +00005450% o channel_mask: the channel mask.
5451%
cristy2b9582a2011-07-04 17:38:56 +00005452*/
cristybd5a96c2011-08-21 00:04:26 +00005453MagickExport ChannelType SetPixelChannelMask(Image *image,
5454 const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005455{
cristybd5a96c2011-08-21 00:04:26 +00005456 ChannelType
5457 mask;
cristy222b19c2011-08-04 01:35:11 +00005458
cristybd5a96c2011-08-21 00:04:26 +00005459 mask=image->channel_mask;
5460 image->channel_mask=channel_mask;
cristye2a912b2011-12-05 20:02:07 +00005461 SetPixelChannelMapMask(image,channel_mask);
cristybd5a96c2011-08-21 00:04:26 +00005462 return(mask);
cristy2b9582a2011-07-04 17:38:56 +00005463}