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