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