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