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