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