blob: 261a8d1ed451f32131c5ce064738556f5b3aa060 [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 \
cristy46795722011-12-10 23:56:57 +000084 *name; \
85 \
86 PixelChannel \
87 channel; \
cristy146a62b2011-10-23 23:40:46 +000088 \
cristye2a912b2011-12-05 20:02:07 +000089 switch (GetPixelChannelMapChannel(image,i)) \
cristy146a62b2011-10-23 23:40:46 +000090 { \
91 case RedPixelChannel: \
92 { \
cristy46795722011-12-10 23:56:57 +000093 name="red"; \
cristy146a62b2011-10-23 23:40:46 +000094 if (image->colorspace == CMYKColorspace) \
cristy46795722011-12-10 23:56:57 +000095 name="cyan"; \
cristy146a62b2011-10-23 23:40:46 +000096 if (image->colorspace == GRAYColorspace) \
cristy46795722011-12-10 23:56:57 +000097 name="gray"; \
cristy146a62b2011-10-23 23:40:46 +000098 break; \
99 } \
100 case GreenPixelChannel: \
101 { \
cristy46795722011-12-10 23:56:57 +0000102 name="green"; \
cristy146a62b2011-10-23 23:40:46 +0000103 if (image->colorspace == CMYKColorspace) \
cristy46795722011-12-10 23:56:57 +0000104 name="magenta"; \
cristy146a62b2011-10-23 23:40:46 +0000105 break; \
106 } \
107 case BluePixelChannel: \
108 { \
cristy46795722011-12-10 23:56:57 +0000109 name="blue"; \
cristy146a62b2011-10-23 23:40:46 +0000110 if (image->colorspace == CMYKColorspace) \
cristy46795722011-12-10 23:56:57 +0000111 name="yellow"; \
cristy146a62b2011-10-23 23:40:46 +0000112 break; \
113 } \
114 case BlackPixelChannel: \
115 { \
cristy46795722011-12-10 23:56:57 +0000116 name="black"; \
cristy146a62b2011-10-23 23:40:46 +0000117 if (image->storage_class == PseudoClass) \
cristy46795722011-12-10 23:56:57 +0000118 name="index"; \
cristy146a62b2011-10-23 23:40:46 +0000119 break; \
120 } \
cristye2a912b2011-12-05 20:02:07 +0000121 case IndexPixelChannel: \
122 { \
cristy46795722011-12-10 23:56:57 +0000123 name="index"; \
cristye2a912b2011-12-05 20:02:07 +0000124 break; \
125 } \
cristy146a62b2011-10-23 23:40:46 +0000126 case AlphaPixelChannel: \
127 { \
cristy46795722011-12-10 23:56:57 +0000128 name="alpha"; \
cristy146a62b2011-10-23 23:40:46 +0000129 break; \
130 } \
131 case MaskPixelChannel: \
132 { \
cristy46795722011-12-10 23:56:57 +0000133 name="mask"; \
cristy146a62b2011-10-23 23:40:46 +0000134 break; \
135 } \
cristye2a912b2011-12-05 20:02:07 +0000136 case MetaPixelChannel: \
cristy146a62b2011-10-23 23:40:46 +0000137 { \
cristy46795722011-12-10 23:56:57 +0000138 name="meta"; \
cristye2a912b2011-12-05 20:02:07 +0000139 break; \
cristy146a62b2011-10-23 23:40:46 +0000140 } \
cristye2a912b2011-12-05 20:02:07 +0000141 default: \
cristy46795722011-12-10 23:56:57 +0000142 name="undefined"; \
cristy146a62b2011-10-23 23:40:46 +0000143 } \
cristy46795722011-12-10 23:56:57 +0000144 channel=GetPixelChannelMapChannel(image,i); \
cristy146a62b2011-10-23 23:40:46 +0000145 *traits='\0'; \
cristy46795722011-12-10 23:56:57 +0000146 if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \
cristy146a62b2011-10-23 23:40:46 +0000147 (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
cristy46795722011-12-10 23:56:57 +0000148 if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \
cristy146a62b2011-10-23 23:40:46 +0000149 (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
cristy46795722011-12-10 23:56:57 +0000150 if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \
cristy146a62b2011-10-23 23:40:46 +0000151 (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
152 if (*traits == '\0') \
153 (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
154 traits[strlen(traits)-1]='\0'; \
155 (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \
cristy46795722011-12-10 23:56:57 +0000156 (double) i,name,traits); \
cristy146a62b2011-10-23 23:40:46 +0000157 } \
158}
159
160/*
cristy4c08aed2011-07-01 19:47:50 +0000161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162% %
163% %
164% %
cristyed231572011-07-14 02:18:59 +0000165+ 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 +0000166% %
167% %
168% %
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170%
cristyed231572011-07-14 02:18:59 +0000171% AcquirePixelChannelMap() acquires a pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000172%
cristyed231572011-07-14 02:18:59 +0000173% The format of the AcquirePixelChannelMap() method is:
cristy4c08aed2011-07-01 19:47:50 +0000174%
cristybd5a96c2011-08-21 00:04:26 +0000175% PixelChannelMap *AcquirePixelChannelMap(void)
cristy4c08aed2011-07-01 19:47:50 +0000176%
177*/
cristybd5a96c2011-08-21 00:04:26 +0000178MagickExport PixelChannelMap *AcquirePixelChannelMap(void)
cristy4c08aed2011-07-01 19:47:50 +0000179{
cristyed231572011-07-14 02:18:59 +0000180 PixelChannelMap
cristybd5a96c2011-08-21 00:04:26 +0000181 *channel_map;
cristy4c08aed2011-07-01 19:47:50 +0000182
183 register ssize_t
184 i;
185
cristybd5a96c2011-08-21 00:04:26 +0000186 channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels,
187 sizeof(*channel_map));
188 if (channel_map == (PixelChannelMap *) NULL)
cristy4c08aed2011-07-01 19:47:50 +0000189 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristybd5a96c2011-08-21 00:04:26 +0000190 (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
191 for (i=0; i < MaxPixelChannels; i++)
192 channel_map[i].channel=(PixelChannel) i;
cristyed231572011-07-14 02:18:59 +0000193 return(channel_map);
cristy4c08aed2011-07-01 19:47:50 +0000194}
195
196/*
197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198% %
199% %
200% %
cristyed231572011-07-14 02:18:59 +0000201+ 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 +0000202% %
203% %
204% %
205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206%
cristyed231572011-07-14 02:18:59 +0000207% ClonePixelChannelMap() clones a pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000208%
cristyed231572011-07-14 02:18:59 +0000209% The format of the ClonePixelChannelMap() method is:
cristy4c08aed2011-07-01 19:47:50 +0000210%
cristybd5a96c2011-08-21 00:04:26 +0000211% PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000212%
213% A description of each parameter follows:
214%
cristyed231572011-07-14 02:18:59 +0000215% o channel_map: the pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000216%
217*/
cristybd5a96c2011-08-21 00:04:26 +0000218MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000219{
cristyed231572011-07-14 02:18:59 +0000220 PixelChannelMap
cristybd5a96c2011-08-21 00:04:26 +0000221 *clone_map;
cristy4c08aed2011-07-01 19:47:50 +0000222
cristybd5a96c2011-08-21 00:04:26 +0000223 assert(channel_map != (PixelChannelMap *) NULL);
cristyed231572011-07-14 02:18:59 +0000224 clone_map=AcquirePixelChannelMap();
cristybd5a96c2011-08-21 00:04:26 +0000225 if (clone_map == (PixelChannelMap *) NULL)
226 return((PixelChannelMap *) NULL);
227 (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
228 sizeof(*channel_map));
cristy4c08aed2011-07-01 19:47:50 +0000229 return(clone_map);
230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
237+ C l o n e P i x e l I n f o %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
243% ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
244% pixel info is NULL, a new one.
245%
246% The format of the ClonePixelInfo method is:
247%
248% PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info)
249%
250% A description of each parameter follows:
251%
252% o pixel_info: the pixel info.
253%
254*/
255MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
256{
257 PixelInfo
258 *pixel_info;
259
cristya64b85d2011-09-14 01:02:31 +0000260 pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
cristy4c08aed2011-07-01 19:47:50 +0000261 if (pixel_info == (PixelInfo *) NULL)
262 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
263 *pixel_info=(*pixel);
264 return(pixel_info);
265}
266
267/*
268%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269% %
270% %
271% %
cristyed231572011-07-14 02:18:59 +0000272+ 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 +0000273% %
274% %
275% %
276%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277%
cristyed231572011-07-14 02:18:59 +0000278% DestroyPixelChannelMap() deallocates memory associated with the pixel
279% channel map.
cristy4c08aed2011-07-01 19:47:50 +0000280%
cristyed231572011-07-14 02:18:59 +0000281% The format of the DestroyPixelChannelMap() method is:
cristy4c08aed2011-07-01 19:47:50 +0000282%
cristybd5a96c2011-08-21 00:04:26 +0000283% PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000284%
285% A description of each parameter follows:
286%
cristyed231572011-07-14 02:18:59 +0000287% o channel_map: the pixel component map.
cristy4c08aed2011-07-01 19:47:50 +0000288%
289*/
cristybd5a96c2011-08-21 00:04:26 +0000290MagickExport PixelChannelMap *DestroyPixelChannelMap(
291 PixelChannelMap *channel_map)
cristy4c08aed2011-07-01 19:47:50 +0000292{
cristybd5a96c2011-08-21 00:04:26 +0000293 assert(channel_map != (PixelChannelMap *) NULL);
294 channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
295 return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
cristy4c08aed2011-07-01 19:47:50 +0000296}
297
298/*
299%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300% %
301% %
302% %
303% E x p o r t I m a g e P i x e l s %
304% %
305% %
306% %
307%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308%
309% ExportImagePixels() extracts pixel data from an image and returns it to you.
310% The method returns MagickTrue on success otherwise MagickFalse if an error is
311% encountered. The data is returned as char, short int, int, ssize_t, float,
312% or double in the order specified by map.
313%
314% Suppose you want to extract the first scanline of a 640x480 image as
315% character data in red-green-blue order:
316%
317% ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
318%
319% The format of the ExportImagePixels method is:
320%
321% MagickBooleanType ExportImagePixels(const Image *image,
322% const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
323% const size_t rows,const char *map,const StorageType type,
324% void *pixels,ExceptionInfo *exception)
325%
326% A description of each parameter follows:
327%
328% o image: the image.
329%
330% o x_offset,y_offset,columns,rows: These values define the perimeter
331% of a region of pixels you want to extract.
332%
333% o map: This string reflects the expected ordering of the pixel array.
334% It can be any combination or order of R = red, G = green, B = blue,
335% A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
336% Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
337% P = pad.
338%
339% o type: Define the data type of the pixels. Float and double types are
340% normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
341% types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel,
342% QuantumPixel, or ShortPixel.
343%
344% o pixels: This array of values contain the pixel components as defined by
345% map and type. You must preallocate this array where the expected
346% length varies depending on the values of width, height, map, and type.
347%
348% o exception: return any errors or warnings in this structure.
349%
350*/
351MagickExport MagickBooleanType ExportImagePixels(const Image *image,
352 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
353 const size_t rows,const char *map,const StorageType type,void *pixels,
354 ExceptionInfo *exception)
355{
356 QuantumType
357 *quantum_map;
358
359 register ssize_t
360 i,
361 x;
362
363 register const Quantum
364 *p;
365
366 size_t
367 length;
368
369 ssize_t
370 y;
371
372 assert(image != (Image *) NULL);
373 assert(image->signature == MagickSignature);
374 if (image->debug != MagickFalse)
375 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
376 length=strlen(map);
377 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
378 if (quantum_map == (QuantumType *) NULL)
379 {
380 (void) ThrowMagickException(exception,GetMagickModule(),
381 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
382 return(MagickFalse);
383 }
384 for (i=0; i < (ssize_t) length; i++)
385 {
386 switch (map[i])
387 {
388 case 'A':
389 case 'a':
390 {
391 quantum_map[i]=AlphaQuantum;
392 break;
393 }
394 case 'B':
395 case 'b':
396 {
397 quantum_map[i]=BlueQuantum;
398 break;
399 }
400 case 'C':
401 case 'c':
402 {
403 quantum_map[i]=CyanQuantum;
404 if (image->colorspace == CMYKColorspace)
405 break;
406 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
407 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
408 "ColorSeparatedImageRequired","`%s'",map);
409 return(MagickFalse);
410 }
411 case 'g':
412 case 'G':
413 {
414 quantum_map[i]=GreenQuantum;
415 break;
416 }
417 case 'I':
418 case 'i':
419 {
420 quantum_map[i]=IndexQuantum;
421 break;
422 }
423 case 'K':
424 case 'k':
425 {
426 quantum_map[i]=BlackQuantum;
427 if (image->colorspace == CMYKColorspace)
428 break;
429 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
430 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
431 "ColorSeparatedImageRequired","`%s'",map);
432 return(MagickFalse);
433 }
434 case 'M':
435 case 'm':
436 {
437 quantum_map[i]=MagentaQuantum;
438 if (image->colorspace == CMYKColorspace)
439 break;
440 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
441 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
442 "ColorSeparatedImageRequired","`%s'",map);
443 return(MagickFalse);
444 }
445 case 'o':
446 case 'O':
447 {
448 quantum_map[i]=OpacityQuantum;
449 break;
450 }
451 case 'P':
452 case 'p':
453 {
454 quantum_map[i]=UndefinedQuantum;
455 break;
456 }
457 case 'R':
458 case 'r':
459 {
460 quantum_map[i]=RedQuantum;
461 break;
462 }
463 case 'Y':
464 case 'y':
465 {
466 quantum_map[i]=YellowQuantum;
467 if (image->colorspace == CMYKColorspace)
468 break;
469 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
470 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
471 "ColorSeparatedImageRequired","`%s'",map);
472 return(MagickFalse);
473 }
474 default:
475 {
476 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
477 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
478 "UnrecognizedPixelMap","`%s'",map);
479 return(MagickFalse);
480 }
481 }
482 }
483 switch (type)
484 {
485 case CharPixel:
486 {
487 register unsigned char
488 *q;
489
490 q=(unsigned char *) pixels;
491 if (LocaleCompare(map,"BGR") == 0)
492 {
493 for (y=0; y < (ssize_t) rows; y++)
494 {
495 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
496 if (p == (const Quantum *) NULL)
497 break;
498 for (x=0; x < (ssize_t) columns; x++)
499 {
500 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
501 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
502 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +0000503 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000504 }
505 }
506 break;
507 }
508 if (LocaleCompare(map,"BGRA") == 0)
509 {
510 for (y=0; y < (ssize_t) rows; y++)
511 {
512 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
513 if (p == (const Quantum *) NULL)
514 break;
515 for (x=0; x < (ssize_t) columns; x++)
516 {
517 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
518 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
519 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
520 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000521 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000522 }
523 }
524 break;
525 }
526 if (LocaleCompare(map,"BGRP") == 0)
527 {
528 for (y=0; y < (ssize_t) rows; y++)
529 {
530 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
531 if (p == (const Quantum *) NULL)
532 break;
533 for (x=0; x < (ssize_t) columns; x++)
534 {
535 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
536 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
537 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
538 *q++=ScaleQuantumToChar((Quantum) 0);
cristyed231572011-07-14 02:18:59 +0000539 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000540 }
541 }
542 break;
543 }
544 if (LocaleCompare(map,"I") == 0)
545 {
546 for (y=0; y < (ssize_t) rows; y++)
547 {
548 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
549 if (p == (const Quantum *) NULL)
550 break;
551 for (x=0; x < (ssize_t) columns; x++)
552 {
553 *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000554 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000555 }
556 }
557 break;
558 }
559 if (LocaleCompare(map,"RGB") == 0)
560 {
561 for (y=0; y < (ssize_t) rows; y++)
562 {
563 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
564 if (p == (const Quantum *) NULL)
565 break;
566 for (x=0; x < (ssize_t) columns; x++)
567 {
568 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
569 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
570 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000571 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000572 }
573 }
574 break;
575 }
576 if (LocaleCompare(map,"RGBA") == 0)
577 {
578 for (y=0; y < (ssize_t) rows; y++)
579 {
580 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
581 if (p == (const Quantum *) NULL)
582 break;
583 for (x=0; x < (ssize_t) columns; x++)
584 {
585 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
586 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
587 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
588 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000589 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000590 }
591 }
592 break;
593 }
594 if (LocaleCompare(map,"RGBP") == 0)
595 {
596 for (y=0; y < (ssize_t) rows; y++)
597 {
598 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
599 if (p == (const Quantum *) NULL)
600 break;
601 for (x=0; x < (ssize_t) columns; x++)
602 {
603 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
604 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
605 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
606 *q++=ScaleQuantumToChar((Quantum) 0);
cristyed231572011-07-14 02:18:59 +0000607 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000608 }
609 }
610 break;
611 }
612 for (y=0; y < (ssize_t) rows; y++)
613 {
614 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
615 if (p == (const Quantum *) NULL)
616 break;
617 for (x=0; x < (ssize_t) columns; x++)
618 {
619 for (i=0; i < (ssize_t) length; i++)
620 {
621 *q=0;
622 switch (quantum_map[i])
623 {
624 case RedQuantum:
625 case CyanQuantum:
626 {
627 *q=ScaleQuantumToChar(GetPixelRed(image,p));
628 break;
629 }
630 case GreenQuantum:
631 case MagentaQuantum:
632 {
633 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
634 break;
635 }
636 case BlueQuantum:
637 case YellowQuantum:
638 {
639 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
640 break;
641 }
642 case AlphaQuantum:
643 {
644 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
645 break;
646 }
647 case OpacityQuantum:
648 {
649 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
650 break;
651 }
652 case BlackQuantum:
653 {
654 if (image->colorspace == CMYKColorspace)
655 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
656 break;
657 }
658 case IndexQuantum:
659 {
660 *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
661 break;
662 }
663 default:
664 break;
665 }
666 q++;
667 }
cristyed231572011-07-14 02:18:59 +0000668 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000669 }
670 }
671 break;
672 }
673 case DoublePixel:
674 {
675 register double
676 *q;
677
678 q=(double *) pixels;
679 if (LocaleCompare(map,"BGR") == 0)
680 {
681 for (y=0; y < (ssize_t) rows; y++)
682 {
683 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
684 if (p == (const Quantum *) NULL)
685 break;
686 for (x=0; x < (ssize_t) columns; x++)
687 {
688 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
689 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
690 *q++=(double) (QuantumScale*GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +0000691 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000692 }
693 }
694 break;
695 }
696 if (LocaleCompare(map,"BGRA") == 0)
697 {
698 for (y=0; y < (ssize_t) rows; y++)
699 {
700 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
701 if (p == (const Quantum *) NULL)
702 break;
703 for (x=0; x < (ssize_t) columns; x++)
704 {
705 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
706 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
707 *q++=(double) (QuantumScale*GetPixelRed(image,p));
708 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000709 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000710 }
711 }
712 break;
713 }
714 if (LocaleCompare(map,"BGRP") == 0)
715 {
716 for (y=0; y < (ssize_t) rows; y++)
717 {
718 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
719 if (p == (const Quantum *) NULL)
720 break;
721 for (x=0; x < (ssize_t) columns; x++)
722 {
723 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
724 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
725 *q++=(double) (QuantumScale*GetPixelRed(image,p));
726 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000727 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000728 }
729 }
730 break;
731 }
732 if (LocaleCompare(map,"I") == 0)
733 {
734 for (y=0; y < (ssize_t) rows; y++)
735 {
736 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
737 if (p == (const Quantum *) NULL)
738 break;
739 for (x=0; x < (ssize_t) columns; x++)
740 {
741 *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000742 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000743 }
744 }
745 break;
746 }
747 if (LocaleCompare(map,"RGB") == 0)
748 {
749 for (y=0; y < (ssize_t) rows; y++)
750 {
751 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
752 if (p == (const Quantum *) NULL)
753 break;
754 for (x=0; x < (ssize_t) columns; x++)
755 {
756 *q++=(double) (QuantumScale*GetPixelRed(image,p));
757 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
758 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000759 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000760 }
761 }
762 break;
763 }
764 if (LocaleCompare(map,"RGBA") == 0)
765 {
766 for (y=0; y < (ssize_t) rows; y++)
767 {
768 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
769 if (p == (const Quantum *) NULL)
770 break;
771 for (x=0; x < (ssize_t) columns; x++)
772 {
773 *q++=(double) (QuantumScale*GetPixelRed(image,p));
774 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
775 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
776 *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000777 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000778 }
779 }
780 break;
781 }
782 if (LocaleCompare(map,"RGBP") == 0)
783 {
784 for (y=0; y < (ssize_t) rows; y++)
785 {
786 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
787 if (p == (const Quantum *) NULL)
788 break;
789 for (x=0; x < (ssize_t) columns; x++)
790 {
791 *q++=(double) (QuantumScale*GetPixelRed(image,p));
792 *q++=(double) (QuantumScale*GetPixelGreen(image,p));
793 *q++=(double) (QuantumScale*GetPixelBlue(image,p));
794 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000795 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000796 }
797 }
798 break;
799 }
800 for (y=0; y < (ssize_t) rows; y++)
801 {
802 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
803 if (p == (const Quantum *) NULL)
804 break;
805 for (x=0; x < (ssize_t) columns; x++)
806 {
807 for (i=0; i < (ssize_t) length; i++)
808 {
809 *q=0;
810 switch (quantum_map[i])
811 {
812 case RedQuantum:
813 case CyanQuantum:
814 {
815 *q=(double) (QuantumScale*GetPixelRed(image,p));
816 break;
817 }
818 case GreenQuantum:
819 case MagentaQuantum:
820 {
821 *q=(double) (QuantumScale*GetPixelGreen(image,p));
822 break;
823 }
824 case BlueQuantum:
825 case YellowQuantum:
826 {
827 *q=(double) (QuantumScale*GetPixelBlue(image,p));
828 break;
829 }
830 case AlphaQuantum:
831 {
832 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
833 break;
834 }
835 case OpacityQuantum:
836 {
837 *q=(double) (QuantumScale*GetPixelAlpha(image,p));
838 break;
839 }
840 case BlackQuantum:
841 {
842 if (image->colorspace == CMYKColorspace)
843 *q=(double) (QuantumScale*
844 GetPixelBlack(image,p));
845 break;
846 }
847 case IndexQuantum:
848 {
849 *q=(double) (QuantumScale*GetPixelIntensity(image,p));
850 break;
851 }
852 default:
853 *q=0;
854 }
855 q++;
856 }
cristyed231572011-07-14 02:18:59 +0000857 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000858 }
859 }
860 break;
861 }
862 case FloatPixel:
863 {
864 register float
865 *q;
866
867 q=(float *) pixels;
868 if (LocaleCompare(map,"BGR") == 0)
869 {
870 for (y=0; y < (ssize_t) rows; y++)
871 {
872 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
873 if (p == (const Quantum *) NULL)
874 break;
875 for (x=0; x < (ssize_t) columns; x++)
876 {
877 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
878 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
879 *q++=(float) (QuantumScale*GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +0000880 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000881 }
882 }
883 break;
884 }
885 if (LocaleCompare(map,"BGRA") == 0)
886 {
887 for (y=0; y < (ssize_t) rows; y++)
888 {
889 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
890 if (p == (const Quantum *) NULL)
891 break;
892 for (x=0; x < (ssize_t) columns; x++)
893 {
894 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
895 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
896 *q++=(float) (QuantumScale*GetPixelRed(image,p));
897 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000898 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000899 }
900 }
901 break;
902 }
903 if (LocaleCompare(map,"BGRP") == 0)
904 {
905 for (y=0; y < (ssize_t) rows; y++)
906 {
907 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
908 if (p == (const Quantum *) NULL)
909 break;
910 for (x=0; x < (ssize_t) columns; x++)
911 {
912 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
913 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
914 *q++=(float) (QuantumScale*GetPixelRed(image,p));
915 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000916 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000917 }
918 }
919 break;
920 }
921 if (LocaleCompare(map,"I") == 0)
922 {
923 for (y=0; y < (ssize_t) rows; y++)
924 {
925 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
926 if (p == (const Quantum *) NULL)
927 break;
928 for (x=0; x < (ssize_t) columns; x++)
929 {
930 *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +0000931 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000932 }
933 }
934 break;
935 }
936 if (LocaleCompare(map,"RGB") == 0)
937 {
938 for (y=0; y < (ssize_t) rows; y++)
939 {
940 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
941 if (p == (const Quantum *) NULL)
942 break;
943 for (x=0; x < (ssize_t) columns; x++)
944 {
945 *q++=(float) (QuantumScale*GetPixelRed(image,p));
946 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
947 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +0000948 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000949 }
950 }
951 break;
952 }
953 if (LocaleCompare(map,"RGBA") == 0)
954 {
955 for (y=0; y < (ssize_t) rows; y++)
956 {
957 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
958 if (p == (const Quantum *) NULL)
959 break;
960 for (x=0; x < (ssize_t) columns; x++)
961 {
962 *q++=(float) (QuantumScale*GetPixelRed(image,p));
963 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
964 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
965 *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +0000966 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000967 }
968 }
969 break;
970 }
971 if (LocaleCompare(map,"RGBP") == 0)
972 {
973 for (y=0; y < (ssize_t) rows; y++)
974 {
975 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
976 if (p == (const Quantum *) NULL)
977 break;
978 for (x=0; x < (ssize_t) columns; x++)
979 {
980 *q++=(float) (QuantumScale*GetPixelRed(image,p));
981 *q++=(float) (QuantumScale*GetPixelGreen(image,p));
982 *q++=(float) (QuantumScale*GetPixelBlue(image,p));
983 *q++=0.0;
cristyed231572011-07-14 02:18:59 +0000984 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +0000985 }
986 }
987 break;
988 }
989 for (y=0; y < (ssize_t) rows; y++)
990 {
991 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
992 if (p == (const Quantum *) NULL)
993 break;
994 for (x=0; x < (ssize_t) columns; x++)
995 {
996 for (i=0; i < (ssize_t) length; i++)
997 {
998 *q=0;
999 switch (quantum_map[i])
1000 {
1001 case RedQuantum:
1002 case CyanQuantum:
1003 {
1004 *q=(float) (QuantumScale*GetPixelRed(image,p));
1005 break;
1006 }
1007 case GreenQuantum:
1008 case MagentaQuantum:
1009 {
1010 *q=(float) (QuantumScale*GetPixelGreen(image,p));
1011 break;
1012 }
1013 case BlueQuantum:
1014 case YellowQuantum:
1015 {
1016 *q=(float) (QuantumScale*GetPixelBlue(image,p));
1017 break;
1018 }
1019 case AlphaQuantum:
1020 {
1021 *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1022 break;
1023 }
1024 case OpacityQuantum:
1025 {
1026 *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1027 break;
1028 }
1029 case BlackQuantum:
1030 {
1031 if (image->colorspace == CMYKColorspace)
1032 *q=(float) (QuantumScale* GetPixelBlack(image,p));
1033 break;
1034 }
1035 case IndexQuantum:
1036 {
1037 *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1038 break;
1039 }
1040 default:
1041 *q=0;
1042 }
1043 q++;
1044 }
cristyed231572011-07-14 02:18:59 +00001045 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001046 }
1047 }
1048 break;
1049 }
1050 case IntegerPixel:
1051 {
1052 register unsigned int
1053 *q;
1054
1055 q=(unsigned int *) pixels;
1056 if (LocaleCompare(map,"BGR") == 0)
1057 {
1058 for (y=0; y < (ssize_t) rows; y++)
1059 {
1060 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1061 if (p == (const Quantum *) NULL)
1062 break;
1063 for (x=0; x < (ssize_t) columns; x++)
1064 {
1065 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1066 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1067 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +00001068 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001069 }
1070 }
1071 break;
1072 }
1073 if (LocaleCompare(map,"BGRA") == 0)
1074 {
1075 for (y=0; y < (ssize_t) rows; y++)
1076 {
1077 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1078 if (p == (const Quantum *) NULL)
1079 break;
1080 for (x=0; x < (ssize_t) columns; x++)
1081 {
1082 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1083 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1084 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1085 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001086 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001087 }
1088 }
1089 break;
1090 }
1091 if (LocaleCompare(map,"BGRP") == 0)
1092 {
1093 for (y=0; y < (ssize_t) rows; y++)
1094 {
1095 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1096 if (p == (const Quantum *) NULL)
1097 break;
1098 for (x=0; x < (ssize_t) columns; x++)
1099 {
1100 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1101 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1102 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1103 *q++=0U;
cristyed231572011-07-14 02:18:59 +00001104 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001105 }
1106 }
1107 break;
1108 }
1109 if (LocaleCompare(map,"I") == 0)
1110 {
1111 for (y=0; y < (ssize_t) rows; y++)
1112 {
1113 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1114 if (p == (const Quantum *) NULL)
1115 break;
1116 for (x=0; x < (ssize_t) columns; x++)
1117 {
1118 *q++=(unsigned int) ScaleQuantumToLong(
1119 GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +00001120 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001121 }
1122 }
1123 break;
1124 }
1125 if (LocaleCompare(map,"RGB") == 0)
1126 {
1127 for (y=0; y < (ssize_t) rows; y++)
1128 {
1129 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1130 if (p == (const Quantum *) NULL)
1131 break;
1132 for (x=0; x < (ssize_t) columns; x++)
1133 {
1134 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1135 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1136 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +00001137 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001138 }
1139 }
1140 break;
1141 }
1142 if (LocaleCompare(map,"RGBA") == 0)
1143 {
1144 for (y=0; y < (ssize_t) rows; y++)
1145 {
1146 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1147 if (p == (const Quantum *) NULL)
1148 break;
1149 for (x=0; x < (ssize_t) columns; x++)
1150 {
1151 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1152 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1153 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1154 *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001155 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001156 }
1157 }
1158 break;
1159 }
1160 if (LocaleCompare(map,"RGBP") == 0)
1161 {
1162 for (y=0; y < (ssize_t) rows; y++)
1163 {
1164 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1165 if (p == (const Quantum *) NULL)
1166 break;
1167 for (x=0; x < (ssize_t) columns; x++)
1168 {
1169 *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1170 *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1171 *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1172 *q++=0U;
cristyed231572011-07-14 02:18:59 +00001173 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001174 }
1175 }
1176 break;
1177 }
1178 for (y=0; y < (ssize_t) rows; y++)
1179 {
1180 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1181 if (p == (const Quantum *) NULL)
1182 break;
1183 for (x=0; x < (ssize_t) columns; x++)
1184 {
1185 for (i=0; i < (ssize_t) length; i++)
1186 {
1187 *q=0;
1188 switch (quantum_map[i])
1189 {
1190 case RedQuantum:
1191 case CyanQuantum:
1192 {
1193 *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
1194 break;
1195 }
1196 case GreenQuantum:
1197 case MagentaQuantum:
1198 {
1199 *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
1200 break;
1201 }
1202 case BlueQuantum:
1203 case YellowQuantum:
1204 {
1205 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
1206 break;
1207 }
1208 case AlphaQuantum:
1209 {
1210 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1211 break;
1212 }
1213 case OpacityQuantum:
1214 {
1215 *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
1216 break;
1217 }
1218 case BlackQuantum:
1219 {
1220 if (image->colorspace == CMYKColorspace)
1221 *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
1222 break;
1223 }
1224 case IndexQuantum:
1225 {
1226 *q=(unsigned int) ScaleQuantumToLong(
1227 GetPixelIntensity(image,p));
1228 break;
1229 }
1230 default:
1231 *q=0;
1232 }
1233 q++;
1234 }
cristyed231572011-07-14 02:18:59 +00001235 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001236 }
1237 }
1238 break;
1239 }
1240 case LongPixel:
1241 {
1242 register size_t
1243 *q;
1244
1245 q=(size_t *) pixels;
1246 if (LocaleCompare(map,"BGR") == 0)
1247 {
1248 for (y=0; y < (ssize_t) rows; y++)
1249 {
1250 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1251 if (p == (const Quantum *) NULL)
1252 break;
1253 for (x=0; x < (ssize_t) columns; x++)
1254 {
1255 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1256 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1257 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +00001258 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001259 }
1260 }
1261 break;
1262 }
1263 if (LocaleCompare(map,"BGRA") == 0)
1264 {
1265 for (y=0; y < (ssize_t) rows; y++)
1266 {
1267 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1268 if (p == (const Quantum *) NULL)
1269 break;
1270 for (x=0; x < (ssize_t) columns; x++)
1271 {
1272 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1273 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1274 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1275 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001276 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001277 }
1278 }
1279 break;
1280 }
1281 if (LocaleCompare(map,"BGRP") == 0)
1282 {
1283 for (y=0; y < (ssize_t) rows; y++)
1284 {
1285 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1286 if (p == (const Quantum *) NULL)
1287 break;
1288 for (x=0; x < (ssize_t) columns; x++)
1289 {
1290 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1291 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1292 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1293 *q++=0;
cristyed231572011-07-14 02:18:59 +00001294 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001295 }
1296 }
1297 break;
1298 }
1299 if (LocaleCompare(map,"I") == 0)
1300 {
1301 for (y=0; y < (ssize_t) rows; y++)
1302 {
1303 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1304 if (p == (const Quantum *) NULL)
1305 break;
1306 for (x=0; x < (ssize_t) columns; x++)
1307 {
1308 *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +00001309 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001310 }
1311 }
1312 break;
1313 }
1314 if (LocaleCompare(map,"RGB") == 0)
1315 {
1316 for (y=0; y < (ssize_t) rows; y++)
1317 {
1318 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1319 if (p == (const Quantum *) NULL)
1320 break;
1321 for (x=0; x < (ssize_t) columns; x++)
1322 {
1323 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1324 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1325 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +00001326 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001327 }
1328 }
1329 break;
1330 }
1331 if (LocaleCompare(map,"RGBA") == 0)
1332 {
1333 for (y=0; y < (ssize_t) rows; y++)
1334 {
1335 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1336 if (p == (const Quantum *) NULL)
1337 break;
1338 for (x=0; x < (ssize_t) columns; x++)
1339 {
1340 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1341 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1342 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1343 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001344 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001345 }
1346 }
1347 break;
1348 }
1349 if (LocaleCompare(map,"RGBP") == 0)
1350 {
1351 for (y=0; y < (ssize_t) rows; y++)
1352 {
1353 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1354 if (p == (const Quantum *) NULL)
1355 break;
1356 for (x=0; x < (ssize_t) columns; x++)
1357 {
1358 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1359 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1360 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1361 *q++=0;
cristyed231572011-07-14 02:18:59 +00001362 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001363 }
1364 }
1365 break;
1366 }
1367 for (y=0; y < (ssize_t) rows; y++)
1368 {
1369 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1370 if (p == (const Quantum *) NULL)
1371 break;
1372 for (x=0; x < (ssize_t) columns; x++)
1373 {
1374 for (i=0; i < (ssize_t) length; i++)
1375 {
1376 *q=0;
1377 switch (quantum_map[i])
1378 {
1379 case RedQuantum:
1380 case CyanQuantum:
1381 {
1382 *q=ScaleQuantumToLong(GetPixelRed(image,p));
1383 break;
1384 }
1385 case GreenQuantum:
1386 case MagentaQuantum:
1387 {
1388 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1389 break;
1390 }
1391 case BlueQuantum:
1392 case YellowQuantum:
1393 {
1394 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1395 break;
1396 }
1397 case AlphaQuantum:
1398 {
1399 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1400 break;
1401 }
1402 case OpacityQuantum:
1403 {
1404 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1405 break;
1406 }
1407 case BlackQuantum:
1408 {
1409 if (image->colorspace == CMYKColorspace)
1410 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1411 break;
1412 }
1413 case IndexQuantum:
1414 {
1415 *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
1416 break;
1417 }
1418 default:
1419 break;
1420 }
1421 q++;
1422 }
cristyed231572011-07-14 02:18:59 +00001423 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001424 }
1425 }
1426 break;
1427 }
1428 case QuantumPixel:
1429 {
1430 register Quantum
1431 *q;
1432
1433 q=(Quantum *) pixels;
1434 if (LocaleCompare(map,"BGR") == 0)
1435 {
1436 for (y=0; y < (ssize_t) rows; y++)
1437 {
1438 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1439 if (p == (const Quantum *) NULL)
1440 break;
1441 for (x=0; x < (ssize_t) columns; x++)
1442 {
1443 *q++=GetPixelBlue(image,p);
1444 *q++=GetPixelGreen(image,p);
1445 *q++=GetPixelRed(image,p);
cristyed231572011-07-14 02:18:59 +00001446 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001447 }
1448 }
1449 break;
1450 }
1451 if (LocaleCompare(map,"BGRA") == 0)
1452 {
1453 for (y=0; y < (ssize_t) rows; y++)
1454 {
1455 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1456 if (p == (const Quantum *) NULL)
1457 break;
1458 for (x=0; x < (ssize_t) columns; x++)
1459 {
1460 *q++=GetPixelBlue(image,p);
1461 *q++=GetPixelGreen(image,p);
1462 *q++=GetPixelRed(image,p);
1463 *q++=(Quantum) (GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001464 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001465 }
1466 }
1467 break;
1468 }
1469 if (LocaleCompare(map,"BGRP") == 0)
1470 {
1471 for (y=0; y < (ssize_t) rows; y++)
1472 {
1473 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1474 if (p == (const Quantum *) NULL)
1475 break;
1476 for (x=0; x < (ssize_t) columns; x++)
1477 {
1478 *q++=GetPixelBlue(image,p);
1479 *q++=GetPixelGreen(image,p);
1480 *q++=GetPixelRed(image,p);
1481 *q++=(Quantum) 0;
cristyed231572011-07-14 02:18:59 +00001482 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001483 }
1484 }
1485 break;
1486 }
1487 if (LocaleCompare(map,"I") == 0)
1488 {
1489 for (y=0; y < (ssize_t) rows; y++)
1490 {
1491 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1492 if (p == (const Quantum *) NULL)
1493 break;
1494 for (x=0; x < (ssize_t) columns; x++)
1495 {
1496 *q++=GetPixelIntensity(image,p);
cristyed231572011-07-14 02:18:59 +00001497 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001498 }
1499 }
1500 break;
1501 }
1502 if (LocaleCompare(map,"RGB") == 0)
1503 {
1504 for (y=0; y < (ssize_t) rows; y++)
1505 {
1506 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1507 if (p == (const Quantum *) NULL)
1508 break;
1509 for (x=0; x < (ssize_t) columns; x++)
1510 {
1511 *q++=GetPixelRed(image,p);
1512 *q++=GetPixelGreen(image,p);
1513 *q++=GetPixelBlue(image,p);
cristyed231572011-07-14 02:18:59 +00001514 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001515 }
1516 }
1517 break;
1518 }
1519 if (LocaleCompare(map,"RGBA") == 0)
1520 {
1521 for (y=0; y < (ssize_t) rows; y++)
1522 {
1523 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1524 if (p == (const Quantum *) NULL)
1525 break;
1526 for (x=0; x < (ssize_t) columns; x++)
1527 {
1528 *q++=GetPixelRed(image,p);
1529 *q++=GetPixelGreen(image,p);
1530 *q++=GetPixelBlue(image,p);
1531 *q++=(Quantum) (GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001532 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001533 }
1534 }
1535 break;
1536 }
1537 if (LocaleCompare(map,"RGBP") == 0)
1538 {
1539 for (y=0; y < (ssize_t) rows; y++)
1540 {
1541 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1542 if (p == (const Quantum *) NULL)
1543 break;
1544 for (x=0; x < (ssize_t) columns; x++)
1545 {
1546 *q++=GetPixelRed(image,p);
1547 *q++=GetPixelGreen(image,p);
1548 *q++=GetPixelBlue(image,p);
1549 *q++=(Quantum) 0;
cristyed231572011-07-14 02:18:59 +00001550 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001551 }
1552 }
1553 break;
1554 }
1555 for (y=0; y < (ssize_t) rows; y++)
1556 {
1557 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1558 if (p == (const Quantum *) NULL)
1559 break;
1560 for (x=0; x < (ssize_t) columns; x++)
1561 {
1562 for (i=0; i < (ssize_t) length; i++)
1563 {
1564 *q=(Quantum) 0;
1565 switch (quantum_map[i])
1566 {
1567 case RedQuantum:
1568 case CyanQuantum:
1569 {
1570 *q=GetPixelRed(image,p);
1571 break;
1572 }
1573 case GreenQuantum:
1574 case MagentaQuantum:
1575 {
1576 *q=GetPixelGreen(image,p);
1577 break;
1578 }
1579 case BlueQuantum:
1580 case YellowQuantum:
1581 {
1582 *q=GetPixelBlue(image,p);
1583 break;
1584 }
1585 case AlphaQuantum:
1586 {
1587 *q=(Quantum) (GetPixelAlpha(image,p));
1588 break;
1589 }
1590 case OpacityQuantum:
1591 {
1592 *q=GetPixelAlpha(image,p);
1593 break;
1594 }
1595 case BlackQuantum:
1596 {
1597 if (image->colorspace == CMYKColorspace)
1598 *q=GetPixelBlack(image,p);
1599 break;
1600 }
1601 case IndexQuantum:
1602 {
1603 *q=(GetPixelIntensity(image,p));
1604 break;
1605 }
1606 default:
1607 *q=(Quantum) 0;
1608 }
1609 q++;
1610 }
cristyed231572011-07-14 02:18:59 +00001611 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001612 }
1613 }
1614 break;
1615 }
1616 case ShortPixel:
1617 {
1618 register unsigned short
1619 *q;
1620
1621 q=(unsigned short *) pixels;
1622 if (LocaleCompare(map,"BGR") == 0)
1623 {
1624 for (y=0; y < (ssize_t) rows; y++)
1625 {
1626 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1627 if (p == (const Quantum *) NULL)
1628 break;
1629 for (x=0; x < (ssize_t) columns; x++)
1630 {
1631 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1632 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1633 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
cristyed231572011-07-14 02:18:59 +00001634 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001635 }
1636 }
1637 break;
1638 }
1639 if (LocaleCompare(map,"BGRA") == 0)
1640 {
1641 for (y=0; y < (ssize_t) rows; y++)
1642 {
1643 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1644 if (p == (const Quantum *) NULL)
1645 break;
1646 for (x=0; x < (ssize_t) columns; x++)
1647 {
1648 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1649 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1650 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1651 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001652 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001653 }
1654 }
1655 break;
1656 }
1657 if (LocaleCompare(map,"BGRP") == 0)
1658 {
1659 for (y=0; y < (ssize_t) rows; y++)
1660 {
1661 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1662 if (p == (const Quantum *) NULL)
1663 break;
1664 for (x=0; x < (ssize_t) columns; x++)
1665 {
1666 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1667 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1668 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1669 *q++=0;
cristyed231572011-07-14 02:18:59 +00001670 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001671 }
1672 }
1673 break;
1674 }
1675 if (LocaleCompare(map,"I") == 0)
1676 {
1677 for (y=0; y < (ssize_t) rows; y++)
1678 {
1679 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1680 if (p == (const Quantum *) NULL)
1681 break;
1682 for (x=0; x < (ssize_t) columns; x++)
1683 {
1684 *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
cristyed231572011-07-14 02:18:59 +00001685 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001686 }
1687 }
1688 break;
1689 }
1690 if (LocaleCompare(map,"RGB") == 0)
1691 {
1692 for (y=0; y < (ssize_t) rows; y++)
1693 {
1694 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1695 if (p == (const Quantum *) NULL)
1696 break;
1697 for (x=0; x < (ssize_t) columns; x++)
1698 {
1699 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1700 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1701 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
cristyed231572011-07-14 02:18:59 +00001702 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001703 }
1704 }
1705 break;
1706 }
1707 if (LocaleCompare(map,"RGBA") == 0)
1708 {
1709 for (y=0; y < (ssize_t) rows; y++)
1710 {
1711 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1712 if (p == (const Quantum *) NULL)
1713 break;
1714 for (x=0; x < (ssize_t) columns; x++)
1715 {
1716 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1717 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1718 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1719 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
cristyed231572011-07-14 02:18:59 +00001720 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001721 }
1722 }
1723 break;
1724 }
1725 if (LocaleCompare(map,"RGBP") == 0)
1726 {
1727 for (y=0; y < (ssize_t) rows; y++)
1728 {
1729 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1730 if (p == (const Quantum *) NULL)
1731 break;
1732 for (x=0; x < (ssize_t) columns; x++)
1733 {
1734 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1735 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1736 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1737 *q++=0;
cristyed231572011-07-14 02:18:59 +00001738 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001739 }
1740 }
1741 break;
1742 }
1743 for (y=0; y < (ssize_t) rows; y++)
1744 {
1745 p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
1746 if (p == (const Quantum *) NULL)
1747 break;
1748 for (x=0; x < (ssize_t) columns; x++)
1749 {
1750 for (i=0; i < (ssize_t) length; i++)
1751 {
1752 *q=0;
1753 switch (quantum_map[i])
1754 {
1755 case RedQuantum:
1756 case CyanQuantum:
1757 {
1758 *q=ScaleQuantumToShort(GetPixelRed(image,p));
1759 break;
1760 }
1761 case GreenQuantum:
1762 case MagentaQuantum:
1763 {
1764 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1765 break;
1766 }
1767 case BlueQuantum:
1768 case YellowQuantum:
1769 {
1770 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1771 break;
1772 }
1773 case AlphaQuantum:
1774 {
1775 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1776 break;
1777 }
1778 case OpacityQuantum:
1779 {
1780 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1781 break;
1782 }
1783 case BlackQuantum:
1784 {
1785 if (image->colorspace == CMYKColorspace)
1786 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1787 break;
1788 }
1789 case IndexQuantum:
1790 {
1791 *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
1792 break;
1793 }
1794 default:
1795 break;
1796 }
1797 q++;
1798 }
cristyed231572011-07-14 02:18:59 +00001799 p+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00001800 }
1801 }
1802 break;
1803 }
1804 default:
1805 {
1806 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1807 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1808 "UnrecognizedPixelMap","`%s'",map);
1809 break;
1810 }
1811 }
1812 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1813 return(MagickTrue);
1814}
1815
1816/*
1817%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1818% %
1819% %
1820% %
cristyaa8634f2011-10-01 13:25:12 +00001821% G e t P i x e l I n f o %
cristy4c08aed2011-07-01 19:47:50 +00001822% %
1823% %
1824% %
1825%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1826%
1827% GetPixelInfo() initializes the PixelInfo structure.
1828%
1829% The format of the GetPixelInfo method is:
1830%
1831% GetPixelInfo(const Image *image,PixelInfo *pixel)
1832%
1833% A description of each parameter follows:
1834%
1835% o image: the image.
1836%
cristy101ab702011-10-13 13:06:32 +00001837% o pixel: Specifies a pointer to a PixelInfo structure.
cristy4c08aed2011-07-01 19:47:50 +00001838%
1839*/
cristyaa8634f2011-10-01 13:25:12 +00001840MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
cristy4c08aed2011-07-01 19:47:50 +00001841{
1842 pixel->storage_class=DirectClass;
1843 pixel->colorspace=RGBColorspace;
1844 pixel->matte=MagickFalse;
1845 pixel->fuzz=0.0;
1846 pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
1847 pixel->red=0.0;
1848 pixel->green=0.0;
1849 pixel->blue=0.0;
1850 pixel->black=0.0;
1851 pixel->alpha=(MagickRealType) OpaqueAlpha;
1852 pixel->index=0.0;
1853 if (image == (const Image *) NULL)
1854 return;
1855 pixel->storage_class=image->storage_class;
1856 pixel->colorspace=image->colorspace;
1857 pixel->matte=image->matte;
1858 pixel->depth=image->depth;
1859 pixel->fuzz=image->fuzz;
1860}
1861
1862/*
1863%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864% %
1865% %
1866% %
1867% I m p o r t I m a g e P i x e l s %
1868% %
1869% %
1870% %
1871%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1872%
1873% ImportImagePixels() accepts pixel data and stores in the image at the
1874% location you specify. The method returns MagickTrue on success otherwise
1875% MagickFalse if an error is encountered. The pixel data can be either char,
1876% short int, int, ssize_t, float, or double in the order specified by map.
1877%
1878% Suppose your want to upload the first scanline of a 640x480 image from
1879% character data in red-green-blue order:
1880%
1881% ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
1882%
1883% The format of the ImportImagePixels method is:
1884%
1885% MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset,
1886% const ssize_t y_offset,const size_t columns,
1887% const size_t rows,const char *map,const StorageType type,
cristy018f07f2011-09-04 21:15:19 +00001888% const void *pixels,ExceptionInfo *exception)
cristy4c08aed2011-07-01 19:47:50 +00001889%
1890% A description of each parameter follows:
1891%
1892% o image: the image.
1893%
1894% o x_offset,y_offset,columns,rows: These values define the perimeter
1895% of a region of pixels you want to define.
1896%
1897% o map: This string reflects the expected ordering of the pixel array.
1898% It can be any combination or order of R = red, G = green, B = blue,
1899% A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
1900% Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
1901% P = pad.
1902%
1903% o type: Define the data type of the pixels. Float and double types are
1904% normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
1905% types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
1906% DoublePixel.
1907%
1908% o pixels: This array of values contain the pixel components as defined by
1909% map and type. You must preallocate this array where the expected
1910% length varies depending on the values of width, height, map, and type.
1911%
cristy018f07f2011-09-04 21:15:19 +00001912% o exception: return any errors or warnings in this structure.
1913%
cristy4c08aed2011-07-01 19:47:50 +00001914*/
1915MagickExport MagickBooleanType ImportImagePixels(Image *image,
1916 const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
1917 const size_t rows,const char *map,const StorageType type,
cristy018f07f2011-09-04 21:15:19 +00001918 const void *pixels,ExceptionInfo *exception)
cristy4c08aed2011-07-01 19:47:50 +00001919{
cristy4c08aed2011-07-01 19:47:50 +00001920 QuantumType
1921 *quantum_map;
1922
1923 register Quantum
1924 *q;
1925
1926 register ssize_t
1927 i,
1928 x;
1929
1930 size_t
1931 length;
1932
1933 ssize_t
1934 y;
1935
1936 /*
1937 Allocate image structure.
1938 */
1939 assert(image != (Image *) NULL);
1940 assert(image->signature == MagickSignature);
1941 if (image->debug != MagickFalse)
1942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1943 length=strlen(map);
1944 quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1945 if (quantum_map == (QuantumType *) NULL)
1946 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1947 image->filename);
1948 for (i=0; i < (ssize_t) length; i++)
1949 {
1950 switch (map[i])
1951 {
1952 case 'a':
1953 case 'A':
1954 {
1955 quantum_map[i]=AlphaQuantum;
1956 image->matte=MagickTrue;
1957 break;
1958 }
1959 case 'B':
1960 case 'b':
1961 {
1962 quantum_map[i]=BlueQuantum;
1963 break;
1964 }
1965 case 'C':
1966 case 'c':
1967 {
1968 quantum_map[i]=CyanQuantum;
cristy63240882011-08-05 19:05:27 +00001969 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00001970 break;
1971 }
1972 case 'g':
1973 case 'G':
1974 {
1975 quantum_map[i]=GreenQuantum;
1976 break;
1977 }
1978 case 'K':
1979 case 'k':
1980 {
1981 quantum_map[i]=BlackQuantum;
cristy63240882011-08-05 19:05:27 +00001982 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00001983 break;
1984 }
1985 case 'I':
1986 case 'i':
1987 {
1988 quantum_map[i]=IndexQuantum;
1989 break;
1990 }
1991 case 'm':
1992 case 'M':
1993 {
1994 quantum_map[i]=MagentaQuantum;
cristy63240882011-08-05 19:05:27 +00001995 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00001996 break;
1997 }
1998 case 'O':
1999 case 'o':
2000 {
2001 quantum_map[i]=OpacityQuantum;
2002 image->matte=MagickTrue;
2003 break;
2004 }
2005 case 'P':
2006 case 'p':
2007 {
2008 quantum_map[i]=UndefinedQuantum;
2009 break;
2010 }
2011 case 'R':
2012 case 'r':
2013 {
2014 quantum_map[i]=RedQuantum;
2015 break;
2016 }
2017 case 'Y':
2018 case 'y':
2019 {
2020 quantum_map[i]=YellowQuantum;
cristy63240882011-08-05 19:05:27 +00002021 (void) SetImageColorspace(image,CMYKColorspace,exception);
cristy4c08aed2011-07-01 19:47:50 +00002022 break;
2023 }
2024 default:
2025 {
2026 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
cristy63240882011-08-05 19:05:27 +00002027 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2028 "UnrecognizedPixelMap","`%s'",map);
cristy4c08aed2011-07-01 19:47:50 +00002029 return(MagickFalse);
2030 }
2031 }
2032 }
cristy63240882011-08-05 19:05:27 +00002033 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00002034 return(MagickFalse);
2035 /*
2036 Transfer the pixels from the pixel datarray to the image.
2037 */
cristy4c08aed2011-07-01 19:47:50 +00002038 switch (type)
2039 {
2040 case CharPixel:
2041 {
2042 register const unsigned char
2043 *p;
2044
2045 p=(const unsigned char *) pixels;
2046 if (LocaleCompare(map,"BGR") == 0)
2047 {
2048 for (y=0; y < (ssize_t) rows; y++)
2049 {
2050 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2051 if (q == (Quantum *) NULL)
2052 break;
2053 for (x=0; x < (ssize_t) columns; x++)
2054 {
2055 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2056 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2057 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002058 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002059 }
2060 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2061 break;
2062 }
2063 break;
2064 }
2065 if (LocaleCompare(map,"BGRA") == 0)
2066 {
2067 for (y=0; y < (ssize_t) rows; y++)
2068 {
2069 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2070 if (q == (Quantum *) NULL)
2071 break;
2072 for (x=0; x < (ssize_t) columns; x++)
2073 {
2074 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2075 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2076 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2077 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002078 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002079 }
2080 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2081 break;
2082 }
2083 break;
2084 }
2085 if (LocaleCompare(map,"BGRO") == 0)
2086 {
2087 for (y=0; y < (ssize_t) rows; y++)
2088 {
2089 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2090 if (q == (Quantum *) NULL)
2091 break;
2092 for (x=0; x < (ssize_t) columns; x++)
2093 {
2094 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2095 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2096 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2097 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002098 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002099 }
2100 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2101 break;
2102 }
2103 break;
2104 }
2105 if (LocaleCompare(map,"BGRP") == 0)
2106 {
2107 for (y=0; y < (ssize_t) rows; y++)
2108 {
2109 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2110 if (q == (Quantum *) NULL)
2111 break;
2112 for (x=0; x < (ssize_t) columns; x++)
2113 {
2114 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2115 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2116 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2117 p++;
cristyed231572011-07-14 02:18:59 +00002118 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002119 }
2120 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2121 break;
2122 }
2123 break;
2124 }
2125 if (LocaleCompare(map,"I") == 0)
2126 {
2127 for (y=0; y < (ssize_t) rows; y++)
2128 {
2129 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2130 if (q == (Quantum *) NULL)
2131 break;
2132 for (x=0; x < (ssize_t) columns; x++)
2133 {
2134 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2135 SetPixelGreen(image,GetPixelRed(image,q),q);
2136 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00002137 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002138 }
2139 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2140 break;
2141 }
2142 break;
2143 }
2144 if (LocaleCompare(map,"RGB") == 0)
2145 {
2146 for (y=0; y < (ssize_t) rows; y++)
2147 {
2148 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2149 if (q == (Quantum *) NULL)
2150 break;
2151 for (x=0; x < (ssize_t) columns; x++)
2152 {
2153 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2154 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2155 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002156 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002157 }
2158 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2159 break;
2160 }
2161 break;
2162 }
2163 if (LocaleCompare(map,"RGBA") == 0)
2164 {
2165 for (y=0; y < (ssize_t) rows; y++)
2166 {
2167 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2168 if (q == (Quantum *) NULL)
2169 break;
2170 for (x=0; x < (ssize_t) columns; x++)
2171 {
2172 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2173 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2174 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2175 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002176 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002177 }
2178 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2179 break;
2180 }
2181 break;
2182 }
2183 if (LocaleCompare(map,"RGBO") == 0)
2184 {
2185 for (y=0; y < (ssize_t) rows; y++)
2186 {
2187 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2188 if (q == (Quantum *) NULL)
2189 break;
2190 for (x=0; x < (ssize_t) columns; x++)
2191 {
2192 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2193 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2194 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2195 SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002196 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002197 }
2198 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2199 break;
2200 }
2201 break;
2202 }
2203 if (LocaleCompare(map,"RGBP") == 0)
2204 {
2205 for (y=0; y < (ssize_t) rows; y++)
2206 {
2207 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2208 if (q == (Quantum *) NULL)
2209 break;
2210 for (x=0; x < (ssize_t) columns; x++)
2211 {
2212 SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2213 SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2214 SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2215 p++;
cristyed231572011-07-14 02:18:59 +00002216 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002217 }
2218 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2219 break;
2220 }
2221 break;
2222 }
2223 for (y=0; y < (ssize_t) rows; y++)
2224 {
2225 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2226 if (q == (Quantum *) NULL)
2227 break;
2228 for (x=0; x < (ssize_t) columns; x++)
2229 {
2230 for (i=0; i < (ssize_t) length; i++)
2231 {
2232 switch (quantum_map[i])
2233 {
2234 case RedQuantum:
2235 case CyanQuantum:
2236 {
2237 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2238 break;
2239 }
2240 case GreenQuantum:
2241 case MagentaQuantum:
2242 {
2243 SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2244 break;
2245 }
2246 case BlueQuantum:
2247 case YellowQuantum:
2248 {
2249 SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2250 break;
2251 }
2252 case AlphaQuantum:
2253 {
2254 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2255 break;
2256 }
2257 case OpacityQuantum:
2258 {
2259 SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2260 break;
2261 }
2262 case BlackQuantum:
2263 {
2264 SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2265 break;
2266 }
2267 case IndexQuantum:
2268 {
2269 SetPixelRed(image,ScaleCharToQuantum(*p),q);
2270 SetPixelGreen(image,GetPixelRed(image,q),q);
2271 SetPixelBlue(image,GetPixelRed(image,q),q);
2272 break;
2273 }
2274 default:
2275 break;
2276 }
2277 p++;
2278 }
cristyed231572011-07-14 02:18:59 +00002279 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002280 }
2281 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2282 break;
2283 }
2284 break;
2285 }
2286 case DoublePixel:
2287 {
2288 register const double
2289 *p;
2290
2291 p=(const double *) pixels;
2292 if (LocaleCompare(map,"BGR") == 0)
2293 {
2294 for (y=0; y < (ssize_t) rows; y++)
2295 {
2296 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2297 if (q == (Quantum *) NULL)
2298 break;
2299 for (x=0; x < (ssize_t) columns; x++)
2300 {
2301 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2302 (*p)),q);
2303 p++;
2304 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2305 (*p)),q);
2306 p++;
2307 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2308 (*p)),q);
2309 p++;
cristyed231572011-07-14 02:18:59 +00002310 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002311 }
2312 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2313 break;
2314 }
2315 break;
2316 }
2317 if (LocaleCompare(map,"BGRA") == 0)
2318 {
2319 for (y=0; y < (ssize_t) rows; y++)
2320 {
2321 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2322 if (q == (Quantum *) NULL)
2323 break;
2324 for (x=0; x < (ssize_t) columns; x++)
2325 {
2326 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2327 (*p)),q);
2328 p++;
2329 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2330 (*p)),q);
2331 p++;
2332 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2333 (*p)),q);
2334 p++;
2335 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2336 (*p)),q);
2337 p++;
cristyed231572011-07-14 02:18:59 +00002338 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002339 }
2340 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2341 break;
2342 }
2343 break;
2344 }
2345 if (LocaleCompare(map,"BGRP") == 0)
2346 {
2347 for (y=0; y < (ssize_t) rows; y++)
2348 {
2349 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2350 if (q == (Quantum *) NULL)
2351 break;
2352 for (x=0; x < (ssize_t) columns; x++)
2353 {
2354 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2355 (*p)),q);
2356 p++;
2357 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2358 (*p)),q);
2359 p++;
2360 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2361 (*p)),q);
2362 p++;
2363 p++;
cristyed231572011-07-14 02:18:59 +00002364 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002365 }
2366 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2367 break;
2368 }
2369 break;
2370 }
2371 if (LocaleCompare(map,"I") == 0)
2372 {
2373 for (y=0; y < (ssize_t) rows; y++)
2374 {
2375 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2376 if (q == (Quantum *) NULL)
2377 break;
2378 for (x=0; x < (ssize_t) columns; x++)
2379 {
2380 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2381 (*p)),q);
2382 SetPixelGreen(image,GetPixelRed(image,q),q);
2383 SetPixelBlue(image,GetPixelRed(image,q),q);
2384 p++;
cristyed231572011-07-14 02:18:59 +00002385 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002386 }
2387 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2388 break;
2389 }
2390 break;
2391 }
2392 if (LocaleCompare(map,"RGB") == 0)
2393 {
2394 for (y=0; y < (ssize_t) rows; y++)
2395 {
2396 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2397 if (q == (Quantum *) NULL)
2398 break;
2399 for (x=0; x < (ssize_t) columns; x++)
2400 {
2401 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2402 (*p)),q);
2403 p++;
2404 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2405 (*p)),q);
2406 p++;
2407 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2408 (*p)),q);
2409 p++;
cristyed231572011-07-14 02:18:59 +00002410 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002411 }
2412 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2413 break;
2414 }
2415 break;
2416 }
2417 if (LocaleCompare(map,"RGBA") == 0)
2418 {
2419 for (y=0; y < (ssize_t) rows; y++)
2420 {
2421 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2422 if (q == (Quantum *) NULL)
2423 break;
2424 for (x=0; x < (ssize_t) columns; x++)
2425 {
2426 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2427 (*p)),q);
2428 p++;
2429 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2430 (*p)),q);
2431 p++;
2432 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2433 (*p)),q);
2434 p++;
2435 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2436 (*p)),q);
2437 p++;
cristyed231572011-07-14 02:18:59 +00002438 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002439 }
2440 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2441 break;
2442 }
2443 break;
2444 }
2445 if (LocaleCompare(map,"RGBP") == 0)
2446 {
2447 for (y=0; y < (ssize_t) rows; y++)
2448 {
2449 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2450 if (q == (Quantum *) NULL)
2451 break;
2452 for (x=0; x < (ssize_t) columns; x++)
2453 {
2454 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2455 (*p)),q);
2456 p++;
2457 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2458 (*p)),q);
2459 p++;
2460 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2461 (*p)),q);
2462 p++;
cristyed231572011-07-14 02:18:59 +00002463 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002464 }
2465 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2466 break;
2467 }
2468 break;
2469 }
2470 for (y=0; y < (ssize_t) rows; y++)
2471 {
2472 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2473 if (q == (Quantum *) NULL)
2474 break;
2475 for (x=0; x < (ssize_t) columns; x++)
2476 {
2477 for (i=0; i < (ssize_t) length; i++)
2478 {
2479 switch (quantum_map[i])
2480 {
2481 case RedQuantum:
2482 case CyanQuantum:
2483 {
2484 SetPixelRed(image,ClampToQuantum((MagickRealType)
2485 QuantumRange*(*p)),q);
2486 break;
2487 }
2488 case GreenQuantum:
2489 case MagentaQuantum:
2490 {
2491 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2492 QuantumRange*(*p)),q);
2493 break;
2494 }
2495 case BlueQuantum:
2496 case YellowQuantum:
2497 {
2498 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2499 QuantumRange*(*p)),q);
2500 break;
2501 }
2502 case AlphaQuantum:
2503 {
2504 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2505 QuantumRange*(*p)),q);
2506 break;
2507 }
2508 case OpacityQuantum:
2509 {
2510 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2511 QuantumRange*(*p)),q);
2512 break;
2513 }
2514 case BlackQuantum:
2515 {
2516 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2517 QuantumRange*(*p)),q);
2518 break;
2519 }
2520 case IndexQuantum:
2521 {
2522 SetPixelRed(image,ClampToQuantum((MagickRealType)
2523 QuantumRange*(*p)),q);
2524 SetPixelGreen(image,GetPixelRed(image,q),q);
2525 SetPixelBlue(image,GetPixelRed(image,q),q);
2526 break;
2527 }
2528 default:
2529 break;
2530 }
2531 p++;
2532 }
cristyed231572011-07-14 02:18:59 +00002533 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002534 }
2535 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2536 break;
2537 }
2538 break;
2539 }
2540 case FloatPixel:
2541 {
2542 register const float
2543 *p;
2544
2545 p=(const float *) pixels;
2546 if (LocaleCompare(map,"BGR") == 0)
2547 {
2548 for (y=0; y < (ssize_t) rows; y++)
2549 {
2550 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2551 if (q == (Quantum *) NULL)
2552 break;
2553 for (x=0; x < (ssize_t) columns; x++)
2554 {
2555 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2556 (*p)),q);
2557 p++;
2558 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2559 (*p)),q);
2560 p++;
2561 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2562 (*p)),q);
2563 p++;
cristyed231572011-07-14 02:18:59 +00002564 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002565 }
2566 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2567 break;
2568 }
2569 break;
2570 }
2571 if (LocaleCompare(map,"BGRA") == 0)
2572 {
2573 for (y=0; y < (ssize_t) rows; y++)
2574 {
2575 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2576 if (q == (Quantum *) NULL)
2577 break;
2578 for (x=0; x < (ssize_t) columns; x++)
2579 {
2580 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2581 (*p)),q);
2582 p++;
2583 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2584 (*p)),q);
2585 p++;
2586 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2587 (*p)),q);
2588 p++;
2589 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2590 (*p)),q);
2591 p++;
cristyed231572011-07-14 02:18:59 +00002592 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002593 }
2594 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2595 break;
2596 }
2597 break;
2598 }
2599 if (LocaleCompare(map,"BGRP") == 0)
2600 {
2601 for (y=0; y < (ssize_t) rows; y++)
2602 {
2603 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2604 if (q == (Quantum *) NULL)
2605 break;
2606 for (x=0; x < (ssize_t) columns; x++)
2607 {
2608 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2609 (*p)),q);
2610 p++;
2611 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2612 (*p)),q);
2613 p++;
2614 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2615 (*p)),q);
2616 p++;
2617 p++;
cristyed231572011-07-14 02:18:59 +00002618 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002619 }
2620 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2621 break;
2622 }
2623 break;
2624 }
2625 if (LocaleCompare(map,"I") == 0)
2626 {
2627 for (y=0; y < (ssize_t) rows; y++)
2628 {
2629 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2630 if (q == (Quantum *) NULL)
2631 break;
2632 for (x=0; x < (ssize_t) columns; x++)
2633 {
2634 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2635 (*p)),q);
2636 SetPixelGreen(image,GetPixelRed(image,q),q);
2637 SetPixelBlue(image,GetPixelRed(image,q),q);
2638 p++;
cristyed231572011-07-14 02:18:59 +00002639 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002640 }
2641 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2642 break;
2643 }
2644 break;
2645 }
2646 if (LocaleCompare(map,"RGB") == 0)
2647 {
2648 for (y=0; y < (ssize_t) rows; y++)
2649 {
2650 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2651 if (q == (Quantum *) NULL)
2652 break;
2653 for (x=0; x < (ssize_t) columns; x++)
2654 {
2655 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2656 (*p)),q);
2657 p++;
2658 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2659 (*p)),q);
2660 p++;
2661 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2662 (*p)),q);
2663 p++;
cristyed231572011-07-14 02:18:59 +00002664 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002665 }
2666 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2667 break;
2668 }
2669 break;
2670 }
2671 if (LocaleCompare(map,"RGBA") == 0)
2672 {
2673 for (y=0; y < (ssize_t) rows; y++)
2674 {
2675 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2676 if (q == (Quantum *) NULL)
2677 break;
2678 for (x=0; x < (ssize_t) columns; x++)
2679 {
2680 SetPixelRed(image,ClampToQuantum((MagickRealType)
2681 QuantumRange*(*p)),q);
2682 p++;
2683 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2684 (*p)),q);
2685 p++;
2686 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2687 (*p)),q);
2688 p++;
2689 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2690 (*p)),q);
2691 p++;
cristyed231572011-07-14 02:18:59 +00002692 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002693 }
2694 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2695 break;
2696 }
2697 break;
2698 }
2699 if (LocaleCompare(map,"RGBP") == 0)
2700 {
2701 for (y=0; y < (ssize_t) rows; y++)
2702 {
2703 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2704 if (q == (Quantum *) NULL)
2705 break;
2706 for (x=0; x < (ssize_t) columns; x++)
2707 {
2708 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2709 (*p)),q);
2710 p++;
2711 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2712 (*p)),q);
2713 p++;
2714 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
2715 (*p)),q);
2716 p++;
cristyed231572011-07-14 02:18:59 +00002717 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002718 }
2719 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2720 break;
2721 }
2722 break;
2723 }
2724 for (y=0; y < (ssize_t) rows; y++)
2725 {
2726 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2727 if (q == (Quantum *) NULL)
2728 break;
2729 for (x=0; x < (ssize_t) columns; x++)
2730 {
2731 for (i=0; i < (ssize_t) length; i++)
2732 {
2733 switch (quantum_map[i])
2734 {
2735 case RedQuantum:
2736 case CyanQuantum:
2737 {
2738 SetPixelRed(image,ClampToQuantum((MagickRealType)
2739 QuantumRange*(*p)),q);
2740 break;
2741 }
2742 case GreenQuantum:
2743 case MagentaQuantum:
2744 {
2745 SetPixelGreen(image,ClampToQuantum((MagickRealType)
2746 QuantumRange*(*p)),q);
2747 break;
2748 }
2749 case BlueQuantum:
2750 case YellowQuantum:
2751 {
2752 SetPixelBlue(image,ClampToQuantum((MagickRealType)
2753 QuantumRange*(*p)),q);
2754 break;
2755 }
2756 case AlphaQuantum:
2757 {
2758 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2759 QuantumRange*(*p)),q);
2760 break;
2761 }
2762 case OpacityQuantum:
2763 {
2764 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2765 QuantumRange*(*p)),q);
2766 break;
2767 }
2768 case BlackQuantum:
2769 {
2770 SetPixelBlack(image,ClampToQuantum((MagickRealType)
2771 QuantumRange*(*p)),q);
2772 break;
2773 }
2774 case IndexQuantum:
2775 {
2776 SetPixelRed(image,ClampToQuantum((MagickRealType)
2777 QuantumRange*(*p)),q);
2778 SetPixelGreen(image,GetPixelRed(image,q),q);
2779 SetPixelBlue(image,GetPixelRed(image,q),q);
2780 break;
2781 }
2782 default:
2783 break;
2784 }
2785 p++;
2786 }
cristyed231572011-07-14 02:18:59 +00002787 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002788 }
2789 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2790 break;
2791 }
2792 break;
2793 }
2794 case IntegerPixel:
2795 {
2796 register const unsigned int
2797 *p;
2798
2799 p=(const unsigned int *) pixels;
2800 if (LocaleCompare(map,"BGR") == 0)
2801 {
2802 for (y=0; y < (ssize_t) rows; y++)
2803 {
2804 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2805 if (q == (Quantum *) NULL)
2806 break;
2807 for (x=0; x < (ssize_t) columns; x++)
2808 {
2809 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2810 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2811 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002812 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002813 }
2814 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2815 break;
2816 }
2817 break;
2818 }
2819 if (LocaleCompare(map,"BGRA") == 0)
2820 {
2821 for (y=0; y < (ssize_t) rows; y++)
2822 {
2823 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2824 if (q == (Quantum *) NULL)
2825 break;
2826 for (x=0; x < (ssize_t) columns; x++)
2827 {
2828 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2829 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2830 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2831 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002832 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002833 }
2834 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2835 break;
2836 }
2837 break;
2838 }
2839 if (LocaleCompare(map,"BGRP") == 0)
2840 {
2841 for (y=0; y < (ssize_t) rows; y++)
2842 {
2843 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2844 if (q == (Quantum *) NULL)
2845 break;
2846 for (x=0; x < (ssize_t) columns; x++)
2847 {
2848 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2849 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2850 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2851 p++;
cristyed231572011-07-14 02:18:59 +00002852 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002853 }
2854 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2855 break;
2856 }
2857 break;
2858 }
2859 if (LocaleCompare(map,"I") == 0)
2860 {
2861 for (y=0; y < (ssize_t) rows; y++)
2862 {
2863 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2864 if (q == (Quantum *) NULL)
2865 break;
2866 for (x=0; x < (ssize_t) columns; x++)
2867 {
2868 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2869 SetPixelGreen(image,GetPixelRed(image,q),q);
2870 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00002871 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002872 }
2873 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2874 break;
2875 }
2876 break;
2877 }
2878 if (LocaleCompare(map,"RGB") == 0)
2879 {
2880 for (y=0; y < (ssize_t) rows; y++)
2881 {
2882 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2883 if (q == (Quantum *) NULL)
2884 break;
2885 for (x=0; x < (ssize_t) columns; x++)
2886 {
2887 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2888 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2889 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002890 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002891 }
2892 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2893 break;
2894 }
2895 break;
2896 }
2897 if (LocaleCompare(map,"RGBA") == 0)
2898 {
2899 for (y=0; y < (ssize_t) rows; y++)
2900 {
2901 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2902 if (q == (Quantum *) NULL)
2903 break;
2904 for (x=0; x < (ssize_t) columns; x++)
2905 {
2906 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2907 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2908 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2909 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00002910 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002911 }
2912 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2913 break;
2914 }
2915 break;
2916 }
2917 if (LocaleCompare(map,"RGBP") == 0)
2918 {
2919 for (y=0; y < (ssize_t) rows; y++)
2920 {
2921 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2922 if (q == (Quantum *) NULL)
2923 break;
2924 for (x=0; x < (ssize_t) columns; x++)
2925 {
2926 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
2927 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
2928 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
2929 p++;
cristyed231572011-07-14 02:18:59 +00002930 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002931 }
2932 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2933 break;
2934 }
2935 break;
2936 }
2937 for (y=0; y < (ssize_t) rows; y++)
2938 {
2939 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
2940 if (q == (Quantum *) NULL)
2941 break;
2942 for (x=0; x < (ssize_t) columns; x++)
2943 {
2944 for (i=0; i < (ssize_t) length; i++)
2945 {
2946 switch (quantum_map[i])
2947 {
2948 case RedQuantum:
2949 case CyanQuantum:
2950 {
2951 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2952 break;
2953 }
2954 case GreenQuantum:
2955 case MagentaQuantum:
2956 {
2957 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
2958 break;
2959 }
2960 case BlueQuantum:
2961 case YellowQuantum:
2962 {
2963 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
2964 break;
2965 }
2966 case AlphaQuantum:
2967 {
2968 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2969 break;
2970 }
2971 case OpacityQuantum:
2972 {
2973 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
2974 break;
2975 }
2976 case BlackQuantum:
2977 {
2978 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
2979 break;
2980 }
2981 case IndexQuantum:
2982 {
2983 SetPixelRed(image,ScaleLongToQuantum(*p),q);
2984 SetPixelGreen(image,GetPixelRed(image,q),q);
2985 SetPixelBlue(image,GetPixelRed(image,q),q);
2986 break;
2987 }
2988 default:
2989 break;
2990 }
2991 p++;
2992 }
cristyed231572011-07-14 02:18:59 +00002993 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002994 }
2995 if (SyncAuthenticPixels(image,exception) == MagickFalse)
2996 break;
2997 }
2998 break;
2999 }
3000 case LongPixel:
3001 {
3002 register const unsigned int
3003 *p;
3004
3005 p=(const unsigned int *) pixels;
3006 if (LocaleCompare(map,"BGR") == 0)
3007 {
3008 for (y=0; y < (ssize_t) rows; y++)
3009 {
3010 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3011 if (q == (Quantum *) NULL)
3012 break;
3013 for (x=0; x < (ssize_t) columns; x++)
3014 {
3015 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3016 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3017 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003018 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003019 }
3020 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3021 break;
3022 }
3023 break;
3024 }
3025 if (LocaleCompare(map,"BGRA") == 0)
3026 {
3027 for (y=0; y < (ssize_t) rows; y++)
3028 {
3029 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3030 if (q == (Quantum *) NULL)
3031 break;
3032 for (x=0; x < (ssize_t) columns; x++)
3033 {
3034 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3035 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3036 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3037 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003038 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003039 }
3040 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3041 break;
3042 }
3043 break;
3044 }
3045 if (LocaleCompare(map,"BGRP") == 0)
3046 {
3047 for (y=0; y < (ssize_t) rows; y++)
3048 {
3049 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3050 if (q == (Quantum *) NULL)
3051 break;
3052 for (x=0; x < (ssize_t) columns; x++)
3053 {
3054 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3055 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3056 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3057 p++;
cristyed231572011-07-14 02:18:59 +00003058 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003059 }
3060 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3061 break;
3062 }
3063 break;
3064 }
3065 if (LocaleCompare(map,"I") == 0)
3066 {
3067 for (y=0; y < (ssize_t) rows; y++)
3068 {
3069 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3070 if (q == (Quantum *) NULL)
3071 break;
3072 for (x=0; x < (ssize_t) columns; x++)
3073 {
3074 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3075 SetPixelGreen(image,GetPixelRed(image,q),q);
3076 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00003077 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003078 }
3079 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3080 break;
3081 }
3082 break;
3083 }
3084 if (LocaleCompare(map,"RGB") == 0)
3085 {
3086 for (y=0; y < (ssize_t) rows; y++)
3087 {
3088 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3089 if (q == (Quantum *) NULL)
3090 break;
3091 for (x=0; x < (ssize_t) columns; x++)
3092 {
3093 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3094 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3095 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003096 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003097 }
3098 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3099 break;
3100 }
3101 break;
3102 }
3103 if (LocaleCompare(map,"RGBA") == 0)
3104 {
3105 for (y=0; y < (ssize_t) rows; y++)
3106 {
3107 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3108 if (q == (Quantum *) NULL)
3109 break;
3110 for (x=0; x < (ssize_t) columns; x++)
3111 {
3112 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3113 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3114 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3115 SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003116 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003117 }
3118 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3119 break;
3120 }
3121 break;
3122 }
3123 if (LocaleCompare(map,"RGBP") == 0)
3124 {
3125 for (y=0; y < (ssize_t) rows; y++)
3126 {
3127 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3128 if (q == (Quantum *) NULL)
3129 break;
3130 for (x=0; x < (ssize_t) columns; x++)
3131 {
3132 SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3133 SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3134 SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3135 p++;
cristyed231572011-07-14 02:18:59 +00003136 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003137 }
3138 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3139 break;
3140 }
3141 break;
3142 }
3143 for (y=0; y < (ssize_t) rows; y++)
3144 {
3145 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3146 if (q == (Quantum *) NULL)
3147 break;
3148 for (x=0; x < (ssize_t) columns; x++)
3149 {
3150 for (i=0; i < (ssize_t) length; i++)
3151 {
3152 switch (quantum_map[i])
3153 {
3154 case RedQuantum:
3155 case CyanQuantum:
3156 {
3157 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3158 break;
3159 }
3160 case GreenQuantum:
3161 case MagentaQuantum:
3162 {
3163 SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3164 break;
3165 }
3166 case BlueQuantum:
3167 case YellowQuantum:
3168 {
3169 SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3170 break;
3171 }
3172 case AlphaQuantum:
3173 {
3174 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3175 break;
3176 }
3177 case OpacityQuantum:
3178 {
3179 SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3180 break;
3181 }
3182 case BlackQuantum:
3183 {
3184 SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3185 break;
3186 }
3187 case IndexQuantum:
3188 {
3189 SetPixelRed(image,ScaleLongToQuantum(*p),q);
3190 SetPixelGreen(image,GetPixelRed(image,q),q);
3191 SetPixelBlue(image,GetPixelRed(image,q),q);
3192 break;
3193 }
3194 default:
3195 break;
3196 }
3197 p++;
3198 }
cristyed231572011-07-14 02:18:59 +00003199 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003200 }
3201 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3202 break;
3203 }
3204 break;
3205 }
3206 case QuantumPixel:
3207 {
3208 register const Quantum
3209 *p;
3210
3211 p=(const Quantum *) pixels;
3212 if (LocaleCompare(map,"BGR") == 0)
3213 {
3214 for (y=0; y < (ssize_t) rows; y++)
3215 {
3216 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3217 if (q == (Quantum *) NULL)
3218 break;
3219 for (x=0; x < (ssize_t) columns; x++)
3220 {
3221 SetPixelBlue(image,*p++,q);
3222 SetPixelGreen(image,*p++,q);
3223 SetPixelRed(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003224 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003225 }
3226 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3227 break;
3228 }
3229 break;
3230 }
3231 if (LocaleCompare(map,"BGRA") == 0)
3232 {
3233 for (y=0; y < (ssize_t) rows; y++)
3234 {
3235 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3236 if (q == (Quantum *) NULL)
3237 break;
3238 for (x=0; x < (ssize_t) columns; x++)
3239 {
3240 SetPixelBlue(image,*p++,q);
3241 SetPixelGreen(image,*p++,q);
3242 SetPixelRed(image,*p++,q);
3243 SetPixelAlpha(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003244 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003245 }
3246 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3247 break;
3248 }
3249 break;
3250 }
3251 if (LocaleCompare(map,"BGRP") == 0)
3252 {
3253 for (y=0; y < (ssize_t) rows; y++)
3254 {
3255 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3256 if (q == (Quantum *) NULL)
3257 break;
3258 for (x=0; x < (ssize_t) columns; x++)
3259 {
3260 SetPixelBlue(image,*p++,q);
3261 SetPixelGreen(image,*p++,q);
3262 SetPixelRed(image,*p++,q);
3263 p++;
cristyed231572011-07-14 02:18:59 +00003264 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003265 }
3266 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3267 break;
3268 }
3269 break;
3270 }
3271 if (LocaleCompare(map,"I") == 0)
3272 {
3273 for (y=0; y < (ssize_t) rows; y++)
3274 {
3275 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3276 if (q == (Quantum *) NULL)
3277 break;
3278 for (x=0; x < (ssize_t) columns; x++)
3279 {
3280 SetPixelRed(image,*p++,q);
3281 SetPixelGreen(image,GetPixelRed(image,q),q);
3282 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00003283 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003284 }
3285 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3286 break;
3287 }
3288 break;
3289 }
3290 if (LocaleCompare(map,"RGB") == 0)
3291 {
3292 for (y=0; y < (ssize_t) rows; y++)
3293 {
3294 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3295 if (q == (Quantum *) NULL)
3296 break;
3297 for (x=0; x < (ssize_t) columns; x++)
3298 {
3299 SetPixelRed(image,*p++,q);
3300 SetPixelGreen(image,*p++,q);
3301 SetPixelBlue(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003302 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003303 }
3304 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3305 break;
3306 }
3307 break;
3308 }
3309 if (LocaleCompare(map,"RGBA") == 0)
3310 {
3311 for (y=0; y < (ssize_t) rows; y++)
3312 {
3313 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3314 if (q == (Quantum *) NULL)
3315 break;
3316 for (x=0; x < (ssize_t) columns; x++)
3317 {
3318 SetPixelRed(image,*p++,q);
3319 SetPixelGreen(image,*p++,q);
3320 SetPixelBlue(image,*p++,q);
3321 SetPixelAlpha(image,*p++,q);
cristyed231572011-07-14 02:18:59 +00003322 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003323 }
3324 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3325 break;
3326 }
3327 break;
3328 }
3329 if (LocaleCompare(map,"RGBP") == 0)
3330 {
3331 for (y=0; y < (ssize_t) rows; y++)
3332 {
3333 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3334 if (q == (Quantum *) NULL)
3335 break;
3336 for (x=0; x < (ssize_t) columns; x++)
3337 {
3338 SetPixelRed(image,*p++,q);
3339 SetPixelGreen(image,*p++,q);
3340 SetPixelBlue(image,*p++,q);
3341 p++;
cristyed231572011-07-14 02:18:59 +00003342 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003343 }
3344 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3345 break;
3346 }
3347 break;
3348 }
3349 for (y=0; y < (ssize_t) rows; y++)
3350 {
3351 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3352 if (q == (Quantum *) NULL)
3353 break;
3354 for (x=0; x < (ssize_t) columns; x++)
3355 {
3356 for (i=0; i < (ssize_t) length; i++)
3357 {
3358 switch (quantum_map[i])
3359 {
3360 case RedQuantum:
3361 case CyanQuantum:
3362 {
3363 SetPixelRed(image,*p,q);
3364 break;
3365 }
3366 case GreenQuantum:
3367 case MagentaQuantum:
3368 {
3369 SetPixelGreen(image,*p,q);
3370 break;
3371 }
3372 case BlueQuantum:
3373 case YellowQuantum:
3374 {
3375 SetPixelBlue(image,*p,q);
3376 break;
3377 }
3378 case AlphaQuantum:
3379 {
3380 SetPixelAlpha(image,*p,q);
3381 break;
3382 }
3383 case OpacityQuantum:
3384 {
3385 SetPixelAlpha(image,*p,q);
3386 break;
3387 }
3388 case BlackQuantum:
3389 {
3390 SetPixelBlack(image,*p,q);
3391 break;
3392 }
3393 case IndexQuantum:
3394 {
3395 SetPixelRed(image,*p,q);
3396 SetPixelGreen(image,GetPixelRed(image,q),q);
3397 SetPixelBlue(image,GetPixelRed(image,q),q);
3398 break;
3399 }
3400 default:
3401 break;
3402 }
3403 p++;
3404 }
cristyed231572011-07-14 02:18:59 +00003405 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003406 }
3407 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3408 break;
3409 }
3410 break;
3411 }
3412 case ShortPixel:
3413 {
3414 register const unsigned short
3415 *p;
3416
3417 p=(const unsigned short *) pixels;
3418 if (LocaleCompare(map,"BGR") == 0)
3419 {
3420 for (y=0; y < (ssize_t) rows; y++)
3421 {
3422 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3423 if (q == (Quantum *) NULL)
3424 break;
3425 for (x=0; x < (ssize_t) columns; x++)
3426 {
3427 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3428 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3429 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003430 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003431 }
3432 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3433 break;
3434 }
3435 break;
3436 }
3437 if (LocaleCompare(map,"BGRA") == 0)
3438 {
3439 for (y=0; y < (ssize_t) rows; y++)
3440 {
3441 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3442 if (q == (Quantum *) NULL)
3443 break;
3444 for (x=0; x < (ssize_t) columns; x++)
3445 {
3446 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3447 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3448 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3449 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003450 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003451 }
3452 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3453 break;
3454 }
3455 break;
3456 }
3457 if (LocaleCompare(map,"BGRP") == 0)
3458 {
3459 for (y=0; y < (ssize_t) rows; y++)
3460 {
3461 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3462 if (q == (Quantum *) NULL)
3463 break;
3464 for (x=0; x < (ssize_t) columns; x++)
3465 {
3466 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3467 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3468 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3469 p++;
cristyed231572011-07-14 02:18:59 +00003470 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003471 }
3472 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3473 break;
3474 }
3475 break;
3476 }
3477 if (LocaleCompare(map,"I") == 0)
3478 {
3479 for (y=0; y < (ssize_t) rows; y++)
3480 {
3481 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3482 if (q == (Quantum *) NULL)
3483 break;
3484 for (x=0; x < (ssize_t) columns; x++)
3485 {
3486 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3487 SetPixelGreen(image,GetPixelRed(image,q),q);
3488 SetPixelBlue(image,GetPixelRed(image,q),q);
cristyed231572011-07-14 02:18:59 +00003489 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003490 }
3491 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3492 break;
3493 }
3494 break;
3495 }
3496 if (LocaleCompare(map,"RGB") == 0)
3497 {
3498 for (y=0; y < (ssize_t) rows; y++)
3499 {
3500 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3501 if (q == (Quantum *) NULL)
3502 break;
3503 for (x=0; x < (ssize_t) columns; x++)
3504 {
3505 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3506 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3507 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003508 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003509 }
3510 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3511 break;
3512 }
3513 break;
3514 }
3515 if (LocaleCompare(map,"RGBA") == 0)
3516 {
3517 for (y=0; y < (ssize_t) rows; y++)
3518 {
3519 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3520 if (q == (Quantum *) NULL)
3521 break;
3522 for (x=0; x < (ssize_t) columns; x++)
3523 {
3524 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3525 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3526 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3527 SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
cristyed231572011-07-14 02:18:59 +00003528 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003529 }
3530 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3531 break;
3532 }
3533 break;
3534 }
3535 if (LocaleCompare(map,"RGBP") == 0)
3536 {
3537 for (y=0; y < (ssize_t) rows; y++)
3538 {
3539 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3540 if (q == (Quantum *) NULL)
3541 break;
3542 for (x=0; x < (ssize_t) columns; x++)
3543 {
3544 SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3545 SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3546 SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3547 p++;
cristyed231572011-07-14 02:18:59 +00003548 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003549 }
3550 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3551 break;
3552 }
3553 break;
3554 }
3555 for (y=0; y < (ssize_t) rows; y++)
3556 {
3557 q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
3558 if (q == (Quantum *) NULL)
3559 break;
3560 for (x=0; x < (ssize_t) columns; x++)
3561 {
3562 for (i=0; i < (ssize_t) length; i++)
3563 {
3564 switch (quantum_map[i])
3565 {
3566 case RedQuantum:
3567 case CyanQuantum:
3568 {
3569 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3570 break;
3571 }
3572 case GreenQuantum:
3573 case MagentaQuantum:
3574 {
3575 SetPixelGreen(image,ScaleShortToQuantum(*p),q);
3576 break;
3577 }
3578 case BlueQuantum:
3579 case YellowQuantum:
3580 {
3581 SetPixelBlue(image,ScaleShortToQuantum(*p),q);
3582 break;
3583 }
3584 case AlphaQuantum:
3585 {
3586 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3587 break;
3588 }
3589 case OpacityQuantum:
3590 {
3591 SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
3592 break;
3593 }
3594 case BlackQuantum:
3595 {
3596 SetPixelBlack(image,ScaleShortToQuantum(*p),q);
3597 break;
3598 }
3599 case IndexQuantum:
3600 {
3601 SetPixelRed(image,ScaleShortToQuantum(*p),q);
3602 SetPixelGreen(image,GetPixelRed(image,q),q);
3603 SetPixelBlue(image,GetPixelRed(image,q),q);
3604 break;
3605 }
3606 default:
3607 break;
3608 }
3609 p++;
3610 }
cristyed231572011-07-14 02:18:59 +00003611 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00003612 }
3613 if (SyncAuthenticPixels(image,exception) == MagickFalse)
3614 break;
3615 }
3616 break;
3617 }
3618 default:
3619 {
3620 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
cristyc82a27b2011-10-21 01:07:16 +00003621 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3622 "UnrecognizedPixelMap","`%s'",map);
cristy4c08aed2011-07-01 19:47:50 +00003623 break;
3624 }
3625 }
3626 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
3627 return(MagickTrue);
3628}
3629
3630/*
3631%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3632% %
3633% %
3634% %
cristybd5a96c2011-08-21 00:04:26 +00003635+ 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 %
3636% %
3637% %
3638% %
3639%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3640%
3641% InitializePixelChannelMap() defines the standard pixel component map.
3642%
3643% The format of the InitializePixelChannelMap() method is:
3644%
3645% void InitializePixelChannelMap(Image *image)
3646%
3647% A description of each parameter follows:
3648%
3649% o image: the image.
3650%
3651*/
cristye2a912b2011-12-05 20:02:07 +00003652MagickExport void InitializePixelChannelMap(Image *image)
cristy77c30f52011-10-24 18:56:57 +00003653{
cristye2a912b2011-12-05 20:02:07 +00003654 PixelTrait
3655 trait;
3656
cristy77c30f52011-10-24 18:56:57 +00003657 register ssize_t
3658 i;
3659
3660 size_t
3661 n;
3662
3663 assert(image != (Image *) NULL);
3664 assert(image->signature == MagickSignature);
cristye2a912b2011-12-05 20:02:07 +00003665 (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
3666 sizeof(*image->channel_map));
3667 trait=UpdatePixelTrait;
3668 if (image->matte != MagickFalse)
cristy61f18ad2011-12-08 21:12:37 +00003669 trait=(PixelTrait) (trait | BlendPixelTrait);
cristy77c30f52011-10-24 18:56:57 +00003670 n=0;
cristye2a912b2011-12-05 20:02:07 +00003671 SetPixelChannelMap(image,RedPixelChannel,trait,n++);
3672 SetPixelChannelMap(image,GreenPixelChannel,trait,n++);
3673 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
3674if (0)
cristy77c30f52011-10-24 18:56:57 +00003675 if (image->colorspace == GRAYColorspace)
3676 {
3677 n=0;
cristye2a912b2011-12-05 20:02:07 +00003678 SetPixelChannelMap(image,RedPixelChannel,trait,n);
3679 SetPixelChannelMap(image,GreenPixelChannel,trait,n);
3680 SetPixelChannelMap(image,BluePixelChannel,trait,n++);
cristy77c30f52011-10-24 18:56:57 +00003681 }
3682 if (image->colorspace == CMYKColorspace)
cristye2a912b2011-12-05 20:02:07 +00003683 SetPixelChannelMap(image,BlackPixelChannel,trait,n++);
cristy77c30f52011-10-24 18:56:57 +00003684 if (image->matte != MagickFalse)
cristye2a912b2011-12-05 20:02:07 +00003685 SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++);
3686 if (image->storage_class == PseudoClass)
3687 SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++);
3688 assert((n+image->number_meta_channels) < MaxPixelChannels);
3689 for (i=0; i < (ssize_t) image->number_meta_channels; i++)
cristy61f18ad2011-12-08 21:12:37 +00003690 SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait,
cristye2a912b2011-12-05 20:02:07 +00003691 n++);
cristy77c30f52011-10-24 18:56:57 +00003692 image->number_channels=n;
3693 if (image->debug != MagickFalse)
3694 LogPixelChannels(image);
3695 (void) SetPixelChannelMask(image,image->channel_mask);
3696}
cristybd5a96c2011-08-21 00:04:26 +00003697
3698/*
3699%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3700% %
3701% %
3702% %
cristya085a432011-07-30 01:39:32 +00003703% I n t e r p o l a t e P i x e l C h a n n e l %
3704% %
3705% %
3706% %
3707%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3708%
cristy884f6002011-07-31 00:51:45 +00003709% InterpolatePixelChannel() applies a pixel interpolation method between a
3710% floating point coordinate and the pixels surrounding that coordinate. No
3711% pixel area resampling, or scaling of the result is performed.
cristya085a432011-07-30 01:39:32 +00003712%
3713% The format of the InterpolatePixelChannel method is:
3714%
3715% MagickBooleanType InterpolatePixelChannel(const Image *image,
cristy444eda62011-08-10 02:07:46 +00003716% const CacheView *image_view,const PixelChannel channel,
cristy5c4e2582011-09-11 19:21:03 +00003717% const PixelInterpolateMethod method,const double x,const double y,
cristya085a432011-07-30 01:39:32 +00003718% double *pixel,ExceptionInfo *exception)
3719%
3720% A description of each parameter follows:
3721%
3722% o image: the image.
3723%
3724% o image_view: the image view.
3725%
3726% o channel: the pixel channel to interpolate.
3727%
3728% o method: the pixel color interpolation method.
3729%
3730% o x,y: A double representing the current (x,y) position of the pixel.
3731%
3732% o pixel: return the interpolated pixel here.
3733%
3734% o exception: return any errors or warnings in this structure.
3735%
3736*/
cristy94ea1632011-07-30 20:40:25 +00003737
cristy884f6002011-07-31 00:51:45 +00003738static inline double MagickMax(const MagickRealType x,const MagickRealType y)
3739{
3740 if (x > y)
3741 return(x);
3742 return(y);
3743}
3744
3745static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3746{
3747 MagickRealType
3748 alpha,
3749 gamma;
3750
3751 alpha=MagickMax(x+2.0,0.0);
3752 gamma=1.0*alpha*alpha*alpha;
3753 alpha=MagickMax(x+1.0,0.0);
3754 gamma-=4.0*alpha*alpha*alpha;
3755 alpha=MagickMax(x+0.0,0.0);
3756 gamma+=6.0*alpha*alpha*alpha;
3757 alpha=MagickMax(x-1.0,0.0);
3758 gamma-=4.0*alpha*alpha*alpha;
3759 return(gamma/6.0);
3760}
3761
cristy94ea1632011-07-30 20:40:25 +00003762static inline double MeshInterpolate(const PointInfo *delta,const double p,
3763 const double x,const double y)
3764{
3765 return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
3766}
3767
cristy884f6002011-07-31 00:51:45 +00003768static inline ssize_t NearestNeighbor(const MagickRealType x)
3769{
3770 if (x >= 0.0)
3771 return((ssize_t) (x+0.5));
3772 return((ssize_t) (x-0.5));
3773}
3774
cristya085a432011-07-30 01:39:32 +00003775MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
3776 const CacheView *image_view,const PixelChannel channel,
cristy5c4e2582011-09-11 19:21:03 +00003777 const PixelInterpolateMethod method,const double x,const double y,
cristya085a432011-07-30 01:39:32 +00003778 double *pixel,ExceptionInfo *exception)
3779{
3780 MagickBooleanType
3781 status;
3782
cristy94ea1632011-07-30 20:40:25 +00003783 MagickRealType
3784 alpha[16],
cristy884f6002011-07-31 00:51:45 +00003785 gamma,
3786 pixels[16];
cristy94ea1632011-07-30 20:40:25 +00003787
3788 PixelTrait
3789 traits;
3790
cristy94ea1632011-07-30 20:40:25 +00003791 register const Quantum
3792 *p;
3793
3794 register ssize_t
3795 i;
3796
cristya085a432011-07-30 01:39:32 +00003797 ssize_t
3798 x_offset,
3799 y_offset;
3800
3801 assert(image != (Image *) NULL);
3802 assert(image != (Image *) NULL);
3803 assert(image->signature == MagickSignature);
3804 assert(image_view != (CacheView *) NULL);
3805 status=MagickTrue;
cristy884f6002011-07-31 00:51:45 +00003806 *pixel=0.0;
cristy94ea1632011-07-30 20:40:25 +00003807 traits=GetPixelChannelMapTraits(image,channel);
cristya085a432011-07-30 01:39:32 +00003808 x_offset=(ssize_t) floor(x);
3809 y_offset=(ssize_t) floor(y);
3810 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
3811 {
cristy884f6002011-07-31 00:51:45 +00003812 case AverageInterpolatePixel:
3813 {
3814 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3815 exception);
3816 if (p == (const Quantum *) NULL)
3817 {
3818 status=MagickFalse;
3819 break;
3820 }
cristy222b19c2011-08-04 01:35:11 +00003821 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00003822 for (i=0; i < 16; i++)
3823 {
3824 alpha[i]=1.0;
3825 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3826 }
3827 else
3828 for (i=0; i < 16; i++)
3829 {
3830 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3831 GetPixelChannels(image));
3832 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3833 }
3834 for (i=0; i < 16; i++)
3835 {
3836 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
3837 *pixel+=gamma*0.0625*pixels[i];
3838 }
3839 break;
3840 }
3841 case BicubicInterpolatePixel:
3842 {
3843 MagickRealType
3844 u[4],
3845 v[4];
3846
3847 PointInfo
3848 delta;
3849
3850 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
3851 exception);
3852 if (p == (const Quantum *) NULL)
3853 {
3854 status=MagickFalse;
3855 break;
3856 }
cristy222b19c2011-08-04 01:35:11 +00003857 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00003858 for (i=0; i < 16; i++)
3859 {
3860 alpha[i]=1.0;
3861 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3862 }
3863 else
3864 for (i=0; i < 16; i++)
3865 {
3866 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3867 GetPixelChannels(image));
3868 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3869 }
3870 delta.x=x-x_offset;
3871 delta.y=y-y_offset;
3872 for (i=0; i < 4; i++)
3873 {
3874 u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
3875 u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
3876 u[2]=pixels[4*i+2]-pixels[4*i+0];
3877 u[3]=pixels[4*i+1];
3878 v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
3879 u[2])+u[3];
3880 }
3881 u[0]=(v[3]-v[2])-(v[0]-v[1]);
3882 u[1]=(v[0]-v[1])-u[0];
3883 u[2]=v[2]-v[0];
3884 u[3]=v[1];
3885 *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
3886 u[2])+u[3];
3887 break;
3888 }
3889 case BilinearInterpolatePixel:
cristy94ea1632011-07-30 20:40:25 +00003890 default:
cristya085a432011-07-30 01:39:32 +00003891 {
cristy94ea1632011-07-30 20:40:25 +00003892 PointInfo
3893 delta,
cristy884f6002011-07-31 00:51:45 +00003894 epsilon;
3895
3896 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3897 if (p == (const Quantum *) NULL)
3898 {
3899 status=MagickFalse;
3900 break;
3901 }
cristy222b19c2011-08-04 01:35:11 +00003902 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00003903 for (i=0; i < 4; i++)
3904 {
3905 alpha[i]=1.0;
3906 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
3907 }
3908 else
3909 for (i=0; i < 4; i++)
3910 {
3911 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
3912 GetPixelChannels(image));
3913 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
3914 }
3915 delta.x=x-x_offset;
3916 delta.y=y-y_offset;
3917 epsilon.x=1.0-delta.x;
3918 epsilon.y=1.0-delta.y;
3919 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
3920 (epsilon.x*alpha[2]+delta.x*alpha[3])));
3921 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3922 *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
3923 (epsilon.x*pixels[2]+delta.x*pixels[3]));
3924 break;
3925 }
3926 case FilterInterpolatePixel:
3927 {
3928 CacheView
3929 *filter_view;
3930
3931 Image
3932 *excerpt_image,
3933 *filter_image;
3934
3935 RectangleInfo
3936 geometry;
3937
3938 geometry.width=4L;
3939 geometry.height=4L;
3940 geometry.x=x_offset-1;
3941 geometry.y=y_offset-1;
3942 excerpt_image=ExcerptImage(image,&geometry,exception);
3943 if (excerpt_image == (Image *) NULL)
3944 {
3945 status=MagickFalse;
3946 break;
3947 }
3948 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
3949 exception);
3950 excerpt_image=DestroyImage(excerpt_image);
3951 if (filter_image == (Image *) NULL)
3952 break;
3953 filter_view=AcquireCacheView(filter_image);
3954 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
3955 if (p == (const Quantum *) NULL)
3956 status=MagickFalse;
3957 else
cristy0beccfa2011-09-25 20:47:53 +00003958 *pixel=(double) GetPixelChannel(image,channel,p);
cristy884f6002011-07-31 00:51:45 +00003959 filter_view=DestroyCacheView(filter_view);
3960 filter_image=DestroyImage(filter_image);
3961 break;
3962 }
3963 case IntegerInterpolatePixel:
3964 {
3965 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
3966 if (p == (const Quantum *) NULL)
3967 {
3968 status=MagickFalse;
3969 break;
3970 }
cristy0beccfa2011-09-25 20:47:53 +00003971 *pixel=(double) GetPixelChannel(image,channel,p);
cristy884f6002011-07-31 00:51:45 +00003972 break;
3973 }
3974 case NearestNeighborInterpolatePixel:
3975 {
3976 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
3977 NearestNeighbor(y),1,1,exception);
3978 if (p == (const Quantum *) NULL)
3979 {
3980 status=MagickFalse;
3981 break;
3982 }
cristy0beccfa2011-09-25 20:47:53 +00003983 *pixel=(double) GetPixelChannel(image,channel,p);
cristy884f6002011-07-31 00:51:45 +00003984 break;
3985 }
3986 case MeshInterpolatePixel:
3987 {
3988 PointInfo
3989 delta,
cristy94ea1632011-07-30 20:40:25 +00003990 luminance;
3991
3992 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
3993 if (p == (const Quantum *) NULL)
3994 {
3995 status=MagickFalse;
3996 break;
3997 }
cristy222b19c2011-08-04 01:35:11 +00003998 if ((traits & BlendPixelTrait) == 0)
cristy94ea1632011-07-30 20:40:25 +00003999 for (i=0; i < 4; i++)
4000 {
4001 alpha[i]=1.0;
cristy884f6002011-07-31 00:51:45 +00004002 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
cristy94ea1632011-07-30 20:40:25 +00004003 }
4004 else
4005 for (i=0; i < 4; i++)
4006 {
4007 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4008 GetPixelChannels(image));
4009 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4010 }
cristy884f6002011-07-31 00:51:45 +00004011 delta.x=x-x_offset;
4012 delta.y=y-y_offset;
4013 luminance.x=GetPixelLuminance(image,p)-(double)
4014 GetPixelLuminance(image,p+3*GetPixelChannels(image));
cristy28474bf2011-09-11 23:32:52 +00004015 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
cristy884f6002011-07-31 00:51:45 +00004016 GetPixelLuminance(image,p+2*GetPixelChannels(image));
cristy94ea1632011-07-30 20:40:25 +00004017 if (fabs(luminance.x) < fabs(luminance.y))
4018 {
4019 /*
4020 Diagonal 0-3 NW-SE.
4021 */
4022 if (delta.x <= delta.y)
4023 {
4024 /*
4025 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4026 */
4027 delta.y=1.0-delta.y;
4028 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4029 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4030 *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4031 pixels[0]);
4032 }
4033 else
4034 {
4035 /*
4036 Top-right triangle (pixel: 1, diagonal: 0-3).
4037 */
4038 delta.x=1.0-delta.x;
4039 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4040 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4041 *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4042 pixels[3]);
4043 }
4044 }
4045 else
4046 {
4047 /*
4048 Diagonal 1-2 NE-SW.
4049 */
4050 if (delta.x <= (1.0-delta.y))
4051 {
4052 /*
4053 Top-left triangle (pixel: 0, diagonal: 1-2).
4054 */
4055 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4056 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4057 *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4058 pixels[2]);
4059 }
4060 else
4061 {
4062 /*
4063 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4064 */
4065 delta.x=1.0-delta.x;
4066 delta.y=1.0-delta.y;
4067 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4068 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4069 *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4070 pixels[1]);
4071 }
4072 }
cristya085a432011-07-30 01:39:32 +00004073 break;
4074 }
cristy884f6002011-07-31 00:51:45 +00004075 case SplineInterpolatePixel:
4076 {
4077 MagickRealType
4078 dx,
4079 dy;
4080
4081 PointInfo
4082 delta;
4083
4084 ssize_t
4085 j,
4086 n;
4087
4088 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4089 exception);
4090 if (p == (const Quantum *) NULL)
4091 {
4092 status=MagickFalse;
4093 break;
4094 }
cristy222b19c2011-08-04 01:35:11 +00004095 if ((traits & BlendPixelTrait) == 0)
cristy884f6002011-07-31 00:51:45 +00004096 for (i=0; i < 16; i++)
4097 {
4098 alpha[i]=1.0;
4099 pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4100 }
4101 else
4102 for (i=0; i < 16; i++)
4103 {
4104 alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4105 GetPixelChannels(image));
4106 pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4107 }
4108 delta.x=x-x_offset;
4109 delta.y=y-y_offset;
4110 n=0;
4111 for (i=(-1); i < 3L; i++)
4112 {
4113 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
4114 for (j=(-1); j < 3L; j++)
4115 {
4116 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
4117 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
4118 *pixel+=gamma*dx*dy*pixels[n];
4119 n++;
4120 }
4121 }
4122 break;
4123 }
cristya085a432011-07-30 01:39:32 +00004124 }
4125 return(status);
4126}
4127
4128/*
4129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4130% %
4131% %
4132% %
cristy5c4e2582011-09-11 19:21:03 +00004133% I n t e r p o l a t e P i x e l C h a n n e l s %
4134% %
4135% %
4136% %
4137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4138%
4139% InterpolatePixelChannels() applies a pixel interpolation method between a
4140% floating point coordinate and the pixels surrounding that coordinate. No
4141% pixel area resampling, or scaling of the result is performed.
4142%
4143% The format of the InterpolatePixelChannels method is:
4144%
4145% MagickBooleanType InterpolatePixelChannels(const Image *source,
4146% const CacheView *source_view,const Image *destination,
4147% const PixelInterpolateMethod method,const double x,const double y,
4148% Quantum *pixel,ExceptionInfo *exception)
4149%
4150% A description of each parameter follows:
4151%
4152% o source: the source.
4153%
4154% o source_view: the source view.
4155%
4156% o destination: the destination image.
4157%
4158% o method: the pixel color interpolation method.
4159%
4160% o x,y: A double representing the current (x,y) position of the pixel.
4161%
4162% o pixel: return the interpolated pixel here.
4163%
4164% o exception: return any errors or warnings in this structure.
4165%
4166*/
4167MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
4168 const CacheView *source_view,const Image *destination,
4169 const PixelInterpolateMethod method,const double x,const double y,
4170 Quantum *pixel,ExceptionInfo *exception)
4171{
4172 MagickBooleanType
4173 status;
4174
4175 MagickRealType
4176 alpha[16],
4177 gamma,
4178 pixels[16];
4179
4180 PixelChannel
4181 channel;
4182
4183 PixelTrait
4184 destination_traits,
4185 traits;
4186
4187 register const Quantum
4188 *p;
4189
4190 register ssize_t
4191 i;
4192
4193 ssize_t
4194 x_offset,
4195 y_offset;
4196
4197 assert(source != (Image *) NULL);
4198 assert(source != (Image *) NULL);
4199 assert(source->signature == MagickSignature);
4200 assert(source_view != (CacheView *) NULL);
4201 status=MagickTrue;
4202 x_offset=(ssize_t) floor(x);
4203 y_offset=(ssize_t) floor(y);
4204 switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
4205 {
4206 case AverageInterpolatePixel:
4207 {
4208 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4209 exception);
4210 if (p == (const Quantum *) NULL)
4211 {
4212 status=MagickFalse;
4213 break;
4214 }
4215 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4216 {
4217 double
4218 sum;
4219
4220 register ssize_t
4221 j;
4222
cristye2a912b2011-12-05 20:02:07 +00004223 traits=GetPixelChannelMapTraits(source,i);
4224 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004225 destination_traits=GetPixelChannelMapTraits(destination,channel);
4226 if ((traits == UndefinedPixelTrait) ||
4227 (destination_traits == UndefinedPixelTrait))
4228 continue;
4229 for (j=0; j < 16; j++)
4230 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4231 if ((traits & BlendPixelTrait) == 0)
4232 {
4233 for (j=0; j < 16; j++)
4234 pixel[channel]+=0.0625*pixels[j];
4235 continue;
4236 }
4237 sum=0.0;
4238 for (j=0; j < 16; j++)
4239 {
4240 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4241 GetPixelChannels(source));
4242 pixels[j]*=alpha[j];
4243 gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
4244 sum+=gamma*0.0625*pixels[j];
4245 }
4246 pixel[channel]=ClampToQuantum(sum);
4247 }
4248 break;
4249 }
4250 case BicubicInterpolatePixel:
4251 {
4252 MagickRealType
4253 u[4],
4254 v[4];
4255
4256 PointInfo
4257 delta;
4258
4259 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4260 exception);
4261 if (p == (const Quantum *) NULL)
4262 {
4263 status=MagickFalse;
4264 break;
4265 }
4266 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4267 {
4268 register ssize_t
4269 j;
4270
cristye2a912b2011-12-05 20:02:07 +00004271 traits=GetPixelChannelMapTraits(source,i);
4272 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004273 destination_traits=GetPixelChannelMapTraits(destination,channel);
4274 if ((traits == UndefinedPixelTrait) ||
4275 (destination_traits == UndefinedPixelTrait))
4276 continue;
4277 if ((traits & BlendPixelTrait) == 0)
4278 for (j=0; j < 16; j++)
4279 {
4280 alpha[j]=1.0;
4281 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4282 }
4283 else
4284 for (j=0; j < 16; j++)
4285 {
4286 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4287 GetPixelChannels(source));
4288 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4289 }
4290 delta.x=x-x_offset;
4291 delta.y=y-y_offset;
4292 for (j=0; j < 4; j++)
4293 {
4294 u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
4295 u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
4296 u[2]=pixels[4*j+2]-pixels[4*j+0];
4297 u[3]=pixels[4*j+1];
4298 v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
4299 u[2])+u[3];
4300 }
4301 u[0]=(v[3]-v[2])-(v[0]-v[1]);
4302 u[1]=(v[0]-v[1])-u[0];
4303 u[2]=v[2]-v[0];
4304 u[3]=v[1];
4305 pixel[channel]=ClampToQuantum((delta.y*delta.y*delta.y*u[0])+(delta.y*
4306 delta.y*u[1])+(delta.y*u[2])+u[3]);
4307 }
4308 break;
4309 }
4310 case BilinearInterpolatePixel:
4311 default:
4312 {
4313 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4314 if (p == (const Quantum *) NULL)
4315 {
4316 status=MagickFalse;
4317 break;
4318 }
4319 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4320 {
4321 PointInfo
4322 delta,
4323 epsilon;
4324
cristye2a912b2011-12-05 20:02:07 +00004325 traits=GetPixelChannelMapTraits(source,i);
4326 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004327 destination_traits=GetPixelChannelMapTraits(destination,channel);
4328 if ((traits == UndefinedPixelTrait) ||
4329 (destination_traits == UndefinedPixelTrait))
4330 continue;
4331 delta.x=x-x_offset;
4332 delta.y=y-y_offset;
4333 epsilon.x=1.0-delta.x;
4334 epsilon.y=1.0-delta.y;
cristy28474bf2011-09-11 23:32:52 +00004335 pixels[0]=(MagickRealType) p[i];
4336 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
cristy5c4e2582011-09-11 19:21:03 +00004337 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4338 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4339 if ((traits & BlendPixelTrait) == 0)
4340 {
4341 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4342 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4343 pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
4344 delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*
4345 pixels[3])));
4346 continue;
4347 }
cristy28474bf2011-09-11 23:32:52 +00004348 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4349 alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
cristy5c4e2582011-09-11 19:21:03 +00004350 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4351 GetPixelChannels(source));
4352 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4353 GetPixelChannels(source));
4354 pixels[0]*=alpha[0];
4355 pixels[1]*=alpha[1];
4356 pixels[2]*=alpha[2];
4357 pixels[3]*=alpha[3];
4358 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4359 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4360 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4361 pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
4362 delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*pixels[3])));
4363 }
4364 break;
4365 }
4366 case FilterInterpolatePixel:
4367 {
4368 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4369 {
4370 CacheView
4371 *filter_view;
4372
4373 Image
4374 *excerpt_source,
4375 *filter_source;
4376
4377 RectangleInfo
4378 geometry;
4379
cristye2a912b2011-12-05 20:02:07 +00004380 traits=GetPixelChannelMapTraits(source,i);
4381 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004382 destination_traits=GetPixelChannelMapTraits(destination,channel);
4383 if ((traits == UndefinedPixelTrait) ||
4384 (destination_traits == UndefinedPixelTrait))
4385 continue;
4386 geometry.width=4L;
4387 geometry.height=4L;
4388 geometry.x=x_offset-1;
4389 geometry.y=y_offset-1;
4390 excerpt_source=ExcerptImage(source,&geometry,exception);
4391 if (excerpt_source == (Image *) NULL)
4392 {
4393 status=MagickFalse;
4394 continue;
4395 }
4396 filter_source=ResizeImage(excerpt_source,1,1,source->filter,
4397 source->blur,exception);
4398 excerpt_source=DestroyImage(excerpt_source);
4399 if (filter_source == (Image *) NULL)
4400 continue;
4401 filter_view=AcquireCacheView(filter_source);
4402 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4403 if (p == (const Quantum *) NULL)
4404 status=MagickFalse;
4405 else
4406 pixel[channel]=p[i];
4407 filter_view=DestroyCacheView(filter_view);
4408 filter_source=DestroyImage(filter_source);
4409 }
4410 break;
4411 }
4412 case IntegerInterpolatePixel:
4413 {
4414 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
4415 if (p == (const Quantum *) NULL)
4416 {
4417 status=MagickFalse;
4418 break;
4419 }
4420 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4421 {
cristye2a912b2011-12-05 20:02:07 +00004422 traits=GetPixelChannelMapTraits(source,i);
4423 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004424 destination_traits=GetPixelChannelMapTraits(destination,channel);
4425 if ((traits == UndefinedPixelTrait) ||
4426 (destination_traits == UndefinedPixelTrait))
4427 continue;
4428 pixel[channel]=p[i];
4429 }
4430 break;
4431 }
4432 case NearestNeighborInterpolatePixel:
4433 {
4434 p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
4435 NearestNeighbor(y),1,1,exception);
4436 if (p == (const Quantum *) NULL)
4437 {
4438 status=MagickFalse;
4439 break;
4440 }
4441 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4442 {
cristye2a912b2011-12-05 20:02:07 +00004443 traits=GetPixelChannelMapTraits(source,i);
4444 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004445 destination_traits=GetPixelChannelMapTraits(destination,channel);
4446 if ((traits == UndefinedPixelTrait) ||
4447 (destination_traits == UndefinedPixelTrait))
4448 continue;
4449 pixel[channel]=p[i];
4450 }
4451 break;
4452 }
4453 case MeshInterpolatePixel:
4454 {
4455 p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
4456 if (p == (const Quantum *) NULL)
4457 {
4458 status=MagickFalse;
4459 break;
4460 }
4461 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4462 {
4463 PointInfo
4464 delta,
4465 luminance;
4466
cristye2a912b2011-12-05 20:02:07 +00004467 traits=GetPixelChannelMapTraits(source,i);
4468 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004469 destination_traits=GetPixelChannelMapTraits(destination,channel);
4470 if ((traits == UndefinedPixelTrait) ||
4471 (destination_traits == UndefinedPixelTrait))
4472 continue;
cristy28474bf2011-09-11 23:32:52 +00004473 pixels[0]=(MagickRealType) p[i];
4474 pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i];
cristy5c4e2582011-09-11 19:21:03 +00004475 pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
4476 pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
4477 if ((traits & BlendPixelTrait) == 0)
4478 {
4479 alpha[0]=1.0;
4480 alpha[1]=1.0;
4481 alpha[2]=1.0;
4482 alpha[3]=1.0;
4483 }
4484 else
4485 {
cristy28474bf2011-09-11 23:32:52 +00004486 alpha[0]=QuantumScale*GetPixelAlpha(source,p);
4487 alpha[1]=QuantumScale*GetPixelAlpha(source,p+
cristy5c4e2582011-09-11 19:21:03 +00004488 GetPixelChannels(source));
4489 alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
4490 GetPixelChannels(source));
4491 alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
4492 GetPixelChannels(source));
4493 }
4494 delta.x=x-x_offset;
4495 delta.y=y-y_offset;
4496 luminance.x=GetPixelLuminance(source,p)-(double)
4497 GetPixelLuminance(source,p+3*GetPixelChannels(source));
cristy28474bf2011-09-11 23:32:52 +00004498 luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))-
cristy5c4e2582011-09-11 19:21:03 +00004499 (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
4500 if (fabs(luminance.x) < fabs(luminance.y))
4501 {
4502 /*
4503 Diagonal 0-3 NW-SE.
4504 */
4505 if (delta.x <= delta.y)
4506 {
4507 /*
4508 Bottom-left triangle (pixel: 2, diagonal: 0-3).
4509 */
4510 delta.y=1.0-delta.y;
4511 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4512 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4513 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4514 pixels[2],pixels[3],pixels[0]));
4515 }
4516 else
4517 {
4518 /*
4519 Top-right triangle (pixel: 1, diagonal: 0-3).
4520 */
4521 delta.x=1.0-delta.x;
4522 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4523 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4524 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4525 pixels[1],pixels[0],pixels[3]));
4526 }
4527 }
4528 else
4529 {
4530 /*
4531 Diagonal 1-2 NE-SW.
4532 */
4533 if (delta.x <= (1.0-delta.y))
4534 {
4535 /*
4536 Top-left triangle (pixel: 0, diagonal: 1-2).
4537 */
4538 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4539 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4540 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4541 pixels[0],pixels[1],pixels[2]));
4542 }
4543 else
4544 {
4545 /*
4546 Bottom-right triangle (pixel: 3, diagonal: 1-2).
4547 */
4548 delta.x=1.0-delta.x;
4549 delta.y=1.0-delta.y;
4550 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4551 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4552 pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
4553 pixels[3],pixels[2],pixels[1]));
4554 }
4555 }
4556 }
4557 break;
4558 }
4559 case SplineInterpolatePixel:
4560 {
4561 p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
4562 exception);
4563 if (p == (const Quantum *) NULL)
4564 {
4565 status=MagickFalse;
4566 break;
4567 }
4568 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4569 {
4570 double
4571 sum;
4572
4573 MagickRealType
4574 dx,
4575 dy;
4576
4577 PointInfo
4578 delta;
4579
4580 register ssize_t
4581 j;
4582
4583 ssize_t
4584 k,
4585 n;
4586
cristye2a912b2011-12-05 20:02:07 +00004587 traits=GetPixelChannelMapTraits(source,i);
4588 channel=GetPixelChannelMapChannel(source,i);
cristy5c4e2582011-09-11 19:21:03 +00004589 destination_traits=GetPixelChannelMapTraits(destination,channel);
4590 if ((traits == UndefinedPixelTrait) ||
4591 (destination_traits == UndefinedPixelTrait))
4592 continue;
4593 if ((traits & BlendPixelTrait) == 0)
4594 for (j=0; j < 16; j++)
4595 {
4596 alpha[j]=1.0;
4597 pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
4598 }
4599 else
4600 for (j=0; j < 16; j++)
4601 {
4602 alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
4603 GetPixelChannels(source));
4604 pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
4605 }
4606 delta.x=x-x_offset;
4607 delta.y=y-y_offset;
4608 sum=0.0;
4609 n=0;
4610 for (j=(-1); j < 3L; j++)
4611 {
4612 dy=CubicWeightingFunction((MagickRealType) j-delta.y);
4613 for (k=(-1); k < 3L; k++)
4614 {
4615 dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
4616 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
4617 alpha[n]);
4618 sum+=gamma*dx*dy*pixels[n];
4619 n++;
4620 }
4621 }
4622 pixel[channel]=ClampToQuantum(sum);
4623 }
4624 break;
4625 }
4626 }
4627 return(status);
4628}
4629
4630/*
4631%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4632% %
4633% %
4634% %
cristy9075cdb2011-07-30 01:06:23 +00004635% 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 +00004636% %
4637% %
4638% %
4639%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4640%
cristy884f6002011-07-31 00:51:45 +00004641% InterpolatePixelInfo() applies a pixel interpolation method between a
4642% floating point coordinate and the pixels surrounding that coordinate. No
4643% pixel area resampling, or scaling of the result is performed.
cristy4c08aed2011-07-01 19:47:50 +00004644%
4645% The format of the InterpolatePixelInfo method is:
4646%
4647% MagickBooleanType InterpolatePixelInfo(const Image *image,
cristy5c4e2582011-09-11 19:21:03 +00004648% const CacheView *image_view,const PixelInterpolateMethod method,
cristy4c08aed2011-07-01 19:47:50 +00004649% const double x,const double y,PixelInfo *pixel,
4650% ExceptionInfo *exception)
4651%
4652% A description of each parameter follows:
4653%
4654% o image: the image.
4655%
4656% o image_view: the image view.
4657%
4658% o method: the pixel color interpolation method.
4659%
4660% o x,y: A double representing the current (x,y) position of the pixel.
4661%
4662% o pixel: return the interpolated pixel here.
4663%
4664% o exception: return any errors or warnings in this structure.
4665%
4666*/
4667
4668static inline void AlphaBlendPixelInfo(const Image *image,
4669 const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
4670{
4671 if (image->matte == MagickFalse)
4672 {
4673 *alpha=1.0;
4674 pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
4675 pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
4676 pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
4677 pixel_info->black=0.0;
4678 if (image->colorspace == CMYKColorspace)
4679 pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
4680 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4681 return;
4682 }
4683 *alpha=QuantumScale*GetPixelAlpha(image,pixel);
4684 pixel_info->red=(*alpha*GetPixelRed(image,pixel));
4685 pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
4686 pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
4687 pixel_info->black=0.0;
4688 if (image->colorspace == CMYKColorspace)
4689 pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
4690 pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
4691}
4692
4693static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
4694 PixelInfo *pixel)
4695{
4696 MagickRealType
4697 dx2,
4698 p,
4699 q,
4700 r,
4701 s;
4702
4703 dx2=dx*dx;
4704 p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
4705 q=(pixels[0].red-pixels[1].red)-p;
4706 r=pixels[2].red-pixels[0].red;
4707 s=pixels[1].red;
4708 pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4709 p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
4710 q=(pixels[0].green-pixels[1].green)-p;
4711 r=pixels[2].green-pixels[0].green;
4712 s=pixels[1].green;
4713 pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4714 p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
4715 q=(pixels[0].blue-pixels[1].blue)-p;
4716 r=pixels[2].blue-pixels[0].blue;
4717 s=pixels[1].blue;
4718 pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4719 p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
4720 q=(pixels[0].alpha-pixels[1].alpha)-p;
4721 r=pixels[2].alpha-pixels[0].alpha;
4722 s=pixels[1].alpha;
4723 pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4724 if (pixel->colorspace == CMYKColorspace)
4725 {
4726 p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
4727 q=(pixels[0].black-pixels[1].black)-p;
4728 r=pixels[2].black-pixels[0].black;
4729 s=pixels[1].black;
4730 pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
4731 }
4732}
4733
cristy4c08aed2011-07-01 19:47:50 +00004734MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
cristy5c4e2582011-09-11 19:21:03 +00004735 const CacheView *image_view,const PixelInterpolateMethod method,
cristy4c08aed2011-07-01 19:47:50 +00004736 const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
4737{
4738 MagickBooleanType
4739 status;
4740
cristy4c08aed2011-07-01 19:47:50 +00004741 MagickRealType
4742 alpha[16],
4743 gamma;
4744
cristy865d58d2011-07-09 00:44:52 +00004745 PixelInfo
4746 pixels[16];
4747
cristy4c08aed2011-07-01 19:47:50 +00004748 register const Quantum
4749 *p;
4750
4751 register ssize_t
4752 i;
4753
4754 ssize_t
4755 x_offset,
4756 y_offset;
4757
4758 assert(image != (Image *) NULL);
4759 assert(image->signature == MagickSignature);
4760 assert(image_view != (CacheView *) NULL);
4761 status=MagickTrue;
4762 x_offset=(ssize_t) floor(x);
4763 y_offset=(ssize_t) floor(y);
4764 switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
4765 {
4766 case AverageInterpolatePixel:
4767 {
4768 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4769 exception);
4770 if (p == (const Quantum *) NULL)
4771 {
4772 status=MagickFalse;
4773 break;
4774 }
cristy5ce8df82011-07-07 14:52:23 +00004775 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004776 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004777 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4778 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4779 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4780 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4781 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4782 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4783 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4784 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4785 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
cristy865d58d2011-07-09 00:44:52 +00004786 10);
cristyed231572011-07-14 02:18:59 +00004787 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
cristy865d58d2011-07-09 00:44:52 +00004788 11);
cristyed231572011-07-14 02:18:59 +00004789 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
cristy865d58d2011-07-09 00:44:52 +00004790 12);
cristyed231572011-07-14 02:18:59 +00004791 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
cristy865d58d2011-07-09 00:44:52 +00004792 13);
cristyed231572011-07-14 02:18:59 +00004793 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
cristy865d58d2011-07-09 00:44:52 +00004794 14);
cristyed231572011-07-14 02:18:59 +00004795 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
cristy865d58d2011-07-09 00:44:52 +00004796 15);
cristy4c08aed2011-07-01 19:47:50 +00004797 pixel->red=0.0;
4798 pixel->green=0.0;
4799 pixel->blue=0.0;
cristy4c08aed2011-07-01 19:47:50 +00004800 pixel->black=0.0;
cristy865d58d2011-07-09 00:44:52 +00004801 pixel->alpha=0.0;
cristy4c08aed2011-07-01 19:47:50 +00004802 for (i=0; i < 16L; i++)
4803 {
4804 gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
4805 pixel->red+=gamma*0.0625*pixels[i].red;
4806 pixel->green+=gamma*0.0625*pixels[i].green;
4807 pixel->blue+=gamma*0.0625*pixels[i].blue;
cristy4c08aed2011-07-01 19:47:50 +00004808 if (image->colorspace == CMYKColorspace)
4809 pixel->black+=gamma*0.0625*pixels[i].black;
cristy865d58d2011-07-09 00:44:52 +00004810 pixel->alpha+=0.0625*pixels[i].alpha;
cristy4c08aed2011-07-01 19:47:50 +00004811 }
4812 break;
4813 }
4814 case BicubicInterpolatePixel:
4815 {
4816 PixelInfo
4817 u[4];
4818
4819 PointInfo
4820 delta;
4821
4822 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4823 exception);
4824 if (p == (const Quantum *) NULL)
4825 {
4826 status=MagickFalse;
4827 break;
4828 }
cristy5ce8df82011-07-07 14:52:23 +00004829 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004830 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004831 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4832 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
4833 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
4834 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
4835 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
4836 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
4837 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
4838 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
4839 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
cristy865d58d2011-07-09 00:44:52 +00004840 10);
cristyed231572011-07-14 02:18:59 +00004841 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
cristy865d58d2011-07-09 00:44:52 +00004842 11);
cristyed231572011-07-14 02:18:59 +00004843 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
cristy865d58d2011-07-09 00:44:52 +00004844 12);
cristyed231572011-07-14 02:18:59 +00004845 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
cristy865d58d2011-07-09 00:44:52 +00004846 13);
cristyed231572011-07-14 02:18:59 +00004847 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
cristy865d58d2011-07-09 00:44:52 +00004848 14);
cristyed231572011-07-14 02:18:59 +00004849 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
cristy865d58d2011-07-09 00:44:52 +00004850 15);
cristy4c08aed2011-07-01 19:47:50 +00004851 delta.x=x-x_offset;
4852 delta.y=y-y_offset;
4853 for (i=0; i < 4L; i++)
4854 BicubicInterpolate(pixels+4*i,delta.x,u+i);
4855 BicubicInterpolate(u,delta.y,pixel);
4856 break;
4857 }
4858 case BilinearInterpolatePixel:
4859 default:
4860 {
4861 PointInfo
4862 delta,
4863 epsilon;
4864
4865 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4866 if (p == (const Quantum *) NULL)
4867 {
4868 status=MagickFalse;
4869 break;
4870 }
cristy5ce8df82011-07-07 14:52:23 +00004871 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004872 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004873 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4874 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
cristy4c08aed2011-07-01 19:47:50 +00004875 delta.x=x-x_offset;
4876 delta.y=y-y_offset;
4877 epsilon.x=1.0-delta.x;
4878 epsilon.y=1.0-delta.y;
4879 gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4880 (epsilon.x*alpha[2]+delta.x*alpha[3])));
4881 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4882 pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
4883 pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
4884 pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
4885 pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x*
4886 pixels[3].green));
4887 pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x*
4888 pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x*
4889 pixels[3].blue));
cristy4c08aed2011-07-01 19:47:50 +00004890 if (image->colorspace == CMYKColorspace)
4891 pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x*
4892 pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
4893 pixels[3].black));
cristy884f6002011-07-31 00:51:45 +00004894 gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
4895 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristy865d58d2011-07-09 00:44:52 +00004896 pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
4897 pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
4898 pixels[3].alpha));
cristy4c08aed2011-07-01 19:47:50 +00004899 break;
4900 }
4901 case FilterInterpolatePixel:
4902 {
4903 CacheView
4904 *filter_view;
4905
4906 Image
4907 *excerpt_image,
4908 *filter_image;
4909
4910 RectangleInfo
4911 geometry;
4912
4913 geometry.width=4L;
4914 geometry.height=4L;
4915 geometry.x=x_offset-1;
4916 geometry.y=y_offset-1;
4917 excerpt_image=ExcerptImage(image,&geometry,exception);
4918 if (excerpt_image == (Image *) NULL)
4919 {
4920 status=MagickFalse;
4921 break;
4922 }
4923 filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
4924 exception);
4925 excerpt_image=DestroyImage(excerpt_image);
4926 if (filter_image == (Image *) NULL)
4927 break;
4928 filter_view=AcquireCacheView(filter_image);
4929 p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
4930 if (p != (const Quantum *) NULL)
cristy803640d2011-11-17 02:11:32 +00004931 GetPixelInfoPixel(image,p,pixel);
cristy4c08aed2011-07-01 19:47:50 +00004932 filter_view=DestroyCacheView(filter_view);
4933 filter_image=DestroyImage(filter_image);
4934 break;
4935 }
4936 case IntegerInterpolatePixel:
4937 {
4938 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4939 if (p == (const Quantum *) NULL)
4940 {
4941 status=MagickFalse;
4942 break;
4943 }
cristy803640d2011-11-17 02:11:32 +00004944 GetPixelInfoPixel(image,p,pixel);
cristy4c08aed2011-07-01 19:47:50 +00004945 break;
4946 }
4947 case MeshInterpolatePixel:
4948 {
4949 PointInfo
4950 delta,
4951 luminance;
4952
cristy94ea1632011-07-30 20:40:25 +00004953 p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
cristy4c08aed2011-07-01 19:47:50 +00004954 if (p == (const Quantum *) NULL)
4955 {
4956 status=MagickFalse;
4957 break;
4958 }
cristy94ea1632011-07-30 20:40:25 +00004959 delta.x=x-x_offset;
4960 delta.y=y-y_offset;
cristy884f6002011-07-31 00:51:45 +00004961 luminance.x=GetPixelLuminance(image,p)-(double)
cristy94ea1632011-07-30 20:40:25 +00004962 GetPixelLuminance(image,p+3*GetPixelChannels(image));
cristy28474bf2011-09-11 23:32:52 +00004963 luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
cristy94ea1632011-07-30 20:40:25 +00004964 GetPixelLuminance(image,p+2*GetPixelChannels(image));
cristy5ce8df82011-07-07 14:52:23 +00004965 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00004966 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00004967 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
4968 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
cristy4c08aed2011-07-01 19:47:50 +00004969 if (fabs(luminance.x) < fabs(luminance.y))
4970 {
4971 /*
4972 Diagonal 0-3 NW-SE.
4973 */
4974 if (delta.x <= delta.y)
4975 {
4976 /*
cristy94ea1632011-07-30 20:40:25 +00004977 Bottom-left triangle (pixel: 2, diagonal: 0-3).
cristy4c08aed2011-07-01 19:47:50 +00004978 */
4979 delta.y=1.0-delta.y;
4980 gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4981 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
4982 pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
4983 pixels[3].red,pixels[0].red);
4984 pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
4985 pixels[3].green,pixels[0].green);
4986 pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
4987 pixels[3].blue,pixels[0].blue);
cristy4c08aed2011-07-01 19:47:50 +00004988 if (image->colorspace == CMYKColorspace)
4989 pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black,
4990 pixels[3].black,pixels[0].black);
cristy94ea1632011-07-30 20:40:25 +00004991 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00004992 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha,
4993 pixels[3].alpha,pixels[0].alpha);
cristy4c08aed2011-07-01 19:47:50 +00004994 }
4995 else
4996 {
4997 /*
cristy94ea1632011-07-30 20:40:25 +00004998 Top-right triangle (pixel:1 , diagonal: 0-3).
cristy4c08aed2011-07-01 19:47:50 +00004999 */
5000 delta.x=1.0-delta.x;
5001 gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5002 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5003 pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
5004 pixels[0].red,pixels[3].red);
5005 pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
5006 pixels[0].green,pixels[3].green);
5007 pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
5008 pixels[0].blue,pixels[3].blue);
cristy4c08aed2011-07-01 19:47:50 +00005009 if (image->colorspace == CMYKColorspace)
5010 pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black,
5011 pixels[0].black,pixels[3].black);
cristy94ea1632011-07-30 20:40:25 +00005012 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00005013 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha,
5014 pixels[0].alpha,pixels[3].alpha);
cristy4c08aed2011-07-01 19:47:50 +00005015 }
5016 }
5017 else
5018 {
5019 /*
5020 Diagonal 1-2 NE-SW.
5021 */
5022 if (delta.x <= (1.0-delta.y))
5023 {
5024 /*
cristy94ea1632011-07-30 20:40:25 +00005025 Top-left triangle (pixel: 0, diagonal: 1-2).
cristy4c08aed2011-07-01 19:47:50 +00005026 */
5027 gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5028 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5029 pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
5030 pixels[1].red,pixels[2].red);
5031 pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
5032 pixels[1].green,pixels[2].green);
5033 pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
5034 pixels[1].blue,pixels[2].blue);
cristy4c08aed2011-07-01 19:47:50 +00005035 if (image->colorspace == CMYKColorspace)
5036 pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black,
5037 pixels[1].black,pixels[2].black);
cristy94ea1632011-07-30 20:40:25 +00005038 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00005039 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha,
5040 pixels[1].alpha,pixels[2].alpha);
cristy4c08aed2011-07-01 19:47:50 +00005041 }
5042 else
5043 {
5044 /*
5045 Bottom-right triangle (pixel: 3, diagonal: 1-2).
5046 */
5047 delta.x=1.0-delta.x;
5048 delta.y=1.0-delta.y;
5049 gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5050 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
5051 pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
5052 pixels[2].red,pixels[1].red);
5053 pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
5054 pixels[2].green,pixels[1].green);
5055 pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
5056 pixels[2].blue,pixels[1].blue);
cristy4c08aed2011-07-01 19:47:50 +00005057 if (image->colorspace == CMYKColorspace)
5058 pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black,
5059 pixels[2].black,pixels[1].black);
cristy94ea1632011-07-30 20:40:25 +00005060 gamma=MeshInterpolate(&delta,1.0,1.0,1.0);
cristy865d58d2011-07-09 00:44:52 +00005061 pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha,
5062 pixels[2].alpha,pixels[1].alpha);
cristy4c08aed2011-07-01 19:47:50 +00005063 }
5064 }
5065 break;
5066 }
5067 case NearestNeighborInterpolatePixel:
5068 {
5069 p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
5070 NearestNeighbor(y),1,1,exception);
5071 if (p == (const Quantum *) NULL)
5072 {
5073 status=MagickFalse;
5074 break;
5075 }
cristy803640d2011-11-17 02:11:32 +00005076 GetPixelInfoPixel(image,p,pixel);
cristy4c08aed2011-07-01 19:47:50 +00005077 break;
5078 }
5079 case SplineInterpolatePixel:
5080 {
5081 MagickRealType
5082 dx,
5083 dy;
5084
5085 PointInfo
5086 delta;
5087
5088 ssize_t
5089 j,
5090 n;
5091
5092 p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
5093 exception);
5094 if (p == (const Quantum *) NULL)
5095 {
5096 status=MagickFalse;
5097 break;
5098 }
cristy5ce8df82011-07-07 14:52:23 +00005099 AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
cristy28474bf2011-09-11 23:32:52 +00005100 AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
cristyed231572011-07-14 02:18:59 +00005101 AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
5102 AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
5103 AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
5104 AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
5105 AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
5106 AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
5107 AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
5108 AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
5109 AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
cristy865d58d2011-07-09 00:44:52 +00005110 10);
cristyed231572011-07-14 02:18:59 +00005111 AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
cristy865d58d2011-07-09 00:44:52 +00005112 11);
cristyed231572011-07-14 02:18:59 +00005113 AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
cristy865d58d2011-07-09 00:44:52 +00005114 12);
cristyed231572011-07-14 02:18:59 +00005115 AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
cristy865d58d2011-07-09 00:44:52 +00005116 13);
cristyed231572011-07-14 02:18:59 +00005117 AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
cristy865d58d2011-07-09 00:44:52 +00005118 14);
cristyed231572011-07-14 02:18:59 +00005119 AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
cristy865d58d2011-07-09 00:44:52 +00005120 15);
cristy4c08aed2011-07-01 19:47:50 +00005121 pixel->red=0.0;
5122 pixel->green=0.0;
5123 pixel->blue=0.0;
cristy4c08aed2011-07-01 19:47:50 +00005124 pixel->black=0.0;
cristy865d58d2011-07-09 00:44:52 +00005125 pixel->alpha=0.0;
cristy4c08aed2011-07-01 19:47:50 +00005126 delta.x=x-x_offset;
5127 delta.y=y-y_offset;
5128 n=0;
5129 for (i=(-1); i < 3L; i++)
5130 {
5131 dy=CubicWeightingFunction((MagickRealType) i-delta.y);
5132 for (j=(-1); j < 3L; j++)
5133 {
5134 dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
5135 gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
5136 pixel->red+=gamma*dx*dy*pixels[n].red;
5137 pixel->green+=gamma*dx*dy*pixels[n].green;
5138 pixel->blue+=gamma*dx*dy*pixels[n].blue;
5139 if (image->colorspace == CMYKColorspace)
5140 pixel->black+=gamma*dx*dy*pixels[n].black;
5141 pixel->alpha+=dx*dy*pixels[n].alpha;
5142 n++;
5143 }
5144 }
5145 break;
5146 }
5147 }
5148 return(status);
5149}
5150
5151/*
5152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5153% %
5154% %
5155% %
5156+ I s F u z z y E q u i v a l e n c e P i x e l %
5157% %
5158% %
5159% %
5160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5161%
5162% IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two
5163% pixels is less than the specified distance in a linear three (or four)u
5164% dimensional color space.
5165%
5166% The format of the IsFuzzyEquivalencePixel method is:
5167%
5168% void IsFuzzyEquivalencePixel(const Image *image,const Quantum *p,
5169% const Quantum *q)
5170%
5171% A description of each parameter follows:
5172%
5173% o image: the image.
5174%
5175% o p: Pixel p.
5176%
5177% o q: Pixel q.
5178%
5179*/
5180MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
5181 const Quantum *p,const Quantum *q)
5182{
5183 MagickRealType
5184 fuzz,
5185 pixel;
5186
5187 register MagickRealType
5188 distance,
5189 scale;
5190
cristy5f95f4f2011-10-23 01:01:01 +00005191 fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(
5192 image->fuzz,(MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005193 scale=1.0;
5194 distance=0.0;
5195 if (image->matte != MagickFalse)
5196 {
5197 /*
5198 Transparencies are involved - set alpha distance
5199 */
5200 pixel=(MagickRealType) ((image->matte != MagickFalse ?
5201 GetPixelAlpha(image,p) : OpaqueAlpha)-(image->matte != MagickFalse ?
5202 GetPixelAlpha(image,q) : OpaqueAlpha));
5203 distance=pixel*pixel;
5204 if (distance > fuzz)
5205 return(MagickFalse);
5206 /*
5207 Generate a alpha scaling factor to generate a 4D cone on colorspace
5208 Note that if one color is transparent, distance has no color component.
5209 */
5210 scale=QuantumScale*GetPixelAlpha(image,p);
5211 scale*=QuantumScale*GetPixelAlpha(image,q);
5212 if (scale <= MagickEpsilon)
5213 return(MagickTrue);
5214 }
5215 /*
5216 RGB or CMY color cube
5217 */
5218 distance*=3.0; /* rescale appropriately */
5219 fuzz*=3.0;
5220 pixel=GetPixelRed(image,p)-(MagickRealType) GetPixelRed(image,q);
5221 if ((image->colorspace == HSLColorspace) ||
5222 (image->colorspace == HSBColorspace) ||
5223 (image->colorspace == HWBColorspace))
5224 {
5225 /*
5226 Compute an arc distance for hue. It should be a vector angle of
5227 'S'/'W' length with 'L'/'B' forming appropriate cones.
5228 */
5229 if (fabs((double) pixel) > (QuantumRange/2))
5230 pixel-=QuantumRange;
5231 pixel*=2;
5232 }
5233 distance+=scale*pixel*pixel;
5234 if (distance > fuzz)
5235 return(MagickFalse);
5236 pixel=GetPixelGreen(image,p)-(MagickRealType) GetPixelGreen(image,q);
5237 distance+=scale*pixel*pixel;
5238 if (distance > fuzz)
5239 return(MagickFalse);
5240 pixel=GetPixelBlue(image,p)-(MagickRealType) GetPixelBlue(image,q);
5241 distance+=scale*pixel*pixel;
5242 if (distance > fuzz)
5243 return(MagickFalse);
5244 return(MagickTrue);
5245}
5246
5247/*
5248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5249% %
5250% %
5251% %
5252+ 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 %
5253% %
5254% %
5255% %
5256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5257%
5258% IsFuzzyEquivalencePixelInfo() returns true if the distance between two
5259% colors is less than the specified distance in a linear three (or four)
5260% dimensional color space.
5261%
cristy5f95f4f2011-10-23 01:01:01 +00005262% This implements the equivalent of:
5263% fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2)
cristy4c08aed2011-07-01 19:47:50 +00005264%
5265% Which produces a multi-dimensional cone for that colorspace along the
5266% transparency vector.
5267%
cristy5f95f4f2011-10-23 01:01:01 +00005268% For example for an RGB:
cristy4c08aed2011-07-01 19:47:50 +00005269% color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
5270%
5271% See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
5272%
5273% Hue colorspace distances need more work. Hue is not a distance, it is an
5274% angle!
5275%
5276% A check that q is in the same color space as p should be made and the
5277% appropriate mapping made. -- Anthony Thyssen 8 December 2010
5278%
5279% The format of the IsFuzzyEquivalencePixelInfo method is:
5280%
5281% MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5282% const PixelInfo *q)
5283%
5284% A description of each parameter follows:
5285%
5286% o p: Pixel p.
5287%
5288% o q: Pixel q.
5289%
5290*/
5291MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
5292 const PixelInfo *q)
5293{
5294 MagickRealType
5295 fuzz,
5296 pixel;
5297
5298 register MagickRealType
5299 scale,
5300 distance;
5301
5302 if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
5303 return(IsPixelInfoEquivalent(p,q));
5304 if (p->fuzz == 0.0)
cristy5f95f4f2011-10-23 01:01:01 +00005305 fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5306 (MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005307 else if (q->fuzz == 0.0)
cristy5f95f4f2011-10-23 01:01:01 +00005308 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz,
5309 (MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005310 else
cristy5f95f4f2011-10-23 01:01:01 +00005311 fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz,
5312 (MagickRealType) MagickSQ1_2);
cristy4c08aed2011-07-01 19:47:50 +00005313 scale=1.0;
5314 distance=0.0;
5315 if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
5316 {
5317 /*
5318 Transparencies are involved - set alpha distance.
5319 */
5320 pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
5321 (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
5322 distance=pixel*pixel;
5323 if (distance > fuzz)
5324 return(MagickFalse);
5325 /*
5326 Generate a alpha scaling factor to generate a 4D cone on colorspace.
cristy5f95f4f2011-10-23 01:01:01 +00005327 If one color is transparent, distance has no color component.
cristy4c08aed2011-07-01 19:47:50 +00005328 */
5329 if (p->matte != MagickFalse)
5330 scale=(QuantumScale*p->alpha);
5331 if (q->matte != MagickFalse)
5332 scale*=(QuantumScale*q->alpha);
5333 if (scale <= MagickEpsilon )
5334 return(MagickTrue);
5335 }
5336 /*
5337 CMYK create a CMY cube with a multi-dimensional cone toward black.
5338 */
5339 if (p->colorspace == CMYKColorspace)
5340 {
5341 pixel=p->black-q->black;
5342 distance+=pixel*pixel*scale;
5343 if (distance > fuzz)
5344 return(MagickFalse);
5345 scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
5346 scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
5347 }
5348 /*
5349 RGB or CMY color cube.
5350 */
5351 distance*=3.0; /* rescale appropriately */
5352 fuzz*=3.0;
5353 pixel=p->red-q->red;
5354 if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
5355 (p->colorspace == HWBColorspace))
5356 {
cristy5f95f4f2011-10-23 01:01:01 +00005357 /*
5358 This calculates a arc distance for hue-- it should be a vector angle
5359 of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other
5360 words this is a hack - Anthony.
cristy4c08aed2011-07-01 19:47:50 +00005361 */
5362 if (fabs((double) pixel) > (QuantumRange/2))
5363 pixel-=QuantumRange;
5364 pixel*=2;
5365 }
5366 distance+=pixel*pixel*scale;
5367 if (distance > fuzz)
5368 return(MagickFalse);
5369 pixel=p->green-q->green;
5370 distance+=pixel*pixel*scale;
5371 if (distance > fuzz)
5372 return(MagickFalse);
5373 pixel=p->blue-q->blue;
5374 distance+=pixel*pixel*scale;
5375 if (distance > fuzz)
5376 return(MagickFalse);
5377 return(MagickTrue);
5378}
5379
5380/*
5381%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5382% %
5383% %
5384% %
cristye2a912b2011-12-05 20:02:07 +00005385% 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 +00005386% %
5387% %
5388% %
5389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5390%
cristye2a912b2011-12-05 20:02:07 +00005391% SetPixelChannelMapMask() sets the pixel channel map from the specified
5392% channel mask.
cristy2b9582a2011-07-04 17:38:56 +00005393%
cristye2a912b2011-12-05 20:02:07 +00005394% The format of the SetPixelChannelMapMask method is:
cristy2b9582a2011-07-04 17:38:56 +00005395%
cristye2a912b2011-12-05 20:02:07 +00005396% void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005397%
5398% A description of each parameter follows:
5399%
5400% o image: the image.
5401%
cristy44261462011-08-09 13:34:47 +00005402% o mask: the channel mask.
cristy2b9582a2011-07-04 17:38:56 +00005403%
5404*/
cristye2a912b2011-12-05 20:02:07 +00005405MagickExport void SetPixelChannelMapMask(Image *image,
cristy07a67852011-08-26 13:25:03 +00005406 const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005407{
cristy6a917d62011-08-24 17:31:30 +00005408#define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
cristydafd2872011-07-24 22:06:13 +00005409
cristy2b9582a2011-07-04 17:38:56 +00005410 register ssize_t
5411 i;
5412
cristy3c309812011-11-08 02:40:43 +00005413 image->channel_mask=channel_mask;
cristydafd2872011-07-24 22:06:13 +00005414 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristye2a912b2011-12-05 20:02:07 +00005415 {
5416 PixelChannel
5417 channel;
5418
5419 channel=GetPixelChannelMapChannel(image,i);
5420 SetPixelChannelMapTraits(image,channel,
5421 GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
cristy3fac9ec2011-11-17 18:04:39 +00005422 image->matte == MagickFalse ? UpdatePixelTrait : (PixelTrait)
5423 (UpdatePixelTrait | BlendPixelTrait));
cristye2a912b2011-12-05 20:02:07 +00005424 }
cristy1685e722011-09-06 00:04:19 +00005425 if (image->storage_class == PseudoClass)
5426 SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
cristy6dcb9b82011-10-23 23:21:25 +00005427 if (image->debug != MagickFalse)
5428 LogPixelChannels(image);
cristy2b9582a2011-07-04 17:38:56 +00005429}
5430
5431/*
5432%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5433% %
5434% %
5435% %
cristybd5a96c2011-08-21 00:04:26 +00005436% 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 +00005437% %
5438% %
5439% %
5440%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5441%
cristy5f95f4f2011-10-23 01:01:01 +00005442% SetPixelChannelMask() sets the pixel channel mask from the specified channel
5443% mask.
cristy2b9582a2011-07-04 17:38:56 +00005444%
cristybd5a96c2011-08-21 00:04:26 +00005445% The format of the SetPixelChannelMask method is:
cristy2b9582a2011-07-04 17:38:56 +00005446%
cristybd5a96c2011-08-21 00:04:26 +00005447% ChannelType SetPixelChannelMask(Image *image,
5448% const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005449%
5450% A description of each parameter follows:
5451%
5452% o image: the image.
5453%
cristybd5a96c2011-08-21 00:04:26 +00005454% o channel_mask: the channel mask.
5455%
cristy2b9582a2011-07-04 17:38:56 +00005456*/
cristybd5a96c2011-08-21 00:04:26 +00005457MagickExport ChannelType SetPixelChannelMask(Image *image,
5458 const ChannelType channel_mask)
cristy2b9582a2011-07-04 17:38:56 +00005459{
cristybd5a96c2011-08-21 00:04:26 +00005460 ChannelType
5461 mask;
cristy222b19c2011-08-04 01:35:11 +00005462
cristybd5a96c2011-08-21 00:04:26 +00005463 mask=image->channel_mask;
5464 image->channel_mask=channel_mask;
cristye2a912b2011-12-05 20:02:07 +00005465 SetPixelChannelMapMask(image,channel_mask);
cristybd5a96c2011-08-21 00:04:26 +00005466 return(mask);
cristy2b9582a2011-07-04 17:38:56 +00005467}