]> granicus.if.org Git - imagemagick/blob - Magick++/lib/Image.cpp
(no commit message)
[imagemagick] / Magick++ / lib / Image.cpp
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4 //
5 // Implementation of Image
6 //
7
8 #define MAGICKCORE_IMPLEMENTATION  1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
10
11 #include "Magick++/Include.h"
12 #include <cstdlib>
13 #include <string>
14 #include <string.h>
15 #include <errno.h>
16 #include <math.h>
17
18 using namespace std;
19
20 #include "Magick++/Image.h"
21 #include "Magick++/Functions.h"
22 #include "Magick++/Pixels.h"
23 #include "Magick++/Options.h"
24 #include "Magick++/ImageRef.h"
25
26 #define AbsoluteValue(x)  ((x) < 0 ? -(x) : (x))
27 #define MagickPI  3.14159265358979323846264338327950288419716939937510
28 #define DegreesToRadians(x)  (MagickPI*(x)/180.0)
29
30 MagickPPExport const char *Magick::borderGeometryDefault="6x6+0+0";
31 MagickPPExport const char *Magick::frameGeometryDefault="25x25+6+6";
32 MagickPPExport const char *Magick::raiseGeometryDefault="6x6+0+0";
33
34 MagickPPExport int Magick::operator == (const Magick::Image &left_,
35   const Magick::Image &right_)
36 {
37   // If image pixels and signature are the same, then the image is identical
38   return((left_.rows() == right_.rows()) &&
39     (left_.columns() == right_.columns()) &&
40     (left_.signature() == right_.signature()));
41 }
42
43 MagickPPExport int Magick::operator != (const Magick::Image &left_,
44   const Magick::Image &right_)
45 {
46   return(!(left_ == right_));
47 }
48
49 MagickPPExport int Magick::operator > (const Magick::Image &left_,
50   const Magick::Image &right_)
51 {
52   return(!(left_ < right_) && (left_ != right_));
53 }
54
55 MagickPPExport int Magick::operator < (const Magick::Image &left_,
56   const Magick::Image &right_)
57 {
58   // If image pixels are less, then image is smaller
59   return((left_.rows() * left_.columns()) <
60     (right_.rows() * right_.columns()));
61 }
62
63 MagickPPExport int Magick::operator >= (const Magick::Image &left_,
64   const Magick::Image &right_)
65 {
66   return((left_ > right_) || (left_ == right_));
67 }
68
69 MagickPPExport int Magick::operator <= (const Magick::Image &left_,
70   const Magick::Image &right_)
71 {
72   return((left_ < right_) || ( left_ == right_));
73 }
74
75 Magick::Image::Image(void)
76   : _imgRef(new ImageRef)
77 {
78 }
79
80 Magick::Image::Image(const Blob &blob_)
81   : _imgRef(new ImageRef)
82 {
83   try
84   {
85     // Initialize, Allocate and Read images
86     read(blob_);
87   }
88   catch(const Warning &/*warning_*/)
89   {
90     // FIXME: need a way to report warnings in constructor
91   }
92   catch (const Error &/*error_*/)
93   {
94     // Release resources
95     delete _imgRef;
96     throw;
97   }
98 }
99
100 Magick::Image::Image(const Blob &blob_,const Geometry &size_)
101   : _imgRef(new ImageRef)
102 {
103   try
104   {
105     // Read from Blob
106     read(blob_, size_);
107   }
108   catch(const Warning &/*warning_*/)
109   {
110     // FIXME: need a way to report warnings in constructor
111   }
112   catch(const Error &/*error_*/)
113   {
114     // Release resources
115     delete _imgRef;
116     throw;
117   }
118 }
119
120 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
121   const size_t depth_)
122   : _imgRef(new ImageRef)
123 {
124   try
125   {
126     // Read from Blob
127     read(blob_,size_,depth_);
128   }
129   catch(const Warning &/*warning_*/)
130   {
131     // FIXME: need a way to report warnings in constructor
132   }
133   catch(const Error &/*error_*/)
134   {
135     // Release resources
136     delete _imgRef;
137     throw;
138   }
139 }
140
141 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
142   const size_t depth_,const std::string &magick_)
143   : _imgRef(new ImageRef)
144 {
145   try
146   {
147     // Read from Blob
148     read(blob_,size_,depth_,magick_);
149   }
150   catch(const Warning &/*warning_*/)
151   {
152     // FIXME: need a way to report warnings in constructor
153   }
154   catch(const Error &/*error_*/)
155   {
156     // Release resources
157     delete _imgRef;
158     throw;
159   }
160 }
161
162 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
163   const std::string &magick_)
164   : _imgRef(new ImageRef)
165 {
166   try
167   {
168     // Read from Blob
169     read(blob_,size_,magick_);
170   }
171   catch(const Warning &/*warning_*/)
172   {
173     // FIXME: need a way to report warnings in constructor
174   }
175   catch(const Error &/*error_*/)
176   {
177     // Release resources
178     delete _imgRef;
179     throw;
180   }
181 }
182
183 Magick::Image::Image(const Geometry &size_,const Color &color_)
184   : _imgRef(new ImageRef)
185 {
186   // xc: prefix specifies an X11 color string
187   std::string imageSpec("xc:");
188   imageSpec+=color_;
189
190   try
191   {
192     // Set image size
193     size(size_);
194
195     // Initialize, Allocate and Read images
196     read(imageSpec);
197   }
198   catch(const Warning &/*warning_*/)
199   {
200     // FIXME: need a way to report warnings in constructor
201   }
202   catch(const Error & /*error_*/)
203   {
204     // Release resources
205     delete _imgRef;
206     throw;
207   }
208 }
209
210 Magick::Image::Image(const Image &image_)
211   : _imgRef(image_._imgRef)
212 {
213   Lock(&_imgRef->_mutexLock);
214
215   // Increase reference count
216   ++_imgRef->_refCount;
217 }
218
219 Magick::Image::Image(const size_t width_,const size_t height_,
220   const std::string &map_,const StorageType type_,const void *pixels_)
221   : _imgRef(new ImageRef)
222 {
223   try
224   {
225     read(width_,height_,map_.c_str(),type_,pixels_);
226   }
227   catch(const Warning &/*warning_*/)
228   {
229     // FIXME: need a way to report warnings in constructor
230   }
231   catch(const Error &/*error_*/)
232   {
233     // Release resources
234     delete _imgRef;
235     throw;
236   }
237 }
238
239 Magick::Image::Image(const std::string &imageSpec_)
240   : _imgRef(new ImageRef)
241 {
242   try
243   {
244     // Initialize, Allocate and Read images
245     read(imageSpec_);
246   }
247   catch(const Warning &/*warning_*/)
248   {
249     // FIXME: need a way to report warnings in constructor
250   }
251   catch(const Error &/*error_*/)
252   {
253     // Release resources
254     delete _imgRef;
255     throw;
256   }
257 }
258
259 Magick::Image::~Image()
260 {
261   bool
262     doDelete=false;
263
264   {
265     Lock(&_imgRef->_mutexLock);
266     if (--_imgRef->_refCount == 0)
267       doDelete=true;
268   }
269
270   if (doDelete)
271     delete _imgRef;
272
273   _imgRef=0;
274 }
275
276 Magick::Image& Magick::Image::operator=(const Magick::Image &image_)
277 {
278   if(this != &image_)
279     {
280       bool
281         doDelete=false;
282
283       {
284         Lock(&image_._imgRef->_mutexLock);
285         ++image_._imgRef->_refCount;
286       }
287
288       {
289         Lock(&_imgRef->_mutexLock);
290         if (--_imgRef->_refCount == 0)
291           doDelete=true;
292       }
293
294       if (doDelete)
295         {
296           // Delete old image reference with associated image and options.
297           delete _imgRef;
298           _imgRef=0;
299         }
300       // Use new image reference
301       _imgRef=image_._imgRef;
302     }
303
304   return(*this);
305 }
306
307 void Magick::Image::adjoin(const bool flag_)
308 {
309   modifyImage();
310   options()->adjoin(flag_);
311 }
312
313 bool Magick::Image::adjoin(void) const
314 {
315   return(constOptions()->adjoin());
316 }
317
318 void Magick::Image::alpha(const bool matteFlag_)
319 {
320   modifyImage();
321
322   // If matte channel is requested, but image doesn't already have a
323   // matte channel, then create an opaque matte channel.  Likewise, if
324   // the image already has a matte channel but a matte channel is not
325   // desired, then set the matte channel to opaque.
326   GetPPException;
327   if ((matteFlag_ && !constImage()->alpha_trait) ||
328       (constImage()->alpha_trait && !matteFlag_))
329     SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo);
330   ThrowPPException;
331
332   image()->alpha_trait=matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait;
333 }
334
335 bool Magick::Image::alpha(void) const
336 {
337   if (constImage()->alpha_trait == BlendPixelTrait)
338     return(true);
339   else
340     return(false);
341 }
342
343 void Magick::Image::alphaColor(const Color &alphaColor_)
344 {
345   modifyImage();
346
347   if (alphaColor_.isValid())
348     {
349       image()->matte_color=alphaColor_;
350       options()->matteColor(alphaColor_);
351     }
352   else
353     {
354       // Set to default matte color
355       Color tmpColor("#BDBDBD");
356       image()->matte_color=tmpColor;
357       options()->matteColor(tmpColor);
358     }
359 }
360
361 Magick::Color Magick::Image::alphaColor(void) const
362 {
363   return(Color(ClampToQuantum(constImage()->matte_color.red),
364     ClampToQuantum(constImage()->matte_color.green),
365     ClampToQuantum(constImage()->matte_color.blue)));
366 }
367
368 void Magick::Image::antiAlias(const bool flag_)
369 {
370   modifyImage();
371   options()->antiAlias(static_cast<size_t>(flag_));
372 }
373
374 bool Magick::Image::antiAlias(void)
375 {
376   return(static_cast<bool>(options()->antiAlias()));
377 }
378
379 void Magick::Image::animationDelay(const size_t delay_)
380 {
381   modifyImage();
382   image()->delay=delay_;
383 }
384
385 size_t Magick::Image::animationDelay(void) const
386 {
387   return(constImage()->delay);
388 }
389
390 void Magick::Image::animationIterations(const size_t iterations_)
391 {
392   modifyImage();
393   image()->iterations=iterations_;
394 }
395
396 size_t Magick::Image::animationIterations(void) const
397 {
398   return(constImage()->iterations);
399 }
400
401 void Magick::Image::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   (void) 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   if (constOptions()->type() != UndefinedType)
1559     return(constOptions()->type());
1560   else if (constImage()->type != UndefinedType)
1561     return(constImage()->type);
1562   else
1563     return(determineType());
1564 }
1565
1566 void Magick::Image::type(const Magick::ImageType type_)
1567 {
1568   modifyImage();
1569   options()->type(type_);
1570   GetPPException;
1571   SetImageType(image(),type_,&exceptionInfo);
1572   ThrowPPException;
1573 }
1574
1575 void Magick::Image::verbose(const bool verboseFlag_)
1576 {
1577   modifyImage();
1578   options()->verbose(verboseFlag_);
1579 }
1580
1581 bool Magick::Image::verbose(void) const
1582 {
1583   return(constOptions()->verbose());
1584 }
1585
1586 void Magick::Image::view(const std::string &view_)
1587 {
1588   modifyImage();
1589   options()->view(view_);
1590 }
1591
1592 std::string Magick::Image::view(void) const
1593 {
1594   return(constOptions()->view());
1595 }
1596
1597 void Magick::Image::virtualPixelMethod(
1598   const VirtualPixelMethod virtualPixelMethod_)
1599 {
1600   modifyImage();
1601   GetPPException;
1602   SetImageVirtualPixelMethod(image(),virtualPixelMethod_,&exceptionInfo);
1603   ThrowPPException;
1604 }
1605
1606 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod(void) const
1607 {
1608   return(GetImageVirtualPixelMethod(constImage()));
1609 }
1610
1611 void Magick::Image::x11Display(const std::string &display_)
1612 {
1613   modifyImage();
1614   options()->x11Display(display_);
1615 }
1616
1617 std::string Magick::Image::x11Display(void) const
1618 {
1619   return(constOptions()->x11Display());
1620 }
1621
1622 double Magick::Image::xResolution(void) const
1623 {
1624   return(constImage()->resolution.x);
1625 }
1626
1627 double Magick::Image::yResolution(void) const
1628 {
1629   return(constImage()->resolution.y);
1630 }
1631
1632 void Magick::Image::adaptiveBlur(const double radius_,const double sigma_)
1633 {
1634   MagickCore::Image
1635     *newImage;
1636
1637   GetPPException;
1638   newImage=AdaptiveBlurImage(constImage(),radius_,sigma_,&exceptionInfo);
1639   replaceImage(newImage);
1640   ThrowPPException;
1641 }
1642
1643 void Magick::Image::adaptiveResize(const Geometry &geometry_)
1644 {
1645   MagickCore::Image
1646     *newImage;
1647
1648   size_t
1649     height=rows(),
1650     width=columns();
1651
1652   ssize_t
1653     x=0,
1654     y=0;
1655
1656   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
1657     &height);
1658
1659   GetPPException;
1660   newImage=AdaptiveResizeImage(constImage(),width,height,&exceptionInfo);
1661   replaceImage(newImage);
1662   ThrowPPException;
1663 }
1664
1665 void Magick::Image::adaptiveSharpen(const double radius_,const double sigma_)
1666 {
1667   MagickCore::Image
1668     *newImage;
1669
1670   GetPPException;
1671   newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,&exceptionInfo);
1672   replaceImage(newImage);
1673   ThrowPPException;
1674 }
1675
1676 void Magick::Image::adaptiveSharpenChannel(const ChannelType channel_,
1677   const double radius_,const double sigma_ )
1678 {
1679   MagickCore::Image
1680     *newImage;
1681
1682   GetPPException;
1683   SetPPChannelMask(channel_);
1684   newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,&exceptionInfo);
1685   RestorePPChannelMask;
1686   replaceImage(newImage);
1687   ThrowPPException;
1688 }
1689
1690 void Magick::Image::adaptiveThreshold(const size_t width_,const size_t height_,
1691   const ssize_t offset_)
1692 {
1693
1694   MagickCore::Image
1695     *newImage;
1696
1697   GetPPException;
1698   newImage=AdaptiveThresholdImage(constImage(),width_,height_,offset_,
1699     &exceptionInfo);
1700   replaceImage(newImage);
1701   ThrowPPException;
1702 }
1703
1704 void Magick::Image::addNoise(const NoiseType noiseType_)
1705 {
1706   MagickCore::Image
1707     *newImage;
1708
1709   GetPPException;
1710   newImage=AddNoiseImage(constImage(),noiseType_,1.0,&exceptionInfo);
1711   replaceImage(newImage);
1712   ThrowPPException;
1713 }
1714
1715 void Magick::Image::addNoiseChannel(const ChannelType channel_,
1716   const NoiseType noiseType_)
1717 {
1718   MagickCore::Image
1719     *newImage;
1720
1721   GetPPException;
1722   SetPPChannelMask(channel_);
1723   newImage=AddNoiseImage(constImage(),noiseType_,1.0,&exceptionInfo);
1724   RestorePPChannelMask;
1725   replaceImage(newImage);
1726   ThrowPPException;
1727 }
1728
1729 void Magick::Image::affineTransform(const DrawableAffine &affine_)
1730 {
1731   AffineMatrix
1732     _affine;
1733
1734   MagickCore::Image
1735     *newImage;
1736
1737   _affine.sx=affine_.sx();
1738   _affine.sy=affine_.sy();
1739   _affine.rx=affine_.rx();
1740   _affine.ry=affine_.ry();
1741   _affine.tx=affine_.tx();
1742   _affine.ty=affine_.ty();
1743
1744   GetPPException;
1745   newImage=AffineTransformImage(constImage(),&_affine,&exceptionInfo);
1746   replaceImage(newImage);
1747   ThrowPPException;
1748 }
1749
1750 void Magick::Image::alpha(const unsigned int alpha_)
1751 {
1752   modifyImage();
1753   GetPPException;
1754   SetImageAlpha(image(),alpha_,&exceptionInfo);
1755   ThrowPPException;
1756 }
1757
1758 void Magick::Image::alphaChannel(AlphaChannelOption alphaOption_)
1759 {
1760   modifyImage();
1761   GetPPException;
1762   SetImageAlphaChannel(image(),alphaOption_,&exceptionInfo);
1763   ThrowPPException;
1764 }
1765
1766 void Magick::Image::alphaFloodfill(const Color &target_,
1767   const unsigned int alpha_,const ssize_t x_,const ssize_t y_,
1768   const Magick::PaintMethod method_)
1769 {
1770   PixelInfo
1771     target;
1772
1773   modifyImage();
1774   GetPixelInfo(constImage(),&target);
1775   target.red=static_cast<PixelInfo>(target_).red;
1776   target.green=static_cast<PixelInfo>(target_).green;
1777   target.blue=static_cast<PixelInfo>(target_).blue;
1778   target.alpha=alpha_;
1779   GetPPException;
1780   SetPPChannelMask(AlphaChannel);
1781   FloodfillPaintImage(image(),options()->drawInfo(),&target,x_,y_,
1782     method_ == FloodfillMethod ? MagickFalse : MagickTrue,&exceptionInfo);
1783   RestorePPChannelMask;
1784   ThrowPPException;
1785 }
1786
1787 void Magick::Image::annotate(const std::string &text_,
1788   const Geometry &location_)
1789 {
1790   annotate(text_,location_,NorthWestGravity,0.0);
1791 }
1792
1793 void Magick::Image::annotate(const std::string &text_,
1794   const Geometry &boundingArea_,const GravityType gravity_)
1795 {
1796   annotate(text_,boundingArea_,gravity_,0.0);
1797 }
1798
1799 void Magick::Image::annotate(const std::string &text_,
1800   const Geometry &boundingArea_,const GravityType gravity_,
1801   const double degrees_)
1802 {
1803   AffineMatrix
1804     oaffine;
1805
1806   char
1807     boundingArea[MaxTextExtent];
1808
1809   DrawInfo
1810     *drawInfo;
1811
1812   modifyImage();
1813
1814   drawInfo=options()->drawInfo();
1815   drawInfo->text=const_cast<char *>(text_.c_str());
1816   drawInfo->geometry=0;
1817
1818   if (boundingArea_.isValid())
1819     {
1820       if (boundingArea_.width() == 0 || boundingArea_.height() == 0)
1821         {
1822           FormatLocaleString(boundingArea,MaxTextExtent,"%+.20g%+.20g",
1823             (double) boundingArea_.xOff(),(double) boundingArea_.yOff());
1824         }
1825       else
1826         {
1827           (void) CopyMagickString(boundingArea,string(boundingArea_).c_str(),
1828             MaxTextExtent);
1829         }
1830       drawInfo->geometry=boundingArea;
1831     }
1832
1833   drawInfo->gravity=gravity_;
1834
1835   oaffine=drawInfo->affine;
1836   if (degrees_ != 0.0)
1837     {
1838        AffineMatrix
1839          affine,
1840          current;
1841
1842        affine.sx=1.0;
1843        affine.rx=0.0;
1844        affine.ry=0.0;
1845        affine.sy=1.0;
1846        affine.tx=0.0;
1847        affine.ty=0.0;
1848
1849        current=drawInfo->affine;
1850        affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
1851        affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
1852        affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
1853        affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
1854
1855        drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
1856        drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
1857        drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
1858        drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
1859        drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
1860          +current.tx;
1861     }
1862
1863   GetPPException;
1864   AnnotateImage(image(),drawInfo,&exceptionInfo);
1865
1866   // Restore original values
1867   drawInfo->affine=oaffine;
1868   drawInfo->text=0;
1869   drawInfo->geometry=0;
1870
1871   ThrowPPException;
1872 }
1873
1874 void Magick::Image::annotate(const std::string &text_,
1875   const GravityType gravity_)
1876 {
1877   DrawInfo
1878     *drawInfo;
1879
1880   modifyImage();
1881
1882   drawInfo=options()->drawInfo();
1883   drawInfo->text=const_cast<char *>(text_.c_str());
1884   drawInfo->gravity=gravity_;
1885
1886   GetPPException;
1887   AnnotateImage(image(),drawInfo,&exceptionInfo);
1888
1889   drawInfo->gravity=NorthWestGravity;
1890   drawInfo->text=0;
1891
1892   ThrowPPException;
1893 }
1894
1895 void Magick::Image::artifact(const std::string &name_,const std::string &value_)
1896 {
1897   modifyImage();
1898   (void) SetImageArtifact(image(),name_.c_str(),value_.c_str());
1899 }
1900
1901 std::string Magick::Image::artifact(const std::string &name_)
1902 {
1903   const char
1904     *value;
1905
1906   value=GetImageArtifact(constImage(),name_.c_str());
1907   if (value)
1908     return(std::string(value));
1909   return(std::string());
1910 }
1911
1912 void Magick::Image::attribute(const std::string name_,const std::string value_)
1913 {
1914   modifyImage();
1915   GetPPException;
1916   SetImageProperty(image(),name_.c_str(),value_.c_str(),&exceptionInfo);
1917   ThrowPPException;
1918 }
1919
1920 std::string Magick::Image::attribute(const std::string name_)
1921 {
1922   const char
1923     *value;
1924
1925   GetPPException;
1926   value=GetImageProperty(constImage(),name_.c_str(),&exceptionInfo);
1927   ThrowPPException;
1928
1929   if (value)
1930     return(std::string(value));
1931
1932   return(std::string()); // Intentionally no exception
1933 }
1934
1935 void Magick::Image::autoGamma(void)
1936 {
1937   modifyImage();
1938   GetPPException;
1939   (void) SyncImageSettings(imageInfo(),image(),&exceptionInfo);
1940   (void) AutoGammaImage(image(),&exceptionInfo);
1941   ThrowPPException;
1942 }
1943
1944 void Magick::Image::autoGammaChannel(const ChannelType channel_)
1945 {
1946   modifyImage();
1947   GetPPException;
1948   SetPPChannelMask(channel_);
1949   (void) SyncImageSettings(imageInfo(),image(),&exceptionInfo);
1950   (void) AutoGammaImage(image(),&exceptionInfo);
1951   RestorePPChannelMask;
1952   ThrowPPException;
1953 }
1954
1955 void Magick::Image::autoLevel(void)
1956 {
1957   modifyImage();
1958   GetPPException;
1959   (void) SyncImageSettings(imageInfo(),image(),&exceptionInfo);
1960   (void) AutoLevelImage(image(),&exceptionInfo);
1961   ThrowPPException;
1962 }
1963
1964 void Magick::Image::autoLevelChannel(const ChannelType channel_)
1965 {
1966   modifyImage();
1967   GetPPException;
1968   SetPPChannelMask(channel_);
1969   (void) SyncImageSettings(imageInfo(),image(),&exceptionInfo);
1970   (void) AutoLevelImage(image(),&exceptionInfo);
1971   RestorePPChannelMask;
1972   ThrowPPException;
1973 }
1974
1975 void Magick::Image::autoOrient(void)
1976 {
1977   MagickCore::Image
1978     *newImage;
1979
1980   if (image()->orientation == UndefinedOrientation ||
1981       image()->orientation == TopLeftOrientation)
1982     return;
1983
1984   GetPPException;
1985   (void) SyncImageSettings(imageInfo(),image(),&exceptionInfo);
1986   newImage=AutoOrientImage(constImage(),image()->orientation,&exceptionInfo);
1987   replaceImage(newImage);
1988   ThrowPPException;
1989 }
1990
1991 void Magick::Image::blackThreshold(const std::string &threshold_)
1992 {
1993   modifyImage();
1994   GetPPException;
1995   BlackThresholdImage(image(),threshold_.c_str(),&exceptionInfo);
1996   ThrowPPException;
1997 }
1998
1999 void Magick::Image::blackThresholdChannel(const ChannelType channel_,
2000   const std::string &threshold_)
2001 {
2002   modifyImage();
2003   GetPPException;
2004   SetPPChannelMask(channel_);
2005   BlackThresholdImage(image(),threshold_.c_str(),&exceptionInfo);
2006   RestorePPChannelMask;
2007   ThrowPPException;
2008 }
2009
2010 void Magick::Image::blueShift(const double factor_)
2011 {
2012   MagickCore::Image
2013     *newImage;
2014
2015   GetPPException;
2016   newImage=BlueShiftImage(constImage(),factor_,&exceptionInfo);
2017   replaceImage(newImage);
2018   ThrowPPException;
2019 }
2020
2021 void Magick::Image::blur(const double radius_,const double sigma_)
2022 {
2023   MagickCore::Image
2024     *newImage;
2025
2026   GetPPException;
2027   newImage=BlurImage(constImage(),radius_,sigma_,&exceptionInfo);
2028   replaceImage(newImage);
2029   ThrowPPException;
2030 }
2031
2032 void Magick::Image::blurChannel(const ChannelType channel_,
2033   const double radius_,const double sigma_)
2034 {
2035   MagickCore::Image
2036     *newImage;
2037
2038   GetPPException;
2039   SetPPChannelMask(channel_);
2040   newImage=BlurImage(constImage(),radius_,sigma_,&exceptionInfo);
2041   RestorePPChannelMask;
2042   replaceImage(newImage);
2043   ThrowPPException;
2044 }
2045
2046 void Magick::Image::border(const Geometry &geometry_)
2047 {
2048   MagickCore::Image
2049     *newImage;
2050
2051   RectangleInfo
2052     borderInfo=geometry_;
2053
2054   GetPPException;
2055   newImage=BorderImage(constImage(),&borderInfo,image()->compose,
2056     &exceptionInfo);
2057   replaceImage(newImage);
2058   ThrowPPException;
2059 }
2060
2061 void Magick::Image::brightnessContrast(const double brightness_,
2062   const double contrast_)
2063 {
2064   modifyImage();
2065   GetPPException;
2066   BrightnessContrastImage(image(),brightness_,contrast_,&exceptionInfo);
2067   ThrowPPException;
2068 }
2069
2070 void Magick::Image::brightnessContrastChannel(const ChannelType channel_,
2071   const double brightness_,const double contrast_)
2072 {
2073   modifyImage();
2074   GetPPException;
2075   SetPPChannelMask(channel_);
2076   BrightnessContrastImage(image(),brightness_,contrast_,&exceptionInfo);
2077   RestorePPChannelMask;
2078   ThrowPPException;
2079 }
2080
2081 void Magick::Image::cannyEdge(const double radius_,const double sigma_,
2082   const double lowerPercent_,const double upperPercent_)
2083 {
2084   MagickCore::Image
2085     *newImage;
2086
2087   modifyImage();
2088   GetPPException;
2089   newImage=CannyEdgeImage(constImage(),radius_,sigma_,lowerPercent_,
2090     upperPercent_,&exceptionInfo);
2091   replaceImage(newImage);
2092   ThrowPPException;
2093 }
2094
2095 void Magick::Image::channel(const ChannelType channel_)
2096 {
2097   MagickCore::Image
2098     *newImage;
2099
2100   GetPPException;
2101   newImage=SeparateImage(image(),channel_,&exceptionInfo);
2102   replaceImage(newImage);
2103   ThrowPPException;
2104 }
2105
2106 void Magick::Image::charcoal(const double radius_,const double sigma_)
2107 {
2108   MagickCore::Image
2109     *newImage;
2110
2111   GetPPException;
2112   newImage=CharcoalImage(image(),radius_,sigma_,&exceptionInfo);
2113   replaceImage(newImage);
2114   ThrowPPException;
2115 }
2116
2117 void Magick::Image::chop(const Geometry &geometry_)
2118 {
2119   MagickCore::Image
2120     *newImage;
2121
2122   RectangleInfo
2123     chopInfo=geometry_;
2124
2125   GetPPException;
2126   newImage=ChopImage(image(),&chopInfo,&exceptionInfo);
2127   replaceImage(newImage);
2128   ThrowPPException;
2129 }
2130
2131 void Magick::Image::chromaBluePrimary(const double x_,const double y_)
2132 {
2133   modifyImage();
2134   image()->chromaticity.blue_primary.x=x_;
2135   image()->chromaticity.blue_primary.y=y_;
2136 }
2137
2138 void Magick::Image::chromaBluePrimary(double *x_,double *y_) const
2139 {
2140   *x_=constImage()->chromaticity.blue_primary.x;
2141   *y_=constImage()->chromaticity.blue_primary.y;
2142 }
2143
2144 void Magick::Image::chromaGreenPrimary(const double x_,const double y_)
2145 {
2146   modifyImage();
2147   image()->chromaticity.green_primary.x=x_;
2148   image()->chromaticity.green_primary.y=y_;
2149 }
2150
2151 void Magick::Image::chromaGreenPrimary(double *x_,double *y_) const
2152 {
2153   *x_=constImage()->chromaticity.green_primary.x;
2154   *y_=constImage()->chromaticity.green_primary.y;
2155 }
2156
2157 void Magick::Image::chromaRedPrimary(const double x_,const double y_)
2158 {
2159   modifyImage();
2160   image()->chromaticity.red_primary.x=x_;
2161   image()->chromaticity.red_primary.y=y_;
2162 }
2163
2164 void Magick::Image::chromaRedPrimary(double *x_,double *y_) const
2165 {
2166   *x_=constImage()->chromaticity.red_primary.x;
2167   *y_=constImage()->chromaticity.red_primary.y;
2168 }
2169
2170 void Magick::Image::chromaWhitePoint(const double x_,const double y_)
2171 {
2172   modifyImage();
2173   image()->chromaticity.white_point.x=x_;
2174   image()->chromaticity.white_point.y=y_;
2175 }
2176
2177 void Magick::Image::chromaWhitePoint(double *x_,double *y_) const
2178 {
2179   *x_=constImage()->chromaticity.white_point.x;
2180   *y_=constImage()->chromaticity.white_point.y;
2181 }
2182
2183 void Magick::Image::cdl(const std::string &cdl_)
2184 {
2185   modifyImage();
2186   GetPPException;
2187   (void) ColorDecisionListImage(image(),cdl_.c_str(),&exceptionInfo);
2188   ThrowPPException;
2189 }
2190
2191 void Magick::Image::clamp(void)
2192 {
2193   modifyImage();
2194   GetPPException;
2195   ClampImage(image(),&exceptionInfo);
2196   ThrowPPException;
2197 }
2198
2199 void Magick::Image::clampChannel(const ChannelType channel_)
2200 {
2201   modifyImage();
2202   GetPPException;
2203   SetPPChannelMask(channel_);
2204   ClampImage(image(),&exceptionInfo);
2205   RestorePPChannelMask;
2206   ThrowPPException;
2207 }
2208
2209 void Magick::Image::clip(void)
2210 {
2211   modifyImage();
2212   GetPPException;
2213   ClipImage(image(),&exceptionInfo);
2214   ThrowPPException;
2215 }
2216
2217 void Magick::Image::clipPath(const std::string pathname_,const bool inside_)
2218 {
2219   modifyImage();
2220   GetPPException;
2221   ClipImagePath(image(),pathname_.c_str(),(MagickBooleanType) inside_,
2222     &exceptionInfo);
2223   ThrowPPException;
2224 }
2225
2226 void Magick::Image::clut(const Image &clutImage_,
2227   const PixelInterpolateMethod method)
2228 {
2229   modifyImage();
2230   GetPPException;
2231   ClutImage(image(),clutImage_.constImage(),method,&exceptionInfo);
2232   ThrowPPException;
2233 }
2234
2235 void Magick::Image::clutChannel(const ChannelType channel_,
2236   const Image &clutImage_,const PixelInterpolateMethod method)
2237 {
2238   modifyImage();
2239   GetPPException;
2240   SetPPChannelMask(channel_);
2241   ClutImage(image(),clutImage_.constImage(),method,&exceptionInfo);
2242   RestorePPChannelMask;
2243   ThrowPPException;
2244 }
2245
2246 void Magick::Image::colorize(const unsigned int alpha_,const Color &penColor_)
2247 {
2248   colorize(alpha_,alpha_,alpha_,penColor_);
2249 }
2250
2251 void Magick::Image::colorize(const unsigned int alphaRed_,
2252   const unsigned int alphaGreen_,const unsigned int alphaBlue_,
2253   const Color &penColor_)
2254 {
2255   char
2256     blend[MaxTextExtent];
2257
2258   MagickCore::Image
2259     *newImage;
2260
2261   PixelInfo
2262     pixel,
2263     target;
2264
2265   if (!penColor_.isValid())
2266     throwExceptionExplicit(OptionError,"Pen color argument is invalid");
2267
2268   FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,
2269     alphaBlue_);
2270
2271   GetPixelInfo(image(),&target);
2272   pixel=static_cast<PixelInfo>(penColor_);
2273   target.red=pixel.red;
2274   target.green=pixel.green;
2275   target.blue=pixel.blue;
2276   target.alpha=pixel.alpha;
2277   GetPPException;
2278   newImage=ColorizeImage(image(),blend,&target,&exceptionInfo);
2279   replaceImage(newImage);
2280   ThrowPPException;
2281 }
2282
2283 void Magick::Image::colorMap(const size_t index_,const Color &color_)
2284 {
2285   MagickCore::Image
2286     *imageptr;
2287
2288   imageptr=image();
2289
2290   if (index_ > (MaxColormapSize-1))
2291     throwExceptionExplicit(OptionError,
2292       "Colormap index must be less than MaxColormapSize");
2293
2294   if (!color_.isValid())
2295     throwExceptionExplicit(OptionError,"Color argument is invalid");
2296
2297   modifyImage();
2298
2299   // Ensure that colormap size is large enough
2300   if (colorMapSize() < (index_+1))
2301     colorMapSize(index_+1);
2302
2303   // Set color at index in colormap
2304   (imageptr->colormap)[index_]=color_;
2305 }
2306
2307 Magick::Color Magick::Image::colorMap(const size_t index_) const
2308 {
2309   if (!constImage()->colormap)
2310     {
2311       throwExceptionExplicit(OptionError,"Image does not contain a colormap");
2312       return(Color());
2313     }
2314
2315   if (index_ > constImage()->colors-1)
2316     throwExceptionExplicit(OptionError,"Index out of range");
2317
2318   return(Magick::Color((constImage()->colormap)[index_]));
2319 }
2320
2321 void Magick::Image::colorMatrix(const size_t order_,
2322   const double *color_matrix_)
2323 {
2324   KernelInfo
2325     *kernel_info;
2326
2327   GetPPException;
2328   kernel_info=AcquireKernelInfo((const char *) NULL);
2329   kernel_info->width=order_;
2330   kernel_info->height=order_;
2331   kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
2332     order_*sizeof(*kernel_info->values));
2333   if (kernel_info->values != (MagickRealType *) NULL)
2334     {
2335       MagickCore::Image
2336         *newImage;
2337
2338       for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
2339         kernel_info->values[i]=color_matrix_[i];
2340       newImage=ColorMatrixImage(image(),kernel_info,&exceptionInfo);
2341       replaceImage(newImage);
2342     }
2343   kernel_info=DestroyKernelInfo(kernel_info);
2344   ThrowPPException;
2345 }
2346
2347 bool Magick::Image::compare(const Image &reference_)
2348 {
2349   bool
2350     status;
2351
2352   Image
2353     ref=reference_;
2354
2355   GetPPException;
2356   modifyImage();
2357   ref.modifyImage();
2358   status=static_cast<bool>(IsImagesEqual(image(),ref.image(),&exceptionInfo));
2359   ThrowPPException;
2360   return(status);
2361 }
2362
2363 double Magick::Image::compare(const Image &reference_,const MetricType metric_)
2364 {
2365   double
2366     distortion=0.0;
2367
2368   GetPPException;
2369   GetImageDistortion(image(),reference_.constImage(),metric_,&distortion,
2370     &exceptionInfo);
2371   ThrowPPException;
2372   return(distortion);
2373 }
2374
2375 double Magick::Image::compareChannel(const ChannelType channel_,
2376   const Image &reference_,const MetricType metric_)
2377 {
2378   double
2379     distortion=0.0;
2380
2381   GetPPException;
2382   SetPPChannelMask(channel_);
2383   GetImageDistortion(image(),reference_.constImage(),metric_,&distortion,
2384     &exceptionInfo);
2385   RestorePPChannelMask;
2386   ThrowPPException;
2387   return(distortion);
2388 }
2389
2390 Magick::Image Magick::Image::compare(const Image &reference_,
2391   const MetricType metric_,double *distortion)
2392 {
2393   MagickCore::Image
2394     *newImage;
2395
2396   GetPPException;
2397   newImage=CompareImages(image(),reference_.constImage(),metric_,distortion,
2398     &exceptionInfo);
2399   ThrowPPException;
2400   if (newImage == (MagickCore::Image *) NULL)
2401     return(Magick::Image());
2402   else
2403     return(Magick::Image(newImage));
2404 }
2405
2406 Magick::Image Magick::Image::compareChannel(const ChannelType channel_,
2407   const Image &reference_,const MetricType metric_,double *distortion)
2408 {
2409   MagickCore::Image
2410     *newImage;
2411
2412   GetPPException;
2413   SetPPChannelMask(channel_);
2414   newImage=CompareImages(image(),reference_.constImage(),metric_,distortion,
2415     &exceptionInfo);
2416   RestorePPChannelMask;
2417   ThrowPPException;
2418   if (newImage == (MagickCore::Image *) NULL)
2419     return(Magick::Image());
2420   else
2421     return(Magick::Image(newImage));
2422 }
2423
2424 void Magick::Image::composite(const Image &compositeImage_,
2425   const Geometry &offset_,const CompositeOperator compose_)
2426 {
2427   size_t
2428     height=rows(),
2429     width=columns();
2430
2431   ssize_t
2432     x=offset_.xOff(),
2433     y=offset_.yOff();
2434
2435   ParseMetaGeometry(static_cast<std::string>(offset_).c_str(),&x,&y,&width,
2436     &height);
2437
2438   modifyImage();
2439   GetPPException;
2440   CompositeImage(image(),compositeImage_.constImage(),compose_,MagickFalse,
2441     x,y,&exceptionInfo);
2442   ThrowPPException;
2443 }
2444
2445 void Magick::Image::composite(const Image &compositeImage_,
2446   const GravityType gravity_,const CompositeOperator compose_)
2447 {
2448   RectangleInfo
2449     geometry;
2450
2451   modifyImage();
2452   SetGeometry(compositeImage_.constImage(),&geometry);
2453   GravityAdjustGeometry(columns(),rows(),gravity_,&geometry);
2454
2455   GetPPException;
2456   CompositeImage(image(),compositeImage_.constImage(),compose_,MagickFalse,
2457     geometry.x,geometry.y,&exceptionInfo);
2458   ThrowPPException;
2459 }
2460
2461 void Magick::Image::composite(const Image &compositeImage_,
2462   const ssize_t xOffset_,const ssize_t yOffset_,
2463   const CompositeOperator compose_)
2464 {
2465   // Image supplied as compositeImage is composited with current image and
2466   // results in updating current image.
2467   modifyImage();
2468   GetPPException;
2469   CompositeImage(image(),compositeImage_.constImage(),compose_,MagickFalse,
2470     xOffset_,yOffset_,&exceptionInfo);
2471   ThrowPPException;
2472 }
2473
2474 void Magick::Image::contrast(const size_t sharpen_)
2475 {
2476   modifyImage();
2477   GetPPException;
2478   ContrastImage(image(),(MagickBooleanType) sharpen_,&exceptionInfo);
2479   ThrowPPException;
2480 }
2481
2482 void Magick::Image::contrastStretch(const double blackPoint_,
2483   const double whitePoint_)
2484 {
2485   modifyImage();
2486   GetPPException;
2487   ContrastStretchImage(image(),blackPoint_,whitePoint_,&exceptionInfo);
2488   ThrowPPException;
2489 }
2490
2491 void Magick::Image::contrastStretchChannel(const ChannelType channel_,
2492   const double blackPoint_,const double whitePoint_)
2493 {
2494   modifyImage();
2495   GetPPException;
2496   SetPPChannelMask(channel_);
2497   ContrastStretchImage(image(),blackPoint_,whitePoint_,&exceptionInfo);
2498   RestorePPChannelMask;
2499   ThrowPPException;
2500 }
2501
2502 void Magick::Image::convolve(const size_t order_,const double *kernel_)
2503 {
2504   KernelInfo
2505     *kernel_info;
2506
2507   GetPPException;
2508   kernel_info=AcquireKernelInfo((const char *) NULL);
2509   kernel_info->width=order_;
2510   kernel_info->height=order_;
2511   kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
2512     order_*sizeof(*kernel_info->values));
2513   if (kernel_info->values != (MagickRealType *) NULL)
2514     {
2515       MagickCore::Image
2516         *newImage;
2517
2518       for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
2519         kernel_info->values[i]=kernel_[i];
2520       newImage=ConvolveImage(image(),kernel_info,&exceptionInfo);
2521       replaceImage(newImage);
2522     }
2523   kernel_info=DestroyKernelInfo(kernel_info);
2524   ThrowPPException;
2525 }
2526
2527 void Magick::Image::crop(const Geometry &geometry_)
2528 {
2529   MagickCore::Image
2530     *newImage;
2531
2532   RectangleInfo
2533     cropInfo=geometry_;
2534
2535   GetPPException;
2536   newImage=CropImage(constImage(),&cropInfo,&exceptionInfo);
2537   replaceImage(newImage);
2538   ThrowPPException;
2539 }
2540
2541 void Magick::Image::cycleColormap(const ssize_t amount_)
2542 {
2543   modifyImage();
2544   GetPPException;
2545   CycleColormapImage(image(),amount_,&exceptionInfo);
2546   ThrowPPException;
2547 }
2548
2549 void Magick::Image::decipher(const std::string &passphrase_)
2550 {
2551   modifyImage();
2552   GetPPException;
2553   DecipherImage(image(),passphrase_.c_str(),&exceptionInfo);
2554   ThrowPPException;
2555 }
2556
2557 void Magick::Image::defineSet(const std::string &magick_,
2558   const std::string &key_,bool flag_)
2559 {
2560   std::string
2561     definition;
2562
2563   modifyImage();
2564   definition=magick_ + ":" + key_;
2565   if (flag_)
2566     (void) SetImageOption(imageInfo(),definition.c_str(),"");
2567   else
2568     DeleteImageOption(imageInfo(),definition.c_str());
2569 }
2570
2571 bool Magick::Image::defineSet(const std::string &magick_,
2572   const std::string &key_ ) const
2573 {
2574   const char
2575     *option;
2576
2577   std::string
2578     key;
2579
2580   key=magick_ + ":" + key_;
2581   option=GetImageOption(constImageInfo(),key.c_str());
2582   if (option)
2583     return(true);
2584   return(false);
2585 }
2586
2587 void Magick::Image::defineValue(const std::string &magick_,
2588   const std::string &key_,const std::string &value_)
2589 {
2590   std::string
2591     format,
2592     option;
2593
2594   modifyImage();
2595   format=magick_ + ":" + key_;
2596   option=value_;
2597   (void) SetImageOption(imageInfo(),format.c_str(),option.c_str());
2598 }
2599
2600 std::string Magick::Image::defineValue(const std::string &magick_,
2601   const std::string &key_) const
2602 {
2603   const char
2604     *option;
2605
2606   std::string
2607     definition;
2608
2609   definition=magick_ + ":" + key_;
2610   option=GetImageOption(constImageInfo(),definition.c_str());
2611   if (option)
2612     return(std::string(option));
2613   return(std::string());
2614 }
2615
2616 void Magick::Image::deskew(const double threshold_)
2617 {
2618   MagickCore::Image
2619     *newImage;
2620
2621   GetPPException;
2622   newImage=DeskewImage(constImage(),threshold_,&exceptionInfo);
2623   replaceImage(newImage);
2624   ThrowPPException;
2625 }
2626
2627 void Magick::Image::despeckle(void)
2628 {
2629   MagickCore::Image
2630     *newImage;
2631
2632   GetPPException;
2633   newImage=DespeckleImage(constImage(),&exceptionInfo);
2634   replaceImage(newImage);
2635   ThrowPPException;
2636 }
2637
2638 Magick::ImageType Magick::Image::determineType(void) const
2639 {
2640   ImageType
2641     image_type;
2642
2643   GetPPException;
2644   image_type=GetImageType(constImage(),&exceptionInfo);
2645   ThrowPPException;
2646   return(image_type);
2647 }
2648
2649 void Magick::Image::display(void)
2650 {
2651   GetPPException;
2652   DisplayImages(imageInfo(),image(),&exceptionInfo);
2653   ThrowPPException;
2654 }
2655
2656 void Magick::Image::distort(const DistortImageMethod method_,
2657   const size_t numberArguments_,const double *arguments_,const bool bestfit_)
2658 {
2659   MagickCore::Image
2660     *newImage;
2661
2662   GetPPException;
2663   newImage=DistortImage(constImage(), method_,numberArguments_,arguments_,
2664     bestfit_ == true ? MagickTrue : MagickFalse,&exceptionInfo);
2665   replaceImage(newImage);
2666   ThrowPPException;
2667 }
2668
2669 void Magick::Image::draw(const Magick::Drawable &drawable_)
2670 {
2671   DrawingWand
2672     *wand;
2673
2674   modifyImage();
2675
2676   wand=DrawAllocateWand(options()->drawInfo(),image());
2677
2678   if(wand)
2679     {
2680       drawable_.operator()(wand);
2681
2682       DrawRender(wand);
2683
2684       ClonePPDrawException(wand);
2685       wand=DestroyDrawingWand(wand);
2686       ThrowPPDrawException;
2687     }
2688 }
2689
2690 void Magick::Image::draw(const std::list<Magick::Drawable> &drawable_)
2691 {
2692   DrawingWand
2693     *wand;
2694
2695   modifyImage();
2696
2697   wand=DrawAllocateWand(options()->drawInfo(),image());
2698
2699   if(wand)
2700     {
2701       for (std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
2702            p != drawable_.end(); p++ )
2703         {
2704           p->operator()(wand);
2705           if (DrawGetExceptionType(wand) != UndefinedException)
2706             break;
2707         }
2708
2709       if (DrawGetExceptionType(wand) == UndefinedException)
2710         DrawRender(wand);
2711
2712       ClonePPDrawException(wand);
2713       wand=DestroyDrawingWand(wand);
2714       ThrowPPDrawException;
2715     }
2716 }
2717
2718 void Magick::Image::edge(const double radius_)
2719 {
2720   MagickCore::Image
2721     *newImage;
2722
2723   GetPPException;
2724   newImage=EdgeImage(constImage(),radius_,&exceptionInfo);
2725   replaceImage(newImage);
2726   ThrowPPException;
2727 }
2728
2729 void Magick::Image::emboss(const double radius_,const double sigma_)
2730 {
2731   MagickCore::Image
2732     *newImage;
2733
2734   GetPPException;
2735   newImage=EmbossImage(constImage(),radius_,sigma_,&exceptionInfo);
2736   replaceImage(newImage);
2737   ThrowPPException;
2738 }
2739
2740 void Magick::Image::encipher(const std::string &passphrase_)
2741 {
2742   modifyImage();
2743   GetPPException;
2744   EncipherImage(image(),passphrase_.c_str(),&exceptionInfo);
2745   ThrowPPException;
2746 }
2747
2748 void Magick::Image::enhance(void)
2749 {
2750   MagickCore::Image
2751     *newImage;
2752
2753   GetPPException;
2754   newImage=EnhanceImage(constImage(),&exceptionInfo);
2755   replaceImage(newImage);
2756   ThrowPPException;
2757 }
2758
2759 void Magick::Image::equalize(void)
2760 {
2761   modifyImage();
2762   GetPPException;
2763   EqualizeImage(image(),&exceptionInfo);
2764   ThrowPPException;
2765 }
2766
2767 void Magick::Image::erase(void)
2768 {
2769   modifyImage();
2770   GetPPException;
2771   (void) SetImageBackgroundColor(image(),&exceptionInfo);
2772   ThrowPPException;
2773 }
2774
2775 void Magick::Image::extent(const Geometry &geometry_ )
2776 {
2777   MagickCore::Image
2778     *newImage;
2779
2780   RectangleInfo
2781     extentInfo=geometry_;
2782
2783   modifyImage();
2784   extentInfo.x=geometry_.xOff();
2785   extentInfo.y=geometry_.yOff();
2786   GetPPException;
2787   newImage=ExtentImage(image(),&extentInfo,&exceptionInfo);
2788   replaceImage(newImage);
2789   ThrowPPException;
2790 }
2791
2792 void Magick::Image::extent(const Geometry &geometry_,
2793   const Color &backgroundColor_)
2794 {
2795   backgroundColor(backgroundColor_);
2796   extent(geometry_);
2797 }
2798
2799 void Magick::Image::extent(const Geometry &geometry_,
2800   const Color &backgroundColor_,const GravityType gravity_)
2801 {
2802   backgroundColor(backgroundColor_);
2803   extent(geometry_,gravity_);
2804 }
2805
2806 void Magick::Image::extent(const Geometry &geometry_,
2807   const GravityType gravity_)
2808 {
2809   RectangleInfo
2810     geometry;
2811
2812   SetGeometry(image(),&geometry);
2813   geometry.width=geometry_.width();
2814   geometry.height=geometry_.height();
2815   GravityAdjustGeometry(image()->columns,image()->rows,gravity_,&geometry);
2816   extent(geometry);
2817 }
2818
2819 void Magick::Image::flip(void)
2820 {
2821   MagickCore::Image
2822     *newImage;
2823
2824   GetPPException;
2825   newImage=FlipImage(constImage(),&exceptionInfo);
2826   replaceImage(newImage);
2827   ThrowPPException;
2828 }
2829
2830 void Magick::Image::floodFillAlpha(const ssize_t x_,const ssize_t y_,
2831   const unsigned int alpha_,const PaintMethod method_)
2832 {
2833   PixelInfo
2834     pixel,
2835     target;
2836
2837   modifyImage();
2838   GetPixelInfo(image(),&target);
2839   pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
2840   target.red=pixel.red;
2841   target.green=pixel.green;
2842   target.blue=pixel.blue;
2843   target.alpha=alpha_;
2844
2845   GetPPException;
2846   FloodfillPaintImage(image(),options()->drawInfo(),&target,
2847     static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
2848     method_  == FloodfillMethod ? MagickFalse : MagickTrue,&exceptionInfo);
2849   ThrowPPException;
2850 }
2851
2852 void Magick::Image::floodFillColor(const Geometry &point_,
2853   const Magick::Color &fillColor_)
2854 {
2855   floodFillTexture(point_,Image(Geometry(1,1),fillColor_));
2856 }
2857
2858 void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_,
2859   const Magick::Color &fillColor_)
2860 {
2861   floodFillTexture(x_,y_,Image(Geometry(1,1),fillColor_));
2862 }
2863
2864 void Magick::Image::floodFillColor(const Geometry &point_,
2865   const Magick::Color &fillColor_,const Magick::Color &borderColor_)
2866 {
2867   floodFillTexture(point_,Image(Geometry(1,1),fillColor_),borderColor_);
2868 }
2869
2870 void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_,
2871   const Magick::Color &fillColor_,const Magick::Color &borderColor_)
2872 {
2873   floodFillTexture(x_,y_,Image(Geometry(1,1),fillColor_),borderColor_);
2874 }
2875
2876 void Magick::Image::floodFillTexture(const Magick::Geometry &point_,
2877   const Magick::Image &texture_)
2878 {
2879   floodFillTexture(point_.xOff(),point_.yOff(),texture_);
2880 }
2881
2882 void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_,
2883   const Magick::Image &texture_)
2884 {
2885   MagickCore::Image
2886     *fillPattern;
2887
2888   Quantum
2889     *p;
2890
2891   modifyImage();
2892
2893   // Set drawing fill pattern
2894   fillPattern=(MagickCore::Image *)NULL;
2895   if (options()->fillPattern() != (MagickCore::Image *)NULL)
2896     {
2897       GetPPException;
2898       fillPattern=CloneImage(options()->fillPattern(),0,0,MagickTrue,
2899         &exceptionInfo);
2900       ThrowPPException;
2901     }
2902   options()->fillPattern(texture_.constImage());
2903
2904   // Get pixel view
2905   Pixels pixels(*this);
2906   // Fill image
2907   p=pixels.get(x_,y_,1,1);
2908
2909   if (p)
2910     {
2911       PixelInfo
2912         target;
2913
2914       GetPixelInfo(constImage(),&target);
2915       target.red=GetPixelRed(constImage(),p);
2916       target.green=GetPixelGreen(constImage(),p);
2917       target.blue=GetPixelBlue(constImage(),p);
2918       GetPPException;
2919       FloodfillPaintImage(image(),options()->drawInfo(),&target,
2920         static_cast<ssize_t>(x_),static_cast<ssize_t>(y_),MagickFalse,
2921         &exceptionInfo);
2922       options()->fillPattern(fillPattern);
2923       ThrowPPException;
2924     }
2925   else
2926     options()->fillPattern(fillPattern);
2927 }
2928
2929 void Magick::Image::floodFillTexture(const Magick::Geometry &point_,
2930   const Magick::Image &texture_,const Magick::Color &borderColor_)
2931 {
2932   floodFillTexture(point_.xOff(),point_.yOff(),texture_,borderColor_);
2933 }
2934
2935 void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_,
2936   const Magick::Image &texture_,const Magick::Color &borderColor_)
2937 {
2938   MagickCore::Image
2939     *fillPattern;
2940
2941   PixelInfo
2942     target;
2943
2944   modifyImage();
2945
2946   // Set drawing fill pattern
2947   fillPattern=(MagickCore::Image *)NULL;
2948   if (options()->fillPattern() != (MagickCore::Image *)NULL)
2949     {
2950       GetPPException;
2951       fillPattern=CloneImage(options()->fillPattern(),0,0,MagickTrue,
2952         &exceptionInfo);
2953       ThrowPPException;
2954     }
2955   options()->fillPattern(texture_.constImage());
2956
2957   GetPixelInfo(constImage(),&target);
2958   target.red=static_cast<PixelInfo>(borderColor_).red;
2959   target.green=static_cast<PixelInfo>(borderColor_).green;
2960   target.blue=static_cast<PixelInfo>(borderColor_).blue;
2961   GetPPException;
2962   FloodfillPaintImage(image(),options()->drawInfo(),&target,
2963     static_cast<ssize_t>(x_),static_cast<ssize_t>(y_),MagickTrue,
2964     &exceptionInfo);
2965   options()->fillPattern(fillPattern);
2966   ThrowPPException;
2967 }
2968
2969 void Magick::Image::flop(void)
2970 {
2971   MagickCore::Image
2972     *newImage;
2973
2974   GetPPException;
2975   newImage=FlopImage(constImage(),&exceptionInfo);
2976   replaceImage(newImage);
2977   ThrowPPException;
2978 }
2979
2980 void Magick::Image::fontTypeMetrics(const std::string &text_,
2981   TypeMetric *metrics)
2982 {
2983   DrawInfo
2984     *drawInfo;
2985
2986   drawInfo=options()->drawInfo();
2987   drawInfo->text=const_cast<char *>(text_.c_str());
2988   GetPPException;
2989   GetTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),&exceptionInfo);
2990   drawInfo->text=0;
2991   ThrowPPException;
2992 }
2993
2994 void Magick::Image::fontTypeMetricsMultiline(const std::string &text_,
2995   TypeMetric *metrics)
2996 {
2997   DrawInfo
2998     *drawInfo;
2999
3000   drawInfo=options()->drawInfo();
3001   drawInfo->text=const_cast<char *>(text_.c_str());
3002   GetPPException;
3003   GetMultilineTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),&exceptionInfo);
3004   drawInfo->text=0;
3005   ThrowPPException;
3006 }
3007
3008 void Magick::Image::frame(const Geometry &geometry_)
3009 {
3010   FrameInfo
3011     info;
3012   
3013   MagickCore::Image
3014     *newImage;
3015
3016   info.x=static_cast<ssize_t>(geometry_.width());
3017   info.y=static_cast<ssize_t>(geometry_.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=geometry_.xOff();
3021   info.inner_bevel=geometry_.yOff();
3022
3023   GetPPException;
3024   newImage=FrameImage(constImage(),&info,image()->compose,&exceptionInfo);
3025   replaceImage(newImage);
3026   ThrowPPException;
3027 }
3028
3029 void Magick::Image::frame(const size_t width_,const size_t height_,
3030   const ssize_t outerBevel_,const ssize_t innerBevel_)
3031 {
3032   FrameInfo
3033     info;
3034
3035   MagickCore::Image
3036     *newImage;
3037
3038   info.x=static_cast<ssize_t>(width_);
3039   info.y=static_cast<ssize_t>(height_);
3040   info.width=columns() + (static_cast<size_t>(info.x) << 1);
3041   info.height=rows() + (static_cast<size_t>(info.y) << 1);
3042   info.outer_bevel=static_cast<ssize_t>(outerBevel_);
3043   info.inner_bevel=static_cast<ssize_t>(innerBevel_);
3044
3045   GetPPException;
3046   newImage=FrameImage(constImage(),&info,image()->compose,&exceptionInfo);
3047   replaceImage(newImage);
3048   ThrowPPException;
3049 }
3050
3051 void Magick::Image::fx(const std::string expression_)
3052 {
3053   MagickCore::Image
3054     *newImage;
3055
3056   GetPPException;
3057   newImage=FxImage(constImage(),expression_.c_str(),&exceptionInfo);
3058   replaceImage(newImage);
3059   ThrowPPException;
3060 }
3061
3062 void Magick::Image::fx(const std::string expression_,
3063   const Magick::ChannelType channel_)
3064 {
3065   MagickCore::Image
3066     *newImage;
3067
3068   GetPPException;
3069   SetPPChannelMask(channel_);
3070   newImage=FxImage(constImage(),expression_.c_str(),&exceptionInfo);
3071   RestorePPChannelMask;
3072   replaceImage(newImage);
3073   ThrowPPException;
3074 }
3075
3076 void Magick::Image::gamma(const double gamma_)
3077 {
3078   modifyImage();
3079   GetPPException;
3080   GammaImage(image(),gamma_,&exceptionInfo);
3081   ThrowPPException;
3082 }
3083
3084 void Magick::Image::gamma(const double gammaRed_,const double gammaGreen_,
3085   const double gammaBlue_)
3086 {
3087   char
3088     gamma[MaxTextExtent + 1];
3089
3090   FormatLocaleString(gamma,MaxTextExtent,"%3.6f/%3.6f/%3.6f/",gammaRed_,
3091     gammaGreen_,gammaBlue_);
3092
3093   modifyImage();
3094   GetPPException;
3095   GammaImage(image(),atof(gamma),&exceptionInfo);
3096   ThrowPPException;
3097 }
3098
3099 void Magick::Image::gaussianBlur(const double width_,const double sigma_)
3100 {
3101   MagickCore::Image
3102     *newImage;
3103
3104   GetPPException;
3105   newImage=GaussianBlurImage(constImage(),width_,sigma_,&exceptionInfo);
3106   replaceImage(newImage);
3107   ThrowPPException;
3108 }
3109
3110 void Magick::Image::gaussianBlurChannel(const ChannelType channel_,
3111   const double width_,const double sigma_)
3112 {
3113   MagickCore::Image
3114     *newImage;
3115
3116   GetPPException;
3117   SetPPChannelMask(channel_);
3118   newImage=GaussianBlurImage(constImage(),width_,sigma_,&exceptionInfo);
3119   RestorePPChannelMask;
3120   replaceImage(newImage);
3121   ThrowPPException;
3122 }
3123
3124 const Magick::Quantum *Magick::Image::getConstPixels(const ssize_t x_,
3125   const ssize_t y_,const size_t columns_,const size_t rows_) const
3126 {
3127   const Quantum
3128     *p;
3129
3130   GetPPException;
3131   p=(*GetVirtualPixels)(constImage(),x_, y_,columns_, rows_,&exceptionInfo);
3132   ThrowPPException;
3133   return(p);
3134 }
3135
3136 const void *Magick::Image::getConstMetacontent(void) const
3137 {
3138   const void
3139     *result;
3140
3141   result=GetVirtualMetacontent(constImage());
3142
3143   if(!result)
3144     throwExceptionExplicit(OptionError,"Unable to retrieve meta content.");
3145
3146   return(result);
3147 }
3148
3149 void *Magick::Image::getMetacontent(void )
3150 {
3151   void
3152     *result;
3153
3154   result=GetAuthenticMetacontent(image());
3155
3156   if(!result)
3157     throwExceptionExplicit(OptionError,"Unable to retrieve meta content.");
3158
3159   return(result);
3160 }
3161
3162 Magick::Quantum *Magick::Image::getPixels(const ssize_t x_,const ssize_t y_,
3163   const size_t columns_,const size_t rows_)
3164 {
3165   Quantum
3166     *result;
3167
3168   modifyImage();
3169   GetPPException;
3170   result=(*GetAuthenticPixels)(image(),x_, y_,columns_,rows_,&exceptionInfo);
3171   ThrowPPException;
3172
3173   return(result);
3174 }
3175
3176 void  Magick::Image::haldClut(const Image &clutImage_)
3177 {
3178   modifyImage();
3179   GetPPException;
3180   (void) HaldClutImage(image(),clutImage_.constImage(),&exceptionInfo);
3181   ThrowPPException;
3182 }
3183
3184 void Magick::Image::houghLine(const size_t width_,const size_t height_,
3185   const size_t threshold_)
3186 {
3187   MagickCore::Image
3188     *newImage;
3189
3190   GetPPException;
3191   newImage=HoughLineImage(constImage(),width_,height_,threshold_,
3192     &exceptionInfo);
3193   replaceImage(newImage);
3194   ThrowPPException;
3195 }
3196
3197 void Magick::Image::implode(const double factor_)
3198 {
3199   MagickCore::Image
3200     *newImage;
3201
3202   GetPPException;
3203   newImage=ImplodeImage(constImage(),factor_,image()->interpolate,
3204     &exceptionInfo);
3205   replaceImage(newImage);
3206   ThrowPPException;
3207 }
3208
3209 void Magick::Image::inverseFourierTransform(const Image &phase_)
3210 {
3211   inverseFourierTransform(phase_,true);
3212 }
3213
3214 void Magick::Image::inverseFourierTransform(const Image &phase_,
3215   const bool magnitude_)
3216 {
3217   MagickCore::Image
3218     *newImage;
3219
3220   GetPPException;
3221   newImage=InverseFourierTransformImage(constImage(),phase_.constImage(),
3222     magnitude_ == true ? MagickTrue : MagickFalse,&exceptionInfo);
3223   replaceImage(newImage);
3224   ThrowPPException;
3225 }
3226
3227 void Magick::Image::level(const double blackPoint_,const double whitePoint_,
3228   const double gamma_)
3229 {
3230   modifyImage();
3231   GetPPException;
3232   (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,&exceptionInfo);
3233   ThrowPPException;
3234 }
3235
3236 void Magick::Image::levelChannel(const ChannelType channel_,
3237   const double blackPoint_,const double whitePoint_,const double gamma_)
3238 {
3239   modifyImage();
3240   GetPPException;
3241   SetPPChannelMask(channel_);
3242   (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,&exceptionInfo);
3243   RestorePPChannelMask;
3244   ThrowPPException;
3245 }
3246
3247 void Magick::Image::levelColors(const Color &blackColor_,
3248   const Color &whiteColor_,const bool invert_)
3249 {
3250   PixelInfo
3251     black,
3252     pixel,
3253     white;
3254
3255   modifyImage();
3256
3257   GetPixelInfo(image(),&black);
3258   pixel=static_cast<PixelInfo>(blackColor_);
3259   black.red=pixel.red;
3260   black.green=pixel.green;
3261   black.blue=pixel.blue;
3262   black.alpha=pixel.alpha;
3263
3264   GetPixelInfo(image(),&white);
3265   pixel=static_cast<PixelInfo>(whiteColor_);
3266   white.red=pixel.red;
3267   white.green=pixel.green;
3268   white.blue=pixel.blue;
3269   white.alpha=pixel.alpha;
3270
3271   GetPPException;
3272   (void) LevelImageColors(image(),&black,&white,invert_ == true ?
3273     MagickTrue : MagickFalse,&exceptionInfo);
3274   ThrowPPException;
3275 }
3276
3277 void Magick::Image::levelColorsChannel(const ChannelType channel_,
3278   const Color &blackColor_,const Color &whiteColor_,const bool invert_)
3279 {
3280   PixelInfo
3281     black,
3282     pixel,
3283     white;
3284
3285   modifyImage();
3286
3287   GetPixelInfo(image(),&black);
3288   pixel=static_cast<PixelInfo>(blackColor_);
3289   black.red=pixel.red;
3290   black.green=pixel.green;
3291   black.blue=pixel.blue;
3292   black.alpha=pixel.alpha;
3293
3294   GetPixelInfo(image(),&white);
3295   pixel=static_cast<PixelInfo>(whiteColor_);
3296   white.red=pixel.red;
3297   white.green=pixel.green;
3298   white.blue=pixel.blue;
3299   white.alpha=pixel.alpha;
3300
3301   GetPPException;
3302   SetPPChannelMask(channel_);
3303   (void) LevelImageColors(image(),&black,&white,invert_ == true ?
3304     MagickTrue : MagickFalse,&exceptionInfo);
3305   RestorePPChannelMask;
3306   ThrowPPException;
3307 }
3308
3309 void Magick::Image::linearStretch(const double blackPoint_,
3310   const double whitePoint_)
3311 {
3312   modifyImage();
3313   GetPPException;
3314   LinearStretchImage(image(),blackPoint_,whitePoint_,&exceptionInfo);
3315   ThrowPPException;
3316 }
3317
3318 void Magick::Image::liquidRescale(const Geometry &geometry_)
3319 {
3320   MagickCore::Image
3321     *newImage;
3322
3323   size_t
3324     height=rows(),
3325     width=columns();
3326
3327   ssize_t
3328     x=0,
3329     y=0;
3330
3331   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
3332     &height);
3333
3334   GetPPException;
3335   newImage=LiquidRescaleImage(image(),width,height,x,y,&exceptionInfo);
3336   replaceImage(newImage);
3337   ThrowPPException;
3338 }
3339
3340 void Magick::Image::magnify(void)
3341 {
3342   MagickCore::Image
3343     *newImage;
3344
3345   GetPPException;
3346   newImage=MagnifyImage(constImage(),&exceptionInfo);
3347   replaceImage(newImage);
3348   ThrowPPException;
3349 }
3350
3351 void Magick::Image::map(const Image &mapImage_,const bool dither_)
3352 {
3353   modifyImage();
3354   GetPPException;
3355   options()->quantizeDither(dither_);
3356   RemapImage(options()->quantizeInfo(),image(),mapImage_.constImage(),
3357     &exceptionInfo);
3358   ThrowPPException;
3359 }
3360
3361 void Magick::Image::medianFilter(const double radius_)
3362 {
3363   MagickCore::Image
3364     *newImage;
3365
3366   GetPPException;
3367   newImage=StatisticImage(image(),MedianStatistic,(size_t) radius_,
3368     (size_t) radius_,&exceptionInfo);
3369   replaceImage(newImage);
3370   ThrowPPException;
3371 }
3372
3373 void Magick::Image::minify(void)
3374 {
3375   MagickCore::Image
3376     *newImage;
3377
3378   GetPPException;
3379   newImage=MinifyImage(constImage(),&exceptionInfo);
3380   replaceImage(newImage);
3381   ThrowPPException;
3382 }
3383
3384 void Magick::Image::modulate(const double brightness_,const double saturation_,
3385   const double hue_)
3386 {
3387   char
3388     modulate[MaxTextExtent + 1];
3389
3390   FormatLocaleString(modulate,MaxTextExtent,"%3.6f,%3.6f,%3.6f",brightness_,
3391     saturation_,hue_);
3392
3393   modifyImage();
3394   GetPPException;
3395   ModulateImage(image(),modulate,&exceptionInfo);
3396   ThrowPPException;
3397 }
3398
3399 Magick::ImageMoments Magick::Image::moments(void)
3400 {
3401   return(ImageMoments(constImage()));
3402 }
3403
3404 void Magick::Image::morphology(const MorphologyMethod method_,
3405   const std::string kernel_,const ssize_t iterations_)
3406 {
3407   KernelInfo
3408     *kernel;
3409
3410   MagickCore::Image
3411     *newImage;
3412
3413   kernel=AcquireKernelInfo(kernel_.c_str());
3414   if (kernel == (KernelInfo *)NULL)
3415     throwExceptionExplicit(OptionError,"Unable to parse kernel.");
3416
3417   GetPPException;
3418   newImage=MorphologyImage(constImage(),method_,iterations_,kernel,
3419     &exceptionInfo);
3420   replaceImage(newImage);
3421   kernel=DestroyKernelInfo(kernel);
3422   ThrowPPException;
3423 }
3424
3425 void Magick::Image::morphology(const MorphologyMethod method_,
3426   const KernelInfoType kernel_,const std::string arguments_,
3427   const ssize_t iterations_)
3428 {
3429   const char
3430     *option;
3431
3432   std::string
3433     kernel;
3434
3435   option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
3436   if (option == (const char *)NULL)
3437     throwExceptionExplicit(OptionError,"Unable to determine kernel type.");
3438
3439   kernel=std::string(option);
3440   if (!arguments_.empty())
3441     kernel+=":"+arguments_;
3442
3443   morphology(method_,kernel,iterations_);
3444 }
3445
3446 void Magick::Image::morphologyChannel(const ChannelType channel_,
3447   const MorphologyMethod method_,const std::string kernel_,
3448   const ssize_t iterations_)
3449 {
3450   KernelInfo
3451     *kernel;
3452
3453   MagickCore::Image
3454     *newImage;
3455
3456   kernel=AcquireKernelInfo(kernel_.c_str());
3457   if (kernel == (KernelInfo *)NULL)
3458     throwExceptionExplicit(OptionError,"Unable to parse kernel.");
3459
3460   GetPPException;
3461   SetPPChannelMask(channel_);
3462   newImage=MorphologyImage(constImage(),method_,iterations_,kernel,
3463     &exceptionInfo);
3464   RestorePPChannelMask;
3465   replaceImage(newImage);
3466   kernel=DestroyKernelInfo(kernel);
3467   ThrowPPException;
3468 }
3469
3470 void Magick::Image::morphologyChannel(const ChannelType channel_,
3471   const MorphologyMethod method_,const KernelInfoType kernel_,
3472   const std::string arguments_,const ssize_t iterations_)
3473 {
3474   const char
3475     *option;
3476
3477   std::string
3478     kernel;
3479
3480   option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
3481   if (option == (const char *)NULL)
3482     throwExceptionExplicit(OptionError,"Unable to determine kernel type.");
3483
3484   kernel=std::string(option);
3485   if (!arguments_.empty())
3486     kernel+=":"+arguments_;
3487
3488   morphologyChannel(channel_,method_,kernel,iterations_);
3489 }
3490
3491 void Magick::Image::motionBlur(const double radius_,const double sigma_,
3492   const double angle_)
3493 {
3494   MagickCore::Image
3495     *newImage;
3496
3497   GetPPException;
3498   newImage=MotionBlurImage(constImage(),radius_,sigma_,angle_,&exceptionInfo);
3499   replaceImage(newImage);
3500   ThrowPPException;
3501 }
3502
3503 void Magick::Image::negate(const bool grayscale_)
3504 {
3505   modifyImage();
3506   GetPPException;
3507   NegateImage(image(),(MagickBooleanType) grayscale_,&exceptionInfo);
3508   ThrowPPException;
3509 }
3510
3511 void Magick::Image::negateChannel(const ChannelType channel_,
3512   const bool grayscale_)
3513 {
3514   modifyImage();
3515   GetPPException;
3516   SetPPChannelMask(channel_);
3517   NegateImage(image(),(MagickBooleanType) grayscale_,&exceptionInfo);
3518   RestorePPChannelMask;
3519   ThrowPPException;
3520 }
3521
3522 void Magick::Image::normalize(void)
3523 {
3524   modifyImage();
3525   GetPPException;
3526   NormalizeImage(image(),&exceptionInfo);
3527   ThrowPPException;
3528 }
3529
3530 void Magick::Image::oilPaint(const double radius_,const double sigma_)
3531 {
3532   MagickCore::Image
3533     *newImage;
3534
3535   GetPPException;
3536   newImage=OilPaintImage(constImage(),radius_,sigma_,&exceptionInfo);
3537   replaceImage(newImage);
3538   ThrowPPException;
3539 }
3540
3541 void Magick::Image::opaque(const Color &opaqueColor_,const Color &penColor_)
3542 {
3543   std::string
3544     opaqueColor,
3545     penColor;
3546
3547   PixelInfo
3548     opaque,
3549     pen;
3550
3551   if (!opaqueColor_.isValid())
3552     throwExceptionExplicit(OptionError,"Opaque color argument is invalid");
3553
3554   if (!penColor_.isValid())
3555     throwExceptionExplicit(OptionError,"Pen color argument is invalid");
3556
3557   modifyImage();
3558   opaqueColor=opaqueColor_;
3559   penColor=penColor_;
3560
3561   GetPPException;
3562   (void) QueryColorCompliance(opaqueColor.c_str(),AllCompliance,&opaque,
3563     &exceptionInfo);
3564   (void) QueryColorCompliance(penColor.c_str(),AllCompliance,&pen,
3565     &exceptionInfo);
3566   OpaquePaintImage(image(),&opaque,&pen,MagickFalse,&exceptionInfo);
3567   ThrowPPException;
3568 }
3569
3570 void Magick::Image::orderedDither(std::string thresholdMap_)
3571 {
3572   modifyImage();
3573   GetPPException;
3574   (void) OrderedPosterizeImage(image(),thresholdMap_.c_str(),&exceptionInfo);
3575   ThrowPPException;
3576 }
3577
3578 void Magick::Image::orderedDitherChannel(const ChannelType channel_,
3579   std::string thresholdMap_)
3580 {
3581   modifyImage();
3582   GetPPException;
3583   SetPPChannelMask(channel_);
3584   (void) OrderedPosterizeImage(image(),thresholdMap_.c_str(),&exceptionInfo);
3585   RestorePPChannelMask;
3586   ThrowPPException;
3587 }
3588
3589 void Magick::Image::perceptible(const double epsilon_)
3590 {
3591   modifyImage();
3592   GetPPException;
3593   PerceptibleImage(image(),epsilon_,&exceptionInfo);
3594   ThrowPPException;
3595 }
3596
3597 void Magick::Image::perceptibleChannel(const ChannelType channel_,
3598   const double epsilon_)
3599 {
3600   modifyImage();
3601   GetPPException;
3602   SetPPChannelMask(channel_);
3603   PerceptibleImage(image(),epsilon_,&exceptionInfo);
3604   RestorePPChannelMask;
3605   ThrowPPException;
3606 }
3607
3608 void Magick::Image::ping(const std::string &imageSpec_)
3609 {
3610   MagickCore::Image
3611     *newImage;
3612
3613   GetPPException;
3614   options()->fileName(imageSpec_);
3615   newImage=PingImage(imageInfo(),&exceptionInfo);
3616   replaceImage(newImage);
3617   ThrowPPException;
3618 }
3619
3620 void Magick::Image::ping(const Blob& blob_)
3621 {
3622   MagickCore::Image
3623     *newImage;
3624
3625   GetPPException;
3626   newImage=PingBlob(imageInfo(),blob_.data(),blob_.length(),&exceptionInfo);
3627   replaceImage(newImage);
3628   ThrowPPException;
3629 }
3630
3631 void Magick::Image::pixelColor(const ssize_t x_,const ssize_t y_,
3632   const Color &color_)
3633 {
3634   PixelInfo
3635     packet;
3636
3637   Quantum
3638     *pixel;
3639
3640   // Test arguments to ensure they are within the image.
3641   if (y_ > (ssize_t) rows() || x_ > (ssize_t) columns())
3642     throwExceptionExplicit(OptionError,"Access outside of image boundary");
3643
3644   modifyImage();
3645
3646   // Set image to DirectClass
3647   classType(DirectClass );
3648
3649   // Get pixel view
3650   Pixels pixels(*this);
3651     // Set pixel value
3652   pixel=pixels.get(x_, y_, 1, 1 );
3653   packet=color_;
3654   MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel);
3655   // Tell ImageMagick that pixels have been updated
3656   pixels.sync();
3657 }
3658
3659 Magick::Color Magick::Image::pixelColor(const ssize_t x_,
3660   const ssize_t y_) const
3661 {
3662   const Quantum
3663     *pixel;
3664
3665   pixel=getConstPixels(x_,y_,1,1);
3666   if (pixel)
3667     {
3668       PixelInfo
3669         packet;
3670
3671       MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3672       return(Color(packet));
3673     }
3674
3675   return(Color()); // invalid
3676 }
3677
3678 void Magick::Image::polaroid(const std::string &caption_,const double angle_,
3679   const PixelInterpolateMethod method_)
3680 {
3681   MagickCore::Image
3682     *newImage;
3683
3684   GetPPException;
3685   newImage=PolaroidImage(constImage(),options()->drawInfo(),caption_.c_str(),
3686     angle_,method_,&exceptionInfo);
3687   replaceImage(newImage);
3688   ThrowPPException;
3689 }
3690
3691 void Magick::Image::posterize(const size_t levels_,const DitherMethod method_)
3692 {
3693   modifyImage();
3694   GetPPException;
3695   PosterizeImage(image(),levels_,method_,&exceptionInfo);
3696   ThrowPPException;
3697 }
3698
3699 void Magick::Image::posterizeChannel(const ChannelType channel_,
3700   const size_t levels_,const DitherMethod method_)
3701 {
3702   modifyImage();
3703   GetPPException;
3704   SetPPChannelMask(channel_);
3705   PosterizeImage(image(),levels_,method_,&exceptionInfo);
3706   RestorePPChannelMask;
3707   ThrowPPException;
3708 }
3709
3710 void Magick::Image::process(std::string name_,const ssize_t argc,
3711   const char **argv)
3712 {
3713   modifyImage();
3714
3715   GetPPException;
3716   (void) InvokeDynamicImageFilter(name_.c_str(),&image(),argc,argv,
3717       &exceptionInfo);
3718   ThrowPPException;
3719 }
3720
3721 void Magick::Image::profile(const std::string name_,
3722   const Magick::Blob &profile_)
3723 {
3724   modifyImage();
3725   GetPPException;
3726   (void) ProfileImage(image(),name_.c_str(),(unsigned char *)profile_.data(),
3727     profile_.length(),&exceptionInfo);
3728   ThrowPPException;
3729 }
3730
3731 Magick::Blob Magick::Image::profile(const std::string name_) const
3732 {
3733   const StringInfo
3734     *profile;
3735
3736   profile=GetImageProfile(constImage(),name_.c_str());
3737
3738   if (profile == (StringInfo *) NULL)
3739     return(Blob());
3740   return(Blob((void*) GetStringInfoDatum(profile),GetStringInfoLength(
3741     profile)));
3742 }
3743
3744 void Magick::Image::quantize(const bool measureError_)
3745 {
3746   modifyImage();
3747  
3748   if (measureError_)
3749     options()->quantizeInfo()->measure_error=MagickTrue;
3750   else
3751     options()->quantizeInfo()->measure_error=MagickFalse;
3752
3753   GetPPException;
3754   QuantizeImage(options()->quantizeInfo(),image(),&exceptionInfo);
3755   ThrowPPException;
3756 }
3757
3758 void Magick::Image::quantumOperator(const ChannelType channel_,
3759   const MagickEvaluateOperator operator_,double rvalue_)
3760 {
3761   GetPPException;
3762   SetPPChannelMask(channel_);
3763   EvaluateImage(image(),operator_,rvalue_,&exceptionInfo);
3764   RestorePPChannelMask;
3765   ThrowPPException;
3766 }
3767
3768 void Magick::Image::quantumOperator(const ssize_t x_,const ssize_t y_,
3769   const size_t columns_,const size_t rows_,const ChannelType channel_,
3770   const MagickEvaluateOperator operator_,const double rvalue_)
3771 {
3772   RectangleInfo
3773     geometry;
3774
3775   MagickCore::Image
3776     *cropImage;
3777
3778   geometry.width = columns_;
3779   geometry.height = rows_;
3780   geometry.x = x_;
3781   geometry.y = y_;
3782
3783   GetPPException;
3784   cropImage=CropImage(image(),&geometry,&exceptionInfo);
3785   SetPPChannelMask(channel_);
3786   EvaluateImage(cropImage,operator_,rvalue_,&exceptionInfo);
3787   RestorePPChannelMask;
3788   (void) CompositeImage(image(),cropImage,image()->alpha_trait == 
3789     BlendPixelTrait ? OverCompositeOp : CopyCompositeOp,MagickFalse,
3790     geometry.x,geometry.y,&exceptionInfo );
3791   cropImage=DestroyImageList(cropImage);
3792   ThrowPPException;
3793 }
3794
3795 void Magick::Image::raise(const Geometry &geometry_,const bool raisedFlag_)
3796 {
3797   RectangleInfo
3798     raiseInfo=geometry_;
3799
3800   GetPPException;
3801   modifyImage();
3802   RaiseImage(image(),&raiseInfo,raisedFlag_ == true ? MagickTrue : MagickFalse,
3803     &exceptionInfo);
3804   ThrowPPException;
3805 }
3806
3807 void Magick::Image::randomThreshold(const Geometry &thresholds_)
3808 {
3809   GetPPException;
3810   (void) RandomThresholdImage(image(),static_cast<std::string>(
3811     thresholds_).c_str(),&exceptionInfo);
3812   ThrowPPException;
3813 }
3814
3815 void Magick::Image::randomThresholdChannel(const ChannelType channel_,
3816   const Geometry &thresholds_)
3817 {
3818   modifyImage();
3819   GetPPException;
3820   SetPPChannelMask(channel_);
3821   (void) RandomThresholdImage(image(),static_cast<std::string>(
3822     thresholds_).c_str(),&exceptionInfo);
3823   RestorePPChannelMask;
3824   ThrowPPException;
3825 }
3826
3827 void Magick::Image::read(const Blob &blob_)
3828 {
3829   MagickCore::Image
3830     *newImage;
3831
3832   GetPPException;
3833   newImage=BlobToImage(imageInfo(),static_cast<const void *>(blob_.data()),
3834     blob_.length(),&exceptionInfo);
3835   replaceImage(newImage);
3836   ThrowPPException;
3837 }
3838
3839 void Magick::Image::read(const Blob &blob_,const Geometry &size_)
3840 {
3841   size(size_);
3842   read(blob_);
3843 }
3844
3845 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
3846   const size_t depth_)
3847 {
3848   size(size_);
3849   depth(depth_);
3850   read(blob_);
3851 }
3852
3853 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
3854   const size_t depth_,const std::string &magick_)
3855 {
3856   size(size_);
3857   depth(depth_);
3858   magick(magick_);
3859   // Set explicit image format
3860   fileName(magick_ + ':');
3861   read(blob_);
3862 }
3863
3864 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
3865   const std::string &magick_)
3866 {
3867   size(size_);
3868   magick(magick_);
3869   // Set explicit image format
3870   fileName(magick_ + ':');
3871   read(blob_);
3872 }
3873
3874 void Magick::Image::read(const Geometry &size_,const std::string &imageSpec_)
3875 {
3876   size(size_);
3877   read(imageSpec_);
3878 }
3879
3880 void Magick::Image::read(const size_t width_,const size_t height_,
3881   const std::string &map_,const StorageType type_,const void *pixels_)
3882 {
3883   MagickCore::Image
3884     *newImage;
3885
3886   GetPPException;
3887   newImage=ConstituteImage(width_,height_,map_.c_str(),type_, pixels_,
3888     &exceptionInfo);
3889   replaceImage(newImage);
3890   ThrowPPException;
3891 }
3892
3893 void Magick::Image::read(const std::string &imageSpec_)
3894 {
3895   MagickCore::Image
3896     *newImage;
3897
3898   GetPPException;
3899   options()->fileName(imageSpec_);
3900   newImage=ReadImage(imageInfo(),&exceptionInfo);
3901
3902   // Ensure that multiple image frames were not read.
3903   if (newImage && newImage->next)
3904     {
3905       MagickCore::Image
3906          *next;
3907
3908       // Destroy any extra image frames
3909       next=newImage->next;
3910       newImage->next=0;
3911       next->previous=0;
3912       DestroyImageList(next);
3913     }
3914   replaceImage(newImage);
3915   ThrowPPException;
3916 }
3917
3918 void Magick::Image::readPixels(const Magick::QuantumType quantum_,
3919   const unsigned char *source_)
3920 {
3921   QuantumInfo
3922     *quantum_info;
3923
3924   quantum_info=AcquireQuantumInfo(imageInfo(),image());
3925   GetPPException;
3926   ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
3927     quantum_,source_,&exceptionInfo);
3928   quantum_info=DestroyQuantumInfo(quantum_info);
3929   ThrowPPException;
3930 }
3931
3932 void Magick::Image::reduceNoise(void)
3933 {
3934   reduceNoise(3.0);
3935 }
3936
3937 void Magick::Image::reduceNoise(const double order_)
3938 {
3939   MagickCore::Image
3940     *newImage;
3941
3942   GetPPException;
3943   newImage=StatisticImage(constImage(),NonpeakStatistic,(size_t) order_,
3944     (size_t) order_,&exceptionInfo);
3945   replaceImage(newImage);
3946   ThrowPPException;
3947 }
3948
3949 void Magick::Image::resample(const Geometry &geometry_)
3950 {
3951   MagickCore::Image
3952     *newImage;
3953
3954   size_t
3955     height=rows(),
3956     width=columns();
3957
3958   ssize_t
3959     x=0,
3960     y=0;
3961
3962   // Calculate new size.  This code should be supported using binary arguments
3963   // in the ImageMagick library.
3964   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
3965     &height);
3966
3967   GetPPException;
3968   newImage=ResampleImage(constImage(),width,height,image()->filter,
3969     &exceptionInfo);
3970   replaceImage(newImage);
3971   ThrowPPException;
3972 }
3973
3974 void Magick::Image::resize(const Geometry &geometry_)
3975 {
3976   MagickCore::Image
3977     *newImage;
3978
3979   size_t
3980     height=rows(),
3981     width=columns();
3982
3983   ssize_t
3984     x=0,
3985     y=0;
3986
3987   // Calculate new size.  This code should be supported using binary arguments
3988   // in the ImageMagick library.
3989   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
3990     &height);
3991
3992   GetPPException;
3993   newImage=ResizeImage(constImage(),width,height,image()->filter,
3994     &exceptionInfo);
3995   replaceImage(newImage);
3996   ThrowPPException;
3997 }
3998
3999 void Magick::Image::roll(const Geometry &roll_)
4000 {
4001   MagickCore::Image
4002     *newImage;
4003
4004   ssize_t
4005     xOff=roll_.xOff(),
4006     yOff=roll_.yOff();
4007
4008   if (roll_.xNegative())
4009     xOff = 0 - xOff;
4010   if (roll_.yNegative())
4011     yOff = 0 - yOff;
4012
4013   GetPPException;
4014   newImage=RollImage(constImage(),xOff,yOff,&exceptionInfo);
4015   replaceImage(newImage);
4016   ThrowPPException;
4017 }
4018
4019 void Magick::Image::roll(const size_t columns_,const size_t rows_)
4020 {
4021   MagickCore::Image
4022     *newImage;
4023
4024   GetPPException;
4025   newImage=RollImage(constImage(),static_cast<ssize_t>(columns_),
4026     static_cast<ssize_t>(rows_),&exceptionInfo);
4027   replaceImage(newImage);
4028   ThrowPPException;
4029 }
4030
4031 void Magick::Image::rotate(const double degrees_)
4032 {
4033   MagickCore::Image
4034     *newImage;
4035
4036   GetPPException;
4037   newImage=RotateImage(constImage(),degrees_,&exceptionInfo);
4038   replaceImage(newImage);
4039   ThrowPPException;
4040 }
4041
4042 void Magick::Image::rotationalBlur(const double angle_)
4043 {
4044   MagickCore::Image
4045     *newImage;
4046
4047   GetPPException;
4048   newImage=RotationalBlurImage(constImage(),angle_,&exceptionInfo);
4049   replaceImage(newImage);
4050   ThrowPPException;
4051 }
4052
4053 void Magick::Image::rotationalBlurChannel(const ChannelType channel_,
4054   const double angle_)
4055 {
4056   MagickCore::Image
4057     *newImage;
4058
4059   GetPPException;
4060   SetPPChannelMask(channel_);
4061   newImage=RotationalBlurImage(constImage(),angle_,&exceptionInfo);
4062   RestorePPChannelMask;
4063   replaceImage(newImage);
4064   ThrowPPException;
4065 }
4066
4067 void Magick::Image::sample(const Geometry &geometry_)
4068 {
4069   MagickCore::Image
4070     *newImage;
4071
4072   size_t
4073     height=rows(),
4074     width=columns();
4075
4076   ssize_t
4077     x=0,
4078     y=0;
4079
4080   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4081     &height);
4082
4083   GetPPException;
4084   newImage=SampleImage(constImage(),width,height,&exceptionInfo);
4085   replaceImage(newImage);
4086   ThrowPPException;
4087 }
4088
4089 void Magick::Image::scale(const Geometry &geometry_)
4090 {
4091   MagickCore::Image
4092     *newImage;
4093
4094   size_t
4095     height=rows(),
4096     width=columns();
4097
4098   ssize_t
4099     x=0,
4100     y=0;
4101
4102   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4103     &height);
4104
4105   GetPPException;
4106   newImage=ScaleImage(constImage(),width,height,&exceptionInfo);
4107   replaceImage(newImage);
4108   ThrowPPException;
4109 }
4110
4111 void Magick::Image::segment(const double clusterThreshold_,
4112   const double smoothingThreshold_)
4113 {
4114   modifyImage();
4115   GetPPException;
4116   SegmentImage(image(),options()->quantizeColorSpace(),
4117     (MagickBooleanType) options()->verbose(),clusterThreshold_,
4118     smoothingThreshold_,&exceptionInfo);
4119   SyncImage(image(),&exceptionInfo);
4120   ThrowPPException;
4121 }
4122
4123 void Magick::Image::selectiveBlur(const double radius_,const double sigma_,
4124   const double threshold_)
4125 {
4126   MagickCore::Image
4127     *newImage;
4128
4129   GetPPException;
4130   newImage=SelectiveBlurImage(constImage(),radius_,sigma_,threshold_,
4131     &exceptionInfo);
4132   replaceImage(newImage);
4133   ThrowPPException;
4134 }
4135
4136 void Magick::Image::selectiveBlurChannel(const ChannelType channel_,
4137   const double radius_,const double sigma_,const double threshold_)
4138 {
4139   MagickCore::Image
4140     *newImage;
4141
4142   GetPPException;
4143   SetPPChannelMask(channel_);
4144   newImage=SelectiveBlurImage(constImage(),radius_,sigma_,threshold_,
4145     &exceptionInfo);
4146   RestorePPChannelMask;
4147   replaceImage(newImage);
4148   ThrowPPException;
4149 }
4150
4151 Magick::Image Magick::Image::separate(const ChannelType channel_)
4152 {
4153   MagickCore::Image
4154     *image;
4155
4156   GetPPException;
4157   image=SeparateImage(constImage(),channel_,&exceptionInfo);
4158   ThrowPPException;
4159   if (image == (MagickCore::Image *) NULL)
4160     return(Magick::Image());
4161   else
4162     return(Magick::Image(image));
4163 }
4164
4165 void Magick::Image::sepiaTone(const double threshold_)
4166 {
4167   MagickCore::Image
4168     *newImage;
4169
4170   GetPPException;
4171   newImage=SepiaToneImage(constImage(),threshold_,&exceptionInfo);
4172   replaceImage(newImage);
4173   ThrowPPException;
4174 }
4175
4176 Magick::Quantum *Magick::Image::setPixels(const ssize_t x_,const ssize_t y_,
4177   const size_t columns_,const size_t rows_)
4178 {
4179   Quantum
4180     *result;
4181
4182   modifyImage();
4183   GetPPException;
4184   result=(*QueueAuthenticPixels)(image(),x_,y_,columns_,rows_,&exceptionInfo);
4185   ThrowPPException;
4186   return(result);
4187 }
4188
4189 void Magick::Image::shade(const double azimuth_,const double elevation_,
4190   const bool colorShading_)
4191 {
4192   MagickCore::Image
4193     *newImage;
4194
4195   GetPPException;
4196   newImage=ShadeImage(constImage(),colorShading_ == true ?
4197     MagickTrue : MagickFalse,azimuth_,elevation_,&exceptionInfo);
4198   replaceImage(newImage);
4199   ThrowPPException;
4200 }
4201
4202 void Magick::Image::shadow(const double percent_opacity_,const double sigma_,
4203   const ssize_t x_,const ssize_t y_)
4204 {
4205   MagickCore::Image
4206     *newImage;
4207
4208   GetPPException;
4209   newImage=ShadowImage(constImage(),percent_opacity_, sigma_,x_, y_,
4210     &exceptionInfo);
4211   replaceImage(newImage);
4212   ThrowPPException;
4213 }
4214
4215 void Magick::Image::sharpen(const double radius_,const double sigma_)
4216 {
4217   MagickCore::Image
4218     *newImage;
4219
4220   GetPPException;
4221   newImage=SharpenImage(constImage(),radius_,sigma_,&exceptionInfo);
4222   replaceImage(newImage);
4223   ThrowPPException;
4224 }
4225
4226 void Magick::Image::sharpenChannel(const ChannelType channel_,
4227   const double radius_,const double sigma_)
4228 {
4229   MagickCore::Image
4230     *newImage;
4231
4232   GetPPException;
4233   SetPPChannelMask(channel_);
4234   newImage=SharpenImage(constImage(),radius_,sigma_,&exceptionInfo);
4235   RestorePPChannelMask;
4236   replaceImage(newImage);
4237   ThrowPPException;
4238 }
4239
4240 void Magick::Image::shave(const Geometry &geometry_)
4241 {
4242   MagickCore::Image
4243     *newImage;
4244
4245   RectangleInfo
4246     shaveInfo=geometry_;
4247
4248   GetPPException;
4249   newImage=ShaveImage(constImage(),&shaveInfo,&exceptionInfo);
4250   replaceImage(newImage);
4251   ThrowPPException;
4252 }
4253
4254 void Magick::Image::shear(const double xShearAngle_,const double yShearAngle_)
4255 {
4256   MagickCore::Image
4257     *newImage;
4258
4259   GetPPException;
4260   newImage=ShearImage(constImage(),xShearAngle_,yShearAngle_,&exceptionInfo);
4261   replaceImage(newImage);
4262   ThrowPPException;
4263 }
4264
4265 void Magick::Image::sigmoidalContrast(const size_t sharpen_,
4266   const double contrast,const double midpoint)
4267 {
4268   modifyImage();
4269   GetPPException;
4270   (void) SigmoidalContrastImage(image(),(MagickBooleanType) sharpen_,contrast,
4271     midpoint,&exceptionInfo);
4272   ThrowPPException;
4273 }
4274
4275 std::string Magick::Image::signature(const bool force_) const
4276 {
4277   const char
4278     *property;
4279
4280   Lock(&_imgRef->_mutexLock);
4281
4282   // Re-calculate image signature if necessary
4283   GetPPException;
4284   if (force_ || !GetImageProperty(constImage(),"Signature",&exceptionInfo) ||
4285     constImage()->taint)
4286     SignatureImage(const_cast<MagickCore::Image *>(constImage()),
4287       &exceptionInfo);
4288
4289   property=GetImageProperty(constImage(),"Signature",&exceptionInfo);
4290   ThrowPPException;
4291
4292   return(std::string(property));
4293 }
4294
4295 void Magick::Image::sketch(const double radius_,const double sigma_,
4296   const double angle_)
4297 {
4298   MagickCore::Image
4299     *newImage;
4300
4301   GetPPException;
4302   newImage=SketchImage(constImage(),radius_,sigma_,angle_,&exceptionInfo);
4303   replaceImage(newImage);
4304   ThrowPPException;
4305 }
4306
4307 void Magick::Image::solarize(const double factor_)
4308 {
4309   modifyImage();
4310   GetPPException;
4311   SolarizeImage(image(),factor_,&exceptionInfo);
4312   ThrowPPException;
4313 }
4314
4315 void Magick::Image::sparseColor(const ChannelType channel_,
4316   const SparseColorMethod method_,const size_t numberArguments_,
4317   const double *arguments_)
4318 {
4319   MagickCore::Image
4320     *newImage;
4321
4322   GetPPException;
4323   SetPPChannelMask(channel_);
4324   newImage=SparseColorImage(constImage(),method_,numberArguments_,arguments_,
4325     &exceptionInfo);
4326   RestorePPChannelMask;
4327   replaceImage(newImage);
4328   ThrowPPException;
4329 }
4330
4331 void Magick::Image::splice(const Geometry &geometry_)
4332 {
4333   MagickCore::Image
4334     *newImage;
4335
4336   RectangleInfo
4337     spliceInfo=geometry_;
4338
4339   GetPPException;
4340   newImage=SpliceImage(constImage(),&spliceInfo,&exceptionInfo);
4341   replaceImage(newImage);
4342   ThrowPPException;
4343 }
4344
4345 void Magick::Image::spread(const size_t amount_)
4346 {
4347   MagickCore::Image
4348     *newImage;
4349
4350   GetPPException;
4351   newImage=SpreadImage(constImage(),amount_,image()->interpolate,
4352     &exceptionInfo);
4353   replaceImage(newImage);
4354   ThrowPPException;
4355 }
4356
4357 void Magick::Image::statistics(ImageStatistics *statistics)
4358 {
4359   double
4360     maximum,
4361     minimum;
4362
4363   GetPPException;
4364
4365   SetPPChannelMask(RedChannel);
4366   (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo);
4367   statistics->red.minimum=minimum;
4368   statistics->red.maximum=maximum;
4369   (void) GetImageMean(constImage(),&statistics->red.mean,
4370     &statistics->red.standard_deviation,&exceptionInfo);
4371   (void) GetImageKurtosis(constImage(),&statistics->red.kurtosis,
4372     &statistics->red.skewness,&exceptionInfo);
4373
4374   (void) SetImageChannelMask(image(),GreenChannel);
4375   (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo);
4376   statistics->green.minimum=minimum;
4377   statistics->green.maximum=maximum;
4378   (void) GetImageMean(constImage(),&statistics->green.mean,
4379     &statistics->green.standard_deviation,&exceptionInfo);
4380   (void) GetImageKurtosis(constImage(),&statistics->green.kurtosis,
4381     &statistics->green.skewness,&exceptionInfo);
4382
4383   (void) SetImageChannelMask(image(),GreenChannel);
4384   (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo);
4385   statistics->blue.minimum=minimum;
4386   statistics->blue.maximum=maximum;
4387   (void) GetImageMean(constImage(),&statistics->blue.mean,
4388     &statistics->blue.standard_deviation,&exceptionInfo);
4389   (void) GetImageKurtosis(constImage(),&statistics->blue.kurtosis,
4390     &statistics->blue.skewness,&exceptionInfo);
4391
4392   (void) SetImageChannelMask(image(),AlphaChannel);
4393   (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo);
4394   statistics->alpha.minimum=minimum;
4395   statistics->alpha.maximum=maximum;
4396   (void) GetImageMean(constImage(),&statistics->alpha.mean,
4397     &statistics->alpha.standard_deviation,&exceptionInfo);
4398   (void) GetImageKurtosis(constImage(),&statistics->alpha.kurtosis,
4399     &statistics->alpha.skewness,&exceptionInfo);
4400   RestorePPChannelMask;
4401   ThrowPPException;
4402 }
4403
4404 void Magick::Image::stegano(const Image &watermark_)
4405 {
4406   MagickCore::Image
4407     *newImage;
4408
4409   GetPPException;
4410   newImage=SteganoImage(constImage(),watermark_.constImage(),&exceptionInfo);
4411   replaceImage(newImage);
4412   ThrowPPException;
4413 }
4414
4415 void Magick::Image::stereo(const Image &rightImage_)
4416 {
4417   MagickCore::Image
4418     *newImage;
4419
4420   GetPPException;
4421   newImage=StereoImage(constImage(),rightImage_.constImage(),&exceptionInfo);
4422   replaceImage(newImage);
4423   ThrowPPException;
4424 }
4425
4426 void Magick::Image::strip(void)
4427 {
4428   modifyImage();
4429   GetPPException;
4430   StripImage(image(),&exceptionInfo);
4431   ThrowPPException;
4432 }
4433
4434 Magick::Image Magick::Image::subImageSearch(const Image &reference_,
4435   const MetricType metric_,Geometry *offset_,double *similarityMetric_,
4436   const double similarityThreshold)
4437 {
4438   MagickCore::Image
4439     *newImage;
4440
4441   RectangleInfo
4442     offset;
4443
4444   GetPPException;
4445   newImage=SimilarityImage(image(),reference_.constImage(),metric_,
4446     similarityThreshold,&offset,similarityMetric_,&exceptionInfo);
4447   ThrowPPException;
4448   if (offset_ != (Geometry *) NULL)
4449     *offset_=offset;
4450   if (newImage == (MagickCore::Image *) NULL)
4451     return(Magick::Image());
4452   else
4453     return(Magick::Image(newImage));
4454 }
4455
4456 void Magick::Image::swirl(const double degrees_)
4457 {
4458   MagickCore::Image
4459     *newImage;
4460
4461   GetPPException;
4462   newImage=SwirlImage(constImage(),degrees_,image()->interpolate,
4463     &exceptionInfo);
4464   replaceImage(newImage);
4465   ThrowPPException;
4466 }
4467
4468 void Magick::Image::syncPixels(void)
4469 {
4470   GetPPException;
4471   (void) (*SyncAuthenticPixels)(image(),&exceptionInfo);
4472   ThrowPPException;
4473 }
4474
4475 void Magick::Image::texture(const Image &texture_)
4476 {
4477   modifyImage();
4478   GetPPException;
4479   TextureImage(image(),texture_.constImage(),&exceptionInfo);
4480   ThrowPPException;
4481 }
4482
4483 void Magick::Image::threshold(const double threshold_)
4484 {
4485   modifyImage();
4486   GetPPException;
4487   BilevelImage(image(),threshold_,&exceptionInfo);
4488   ThrowPPException;
4489 }
4490
4491 void Magick::Image::thumbnail(const Geometry &geometry_)
4492 {
4493   MagickCore::Image
4494     *newImage;
4495
4496   size_t
4497     height=rows(),
4498     width=columns();
4499
4500   ssize_t
4501     x=0,
4502     y=0;
4503
4504   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4505     &height);
4506
4507   GetPPException;
4508   newImage=ThumbnailImage(constImage(),width,height,&exceptionInfo);
4509   replaceImage(newImage);
4510   ThrowPPException;
4511 }
4512
4513 void Magick::Image::tint(const std::string opacity_)
4514 {
4515   MagickCore::Image
4516     *newImage;
4517
4518   PixelInfo
4519     color;
4520
4521   GetPPException;
4522   color=static_cast<PixelInfo>(constOptions()->fillColor());
4523   newImage=TintImage(constImage(),opacity_.c_str(),&color,&exceptionInfo);
4524   replaceImage(newImage);
4525   ThrowPPException;
4526 }
4527
4528 void Magick::Image::transform(const Geometry &imageGeometry_)
4529 {
4530   modifyImage();
4531   GetPPException;
4532   TransformImage(&(image()),0,std::string(imageGeometry_).c_str(),
4533     &exceptionInfo);
4534   ThrowPPException;
4535 }
4536
4537 void Magick::Image::transform(const Geometry &imageGeometry_,
4538   const Geometry &cropGeometry_)
4539 {
4540   modifyImage();
4541   GetPPException;
4542   TransformImage(&(image()),std::string(cropGeometry_).c_str(),std::string(
4543     imageGeometry_).c_str(), &exceptionInfo);
4544   ThrowPPException;
4545 }
4546
4547 void Magick::Image::transformOrigin(const double x_,const double y_)
4548 {
4549   modifyImage();
4550   options()->transformOrigin(x_,y_);
4551 }
4552
4553 void Magick::Image::transformReset(void)
4554 {
4555   modifyImage();
4556   options()->transformReset();
4557 }
4558
4559 void Magick::Image::transformScale(const double sx_,const double sy_)
4560 {
4561   modifyImage();
4562   options()->transformScale(sx_,sy_);
4563 }
4564
4565 void Magick::Image::transparent(const Color &color_)
4566 {
4567   PixelInfo
4568     target;
4569
4570   std::string
4571     color;
4572
4573   if (!color_.isValid())
4574     throwExceptionExplicit(OptionError,"Color argument is invalid");
4575
4576   color=color_;
4577   GetPPException;
4578   (void) QueryColorCompliance(color.c_str(),AllCompliance,&target,
4579     &exceptionInfo);
4580   modifyImage();
4581   TransparentPaintImage(image(),&target,TransparentAlpha,MagickFalse,
4582     &exceptionInfo);
4583   ThrowPPException;
4584 }
4585
4586 void Magick::Image::transparentChroma(const Color &colorLow_,
4587   const Color &colorHigh_)
4588 {
4589   std::string
4590     colorHigh,
4591     colorLow;
4592
4593   PixelInfo
4594     targetHigh,
4595     targetLow;
4596
4597   if (!colorLow_.isValid() || !colorHigh_.isValid())
4598     throwExceptionExplicit(OptionError,"Color argument is invalid");
4599
4600   colorLow=colorLow_;
4601   colorHigh=colorHigh_;
4602
4603   GetPPException;
4604   (void) QueryColorCompliance(colorLow.c_str(),AllCompliance,&targetLow,
4605     &exceptionInfo);
4606   (void) QueryColorCompliance(colorHigh.c_str(),AllCompliance,&targetHigh,
4607     &exceptionInfo);
4608   modifyImage();
4609   TransparentPaintImageChroma(image(),&targetLow,&targetHigh,TransparentAlpha,
4610     MagickFalse,&exceptionInfo);
4611   ThrowPPException;
4612 }
4613
4614 void Magick::Image::transpose(void)
4615 {
4616   MagickCore::Image
4617     *newImage;
4618
4619   GetPPException;
4620   newImage=TransposeImage(constImage(),&exceptionInfo);
4621   replaceImage(newImage);
4622   ThrowPPException;
4623 }
4624
4625 void Magick::Image::transverse(void)
4626 {
4627   MagickCore::Image
4628     *newImage;
4629
4630   GetPPException;
4631   newImage=TransverseImage(constImage(),&exceptionInfo);
4632   replaceImage(newImage);
4633   ThrowPPException;
4634 }
4635
4636 void Magick::Image::trim(void)
4637 {
4638   MagickCore::Image
4639     *newImage;
4640
4641   GetPPException;
4642   newImage=TrimImage(constImage(),&exceptionInfo);
4643   replaceImage(newImage);
4644   ThrowPPException;
4645 }
4646
4647 Magick::Image Magick::Image::uniqueColors(void)
4648 {
4649   MagickCore::Image
4650     *image;
4651
4652   GetPPException;
4653   image=UniqueImageColors(constImage(),&exceptionInfo);
4654   ThrowPPException;
4655   if (image == (MagickCore::Image *) NULL)
4656     return(Magick::Image());
4657   else
4658     return(Magick::Image(image));
4659 }
4660
4661 void Magick::Image::unsharpmask(const double radius_,const double sigma_,
4662   const double amount_,const double threshold_)
4663 {
4664   MagickCore::Image
4665     *newImage;
4666
4667   GetPPException;
4668   newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_,
4669     &exceptionInfo);
4670   replaceImage(newImage);
4671   ThrowPPException;
4672 }
4673
4674 void Magick::Image::unsharpmaskChannel(const ChannelType channel_,
4675   const double radius_,const double sigma_,const double amount_,
4676   const double threshold_)
4677 {
4678   MagickCore::Image
4679     *newImage;
4680
4681   GetPPException;
4682   SetPPChannelMask(channel_);
4683   newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_,
4684     &exceptionInfo);
4685   RestorePPChannelMask;
4686   replaceImage(newImage);
4687   ThrowPPException;
4688 }
4689
4690 void Magick::Image::vignette(const double radius_,const double sigma_,
4691   const ssize_t x_,const ssize_t y_)
4692 {
4693   MagickCore::Image
4694     *newImage;
4695
4696   GetPPException;
4697   newImage=VignetteImage(constImage(),radius_,sigma_,x_,y_,&exceptionInfo);
4698   replaceImage(newImage);
4699   ThrowPPException;
4700 }
4701
4702 void Magick::Image::wave(const double amplitude_,const double wavelength_)
4703 {
4704   MagickCore::Image
4705     *newImage;
4706
4707   GetPPException;
4708   newImage=WaveImage(constImage(),amplitude_,wavelength_,image()->interpolate,
4709     &exceptionInfo);
4710   replaceImage(newImage);
4711   ThrowPPException;
4712 }
4713
4714 void Magick::Image::whiteThreshold(const std::string &threshold_)
4715 {
4716   modifyImage();
4717   GetPPException;
4718   WhiteThresholdImage(image(),threshold_.c_str(),&exceptionInfo);
4719   ThrowPPException;
4720 }
4721
4722 void Magick::Image::whiteThresholdChannel(const ChannelType channel_,
4723   const std::string &threshold_)
4724 {
4725   modifyImage();
4726   GetPPException;
4727   SetPPChannelMask(channel_);
4728   WhiteThresholdImage(image(),threshold_.c_str(),&exceptionInfo);
4729   RestorePPChannelMask;
4730   ThrowPPException;
4731 }
4732
4733 void Magick::Image::write(Blob *blob_)
4734 {
4735   size_t
4736     length=0;
4737
4738   void
4739     *data;
4740
4741   modifyImage();
4742   GetPPException;
4743   data=ImagesToBlob(constImageInfo(),image(),&length,&exceptionInfo);
4744   if (length > 0)
4745     blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4746   ThrowPPException;
4747 }
4748
4749 void Magick::Image::write(Blob *blob_,const std::string &magick_)
4750 {
4751   size_t
4752     length=0;
4753
4754   void
4755     *data;
4756
4757   modifyImage();
4758   magick(magick_);
4759   GetPPException;
4760   data=ImagesToBlob(constImageInfo(),image(),&length,&exceptionInfo);
4761   if (length > 0)
4762     blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4763   ThrowPPException;
4764 }
4765
4766 void Magick::Image::write(Blob *blob_,const std::string &magick_,
4767   const size_t depth_)
4768 {
4769   size_t
4770     length=0;
4771
4772   void
4773     *data;
4774
4775   modifyImage();
4776   magick(magick_);
4777   depth(depth_);
4778   GetPPException;
4779   data=ImagesToBlob(constImageInfo(),image(),&length,&exceptionInfo);
4780   if (length > 0)
4781     blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4782   ThrowPPException;
4783 }
4784
4785 void Magick::Image::write(const ssize_t x_,const ssize_t y_,
4786   const size_t columns_,const size_t rows_,const std::string &map_,
4787   const StorageType type_,void *pixels_)
4788 {
4789   GetPPException;
4790   ExportImagePixels(image(),x_,y_,columns_,rows_,map_.c_str(),type_,pixels_,
4791     &exceptionInfo);
4792   ThrowPPException;
4793 }
4794
4795 void Magick::Image::write(const std::string &imageSpec_)
4796 {
4797   modifyImage();
4798   fileName(imageSpec_);
4799   GetPPException;
4800   WriteImage(constImageInfo(),image(),&exceptionInfo);
4801   ThrowPPException;
4802 }
4803
4804 void Magick::Image::writePixels(const Magick::QuantumType quantum_,
4805   unsigned char *destination_)
4806 {
4807   QuantumInfo
4808     *quantum_info;
4809
4810   quantum_info=AcquireQuantumInfo(imageInfo(),image());
4811   GetPPException;
4812   ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4813     quantum_,destination_, &exceptionInfo);
4814   quantum_info=DestroyQuantumInfo(quantum_info);
4815   ThrowPPException;
4816 }
4817
4818 void Magick::Image::zoom(const Geometry &geometry_)
4819 {
4820   MagickCore::Image
4821     *newImage;
4822
4823   size_t
4824     height=rows(),
4825     width=columns();
4826
4827   ssize_t
4828     x=0,
4829     y=0;
4830
4831   ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4832     &height);
4833
4834   GetPPException;
4835   newImage=ResizeImage(constImage(),width,height,image()->filter,&exceptionInfo);
4836   replaceImage(newImage);
4837   ThrowPPException;
4838 }
4839
4840 Magick::Image::Image(MagickCore::Image *image_)
4841   : _imgRef(new ImageRef(image_))
4842 {
4843 }
4844
4845 MagickCore::Image *&Magick::Image::image(void)
4846 {
4847   return(_imgRef->image());
4848 }
4849
4850 const MagickCore::Image *Magick::Image::constImage(void) const
4851 {
4852   return(_imgRef->image());
4853 }
4854
4855 MagickCore::ImageInfo *Magick::Image::imageInfo(void)
4856 {
4857   return(_imgRef->options()->imageInfo());
4858 }
4859
4860 const MagickCore::ImageInfo *Magick::Image::constImageInfo(void) const
4861 {
4862   return(_imgRef->options()->imageInfo());
4863 }
4864
4865 Magick::Options *Magick::Image::options(void)
4866 {
4867   return(_imgRef->options());
4868 }
4869
4870 const Magick::Options *Magick::Image::constOptions(void) const
4871 {
4872   return(_imgRef->options());
4873 }
4874
4875 MagickCore::QuantizeInfo *Magick::Image::quantizeInfo(void)
4876 {
4877   return(_imgRef->options()->quantizeInfo());
4878 }
4879
4880 const MagickCore::QuantizeInfo *Magick::Image::constQuantizeInfo(void) const
4881 {
4882   return(_imgRef->options()->quantizeInfo());
4883 }
4884
4885 void Magick::Image::modifyImage(void)
4886 {
4887   {
4888     Lock(&_imgRef->_mutexLock);
4889     if (_imgRef->_refCount == 1)
4890       {
4891         // De-register image and return
4892         _imgRef->id(-1);
4893         return;
4894       }
4895   }
4896
4897   GetPPException;
4898   replaceImage(CloneImage(image(),0,0,MagickTrue,&exceptionInfo));
4899   ThrowPPException;
4900 }
4901
4902 ssize_t Magick::Image::registerId(void)
4903 {
4904   Lock(&_imgRef->_mutexLock);
4905   if ( _imgRef->id() < 0)
4906     {
4907       char
4908         id[MaxTextExtent];
4909
4910       GetPPException;
4911       _imgRef->id(_imgRef->id()+1);
4912       sprintf(id,"%.20g\n",(double) _imgRef->id());
4913       SetImageRegistry(ImageRegistryType,id,image(),&exceptionInfo);
4914       ThrowPPException;
4915     }
4916   return(_imgRef->id());
4917 }
4918
4919 MagickCore::Image *Magick::Image::replaceImage(MagickCore::Image *replacement_)
4920 {
4921   MagickCore::Image
4922     *image;
4923
4924   if (replacement_)
4925     image = replacement_;
4926   else
4927     {
4928       GetPPException;
4929       image=AcquireImage(constImageInfo(),&exceptionInfo);
4930       ThrowPPException;
4931     }
4932
4933   {
4934     Lock(&_imgRef->_mutexLock);
4935
4936     if (_imgRef->_refCount == 1)
4937       {
4938         // We own the image, just replace it, and de-register
4939         _imgRef->id(-1);
4940         _imgRef->image(image);
4941       }
4942     else
4943       {
4944         // We don't own the image, dereference and replace with copy
4945         --_imgRef->_refCount;
4946         _imgRef=new ImageRef(image,constOptions());
4947       }
4948   }
4949
4950   return(_imgRef->_image);
4951 }
4952
4953 void Magick::Image::unregisterId(void)
4954 {
4955   modifyImage();
4956   _imgRef->id(-1);
4957 }