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