]> granicus.if.org Git - imagemagick/blob - Magick++/lib/Image.cpp
Copy past mistake.
[imagemagick] / Magick++ / lib / Image.cpp
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4 // Copyright Dirk Lemstra 2013-2014
5 //
6 // Implementation of Image
7 //
8
9 #define MAGICKCORE_IMPLEMENTATION  1
10 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11
12 #include "Magick++/Include.h"
13 #include <cstdlib>
14 #include <string>
15 #include <string.h>
16 #include <errno.h>
17 #include <math.h>
18
19 using namespace std;
20
21 #include "Magick++/Image.h"
22 #include "Magick++/Functions.h"
23 #include "Magick++/Pixels.h"
24 #include "Magick++/Options.h"
25 #include "Magick++/ImageRef.h"
26
27 #define AbsoluteValue(x)  ((x) < 0 ? -(x) : (x))
28 #define MagickPI  3.14159265358979323846264338327950288419716939937510
29 #define DegreesToRadians(x)  (MagickPI*(x)/180.0)
30
31 MagickPPExport const char *Magick::borderGeometryDefault="6x6+0+0";
32 MagickPPExport const char *Magick::frameGeometryDefault="25x25+6+6";
33 MagickPPExport const char *Magick::raiseGeometryDefault="6x6+0+0";
34
35 MagickPPExport int Magick::operator == (const Magick::Image &left_,
36   const Magick::Image &right_)
37 {
38   // If image pixels and signature are the same, then the image is identical
39   return((left_.rows() == right_.rows()) &&
40     (left_.columns() == right_.columns()) &&
41     (left_.signature() == right_.signature()));
42 }
43
44 MagickPPExport int Magick::operator != (const Magick::Image &left_,
45   const Magick::Image &right_)
46 {
47   return(!(left_ == right_));
48 }
49
50 MagickPPExport int Magick::operator > (const Magick::Image &left_,
51   const Magick::Image &right_)
52 {
53   return(!(left_ < right_) && (left_ != right_));
54 }
55
56 MagickPPExport int Magick::operator < (const Magick::Image &left_,
57   const Magick::Image &right_)
58 {
59   // If image pixels are less, then image is smaller
60   return((left_.rows() * left_.columns()) <
61     (right_.rows() * right_.columns()));
62 }
63
64 MagickPPExport int Magick::operator >= (const Magick::Image &left_,
65   const Magick::Image &right_)
66 {
67   return((left_ > right_) || (left_ == right_));
68 }
69
70 MagickPPExport int Magick::operator <= (const Magick::Image &left_,
71   const Magick::Image &right_)
72 {
73   return((left_ < right_) || ( left_ == right_));
74 }
75
76 Magick::Image::Image(void)
77   : _imgRef(new ImageRef)
78 {
79 }
80
81 Magick::Image::Image(const Blob &blob_)
82   : _imgRef(new ImageRef)
83 {
84   try
85   {
86     // Initialize, Allocate and Read images
87     read(blob_);
88   }
89   catch(const Warning &/*warning_*/)
90   {
91     // FIXME: need a way to report warnings in constructor
92   }
93   catch (const Error &/*error_*/)
94   {
95     // Release resources
96     delete _imgRef;
97     throw;
98   }
99 }
100
101 Magick::Image::Image(const Blob &blob_,const Geometry &size_)
102   : _imgRef(new ImageRef)
103 {
104   try
105   {
106     // Read from Blob
107     read(blob_, size_);
108   }
109   catch(const Warning &/*warning_*/)
110   {
111     // FIXME: need a way to report warnings in constructor
112   }
113   catch(const Error &/*error_*/)
114   {
115     // Release resources
116     delete _imgRef;
117     throw;
118   }
119 }
120
121 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
122   const size_t depth_)
123   : _imgRef(new ImageRef)
124 {
125   try
126   {
127     // Read from Blob
128     read(blob_,size_,depth_);
129   }
130   catch(const Warning &/*warning_*/)
131   {
132     // FIXME: need a way to report warnings in constructor
133   }
134   catch(const Error &/*error_*/)
135   {
136     // Release resources
137     delete _imgRef;
138     throw;
139   }
140 }
141
142 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
143   const size_t depth_,const std::string &magick_)
144   : _imgRef(new ImageRef)
145 {
146   try
147   {
148     // Read from Blob
149     read(blob_,size_,depth_,magick_);
150   }
151   catch(const Warning &/*warning_*/)
152   {
153     // FIXME: need a way to report warnings in constructor
154   }
155   catch(const Error &/*error_*/)
156   {
157     // Release resources
158     delete _imgRef;
159     throw;
160   }
161 }
162
163 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
164   const std::string &magick_)
165   : _imgRef(new ImageRef)
166 {
167   try
168   {
169     // Read from Blob
170     read(blob_,size_,magick_);
171   }
172   catch(const Warning &/*warning_*/)
173   {
174     // FIXME: need a way to report warnings in constructor
175   }
176   catch(const Error &/*error_*/)
177   {
178     // Release resources
179     delete _imgRef;
180     throw;
181   }
182 }
183
184 Magick::Image::Image(const Geometry &size_,const Color &color_)
185   : _imgRef(new ImageRef)
186 {
187   // xc: prefix specifies an X11 color string
188   std::string imageSpec("xc:");
189   imageSpec+=color_;
190
191   try
192   {
193     // Set image size
194     size(size_);
195
196     // Initialize, Allocate and Read images
197     read(imageSpec);
198   }
199   catch(const Warning &/*warning_*/)
200   {
201     // FIXME: need a way to report warnings in constructor
202   }
203   catch(const Error & /*error_*/)
204   {
205     // Release resources
206     delete _imgRef;
207     throw;
208   }
209 }
210
211 Magick::Image::Image(const Image &image_)
212   : _imgRef(image_._imgRef)
213 {
214   _imgRef->increase();
215 }
216
217 Magick::Image::Image(const size_t width_,const size_t height_,
218   const std::string &map_,const StorageType type_,const void *pixels_)
219   : _imgRef(new ImageRef)
220 {
221   try
222   {
223     read(width_,height_,map_.c_str(),type_,pixels_);
224   }
225   catch(const Warning &/*warning_*/)
226   {
227     // FIXME: need a way to report warnings in constructor
228   }
229   catch(const Error &/*error_*/)
230   {
231     // Release resources
232     delete _imgRef;
233     throw;
234   }
235 }
236
237 Magick::Image::Image(const std::string &imageSpec_)
238   : _imgRef(new ImageRef)
239 {
240   try
241   {
242     // Initialize, Allocate and Read images
243     read(imageSpec_);
244   }
245   catch(const Warning &/*warning_*/)
246   {
247     // FIXME: need a way to report warnings in constructor
248   }
249   catch(const Error &/*error_*/)
250   {
251     // Release resources
252     delete _imgRef;
253     throw;
254   }
255 }
256
257 Magick::Image::~Image()
258 {
259   if (_imgRef->decrease() == 0)
260     delete _imgRef;
261
262   _imgRef=(Magick::ImageRef *) NULL;
263 }
264
265 Magick::Image& Magick::Image::operator=(const Magick::Image &image_)
266 {
267   if (this != &image_)
268     {
269       image_._imgRef->increase();
270       if (_imgRef->decrease() == 0)
271         delete _imgRef;
272
273       // Use new image reference
274       _imgRef=image_._imgRef;
275     }
276   return(*this);
277 }
278
279 void Magick::Image::adjoin(const bool flag_)
280 {
281   modifyImage();
282   options()->adjoin(flag_);
283 }
284
285 bool Magick::Image::adjoin(void) const
286 {
287   return(constOptions()->adjoin());
288 }
289
290 void Magick::Image::alpha(const bool matteFlag_)
291 {
292   modifyImage();
293
294   // If matte channel is requested, but image doesn't already have a
295   // matte channel, then create an opaque matte channel.  Likewise, if
296   // the image already has a matte channel but a matte channel is not
297   // desired, then set the matte channel to opaque.
298   GetPPException;
299   if ((matteFlag_ && !constImage()->alpha_trait) ||
300       (constImage()->alpha_trait && !matteFlag_))
301     SetImageAlpha(image(),OpaqueAlpha,exceptionInfo);
302   ThrowPPException;
303
304   image()->alpha_trait=matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait;
305 }
306
307 bool Magick::Image::alpha(void) const
308 {
309   if (constImage()->alpha_trait == BlendPixelTrait)
310     return(true);
311   else
312     return(false);
313 }
314
315 void Magick::Image::alphaColor(const Color &alphaColor_)
316 {
317   modifyImage();
318
319   if (alphaColor_.isValid())
320     {
321       image()->matte_color=alphaColor_;
322       options()->matteColor(alphaColor_);
323     }
324   else
325     {
326       // Set to default matte color
327       Color tmpColor("#BDBDBD");
328       image()->matte_color=tmpColor;
329       options()->matteColor(tmpColor);
330     }
331 }
332
333 Magick::Color Magick::Image::alphaColor(void) const
334 {
335   return(Color(constImage()->matte_color));
336 }
337
338 void Magick::Image::antiAlias(const bool flag_)
339 {
340   modifyImage();
341   options()->antiAlias(static_cast<size_t>(flag_));
342 }
343
344 bool Magick::Image::antiAlias(void)
345 {
346   return(static_cast<bool>(options()->antiAlias()));
347 }
348
349 void Magick::Image::animationDelay(const size_t delay_)
350 {
351   modifyImage();
352   image()->delay=delay_;
353 }
354
355 size_t Magick::Image::animationDelay(void) const
356 {
357   return(constImage()->delay);
358 }
359
360 void Magick::Image::animationIterations(const size_t iterations_)
361 {
362   modifyImage();
363   image()->iterations=iterations_;
364 }
365
366 size_t Magick::Image::animationIterations(void) const
367 {
368   return(constImage()->iterations);
369 }
370
371 void Magick::Image::attenuate(const double attenuate_)
372 {
373   char
374     value[MaxTextExtent];
375
376   modifyImage();
377   FormatLocaleString(value,MaxTextExtent,"%.20g",attenuate_);
378   (void) SetImageArtifact(image(),"attenuate",value);
379 }
380
381 void Magick::Image::backgroundColor(const Color &backgroundColor_)
382 {
383   modifyImage();
384
385   if (backgroundColor_.isValid())
386     image()->background_color=backgroundColor_;
387   else
388     image()->background_color=Color();
389
390   options()->backgroundColor(backgroundColor_);
391 }
392
393 Magick::Color Magick::Image::backgroundColor(void) const
394 {
395   return(constOptions()->backgroundColor());
396 }
397
398 void Magick::Image::backgroundTexture(const std::string &backgroundTexture_)
399 {
400   modifyImage();
401   options()->backgroundTexture(backgroundTexture_);
402 }
403
404 std::string Magick::Image::backgroundTexture(void) const
405 {
406   return(constOptions()->backgroundTexture());
407 }
408
409 size_t Magick::Image::baseColumns(void) const
410 {
411   return(constImage()->magick_columns);
412 }
413
414 std::string Magick::Image::baseFilename(void) const
415 {
416   return(std::string(constImage()->magick_filename));
417 }
418
419 size_t Magick::Image::baseRows(void) const
420 {
421   return(constImage()->magick_rows);
422 }
423
424 void Magick::Image::blackPointCompensation(const bool flag_)
425 {
426   image()->black_point_compensation=(MagickBooleanType) flag_;
427 }
428
429 bool Magick::Image::blackPointCompensation(void) const
430 {
431   return(static_cast<bool>(constImage()->black_point_compensation));
432 }
433
434 void Magick::Image::borderColor(const Color &borderColor_)
435 {
436   modifyImage();
437
438   if (borderColor_.isValid())
439     image()->border_color=borderColor_;
440   else
441     image()->border_color=Color();
442
443   options()->borderColor(borderColor_);
444 }
445
446 Magick::Color Magick::Image::borderColor(void) const
447 {
448   return(constOptions()->borderColor());
449 }
450
451 Magick::Geometry Magick::Image::boundingBox(void) const
452 {
453   RectangleInfo
454     bbox;
455
456   GetPPException;
457   bbox=GetImageBoundingBox(constImage(),exceptionInfo);
458   ThrowPPException;
459   return(Geometry(bbox));
460 }
461
462 void Magick::Image::boxColor(const Color &boxColor_)
463 {
464   modifyImage();
465   options()->boxColor(boxColor_);
466 }
467
468 Magick::Color Magick::Image::boxColor(void) const
469 {
470   return(constOptions()->boxColor());
471 }
472
473 void Magick::Image::channelDepth(const ChannelType channel_,
474   const size_t depth_)
475 {
476   modifyImage();
477   GetPPException;
478   SetPPChannelMask(channel_);
479   SetImageDepth(image(),depth_,exceptionInfo);
480   RestorePPChannelMask;
481   ThrowPPException;
482 }
483
484 size_t Magick::Image::channelDepth(const ChannelType channel_)
485 {
486   size_t
487     channel_depth;
488
489   GetPPException;
490   SetPPChannelMask(channel_);
491   channel_depth=GetImageDepth(constImage(),exceptionInfo);
492   RestorePPChannelMask;
493   ThrowPPException;
494   return(channel_depth);
495 }
496
497 size_t Magick::Image::channels() const
498 {
499   return(constImage()->number_channels);
500 }
501
502 void Magick::Image::classType(const ClassType class_)
503 {
504   if (classType() == PseudoClass && class_ == DirectClass)
505     {
506       // Use SyncImage to synchronize the DirectClass pixels with the
507       // color map and then set to DirectClass type.
508       modifyImage();
509       GetPPException;
510       SyncImage(image(),exceptionInfo);
511       ThrowPPException;
512       image()->colormap=(PixelInfo *)RelinquishMagickMemory(image()->colormap);
513       image()->storage_class=static_cast<MagickCore::ClassType>(DirectClass);
514       return;
515     }
516
517   if (classType() == DirectClass && class_ == PseudoClass)
518     {
519       // Quantize to create PseudoClass color map
520       modifyImage();
521       quantizeColors(MaxColormapSize);
522       quantize();
523       image()->storage_class=static_cast<MagickCore::ClassType>(PseudoClass);
524     }
525 }
526
527 Magick::ClassType Magick::Image::classType(void) const
528 {
529   return static_cast<Magick::ClassType>(constImage()->storage_class);
530 }
531
532 void Magick::Image::colorFuzz(const double fuzz_)
533 {
534   modifyImage();
535   image()->fuzz=fuzz_;
536   options()->colorFuzz(fuzz_);
537 }
538
539 double Magick::Image::colorFuzz(void) const
540 {
541   return(constOptions()->colorFuzz());
542 }
543
544 void Magick::Image::colorMapSize(const size_t entries_)
545 {
546   if (entries_ >MaxColormapSize)
547     throwExceptionExplicit(OptionError,
548       "Colormap entries must not exceed MaxColormapSize");
549
550   modifyImage();
551   GetPPException;
552   (void) AcquireImageColormap(image(),entries_,exceptionInfo);
553   ThrowPPException;
554 }
555
556 size_t Magick::Image::colorMapSize(void) const
557 {
558   if (!constImage()->colormap)
559     throwExceptionExplicit(OptionError,"Image does not contain a colormap");
560
561   return(constImage()->colors);
562 }
563
564 void Magick::Image::colorSpace(const ColorspaceType colorSpace_)
565 {
566   if (image()->colorspace == colorSpace_)
567     return;
568
569   modifyImage();
570   GetPPException;
571   TransformImageColorspace(image(),colorSpace_,exceptionInfo);
572   ThrowPPException;
573 }
574
575 Magick::ColorspaceType Magick::Image::colorSpace(void) const
576 {
577   return (constImage()->colorspace);
578 }
579
580 void Magick::Image::colorSpaceType(const ColorspaceType colorSpace_)
581 {
582   modifyImage();
583   GetPPException;
584   SetImageColorspace(image(),colorSpace_,exceptionInfo);
585   ThrowPPException;
586   options()->colorspaceType(colorSpace_);
587 }
588
589 Magick::ColorspaceType Magick::Image::colorSpaceType(void) const
590 {
591   return(constOptions()->colorspaceType());
592 }
593
594 size_t Magick::Image::columns(void) const
595 {
596   return(constImage()->columns);
597 }
598
599 void Magick::Image::comment(const std::string &comment_)
600 {
601   modifyImage();
602   GetPPException;
603   SetImageProperty(image(),"Comment",NULL,exceptionInfo);
604   if (comment_.length() > 0)
605     SetImageProperty(image(),"Comment",comment_.c_str(),exceptionInfo);
606   ThrowPPException;
607 }
608
609 std::string Magick::Image::comment(void) const
610 {
611   const char
612     *value;
613
614   GetPPException;
615   value=GetImageProperty(constImage(),"Comment",exceptionInfo);
616   ThrowPPException;
617
618   if (value)
619     return(std::string(value));
620
621   return(std::string()); // Intentionally no exception
622 }
623
624 void Magick::Image::compose(const CompositeOperator compose_)
625 {
626   image()->compose=compose_;
627 }
628
629 Magick::CompositeOperator Magick::Image::compose(void) const
630 {
631   return(constImage()->compose);
632 }
633
634 void Magick::Image::compressType(const CompressionType compressType_)
635 {
636   modifyImage();
637   image()->compression=compressType_;
638   options()->compressType(compressType_);
639 }
640
641 Magick::CompressionType Magick::Image::compressType(void) const
642 {
643   return(constImage()->compression);
644 }
645
646 void Magick::Image::debug(const bool flag_)
647 {
648   modifyImage();
649   options()->debug(flag_);
650 }
651
652 bool Magick::Image::debug(void) const
653 {
654   return(constOptions()->debug());
655 }
656
657 void Magick::Image::density(const Point &density_)
658 {
659   modifyImage();
660   options()->density(density_);
661   if (density_.isValid())
662     {
663       image()->resolution.x=density_.x();
664       if (density_.y() != 0.0)
665         image()->resolution.y=density_.y();
666       else
667         image()->resolution.y=density_.x();
668     }
669   else
670     {
671       // Reset to default
672       image()->resolution.x=0.0;
673       image()->resolution.y=0.0;
674     }
675 }
676
677 Magick::Point Magick::Image::density(void) const
678 {
679   if (isValid())
680     {
681       ssize_t
682         x_resolution=72,
683         y_resolution=72;
684
685       if (constImage()->resolution.x > 0.0)
686         x_resolution=constImage()->resolution.x;
687
688       if (constImage()->resolution.y > 0.0)
689         y_resolution=constImage()->resolution.y;
690
691       return(Point(x_resolution,y_resolution));
692     }
693
694   return(constOptions()->density());
695 }
696
697 void Magick::Image::depth(const size_t depth_)
698 {
699   size_t
700     depth = depth_;
701
702   if (depth > MAGICKCORE_QUANTUM_DEPTH)
703     depth=MAGICKCORE_QUANTUM_DEPTH;
704
705   modifyImage();
706   image()->depth=depth;
707   options()->depth(depth);
708 }
709
710 size_t Magick::Image::depth(void) const
711 {
712   return(constImage()->depth);
713 }
714
715 std::string Magick::Image::directory(void) const
716 {
717   if (constImage()->directory)
718     return(std::string(constImage()->directory));
719
720   throwExceptionExplicit(CorruptImageWarning,
721     "Image does not contain a directory");
722
723   return(std::string());
724 }
725
726 void Magick::Image::endian(const Magick::EndianType endian_)
727 {
728   modifyImage();
729   options()->endian(endian_);
730   image()->endian=endian_;
731 }
732
733 Magick::EndianType Magick::Image::endian(void) const
734 {
735   return(constImage()->endian);
736 }
737
738 void Magick::Image::exifProfile(const Magick::Blob &exifProfile_)
739 {
740   modifyImage();
741
742   if (exifProfile_.data() != 0)
743     {
744       StringInfo
745         *exif_profile;
746
747       exif_profile=AcquireStringInfo(exifProfile_.length());
748       SetStringInfoDatum(exif_profile,(unsigned char *) exifProfile_.data());
749       GetPPException;
750       (void) SetImageProfile(image(),"exif",exif_profile,exceptionInfo);
751       exif_profile=DestroyStringInfo(exif_profile);
752       ThrowPPException;
753     }
754 }
755
756 Magick::Blob Magick::Image::exifProfile(void) const
757 {
758   const StringInfo 
759     *exif_profile;
760
761   exif_profile=GetImageProfile(constImage(),"exif");
762   if (exif_profile == (StringInfo *) NULL)
763     return(Blob());
764   return(Blob(GetStringInfoDatum(exif_profile),
765     GetStringInfoLength(exif_profile)));
766
767
768 void Magick::Image::fileName(const std::string &fileName_)
769 {
770   modifyImage();
771
772   fileName_.copy(image()->filename,sizeof(image()->filename)-1);
773   image()->filename[fileName_.length()]=0; // Null terminate
774
775   options()->fileName(fileName_);
776 }
777
778 std::string Magick::Image::fileName(void) const
779 {
780   return(constOptions()->fileName());
781 }
782
783 MagickCore::MagickSizeType Magick::Image::fileSize(void) const
784 {
785   return(GetBlobSize(constImage()));
786 }
787
788 void Magick::Image::fillColor(const Magick::Color &fillColor_)
789 {
790   std::string
791     value;
792
793   modifyImage();
794   options()->fillColor(fillColor_);
795   value=fillColor_;
796   artifact("fill",value);
797 }
798
799 Magick::Color Magick::Image::fillColor(void) const
800 {
801   return(constOptions()->fillColor());
802 }
803
804 void Magick::Image::fillRule(const Magick::FillRule &fillRule_)
805 {
806   modifyImage();
807   options()->fillRule(fillRule_);
808 }
809
810 Magick::FillRule Magick::Image::fillRule(void) const
811 {
812   return constOptions()->fillRule();
813 }
814
815 void Magick::Image::fillPattern(const Image &fillPattern_)
816 {
817   modifyImage();
818   if (fillPattern_.isValid())
819     options()->fillPattern(fillPattern_.constImage());
820   else
821     options()->fillPattern(static_cast<MagickCore::Image*>(NULL));
822 }
823
824 Magick::Image Magick::Image::fillPattern(void) const
825 {
826   // FIXME: This is inordinately innefficient
827   const MagickCore::Image
828     *tmpTexture;
829
830   Image
831     texture;
832
833   tmpTexture=constOptions()->fillPattern();
834
835   if (tmpTexture)
836     {
837       MagickCore::Image
838         *image;
839
840       GetPPException;
841       image=CloneImage(tmpTexture,0,0,MagickTrue,exceptionInfo);
842       texture.replaceImage(image);
843       ThrowPPException;
844     }
845   return(texture);
846 }
847
848 void Magick::Image::filterType(const Magick::FilterTypes filterType_)
849 {
850   modifyImage();
851   image()->filter=filterType_;
852 }
853
854 Magick::FilterTypes Magick::Image::filterType(void) const
855 {
856   return(constImage()->filter);
857 }
858
859 void Magick::Image::font(const std::string &font_)
860 {
861   modifyImage();
862   options()->font(font_);
863 }
864
865 std::string Magick::Image::font(void) const
866 {
867   return(constOptions()->font());
868 }
869
870 void Magick::Image::fontPointsize(const double pointSize_)
871 {
872   modifyImage();
873   options()->fontPointsize(pointSize_);
874 }
875
876 double Magick::Image::fontPointsize(void) const
877 {
878   return(constOptions()->fontPointsize());
879 }
880
881 std::string Magick::Image::format(void) const
882 {
883   const MagickInfo 
884    *magick_info;
885
886   GetPPException;
887   magick_info=GetMagickInfo(constImage()->magick,exceptionInfo);
888   ThrowPPException;
889
890   if ((magick_info != 0) && (*magick_info->description != '\0'))
891     return(std::string(magick_info->description));
892
893   throwExceptionExplicit(CorruptImageWarning,"Unrecognized image magick type");
894   return(std::string());
895 }
896
897 std::string Magick::Image::formatExpression(const std::string expression)
898 {
899   char
900     *text;
901
902   std::string
903     text_string;
904
905   GetPPException;
906   modifyImage();
907   text=InterpretImageProperties(imageInfo(),image(),expression.c_str(),
908     exceptionInfo);
909   if (text != (char *) NULL)
910     {
911       text_string=std::string(text);
912       text=DestroyString(text);
913     }
914   ThrowPPException;
915   return(text_string);
916 }
917
918 double Magick::Image::gamma(void) const
919 {
920   return(constImage()->gamma);
921 }
922
923 Magick::Geometry Magick::Image::geometry(void) const
924 {
925   if (constImage()->geometry)
926     return Geometry(constImage()->geometry);
927
928   throwExceptionExplicit(OptionWarning,"Image does not contain a geometry");
929
930   return(Geometry());
931 }
932
933 void Magick::Image::gifDisposeMethod(
934   const MagickCore::DisposeType disposeMethod_)
935 {
936   modifyImage();
937   image()->dispose=disposeMethod_;
938 }
939
940 MagickCore::DisposeType Magick::Image::gifDisposeMethod(void) const
941 {
942   return(constImage()->dispose);
943 }
944
945 void Magick::Image::highlightColor(const Color color_)
946 {
947   std::string
948     value;
949
950   value=color_;
951   artifact("highlight-color",value);
952 }
953
954 void Magick::Image::iccColorProfile(const Magick::Blob &colorProfile_)
955 {
956   profile("icm",colorProfile_);
957 }
958
959 Magick::Blob Magick::Image::iccColorProfile(void) const
960 {
961   const StringInfo
962     *color_profile;
963
964   color_profile=GetImageProfile(constImage(),"icc");
965   if (color_profile == (StringInfo *) NULL)
966     return(Blob());
967   return(Blob(GetStringInfoDatum(color_profile),GetStringInfoLength(
968     color_profile)));
969 }
970
971 void Magick::Image::interlaceType(const Magick::InterlaceType interlace_)
972 {
973   modifyImage();
974   image()->interlace=interlace_;
975   options()->interlaceType(interlace_);
976 }
977
978 Magick::InterlaceType Magick::Image::interlaceType(void) const
979 {
980   return(constImage()->interlace);
981 }
982
983 void Magick::Image::interpolate(const PixelInterpolateMethod interpolate_)
984 {
985   modifyImage();
986   image()->interpolate=interpolate_;
987 }
988
989 Magick::PixelInterpolateMethod Magick::Image::interpolate(void) const
990 {
991   return constImage()->interpolate;
992 }
993
994 void Magick::Image::iptcProfile(const Magick::Blob &iptcProfile_)
995 {
996   modifyImage();
997   if (iptcProfile_.data() != 0)
998     {
999       StringInfo
1000         *iptc_profile;
1001
1002       iptc_profile=AcquireStringInfo(iptcProfile_.length());
1003       SetStringInfoDatum(iptc_profile,(unsigned char *) iptcProfile_.data());
1004       GetPPException;
1005       (void) SetImageProfile(image(),"iptc",iptc_profile,exceptionInfo);
1006       iptc_profile=DestroyStringInfo(iptc_profile);
1007       ThrowPPException;
1008     }
1009 }
1010
1011 Magick::Blob Magick::Image::iptcProfile(void) const
1012 {
1013   const StringInfo
1014     *iptc_profile;
1015
1016   iptc_profile=GetImageProfile(constImage(),"iptc");
1017   if (iptc_profile == (StringInfo *) NULL)
1018     return(Blob());
1019   return(Blob(GetStringInfoDatum(iptc_profile),GetStringInfoLength(
1020     iptc_profile)));
1021 }
1022
1023 void Magick::Image::isValid(const bool isValid_)
1024 {
1025   if (!isValid_)
1026     {
1027       delete _imgRef;
1028       _imgRef=new ImageRef;
1029     }
1030   else if (!isValid())
1031     {
1032       // Construct with single-pixel black image to make
1033       // image valid. This is an obvious hack.
1034       size(Geometry(1,1));
1035       read("xc:black");
1036     }
1037 }
1038
1039 bool Magick::Image::isValid(void) const
1040 {
1041   return rows() && columns();
1042 }
1043
1044 void Magick::Image::label(const std::string &label_)
1045 {
1046   modifyImage();
1047   GetPPException;
1048   (void) SetImageProperty(image(),"Label",NULL,exceptionInfo);
1049   if (label_.length() > 0)
1050     (void) SetImageProperty(image(),"Label",label_.c_str(),exceptionInfo);
1051   ThrowPPException;
1052 }
1053
1054 std::string Magick::Image::label(void) const
1055 {
1056   const char
1057     *value;
1058
1059   GetPPException;
1060   value=GetImageProperty(constImage(),"Label",exceptionInfo);
1061   ThrowPPException;
1062
1063   if (value)
1064     return(std::string(value));
1065
1066   return(std::string());
1067 }
1068
1069 void Magick::Image::lowlightColor(const Color color_)
1070 {
1071   std::string
1072     value;
1073
1074   value=color_;
1075   artifact("lowlight-color",value);
1076 }
1077
1078 void Magick::Image::mask(const Magick::Image &mask_)
1079 {
1080   modifyImage();
1081
1082   GetPPException;
1083   if (mask_.isValid())
1084     SetImageMask(image(),mask_.constImage(),exceptionInfo);
1085   else
1086     SetImageMask(image(),(MagickCore::Image *) NULL,exceptionInfo);
1087   ThrowPPException;
1088 }
1089
1090 Magick::Image Magick::Image::mask(void) const
1091 {
1092   MagickCore::Image
1093     *image;
1094
1095   GetPPException;
1096   image=GetImageMask(constImage(),exceptionInfo);
1097   ThrowPPException;
1098
1099   if (image == (MagickCore::Image *) NULL)
1100     return(Magick::Image());
1101   else
1102     return(Magick::Image(image));
1103 }
1104
1105 void Magick::Image::magick(const std::string &magick_)
1106 {
1107   modifyImage();
1108
1109   magick_.copy(image()->magick,sizeof(image()->magick)-1);
1110   image()->magick[magick_.length()]=0;
1111   
1112   options()->magick(magick_);
1113 }
1114
1115 std::string Magick::Image::magick(void) const
1116 {
1117   if (*(constImage()->magick) != '\0')
1118     return(std::string(constImage()->magick));
1119
1120   return(constOptions()->magick());
1121 }
1122
1123 double Magick::Image::meanErrorPerPixel(void) const
1124 {
1125   return(constImage()->error.mean_error_per_pixel);
1126 }
1127
1128 void Magick::Image::modulusDepth(const size_t depth_)
1129 {
1130   modifyImage();
1131   GetPPException;
1132   SetImageDepth(image(),depth_,exceptionInfo);
1133   ThrowPPException;
1134   options()->depth(depth_);
1135 }
1136
1137 size_t Magick::Image::modulusDepth(void) const
1138 {
1139   size_t 
1140     depth;
1141
1142   GetPPException;
1143   depth=GetImageDepth(constImage(),exceptionInfo);
1144   ThrowPPException;
1145   return(depth);
1146 }
1147
1148 void Magick::Image::monochrome(const bool monochromeFlag_)
1149 {
1150   modifyImage();
1151   options()->monochrome(monochromeFlag_);
1152 }
1153
1154 bool Magick::Image::monochrome(void) const
1155 {
1156   return(constOptions()->monochrome());
1157 }
1158
1159 Magick::Geometry Magick::Image::montageGeometry(void) const
1160 {
1161   if (constImage()->montage)
1162     return Magick::Geometry(constImage()->montage);
1163
1164   throwExceptionExplicit(CorruptImageWarning,
1165     "Image does not contain a montage");
1166
1167   return(Magick::Geometry());
1168 }
1169
1170 double Magick::Image::normalizedMaxError(void) const
1171 {
1172   return(constImage()->error.normalized_maximum_error);
1173 }
1174
1175 double Magick::Image::normalizedMeanError(void) const
1176 {
1177   return(constImage()->error.normalized_mean_error);
1178 }
1179
1180 void Magick::Image::orientation(const Magick::OrientationType orientation_)
1181 {
1182   modifyImage();
1183   image()->orientation=orientation_;
1184 }
1185
1186 Magick::OrientationType Magick::Image::orientation(void) const
1187 {
1188   return(constImage()->orientation);
1189 }
1190
1191 void Magick::Image::page(const Magick::Geometry &pageSize_)
1192 {
1193   modifyImage();
1194   options()->page(pageSize_);
1195   image()->page=pageSize_;
1196 }
1197
1198 Magick::Geometry Magick::Image::page(void) const
1199 {
1200   return(Geometry(constImage()->page.width,constImage()->page.height,
1201     AbsoluteValue(constImage()->page.x),AbsoluteValue(constImage()->page.y)));
1202 }
1203
1204 void Magick::Image::quality(const size_t quality_)
1205 {
1206   modifyImage();
1207   image()->quality=quality_;
1208   options()->quality(quality_);
1209 }
1210
1211 size_t Magick::Image::quality(void) const
1212 {
1213   return(constImage()->quality);
1214 }
1215
1216 void Magick::Image::quantizeColors(const size_t colors_)
1217 {
1218   modifyImage();
1219   options()->quantizeColors(colors_);
1220 }
1221
1222 size_t Magick::Image::quantizeColors(void) const
1223 {
1224   return(constOptions()->quantizeColors());
1225 }
1226
1227 void Magick::Image::quantizeColorSpace(
1228   const Magick::ColorspaceType colorSpace_)
1229 {
1230   modifyImage();
1231   options()->quantizeColorSpace(colorSpace_);
1232 }
1233
1234 Magick::ColorspaceType Magick::Image::quantizeColorSpace(void) const
1235 {
1236   return(constOptions()->quantizeColorSpace());
1237 }
1238
1239 void Magick::Image::quantizeDither(const bool ditherFlag_)
1240 {
1241   modifyImage();
1242   options()->quantizeDither(ditherFlag_);
1243 }
1244
1245 bool Magick::Image::quantizeDither(void) const
1246 {
1247   return(constOptions()->quantizeDither());
1248 }
1249
1250 void Magick::Image::quantizeDitherMethod(const DitherMethod ditherMethod_)
1251 {
1252   modifyImage();
1253   options()->quantizeDitherMethod(ditherMethod_);
1254 }
1255
1256 MagickCore::DitherMethod Magick::Image::quantizeDitherMethod(void) const
1257 {
1258   return(constOptions()->quantizeDitherMethod());
1259 }
1260
1261 void Magick::Image::quantizeTreeDepth(const size_t treeDepth_)
1262 {
1263   modifyImage();
1264   options()->quantizeTreeDepth(treeDepth_);
1265 }
1266
1267 size_t Magick::Image::quantizeTreeDepth() const
1268 {
1269   return(constOptions()->quantizeTreeDepth());
1270 }
1271
1272 void Magick::Image::renderingIntent(
1273   const Magick::RenderingIntent renderingIntent_)
1274 {
1275   modifyImage();
1276   image()->rendering_intent=renderingIntent_;
1277 }
1278
1279 Magick::RenderingIntent Magick::Image::renderingIntent(void) const
1280 {
1281   return(static_cast<Magick::RenderingIntent>(constImage()->rendering_intent));
1282 }
1283
1284 void Magick::Image::resolutionUnits(
1285   const Magick::ResolutionType resolutionUnits_)
1286 {
1287   modifyImage();
1288   image()->units=resolutionUnits_;
1289   options()->resolutionUnits(resolutionUnits_);
1290 }
1291
1292 Magick::ResolutionType Magick::Image::resolutionUnits(void) const
1293 {
1294   return(static_cast<Magick::ResolutionType>(constImage()->units));
1295 }
1296
1297 size_t Magick::Image::rows(void) const
1298 {
1299   return(constImage()->rows);
1300 }
1301
1302 void Magick::Image::scene(const size_t scene_)
1303 {
1304   modifyImage();
1305   image()->scene=scene_;
1306 }
1307
1308 size_t Magick::Image::scene(void) const
1309 {
1310   return(constImage()->scene);
1311 }
1312
1313 void Magick::Image::size(const Geometry &geometry_)
1314 {
1315   modifyImage();
1316   options()->size(geometry_);
1317   image()->rows=geometry_.height();
1318   image()->columns=geometry_.width();
1319 }
1320
1321 Magick::Geometry Magick::Image::size(void) const
1322 {
1323   return(Magick::Geometry(constImage()->columns,constImage()->rows));
1324 }
1325
1326 void Magick::Image::strokeAntiAlias(const bool flag_)
1327 {
1328   modifyImage();
1329   options()->strokeAntiAlias(flag_);
1330 }
1331
1332 bool Magick::Image::strokeAntiAlias(void) const
1333 {
1334   return(constOptions()->strokeAntiAlias());
1335 }
1336
1337 void Magick::Image::strokeColor(const Magick::Color &strokeColor_)
1338 {
1339   std::string
1340     value;
1341
1342   modifyImage();
1343   options()->strokeColor(strokeColor_);
1344   value=strokeColor_;
1345   artifact("stroke",value);
1346 }
1347
1348 Magick::Color Magick::Image::strokeColor(void) const
1349 {
1350   return(constOptions()->strokeColor());
1351 }
1352
1353 void Magick::Image::strokeDashArray(const double *strokeDashArray_)
1354 {
1355   modifyImage();
1356   options()->strokeDashArray(strokeDashArray_);
1357 }
1358
1359 const double* Magick::Image::strokeDashArray(void) const
1360 {
1361   return(constOptions()->strokeDashArray());
1362 }
1363
1364 void Magick::Image::strokeDashOffset(const double strokeDashOffset_)
1365 {
1366   modifyImage();
1367   options()->strokeDashOffset(strokeDashOffset_);
1368 }
1369
1370 double Magick::Image::strokeDashOffset(void) const
1371 {
1372   return(constOptions()->strokeDashOffset());
1373 }
1374
1375 void Magick::Image::strokeLineCap(const Magick::LineCap lineCap_)
1376 {
1377   modifyImage();
1378   options()->strokeLineCap(lineCap_);
1379 }
1380
1381 Magick::LineCap Magick::Image::strokeLineCap(void) const
1382 {
1383   return(constOptions()->strokeLineCap());
1384 }
1385
1386 void Magick::Image::strokeLineJoin(const Magick::LineJoin lineJoin_)
1387 {
1388   modifyImage();
1389   options()->strokeLineJoin(lineJoin_);
1390 }
1391
1392 Magick::LineJoin Magick::Image::strokeLineJoin(void) const
1393 {
1394   return(constOptions()->strokeLineJoin());
1395 }
1396
1397 void Magick::Image::strokeMiterLimit(const size_t strokeMiterLimit_)
1398 {
1399   modifyImage();
1400   options()->strokeMiterLimit(strokeMiterLimit_);
1401 }
1402
1403 size_t Magick::Image::strokeMiterLimit(void) const
1404 {
1405   return(constOptions()->strokeMiterLimit());
1406 }
1407
1408 void Magick::Image::strokePattern(const Image &strokePattern_)
1409 {
1410   modifyImage();
1411   if(strokePattern_.isValid())
1412     options()->strokePattern(strokePattern_.constImage());
1413   else
1414     options()->strokePattern(static_cast<MagickCore::Image*>(NULL));
1415 }
1416
1417 Magick::Image Magick::Image::strokePattern(void) const
1418 {
1419   // FIXME: This is inordinately innefficient
1420   const MagickCore::Image 
1421     *tmpTexture;
1422
1423   Image
1424     texture;
1425
1426   tmpTexture=constOptions()->strokePattern();
1427
1428   if (tmpTexture)
1429     {
1430       MagickCore::Image
1431         *image;
1432
1433       GetPPException;
1434       image=CloneImage(tmpTexture,0,0,MagickTrue,exceptionInfo);
1435       texture.replaceImage(image);
1436       ThrowPPException;
1437     }
1438   return(texture);
1439 }
1440
1441 void Magick::Image::strokeWidth(const double strokeWidth_)
1442 {
1443   char
1444     value[MaxTextExtent];
1445
1446   modifyImage();
1447   options()->strokeWidth(strokeWidth_);
1448   FormatLocaleString(value,MaxTextExtent,"%.20g",strokeWidth_);
1449   (void) SetImageArtifact(image(),"strokewidth",value);
1450 }
1451
1452 double Magick::Image::strokeWidth(void) const
1453 {
1454   return(constOptions()->strokeWidth());
1455 }
1456
1457 void Magick::Image::subImage(const size_t subImage_)
1458 {
1459   modifyImage();
1460   options()->subImage(subImage_);
1461 }
1462
1463 size_t Magick::Image::subImage(void) const
1464 {
1465   return(constOptions()->subImage());
1466 }
1467
1468 void Magick::Image::subRange(const size_t subRange_)
1469 {
1470   modifyImage();
1471   options()->subRange(subRange_);
1472 }
1473
1474 size_t Magick::Image::subRange(void) const
1475 {
1476   return(constOptions()->subRange());
1477 }
1478
1479 void Magick::Image::textDirection(DirectionType direction_)
1480 {
1481   modifyImage();
1482   options()->textDirection(direction_);
1483 }
1484
1485 Magick::DirectionType Magick::Image::textDirection(void) const
1486 {
1487   return(constOptions()->textDirection());
1488 }
1489
1490 void Magick::Image::textEncoding(const std::string &encoding_)
1491 {
1492   modifyImage();
1493   options()->textEncoding(encoding_);
1494 }
1495
1496 std::string Magick::Image::textEncoding(void) const
1497 {
1498   return(constOptions()->textEncoding());
1499 }
1500
1501 void Magick::Image::textGravity(GravityType gravity_)
1502 {
1503   modifyImage();
1504   options()->textGravity(gravity_);
1505 }
1506
1507 Magick::GravityType Magick::Image::textGravity(void) const
1508 {
1509   return(constOptions()->textGravity());
1510 }
1511
1512 void Magick::Image::textInterlineSpacing(double spacing_)
1513 {
1514   modifyImage();
1515   options()->textInterlineSpacing(spacing_);
1516 }
1517
1518 double Magick::Image::textInterlineSpacing(void) const
1519 {
1520   return(constOptions()->textInterlineSpacing());
1521 }
1522
1523 void Magick::Image::textInterwordSpacing(double spacing_)
1524 {
1525   modifyImage();
1526   options()->textInterwordSpacing(spacing_);
1527 }
1528
1529 double Magick::Image::textInterwordSpacing(void) const
1530 {
1531   return(constOptions()->textInterwordSpacing());
1532 }
1533
1534 void Magick::Image::textKerning(double kerning_)
1535 {
1536   modifyImage();
1537   options()->textKerning(kerning_);
1538 }
1539
1540 double Magick::Image::textKerning(void) const
1541 {
1542   return(constOptions()->textKerning());
1543 }
1544
1545 size_t Magick::Image::totalColors(void) const
1546 {
1547   size_t
1548     colors;
1549
1550   GetPPException;
1551   colors=GetNumberColors(constImage(),0,exceptionInfo);
1552   ThrowPPException;
1553   return colors;
1554 }
1555
1556 void Magick::Image::transformRotation(const double angle_)
1557 {
1558   modifyImage();
1559   options()->transformRotation(angle_);
1560 }
1561
1562 void Magick::Image::transformSkewX(const double skewx_)
1563 {
1564   modifyImage();
1565   options()->transformSkewX(skewx_);
1566 }
1567
1568 void Magick::Image::transformSkewY(const double skewy_)
1569 {
1570   modifyImage();
1571   options()->transformSkewY(skewy_);
1572 }
1573
1574 Magick::ImageType Magick::Image::type(void) const
1575 {
1576   if (constOptions()->type() != UndefinedType)
1577     return(constOptions()->type());
1578   else if (constImage()->type != UndefinedType)
1579     return(constImage()->type);
1580   else
1581     return(determineType());
1582 }
1583
1584 void Magick::Image::type(const Magick::ImageType type_)
1585 {
1586   modifyImage();
1587   options()->type(type_);
1588   GetPPException;
1589   SetImageType(image(),type_,exceptionInfo);
1590   ThrowPPException;
1591 }
1592
1593 void Magick::Image::verbose(const bool verboseFlag_)
1594 {
1595   modifyImage();
1596   options()->verbose(verboseFlag_);
1597 }
1598
1599 bool Magick::Image::verbose(void) const
1600 {
1601   return(constOptions()->verbose());
1602 }
1603
1604 void Magick::Image::view(const std::string &view_)
1605 {
1606   modifyImage();
1607   options()->view(view_);
1608 }
1609
1610 std::string Magick::Image::view(void) const
1611 {
1612   return(constOptions()->view());
1613 }
1614
1615 void Magick::Image::virtualPixelMethod(
1616   const VirtualPixelMethod virtualPixelMethod_)
1617 {
1618   modifyImage();
1619   GetPPException;
1620   SetImageVirtualPixelMethod(image(),virtualPixelMethod_,exceptionInfo);
1621   ThrowPPException;
1622 }
1623
1624 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod(void) const
1625 {
1626   return(GetImageVirtualPixelMethod(constImage()));
1627 }
1628
1629 void Magick::Image::x11Display(const std::string &display_)
1630 {
1631   modifyImage();
1632   options()->x11Display(display_);
1633 }
1634
1635 std::string Magick::Image::x11Display(void) const
1636 {
1637   return(constOptions()->x11Display());
1638 }
1639
1640 double Magick::Image::xResolution(void) const
1641 {
1642   return(constImage()->resolution.x);
1643 }
1644
1645 double Magick::Image::yResolution(void) const
1646 {
1647   return(constImage()->resolution.y);
1648 }
1649
1650 void Magick::Image::adaptiveBlur(const double radius_,const double sigma_)
1651 {
1652   MagickCore::Image
1653     *newImage;
1654
1655   GetPPException;
1656   newImage=AdaptiveBlurImage(constImage(),radius_,sigma_,exceptionInfo);
1657   replaceImage(newImage);
1658   ThrowPPException;
1659 }
1660
1661 void Magick::Image::adaptiveResize(const Geometry &geometry_)
1662 {
1663   MagickCore::Image
1664     *newImage;
1665
1666   size_t
1667     height=rows(),
1668     width=columns();
1669
1670   ssize_t
1671     x=0,
1672     y=0;
1673
1674   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
1675     &height);
1676
1677   GetPPException;
1678   newImage=AdaptiveResizeImage(constImage(),width,height,exceptionInfo);
1679   replaceImage(newImage);
1680   ThrowPPException;
1681 }
1682
1683 void Magick::Image::adaptiveSharpen(const double radius_,const double sigma_)
1684 {
1685   MagickCore::Image
1686     *newImage;
1687
1688   GetPPException;
1689   newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,exceptionInfo);
1690   replaceImage(newImage);
1691   ThrowPPException;
1692 }
1693
1694 void Magick::Image::adaptiveSharpenChannel(const ChannelType channel_,
1695   const double radius_,const double sigma_ )
1696 {
1697   MagickCore::Image
1698     *newImage;
1699
1700   GetPPException;
1701   SetPPChannelMask(channel_);
1702   newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,exceptionInfo);
1703   RestorePPChannelMask;
1704   replaceImage(newImage);
1705   ThrowPPException;
1706 }
1707
1708 void Magick::Image::adaptiveThreshold(const size_t width_,const size_t height_,
1709    const double bias_)
1710 {
1711
1712   MagickCore::Image
1713     *newImage;
1714
1715   GetPPException;
1716   newImage=AdaptiveThresholdImage(constImage(),width_,height_,bias_,
1717     exceptionInfo);
1718   replaceImage(newImage);
1719   ThrowPPException;
1720 }
1721
1722 void Magick::Image::addNoise(const NoiseType noiseType_)
1723 {
1724   MagickCore::Image
1725     *newImage;
1726
1727   GetPPException;
1728   newImage=AddNoiseImage(constImage(),noiseType_,1.0,exceptionInfo);
1729   replaceImage(newImage);
1730   ThrowPPException;
1731 }
1732
1733 void Magick::Image::addNoiseChannel(const ChannelType channel_,
1734   const NoiseType noiseType_)
1735 {
1736   MagickCore::Image
1737     *newImage;
1738
1739   GetPPException;
1740   SetPPChannelMask(channel_);
1741   newImage=AddNoiseImage(constImage(),noiseType_,1.0,exceptionInfo);
1742   RestorePPChannelMask;
1743   replaceImage(newImage);
1744   ThrowPPException;
1745 }
1746
1747 void Magick::Image::affineTransform(const DrawableAffine &affine_)
1748 {
1749   AffineMatrix
1750     _affine;
1751
1752   MagickCore::Image
1753     *newImage;
1754
1755   _affine.sx=affine_.sx();
1756   _affine.sy=affine_.sy();
1757   _affine.rx=affine_.rx();
1758   _affine.ry=affine_.ry();
1759   _affine.tx=affine_.tx();
1760   _affine.ty=affine_.ty();
1761
1762   GetPPException;
1763   newImage=AffineTransformImage(constImage(),&_affine,exceptionInfo);
1764   replaceImage(newImage);
1765   ThrowPPException;
1766 }
1767
1768 void Magick::Image::alpha(const unsigned int alpha_)
1769 {
1770   modifyImage();
1771   GetPPException;
1772   SetImageAlpha(image(),alpha_,exceptionInfo);
1773   ThrowPPException;
1774 }
1775
1776 void Magick::Image::alphaChannel(AlphaChannelOption alphaOption_)
1777 {
1778   modifyImage();
1779   GetPPException;
1780   SetImageAlphaChannel(image(),alphaOption_,exceptionInfo);
1781   ThrowPPException;
1782 }
1783
1784 void Magick::Image::annotate(const std::string &text_,
1785   const Geometry &location_)
1786 {
1787   annotate(text_,location_,NorthWestGravity,0.0);
1788 }
1789
1790 void Magick::Image::annotate(const std::string &text_,
1791   const Geometry &boundingArea_,const GravityType gravity_)
1792 {
1793   annotate(text_,boundingArea_,gravity_,0.0);
1794 }
1795
1796 void Magick::Image::annotate(const std::string &text_,
1797   const Geometry &boundingArea_,const GravityType gravity_,
1798   const double degrees_)
1799 {
1800   AffineMatrix
1801     oaffine;
1802
1803   char
1804     boundingArea[MaxTextExtent];
1805
1806   DrawInfo
1807     *drawInfo;
1808
1809   modifyImage();
1810
1811   drawInfo=options()->drawInfo();
1812   drawInfo->text=const_cast<char *>(text_.c_str());
1813   drawInfo->geometry=0;
1814
1815   if (boundingArea_.isValid())
1816     {
1817       if (boundingArea_.width() == 0 || boundingArea_.height() == 0)
1818         {
1819           FormatLocaleString(boundingArea,MaxTextExtent,"%+.20g%+.20g",
1820             (double) boundingArea_.xOff(),(double) boundingArea_.yOff());
1821         }
1822       else
1823         {
1824           (void) CopyMagickString(boundingArea,string(boundingArea_).c_str(),
1825             MaxTextExtent);
1826         }
1827       drawInfo->geometry=boundingArea;
1828     }
1829
1830   drawInfo->gravity=gravity_;
1831
1832   oaffine=drawInfo->affine;
1833   if (degrees_ != 0.0)
1834     {
1835        AffineMatrix
1836          affine,
1837          current;
1838
1839        affine.sx=1.0;
1840        affine.rx=0.0;
1841        affine.ry=0.0;
1842        affine.sy=1.0;
1843        affine.tx=0.0;
1844        affine.ty=0.0;
1845
1846        current=drawInfo->affine;
1847        affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
1848        affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
1849        affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
1850        affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
1851
1852        drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
1853        drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
1854        drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
1855        drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
1856        drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
1857          +current.tx;
1858     }
1859
1860   GetPPException;
1861   AnnotateImage(image(),drawInfo,exceptionInfo);
1862
1863   // Restore original values
1864   drawInfo->affine=oaffine;
1865   drawInfo->text=0;
1866   drawInfo->geometry=0;
1867
1868   ThrowPPException;
1869 }
1870
1871 void Magick::Image::annotate(const std::string &text_,
1872   const GravityType gravity_)
1873 {
1874   DrawInfo
1875     *drawInfo;
1876
1877   modifyImage();
1878
1879   drawInfo=options()->drawInfo();
1880   drawInfo->text=const_cast<char *>(text_.c_str());
1881   drawInfo->gravity=gravity_;
1882
1883   GetPPException;
1884   AnnotateImage(image(),drawInfo,exceptionInfo);
1885
1886   drawInfo->gravity=NorthWestGravity;
1887   drawInfo->text=0;
1888
1889   ThrowPPException;
1890 }
1891
1892 void Magick::Image::artifact(const std::string &name_,const std::string &value_)
1893 {
1894   modifyImage();
1895   (void) SetImageArtifact(image(),name_.c_str(),value_.c_str());
1896 }
1897
1898 std::string Magick::Image::artifact(const std::string &name_)
1899 {
1900   const char
1901     *value;
1902
1903   value=GetImageArtifact(constImage(),name_.c_str());
1904   if (value)
1905     return(std::string(value));
1906   return(std::string());
1907 }
1908
1909 void Magick::Image::attribute(const std::string name_,const std::string value_)
1910 {
1911   modifyImage();
1912   GetPPException;
1913   SetImageProperty(image(),name_.c_str(),value_.c_str(),exceptionInfo);
1914   ThrowPPException;
1915 }
1916
1917 std::string Magick::Image::attribute(const std::string name_)
1918 {
1919   const char
1920     *value;
1921
1922   GetPPException;
1923   value=GetImageProperty(constImage(),name_.c_str(),exceptionInfo);
1924   ThrowPPException;
1925
1926   if (value)
1927     return(std::string(value));
1928
1929   return(std::string()); // Intentionally no exception
1930 }
1931
1932 void Magick::Image::autoGamma(void)
1933 {
1934   modifyImage();
1935   GetPPException;
1936   (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
1937   (void) AutoGammaImage(image(),exceptionInfo);
1938   ThrowPPException;
1939 }
1940
1941 void Magick::Image::autoGammaChannel(const ChannelType channel_)
1942 {
1943   modifyImage();
1944   GetPPException;
1945   SetPPChannelMask(channel_);
1946   (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
1947   (void) AutoGammaImage(image(),exceptionInfo);
1948   RestorePPChannelMask;
1949   ThrowPPException;
1950 }
1951
1952 void Magick::Image::autoLevel(void)
1953 {
1954   modifyImage();
1955   GetPPException;
1956   (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
1957   (void) AutoLevelImage(image(),exceptionInfo);
1958   ThrowPPException;
1959 }
1960
1961 void Magick::Image::autoLevelChannel(const ChannelType channel_)
1962 {
1963   modifyImage();
1964   GetPPException;
1965   SetPPChannelMask(channel_);
1966   (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
1967   (void) AutoLevelImage(image(),exceptionInfo);
1968   RestorePPChannelMask;
1969   ThrowPPException;
1970 }
1971
1972 void Magick::Image::autoOrient(void)
1973 {
1974   MagickCore::Image
1975     *newImage;
1976
1977   if (image()->orientation == UndefinedOrientation ||
1978       image()->orientation == TopLeftOrientation)
1979     return;
1980
1981   GetPPException;
1982   (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
1983   newImage=AutoOrientImage(constImage(),image()->orientation,exceptionInfo);
1984   replaceImage(newImage);
1985   ThrowPPException;
1986 }
1987
1988 void Magick::Image::blackThreshold(const std::string &threshold_)
1989 {
1990   modifyImage();
1991   GetPPException;
1992   BlackThresholdImage(image(),threshold_.c_str(),exceptionInfo);
1993   ThrowPPException;
1994 }
1995
1996 void Magick::Image::blackThresholdChannel(const ChannelType channel_,
1997   const std::string &threshold_)
1998 {
1999   modifyImage();
2000   GetPPException;
2001   SetPPChannelMask(channel_);
2002   BlackThresholdImage(image(),threshold_.c_str(),exceptionInfo);
2003   RestorePPChannelMask;
2004   ThrowPPException;
2005 }
2006
2007 void Magick::Image::blueShift(const double factor_)
2008 {
2009   MagickCore::Image
2010     *newImage;
2011
2012   GetPPException;
2013   newImage=BlueShiftImage(constImage(),factor_,exceptionInfo);
2014   replaceImage(newImage);
2015   ThrowPPException;
2016 }
2017
2018 void Magick::Image::blur(const double radius_,const double sigma_)
2019 {
2020   MagickCore::Image
2021     *newImage;
2022
2023   GetPPException;
2024   newImage=BlurImage(constImage(),radius_,sigma_,exceptionInfo);
2025   replaceImage(newImage);
2026   ThrowPPException;
2027 }
2028
2029 void Magick::Image::blurChannel(const ChannelType channel_,
2030   const double radius_,const double sigma_)
2031 {
2032   MagickCore::Image
2033     *newImage;
2034
2035   GetPPException;
2036   SetPPChannelMask(channel_);
2037   newImage=BlurImage(constImage(),radius_,sigma_,exceptionInfo);
2038   RestorePPChannelMask;
2039   replaceImage(newImage);
2040   ThrowPPException;
2041 }
2042
2043 void Magick::Image::border(const Geometry &geometry_)
2044 {
2045   MagickCore::Image
2046     *newImage;
2047
2048   RectangleInfo
2049     borderInfo=geometry_;
2050
2051   GetPPException;
2052   newImage=BorderImage(constImage(),&borderInfo,image()->compose,
2053     exceptionInfo);
2054   replaceImage(newImage);
2055   ThrowPPException;
2056 }
2057
2058 void Magick::Image::brightnessContrast(const double brightness_,
2059   const double contrast_)
2060 {
2061   modifyImage();
2062   GetPPException;
2063   BrightnessContrastImage(image(),brightness_,contrast_,exceptionInfo);
2064   ThrowPPException;
2065 }
2066
2067 void Magick::Image::brightnessContrastChannel(const ChannelType channel_,
2068   const double brightness_,const double contrast_)
2069 {
2070   modifyImage();
2071   GetPPException;
2072   SetPPChannelMask(channel_);
2073   BrightnessContrastImage(image(),brightness_,contrast_,exceptionInfo);
2074   RestorePPChannelMask;
2075   ThrowPPException;
2076 }
2077
2078 void Magick::Image::cannyEdge(const double radius_,const double sigma_,
2079   const double lowerPercent_,const double upperPercent_)
2080 {
2081   MagickCore::Image
2082     *newImage;
2083
2084   modifyImage();
2085   GetPPException;
2086   newImage=CannyEdgeImage(constImage(),radius_,sigma_,lowerPercent_,
2087     upperPercent_,exceptionInfo);
2088   replaceImage(newImage);
2089   ThrowPPException;
2090 }
2091
2092 void Magick::Image::channel(const ChannelType channel_)
2093 {
2094   MagickCore::Image
2095     *newImage;
2096
2097   GetPPException;
2098   newImage=SeparateImage(image(),channel_,exceptionInfo);
2099   replaceImage(newImage);
2100   ThrowPPException;
2101 }
2102
2103 void Magick::Image::charcoal(const double radius_,const double sigma_)
2104 {
2105   MagickCore::Image
2106     *newImage;
2107
2108   GetPPException;
2109   newImage=CharcoalImage(image(),radius_,sigma_,exceptionInfo);
2110   replaceImage(newImage);
2111   ThrowPPException;
2112 }
2113
2114 void Magick::Image::chop(const Geometry &geometry_)
2115 {
2116   MagickCore::Image
2117     *newImage;
2118
2119   RectangleInfo
2120     chopInfo=geometry_;
2121
2122   GetPPException;
2123   newImage=ChopImage(image(),&chopInfo,exceptionInfo);
2124   replaceImage(newImage);
2125   ThrowPPException;
2126 }
2127
2128 void Magick::Image::chromaBluePrimary(const double x_,const double y_)
2129 {
2130   modifyImage();
2131   image()->chromaticity.blue_primary.x=x_;
2132   image()->chromaticity.blue_primary.y=y_;
2133 }
2134
2135 void Magick::Image::chromaBluePrimary(double *x_,double *y_) const
2136 {
2137   *x_=constImage()->chromaticity.blue_primary.x;
2138   *y_=constImage()->chromaticity.blue_primary.y;
2139 }
2140
2141 void Magick::Image::chromaGreenPrimary(const double x_,const double y_)
2142 {
2143   modifyImage();
2144   image()->chromaticity.green_primary.x=x_;
2145   image()->chromaticity.green_primary.y=y_;
2146 }
2147
2148 void Magick::Image::chromaGreenPrimary(double *x_,double *y_) const
2149 {
2150   *x_=constImage()->chromaticity.green_primary.x;
2151   *y_=constImage()->chromaticity.green_primary.y;
2152 }
2153
2154 void Magick::Image::chromaRedPrimary(const double x_,const double y_)
2155 {
2156   modifyImage();
2157   image()->chromaticity.red_primary.x=x_;
2158   image()->chromaticity.red_primary.y=y_;
2159 }
2160
2161 void Magick::Image::chromaRedPrimary(double *x_,double *y_) const
2162 {
2163   *x_=constImage()->chromaticity.red_primary.x;
2164   *y_=constImage()->chromaticity.red_primary.y;
2165 }
2166
2167 void Magick::Image::chromaWhitePoint(const double x_,const double y_)
2168 {
2169   modifyImage();
2170   image()->chromaticity.white_point.x=x_;
2171   image()->chromaticity.white_point.y=y_;
2172 }
2173
2174 void Magick::Image::chromaWhitePoint(double *x_,double *y_) const
2175 {
2176   *x_=constImage()->chromaticity.white_point.x;
2177   *y_=constImage()->chromaticity.white_point.y;
2178 }
2179
2180 void Magick::Image::cdl(const std::string &cdl_)
2181 {
2182   modifyImage();
2183   GetPPException;
2184   (void) ColorDecisionListImage(image(),cdl_.c_str(),exceptionInfo);
2185   ThrowPPException;
2186 }
2187
2188 void Magick::Image::clamp(void)
2189 {
2190   modifyImage();
2191   GetPPException;
2192   ClampImage(image(),exceptionInfo);
2193   ThrowPPException;
2194 }
2195
2196 void Magick::Image::clampChannel(const ChannelType channel_)
2197 {
2198   modifyImage();
2199   GetPPException;
2200   SetPPChannelMask(channel_);
2201   ClampImage(image(),exceptionInfo);
2202   RestorePPChannelMask;
2203   ThrowPPException;
2204 }
2205
2206 void Magick::Image::clip(void)
2207 {
2208   modifyImage();
2209   GetPPException;
2210   ClipImage(image(),exceptionInfo);
2211   ThrowPPException;
2212 }
2213
2214 void Magick::Image::clipPath(const std::string pathname_,const bool inside_)
2215 {
2216   modifyImage();
2217   GetPPException;
2218   ClipImagePath(image(),pathname_.c_str(),(MagickBooleanType) inside_,
2219     exceptionInfo);
2220   ThrowPPException;
2221 }
2222
2223 void Magick::Image::clut(const Image &clutImage_,
2224   const PixelInterpolateMethod method)
2225 {
2226   modifyImage();
2227   GetPPException;
2228   ClutImage(image(),clutImage_.constImage(),method,exceptionInfo);
2229   ThrowPPException;
2230 }
2231
2232 void Magick::Image::clutChannel(const ChannelType channel_,
2233   const Image &clutImage_,const PixelInterpolateMethod method)
2234 {
2235   modifyImage();
2236   GetPPException;
2237   SetPPChannelMask(channel_);
2238   ClutImage(image(),clutImage_.constImage(),method,exceptionInfo);
2239   RestorePPChannelMask;
2240   ThrowPPException;
2241 }
2242
2243 void Magick::Image::colorize(const unsigned int alpha_,const Color &penColor_)
2244 {
2245   colorize(alpha_,alpha_,alpha_,penColor_);
2246 }
2247
2248 void Magick::Image::colorize(const unsigned int alphaRed_,
2249   const unsigned int alphaGreen_,const unsigned int alphaBlue_,
2250   const Color &penColor_)
2251 {
2252   char
2253     blend[MaxTextExtent];
2254
2255   MagickCore::Image
2256     *newImage;
2257
2258   PixelInfo
2259     target;
2260
2261   if (!penColor_.isValid())
2262     throwExceptionExplicit(OptionError,"Pen color argument is invalid");
2263
2264   FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,
2265     alphaBlue_);
2266
2267   target=static_cast<PixelInfo>(penColor_);
2268   GetPPException;
2269   newImage=ColorizeImage(image(),blend,&target,exceptionInfo);
2270   replaceImage(newImage);
2271   ThrowPPException;
2272 }
2273
2274 void Magick::Image::colorMap(const size_t index_,const Color &color_)
2275 {
2276   MagickCore::Image
2277     *imageptr;
2278
2279   imageptr=image();
2280
2281   if (index_ > (MaxColormapSize-1))
2282     throwExceptionExplicit(OptionError,
2283       "Colormap index must be less than MaxColormapSize");
2284
2285   if (!color_.isValid())
2286     throwExceptionExplicit(OptionError,"Color argument is invalid");
2287
2288   modifyImage();
2289
2290   // Ensure that colormap size is large enough
2291   if (colorMapSize() < (index_+1))
2292     colorMapSize(index_+1);
2293
2294   // Set color at index in colormap
2295   (imageptr->colormap)[index_]=color_;
2296 }
2297
2298 Magick::Color Magick::Image::colorMap(const size_t index_) const
2299 {
2300   if (!constImage()->colormap)
2301     {
2302       throwExceptionExplicit(OptionError,"Image does not contain a colormap");
2303       return(Color());
2304     }
2305
2306   if (index_ > constImage()->colors-1)
2307     throwExceptionExplicit(OptionError,"Index out of range");
2308
2309   return(Magick::Color((constImage()->colormap)[index_]));
2310 }
2311
2312 void Magick::Image::colorMatrix(const size_t order_,
2313   const double *color_matrix_)
2314 {
2315   KernelInfo
2316     *kernel_info;
2317
2318   GetPPException;
2319   kernel_info=AcquireKernelInfo((const char *) NULL,exceptionInfo);
2320   if (kernel_info != (KernelInfo *) NULL)
2321     {
2322       kernel_info->width=order_;
2323       kernel_info->height=order_;
2324       kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
2325         order_*sizeof(*kernel_info->values));
2326       if (kernel_info->values != (MagickRealType *) NULL)
2327         {
2328           MagickCore::Image
2329             *newImage;
2330
2331           for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
2332             kernel_info->values[i]=color_matrix_[i];
2333           newImage=ColorMatrixImage(image(),kernel_info,exceptionInfo);
2334           replaceImage(newImage);
2335         }
2336       kernel_info=DestroyKernelInfo(kernel_info);
2337     }
2338   ThrowPPException;
2339 }
2340
2341 bool Magick::Image::compare(const Image &reference_)
2342 {
2343   bool
2344     status;
2345
2346   Image
2347     ref=reference_;
2348
2349   GetPPException;
2350   modifyImage();
2351   ref.modifyImage();
2352   status=static_cast<bool>(IsImagesEqual(image(),ref.image(),exceptionInfo));
2353   ThrowPPException;
2354   return(status);
2355 }
2356
2357 double Magick::Image::compare(const Image &reference_,const MetricType metric_)
2358 {
2359   double
2360     distortion=0.0;
2361
2362   GetPPException;
2363   GetImageDistortion(image(),reference_.constImage(),metric_,&distortion,
2364     exceptionInfo);
2365   ThrowPPException;
2366   return(distortion);
2367 }
2368
2369 double Magick::Image::compareChannel(const ChannelType channel_,
2370   const Image &reference_,const MetricType metric_)
2371 {
2372   double
2373     distortion=0.0;
2374
2375   GetPPException;
2376   SetPPChannelMask(channel_);
2377   GetImageDistortion(image(),reference_.constImage(),metric_,&distortion,
2378     exceptionInfo);
2379   RestorePPChannelMask;
2380   ThrowPPException;
2381   return(distortion);
2382 }
2383
2384 Magick::Image Magick::Image::compare(const Image &reference_,
2385   const MetricType metric_,double *distortion)
2386 {
2387   MagickCore::Image
2388     *newImage;
2389
2390   GetPPException;
2391   newImage=CompareImages(image(),reference_.constImage(),metric_,distortion,
2392     exceptionInfo);
2393   ThrowPPException;
2394   if (newImage == (MagickCore::Image *) NULL)
2395     return(Magick::Image());
2396   else
2397     return(Magick::Image(newImage));
2398 }
2399
2400 Magick::Image Magick::Image::compareChannel(const ChannelType channel_,
2401   const Image &reference_,const MetricType metric_,double *distortion)
2402 {
2403   MagickCore::Image
2404     *newImage;
2405
2406   GetPPException;
2407   SetPPChannelMask(channel_);
2408   newImage=CompareImages(image(),reference_.constImage(),metric_,distortion,
2409     exceptionInfo);
2410   RestorePPChannelMask;
2411   ThrowPPException;
2412   if (newImage == (MagickCore::Image *) NULL)
2413     return(Magick::Image());
2414   else
2415     return(Magick::Image(newImage));
2416 }
2417
2418 void Magick::Image::composite(const Image &compositeImage_,
2419   const Geometry &offset_,const CompositeOperator compose_)
2420 {
2421   size_t
2422     height=rows(),
2423     width=columns();
2424
2425   ssize_t
2426     x=offset_.xOff(),
2427     y=offset_.yOff();
2428
2429   ParseMetaGeometry(static_cast<std::string>(offset_).c_str(),&x,&y,&width,
2430     &height);
2431
2432   modifyImage();
2433   GetPPException;
2434   CompositeImage(image(),compositeImage_.constImage(),compose_,MagickTrue,
2435     x,y,exceptionInfo);
2436   ThrowPPException;
2437 }
2438
2439 void Magick::Image::composite(const Image &compositeImage_,
2440   const GravityType gravity_,const CompositeOperator compose_)
2441 {
2442   RectangleInfo
2443     geometry;
2444
2445   modifyImage();
2446   SetGeometry(compositeImage_.constImage(),&geometry);
2447   GravityAdjustGeometry(columns(),rows(),gravity_,&geometry);
2448
2449   GetPPException;
2450   CompositeImage(image(),compositeImage_.constImage(),compose_,MagickTrue,
2451     geometry.x,geometry.y,exceptionInfo);
2452   ThrowPPException;
2453 }
2454
2455 void Magick::Image::composite(const Image &compositeImage_,
2456   const ssize_t xOffset_,const ssize_t yOffset_,
2457   const CompositeOperator compose_)
2458 {
2459   // Image supplied as compositeImage is composited with current image and
2460   // results in updating current image.
2461   modifyImage();
2462   GetPPException;
2463   CompositeImage(image(),compositeImage_.constImage(),compose_,MagickTrue,
2464     xOffset_,yOffset_,exceptionInfo);
2465   ThrowPPException;
2466 }
2467
2468 void Magick::Image::connectedComponents(const size_t connectivity_)
2469 {
2470   MagickCore::Image
2471     *newImage;
2472
2473   GetPPException;
2474   newImage=ConnectedComponentsImage(constImage(),connectivity_,exceptionInfo);
2475   replaceImage(newImage);
2476   ThrowPPException;
2477 }
2478
2479 void Magick::Image::contrast(const size_t sharpen_)
2480 {
2481   modifyImage();
2482   GetPPException;
2483   ContrastImage(image(),(MagickBooleanType) sharpen_,exceptionInfo);
2484   ThrowPPException;
2485 }
2486
2487 void Magick::Image::contrastStretch(const double blackPoint_,
2488   const double whitePoint_)
2489 {
2490   modifyImage();
2491   GetPPException;
2492   ContrastStretchImage(image(),blackPoint_,whitePoint_,exceptionInfo);
2493   ThrowPPException;
2494 }
2495
2496 void Magick::Image::contrastStretchChannel(const ChannelType channel_,
2497   const double blackPoint_,const double whitePoint_)
2498 {
2499   modifyImage();
2500   GetPPException;
2501   SetPPChannelMask(channel_);
2502   ContrastStretchImage(image(),blackPoint_,whitePoint_,exceptionInfo);
2503   RestorePPChannelMask;
2504   ThrowPPException;
2505 }
2506
2507 void Magick::Image::convolve(const size_t order_,const double *kernel_)
2508 {
2509   KernelInfo
2510     *kernel_info;
2511
2512   GetPPException;
2513   kernel_info=AcquireKernelInfo((const char *) NULL,exceptionInfo);
2514   kernel_info->width=order_;
2515   kernel_info->height=order_;
2516   kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
2517     order_*sizeof(*kernel_info->values));
2518   if (kernel_info->values != (MagickRealType *) NULL)
2519     {
2520       MagickCore::Image
2521         *newImage;
2522
2523       for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
2524         kernel_info->values[i]=kernel_[i];
2525       newImage=ConvolveImage(image(),kernel_info,exceptionInfo);
2526       replaceImage(newImage);
2527     }
2528   kernel_info=DestroyKernelInfo(kernel_info);
2529   ThrowPPException;
2530 }
2531
2532 void Magick::Image::crop(const Geometry &geometry_)
2533 {
2534   MagickCore::Image
2535     *newImage;
2536
2537   RectangleInfo
2538     cropInfo=geometry_;
2539
2540   GetPPException;
2541   newImage=CropImage(constImage(),&cropInfo,exceptionInfo);
2542   replaceImage(newImage);
2543   ThrowPPException;
2544 }
2545
2546 void Magick::Image::cycleColormap(const ssize_t amount_)
2547 {
2548   modifyImage();
2549   GetPPException;
2550   CycleColormapImage(image(),amount_,exceptionInfo);
2551   ThrowPPException;
2552 }
2553
2554 void Magick::Image::decipher(const std::string &passphrase_)
2555 {
2556   modifyImage();
2557   GetPPException;
2558   DecipherImage(image(),passphrase_.c_str(),exceptionInfo);
2559   ThrowPPException;
2560 }
2561
2562 void Magick::Image::defineSet(const std::string &magick_,
2563   const std::string &key_,bool flag_)
2564 {
2565   std::string
2566     definition;
2567
2568   modifyImage();
2569   definition=magick_ + ":" + key_;
2570   if (flag_)
2571     (void) SetImageOption(imageInfo(),definition.c_str(),"");
2572   else
2573     DeleteImageOption(imageInfo(),definition.c_str());
2574 }
2575
2576 bool Magick::Image::defineSet(const std::string &magick_,
2577   const std::string &key_ ) const
2578 {
2579   const char
2580     *option;
2581
2582   std::string
2583     key;
2584
2585   key=magick_ + ":" + key_;
2586   option=GetImageOption(constImageInfo(),key.c_str());
2587   if (option)
2588     return(true);
2589   return(false);
2590 }
2591
2592 void Magick::Image::defineValue(const std::string &magick_,
2593   const std::string &key_,const std::string &value_)
2594 {
2595   std::string
2596     format,
2597     option;
2598
2599   modifyImage();
2600   format=magick_ + ":" + key_;
2601   option=value_;
2602   (void) SetImageOption(imageInfo(),format.c_str(),option.c_str());
2603 }
2604
2605 std::string Magick::Image::defineValue(const std::string &magick_,
2606   const std::string &key_) const
2607 {
2608   const char
2609     *option;
2610
2611   std::string
2612     definition;
2613
2614   definition=magick_ + ":" + key_;
2615   option=GetImageOption(constImageInfo(),definition.c_str());
2616   if (option)
2617     return(std::string(option));
2618   return(std::string());
2619 }
2620
2621 void Magick::Image::deskew(const double threshold_)
2622 {
2623   MagickCore::Image
2624     *newImage;
2625
2626   GetPPException;
2627   newImage=DeskewImage(constImage(),threshold_,exceptionInfo);
2628   replaceImage(newImage);
2629   ThrowPPException;
2630 }
2631
2632 void Magick::Image::despeckle(void)
2633 {
2634   MagickCore::Image
2635     *newImage;
2636
2637   GetPPException;
2638   newImage=DespeckleImage(constImage(),exceptionInfo);
2639   replaceImage(newImage);
2640   ThrowPPException;
2641 }
2642
2643 Magick::ImageType Magick::Image::determineType(void) const
2644 {
2645   ImageType
2646     image_type;
2647
2648   GetPPException;
2649   image_type=GetImageType(constImage(),exceptionInfo);
2650   ThrowPPException;
2651   return(image_type);
2652 }
2653
2654 void Magick::Image::display(void)
2655 {
2656   GetPPException;
2657   DisplayImages(imageInfo(),image(),exceptionInfo);
2658   ThrowPPException;
2659 }
2660
2661 void Magick::Image::distort(const DistortImageMethod method_,
2662   const size_t numberArguments_,const double *arguments_,const bool bestfit_)
2663 {
2664   MagickCore::Image
2665     *newImage;
2666
2667   GetPPException;
2668   newImage=DistortImage(constImage(), method_,numberArguments_,arguments_,
2669     bestfit_ == true ? MagickTrue : MagickFalse,exceptionInfo);
2670   replaceImage(newImage);
2671   ThrowPPException;
2672 }
2673
2674 void Magick::Image::draw(const Magick::Drawable &drawable_)
2675 {
2676   DrawingWand
2677     *wand;
2678
2679   modifyImage();
2680
2681   wand=DrawAllocateWand(options()->drawInfo(),image());
2682
2683   if(wand)
2684     {
2685       drawable_.operator()(wand);
2686
2687       DrawRender(wand);
2688
2689       ClonePPDrawException(wand);
2690       wand=DestroyDrawingWand(wand);
2691       ThrowPPDrawException;
2692     }
2693 }
2694
2695 void Magick::Image::draw(const std::vector<Magick::Drawable> &drawable_)
2696 {
2697   DrawingWand
2698     *wand;
2699
2700   modifyImage();
2701
2702   wand=DrawAllocateWand(options()->drawInfo(),image());
2703
2704   if(wand)
2705     {
2706       for (std::vector<Magick::Drawable>::const_iterator p = drawable_.begin();
2707            p != drawable_.end(); p++ )
2708         {
2709           p->operator()(wand);
2710           if (DrawGetExceptionType(wand) != UndefinedException)
2711             break;
2712         }
2713
2714       if (DrawGetExceptionType(wand) == UndefinedException)
2715         DrawRender(wand);
2716
2717       ClonePPDrawException(wand);
2718       wand=DestroyDrawingWand(wand);
2719       ThrowPPDrawException;
2720     }
2721 }
2722
2723 void Magick::Image::edge(const double radius_)
2724 {
2725   MagickCore::Image
2726     *newImage;
2727
2728   GetPPException;
2729   newImage=EdgeImage(constImage(),radius_,exceptionInfo);
2730   replaceImage(newImage);
2731   ThrowPPException;
2732 }
2733
2734 void Magick::Image::emboss(const double radius_,const double sigma_)
2735 {
2736   MagickCore::Image
2737     *newImage;
2738
2739   GetPPException;
2740   newImage=EmbossImage(constImage(),radius_,sigma_,exceptionInfo);
2741   replaceImage(newImage);
2742   ThrowPPException;
2743 }
2744
2745 void Magick::Image::encipher(const std::string &passphrase_)
2746 {
2747   modifyImage();
2748   GetPPException;
2749   EncipherImage(image(),passphrase_.c_str(),exceptionInfo);
2750   ThrowPPException;
2751 }
2752
2753 void Magick::Image::enhance(void)
2754 {
2755   MagickCore::Image
2756     *newImage;
2757
2758   GetPPException;
2759   newImage=EnhanceImage(constImage(),exceptionInfo);
2760   replaceImage(newImage);
2761   ThrowPPException;
2762 }
2763
2764 void Magick::Image::equalize(void)
2765 {
2766   modifyImage();
2767   GetPPException;
2768   EqualizeImage(image(),exceptionInfo);
2769   ThrowPPException;
2770 }
2771
2772 void Magick::Image::erase(void)
2773 {
2774   modifyImage();
2775   GetPPException;
2776   (void) SetImageBackgroundColor(image(),exceptionInfo);
2777   ThrowPPException;
2778 }
2779
2780 void Magick::Image::extent(const Geometry &geometry_ )
2781 {
2782   MagickCore::Image
2783     *newImage;
2784
2785   RectangleInfo
2786     extentInfo=geometry_;
2787
2788   modifyImage();
2789   extentInfo.x=geometry_.xOff();
2790   extentInfo.y=geometry_.yOff();
2791   GetPPException;
2792   newImage=ExtentImage(image(),&extentInfo,exceptionInfo);
2793   replaceImage(newImage);
2794   ThrowPPException;
2795 }
2796
2797 void Magick::Image::extent(const Geometry &geometry_,
2798   const Color &backgroundColor_)
2799 {
2800   backgroundColor(backgroundColor_);
2801   extent(geometry_);
2802 }
2803
2804 void Magick::Image::extent(const Geometry &geometry_,
2805   const Color &backgroundColor_,const GravityType gravity_)
2806 {
2807   backgroundColor(backgroundColor_);
2808   extent(geometry_,gravity_);
2809 }
2810
2811 void Magick::Image::extent(const Geometry &geometry_,
2812   const GravityType gravity_)
2813 {
2814   RectangleInfo
2815     geometry;
2816
2817   SetGeometry(image(),&geometry);
2818   geometry.width=geometry_.width();
2819   geometry.height=geometry_.height();
2820   GravityAdjustGeometry(image()->columns,image()->rows,gravity_,&geometry);
2821   extent(geometry);
2822 }
2823
2824 void Magick::Image::flip(void)
2825 {
2826   MagickCore::Image
2827     *newImage;
2828
2829   GetPPException;
2830   newImage=FlipImage(constImage(),exceptionInfo);
2831   replaceImage(newImage);
2832   ThrowPPException;
2833 }
2834
2835 void Magick::Image::floodFillAlpha(const ssize_t x_,const ssize_t y_,
2836   const unsigned int alpha_,const bool invert_)
2837 {
2838   PixelInfo
2839     target;
2840
2841   modifyImage();
2842
2843   target=static_cast<PixelInfo>(pixelColor(x_,y_));
2844   target.alpha=alpha_;
2845   GetPPException;
2846   SetPPChannelMask(AlphaChannel);
2847   FloodfillPaintImage(image(),options()->drawInfo(),&target,x_,y_,
2848     (MagickBooleanType)invert_,exceptionInfo);
2849   RestorePPChannelMask;
2850   ThrowPPException;
2851 }
2852
2853 void Magick::Image::floodFillAlpha(const ssize_t x_,const ssize_t y_,
2854   const unsigned int alpha_,const Color &target_,const bool invert_)
2855 {
2856   PixelInfo
2857     target;
2858
2859   modifyImage();
2860
2861   target=static_cast<PixelInfo>(target_);
2862   target.alpha=alpha_;
2863   GetPPException;
2864   SetPPChannelMask(AlphaChannel);
2865   FloodfillPaintImage(image(),options()->drawInfo(),&target,x_,y_,
2866     (MagickBooleanType)invert_,exceptionInfo);
2867   RestorePPChannelMask;
2868   ThrowPPException;
2869 }
2870
2871 void Magick::Image::floodFillColor(const Geometry &point_,
2872   const Magick::Color &fillColor_,const bool invert_)
2873 {
2874   floodFillColor(point_.xOff(),point_.yOff(),fillColor_,invert_);
2875 }
2876
2877 void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_,
2878   const Magick::Color &fillColor_,const bool invert_)
2879 {
2880   PixelInfo
2881     pixel;
2882
2883   modifyImage();
2884
2885   pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
2886   floodFill(x_,y_,(Magick::Image *)NULL,fillColor_,&pixel,invert_);
2887 }
2888
2889 void Magick::Image::floodFillColor(const Geometry &point_,
2890   const Magick::Color &fillColor_,const Magick::Color &borderColor_,
2891   const bool invert_)
2892 {
2893   floodFillColor(point_.xOff(),point_.yOff(),fillColor_,borderColor_,invert_);
2894 }
2895
2896 void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_,
2897   const Magick::Color &fillColor_,const Magick::Color &borderColor_,
2898   const bool invert_)
2899 {
2900   PixelInfo
2901     pixel;
2902
2903   modifyImage();
2904
2905   pixel=static_cast<PixelInfo>(borderColor_);
2906   floodFill(x_,y_,(Magick::Image *)NULL,fillColor_,&pixel,invert_);
2907 }
2908
2909 void Magick::Image::floodFillTexture(const Magick::Geometry &point_,
2910   const Magick::Image &texture_,const bool invert_)
2911 {
2912   floodFillTexture(point_.xOff(),point_.yOff(),texture_,invert_);
2913 }
2914
2915 void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_,
2916   const Magick::Image &texture_,const bool invert_)
2917 {
2918   PixelInfo
2919     pixel;
2920
2921   modifyImage();
2922
2923   pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
2924   floodFill(x_,y_,&texture_,Magick::Color(),&pixel,invert_);
2925 }
2926
2927 void Magick::Image::floodFillTexture(const Magick::Geometry &point_,
2928   const Magick::Image &texture_,const Magick::Color &borderColor_,
2929   const bool invert_)
2930 {
2931   floodFillTexture(point_.xOff(),point_.yOff(),texture_,borderColor_,invert_);
2932 }
2933
2934 void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_,
2935   const Magick::Image &texture_,const Magick::Color &borderColor_,
2936   const bool invert_)
2937 {
2938   PixelInfo
2939     pixel;
2940
2941   modifyImage();
2942
2943   pixel=static_cast<PixelInfo>(borderColor_);
2944   floodFill(x_,y_,&texture_,Magick::Color(),&pixel,invert_);
2945 }
2946
2947 void Magick::Image::flop(void)
2948 {
2949   MagickCore::Image
2950     *newImage;
2951
2952   GetPPException;
2953   newImage=FlopImage(constImage(),exceptionInfo);
2954   replaceImage(newImage);
2955   ThrowPPException;
2956 }
2957
2958 void Magick::Image::fontTypeMetrics(const std::string &text_,
2959   TypeMetric *metrics)
2960 {
2961   DrawInfo
2962     *drawInfo;
2963
2964   drawInfo=options()->drawInfo();
2965   drawInfo->text=const_cast<char *>(text_.c_str());
2966   GetPPException;
2967   GetTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),exceptionInfo);
2968   drawInfo->text=0;
2969   ThrowPPException;
2970 }
2971
2972 void Magick::Image::fontTypeMetricsMultiline(const std::string &text_,
2973   TypeMetric *metrics)
2974 {
2975   DrawInfo
2976     *drawInfo;
2977
2978   drawInfo=options()->drawInfo();
2979   drawInfo->text=const_cast<char *>(text_.c_str());
2980   GetPPException;
2981   GetMultilineTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),exceptionInfo);
2982   drawInfo->text=0;
2983   ThrowPPException;
2984 }
2985
2986 void Magick::Image::frame(const Geometry &geometry_)
2987 {
2988   FrameInfo
2989     info;
2990   
2991   MagickCore::Image
2992     *newImage;
2993
2994   info.x=static_cast<ssize_t>(geometry_.width());
2995   info.y=static_cast<ssize_t>(geometry_.height());
2996   info.width=columns() + (static_cast<size_t>(info.x) << 1);
2997   info.height=rows() + (static_cast<size_t>(info.y) << 1);
2998   info.outer_bevel=geometry_.xOff();
2999   info.inner_bevel=geometry_.yOff();
3000
3001   GetPPException;
3002   newImage=FrameImage(constImage(),&info,image()->compose,exceptionInfo);
3003   replaceImage(newImage);
3004   ThrowPPException;
3005 }
3006
3007 void Magick::Image::frame(const size_t width_,const size_t height_,
3008   const ssize_t outerBevel_,const ssize_t innerBevel_)
3009 {
3010   FrameInfo
3011     info;
3012
3013   MagickCore::Image
3014     *newImage;
3015
3016   info.x=static_cast<ssize_t>(width_);
3017   info.y=static_cast<ssize_t>(height_);
3018   info.width=columns() + (static_cast<size_t>(info.x) << 1);
3019   info.height=rows() + (static_cast<size_t>(info.y) << 1);
3020   info.outer_bevel=static_cast<ssize_t>(outerBevel_);
3021   info.inner_bevel=static_cast<ssize_t>(innerBevel_);
3022
3023   GetPPException;
3024   newImage=FrameImage(constImage(),&info,image()->compose,exceptionInfo);
3025   replaceImage(newImage);
3026   ThrowPPException;
3027 }
3028
3029 void Magick::Image::fx(const std::string expression_)
3030 {
3031   MagickCore::Image
3032     *newImage;
3033
3034   GetPPException;
3035   newImage=FxImage(constImage(),expression_.c_str(),exceptionInfo);
3036   replaceImage(newImage);
3037   ThrowPPException;
3038 }
3039
3040 void Magick::Image::fx(const std::string expression_,
3041   const Magick::ChannelType channel_)
3042 {
3043   MagickCore::Image
3044     *newImage;
3045
3046   GetPPException;
3047   SetPPChannelMask(channel_);
3048   newImage=FxImage(constImage(),expression_.c_str(),exceptionInfo);
3049   RestorePPChannelMask;
3050   replaceImage(newImage);
3051   ThrowPPException;
3052 }
3053
3054 void Magick::Image::gamma(const double gamma_)
3055 {
3056   modifyImage();
3057   GetPPException;
3058   GammaImage(image(),gamma_,exceptionInfo);
3059   ThrowPPException;
3060 }
3061
3062 void Magick::Image::gamma(const double gammaRed_,const double gammaGreen_,
3063   const double gammaBlue_)
3064 {
3065   char
3066     gamma[MaxTextExtent + 1];
3067
3068   FormatLocaleString(gamma,MaxTextExtent,"%3.6f/%3.6f/%3.6f/",gammaRed_,
3069     gammaGreen_,gammaBlue_);
3070
3071   modifyImage();
3072   GetPPException;
3073   GammaImage(image(),atof(gamma),exceptionInfo);
3074   ThrowPPException;
3075 }
3076
3077 void Magick::Image::gaussianBlur(const double width_,const double sigma_)
3078 {
3079   MagickCore::Image
3080     *newImage;
3081
3082   GetPPException;
3083   newImage=GaussianBlurImage(constImage(),width_,sigma_,exceptionInfo);
3084   replaceImage(newImage);
3085   ThrowPPException;
3086 }
3087
3088 void Magick::Image::gaussianBlurChannel(const ChannelType channel_,
3089   const double width_,const double sigma_)
3090 {
3091   MagickCore::Image
3092     *newImage;
3093
3094   GetPPException;
3095   SetPPChannelMask(channel_);
3096   newImage=GaussianBlurImage(constImage(),width_,sigma_,exceptionInfo);
3097   RestorePPChannelMask;
3098   replaceImage(newImage);
3099   ThrowPPException;
3100 }
3101
3102 const Magick::Quantum *Magick::Image::getConstPixels(const ssize_t x_,
3103   const ssize_t y_,const size_t columns_,const size_t rows_) const
3104 {
3105   const Quantum
3106     *p;
3107
3108   GetPPException;
3109   p=(*GetVirtualPixels)(constImage(),x_, y_,columns_, rows_,exceptionInfo);
3110   ThrowPPException;
3111   return(p);
3112 }
3113
3114 const void *Magick::Image::getConstMetacontent(void) const
3115 {
3116   const void
3117     *result;
3118
3119   result=GetVirtualMetacontent(constImage());
3120
3121   if(!result)
3122     throwExceptionExplicit(OptionError,"Unable to retrieve meta content.");
3123
3124   return(result);
3125 }
3126
3127 void *Magick::Image::getMetacontent(void )
3128 {
3129   void
3130     *result;
3131
3132   result=GetAuthenticMetacontent(image());
3133
3134   if(!result)
3135     throwExceptionExplicit(OptionError,"Unable to retrieve meta content.");
3136
3137   return(result);
3138 }
3139
3140 Magick::Quantum *Magick::Image::getPixels(const ssize_t x_,const ssize_t y_,
3141   const size_t columns_,const size_t rows_)
3142 {
3143   Quantum
3144     *result;
3145
3146   modifyImage();
3147   GetPPException;
3148   result=(*GetAuthenticPixels)(image(),x_, y_,columns_,rows_,exceptionInfo);
3149   ThrowPPException;
3150
3151   return(result);
3152 }
3153
3154 void Magick::Image::grayscale(const PixelIntensityMethod method_)
3155 {
3156   modifyImage();
3157   GetPPException;
3158   (void) GrayscaleImage(image(),method_,exceptionInfo);
3159   ThrowPPException;
3160 }
3161
3162 void  Magick::Image::haldClut(const Image &clutImage_)
3163 {
3164   modifyImage();
3165   GetPPException;
3166   (void) HaldClutImage(image(),clutImage_.constImage(),exceptionInfo);
3167   ThrowPPException;
3168 }
3169
3170 void Magick::Image::houghLine(const size_t width_,const size_t height_,
3171   const size_t threshold_)
3172 {
3173   MagickCore::Image
3174     *newImage;
3175
3176   GetPPException;
3177   newImage=HoughLineImage(constImage(),width_,height_,threshold_,
3178     exceptionInfo);
3179   replaceImage(newImage);
3180   ThrowPPException;
3181 }
3182
3183 void Magick::Image::implode(const double factor_)
3184 {
3185   MagickCore::Image
3186     *newImage;
3187
3188   GetPPException;
3189   newImage=ImplodeImage(constImage(),factor_,image()->interpolate,
3190     exceptionInfo);
3191   replaceImage(newImage);
3192   ThrowPPException;
3193 }
3194
3195 void Magick::Image::inverseFourierTransform(const Image &phase_)
3196 {
3197   inverseFourierTransform(phase_,true);
3198 }
3199
3200 void Magick::Image::inverseFourierTransform(const Image &phase_,
3201   const bool magnitude_)
3202 {
3203   MagickCore::Image
3204     *newImage;
3205
3206   GetPPException;
3207   newImage=InverseFourierTransformImage(constImage(),phase_.constImage(),
3208     magnitude_ == true ? MagickTrue : MagickFalse,exceptionInfo);
3209   replaceImage(newImage);
3210   ThrowPPException;
3211 }
3212
3213 void Magick::Image::kuwahara(const double radius_,const double sigma_)
3214 {
3215   MagickCore::Image
3216     *newImage;
3217
3218   GetPPException;
3219   newImage=KuwaharaImage(constImage(),radius_,sigma_,exceptionInfo);
3220   replaceImage(newImage);
3221   ThrowPPException;
3222 }
3223
3224 void Magick::Image::kuwaharaChannel(const ChannelType channel_,
3225   const double radius_,const double sigma_)
3226 {
3227   MagickCore::Image
3228     *newImage;
3229
3230   GetPPException;
3231   SetPPChannelMask(channel_);
3232   newImage=KuwaharaImage(constImage(),radius_,sigma_,exceptionInfo);
3233   replaceImage(newImage);
3234   RestorePPChannelMask;
3235   ThrowPPException;
3236 }
3237
3238 void Magick::Image::level(const double blackPoint_,const double whitePoint_,
3239   const double gamma_)
3240 {
3241   modifyImage();
3242   GetPPException;
3243   (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
3244   ThrowPPException;
3245 }
3246
3247 void Magick::Image::levelChannel(const ChannelType channel_,
3248   const double blackPoint_,const double whitePoint_,const double gamma_)
3249 {
3250   modifyImage();
3251   GetPPException;
3252   SetPPChannelMask(channel_);
3253   (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
3254   RestorePPChannelMask;
3255   ThrowPPException;
3256 }
3257
3258 void Magick::Image::levelColors(const Color &blackColor_,
3259   const Color &whiteColor_,const bool invert_)
3260 {
3261   PixelInfo
3262     black,
3263     white;
3264
3265   modifyImage();
3266
3267   black=static_cast<PixelInfo>(blackColor_);
3268   white=static_cast<PixelInfo>(whiteColor_);
3269   GetPPException;
3270   (void) LevelImageColors(image(),&black,&white,invert_ == true ?
3271     MagickTrue : MagickFalse,exceptionInfo);
3272   ThrowPPException;
3273 }
3274
3275 void Magick::Image::levelColorsChannel(const ChannelType channel_,
3276   const Color &blackColor_,const Color &whiteColor_,const bool invert_)
3277 {
3278   PixelInfo
3279     black,
3280     white;
3281
3282   modifyImage();
3283
3284   black=static_cast<PixelInfo>(blackColor_);
3285   white=static_cast<PixelInfo>(whiteColor_);
3286   GetPPException;
3287   SetPPChannelMask(channel_);
3288   (void) LevelImageColors(image(),&black,&white,invert_ == true ?
3289     MagickTrue : MagickFalse,exceptionInfo);
3290   RestorePPChannelMask;
3291   ThrowPPException;
3292 }
3293
3294 void Magick::Image::linearStretch(const double blackPoint_,
3295   const double whitePoint_)
3296 {
3297   modifyImage();
3298   GetPPException;
3299   LinearStretchImage(image(),blackPoint_,whitePoint_,exceptionInfo);
3300   ThrowPPException;
3301 }
3302
3303 void Magick::Image::liquidRescale(const Geometry &geometry_)
3304 {
3305   MagickCore::Image
3306     *newImage;
3307
3308   size_t
3309     height=rows(),
3310     width=columns();
3311
3312   ssize_t
3313     x=0,
3314     y=0;
3315
3316   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
3317     &height);
3318
3319   GetPPException;
3320   newImage=LiquidRescaleImage(image(),width,height,x,y,exceptionInfo);
3321   replaceImage(newImage);
3322   ThrowPPException;
3323 }
3324
3325 void Magick::Image::magnify(void)
3326 {
3327   MagickCore::Image
3328     *newImage;
3329
3330   GetPPException;
3331   newImage=MagnifyImage(constImage(),exceptionInfo);
3332   replaceImage(newImage);
3333   ThrowPPException;
3334 }
3335
3336 void Magick::Image::map(const Image &mapImage_,const bool dither_)
3337 {
3338   modifyImage();
3339   GetPPException;
3340   options()->quantizeDither(dither_);
3341   RemapImage(options()->quantizeInfo(),image(),mapImage_.constImage(),
3342     exceptionInfo);
3343   ThrowPPException;
3344 }
3345
3346 void Magick::Image::medianFilter(const double radius_)
3347 {
3348   MagickCore::Image
3349     *newImage;
3350
3351   GetPPException;
3352   newImage=StatisticImage(image(),MedianStatistic,(size_t) radius_,
3353     (size_t) radius_,exceptionInfo);
3354   replaceImage(newImage);
3355   ThrowPPException;
3356 }
3357
3358 void Magick::Image::minify(void)
3359 {
3360   MagickCore::Image
3361     *newImage;
3362
3363   GetPPException;
3364   newImage=MinifyImage(constImage(),exceptionInfo);
3365   replaceImage(newImage);
3366   ThrowPPException;
3367 }
3368
3369 void Magick::Image::modulate(const double brightness_,const double saturation_,
3370   const double hue_)
3371 {
3372   char
3373     modulate[MaxTextExtent + 1];
3374
3375   FormatLocaleString(modulate,MaxTextExtent,"%3.6f,%3.6f,%3.6f",brightness_,
3376     saturation_,hue_);
3377
3378   modifyImage();
3379   GetPPException;
3380   ModulateImage(image(),modulate,exceptionInfo);
3381   ThrowPPException;
3382 }
3383
3384 Magick::ImageMoments Magick::Image::moments(void)
3385 {
3386   return(ImageMoments(constImage()));
3387 }
3388
3389 void Magick::Image::morphology(const MorphologyMethod method_,
3390   const std::string kernel_,const ssize_t iterations_)
3391 {
3392   KernelInfo
3393     *kernel;
3394
3395   MagickCore::Image
3396     *newImage;
3397
3398   GetPPException;
3399   kernel=AcquireKernelInfo(kernel_.c_str(),exceptionInfo);
3400   if (kernel == (KernelInfo *) NULL)
3401     throwExceptionExplicit(OptionError,"Unable to parse kernel.");
3402   newImage=MorphologyImage(constImage(),method_,iterations_,kernel,
3403     exceptionInfo);
3404   replaceImage(newImage);
3405   kernel=DestroyKernelInfo(kernel);
3406   ThrowPPException;
3407 }
3408
3409 void Magick::Image::morphology(const MorphologyMethod method_,
3410   const KernelInfoType kernel_,const std::string arguments_,
3411   const ssize_t iterations_)
3412 {
3413   const char
3414     *option;
3415
3416   std::string
3417     kernel;
3418
3419   option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
3420   if (option == (const char *)NULL)
3421     throwExceptionExplicit(OptionError,"Unable to determine kernel type.");
3422
3423   kernel=std::string(option);
3424   if (!arguments_.empty())
3425     kernel+=":"+arguments_;
3426
3427   morphology(method_,kernel,iterations_);
3428 }
3429
3430 void Magick::Image::morphologyChannel(const ChannelType channel_,
3431   const MorphologyMethod method_,const std::string kernel_,
3432   const ssize_t iterations_)
3433 {
3434   KernelInfo
3435     *kernel;
3436
3437   MagickCore::Image
3438     *newImage;
3439
3440
3441   GetPPException;
3442   kernel=AcquireKernelInfo(kernel_.c_str(),exceptionInfo);
3443   if (kernel == (KernelInfo *)NULL)
3444     throwExceptionExplicit(OptionError,"Unable to parse kernel.");
3445   SetPPChannelMask(channel_);
3446   newImage=MorphologyImage(constImage(),method_,iterations_,kernel,
3447     exceptionInfo);
3448   RestorePPChannelMask;
3449   replaceImage(newImage);
3450   kernel=DestroyKernelInfo(kernel);
3451   ThrowPPException;
3452 }
3453
3454 void Magick::Image::morphologyChannel(const ChannelType channel_,
3455   const MorphologyMethod method_,const KernelInfoType kernel_,
3456   const std::string arguments_,const ssize_t iterations_)
3457 {
3458   const char
3459     *option;
3460
3461   std::string
3462     kernel;
3463
3464   option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
3465   if (option == (const char *)NULL)
3466     throwExceptionExplicit(OptionError,"Unable to determine kernel type.");
3467
3468   kernel=std::string(option);
3469   if (!arguments_.empty())
3470     kernel+=":"+arguments_;
3471
3472   morphologyChannel(channel_,method_,kernel,iterations_);
3473 }
3474
3475 void Magick::Image::motionBlur(const double radius_,const double sigma_,
3476   const double angle_)
3477 {
3478   MagickCore::Image
3479     *newImage;
3480
3481   GetPPException;
3482   newImage=MotionBlurImage(constImage(),radius_,sigma_,angle_,exceptionInfo);
3483   replaceImage(newImage);
3484   ThrowPPException;
3485 }
3486
3487 void Magick::Image::negate(const bool grayscale_)
3488 {
3489   modifyImage();
3490   GetPPException;
3491   NegateImage(image(),(MagickBooleanType) grayscale_,exceptionInfo);
3492   ThrowPPException;
3493 }
3494
3495 void Magick::Image::negateChannel(const ChannelType channel_,
3496   const bool grayscale_)
3497 {
3498   modifyImage();
3499   GetPPException;
3500   SetPPChannelMask(channel_);
3501   NegateImage(image(),(MagickBooleanType) grayscale_,exceptionInfo);
3502   RestorePPChannelMask;
3503   ThrowPPException;
3504 }
3505
3506 void Magick::Image::normalize(void)
3507 {
3508   modifyImage();
3509   GetPPException;
3510   NormalizeImage(image(),exceptionInfo);
3511   ThrowPPException;
3512 }
3513
3514 void Magick::Image::oilPaint(const double radius_,const double sigma_)
3515 {
3516   MagickCore::Image
3517     *newImage;
3518
3519   GetPPException;
3520   newImage=OilPaintImage(constImage(),radius_,sigma_,exceptionInfo);
3521   replaceImage(newImage);
3522   ThrowPPException;
3523 }
3524
3525 void Magick::Image::opaque(const Color &opaqueColor_,const Color &penColor_,
3526   const bool invert_)
3527 {
3528   std::string
3529     opaqueColor,
3530     penColor;
3531
3532   PixelInfo
3533     opaque,
3534     pen;
3535
3536   if (!opaqueColor_.isValid())
3537     throwExceptionExplicit(OptionError,"Opaque color argument is invalid");
3538
3539   if (!penColor_.isValid())
3540     throwExceptionExplicit(OptionError,"Pen color argument is invalid");
3541
3542   modifyImage();
3543   opaqueColor=opaqueColor_;
3544   penColor=penColor_;
3545
3546   GetPPException;
3547   (void) QueryColorCompliance(opaqueColor.c_str(),AllCompliance,&opaque,
3548     exceptionInfo);
3549   (void) QueryColorCompliance(penColor.c_str(),AllCompliance,&pen,
3550     exceptionInfo);
3551   OpaquePaintImage(image(),&opaque,&pen,invert_ ? MagickTrue : MagickFalse,
3552     exceptionInfo);
3553   ThrowPPException;
3554 }
3555
3556 void Magick::Image::orderedDither(std::string thresholdMap_)
3557 {
3558   modifyImage();
3559   GetPPException;
3560   (void) OrderedPosterizeImage(image(),thresholdMap_.c_str(),exceptionInfo);
3561   ThrowPPException;
3562 }
3563
3564 void Magick::Image::orderedDitherChannel(const ChannelType channel_,
3565   std::string thresholdMap_)
3566 {
3567   modifyImage();
3568   GetPPException;
3569   SetPPChannelMask(channel_);
3570   (void) OrderedPosterizeImage(image(),thresholdMap_.c_str(),exceptionInfo);
3571   RestorePPChannelMask;
3572   ThrowPPException;
3573 }
3574
3575 void Magick::Image::perceptible(const double epsilon_)
3576 {
3577   modifyImage();
3578   GetPPException;
3579   PerceptibleImage(image(),epsilon_,exceptionInfo);
3580   ThrowPPException;
3581 }
3582
3583 void Magick::Image::perceptibleChannel(const ChannelType channel_,
3584   const double epsilon_)
3585 {
3586   modifyImage();
3587   GetPPException;
3588   SetPPChannelMask(channel_);
3589   PerceptibleImage(image(),epsilon_,exceptionInfo);
3590   RestorePPChannelMask;
3591   ThrowPPException;
3592 }
3593
3594  Magick::ImagePerceptualHash Magick::Image::perceptualHash()
3595 {
3596   return(ImagePerceptualHash(constImage()));
3597 }
3598
3599 void Magick::Image::ping(const std::string &imageSpec_)
3600 {
3601   MagickCore::Image
3602     *newImage;
3603
3604   GetPPException;
3605   options()->fileName(imageSpec_);
3606   newImage=PingImage(imageInfo(),exceptionInfo);
3607   read(newImage,exceptionInfo);
3608 }
3609
3610 void Magick::Image::ping(const Blob& blob_)
3611 {
3612   MagickCore::Image
3613     *newImage;
3614
3615   GetPPException;
3616   newImage=PingBlob(imageInfo(),blob_.data(),blob_.length(),exceptionInfo);
3617   read(newImage,exceptionInfo);
3618 }
3619
3620 void Magick::Image::pixelColor(const ssize_t x_,const ssize_t y_,
3621   const Color &color_)
3622 {
3623   PixelInfo
3624     packet;
3625
3626   Quantum
3627     *pixel;
3628
3629   // Test arguments to ensure they are within the image.
3630   if (y_ > (ssize_t) rows() || x_ > (ssize_t) columns())
3631     throwExceptionExplicit(OptionError,"Access outside of image boundary");
3632
3633   modifyImage();
3634
3635   // Set image to DirectClass
3636   classType(DirectClass );
3637
3638   // Get pixel view
3639   Pixels pixels(*this);
3640     // Set pixel value
3641   pixel=pixels.get(x_, y_, 1, 1 );
3642   packet=color_;
3643   MagickCore::SetPixelViaPixelInfo(constImage(),&packet,pixel);
3644   // Tell ImageMagick that pixels have been updated
3645   pixels.sync();
3646 }
3647
3648 Magick::Color Magick::Image::pixelColor(const ssize_t x_,
3649   const ssize_t y_) const
3650 {
3651   const Quantum
3652     *pixel;
3653
3654   pixel=getConstPixels(x_,y_,1,1);
3655   if (pixel)
3656     {
3657       PixelInfo
3658         packet;
3659
3660       MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3661       return(Color(packet));
3662     }
3663
3664   return(Color()); // invalid
3665 }
3666
3667 void Magick::Image::polaroid(const std::string &caption_,const double angle_,
3668   const PixelInterpolateMethod method_)
3669 {
3670   MagickCore::Image
3671     *newImage;
3672
3673   GetPPException;
3674   newImage=PolaroidImage(constImage(),options()->drawInfo(),caption_.c_str(),
3675     angle_,method_,exceptionInfo);
3676   replaceImage(newImage);
3677   ThrowPPException;
3678 }
3679
3680 void Magick::Image::posterize(const size_t levels_,const DitherMethod method_)
3681 {
3682   modifyImage();
3683   GetPPException;
3684   PosterizeImage(image(),levels_,method_,exceptionInfo);
3685   ThrowPPException;
3686 }
3687
3688 void Magick::Image::posterizeChannel(const ChannelType channel_,
3689   const size_t levels_,const DitherMethod method_)
3690 {
3691   modifyImage();
3692   GetPPException;
3693   SetPPChannelMask(channel_);
3694   PosterizeImage(image(),levels_,method_,exceptionInfo);
3695   RestorePPChannelMask;
3696   ThrowPPException;
3697 }
3698
3699 void Magick::Image::process(std::string name_,const ssize_t argc,
3700   const char **argv)
3701 {
3702   modifyImage();
3703
3704   GetPPException;
3705   (void) InvokeDynamicImageFilter(name_.c_str(),&image(),argc,argv,
3706       exceptionInfo);
3707   ThrowPPException;
3708 }
3709
3710 void Magick::Image::profile(const std::string name_,
3711   const Magick::Blob &profile_)
3712 {
3713   modifyImage();
3714   GetPPException;
3715   (void) ProfileImage(image(),name_.c_str(),(unsigned char *)profile_.data(),
3716     profile_.length(),exceptionInfo);
3717   ThrowPPException;
3718 }
3719
3720 Magick::Blob Magick::Image::profile(const std::string name_) const
3721 {
3722   const StringInfo
3723     *profile;
3724
3725   profile=GetImageProfile(constImage(),name_.c_str());
3726
3727   if (profile == (StringInfo *) NULL)
3728     return(Blob());
3729   return(Blob((void*) GetStringInfoDatum(profile),GetStringInfoLength(
3730     profile)));
3731 }
3732
3733 void Magick::Image::quantize(const bool measureError_)
3734 {
3735   modifyImage();
3736  
3737   if (measureError_)
3738     options()->quantizeInfo()->measure_error=MagickTrue;
3739   else
3740     options()->quantizeInfo()->measure_error=MagickFalse;
3741
3742   GetPPException;
3743   QuantizeImage(options()->quantizeInfo(),image(),exceptionInfo);
3744   ThrowPPException;
3745 }
3746
3747 void Magick::Image::quantumOperator(const ChannelType channel_,
3748   const MagickEvaluateOperator operator_,double rvalue_)
3749 {
3750   GetPPException;
3751   SetPPChannelMask(channel_);
3752   EvaluateImage(image(),operator_,rvalue_,exceptionInfo);
3753   RestorePPChannelMask;
3754   ThrowPPException;
3755 }
3756
3757 void Magick::Image::quantumOperator(const ssize_t x_,const ssize_t y_,
3758   const size_t columns_,const size_t rows_,const ChannelType channel_,
3759   const MagickEvaluateOperator operator_,const double rvalue_)
3760 {
3761   RectangleInfo
3762     geometry;
3763
3764   MagickCore::Image
3765     *cropImage;
3766
3767   geometry.width = columns_;
3768   geometry.height = rows_;
3769   geometry.x = x_;
3770   geometry.y = y_;
3771
3772   GetPPException;
3773   cropImage=CropImage(image(),&geometry,exceptionInfo);
3774   SetPPChannelMask(channel_);
3775   EvaluateImage(cropImage,operator_,rvalue_,exceptionInfo);
3776   RestorePPChannelMask;
3777   (void) CompositeImage(image(),cropImage,image()->alpha_trait == 
3778     BlendPixelTrait ? OverCompositeOp : CopyCompositeOp,MagickFalse,
3779     geometry.x,geometry.y,exceptionInfo );
3780   cropImage=DestroyImageList(cropImage);
3781   ThrowPPException;
3782 }
3783
3784 void Magick::Image::raise(const Geometry &geometry_,const bool raisedFlag_)
3785 {
3786   RectangleInfo
3787     raiseInfo=geometry_;
3788
3789   GetPPException;
3790   modifyImage();
3791   RaiseImage(image(),&raiseInfo,raisedFlag_ == true ? MagickTrue : MagickFalse,
3792     exceptionInfo);
3793   ThrowPPException;
3794 }
3795
3796 void Magick::Image::randomThreshold(const Geometry &thresholds_)
3797 {
3798   GetPPException;
3799   (void) RandomThresholdImage(image(),static_cast<std::string>(
3800     thresholds_).c_str(),exceptionInfo);
3801   ThrowPPException;
3802 }
3803
3804 void Magick::Image::randomThresholdChannel(const ChannelType channel_,
3805   const Geometry &thresholds_)
3806 {
3807   modifyImage();
3808   GetPPException;
3809   SetPPChannelMask(channel_);
3810   (void) RandomThresholdImage(image(),static_cast<std::string>(
3811     thresholds_).c_str(),exceptionInfo);
3812   RestorePPChannelMask;
3813   ThrowPPException;
3814 }
3815
3816 void Magick::Image::read(const Blob &blob_)
3817 {
3818   MagickCore::Image
3819     *newImage;
3820
3821   GetPPException;
3822   newImage=BlobToImage(imageInfo(),static_cast<const void *>(blob_.data()),
3823     blob_.length(),exceptionInfo);
3824   read(newImage,exceptionInfo);
3825 }
3826
3827 void Magick::Image::read(const Blob &blob_,const Geometry &size_)
3828 {
3829   size(size_);
3830   read(blob_);
3831 }
3832
3833 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
3834   const size_t depth_)
3835 {
3836   size(size_);
3837   depth(depth_);
3838   read(blob_);
3839 }
3840
3841 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
3842   const size_t depth_,const std::string &magick_)
3843 {
3844   size(size_);
3845   depth(depth_);
3846   magick(magick_);
3847   // Set explicit image format
3848   fileName(magick_ + ':');
3849   read(blob_);
3850 }
3851
3852 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
3853   const std::string &magick_)
3854 {
3855   size(size_);
3856   magick(magick_);
3857   // Set explicit image format
3858   fileName(magick_ + ':');
3859   read(blob_);
3860 }
3861
3862 void Magick::Image::read(const Geometry &size_,const std::string &imageSpec_)
3863 {
3864   size(size_);
3865   read(imageSpec_);
3866 }
3867
3868 void Magick::Image::read(const size_t width_,const size_t height_,
3869   const std::string &map_,const StorageType type_,const void *pixels_)
3870 {
3871   MagickCore::Image
3872     *newImage;
3873
3874   GetPPException;
3875   newImage=ConstituteImage(width_,height_,map_.c_str(),type_, pixels_,
3876     exceptionInfo);
3877   replaceImage(newImage);
3878   ThrowPPException;
3879 }
3880
3881 void Magick::Image::read(const std::string &imageSpec_)
3882 {
3883   MagickCore::Image
3884     *newImage;
3885
3886   GetPPException;
3887   options()->fileName(imageSpec_);
3888   newImage=ReadImage(imageInfo(),exceptionInfo);
3889   read(newImage,exceptionInfo);
3890 }
3891
3892 void Magick::Image::readPixels(const Magick::QuantumType quantum_,
3893   const unsigned char *source_)
3894 {
3895   QuantumInfo
3896     *quantum_info;
3897
3898   quantum_info=AcquireQuantumInfo(imageInfo(),image());
3899   GetPPException;
3900   ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
3901     quantum_,source_,exceptionInfo);
3902   quantum_info=DestroyQuantumInfo(quantum_info);
3903   ThrowPPException;
3904 }
3905
3906 void Magick::Image::reduceNoise(void)
3907 {
3908   reduceNoise(3.0);
3909 }
3910
3911 void Magick::Image::reduceNoise(const double order_)
3912 {
3913   MagickCore::Image
3914     *newImage;
3915
3916   GetPPException;
3917   newImage=StatisticImage(constImage(),NonpeakStatistic,(size_t) order_,
3918     (size_t) order_,exceptionInfo);
3919   replaceImage(newImage);
3920   ThrowPPException;
3921 }
3922
3923 void Magick::Image::resample(const Point &density_)
3924 {
3925   MagickCore::Image
3926     *newImage;
3927
3928   GetPPException;
3929   newImage=ResampleImage(constImage(),density_.x(),density_.y(),
3930     image()->filter,exceptionInfo);
3931   replaceImage(newImage);
3932   ThrowPPException;
3933 }
3934
3935 void Magick::Image::resize(const Geometry &geometry_)
3936 {
3937   MagickCore::Image
3938     *newImage;
3939
3940   size_t
3941     height=rows(),
3942     width=columns();
3943
3944   ssize_t
3945     x=0,
3946     y=0;
3947
3948   // Calculate new size.  This code should be supported using binary arguments
3949   // in the ImageMagick library.
3950   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
3951     &height);
3952
3953   GetPPException;
3954   newImage=ResizeImage(constImage(),width,height,image()->filter,
3955     exceptionInfo);
3956   replaceImage(newImage);
3957   ThrowPPException;
3958 }
3959
3960 void Magick::Image::roll(const Geometry &roll_)
3961 {
3962   MagickCore::Image
3963     *newImage;
3964
3965   GetPPException;
3966   newImage=RollImage(constImage(),roll_.xOff(),roll_.yOff(),exceptionInfo);
3967   replaceImage(newImage);
3968   ThrowPPException;
3969 }
3970
3971 void Magick::Image::roll(const size_t columns_,const size_t rows_)
3972 {
3973   MagickCore::Image
3974     *newImage;
3975
3976   GetPPException;
3977   newImage=RollImage(constImage(),static_cast<ssize_t>(columns_),
3978     static_cast<ssize_t>(rows_),exceptionInfo);
3979   replaceImage(newImage);
3980   ThrowPPException;
3981 }
3982
3983 void Magick::Image::rotate(const double degrees_)
3984 {
3985   MagickCore::Image
3986     *newImage;
3987
3988   GetPPException;
3989   newImage=RotateImage(constImage(),degrees_,exceptionInfo);
3990   replaceImage(newImage);
3991   ThrowPPException;
3992 }
3993
3994 void Magick::Image::rotationalBlur(const double angle_)
3995 {
3996   MagickCore::Image
3997     *newImage;
3998
3999   GetPPException;
4000   newImage=RotationalBlurImage(constImage(),angle_,exceptionInfo);
4001   replaceImage(newImage);
4002   ThrowPPException;
4003 }
4004
4005 void Magick::Image::rotationalBlurChannel(const ChannelType channel_,
4006   const double angle_)
4007 {
4008   MagickCore::Image
4009     *newImage;
4010
4011   GetPPException;
4012   SetPPChannelMask(channel_);
4013   newImage=RotationalBlurImage(constImage(),angle_,exceptionInfo);
4014   RestorePPChannelMask;
4015   replaceImage(newImage);
4016   ThrowPPException;
4017 }
4018
4019 void Magick::Image::sample(const Geometry &geometry_)
4020 {
4021   MagickCore::Image
4022     *newImage;
4023
4024   size_t
4025     height=rows(),
4026     width=columns();
4027
4028   ssize_t
4029     x=0,
4030     y=0;
4031
4032   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4033     &height);
4034
4035   GetPPException;
4036   newImage=SampleImage(constImage(),width,height,exceptionInfo);
4037   replaceImage(newImage);
4038   ThrowPPException;
4039 }
4040
4041 void Magick::Image::scale(const Geometry &geometry_)
4042 {
4043   MagickCore::Image
4044     *newImage;
4045
4046   size_t
4047     height=rows(),
4048     width=columns();
4049
4050   ssize_t
4051     x=0,
4052     y=0;
4053
4054   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4055     &height);
4056
4057   GetPPException;
4058   newImage=ScaleImage(constImage(),width,height,exceptionInfo);
4059   replaceImage(newImage);
4060   ThrowPPException;
4061 }
4062
4063 void Magick::Image::segment(const double clusterThreshold_,
4064   const double smoothingThreshold_)
4065 {
4066   modifyImage();
4067   GetPPException;
4068   SegmentImage(image(),options()->quantizeColorSpace(),
4069     (MagickBooleanType) options()->verbose(),clusterThreshold_,
4070     smoothingThreshold_,exceptionInfo);
4071   SyncImage(image(),exceptionInfo);
4072   ThrowPPException;
4073 }
4074
4075 void Magick::Image::selectiveBlur(const double radius_,const double sigma_,
4076   const double threshold_)
4077 {
4078   MagickCore::Image
4079     *newImage;
4080
4081   GetPPException;
4082   newImage=SelectiveBlurImage(constImage(),radius_,sigma_,threshold_,
4083     exceptionInfo);
4084   replaceImage(newImage);
4085   ThrowPPException;
4086 }
4087
4088 void Magick::Image::selectiveBlurChannel(const ChannelType channel_,
4089   const double radius_,const double sigma_,const double threshold_)
4090 {
4091   MagickCore::Image
4092     *newImage;
4093
4094   GetPPException;
4095   SetPPChannelMask(channel_);
4096   newImage=SelectiveBlurImage(constImage(),radius_,sigma_,threshold_,
4097     exceptionInfo);
4098   RestorePPChannelMask;
4099   replaceImage(newImage);
4100   ThrowPPException;
4101 }
4102
4103 Magick::Image Magick::Image::separate(const ChannelType channel_)
4104 {
4105   MagickCore::Image
4106     *image;
4107
4108   GetPPException;
4109   image=SeparateImage(constImage(),channel_,exceptionInfo);
4110   ThrowPPException;
4111   if (image == (MagickCore::Image *) NULL)
4112     return(Magick::Image());
4113   else
4114     return(Magick::Image(image));
4115 }
4116
4117 void Magick::Image::sepiaTone(const double threshold_)
4118 {
4119   MagickCore::Image
4120     *newImage;
4121
4122   GetPPException;
4123   newImage=SepiaToneImage(constImage(),threshold_,exceptionInfo);
4124   replaceImage(newImage);
4125   ThrowPPException;
4126 }
4127
4128 Magick::Quantum *Magick::Image::setPixels(const ssize_t x_,const ssize_t y_,
4129   const size_t columns_,const size_t rows_)
4130 {
4131   Quantum
4132     *result;
4133
4134   modifyImage();
4135   GetPPException;
4136   result=(*QueueAuthenticPixels)(image(),x_,y_,columns_,rows_,exceptionInfo);
4137   ThrowPPException;
4138   return(result);
4139 }
4140
4141 void Magick::Image::shade(const double azimuth_,const double elevation_,
4142   const bool colorShading_)
4143 {
4144   MagickCore::Image
4145     *newImage;
4146
4147   GetPPException;
4148   newImage=ShadeImage(constImage(),colorShading_ == true ?
4149     MagickTrue : MagickFalse,azimuth_,elevation_,exceptionInfo);
4150   replaceImage(newImage);
4151   ThrowPPException;
4152 }
4153
4154 void Magick::Image::shadow(const double percent_opacity_,const double sigma_,
4155   const ssize_t x_,const ssize_t y_)
4156 {
4157   MagickCore::Image
4158     *newImage;
4159
4160   GetPPException;
4161   newImage=ShadowImage(constImage(),percent_opacity_, sigma_,x_, y_,
4162     exceptionInfo);
4163   replaceImage(newImage);
4164   ThrowPPException;
4165 }
4166
4167 void Magick::Image::sharpen(const double radius_,const double sigma_)
4168 {
4169   MagickCore::Image
4170     *newImage;
4171
4172   GetPPException;
4173   newImage=SharpenImage(constImage(),radius_,sigma_,exceptionInfo);
4174   replaceImage(newImage);
4175   ThrowPPException;
4176 }
4177
4178 void Magick::Image::sharpenChannel(const ChannelType channel_,
4179   const double radius_,const double sigma_)
4180 {
4181   MagickCore::Image
4182     *newImage;
4183
4184   GetPPException;
4185   SetPPChannelMask(channel_);
4186   newImage=SharpenImage(constImage(),radius_,sigma_,exceptionInfo);
4187   RestorePPChannelMask;
4188   replaceImage(newImage);
4189   ThrowPPException;
4190 }
4191
4192 void Magick::Image::shave(const Geometry &geometry_)
4193 {
4194   MagickCore::Image
4195     *newImage;
4196
4197   RectangleInfo
4198     shaveInfo=geometry_;
4199
4200   GetPPException;
4201   newImage=ShaveImage(constImage(),&shaveInfo,exceptionInfo);
4202   replaceImage(newImage);
4203   ThrowPPException;
4204 }
4205
4206 void Magick::Image::shear(const double xShearAngle_,const double yShearAngle_)
4207 {
4208   MagickCore::Image
4209     *newImage;
4210
4211   GetPPException;
4212   newImage=ShearImage(constImage(),xShearAngle_,yShearAngle_,exceptionInfo);
4213   replaceImage(newImage);
4214   ThrowPPException;
4215 }
4216
4217 void Magick::Image::sigmoidalContrast(const size_t sharpen_,
4218   const double contrast,const double midpoint)
4219 {
4220   modifyImage();
4221   GetPPException;
4222   (void) SigmoidalContrastImage(image(),(MagickBooleanType) sharpen_,contrast,
4223     midpoint,exceptionInfo);
4224   ThrowPPException;
4225 }
4226
4227 std::string Magick::Image::signature(const bool force_) const
4228 {
4229   return(_imgRef->signature());
4230 }
4231
4232 void Magick::Image::sketch(const double radius_,const double sigma_,
4233   const double angle_)
4234 {
4235   MagickCore::Image
4236     *newImage;
4237
4238   GetPPException;
4239   newImage=SketchImage(constImage(),radius_,sigma_,angle_,exceptionInfo);
4240   replaceImage(newImage);
4241   ThrowPPException;
4242 }
4243
4244 void Magick::Image::solarize(const double factor_)
4245 {
4246   modifyImage();
4247   GetPPException;
4248   SolarizeImage(image(),factor_,exceptionInfo);
4249   ThrowPPException;
4250 }
4251
4252 void Magick::Image::sparseColor(const ChannelType channel_,
4253   const SparseColorMethod method_,const size_t numberArguments_,
4254   const double *arguments_)
4255 {
4256   MagickCore::Image
4257     *newImage;
4258
4259   GetPPException;
4260   SetPPChannelMask(channel_);
4261   newImage=SparseColorImage(constImage(),method_,numberArguments_,arguments_,
4262     exceptionInfo);
4263   RestorePPChannelMask;
4264   replaceImage(newImage);
4265   ThrowPPException;
4266 }
4267
4268 void Magick::Image::splice(const Geometry &geometry_)
4269 {
4270   MagickCore::Image
4271     *newImage;
4272
4273   RectangleInfo
4274     spliceInfo=geometry_;
4275
4276   GetPPException;
4277   newImage=SpliceImage(constImage(),&spliceInfo,exceptionInfo);
4278   replaceImage(newImage);
4279   ThrowPPException;
4280 }
4281
4282 void Magick::Image::spread(const size_t amount_)
4283 {
4284   MagickCore::Image
4285     *newImage;
4286
4287   GetPPException;
4288   newImage=SpreadImage(constImage(),amount_,image()->interpolate,
4289     exceptionInfo);
4290   replaceImage(newImage);
4291   ThrowPPException;
4292 }
4293
4294 Magick::ImageStatistics Magick::Image::statistics()
4295 {
4296   return(ImageStatistics(constImage()));
4297 }
4298
4299 void Magick::Image::stegano(const Image &watermark_)
4300 {
4301   MagickCore::Image
4302     *newImage;
4303
4304   GetPPException;
4305   newImage=SteganoImage(constImage(),watermark_.constImage(),exceptionInfo);
4306   replaceImage(newImage);
4307   ThrowPPException;
4308 }
4309
4310 void Magick::Image::stereo(const Image &rightImage_)
4311 {
4312   MagickCore::Image
4313     *newImage;
4314
4315   GetPPException;
4316   newImage=StereoImage(constImage(),rightImage_.constImage(),exceptionInfo);
4317   replaceImage(newImage);
4318   ThrowPPException;
4319 }
4320
4321 void Magick::Image::strip(void)
4322 {
4323   modifyImage();
4324   GetPPException;
4325   StripImage(image(),exceptionInfo);
4326   ThrowPPException;
4327 }
4328
4329 Magick::Image Magick::Image::subImageSearch(const Image &reference_,
4330   const MetricType metric_,Geometry *offset_,double *similarityMetric_,
4331   const double similarityThreshold)
4332 {
4333   MagickCore::Image
4334     *newImage;
4335
4336   RectangleInfo
4337     offset;
4338
4339   GetPPException;
4340   newImage=SimilarityImage(image(),reference_.constImage(),metric_,
4341     similarityThreshold,&offset,similarityMetric_,exceptionInfo);
4342   ThrowPPException;
4343   if (offset_ != (Geometry *) NULL)
4344     *offset_=offset;
4345   if (newImage == (MagickCore::Image *) NULL)
4346     return(Magick::Image());
4347   else
4348     return(Magick::Image(newImage));
4349 }
4350
4351 void Magick::Image::swirl(const double degrees_)
4352 {
4353   MagickCore::Image
4354     *newImage;
4355
4356   GetPPException;
4357   newImage=SwirlImage(constImage(),degrees_,image()->interpolate,
4358     exceptionInfo);
4359   replaceImage(newImage);
4360   ThrowPPException;
4361 }
4362
4363 void Magick::Image::syncPixels(void)
4364 {
4365   GetPPException;
4366   (void) (*SyncAuthenticPixels)(image(),exceptionInfo);
4367   ThrowPPException;
4368 }
4369
4370 void Magick::Image::texture(const Image &texture_)
4371 {
4372   modifyImage();
4373   GetPPException;
4374   TextureImage(image(),texture_.constImage(),exceptionInfo);
4375   ThrowPPException;
4376 }
4377
4378 void Magick::Image::threshold(const double threshold_)
4379 {
4380   modifyImage();
4381   GetPPException;
4382   BilevelImage(image(),threshold_,exceptionInfo);
4383   ThrowPPException;
4384 }
4385
4386 void Magick::Image::thumbnail(const Geometry &geometry_)
4387 {
4388   MagickCore::Image
4389     *newImage;
4390
4391   size_t
4392     height=rows(),
4393     width=columns();
4394
4395   ssize_t
4396     x=0,
4397     y=0;
4398
4399   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4400     &height);
4401
4402   GetPPException;
4403   newImage=ThumbnailImage(constImage(),width,height,exceptionInfo);
4404   replaceImage(newImage);
4405   ThrowPPException;
4406 }
4407
4408 void Magick::Image::tint(const std::string opacity_)
4409 {
4410   MagickCore::Image
4411     *newImage;
4412
4413   PixelInfo
4414     color;
4415
4416   GetPPException;
4417   color=static_cast<PixelInfo>(constOptions()->fillColor());
4418   newImage=TintImage(constImage(),opacity_.c_str(),&color,exceptionInfo);
4419   replaceImage(newImage);
4420   ThrowPPException;
4421 }
4422
4423 void Magick::Image::transform(const Geometry &imageGeometry_)
4424 {
4425   modifyImage();
4426   GetPPException;
4427   TransformImage(&(image()),0,std::string(imageGeometry_).c_str(),
4428     exceptionInfo);
4429   ThrowPPException;
4430 }
4431
4432 void Magick::Image::transform(const Geometry &imageGeometry_,
4433   const Geometry &cropGeometry_)
4434 {
4435   modifyImage();
4436   GetPPException;
4437   TransformImage(&(image()),std::string(cropGeometry_).c_str(),std::string(
4438     imageGeometry_).c_str(), exceptionInfo);
4439   ThrowPPException;
4440 }
4441
4442 void Magick::Image::transformOrigin(const double x_,const double y_)
4443 {
4444   modifyImage();
4445   options()->transformOrigin(x_,y_);
4446 }
4447
4448 void Magick::Image::transformReset(void)
4449 {
4450   modifyImage();
4451   options()->transformReset();
4452 }
4453
4454 void Magick::Image::transformScale(const double sx_,const double sy_)
4455 {
4456   modifyImage();
4457   options()->transformScale(sx_,sy_);
4458 }
4459
4460 void Magick::Image::transparent(const Color &color_)
4461 {
4462   PixelInfo
4463     target;
4464
4465   std::string
4466     color;
4467
4468   if (!color_.isValid())
4469     throwExceptionExplicit(OptionError,"Color argument is invalid");
4470
4471   color=color_;
4472   GetPPException;
4473   (void) QueryColorCompliance(color.c_str(),AllCompliance,&target,
4474     exceptionInfo);
4475   modifyImage();
4476   TransparentPaintImage(image(),&target,TransparentAlpha,MagickFalse,
4477     exceptionInfo);
4478   ThrowPPException;
4479 }
4480
4481 void Magick::Image::transparentChroma(const Color &colorLow_,
4482   const Color &colorHigh_)
4483 {
4484   std::string
4485     colorHigh,
4486     colorLow;
4487
4488   PixelInfo
4489     targetHigh,
4490     targetLow;
4491
4492   if (!colorLow_.isValid() || !colorHigh_.isValid())
4493     throwExceptionExplicit(OptionError,"Color argument is invalid");
4494
4495   colorLow=colorLow_;
4496   colorHigh=colorHigh_;
4497
4498   GetPPException;
4499   (void) QueryColorCompliance(colorLow.c_str(),AllCompliance,&targetLow,
4500     exceptionInfo);
4501   (void) QueryColorCompliance(colorHigh.c_str(),AllCompliance,&targetHigh,
4502     exceptionInfo);
4503   modifyImage();
4504   TransparentPaintImageChroma(image(),&targetLow,&targetHigh,TransparentAlpha,
4505     MagickFalse,exceptionInfo);
4506   ThrowPPException;
4507 }
4508
4509 void Magick::Image::transpose(void)
4510 {
4511   MagickCore::Image
4512     *newImage;
4513
4514   GetPPException;
4515   newImage=TransposeImage(constImage(),exceptionInfo);
4516   replaceImage(newImage);
4517   ThrowPPException;
4518 }
4519
4520 void Magick::Image::transverse(void)
4521 {
4522   MagickCore::Image
4523     *newImage;
4524
4525   GetPPException;
4526   newImage=TransverseImage(constImage(),exceptionInfo);
4527   replaceImage(newImage);
4528   ThrowPPException;
4529 }
4530
4531 void Magick::Image::trim(void)
4532 {
4533   MagickCore::Image
4534     *newImage;
4535
4536   GetPPException;
4537   newImage=TrimImage(constImage(),exceptionInfo);
4538   replaceImage(newImage);
4539   ThrowPPException;
4540 }
4541
4542 Magick::Image Magick::Image::uniqueColors(void)
4543 {
4544   MagickCore::Image
4545     *image;
4546
4547   GetPPException;
4548   image=UniqueImageColors(constImage(),exceptionInfo);
4549   ThrowPPException;
4550   if (image == (MagickCore::Image *) NULL)
4551     return(Magick::Image());
4552   else
4553     return(Magick::Image(image));
4554 }
4555
4556 void Magick::Image::unsharpmask(const double radius_,const double sigma_,
4557   const double amount_,const double threshold_)
4558 {
4559   MagickCore::Image
4560     *newImage;
4561
4562   GetPPException;
4563   newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_,
4564     exceptionInfo);
4565   replaceImage(newImage);
4566   ThrowPPException;
4567 }
4568
4569 void Magick::Image::unsharpmaskChannel(const ChannelType channel_,
4570   const double radius_,const double sigma_,const double amount_,
4571   const double threshold_)
4572 {
4573   MagickCore::Image
4574     *newImage;
4575
4576   GetPPException;
4577   SetPPChannelMask(channel_);
4578   newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_,
4579     exceptionInfo);
4580   RestorePPChannelMask;
4581   replaceImage(newImage);
4582   ThrowPPException;
4583 }
4584
4585 void Magick::Image::vignette(const double radius_,const double sigma_,
4586   const ssize_t x_,const ssize_t y_)
4587 {
4588   MagickCore::Image
4589     *newImage;
4590
4591   GetPPException;
4592   newImage=VignetteImage(constImage(),radius_,sigma_,x_,y_,exceptionInfo);
4593   replaceImage(newImage);
4594   ThrowPPException;
4595 }
4596
4597 void Magick::Image::wave(const double amplitude_,const double wavelength_)
4598 {
4599   MagickCore::Image
4600     *newImage;
4601
4602   GetPPException;
4603   newImage=WaveImage(constImage(),amplitude_,wavelength_,image()->interpolate,
4604     exceptionInfo);
4605   replaceImage(newImage);
4606   ThrowPPException;
4607 }
4608
4609 void Magick::Image::whiteThreshold(const std::string &threshold_)
4610 {
4611   modifyImage();
4612   GetPPException;
4613   WhiteThresholdImage(image(),threshold_.c_str(),exceptionInfo);
4614   ThrowPPException;
4615 }
4616
4617 void Magick::Image::whiteThresholdChannel(const ChannelType channel_,
4618   const std::string &threshold_)
4619 {
4620   modifyImage();
4621   GetPPException;
4622   SetPPChannelMask(channel_);
4623   WhiteThresholdImage(image(),threshold_.c_str(),exceptionInfo);
4624   RestorePPChannelMask;
4625   ThrowPPException;
4626 }
4627
4628 void Magick::Image::write(Blob *blob_)
4629 {
4630   size_t
4631     length=0;
4632
4633   void
4634     *data;
4635
4636   modifyImage();
4637   GetPPException;
4638   data=ImagesToBlob(constImageInfo(),image(),&length,exceptionInfo);
4639   if (length > 0)
4640     blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4641   ThrowPPException;
4642 }
4643
4644 void Magick::Image::write(Blob *blob_,const std::string &magick_)
4645 {
4646   size_t
4647     length=0;
4648
4649   void
4650     *data;
4651
4652   modifyImage();
4653   magick(magick_);
4654   GetPPException;
4655   data=ImagesToBlob(constImageInfo(),image(),&length,exceptionInfo);
4656   if (length > 0)
4657     blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4658   ThrowPPException;
4659 }
4660
4661 void Magick::Image::write(Blob *blob_,const std::string &magick_,
4662   const size_t depth_)
4663 {
4664   size_t
4665     length=0;
4666
4667   void
4668     *data;
4669
4670   modifyImage();
4671   magick(magick_);
4672   depth(depth_);
4673   GetPPException;
4674   data=ImagesToBlob(constImageInfo(),image(),&length,exceptionInfo);
4675   if (length > 0)
4676     blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4677   ThrowPPException;
4678 }
4679
4680 void Magick::Image::write(const ssize_t x_,const ssize_t y_,
4681   const size_t columns_,const size_t rows_,const std::string &map_,
4682   const StorageType type_,void *pixels_)
4683 {
4684   GetPPException;
4685   ExportImagePixels(image(),x_,y_,columns_,rows_,map_.c_str(),type_,pixels_,
4686     exceptionInfo);
4687   ThrowPPException;
4688 }
4689
4690 void Magick::Image::write(const std::string &imageSpec_)
4691 {
4692   modifyImage();
4693   fileName(imageSpec_);
4694   GetPPException;
4695   WriteImage(constImageInfo(),image(),exceptionInfo);
4696   ThrowPPException;
4697 }
4698
4699 void Magick::Image::writePixels(const Magick::QuantumType quantum_,
4700   unsigned char *destination_)
4701 {
4702   QuantumInfo
4703     *quantum_info;
4704
4705   quantum_info=AcquireQuantumInfo(imageInfo(),image());
4706   GetPPException;
4707   ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4708     quantum_,destination_, exceptionInfo);
4709   quantum_info=DestroyQuantumInfo(quantum_info);
4710   ThrowPPException;
4711 }
4712
4713 void Magick::Image::zoom(const Geometry &geometry_)
4714 {
4715   MagickCore::Image
4716     *newImage;
4717
4718   size_t
4719     height=rows(),
4720     width=columns();
4721
4722   ssize_t
4723     x=0,
4724     y=0;
4725
4726   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4727     &height);
4728
4729   GetPPException;
4730   newImage=ResizeImage(constImage(),width,height,image()->filter,exceptionInfo);
4731   replaceImage(newImage);
4732   ThrowPPException;
4733 }
4734
4735 Magick::Image::Image(MagickCore::Image *image_)
4736   : _imgRef(new ImageRef(image_))
4737 {
4738 }
4739
4740 MagickCore::Image *&Magick::Image::image(void)
4741 {
4742   return(_imgRef->image());
4743 }
4744
4745 const MagickCore::Image *Magick::Image::constImage(void) const
4746 {
4747   return(_imgRef->image());
4748 }
4749
4750 MagickCore::ImageInfo *Magick::Image::imageInfo(void)
4751 {
4752   return(_imgRef->options()->imageInfo());
4753 }
4754
4755 const MagickCore::ImageInfo *Magick::Image::constImageInfo(void) const
4756 {
4757   return(_imgRef->options()->imageInfo());
4758 }
4759
4760 Magick::Options *Magick::Image::options(void)
4761 {
4762   return(_imgRef->options());
4763 }
4764
4765 const Magick::Options *Magick::Image::constOptions(void) const
4766 {
4767   return(_imgRef->options());
4768 }
4769
4770 MagickCore::QuantizeInfo *Magick::Image::quantizeInfo(void)
4771 {
4772   return(_imgRef->options()->quantizeInfo());
4773 }
4774
4775 const MagickCore::QuantizeInfo *Magick::Image::constQuantizeInfo(void) const
4776 {
4777   return(_imgRef->options()->quantizeInfo());
4778 }
4779
4780 void Magick::Image::modifyImage(void)
4781 {
4782   if (_imgRef->isOwner())
4783     return;
4784
4785   GetPPException;
4786   replaceImage(CloneImage(image(),0,0,MagickTrue,exceptionInfo));
4787   ThrowPPException;
4788 }
4789
4790 MagickCore::Image *Magick::Image::replaceImage(MagickCore::Image *replacement_)
4791 {
4792   MagickCore::Image
4793     *image;
4794
4795   if (replacement_)
4796     image=replacement_;
4797   else
4798     {
4799       GetPPException;
4800       image=AcquireImage(constImageInfo(),exceptionInfo);
4801       ThrowPPException;
4802     }
4803
4804   // We can replace the image if we own it.
4805   if (!_imgRef->replaceImage(image))
4806     {
4807       // We don't own the image, dereference and replace with new reference
4808       if (_imgRef->decrease() == 0)
4809         delete _imgRef;
4810
4811       _imgRef=new ImageRef(image,constOptions());
4812     }
4813
4814   return(image);
4815 }
4816
4817 void Magick::Image::read(MagickCore::Image *image,
4818   MagickCore::ExceptionInfo *exceptionInfo)
4819 {
4820   // Ensure that multiple image frames were not read.
4821   if (image != (MagickCore::Image *) NULL &&
4822       image->next != (MagickCore::Image *) NULL)
4823     {
4824       MagickCore::Image
4825         *next;
4826
4827       // Destroy any extra image frames
4828       next=image->next;
4829       image->next=(MagickCore::Image *) NULL;
4830       next->previous=(MagickCore::Image *) NULL;
4831       DestroyImageList(next);
4832     }
4833   replaceImage(image);
4834   if (exceptionInfo->severity == MagickCore::UndefinedException &&
4835       image == (MagickCore::Image *) NULL)
4836     {
4837       (void) MagickCore::DestroyExceptionInfo(exceptionInfo);
4838       throwExceptionExplicit(ImageWarning,"No image was loaded.");
4839     }
4840   ThrowPPException;
4841 }
4842
4843 void Magick::Image::floodFill(const ssize_t x_,const ssize_t y_,
4844   const Magick::Image *fillPattern_,const Magick::Color &fill_,
4845   const MagickCore::PixelInfo *target_,const bool invert_)
4846 {
4847   Magick::Color
4848     fillColor;
4849
4850   MagickCore::Image
4851     *fillPattern;
4852
4853   // Set drawing fill pattern or fill color
4854   fillColor=options()->fillColor();
4855   fillPattern=(MagickCore::Image *)NULL;
4856   if (options()->fillPattern() != (MagickCore::Image *)NULL)
4857     {
4858       GetPPException;
4859       fillPattern=CloneImage(options()->fillPattern(),0,0,MagickTrue,
4860         exceptionInfo);
4861       ThrowPPException;
4862     }
4863
4864   if (fillPattern_ == (Magick::Image *)NULL)
4865     {
4866       options()->fillPattern((MagickCore::Image *)NULL);
4867       options()->fillColor(fill_);
4868     }
4869   else
4870     options()->fillPattern(fillPattern_->constImage());
4871
4872   GetPPException;
4873   (void) FloodfillPaintImage(image(),options()->drawInfo(),
4874     target_,static_cast<ssize_t>(x_),static_cast<ssize_t>(y_),
4875     (MagickBooleanType) invert_,exceptionInfo);
4876
4877   options()->fillColor(fillColor);
4878   options()->fillPattern(fillPattern);
4879   ThrowPPException;
4880 }