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