1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Implementation of Image
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11 #include "Magick++/Include.h"
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"
26 #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
27 #define DegreesToRadians(x) (MagickPI*(x)/180.0)
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";
33 static bool magick_initialized=false;
36 // Explicit template instantiations
40 // Friend functions to compare Image objects
43 MagickPPExport int Magick::operator == ( const Magick::Image& left_,
44 const Magick::Image& right_ )
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() )
52 MagickPPExport int Magick::operator != ( const Magick::Image& left_,
53 const Magick::Image& right_ )
55 return ( ! (left_ == right_) );
57 MagickPPExport int Magick::operator > ( const Magick::Image& left_,
58 const Magick::Image& right_ )
60 return ( !( left_ < right_ ) && ( left_ != right_ ) );
62 MagickPPExport int Magick::operator < ( const Magick::Image& left_,
63 const Magick::Image& right_ )
65 // If image pixels are less, then image is smaller
66 return ( ( left_.rows() * left_.columns() ) <
67 ( right_.rows() * right_.columns() )
70 MagickPPExport int Magick::operator >= ( const Magick::Image& left_,
71 const Magick::Image& right_ )
73 return ( ( left_ > right_ ) || ( left_ == right_ ) );
75 MagickPPExport int Magick::operator <= ( const Magick::Image& left_,
76 const Magick::Image& right_ )
78 return ( ( left_ < right_ ) || ( left_ == right_ ) );
82 // Image object implementation
85 // Construct from image file or image specification
86 Magick::Image::Image( const std::string &imageSpec_ )
87 : _imgRef(new ImageRef)
91 // Initialize, Allocate and Read images
94 catch ( const Warning & /*warning_*/ )
96 // FIXME: need a way to report warnings in constructor
98 catch ( const Error & /*error_*/ )
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)
111 // xc: prefix specifies an X11 color string
112 std::string imageSpec("xc:");
120 // Initialize, Allocate and Read images
123 catch ( const Warning & /*warning_*/ )
125 // FIXME: need a way to report warnings in constructor
127 catch ( const Error & /*error_*/ )
135 // Construct Image from in-memory BLOB
136 Magick::Image::Image ( const Blob &blob_ )
137 : _imgRef(new ImageRef)
141 // Initialize, Allocate and Read images
144 catch ( const Warning & /*warning_*/ )
146 // FIXME: need a way to report warnings in constructor
148 catch ( const Error & /*error_*/ )
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)
164 read( blob_, size_ );
166 catch ( const Warning & /*warning_*/ )
168 // FIXME: need a way to report warnings in constructor
170 catch ( const Error & /*error_*/ )
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)
187 read( blob_, size_, depth_ );
189 catch ( const Warning & /*warning_*/ )
191 // FIXME: need a way to report warnings in constructor
193 catch ( const Error & /*error_*/ )
201 // Construct Image of specified size, depth, and format from in-memory BLOB
202 Magick::Image::Image ( const Blob &blob_,
203 const Geometry &size_,
205 const std::string &magick_ )
206 : _imgRef(new ImageRef)
211 read( blob_, size_, depth_, magick_ );
213 catch ( const Warning & /*warning_*/ )
215 // FIXME: need a way to report warnings in constructor
217 catch ( const Error & /*error_*/ )
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)
234 read( blob_, size_, magick_ );
236 catch ( const Warning & /*warning_*/ )
238 // FIXME: need a way to report warnings in constructor
240 catch ( const Error & /*error_*/ )
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)
259 read( width_, height_, map_.c_str(), type_, pixels_ );
261 catch ( const Warning & /*warning_*/ )
263 // FIXME: need a way to report warnings in constructor
265 catch ( const Error & /*error_*/ )
273 // Default constructor
274 Magick::Image::Image( void )
275 : _imgRef(new ImageRef)
281 Magick::Image::~Image()
283 bool doDelete = false;
285 Lock( &_imgRef->_mutexLock );
286 if ( --_imgRef->_refCount == 0 )
297 // Adaptive-blur image
298 void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
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 );
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_ )
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 );
326 // Add noise to image
327 void Magick::Image::addNoise( const NoiseType noiseType_ )
329 ExceptionInfo exceptionInfo;
330 GetExceptionInfo( &exceptionInfo );
331 MagickCore::Image* newImage =
332 AddNoiseImage ( image(),
335 replaceImage( newImage );
336 throwException( exceptionInfo );
337 (void) DestroyExceptionInfo( &exceptionInfo );
340 void Magick::Image::addNoiseChannel( const ChannelType channel_,
341 const NoiseType noiseType_ )
343 ExceptionInfo exceptionInfo;
344 GetExceptionInfo( &exceptionInfo );
345 ChannelType channel_mask = SetImageChannelMask( image(), channel_);
346 MagickCore::Image* newImage =
347 AddNoiseImage ( image(),
350 (void) SetPixelChannelMask( image(), channel_mask );
351 replaceImage( newImage );
352 throwException( exceptionInfo );
353 (void) DestroyExceptionInfo( &exceptionInfo );
356 // Affine Transform image
357 void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
359 ExceptionInfo exceptionInfo;
360 GetExceptionInfo( &exceptionInfo );
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();
370 MagickCore::Image* newImage =
371 AffineTransformImage( image(), &_affine, &exceptionInfo);
372 replaceImage( newImage );
373 throwException( exceptionInfo );
374 (void) DestroyExceptionInfo( &exceptionInfo );
377 // Annotate using specified text, and placement location
378 void Magick::Image::annotate ( const std::string &text_,
379 const Geometry &location_ )
381 annotate ( text_, location_, NorthWestGravity, 0.0 );
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_ )
388 annotate ( text_, boundingArea_, gravity_, 0.0 );
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_ )
400 = options()->drawInfo();
402 drawInfo->text = const_cast<char *>(text_.c_str());
404 char boundingArea[MaxTextExtent];
406 drawInfo->geometry = 0;
407 if ( boundingArea_.isValid() ){
408 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
410 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
411 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
415 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
418 drawInfo->geometry = boundingArea;
421 drawInfo->gravity = gravity_;
423 AffineMatrix oaffine = drawInfo->affine;
424 if ( degrees_ != 0.0)
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)));
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
448 ExceptionInfo exceptionInfo;
449 GetExceptionInfo( &exceptionInfo );
450 AnnotateImage( image(), drawInfo, &exceptionInfo );
452 // Restore original values
453 drawInfo->affine = oaffine;
455 drawInfo->geometry = 0;
457 throwException( exceptionInfo );
458 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
467 = options()->drawInfo();
469 drawInfo->text = const_cast<char *>(text_.c_str());
471 drawInfo->gravity = gravity_;
473 ExceptionInfo exceptionInfo;
474 GetExceptionInfo( &exceptionInfo );
475 AnnotateImage( image(), drawInfo, &exceptionInfo );
477 drawInfo->gravity = NorthWestGravity;
480 throwException( exceptionInfo );
481 (void) DestroyExceptionInfo( &exceptionInfo );
485 void Magick::Image::blur( const double radius_, const double sigma_ )
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 );
496 void Magick::Image::blurChannel( const ChannelType channel_,
497 const double radius_, const double sigma_ )
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 );
510 // Add border to image
511 // Only uses width & height
512 void Magick::Image::border( const Geometry &geometry_ )
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 );
524 // Extract channel from image
525 void Magick::Image::channel ( const ChannelType channel_ )
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 );
537 // Set or obtain modulus channel depth
538 void Magick::Image::channelDepth ( const size_t depth_ )
541 ExceptionInfo exceptionInfo;
542 GetExceptionInfo( &exceptionInfo );
543 SetImageDepth( image(), depth_, &exceptionInfo);
544 throwException( exceptionInfo );
545 (void) DestroyExceptionInfo( &exceptionInfo );
547 size_t Magick::Image::channelDepth ( )
549 size_t channel_depth;
551 ExceptionInfo exceptionInfo;
552 GetExceptionInfo( &exceptionInfo );
553 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
554 throwException( exceptionInfo );
555 (void) DestroyExceptionInfo( &exceptionInfo );
556 return channel_depth;
560 // Charcoal-effect image
561 void Magick::Image::charcoal( const double radius_, const double sigma_ )
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 );
573 void Magick::Image::chop( const Geometry &geometry_ )
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 );
585 // contains one or more color corrections and applies the correction to the
587 void Magick::Image::cdl ( const std::string &cdl_ )
590 ExceptionInfo exceptionInfo;
591 GetExceptionInfo( &exceptionInfo );
592 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
593 throwException( exceptionInfo );
594 (void) DestroyExceptionInfo( &exceptionInfo );
598 void Magick::Image::colorize ( const unsigned int alphaRed_,
599 const unsigned int alphaGreen_,
600 const unsigned int alphaBlue_,
601 const Color &penColor_ )
603 if ( !penColor_.isValid() )
605 throwExceptionExplicit( OptionError,
606 "Pen color argument is invalid");
609 char blend[MaxTextExtent];
610 FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
612 ExceptionInfo exceptionInfo;
613 GetExceptionInfo( &exceptionInfo );
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 );
627 void Magick::Image::colorize ( const unsigned int alpha_,
628 const Color &penColor_ )
630 colorize( alpha_, alpha_, alpha_, penColor_ );
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_)
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)
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 );
656 kernel_info=DestroyKernelInfo(kernel_info);
657 throwException( exceptionInfo );
658 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
666 ExceptionInfo exceptionInfo;
667 GetExceptionInfo( &exceptionInfo );
669 Image ref = reference_;
672 static_cast<bool>(IsImagesEqual(image(), ref.image(), &exceptionInfo));
673 throwException( exceptionInfo );
674 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
684 // Image supplied as compositeImage is composited with current image and
685 // results in updating current image.
688 ExceptionInfo exceptionInfo;
689 GetExceptionInfo( &exceptionInfo );
690 CompositeImage( image(),
691 compositeImage_.constImage(),
692 compose_, MagickFalse,
694 yOffset_, &exceptionInfo );
695 throwException( exceptionInfo );
696 (void) DestroyExceptionInfo( &exceptionInfo );
698 void Magick::Image::composite ( const Image &compositeImage_,
699 const Geometry &offset_,
700 const CompositeOperator compose_ )
704 ssize_t x = offset_.xOff();
705 ssize_t y = offset_.yOff();
706 size_t width = columns();
707 size_t height = rows();
709 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
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 );
722 void Magick::Image::composite ( const Image &compositeImage_,
723 const GravityType gravity_,
724 const CompositeOperator compose_ )
728 RectangleInfo geometry;
730 SetGeometry(compositeImage_.constImage(), &geometry);
731 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
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 );
744 void Magick::Image::contrast ( const size_t sharpen_ )
747 ExceptionInfo exceptionInfo;
748 GetExceptionInfo( &exceptionInfo );
749 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
750 throwException( exceptionInfo );
751 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
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)
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 );
778 kernel_info=DestroyKernelInfo(kernel_info);
779 throwException( exceptionInfo );
780 (void) DestroyExceptionInfo( &exceptionInfo );
784 void Magick::Image::crop ( const Geometry &geometry_ )
786 RectangleInfo cropInfo = geometry_;
787 ExceptionInfo exceptionInfo;
788 GetExceptionInfo( &exceptionInfo );
789 MagickCore::Image* newImage =
793 replaceImage( newImage );
794 throwException( exceptionInfo );
795 (void) DestroyExceptionInfo( &exceptionInfo );
799 void Magick::Image::cycleColormap ( const ssize_t amount_ )
801 ExceptionInfo exceptionInfo;
802 GetExceptionInfo( &exceptionInfo );
804 CycleColormapImage( image(), amount_, &exceptionInfo );
805 throwException( exceptionInfo );
806 (void) DestroyExceptionInfo( &exceptionInfo );
810 void Magick::Image::despeckle ( void )
812 ExceptionInfo exceptionInfo;
813 GetExceptionInfo( &exceptionInfo );
814 MagickCore::Image* newImage =
815 DespeckleImage( image(), &exceptionInfo );
816 replaceImage( newImage );
817 throwException( exceptionInfo );
818 (void) DestroyExceptionInfo( &exceptionInfo );
822 void Magick::Image::display( void )
824 ExceptionInfo exceptionInfo;
825 GetExceptionInfo( &exceptionInfo );
826 DisplayImages( imageInfo(), image(), &exceptionInfo );
827 throwException( exceptionInfo );
828 (void) DestroyExceptionInfo( &exceptionInfo );
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
835 void Magick::Image::distort ( const DistortImageMethod method_,
836 const size_t number_arguments_,
837 const double *arguments_,
838 const bool bestfit_ )
840 ExceptionInfo exceptionInfo;
841 GetExceptionInfo( &exceptionInfo );
842 MagickCore::Image* newImage = DistortImage ( image(), method_,
843 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
845 replaceImage( newImage );
846 throwException( exceptionInfo );
847 (void) DestroyExceptionInfo( &exceptionInfo );
850 // Draw on image using single drawable
851 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
855 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
859 drawable_.operator()(wand);
863 wand=DestroyDrawingWand(wand);
866 throwImageException();
869 // Draw on image using a drawable list
870 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
874 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
878 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
879 p != drawable_.end(); p++ )
886 wand=DestroyDrawingWand(wand);
889 throwImageException();
892 // Hilight edges in image
893 void Magick::Image::edge ( const double radius_, const double sigma_ )
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 );
904 // Emboss image (hilight edges)
905 void Magick::Image::emboss ( const double radius_, const double sigma_ )
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 );
916 // Enhance image (minimize noise)
917 void Magick::Image::enhance ( void )
919 ExceptionInfo exceptionInfo;
920 GetExceptionInfo( &exceptionInfo );
921 MagickCore::Image* newImage =
922 EnhanceImage( image(), &exceptionInfo );
923 replaceImage( newImage );
924 throwException( exceptionInfo );
925 (void) DestroyExceptionInfo( &exceptionInfo );
928 // Equalize image (histogram equalization)
929 void Magick::Image::equalize ( void )
931 ExceptionInfo exceptionInfo;
932 GetExceptionInfo( &exceptionInfo );
934 EqualizeImage( image(), &exceptionInfo );
935 throwException( exceptionInfo );
936 (void) DestroyExceptionInfo( &exceptionInfo );
939 // Erase image to current "background color"
940 void Magick::Image::erase ( void )
943 ExceptionInfo exceptionInfo;
944 GetExceptionInfo( &exceptionInfo );
945 SetImageBackgroundColor( image(), &exceptionInfo );
946 throwException( exceptionInfo );
947 (void) DestroyExceptionInfo( &exceptionInfo );
950 // Extends image as defined by the geometry.
952 void Magick::Image::extent ( const Geometry &geometry_ )
954 RectangleInfo extentInfo = geometry_;
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 );
964 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
966 backgroundColor ( backgroundColor_ );
967 extent ( geometry_ );
969 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
971 RectangleInfo geometry;
973 SetGeometry(image(), &geometry);
974 GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry);
975 extent ( geometry_ );
977 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
979 image()->gravity = gravity_;
980 backgroundColor ( backgroundColor_ );
981 extent ( geometry_ );
984 // Flip image (reflect each scanline in the vertical direction)
985 void Magick::Image::flip ( void )
987 ExceptionInfo exceptionInfo;
988 GetExceptionInfo( &exceptionInfo );
989 MagickCore::Image* newImage =
990 FlipImage( image(), &exceptionInfo );
991 replaceImage( newImage );
992 throwException( exceptionInfo );
993 (void) DestroyExceptionInfo( &exceptionInfo );
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_,
1001 const Magick::Color &fillColor_ )
1003 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
1005 void Magick::Image::floodFillColor( const Geometry &point_,
1006 const Magick::Color &fillColor_ )
1008 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
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_,
1016 const Magick::Color &fillColor_,
1017 const Magick::Color &borderColor_ )
1019 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
1022 void Magick::Image::floodFillColor( const Geometry &point_,
1023 const Magick::Color &fillColor_,
1024 const Magick::Color &borderColor_ )
1026 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
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_,
1034 const unsigned int alpha_,
1035 const PaintMethod method_ )
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
1050 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
1051 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1053 throwException( exceptionInfo );
1054 (void) DestroyExceptionInfo( &exceptionInfo );
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_,
1062 const Magick::Image &texture_ )
1066 // Set drawing pattern
1067 options()->fillPattern(texture_.constImage());
1070 Pixels pixels(*this);
1072 Quantum *p = pixels.get(x_, y_, 1, 1 );
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 );
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
1088 throwException( exceptionInfo );
1089 (void) DestroyExceptionInfo( &exceptionInfo );
1092 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1093 const Magick::Image &texture_ )
1095 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
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_,
1103 const Magick::Image &texture_,
1104 const Magick::Color &borderColor_ )
1108 // Set drawing fill pattern
1109 options()->fillPattern(texture_.constImage());
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(),
1121 static_cast<ssize_t>(x_),
1122 static_cast<ssize_t>(y_),
1123 MagickTrue, &exceptionInfo);
1125 throwException( exceptionInfo );
1126 (void) DestroyExceptionInfo( &exceptionInfo );
1128 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1129 const Magick::Image &texture_,
1130 const Magick::Color &borderColor_ )
1132 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1135 // Flop image (reflect each scanline in the horizontal direction)
1136 void Magick::Image::flop ( void )
1138 ExceptionInfo exceptionInfo;
1139 GetExceptionInfo( &exceptionInfo );
1140 MagickCore::Image* newImage =
1141 FlopImage( image(), &exceptionInfo );
1142 replaceImage( newImage );
1143 throwException( exceptionInfo );
1144 (void) DestroyExceptionInfo( &exceptionInfo );
1148 void Magick::Image::frame ( const Geometry &geometry_ )
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();
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 );
1167 void Magick::Image::frame ( const size_t width_,
1168 const size_t height_,
1169 const ssize_t outerBevel_, const ssize_t innerBevel_ )
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_);
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 );
1188 // Fx image. Applies a mathematical expression to the image.
1189 void Magick::Image::fx ( const std::string expression )
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 );
1199 void Magick::Image::fx ( const std::string expression,
1200 const Magick::ChannelType channel )
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 );
1213 // Gamma correct image
1214 void Magick::Image::gamma ( const double gamma_ )
1216 ExceptionInfo exceptionInfo;
1217 GetExceptionInfo( &exceptionInfo );
1219 GammaImage ( image(), gamma_, &exceptionInfo );
1220 throwException( exceptionInfo );
1221 (void) DestroyExceptionInfo( &exceptionInfo );
1224 void Magick::Image::gamma ( const double gammaRed_,
1225 const double gammaGreen_,
1226 const double gammaBlue_ )
1228 char gamma[MaxTextExtent + 1];
1229 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1230 gammaRed_, gammaGreen_, gammaBlue_);
1232 ExceptionInfo exceptionInfo;
1233 GetExceptionInfo( &exceptionInfo );
1235 GammaImage ( image(), atof(gamma), &exceptionInfo );
1236 throwException( exceptionInfo );
1237 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
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 );
1255 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1256 const double width_,
1257 const double sigma_ )
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 );
1270 // Apply a color lookup table (Hald CLUT) to the image.
1271 void Magick::Image::haldClut ( const Image &clutImage_ )
1273 ExceptionInfo exceptionInfo;
1274 GetExceptionInfo( &exceptionInfo );
1276 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1277 throwException( exceptionInfo );
1278 (void) DestroyExceptionInfo( &exceptionInfo );
1282 void Magick::Image::implode ( const double factor_ )
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 );
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_ )
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 );
1305 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1306 const bool magnitude_ )
1308 ExceptionInfo exceptionInfo;
1309 GetExceptionInfo( &exceptionInfo );
1310 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1311 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1313 replaceImage( newImage );
1314 throwException( exceptionInfo );
1315 (void) DestroyExceptionInfo( &exceptionInfo );
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 )
1332 ExceptionInfo exceptionInfo;
1333 GetExceptionInfo( &exceptionInfo );
1335 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1336 throwException( exceptionInfo );
1337 (void) DestroyExceptionInfo( &exceptionInfo );
1340 // Magnify image by integral size
1341 void Magick::Image::magnify ( void )
1343 ExceptionInfo exceptionInfo;
1344 GetExceptionInfo( &exceptionInfo );
1345 MagickCore::Image* newImage =
1346 MagnifyImage( image(), &exceptionInfo );
1347 replaceImage( newImage );
1348 throwException( exceptionInfo );
1349 (void) DestroyExceptionInfo( &exceptionInfo );
1352 // Remap image colors with closest color from reference image
1353 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1355 ExceptionInfo exceptionInfo;
1356 GetExceptionInfo( &exceptionInfo );
1358 options()->quantizeDither( dither_ );
1359 RemapImage ( options()->quantizeInfo(), image(),
1360 mapImage_.constImage(), &exceptionInfo);
1361 throwException( exceptionInfo );
1362 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
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 );
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_ )
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 );
1402 void Magick::Image::mergeLayers( const LayerMethod layerMethod_ )
1404 ExceptionInfo exceptionInfo;
1405 GetExceptionInfo( &exceptionInfo );
1406 MagickCore::Image* newImage =
1407 MergeImageLayers ( image(),
1410 replaceImage( newImage );
1411 throwException( exceptionInfo );
1412 (void) DestroyExceptionInfo( &exceptionInfo );
1415 // Reduce image by integral size
1416 void Magick::Image::minify ( void )
1418 ExceptionInfo exceptionInfo;
1419 GetExceptionInfo( &exceptionInfo );
1420 MagickCore::Image* newImage =
1421 MinifyImage( image(), &exceptionInfo );
1422 replaceImage( newImage );
1423 throwException( exceptionInfo );
1424 (void) DestroyExceptionInfo( &exceptionInfo );
1427 // Modulate percent hue, saturation, and brightness of an image
1428 void Magick::Image::modulate ( const double brightness_,
1429 const double saturation_,
1432 char modulate[MaxTextExtent + 1];
1433 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1434 brightness_, saturation_, hue_);
1436 ExceptionInfo exceptionInfo;
1437 GetExceptionInfo( &exceptionInfo );
1439 ModulateImage( image(), modulate, &exceptionInfo );
1440 throwException( exceptionInfo );
1441 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
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 );
1463 // Negate image. Set grayscale_ to true to effect grayscale values
1465 void Magick::Image::negate ( const bool grayscale_ )
1467 ExceptionInfo exceptionInfo;
1468 GetExceptionInfo( &exceptionInfo );
1470 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1472 throwException( exceptionInfo );
1473 (void) DestroyExceptionInfo( &exceptionInfo );
1477 void Magick::Image::normalize ( void )
1480 ExceptionInfo exceptionInfo;
1481 GetExceptionInfo( &exceptionInfo );
1482 NormalizeImage ( image(), &exceptionInfo );
1483 throwException( exceptionInfo );
1484 (void) DestroyExceptionInfo( &exceptionInfo );
1488 void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
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 );
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_ )
1508 ExceptionInfo exceptionInfo;
1509 GetExceptionInfo( &exceptionInfo );
1510 SetImageAlpha( image(), alpha_, &exceptionInfo );
1511 throwException( exceptionInfo );
1512 (void) DestroyExceptionInfo( &exceptionInfo );
1515 // Change the color of an opaque pixel to the pen color.
1516 void Magick::Image::opaque ( const Color &opaqueColor_,
1517 const Color &penColor_ )
1519 if ( !opaqueColor_.isValid() )
1521 throwExceptionExplicit( OptionError,
1522 "Opaque color argument is invalid" );
1524 if ( !penColor_.isValid() )
1526 throwExceptionExplicit( OptionError,
1527 "Pen color argument is invalid" );
1531 std::string opaqueColor = opaqueColor_;
1532 std::string penColor = penColor_;
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 );
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_ )
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 );
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_ )
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 );
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
1582 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1586 ExceptionInfo exceptionInfo;
1587 GetExceptionInfo( &exceptionInfo );
1589 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1592 throwException( exceptionInfo );
1593 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
1603 options()->quantizeInfo()->measure_error=MagickTrue;
1605 options()->quantizeInfo()->measure_error=MagickFalse;
1607 ExceptionInfo exceptionInfo;
1608 GetExceptionInfo( &exceptionInfo );
1609 QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo );
1611 throwException( exceptionInfo );
1612 (void) DestroyExceptionInfo( &exceptionInfo );
1615 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1616 void Magick::Image::quantumOperator ( const ChannelType channel_,
1617 const MagickEvaluateOperator operator_,
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 );
1629 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1630 const size_t columns_,
1632 const ChannelType channel_,
1633 const MagickEvaluateOperator operator_,
1634 const double rvalue_)
1636 ExceptionInfo exceptionInfo;
1637 GetExceptionInfo( &exceptionInfo );
1638 RectangleInfo geometry;
1639 geometry.width = columns_;
1640 geometry.height = rows_;
1643 MagickCore::Image *crop_image = CropImage( image(), &geometry,
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,
1651 crop_image = DestroyImageList(crop_image);
1652 throwException( exceptionInfo );
1653 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
1661 ExceptionInfo exceptionInfo;
1662 GetExceptionInfo( &exceptionInfo );
1663 RectangleInfo raiseInfo = geometry_;
1665 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
1666 throwException( exceptionInfo );
1667 (void) DestroyExceptionInfo( &exceptionInfo );
1671 // Random threshold image.
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_ )
1683 randomThresholdChannel(thresholds_,DefaultChannels);
1685 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1686 const ChannelType channel_ )
1688 ExceptionInfo exceptionInfo;
1689 GetExceptionInfo( &exceptionInfo );
1691 ChannelType channel_mask = SetImageChannelMask( image(), channel_);
1692 (void) RandomThresholdImage( image(),
1693 static_cast<std::string>(thresholds_).c_str(),
1695 (void) SetPixelChannelMask( image(), channel_mask );
1696 throwImageException();
1697 (void) DestroyExceptionInfo( &exceptionInfo );
1700 // Read image into current object
1701 void Magick::Image::read ( const std::string &imageSpec_ )
1703 options()->fileName( imageSpec_ );
1705 ExceptionInfo exceptionInfo;
1706 GetExceptionInfo( &exceptionInfo );
1707 MagickCore::Image* image =
1708 ReadImage( imageInfo(), &exceptionInfo );
1710 // Ensure that multiple image frames were not read.
1711 if ( image && image->next )
1713 // Destroy any extra image frames
1714 MagickCore::Image* next = image->next;
1717 DestroyImageList( next );
1720 replaceImage( image );
1721 throwException( exceptionInfo );
1722 (void) DestroyExceptionInfo( &exceptionInfo );
1725 // Read image of specified size into current object
1726 void Magick::Image::read ( const Geometry &size_,
1727 const std::string &imageSpec_ )
1733 // Read image from in-memory BLOB
1734 void Magick::Image::read ( const Blob &blob_ )
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 );
1747 // Read image of specified size from in-memory BLOB
1748 void Magick::Image::read ( const Blob &blob_,
1749 const Geometry &size_ )
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_ )
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_ )
1782 // Set explicit image format
1783 fileName( magick_ + ':');
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_ )
1797 // Set explicit image format
1798 fileName( magick_ + ':');
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_ )
1810 ExceptionInfo exceptionInfo;
1811 GetExceptionInfo( &exceptionInfo );
1812 MagickCore::Image* image =
1813 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1815 replaceImage( image );
1816 throwException( exceptionInfo );
1817 (void) DestroyExceptionInfo( &exceptionInfo );
1820 // Reduce noise in image
1821 void Magick::Image::reduceNoise ( const double order_ )
1823 ExceptionInfo exceptionInfo;
1824 GetExceptionInfo( &exceptionInfo );
1825 MagickCore::Image* newImage =
1826 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1828 replaceImage( newImage );
1829 throwException( exceptionInfo );
1830 (void) DestroyExceptionInfo( &exceptionInfo );
1834 void Magick::Image::resize( const Geometry &geometry_ )
1836 // Calculate new size. This code should be supported using binary arguments
1837 // in the ImageMagick library.
1840 size_t width = columns();
1841 size_t height = rows();
1843 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1847 ExceptionInfo exceptionInfo;
1848 GetExceptionInfo( &exceptionInfo );
1849 MagickCore::Image* newImage =
1850 ResizeImage( image(),
1855 replaceImage( newImage );
1856 throwException( exceptionInfo );
1857 (void) DestroyExceptionInfo( &exceptionInfo );
1861 void Magick::Image::roll ( const Geometry &roll_ )
1863 ssize_t xOff = roll_.xOff();
1864 if ( roll_.xNegative() )
1866 ssize_t yOff = roll_.yOff();
1867 if ( roll_.yNegative() )
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 );
1878 void Magick::Image::roll ( const size_t columns_,
1879 const size_t rows_ )
1881 ExceptionInfo exceptionInfo;
1882 GetExceptionInfo( &exceptionInfo );
1883 MagickCore::Image* newImage =
1885 static_cast<ssize_t>(columns_),
1886 static_cast<ssize_t>(rows_), &exceptionInfo );
1887 replaceImage( newImage );
1888 throwException( exceptionInfo );
1889 (void) DestroyExceptionInfo( &exceptionInfo );
1893 void Magick::Image::rotate ( const double degrees_ )
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 );
1905 void Magick::Image::sample ( const Geometry &geometry_ )
1909 size_t width = columns();
1910 size_t height = rows();
1912 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
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 );
1926 void Magick::Image::scale ( const Geometry &geometry_ )
1930 size_t width = columns();
1931 size_t height = rows();
1933 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
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 );
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_ )
1952 ExceptionInfo exceptionInfo;
1953 GetExceptionInfo( &exceptionInfo );
1955 SegmentImage ( image(),
1956 options()->quantizeColorSpace(),
1957 (MagickBooleanType) options()->verbose(),
1959 smoothingThreshold_, &exceptionInfo );
1960 SyncImage( image(), &exceptionInfo );
1961 throwException( exceptionInfo );
1962 (void) DestroyExceptionInfo( &exceptionInfo );
1965 // Shade image using distant light source
1966 void Magick::Image::shade ( const double azimuth_,
1967 const double elevation_,
1968 const bool colorShading_ )
1970 ExceptionInfo exceptionInfo;
1971 GetExceptionInfo( &exceptionInfo );
1972 MagickCore::Image* newImage =
1973 ShadeImage( image(),
1974 colorShading_ == true ? MagickTrue : MagickFalse,
1978 replaceImage( newImage );
1979 throwException( exceptionInfo );
1980 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
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 );
1996 // Sharpen pixels in image
1997 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1999 ExceptionInfo exceptionInfo;
2000 GetExceptionInfo( &exceptionInfo );
2001 MagickCore::Image* newImage =
2002 SharpenImage( image(),
2006 replaceImage( newImage );
2007 throwException( exceptionInfo );
2008 (void) DestroyExceptionInfo( &exceptionInfo );
2011 void Magick::Image::sharpenChannel ( const ChannelType channel_,
2012 const double radius_, const double sigma_ )
2014 ExceptionInfo exceptionInfo;
2015 GetExceptionInfo( &exceptionInfo );
2016 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2017 MagickCore::Image* newImage =
2018 SharpenImage( image(),
2022 (void) SetPixelChannelMask( image(), channel_mask );
2023 replaceImage( newImage );
2024 throwException( exceptionInfo );
2025 (void) DestroyExceptionInfo( &exceptionInfo );
2028 // Shave pixels from image edges.
2029 void Magick::Image::shave ( const Geometry &geometry_ )
2031 RectangleInfo shaveInfo = geometry_;
2032 ExceptionInfo exceptionInfo;
2033 GetExceptionInfo( &exceptionInfo );
2034 MagickCore::Image* newImage =
2035 ShaveImage( image(),
2038 replaceImage( newImage );
2039 throwException( exceptionInfo );
2040 (void) DestroyExceptionInfo( &exceptionInfo );
2044 void Magick::Image::shear ( const double xShearAngle_,
2045 const double yShearAngle_ )
2047 ExceptionInfo exceptionInfo;
2048 GetExceptionInfo( &exceptionInfo );
2049 MagickCore::Image* newImage =
2050 ShearImage( image(),
2054 replaceImage( newImage );
2055 throwException( exceptionInfo );
2056 (void) DestroyExceptionInfo( &exceptionInfo );
2060 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
2062 ExceptionInfo exceptionInfo;
2063 GetExceptionInfo( &exceptionInfo );
2065 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
2066 throwException( exceptionInfo );
2067 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
2074 ExceptionInfo exceptionInfo;
2075 GetExceptionInfo( &exceptionInfo );
2077 SolarizeImage ( image(), factor_, &exceptionInfo );
2078 throwException( exceptionInfo );
2079 (void) DestroyExceptionInfo( &exceptionInfo );
2082 // Sparse color image, given a set of coordinates, interpolates the colors
2083 // found at those coordinates, across the whole image, using various methods.
2085 void Magick::Image::sparseColor ( const ChannelType channel,
2086 const SparseColorMethod method,
2087 const size_t number_arguments,
2088 const double *arguments )
2090 ExceptionInfo exceptionInfo;
2091 GetExceptionInfo( &exceptionInfo );
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 );
2102 // Spread pixels randomly within image by specified ammount
2103 void Magick::Image::spread ( const size_t amount_ )
2105 ExceptionInfo exceptionInfo;
2106 GetExceptionInfo( &exceptionInfo );
2107 MagickCore::Image* newImage =
2108 SpreadImage( image(),
2110 image()->interpolate,
2112 replaceImage( newImage );
2113 throwException( exceptionInfo );
2114 (void) DestroyExceptionInfo( &exceptionInfo );
2117 // Add a digital watermark to the image (based on second image)
2118 void Magick::Image::stegano ( const Image &watermark_ )
2120 ExceptionInfo exceptionInfo;
2121 GetExceptionInfo( &exceptionInfo );
2122 MagickCore::Image* newImage =
2123 SteganoImage( image(),
2124 watermark_.constImage(),
2126 replaceImage( newImage );
2127 throwException( exceptionInfo );
2128 (void) DestroyExceptionInfo( &exceptionInfo );
2131 // Stereo image (left image is current image)
2132 void Magick::Image::stereo ( const Image &rightImage_ )
2134 ExceptionInfo exceptionInfo;
2135 GetExceptionInfo( &exceptionInfo );
2136 MagickCore::Image* newImage =
2137 StereoImage( image(),
2138 rightImage_.constImage(),
2140 replaceImage( newImage );
2141 throwException( exceptionInfo );
2142 (void) DestroyExceptionInfo( &exceptionInfo );
2146 void Magick::Image::swirl ( const double degrees_ )
2148 ExceptionInfo exceptionInfo;
2149 GetExceptionInfo( &exceptionInfo );
2150 MagickCore::Image* newImage =
2151 SwirlImage( image(), degrees_, image()->interpolate,
2153 replaceImage( newImage );
2154 throwException( exceptionInfo );
2155 (void) DestroyExceptionInfo( &exceptionInfo );
2159 void Magick::Image::texture ( const Image &texture_ )
2162 ExceptionInfo exceptionInfo;
2163 GetExceptionInfo( &exceptionInfo );
2164 TextureImage( image(), texture_.constImage(), &exceptionInfo );
2165 throwException( exceptionInfo );
2166 (void) DestroyExceptionInfo( &exceptionInfo );
2170 void Magick::Image::threshold ( const double threshold_ )
2173 ExceptionInfo exceptionInfo;
2174 GetExceptionInfo( &exceptionInfo );
2175 BilevelImage( image(), threshold_, &exceptionInfo );
2176 throwException( exceptionInfo );
2177 (void) DestroyExceptionInfo( &exceptionInfo );
2180 // Transform image based on image geometry only
2181 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2184 ExceptionInfo exceptionInfo;
2185 GetExceptionInfo( &exceptionInfo );
2186 TransformImage ( &(image()), 0,
2187 std::string(imageGeometry_).c_str(), &exceptionInfo );
2188 throwException( exceptionInfo );
2189 (void) DestroyExceptionInfo( &exceptionInfo );
2191 // Transform image based on image and crop geometries
2192 void Magick::Image::transform ( const Geometry &imageGeometry_,
2193 const Geometry &cropGeometry_ )
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 );
2204 // Add matte image to image, setting pixels matching color to transparent
2205 void Magick::Image::transparent ( const Color &color_ )
2207 if ( !color_.isValid() )
2209 throwExceptionExplicit( OptionError,
2210 "Color argument is invalid" );
2213 std::string color = color_;
2216 ExceptionInfo exceptionInfo;
2217 GetExceptionInfo( &exceptionInfo );
2218 (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
2219 &target,&exceptionInfo);
2221 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2223 throwException( exceptionInfo );
2224 (void) DestroyExceptionInfo( &exceptionInfo );
2227 // Add matte image to image, setting pixels matching color to transparent
2228 void Magick::Image::transparentChroma(const Color &colorLow_,
2229 const Color &colorHigh_)
2231 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2233 throwExceptionExplicit( OptionError,
2234 "Color argument is invalid" );
2237 std::string colorLow = colorLow_;
2238 std::string colorHigh = colorHigh_;
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);
2249 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2250 TransparentAlpha, MagickFalse, &exceptionInfo );
2251 throwException( exceptionInfo );
2252 (void) DestroyExceptionInfo( &exceptionInfo );
2256 // Trim edges that are the background color from the image
2257 void Magick::Image::trim ( void )
2259 ExceptionInfo exceptionInfo;
2260 GetExceptionInfo( &exceptionInfo );
2261 MagickCore::Image* newImage =
2262 TrimImage( image(), &exceptionInfo);
2263 replaceImage( newImage );
2264 throwException( exceptionInfo );
2265 (void) DestroyExceptionInfo( &exceptionInfo );
2268 // Replace image with a sharpened version of the original image
2269 // using the unsharp mask algorithm.
2271 // the radius of the Gaussian, in pixels, not counting the
2274 // the standard deviation of the Gaussian, in pixels.
2276 // the percentage of the difference between the original and
2277 // the blur image that is added back into the original.
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_ )
2285 ExceptionInfo exceptionInfo;
2286 GetExceptionInfo( &exceptionInfo );
2287 MagickCore::Image* newImage =
2288 UnsharpMaskImage( image(),
2294 replaceImage( newImage );
2295 throwException( exceptionInfo );
2296 (void) DestroyExceptionInfo( &exceptionInfo );
2299 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2300 const double radius_,
2301 const double sigma_,
2302 const double amount_,
2303 const double threshold_ )
2305 ExceptionInfo exceptionInfo;
2306 GetExceptionInfo( &exceptionInfo );
2307 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2308 MagickCore::Image* newImage =
2309 UnsharpMaskImage( image(),
2315 (void) SetPixelChannelMask( image(), channel_mask );
2316 replaceImage( newImage );
2317 throwException( exceptionInfo );
2318 (void) DestroyExceptionInfo( &exceptionInfo );
2321 // Map image pixels to a sine wave
2322 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2324 ExceptionInfo exceptionInfo;
2325 GetExceptionInfo( &exceptionInfo );
2326 MagickCore::Image* newImage =
2330 image()->interpolate,
2332 replaceImage( newImage );
2333 throwException( exceptionInfo );
2334 (void) DestroyExceptionInfo( &exceptionInfo );
2337 // Write image to file
2338 void Magick::Image::write( const std::string &imageSpec_ )
2340 ExceptionInfo exceptionInfo;
2341 GetExceptionInfo( &exceptionInfo );
2343 fileName( imageSpec_ );
2344 WriteImage( imageInfo(), image(), &exceptionInfo );
2345 throwException( exceptionInfo );
2346 (void) DestroyExceptionInfo( &exceptionInfo );
2349 // Write image to in-memory BLOB
2350 void Magick::Image::write ( Blob *blob_ )
2353 size_t length = 2048; // Efficient size for small images
2354 ExceptionInfo exceptionInfo;
2355 GetExceptionInfo( &exceptionInfo );
2356 void* data = ImageToBlob( imageInfo(),
2360 throwException( exceptionInfo );
2361 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2362 throwImageException();
2363 (void) DestroyExceptionInfo( &exceptionInfo );
2365 void Magick::Image::write ( Blob *blob_,
2366 const std::string &magick_ )
2370 size_t length = 2048; // Efficient size for small images
2371 ExceptionInfo exceptionInfo;
2372 GetExceptionInfo( &exceptionInfo );
2373 void* data = ImageToBlob( imageInfo(),
2377 throwException( exceptionInfo );
2378 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2379 throwImageException();
2380 (void) DestroyExceptionInfo( &exceptionInfo );
2382 void Magick::Image::write ( Blob *blob_,
2383 const std::string &magick_,
2384 const size_t depth_ )
2389 size_t length = 2048; // Efficient size for small images
2390 ExceptionInfo exceptionInfo;
2391 GetExceptionInfo( &exceptionInfo );
2392 void* data = ImageToBlob( imageInfo(),
2396 throwException( exceptionInfo );
2397 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2398 throwImageException();
2399 (void) DestroyExceptionInfo( &exceptionInfo );
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_,
2407 const size_t columns_,
2409 const std::string &map_,
2410 const StorageType type_,
2413 ExceptionInfo exceptionInfo;
2414 GetExceptionInfo( &exceptionInfo );
2415 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2418 throwException( exceptionInfo );
2419 (void) DestroyExceptionInfo( &exceptionInfo );
2423 void Magick::Image::zoom( const Geometry &geometry_ )
2425 // Calculate new size. This code should be supported using binary arguments
2426 // in the ImageMagick library.
2429 size_t width = columns();
2430 size_t height = rows();
2432 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2436 ExceptionInfo exceptionInfo;
2437 GetExceptionInfo( &exceptionInfo );
2438 MagickCore::Image* newImage =
2439 ResizeImage( image(),
2444 replaceImage( newImage );
2445 throwException( exceptionInfo );
2446 (void) DestroyExceptionInfo( &exceptionInfo );
2450 * Methods for setting image attributes
2454 // Join images into a single multi-image file
2455 void Magick::Image::adjoin ( const bool flag_ )
2458 options()->adjoin( flag_ );
2460 bool Magick::Image::adjoin ( void ) const
2462 return constOptions()->adjoin();
2465 // Remove pixel aliasing
2466 void Magick::Image::antiAlias( const bool flag_ )
2469 options()->antiAlias( static_cast<size_t>(flag_) );
2471 bool Magick::Image::antiAlias( void )
2473 return static_cast<bool>( options()->antiAlias( ) );
2476 // Animation inter-frame delay
2477 void Magick::Image::animationDelay ( const size_t delay_ )
2480 image()->delay = delay_;
2482 size_t Magick::Image::animationDelay ( void ) const
2484 return constImage()->delay;
2487 // Number of iterations to play animation
2488 void Magick::Image::animationIterations ( const size_t iterations_ )
2491 image()->iterations = iterations_;
2493 size_t Magick::Image::animationIterations ( void ) const
2495 return constImage()->iterations;
2498 // Access/Update a named image attribute
2499 void Magick::Image::attribute ( const std::string name_,
2500 const std::string value_ )
2503 ExceptionInfo exceptionInfo;
2504 GetExceptionInfo( &exceptionInfo );
2505 SetImageProperty( image(), name_.c_str(), value_.c_str(), &exceptionInfo );
2506 throwException( exceptionInfo );
2507 (void) DestroyExceptionInfo( &exceptionInfo );
2509 std::string Magick::Image::attribute ( const std::string name_ )
2511 ExceptionInfo exceptionInfo;
2512 GetExceptionInfo( &exceptionInfo );
2513 const char *value = GetImageProperty( constImage(), name_.c_str(),
2515 throwException( exceptionInfo );
2516 (void) DestroyExceptionInfo( &exceptionInfo );
2519 return std::string( value );
2521 return std::string(); // Intentionally no exception
2525 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2529 if ( backgroundColor_.isValid() )
2531 image()->background_color = backgroundColor_;
2535 image()->background_color = Color();
2538 options()->backgroundColor( backgroundColor_ );
2540 Magick::Color Magick::Image::backgroundColor ( void ) const
2542 return constOptions()->backgroundColor( );
2545 // Background fill texture
2546 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2549 options()->backgroundTexture( backgroundTexture_ );
2551 std::string Magick::Image::backgroundTexture ( void ) const
2553 return constOptions()->backgroundTexture( );
2556 // Original image columns
2557 size_t Magick::Image::baseColumns ( void ) const
2559 return constImage()->magick_columns;
2562 // Original image name
2563 std::string Magick::Image::baseFilename ( void ) const
2565 return std::string(constImage()->magick_filename);
2568 // Original image rows
2569 size_t Magick::Image::baseRows ( void ) const
2571 return constImage()->magick_rows;
2575 void Magick::Image::borderColor ( const Color &borderColor_ )
2579 if ( borderColor_.isValid() )
2581 image()->border_color = borderColor_;
2585 image()->border_color = Color();
2588 options()->borderColor( borderColor_ );
2590 Magick::Color Magick::Image::borderColor ( void ) const
2592 return constOptions()->borderColor( );
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
2600 ExceptionInfo exceptionInfo;
2601 GetExceptionInfo( &exceptionInfo );
2602 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2603 throwException( exceptionInfo );
2604 (void) DestroyExceptionInfo( &exceptionInfo );
2605 return Geometry( bbox );
2608 // Text bounding-box base color
2609 void Magick::Image::boxColor ( const Color &boxColor_ )
2612 options()->boxColor( boxColor_ );
2614 Magick::Color Magick::Image::boxColor ( void ) const
2616 return constOptions()->boxColor( );
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.
2623 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2625 SetMagickResourceLimit( MemoryResource, threshold_ );
2628 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2631 image()->chromaticity.blue_primary.x = x_;
2632 image()->chromaticity.blue_primary.y = y_;
2634 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2636 *x_ = constImage()->chromaticity.blue_primary.x;
2637 *y_ = constImage()->chromaticity.blue_primary.y;
2640 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2643 image()->chromaticity.green_primary.x = x_;
2644 image()->chromaticity.green_primary.y = y_;
2646 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2648 *x_ = constImage()->chromaticity.green_primary.x;
2649 *y_ = constImage()->chromaticity.green_primary.y;
2652 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2655 image()->chromaticity.red_primary.x = x_;
2656 image()->chromaticity.red_primary.y = y_;
2658 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2660 *x_ = constImage()->chromaticity.red_primary.x;
2661 *y_ = constImage()->chromaticity.red_primary.y;
2664 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2667 image()->chromaticity.white_point.x = x_;
2668 image()->chromaticity.white_point.y = y_;
2670 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2672 *x_ = constImage()->chromaticity.white_point.x;
2673 *y_ = constImage()->chromaticity.white_point.y;
2676 // Set image storage class
2677 void Magick::Image::classType ( const ClassType class_ )
2679 if ( classType() == PseudoClass && class_ == DirectClass )
2681 // Use SyncImage to synchronize the DirectClass pixels with the
2682 // color map and then set to DirectClass type.
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);
2695 if ( classType() == DirectClass && class_ == PseudoClass )
2697 // Quantize to create PseudoClass color map
2699 quantizeColors(MaxColormapSize);
2701 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
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_ )
2712 ExceptionInfo exceptionInfo;
2713 GetExceptionInfo( &exceptionInfo );
2714 if( clipMask_.isValid() )
2717 SetImageMask( image(), clipMask_.constImage(), &exceptionInfo );
2721 // Unset existing clip mask
2722 SetImageMask( image(), 0, &exceptionInfo );
2724 throwException( exceptionInfo );
2725 (void) DestroyExceptionInfo( &exceptionInfo );
2727 Magick::Image Magick::Image::clipMask ( void ) const
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 );
2737 void Magick::Image::colorFuzz ( const double fuzz_ )
2740 image()->fuzz = fuzz_;
2741 options()->colorFuzz( fuzz_ );
2743 double Magick::Image::colorFuzz ( void ) const
2745 return constOptions()->colorFuzz( );
2748 // Set color in colormap at index
2749 void Magick::Image::colorMap ( const size_t index_,
2750 const Color &color_ )
2752 MagickCore::Image* imageptr = image();
2754 if (index_ > (MaxColormapSize-1) )
2755 throwExceptionExplicit( OptionError,
2756 "Colormap index must be less than MaxColormapSize" );
2758 if ( !color_.isValid() )
2759 throwExceptionExplicit( OptionError,
2760 "Color argument is invalid");
2763 // Ensure that colormap size is large enough
2764 if ( colorMapSize() < (index_+1) )
2765 colorMapSize( index_ + 1 );
2767 // Set color at index in colormap
2768 (imageptr->colormap)[index_] = color_;
2770 // Return color in colormap at index
2771 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2773 const MagickCore::Image* imageptr = constImage();
2775 if ( !imageptr->colormap )
2776 throwExceptionExplicit( OptionError,
2777 "Image does not contain a colormap");
2779 if ( index_ > imageptr->colors-1 )
2780 throwExceptionExplicit( OptionError,
2781 "Index out of range");
2783 return Magick::Color( (imageptr->colormap)[index_] );
2786 // Colormap size (number of colormap entries)
2787 void Magick::Image::colorMapSize ( const size_t entries_ )
2789 if (entries_ >MaxColormapSize )
2790 throwExceptionExplicit( OptionError,
2791 "Colormap entries must not exceed MaxColormapSize" );
2795 MagickCore::Image* imageptr = image();
2797 if( !imageptr->colormap )
2799 // Allocate colormap
2800 imageptr->colormap =
2801 static_cast<PixelInfo*>(AcquireMagickMemory(entries_*sizeof(PixelInfo)));
2802 imageptr->colors = 0;
2804 else if ( entries_ > imageptr->colors )
2806 // Re-allocate colormap
2807 imageptr->colormap=(PixelInfo *)
2808 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelInfo));
2811 // Initialize any new colormap entries as all black
2813 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2814 (imageptr->colormap)[i] = black;
2816 imageptr->colors = entries_;
2818 size_t Magick::Image::colorMapSize ( void )
2820 const MagickCore::Image* imageptr = constImage();
2822 if ( !imageptr->colormap )
2823 throwExceptionExplicit( OptionError,
2824 "Image does not contain a colormap");
2826 return imageptr->colors;
2830 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2832 if ( image()->colorspace == colorSpace_ )
2836 ExceptionInfo exceptionInfo;
2837 GetExceptionInfo( &exceptionInfo );
2838 TransformImageColorspace(image(), colorSpace_, &exceptionInfo);
2839 throwException( exceptionInfo );
2840 (void) DestroyExceptionInfo( &exceptionInfo );
2842 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2844 return constImage()->colorspace;
2847 // Set image colorspace type.
2848 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2851 ExceptionInfo exceptionInfo;
2852 GetExceptionInfo( &exceptionInfo );
2853 SetImageColorspace(image(), colorSpace_, &exceptionInfo);
2854 throwException( exceptionInfo );
2855 (void) DestroyExceptionInfo( &exceptionInfo );
2856 options()->colorspaceType( colorSpace_ );
2858 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2860 return constOptions()->colorspaceType();
2865 void Magick::Image::comment ( const std::string &comment_ )
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 );
2876 std::string Magick::Image::comment ( void ) const
2878 ExceptionInfo exceptionInfo;
2879 GetExceptionInfo( &exceptionInfo );
2880 const char *value = GetImageProperty( constImage(), "Comment",
2882 throwException( exceptionInfo );
2883 (void) DestroyExceptionInfo( &exceptionInfo );
2886 return std::string( value );
2888 return std::string(); // Intentionally no exception
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_)
2895 image()->compose=compose_;
2898 Magick::CompositeOperator Magick::Image::compose ( void ) const
2900 return constImage()->compose;
2903 // Compression algorithm
2904 void Magick::Image::compressType ( const CompressionType compressType_ )
2907 image()->compression = compressType_;
2908 options()->compressType( compressType_ );
2910 Magick::CompressionType Magick::Image::compressType ( void ) const
2912 return constImage()->compression;
2915 // Enable printing of debug messages from ImageMagick
2916 void Magick::Image::debug ( const bool flag_ )
2919 options()->debug( flag_ );
2921 bool Magick::Image::debug ( void ) const
2923 return constOptions()->debug();
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_ )
2936 std::string format = magick_ + ":" + key_;
2937 std::string option = value_;
2938 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2940 std::string Magick::Image::defineValue ( const std::string &magick_,
2941 const std::string &key_ ) const
2943 std::string definition = magick_ + ":" + key_;
2944 const char *option =
2945 GetImageOption ( constImageInfo(), definition.c_str() );
2947 return std::string( option );
2948 return std::string( );
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_,
2961 std::string definition = magick_ + ":" + key_;
2964 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2968 DeleteImageOption( imageInfo(), definition.c_str() );
2971 bool Magick::Image::defineSet ( const std::string &magick_,
2972 const std::string &key_ ) const
2974 std::string key = magick_ + ":" + key_;
2975 const char *option =
2976 GetImageOption ( constImageInfo(), key.c_str() );
2983 void Magick::Image::density ( const Geometry &density_ )
2986 options()->density( density_ );
2987 if ( density_.isValid() )
2989 image()->resolution.x = density_.width();
2990 if ( density_.height() != 0 )
2992 image()->resolution.y = density_.height();
2996 image()->resolution.y = density_.width();
3002 image()->resolution.x = 0;
3003 image()->resolution.y = 0;
3006 Magick::Geometry Magick::Image::density ( void ) const
3010 ssize_t x_resolution=72;
3011 ssize_t y_resolution=72;
3013 if (constImage()->resolution.x > 0.0)
3014 x_resolution=static_cast<ssize_t>(constImage()->resolution.x + 0.5);
3016 if (constImage()->resolution.y > 0.0)
3017 y_resolution=static_cast<ssize_t>(constImage()->resolution.y + 0.5);
3019 return Geometry(x_resolution,y_resolution);
3022 return constOptions()->density( );
3025 // Image depth (bits allocated to red/green/blue components)
3026 void Magick::Image::depth ( const size_t depth_ )
3028 size_t depth = depth_;
3030 if (depth > MAGICKCORE_QUANTUM_DEPTH)
3031 depth=MAGICKCORE_QUANTUM_DEPTH;
3034 image()->depth=depth;
3035 options()->depth( depth );
3037 size_t Magick::Image::depth ( void ) const
3039 return constImage()->depth;
3042 std::string Magick::Image::directory ( void ) const
3044 if ( constImage()->directory )
3045 return std::string( constImage()->directory );
3047 throwExceptionExplicit( CorruptImageWarning,
3048 "Image does not contain a directory");
3050 return std::string();
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_ )
3058 options()->endian( endian_ );
3059 image()->endian = endian_;
3061 Magick::EndianType Magick::Image::endian ( void ) const
3063 return constImage()->endian;
3066 // EXIF profile (BLOB)
3067 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
3070 if ( exifProfile_.data() != 0 )
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 );
3082 Magick::Blob Magick::Image::exifProfile( void ) const
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));
3091 void Magick::Image::fileName ( const std::string &fileName_ )
3095 fileName_.copy( image()->filename,
3096 sizeof(image()->filename) - 1 );
3097 image()->filename[ fileName_.length() ] = 0; // Null terminate
3099 options()->fileName( fileName_ );
3102 std::string Magick::Image::fileName ( void ) const
3104 return constOptions()->fileName( );
3108 off_t Magick::Image::fileSize ( void ) const
3110 return (off_t) GetBlobSize( constImage() );
3113 // Color to use when drawing inside an object
3114 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3117 options()->fillColor(fillColor_);
3119 Magick::Color Magick::Image::fillColor ( void ) const
3121 return constOptions()->fillColor();
3124 // Rule to use when filling drawn objects
3125 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3128 options()->fillRule(fillRule_);
3130 Magick::FillRule Magick::Image::fillRule ( void ) const
3132 return constOptions()->fillRule();
3135 // Pattern to use while filling drawn objects.
3136 void Magick::Image::fillPattern ( const Image &fillPattern_ )
3139 if(fillPattern_.isValid())
3140 options()->fillPattern( fillPattern_.constImage() );
3142 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3144 Magick::Image Magick::Image::fillPattern ( void ) const
3146 // FIXME: This is inordinately innefficient
3149 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3153 ExceptionInfo exceptionInfo;
3154 GetExceptionInfo( &exceptionInfo );
3155 MagickCore::Image* image =
3156 CloneImage( tmpTexture,
3159 MagickTrue, // orphan
3161 texture.replaceImage( image );
3162 throwException( exceptionInfo );
3163 (void) DestroyExceptionInfo( &exceptionInfo );
3168 // Filter used by zoom
3169 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3172 image()->filter = filterType_;
3174 Magick::FilterTypes Magick::Image::filterType ( void ) const
3176 return constImage()->filter;
3180 void Magick::Image::font ( const std::string &font_ )
3183 options()->font( font_ );
3185 std::string Magick::Image::font ( void ) const
3187 return constOptions()->font( );
3191 void Magick::Image::fontPointsize ( const double pointSize_ )
3194 options()->fontPointsize( pointSize_ );
3196 double Magick::Image::fontPointsize ( void ) const
3198 return constOptions()->fontPointsize( );
3201 // Font type metrics
3202 void Magick::Image::fontTypeMetrics( const std::string &text_,
3203 TypeMetric *metrics )
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 );
3211 throwException( exceptionInfo );
3212 (void) DestroyExceptionInfo( &exceptionInfo );
3215 // Image format string
3216 std::string Magick::Image::format ( void ) const
3218 ExceptionInfo exceptionInfo;
3219 GetExceptionInfo( &exceptionInfo );
3220 const MagickInfo * magick_info
3221 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3222 throwException( exceptionInfo );
3223 (void) DestroyExceptionInfo( &exceptionInfo );
3225 if (( magick_info != 0 ) &&
3226 ( *magick_info->description != '\0' ))
3227 return std::string(magick_info->description);
3229 throwExceptionExplicit( CorruptImageWarning,
3230 "Unrecognized image magick type" );
3231 return std::string();
3235 double Magick::Image::gamma ( void ) const
3237 return constImage()->gamma;
3240 Magick::Geometry Magick::Image::geometry ( void ) const
3242 if ( constImage()->geometry )
3244 return Geometry(constImage()->geometry);
3247 throwExceptionExplicit( OptionWarning,
3248 "Image does not contain a geometry");
3253 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3256 image()->dispose = (DisposeType) disposeMethod_;
3258 size_t Magick::Image::gifDisposeMethod ( void ) const
3260 // FIXME: It would be better to return an enumeration
3261 return constImage()->dispose;
3264 // ICC ICM color profile (BLOB)
3265 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3267 profile("icm",colorProfile_);
3269 Magick::Blob Magick::Image::iccColorProfile( void ) const
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) );
3277 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3280 image()->interlace = interlace_;
3281 options()->interlaceType ( interlace_ );
3283 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3285 return constImage()->interlace;
3288 // IPTC profile (BLOB)
3289 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3292 if ( iptcProfile_.data() != 0 )
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 );
3304 Magick::Blob Magick::Image::iptcProfile( void ) const
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));
3312 // Does object contain valid image?
3313 void Magick::Image::isValid ( const bool isValid_ )
3318 _imgRef = new ImageRef;
3320 else if ( !isValid() )
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" );
3329 bool Magick::Image::isValid ( void ) const
3331 if ( rows() && columns() )
3338 void Magick::Image::label ( const std::string &label_ )
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 );
3349 std::string Magick::Image::label ( void ) const
3351 ExceptionInfo exceptionInfo;
3352 GetExceptionInfo( &exceptionInfo );
3353 const char *value = GetImageProperty( constImage(), "Label", &exceptionInfo );
3354 throwException( exceptionInfo );
3355 (void) DestroyExceptionInfo( &exceptionInfo );
3358 return std::string( value );
3360 return std::string();
3363 void Magick::Image::magick ( const std::string &magick_ )
3367 magick_.copy( image()->magick,
3368 sizeof(image()->magick) - 1 );
3369 image()->magick[ magick_.length() ] = 0;
3371 options()->magick( magick_ );
3373 std::string Magick::Image::magick ( void ) const
3375 if ( *(constImage()->magick) != '\0' )
3376 return std::string(constImage()->magick);
3378 return constOptions()->magick( );
3381 void Magick::Image::matte ( const bool matteFlag_ )
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 );
3397 image()->alpha_trait = matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait;
3399 bool Magick::Image::matte ( void ) const
3401 if ( constImage()->alpha_trait == BlendPixelTrait )
3407 void Magick::Image::matteColor ( const Color &matteColor_ )
3411 if ( matteColor_.isValid() )
3413 image()->matte_color = matteColor_;
3414 options()->matteColor( matteColor_ );
3418 // Set to default matte color
3419 Color tmpColor( "#BDBDBD" );
3420 image()->matte_color = tmpColor;
3421 options()->matteColor( tmpColor );
3424 Magick::Color Magick::Image::matteColor ( void ) const
3426 return Color( ClampToQuantum( constImage()->matte_color.red ),
3427 ClampToQuantum( constImage()->matte_color.green ),
3428 ClampToQuantum( constImage()->matte_color.blue ) );
3431 double Magick::Image::meanErrorPerPixel ( void ) const
3433 return(constImage()->error.mean_error_per_pixel);
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_ )
3441 ExceptionInfo exceptionInfo;
3442 GetExceptionInfo( &exceptionInfo );
3443 SetImageDepth( image(), depth_, &exceptionInfo );
3444 throwException( exceptionInfo );
3445 (void) DestroyExceptionInfo( &exceptionInfo );
3446 options()->depth( depth_ );
3448 size_t Magick::Image::modulusDepth ( void ) const
3450 ExceptionInfo exceptionInfo;
3451 GetExceptionInfo( &exceptionInfo );
3452 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3453 throwException( exceptionInfo );
3454 (void) DestroyExceptionInfo( &exceptionInfo );
3458 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3461 options()->monochrome( monochromeFlag_ );
3463 bool Magick::Image::monochrome ( void ) const
3465 return constOptions()->monochrome( );
3468 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3470 if ( constImage()->montage )
3471 return Magick::Geometry(constImage()->montage);
3473 throwExceptionExplicit( CorruptImageWarning,
3474 "Image does not contain a montage" );
3476 return Magick::Geometry();
3479 double Magick::Image::normalizedMaxError ( void ) const
3481 return(constImage()->error.normalized_maximum_error);
3484 double Magick::Image::normalizedMeanError ( void ) const
3486 return constImage()->error.normalized_mean_error;
3489 // Image orientation
3490 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3493 image()->orientation = orientation_;
3495 Magick::OrientationType Magick::Image::orientation ( void ) const
3497 return constImage()->orientation;
3500 void Magick::Image::penColor ( const Color &penColor_ )
3503 options()->fillColor(penColor_);
3504 options()->strokeColor(penColor_);
3506 Magick::Color Magick::Image::penColor ( void ) const
3508 return constOptions()->fillColor();
3511 void Magick::Image::penTexture ( const Image &penTexture_ )
3514 if(penTexture_.isValid())
3515 options()->fillPattern( penTexture_.constImage() );
3517 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3520 Magick::Image Magick::Image::penTexture ( void ) const
3522 // FIXME: This is inordinately innefficient
3525 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3529 ExceptionInfo exceptionInfo;
3530 GetExceptionInfo( &exceptionInfo );
3531 MagickCore::Image* image =
3532 CloneImage( tmpTexture,
3535 MagickTrue, // orphan
3537 texture.replaceImage( image );
3538 throwException( exceptionInfo );
3539 (void) DestroyExceptionInfo( &exceptionInfo );
3544 // Set the color of a pixel.
3545 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3546 const Color &color_ )
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" );
3555 // Set image to DirectClass
3556 classType( DirectClass );
3559 Pixels pixels(*this);
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
3570 // Get the color of a pixel
3571 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3572 const ssize_t y_ ) const
3574 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3578 MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3579 return Color( packet );
3582 return Color(); // invalid
3585 // Preferred size and location of an image canvas.
3586 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3589 options()->page( pageSize_ );
3590 image()->page = pageSize_;
3592 Magick::Geometry Magick::Image::page ( void ) const
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);
3602 // Add a named profile to an image or remove a named profile by
3603 // passing an empty Blob (use default Blob constructor).
3605 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3606 void Magick::Image::profile( const std::string name_,
3607 const Magick::Blob &profile_ )
3610 ExceptionInfo exceptionInfo;
3611 GetExceptionInfo( &exceptionInfo );
3612 ssize_t result = ProfileImage( image(), name_.c_str(),
3613 (unsigned char *)profile_.data(),
3614 profile_.length(), &exceptionInfo);
3616 throwException( exceptionInfo );
3617 (void) DestroyExceptionInfo( &exceptionInfo );
3621 // Retrieve a named profile from the image.
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
3627 const MagickCore::Image* image = constImage();
3629 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3631 if ( profile != (StringInfo *) NULL)
3632 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3635 Image temp_image = *this;
3636 temp_image.write( &blob, name_ );
3640 void Magick::Image::quality ( const size_t quality_ )
3643 image()->quality = quality_;
3644 options()->quality( quality_ );
3646 size_t Magick::Image::quality ( void ) const
3648 return constImage()->quality;
3651 void Magick::Image::quantizeColors ( const size_t colors_ )
3654 options()->quantizeColors( colors_ );
3656 size_t Magick::Image::quantizeColors ( void ) const
3658 return constOptions()->quantizeColors( );
3661 void Magick::Image::quantizeColorSpace
3662 ( const Magick::ColorspaceType colorSpace_ )
3665 options()->quantizeColorSpace( colorSpace_ );
3667 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3669 return constOptions()->quantizeColorSpace( );
3672 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3675 options()->quantizeDither( ditherFlag_ );
3677 bool Magick::Image::quantizeDither ( void ) const
3679 return constOptions()->quantizeDither( );
3682 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3685 options()->quantizeTreeDepth( treeDepth_ );
3687 size_t Magick::Image::quantizeTreeDepth ( void ) const
3689 return constOptions()->quantizeTreeDepth( );
3692 void Magick::Image::renderingIntent
3693 ( const Magick::RenderingIntent renderingIntent_ )
3696 image()->rendering_intent = renderingIntent_;
3698 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3700 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3703 void Magick::Image::resolutionUnits
3704 ( const Magick::ResolutionType resolutionUnits_ )
3707 image()->units = resolutionUnits_;
3708 options()->resolutionUnits( resolutionUnits_ );
3710 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3712 return constOptions()->resolutionUnits( );
3715 void Magick::Image::scene ( const size_t scene_ )
3718 image()->scene = scene_;
3720 size_t Magick::Image::scene ( void ) const
3722 return constImage()->scene;
3725 std::string Magick::Image::signature ( const bool force_ ) const
3727 Lock( &_imgRef->_mutexLock );
3729 // Re-calculate image signature if necessary
3730 ExceptionInfo exceptionInfo;
3731 GetExceptionInfo( &exceptionInfo );
3733 !GetImageProperty(constImage(), "Signature", &exceptionInfo) ||
3734 constImage()->taint )
3736 SignatureImage( const_cast<MagickCore::Image *>(constImage()), &exceptionInfo );
3739 const char *property = GetImageProperty(constImage(), "Signature",
3741 throwException( exceptionInfo );
3742 (void) DestroyExceptionInfo( &exceptionInfo );
3744 return std::string( property );
3747 void Magick::Image::size ( const Geometry &geometry_ )
3750 options()->size( geometry_ );
3751 image()->rows = geometry_.height();
3752 image()->columns = geometry_.width();
3754 Magick::Geometry Magick::Image::size ( void ) const
3756 return Magick::Geometry( constImage()->columns, constImage()->rows );
3760 void Magick::Image::splice( const Geometry &geometry_ )
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 );
3772 // Obtain image statistics. Statistics are normalized to the range of
3773 // 0.0 to 1.0 and are output to the specified ImageStatistics
3775 void Magick::Image::statistics ( ImageStatistics *statistics )
3781 ExceptionInfo exceptionInfo;
3782 GetExceptionInfo( &exceptionInfo );
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 );
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 );
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 );
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 );
3824 throwException( exceptionInfo );
3825 (void) DestroyExceptionInfo( &exceptionInfo );
3828 // Strip strips an image of all profiles and comments.
3829 void Magick::Image::strip ( void )
3832 ExceptionInfo exceptionInfo;
3833 GetExceptionInfo( &exceptionInfo );
3834 StripImage( image(), &exceptionInfo );
3835 throwException( exceptionInfo );
3836 (void) DestroyExceptionInfo( &exceptionInfo );
3839 // enabled/disable stroke anti-aliasing
3840 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3843 options()->strokeAntiAlias(flag_);
3845 bool Magick::Image::strokeAntiAlias ( void ) const
3847 return constOptions()->strokeAntiAlias();
3850 // Color to use when drawing object outlines
3851 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3854 options()->strokeColor(strokeColor_);
3856 Magick::Color Magick::Image::strokeColor ( void ) const
3858 return constOptions()->strokeColor();
3861 // dash pattern for drawing vector objects (default one)
3862 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3865 options()->strokeDashArray( strokeDashArray_ );
3868 const double* Magick::Image::strokeDashArray ( void ) const
3870 return constOptions()->strokeDashArray( );
3873 // dash offset for drawing vector objects (default one)
3874 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3877 options()->strokeDashOffset( strokeDashOffset_ );
3880 double Magick::Image::strokeDashOffset ( void ) const
3882 return constOptions()->strokeDashOffset( );
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,
3888 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3891 options()->strokeLineCap( lineCap_ );
3893 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3895 return constOptions()->strokeLineCap( );
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_ )
3904 options()->strokeLineJoin( lineJoin_ );
3906 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3908 return constOptions()->strokeLineJoin( );
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
3917 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3920 options()->strokeMiterLimit( strokeMiterLimit_ );
3922 size_t Magick::Image::strokeMiterLimit ( void ) const
3924 return constOptions()->strokeMiterLimit( );
3927 // Pattern to use while stroking drawn objects.
3928 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3931 if(strokePattern_.isValid())
3932 options()->strokePattern( strokePattern_.constImage() );
3934 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3936 Magick::Image Magick::Image::strokePattern ( void ) const
3938 // FIXME: This is inordinately innefficient
3941 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3945 ExceptionInfo exceptionInfo;
3946 GetExceptionInfo( &exceptionInfo );
3947 MagickCore::Image* image =
3948 CloneImage( tmpTexture,
3951 MagickTrue, // orphan
3953 throwException( exceptionInfo );
3954 (void) DestroyExceptionInfo( &exceptionInfo );
3955 texture.replaceImage( image );
3960 // Stroke width for drawing lines, circles, ellipses, etc.
3961 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3964 options()->strokeWidth( strokeWidth_ );
3966 double Magick::Image::strokeWidth ( void ) const
3968 return constOptions()->strokeWidth( );
3971 void Magick::Image::subImage ( const size_t subImage_ )
3974 options()->subImage( subImage_ );
3976 size_t Magick::Image::subImage ( void ) const
3978 return constOptions()->subImage( );
3981 void Magick::Image::subRange ( const size_t subRange_ )
3984 options()->subRange( subRange_ );
3986 size_t Magick::Image::subRange ( void ) const
3988 return constOptions()->subRange( );
3991 // Annotation text encoding (e.g. "UTF-16")
3992 void Magick::Image::textEncoding ( const std::string &encoding_ )
3995 options()->textEncoding( encoding_ );
3997 std::string Magick::Image::textEncoding ( void ) const
3999 return constOptions()->textEncoding( );
4002 size_t Magick::Image::totalColors ( void )
4004 ExceptionInfo exceptionInfo;
4005 GetExceptionInfo( &exceptionInfo );
4006 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
4007 throwException( exceptionInfo );
4008 (void) DestroyExceptionInfo( &exceptionInfo );
4012 // Origin of coordinate system to use when annotating with text or drawing
4013 void Magick::Image::transformOrigin ( const double x_, const double y_ )
4016 options()->transformOrigin( x_, y_ );
4019 // Rotation to use when annotating with text or drawing
4020 void Magick::Image::transformRotation ( const double angle_ )
4023 options()->transformRotation( angle_ );
4026 // Reset transformation parameters to default
4027 void Magick::Image::transformReset ( void )
4030 options()->transformReset();
4033 // Scale to use when annotating with text or drawing
4034 void Magick::Image::transformScale ( const double sx_, const double sy_ )
4037 options()->transformScale( sx_, sy_ );
4040 // Skew to use in X axis when annotating with text or drawing
4041 void Magick::Image::transformSkewX ( const double skewx_ )
4044 options()->transformSkewX( skewx_ );
4047 // Skew to use in Y axis when annotating with text or drawing
4048 void Magick::Image::transformSkewY ( const double skewy_ )
4051 options()->transformSkewY( skewy_ );
4054 // Image representation type
4055 Magick::ImageType Magick::Image::type ( void ) const
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 );
4067 void Magick::Image::type ( const Magick::ImageType type_)
4069 ExceptionInfo exceptionInfo;
4070 GetExceptionInfo( &exceptionInfo );
4072 options()->type( type_ );
4073 SetImageType( image(), type_, &exceptionInfo );
4074 throwException( exceptionInfo );
4075 (void) DestroyExceptionInfo( &exceptionInfo );
4078 void Magick::Image::verbose ( const bool verboseFlag_ )
4081 options()->verbose( verboseFlag_ );
4083 bool Magick::Image::verbose ( void ) const
4085 return constOptions()->verbose( );
4088 void Magick::Image::view ( const std::string &view_ )
4091 options()->view( view_ );
4093 std::string Magick::Image::view ( void ) const
4095 return constOptions()->view( );
4098 // Virtual pixel method
4099 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
4102 ExceptionInfo exceptionInfo;
4103 GetExceptionInfo( &exceptionInfo );
4104 SetImageVirtualPixelMethod( image(), virtual_pixel_method_, &exceptionInfo );
4105 throwException( exceptionInfo );
4106 (void) DestroyExceptionInfo( &exceptionInfo );
4108 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
4110 return GetImageVirtualPixelMethod( constImage() );
4113 void Magick::Image::x11Display ( const std::string &display_ )
4116 options()->x11Display( display_ );
4118 std::string Magick::Image::x11Display ( void ) const
4120 return constOptions()->x11Display( );
4123 double Magick::Image::xResolution ( void ) const
4125 return constImage()->resolution.x;
4127 double Magick::Image::yResolution ( void ) const
4129 return constImage()->resolution.y;
4133 Magick::Image::Image( const Image & image_ )
4134 : _imgRef(image_._imgRef)
4136 Lock( &_imgRef->_mutexLock );
4138 // Increase reference count
4139 ++_imgRef->_refCount;
4142 // Assignment operator
4143 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
4145 if( this != &image_ )
4148 Lock( &image_._imgRef->_mutexLock );
4149 ++image_._imgRef->_refCount;
4152 bool doDelete = false;
4154 Lock( &_imgRef->_mutexLock );
4155 if ( --_imgRef->_refCount == 0 )
4161 // Delete old image reference with associated image and options.
4165 // Use new image reference
4166 _imgRef = image_._imgRef;
4172 //////////////////////////////////////////////////////////////////////
4174 // Low-level Pixel Access Routines
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.
4180 //////////////////////////////////////////////////////////////////////
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
4189 ExceptionInfo exceptionInfo;
4190 GetExceptionInfo( &exceptionInfo );
4191 const Quantum* p = (*GetVirtualPixels)( constImage(),
4195 throwException( exceptionInfo );
4196 (void) DestroyExceptionInfo( &exceptionInfo );
4200 // Obtain read-only pixel associated pixels channels
4201 const void* Magick::Image::getConstMetacontent ( void ) const
4203 const void* result = GetVirtualMetacontent( constImage() );
4206 throwImageException();
4211 // Obtain image pixel associated pixels channels
4212 void* Magick::Image::getMetacontent ( void )
4214 void* result = GetAuthenticMetacontent( image() );
4217 throwImageException();
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_ )
4230 ExceptionInfo exceptionInfo;
4231 GetExceptionInfo( &exceptionInfo );
4232 Quantum* result = (*GetAuthenticPixels)( image(),
4234 columns_, rows_, &exceptionInfo );
4235 throwException( exceptionInfo );
4236 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
4249 ExceptionInfo exceptionInfo;
4250 GetExceptionInfo( &exceptionInfo );
4251 Quantum* result = (*QueueAuthenticPixels)( image(),
4253 columns_, rows_, &exceptionInfo );
4254 throwException( exceptionInfo );
4255 (void) DestroyExceptionInfo( &exceptionInfo );
4260 // Transfers the image cache pixels to the image.
4261 void Magick::Image::syncPixels ( void )
4263 ExceptionInfo exceptionInfo;
4264 GetExceptionInfo( &exceptionInfo );
4265 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4266 throwException( exceptionInfo );
4267 (void) DestroyExceptionInfo( &exceptionInfo );
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_ )
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);
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_ )
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 );
4308 /////////////////////////////////////////////////////////////////////
4310 // No end-user methods beyond this point
4312 /////////////////////////////////////////////////////////////////////
4316 // Construct using existing image and default options
4318 Magick::Image::Image ( MagickCore::Image* image_ )
4319 : _imgRef(new ImageRef( image_))
4323 // Get Magick::Options*
4324 Magick::Options* Magick::Image::options( void )
4326 return _imgRef->options();
4328 const Magick::Options* Magick::Image::constOptions( void ) const
4330 return _imgRef->options();
4333 // Get MagickCore::Image*
4334 MagickCore::Image*& Magick::Image::image( void )
4336 return _imgRef->image();
4338 const MagickCore::Image* Magick::Image::constImage( void ) const
4340 return _imgRef->image();
4344 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4346 return _imgRef->options()->imageInfo();
4348 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4350 return _imgRef->options()->imageInfo();
4353 // Get QuantizeInfo *
4354 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4356 return _imgRef->options()->quantizeInfo();
4358 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4360 return _imgRef->options()->quantizeInfo();
4364 // Replace current image
4366 MagickCore::Image * Magick::Image::replaceImage
4367 ( MagickCore::Image* replacement_ )
4369 MagickCore::Image* image;
4372 image = replacement_;
4375 ExceptionInfo exceptionInfo;
4376 GetExceptionInfo( &exceptionInfo );
4377 image = AcquireImage(constImageInfo(), &exceptionInfo);
4378 throwException( exceptionInfo );
4379 (void) DestroyExceptionInfo( &exceptionInfo );
4383 Lock( &_imgRef->_mutexLock );
4385 if ( _imgRef->_refCount == 1 )
4387 // We own the image, just replace it, and de-register
4389 _imgRef->image(image);
4393 // We don't own the image, dereference and replace with copy
4394 --_imgRef->_refCount;
4395 _imgRef = new ImageRef( image, constOptions() );
4399 return _imgRef->_image;
4403 // Prepare to modify image or image options
4404 // Replace current image and options with copy if reference count > 1
4406 void Magick::Image::modifyImage( void )
4409 Lock( &_imgRef->_mutexLock );
4410 if ( _imgRef->_refCount == 1 )
4412 // De-register image and return
4418 ExceptionInfo exceptionInfo;
4419 GetExceptionInfo( &exceptionInfo );
4420 replaceImage( CloneImage( image(),
4423 MagickTrue, // orphan
4425 throwException( exceptionInfo );
4426 (void) DestroyExceptionInfo( &exceptionInfo );
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.
4435 void Magick::Image::throwImageException( void ) const
4437 // Throw C++ exception while resetting Image exception to default state
4440 // Register image with image registry or obtain registration id
4441 ssize_t Magick::Image::registerId( void )
4443 Lock( &_imgRef->_mutexLock );
4444 if( _imgRef->id() < 0 )
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 );
4455 return _imgRef->id();
4458 // Unregister image from image registry
4459 void Magick::Image::unregisterId( void )
4466 // Create a local wrapper around MagickCoreTerminus
4471 void MagickPlusPlusDestroyMagick(void);
4475 void Magick::MagickPlusPlusDestroyMagick(void)
4477 if (magick_initialized)
4479 magick_initialized=false;
4480 MagickCore::MagickCoreTerminus();
4484 // C library initialization routine
4485 void MagickPPExport Magick::InitializeMagick(const char *path_)
4487 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4488 if (!magick_initialized)
4489 magick_initialized=true;
4493 // Cleanup class to ensure that ImageMagick singletons are destroyed
4494 // so as to avoid any resemblence to a memory leak (which seems to
4503 MagickCleanUp( void );
4504 ~MagickCleanUp( void );
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;
4512 Magick::MagickCleanUp::MagickCleanUp ( void )
4514 // Don't even think about invoking InitializeMagick here!
4517 Magick::MagickCleanUp::~MagickCleanUp ( void )
4519 MagickPlusPlusDestroyMagick();