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