MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
pixel.c
Go to the documentation of this file.
1 /*
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 % Cristy %
16 % October 1998 %
17 % %
18 % %
19 % Copyright 1999-2018 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 % https://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"
48 #include "MagickCore/draw.h"
49 #include "MagickCore/exception.h"
51 #include "MagickCore/cache.h"
52 #include "MagickCore/constitute.h"
53 #include "MagickCore/delegate.h"
54 #include "MagickCore/geometry.h"
56 #include "MagickCore/list.h"
57 #include "MagickCore/magick.h"
58 #include "MagickCore/memory_.h"
60 #include "MagickCore/monitor.h"
61 #include "MagickCore/option.h"
62 #include "MagickCore/pixel.h"
65 #include "MagickCore/quantum.h"
67 #include "MagickCore/resource_.h"
68 #include "MagickCore/semaphore.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/stream.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/transform.h"
73 #include "MagickCore/utility.h"
74 
75 /*
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % %
78 % %
79 % %
80 + A c q u i r e P i x e l C h a n n e l M a p %
81 % %
82 % %
83 % %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 %
86 % AcquirePixelChannelMap() acquires a pixel component map.
87 %
88 % The format of the AcquirePixelChannelMap() method is:
89 %
90 % PixelChannelMap *AcquirePixelChannelMap(void)
91 %
92 */
94 {
96  *channel_map;
97 
98  register ssize_t
99  i;
100 
102  sizeof(*channel_map));
103  if (channel_map == (PixelChannelMap *) NULL)
104  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
105  (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map));
106  for (i=0; i < MaxPixelChannels; i++)
107  channel_map[i].channel=(PixelChannel) i;
108  return(channel_map);
109 }
110 
111 /*
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % %
114 % %
115 % %
116 + C l o n e P i x e l C h a n n e l M a p %
117 % %
118 % %
119 % %
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 %
122 % ClonePixelChannelMap() clones a pixel component map.
123 %
124 % The format of the ClonePixelChannelMap() method is:
125 %
126 % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map)
127 %
128 % A description of each parameter follows:
129 %
130 % o channel_map: the pixel component map.
131 %
132 */
134 {
136  *clone_map;
137 
138  assert(channel_map != (PixelChannelMap *) NULL);
139  clone_map=AcquirePixelChannelMap();
140  if (clone_map == (PixelChannelMap *) NULL)
141  return((PixelChannelMap *) NULL);
142  (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels*
143  sizeof(*channel_map));
144  return(clone_map);
145 }
146 
147 /*
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % %
150 % %
151 % %
152 + C l o n e P i x e l I n f o %
153 % %
154 % %
155 % %
156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 %
158 % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if
159 % pixel info is NULL, a new one.
160 %
161 % The format of the ClonePixelInfo method is:
162 %
163 % PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
164 %
165 % A description of each parameter follows:
166 %
167 % o pixel: the pixel info.
168 %
169 */
171 {
172  PixelInfo
173  *pixel_info;
174 
175  pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
176  if (pixel_info == (PixelInfo *) NULL)
177  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
178  *pixel_info=(*pixel);
179  return(pixel_info);
180 }
181 
182 /*
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 % %
185 % %
186 % %
187 + C o n f o r m P i x e l I n f o %
188 % %
189 % %
190 % %
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 %
193 % ConformPixelInfo() ensures the pixel conforms with the colorspace and alpha
194 % attribute of the image.
195 %
196 % The format of the ConformPixelInfo method is:
197 %
198 % void *ConformPixelInfo((Image *image,const PixelInfo *source,
199 % PixelInfo *destination,ExceptionInfo *exception)
200 %
201 % A description of each parameter follows:
202 %
203 % o image: the image.
204 %
205 % o source: the source pixel info.
206 %
207 % o destination: the destination pixel info.
208 %
209 % o exception: return any errors or warnings in this structure.
210 %
211 */
212 MagickExport void ConformPixelInfo(Image *image,const PixelInfo *source,
213  PixelInfo *destination,ExceptionInfo *exception)
214 {
215  assert(image != (Image *) NULL);
216  assert(image->signature == MagickCoreSignature);
217  assert(destination != (const PixelInfo *) NULL);
218  *destination=(*source);
219  if (image->colorspace == CMYKColorspace)
220  {
221  if (IssRGBCompatibleColorspace(destination->colorspace))
222  ConvertRGBToCMYK(destination);
223  }
224  else
225  if (destination->colorspace == CMYKColorspace)
226  {
228  ConvertCMYKToRGB(destination);
229  }
230  if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
232  (void) TransformImageColorspace(image,sRGBColorspace,exception);
233  if ((destination->alpha_trait != UndefinedPixelTrait) &&
234  (image->alpha_trait == UndefinedPixelTrait))
235  (void) SetImageAlpha(image,OpaqueAlpha,exception);
236 }
237 
238 /*
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % %
241 % %
242 % %
243 % D e c o d e P i x e l G a m m a %
244 % %
245 % %
246 % %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 %
249 % DecodePixelGamma() applies the expansive power-law nonlinearity to the pixel.
250 %
251 % The format of the DecodePixelGamma method is:
252 %
253 % double DecodePixelGamma(const MagickRealType pixel)
254 %
255 % A description of each parameter follows:
256 %
257 % o pixel: the pixel.
258 %
259 */
260 
261 static inline double DecodeGamma(const double x)
262 {
263  div_t
264  quotient;
265 
266  double
267  p,
268  term[9];
269 
270  int
271  exponent;
272 
273  static const double coefficient[] = /* terms for x^(7/5), x=1.5 */
274  {
275  1.7917488588043277509,
276  0.82045614371976854984,
277  0.027694100686325412819,
278  -0.00094244335181762134018,
279  0.000064355540911469709545,
280  -5.7224404636060757485e-06,
281  5.8767669437311184313e-07,
282  -6.6139920053589721168e-08,
283  7.9323242696227458163e-09
284  };
285 
286  static const double powers_of_two[] = /* (2^x)^(7/5) */
287  {
288  1.0,
289  2.6390158215457883983,
290  6.9644045063689921093,
291  1.8379173679952558018e+01,
292  4.8502930128332728543e+01
293  };
294 
295  /*
296  Compute x^2.4 == x*x^(7/5) == pow(x,2.4).
297  */
298  term[0]=1.0;
299  term[1]=4.0*frexp(x,&exponent)-3.0;
300  term[2]=2.0*term[1]*term[1]-term[0];
301  term[3]=2.0*term[1]*term[2]-term[1];
302  term[4]=2.0*term[1]*term[3]-term[2];
303  term[5]=2.0*term[1]*term[4]-term[3];
304  term[6]=2.0*term[1]*term[5]-term[4];
305  term[7]=2.0*term[1]*term[6]-term[5];
306  term[8]=2.0*term[1]*term[7]-term[6];
307  p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
308  coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
309  coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
310  quotient=div(exponent-1,5);
311  if (quotient.rem < 0)
312  {
313  quotient.quot-=1;
314  quotient.rem+=5;
315  }
316  return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot));
317 }
318 
320 {
321  if (pixel <= (0.0404482362771076*QuantumRange))
322  return(pixel/12.92f);
324  pixel+0.055)/1.055)));
325 }
326 
327 /*
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 % %
330 % %
331 % %
332 + D e s t r o y P i x e l C h a n n e l M a p %
333 % %
334 % %
335 % %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 %
338 % DestroyPixelChannelMap() deallocates memory associated with the pixel
339 % channel map.
340 %
341 % The format of the DestroyPixelChannelMap() method is:
342 %
343 % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map)
344 %
345 % A description of each parameter follows:
346 %
347 % o channel_map: the pixel component map.
348 %
349 */
351  PixelChannelMap *channel_map)
352 {
353  assert(channel_map != (PixelChannelMap *) NULL);
354  channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map);
355  return((PixelChannelMap *) RelinquishMagickMemory(channel_map));
356 }
357 
358 /*
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 % %
361 % %
362 % %
363 + E n c o d e P i x e l G a m m a %
364 % %
365 % %
366 % %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368 %
369 % EncodePixelGamma() cancels any nonlinearity in the pixel.
370 %
371 % The format of the EncodePixelGamma method is:
372 %
373 % MagickRealType EncodePixelGamma(const double MagickRealType)
374 %
375 % A description of each parameter follows:
376 %
377 % o pixel: the pixel.
378 %
379 */
380 
381 static inline double EncodeGamma(const double x)
382 {
383  div_t
384  quotient;
385 
386  double
387  p,
388  term[9];
389 
390  int
391  exponent;
392 
393  static const double coefficient[] = /* Chebychevi poly: x^(5/12), x=1.5 */
394  {
395  1.1758200232996901923,
396  0.16665763094889061230,
397  -0.0083154894939042125035,
398  0.00075187976780420279038,
399  -0.000083240178519391795367,
400  0.000010229209410070008679,
401  -1.3400466409860246e-06,
402  1.8333422241635376682e-07,
403  -2.5878596761348859722e-08
404  };
405 
406  static const double powers_of_two[] = /* (2^N)^(5/12) */
407  {
408  1.0,
409  1.3348398541700343678,
410  1.7817974362806785482,
411  2.3784142300054420538,
412  3.1748021039363991669,
413  4.2378523774371812394,
414  5.6568542494923805819,
415  7.5509945014535482244,
416  1.0079368399158985525e1,
417  1.3454342644059433809e1,
418  1.7959392772949968275e1,
419  2.3972913230026907883e1
420  };
421 
422  /*
423  Compute x^(1/2.4) == x^(5/12) == pow(x,1.0/2.4).
424  */
425  term[0]=1.0;
426  term[1]=4.0*frexp(x,&exponent)-3.0;
427  term[2]=2.0*term[1]*term[1]-term[0];
428  term[3]=2.0*term[1]*term[2]-term[1];
429  term[4]=2.0*term[1]*term[3]-term[2];
430  term[5]=2.0*term[1]*term[4]-term[3];
431  term[6]=2.0*term[1]*term[5]-term[4];
432  term[7]=2.0*term[1]*term[6]-term[5];
433  term[8]=2.0*term[1]*term[7]-term[6];
434  p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+
435  coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+
436  coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8];
437  quotient=div(exponent-1,12);
438  if (quotient.rem < 0)
439  {
440  quotient.quot-=1;
441  quotient.rem+=12;
442  }
443  return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot));
444 }
445 
447 {
448  if (pixel <= (0.0031306684425005883*QuantumRange))
449  return(12.92f*pixel);
450  return((MagickRealType) QuantumRange*(1.055*EncodeGamma((double) QuantumScale*
451  pixel)-0.055));
452 }
453 
454 /*
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 % %
457 % %
458 % %
459 % E x p o r t I m a g e P i x e l s %
460 % %
461 % %
462 % %
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464 %
465 % ExportImagePixels() extracts pixel data from an image and returns it to you.
466 % The method returns MagickTrue on success otherwise MagickFalse if an error is
467 % encountered. The data is returned as char, short int, Quantum, unsigned int,
468 % unsigned long long, float, or double in the order specified by map.
469 %
470 % Suppose you want to extract the first scanline of a 640x480 image as
471 % character data in red-green-blue order:
472 %
473 % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
474 %
475 % The format of the ExportImagePixels method is:
476 %
477 % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
478 % const ssize_t y,const size_t width,const size_t height,
479 % const char *map,const StorageType type,void *pixels,
480 % ExceptionInfo *exception)
481 %
482 % A description of each parameter follows:
483 %
484 % o image: the image.
485 %
486 % o x,y,width,height: These values define the perimeter
487 % of a region of pixels you want to extract.
488 %
489 % o map: This string reflects the expected ordering of the pixel array.
490 % It can be any combination or order of R = red, G = green, B = blue,
491 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
492 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
493 % P = pad.
494 %
495 % o type: Define the data type of the pixels. Float and double types are
496 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
497 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
498 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
499 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
500 %
501 % o pixels: This array of values contain the pixel components as defined by
502 % map and type. You must preallocate this array where the expected
503 % length varies depending on the values of width, height, map, and type.
504 %
505 % o exception: return any errors or warnings in this structure.
506 %
507 */
508 
510  const RectangleInfo *roi,const char *magick_restrict map,
511  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
512 {
513  register const Quantum
514  *magick_restrict p;
515 
516  register ssize_t
517  x;
518 
519  register unsigned char
520  *magick_restrict q;
521 
522  size_t
523  length;
524 
525  ssize_t
526  y;
527 
528  q=(unsigned char *) pixels;
529  if (LocaleCompare(map,"BGR") == 0)
530  {
531  for (y=0; y < (ssize_t) roi->height; y++)
532  {
533  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
534  if (p == (const Quantum *) NULL)
535  break;
536  for (x=0; x < (ssize_t) roi->width; x++)
537  {
538  *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
539  *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
540  *q++=ScaleQuantumToChar(GetPixelRed(image,p));
541  p+=GetPixelChannels(image);
542  }
543  }
544  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
545  }
546  if (LocaleCompare(map,"BGRA") == 0)
547  {
548  for (y=0; y < (ssize_t) roi->height; y++)
549  {
550  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
551  if (p == (const Quantum *) NULL)
552  break;
553  for (x=0; x < (ssize_t) roi->width; x++)
554  {
555  *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
556  *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
557  *q++=ScaleQuantumToChar(GetPixelRed(image,p));
558  *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
559  p+=GetPixelChannels(image);
560  }
561  }
562  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
563  }
564  if (LocaleCompare(map,"BGRP") == 0)
565  {
566  for (y=0; y < (ssize_t) roi->height; y++)
567  {
568  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
569  if (p == (const Quantum *) NULL)
570  break;
571  for (x=0; x < (ssize_t) roi->width; x++)
572  {
573  *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
574  *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
575  *q++=ScaleQuantumToChar(GetPixelRed(image,p));
576  *q++=ScaleQuantumToChar((Quantum) 0);
577  p+=GetPixelChannels(image);
578  }
579  }
580  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
581  }
582  if (LocaleCompare(map,"I") == 0)
583  {
584  for (y=0; y < (ssize_t) roi->height; y++)
585  {
586  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
587  if (p == (const Quantum *) NULL)
588  break;
589  for (x=0; x < (ssize_t) roi->width; x++)
590  {
591  *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
592  p+=GetPixelChannels(image);
593  }
594  }
595  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
596  }
597  if (LocaleCompare(map,"RGB") == 0)
598  {
599  for (y=0; y < (ssize_t) roi->height; y++)
600  {
601  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
602  if (p == (const Quantum *) NULL)
603  break;
604  for (x=0; x < (ssize_t) roi->width; x++)
605  {
606  *q++=ScaleQuantumToChar(GetPixelRed(image,p));
607  *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
608  *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
609  p+=GetPixelChannels(image);
610  }
611  }
612  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
613  }
614  if (LocaleCompare(map,"RGBA") == 0)
615  {
616  for (y=0; y < (ssize_t) roi->height; y++)
617  {
618  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
619  if (p == (const Quantum *) NULL)
620  break;
621  for (x=0; x < (ssize_t) roi->width; x++)
622  {
623  *q++=ScaleQuantumToChar(GetPixelRed(image,p));
624  *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
625  *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
626  *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
627  p+=GetPixelChannels(image);
628  }
629  }
630  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
631  }
632  if (LocaleCompare(map,"RGBP") == 0)
633  {
634  for (y=0; y < (ssize_t) roi->height; y++)
635  {
636  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
637  if (p == (const Quantum *) NULL)
638  break;
639  for (x=0; x < (ssize_t) roi->width; x++)
640  {
641  *q++=ScaleQuantumToChar(GetPixelRed(image,p));
642  *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
643  *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
644  *q++=ScaleQuantumToChar((Quantum) 0);
645  p+=GetPixelChannels(image);
646  }
647  }
648  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
649  }
650  length=strlen(map);
651  for (y=0; y < (ssize_t) roi->height; y++)
652  {
653  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
654  if (p == (const Quantum *) NULL)
655  break;
656  for (x=0; x < (ssize_t) roi->width; x++)
657  {
658  register ssize_t
659  i;
660 
661  for (i=0; i < (ssize_t) length; i++)
662  {
663  *q=0;
664  switch (quantum_map[i])
665  {
666  case RedQuantum:
667  case CyanQuantum:
668  {
669  *q=ScaleQuantumToChar(GetPixelRed(image,p));
670  break;
671  }
672  case GreenQuantum:
673  case MagentaQuantum:
674  {
675  *q=ScaleQuantumToChar(GetPixelGreen(image,p));
676  break;
677  }
678  case BlueQuantum:
679  case YellowQuantum:
680  {
681  *q=ScaleQuantumToChar(GetPixelBlue(image,p));
682  break;
683  }
684  case AlphaQuantum:
685  {
686  *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
687  break;
688  }
689  case OpacityQuantum:
690  {
691  *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
692  break;
693  }
694  case BlackQuantum:
695  {
696  if (image->colorspace == CMYKColorspace)
697  *q=ScaleQuantumToChar(GetPixelBlack(image,p));
698  break;
699  }
700  case IndexQuantum:
701  {
702  *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
703  break;
704  }
705  default:
706  break;
707  }
708  q++;
709  }
710  p+=GetPixelChannels(image);
711  }
712  }
713  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
714 }
715 
717  const RectangleInfo *roi,const char *magick_restrict map,
718  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
719 {
720  register const Quantum
721  *magick_restrict p;
722 
723  register double
724  *magick_restrict q;
725 
726  register ssize_t
727  x;
728 
729  size_t
730  length;
731 
732  ssize_t
733  y;
734 
735  q=(double *) pixels;
736  if (LocaleCompare(map,"BGR") == 0)
737  {
738  for (y=0; y < (ssize_t) roi->height; y++)
739  {
740  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
741  if (p == (const Quantum *) NULL)
742  break;
743  for (x=0; x < (ssize_t) roi->width; x++)
744  {
745  *q++=(double) (QuantumScale*GetPixelBlue(image,p));
746  *q++=(double) (QuantumScale*GetPixelGreen(image,p));
747  *q++=(double) (QuantumScale*GetPixelRed(image,p));
748  p+=GetPixelChannels(image);
749  }
750  }
751  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
752  }
753  if (LocaleCompare(map,"BGRA") == 0)
754  {
755  for (y=0; y < (ssize_t) roi->height; y++)
756  {
757  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
758  if (p == (const Quantum *) NULL)
759  break;
760  for (x=0; x < (ssize_t) roi->width; x++)
761  {
762  *q++=(double) (QuantumScale*GetPixelBlue(image,p));
763  *q++=(double) (QuantumScale*GetPixelGreen(image,p));
764  *q++=(double) (QuantumScale*GetPixelRed(image,p));
765  *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
766  p+=GetPixelChannels(image);
767  }
768  }
769  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
770  }
771  if (LocaleCompare(map,"BGRP") == 0)
772  {
773  for (y=0; y < (ssize_t) roi->height; y++)
774  {
775  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
776  if (p == (const Quantum *) NULL)
777  break;
778  for (x=0; x < (ssize_t) roi->width; x++)
779  {
780  *q++=(double) (QuantumScale*GetPixelBlue(image,p));
781  *q++=(double) (QuantumScale*GetPixelGreen(image,p));
782  *q++=(double) (QuantumScale*GetPixelRed(image,p));
783  *q++=0.0;
784  p+=GetPixelChannels(image);
785  }
786  }
787  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
788  }
789  if (LocaleCompare(map,"I") == 0)
790  {
791  for (y=0; y < (ssize_t) roi->height; y++)
792  {
793  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
794  if (p == (const Quantum *) NULL)
795  break;
796  for (x=0; x < (ssize_t) roi->width; x++)
797  {
798  *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
799  p+=GetPixelChannels(image);
800  }
801  }
802  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
803  }
804  if (LocaleCompare(map,"RGB") == 0)
805  {
806  for (y=0; y < (ssize_t) roi->height; y++)
807  {
808  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
809  if (p == (const Quantum *) NULL)
810  break;
811  for (x=0; x < (ssize_t) roi->width; x++)
812  {
813  *q++=(double) (QuantumScale*GetPixelRed(image,p));
814  *q++=(double) (QuantumScale*GetPixelGreen(image,p));
815  *q++=(double) (QuantumScale*GetPixelBlue(image,p));
816  p+=GetPixelChannels(image);
817  }
818  }
819  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
820  }
821  if (LocaleCompare(map,"RGBA") == 0)
822  {
823  for (y=0; y < (ssize_t) roi->height; y++)
824  {
825  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
826  if (p == (const Quantum *) NULL)
827  break;
828  for (x=0; x < (ssize_t) roi->width; x++)
829  {
830  *q++=(double) (QuantumScale*GetPixelRed(image,p));
831  *q++=(double) (QuantumScale*GetPixelGreen(image,p));
832  *q++=(double) (QuantumScale*GetPixelBlue(image,p));
833  *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
834  p+=GetPixelChannels(image);
835  }
836  }
837  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
838  }
839  if (LocaleCompare(map,"RGBP") == 0)
840  {
841  for (y=0; y < (ssize_t) roi->height; y++)
842  {
843  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
844  if (p == (const Quantum *) NULL)
845  break;
846  for (x=0; x < (ssize_t) roi->width; x++)
847  {
848  *q++=(double) (QuantumScale*GetPixelRed(image,p));
849  *q++=(double) (QuantumScale*GetPixelGreen(image,p));
850  *q++=(double) (QuantumScale*GetPixelBlue(image,p));
851  *q++=0.0;
852  p+=GetPixelChannels(image);
853  }
854  }
855  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
856  }
857  length=strlen(map);
858  for (y=0; y < (ssize_t) roi->height; y++)
859  {
860  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
861  if (p == (const Quantum *) NULL)
862  break;
863  for (x=0; x < (ssize_t) roi->width; x++)
864  {
865  register ssize_t
866  i;
867 
868  for (i=0; i < (ssize_t) length; i++)
869  {
870  *q=0;
871  switch (quantum_map[i])
872  {
873  case RedQuantum:
874  case CyanQuantum:
875  {
876  *q=(double) (QuantumScale*GetPixelRed(image,p));
877  break;
878  }
879  case GreenQuantum:
880  case MagentaQuantum:
881  {
882  *q=(double) (QuantumScale*GetPixelGreen(image,p));
883  break;
884  }
885  case BlueQuantum:
886  case YellowQuantum:
887  {
888  *q=(double) (QuantumScale*GetPixelBlue(image,p));
889  break;
890  }
891  case AlphaQuantum:
892  {
893  *q=(double) (QuantumScale*GetPixelAlpha(image,p));
894  break;
895  }
896  case OpacityQuantum:
897  {
898  *q=(double) (QuantumScale*GetPixelAlpha(image,p));
899  break;
900  }
901  case BlackQuantum:
902  {
903  if (image->colorspace == CMYKColorspace)
904  *q=(double) (QuantumScale*
905  GetPixelBlack(image,p));
906  break;
907  }
908  case IndexQuantum:
909  {
910  *q=(double) (QuantumScale*GetPixelIntensity(image,p));
911  break;
912  }
913  default:
914  *q=0;
915  }
916  q++;
917  }
918  p+=GetPixelChannels(image);
919  }
920  }
921  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
922 }
923 
925  const RectangleInfo *roi,const char *magick_restrict map,
926  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
927 {
928  register const Quantum
929  *magick_restrict p;
930 
931  register float
932  *magick_restrict q;
933 
934  register ssize_t
935  x;
936 
937  size_t
938  length;
939 
940  ssize_t
941  y;
942 
943  q=(float *) pixels;
944  if (LocaleCompare(map,"BGR") == 0)
945  {
946  for (y=0; y < (ssize_t) roi->height; y++)
947  {
948  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
949  if (p == (const Quantum *) NULL)
950  break;
951  for (x=0; x < (ssize_t) roi->width; x++)
952  {
953  *q++=(float) (QuantumScale*GetPixelBlue(image,p));
954  *q++=(float) (QuantumScale*GetPixelGreen(image,p));
955  *q++=(float) (QuantumScale*GetPixelRed(image,p));
956  p+=GetPixelChannels(image);
957  }
958  }
959  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
960  }
961  if (LocaleCompare(map,"BGRA") == 0)
962  {
963  for (y=0; y < (ssize_t) roi->height; y++)
964  {
965  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
966  if (p == (const Quantum *) NULL)
967  break;
968  for (x=0; x < (ssize_t) roi->width; x++)
969  {
970  *q++=(float) (QuantumScale*GetPixelBlue(image,p));
971  *q++=(float) (QuantumScale*GetPixelGreen(image,p));
972  *q++=(float) (QuantumScale*GetPixelRed(image,p));
973  *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
974  p+=GetPixelChannels(image);
975  }
976  }
977  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
978  }
979  if (LocaleCompare(map,"BGRP") == 0)
980  {
981  for (y=0; y < (ssize_t) roi->height; y++)
982  {
983  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
984  if (p == (const Quantum *) NULL)
985  break;
986  for (x=0; x < (ssize_t) roi->width; x++)
987  {
988  *q++=(float) (QuantumScale*GetPixelBlue(image,p));
989  *q++=(float) (QuantumScale*GetPixelGreen(image,p));
990  *q++=(float) (QuantumScale*GetPixelRed(image,p));
991  *q++=0.0;
992  p+=GetPixelChannels(image);
993  }
994  }
995  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
996  }
997  if (LocaleCompare(map,"I") == 0)
998  {
999  for (y=0; y < (ssize_t) roi->height; y++)
1000  {
1001  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1002  if (p == (const Quantum *) NULL)
1003  break;
1004  for (x=0; x < (ssize_t) roi->width; x++)
1005  {
1006  *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
1007  p+=GetPixelChannels(image);
1008  }
1009  }
1010  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1011  }
1012  if (LocaleCompare(map,"RGB") == 0)
1013  {
1014  for (y=0; y < (ssize_t) roi->height; y++)
1015  {
1016  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1017  if (p == (const Quantum *) NULL)
1018  break;
1019  for (x=0; x < (ssize_t) roi->width; x++)
1020  {
1021  *q++=(float) (QuantumScale*GetPixelRed(image,p));
1022  *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1023  *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1024  p+=GetPixelChannels(image);
1025  }
1026  }
1027  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1028  }
1029  if (LocaleCompare(map,"RGBA") == 0)
1030  {
1031  for (y=0; y < (ssize_t) roi->height; y++)
1032  {
1033  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1034  if (p == (const Quantum *) NULL)
1035  break;
1036  for (x=0; x < (ssize_t) roi->width; x++)
1037  {
1038  *q++=(float) (QuantumScale*GetPixelRed(image,p));
1039  *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1040  *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1041  *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
1042  p+=GetPixelChannels(image);
1043  }
1044  }
1045  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1046  }
1047  if (LocaleCompare(map,"RGBP") == 0)
1048  {
1049  for (y=0; y < (ssize_t) roi->height; y++)
1050  {
1051  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1052  if (p == (const Quantum *) NULL)
1053  break;
1054  for (x=0; x < (ssize_t) roi->width; x++)
1055  {
1056  *q++=(float) (QuantumScale*GetPixelRed(image,p));
1057  *q++=(float) (QuantumScale*GetPixelGreen(image,p));
1058  *q++=(float) (QuantumScale*GetPixelBlue(image,p));
1059  *q++=0.0;
1060  p+=GetPixelChannels(image);
1061  }
1062  }
1063  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1064  }
1065  length=strlen(map);
1066  for (y=0; y < (ssize_t) roi->height; y++)
1067  {
1068  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1069  if (p == (const Quantum *) NULL)
1070  break;
1071  for (x=0; x < (ssize_t) roi->width; x++)
1072  {
1073  register ssize_t
1074  i;
1075 
1076  for (i=0; i < (ssize_t) length; i++)
1077  {
1078  *q=0;
1079  switch (quantum_map[i])
1080  {
1081  case RedQuantum:
1082  case CyanQuantum:
1083  {
1084  *q=(float) (QuantumScale*GetPixelRed(image,p));
1085  break;
1086  }
1087  case GreenQuantum:
1088  case MagentaQuantum:
1089  {
1090  *q=(float) (QuantumScale*GetPixelGreen(image,p));
1091  break;
1092  }
1093  case BlueQuantum:
1094  case YellowQuantum:
1095  {
1096  *q=(float) (QuantumScale*GetPixelBlue(image,p));
1097  break;
1098  }
1099  case AlphaQuantum:
1100  {
1101  *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
1102  break;
1103  }
1104  case OpacityQuantum:
1105  {
1106  *q=(float) (QuantumScale*GetPixelAlpha(image,p));
1107  break;
1108  }
1109  case BlackQuantum:
1110  {
1111  if (image->colorspace == CMYKColorspace)
1112  *q=(float) (QuantumScale* GetPixelBlack(image,p));
1113  break;
1114  }
1115  case IndexQuantum:
1116  {
1117  *q=(float) (QuantumScale*GetPixelIntensity(image,p));
1118  break;
1119  }
1120  default:
1121  *q=0;
1122  }
1123  q++;
1124  }
1125  p+=GetPixelChannels(image);
1126  }
1127  }
1128  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1129 }
1130 
1132  const RectangleInfo *roi,const char *magick_restrict map,
1133  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1134 {
1135  register const Quantum
1136  *magick_restrict p;
1137 
1138  register ssize_t
1139  x;
1140 
1141  register unsigned int
1142  *magick_restrict q;
1143 
1144  size_t
1145  length;
1146 
1147  ssize_t
1148  y;
1149 
1150  q=(unsigned int *) pixels;
1151  if (LocaleCompare(map,"BGR") == 0)
1152  {
1153  for (y=0; y < (ssize_t) roi->height; y++)
1154  {
1155  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1156  if (p == (const Quantum *) NULL)
1157  break;
1158  for (x=0; x < (ssize_t) roi->width; x++)
1159  {
1160  *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1161  *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1162  *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1163  p+=GetPixelChannels(image);
1164  }
1165  }
1166  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1167  }
1168  if (LocaleCompare(map,"BGRA") == 0)
1169  {
1170  for (y=0; y < (ssize_t) roi->height; y++)
1171  {
1172  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1173  if (p == (const Quantum *) NULL)
1174  break;
1175  for (x=0; x < (ssize_t) roi->width; x++)
1176  {
1177  *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1178  *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1179  *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1180  *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1181  p+=GetPixelChannels(image);
1182  }
1183  }
1184  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1185  }
1186  if (LocaleCompare(map,"BGRP") == 0)
1187  {
1188  for (y=0; y < (ssize_t) roi->height; y++)
1189  {
1190  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1191  if (p == (const Quantum *) NULL)
1192  break;
1193  for (x=0; x < (ssize_t) roi->width; x++)
1194  {
1195  *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1196  *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1197  *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1198  *q++=0;
1199  p+=GetPixelChannels(image);
1200  }
1201  }
1202  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1203  }
1204  if (LocaleCompare(map,"I") == 0)
1205  {
1206  for (y=0; y < (ssize_t) roi->height; y++)
1207  {
1208  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1209  if (p == (const Quantum *) NULL)
1210  break;
1211  for (x=0; x < (ssize_t) roi->width; x++)
1212  {
1213  *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1214  p+=GetPixelChannels(image);
1215  }
1216  }
1217  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1218  }
1219  if (LocaleCompare(map,"RGB") == 0)
1220  {
1221  for (y=0; y < (ssize_t) roi->height; y++)
1222  {
1223  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1224  if (p == (const Quantum *) NULL)
1225  break;
1226  for (x=0; x < (ssize_t) roi->width; x++)
1227  {
1228  *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1229  *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1230  *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1231  p+=GetPixelChannels(image);
1232  }
1233  }
1234  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1235  }
1236  if (LocaleCompare(map,"RGBA") == 0)
1237  {
1238  for (y=0; y < (ssize_t) roi->height; y++)
1239  {
1240  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1241  if (p == (const Quantum *) NULL)
1242  break;
1243  for (x=0; x < (ssize_t) roi->width; x++)
1244  {
1245  *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1246  *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1247  *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1248  *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
1249  p+=GetPixelChannels(image);
1250  }
1251  }
1252  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1253  }
1254  if (LocaleCompare(map,"RGBP") == 0)
1255  {
1256  for (y=0; y < (ssize_t) roi->height; y++)
1257  {
1258  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1259  if (p == (const Quantum *) NULL)
1260  break;
1261  for (x=0; x < (ssize_t) roi->width; x++)
1262  {
1263  *q++=ScaleQuantumToLong(GetPixelRed(image,p));
1264  *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
1265  *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
1266  *q++=0;
1267  p+=GetPixelChannels(image);
1268  }
1269  }
1270  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1271  }
1272  length=strlen(map);
1273  for (y=0; y < (ssize_t) roi->height; y++)
1274  {
1275  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1276  if (p == (const Quantum *) NULL)
1277  break;
1278  for (x=0; x < (ssize_t) roi->width; x++)
1279  {
1280  register ssize_t
1281  i;
1282 
1283  for (i=0; i < (ssize_t) length; i++)
1284  {
1285  *q=0;
1286  switch (quantum_map[i])
1287  {
1288  case RedQuantum:
1289  case CyanQuantum:
1290  {
1291  *q=ScaleQuantumToLong(GetPixelRed(image,p));
1292  break;
1293  }
1294  case GreenQuantum:
1295  case MagentaQuantum:
1296  {
1297  *q=ScaleQuantumToLong(GetPixelGreen(image,p));
1298  break;
1299  }
1300  case BlueQuantum:
1301  case YellowQuantum:
1302  {
1303  *q=ScaleQuantumToLong(GetPixelBlue(image,p));
1304  break;
1305  }
1306  case AlphaQuantum:
1307  {
1308  *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1309  break;
1310  }
1311  case OpacityQuantum:
1312  {
1313  *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
1314  break;
1315  }
1316  case BlackQuantum:
1317  {
1318  if (image->colorspace == CMYKColorspace)
1319  *q=ScaleQuantumToLong(GetPixelBlack(image,p));
1320  break;
1321  }
1322  case IndexQuantum:
1323  {
1324  *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
1325  break;
1326  }
1327  default:
1328  break;
1329  }
1330  q++;
1331  }
1332  p+=GetPixelChannels(image);
1333  }
1334  }
1335  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1336 }
1337 
1339  const RectangleInfo *roi,const char *magick_restrict map,
1340  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1341 {
1342  register const Quantum
1343  *magick_restrict p;
1344 
1345  register ssize_t
1346  x;
1347 
1348  register MagickSizeType
1349  *magick_restrict q;
1350 
1351  size_t
1352  length;
1353 
1354  ssize_t
1355  y;
1356 
1357  q=(MagickSizeType *) pixels;
1358  if (LocaleCompare(map,"BGR") == 0)
1359  {
1360  for (y=0; y < (ssize_t) roi->height; y++)
1361  {
1362  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1363  if (p == (const Quantum *) NULL)
1364  break;
1365  for (x=0; x < (ssize_t) roi->width; x++)
1366  {
1367  *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1368  *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1369  *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1370  p+=GetPixelChannels(image);
1371  }
1372  }
1373  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1374  }
1375  if (LocaleCompare(map,"BGRA") == 0)
1376  {
1377  for (y=0; y < (ssize_t) roi->height; y++)
1378  {
1379  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1380  if (p == (const Quantum *) NULL)
1381  break;
1382  for (x=0; x < (ssize_t) roi->width; x++)
1383  {
1384  *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1385  *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1386  *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1387  *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1388  p+=GetPixelChannels(image);
1389  }
1390  }
1391  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1392  }
1393  if (LocaleCompare(map,"BGRP") == 0)
1394  {
1395  for (y=0; y < (ssize_t) roi->height; y++)
1396  {
1397  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1398  if (p == (const Quantum *) NULL)
1399  break;
1400  for (x=0; x < (ssize_t) roi->width; x++)
1401  {
1402  *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1403  *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1404  *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1405  *q++=0;
1406  p+=GetPixelChannels(image);
1407  }
1408  }
1409  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1410  }
1411  if (LocaleCompare(map,"I") == 0)
1412  {
1413  for (y=0; y < (ssize_t) roi->height; y++)
1414  {
1415  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1416  if (p == (const Quantum *) NULL)
1417  break;
1418  for (x=0; x < (ssize_t) roi->width; x++)
1419  {
1420  *q++=ScaleQuantumToLongLong(ClampToQuantum(
1421  GetPixelIntensity(image,p)));
1422  p+=GetPixelChannels(image);
1423  }
1424  }
1425  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1426  }
1427  if (LocaleCompare(map,"RGB") == 0)
1428  {
1429  for (y=0; y < (ssize_t) roi->height; y++)
1430  {
1431  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1432  if (p == (const Quantum *) NULL)
1433  break;
1434  for (x=0; x < (ssize_t) roi->width; x++)
1435  {
1436  *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1437  *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1438  *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1439  p+=GetPixelChannels(image);
1440  }
1441  }
1442  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1443  }
1444  if (LocaleCompare(map,"RGBA") == 0)
1445  {
1446  for (y=0; y < (ssize_t) roi->height; y++)
1447  {
1448  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1449  if (p == (const Quantum *) NULL)
1450  break;
1451  for (x=0; x < (ssize_t) roi->width; x++)
1452  {
1453  *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1454  *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1455  *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1456  *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1457  p+=GetPixelChannels(image);
1458  }
1459  }
1460  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1461  }
1462  if (LocaleCompare(map,"RGBP") == 0)
1463  {
1464  for (y=0; y < (ssize_t) roi->height; y++)
1465  {
1466  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1467  if (p == (const Quantum *) NULL)
1468  break;
1469  for (x=0; x < (ssize_t) roi->width; x++)
1470  {
1471  *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
1472  *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1473  *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1474  *q++=0;
1475  p+=GetPixelChannels(image);
1476  }
1477  }
1478  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1479  }
1480  length=strlen(map);
1481  for (y=0; y < (ssize_t) roi->height; y++)
1482  {
1483  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1484  if (p == (const Quantum *) NULL)
1485  break;
1486  for (x=0; x < (ssize_t) roi->width; x++)
1487  {
1488  register ssize_t
1489  i;
1490 
1491  for (i=0; i < (ssize_t) length; i++)
1492  {
1493  *q=0;
1494  switch (quantum_map[i])
1495  {
1496  case RedQuantum:
1497  case CyanQuantum:
1498  {
1499  *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
1500  break;
1501  }
1502  case GreenQuantum:
1503  case MagentaQuantum:
1504  {
1505  *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
1506  break;
1507  }
1508  case BlueQuantum:
1509  case YellowQuantum:
1510  {
1511  *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
1512  break;
1513  }
1514  case AlphaQuantum:
1515  {
1516  *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1517  break;
1518  }
1519  case OpacityQuantum:
1520  {
1521  *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
1522  break;
1523  }
1524  case BlackQuantum:
1525  {
1526  if (image->colorspace == CMYKColorspace)
1527  *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
1528  break;
1529  }
1530  case IndexQuantum:
1531  {
1532  *q=ScaleQuantumToLongLong(ClampToQuantum(
1533  GetPixelIntensity(image,p)));
1534  break;
1535  }
1536  default:
1537  break;
1538  }
1539  q++;
1540  }
1541  p+=GetPixelChannels(image);
1542  }
1543  }
1544  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1545 }
1546 
1548  const RectangleInfo *roi,const char *magick_restrict map,
1549  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1550 {
1551  register const Quantum
1552  *magick_restrict p;
1553 
1554  register Quantum
1555  *magick_restrict q;
1556 
1557  register ssize_t
1558  x;
1559 
1560  size_t
1561  length;
1562 
1563  ssize_t
1564  y;
1565 
1566  q=(Quantum *) pixels;
1567  if (LocaleCompare(map,"BGR") == 0)
1568  {
1569  for (y=0; y < (ssize_t) roi->height; y++)
1570  {
1571  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1572  if (p == (const Quantum *) NULL)
1573  break;
1574  for (x=0; x < (ssize_t) roi->width; x++)
1575  {
1576  *q++=GetPixelBlue(image,p);
1577  *q++=GetPixelGreen(image,p);
1578  *q++=GetPixelRed(image,p);
1579  p+=GetPixelChannels(image);
1580  }
1581  }
1582  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1583  }
1584  if (LocaleCompare(map,"BGRA") == 0)
1585  {
1586  for (y=0; y < (ssize_t) roi->height; y++)
1587  {
1588  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1589  if (p == (const Quantum *) NULL)
1590  break;
1591  for (x=0; x < (ssize_t) roi->width; x++)
1592  {
1593  *q++=GetPixelBlue(image,p);
1594  *q++=GetPixelGreen(image,p);
1595  *q++=GetPixelRed(image,p);
1596  *q++=(Quantum) (GetPixelAlpha(image,p));
1597  p+=GetPixelChannels(image);
1598  }
1599  }
1600  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1601  }
1602  if (LocaleCompare(map,"BGRP") == 0)
1603  {
1604  for (y=0; y < (ssize_t) roi->height; y++)
1605  {
1606  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1607  if (p == (const Quantum *) NULL)
1608  break;
1609  for (x=0; x < (ssize_t) roi->width; x++)
1610  {
1611  *q++=GetPixelBlue(image,p);
1612  *q++=GetPixelGreen(image,p);
1613  *q++=GetPixelRed(image,p);
1614  *q++=(Quantum) 0;
1615  p+=GetPixelChannels(image);
1616  }
1617  }
1618  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1619  }
1620  if (LocaleCompare(map,"I") == 0)
1621  {
1622  for (y=0; y < (ssize_t) roi->height; y++)
1623  {
1624  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1625  if (p == (const Quantum *) NULL)
1626  break;
1627  for (x=0; x < (ssize_t) roi->width; x++)
1628  {
1629  *q++=ClampToQuantum(GetPixelIntensity(image,p));
1630  p+=GetPixelChannels(image);
1631  }
1632  }
1633  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1634  }
1635  if (LocaleCompare(map,"RGB") == 0)
1636  {
1637  for (y=0; y < (ssize_t) roi->height; y++)
1638  {
1639  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1640  if (p == (const Quantum *) NULL)
1641  break;
1642  for (x=0; x < (ssize_t) roi->width; x++)
1643  {
1644  *q++=GetPixelRed(image,p);
1645  *q++=GetPixelGreen(image,p);
1646  *q++=GetPixelBlue(image,p);
1647  p+=GetPixelChannels(image);
1648  }
1649  }
1650  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1651  }
1652  if (LocaleCompare(map,"RGBA") == 0)
1653  {
1654  for (y=0; y < (ssize_t) roi->height; y++)
1655  {
1656  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1657  if (p == (const Quantum *) NULL)
1658  break;
1659  for (x=0; x < (ssize_t) roi->width; x++)
1660  {
1661  *q++=GetPixelRed(image,p);
1662  *q++=GetPixelGreen(image,p);
1663  *q++=GetPixelBlue(image,p);
1664  *q++=(Quantum) (GetPixelAlpha(image,p));
1665  p+=GetPixelChannels(image);
1666  }
1667  }
1668  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1669  }
1670  if (LocaleCompare(map,"RGBP") == 0)
1671  {
1672  for (y=0; y < (ssize_t) roi->height; y++)
1673  {
1674  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1675  if (p == (const Quantum *) NULL)
1676  break;
1677  for (x=0; x < (ssize_t) roi->width; x++)
1678  {
1679  *q++=GetPixelRed(image,p);
1680  *q++=GetPixelGreen(image,p);
1681  *q++=GetPixelBlue(image,p);
1682  *q++=(Quantum) 0;
1683  p+=GetPixelChannels(image);
1684  }
1685  }
1686  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1687  }
1688  length=strlen(map);
1689  for (y=0; y < (ssize_t) roi->height; y++)
1690  {
1691  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1692  if (p == (const Quantum *) NULL)
1693  break;
1694  for (x=0; x < (ssize_t) roi->width; x++)
1695  {
1696  register ssize_t
1697  i;
1698 
1699  for (i=0; i < (ssize_t) length; i++)
1700  {
1701  *q=(Quantum) 0;
1702  switch (quantum_map[i])
1703  {
1704  case RedQuantum:
1705  case CyanQuantum:
1706  {
1707  *q=GetPixelRed(image,p);
1708  break;
1709  }
1710  case GreenQuantum:
1711  case MagentaQuantum:
1712  {
1713  *q=GetPixelGreen(image,p);
1714  break;
1715  }
1716  case BlueQuantum:
1717  case YellowQuantum:
1718  {
1719  *q=GetPixelBlue(image,p);
1720  break;
1721  }
1722  case AlphaQuantum:
1723  {
1724  *q=GetPixelAlpha(image,p);
1725  break;
1726  }
1727  case OpacityQuantum:
1728  {
1729  *q=GetPixelAlpha(image,p);
1730  break;
1731  }
1732  case BlackQuantum:
1733  {
1734  if (image->colorspace == CMYKColorspace)
1735  *q=GetPixelBlack(image,p);
1736  break;
1737  }
1738  case IndexQuantum:
1739  {
1740  *q=ClampToQuantum(GetPixelIntensity(image,p));
1741  break;
1742  }
1743  default:
1744  {
1745  *q=(Quantum) 0;
1746  break;
1747  }
1748  }
1749  q++;
1750  }
1751  p+=GetPixelChannels(image);
1752  }
1753  }
1754  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1755 }
1756 
1758  const RectangleInfo *roi,const char *magick_restrict map,
1759  const QuantumType *quantum_map,void *pixels,ExceptionInfo *exception)
1760 {
1761  register const Quantum
1762  *magick_restrict p;
1763 
1764  register ssize_t
1765  x;
1766 
1767  register unsigned short
1768  *magick_restrict q;
1769 
1770  size_t
1771  length;
1772 
1773  ssize_t
1774  y;
1775 
1776  q=(unsigned short *) pixels;
1777  if (LocaleCompare(map,"BGR") == 0)
1778  {
1779  for (y=0; y < (ssize_t) roi->height; y++)
1780  {
1781  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1782  if (p == (const Quantum *) NULL)
1783  break;
1784  for (x=0; x < (ssize_t) roi->width; x++)
1785  {
1786  *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1787  *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1788  *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1789  p+=GetPixelChannels(image);
1790  }
1791  }
1792  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1793  }
1794  if (LocaleCompare(map,"BGRA") == 0)
1795  {
1796  for (y=0; y < (ssize_t) roi->height; y++)
1797  {
1798  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1799  if (p == (const Quantum *) NULL)
1800  break;
1801  for (x=0; x < (ssize_t) roi->width; x++)
1802  {
1803  *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1804  *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1805  *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1806  *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1807  p+=GetPixelChannels(image);
1808  }
1809  }
1810  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1811  }
1812  if (LocaleCompare(map,"BGRP") == 0)
1813  {
1814  for (y=0; y < (ssize_t) roi->height; y++)
1815  {
1816  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1817  if (p == (const Quantum *) NULL)
1818  break;
1819  for (x=0; x < (ssize_t) roi->width; x++)
1820  {
1821  *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1822  *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1823  *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1824  *q++=0;
1825  p+=GetPixelChannels(image);
1826  }
1827  }
1828  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1829  }
1830  if (LocaleCompare(map,"I") == 0)
1831  {
1832  for (y=0; y < (ssize_t) roi->height; y++)
1833  {
1834  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1835  if (p == (const Quantum *) NULL)
1836  break;
1837  for (x=0; x < (ssize_t) roi->width; x++)
1838  {
1839  *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1840  p+=GetPixelChannels(image);
1841  }
1842  }
1843  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1844  }
1845  if (LocaleCompare(map,"RGB") == 0)
1846  {
1847  for (y=0; y < (ssize_t) roi->height; y++)
1848  {
1849  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1850  if (p == (const Quantum *) NULL)
1851  break;
1852  for (x=0; x < (ssize_t) roi->width; x++)
1853  {
1854  *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1855  *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1856  *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1857  p+=GetPixelChannels(image);
1858  }
1859  }
1860  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1861  }
1862  if (LocaleCompare(map,"RGBA") == 0)
1863  {
1864  for (y=0; y < (ssize_t) roi->height; y++)
1865  {
1866  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1867  if (p == (const Quantum *) NULL)
1868  break;
1869  for (x=0; x < (ssize_t) roi->width; x++)
1870  {
1871  *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1872  *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1873  *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1874  *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
1875  p+=GetPixelChannels(image);
1876  }
1877  }
1878  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1879  }
1880  if (LocaleCompare(map,"RGBP") == 0)
1881  {
1882  for (y=0; y < (ssize_t) roi->height; y++)
1883  {
1884  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1885  if (p == (const Quantum *) NULL)
1886  break;
1887  for (x=0; x < (ssize_t) roi->width; x++)
1888  {
1889  *q++=ScaleQuantumToShort(GetPixelRed(image,p));
1890  *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
1891  *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
1892  *q++=0;
1893  p+=GetPixelChannels(image);
1894  }
1895  }
1896  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1897  }
1898  length=strlen(map);
1899  for (y=0; y < (ssize_t) roi->height; y++)
1900  {
1901  p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
1902  if (p == (const Quantum *) NULL)
1903  break;
1904  for (x=0; x < (ssize_t) roi->width; x++)
1905  {
1906  register ssize_t
1907  i;
1908 
1909  for (i=0; i < (ssize_t) length; i++)
1910  {
1911  *q=0;
1912  switch (quantum_map[i])
1913  {
1914  case RedQuantum:
1915  case CyanQuantum:
1916  {
1917  *q=ScaleQuantumToShort(GetPixelRed(image,p));
1918  break;
1919  }
1920  case GreenQuantum:
1921  case MagentaQuantum:
1922  {
1923  *q=ScaleQuantumToShort(GetPixelGreen(image,p));
1924  break;
1925  }
1926  case BlueQuantum:
1927  case YellowQuantum:
1928  {
1929  *q=ScaleQuantumToShort(GetPixelBlue(image,p));
1930  break;
1931  }
1932  case AlphaQuantum:
1933  {
1934  *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1935  break;
1936  }
1937  case OpacityQuantum:
1938  {
1939  *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
1940  break;
1941  }
1942  case BlackQuantum:
1943  {
1944  if (image->colorspace == CMYKColorspace)
1945  *q=ScaleQuantumToShort(GetPixelBlack(image,p));
1946  break;
1947  }
1948  case IndexQuantum:
1949  {
1950  *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p)));
1951  break;
1952  }
1953  default:
1954  break;
1955  }
1956  q++;
1957  }
1958  p+=GetPixelChannels(image);
1959  }
1960  }
1961  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
1962 }
1963 
1965  const ssize_t x,const ssize_t y,const size_t width,const size_t height,
1966  const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1967 {
1969  status;
1970 
1971  QuantumType
1972  *quantum_map;
1973 
1975  roi;
1976 
1977  register ssize_t
1978  i;
1979 
1980  size_t
1981  length;
1982 
1983  assert(image != (Image *) NULL);
1984  assert(image->signature == MagickCoreSignature);
1985  if (image->debug != MagickFalse)
1986  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1987  length=strlen(map);
1988  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
1989  if (quantum_map == (QuantumType *) NULL)
1990  {
1991  (void) ThrowMagickException(exception,GetMagickModule(),
1992  ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
1993  return(MagickFalse);
1994  }
1995  for (i=0; i < (ssize_t) length; i++)
1996  {
1997  switch (map[i])
1998  {
1999  case 'A':
2000  case 'a':
2001  {
2002  quantum_map[i]=AlphaQuantum;
2003  break;
2004  }
2005  case 'B':
2006  case 'b':
2007  {
2008  quantum_map[i]=BlueQuantum;
2009  break;
2010  }
2011  case 'C':
2012  case 'c':
2013  {
2014  quantum_map[i]=CyanQuantum;
2015  if (image->colorspace == CMYKColorspace)
2016  break;
2017  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2018  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2019  "ColorSeparatedImageRequired","`%s'",map);
2020  return(MagickFalse);
2021  }
2022  case 'g':
2023  case 'G':
2024  {
2025  quantum_map[i]=GreenQuantum;
2026  break;
2027  }
2028  case 'I':
2029  case 'i':
2030  {
2031  quantum_map[i]=IndexQuantum;
2032  break;
2033  }
2034  case 'K':
2035  case 'k':
2036  {
2037  quantum_map[i]=BlackQuantum;
2038  if (image->colorspace == CMYKColorspace)
2039  break;
2040  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2041  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2042  "ColorSeparatedImageRequired","`%s'",map);
2043  return(MagickFalse);
2044  }
2045  case 'M':
2046  case 'm':
2047  {
2048  quantum_map[i]=MagentaQuantum;
2049  if (image->colorspace == CMYKColorspace)
2050  break;
2051  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2052  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2053  "ColorSeparatedImageRequired","`%s'",map);
2054  return(MagickFalse);
2055  }
2056  case 'o':
2057  case 'O':
2058  {
2059  quantum_map[i]=OpacityQuantum;
2060  break;
2061  }
2062  case 'P':
2063  case 'p':
2064  {
2065  quantum_map[i]=UndefinedQuantum;
2066  break;
2067  }
2068  case 'R':
2069  case 'r':
2070  {
2071  quantum_map[i]=RedQuantum;
2072  break;
2073  }
2074  case 'Y':
2075  case 'y':
2076  {
2077  quantum_map[i]=YellowQuantum;
2078  if (image->colorspace == CMYKColorspace)
2079  break;
2080  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2081  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2082  "ColorSeparatedImageRequired","`%s'",map);
2083  return(MagickFalse);
2084  }
2085  default:
2086  {
2087  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2089  "UnrecognizedPixelMap","`%s'",map);
2090  return(MagickFalse);
2091  }
2092  }
2093  }
2094  roi.width=width;
2095  roi.height=height;
2096  roi.x=x;
2097  roi.y=y;
2098  switch (type)
2099  {
2100  case CharPixel:
2101  {
2102  status=ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
2103  break;
2104  }
2105  case DoublePixel:
2106  {
2107  status=ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
2108  break;
2109  }
2110  case FloatPixel:
2111  {
2112  status=ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
2113  break;
2114  }
2115  case LongPixel:
2116  {
2117  status=ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
2118  break;
2119  }
2120  case LongLongPixel:
2121  {
2122  status=ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
2123  break;
2124  }
2125  case QuantumPixel:
2126  {
2127  status=ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
2128  break;
2129  }
2130  case ShortPixel:
2131  {
2132  status=ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
2133  break;
2134  }
2135  default:
2136  {
2138  "UnrecognizedPixelMap","`%s'",map);
2139  status=MagickFalse;
2140  }
2141  }
2142  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2143  return(status);
2144 }
2145 
2146 /*
2147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2148 % %
2149 % %
2150 % %
2151 % G e t P i x e l I n f o %
2152 % %
2153 % %
2154 % %
2155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2156 %
2157 % GetPixelInfo() initializes the PixelInfo structure.
2158 %
2159 % The format of the GetPixelInfo method is:
2160 %
2161 % GetPixelInfo(const Image *image,PixelInfo *pixel)
2162 %
2163 % A description of each parameter follows:
2164 %
2165 % o image: the image. (optional - may be NULL)
2166 %
2167 % o pixel: Specifies a pointer to a PixelInfo structure.
2168 %
2169 */
2170 MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
2171 {
2172  pixel->storage_class=DirectClass;
2173  pixel->colorspace=sRGBColorspace;
2175  pixel->fuzz=0.0;
2177  pixel->red=0.0;
2178  pixel->green=0.0;
2179  pixel->blue=0.0;
2180  pixel->black=0.0;
2181  pixel->alpha=(double) OpaqueAlpha;
2182  pixel->index=0.0;
2183  pixel->count=0;
2184  if (image == (const Image *) NULL)
2185  return;
2186  pixel->storage_class=image->storage_class;
2187  pixel->colorspace=image->colorspace;
2188  pixel->alpha_trait=image->alpha_trait;
2189  pixel->depth=image->depth;
2190  pixel->fuzz=image->fuzz;
2191 }
2192 
2193 /*
2194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2195 % %
2196 % %
2197 % %
2198 % G e t P i x e l I n d o I n t e n s i t y %
2199 % %
2200 % %
2201 % %
2202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2203 %
2204 % GetPixelInfoIntensity() returns a single sample intensity value from the red,
2205 % green, and blue components of a pixel based on the selected method:
2206 %
2207 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2208 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2209 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2210 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2211 % Brightness max(R', G', B')
2212 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2213 %
2214 % MS (R^2 + G^2 + B^2) / 3.0
2215 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2216 % Average (R + G + B') / 3.0
2217 %
2218 % The format of the GetPixelInfoIntensity method is:
2219 %
2220 % MagickRealType GetPixelInfoIntensity(const Image *image,
2221 % const Quantum *pixel)
2222 %
2223 % A description of each parameter follows:
2224 %
2225 % o image: the image.
2226 %
2227 % o pixel: Specifies a pointer to a Quantum structure.
2228 %
2229 */
2231  const Image *magick_restrict image,const PixelInfo *magick_restrict pixel)
2232 {
2234  blue,
2235  green,
2236  red,
2237  intensity;
2238 
2240  method;
2241 
2243  if (image != (const Image *) NULL)
2244  method=image->intensity;
2245  red=pixel->red;
2246  green=pixel->green;
2247  blue=pixel->blue;
2248  switch (method)
2249  {
2251  {
2252  intensity=(red+green+blue)/3.0;
2253  break;
2254  }
2256  {
2257  intensity=MagickMax(MagickMax(red,green),blue);
2258  break;
2259  }
2261  {
2262  intensity=(MagickMin(MagickMin(red,green),blue)+
2263  MagickMax(MagickMax(red,green),blue))/2.0;
2264  break;
2265  }
2267  {
2268  intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2269  (3.0*QuantumRange));
2270  break;
2271  }
2273  {
2274  if (pixel->colorspace == RGBColorspace)
2275  {
2276  red=EncodePixelGamma(red);
2277  green=EncodePixelGamma(green);
2278  blue=EncodePixelGamma(blue);
2279  }
2280  intensity=0.298839*red+0.586811*green+0.114350*blue;
2281  break;
2282  }
2284  {
2285  if (pixel->colorspace == sRGBColorspace)
2286  {
2287  red=DecodePixelGamma(red);
2288  green=DecodePixelGamma(green);
2289  blue=DecodePixelGamma(blue);
2290  }
2291  intensity=0.298839*red+0.586811*green+0.114350*blue;
2292  break;
2293  }
2295  default:
2296  {
2297  if (pixel->colorspace == RGBColorspace)
2298  {
2299  red=EncodePixelGamma(red);
2300  green=EncodePixelGamma(green);
2301  blue=EncodePixelGamma(blue);
2302  }
2303  intensity=0.212656*red+0.715158*green+0.072186*blue;
2304  break;
2305  }
2307  {
2308  if (pixel->colorspace == sRGBColorspace)
2309  {
2310  red=DecodePixelGamma(red);
2311  green=DecodePixelGamma(green);
2312  blue=DecodePixelGamma(blue);
2313  }
2314  intensity=0.212656*red+0.715158*green+0.072186*blue;
2315  break;
2316  }
2318  {
2319  intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2320  sqrt(3.0));
2321  break;
2322  }
2323  }
2324  return(intensity);
2325 }
2326 
2327 /*
2328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2329 % %
2330 % %
2331 % %
2332 % G e t P i x e l I n t e n s i t y %
2333 % %
2334 % %
2335 % %
2336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2337 %
2338 % GetPixelIntensity() returns a single sample intensity value from the red,
2339 % green, and blue components of a pixel based on the selected method:
2340 %
2341 % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B'
2342 % Rec601Luminance 0.298839R + 0.586811G + 0.114350B
2343 % Rec709Luma 0.212656R' + 0.715158G' + 0.072186B'
2344 % Rec709Luminance 0.212656R + 0.715158G + 0.072186B
2345 % Brightness max(R', G', B')
2346 % Lightness (min(R', G', B') + max(R', G', B')) / 2.0
2347 %
2348 % MS (R^2 + G^2 + B^2) / 3.0
2349 % RMS sqrt((R^2 + G^2 + B^2) / 3.0
2350 % Average (R + G + B') / 3.0
2351 %
2352 % The format of the GetPixelIntensity method is:
2353 %
2354 % MagickRealType GetPixelIntensity(const Image *image,
2355 % const Quantum *pixel)
2356 %
2357 % A description of each parameter follows:
2358 %
2359 % o image: the image.
2360 %
2361 % o pixel: Specifies a pointer to a Quantum structure.
2362 %
2363 */
2365  const Image *magick_restrict image,const Quantum *magick_restrict pixel)
2366 {
2368  blue,
2369  green,
2370  red,
2371  intensity;
2372 
2373  red=(MagickRealType) GetPixelRed(image,pixel);
2374  green=(MagickRealType) GetPixelGreen(image,pixel);
2375  blue=(MagickRealType) GetPixelBlue(image,pixel);
2376  switch (image->intensity)
2377  {
2379  {
2380  intensity=(red+green+blue)/3.0;
2381  break;
2382  }
2384  {
2385  intensity=MagickMax(MagickMax(red,green),blue);
2386  break;
2387  }
2389  {
2390  intensity=(MagickMin(MagickMin(red,green),blue)+
2391  MagickMax(MagickMax(red,green),blue))/2.0;
2392  break;
2393  }
2395  {
2396  intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/
2397  (3.0*QuantumRange));
2398  break;
2399  }
2401  {
2402  if (image->colorspace == RGBColorspace)
2403  {
2404  red=EncodePixelGamma(red);
2405  green=EncodePixelGamma(green);
2406  blue=EncodePixelGamma(blue);
2407  }
2408  intensity=0.298839*red+0.586811*green+0.114350*blue;
2409  break;
2410  }
2412  {
2413  if (image->colorspace == sRGBColorspace)
2414  {
2415  red=DecodePixelGamma(red);
2416  green=DecodePixelGamma(green);
2417  blue=DecodePixelGamma(blue);
2418  }
2419  intensity=0.298839*red+0.586811*green+0.114350*blue;
2420  break;
2421  }
2423  default:
2424  {
2425  if (image->colorspace == RGBColorspace)
2426  {
2427  red=EncodePixelGamma(red);
2428  green=EncodePixelGamma(green);
2429  blue=EncodePixelGamma(blue);
2430  }
2431  intensity=0.212656*red+0.715158*green+0.072186*blue;
2432  break;
2433  }
2435  {
2436  if (image->colorspace == sRGBColorspace)
2437  {
2438  red=DecodePixelGamma(red);
2439  green=DecodePixelGamma(green);
2440  blue=DecodePixelGamma(blue);
2441  }
2442  intensity=0.212656*red+0.715158*green+0.072186*blue;
2443  break;
2444  }
2446  {
2447  intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/
2448  sqrt(3.0));
2449  break;
2450  }
2451  }
2452  return(intensity);
2453 }
2454 
2455 /*
2456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2457 % %
2458 % %
2459 % %
2460 % I m p o r t I m a g e P i x e l s %
2461 % %
2462 % %
2463 % %
2464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2465 %
2466 % ImportImagePixels() accepts pixel data and stores in the image at the
2467 % location you specify. The method returns MagickTrue on success otherwise
2468 % MagickFalse if an error is encountered. The pixel data can be either char,
2469 % Quantum, short int, unsigned int, unsigned long long, float, or double in
2470 % the order specified by map.
2471 %
2472 % Suppose your want to upload the first scanline of a 640x480 image from
2473 % character data in red-green-blue order:
2474 %
2475 % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
2476 %
2477 % The format of the ImportImagePixels method is:
2478 %
2479 % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
2480 % const ssize_t y,const size_t width,const size_t height,
2481 % const char *map,const StorageType type,const void *pixels,
2482 % ExceptionInfo *exception)
2483 %
2484 % A description of each parameter follows:
2485 %
2486 % o image: the image.
2487 %
2488 % o x,y,width,height: These values define the perimeter
2489 % of a region of pixels you want to define.
2490 %
2491 % o map: This string reflects the expected ordering of the pixel array.
2492 % It can be any combination or order of R = red, G = green, B = blue,
2493 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
2494 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
2495 % P = pad.
2496 %
2497 % o type: Define the data type of the pixels. Float and double types are
2498 % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these
2499 % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
2500 % LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
2501 % QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
2502 %
2503 % o pixels: This array of values contain the pixel components as defined by
2504 % map and type. You must preallocate this array where the expected
2505 % length varies depending on the values of width, height, map, and type.
2506 %
2507 % o exception: return any errors or warnings in this structure.
2508 %
2509 */
2510 
2512  const char *magick_restrict map,const QuantumType *quantum_map,
2513  const void *pixels,ExceptionInfo *exception)
2514 {
2515  register const unsigned char
2516  *magick_restrict p;
2517 
2518  register Quantum
2519  *magick_restrict q;
2520 
2521  register ssize_t
2522  x;
2523 
2524  size_t
2525  length;
2526 
2527  ssize_t
2528  y;
2529 
2530  p=(const unsigned char *) pixels;
2531  if (LocaleCompare(map,"BGR") == 0)
2532  {
2533  for (y=0; y < (ssize_t) roi->height; y++)
2534  {
2535  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2536  if (q == (Quantum *) NULL)
2537  break;
2538  for (x=0; x < (ssize_t) roi->width; x++)
2539  {
2540  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2541  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2542  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2543  q+=GetPixelChannels(image);
2544  }
2545  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2546  break;
2547  }
2548  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2549  }
2550  if (LocaleCompare(map,"BGRA") == 0)
2551  {
2552  for (y=0; y < (ssize_t) roi->height; y++)
2553  {
2554  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2555  if (q == (Quantum *) NULL)
2556  break;
2557  for (x=0; x < (ssize_t) roi->width; x++)
2558  {
2559  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2560  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2561  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2562  SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2563  q+=GetPixelChannels(image);
2564  }
2565  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2566  break;
2567  }
2568  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2569  }
2570  if (LocaleCompare(map,"BGRO") == 0)
2571  {
2572  for (y=0; y < (ssize_t) roi->height; y++)
2573  {
2574  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2575  if (q == (Quantum *) NULL)
2576  break;
2577  for (x=0; x < (ssize_t) roi->width; x++)
2578  {
2579  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2580  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2581  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2582  SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2583  q+=GetPixelChannels(image);
2584  }
2585  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2586  break;
2587  }
2588  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2589  }
2590  if (LocaleCompare(map,"BGRP") == 0)
2591  {
2592  for (y=0; y < (ssize_t) roi->height; y++)
2593  {
2594  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2595  if (q == (Quantum *) NULL)
2596  break;
2597  for (x=0; x < (ssize_t) roi->width; x++)
2598  {
2599  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2600  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2601  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2602  p++;
2603  q+=GetPixelChannels(image);
2604  }
2605  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2606  break;
2607  }
2608  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2609  }
2610  if (LocaleCompare(map,"I") == 0)
2611  {
2612  for (y=0; y < (ssize_t) roi->height; y++)
2613  {
2614  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2615  if (q == (Quantum *) NULL)
2616  break;
2617  for (x=0; x < (ssize_t) roi->width; x++)
2618  {
2619  SetPixelGray(image,ScaleCharToQuantum(*p++),q);
2620  q+=GetPixelChannels(image);
2621  }
2622  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2623  break;
2624  }
2625  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2626  }
2627  if (LocaleCompare(map,"RGB") == 0)
2628  {
2629  for (y=0; y < (ssize_t) roi->height; y++)
2630  {
2631  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2632  if (q == (Quantum *) NULL)
2633  break;
2634  for (x=0; x < (ssize_t) roi->width; x++)
2635  {
2636  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2637  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2638  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2639  q+=GetPixelChannels(image);
2640  }
2641  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2642  break;
2643  }
2644  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2645  }
2646  if (LocaleCompare(map,"RGBA") == 0)
2647  {
2648  for (y=0; y < (ssize_t) roi->height; y++)
2649  {
2650  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2651  if (q == (Quantum *) NULL)
2652  break;
2653  for (x=0; x < (ssize_t) roi->width; x++)
2654  {
2655  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2656  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2657  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2658  SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2659  q+=GetPixelChannels(image);
2660  }
2661  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2662  break;
2663  }
2664  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2665  }
2666  if (LocaleCompare(map,"RGBO") == 0)
2667  {
2668  for (y=0; y < (ssize_t) roi->height; y++)
2669  {
2670  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2671  if (q == (Quantum *) NULL)
2672  break;
2673  for (x=0; x < (ssize_t) roi->width; x++)
2674  {
2675  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2676  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2677  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2678  SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
2679  q+=GetPixelChannels(image);
2680  }
2681  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2682  break;
2683  }
2684  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2685  }
2686  if (LocaleCompare(map,"RGBP") == 0)
2687  {
2688  for (y=0; y < (ssize_t) roi->height; y++)
2689  {
2690  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2691  if (q == (Quantum *) NULL)
2692  break;
2693  for (x=0; x < (ssize_t) roi->width; x++)
2694  {
2695  SetPixelRed(image,ScaleCharToQuantum(*p++),q);
2696  SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
2697  SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
2698  p++;
2699  q+=GetPixelChannels(image);
2700  }
2701  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2702  break;
2703  }
2704  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2705  }
2706  length=strlen(map);
2707  for (y=0; y < (ssize_t) roi->height; y++)
2708  {
2709  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2710  if (q == (Quantum *) NULL)
2711  break;
2712  for (x=0; x < (ssize_t) roi->width; x++)
2713  {
2714  register ssize_t
2715  i;
2716 
2717  for (i=0; i < (ssize_t) length; i++)
2718  {
2719  switch (quantum_map[i])
2720  {
2721  case RedQuantum:
2722  case CyanQuantum:
2723  {
2724  SetPixelRed(image,ScaleCharToQuantum(*p),q);
2725  break;
2726  }
2727  case GreenQuantum:
2728  case MagentaQuantum:
2729  {
2730  SetPixelGreen(image,ScaleCharToQuantum(*p),q);
2731  break;
2732  }
2733  case BlueQuantum:
2734  case YellowQuantum:
2735  {
2736  SetPixelBlue(image,ScaleCharToQuantum(*p),q);
2737  break;
2738  }
2739  case AlphaQuantum:
2740  {
2741  SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2742  break;
2743  }
2744  case OpacityQuantum:
2745  {
2746  SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
2747  break;
2748  }
2749  case BlackQuantum:
2750  {
2751  SetPixelBlack(image,ScaleCharToQuantum(*p),q);
2752  break;
2753  }
2754  case IndexQuantum:
2755  {
2756  SetPixelGray(image,ScaleCharToQuantum(*p),q);
2757  break;
2758  }
2759  default:
2760  break;
2761  }
2762  p++;
2763  }
2764  q+=GetPixelChannels(image);
2765  }
2766  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2767  break;
2768  }
2769  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2770 }
2771 
2773  const RectangleInfo *roi,const char *magick_restrict map,
2774  const QuantumType *quantum_map,const void *pixels,ExceptionInfo *exception)
2775 {
2776  register const double
2777  *magick_restrict p;
2778 
2779  register Quantum
2780  *magick_restrict q;
2781 
2782  register ssize_t
2783  x;
2784 
2785  size_t
2786  length;
2787 
2788  ssize_t
2789  y;
2790 
2791  p=(const double *) pixels;
2792  if (LocaleCompare(map,"BGR") == 0)
2793  {
2794  for (y=0; y < (ssize_t) roi->height; y++)
2795  {
2796  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2797  if (q == (Quantum *) NULL)
2798  break;
2799  for (x=0; x < (ssize_t) roi->width; x++)
2800  {
2801  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2802  p++;
2803  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2804  p++;
2805  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2806  p++;
2807  q+=GetPixelChannels(image);
2808  }
2809  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2810  break;
2811  }
2812  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2813  }
2814  if (LocaleCompare(map,"BGRA") == 0)
2815  {
2816  for (y=0; y < (ssize_t) roi->height; y++)
2817  {
2818  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2819  if (q == (Quantum *) NULL)
2820  break;
2821  for (x=0; x < (ssize_t) roi->width; x++)
2822  {
2823  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2824  p++;
2825  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2826  p++;
2827  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2828  p++;
2829  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2830  p++;
2831  q+=GetPixelChannels(image);
2832  }
2833  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2834  break;
2835  }
2836  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2837  }
2838  if (LocaleCompare(map,"BGRP") == 0)
2839  {
2840  for (y=0; y < (ssize_t) roi->height; y++)
2841  {
2842  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2843  if (q == (Quantum *) NULL)
2844  break;
2845  for (x=0; x < (ssize_t) roi->width; x++)
2846  {
2847  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2848  p++;
2849  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2850  p++;
2851  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2852  p++;
2853  p++;
2854  q+=GetPixelChannels(image);
2855  }
2856  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2857  break;
2858  }
2859  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2860  }
2861  if (LocaleCompare(map,"I") == 0)
2862  {
2863  for (y=0; y < (ssize_t) roi->height; y++)
2864  {
2865  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2866  if (q == (Quantum *) NULL)
2867  break;
2868  for (x=0; x < (ssize_t) roi->width; x++)
2869  {
2870  SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2871  p++;
2872  q+=GetPixelChannels(image);
2873  }
2874  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2875  break;
2876  }
2877  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2878  }
2879  if (LocaleCompare(map,"RGB") == 0)
2880  {
2881  for (y=0; y < (ssize_t) roi->height; y++)
2882  {
2883  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2884  if (q == (Quantum *) NULL)
2885  break;
2886  for (x=0; x < (ssize_t) roi->width; x++)
2887  {
2888  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2889  p++;
2890  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2891  p++;
2892  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2893  p++;
2894  q+=GetPixelChannels(image);
2895  }
2896  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2897  break;
2898  }
2899  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2900  }
2901  if (LocaleCompare(map,"RGBA") == 0)
2902  {
2903  for (y=0; y < (ssize_t) roi->height; y++)
2904  {
2905  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2906  if (q == (Quantum *) NULL)
2907  break;
2908  for (x=0; x < (ssize_t) roi->width; x++)
2909  {
2910  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2911  p++;
2912  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2913  p++;
2914  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2915  p++;
2916  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2917  p++;
2918  q+=GetPixelChannels(image);
2919  }
2920  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2921  break;
2922  }
2923  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2924  }
2925  if (LocaleCompare(map,"RGBP") == 0)
2926  {
2927  for (y=0; y < (ssize_t) roi->height; y++)
2928  {
2929  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2930  if (q == (Quantum *) NULL)
2931  break;
2932  for (x=0; x < (ssize_t) roi->width; x++)
2933  {
2934  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2935  p++;
2936  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2937  p++;
2938  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2939  p++;
2940  q+=GetPixelChannels(image);
2941  }
2942  if (SyncAuthenticPixels(image,exception) == MagickFalse)
2943  break;
2944  }
2945  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
2946  }
2947  length=strlen(map);
2948  for (y=0; y < (ssize_t) roi->height; y++)
2949  {
2950  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
2951  if (q == (Quantum *) NULL)
2952  break;
2953  for (x=0; x < (ssize_t) roi->width; x++)
2954  {
2955  register ssize_t
2956  i;
2957 
2958  for (i=0; i < (ssize_t) length; i++)
2959  {
2960  switch (quantum_map[i])
2961  {
2962  case RedQuantum:
2963  case CyanQuantum:
2964  {
2965  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
2966  break;
2967  }
2968  case GreenQuantum:
2969  case MagentaQuantum:
2970  {
2971  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
2972  break;
2973  }
2974  case BlueQuantum:
2975  case YellowQuantum:
2976  {
2977  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
2978  break;
2979  }
2980  case AlphaQuantum:
2981  {
2982  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2983  break;
2984  }
2985  case OpacityQuantum:
2986  {
2987  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
2988  break;
2989  }
2990  case BlackQuantum:
2991  {
2992  SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
2993  break;
2994  }
2995  case IndexQuantum:
2996  {
2997  SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
2998  break;
2999  }
3000  default:
3001  break;
3002  }
3003  p++;
3004  }
3005  q+=GetPixelChannels(image);
3006  }
3007  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3008  break;
3009  }
3010  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3011 }
3012 
3014  const char *magick_restrict map,const QuantumType *quantum_map,
3015  const void *pixels,ExceptionInfo *exception)
3016 {
3017  register const float
3018  *magick_restrict p;
3019 
3020  register Quantum
3021  *magick_restrict q;
3022 
3023  register ssize_t
3024  x;
3025 
3026  size_t
3027  length;
3028 
3029  ssize_t
3030  y;
3031 
3032  p=(const float *) pixels;
3033  if (LocaleCompare(map,"BGR") == 0)
3034  {
3035  for (y=0; y < (ssize_t) roi->height; y++)
3036  {
3037  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3038  if (q == (Quantum *) NULL)
3039  break;
3040  for (x=0; x < (ssize_t) roi->width; x++)
3041  {
3042  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3043  p++;
3044  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3045  p++;
3046  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3047  p++;
3048  q+=GetPixelChannels(image);
3049  }
3050  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3051  break;
3052  }
3053  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3054  }
3055  if (LocaleCompare(map,"BGRA") == 0)
3056  {
3057  for (y=0; y < (ssize_t) roi->height; y++)
3058  {
3059  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3060  if (q == (Quantum *) NULL)
3061  break;
3062  for (x=0; x < (ssize_t) roi->width; x++)
3063  {
3064  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3065  p++;
3066  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3067  p++;
3068  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3069  p++;
3070  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3071  p++;
3072  q+=GetPixelChannels(image);
3073  }
3074  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3075  break;
3076  }
3077  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3078  }
3079  if (LocaleCompare(map,"BGRP") == 0)
3080  {
3081  for (y=0; y < (ssize_t) roi->height; y++)
3082  {
3083  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3084  if (q == (Quantum *) NULL)
3085  break;
3086  for (x=0; x < (ssize_t) roi->width; x++)
3087  {
3088  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3089  p++;
3090  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3091  p++;
3092  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3093  p++;
3094  p++;
3095  q+=GetPixelChannels(image);
3096  }
3097  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3098  break;
3099  }
3100  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3101  }
3102  if (LocaleCompare(map,"I") == 0)
3103  {
3104  for (y=0; y < (ssize_t) roi->height; y++)
3105  {
3106  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3107  if (q == (Quantum *) NULL)
3108  break;
3109  for (x=0; x < (ssize_t) roi->width; x++)
3110  {
3111  SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3112  p++;
3113  q+=GetPixelChannels(image);
3114  }
3115  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3116  break;
3117  }
3118  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3119  }
3120  if (LocaleCompare(map,"RGB") == 0)
3121  {
3122  for (y=0; y < (ssize_t) roi->height; y++)
3123  {
3124  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3125  if (q == (Quantum *) NULL)
3126  break;
3127  for (x=0; x < (ssize_t) roi->width; x++)
3128  {
3129  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3130  p++;
3131  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3132  p++;
3133  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3134  p++;
3135  q+=GetPixelChannels(image);
3136  }
3137  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3138  break;
3139  }
3140  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3141  }
3142  if (LocaleCompare(map,"RGBA") == 0)
3143  {
3144  for (y=0; y < (ssize_t) roi->height; y++)
3145  {
3146  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3147  if (q == (Quantum *) NULL)
3148  break;
3149  for (x=0; x < (ssize_t) roi->width; x++)
3150  {
3151  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3152  p++;
3153  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3154  p++;
3155  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3156  p++;
3157  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3158  p++;
3159  q+=GetPixelChannels(image);
3160  }
3161  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3162  break;
3163  }
3164  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3165  }
3166  if (LocaleCompare(map,"RGBP") == 0)
3167  {
3168  for (y=0; y < (ssize_t) roi->height; y++)
3169  {
3170  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3171  if (q == (Quantum *) NULL)
3172  break;
3173  for (x=0; x < (ssize_t) roi->width; x++)
3174  {
3175  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3176  p++;
3177  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3178  p++;
3179  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3180  p++;
3181  q+=GetPixelChannels(image);
3182  }
3183  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3184  break;
3185  }
3186  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3187  }
3188  length=strlen(map);
3189  for (y=0; y < (ssize_t) roi->height; y++)
3190  {
3191  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3192  if (q == (Quantum *) NULL)
3193  break;
3194  for (x=0; x < (ssize_t) roi->width; x++)
3195  {
3196  register ssize_t
3197  i;
3198 
3199  for (i=0; i < (ssize_t) length; i++)
3200  {
3201  switch (quantum_map[i])
3202  {
3203  case RedQuantum:
3204  case CyanQuantum:
3205  {
3206  SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
3207  break;
3208  }
3209  case GreenQuantum:
3210  case MagentaQuantum:
3211  {
3212  SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
3213  break;
3214  }
3215  case BlueQuantum:
3216  case YellowQuantum:
3217  {
3218  SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
3219  break;
3220  }
3221  case AlphaQuantum:
3222  {
3223  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3224  break;
3225  }
3226  case OpacityQuantum:
3227  {
3228  SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
3229  break;
3230  }
3231  case BlackQuantum:
3232  {
3233  SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
3234  break;
3235  }
3236  case IndexQuantum:
3237  {
3238  SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
3239  break;
3240  }
3241  default:
3242  break;
3243  }
3244  p++;
3245  }
3246  q+=GetPixelChannels(image);
3247  }
3248  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3249  break;
3250  }
3251  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3252 }
3253 
3255  const char *magick_restrict map,const QuantumType *quantum_map,
3256  const void *pixels,ExceptionInfo *exception)
3257 {
3258  register const unsigned int
3259  *magick_restrict p;
3260 
3261  register Quantum
3262  *magick_restrict q;
3263 
3264  register ssize_t
3265  x;
3266 
3267  size_t
3268  length;
3269 
3270  ssize_t
3271  y;
3272 
3273  p=(const unsigned int *) pixels;
3274  if (LocaleCompare(map,"BGR") == 0)
3275  {
3276  for (y=0; y < (ssize_t) roi->height; y++)
3277  {
3278  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3279  if (q == (Quantum *) NULL)
3280  break;
3281  for (x=0; x < (ssize_t) roi->width; x++)
3282  {
3283  SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3284  SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3285  SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3286  q+=GetPixelChannels(image);
3287  }
3288  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3289  break;
3290  }
3291  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3292  }
3293  if (LocaleCompare(map,"BGRA") == 0)
3294  {
3295  for (y=0; y < (ssize_t) roi->height; y++)
3296  {
3297  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3298  if (q == (Quantum *) NULL)
3299  break;
3300  for (x=0; x < (ssize_t) roi->width; x++)
3301  {
3302  SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3303  SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3304  SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3305  SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3306  q+=GetPixelChannels(image);
3307  }
3308  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3309  break;
3310  }
3311  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3312  }
3313  if (LocaleCompare(map,"BGRP") == 0)
3314  {
3315  for (y=0; y < (ssize_t) roi->height; y++)
3316  {
3317  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3318  if (q == (Quantum *) NULL)
3319  break;
3320  for (x=0; x < (ssize_t) roi->width; x++)
3321  {
3322  SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3323  SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3324  SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3325  p++;
3326  q+=GetPixelChannels(image);
3327  }
3328  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3329  break;
3330  }
3331  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3332  }
3333  if (LocaleCompare(map,"I") == 0)
3334  {
3335  for (y=0; y < (ssize_t) roi->height; y++)
3336  {
3337  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3338  if (q == (Quantum *) NULL)
3339  break;
3340  for (x=0; x < (ssize_t) roi->width; x++)
3341  {
3342  SetPixelGray(image,ScaleLongToQuantum(*p++),q);
3343  q+=GetPixelChannels(image);
3344  }
3345  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3346  break;
3347  }
3348  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3349  }
3350  if (LocaleCompare(map,"RGB") == 0)
3351  {
3352  for (y=0; y < (ssize_t) roi->height; y++)
3353  {
3354  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3355  if (q == (Quantum *) NULL)
3356  break;
3357  for (x=0; x < (ssize_t) roi->width; x++)
3358  {
3359  SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3360  SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3361  SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3362  q+=GetPixelChannels(image);
3363  }
3364  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3365  break;
3366  }
3367  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3368  }
3369  if (LocaleCompare(map,"RGBA") == 0)
3370  {
3371  for (y=0; y < (ssize_t) roi->height; y++)
3372  {
3373  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3374  if (q == (Quantum *) NULL)
3375  break;
3376  for (x=0; x < (ssize_t) roi->width; x++)
3377  {
3378  SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3379  SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3380  SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3381  SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
3382  q+=GetPixelChannels(image);
3383  }
3384  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3385  break;
3386  }
3387  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3388  }
3389  if (LocaleCompare(map,"RGBP") == 0)
3390  {
3391  for (y=0; y < (ssize_t) roi->height; y++)
3392  {
3393  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3394  if (q == (Quantum *) NULL)
3395  break;
3396  for (x=0; x < (ssize_t) roi->width; x++)
3397  {
3398  SetPixelRed(image,ScaleLongToQuantum(*p++),q);
3399  SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
3400  SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
3401  p++;
3402  q+=GetPixelChannels(image);
3403  }
3404  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3405  break;
3406  }
3407  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3408  }
3409  length=strlen(map);
3410  for (y=0; y < (ssize_t) roi->height; y++)
3411  {
3412  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3413  if (q == (Quantum *) NULL)
3414  break;
3415  for (x=0; x < (ssize_t) roi->width; x++)
3416  {
3417  register ssize_t
3418  i;
3419 
3420  for (i=0; i < (ssize_t) length; i++)
3421  {
3422  switch (quantum_map[i])
3423  {
3424  case RedQuantum:
3425  case CyanQuantum:
3426  {
3427  SetPixelRed(image,ScaleLongToQuantum(*p),q);
3428  break;
3429  }
3430  case GreenQuantum:
3431  case MagentaQuantum:
3432  {
3433  SetPixelGreen(image,ScaleLongToQuantum(*p),q);
3434  break;
3435  }
3436  case BlueQuantum:
3437  case YellowQuantum:
3438  {
3439  SetPixelBlue(image,ScaleLongToQuantum(*p),q);
3440  break;
3441  }
3442  case AlphaQuantum:
3443  {
3444  SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3445  break;
3446  }
3447  case OpacityQuantum:
3448  {
3449  SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
3450  break;
3451  }
3452  case BlackQuantum:
3453  {
3454  SetPixelBlack(image,ScaleLongToQuantum(*p),q);
3455  break;
3456  }
3457  case IndexQuantum:
3458  {
3459  SetPixelGray(image,ScaleLongToQuantum(*p),q);
3460  break;
3461  }
3462  default:
3463  break;
3464  }
3465  p++;
3466  }
3467  q+=GetPixelChannels(image);
3468  }
3469  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3470  break;
3471  }
3472  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3473 }
3474 
3476  const RectangleInfo *roi,const char *magick_restrict map,
3477  const QuantumType *quantum_map,const void *pixels,ExceptionInfo *exception)
3478 {
3479  register const MagickSizeType
3480  *magick_restrict p;
3481 
3482  register Quantum
3483  *magick_restrict q;
3484 
3485  register ssize_t
3486  x;
3487 
3488  size_t
3489  length;
3490 
3491  ssize_t
3492  y;
3493 
3494  p=(const MagickSizeType *) pixels;
3495  if (LocaleCompare(map,"BGR") == 0)
3496  {
3497  for (y=0; y < (ssize_t) roi->height; y++)
3498  {
3499  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3500  if (q == (Quantum *) NULL)
3501  break;
3502  for (x=0; x < (ssize_t) roi->width; x++)
3503  {
3504  SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3505  SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3506  SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3507  q+=GetPixelChannels(image);
3508  }
3509  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3510  break;
3511  }
3512  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3513  }
3514  if (LocaleCompare(map,"BGRA") == 0)
3515  {
3516  for (y=0; y < (ssize_t) roi->height; y++)
3517  {
3518  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3519  if (q == (Quantum *) NULL)
3520  break;
3521  for (x=0; x < (ssize_t) roi->width; x++)
3522  {
3523  SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3524  SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3525  SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3526  SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3527  q+=GetPixelChannels(image);
3528  }
3529  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3530  break;
3531  }
3532  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3533  }
3534  if (LocaleCompare(map,"BGRP") == 0)
3535  {
3536  for (y=0; y < (ssize_t) roi->height; y++)
3537  {
3538  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3539  if (q == (Quantum *) NULL)
3540  break;
3541  for (x=0; x < (ssize_t) roi->width; x++)
3542  {
3543  SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3544  SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3545  SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3546  p++;
3547  q+=GetPixelChannels(image);
3548  }
3549  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3550  break;
3551  }
3552  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3553  }
3554  if (LocaleCompare(map,"I") == 0)
3555  {
3556  for (y=0; y < (ssize_t) roi->height; y++)
3557  {
3558  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3559  if (q == (Quantum *) NULL)
3560  break;
3561  for (x=0; x < (ssize_t) roi->width; x++)
3562  {
3563  SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
3564  q+=GetPixelChannels(image);
3565  }
3566  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3567  break;
3568  }
3569  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3570  }
3571  if (LocaleCompare(map,"RGB") == 0)
3572  {
3573  for (y=0; y < (ssize_t) roi->height; y++)
3574  {
3575  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3576  if (q == (Quantum *) NULL)
3577  break;
3578  for (x=0; x < (ssize_t) roi->width; x++)
3579  {
3580  SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3581  SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3582  SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3583  q+=GetPixelChannels(image);
3584  }
3585  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3586  break;
3587  }
3588  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3589  }
3590  if (LocaleCompare(map,"RGBA") == 0)
3591  {
3592  for (y=0; y < (ssize_t) roi->height; y++)
3593  {
3594  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3595  if (q == (Quantum *) NULL)
3596  break;
3597  for (x=0; x < (ssize_t) roi->width; x++)
3598  {
3599  SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3600  SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3601  SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3602  SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
3603  q+=GetPixelChannels(image);
3604  }
3605  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3606  break;
3607  }
3608  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3609  }
3610  if (LocaleCompare(map,"RGBP") == 0)
3611  {
3612  for (y=0; y < (ssize_t) roi->height; y++)
3613  {
3614  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3615  if (q == (Quantum *) NULL)
3616  break;
3617  for (x=0; x < (ssize_t) roi->width; x++)
3618  {
3619  SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
3620  SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
3621  SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
3622  p++;
3623  q+=GetPixelChannels(image);
3624  }
3625  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3626  break;
3627  }
3628  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3629  }
3630  length=strlen(map);
3631  for (y=0; y < (ssize_t) roi->height; y++)
3632  {
3633  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3634  if (q == (Quantum *) NULL)
3635  break;
3636  for (x=0; x < (ssize_t) roi->width; x++)
3637  {
3638  register ssize_t
3639  i;
3640 
3641  for (i=0; i < (ssize_t) length; i++)
3642  {
3643  switch (quantum_map[i])
3644  {
3645  case RedQuantum:
3646  case CyanQuantum:
3647  {
3648  SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
3649  break;
3650  }
3651  case GreenQuantum:
3652  case MagentaQuantum:
3653  {
3654  SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
3655  break;
3656  }
3657  case BlueQuantum:
3658  case YellowQuantum:
3659  {
3660  SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
3661  break;
3662  }
3663  case AlphaQuantum:
3664  {
3665  SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3666  break;
3667  }
3668  case OpacityQuantum:
3669  {
3670  SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
3671  break;
3672  }
3673  case BlackQuantum:
3674  {
3675  SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
3676  break;
3677  }
3678  case IndexQuantum:
3679  {
3680  SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
3681  break;
3682  }
3683  default:
3684  break;
3685  }
3686  p++;
3687  }
3688  q+=GetPixelChannels(image);
3689  }
3690  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3691  break;
3692  }
3693  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3694 }
3695 
3697  const RectangleInfo *roi,const char *magick_restrict map,
3698  const QuantumType *quantum_map,const void *pixels,ExceptionInfo *exception)
3699 {
3700  register const Quantum
3701  *magick_restrict p;
3702 
3703  register Quantum
3704  *magick_restrict q;
3705 
3706  register ssize_t
3707  x;
3708 
3709  size_t
3710  length;
3711 
3712  ssize_t
3713  y;
3714 
3715  p=(const Quantum *) pixels;
3716  if (LocaleCompare(map,"BGR") == 0)
3717  {
3718  for (y=0; y < (ssize_t) roi->height; y++)
3719  {
3720  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3721  if (q == (Quantum *) NULL)
3722  break;
3723  for (x=0; x < (ssize_t) roi->width; x++)
3724  {
3725  SetPixelBlue(image,*p++,q);
3726  SetPixelGreen(image,*p++,q);
3727  SetPixelRed(image,*p++,q);
3728  q+=GetPixelChannels(image);
3729  }
3730  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3731  break;
3732  }
3733  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3734  }
3735  if (LocaleCompare(map,"BGRA") == 0)
3736  {
3737  for (y=0; y < (ssize_t) roi->height; y++)
3738  {
3739  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3740  if (q == (Quantum *) NULL)
3741  break;
3742  for (x=0; x < (ssize_t) roi->width; x++)
3743  {
3744  SetPixelBlue(image,*p++,q);
3745  SetPixelGreen(image,*p++,q);
3746  SetPixelRed(image,*p++,q);
3747  SetPixelAlpha(image,*p++,q);
3748  q+=GetPixelChannels(image);
3749  }
3750  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3751  break;
3752  }
3753  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3754  }
3755  if (LocaleCompare(map,"BGRP") == 0)
3756  {
3757  for (y=0; y < (ssize_t) roi->height; y++)
3758  {
3759  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3760  if (q == (Quantum *) NULL)
3761  break;
3762  for (x=0; x < (ssize_t) roi->width; x++)
3763  {
3764  SetPixelBlue(image,*p++,q);
3765  SetPixelGreen(image,*p++,q);
3766  SetPixelRed(image,*p++,q);
3767  p++;
3768  q+=GetPixelChannels(image);
3769  }
3770  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3771  break;
3772  }
3773  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3774  }
3775  if (LocaleCompare(map,"I") == 0)
3776  {
3777  for (y=0; y < (ssize_t) roi->height; y++)
3778  {
3779  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3780  if (q == (Quantum *) NULL)
3781  break;
3782  for (x=0; x < (ssize_t) roi->width; x++)
3783  {
3784  SetPixelGray(image,*p++,q);
3785  q+=GetPixelChannels(image);
3786  }
3787  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3788  break;
3789  }
3790  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3791  }
3792  if (LocaleCompare(map,"RGB") == 0)
3793  {
3794  for (y=0; y < (ssize_t) roi->height; y++)
3795  {
3796  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3797  if (q == (Quantum *) NULL)
3798  break;
3799  for (x=0; x < (ssize_t) roi->width; x++)
3800  {
3801  SetPixelRed(image,*p++,q);
3802  SetPixelGreen(image,*p++,q);
3803  SetPixelBlue(image,*p++,q);
3804  q+=GetPixelChannels(image);
3805  }
3806  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3807  break;
3808  }
3809  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3810  }
3811  if (LocaleCompare(map,"RGBA") == 0)
3812  {
3813  for (y=0; y < (ssize_t) roi->height; y++)
3814  {
3815  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3816  if (q == (Quantum *) NULL)
3817  break;
3818  for (x=0; x < (ssize_t) roi->width; x++)
3819  {
3820  SetPixelRed(image,*p++,q);
3821  SetPixelGreen(image,*p++,q);
3822  SetPixelBlue(image,*p++,q);
3823  SetPixelAlpha(image,*p++,q);
3824  q+=GetPixelChannels(image);
3825  }
3826  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3827  break;
3828  }
3829  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3830  }
3831  if (LocaleCompare(map,"RGBP") == 0)
3832  {
3833  for (y=0; y < (ssize_t) roi->height; y++)
3834  {
3835  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3836  if (q == (Quantum *) NULL)
3837  break;
3838  for (x=0; x < (ssize_t) roi->width; x++)
3839  {
3840  SetPixelRed(image,*p++,q);
3841  SetPixelGreen(image,*p++,q);
3842  SetPixelBlue(image,*p++,q);
3843  p++;
3844  q+=GetPixelChannels(image);
3845  }
3846  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3847  break;
3848  }
3849  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3850  }
3851  length=strlen(map);
3852  for (y=0; y < (ssize_t) roi->height; y++)
3853  {
3854  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3855  if (q == (Quantum *) NULL)
3856  break;
3857  for (x=0; x < (ssize_t) roi->width; x++)
3858  {
3859  register ssize_t
3860  i;
3861 
3862  for (i=0; i < (ssize_t) length; i++)
3863  {
3864  switch (quantum_map[i])
3865  {
3866  case RedQuantum:
3867  case CyanQuantum:
3868  {
3869  SetPixelRed(image,*p,q);
3870  break;
3871  }
3872  case GreenQuantum:
3873  case MagentaQuantum:
3874  {
3875  SetPixelGreen(image,*p,q);
3876  break;
3877  }
3878  case BlueQuantum:
3879  case YellowQuantum:
3880  {
3881  SetPixelBlue(image,*p,q);
3882  break;
3883  }
3884  case AlphaQuantum:
3885  {
3886  SetPixelAlpha(image,*p,q);
3887  break;
3888  }
3889  case OpacityQuantum:
3890  {
3891  SetPixelAlpha(image,*p,q);
3892  break;
3893  }
3894  case BlackQuantum:
3895  {
3896  SetPixelBlack(image,*p,q);
3897  break;
3898  }
3899  case IndexQuantum:
3900  {
3901  SetPixelGray(image,*p,q);
3902  break;
3903  }
3904  default:
3905  break;
3906  }
3907  p++;
3908  }
3909  q+=GetPixelChannels(image);
3910  }
3911  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3912  break;
3913  }
3914  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3915 }
3916 
3918  const char *magick_restrict map,const QuantumType *quantum_map,
3919  const void *pixels,ExceptionInfo *exception)
3920 {
3921  register const unsigned short
3922  *magick_restrict p;
3923 
3924  register Quantum
3925  *magick_restrict q;
3926 
3927  register ssize_t
3928  x;
3929 
3930  size_t
3931  length;
3932 
3933  ssize_t
3934  y;
3935 
3936  p=(const unsigned short *) pixels;
3937  if (LocaleCompare(map,"BGR") == 0)
3938  {
3939  for (y=0; y < (ssize_t) roi->height; y++)
3940  {
3941  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3942  if (q == (Quantum *) NULL)
3943  break;
3944  for (x=0; x < (ssize_t) roi->width; x++)
3945  {
3946  SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3947  SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3948  SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3949  q+=GetPixelChannels(image);
3950  }
3951  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3952  break;
3953  }
3954  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3955  }
3956  if (LocaleCompare(map,"BGRA") == 0)
3957  {
3958  for (y=0; y < (ssize_t) roi->height; y++)
3959  {
3960  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3961  if (q == (Quantum *) NULL)
3962  break;
3963  for (x=0; x < (ssize_t) roi->width; x++)
3964  {
3965  SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3966  SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3967  SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3968  SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
3969  q+=GetPixelChannels(image);
3970  }
3971  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3972  break;
3973  }
3974  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3975  }
3976  if (LocaleCompare(map,"BGRP") == 0)
3977  {
3978  for (y=0; y < (ssize_t) roi->height; y++)
3979  {
3980  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
3981  if (q == (Quantum *) NULL)
3982  break;
3983  for (x=0; x < (ssize_t) roi->width; x++)
3984  {
3985  SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
3986  SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
3987  SetPixelRed(image,ScaleShortToQuantum(*p++),q);
3988  p++;
3989  q+=GetPixelChannels(image);
3990  }
3991  if (SyncAuthenticPixels(image,exception) == MagickFalse)
3992  break;
3993  }
3994  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
3995  }
3996  if (LocaleCompare(map,"I") == 0)
3997  {
3998  for (y=0; y < (ssize_t) roi->height; y++)
3999  {
4000  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4001  if (q == (Quantum *) NULL)
4002  break;
4003  for (x=0; x < (ssize_t) roi->width; x++)
4004  {
4005  SetPixelGray(image,ScaleShortToQuantum(*p++),q);
4006  q+=GetPixelChannels(image);
4007  }
4008  if (SyncAuthenticPixels(image,exception) == MagickFalse)
4009  break;
4010  }
4011  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4012  }
4013  if (LocaleCompare(map,"RGB") == 0)
4014  {
4015  for (y=0; y < (ssize_t) roi->height; y++)
4016  {
4017  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4018  if (q == (Quantum *) NULL)
4019  break;
4020  for (x=0; x < (ssize_t) roi->width; x++)
4021  {
4022  SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4023  SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4024  SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4025  q+=GetPixelChannels(image);
4026  }
4027  if (SyncAuthenticPixels(image,exception) == MagickFalse)
4028  break;
4029  }
4030  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4031  }
4032  if (LocaleCompare(map,"RGBA") == 0)
4033  {
4034  for (y=0; y < (ssize_t) roi->height; y++)
4035  {
4036  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4037  if (q == (Quantum *) NULL)
4038  break;
4039  for (x=0; x < (ssize_t) roi->width; x++)
4040  {
4041  SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4042  SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4043  SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4044  SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
4045  q+=GetPixelChannels(image);
4046  }
4047  if (SyncAuthenticPixels(image,exception) == MagickFalse)
4048  break;
4049  }
4050  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4051  }
4052  if (LocaleCompare(map,"RGBP") == 0)
4053  {
4054  for (y=0; y < (ssize_t) roi->height; y++)
4055  {
4056  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4057  if (q == (Quantum *) NULL)
4058  break;
4059  for (x=0; x < (ssize_t) roi->width; x++)
4060  {
4061  SetPixelRed(image,ScaleShortToQuantum(*p++),q);
4062  SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
4063  SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
4064  p++;
4065  q+=GetPixelChannels(image);
4066  }
4067  if (SyncAuthenticPixels(image,exception) == MagickFalse)
4068  break;
4069  }
4070  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4071  }
4072  length=strlen(map);
4073  for (y=0; y < (ssize_t) roi->height; y++)
4074  {
4075  q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
4076  if (q == (Quantum *) NULL)
4077  break;
4078  for (x=0; x < (ssize_t) roi->width; x++)
4079  {
4080  register ssize_t
4081  i;
4082 
4083  for (i=0; i < (ssize_t) length; i++)
4084  {
4085  switch (quantum_map[i])
4086  {
4087  case RedQuantum:
4088  case CyanQuantum:
4089  {
4090  SetPixelRed(image,ScaleShortToQuantum(*p),q);
4091  break;
4092  }
4093  case GreenQuantum:
4094  case MagentaQuantum:
4095  {
4096  SetPixelGreen(image,ScaleShortToQuantum(*p),q);
4097  break;
4098  }
4099  case BlueQuantum:
4100  case YellowQuantum:
4101  {
4102  SetPixelBlue(image,ScaleShortToQuantum(*p),q);
4103  break;
4104  }
4105  case AlphaQuantum:
4106  {
4107  SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4108  break;
4109  }
4110  case OpacityQuantum:
4111  {
4112  SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
4113  break;
4114  }
4115  case BlackQuantum:
4116  {
4117  SetPixelBlack(image,ScaleShortToQuantum(*p),q);
4118  break;
4119  }
4120  case IndexQuantum:
4121  {
4122  SetPixelGray(image,ScaleShortToQuantum(*p),q);
4123  break;
4124  }
4125  default:
4126  break;
4127  }
4128  p++;
4129  }
4130  q+=GetPixelChannels(image);
4131  }
4132  if (SyncAuthenticPixels(image,exception) == MagickFalse)
4133  break;
4134  }
4135  return(y < (ssize_t) roi->height ? MagickFalse : MagickTrue);
4136 }
4137 
4139  const ssize_t y,const size_t width,const size_t height,const char *map,
4140  const StorageType type,const void *pixels,ExceptionInfo *exception)
4141 {
4143  status;
4144 
4145  QuantumType
4146  *quantum_map;
4147 
4149  roi;
4150 
4151  register ssize_t
4152  i;
4153 
4154  size_t
4155  length;
4156 
4157  /*
4158  Allocate image structure.
4159  */
4160  assert(image != (Image *) NULL);
4161  assert(image->signature == MagickCoreSignature);
4162  if (image->debug != MagickFalse)
4163  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4164  length=strlen(map);
4165  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
4166  if (quantum_map == (QuantumType *) NULL)
4167  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
4168  image->filename);
4169  for (i=0; i < (ssize_t) length; i++)
4170  {
4171  switch (map[i])
4172  {
4173  case 'a':
4174  case 'A':
4175  {
4176  quantum_map[i]=AlphaQuantum;
4178  break;
4179  }
4180  case 'B':
4181  case 'b':
4182  {
4183  quantum_map[i]=BlueQuantum;
4184  break;
4185  }
4186  case 'C':
4187  case 'c':
4188  {
4189  quantum_map[i]=CyanQuantum;
4190  (void) SetImageColorspace(image,CMYKColorspace,exception);
4191  break;
4192  }
4193  case 'g':
4194  case 'G':
4195  {
4196  quantum_map[i]=GreenQuantum;
4197  break;
4198  }
4199  case 'K':
4200  case 'k':
4201  {
4202  quantum_map[i]=BlackQuantum;
4203  (void) SetImageColorspace(image,CMYKColorspace,exception);
4204  break;
4205  }
4206  case 'I':
4207  case 'i':
4208  {
4209  quantum_map[i]=IndexQuantum;
4210  (void) SetImageColorspace(image,GRAYColorspace,exception);
4211  break;
4212  }
4213  case 'm':
4214  case 'M':
4215  {
4216  quantum_map[i]=MagentaQuantum;
4217  (void) SetImageColorspace(image,CMYKColorspace,exception);
4218  break;
4219  }
4220  case 'O':
4221  case 'o':
4222  {
4223  quantum_map[i]=OpacityQuantum;
4225  break;
4226  }
4227  case 'P':
4228  case 'p':
4229  {
4230  quantum_map[i]=UndefinedQuantum;
4231  break;
4232  }
4233  case 'R':
4234  case 'r':
4235  {
4236  quantum_map[i]=RedQuantum;
4237  break;
4238  }
4239  case 'Y':
4240  case 'y':
4241  {
4242  quantum_map[i]=YellowQuantum;
4243  (void) SetImageColorspace(image,CMYKColorspace,exception);
4244  break;
4245  }
4246  default:
4247  {
4248  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4250  "UnrecognizedPixelMap","`%s'",map);
4251  return(MagickFalse);
4252  }
4253  }
4254  }
4255  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
4256  return(MagickFalse);
4257  /*
4258  Transfer the pixels from the pixel data to the image.
4259  */
4260  roi.width=width;
4261  roi.height=height;
4262  roi.x=x;
4263  roi.y=y;
4264  switch (type)
4265  {
4266  case CharPixel:
4267  {
4268  status=ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
4269  break;
4270  }
4271  case DoublePixel:
4272  {
4273  status=ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
4274  break;
4275  }
4276  case FloatPixel:
4277  {
4278  status=ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
4279  break;
4280  }
4281  case LongPixel:
4282  {
4283  status=ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
4284  break;
4285  }
4286  case LongLongPixel:
4287  {
4288  status=ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
4289  break;
4290  }
4291  case QuantumPixel:
4292  {
4293  status=ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
4294  break;
4295  }
4296  case ShortPixel:
4297  {
4298  status=ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
4299  break;
4300  }
4301  default:
4302  {
4304  "UnrecognizedStorageType","`%d'",type);
4305  status=MagickFalse;
4306  }
4307  }
4308  quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
4309  return(status);
4310 }
4311 
4312 /*
4313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4314 % %
4315 % %
4316 % %
4317 + 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 %
4318 % %
4319 % %
4320 % %
4321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4322 %
4323 % InitializePixelChannelMap() defines the standard pixel component map.
4324 %
4325 % The format of the InitializePixelChannelMap() method is:
4326 %
4327 % void InitializePixelChannelMap(Image *image)
4328 %
4329 % A description of each parameter follows:
4330 %
4331 % o image: the image.
4332 %
4333 */
4335 {
4336  PixelTrait
4337  trait;
4338 
4339  register ssize_t
4340  i;
4341 
4342  ssize_t
4343  n;
4344 
4345  assert(image != (Image *) NULL);
4346  assert(image->signature == MagickCoreSignature);
4348  sizeof(*image->channel_map));
4349  trait=UpdatePixelTrait;
4350  if (image->alpha_trait != UndefinedPixelTrait)
4351  trait=(PixelTrait) (trait | BlendPixelTrait);
4352  n=0;
4353  if ((image->colorspace == LinearGRAYColorspace) ||
4354  (image->colorspace == GRAYColorspace))
4355  {
4358  SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4359  }
4360  else
4361  {
4362  SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
4365  }
4366  if (image->colorspace == CMYKColorspace)
4368  for (i=0; i < (ssize_t) image->number_meta_channels; i++)
4369  {
4371  n++;
4372  }
4373  if (image->alpha_trait != UndefinedPixelTrait)
4375  if (image->storage_class == PseudoClass)
4377  if (image->read_mask != MagickFalse)
4379  if (image->write_mask != MagickFalse)
4381  image->number_channels=(size_t) n;
4382  (void) SetPixelChannelMask(image,image->channel_mask);
4383 }
4384 
4385 /*
4386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4387 % %
4388 % %
4389 % %
4390 % I n t e r p o l a t e P i x e l C h a n n e l %
4391 % %
4392 % %
4393 % %
4394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4395 %
4396 % InterpolatePixelChannel() applies a pixel interpolation method between a
4397 % floating point coordinate and the pixels surrounding that coordinate. No
4398 % pixel area resampling, or scaling of the result is performed.
4399 %
4400 % Interpolation is restricted to just the specified channel.
4401 %
4402 % The format of the InterpolatePixelChannel method is:
4403 %
4404 % MagickBooleanType InterpolatePixelChannel(const Image *image,
4405 % const CacheView *image_view,const PixelChannel channel,
4406 % const PixelInterpolateMethod method,const double x,const double y,
4407 % double *pixel,ExceptionInfo *exception)
4408 %
4409 % A description of each parameter follows:
4410 %
4411 % o image: the image.
4412 %
4413 % o image_view: the image view.
4414 %
4415 % o channel: the pixel channel to interpolate.
4416 %
4417 % o method: the pixel color interpolation method.
4418 %
4419 % o x,y: A double representing the current (x,y) position of the pixel.
4420 %
4421 % o pixel: return the interpolated pixel here.
4422 %
4423 % o exception: return any errors or warnings in this structure.
4424 %
4425 */
4426 
4427 static inline void CatromWeights(const double x,double (*weights)[4])
4428 {
4429  double
4430  alpha,
4431  beta,
4432  gamma;
4433 
4434  /*
4435  Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
4436  of the standard four 1D Catmull-Rom weights. The sampling location is
4437  assumed between the second and third input pixel locations, and x is the
4438  position relative to the second input pixel location. Formulas originally
4439  derived for the VIPS (Virtual Image Processing System) library.
4440  */
4441  alpha=(double) 1.0-x;
4442  beta=(double) (-0.5)*x*alpha;
4443  (*weights)[0]=alpha*beta;
4444  (*weights)[3]=x*beta;
4445  /*
4446  The following computation of the inner weights from the outer ones work
4447  for all Keys cubics.
4448  */
4449  gamma=(*weights)[3]-(*weights)[0];
4450  (*weights)[1]=alpha-(*weights)[0]+gamma;
4451  (*weights)[2]=x-(*weights)[3]-gamma;
4452 }
4453 
4454 static inline void SplineWeights(const double x,double (*weights)[4])
4455 {
4456  double
4457  alpha,
4458  beta;
4459 
4460  /*
4461  Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the computation
4462  of the standard four 1D cubic B-spline smoothing weights. The sampling
4463  location is assumed between the second and third input pixel locations,
4464  and x is the position relative to the second input pixel location.
4465  */
4466  alpha=(double) 1.0-x;
4467  (*weights)[3]=(double) (1.0/6.0)*x*x*x;
4468  (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
4469  beta=(*weights)[3]-(*weights)[0];
4470  (*weights)[1]=alpha-(*weights)[0]+beta;
4471  (*weights)[2]=x-(*weights)[3]-beta;
4472 }
4473 
4474 static inline double MeshInterpolate(const PointInfo *delta,const double p,
4475  const double x,const double y)
4476 {
4477  return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
4478 }
4479 
4480 /*
4481 static inline ssize_t NearestNeighbor(const double x)
4482 {
4483  if (x >= 0.0)
4484  return((ssize_t) (x+0.5));
4485  return((ssize_t) (x-0.5));
4486 }
4487 */
4488 
4490  const CacheView_ *image_view,const PixelChannel channel,
4491  const PixelInterpolateMethod method,const double x,const double y,
4492  double *pixel,ExceptionInfo *exception)
4493 {
4494  double
4495  alpha[16],
4496  gamma,
4497  pixels[16];
4498 
4500  status;
4501 
4503  interpolate;
4504 
4505  PixelTrait
4506  traits;
4507 
4508  register const Quantum
4509  *p;
4510 
4511  register ssize_t
4512  i;
4513 
4514  ssize_t
4515  x_offset,
4516  y_offset;
4517 
4518  assert(image != (Image *) NULL);
4519  assert(image->signature == MagickCoreSignature);
4520  assert(image_view != (CacheView *) NULL);
4521  status=MagickTrue;
4522  *pixel=0.0;
4523  traits=GetPixelChannelTraits(image,channel);
4524  x_offset=(ssize_t) floor(x);
4525  y_offset=(ssize_t) floor(y);
4526  interpolate=method;
4527  if (interpolate == UndefinedInterpolatePixel)
4528  interpolate=image->interpolate;
4529  switch (interpolate)
4530  {
4531  case AverageInterpolatePixel: /* nearest 4 neighbours */
4532  case Average9InterpolatePixel: /* nearest 9 neighbours */
4533  case Average16InterpolatePixel: /* nearest 16 neighbours */
4534  {
4535  ssize_t
4536  count;
4537 
4538  count=2; /* size of the area to average - default nearest 4 */
4539  if (interpolate == Average9InterpolatePixel)
4540  {
4541  count=3;
4542  x_offset=(ssize_t) (floor(x+0.5)-1);
4543  y_offset=(ssize_t) (floor(y+0.5)-1);
4544  }
4545  else
4546  if (interpolate == Average16InterpolatePixel)
4547  {
4548  count=4;
4549  x_offset--;
4550  y_offset--;
4551  }
4552  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
4553  (size_t) count,exception);
4554  if (p == (const Quantum *) NULL)
4555  {
4556  status=MagickFalse;
4557  break;
4558  }
4559  count*=count; /* Number of pixels to average */
4560  if ((traits & BlendPixelTrait) == 0)
4561  for (i=0; i < (ssize_t) count; i++)
4562  {
4563  alpha[i]=1.0;
4564  pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4565  }
4566  else
4567  for (i=0; i < (ssize_t) count; i++)
4568  {
4569  alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4570  GetPixelChannels(image));
4571  pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4572  }
4573  for (i=0; i < (ssize_t) count; i++)
4574  {
4575  gamma=PerceptibleReciprocal(alpha[i])/count;
4576  *pixel+=gamma*pixels[i];
4577  }
4578  break;
4579  }
4581  default:
4582  {
4583  PointInfo
4584  delta,
4585  epsilon;
4586 
4587  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4588  if (p == (const Quantum *) NULL)
4589  {
4590  status=MagickFalse;
4591  break;
4592  }
4593  if ((traits & BlendPixelTrait) == 0)
4594  for (i=0; i < 4; i++)
4595  {
4596  alpha[i]=1.0;
4597  pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4598  }
4599  else
4600  for (i=0; i < 4; i++)
4601  {
4602  alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4603  GetPixelChannels(image));
4604  pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4605  }
4606  delta.x=x-x_offset;
4607  delta.y=y-y_offset;
4608  epsilon.x=1.0-delta.x;
4609  epsilon.y=1.0-delta.y;
4610  gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
4611  (epsilon.x*alpha[2]+delta.x*alpha[3])));
4612  gamma=PerceptibleReciprocal(gamma);
4613  *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
4614  (epsilon.x*pixels[2]+delta.x*pixels[3]));
4615  break;
4616  }
4617  case BlendInterpolatePixel:
4618  {
4619  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4620  if (p == (const Quantum *) NULL)
4621  {
4622  status=MagickFalse;
4623  break;
4624  }
4625  if ((traits & BlendPixelTrait) == 0)
4626  for (i=0; i < 4; i++)
4627  {
4628  alpha[i]=1.0;
4629  pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
4630  }
4631  else
4632  for (i=0; i < 4; i++)
4633  {
4634  alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4635  GetPixelChannels(image));
4636  pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4637  }
4638  gamma=1.0; /* number of pixels blended together (its variable) */
4639  for (i=0; i <= 1L; i++) {
4640  if ((y-y_offset) >= 0.75)
4641  {
4642  alpha[i]=alpha[i+2]; /* take right pixels */
4643  pixels[i]=pixels[i+2];
4644  }
4645  else
4646  if ((y-y_offset) > 0.25)
4647  {
4648  gamma=2.0; /* blend both pixels in row */
4649  alpha[i]+=alpha[i+2]; /* add up alpha weights */
4650  pixels[i]+=pixels[i+2];
4651  }
4652  }
4653  if ((x-x_offset) >= 0.75)
4654  {
4655  alpha[0]=alpha[1]; /* take bottom row blend */
4656  pixels[0]=pixels[1];
4657  }
4658  else
4659  if ((x-x_offset) > 0.25)
4660  {
4661  gamma*=2.0; /* blend both rows */
4662  alpha[0]+=alpha[1]; /* add up alpha weights */
4663  pixels[0]+=pixels[1];
4664  }
4665  if (channel != AlphaPixelChannel)
4666  gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
4667  else
4668  gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
4669  *pixel=gamma*pixels[0];
4670  break;
4671  }
4673  {
4674  double
4675  cx[4],
4676  cy[4];
4677 
4678  p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4679  exception);
4680  if (p == (const Quantum *) NULL)
4681  {
4682  status=MagickFalse;
4683  break;
4684  }
4685  if ((traits & BlendPixelTrait) == 0)
4686  for (i=0; i < 16; i++)
4687  {
4688  alpha[i]=1.0;
4689  pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4690  }
4691  else
4692  for (i=0; i < 16; i++)
4693  {
4694  alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4695  GetPixelChannels(image));
4696  pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4697  }
4698  CatromWeights((double) (x-x_offset),&cx);
4699  CatromWeights((double) (y-y_offset),&cy);
4700  gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4701  PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4702  alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4703  alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4704  alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4705  cx[2]*alpha[14]+cx[3]*alpha[15])));
4706  *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4707  cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4708  pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4709  cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4710  pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4711  break;
4712  }
4714  {
4715  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4716  if (p == (const Quantum *) NULL)
4717  {
4718  status=MagickFalse;
4719  break;
4720  }
4721  *pixel=(double) GetPixelChannel(image,channel,p);
4722  break;
4723  }
4725  {
4726  x_offset=(ssize_t) floor(x+0.5);
4727  y_offset=(ssize_t) floor(y+0.5);
4728  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
4729  if (p == (const Quantum *) NULL)
4730  {
4731  status=MagickFalse;
4732  break;
4733  }
4734  *pixel=(double) GetPixelChannel(image,channel,p);
4735  break;
4736  }
4737  case MeshInterpolatePixel:
4738  {
4739  PointInfo
4740  delta,
4741  luminance;
4742 
4743  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
4744  if (p == (const Quantum *) NULL)
4745  {
4746  status=MagickFalse;
4747  break;
4748  }
4749  if ((traits & BlendPixelTrait) == 0)
4750  for (i=0; i < 4; i++)
4751  {
4752  alpha[i]=1.0;
4753  pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4754  }
4755  else
4756  for (i=0; i < 4; i++)
4757  {
4758  alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4759  GetPixelChannels(image));
4760  pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4761  }
4762  delta.x=x-x_offset;
4763  delta.y=y-y_offset;
4764  luminance.x=GetPixelLuma(image,p)-(double)
4765  GetPixelLuma(image,p+3*GetPixelChannels(image));
4766  luminance.y=GetPixelLuma(image,p+GetPixelChannels(image))-(double)
4767  GetPixelLuma(image,p+2*GetPixelChannels(image));
4768  if (fabs(luminance.x) < fabs(luminance.y))
4769  {
4770  /*
4771  Diagonal 0-3 NW-SE.
4772  */
4773  if (delta.x <= delta.y)
4774  {
4775  /*
4776  Bottom-left triangle (pixel: 2, diagonal: 0-3).
4777  */
4778  delta.y=1.0-delta.y;
4779  gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
4780  gamma=PerceptibleReciprocal(gamma);
4781  *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
4782  pixels[0]);
4783  }
4784  else
4785  {
4786  /*
4787  Top-right triangle (pixel: 1, diagonal: 0-3).
4788  */
4789  delta.x=1.0-delta.x;
4790  gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
4791  gamma=PerceptibleReciprocal(gamma);
4792  *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
4793  pixels[3]);
4794  }
4795  }
4796  else
4797  {
4798  /*
4799  Diagonal 1-2 NE-SW.
4800  */
4801  if (delta.x <= (1.0-delta.y))
4802  {
4803  /*
4804  Top-left triangle (pixel: 0, diagonal: 1-2).
4805  */
4806  gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
4807  gamma=PerceptibleReciprocal(gamma);
4808  *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
4809  pixels[2]);
4810  }
4811  else
4812  {
4813  /*
4814  Bottom-right triangle (pixel: 3, diagonal: 1-2).
4815  */
4816  delta.x=1.0-delta.x;
4817  delta.y=1.0-delta.y;
4818  gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
4819  gamma=PerceptibleReciprocal(gamma);
4820  *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
4821  pixels[1]);
4822  }
4823  }
4824  break;
4825  }
4827  {
4828  double
4829  cx[4],
4830  cy[4];
4831 
4832  p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
4833  exception);
4834  if (p == (const Quantum *) NULL)
4835  {
4836  status=MagickFalse;
4837  break;
4838  }
4839  if ((traits & BlendPixelTrait) == 0)
4840  for (i=0; i < 16; i++)
4841  {
4842  alpha[i]=1.0;
4843  pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
4844  }
4845  else
4846  for (i=0; i < 16; i++)
4847  {
4848  alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
4849  GetPixelChannels(image));
4850  pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
4851  }
4852  SplineWeights((double) (x-x_offset),&cx);
4853  SplineWeights((double) (y-y_offset),&cy);
4854  gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
4855  PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
4856  alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
4857  alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
4858  alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
4859  cx[2]*alpha[14]+cx[3]*alpha[15])));
4860  *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
4861  cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
4862  pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
4863  cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
4864  pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
4865  break;
4866  }
4867  }
4868  return(status);
4869 }
4870 
4871 /*
4872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4873 % %
4874 % %
4875 % %
4876 % I n t e r p o l a t e P i x e l C h a n n e l s %
4877 % %
4878 % %
4879 % %
4880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4881 %
4882 % InterpolatePixelChannels() applies a pixel interpolation method between a
4883 % floating point coordinate and the pixels surrounding that coordinate. No
4884 % pixel area resampling, or scaling of the result is performed.
4885 %
4886 % Interpolation is restricted to just the current channel setting of the
4887 % destination image into which the color is to be stored
4888 %
4889 % The format of the InterpolatePixelChannels method is:
4890 %
4891 % MagickBooleanType InterpolatePixelChannels(const Image *source,
4892 % const CacheView *source_view,const Image *destination,
4893 % const PixelInterpolateMethod method,const double x,const double y,
4894 % Quantum *pixel,ExceptionInfo *exception)
4895 %
4896 % A description of each parameter follows:
4897 %
4898 % o source: the source.
4899 %
4900 % o source_view: the source view.
4901 %
4902 % o destination: the destination image, for the interpolated color
4903 %
4904 % o method: the pixel color interpolation method.
4905 %
4906 % o x,y: A double representing the current (x,y) position of the pixel.
4907 %
4908 % o pixel: return the interpolated pixel here.
4909 %
4910 % o exception: return any errors or warnings in this structure.
4911 %
4912 */
4914  const CacheView_ *source_view,const Image *destination,
4915  const PixelInterpolateMethod method,const double x,const double y,
4916  Quantum *pixel,ExceptionInfo *exception)
4917 {
4919  status;
4920 
4921  double
4922  alpha[16],
4923  gamma,
4924  pixels[16];
4925 
4926  register const Quantum
4927  *p;
4928 
4929  register ssize_t
4930  i;
4931 
4932  ssize_t
4933  x_offset,
4934  y_offset;
4935 
4937  interpolate;
4938 
4939  assert(source != (Image *) NULL);
4940  assert(source->signature == MagickCoreSignature);
4941  assert(source_view != (CacheView *) NULL);
4942  status=MagickTrue;
4943  x_offset=(ssize_t) floor(x);
4944  y_offset=(ssize_t) floor(y);
4945  interpolate=method;
4946  if (interpolate == UndefinedInterpolatePixel)
4947  interpolate=source->interpolate;
4948  switch (interpolate)
4949  {
4950  case AverageInterpolatePixel: /* nearest 4 neighbours */
4951  case Average9InterpolatePixel: /* nearest 9 neighbours */
4952  case Average16InterpolatePixel: /* nearest 16 neighbours */
4953  {
4954  ssize_t
4955  count;
4956 
4957  count=2; /* size of the area to average - default nearest 4 */
4958  if (interpolate == Average9InterpolatePixel)
4959  {
4960  count=3;
4961  x_offset=(ssize_t) (floor(x+0.5)-1);
4962  y_offset=(ssize_t) (floor(y+0.5)-1);
4963  }
4964  else
4965  if (interpolate == Average16InterpolatePixel)
4966  {
4967  count=4;
4968  x_offset--;
4969  y_offset--;
4970  }
4971  p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count,
4972  (size_t) count,exception);
4973  if (p == (const Quantum *) NULL)
4974  {
4975  status=MagickFalse;
4976  break;
4977  }
4978  count*=count; /* Number of pixels to average */
4979  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
4980  {
4981  double
4982  sum;
4983 
4984  register ssize_t
4985  j;
4986 
4987  PixelChannel channel = GetPixelChannelChannel(source,i);
4988  PixelTrait traits = GetPixelChannelTraits(source,channel);
4989  PixelTrait destination_traits=GetPixelChannelTraits(destination,
4990  channel);
4991  if ((traits == UndefinedPixelTrait) ||
4992  (destination_traits == UndefinedPixelTrait))
4993  continue;
4994  for (j=0; j < (ssize_t) count; j++)
4995  pixels[j]=(double) p[j*GetPixelChannels(source)+i];
4996  sum=0.0;
4997  if ((traits & BlendPixelTrait) == 0)
4998  {
4999  for (j=0; j < (ssize_t) count; j++)
5000  sum+=pixels[j];
5001  sum/=count;
5002  SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
5003  continue;
5004  }
5005  for (j=0; j < (ssize_t) count; j++)
5006  {
5007  alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5008  GetPixelChannels(source));
5009  pixels[j]*=alpha[j];
5010  gamma=PerceptibleReciprocal(alpha[j]);
5011  sum+=gamma*pixels[j];
5012  }
5013  sum/=count;
5014  SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
5015  }
5016  break;
5017  }
5019  default:
5020  {
5021  p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5022  if (p == (const Quantum *) NULL)
5023  {
5024  status=MagickFalse;
5025  break;
5026  }
5027  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5028  {
5029  PointInfo
5030  delta,
5031  epsilon;
5032 
5033  PixelChannel channel = GetPixelChannelChannel(source,i);
5034  PixelTrait traits = GetPixelChannelTraits(source,channel);
5035  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5036  channel);
5037  if ((traits == UndefinedPixelTrait) ||
5038  (destination_traits == UndefinedPixelTrait))
5039  continue;
5040  delta.x=x-x_offset;
5041  delta.y=y-y_offset;
5042  epsilon.x=1.0-delta.x;
5043  epsilon.y=1.0-delta.y;
5044  pixels[0]=(double) p[i];
5045  pixels[1]=(double) p[GetPixelChannels(source)+i];
5046  pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5047  pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5048  if ((traits & BlendPixelTrait) == 0)
5049  {
5050  gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
5051  gamma=PerceptibleReciprocal(gamma);
5052  SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5053  (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
5054  pixels[2]+delta.x*pixels[3]))),pixel);
5055  continue;
5056  }
5057  alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5058  alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
5059  alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5060  GetPixelChannels(source));
5061  alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5062  GetPixelChannels(source));
5063  pixels[0]*=alpha[0];
5064  pixels[1]*=alpha[1];
5065  pixels[2]*=alpha[2];
5066  pixels[3]*=alpha[3];
5067  gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5068  (epsilon.x*alpha[2]+delta.x*alpha[3])));
5069  gamma=PerceptibleReciprocal(gamma);
5070  SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
5071  (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
5072  delta.x*pixels[3]))),pixel);
5073  }
5074  break;
5075  }
5076  case BlendInterpolatePixel:
5077  {
5078  p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5079  if (p == (const Quantum *) NULL)
5080  {
5081  status=MagickFalse;
5082  break;
5083  }
5084  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5085  {
5086  register ssize_t
5087  j;
5088 
5089  PixelChannel channel = GetPixelChannelChannel(source,i);
5090  PixelTrait traits = GetPixelChannelTraits(source,channel);
5091  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5092  channel);
5093  if ((traits == UndefinedPixelTrait) ||
5094  (destination_traits == UndefinedPixelTrait))
5095  continue;
5096  if (source->alpha_trait != BlendPixelTrait)
5097  for (j=0; j < 4; j++)
5098  {
5099  alpha[j]=1.0;
5100  pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5101  }
5102  else
5103  for (j=0; j < 4; j++)
5104  {
5105  alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5106  GetPixelChannels(source));
5107  pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5108  if (channel != AlphaPixelChannel)
5109  pixels[j]*=alpha[j];
5110  }
5111  gamma=1.0; /* number of pixels blended together (its variable) */
5112  for (j=0; j <= 1L; j++)
5113  {
5114  if ((y-y_offset) >= 0.75)
5115  {
5116  alpha[j]=alpha[j+2]; /* take right pixels */
5117  pixels[j]=pixels[j+2];
5118  }
5119  else
5120  if ((y-y_offset) > 0.25)
5121  {
5122  gamma=2.0; /* blend both pixels in row */
5123  alpha[j]+=alpha[j+2]; /* add up alpha weights */
5124  pixels[j]+=pixels[j+2];
5125  }
5126  }
5127  if ((x-x_offset) >= 0.75)
5128  {
5129  alpha[0]=alpha[1]; /* take bottom row blend */
5130  pixels[0]=pixels[1];
5131  }
5132  else
5133  if ((x-x_offset) > 0.25)
5134  {
5135  gamma*=2.0; /* blend both rows */
5136  alpha[0]+=alpha[1]; /* add up alpha weights */
5137  pixels[0]+=pixels[1];
5138  }
5139  if (channel != AlphaPixelChannel)
5140  gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */
5141  else
5142  gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */
5143  SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
5144  pixel);
5145  }
5146  break;
5147  }
5149  {
5150  double
5151  cx[4],
5152  cy[4];
5153 
5154  p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5155  exception);
5156  if (p == (const Quantum *) NULL)
5157  {
5158  status=MagickFalse;
5159  break;
5160  }
5161  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5162  {
5163  register ssize_t
5164  j;
5165 
5166  PixelChannel channel = GetPixelChannelChannel(source,i);
5167  PixelTrait traits = GetPixelChannelTraits(source,channel);
5168  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5169  channel);
5170  if ((traits == UndefinedPixelTrait) ||
5171  (destination_traits == UndefinedPixelTrait))
5172  continue;
5173  if ((traits & BlendPixelTrait) == 0)
5174  for (j=0; j < 16; j++)
5175  {
5176  alpha[j]=1.0;
5177  pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5178  }
5179  else
5180  for (j=0; j < 16; j++)
5181  {
5182  alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5183  GetPixelChannels(source));
5184  pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5185  }
5186  CatromWeights((double) (x-x_offset),&cx);
5187  CatromWeights((double) (y-y_offset),&cy);
5188  gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5189  PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5190  alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5191  alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5192  alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5193  cx[2]*alpha[14]+cx[3]*alpha[15])));
5194  SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5195  pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5196  (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5197  cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5198  pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5199  pixels[14]+cx[3]*pixels[15]))),pixel);
5200  }
5201  break;
5202  }
5204  {
5205  p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5206  if (p == (const Quantum *) NULL)
5207  {
5208  status=MagickFalse;
5209  break;
5210  }
5211  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5212  {
5213  PixelChannel channel = GetPixelChannelChannel(source,i);
5214  PixelTrait traits = GetPixelChannelTraits(source,channel);
5215  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5216  channel);
5217  if ((traits == UndefinedPixelTrait) ||
5218  (destination_traits == UndefinedPixelTrait))
5219  continue;
5220  SetPixelChannel(destination,channel,p[i],pixel);
5221  }
5222  break;
5223  }
5225  {
5226  x_offset=(ssize_t) floor(x+0.5);
5227  y_offset=(ssize_t) floor(y+0.5);
5228  p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
5229  if (p == (const Quantum *) NULL)
5230  {
5231  status=MagickFalse;
5232  break;
5233  }
5234  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5235  {
5236  PixelChannel channel = GetPixelChannelChannel(source,i);
5237  PixelTrait traits = GetPixelChannelTraits(source,channel);
5238  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5239  channel);
5240  if ((traits == UndefinedPixelTrait) ||
5241  (destination_traits == UndefinedPixelTrait))
5242  continue;
5243  SetPixelChannel(destination,channel,p[i],pixel);
5244  }
5245  break;
5246  }
5247  case MeshInterpolatePixel:
5248  {
5249  p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
5250  if (p == (const Quantum *) NULL)
5251  {
5252  status=MagickFalse;
5253  break;
5254  }
5255  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5256  {
5257  PointInfo
5258  delta,
5259  luminance;
5260 
5261  PixelChannel channel = GetPixelChannelChannel(source,i);
5262  PixelTrait traits = GetPixelChannelTraits(source,channel);
5263  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5264  channel);
5265  if ((traits == UndefinedPixelTrait) ||
5266  (destination_traits == UndefinedPixelTrait))
5267  continue;
5268  pixels[0]=(double) p[i];
5269  pixels[1]=(double) p[GetPixelChannels(source)+i];
5270  pixels[2]=(double) p[2*GetPixelChannels(source)+i];
5271  pixels[3]=(double) p[3*GetPixelChannels(source)+i];
5272  if ((traits & BlendPixelTrait) == 0)
5273  {
5274  alpha[0]=1.0;
5275  alpha[1]=1.0;
5276  alpha[2]=1.0;
5277  alpha[3]=1.0;
5278  }
5279  else
5280  {
5281  alpha[0]=QuantumScale*GetPixelAlpha(source,p);
5282  alpha[1]=QuantumScale*GetPixelAlpha(source,p+
5283  GetPixelChannels(source));
5284  alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
5285  GetPixelChannels(source));
5286  alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
5287  GetPixelChannels(source));
5288  }
5289  delta.x=x-x_offset;
5290  delta.y=y-y_offset;
5291  luminance.x=fabs((double) (GetPixelLuma(source,p)-
5292  GetPixelLuma(source,p+3*GetPixelChannels(source))));
5293  luminance.y=fabs((double) (GetPixelLuma(source,p+
5294  GetPixelChannels(source))-GetPixelLuma(source,p+2*
5295  GetPixelChannels(source))));
5296  if (luminance.x < luminance.y)
5297  {
5298  /*
5299  Diagonal 0-3 NW-SE.
5300  */
5301  if (delta.x <= delta.y)
5302  {
5303  /*
5304  Bottom-left triangle (pixel: 2, diagonal: 0-3).
5305  */
5306  delta.y=1.0-delta.y;
5307  gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
5308  gamma=PerceptibleReciprocal(gamma);
5309  SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5310  MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
5311  }
5312  else
5313  {
5314  /*
5315  Top-right triangle (pixel: 1, diagonal: 0-3).
5316  */
5317  delta.x=1.0-delta.x;
5318  gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
5319  gamma=PerceptibleReciprocal(gamma);
5320  SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5321  MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
5322  }
5323  }
5324  else
5325  {
5326  /*
5327  Diagonal 1-2 NE-SW.
5328  */
5329  if (delta.x <= (1.0-delta.y))
5330  {
5331  /*
5332  Top-left triangle (pixel: 0, diagonal: 1-2).
5333  */
5334  gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
5335  gamma=PerceptibleReciprocal(gamma);
5336  SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5337  MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
5338  }
5339  else
5340  {
5341  /*
5342  Bottom-right triangle (pixel: 3, diagonal: 1-2).
5343  */
5344  delta.x=1.0-delta.x;
5345  delta.y=1.0-delta.y;
5346  gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
5347  gamma=PerceptibleReciprocal(gamma);
5348  SetPixelChannel(destination,channel,ClampToQuantum(gamma*
5349  MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
5350  }
5351  }
5352  }
5353  break;
5354  }
5356  {
5357  double
5358  cx[4],
5359  cy[4];
5360 
5361  p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
5362  exception);
5363  if (p == (const Quantum *) NULL)
5364  {
5365  status=MagickFalse;
5366  break;
5367  }
5368  for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
5369  {
5370  register ssize_t
5371  j;
5372 
5373  PixelChannel channel = GetPixelChannelChannel(source,i);
5374  PixelTrait traits = GetPixelChannelTraits(source,channel);
5375  PixelTrait destination_traits=GetPixelChannelTraits(destination,
5376  channel);
5377  if ((traits == UndefinedPixelTrait) ||
5378  (destination_traits == UndefinedPixelTrait))
5379  continue;
5380  if ((traits & BlendPixelTrait) == 0)
5381  for (j=0; j < 16; j++)
5382  {
5383  alpha[j]=1.0;
5384  pixels[j]=(double) p[j*GetPixelChannels(source)+i];
5385  }
5386  else
5387  for (j=0; j < 16; j++)
5388  {
5389  alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
5390  GetPixelChannels(source));
5391  pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
5392  }
5393  SplineWeights((double) (x-x_offset),&cx);
5394  SplineWeights((double) (y-y_offset),&cy);
5395  gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
5396  PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
5397  alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
5398  alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
5399  alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
5400  cx[2]*alpha[14]+cx[3]*alpha[15])));
5401  SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
5402  pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
5403  (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
5404  cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
5405  pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
5406  pixels[14]+cx[3]*pixels[15]))),pixel);
5407  }
5408  break;
5409  }
5410  }
5411  return(status);
5412 }
5413 
5414 /*
5415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5416 % %
5417 % %
5418 % %
5419 % I n t e r p o l a t e P i x e l I n f o %
5420 % %
5421 % %
5422 % %
5423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5424 %
5425 % InterpolatePixelInfo() applies a pixel interpolation method between a
5426 % floating point coordinate and the pixels surrounding that coordinate. No
5427 % pixel area resampling, or scaling of the result is performed.
5428 %
5429 % Interpolation is restricted to just RGBKA channels.
5430 %
5431 % The format of the InterpolatePixelInfo method is:
5432 %
5433 % MagickBooleanType InterpolatePixelInfo(const Image *image,
5434 % const CacheView *image_view,const PixelInterpolateMethod method,
5435 % const double x,const double y,PixelInfo *pixel,
5436 % ExceptionInfo *exception)
5437 %
5438 % A description of each parameter follows:
5439 %
5440 % o image: the image.
5441 %
5442 % o image_view: the image view.
5443 %
5444 % o method: the pixel color interpolation method.
5445 %
5446 % o x,y: A double representing the current (x,y) position of the pixel.
5447 %
5448 % o pixel: return the interpolated pixel here.
5449 %
5450 % o exception: return any errors or warnings in this structure.
5451 %
5452 */
5453 
5454 static inline void AlphaBlendPixelInfo(const Image *image,
5455  const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
5456 {
5457  if (image->alpha_trait == UndefinedPixelTrait)
5458  {
5459  *alpha=1.0;
5460  pixel_info->red=(double) GetPixelRed(image,pixel);
5461  pixel_info->green=(double) GetPixelGreen(image,pixel);
5462  pixel_info->blue=(double) GetPixelBlue(image,pixel);
5463  pixel_info->black=0.0;
5464  if (image->colorspace == CMYKColorspace)
5465  pixel_info->black=(double) GetPixelBlack(image,pixel);
5466  pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5467  return;
5468  }
5469  *alpha=QuantumScale*GetPixelAlpha(image,pixel);
5470  pixel_info->red=(*alpha*GetPixelRed(image,pixel));
5471  pixel_info->green=(*alpha*GetPixelGreen(image,pixel));
5472  pixel_info->blue=(*alpha*GetPixelBlue(image,pixel));
5473  pixel_info->black=0.0;
5474  if (image->colorspace == CMYKColorspace)
5475  pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
5476  pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
5477 }
5478 
5480  const CacheView_ *image_view,const PixelInterpolateMethod method,
5481  const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception)
5482 {
5484  status;
5485 
5486  double
5487  alpha[16],
5488  gamma;
5489 
5490  PixelInfo
5491  pixels[16];
5492 
5493  register const Quantum
5494  *p;
5495 
5496  register ssize_t
5497  i;
5498 
5499  ssize_t
5500  x_offset,
5501  y_offset;
5502 
5504  interpolate;
5505 
5506  assert(image != (Image *) NULL);
5507  assert(image->signature == MagickCoreSignature);
5508  assert(image_view != (CacheView *) NULL);
5509  status=MagickTrue;
5510  x_offset=(ssize_t) floor(x);
5511  y_offset=(ssize_t) floor(y);
5512  interpolate=method;
5513  if (interpolate == UndefinedInterpolatePixel)
5514  interpolate=image->interpolate;
5515  (void) ResetMagickMemory(&pixels,0,sizeof(pixels));
5516  switch (interpolate)
5517  {
5518  case AverageInterpolatePixel: /* nearest 4 neighbours */
5519  case Average9InterpolatePixel: /* nearest 9 neighbours */
5520  case Average16InterpolatePixel: /* nearest 16 neighbours */
5521  {
5522  ssize_t
5523  count;
5524 
5525  count=2; /* size of the area to average - default nearest 4 */
5526  if (interpolate == Average9InterpolatePixel)
5527  {
5528  count=3;
5529  x_offset=(ssize_t) (floor(x+0.5)-1);
5530  y_offset=(ssize_t) (floor(y+0.5)-1);
5531  }
5532  else if (interpolate == Average16InterpolatePixel)
5533  {
5534  count=4;
5535  x_offset--;
5536  y_offset--;
5537  }
5538  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count,
5539  (size_t) count,exception);
5540  if (p == (const Quantum *) NULL)
5541  {
5542  status=MagickFalse;
5543  break;
5544  }
5545  pixel->red=0.0;
5546  pixel->green=0.0;
5547  pixel->blue=0.0;
5548  pixel->black=0.0;
5549  pixel->alpha=0.0;
5550  count*=count; /* number of pixels - square of size */
5551  for (i=0; i < (ssize_t) count; i++)
5552  {
5553  AlphaBlendPixelInfo(image,p,pixels,alpha);
5554  gamma=PerceptibleReciprocal(alpha[0]);
5555  pixel->red+=gamma*pixels[0].red;
5556  pixel->green+=gamma*pixels[0].green;
5557  pixel->blue+=gamma*pixels[0].blue;
5558  pixel->black+=gamma*pixels[0].black;
5559  pixel->alpha+=pixels[0].alpha;
5560  p += GetPixelChannels(image);
5561  }
5562  gamma=1.0/count; /* average weighting of each pixel in area */
5563  pixel->red*=gamma;
5564  pixel->green*=gamma;
5565  pixel->blue*=gamma;
5566  pixel->black*=gamma;
5567  pixel->alpha*=gamma;
5568  break;
5569  }
5571  {
5572  *pixel=image->background_color; /* Copy PixelInfo Structure */
5573  break;
5574  }
5576  default:
5577  {
5578  PointInfo
5579  delta,
5580  epsilon;
5581 
5582  p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
5583  if (p == (const Quantum *) NULL)
5584  {
5585  status=MagickFalse;
5586  break;
5587  }
5588  for (i=0; i < 4L; i++)
5589  AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
5590  delta.x=x-x_offset;
5591  delta.y=y-y_offset;
5592  epsilon.x=1.0-delta.x;
5593  epsilon.y=1.0-delta.y;
5594  gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
5595  (epsilon.x*alpha[2]+delta.x*alpha[3])));
5596  gamma=PerceptibleReciprocal(gamma);
5597  pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
5598  pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.