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