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