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 MagickDLLDeclExtern const char *Magick::borderGeometryDefault = "6x6+0+0";
30 MagickDLLDeclExtern const char *Magick::frameGeometryDefault = "25x25+6+6";
31 MagickDLLDeclExtern 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 MagickDLLDecl 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 MagickDLLDecl int Magick::operator != ( const Magick::Image& left_,
53 const Magick::Image& right_ )
55 return ( ! (left_ == right_) );
57 MagickDLLDecl int Magick::operator > ( const Magick::Image& left_,
58 const Magick::Image& right_ )
60 return ( !( left_ < right_ ) && ( left_ != right_ ) );
62 MagickDLLDecl 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 MagickDLLDecl int Magick::operator >= ( const Magick::Image& left_,
71 const Magick::Image& right_ )
73 return ( ( left_ > right_ ) || ( left_ == right_ ) );
75 MagickDLLDecl 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) SetPixelChannelMap( 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 AnnotateImage( image(), drawInfo );
450 // Restore original values
451 drawInfo->affine = oaffine;
453 drawInfo->geometry = 0;
455 throwImageException();
457 // Annotate with text (bounding area is entire image) and placement gravity.
458 void Magick::Image::annotate ( const std::string &text_,
459 const GravityType gravity_ )
464 = options()->drawInfo();
466 drawInfo->text = const_cast<char *>(text_.c_str());
468 drawInfo->gravity = gravity_;
470 AnnotateImage( image(), drawInfo );
472 drawInfo->gravity = NorthWestGravity;
475 throwImageException();
479 void Magick::Image::blur( const double radius_, const double sigma_ )
481 ExceptionInfo exceptionInfo;
482 GetExceptionInfo( &exceptionInfo );
483 MagickCore::Image* newImage =
484 BlurImage( image(), radius_, sigma_, &exceptionInfo);
485 replaceImage( newImage );
486 throwException( exceptionInfo );
487 (void) DestroyExceptionInfo( &exceptionInfo );
490 void Magick::Image::blurChannel( const ChannelType channel_,
491 const double radius_, const double sigma_ )
493 ExceptionInfo exceptionInfo;
494 GetExceptionInfo( &exceptionInfo );
495 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
496 MagickCore::Image* newImage =
497 BlurImage( image(), radius_, sigma_, &exceptionInfo);
498 (void) SetPixelChannelMap( image(), channel_mask );
499 replaceImage( newImage );
500 throwException( exceptionInfo );
501 (void) DestroyExceptionInfo( &exceptionInfo );
504 // Add border to image
505 // Only uses width & height
506 void Magick::Image::border( const Geometry &geometry_ )
508 RectangleInfo borderInfo = geometry_;
509 ExceptionInfo exceptionInfo;
510 GetExceptionInfo( &exceptionInfo );
511 MagickCore::Image* newImage =
512 BorderImage( image(), &borderInfo, &exceptionInfo);
513 replaceImage( newImage );
514 throwException( exceptionInfo );
515 (void) DestroyExceptionInfo( &exceptionInfo );
518 // Extract channel from image
519 void Magick::Image::channel ( const ChannelType channel_ )
522 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
523 SeparateImage ( image() );
524 (void) SetPixelChannelMap( image(), channel_mask );
525 throwImageException();
528 // Set or obtain modulus channel depth
529 void Magick::Image::channelDepth ( const size_t depth_ )
532 SetImageDepth( image(), depth_);
533 throwImageException();
535 size_t Magick::Image::channelDepth ( )
537 size_t channel_depth;
539 ExceptionInfo exceptionInfo;
540 GetExceptionInfo( &exceptionInfo );
541 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
542 throwException( exceptionInfo );
543 (void) DestroyExceptionInfo( &exceptionInfo );
544 return channel_depth;
548 // Charcoal-effect image
549 void Magick::Image::charcoal( const double radius_, const double sigma_ )
551 ExceptionInfo exceptionInfo;
552 GetExceptionInfo( &exceptionInfo );
553 MagickCore::Image* newImage =
554 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
555 replaceImage( newImage );
556 throwException( exceptionInfo );
557 (void) DestroyExceptionInfo( &exceptionInfo );
561 void Magick::Image::chop( const Geometry &geometry_ )
563 RectangleInfo chopInfo = geometry_;
564 ExceptionInfo exceptionInfo;
565 GetExceptionInfo( &exceptionInfo );
566 MagickCore::Image* newImage =
567 ChopImage( image(), &chopInfo, &exceptionInfo);
568 replaceImage( newImage );
569 throwException( exceptionInfo );
570 (void) DestroyExceptionInfo( &exceptionInfo );
573 // contains one or more color corrections and applies the correction to the
575 void Magick::Image::cdl ( const std::string &cdl_ )
578 ExceptionInfo exceptionInfo;
579 GetExceptionInfo( &exceptionInfo );
580 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
581 throwException( exceptionInfo );
582 (void) DestroyExceptionInfo( &exceptionInfo );
586 void Magick::Image::colorize ( const unsigned int alphaRed_,
587 const unsigned int alphaGreen_,
588 const unsigned int alphaBlue_,
589 const Color &penColor_ )
591 if ( !penColor_.isValid() )
593 throwExceptionExplicit( OptionError,
594 "Pen color argument is invalid");
597 char alpha[MaxTextExtent];
598 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
600 ExceptionInfo exceptionInfo;
601 GetExceptionInfo( &exceptionInfo );
602 MagickCore::Image* newImage =
603 ColorizeImage ( image(), alpha,
604 penColor_, &exceptionInfo );
605 replaceImage( newImage );
606 throwException( exceptionInfo );
607 (void) DestroyExceptionInfo( &exceptionInfo );
609 void Magick::Image::colorize ( const unsigned int alpha_,
610 const Color &penColor_ )
612 colorize( alpha_, alpha_, alpha_, penColor_ );
615 // Apply a color matrix to the image channels. The user supplied
616 // matrix may be of order 1 to 6 (1x1 through 6x6).
617 void Magick::Image::colorMatrix (const size_t order_,
618 const double *color_matrix_)
623 ExceptionInfo exceptionInfo;
624 GetExceptionInfo( &exceptionInfo );
625 kernel_info=AcquireKernelInfo((const char *) NULL);
626 kernel_info->width=order_;
627 kernel_info->height=order_;
628 kernel_info->values=(double *) color_matrix_;
629 MagickCore::Image* newImage =
630 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
631 kernel_info->values=(double *) NULL;
632 kernel_info=DestroyKernelInfo(kernel_info);
633 replaceImage( newImage );
634 throwException( exceptionInfo );
635 (void) DestroyExceptionInfo( &exceptionInfo );
638 // Compare current image with another image
639 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
640 // in the current image. False is returned if the images are identical.
641 bool Magick::Image::compare ( const Image &reference_ )
644 Image ref = reference_;
646 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
649 // Composite two images
650 void Magick::Image::composite ( const Image &compositeImage_,
651 const ssize_t xOffset_,
652 const ssize_t yOffset_,
653 const CompositeOperator compose_ )
655 // Image supplied as compositeImage is composited with current image and
656 // results in updating current image.
659 CompositeImage( image(),
661 compositeImage_.constImage(),
664 throwImageException();
666 void Magick::Image::composite ( const Image &compositeImage_,
667 const Geometry &offset_,
668 const CompositeOperator compose_ )
672 ssize_t x = offset_.xOff();
673 ssize_t y = offset_.yOff();
674 size_t width = columns();
675 size_t height = rows();
677 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
681 CompositeImage( image(),
683 compositeImage_.constImage(),
685 throwImageException();
687 void Magick::Image::composite ( const Image &compositeImage_,
688 const GravityType gravity_,
689 const CompositeOperator compose_ )
693 RectangleInfo geometry;
695 SetGeometry(compositeImage_.constImage(), &geometry);
696 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
698 CompositeImage( image(),
700 compositeImage_.constImage(),
701 geometry.x, geometry.y );
702 throwImageException();
706 void Magick::Image::contrast ( const size_t sharpen_ )
709 ExceptionInfo exceptionInfo;
710 GetExceptionInfo( &exceptionInfo );
711 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
712 throwException( exceptionInfo );
713 (void) DestroyExceptionInfo( &exceptionInfo );
716 // Convolve image. Applies a general image convolution kernel to the image.
717 // order_ represents the number of columns and rows in the filter kernel.
718 // kernel_ is an array of doubles representing the convolution kernel.
719 void Magick::Image::convolve ( const size_t order_,
720 const double *kernel_ )
725 ExceptionInfo exceptionInfo;
726 GetExceptionInfo( &exceptionInfo );
727 kernel_info=AcquireKernelInfo((const char *) NULL);
728 kernel_info->width=order_;
729 kernel_info->height=order_;
730 kernel_info->values=(double *) kernel_;
731 kernel_info->bias=image()->bias;
732 MagickCore::Image* newImage =
733 ConvolveImage ( image(), kernel_info, &exceptionInfo );
734 kernel_info->values=(double *) NULL;
735 kernel_info=DestroyKernelInfo(kernel_info);
736 replaceImage( newImage );
737 throwException( exceptionInfo );
738 (void) DestroyExceptionInfo( &exceptionInfo );
742 void Magick::Image::crop ( const Geometry &geometry_ )
744 RectangleInfo cropInfo = geometry_;
745 ExceptionInfo exceptionInfo;
746 GetExceptionInfo( &exceptionInfo );
747 MagickCore::Image* newImage =
751 replaceImage( newImage );
752 throwException( exceptionInfo );
753 (void) DestroyExceptionInfo( &exceptionInfo );
757 void Magick::Image::cycleColormap ( const ssize_t amount_ )
760 CycleColormapImage( image(), amount_ );
761 throwImageException();
765 void Magick::Image::despeckle ( void )
767 ExceptionInfo exceptionInfo;
768 GetExceptionInfo( &exceptionInfo );
769 MagickCore::Image* newImage =
770 DespeckleImage( image(), &exceptionInfo );
771 replaceImage( newImage );
772 throwException( exceptionInfo );
773 (void) DestroyExceptionInfo( &exceptionInfo );
777 void Magick::Image::display( void )
779 DisplayImages( imageInfo(), image() );
782 // Distort image. distorts an image using various distortion methods, by
783 // mapping color lookups of the source image to a new destination image
784 // usally of the same size as the source image, unless 'bestfit' is set to
786 void Magick::Image::distort ( const DistortImageMethod method_,
787 const size_t number_arguments_,
788 const double *arguments_,
789 const bool bestfit_ )
791 ExceptionInfo exceptionInfo;
792 GetExceptionInfo( &exceptionInfo );
793 MagickCore::Image* newImage = DistortImage ( image(), method_,
794 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
796 replaceImage( newImage );
797 throwException( exceptionInfo );
798 (void) DestroyExceptionInfo( &exceptionInfo );
801 // Draw on image using single drawable
802 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
806 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
810 drawable_.operator()(wand);
812 if( constImage()->exception.severity == UndefinedException)
815 wand=DestroyDrawingWand(wand);
818 throwImageException();
821 // Draw on image using a drawable list
822 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
826 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
830 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
831 p != drawable_.end(); p++ )
834 if( constImage()->exception.severity != UndefinedException)
838 if( constImage()->exception.severity == UndefinedException)
841 wand=DestroyDrawingWand(wand);
844 throwImageException();
847 // Hilight edges in image
848 void Magick::Image::edge ( const double radius_ )
850 ExceptionInfo exceptionInfo;
851 GetExceptionInfo( &exceptionInfo );
852 MagickCore::Image* newImage =
853 EdgeImage( image(), radius_, &exceptionInfo );
854 replaceImage( newImage );
855 throwException( exceptionInfo );
856 (void) DestroyExceptionInfo( &exceptionInfo );
859 // Emboss image (hilight edges)
860 void Magick::Image::emboss ( const double radius_, const double sigma_ )
862 ExceptionInfo exceptionInfo;
863 GetExceptionInfo( &exceptionInfo );
864 MagickCore::Image* newImage =
865 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
866 replaceImage( newImage );
867 throwException( exceptionInfo );
868 (void) DestroyExceptionInfo( &exceptionInfo );
871 // Enhance image (minimize noise)
872 void Magick::Image::enhance ( void )
874 ExceptionInfo exceptionInfo;
875 GetExceptionInfo( &exceptionInfo );
876 MagickCore::Image* newImage =
877 EnhanceImage( image(), &exceptionInfo );
878 replaceImage( newImage );
879 throwException( exceptionInfo );
880 (void) DestroyExceptionInfo( &exceptionInfo );
883 // Equalize image (histogram equalization)
884 void Magick::Image::equalize ( void )
886 ExceptionInfo exceptionInfo;
887 GetExceptionInfo( &exceptionInfo );
889 EqualizeImage( image(), &exceptionInfo );
890 throwException( exceptionInfo );
893 // Erase image to current "background color"
894 void Magick::Image::erase ( void )
897 SetImageBackgroundColor( image() );
898 throwImageException();
901 // Extends image as defined by the geometry.
903 void Magick::Image::extent ( const Geometry &geometry_ )
905 RectangleInfo extentInfo = geometry_;
907 ExceptionInfo exceptionInfo;
908 GetExceptionInfo( &exceptionInfo );
909 MagickCore::Image* newImage =
910 ExtentImage ( image(), &extentInfo, &exceptionInfo );
911 replaceImage( newImage );
912 throwException( exceptionInfo );
913 (void) DestroyExceptionInfo( &exceptionInfo );
915 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
917 backgroundColor ( backgroundColor_ );
918 extent ( geometry_ );
920 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
922 image()->gravity = gravity_;
923 extent ( geometry_ );
925 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
927 image()->gravity = gravity_;
928 backgroundColor ( backgroundColor_ );
929 extent ( geometry_ );
932 // Flip image (reflect each scanline in the vertical direction)
933 void Magick::Image::flip ( void )
935 ExceptionInfo exceptionInfo;
936 GetExceptionInfo( &exceptionInfo );
937 MagickCore::Image* newImage =
938 FlipImage( image(), &exceptionInfo );
939 replaceImage( newImage );
940 throwException( exceptionInfo );
941 (void) DestroyExceptionInfo( &exceptionInfo );
944 // Flood-fill color across pixels that match the color of the
945 // target pixel and are neighbors of the target pixel.
946 // Uses current fuzz setting when determining color match.
947 void Magick::Image::floodFillColor( const ssize_t x_,
949 const Magick::Color &fillColor_ )
951 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
953 void Magick::Image::floodFillColor( const Geometry &point_,
954 const Magick::Color &fillColor_ )
956 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
959 // Flood-fill color across pixels starting at target-pixel and
960 // stopping at pixels matching specified border color.
961 // Uses current fuzz setting when determining color match.
962 void Magick::Image::floodFillColor( const ssize_t x_,
964 const Magick::Color &fillColor_,
965 const Magick::Color &borderColor_ )
967 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
970 void Magick::Image::floodFillColor( const Geometry &point_,
971 const Magick::Color &fillColor_,
972 const Magick::Color &borderColor_ )
974 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
978 // Floodfill pixels matching color (within fuzz factor) of target
979 // pixel(x,y) with replacement alpha value using method.
980 void Magick::Image::floodFillOpacity( const ssize_t x_,
982 const unsigned int alpha_,
983 const PaintMethod method_ )
987 GetPixelInfo(image(),&target);
988 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
989 target.red=pixel.red;
990 target.green=pixel.green;
991 target.blue=pixel.blue;
993 ExceptionInfo exceptionInfo;
994 GetExceptionInfo( &exceptionInfo );
995 FloodfillPaintImage ( image(),
996 options()->drawInfo(), // const DrawInfo *draw_info
998 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
999 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1001 throwException( exceptionInfo );
1002 (void) DestroyExceptionInfo( &exceptionInfo );
1005 // Flood-fill texture across pixels that match the color of the
1006 // target pixel and are neighbors of the target pixel.
1007 // Uses current fuzz setting when determining color match.
1008 void Magick::Image::floodFillTexture( const ssize_t x_,
1010 const Magick::Image &texture_ )
1014 // Set drawing pattern
1015 options()->fillPattern(texture_.constImage());
1018 Pixels pixels(*this);
1020 Quantum *p = pixels.get(x_, y_, 1, 1 );
1022 GetPixelInfo(constImage(),&target);
1023 target.red=GetPixelRed(constImage(),p);
1024 target.green=GetPixelGreen(constImage(),p);
1025 target.blue=GetPixelBlue(constImage(),p);
1026 ExceptionInfo exceptionInfo;
1027 GetExceptionInfo( &exceptionInfo );
1029 FloodfillPaintImage ( image(), // Image *image
1030 options()->drawInfo(), // const DrawInfo *draw_info
1031 &target, // const MagickPacket target
1032 static_cast<ssize_t>(x_), // const ssize_t x_offset
1033 static_cast<ssize_t>(y_), // const ssize_t y_offset
1034 MagickFalse, // const PaintMethod method
1036 throwException( exceptionInfo );
1037 (void) DestroyExceptionInfo( &exceptionInfo );
1040 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1041 const Magick::Image &texture_ )
1043 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1046 // Flood-fill texture across pixels starting at target-pixel and
1047 // stopping at pixels matching specified border color.
1048 // Uses current fuzz setting when determining color match.
1049 void Magick::Image::floodFillTexture( const ssize_t x_,
1051 const Magick::Image &texture_,
1052 const Magick::Color &borderColor_ )
1056 // Set drawing fill pattern
1057 options()->fillPattern(texture_.constImage());
1060 GetPixelInfo(constImage(),&target);
1061 target.red=static_cast<PixelPacket>(borderColor_).red;
1062 target.green=static_cast<PixelPacket>(borderColor_).green;
1063 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1064 ExceptionInfo exceptionInfo;
1065 GetExceptionInfo( &exceptionInfo );
1066 FloodfillPaintImage ( image(),
1067 options()->drawInfo(),
1069 static_cast<ssize_t>(x_),
1070 static_cast<ssize_t>(y_),
1071 MagickTrue, &exceptionInfo);
1073 throwException( exceptionInfo );
1074 (void) DestroyExceptionInfo( &exceptionInfo );
1076 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1077 const Magick::Image &texture_,
1078 const Magick::Color &borderColor_ )
1080 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1083 // Flop image (reflect each scanline in the horizontal direction)
1084 void Magick::Image::flop ( void )
1086 ExceptionInfo exceptionInfo;
1087 GetExceptionInfo( &exceptionInfo );
1088 MagickCore::Image* newImage =
1089 FlopImage( image(), &exceptionInfo );
1090 replaceImage( newImage );
1091 throwException( exceptionInfo );
1092 (void) DestroyExceptionInfo( &exceptionInfo );
1096 void Magick::Image::frame ( const Geometry &geometry_ )
1100 info.x = static_cast<ssize_t>(geometry_.width());
1101 info.y = static_cast<ssize_t>(geometry_.height());
1102 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1103 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1104 info.outer_bevel = geometry_.xOff();
1105 info.inner_bevel = geometry_.yOff();
1107 ExceptionInfo exceptionInfo;
1108 GetExceptionInfo( &exceptionInfo );
1109 MagickCore::Image* newImage =
1110 FrameImage( image(), &info, &exceptionInfo );
1111 replaceImage( newImage );
1112 throwException( exceptionInfo );
1113 (void) DestroyExceptionInfo( &exceptionInfo );
1115 void Magick::Image::frame ( const size_t width_,
1116 const size_t height_,
1117 const ssize_t outerBevel_, const ssize_t innerBevel_ )
1120 info.x = static_cast<ssize_t>(width_);
1121 info.y = static_cast<ssize_t>(height_);
1122 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1123 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1124 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1125 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1127 ExceptionInfo exceptionInfo;
1128 GetExceptionInfo( &exceptionInfo );
1129 MagickCore::Image* newImage =
1130 FrameImage( image(), &info, &exceptionInfo );
1131 replaceImage( newImage );
1132 throwException( exceptionInfo );
1133 (void) DestroyExceptionInfo( &exceptionInfo );
1136 // Fx image. Applies a mathematical expression to the image.
1137 void Magick::Image::fx ( const std::string expression )
1139 ExceptionInfo exceptionInfo;
1140 GetExceptionInfo( &exceptionInfo );
1141 MagickCore::Image* newImage =
1142 FxImage ( image(), expression.c_str(), &exceptionInfo );
1143 replaceImage( newImage );
1144 throwException( exceptionInfo );
1145 (void) DestroyExceptionInfo( &exceptionInfo );
1147 void Magick::Image::fx ( const std::string expression,
1148 const Magick::ChannelType channel )
1150 ExceptionInfo exceptionInfo;
1151 GetExceptionInfo( &exceptionInfo );
1152 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
1153 MagickCore::Image* newImage =
1154 FxImage ( image(), expression.c_str(), &exceptionInfo );
1155 (void) SetPixelChannelMap( image(), channel_mask );
1156 replaceImage( newImage );
1157 throwException( exceptionInfo );
1158 (void) DestroyExceptionInfo( &exceptionInfo );
1161 // Gamma correct image
1162 void Magick::Image::gamma ( const double gamma_ )
1164 ExceptionInfo exceptionInfo;
1165 GetExceptionInfo( &exceptionInfo );
1167 GammaImage ( image(), gamma_, &exceptionInfo );
1168 throwException( exceptionInfo );
1169 (void) DestroyExceptionInfo( &exceptionInfo );
1172 void Magick::Image::gamma ( const double gammaRed_,
1173 const double gammaGreen_,
1174 const double gammaBlue_ )
1176 char gamma[MaxTextExtent + 1];
1177 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1178 gammaRed_, gammaGreen_, gammaBlue_);
1180 ExceptionInfo exceptionInfo;
1181 GetExceptionInfo( &exceptionInfo );
1183 GammaImage ( image(), atof(gamma), &exceptionInfo );
1184 throwException( exceptionInfo );
1185 (void) DestroyExceptionInfo( &exceptionInfo );
1188 // Gaussian blur image
1189 // The number of neighbor pixels to be included in the convolution
1190 // mask is specified by 'width_'. The standard deviation of the
1191 // gaussian bell curve is specified by 'sigma_'.
1192 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1194 ExceptionInfo exceptionInfo;
1195 GetExceptionInfo( &exceptionInfo );
1196 MagickCore::Image* newImage =
1197 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1198 replaceImage( newImage );
1199 throwException( exceptionInfo );
1200 (void) DestroyExceptionInfo( &exceptionInfo );
1203 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1204 const double width_,
1205 const double sigma_ )
1207 ExceptionInfo exceptionInfo;
1208 GetExceptionInfo( &exceptionInfo );
1209 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1210 MagickCore::Image* newImage =
1211 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1212 (void) SetPixelChannelMap( image(), channel_mask );
1213 replaceImage( newImage );
1214 throwException( exceptionInfo );
1215 (void) DestroyExceptionInfo( &exceptionInfo );
1218 // Apply a color lookup table (Hald CLUT) to the image.
1219 void Magick::Image::haldClut ( const Image &clutImage_ )
1221 ExceptionInfo exceptionInfo;
1222 GetExceptionInfo( &exceptionInfo );
1224 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1225 throwException( exceptionInfo );
1226 (void) DestroyExceptionInfo( &exceptionInfo );
1230 void Magick::Image::implode ( const double factor_ )
1232 ExceptionInfo exceptionInfo;
1233 GetExceptionInfo( &exceptionInfo );
1234 MagickCore::Image* newImage =
1235 ImplodeImage( image(), factor_, &exceptionInfo );
1236 replaceImage( newImage );
1237 throwException( exceptionInfo );
1238 (void) DestroyExceptionInfo( &exceptionInfo );
1241 // implements the inverse discrete Fourier transform (IFT) of the image either
1242 // as a magnitude / phase or real / imaginary image pair.
1243 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1245 ExceptionInfo exceptionInfo;
1246 GetExceptionInfo( &exceptionInfo );
1247 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1248 phase_.constImage(), MagickTrue, &exceptionInfo);
1249 replaceImage( newImage );
1250 throwException( exceptionInfo );
1251 (void) DestroyExceptionInfo( &exceptionInfo );
1253 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1254 const bool magnitude_ )
1256 ExceptionInfo exceptionInfo;
1257 GetExceptionInfo( &exceptionInfo );
1258 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1259 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1261 replaceImage( newImage );
1262 throwException( exceptionInfo );
1263 (void) DestroyExceptionInfo( &exceptionInfo );
1266 // Level image. Adjust the levels of the image by scaling the colors
1267 // falling between specified white and black points to the full
1268 // available quantum range. The parameters provided represent the
1269 // black, mid (gamma), and white points. The black point specifies
1270 // the darkest color in the image. Colors darker than the black point
1271 // are set to zero. Mid point (gamma) specifies a gamma correction to
1272 // apply to the image. White point specifies the lightest color in the
1273 // image. Colors brighter than the white point are set to the maximum
1274 // quantum value. The black and white point have the valid range 0 to
1275 // QuantumRange while gamma has a useful range of 0 to ten.
1276 void Magick::Image::level ( const double black_point,
1277 const double white_point,
1278 const double gamma )
1280 ExceptionInfo exceptionInfo;
1281 GetExceptionInfo( &exceptionInfo );
1283 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1284 throwException( exceptionInfo );
1285 (void) DestroyExceptionInfo( &exceptionInfo );
1288 // Magnify image by integral size
1289 void Magick::Image::magnify ( void )
1291 ExceptionInfo exceptionInfo;
1292 GetExceptionInfo( &exceptionInfo );
1293 MagickCore::Image* newImage =
1294 MagnifyImage( image(), &exceptionInfo );
1295 replaceImage( newImage );
1296 throwException( exceptionInfo );
1297 (void) DestroyExceptionInfo( &exceptionInfo );
1300 // Remap image colors with closest color from reference image
1301 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1304 options()->quantizeDither( dither_ );
1305 RemapImage ( options()->quantizeInfo(), image(),
1306 mapImage_.constImage());
1307 throwImageException();
1309 // Floodfill designated area with replacement alpha value
1310 void Magick::Image::matteFloodfill ( const Color &target_ ,
1311 const unsigned int alpha_,
1312 const ssize_t x_, const ssize_t y_,
1313 const Magick::PaintMethod method_ )
1317 GetPixelInfo(constImage(),&target);
1318 target.red=static_cast<PixelPacket>(target_).red;
1319 target.green=static_cast<PixelPacket>(target_).green;
1320 target.blue=static_cast<PixelPacket>(target_).blue;
1321 target.alpha=alpha_;
1322 ChannelType channel_mask = SetPixelChannelMask( image(), AlphaChannel );
1323 ExceptionInfo exceptionInfo;
1324 GetExceptionInfo( &exceptionInfo );
1325 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1326 method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
1327 (void) SetPixelChannelMap( image(), channel_mask );
1328 throwException( exceptionInfo );
1329 (void) DestroyExceptionInfo( &exceptionInfo );
1332 // Filter image by replacing each pixel component with the median
1333 // color in a circular neighborhood
1334 void Magick::Image::medianFilter ( const double radius_ )
1336 ExceptionInfo exceptionInfo;
1337 GetExceptionInfo( &exceptionInfo );
1338 MagickCore::Image* newImage =
1339 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1340 radius_,&exceptionInfo );
1341 replaceImage( newImage );
1342 throwException( exceptionInfo );
1343 (void) DestroyExceptionInfo( &exceptionInfo );
1346 // Reduce image by integral size
1347 void Magick::Image::minify ( void )
1349 ExceptionInfo exceptionInfo;
1350 GetExceptionInfo( &exceptionInfo );
1351 MagickCore::Image* newImage =
1352 MinifyImage( image(), &exceptionInfo );
1353 replaceImage( newImage );
1354 throwException( exceptionInfo );
1355 (void) DestroyExceptionInfo( &exceptionInfo );
1358 // Modulate percent hue, saturation, and brightness of an image
1359 void Magick::Image::modulate ( const double brightness_,
1360 const double saturation_,
1363 char modulate[MaxTextExtent + 1];
1364 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1365 brightness_, saturation_, hue_);
1367 ExceptionInfo exceptionInfo;
1368 GetExceptionInfo( &exceptionInfo );
1370 ModulateImage( image(), modulate, &exceptionInfo );
1371 throwException( exceptionInfo );
1372 (void) DestroyExceptionInfo( &exceptionInfo );
1375 // Motion blur image with specified blur factor
1376 // The radius_ parameter specifies the radius of the Gaussian, in
1377 // pixels, not counting the center pixel. The sigma_ parameter
1378 // specifies the standard deviation of the Laplacian, in pixels.
1379 // The angle_ parameter specifies the angle the object appears
1380 // to be comming from (zero degrees is from the right).
1381 void Magick::Image::motionBlur ( const double radius_,
1382 const double sigma_,
1383 const double angle_ )
1385 ExceptionInfo exceptionInfo;
1386 GetExceptionInfo( &exceptionInfo );
1387 MagickCore::Image* newImage =
1388 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1389 replaceImage( newImage );
1390 throwException( exceptionInfo );
1391 (void) DestroyExceptionInfo( &exceptionInfo );
1394 // Negate image. Set grayscale_ to true to effect grayscale values
1396 void Magick::Image::negate ( const bool grayscale_ )
1398 ExceptionInfo exceptionInfo;
1399 GetExceptionInfo( &exceptionInfo );
1401 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1403 throwException( exceptionInfo );
1404 (void) DestroyExceptionInfo( &exceptionInfo );
1408 void Magick::Image::normalize ( void )
1411 ExceptionInfo exceptionInfo;
1412 GetExceptionInfo( &exceptionInfo );
1413 NormalizeImage ( image(), &exceptionInfo );
1414 throwException( exceptionInfo );
1415 (void) DestroyExceptionInfo( &exceptionInfo );
1419 void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
1421 ExceptionInfo exceptionInfo;
1422 GetExceptionInfo( &exceptionInfo );
1423 MagickCore::Image* newImage =
1424 OilPaintImage( image(), radius_, sigma_, &exceptionInfo );
1425 replaceImage( newImage );
1426 throwException( exceptionInfo );
1427 (void) DestroyExceptionInfo( &exceptionInfo );
1430 // Set or attenuate the alpha channel. If the image pixels are
1431 // opaque then they are set to the specified alpha value, otherwise
1432 // they are blended with the supplied alpha value. The value of
1433 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1434 // OpaqueAlpha and TransparentAlpha are available to specify
1435 // completely opaque or completely transparent, respectively.
1436 void Magick::Image::alpha ( const unsigned int alpha_ )
1439 SetImageOpacity( image(), alpha_ );
1442 // Change the color of an opaque pixel to the pen color.
1443 void Magick::Image::opaque ( const Color &opaqueColor_,
1444 const Color &penColor_ )
1446 if ( !opaqueColor_.isValid() )
1448 throwExceptionExplicit( OptionError,
1449 "Opaque color argument is invalid" );
1451 if ( !penColor_.isValid() )
1453 throwExceptionExplicit( OptionError,
1454 "Pen color argument is invalid" );
1458 std::string opaqueColor = opaqueColor_;
1459 std::string penColor = penColor_;
1463 ExceptionInfo exceptionInfo;
1464 GetExceptionInfo( &exceptionInfo );
1465 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque, &exceptionInfo);
1466 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen, &exceptionInfo);
1467 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo );
1468 throwException( exceptionInfo );
1469 (void) DestroyExceptionInfo( &exceptionInfo );
1472 // Ping is similar to read except only enough of the image is read to
1473 // determine the image columns, rows, and filesize. Access the
1474 // columns(), rows(), and fileSize() attributes after invoking ping.
1475 // The image data is not valid after calling ping.
1476 void Magick::Image::ping ( const std::string &imageSpec_ )
1478 options()->fileName( imageSpec_ );
1479 ExceptionInfo exceptionInfo;
1480 GetExceptionInfo( &exceptionInfo );
1481 MagickCore::Image* image =
1482 PingImage( imageInfo(), &exceptionInfo );
1483 replaceImage( image );
1484 throwException( exceptionInfo );
1485 (void) DestroyExceptionInfo( &exceptionInfo );
1488 // Ping is similar to read except only enough of the image is read
1489 // to determine the image columns, rows, and filesize. Access the
1490 // columns(), rows(), and fileSize() attributes after invoking
1491 // ping. The image data is not valid after calling ping.
1492 void Magick::Image::ping ( const Blob& blob_ )
1494 ExceptionInfo exceptionInfo;
1495 GetExceptionInfo( &exceptionInfo );
1496 MagickCore::Image* image =
1497 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1498 replaceImage( image );
1499 throwException( exceptionInfo );
1500 (void) DestroyExceptionInfo( &exceptionInfo );
1503 // Execute a named process module using an argc/argv syntax similar to
1504 // that accepted by a C 'main' routine. An exception is thrown if the
1505 // requested process module doesn't exist, fails to load, or fails during
1507 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1512 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1513 &image()->exception );
1515 if (status == false)
1516 throwException( image()->exception );
1519 // Quantize colors in image using current quantization settings
1520 // Set measureError_ to true in order to measure quantization error
1521 void Magick::Image::quantize ( const bool measureError_ )
1526 options()->quantizeInfo()->measure_error=MagickTrue;
1528 options()->quantizeInfo()->measure_error=MagickFalse;
1530 QuantizeImage( options()->quantizeInfo(), image() );
1532 throwImageException();
1535 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1536 void Magick::Image::quantumOperator ( const ChannelType channel_,
1537 const MagickEvaluateOperator operator_,
1540 ExceptionInfo exceptionInfo;
1541 GetExceptionInfo( &exceptionInfo );
1542 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1543 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
1544 (void) SetPixelChannelMap( image(), channel_mask );
1545 throwException( exceptionInfo );
1546 (void) DestroyExceptionInfo( &exceptionInfo );
1549 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1550 const size_t columns_,
1552 const ChannelType channel_,
1553 const MagickEvaluateOperator operator_,
1554 const double rvalue_)
1556 ExceptionInfo exceptionInfo;
1557 GetExceptionInfo( &exceptionInfo );
1558 RectangleInfo geometry;
1559 geometry.width = columns_;
1560 geometry.height = rows_;
1563 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1565 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1566 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
1567 (void) SetPixelChannelMap( image(), channel_mask );
1568 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1569 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1570 crop_image = DestroyImageList(crop_image);
1571 throwException( exceptionInfo );
1572 (void) DestroyExceptionInfo( &exceptionInfo );
1575 // Raise image (lighten or darken the edges of an image to give a 3-D
1576 // raised or lowered effect)
1577 void Magick::Image::raise ( const Geometry &geometry_ ,
1578 const bool raisedFlag_ )
1580 ExceptionInfo exceptionInfo;
1581 GetExceptionInfo( &exceptionInfo );
1582 RectangleInfo raiseInfo = geometry_;
1584 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
1585 throwException( exceptionInfo );
1586 (void) DestroyExceptionInfo( &exceptionInfo );
1590 // Random threshold image.
1592 // Changes the value of individual pixels based on the intensity
1593 // of each pixel compared to a random threshold. The result is a
1594 // low-contrast, two color image. The thresholds_ argument is a
1595 // geometry containing LOWxHIGH thresholds. If the string
1596 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1597 // 3, or 4 will be performed instead. If a channel_ argument is
1598 // specified then only the specified channel is altered. This is
1599 // a very fast alternative to 'quantize' based dithering.
1600 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1602 randomThresholdChannel(thresholds_,DefaultChannels);
1604 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1605 const ChannelType channel_ )
1607 ExceptionInfo exceptionInfo;
1608 GetExceptionInfo( &exceptionInfo );
1610 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1611 (void) RandomThresholdImage( image(),
1612 static_cast<std::string>(thresholds_).c_str(),
1614 (void) SetPixelChannelMap( image(), channel_mask );
1615 throwImageException();
1616 (void) DestroyExceptionInfo( &exceptionInfo );
1619 // Read image into current object
1620 void Magick::Image::read ( const std::string &imageSpec_ )
1622 options()->fileName( imageSpec_ );
1624 ExceptionInfo exceptionInfo;
1625 GetExceptionInfo( &exceptionInfo );
1626 MagickCore::Image* image =
1627 ReadImage( imageInfo(), &exceptionInfo );
1629 // Ensure that multiple image frames were not read.
1630 if ( image && image->next )
1632 // Destroy any extra image frames
1633 MagickCore::Image* next = image->next;
1636 DestroyImageList( next );
1639 replaceImage( image );
1640 throwException( exceptionInfo );
1642 throwException( image->exception );
1643 (void) DestroyExceptionInfo( &exceptionInfo );
1646 // Read image of specified size into current object
1647 void Magick::Image::read ( const Geometry &size_,
1648 const std::string &imageSpec_ )
1654 // Read image from in-memory BLOB
1655 void Magick::Image::read ( const Blob &blob_ )
1657 ExceptionInfo exceptionInfo;
1658 GetExceptionInfo( &exceptionInfo );
1659 MagickCore::Image* image =
1660 BlobToImage( imageInfo(),
1661 static_cast<const void *>(blob_.data()),
1662 blob_.length(), &exceptionInfo );
1663 replaceImage( image );
1664 throwException( exceptionInfo );
1666 throwException( image->exception );
1667 (void) DestroyExceptionInfo( &exceptionInfo );
1670 // Read image of specified size from in-memory BLOB
1671 void Magick::Image::read ( const Blob &blob_,
1672 const Geometry &size_ )
1680 // Read image of specified size and depth from in-memory BLOB
1681 void Magick::Image::read ( const Blob &blob_,
1682 const Geometry &size_,
1683 const size_t depth_ )
1693 // Read image of specified size, depth, and format from in-memory BLOB
1694 void Magick::Image::read ( const Blob &blob_,
1695 const Geometry &size_,
1696 const size_t depth_,
1697 const std::string &magick_ )
1705 // Set explicit image format
1706 fileName( magick_ + ':');
1711 // Read image of specified size, and format from in-memory BLOB
1712 void Magick::Image::read ( const Blob &blob_,
1713 const Geometry &size_,
1714 const std::string &magick_ )
1720 // Set explicit image format
1721 fileName( magick_ + ':');
1726 // Read image based on raw pixels in memory (ConstituteImage)
1727 void Magick::Image::read ( const size_t width_,
1728 const size_t height_,
1729 const std::string &map_,
1730 const StorageType type_,
1731 const void *pixels_ )
1733 ExceptionInfo exceptionInfo;
1734 GetExceptionInfo( &exceptionInfo );
1735 MagickCore::Image* image =
1736 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1738 replaceImage( image );
1739 throwException( exceptionInfo );
1741 throwException( image->exception );
1742 (void) DestroyExceptionInfo( &exceptionInfo );
1745 // Reduce noise in image
1746 void Magick::Image::reduceNoise ( const double order_ )
1748 ExceptionInfo exceptionInfo;
1749 GetExceptionInfo( &exceptionInfo );
1750 MagickCore::Image* newImage =
1751 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1753 replaceImage( newImage );
1754 throwException( exceptionInfo );
1755 (void) DestroyExceptionInfo( &exceptionInfo );
1759 void Magick::Image::resize( const Geometry &geometry_ )
1761 // Calculate new size. This code should be supported using binary arguments
1762 // in the ImageMagick library.
1765 size_t width = columns();
1766 size_t height = rows();
1768 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1772 ExceptionInfo exceptionInfo;
1773 GetExceptionInfo( &exceptionInfo );
1774 MagickCore::Image* newImage =
1775 ResizeImage( image(),
1781 replaceImage( newImage );
1782 throwException( exceptionInfo );
1783 (void) DestroyExceptionInfo( &exceptionInfo );
1787 void Magick::Image::roll ( const Geometry &roll_ )
1789 ssize_t xOff = roll_.xOff();
1790 if ( roll_.xNegative() )
1792 ssize_t yOff = roll_.yOff();
1793 if ( roll_.yNegative() )
1796 ExceptionInfo exceptionInfo;
1797 GetExceptionInfo( &exceptionInfo );
1798 MagickCore::Image* newImage =
1799 RollImage( image(), xOff, yOff, &exceptionInfo );
1800 replaceImage( newImage );
1801 throwException( exceptionInfo );
1802 (void) DestroyExceptionInfo( &exceptionInfo );
1804 void Magick::Image::roll ( const size_t columns_,
1805 const size_t rows_ )
1807 ExceptionInfo exceptionInfo;
1808 GetExceptionInfo( &exceptionInfo );
1809 MagickCore::Image* newImage =
1811 static_cast<ssize_t>(columns_),
1812 static_cast<ssize_t>(rows_), &exceptionInfo );
1813 replaceImage( newImage );
1814 throwException( exceptionInfo );
1815 (void) DestroyExceptionInfo( &exceptionInfo );
1819 void Magick::Image::rotate ( const double degrees_ )
1821 ExceptionInfo exceptionInfo;
1822 GetExceptionInfo( &exceptionInfo );
1823 MagickCore::Image* newImage =
1824 RotateImage( image(), degrees_, &exceptionInfo);
1825 replaceImage( newImage );
1826 throwException( exceptionInfo );
1827 (void) DestroyExceptionInfo( &exceptionInfo );
1831 void Magick::Image::sample ( const Geometry &geometry_ )
1835 size_t width = columns();
1836 size_t height = rows();
1838 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1842 ExceptionInfo exceptionInfo;
1843 GetExceptionInfo( &exceptionInfo );
1844 MagickCore::Image* newImage =
1845 SampleImage( image(), width, height, &exceptionInfo );
1846 replaceImage( newImage );
1847 throwException( exceptionInfo );
1848 (void) DestroyExceptionInfo( &exceptionInfo );
1852 void Magick::Image::scale ( const Geometry &geometry_ )
1856 size_t width = columns();
1857 size_t height = rows();
1859 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1863 ExceptionInfo exceptionInfo;
1864 GetExceptionInfo( &exceptionInfo );
1865 MagickCore::Image* newImage =
1866 ScaleImage( image(), width, height, &exceptionInfo );
1867 replaceImage( newImage );
1868 throwException( exceptionInfo );
1869 (void) DestroyExceptionInfo( &exceptionInfo );
1872 // Segment (coalesce similar image components) by analyzing the
1873 // histograms of the color components and identifying units that are
1874 // homogeneous with the fuzzy c-means technique.
1875 void Magick::Image::segment ( const double clusterThreshold_,
1876 const double smoothingThreshold_ )
1879 SegmentImage ( image(),
1880 options()->quantizeColorSpace(),
1881 (MagickBooleanType) options()->verbose(),
1883 smoothingThreshold_ );
1884 throwImageException();
1885 SyncImage( image() );
1886 throwImageException();
1889 // Shade image using distant light source
1890 void Magick::Image::shade ( const double azimuth_,
1891 const double elevation_,
1892 const bool colorShading_ )
1894 ExceptionInfo exceptionInfo;
1895 GetExceptionInfo( &exceptionInfo );
1896 MagickCore::Image* newImage =
1897 ShadeImage( image(),
1898 colorShading_ == true ? MagickTrue : MagickFalse,
1902 replaceImage( newImage );
1903 throwException( exceptionInfo );
1904 (void) DestroyExceptionInfo( &exceptionInfo );
1907 // Sharpen pixels in image
1908 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1910 ExceptionInfo exceptionInfo;
1911 GetExceptionInfo( &exceptionInfo );
1912 MagickCore::Image* newImage =
1913 SharpenImage( image(),
1917 replaceImage( newImage );
1918 throwException( exceptionInfo );
1919 (void) DestroyExceptionInfo( &exceptionInfo );
1922 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1923 const double radius_, const double sigma_ )
1925 ExceptionInfo exceptionInfo;
1926 GetExceptionInfo( &exceptionInfo );
1927 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1928 MagickCore::Image* newImage =
1929 SharpenImage( image(),
1933 (void) SetPixelChannelMap( image(), channel_mask );
1934 replaceImage( newImage );
1935 throwException( exceptionInfo );
1936 (void) DestroyExceptionInfo( &exceptionInfo );
1939 // Shave pixels from image edges.
1940 void Magick::Image::shave ( const Geometry &geometry_ )
1942 RectangleInfo shaveInfo = geometry_;
1943 ExceptionInfo exceptionInfo;
1944 GetExceptionInfo( &exceptionInfo );
1945 MagickCore::Image* newImage =
1946 ShaveImage( image(),
1949 replaceImage( newImage );
1950 throwException( exceptionInfo );
1951 (void) DestroyExceptionInfo( &exceptionInfo );
1955 void Magick::Image::shear ( const double xShearAngle_,
1956 const double yShearAngle_ )
1958 ExceptionInfo exceptionInfo;
1959 GetExceptionInfo( &exceptionInfo );
1960 MagickCore::Image* newImage =
1961 ShearImage( image(),
1965 replaceImage( newImage );
1966 throwException( exceptionInfo );
1967 (void) DestroyExceptionInfo( &exceptionInfo );
1971 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
1973 ExceptionInfo exceptionInfo;
1974 GetExceptionInfo( &exceptionInfo );
1976 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
1977 throwException( exceptionInfo );
1978 (void) DestroyExceptionInfo( &exceptionInfo );
1981 // Solarize image (similar to effect seen when exposing a photographic
1982 // film to light during the development process)
1983 void Magick::Image::solarize ( const double factor_ )
1986 SolarizeImage ( image(), factor_ );
1987 throwImageException();
1990 // Sparse color image, given a set of coordinates, interpolates the colors
1991 // found at those coordinates, across the whole image, using various methods.
1993 void Magick::Image::sparseColor ( const ChannelType channel,
1994 const SparseColorMethod method,
1995 const size_t number_arguments,
1996 const double *arguments )
1998 ExceptionInfo exceptionInfo;
1999 GetExceptionInfo( &exceptionInfo );
2001 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
2002 MagickCore::Image* newImage = SparseColorImage ( image(), method,
2003 number_arguments, arguments, &exceptionInfo );
2004 (void) SetPixelChannelMap( image(), channel_mask );
2005 replaceImage( newImage );
2006 throwException( exceptionInfo );
2007 (void) DestroyExceptionInfo( &exceptionInfo );
2010 // Spread pixels randomly within image by specified ammount
2011 void Magick::Image::spread ( const size_t amount_ )
2013 ExceptionInfo exceptionInfo;
2014 GetExceptionInfo( &exceptionInfo );
2015 MagickCore::Image* newImage =
2016 SpreadImage( image(),
2019 replaceImage( newImage );
2020 throwException( exceptionInfo );
2021 (void) DestroyExceptionInfo( &exceptionInfo );
2024 // Add a digital watermark to the image (based on second image)
2025 void Magick::Image::stegano ( const Image &watermark_ )
2027 ExceptionInfo exceptionInfo;
2028 GetExceptionInfo( &exceptionInfo );
2029 MagickCore::Image* newImage =
2030 SteganoImage( image(),
2031 watermark_.constImage(),
2033 replaceImage( newImage );
2034 throwException( exceptionInfo );
2035 (void) DestroyExceptionInfo( &exceptionInfo );
2038 // Stereo image (left image is current image)
2039 void Magick::Image::stereo ( const Image &rightImage_ )
2041 ExceptionInfo exceptionInfo;
2042 GetExceptionInfo( &exceptionInfo );
2043 MagickCore::Image* newImage =
2044 StereoImage( image(),
2045 rightImage_.constImage(),
2047 replaceImage( newImage );
2048 throwException( exceptionInfo );
2049 (void) DestroyExceptionInfo( &exceptionInfo );
2053 void Magick::Image::swirl ( const double degrees_ )
2055 ExceptionInfo exceptionInfo;
2056 GetExceptionInfo( &exceptionInfo );
2057 MagickCore::Image* newImage =
2058 SwirlImage( image(), degrees_,
2060 replaceImage( newImage );
2061 throwException( exceptionInfo );
2062 (void) DestroyExceptionInfo( &exceptionInfo );
2066 void Magick::Image::texture ( const Image &texture_ )
2069 TextureImage( image(), texture_.constImage() );
2070 throwImageException();
2074 void Magick::Image::threshold ( const double threshold_ )
2077 BilevelImage( image(), threshold_ );
2078 throwImageException();
2081 // Transform image based on image geometry only
2082 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2085 TransformImage ( &(image()), 0,
2086 std::string(imageGeometry_).c_str() );
2087 throwImageException();
2089 // Transform image based on image and crop geometries
2090 void Magick::Image::transform ( const Geometry &imageGeometry_,
2091 const Geometry &cropGeometry_ )
2094 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2095 std::string(imageGeometry_).c_str() );
2096 throwImageException();
2099 // Add matte image to image, setting pixels matching color to transparent
2100 void Magick::Image::transparent ( const Color &color_ )
2102 if ( !color_.isValid() )
2104 throwExceptionExplicit( OptionError,
2105 "Color argument is invalid" );
2108 std::string color = color_;
2111 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2112 ExceptionInfo exceptionInfo;
2113 GetExceptionInfo( &exceptionInfo );
2115 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2117 throwException( exceptionInfo );
2118 (void) DestroyExceptionInfo( &exceptionInfo );
2121 // Add matte image to image, setting pixels matching color to transparent
2122 void Magick::Image::transparentChroma(const Color &colorLow_,
2123 const Color &colorHigh_)
2125 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2127 throwExceptionExplicit( OptionError,
2128 "Color argument is invalid" );
2131 std::string colorLow = colorLow_;
2132 std::string colorHigh = colorHigh_;
2134 PixelInfo targetLow;
2135 PixelInfo targetHigh;
2136 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2137 &image()->exception);
2138 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2139 &image()->exception);
2140 ExceptionInfo exceptionInfo;
2141 GetExceptionInfo( &exceptionInfo );
2143 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2144 TransparentAlpha, MagickFalse, &exceptionInfo );
2145 throwException( exceptionInfo );
2146 (void) DestroyExceptionInfo( &exceptionInfo );
2150 // Trim edges that are the background color from the image
2151 void Magick::Image::trim ( void )
2153 ExceptionInfo exceptionInfo;
2154 GetExceptionInfo( &exceptionInfo );
2155 MagickCore::Image* newImage =
2156 TrimImage( image(), &exceptionInfo);
2157 replaceImage( newImage );
2158 throwException( exceptionInfo );
2159 (void) DestroyExceptionInfo( &exceptionInfo );
2162 // Replace image with a sharpened version of the original image
2163 // using the unsharp mask algorithm.
2165 // the radius of the Gaussian, in pixels, not counting the
2168 // the standard deviation of the Gaussian, in pixels.
2170 // the percentage of the difference between the original and
2171 // the blur image that is added back into the original.
2173 // the threshold in pixels needed to apply the diffence amount.
2174 void Magick::Image::unsharpmask ( const double radius_,
2175 const double sigma_,
2176 const double amount_,
2177 const double threshold_ )
2179 ExceptionInfo exceptionInfo;
2180 GetExceptionInfo( &exceptionInfo );
2181 MagickCore::Image* newImage =
2182 UnsharpMaskImage( image(),
2188 replaceImage( newImage );
2189 throwException( exceptionInfo );
2190 (void) DestroyExceptionInfo( &exceptionInfo );
2193 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2194 const double radius_,
2195 const double sigma_,
2196 const double amount_,
2197 const double threshold_ )
2199 ExceptionInfo exceptionInfo;
2200 GetExceptionInfo( &exceptionInfo );
2201 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
2202 MagickCore::Image* newImage =
2203 UnsharpMaskImage( image(),
2209 (void) SetPixelChannelMap( image(), channel_mask );
2210 replaceImage( newImage );
2211 throwException( exceptionInfo );
2212 (void) DestroyExceptionInfo( &exceptionInfo );
2215 // Map image pixels to a sine wave
2216 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2218 ExceptionInfo exceptionInfo;
2219 GetExceptionInfo( &exceptionInfo );
2220 MagickCore::Image* newImage =
2225 replaceImage( newImage );
2226 throwException( exceptionInfo );
2227 (void) DestroyExceptionInfo( &exceptionInfo );
2230 // Write image to file
2231 void Magick::Image::write( const std::string &imageSpec_ )
2233 ExceptionInfo exceptionInfo;
2234 GetExceptionInfo( &exceptionInfo );
2236 fileName( imageSpec_ );
2237 WriteImage( imageInfo(), image(), &exceptionInfo );
2238 throwException( exceptionInfo );
2239 (void) DestroyExceptionInfo( &exceptionInfo );
2242 // Write image to in-memory BLOB
2243 void Magick::Image::write ( Blob *blob_ )
2246 size_t length = 2048; // Efficient size for small images
2247 ExceptionInfo exceptionInfo;
2248 GetExceptionInfo( &exceptionInfo );
2249 void* data = ImageToBlob( imageInfo(),
2253 throwException( exceptionInfo );
2254 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2255 throwImageException();
2256 (void) DestroyExceptionInfo( &exceptionInfo );
2258 void Magick::Image::write ( Blob *blob_,
2259 const std::string &magick_ )
2263 size_t length = 2048; // Efficient size for small images
2264 ExceptionInfo exceptionInfo;
2265 GetExceptionInfo( &exceptionInfo );
2266 void* data = ImageToBlob( imageInfo(),
2270 throwException( exceptionInfo );
2271 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2272 throwImageException();
2273 (void) DestroyExceptionInfo( &exceptionInfo );
2275 void Magick::Image::write ( Blob *blob_,
2276 const std::string &magick_,
2277 const size_t depth_ )
2282 size_t length = 2048; // Efficient size for small images
2283 ExceptionInfo exceptionInfo;
2284 GetExceptionInfo( &exceptionInfo );
2285 void* data = ImageToBlob( imageInfo(),
2289 throwException( exceptionInfo );
2290 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2291 throwImageException();
2292 (void) DestroyExceptionInfo( &exceptionInfo );
2295 // Write image to an array of pixels with storage type specified
2296 // by user (ExportImagePixels), e.g.
2297 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2298 void Magick::Image::write ( const ssize_t x_,
2300 const size_t columns_,
2302 const std::string &map_,
2303 const StorageType type_,
2306 ExceptionInfo exceptionInfo;
2307 GetExceptionInfo( &exceptionInfo );
2308 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2311 throwException( exceptionInfo );
2312 (void) DestroyExceptionInfo( &exceptionInfo );
2316 void Magick::Image::zoom( const Geometry &geometry_ )
2318 // Calculate new size. This code should be supported using binary arguments
2319 // in the ImageMagick library.
2322 size_t width = columns();
2323 size_t height = rows();
2325 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2329 ExceptionInfo exceptionInfo;
2330 GetExceptionInfo( &exceptionInfo );
2331 MagickCore::Image* newImage =
2332 ResizeImage( image(),
2338 replaceImage( newImage );
2339 throwException( exceptionInfo );
2340 (void) DestroyExceptionInfo( &exceptionInfo );
2344 * Methods for setting image attributes
2348 // Join images into a single multi-image file
2349 void Magick::Image::adjoin ( const bool flag_ )
2352 options()->adjoin( flag_ );
2354 bool Magick::Image::adjoin ( void ) const
2356 return constOptions()->adjoin();
2359 // Remove pixel aliasing
2360 void Magick::Image::antiAlias( const bool flag_ )
2363 options()->antiAlias( static_cast<size_t>(flag_) );
2365 bool Magick::Image::antiAlias( void )
2367 return static_cast<bool>( options()->antiAlias( ) );
2370 // Animation inter-frame delay
2371 void Magick::Image::animationDelay ( const size_t delay_ )
2374 image()->delay = delay_;
2376 size_t Magick::Image::animationDelay ( void ) const
2378 return constImage()->delay;
2381 // Number of iterations to play animation
2382 void Magick::Image::animationIterations ( const size_t iterations_ )
2385 image()->iterations = iterations_;
2387 size_t Magick::Image::animationIterations ( void ) const
2389 return constImage()->iterations;
2392 // Access/Update a named image attribute
2393 void Magick::Image::attribute ( const std::string name_,
2394 const std::string value_ )
2397 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2399 std::string Magick::Image::attribute ( const std::string name_ )
2401 const char *value = GetImageProperty( constImage(), name_.c_str() );
2404 return std::string( value );
2406 return std::string(); // Intentionally no exception
2410 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2414 if ( backgroundColor_.isValid() )
2416 image()->background_color = backgroundColor_;
2420 image()->background_color = Color();
2423 options()->backgroundColor( backgroundColor_ );
2425 Magick::Color Magick::Image::backgroundColor ( void ) const
2427 return constOptions()->backgroundColor( );
2430 // Background fill texture
2431 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2434 options()->backgroundTexture( backgroundTexture_ );
2436 std::string Magick::Image::backgroundTexture ( void ) const
2438 return constOptions()->backgroundTexture( );
2441 // Original image columns
2442 size_t Magick::Image::baseColumns ( void ) const
2444 return constImage()->magick_columns;
2447 // Original image name
2448 std::string Magick::Image::baseFilename ( void ) const
2450 return std::string(constImage()->magick_filename);
2453 // Original image rows
2454 size_t Magick::Image::baseRows ( void ) const
2456 return constImage()->magick_rows;
2460 void Magick::Image::borderColor ( const Color &borderColor_ )
2464 if ( borderColor_.isValid() )
2466 image()->border_color = borderColor_;
2470 image()->border_color = Color();
2473 options()->borderColor( borderColor_ );
2475 Magick::Color Magick::Image::borderColor ( void ) const
2477 return constOptions()->borderColor( );
2480 // Return smallest bounding box enclosing non-border pixels. The
2481 // current fuzz value is used when discriminating between pixels.
2482 // This is the crop bounding box used by crop(Geometry(0,0));
2483 Magick::Geometry Magick::Image::boundingBox ( void ) const
2485 ExceptionInfo exceptionInfo;
2486 GetExceptionInfo( &exceptionInfo );
2487 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2488 throwException( exceptionInfo );
2489 (void) DestroyExceptionInfo( &exceptionInfo );
2490 return Geometry( bbox );
2493 // Text bounding-box base color
2494 void Magick::Image::boxColor ( const Color &boxColor_ )
2497 options()->boxColor( boxColor_ );
2499 Magick::Color Magick::Image::boxColor ( void ) const
2501 return constOptions()->boxColor( );
2504 // Pixel cache threshold. Once this threshold is exceeded, all
2505 // subsequent pixels cache operations are to/from disk.
2506 // This setting is shared by all Image objects.
2508 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2510 SetMagickResourceLimit( MemoryResource, threshold_ );
2513 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2516 image()->chromaticity.blue_primary.x = x_;
2517 image()->chromaticity.blue_primary.y = y_;
2519 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2521 *x_ = constImage()->chromaticity.blue_primary.x;
2522 *y_ = constImage()->chromaticity.blue_primary.y;
2525 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2528 image()->chromaticity.green_primary.x = x_;
2529 image()->chromaticity.green_primary.y = y_;
2531 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2533 *x_ = constImage()->chromaticity.green_primary.x;
2534 *y_ = constImage()->chromaticity.green_primary.y;
2537 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2540 image()->chromaticity.red_primary.x = x_;
2541 image()->chromaticity.red_primary.y = y_;
2543 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2545 *x_ = constImage()->chromaticity.red_primary.x;
2546 *y_ = constImage()->chromaticity.red_primary.y;
2549 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2552 image()->chromaticity.white_point.x = x_;
2553 image()->chromaticity.white_point.y = y_;
2555 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2557 *x_ = constImage()->chromaticity.white_point.x;
2558 *y_ = constImage()->chromaticity.white_point.y;
2561 // Set image storage class
2562 void Magick::Image::classType ( const ClassType class_ )
2564 if ( classType() == PseudoClass && class_ == DirectClass )
2566 // Use SyncImage to synchronize the DirectClass pixels with the
2567 // color map and then set to DirectClass type.
2569 SyncImage( image() );
2570 image()->colormap = (PixelPacket *)
2571 RelinquishMagickMemory( image()->colormap );
2572 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2576 if ( classType() == DirectClass && class_ == PseudoClass )
2578 // Quantize to create PseudoClass color map
2580 quantizeColors(MaxColormapSize);
2582 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2586 // Associate a clip mask with the image. The clip mask must be the
2587 // same dimensions as the image. Pass an invalid image to unset an
2588 // existing clip mask.
2589 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2593 if( clipMask_.isValid() )
2596 SetImageClipMask( image(), clipMask_.constImage() );
2600 // Unset existing clip mask
2601 SetImageClipMask( image(), 0 );
2604 Magick::Image Magick::Image::clipMask ( void ) const
2606 ExceptionInfo exceptionInfo;
2607 GetExceptionInfo( &exceptionInfo );
2608 MagickCore::Image* image =
2609 GetImageClipMask( constImage(), &exceptionInfo );
2610 throwException( exceptionInfo );
2611 (void) DestroyExceptionInfo( &exceptionInfo );
2612 return Magick::Image( image );
2615 void Magick::Image::colorFuzz ( const double fuzz_ )
2618 image()->fuzz = fuzz_;
2619 options()->colorFuzz( fuzz_ );
2621 double Magick::Image::colorFuzz ( void ) const
2623 return constOptions()->colorFuzz( );
2626 // Set color in colormap at index
2627 void Magick::Image::colorMap ( const size_t index_,
2628 const Color &color_ )
2630 MagickCore::Image* imageptr = image();
2632 if (index_ > (MaxColormapSize-1) )
2633 throwExceptionExplicit( OptionError,
2634 "Colormap index must be less than MaxColormapSize" );
2636 if ( !color_.isValid() )
2637 throwExceptionExplicit( OptionError,
2638 "Color argument is invalid");
2641 // Ensure that colormap size is large enough
2642 if ( colorMapSize() < (index_+1) )
2643 colorMapSize( index_ + 1 );
2645 // Set color at index in colormap
2646 (imageptr->colormap)[index_] = color_;
2648 // Return color in colormap at index
2649 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2651 const MagickCore::Image* imageptr = constImage();
2653 if ( !imageptr->colormap )
2654 throwExceptionExplicit( OptionError,
2655 "Image does not contain a colormap");
2657 if ( index_ > imageptr->colors-1 )
2658 throwExceptionExplicit( OptionError,
2659 "Index out of range");
2661 return Magick::Color( (imageptr->colormap)[index_] );
2664 // Colormap size (number of colormap entries)
2665 void Magick::Image::colorMapSize ( const size_t entries_ )
2667 if (entries_ >MaxColormapSize )
2668 throwExceptionExplicit( OptionError,
2669 "Colormap entries must not exceed MaxColormapSize" );
2673 MagickCore::Image* imageptr = image();
2675 if( !imageptr->colormap )
2677 // Allocate colormap
2678 imageptr->colormap =
2679 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2680 imageptr->colors = 0;
2682 else if ( entries_ > imageptr->colors )
2684 // Re-allocate colormap
2685 imageptr->colormap=(PixelPacket *)
2686 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2689 // Initialize any new colormap entries as all black
2691 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2692 (imageptr->colormap)[i] = black;
2694 imageptr->colors = entries_;
2696 size_t Magick::Image::colorMapSize ( void )
2698 const MagickCore::Image* imageptr = constImage();
2700 if ( !imageptr->colormap )
2701 throwExceptionExplicit( OptionError,
2702 "Image does not contain a colormap");
2704 return imageptr->colors;
2708 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2711 if ( image()->colorspace == colorSpace_ )
2716 if ( colorSpace_ != RGBColorspace &&
2717 colorSpace_ != sRGBColorspace &&
2718 colorSpace_ != TransparentColorspace &&
2719 colorSpace_ != GRAYColorspace )
2721 if (image()->colorspace != RGBColorspace &&
2722 image()->colorspace != sRGBColorspace &&
2723 image()->colorspace != TransparentColorspace &&
2724 image()->colorspace != GRAYColorspace)
2726 /* Transform to RGB colorspace as intermediate step */
2727 TransformRGBImage( image(), image()->colorspace );
2728 throwImageException();
2730 /* Transform to final non-RGB colorspace */
2731 RGBTransformImage( image(), colorSpace_ );
2732 throwImageException();
2736 if ( colorSpace_ == RGBColorspace ||
2737 colorSpace_ == sRGBColorspace ||
2738 colorSpace_ == TransparentColorspace ||
2739 colorSpace_ == GRAYColorspace )
2741 /* Transform to a RGB-type colorspace */
2742 TransformRGBImage( image(), image()->colorspace );
2743 throwImageException();
2747 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2749 return constImage()->colorspace;
2752 // Set image colorspace type.
2753 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2756 options()->colorspaceType( colorSpace_ );
2758 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2760 return constOptions()->colorspaceType();
2765 void Magick::Image::comment ( const std::string &comment_ )
2768 SetImageProperty( image(), "Comment", NULL );
2769 if ( comment_.length() > 0 )
2770 SetImageProperty( image(), "Comment", comment_.c_str() );
2771 throwImageException();
2773 std::string Magick::Image::comment ( void ) const
2775 const char *value = GetImageProperty( constImage(), "Comment" );
2778 return std::string( value );
2780 return std::string(); // Intentionally no exception
2783 // Composition operator to be used when composition is implicitly used
2784 // (such as for image flattening).
2785 void Magick::Image::compose (const CompositeOperator compose_)
2787 image()->compose=compose_;
2790 Magick::CompositeOperator Magick::Image::compose ( void ) const
2792 return constImage()->compose;
2795 // Compression algorithm
2796 void Magick::Image::compressType ( const CompressionType compressType_ )
2799 image()->compression = compressType_;
2800 options()->compressType( compressType_ );
2802 Magick::CompressionType Magick::Image::compressType ( void ) const
2804 return constImage()->compression;
2807 // Enable printing of debug messages from ImageMagick
2808 void Magick::Image::debug ( const bool flag_ )
2811 options()->debug( flag_ );
2813 bool Magick::Image::debug ( void ) const
2815 return constOptions()->debug();
2818 // Tagged image format define (set/access coder-specific option) The
2819 // magick_ option specifies the coder the define applies to. The key_
2820 // option provides the key specific to that coder. The value_ option
2821 // provides the value to set (if any). See the defineSet() method if the
2822 // key must be removed entirely.
2823 void Magick::Image::defineValue ( const std::string &magick_,
2824 const std::string &key_,
2825 const std::string &value_ )
2828 std::string format = magick_ + ":" + key_;
2829 std::string option = value_;
2830 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2832 std::string Magick::Image::defineValue ( const std::string &magick_,
2833 const std::string &key_ ) const
2835 std::string definition = magick_ + ":" + key_;
2836 const char *option =
2837 GetImageOption ( constImageInfo(), definition.c_str() );
2839 return std::string( option );
2840 return std::string( );
2843 // Tagged image format define. Similar to the defineValue() method
2844 // except that passing the flag_ value 'true' creates a value-less
2845 // define with that format and key. Passing the flag_ value 'false'
2846 // removes any existing matching definition. The method returns 'true'
2847 // if a matching key exists, and 'false' if no matching key exists.
2848 void Magick::Image::defineSet ( const std::string &magick_,
2849 const std::string &key_,
2853 std::string definition = magick_ + ":" + key_;
2856 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2860 DeleteImageOption( imageInfo(), definition.c_str() );
2863 bool Magick::Image::defineSet ( const std::string &magick_,
2864 const std::string &key_ ) const
2866 std::string key = magick_ + ":" + key_;
2867 const char *option =
2868 GetImageOption ( constImageInfo(), key.c_str() );
2875 void Magick::Image::density ( const Geometry &density_ )
2878 options()->density( density_ );
2879 if ( density_.isValid() )
2881 image()->x_resolution = density_.width();
2882 if ( density_.height() != 0 )
2884 image()->y_resolution = density_.height();
2888 image()->y_resolution = density_.width();
2894 image()->x_resolution = 0;
2895 image()->y_resolution = 0;
2898 Magick::Geometry Magick::Image::density ( void ) const
2902 ssize_t x_resolution=72;
2903 ssize_t y_resolution=72;
2905 if (constImage()->x_resolution > 0.0)
2906 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
2908 if (constImage()->y_resolution > 0.0)
2909 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
2911 return Geometry(x_resolution,y_resolution);
2914 return constOptions()->density( );
2917 // Image depth (bits allocated to red/green/blue components)
2918 void Magick::Image::depth ( const size_t depth_ )
2920 size_t depth = depth_;
2922 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2923 depth=MAGICKCORE_QUANTUM_DEPTH;
2926 image()->depth=depth;
2927 options()->depth( depth );
2929 size_t Magick::Image::depth ( void ) const
2931 return constImage()->depth;
2934 std::string Magick::Image::directory ( void ) const
2936 if ( constImage()->directory )
2937 return std::string( constImage()->directory );
2939 throwExceptionExplicit( CorruptImageWarning,
2940 "Image does not contain a directory");
2942 return std::string();
2945 // Endianness (little like Intel or big like SPARC) for image
2946 // formats which support endian-specific options.
2947 void Magick::Image::endian ( const Magick::EndianType endian_ )
2950 options()->endian( endian_ );
2951 image()->endian = endian_;
2953 Magick::EndianType Magick::Image::endian ( void ) const
2955 return constImage()->endian;
2958 // EXIF profile (BLOB)
2959 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2962 if ( exifProfile_.data() != 0 )
2964 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2965 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2966 (void) SetImageProfile( image(), "exif", exif_profile);
2967 exif_profile =DestroyStringInfo( exif_profile );
2970 Magick::Blob Magick::Image::exifProfile( void ) const
2972 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2973 if ( exif_profile == (StringInfo *) NULL)
2974 return Blob( 0, 0 );
2975 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2979 void Magick::Image::fileName ( const std::string &fileName_ )
2983 fileName_.copy( image()->filename,
2984 sizeof(image()->filename) - 1 );
2985 image()->filename[ fileName_.length() ] = 0; // Null terminate
2987 options()->fileName( fileName_ );
2990 std::string Magick::Image::fileName ( void ) const
2992 return constOptions()->fileName( );
2996 off_t Magick::Image::fileSize ( void ) const
2998 return (off_t) GetBlobSize( constImage() );
3001 // Color to use when drawing inside an object
3002 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3005 options()->fillColor(fillColor_);
3007 Magick::Color Magick::Image::fillColor ( void ) const
3009 return constOptions()->fillColor();
3012 // Rule to use when filling drawn objects
3013 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3016 options()->fillRule(fillRule_);
3018 Magick::FillRule Magick::Image::fillRule ( void ) const
3020 return constOptions()->fillRule();
3023 // Pattern to use while filling drawn objects.
3024 void Magick::Image::fillPattern ( const Image &fillPattern_ )
3027 if(fillPattern_.isValid())
3028 options()->fillPattern( fillPattern_.constImage() );
3030 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3032 Magick::Image Magick::Image::fillPattern ( void ) const
3034 // FIXME: This is inordinately innefficient
3037 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3041 ExceptionInfo exceptionInfo;
3042 GetExceptionInfo( &exceptionInfo );
3043 MagickCore::Image* image =
3044 CloneImage( tmpTexture,
3047 MagickTrue, // orphan
3049 texture.replaceImage( image );
3050 throwException( exceptionInfo );
3051 (void) DestroyExceptionInfo( &exceptionInfo );
3056 // Filter used by zoom
3057 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3060 image()->filter = filterType_;
3062 Magick::FilterTypes Magick::Image::filterType ( void ) const
3064 return constImage()->filter;
3068 void Magick::Image::font ( const std::string &font_ )
3071 options()->font( font_ );
3073 std::string Magick::Image::font ( void ) const
3075 return constOptions()->font( );
3079 void Magick::Image::fontPointsize ( const double pointSize_ )
3082 options()->fontPointsize( pointSize_ );
3084 double Magick::Image::fontPointsize ( void ) const
3086 return constOptions()->fontPointsize( );
3089 // Font type metrics
3090 void Magick::Image::fontTypeMetrics( const std::string &text_,
3091 TypeMetric *metrics )
3093 DrawInfo *drawInfo = options()->drawInfo();
3094 drawInfo->text = const_cast<char *>(text_.c_str());
3095 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3099 // Image format string
3100 std::string Magick::Image::format ( void ) const
3102 ExceptionInfo exceptionInfo;
3103 GetExceptionInfo( &exceptionInfo );
3104 const MagickInfo * magick_info
3105 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3106 throwException( exceptionInfo );
3107 (void) DestroyExceptionInfo( &exceptionInfo );
3109 if (( magick_info != 0 ) &&
3110 ( *magick_info->description != '\0' ))
3111 return std::string(magick_info->description);
3113 throwExceptionExplicit( CorruptImageWarning,
3114 "Unrecognized image magick type" );
3115 return std::string();
3119 double Magick::Image::gamma ( void ) const
3121 return constImage()->gamma;
3124 Magick::Geometry Magick::Image::geometry ( void ) const
3126 if ( constImage()->geometry )
3128 return Geometry(constImage()->geometry);
3131 throwExceptionExplicit( OptionWarning,
3132 "Image does not contain a geometry");
3137 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3140 image()->dispose = (DisposeType) disposeMethod_;
3142 size_t Magick::Image::gifDisposeMethod ( void ) const
3144 // FIXME: It would be better to return an enumeration
3145 return constImage()->dispose;
3148 // ICC ICM color profile (BLOB)
3149 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3151 profile("icm",colorProfile_);
3153 Magick::Blob Magick::Image::iccColorProfile( void ) const
3155 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3156 if ( color_profile == (StringInfo *) NULL)
3157 return Blob( 0, 0 );
3158 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3161 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3164 image()->interlace = interlace_;
3165 options()->interlaceType ( interlace_ );
3167 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3169 return constImage()->interlace;
3172 // IPTC profile (BLOB)
3173 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3176 if ( iptcProfile_.data() != 0 )
3178 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3179 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3180 (void) SetImageProfile( image(), "iptc", iptc_profile);
3181 iptc_profile =DestroyStringInfo( iptc_profile );
3184 Magick::Blob Magick::Image::iptcProfile( void ) const
3186 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3187 if ( iptc_profile == (StringInfo *) NULL)
3188 return Blob( 0, 0 );
3189 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3192 // Does object contain valid image?
3193 void Magick::Image::isValid ( const bool isValid_ )
3198 _imgRef = new ImageRef;
3200 else if ( !isValid() )
3202 // Construct with single-pixel black image to make
3203 // image valid. This is an obvious hack.
3204 size( Geometry(1,1) );
3205 read( "xc:#000000" );
3209 bool Magick::Image::isValid ( void ) const
3211 if ( rows() && columns() )
3218 void Magick::Image::label ( const std::string &label_ )
3221 SetImageProperty ( image(), "Label", NULL );
3222 if ( label_.length() > 0 )
3223 SetImageProperty ( image(), "Label", label_.c_str() );
3224 throwImageException();
3226 std::string Magick::Image::label ( void ) const
3228 const char *value = GetImageProperty( constImage(), "Label" );
3231 return std::string( value );
3233 return std::string();
3236 void Magick::Image::magick ( const std::string &magick_ )
3240 magick_.copy( image()->magick,
3241 sizeof(image()->magick) - 1 );
3242 image()->magick[ magick_.length() ] = 0;
3244 options()->magick( magick_ );
3246 std::string Magick::Image::magick ( void ) const
3248 if ( *(constImage()->magick) != '\0' )
3249 return std::string(constImage()->magick);
3251 return constOptions()->magick( );
3254 void Magick::Image::matte ( const bool matteFlag_ )
3258 // If matte channel is requested, but image doesn't already have a
3259 // matte channel, then create an opaque matte channel. Likewise, if
3260 // the image already has a matte channel but a matte channel is not
3261 // desired, then set the matte channel to opaque.
3262 if ((matteFlag_ && !constImage()->matte) ||
3263 (constImage()->matte && !matteFlag_))
3264 SetImageOpacity(image(),OpaqueAlpha);
3266 image()->matte = (MagickBooleanType) matteFlag_;
3268 bool Magick::Image::matte ( void ) const
3270 if ( constImage()->matte )
3276 void Magick::Image::matteColor ( const Color &matteColor_ )
3280 if ( matteColor_.isValid() )
3282 image()->matte_color = matteColor_;
3283 options()->matteColor( matteColor_ );
3287 // Set to default matte color
3288 Color tmpColor( "#BDBDBD" );
3289 image()->matte_color = tmpColor;
3290 options()->matteColor( tmpColor );
3293 Magick::Color Magick::Image::matteColor ( void ) const
3295 return Color( constImage()->matte_color.red,
3296 constImage()->matte_color.green,
3297 constImage()->matte_color.blue );
3300 double Magick::Image::meanErrorPerPixel ( void ) const
3302 return(constImage()->error.mean_error_per_pixel);
3305 // Image modulus depth (minimum number of bits required to support
3306 // red/green/blue components without loss of accuracy)
3307 void Magick::Image::modulusDepth ( const size_t depth_ )
3310 SetImageDepth( image(), depth_ );
3311 options()->depth( depth_ );
3313 size_t Magick::Image::modulusDepth ( void ) const
3315 ExceptionInfo exceptionInfo;
3316 GetExceptionInfo( &exceptionInfo );
3317 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3318 throwException( exceptionInfo );
3319 (void) DestroyExceptionInfo( &exceptionInfo );
3323 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3326 options()->monochrome( monochromeFlag_ );
3328 bool Magick::Image::monochrome ( void ) const
3330 return constOptions()->monochrome( );
3333 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3335 if ( constImage()->montage )
3336 return Magick::Geometry(constImage()->montage);
3338 throwExceptionExplicit( CorruptImageWarning,
3339 "Image does not contain a montage" );
3341 return Magick::Geometry();
3344 double Magick::Image::normalizedMaxError ( void ) const
3346 return(constImage()->error.normalized_maximum_error);
3349 double Magick::Image::normalizedMeanError ( void ) const
3351 return constImage()->error.normalized_mean_error;
3354 // Image orientation
3355 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3358 image()->orientation = orientation_;
3360 Magick::OrientationType Magick::Image::orientation ( void ) const
3362 return constImage()->orientation;
3365 void Magick::Image::penColor ( const Color &penColor_ )
3368 options()->fillColor(penColor_);
3369 options()->strokeColor(penColor_);
3371 Magick::Color Magick::Image::penColor ( void ) const
3373 return constOptions()->fillColor();
3376 void Magick::Image::penTexture ( const Image &penTexture_ )
3379 if(penTexture_.isValid())
3380 options()->fillPattern( penTexture_.constImage() );
3382 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3385 Magick::Image Magick::Image::penTexture ( void ) const
3387 // FIXME: This is inordinately innefficient
3390 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3394 ExceptionInfo exceptionInfo;
3395 GetExceptionInfo( &exceptionInfo );
3396 MagickCore::Image* image =
3397 CloneImage( tmpTexture,
3400 MagickTrue, // orphan
3402 texture.replaceImage( image );
3403 throwException( exceptionInfo );
3404 (void) DestroyExceptionInfo( &exceptionInfo );
3409 // Set the color of a pixel.
3410 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3411 const Color &color_ )
3413 // Test arguments to ensure they are within the image.
3414 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3415 throwExceptionExplicit( OptionError,
3416 "Access outside of image boundary" );
3420 // Set image to DirectClass
3421 classType( DirectClass );
3424 Pixels pixels(*this);
3426 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3427 PixelPacket packet = color_;
3428 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
3429 // Tell ImageMagick that pixels have been updated
3435 // Get the color of a pixel
3436 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3437 const ssize_t y_ ) const
3439 ClassType storage_class;
3440 storage_class = classType();
3442 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3446 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3447 return Color( packet );
3450 return Color(); // invalid
3453 // Preferred size and location of an image canvas.
3454 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3457 options()->page( pageSize_ );
3458 image()->page = pageSize_;
3460 Magick::Geometry Magick::Image::page ( void ) const
3462 return Geometry( constImage()->page.width,
3463 constImage()->page.height,
3464 AbsoluteValue(constImage()->page.x),
3465 AbsoluteValue(constImage()->page.y),
3466 constImage()->page.x < 0 ? true : false,
3467 constImage()->page.y < 0 ? true : false);
3470 // Add a named profile to an image or remove a named profile by
3471 // passing an empty Blob (use default Blob constructor).
3473 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3474 void Magick::Image::profile( const std::string name_,
3475 const Magick::Blob &profile_ )
3478 ssize_t result = ProfileImage( image(), name_.c_str(),
3479 (unsigned char *)profile_.data(),
3480 profile_.length(), MagickTrue);
3483 throwImageException();
3486 // Retrieve a named profile from the image.
3488 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3489 // an existing generic profile name.
3490 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3492 const MagickCore::Image* image = constImage();
3494 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3496 if ( profile != (StringInfo *) NULL)
3497 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3500 Image temp_image = *this;
3501 temp_image.write( &blob, name_ );
3505 void Magick::Image::quality ( const size_t quality_ )
3508 image()->quality = quality_;
3509 options()->quality( quality_ );
3511 size_t Magick::Image::quality ( void ) const
3513 return constImage()->quality;
3516 void Magick::Image::quantizeColors ( const size_t colors_ )
3519 options()->quantizeColors( colors_ );
3521 size_t Magick::Image::quantizeColors ( void ) const
3523 return constOptions()->quantizeColors( );
3526 void Magick::Image::quantizeColorSpace
3527 ( const Magick::ColorspaceType colorSpace_ )
3530 options()->quantizeColorSpace( colorSpace_ );
3532 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3534 return constOptions()->quantizeColorSpace( );
3537 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3540 options()->quantizeDither( ditherFlag_ );
3542 bool Magick::Image::quantizeDither ( void ) const
3544 return constOptions()->quantizeDither( );
3547 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3550 options()->quantizeTreeDepth( treeDepth_ );
3552 size_t Magick::Image::quantizeTreeDepth ( void ) const
3554 return constOptions()->quantizeTreeDepth( );
3557 void Magick::Image::renderingIntent
3558 ( const Magick::RenderingIntent renderingIntent_ )
3561 image()->rendering_intent = renderingIntent_;
3563 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3565 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3568 void Magick::Image::resolutionUnits
3569 ( const Magick::ResolutionType resolutionUnits_ )
3572 image()->units = resolutionUnits_;
3573 options()->resolutionUnits( resolutionUnits_ );
3575 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3577 return constOptions()->resolutionUnits( );
3580 void Magick::Image::scene ( const size_t scene_ )
3583 image()->scene = scene_;
3585 size_t Magick::Image::scene ( void ) const
3587 return constImage()->scene;
3590 std::string Magick::Image::signature ( const bool force_ ) const
3592 Lock( &_imgRef->_mutexLock );
3594 // Re-calculate image signature if necessary
3596 !GetImageProperty(constImage(), "Signature") ||
3597 constImage()->taint )
3599 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3602 const char *property = GetImageProperty(constImage(), "Signature");
3604 return std::string( property );
3607 void Magick::Image::size ( const Geometry &geometry_ )
3610 options()->size( geometry_ );
3611 image()->rows = geometry_.height();
3612 image()->columns = geometry_.width();
3614 Magick::Geometry Magick::Image::size ( void ) const
3616 return Magick::Geometry( constImage()->columns, constImage()->rows );
3620 void Magick::Image::splice( const Geometry &geometry_ )
3622 RectangleInfo spliceInfo = geometry_;
3623 ExceptionInfo exceptionInfo;
3624 GetExceptionInfo( &exceptionInfo );
3625 MagickCore::Image* newImage =
3626 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3627 replaceImage( newImage );
3628 throwException( exceptionInfo );
3629 (void) DestroyExceptionInfo( &exceptionInfo );
3632 // Obtain image statistics. Statistics are normalized to the range of
3633 // 0.0 to 1.0 and are output to the specified ImageStatistics
3635 void Magick::Image::statistics ( ImageStatistics *statistics )
3641 ExceptionInfo exceptionInfo;
3642 GetExceptionInfo( &exceptionInfo );
3644 ChannelType channel_mask = SetPixelChannelMask( image(), RedChannel);
3645 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3646 statistics->red.minimum=minimum;
3647 statistics->red.maximum=maximum;
3648 (void) GetImageMean( image(),&statistics->red.mean,
3649 &statistics->red.standard_deviation,&exceptionInfo);
3650 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3651 &statistics->red.skewness,&exceptionInfo);
3652 (void) SetPixelChannelMap( image(), channel_mask );
3654 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3655 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3656 statistics->green.minimum=minimum;
3657 statistics->green.maximum=maximum;
3658 (void) GetImageMean( image(),&statistics->green.mean,
3659 &statistics->green.standard_deviation,&exceptionInfo);
3660 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3661 &statistics->green.skewness,&exceptionInfo);
3662 (void) SetPixelChannelMap( image(), channel_mask );
3664 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3665 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3666 statistics->blue.minimum=minimum;
3667 statistics->blue.maximum=maximum;
3668 (void) GetImageMean( image(),&statistics->blue.mean,
3669 &statistics->blue.standard_deviation,&exceptionInfo);
3670 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3671 &statistics->blue.skewness,&exceptionInfo);
3672 (void) SetPixelChannelMap( image(), channel_mask );
3674 channel_mask = SetPixelChannelMask( image(), AlphaChannel);
3675 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3676 statistics->alpha.minimum=minimum;
3677 statistics->alpha.maximum=maximum;
3678 (void) GetImageMean( image(),&statistics->alpha.mean,
3679 &statistics->alpha.standard_deviation,&exceptionInfo);
3680 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3681 &statistics->alpha.skewness,&exceptionInfo);
3682 (void) SetPixelChannelMap( image(), channel_mask );
3684 throwException( exceptionInfo );
3685 (void) DestroyExceptionInfo( &exceptionInfo );
3688 // Strip strips an image of all profiles and comments.
3689 void Magick::Image::strip ( void )
3692 StripImage( image() );
3693 throwImageException();
3696 // enabled/disable stroke anti-aliasing
3697 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3700 options()->strokeAntiAlias(flag_);
3702 bool Magick::Image::strokeAntiAlias ( void ) const
3704 return constOptions()->strokeAntiAlias();
3707 // Color to use when drawing object outlines
3708 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3711 options()->strokeColor(strokeColor_);
3713 Magick::Color Magick::Image::strokeColor ( void ) const
3715 return constOptions()->strokeColor();
3718 // dash pattern for drawing vector objects (default one)
3719 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3722 options()->strokeDashArray( strokeDashArray_ );
3725 const double* Magick::Image::strokeDashArray ( void ) const
3727 return constOptions()->strokeDashArray( );
3730 // dash offset for drawing vector objects (default one)
3731 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3734 options()->strokeDashOffset( strokeDashOffset_ );
3737 double Magick::Image::strokeDashOffset ( void ) const
3739 return constOptions()->strokeDashOffset( );
3742 // Specify the shape to be used at the end of open subpaths when they
3743 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3745 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3748 options()->strokeLineCap( lineCap_ );
3750 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3752 return constOptions()->strokeLineCap( );
3755 // Specify the shape to be used at the corners of paths (or other
3756 // vector shapes) when they are stroked. Values of LineJoin are
3757 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3758 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3761 options()->strokeLineJoin( lineJoin_ );
3763 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3765 return constOptions()->strokeLineJoin( );
3768 // Specify miter limit. When two line segments meet at a sharp angle
3769 // and miter joins have been specified for 'lineJoin', it is possible
3770 // for the miter to extend far beyond the thickness of the line
3771 // stroking the path. The miterLimit' imposes a limit on the ratio of
3772 // the miter length to the 'lineWidth'. The default value of this
3774 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3777 options()->strokeMiterLimit( strokeMiterLimit_ );
3779 size_t Magick::Image::strokeMiterLimit ( void ) const
3781 return constOptions()->strokeMiterLimit( );
3784 // Pattern to use while stroking drawn objects.
3785 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3788 if(strokePattern_.isValid())
3789 options()->strokePattern( strokePattern_.constImage() );
3791 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3793 Magick::Image Magick::Image::strokePattern ( void ) const
3795 // FIXME: This is inordinately innefficient
3798 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3802 ExceptionInfo exceptionInfo;
3803 GetExceptionInfo( &exceptionInfo );
3804 MagickCore::Image* image =
3805 CloneImage( tmpTexture,
3808 MagickTrue, // orphan
3810 throwException( exceptionInfo );
3811 (void) DestroyExceptionInfo( &exceptionInfo );
3812 texture.replaceImage( image );
3817 // Stroke width for drawing lines, circles, ellipses, etc.
3818 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3821 options()->strokeWidth( strokeWidth_ );
3823 double Magick::Image::strokeWidth ( void ) const
3825 return constOptions()->strokeWidth( );
3828 void Magick::Image::subImage ( const size_t subImage_ )
3831 options()->subImage( subImage_ );
3833 size_t Magick::Image::subImage ( void ) const
3835 return constOptions()->subImage( );
3838 void Magick::Image::subRange ( const size_t subRange_ )
3841 options()->subRange( subRange_ );
3843 size_t Magick::Image::subRange ( void ) const
3845 return constOptions()->subRange( );
3848 // Annotation text encoding (e.g. "UTF-16")
3849 void Magick::Image::textEncoding ( const std::string &encoding_ )
3852 options()->textEncoding( encoding_ );
3854 std::string Magick::Image::textEncoding ( void ) const
3856 return constOptions()->textEncoding( );
3859 size_t Magick::Image::totalColors ( void )
3861 ExceptionInfo exceptionInfo;
3862 GetExceptionInfo( &exceptionInfo );
3863 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3864 throwException( exceptionInfo );
3865 (void) DestroyExceptionInfo( &exceptionInfo );
3869 // Origin of coordinate system to use when annotating with text or drawing
3870 void Magick::Image::transformOrigin ( const double x_, const double y_ )
3873 options()->transformOrigin( x_, y_ );
3876 // Rotation to use when annotating with text or drawing
3877 void Magick::Image::transformRotation ( const double angle_ )
3880 options()->transformRotation( angle_ );
3883 // Reset transformation parameters to default
3884 void Magick::Image::transformReset ( void )
3887 options()->transformReset();
3890 // Scale to use when annotating with text or drawing
3891 void Magick::Image::transformScale ( const double sx_, const double sy_ )
3894 options()->transformScale( sx_, sy_ );
3897 // Skew to use in X axis when annotating with text or drawing
3898 void Magick::Image::transformSkewX ( const double skewx_ )
3901 options()->transformSkewX( skewx_ );
3904 // Skew to use in Y axis when annotating with text or drawing
3905 void Magick::Image::transformSkewY ( const double skewy_ )
3908 options()->transformSkewY( skewy_ );
3911 // Image representation type
3912 Magick::ImageType Magick::Image::type ( void ) const
3915 ExceptionInfo exceptionInfo;
3916 GetExceptionInfo( &exceptionInfo );
3917 ImageType image_type = constOptions()->type();
3918 if ( image_type == UndefinedType )
3919 image_type= GetImageType( constImage(), &exceptionInfo);
3920 throwException( exceptionInfo );
3921 (void) DestroyExceptionInfo( &exceptionInfo );
3924 void Magick::Image::type ( const Magick::ImageType type_)
3927 options()->type( type_ );
3928 SetImageType( image(), type_ );
3931 void Magick::Image::verbose ( const bool verboseFlag_ )
3934 options()->verbose( verboseFlag_ );
3936 bool Magick::Image::verbose ( void ) const
3938 return constOptions()->verbose( );
3941 void Magick::Image::view ( const std::string &view_ )
3944 options()->view( view_ );
3946 std::string Magick::Image::view ( void ) const
3948 return constOptions()->view( );
3951 // Virtual pixel method
3952 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3955 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3956 options()->virtualPixelMethod( virtual_pixel_method_ );
3958 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3960 return GetImageVirtualPixelMethod( constImage() );
3963 void Magick::Image::x11Display ( const std::string &display_ )
3966 options()->x11Display( display_ );
3968 std::string Magick::Image::x11Display ( void ) const
3970 return constOptions()->x11Display( );
3973 double Magick::Image::xResolution ( void ) const
3975 return constImage()->x_resolution;
3977 double Magick::Image::yResolution ( void ) const
3979 return constImage()->y_resolution;
3983 Magick::Image::Image( const Image & image_ )
3984 : _imgRef(image_._imgRef)
3986 Lock( &_imgRef->_mutexLock );
3988 // Increase reference count
3989 ++_imgRef->_refCount;
3992 // Assignment operator
3993 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3995 if( this != &image_ )
3998 Lock( &image_._imgRef->_mutexLock );
3999 ++image_._imgRef->_refCount;
4002 bool doDelete = false;
4004 Lock( &_imgRef->_mutexLock );
4005 if ( --_imgRef->_refCount == 0 )
4011 // Delete old image reference with associated image and options.
4015 // Use new image reference
4016 _imgRef = image_._imgRef;
4022 //////////////////////////////////////////////////////////////////////
4024 // Low-level Pixel Access Routines
4026 // Also see the Pixels class, which provides support for multiple
4027 // cache views. The low-level pixel access routines in the Image
4028 // class are provided in order to support backward compatability.
4030 //////////////////////////////////////////////////////////////////////
4032 // Transfers read-only pixels from the image to the pixel cache as
4033 // defined by the specified region
4034 const Magick::Quantum* Magick::Image::getConstPixels
4035 ( const ssize_t x_, const ssize_t y_,
4036 const size_t columns_,
4037 const size_t rows_ ) const
4039 ExceptionInfo exceptionInfo;
4040 GetExceptionInfo( &exceptionInfo );
4041 const Quantum* p = (*GetVirtualPixels)( constImage(),
4045 throwException( exceptionInfo );
4046 (void) DestroyExceptionInfo( &exceptionInfo );
4050 // Obtain read-only pixel associated pixels channels
4051 const void* Magick::Image::getConstMetacontent ( void ) const
4053 const void* result = GetVirtualMetacontent( constImage() );
4056 throwImageException();
4061 // Obtain image pixel associated pixels channels
4062 void* Magick::Image::getMetacontent ( void )
4064 void* result = GetAuthenticMetacontent( image() );
4067 throwImageException();
4072 // Transfers pixels from the image to the pixel cache as defined
4073 // by the specified region. Modified pixels may be subsequently
4074 // transferred back to the image via syncPixels.
4075 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4076 const size_t columns_,
4077 const size_t rows_ )
4080 ExceptionInfo exceptionInfo;
4081 GetExceptionInfo( &exceptionInfo );
4082 Quantum* result = (*GetAuthenticPixels)( image(),
4084 columns_, rows_, &exceptionInfo );
4085 throwException( exceptionInfo );
4086 (void) DestroyExceptionInfo( &exceptionInfo );
4091 // Allocates a pixel cache region to store image pixels as defined
4092 // by the region rectangle. This area is subsequently transferred
4093 // from the pixel cache to the image via syncPixels.
4094 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4095 const size_t columns_,
4096 const size_t rows_ )
4099 ExceptionInfo exceptionInfo;
4100 GetExceptionInfo( &exceptionInfo );
4101 Quantum* result = (*QueueAuthenticPixels)( image(),
4103 columns_, rows_, &exceptionInfo );
4104 throwException( exceptionInfo );
4105 (void) DestroyExceptionInfo( &exceptionInfo );
4110 // Transfers the image cache pixels to the image.
4111 void Magick::Image::syncPixels ( void )
4113 ExceptionInfo exceptionInfo;
4114 GetExceptionInfo( &exceptionInfo );
4115 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4116 throwException( exceptionInfo );
4117 (void) DestroyExceptionInfo( &exceptionInfo );
4120 // Transfers one or more pixel components from a buffer or file
4121 // into the image pixel cache of an image.
4122 // Used to support image decoders.
4123 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4124 const unsigned char *source_ )
4129 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4130 ExceptionInfo exceptionInfo;
4131 GetExceptionInfo( &exceptionInfo );
4132 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4133 quantum_,source_, &exceptionInfo);
4134 throwException( exceptionInfo );
4135 (void) DestroyExceptionInfo( &exceptionInfo );
4136 quantum_info=DestroyQuantumInfo(quantum_info);
4139 // Transfers one or more pixel components from the image pixel
4140 // cache to a buffer or file.
4141 // Used to support image encoders.
4142 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4143 unsigned char *destination_ )
4148 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4149 ExceptionInfo exceptionInfo;
4150 GetExceptionInfo( &exceptionInfo );
4151 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4152 quantum_,destination_, &exceptionInfo);
4153 quantum_info=DestroyQuantumInfo(quantum_info);
4154 throwException( exceptionInfo );
4155 (void) DestroyExceptionInfo( &exceptionInfo );
4158 /////////////////////////////////////////////////////////////////////
4160 // No end-user methods beyond this point
4162 /////////////////////////////////////////////////////////////////////
4166 // Construct using existing image and default options
4168 Magick::Image::Image ( MagickCore::Image* image_ )
4169 : _imgRef(new ImageRef( image_))
4173 // Get Magick::Options*
4174 Magick::Options* Magick::Image::options( void )
4176 return _imgRef->options();
4178 const Magick::Options* Magick::Image::constOptions( void ) const
4180 return _imgRef->options();
4183 // Get MagickCore::Image*
4184 MagickCore::Image*& Magick::Image::image( void )
4186 return _imgRef->image();
4188 const MagickCore::Image* Magick::Image::constImage( void ) const
4190 return _imgRef->image();
4194 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4196 return _imgRef->options()->imageInfo();
4198 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4200 return _imgRef->options()->imageInfo();
4203 // Get QuantizeInfo *
4204 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4206 return _imgRef->options()->quantizeInfo();
4208 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4210 return _imgRef->options()->quantizeInfo();
4214 // Replace current image
4216 MagickCore::Image * Magick::Image::replaceImage
4217 ( MagickCore::Image* replacement_ )
4219 MagickCore::Image* image;
4222 image = replacement_;
4224 image = AcquireImage(constImageInfo());
4227 Lock( &_imgRef->_mutexLock );
4229 if ( _imgRef->_refCount == 1 )
4231 // We own the image, just replace it, and de-register
4233 _imgRef->image(image);
4237 // We don't own the image, dereference and replace with copy
4238 --_imgRef->_refCount;
4239 _imgRef = new ImageRef( image, constOptions() );
4243 return _imgRef->_image;
4247 // Prepare to modify image or image options
4248 // Replace current image and options with copy if reference count > 1
4250 void Magick::Image::modifyImage( void )
4253 Lock( &_imgRef->_mutexLock );
4254 if ( _imgRef->_refCount == 1 )
4256 // De-register image and return
4262 ExceptionInfo exceptionInfo;
4263 GetExceptionInfo( &exceptionInfo );
4264 replaceImage( CloneImage( image(),
4267 MagickTrue, // orphan
4269 throwException( exceptionInfo );
4270 (void) DestroyExceptionInfo( &exceptionInfo );
4275 // Test for an ImageMagick reported error and throw exception if one
4276 // has been reported. Secretly resets image->exception back to default
4277 // state even though this method is const.
4279 void Magick::Image::throwImageException( void ) const
4281 // Throw C++ exception while resetting Image exception to default state
4282 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4285 // Register image with image registry or obtain registration id
4286 ssize_t Magick::Image::registerId( void )
4288 Lock( &_imgRef->_mutexLock );
4289 if( _imgRef->id() < 0 )
4291 char id[MaxTextExtent];
4292 ExceptionInfo exceptionInfo;
4293 GetExceptionInfo( &exceptionInfo );
4294 _imgRef->id(_imgRef->id()+1);
4295 sprintf(id,"%.20g\n",(double) _imgRef->id());
4296 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4297 throwException( exceptionInfo );
4298 (void) DestroyExceptionInfo( &exceptionInfo );
4300 return _imgRef->id();
4303 // Unregister image from image registry
4304 void Magick::Image::unregisterId( void )
4311 // Create a local wrapper around MagickCoreTerminus
4316 void MagickPlusPlusDestroyMagick(void);
4320 void Magick::MagickPlusPlusDestroyMagick(void)
4322 if (magick_initialized)
4324 magick_initialized=false;
4325 MagickCore::MagickCoreTerminus();
4329 // C library initialization routine
4330 void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4332 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4333 if (!magick_initialized)
4334 magick_initialized=true;
4338 // Cleanup class to ensure that ImageMagick singletons are destroyed
4339 // so as to avoid any resemblence to a memory leak (which seems to
4348 MagickCleanUp( void );
4349 ~MagickCleanUp( void );
4352 // The destructor for this object is invoked when the destructors for
4353 // static objects in this translation unit are invoked.
4354 static MagickCleanUp magickCleanUpGuard;
4357 Magick::MagickCleanUp::MagickCleanUp ( void )
4359 // Don't even think about invoking InitializeMagick here!
4362 Magick::MagickCleanUp::~MagickCleanUp ( void )
4364 MagickPlusPlusDestroyMagick();