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