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