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
16 #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 = SetPixelChannelMask( image(), channel_);
346 MagickCore::Image* newImage =
347 AddNoiseImage ( image(),
350 (void) SetPixelChannelMapMask( 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 = SetPixelChannelMask( image(), channel_ );
502 MagickCore::Image* newImage =
503 BlurImage( image(), radius_, sigma_, &exceptionInfo);
504 (void) SetPixelChannelMapMask( 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=(double *) color_matrix_;
647 MagickCore::Image* newImage =
648 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
649 kernel_info->values=(double *) NULL;
650 kernel_info=DestroyKernelInfo(kernel_info);
651 replaceImage( newImage );
652 throwException( exceptionInfo );
653 (void) DestroyExceptionInfo( &exceptionInfo );
656 // Compare current image with another image
657 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
658 // in the current image. False is returned if the images are identical.
659 bool Magick::Image::compare ( const Image &reference_ )
661 ExceptionInfo exceptionInfo;
662 GetExceptionInfo( &exceptionInfo );
664 Image ref = reference_;
667 static_cast<bool>(IsImagesEqual(image(), ref.image(), &exceptionInfo));
668 throwException( exceptionInfo );
669 (void) DestroyExceptionInfo( &exceptionInfo );
673 // Composite two images
674 void Magick::Image::composite ( const Image &compositeImage_,
675 const ssize_t xOffset_,
676 const ssize_t yOffset_,
677 const CompositeOperator compose_ )
679 // Image supplied as compositeImage is composited with current image and
680 // results in updating current image.
683 ExceptionInfo exceptionInfo;
684 GetExceptionInfo( &exceptionInfo );
685 CompositeImage( image(),
686 compositeImage_.constImage(),
687 compose_, MagickFalse,
689 yOffset_, &exceptionInfo );
690 throwException( exceptionInfo );
691 (void) DestroyExceptionInfo( &exceptionInfo );
693 void Magick::Image::composite ( const Image &compositeImage_,
694 const Geometry &offset_,
695 const CompositeOperator compose_ )
699 ssize_t x = offset_.xOff();
700 ssize_t y = offset_.yOff();
701 size_t width = columns();
702 size_t height = rows();
704 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
708 ExceptionInfo exceptionInfo;
709 GetExceptionInfo( &exceptionInfo );
710 CompositeImage( image(),
711 compositeImage_.constImage(),
712 compose_, MagickFalse,
713 x, y, &exceptionInfo );
714 throwException( exceptionInfo );
715 (void) DestroyExceptionInfo( &exceptionInfo );
717 void Magick::Image::composite ( const Image &compositeImage_,
718 const GravityType gravity_,
719 const CompositeOperator compose_ )
723 RectangleInfo geometry;
725 SetGeometry(compositeImage_.constImage(), &geometry);
726 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
728 ExceptionInfo exceptionInfo;
729 GetExceptionInfo( &exceptionInfo );
730 CompositeImage( image(),
731 compositeImage_.constImage(),
732 compose_, MagickFalse,
733 geometry.x, geometry.y, &exceptionInfo );
734 throwException( exceptionInfo );
735 (void) DestroyExceptionInfo( &exceptionInfo );
739 void Magick::Image::contrast ( const size_t sharpen_ )
742 ExceptionInfo exceptionInfo;
743 GetExceptionInfo( &exceptionInfo );
744 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
745 throwException( exceptionInfo );
746 (void) DestroyExceptionInfo( &exceptionInfo );
749 // Convolve image. Applies a general image convolution kernel to the image.
750 // order_ represents the number of columns and rows in the filter kernel.
751 // kernel_ is an array of doubles representing the convolution kernel.
752 void Magick::Image::convolve ( const size_t order_,
753 const double *kernel_ )
758 ExceptionInfo exceptionInfo;
759 GetExceptionInfo( &exceptionInfo );
760 kernel_info=AcquireKernelInfo((const char *) NULL);
761 kernel_info->width=order_;
762 kernel_info->height=order_;
763 kernel_info->values=(MagickRealType *) kernel_;
764 MagickCore::Image* newImage =
765 ConvolveImage ( image(), kernel_info, &exceptionInfo );
766 kernel_info->values=(MagickRealType *) NULL;
767 kernel_info=DestroyKernelInfo(kernel_info);
768 replaceImage( newImage );
769 throwException( exceptionInfo );
770 (void) DestroyExceptionInfo( &exceptionInfo );
774 void Magick::Image::crop ( const Geometry &geometry_ )
776 RectangleInfo cropInfo = geometry_;
777 ExceptionInfo exceptionInfo;
778 GetExceptionInfo( &exceptionInfo );
779 MagickCore::Image* newImage =
783 replaceImage( newImage );
784 throwException( exceptionInfo );
785 (void) DestroyExceptionInfo( &exceptionInfo );
789 void Magick::Image::cycleColormap ( const ssize_t amount_ )
791 ExceptionInfo exceptionInfo;
792 GetExceptionInfo( &exceptionInfo );
794 CycleColormapImage( image(), amount_, &exceptionInfo );
795 throwException( exceptionInfo );
796 (void) DestroyExceptionInfo( &exceptionInfo );
800 void Magick::Image::despeckle ( void )
802 ExceptionInfo exceptionInfo;
803 GetExceptionInfo( &exceptionInfo );
804 MagickCore::Image* newImage =
805 DespeckleImage( image(), &exceptionInfo );
806 replaceImage( newImage );
807 throwException( exceptionInfo );
808 (void) DestroyExceptionInfo( &exceptionInfo );
812 void Magick::Image::display( void )
814 ExceptionInfo exceptionInfo;
815 GetExceptionInfo( &exceptionInfo );
816 DisplayImages( imageInfo(), image(), &exceptionInfo );
817 throwException( exceptionInfo );
818 (void) DestroyExceptionInfo( &exceptionInfo );
821 // Distort image. distorts an image using various distortion methods, by
822 // mapping color lookups of the source image to a new destination image
823 // usally of the same size as the source image, unless 'bestfit' is set to
825 void Magick::Image::distort ( const DistortImageMethod method_,
826 const size_t number_arguments_,
827 const double *arguments_,
828 const bool bestfit_ )
830 ExceptionInfo exceptionInfo;
831 GetExceptionInfo( &exceptionInfo );
832 MagickCore::Image* newImage = DistortImage ( image(), method_,
833 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
835 replaceImage( newImage );
836 throwException( exceptionInfo );
837 (void) DestroyExceptionInfo( &exceptionInfo );
840 // Draw on image using single drawable
841 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
845 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
849 drawable_.operator()(wand);
853 wand=DestroyDrawingWand(wand);
856 throwImageException();
859 // Draw on image using a drawable list
860 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
864 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
868 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
869 p != drawable_.end(); p++ )
876 wand=DestroyDrawingWand(wand);
879 throwImageException();
882 // Hilight edges in image
883 void Magick::Image::edge ( const double radius_, const double sigma_ )
885 ExceptionInfo exceptionInfo;
886 GetExceptionInfo( &exceptionInfo );
887 MagickCore::Image* newImage =
888 EdgeImage( image(), radius_, sigma_, &exceptionInfo );
889 replaceImage( newImage );
890 throwException( exceptionInfo );
891 (void) DestroyExceptionInfo( &exceptionInfo );
894 // Emboss image (hilight edges)
895 void Magick::Image::emboss ( const double radius_, const double sigma_ )
897 ExceptionInfo exceptionInfo;
898 GetExceptionInfo( &exceptionInfo );
899 MagickCore::Image* newImage =
900 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
901 replaceImage( newImage );
902 throwException( exceptionInfo );
903 (void) DestroyExceptionInfo( &exceptionInfo );
906 // Enhance image (minimize noise)
907 void Magick::Image::enhance ( void )
909 ExceptionInfo exceptionInfo;
910 GetExceptionInfo( &exceptionInfo );
911 MagickCore::Image* newImage =
912 EnhanceImage( image(), &exceptionInfo );
913 replaceImage( newImage );
914 throwException( exceptionInfo );
915 (void) DestroyExceptionInfo( &exceptionInfo );
918 // Equalize image (histogram equalization)
919 void Magick::Image::equalize ( void )
921 ExceptionInfo exceptionInfo;
922 GetExceptionInfo( &exceptionInfo );
924 EqualizeImage( image(), &exceptionInfo );
925 throwException( exceptionInfo );
926 (void) DestroyExceptionInfo( &exceptionInfo );
929 // Erase image to current "background color"
930 void Magick::Image::erase ( void )
933 ExceptionInfo exceptionInfo;
934 GetExceptionInfo( &exceptionInfo );
935 SetImageBackgroundColor( image(), &exceptionInfo );
936 throwException( exceptionInfo );
937 (void) DestroyExceptionInfo( &exceptionInfo );
940 // Extends image as defined by the geometry.
942 void Magick::Image::extent ( const Geometry &geometry_ )
944 RectangleInfo extentInfo = geometry_;
946 ExceptionInfo exceptionInfo;
947 GetExceptionInfo( &exceptionInfo );
948 MagickCore::Image* newImage =
949 ExtentImage ( image(), &extentInfo, &exceptionInfo );
950 replaceImage( newImage );
951 throwException( exceptionInfo );
952 (void) DestroyExceptionInfo( &exceptionInfo );
954 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
956 backgroundColor ( backgroundColor_ );
957 extent ( geometry_ );
959 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
961 image()->gravity = gravity_;
962 extent ( geometry_ );
964 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
966 image()->gravity = gravity_;
967 backgroundColor ( backgroundColor_ );
968 extent ( geometry_ );
971 // Flip image (reflect each scanline in the vertical direction)
972 void Magick::Image::flip ( void )
974 ExceptionInfo exceptionInfo;
975 GetExceptionInfo( &exceptionInfo );
976 MagickCore::Image* newImage =
977 FlipImage( image(), &exceptionInfo );
978 replaceImage( newImage );
979 throwException( exceptionInfo );
980 (void) DestroyExceptionInfo( &exceptionInfo );
983 // Flood-fill color across pixels that match the color of the
984 // target pixel and are neighbors of the target pixel.
985 // Uses current fuzz setting when determining color match.
986 void Magick::Image::floodFillColor( const ssize_t x_,
988 const Magick::Color &fillColor_ )
990 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
992 void Magick::Image::floodFillColor( const Geometry &point_,
993 const Magick::Color &fillColor_ )
995 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
998 // Flood-fill color across pixels starting at target-pixel and
999 // stopping at pixels matching specified border color.
1000 // Uses current fuzz setting when determining color match.
1001 void Magick::Image::floodFillColor( const ssize_t x_,
1003 const Magick::Color &fillColor_,
1004 const Magick::Color &borderColor_ )
1006 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
1009 void Magick::Image::floodFillColor( const Geometry &point_,
1010 const Magick::Color &fillColor_,
1011 const Magick::Color &borderColor_ )
1013 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
1017 // Floodfill pixels matching color (within fuzz factor) of target
1018 // pixel(x,y) with replacement alpha value using method.
1019 void Magick::Image::floodFillAlpha( const ssize_t x_,
1021 const unsigned int alpha_,
1022 const PaintMethod method_ )
1026 GetPixelInfo(image(),&target);
1027 PixelInfo pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
1028 target.red=pixel.red;
1029 target.green=pixel.green;
1030 target.blue=pixel.blue;
1031 target.alpha=alpha_;
1032 ExceptionInfo exceptionInfo;
1033 GetExceptionInfo( &exceptionInfo );
1034 FloodfillPaintImage ( image(),
1035 options()->drawInfo(), // const DrawInfo *draw_info
1037 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
1038 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1040 throwException( exceptionInfo );
1041 (void) DestroyExceptionInfo( &exceptionInfo );
1044 // Flood-fill texture across pixels that match the color of the
1045 // target pixel and are neighbors of the target pixel.
1046 // Uses current fuzz setting when determining color match.
1047 void Magick::Image::floodFillTexture( const ssize_t x_,
1049 const Magick::Image &texture_ )
1053 // Set drawing pattern
1054 options()->fillPattern(texture_.constImage());
1057 Pixels pixels(*this);
1059 Quantum *p = pixels.get(x_, y_, 1, 1 );
1061 GetPixelInfo(constImage(),&target);
1062 target.red=GetPixelRed(constImage(),p);
1063 target.green=GetPixelGreen(constImage(),p);
1064 target.blue=GetPixelBlue(constImage(),p);
1065 ExceptionInfo exceptionInfo;
1066 GetExceptionInfo( &exceptionInfo );
1068 FloodfillPaintImage ( image(), // Image *image
1069 options()->drawInfo(), // const DrawInfo *draw_info
1070 &target, // const MagickPacket target
1071 static_cast<ssize_t>(x_), // const ssize_t x_offset
1072 static_cast<ssize_t>(y_), // const ssize_t y_offset
1073 MagickFalse, // const PaintMethod method
1075 throwException( exceptionInfo );
1076 (void) DestroyExceptionInfo( &exceptionInfo );
1079 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1080 const Magick::Image &texture_ )
1082 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1085 // Flood-fill texture across pixels starting at target-pixel and
1086 // stopping at pixels matching specified border color.
1087 // Uses current fuzz setting when determining color match.
1088 void Magick::Image::floodFillTexture( const ssize_t x_,
1090 const Magick::Image &texture_,
1091 const Magick::Color &borderColor_ )
1095 // Set drawing fill pattern
1096 options()->fillPattern(texture_.constImage());
1099 GetPixelInfo(constImage(),&target);
1100 target.red=static_cast<PixelInfo>(borderColor_).red;
1101 target.green=static_cast<PixelInfo>(borderColor_).green;
1102 target.blue=static_cast<PixelInfo>(borderColor_).blue;
1103 ExceptionInfo exceptionInfo;
1104 GetExceptionInfo( &exceptionInfo );
1105 FloodfillPaintImage ( image(),
1106 options()->drawInfo(),
1108 static_cast<ssize_t>(x_),
1109 static_cast<ssize_t>(y_),
1110 MagickTrue, &exceptionInfo);
1112 throwException( exceptionInfo );
1113 (void) DestroyExceptionInfo( &exceptionInfo );
1115 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1116 const Magick::Image &texture_,
1117 const Magick::Color &borderColor_ )
1119 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1122 // Flop image (reflect each scanline in the horizontal direction)
1123 void Magick::Image::flop ( void )
1125 ExceptionInfo exceptionInfo;
1126 GetExceptionInfo( &exceptionInfo );
1127 MagickCore::Image* newImage =
1128 FlopImage( image(), &exceptionInfo );
1129 replaceImage( newImage );
1130 throwException( exceptionInfo );
1131 (void) DestroyExceptionInfo( &exceptionInfo );
1135 void Magick::Image::frame ( const Geometry &geometry_ )
1139 info.x = static_cast<ssize_t>(geometry_.width());
1140 info.y = static_cast<ssize_t>(geometry_.height());
1141 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1142 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1143 info.outer_bevel = geometry_.xOff();
1144 info.inner_bevel = geometry_.yOff();
1146 ExceptionInfo exceptionInfo;
1147 GetExceptionInfo( &exceptionInfo );
1148 MagickCore::Image* newImage =
1149 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1150 replaceImage( newImage );
1151 throwException( exceptionInfo );
1152 (void) DestroyExceptionInfo( &exceptionInfo );
1154 void Magick::Image::frame ( const size_t width_,
1155 const size_t height_,
1156 const ssize_t outerBevel_, const ssize_t innerBevel_ )
1159 info.x = static_cast<ssize_t>(width_);
1160 info.y = static_cast<ssize_t>(height_);
1161 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1162 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1163 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1164 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1166 ExceptionInfo exceptionInfo;
1167 GetExceptionInfo( &exceptionInfo );
1168 MagickCore::Image* newImage =
1169 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1170 replaceImage( newImage );
1171 throwException( exceptionInfo );
1172 (void) DestroyExceptionInfo( &exceptionInfo );
1175 // Fx image. Applies a mathematical expression to the image.
1176 void Magick::Image::fx ( const std::string expression )
1178 ExceptionInfo exceptionInfo;
1179 GetExceptionInfo( &exceptionInfo );
1180 MagickCore::Image* newImage =
1181 FxImage ( image(), expression.c_str(), &exceptionInfo );
1182 replaceImage( newImage );
1183 throwException( exceptionInfo );
1184 (void) DestroyExceptionInfo( &exceptionInfo );
1186 void Magick::Image::fx ( const std::string expression,
1187 const Magick::ChannelType channel )
1189 ExceptionInfo exceptionInfo;
1190 GetExceptionInfo( &exceptionInfo );
1191 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
1192 MagickCore::Image* newImage =
1193 FxImage ( image(), expression.c_str(), &exceptionInfo );
1194 (void) SetPixelChannelMapMask( image(), channel_mask );
1195 replaceImage( newImage );
1196 throwException( exceptionInfo );
1197 (void) DestroyExceptionInfo( &exceptionInfo );
1200 // Gamma correct image
1201 void Magick::Image::gamma ( const double gamma_ )
1203 ExceptionInfo exceptionInfo;
1204 GetExceptionInfo( &exceptionInfo );
1206 GammaImage ( image(), gamma_, &exceptionInfo );
1207 throwException( exceptionInfo );
1208 (void) DestroyExceptionInfo( &exceptionInfo );
1211 void Magick::Image::gamma ( const double gammaRed_,
1212 const double gammaGreen_,
1213 const double gammaBlue_ )
1215 char gamma[MaxTextExtent + 1];
1216 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1217 gammaRed_, gammaGreen_, gammaBlue_);
1219 ExceptionInfo exceptionInfo;
1220 GetExceptionInfo( &exceptionInfo );
1222 GammaImage ( image(), atof(gamma), &exceptionInfo );
1223 throwException( exceptionInfo );
1224 (void) DestroyExceptionInfo( &exceptionInfo );
1227 // Gaussian blur image
1228 // The number of neighbor pixels to be included in the convolution
1229 // mask is specified by 'width_'. The standard deviation of the
1230 // gaussian bell curve is specified by 'sigma_'.
1231 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1233 ExceptionInfo exceptionInfo;
1234 GetExceptionInfo( &exceptionInfo );
1235 MagickCore::Image* newImage =
1236 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1237 replaceImage( newImage );
1238 throwException( exceptionInfo );
1239 (void) DestroyExceptionInfo( &exceptionInfo );
1242 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1243 const double width_,
1244 const double sigma_ )
1246 ExceptionInfo exceptionInfo;
1247 GetExceptionInfo( &exceptionInfo );
1248 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1249 MagickCore::Image* newImage =
1250 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1251 (void) SetPixelChannelMapMask( image(), channel_mask );
1252 replaceImage( newImage );
1253 throwException( exceptionInfo );
1254 (void) DestroyExceptionInfo( &exceptionInfo );
1257 // Apply a color lookup table (Hald CLUT) to the image.
1258 void Magick::Image::haldClut ( const Image &clutImage_ )
1260 ExceptionInfo exceptionInfo;
1261 GetExceptionInfo( &exceptionInfo );
1263 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1264 throwException( exceptionInfo );
1265 (void) DestroyExceptionInfo( &exceptionInfo );
1269 void Magick::Image::implode ( const double factor_ )
1271 ExceptionInfo exceptionInfo;
1272 GetExceptionInfo( &exceptionInfo );
1273 MagickCore::Image* newImage =
1274 ImplodeImage( image(), factor_, image()->interpolate, &exceptionInfo );
1275 replaceImage( newImage );
1276 throwException( exceptionInfo );
1277 (void) DestroyExceptionInfo( &exceptionInfo );
1280 // implements the inverse discrete Fourier transform (IFT) of the image either
1281 // as a magnitude / phase or real / imaginary image pair.
1282 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1284 ExceptionInfo exceptionInfo;
1285 GetExceptionInfo( &exceptionInfo );
1286 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1287 phase_.constImage(), MagickTrue, &exceptionInfo);
1288 replaceImage( newImage );
1289 throwException( exceptionInfo );
1290 (void) DestroyExceptionInfo( &exceptionInfo );
1292 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1293 const bool magnitude_ )
1295 ExceptionInfo exceptionInfo;
1296 GetExceptionInfo( &exceptionInfo );
1297 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1298 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1300 replaceImage( newImage );
1301 throwException( exceptionInfo );
1302 (void) DestroyExceptionInfo( &exceptionInfo );
1305 // Level image. Adjust the levels of the image by scaling the colors
1306 // falling between specified white and black points to the full
1307 // available quantum range. The parameters provided represent the
1308 // black, mid (gamma), and white points. The black point specifies
1309 // the darkest color in the image. Colors darker than the black point
1310 // are set to zero. Mid point (gamma) specifies a gamma correction to
1311 // apply to the image. White point specifies the lightest color in the
1312 // image. Colors brighter than the white point are set to the maximum
1313 // quantum value. The black and white point have the valid range 0 to
1314 // QuantumRange while gamma has a useful range of 0 to ten.
1315 void Magick::Image::level ( const double black_point,
1316 const double white_point,
1317 const double gamma )
1319 ExceptionInfo exceptionInfo;
1320 GetExceptionInfo( &exceptionInfo );
1322 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1323 throwException( exceptionInfo );
1324 (void) DestroyExceptionInfo( &exceptionInfo );
1327 // Magnify image by integral size
1328 void Magick::Image::magnify ( void )
1330 ExceptionInfo exceptionInfo;
1331 GetExceptionInfo( &exceptionInfo );
1332 MagickCore::Image* newImage =
1333 MagnifyImage( image(), &exceptionInfo );
1334 replaceImage( newImage );
1335 throwException( exceptionInfo );
1336 (void) DestroyExceptionInfo( &exceptionInfo );
1339 // Remap image colors with closest color from reference image
1340 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1342 ExceptionInfo exceptionInfo;
1343 GetExceptionInfo( &exceptionInfo );
1345 options()->quantizeDither( dither_ );
1346 RemapImage ( options()->quantizeInfo(), image(),
1347 mapImage_.constImage(), &exceptionInfo);
1348 throwException( exceptionInfo );
1349 (void) DestroyExceptionInfo( &exceptionInfo );
1351 // Floodfill designated area with replacement alpha value
1352 void Magick::Image::matteFloodfill ( const Color &target_ ,
1353 const unsigned int alpha_,
1354 const ssize_t x_, const ssize_t y_,
1355 const Magick::PaintMethod method_ )
1359 GetPixelInfo(constImage(),&target);
1360 target.red=static_cast<PixelInfo>(target_).red;
1361 target.green=static_cast<PixelInfo>(target_).green;
1362 target.blue=static_cast<PixelInfo>(target_).blue;
1363 target.alpha=alpha_;
1364 ChannelType channel_mask = SetPixelChannelMask( image(), AlphaChannel );
1365 ExceptionInfo exceptionInfo;
1366 GetExceptionInfo( &exceptionInfo );
1367 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1368 method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
1369 (void) SetPixelChannelMapMask( image(), channel_mask );
1370 throwException( exceptionInfo );
1371 (void) DestroyExceptionInfo( &exceptionInfo );
1374 // Filter image by replacing each pixel component with the median
1375 // color in a circular neighborhood
1376 void Magick::Image::medianFilter ( const double radius_ )
1378 ExceptionInfo exceptionInfo;
1379 GetExceptionInfo( &exceptionInfo );
1380 MagickCore::Image* newImage =
1381 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1382 radius_,&exceptionInfo );
1383 replaceImage( newImage );
1384 throwException( exceptionInfo );
1385 (void) DestroyExceptionInfo( &exceptionInfo );
1388 // Reduce image by integral size
1389 void Magick::Image::minify ( void )
1391 ExceptionInfo exceptionInfo;
1392 GetExceptionInfo( &exceptionInfo );
1393 MagickCore::Image* newImage =
1394 MinifyImage( image(), &exceptionInfo );
1395 replaceImage( newImage );
1396 throwException( exceptionInfo );
1397 (void) DestroyExceptionInfo( &exceptionInfo );
1400 // Modulate percent hue, saturation, and brightness of an image
1401 void Magick::Image::modulate ( const double brightness_,
1402 const double saturation_,
1405 char modulate[MaxTextExtent + 1];
1406 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1407 brightness_, saturation_, hue_);
1409 ExceptionInfo exceptionInfo;
1410 GetExceptionInfo( &exceptionInfo );
1412 ModulateImage( image(), modulate, &exceptionInfo );
1413 throwException( exceptionInfo );
1414 (void) DestroyExceptionInfo( &exceptionInfo );
1417 // Motion blur image with specified blur factor
1418 // The radius_ parameter specifies the radius of the Gaussian, in
1419 // pixels, not counting the center pixel. The sigma_ parameter
1420 // specifies the standard deviation of the Laplacian, in pixels.
1421 // The angle_ parameter specifies the angle the object appears
1422 // to be comming from (zero degrees is from the right).
1423 void Magick::Image::motionBlur ( const double radius_,
1424 const double sigma_,
1425 const double angle_ )
1427 ExceptionInfo exceptionInfo;
1428 GetExceptionInfo( &exceptionInfo );
1429 MagickCore::Image* newImage =
1430 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1431 replaceImage( newImage );
1432 throwException( exceptionInfo );
1433 (void) DestroyExceptionInfo( &exceptionInfo );
1436 // Negate image. Set grayscale_ to true to effect grayscale values
1438 void Magick::Image::negate ( const bool grayscale_ )
1440 ExceptionInfo exceptionInfo;
1441 GetExceptionInfo( &exceptionInfo );
1443 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1445 throwException( exceptionInfo );
1446 (void) DestroyExceptionInfo( &exceptionInfo );
1450 void Magick::Image::normalize ( void )
1453 ExceptionInfo exceptionInfo;
1454 GetExceptionInfo( &exceptionInfo );
1455 NormalizeImage ( image(), &exceptionInfo );
1456 throwException( exceptionInfo );
1457 (void) DestroyExceptionInfo( &exceptionInfo );
1461 void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
1463 ExceptionInfo exceptionInfo;
1464 GetExceptionInfo( &exceptionInfo );
1465 MagickCore::Image* newImage =
1466 OilPaintImage( image(), radius_, sigma_, &exceptionInfo );
1467 replaceImage( newImage );
1468 throwException( exceptionInfo );
1469 (void) DestroyExceptionInfo( &exceptionInfo );
1472 // Set or attenuate the alpha channel. If the image pixels are
1473 // opaque then they are set to the specified alpha value, otherwise
1474 // they are blended with the supplied alpha value. The value of
1475 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1476 // OpaqueAlpha and TransparentAlpha are available to specify
1477 // completely opaque or completely transparent, respectively.
1478 void Magick::Image::alpha ( const unsigned int alpha_ )
1481 ExceptionInfo exceptionInfo;
1482 GetExceptionInfo( &exceptionInfo );
1483 SetImageAlpha( image(), alpha_, &exceptionInfo );
1484 throwException( exceptionInfo );
1485 (void) DestroyExceptionInfo( &exceptionInfo );
1488 // Change the color of an opaque pixel to the pen color.
1489 void Magick::Image::opaque ( const Color &opaqueColor_,
1490 const Color &penColor_ )
1492 if ( !opaqueColor_.isValid() )
1494 throwExceptionExplicit( OptionError,
1495 "Opaque color argument is invalid" );
1497 if ( !penColor_.isValid() )
1499 throwExceptionExplicit( OptionError,
1500 "Pen color argument is invalid" );
1504 std::string opaqueColor = opaqueColor_;
1505 std::string penColor = penColor_;
1509 ExceptionInfo exceptionInfo;
1510 GetExceptionInfo( &exceptionInfo );
1511 (void) QueryColorCompliance(std::string(opaqueColor_).c_str(),
1512 AllCompliance, &opaque, &exceptionInfo);
1513 (void) QueryColorCompliance(std::string(penColor_).c_str(),
1514 AllCompliance, &pen, &exceptionInfo);
1515 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo );
1516 throwException( exceptionInfo );
1517 (void) DestroyExceptionInfo( &exceptionInfo );
1520 // Ping is similar to read except only enough of the image is read to
1521 // determine the image columns, rows, and filesize. Access the
1522 // columns(), rows(), and fileSize() attributes after invoking ping.
1523 // The image data is not valid after calling ping.
1524 void Magick::Image::ping ( const std::string &imageSpec_ )
1526 options()->fileName( imageSpec_ );
1527 ExceptionInfo exceptionInfo;
1528 GetExceptionInfo( &exceptionInfo );
1529 MagickCore::Image* image =
1530 PingImage( imageInfo(), &exceptionInfo );
1531 replaceImage( image );
1532 throwException( exceptionInfo );
1533 (void) DestroyExceptionInfo( &exceptionInfo );
1536 // Ping is similar to read except only enough of the image is read
1537 // to determine the image columns, rows, and filesize. Access the
1538 // columns(), rows(), and fileSize() attributes after invoking
1539 // ping. The image data is not valid after calling ping.
1540 void Magick::Image::ping ( const Blob& blob_ )
1542 ExceptionInfo exceptionInfo;
1543 GetExceptionInfo( &exceptionInfo );
1544 MagickCore::Image* image =
1545 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1546 replaceImage( image );
1547 throwException( exceptionInfo );
1548 (void) DestroyExceptionInfo( &exceptionInfo );
1551 // Execute a named process module using an argc/argv syntax similar to
1552 // that accepted by a C 'main' routine. An exception is thrown if the
1553 // requested process module doesn't exist, fails to load, or fails during
1555 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1559 ExceptionInfo exceptionInfo;
1560 GetExceptionInfo( &exceptionInfo );
1562 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1565 throwException( exceptionInfo );
1566 (void) DestroyExceptionInfo( &exceptionInfo );
1569 // Quantize colors in image using current quantization settings
1570 // Set measureError_ to true in order to measure quantization error
1571 void Magick::Image::quantize ( const bool measureError_ )
1576 options()->quantizeInfo()->measure_error=MagickTrue;
1578 options()->quantizeInfo()->measure_error=MagickFalse;
1580 ExceptionInfo exceptionInfo;
1581 GetExceptionInfo( &exceptionInfo );
1582 QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo );
1584 throwException( exceptionInfo );
1585 (void) DestroyExceptionInfo( &exceptionInfo );
1588 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1589 void Magick::Image::quantumOperator ( const ChannelType channel_,
1590 const MagickEvaluateOperator operator_,
1593 ExceptionInfo exceptionInfo;
1594 GetExceptionInfo( &exceptionInfo );
1595 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1596 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
1597 (void) SetPixelChannelMapMask( image(), channel_mask );
1598 throwException( exceptionInfo );
1599 (void) DestroyExceptionInfo( &exceptionInfo );
1602 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1603 const size_t columns_,
1605 const ChannelType channel_,
1606 const MagickEvaluateOperator operator_,
1607 const double rvalue_)
1609 ExceptionInfo exceptionInfo;
1610 GetExceptionInfo( &exceptionInfo );
1611 RectangleInfo geometry;
1612 geometry.width = columns_;
1613 geometry.height = rows_;
1616 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1618 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1619 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
1620 (void) SetPixelChannelMapMask( image(), channel_mask );
1621 (void) CompositeImage( image(), crop_image, image()->matte != MagickFalse ?
1622 OverCompositeOp : CopyCompositeOp, MagickFalse, geometry.x, geometry.y,
1624 crop_image = DestroyImageList(crop_image);
1625 throwException( exceptionInfo );
1626 (void) DestroyExceptionInfo( &exceptionInfo );
1629 // Raise image (lighten or darken the edges of an image to give a 3-D
1630 // raised or lowered effect)
1631 void Magick::Image::raise ( const Geometry &geometry_ ,
1632 const bool raisedFlag_ )
1634 ExceptionInfo exceptionInfo;
1635 GetExceptionInfo( &exceptionInfo );
1636 RectangleInfo raiseInfo = geometry_;
1638 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
1639 throwException( exceptionInfo );
1640 (void) DestroyExceptionInfo( &exceptionInfo );
1644 // Random threshold image.
1646 // Changes the value of individual pixels based on the intensity
1647 // of each pixel compared to a random threshold. The result is a
1648 // low-contrast, two color image. The thresholds_ argument is a
1649 // geometry containing LOWxHIGH thresholds. If the string
1650 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1651 // 3, or 4 will be performed instead. If a channel_ argument is
1652 // specified then only the specified channel is altered. This is
1653 // a very fast alternative to 'quantize' based dithering.
1654 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1656 randomThresholdChannel(thresholds_,DefaultChannels);
1658 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1659 const ChannelType channel_ )
1661 ExceptionInfo exceptionInfo;
1662 GetExceptionInfo( &exceptionInfo );
1664 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1665 (void) RandomThresholdImage( image(),
1666 static_cast<std::string>(thresholds_).c_str(),
1668 (void) SetPixelChannelMapMask( image(), channel_mask );
1669 throwImageException();
1670 (void) DestroyExceptionInfo( &exceptionInfo );
1673 // Read image into current object
1674 void Magick::Image::read ( const std::string &imageSpec_ )
1676 options()->fileName( imageSpec_ );
1678 ExceptionInfo exceptionInfo;
1679 GetExceptionInfo( &exceptionInfo );
1680 MagickCore::Image* image =
1681 ReadImage( imageInfo(), &exceptionInfo );
1683 // Ensure that multiple image frames were not read.
1684 if ( image && image->next )
1686 // Destroy any extra image frames
1687 MagickCore::Image* next = image->next;
1690 DestroyImageList( next );
1693 replaceImage( image );
1694 throwException( exceptionInfo );
1695 (void) DestroyExceptionInfo( &exceptionInfo );
1698 // Read image of specified size into current object
1699 void Magick::Image::read ( const Geometry &size_,
1700 const std::string &imageSpec_ )
1706 // Read image from in-memory BLOB
1707 void Magick::Image::read ( const Blob &blob_ )
1709 ExceptionInfo exceptionInfo;
1710 GetExceptionInfo( &exceptionInfo );
1711 MagickCore::Image* image =
1712 BlobToImage( imageInfo(),
1713 static_cast<const void *>(blob_.data()),
1714 blob_.length(), &exceptionInfo );
1715 replaceImage( image );
1716 throwException( exceptionInfo );
1717 (void) DestroyExceptionInfo( &exceptionInfo );
1720 // Read image of specified size from in-memory BLOB
1721 void Magick::Image::read ( const Blob &blob_,
1722 const Geometry &size_ )
1730 // Read image of specified size and depth from in-memory BLOB
1731 void Magick::Image::read ( const Blob &blob_,
1732 const Geometry &size_,
1733 const size_t depth_ )
1743 // Read image of specified size, depth, and format from in-memory BLOB
1744 void Magick::Image::read ( const Blob &blob_,
1745 const Geometry &size_,
1746 const size_t depth_,
1747 const std::string &magick_ )
1755 // Set explicit image format
1756 fileName( magick_ + ':');
1761 // Read image of specified size, and format from in-memory BLOB
1762 void Magick::Image::read ( const Blob &blob_,
1763 const Geometry &size_,
1764 const std::string &magick_ )
1770 // Set explicit image format
1771 fileName( magick_ + ':');
1776 // Read image based on raw pixels in memory (ConstituteImage)
1777 void Magick::Image::read ( const size_t width_,
1778 const size_t height_,
1779 const std::string &map_,
1780 const StorageType type_,
1781 const void *pixels_ )
1783 ExceptionInfo exceptionInfo;
1784 GetExceptionInfo( &exceptionInfo );
1785 MagickCore::Image* image =
1786 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1788 replaceImage( image );
1789 throwException( exceptionInfo );
1790 (void) DestroyExceptionInfo( &exceptionInfo );
1793 // Reduce noise in image
1794 void Magick::Image::reduceNoise ( const double order_ )
1796 ExceptionInfo exceptionInfo;
1797 GetExceptionInfo( &exceptionInfo );
1798 MagickCore::Image* newImage =
1799 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1801 replaceImage( newImage );
1802 throwException( exceptionInfo );
1803 (void) DestroyExceptionInfo( &exceptionInfo );
1807 void Magick::Image::resize( const Geometry &geometry_ )
1809 // Calculate new size. This code should be supported using binary arguments
1810 // in the ImageMagick library.
1813 size_t width = columns();
1814 size_t height = rows();
1816 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1820 ExceptionInfo exceptionInfo;
1821 GetExceptionInfo( &exceptionInfo );
1822 MagickCore::Image* newImage =
1823 ResizeImage( image(),
1828 replaceImage( newImage );
1829 throwException( exceptionInfo );
1830 (void) DestroyExceptionInfo( &exceptionInfo );
1834 void Magick::Image::roll ( const Geometry &roll_ )
1836 ssize_t xOff = roll_.xOff();
1837 if ( roll_.xNegative() )
1839 ssize_t yOff = roll_.yOff();
1840 if ( roll_.yNegative() )
1843 ExceptionInfo exceptionInfo;
1844 GetExceptionInfo( &exceptionInfo );
1845 MagickCore::Image* newImage =
1846 RollImage( image(), xOff, yOff, &exceptionInfo );
1847 replaceImage( newImage );
1848 throwException( exceptionInfo );
1849 (void) DestroyExceptionInfo( &exceptionInfo );
1851 void Magick::Image::roll ( const size_t columns_,
1852 const size_t rows_ )
1854 ExceptionInfo exceptionInfo;
1855 GetExceptionInfo( &exceptionInfo );
1856 MagickCore::Image* newImage =
1858 static_cast<ssize_t>(columns_),
1859 static_cast<ssize_t>(rows_), &exceptionInfo );
1860 replaceImage( newImage );
1861 throwException( exceptionInfo );
1862 (void) DestroyExceptionInfo( &exceptionInfo );
1866 void Magick::Image::rotate ( const double degrees_ )
1868 ExceptionInfo exceptionInfo;
1869 GetExceptionInfo( &exceptionInfo );
1870 MagickCore::Image* newImage =
1871 RotateImage( image(), degrees_, &exceptionInfo);
1872 replaceImage( newImage );
1873 throwException( exceptionInfo );
1874 (void) DestroyExceptionInfo( &exceptionInfo );
1878 void Magick::Image::sample ( const Geometry &geometry_ )
1882 size_t width = columns();
1883 size_t height = rows();
1885 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1889 ExceptionInfo exceptionInfo;
1890 GetExceptionInfo( &exceptionInfo );
1891 MagickCore::Image* newImage =
1892 SampleImage( image(), width, height, &exceptionInfo );
1893 replaceImage( newImage );
1894 throwException( exceptionInfo );
1895 (void) DestroyExceptionInfo( &exceptionInfo );
1899 void Magick::Image::scale ( const Geometry &geometry_ )
1903 size_t width = columns();
1904 size_t height = rows();
1906 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1910 ExceptionInfo exceptionInfo;
1911 GetExceptionInfo( &exceptionInfo );
1912 MagickCore::Image* newImage =
1913 ScaleImage( image(), width, height, &exceptionInfo );
1914 replaceImage( newImage );
1915 throwException( exceptionInfo );
1916 (void) DestroyExceptionInfo( &exceptionInfo );
1919 // Segment (coalesce similar image components) by analyzing the
1920 // histograms of the color components and identifying units that are
1921 // homogeneous with the fuzzy c-means technique.
1922 void Magick::Image::segment ( const double clusterThreshold_,
1923 const double smoothingThreshold_ )
1925 ExceptionInfo exceptionInfo;
1926 GetExceptionInfo( &exceptionInfo );
1928 SegmentImage ( image(),
1929 options()->quantizeColorSpace(),
1930 (MagickBooleanType) options()->verbose(),
1932 smoothingThreshold_, &exceptionInfo );
1933 SyncImage( image(), &exceptionInfo );
1934 throwException( exceptionInfo );
1935 (void) DestroyExceptionInfo( &exceptionInfo );
1938 // Shade image using distant light source
1939 void Magick::Image::shade ( const double azimuth_,
1940 const double elevation_,
1941 const bool colorShading_ )
1943 ExceptionInfo exceptionInfo;
1944 GetExceptionInfo( &exceptionInfo );
1945 MagickCore::Image* newImage =
1946 ShadeImage( image(),
1947 colorShading_ == true ? MagickTrue : MagickFalse,
1951 replaceImage( newImage );
1952 throwException( exceptionInfo );
1953 (void) DestroyExceptionInfo( &exceptionInfo );
1956 // Simulate an image shadow
1957 void Magick::Image::shadow( const double percent_opacity_, const double sigma_,
1958 const ssize_t x_, const ssize_t y_ )
1960 ExceptionInfo exceptionInfo;
1961 GetExceptionInfo( &exceptionInfo );
1962 MagickCore::Image* newImage = ShadowImage( image(), percent_opacity_, sigma_,
1963 x_, y_, &exceptionInfo );
1964 replaceImage( newImage );
1965 throwException( exceptionInfo );
1966 (void) DestroyExceptionInfo( &exceptionInfo );
1969 // Sharpen pixels in image
1970 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1972 ExceptionInfo exceptionInfo;
1973 GetExceptionInfo( &exceptionInfo );
1974 MagickCore::Image* newImage =
1975 SharpenImage( image(),
1979 replaceImage( newImage );
1980 throwException( exceptionInfo );
1981 (void) DestroyExceptionInfo( &exceptionInfo );
1984 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1985 const double radius_, const double sigma_ )
1987 ExceptionInfo exceptionInfo;
1988 GetExceptionInfo( &exceptionInfo );
1989 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1990 MagickCore::Image* newImage =
1991 SharpenImage( image(),
1995 (void) SetPixelChannelMapMask( image(), channel_mask );
1996 replaceImage( newImage );
1997 throwException( exceptionInfo );
1998 (void) DestroyExceptionInfo( &exceptionInfo );
2001 // Shave pixels from image edges.
2002 void Magick::Image::shave ( const Geometry &geometry_ )
2004 RectangleInfo shaveInfo = geometry_;
2005 ExceptionInfo exceptionInfo;
2006 GetExceptionInfo( &exceptionInfo );
2007 MagickCore::Image* newImage =
2008 ShaveImage( image(),
2011 replaceImage( newImage );
2012 throwException( exceptionInfo );
2013 (void) DestroyExceptionInfo( &exceptionInfo );
2017 void Magick::Image::shear ( const double xShearAngle_,
2018 const double yShearAngle_ )
2020 ExceptionInfo exceptionInfo;
2021 GetExceptionInfo( &exceptionInfo );
2022 MagickCore::Image* newImage =
2023 ShearImage( image(),
2027 replaceImage( newImage );
2028 throwException( exceptionInfo );
2029 (void) DestroyExceptionInfo( &exceptionInfo );
2033 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
2035 ExceptionInfo exceptionInfo;
2036 GetExceptionInfo( &exceptionInfo );
2038 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
2039 throwException( exceptionInfo );
2040 (void) DestroyExceptionInfo( &exceptionInfo );
2043 // Solarize image (similar to effect seen when exposing a photographic
2044 // film to light during the development process)
2045 void Magick::Image::solarize ( const double factor_ )
2047 ExceptionInfo exceptionInfo;
2048 GetExceptionInfo( &exceptionInfo );
2050 SolarizeImage ( image(), factor_, &exceptionInfo );
2051 throwException( exceptionInfo );
2052 (void) DestroyExceptionInfo( &exceptionInfo );
2055 // Sparse color image, given a set of coordinates, interpolates the colors
2056 // found at those coordinates, across the whole image, using various methods.
2058 void Magick::Image::sparseColor ( const ChannelType channel,
2059 const SparseColorMethod method,
2060 const size_t number_arguments,
2061 const double *arguments )
2063 ExceptionInfo exceptionInfo;
2064 GetExceptionInfo( &exceptionInfo );
2066 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
2067 MagickCore::Image* newImage = SparseColorImage ( image(), method,
2068 number_arguments, arguments, &exceptionInfo );
2069 (void) SetPixelChannelMapMask( image(), channel_mask );
2070 replaceImage( newImage );
2071 throwException( exceptionInfo );
2072 (void) DestroyExceptionInfo( &exceptionInfo );
2075 // Spread pixels randomly within image by specified ammount
2076 void Magick::Image::spread ( const size_t amount_ )
2078 ExceptionInfo exceptionInfo;
2079 GetExceptionInfo( &exceptionInfo );
2080 MagickCore::Image* newImage =
2081 SpreadImage( image(),
2083 image()->interpolate,
2085 replaceImage( newImage );
2086 throwException( exceptionInfo );
2087 (void) DestroyExceptionInfo( &exceptionInfo );
2090 // Add a digital watermark to the image (based on second image)
2091 void Magick::Image::stegano ( const Image &watermark_ )
2093 ExceptionInfo exceptionInfo;
2094 GetExceptionInfo( &exceptionInfo );
2095 MagickCore::Image* newImage =
2096 SteganoImage( image(),
2097 watermark_.constImage(),
2099 replaceImage( newImage );
2100 throwException( exceptionInfo );
2101 (void) DestroyExceptionInfo( &exceptionInfo );
2104 // Stereo image (left image is current image)
2105 void Magick::Image::stereo ( const Image &rightImage_ )
2107 ExceptionInfo exceptionInfo;
2108 GetExceptionInfo( &exceptionInfo );
2109 MagickCore::Image* newImage =
2110 StereoImage( image(),
2111 rightImage_.constImage(),
2113 replaceImage( newImage );
2114 throwException( exceptionInfo );
2115 (void) DestroyExceptionInfo( &exceptionInfo );
2119 void Magick::Image::swirl ( const double degrees_ )
2121 ExceptionInfo exceptionInfo;
2122 GetExceptionInfo( &exceptionInfo );
2123 MagickCore::Image* newImage =
2124 SwirlImage( image(), degrees_, image()->interpolate,
2126 replaceImage( newImage );
2127 throwException( exceptionInfo );
2128 (void) DestroyExceptionInfo( &exceptionInfo );
2132 void Magick::Image::texture ( const Image &texture_ )
2135 ExceptionInfo exceptionInfo;
2136 GetExceptionInfo( &exceptionInfo );
2137 TextureImage( image(), texture_.constImage(), &exceptionInfo );
2138 throwException( exceptionInfo );
2139 (void) DestroyExceptionInfo( &exceptionInfo );
2143 void Magick::Image::threshold ( const double threshold_ )
2146 ExceptionInfo exceptionInfo;
2147 GetExceptionInfo( &exceptionInfo );
2148 BilevelImage( image(), threshold_, &exceptionInfo );
2149 throwException( exceptionInfo );
2150 (void) DestroyExceptionInfo( &exceptionInfo );
2153 // Transform image based on image geometry only
2154 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2157 ExceptionInfo exceptionInfo;
2158 GetExceptionInfo( &exceptionInfo );
2159 TransformImage ( &(image()), 0,
2160 std::string(imageGeometry_).c_str(), &exceptionInfo );
2161 throwException( exceptionInfo );
2162 (void) DestroyExceptionInfo( &exceptionInfo );
2164 // Transform image based on image and crop geometries
2165 void Magick::Image::transform ( const Geometry &imageGeometry_,
2166 const Geometry &cropGeometry_ )
2169 ExceptionInfo exceptionInfo;
2170 GetExceptionInfo( &exceptionInfo );
2171 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2172 std::string(imageGeometry_).c_str(), &exceptionInfo );
2173 throwException( exceptionInfo );
2174 (void) DestroyExceptionInfo( &exceptionInfo );
2177 // Add matte image to image, setting pixels matching color to transparent
2178 void Magick::Image::transparent ( const Color &color_ )
2180 if ( !color_.isValid() )
2182 throwExceptionExplicit( OptionError,
2183 "Color argument is invalid" );
2186 std::string color = color_;
2189 ExceptionInfo exceptionInfo;
2190 GetExceptionInfo( &exceptionInfo );
2191 (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
2192 &target,&exceptionInfo);
2194 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2196 throwException( exceptionInfo );
2197 (void) DestroyExceptionInfo( &exceptionInfo );
2200 // Add matte image to image, setting pixels matching color to transparent
2201 void Magick::Image::transparentChroma(const Color &colorLow_,
2202 const Color &colorHigh_)
2204 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2206 throwExceptionExplicit( OptionError,
2207 "Color argument is invalid" );
2210 std::string colorLow = colorLow_;
2211 std::string colorHigh = colorHigh_;
2213 PixelInfo targetLow;
2214 PixelInfo targetHigh;
2215 ExceptionInfo exceptionInfo;
2216 GetExceptionInfo( &exceptionInfo );
2217 (void) QueryColorCompliance(std::string(colorLow_).c_str(),
2218 AllCompliance,&targetLow,&exceptionInfo);
2219 (void) QueryColorCompliance(std::string(colorHigh_).c_str(),
2220 AllCompliance,&targetHigh,&exceptionInfo);
2222 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2223 TransparentAlpha, MagickFalse, &exceptionInfo );
2224 throwException( exceptionInfo );
2225 (void) DestroyExceptionInfo( &exceptionInfo );
2229 // Trim edges that are the background color from the image
2230 void Magick::Image::trim ( void )
2232 ExceptionInfo exceptionInfo;
2233 GetExceptionInfo( &exceptionInfo );
2234 MagickCore::Image* newImage =
2235 TrimImage( image(), &exceptionInfo);
2236 replaceImage( newImage );
2237 throwException( exceptionInfo );
2238 (void) DestroyExceptionInfo( &exceptionInfo );
2241 // Replace image with a sharpened version of the original image
2242 // using the unsharp mask algorithm.
2244 // the radius of the Gaussian, in pixels, not counting the
2247 // the standard deviation of the Gaussian, in pixels.
2249 // the percentage of the difference between the original and
2250 // the blur image that is added back into the original.
2252 // the threshold in pixels needed to apply the diffence amount.
2253 void Magick::Image::unsharpmask ( const double radius_,
2254 const double sigma_,
2255 const double amount_,
2256 const double threshold_ )
2258 ExceptionInfo exceptionInfo;
2259 GetExceptionInfo( &exceptionInfo );
2260 MagickCore::Image* newImage =
2261 UnsharpMaskImage( image(),
2267 replaceImage( newImage );
2268 throwException( exceptionInfo );
2269 (void) DestroyExceptionInfo( &exceptionInfo );
2272 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2273 const double radius_,
2274 const double sigma_,
2275 const double amount_,
2276 const double threshold_ )
2278 ExceptionInfo exceptionInfo;
2279 GetExceptionInfo( &exceptionInfo );
2280 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
2281 MagickCore::Image* newImage =
2282 UnsharpMaskImage( image(),
2288 (void) SetPixelChannelMapMask( image(), channel_mask );
2289 replaceImage( newImage );
2290 throwException( exceptionInfo );
2291 (void) DestroyExceptionInfo( &exceptionInfo );
2294 // Map image pixels to a sine wave
2295 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2297 ExceptionInfo exceptionInfo;
2298 GetExceptionInfo( &exceptionInfo );
2299 MagickCore::Image* newImage =
2303 image()->interpolate,
2305 replaceImage( newImage );
2306 throwException( exceptionInfo );
2307 (void) DestroyExceptionInfo( &exceptionInfo );
2310 // Write image to file
2311 void Magick::Image::write( const std::string &imageSpec_ )
2313 ExceptionInfo exceptionInfo;
2314 GetExceptionInfo( &exceptionInfo );
2316 fileName( imageSpec_ );
2317 WriteImage( imageInfo(), image(), &exceptionInfo );
2318 throwException( exceptionInfo );
2319 (void) DestroyExceptionInfo( &exceptionInfo );
2322 // Write image to in-memory BLOB
2323 void Magick::Image::write ( Blob *blob_ )
2326 size_t length = 2048; // Efficient size for small images
2327 ExceptionInfo exceptionInfo;
2328 GetExceptionInfo( &exceptionInfo );
2329 void* data = ImageToBlob( imageInfo(),
2333 throwException( exceptionInfo );
2334 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2335 throwImageException();
2336 (void) DestroyExceptionInfo( &exceptionInfo );
2338 void Magick::Image::write ( Blob *blob_,
2339 const std::string &magick_ )
2343 size_t length = 2048; // Efficient size for small images
2344 ExceptionInfo exceptionInfo;
2345 GetExceptionInfo( &exceptionInfo );
2346 void* data = ImageToBlob( imageInfo(),
2350 throwException( exceptionInfo );
2351 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2352 throwImageException();
2353 (void) DestroyExceptionInfo( &exceptionInfo );
2355 void Magick::Image::write ( Blob *blob_,
2356 const std::string &magick_,
2357 const size_t depth_ )
2362 size_t length = 2048; // Efficient size for small images
2363 ExceptionInfo exceptionInfo;
2364 GetExceptionInfo( &exceptionInfo );
2365 void* data = ImageToBlob( imageInfo(),
2369 throwException( exceptionInfo );
2370 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2371 throwImageException();
2372 (void) DestroyExceptionInfo( &exceptionInfo );
2375 // Write image to an array of pixels with storage type specified
2376 // by user (ExportImagePixels), e.g.
2377 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2378 void Magick::Image::write ( const ssize_t x_,
2380 const size_t columns_,
2382 const std::string &map_,
2383 const StorageType type_,
2386 ExceptionInfo exceptionInfo;
2387 GetExceptionInfo( &exceptionInfo );
2388 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2391 throwException( exceptionInfo );
2392 (void) DestroyExceptionInfo( &exceptionInfo );
2396 void Magick::Image::zoom( const Geometry &geometry_ )
2398 // Calculate new size. This code should be supported using binary arguments
2399 // in the ImageMagick library.
2402 size_t width = columns();
2403 size_t height = rows();
2405 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2409 ExceptionInfo exceptionInfo;
2410 GetExceptionInfo( &exceptionInfo );
2411 MagickCore::Image* newImage =
2412 ResizeImage( image(),
2417 replaceImage( newImage );
2418 throwException( exceptionInfo );
2419 (void) DestroyExceptionInfo( &exceptionInfo );
2423 * Methods for setting image attributes
2427 // Join images into a single multi-image file
2428 void Magick::Image::adjoin ( const bool flag_ )
2431 options()->adjoin( flag_ );
2433 bool Magick::Image::adjoin ( void ) const
2435 return constOptions()->adjoin();
2438 // Remove pixel aliasing
2439 void Magick::Image::antiAlias( const bool flag_ )
2442 options()->antiAlias( static_cast<size_t>(flag_) );
2444 bool Magick::Image::antiAlias( void )
2446 return static_cast<bool>( options()->antiAlias( ) );
2449 // Animation inter-frame delay
2450 void Magick::Image::animationDelay ( const size_t delay_ )
2453 image()->delay = delay_;
2455 size_t Magick::Image::animationDelay ( void ) const
2457 return constImage()->delay;
2460 // Number of iterations to play animation
2461 void Magick::Image::animationIterations ( const size_t iterations_ )
2464 image()->iterations = iterations_;
2466 size_t Magick::Image::animationIterations ( void ) const
2468 return constImage()->iterations;
2471 // Access/Update a named image attribute
2472 void Magick::Image::attribute ( const std::string name_,
2473 const std::string value_ )
2476 ExceptionInfo exceptionInfo;
2477 GetExceptionInfo( &exceptionInfo );
2478 SetImageProperty( image(), name_.c_str(), value_.c_str(), &exceptionInfo );
2479 throwException( exceptionInfo );
2480 (void) DestroyExceptionInfo( &exceptionInfo );
2482 std::string Magick::Image::attribute ( const std::string name_ )
2484 ExceptionInfo exceptionInfo;
2485 GetExceptionInfo( &exceptionInfo );
2486 const char *value = GetImageProperty( constImage(), name_.c_str(),
2488 throwException( exceptionInfo );
2489 (void) DestroyExceptionInfo( &exceptionInfo );
2492 return std::string( value );
2494 return std::string(); // Intentionally no exception
2498 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2502 if ( backgroundColor_.isValid() )
2504 image()->background_color = backgroundColor_;
2508 image()->background_color = Color();
2511 options()->backgroundColor( backgroundColor_ );
2513 Magick::Color Magick::Image::backgroundColor ( void ) const
2515 return constOptions()->backgroundColor( );
2518 // Background fill texture
2519 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2522 options()->backgroundTexture( backgroundTexture_ );
2524 std::string Magick::Image::backgroundTexture ( void ) const
2526 return constOptions()->backgroundTexture( );
2529 // Original image columns
2530 size_t Magick::Image::baseColumns ( void ) const
2532 return constImage()->magick_columns;
2535 // Original image name
2536 std::string Magick::Image::baseFilename ( void ) const
2538 return std::string(constImage()->magick_filename);
2541 // Original image rows
2542 size_t Magick::Image::baseRows ( void ) const
2544 return constImage()->magick_rows;
2548 void Magick::Image::borderColor ( const Color &borderColor_ )
2552 if ( borderColor_.isValid() )
2554 image()->border_color = borderColor_;
2558 image()->border_color = Color();
2561 options()->borderColor( borderColor_ );
2563 Magick::Color Magick::Image::borderColor ( void ) const
2565 return constOptions()->borderColor( );
2568 // Return smallest bounding box enclosing non-border pixels. The
2569 // current fuzz value is used when discriminating between pixels.
2570 // This is the crop bounding box used by crop(Geometry(0,0));
2571 Magick::Geometry Magick::Image::boundingBox ( void ) const
2573 ExceptionInfo exceptionInfo;
2574 GetExceptionInfo( &exceptionInfo );
2575 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2576 throwException( exceptionInfo );
2577 (void) DestroyExceptionInfo( &exceptionInfo );
2578 return Geometry( bbox );
2581 // Text bounding-box base color
2582 void Magick::Image::boxColor ( const Color &boxColor_ )
2585 options()->boxColor( boxColor_ );
2587 Magick::Color Magick::Image::boxColor ( void ) const
2589 return constOptions()->boxColor( );
2592 // Pixel cache threshold. Once this threshold is exceeded, all
2593 // subsequent pixels cache operations are to/from disk.
2594 // This setting is shared by all Image objects.
2596 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2598 SetMagickResourceLimit( MemoryResource, threshold_ );
2601 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2604 image()->chromaticity.blue_primary.x = x_;
2605 image()->chromaticity.blue_primary.y = y_;
2607 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2609 *x_ = constImage()->chromaticity.blue_primary.x;
2610 *y_ = constImage()->chromaticity.blue_primary.y;
2613 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2616 image()->chromaticity.green_primary.x = x_;
2617 image()->chromaticity.green_primary.y = y_;
2619 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2621 *x_ = constImage()->chromaticity.green_primary.x;
2622 *y_ = constImage()->chromaticity.green_primary.y;
2625 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2628 image()->chromaticity.red_primary.x = x_;
2629 image()->chromaticity.red_primary.y = y_;
2631 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2633 *x_ = constImage()->chromaticity.red_primary.x;
2634 *y_ = constImage()->chromaticity.red_primary.y;
2637 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2640 image()->chromaticity.white_point.x = x_;
2641 image()->chromaticity.white_point.y = y_;
2643 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2645 *x_ = constImage()->chromaticity.white_point.x;
2646 *y_ = constImage()->chromaticity.white_point.y;
2649 // Set image storage class
2650 void Magick::Image::classType ( const ClassType class_ )
2652 if ( classType() == PseudoClass && class_ == DirectClass )
2654 // Use SyncImage to synchronize the DirectClass pixels with the
2655 // color map and then set to DirectClass type.
2657 ExceptionInfo exceptionInfo;
2658 GetExceptionInfo( &exceptionInfo );
2659 SyncImage( image(), &exceptionInfo );
2660 throwException( exceptionInfo );
2661 (void) DestroyExceptionInfo( &exceptionInfo );
2662 image()->colormap = (PixelInfo *)
2663 RelinquishMagickMemory( image()->colormap );
2664 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2668 if ( classType() == DirectClass && class_ == PseudoClass )
2670 // Quantize to create PseudoClass color map
2672 quantizeColors(MaxColormapSize);
2674 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2678 // Associate a clip mask with the image. The clip mask must be the
2679 // same dimensions as the image. Pass an invalid image to unset an
2680 // existing clip mask.
2681 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2685 ExceptionInfo exceptionInfo;
2686 GetExceptionInfo( &exceptionInfo );
2687 if( clipMask_.isValid() )
2690 SetImageMask( image(), clipMask_.constImage(), &exceptionInfo );
2694 // Unset existing clip mask
2695 SetImageMask( image(), 0, &exceptionInfo );
2697 throwException( exceptionInfo );
2698 (void) DestroyExceptionInfo( &exceptionInfo );
2700 Magick::Image Magick::Image::clipMask ( void ) const
2702 ExceptionInfo exceptionInfo;
2703 GetExceptionInfo( &exceptionInfo );
2704 MagickCore::Image* image = GetImageMask( constImage(), &exceptionInfo );
2705 throwException( exceptionInfo );
2706 (void) DestroyExceptionInfo( &exceptionInfo );
2707 return Magick::Image( image );
2710 void Magick::Image::colorFuzz ( const double fuzz_ )
2713 image()->fuzz = fuzz_;
2714 options()->colorFuzz( fuzz_ );
2716 double Magick::Image::colorFuzz ( void ) const
2718 return constOptions()->colorFuzz( );
2721 // Set color in colormap at index
2722 void Magick::Image::colorMap ( const size_t index_,
2723 const Color &color_ )
2725 MagickCore::Image* imageptr = image();
2727 if (index_ > (MaxColormapSize-1) )
2728 throwExceptionExplicit( OptionError,
2729 "Colormap index must be less than MaxColormapSize" );
2731 if ( !color_.isValid() )
2732 throwExceptionExplicit( OptionError,
2733 "Color argument is invalid");
2736 // Ensure that colormap size is large enough
2737 if ( colorMapSize() < (index_+1) )
2738 colorMapSize( index_ + 1 );
2740 // Set color at index in colormap
2741 (imageptr->colormap)[index_] = color_;
2743 // Return color in colormap at index
2744 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2746 const MagickCore::Image* imageptr = constImage();
2748 if ( !imageptr->colormap )
2749 throwExceptionExplicit( OptionError,
2750 "Image does not contain a colormap");
2752 if ( index_ > imageptr->colors-1 )
2753 throwExceptionExplicit( OptionError,
2754 "Index out of range");
2756 return Magick::Color( (imageptr->colormap)[index_] );
2759 // Colormap size (number of colormap entries)
2760 void Magick::Image::colorMapSize ( const size_t entries_ )
2762 if (entries_ >MaxColormapSize )
2763 throwExceptionExplicit( OptionError,
2764 "Colormap entries must not exceed MaxColormapSize" );
2768 MagickCore::Image* imageptr = image();
2770 if( !imageptr->colormap )
2772 // Allocate colormap
2773 imageptr->colormap =
2774 static_cast<PixelInfo*>(AcquireMagickMemory(entries_*sizeof(PixelInfo)));
2775 imageptr->colors = 0;
2777 else if ( entries_ > imageptr->colors )
2779 // Re-allocate colormap
2780 imageptr->colormap=(PixelInfo *)
2781 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelInfo));
2784 // Initialize any new colormap entries as all black
2786 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2787 (imageptr->colormap)[i] = black;
2789 imageptr->colors = entries_;
2791 size_t Magick::Image::colorMapSize ( void )
2793 const MagickCore::Image* imageptr = constImage();
2795 if ( !imageptr->colormap )
2796 throwExceptionExplicit( OptionError,
2797 "Image does not contain a colormap");
2799 return imageptr->colors;
2803 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2807 ExceptionInfo exceptionInfo;
2808 GetExceptionInfo( &exceptionInfo );
2809 TransformImageColorspace(image(), colorSpace_, &exceptionInfo);
2810 throwException( exceptionInfo );
2811 (void) DestroyExceptionInfo( &exceptionInfo );
2813 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2815 return constImage()->colorspace;
2818 // Set image colorspace type.
2819 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2822 options()->colorspaceType( colorSpace_ );
2824 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2826 return constOptions()->colorspaceType();
2831 void Magick::Image::comment ( const std::string &comment_ )
2834 ExceptionInfo exceptionInfo;
2835 GetExceptionInfo( &exceptionInfo );
2836 SetImageProperty( image(), "Comment", NULL, &exceptionInfo );
2837 if ( comment_.length() > 0 )
2838 SetImageProperty( image(), "Comment", comment_.c_str(), &exceptionInfo );
2839 throwException( exceptionInfo );
2840 (void) DestroyExceptionInfo( &exceptionInfo );
2842 std::string Magick::Image::comment ( void ) const
2844 ExceptionInfo exceptionInfo;
2845 GetExceptionInfo( &exceptionInfo );
2846 const char *value = GetImageProperty( constImage(), "Comment",
2848 throwException( exceptionInfo );
2849 (void) DestroyExceptionInfo( &exceptionInfo );
2852 return std::string( value );
2854 return std::string(); // Intentionally no exception
2857 // Composition operator to be used when composition is implicitly used
2858 // (such as for image flattening).
2859 void Magick::Image::compose (const CompositeOperator compose_)
2861 image()->compose=compose_;
2864 Magick::CompositeOperator Magick::Image::compose ( void ) const
2866 return constImage()->compose;
2869 // Compression algorithm
2870 void Magick::Image::compressType ( const CompressionType compressType_ )
2873 image()->compression = compressType_;
2874 options()->compressType( compressType_ );
2876 Magick::CompressionType Magick::Image::compressType ( void ) const
2878 return constImage()->compression;
2881 // Enable printing of debug messages from ImageMagick
2882 void Magick::Image::debug ( const bool flag_ )
2885 options()->debug( flag_ );
2887 bool Magick::Image::debug ( void ) const
2889 return constOptions()->debug();
2892 // Tagged image format define (set/access coder-specific option) The
2893 // magick_ option specifies the coder the define applies to. The key_
2894 // option provides the key specific to that coder. The value_ option
2895 // provides the value to set (if any). See the defineSet() method if the
2896 // key must be removed entirely.
2897 void Magick::Image::defineValue ( const std::string &magick_,
2898 const std::string &key_,
2899 const std::string &value_ )
2902 std::string format = magick_ + ":" + key_;
2903 std::string option = value_;
2904 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2906 std::string Magick::Image::defineValue ( const std::string &magick_,
2907 const std::string &key_ ) const
2909 std::string definition = magick_ + ":" + key_;
2910 const char *option =
2911 GetImageOption ( constImageInfo(), definition.c_str() );
2913 return std::string( option );
2914 return std::string( );
2917 // Tagged image format define. Similar to the defineValue() method
2918 // except that passing the flag_ value 'true' creates a value-less
2919 // define with that format and key. Passing the flag_ value 'false'
2920 // removes any existing matching definition. The method returns 'true'
2921 // if a matching key exists, and 'false' if no matching key exists.
2922 void Magick::Image::defineSet ( const std::string &magick_,
2923 const std::string &key_,
2927 std::string definition = magick_ + ":" + key_;
2930 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2934 DeleteImageOption( imageInfo(), definition.c_str() );
2937 bool Magick::Image::defineSet ( const std::string &magick_,
2938 const std::string &key_ ) const
2940 std::string key = magick_ + ":" + key_;
2941 const char *option =
2942 GetImageOption ( constImageInfo(), key.c_str() );
2949 void Magick::Image::density ( const Geometry &density_ )
2952 options()->density( density_ );
2953 if ( density_.isValid() )
2955 image()->resolution.x = density_.width();
2956 if ( density_.height() != 0 )
2958 image()->resolution.y = density_.height();
2962 image()->resolution.y = density_.width();
2968 image()->resolution.x = 0;
2969 image()->resolution.y = 0;
2972 Magick::Geometry Magick::Image::density ( void ) const
2976 ssize_t x_resolution=72;
2977 ssize_t y_resolution=72;
2979 if (constImage()->resolution.x > 0.0)
2980 x_resolution=static_cast<ssize_t>(constImage()->resolution.x + 0.5);
2982 if (constImage()->resolution.y > 0.0)
2983 y_resolution=static_cast<ssize_t>(constImage()->resolution.y + 0.5);
2985 return Geometry(x_resolution,y_resolution);
2988 return constOptions()->density( );
2991 // Image depth (bits allocated to red/green/blue components)
2992 void Magick::Image::depth ( const size_t depth_ )
2994 size_t depth = depth_;
2996 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2997 depth=MAGICKCORE_QUANTUM_DEPTH;
3000 image()->depth=depth;
3001 options()->depth( depth );
3003 size_t Magick::Image::depth ( void ) const
3005 return constImage()->depth;
3008 std::string Magick::Image::directory ( void ) const
3010 if ( constImage()->directory )
3011 return std::string( constImage()->directory );
3013 throwExceptionExplicit( CorruptImageWarning,
3014 "Image does not contain a directory");
3016 return std::string();
3019 // Endianness (little like Intel or big like SPARC) for image
3020 // formats which support endian-specific options.
3021 void Magick::Image::endian ( const Magick::EndianType endian_ )
3024 options()->endian( endian_ );
3025 image()->endian = endian_;
3027 Magick::EndianType Magick::Image::endian ( void ) const
3029 return constImage()->endian;
3032 // EXIF profile (BLOB)
3033 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
3036 if ( exifProfile_.data() != 0 )
3038 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
3039 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
3040 ExceptionInfo exceptionInfo;
3041 GetExceptionInfo( &exceptionInfo );
3042 (void) SetImageProfile( image(), "exif", exif_profile, &exceptionInfo);
3043 exif_profile =DestroyStringInfo( exif_profile );
3044 throwException( exceptionInfo );
3045 (void) DestroyExceptionInfo( &exceptionInfo );
3048 Magick::Blob Magick::Image::exifProfile( void ) const
3050 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
3051 if ( exif_profile == (StringInfo *) NULL)
3052 return Blob( 0, 0 );
3053 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
3057 void Magick::Image::fileName ( const std::string &fileName_ )
3061 fileName_.copy( image()->filename,
3062 sizeof(image()->filename) - 1 );
3063 image()->filename[ fileName_.length() ] = 0; // Null terminate
3065 options()->fileName( fileName_ );
3068 std::string Magick::Image::fileName ( void ) const
3070 return constOptions()->fileName( );
3074 off_t Magick::Image::fileSize ( void ) const
3076 return (off_t) GetBlobSize( constImage() );
3079 // Color to use when drawing inside an object
3080 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3083 options()->fillColor(fillColor_);
3085 Magick::Color Magick::Image::fillColor ( void ) const
3087 return constOptions()->fillColor();
3090 // Rule to use when filling drawn objects
3091 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3094 options()->fillRule(fillRule_);
3096 Magick::FillRule Magick::Image::fillRule ( void ) const
3098 return constOptions()->fillRule();
3101 // Pattern to use while filling drawn objects.
3102 void Magick::Image::fillPattern ( const Image &fillPattern_ )
3105 if(fillPattern_.isValid())
3106 options()->fillPattern( fillPattern_.constImage() );
3108 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3110 Magick::Image Magick::Image::fillPattern ( void ) const
3112 // FIXME: This is inordinately innefficient
3115 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3119 ExceptionInfo exceptionInfo;
3120 GetExceptionInfo( &exceptionInfo );
3121 MagickCore::Image* image =
3122 CloneImage( tmpTexture,
3125 MagickTrue, // orphan
3127 texture.replaceImage( image );
3128 throwException( exceptionInfo );
3129 (void) DestroyExceptionInfo( &exceptionInfo );
3134 // Filter used by zoom
3135 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3138 image()->filter = filterType_;
3140 Magick::FilterTypes Magick::Image::filterType ( void ) const
3142 return constImage()->filter;
3146 void Magick::Image::font ( const std::string &font_ )
3149 options()->font( font_ );
3151 std::string Magick::Image::font ( void ) const
3153 return constOptions()->font( );
3157 void Magick::Image::fontPointsize ( const double pointSize_ )
3160 options()->fontPointsize( pointSize_ );
3162 double Magick::Image::fontPointsize ( void ) const
3164 return constOptions()->fontPointsize( );
3167 // Font type metrics
3168 void Magick::Image::fontTypeMetrics( const std::string &text_,
3169 TypeMetric *metrics )
3171 DrawInfo *drawInfo = options()->drawInfo();
3172 drawInfo->text = const_cast<char *>(text_.c_str());
3173 ExceptionInfo exceptionInfo;
3174 GetExceptionInfo( &exceptionInfo );
3175 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric), &exceptionInfo );
3177 throwException( exceptionInfo );
3178 (void) DestroyExceptionInfo( &exceptionInfo );
3181 // Image format string
3182 std::string Magick::Image::format ( void ) const
3184 ExceptionInfo exceptionInfo;
3185 GetExceptionInfo( &exceptionInfo );
3186 const MagickInfo * magick_info
3187 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3188 throwException( exceptionInfo );
3189 (void) DestroyExceptionInfo( &exceptionInfo );
3191 if (( magick_info != 0 ) &&
3192 ( *magick_info->description != '\0' ))
3193 return std::string(magick_info->description);
3195 throwExceptionExplicit( CorruptImageWarning,
3196 "Unrecognized image magick type" );
3197 return std::string();
3201 double Magick::Image::gamma ( void ) const
3203 return constImage()->gamma;
3206 Magick::Geometry Magick::Image::geometry ( void ) const
3208 if ( constImage()->geometry )
3210 return Geometry(constImage()->geometry);
3213 throwExceptionExplicit( OptionWarning,
3214 "Image does not contain a geometry");
3219 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3222 image()->dispose = (DisposeType) disposeMethod_;
3224 size_t Magick::Image::gifDisposeMethod ( void ) const
3226 // FIXME: It would be better to return an enumeration
3227 return constImage()->dispose;
3230 // ICC ICM color profile (BLOB)
3231 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3233 profile("icm",colorProfile_);
3235 Magick::Blob Magick::Image::iccColorProfile( void ) const
3237 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3238 if ( color_profile == (StringInfo *) NULL)
3239 return Blob( 0, 0 );
3240 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3243 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3246 image()->interlace = interlace_;
3247 options()->interlaceType ( interlace_ );
3249 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3251 return constImage()->interlace;
3254 // IPTC profile (BLOB)
3255 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3258 if ( iptcProfile_.data() != 0 )
3260 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3261 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3262 ExceptionInfo exceptionInfo;
3263 GetExceptionInfo( &exceptionInfo );
3264 (void) SetImageProfile( image(), "iptc", iptc_profile, &exceptionInfo);
3265 iptc_profile =DestroyStringInfo( iptc_profile );
3266 throwException( exceptionInfo );
3267 (void) DestroyExceptionInfo( &exceptionInfo );
3270 Magick::Blob Magick::Image::iptcProfile( void ) const
3272 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3273 if ( iptc_profile == (StringInfo *) NULL)
3274 return Blob( 0, 0 );
3275 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3278 // Does object contain valid image?
3279 void Magick::Image::isValid ( const bool isValid_ )
3284 _imgRef = new ImageRef;
3286 else if ( !isValid() )
3288 // Construct with single-pixel black image to make
3289 // image valid. This is an obvious hack.
3290 size( Geometry(1,1) );
3291 read( "xc:#000000" );
3295 bool Magick::Image::isValid ( void ) const
3297 if ( rows() && columns() )
3304 void Magick::Image::label ( const std::string &label_ )
3307 ExceptionInfo exceptionInfo;
3308 GetExceptionInfo( &exceptionInfo );
3309 SetImageProperty ( image(), "Label", NULL, &exceptionInfo );
3310 if ( label_.length() > 0 )
3311 SetImageProperty ( image(), "Label", label_.c_str(), &exceptionInfo );
3312 throwException( exceptionInfo );
3313 (void) DestroyExceptionInfo( &exceptionInfo );
3315 std::string Magick::Image::label ( void ) const
3317 ExceptionInfo exceptionInfo;
3318 GetExceptionInfo( &exceptionInfo );
3319 const char *value = GetImageProperty( constImage(), "Label", &exceptionInfo );
3320 throwException( exceptionInfo );
3321 (void) DestroyExceptionInfo( &exceptionInfo );
3324 return std::string( value );
3326 return std::string();
3329 void Magick::Image::magick ( const std::string &magick_ )
3333 magick_.copy( image()->magick,
3334 sizeof(image()->magick) - 1 );
3335 image()->magick[ magick_.length() ] = 0;
3337 options()->magick( magick_ );
3339 std::string Magick::Image::magick ( void ) const
3341 if ( *(constImage()->magick) != '\0' )
3342 return std::string(constImage()->magick);
3344 return constOptions()->magick( );
3347 void Magick::Image::matte ( const bool matteFlag_ )
3351 // If matte channel is requested, but image doesn't already have a
3352 // matte channel, then create an opaque matte channel. Likewise, if
3353 // the image already has a matte channel but a matte channel is not
3354 // desired, then set the matte channel to opaque.
3355 ExceptionInfo exceptionInfo;
3356 GetExceptionInfo( &exceptionInfo );
3357 if ((matteFlag_ && !constImage()->matte) ||
3358 (constImage()->matte && !matteFlag_))
3359 SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo);
3360 throwException( exceptionInfo );
3361 (void) DestroyExceptionInfo( &exceptionInfo );
3363 image()->matte = (MagickBooleanType) matteFlag_;
3365 bool Magick::Image::matte ( void ) const
3367 if ( constImage()->matte )
3373 void Magick::Image::matteColor ( const Color &matteColor_ )
3377 if ( matteColor_.isValid() )
3379 image()->matte_color = matteColor_;
3380 options()->matteColor( matteColor_ );
3384 // Set to default matte color
3385 Color tmpColor( "#BDBDBD" );
3386 image()->matte_color = tmpColor;
3387 options()->matteColor( tmpColor );
3390 Magick::Color Magick::Image::matteColor ( void ) const
3392 return Color( ClampToQuantum( constImage()->matte_color.red ),
3393 ClampToQuantum( constImage()->matte_color.green ),
3394 ClampToQuantum( constImage()->matte_color.blue ) );
3397 double Magick::Image::meanErrorPerPixel ( void ) const
3399 return(constImage()->error.mean_error_per_pixel);
3402 // Image modulus depth (minimum number of bits required to support
3403 // red/green/blue components without loss of accuracy)
3404 void Magick::Image::modulusDepth ( const size_t depth_ )
3407 ExceptionInfo exceptionInfo;
3408 GetExceptionInfo( &exceptionInfo );
3409 SetImageDepth( image(), depth_, &exceptionInfo );
3410 throwException( exceptionInfo );
3411 (void) DestroyExceptionInfo( &exceptionInfo );
3412 options()->depth( depth_ );
3414 size_t Magick::Image::modulusDepth ( void ) const
3416 ExceptionInfo exceptionInfo;
3417 GetExceptionInfo( &exceptionInfo );
3418 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3419 throwException( exceptionInfo );
3420 (void) DestroyExceptionInfo( &exceptionInfo );
3424 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3427 options()->monochrome( monochromeFlag_ );
3429 bool Magick::Image::monochrome ( void ) const
3431 return constOptions()->monochrome( );
3434 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3436 if ( constImage()->montage )
3437 return Magick::Geometry(constImage()->montage);
3439 throwExceptionExplicit( CorruptImageWarning,
3440 "Image does not contain a montage" );
3442 return Magick::Geometry();
3445 double Magick::Image::normalizedMaxError ( void ) const
3447 return(constImage()->error.normalized_maximum_error);
3450 double Magick::Image::normalizedMeanError ( void ) const
3452 return constImage()->error.normalized_mean_error;
3455 // Image orientation
3456 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3459 image()->orientation = orientation_;
3461 Magick::OrientationType Magick::Image::orientation ( void ) const
3463 return constImage()->orientation;
3466 void Magick::Image::penColor ( const Color &penColor_ )
3469 options()->fillColor(penColor_);
3470 options()->strokeColor(penColor_);
3472 Magick::Color Magick::Image::penColor ( void ) const
3474 return constOptions()->fillColor();
3477 void Magick::Image::penTexture ( const Image &penTexture_ )
3480 if(penTexture_.isValid())
3481 options()->fillPattern( penTexture_.constImage() );
3483 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3486 Magick::Image Magick::Image::penTexture ( void ) const
3488 // FIXME: This is inordinately innefficient
3491 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3495 ExceptionInfo exceptionInfo;
3496 GetExceptionInfo( &exceptionInfo );
3497 MagickCore::Image* image =
3498 CloneImage( tmpTexture,
3501 MagickTrue, // orphan
3503 texture.replaceImage( image );
3504 throwException( exceptionInfo );
3505 (void) DestroyExceptionInfo( &exceptionInfo );
3510 // Set the color of a pixel.
3511 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3512 const Color &color_ )
3514 // Test arguments to ensure they are within the image.
3515 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3516 throwExceptionExplicit( OptionError,
3517 "Access outside of image boundary" );
3521 // Set image to DirectClass
3522 classType( DirectClass );
3525 Pixels pixels(*this);
3527 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3528 PixelInfo packet = color_;
3529 MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel);
3530 // Tell ImageMagick that pixels have been updated
3536 // Get the color of a pixel
3537 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3538 const ssize_t y_ ) const
3540 ClassType storage_class;
3541 storage_class = classType();
3542 (void) storage_class;
3544 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3548 MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3549 return Color( packet );
3552 return Color(); // invalid
3555 // Preferred size and location of an image canvas.
3556 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3559 options()->page( pageSize_ );
3560 image()->page = pageSize_;
3562 Magick::Geometry Magick::Image::page ( void ) const
3564 return Geometry( constImage()->page.width,
3565 constImage()->page.height,
3566 AbsoluteValue(constImage()->page.x),
3567 AbsoluteValue(constImage()->page.y),
3568 constImage()->page.x < 0 ? true : false,
3569 constImage()->page.y < 0 ? true : false);
3572 // Add a named profile to an image or remove a named profile by
3573 // passing an empty Blob (use default Blob constructor).
3575 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3576 void Magick::Image::profile( const std::string name_,
3577 const Magick::Blob &profile_ )
3580 ExceptionInfo exceptionInfo;
3581 GetExceptionInfo( &exceptionInfo );
3582 ssize_t result = ProfileImage( image(), name_.c_str(),
3583 (unsigned char *)profile_.data(),
3584 profile_.length(), &exceptionInfo);
3586 throwException( exceptionInfo );
3587 (void) DestroyExceptionInfo( &exceptionInfo );
3591 // Retrieve a named profile from the image.
3593 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3594 // an existing generic profile name.
3595 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3597 const MagickCore::Image* image = constImage();
3599 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3601 if ( profile != (StringInfo *) NULL)
3602 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3605 Image temp_image = *this;
3606 temp_image.write( &blob, name_ );
3610 void Magick::Image::quality ( const size_t quality_ )
3613 image()->quality = quality_;
3614 options()->quality( quality_ );
3616 size_t Magick::Image::quality ( void ) const
3618 return constImage()->quality;
3621 void Magick::Image::quantizeColors ( const size_t colors_ )
3624 options()->quantizeColors( colors_ );
3626 size_t Magick::Image::quantizeColors ( void ) const
3628 return constOptions()->quantizeColors( );
3631 void Magick::Image::quantizeColorSpace
3632 ( const Magick::ColorspaceType colorSpace_ )
3635 options()->quantizeColorSpace( colorSpace_ );
3637 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3639 return constOptions()->quantizeColorSpace( );
3642 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3645 options()->quantizeDither( ditherFlag_ );
3647 bool Magick::Image::quantizeDither ( void ) const
3649 return constOptions()->quantizeDither( );
3652 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3655 options()->quantizeTreeDepth( treeDepth_ );
3657 size_t Magick::Image::quantizeTreeDepth ( void ) const
3659 return constOptions()->quantizeTreeDepth( );
3662 void Magick::Image::renderingIntent
3663 ( const Magick::RenderingIntent renderingIntent_ )
3666 image()->rendering_intent = renderingIntent_;
3668 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3670 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3673 void Magick::Image::resolutionUnits
3674 ( const Magick::ResolutionType resolutionUnits_ )
3677 image()->units = resolutionUnits_;
3678 options()->resolutionUnits( resolutionUnits_ );
3680 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3682 return constOptions()->resolutionUnits( );
3685 void Magick::Image::scene ( const size_t scene_ )
3688 image()->scene = scene_;
3690 size_t Magick::Image::scene ( void ) const
3692 return constImage()->scene;
3695 std::string Magick::Image::signature ( const bool force_ ) const
3697 Lock( &_imgRef->_mutexLock );
3699 // Re-calculate image signature if necessary
3700 ExceptionInfo exceptionInfo;
3701 GetExceptionInfo( &exceptionInfo );
3703 !GetImageProperty(constImage(), "Signature", &exceptionInfo) ||
3704 constImage()->taint )
3706 SignatureImage( const_cast<MagickCore::Image *>(constImage()), &exceptionInfo );
3709 const char *property = GetImageProperty(constImage(), "Signature",
3711 throwException( exceptionInfo );
3712 (void) DestroyExceptionInfo( &exceptionInfo );
3714 return std::string( property );
3717 void Magick::Image::size ( const Geometry &geometry_ )
3720 options()->size( geometry_ );
3721 image()->rows = geometry_.height();
3722 image()->columns = geometry_.width();
3724 Magick::Geometry Magick::Image::size ( void ) const
3726 return Magick::Geometry( constImage()->columns, constImage()->rows );
3730 void Magick::Image::splice( const Geometry &geometry_ )
3732 RectangleInfo spliceInfo = geometry_;
3733 ExceptionInfo exceptionInfo;
3734 GetExceptionInfo( &exceptionInfo );
3735 MagickCore::Image* newImage =
3736 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3737 replaceImage( newImage );
3738 throwException( exceptionInfo );
3739 (void) DestroyExceptionInfo( &exceptionInfo );
3742 // Obtain image statistics. Statistics are normalized to the range of
3743 // 0.0 to 1.0 and are output to the specified ImageStatistics
3745 void Magick::Image::statistics ( ImageStatistics *statistics )
3751 ExceptionInfo exceptionInfo;
3752 GetExceptionInfo( &exceptionInfo );
3754 ChannelType channel_mask = SetPixelChannelMask( image(), RedChannel);
3755 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3756 statistics->red.minimum=minimum;
3757 statistics->red.maximum=maximum;
3758 (void) GetImageMean( image(),&statistics->red.mean,
3759 &statistics->red.standard_deviation,&exceptionInfo);
3760 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3761 &statistics->red.skewness,&exceptionInfo);
3762 (void) SetPixelChannelMapMask( image(), channel_mask );
3764 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3765 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3766 statistics->green.minimum=minimum;
3767 statistics->green.maximum=maximum;
3768 (void) GetImageMean( image(),&statistics->green.mean,
3769 &statistics->green.standard_deviation,&exceptionInfo);
3770 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3771 &statistics->green.skewness,&exceptionInfo);
3772 (void) SetPixelChannelMapMask( image(), channel_mask );
3774 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3775 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3776 statistics->blue.minimum=minimum;
3777 statistics->blue.maximum=maximum;
3778 (void) GetImageMean( image(),&statistics->blue.mean,
3779 &statistics->blue.standard_deviation,&exceptionInfo);
3780 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3781 &statistics->blue.skewness,&exceptionInfo);
3782 (void) SetPixelChannelMapMask( image(), channel_mask );
3784 channel_mask = SetPixelChannelMask( image(), AlphaChannel);
3785 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3786 statistics->alpha.minimum=minimum;
3787 statistics->alpha.maximum=maximum;
3788 (void) GetImageMean( image(),&statistics->alpha.mean,
3789 &statistics->alpha.standard_deviation,&exceptionInfo);
3790 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3791 &statistics->alpha.skewness,&exceptionInfo);
3792 (void) SetPixelChannelMapMask( image(), channel_mask );
3794 throwException( exceptionInfo );
3795 (void) DestroyExceptionInfo( &exceptionInfo );
3798 // Strip strips an image of all profiles and comments.
3799 void Magick::Image::strip ( void )
3802 ExceptionInfo exceptionInfo;
3803 GetExceptionInfo( &exceptionInfo );
3804 StripImage( image(), &exceptionInfo );
3805 throwException( exceptionInfo );
3806 (void) DestroyExceptionInfo( &exceptionInfo );
3809 // enabled/disable stroke anti-aliasing
3810 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3813 options()->strokeAntiAlias(flag_);
3815 bool Magick::Image::strokeAntiAlias ( void ) const
3817 return constOptions()->strokeAntiAlias();
3820 // Color to use when drawing object outlines
3821 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3824 options()->strokeColor(strokeColor_);
3826 Magick::Color Magick::Image::strokeColor ( void ) const
3828 return constOptions()->strokeColor();
3831 // dash pattern for drawing vector objects (default one)
3832 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3835 options()->strokeDashArray( strokeDashArray_ );
3838 const double* Magick::Image::strokeDashArray ( void ) const
3840 return constOptions()->strokeDashArray( );
3843 // dash offset for drawing vector objects (default one)
3844 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3847 options()->strokeDashOffset( strokeDashOffset_ );
3850 double Magick::Image::strokeDashOffset ( void ) const
3852 return constOptions()->strokeDashOffset( );
3855 // Specify the shape to be used at the end of open subpaths when they
3856 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3858 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3861 options()->strokeLineCap( lineCap_ );
3863 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3865 return constOptions()->strokeLineCap( );
3868 // Specify the shape to be used at the corners of paths (or other
3869 // vector shapes) when they are stroked. Values of LineJoin are
3870 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3871 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3874 options()->strokeLineJoin( lineJoin_ );
3876 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3878 return constOptions()->strokeLineJoin( );
3881 // Specify miter limit. When two line segments meet at a sharp angle
3882 // and miter joins have been specified for 'lineJoin', it is possible
3883 // for the miter to extend far beyond the thickness of the line
3884 // stroking the path. The miterLimit' imposes a limit on the ratio of
3885 // the miter length to the 'lineWidth'. The default value of this
3887 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3890 options()->strokeMiterLimit( strokeMiterLimit_ );
3892 size_t Magick::Image::strokeMiterLimit ( void ) const
3894 return constOptions()->strokeMiterLimit( );
3897 // Pattern to use while stroking drawn objects.
3898 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3901 if(strokePattern_.isValid())
3902 options()->strokePattern( strokePattern_.constImage() );
3904 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3906 Magick::Image Magick::Image::strokePattern ( void ) const
3908 // FIXME: This is inordinately innefficient
3911 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3915 ExceptionInfo exceptionInfo;
3916 GetExceptionInfo( &exceptionInfo );
3917 MagickCore::Image* image =
3918 CloneImage( tmpTexture,
3921 MagickTrue, // orphan
3923 throwException( exceptionInfo );
3924 (void) DestroyExceptionInfo( &exceptionInfo );
3925 texture.replaceImage( image );
3930 // Stroke width for drawing lines, circles, ellipses, etc.
3931 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3934 options()->strokeWidth( strokeWidth_ );
3936 double Magick::Image::strokeWidth ( void ) const
3938 return constOptions()->strokeWidth( );
3941 void Magick::Image::subImage ( const size_t subImage_ )
3944 options()->subImage( subImage_ );
3946 size_t Magick::Image::subImage ( void ) const
3948 return constOptions()->subImage( );
3951 void Magick::Image::subRange ( const size_t subRange_ )
3954 options()->subRange( subRange_ );
3956 size_t Magick::Image::subRange ( void ) const
3958 return constOptions()->subRange( );
3961 // Annotation text encoding (e.g. "UTF-16")
3962 void Magick::Image::textEncoding ( const std::string &encoding_ )
3965 options()->textEncoding( encoding_ );
3967 std::string Magick::Image::textEncoding ( void ) const
3969 return constOptions()->textEncoding( );
3972 size_t Magick::Image::totalColors ( void )
3974 ExceptionInfo exceptionInfo;
3975 GetExceptionInfo( &exceptionInfo );
3976 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3977 throwException( exceptionInfo );
3978 (void) DestroyExceptionInfo( &exceptionInfo );
3982 // Origin of coordinate system to use when annotating with text or drawing
3983 void Magick::Image::transformOrigin ( const double x_, const double y_ )
3986 options()->transformOrigin( x_, y_ );
3989 // Rotation to use when annotating with text or drawing
3990 void Magick::Image::transformRotation ( const double angle_ )
3993 options()->transformRotation( angle_ );
3996 // Reset transformation parameters to default
3997 void Magick::Image::transformReset ( void )
4000 options()->transformReset();
4003 // Scale to use when annotating with text or drawing
4004 void Magick::Image::transformScale ( const double sx_, const double sy_ )
4007 options()->transformScale( sx_, sy_ );
4010 // Skew to use in X axis when annotating with text or drawing
4011 void Magick::Image::transformSkewX ( const double skewx_ )
4014 options()->transformSkewX( skewx_ );
4017 // Skew to use in Y axis when annotating with text or drawing
4018 void Magick::Image::transformSkewY ( const double skewy_ )
4021 options()->transformSkewY( skewy_ );
4024 // Image representation type
4025 Magick::ImageType Magick::Image::type ( void ) const
4028 ExceptionInfo exceptionInfo;
4029 GetExceptionInfo( &exceptionInfo );
4030 ImageType image_type = constOptions()->type();
4031 if ( image_type == UndefinedType )
4032 image_type= GetImageType( constImage(), &exceptionInfo);
4033 throwException( exceptionInfo );
4034 (void) DestroyExceptionInfo( &exceptionInfo );
4037 void Magick::Image::type ( const Magick::ImageType type_)
4039 ExceptionInfo exceptionInfo;
4040 GetExceptionInfo( &exceptionInfo );
4042 options()->type( type_ );
4043 SetImageType( image(), type_, &exceptionInfo );
4044 throwException( exceptionInfo );
4045 (void) DestroyExceptionInfo( &exceptionInfo );
4048 void Magick::Image::verbose ( const bool verboseFlag_ )
4051 options()->verbose( verboseFlag_ );
4053 bool Magick::Image::verbose ( void ) const
4055 return constOptions()->verbose( );
4058 void Magick::Image::view ( const std::string &view_ )
4061 options()->view( view_ );
4063 std::string Magick::Image::view ( void ) const
4065 return constOptions()->view( );
4068 // Virtual pixel method
4069 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
4072 ExceptionInfo exceptionInfo;
4073 GetExceptionInfo( &exceptionInfo );
4074 SetImageVirtualPixelMethod( image(), virtual_pixel_method_, &exceptionInfo );
4075 throwException( exceptionInfo );
4076 (void) DestroyExceptionInfo( &exceptionInfo );
4078 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
4080 return GetImageVirtualPixelMethod( constImage() );
4083 void Magick::Image::x11Display ( const std::string &display_ )
4086 options()->x11Display( display_ );
4088 std::string Magick::Image::x11Display ( void ) const
4090 return constOptions()->x11Display( );
4093 double Magick::Image::xResolution ( void ) const
4095 return constImage()->resolution.x;
4097 double Magick::Image::yResolution ( void ) const
4099 return constImage()->resolution.y;
4103 Magick::Image::Image( const Image & image_ )
4104 : _imgRef(image_._imgRef)
4106 Lock( &_imgRef->_mutexLock );
4108 // Increase reference count
4109 ++_imgRef->_refCount;
4112 // Assignment operator
4113 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
4115 if( this != &image_ )
4118 Lock( &image_._imgRef->_mutexLock );
4119 ++image_._imgRef->_refCount;
4122 bool doDelete = false;
4124 Lock( &_imgRef->_mutexLock );
4125 if ( --_imgRef->_refCount == 0 )
4131 // Delete old image reference with associated image and options.
4135 // Use new image reference
4136 _imgRef = image_._imgRef;
4142 //////////////////////////////////////////////////////////////////////
4144 // Low-level Pixel Access Routines
4146 // Also see the Pixels class, which provides support for multiple
4147 // cache views. The low-level pixel access routines in the Image
4148 // class are provided in order to support backward compatability.
4150 //////////////////////////////////////////////////////////////////////
4152 // Transfers read-only pixels from the image to the pixel cache as
4153 // defined by the specified region
4154 const Magick::Quantum* Magick::Image::getConstPixels
4155 ( const ssize_t x_, const ssize_t y_,
4156 const size_t columns_,
4157 const size_t rows_ ) const
4159 ExceptionInfo exceptionInfo;
4160 GetExceptionInfo( &exceptionInfo );
4161 const Quantum* p = (*GetVirtualPixels)( constImage(),
4165 throwException( exceptionInfo );
4166 (void) DestroyExceptionInfo( &exceptionInfo );
4170 // Obtain read-only pixel associated pixels channels
4171 const void* Magick::Image::getConstMetacontent ( void ) const
4173 const void* result = GetVirtualMetacontent( constImage() );
4176 throwImageException();
4181 // Obtain image pixel associated pixels channels
4182 void* Magick::Image::getMetacontent ( void )
4184 void* result = GetAuthenticMetacontent( image() );
4187 throwImageException();
4192 // Transfers pixels from the image to the pixel cache as defined
4193 // by the specified region. Modified pixels may be subsequently
4194 // transferred back to the image via syncPixels.
4195 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4196 const size_t columns_,
4197 const size_t rows_ )
4200 ExceptionInfo exceptionInfo;
4201 GetExceptionInfo( &exceptionInfo );
4202 Quantum* result = (*GetAuthenticPixels)( image(),
4204 columns_, rows_, &exceptionInfo );
4205 throwException( exceptionInfo );
4206 (void) DestroyExceptionInfo( &exceptionInfo );
4211 // Allocates a pixel cache region to store image pixels as defined
4212 // by the region rectangle. This area is subsequently transferred
4213 // from the pixel cache to the image via syncPixels.
4214 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4215 const size_t columns_,
4216 const size_t rows_ )
4219 ExceptionInfo exceptionInfo;
4220 GetExceptionInfo( &exceptionInfo );
4221 Quantum* result = (*QueueAuthenticPixels)( image(),
4223 columns_, rows_, &exceptionInfo );
4224 throwException( exceptionInfo );
4225 (void) DestroyExceptionInfo( &exceptionInfo );
4230 // Transfers the image cache pixels to the image.
4231 void Magick::Image::syncPixels ( void )
4233 ExceptionInfo exceptionInfo;
4234 GetExceptionInfo( &exceptionInfo );
4235 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4236 throwException( exceptionInfo );
4237 (void) DestroyExceptionInfo( &exceptionInfo );
4240 // Transfers one or more pixel components from a buffer or file
4241 // into the image pixel cache of an image.
4242 // Used to support image decoders.
4243 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4244 const unsigned char *source_ )
4249 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4250 ExceptionInfo exceptionInfo;
4251 GetExceptionInfo( &exceptionInfo );
4252 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4253 quantum_,source_, &exceptionInfo);
4254 throwException( exceptionInfo );
4255 (void) DestroyExceptionInfo( &exceptionInfo );
4256 quantum_info=DestroyQuantumInfo(quantum_info);
4259 // Transfers one or more pixel components from the image pixel
4260 // cache to a buffer or file.
4261 // Used to support image encoders.
4262 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4263 unsigned char *destination_ )
4268 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4269 ExceptionInfo exceptionInfo;
4270 GetExceptionInfo( &exceptionInfo );
4271 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4272 quantum_,destination_, &exceptionInfo);
4273 quantum_info=DestroyQuantumInfo(quantum_info);
4274 throwException( exceptionInfo );
4275 (void) DestroyExceptionInfo( &exceptionInfo );
4278 /////////////////////////////////////////////////////////////////////
4280 // No end-user methods beyond this point
4282 /////////////////////////////////////////////////////////////////////
4286 // Construct using existing image and default options
4288 Magick::Image::Image ( MagickCore::Image* image_ )
4289 : _imgRef(new ImageRef( image_))
4293 // Get Magick::Options*
4294 Magick::Options* Magick::Image::options( void )
4296 return _imgRef->options();
4298 const Magick::Options* Magick::Image::constOptions( void ) const
4300 return _imgRef->options();
4303 // Get MagickCore::Image*
4304 MagickCore::Image*& Magick::Image::image( void )
4306 return _imgRef->image();
4308 const MagickCore::Image* Magick::Image::constImage( void ) const
4310 return _imgRef->image();
4314 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4316 return _imgRef->options()->imageInfo();
4318 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4320 return _imgRef->options()->imageInfo();
4323 // Get QuantizeInfo *
4324 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4326 return _imgRef->options()->quantizeInfo();
4328 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4330 return _imgRef->options()->quantizeInfo();
4334 // Replace current image
4336 MagickCore::Image * Magick::Image::replaceImage
4337 ( MagickCore::Image* replacement_ )
4339 MagickCore::Image* image;
4342 image = replacement_;
4345 ExceptionInfo exceptionInfo;
4346 GetExceptionInfo( &exceptionInfo );
4347 image = AcquireImage(constImageInfo(), &exceptionInfo);
4348 throwException( exceptionInfo );
4349 (void) DestroyExceptionInfo( &exceptionInfo );
4353 Lock( &_imgRef->_mutexLock );
4355 if ( _imgRef->_refCount == 1 )
4357 // We own the image, just replace it, and de-register
4359 _imgRef->image(image);
4363 // We don't own the image, dereference and replace with copy
4364 --_imgRef->_refCount;
4365 _imgRef = new ImageRef( image, constOptions() );
4369 return _imgRef->_image;
4373 // Prepare to modify image or image options
4374 // Replace current image and options with copy if reference count > 1
4376 void Magick::Image::modifyImage( void )
4379 Lock( &_imgRef->_mutexLock );
4380 if ( _imgRef->_refCount == 1 )
4382 // De-register image and return
4388 ExceptionInfo exceptionInfo;
4389 GetExceptionInfo( &exceptionInfo );
4390 replaceImage( CloneImage( image(),
4393 MagickTrue, // orphan
4395 throwException( exceptionInfo );
4396 (void) DestroyExceptionInfo( &exceptionInfo );
4401 // Test for an ImageMagick reported error and throw exception if one
4402 // has been reported. Secretly resets image->exception back to default
4403 // state even though this method is const.
4405 void Magick::Image::throwImageException( void ) const
4407 // Throw C++ exception while resetting Image exception to default state
4410 // Register image with image registry or obtain registration id
4411 ssize_t Magick::Image::registerId( void )
4413 Lock( &_imgRef->_mutexLock );
4414 if( _imgRef->id() < 0 )
4416 char id[MaxTextExtent];
4417 ExceptionInfo exceptionInfo;
4418 GetExceptionInfo( &exceptionInfo );
4419 _imgRef->id(_imgRef->id()+1);
4420 sprintf(id,"%.20g\n",(double) _imgRef->id());
4421 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4422 throwException( exceptionInfo );
4423 (void) DestroyExceptionInfo( &exceptionInfo );
4425 return _imgRef->id();
4428 // Unregister image from image registry
4429 void Magick::Image::unregisterId( void )
4436 // Create a local wrapper around MagickCoreTerminus
4441 void MagickPlusPlusDestroyMagick(void);
4445 void Magick::MagickPlusPlusDestroyMagick(void)
4447 if (magick_initialized)
4449 magick_initialized=false;
4450 MagickCore::MagickCoreTerminus();
4454 // C library initialization routine
4455 void MagickPPExport Magick::InitializeMagick(const char *path_)
4457 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4458 if (!magick_initialized)
4459 magick_initialized=true;
4463 // Cleanup class to ensure that ImageMagick singletons are destroyed
4464 // so as to avoid any resemblence to a memory leak (which seems to
4473 MagickCleanUp( void );
4474 ~MagickCleanUp( void );
4477 // The destructor for this object is invoked when the destructors for
4478 // static objects in this translation unit are invoked.
4479 static MagickCleanUp magickCleanUpGuard;
4482 Magick::MagickCleanUp::MagickCleanUp ( void )
4484 // Don't even think about invoking InitializeMagick here!
4487 Magick::MagickCleanUp::~MagickCleanUp ( void )
4489 MagickPlusPlusDestroyMagick();