1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Implementation of Image
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11 #include "Magick++/Include.h"
17 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
23 #include "Magick++/Image.h"
24 #include "Magick++/Functions.h"
25 #include "Magick++/Pixels.h"
26 #include "Magick++/Options.h"
27 #include "Magick++/ImageRef.h"
29 #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
30 #define MagickPI 3.14159265358979323846264338327950288419716939937510
31 #define DegreesToRadians(x) (MagickPI*(x)/180.0)
33 MagickDLLDeclExtern const char *Magick::borderGeometryDefault = "6x6+0+0";
34 MagickDLLDeclExtern const char *Magick::frameGeometryDefault = "25x25+6+6";
35 MagickDLLDeclExtern const char *Magick::raiseGeometryDefault = "6x6+0+0";
37 static bool magick_initialized=false;
40 // Explicit template instantiations
44 // Friend functions to compare Image objects
47 MagickDLLDecl int Magick::operator == ( const Magick::Image& left_,
48 const Magick::Image& right_ )
50 // If image pixels and signature are the same, then the image is identical
51 return ( ( left_.rows() == right_.rows() ) &&
52 ( left_.columns() == right_.columns() ) &&
53 ( left_.signature() == right_.signature() )
56 MagickDLLDecl int Magick::operator != ( const Magick::Image& left_,
57 const Magick::Image& right_ )
59 return ( ! (left_ == right_) );
61 MagickDLLDecl int Magick::operator > ( const Magick::Image& left_,
62 const Magick::Image& right_ )
64 return ( !( left_ < right_ ) && ( left_ != right_ ) );
66 MagickDLLDecl int Magick::operator < ( const Magick::Image& left_,
67 const Magick::Image& right_ )
69 // If image pixels are less, then image is smaller
70 return ( ( left_.rows() * left_.columns() ) <
71 ( right_.rows() * right_.columns() )
74 MagickDLLDecl int Magick::operator >= ( const Magick::Image& left_,
75 const Magick::Image& right_ )
77 return ( ( left_ > right_ ) || ( left_ == right_ ) );
79 MagickDLLDecl int Magick::operator <= ( const Magick::Image& left_,
80 const Magick::Image& right_ )
82 return ( ( left_ < right_ ) || ( left_ == right_ ) );
86 // Image object implementation
89 // Construct from image file or image specification
90 Magick::Image::Image( const std::string &imageSpec_ )
91 : _imgRef(new ImageRef)
95 // Initialize, Allocate and Read images
98 catch ( const Warning & /*warning_*/ )
100 // FIXME: need a way to report warnings in constructor
102 catch ( const Error & /*error_*/ )
110 // Construct a blank image canvas of specified size and color
111 Magick::Image::Image( const Geometry &size_,
112 const Color &color_ )
113 : _imgRef(new ImageRef)
115 // xc: prefix specifies an X11 color string
116 std::string imageSpec("xc:");
124 // Initialize, Allocate and Read images
127 catch ( const Warning & /*warning_*/ )
129 // FIXME: need a way to report warnings in constructor
131 catch ( const Error & /*error_*/ )
139 // Construct Image from in-memory BLOB
140 Magick::Image::Image ( const Blob &blob_ )
141 : _imgRef(new ImageRef)
145 // Initialize, Allocate and Read images
148 catch ( const Warning & /*warning_*/ )
150 // FIXME: need a way to report warnings in constructor
152 catch ( const Error & /*error_*/ )
160 // Construct Image of specified size from in-memory BLOB
161 Magick::Image::Image ( const Blob &blob_,
162 const Geometry &size_ )
163 : _imgRef(new ImageRef)
168 read( blob_, size_ );
170 catch ( const Warning & /*warning_*/ )
172 // FIXME: need a way to report warnings in constructor
174 catch ( const Error & /*error_*/ )
182 // Construct Image of specified size and depth from in-memory BLOB
183 Magick::Image::Image ( const Blob &blob_,
184 const Geometry &size_,
185 const size_t depth_ )
186 : _imgRef(new ImageRef)
191 read( blob_, size_, depth_ );
193 catch ( const Warning & /*warning_*/ )
195 // FIXME: need a way to report warnings in constructor
197 catch ( const Error & /*error_*/ )
205 // Construct Image of specified size, depth, and format from in-memory BLOB
206 Magick::Image::Image ( const Blob &blob_,
207 const Geometry &size_,
209 const std::string &magick_ )
210 : _imgRef(new ImageRef)
215 read( blob_, size_, depth_, magick_ );
217 catch ( const Warning & /*warning_*/ )
219 // FIXME: need a way to report warnings in constructor
221 catch ( const Error & /*error_*/ )
229 // Construct Image of specified size, and format from in-memory BLOB
230 Magick::Image::Image ( const Blob &blob_,
231 const Geometry &size_,
232 const std::string &magick_ )
233 : _imgRef(new ImageRef)
238 read( blob_, size_, magick_ );
240 catch ( const Warning & /*warning_*/ )
242 // FIXME: need a way to report warnings in constructor
244 catch ( const Error & /*error_*/ )
252 // Construct an image based on an array of raw pixels, of specified
253 // type and mapping, in memory
254 Magick::Image::Image ( const size_t width_,
255 const size_t height_,
256 const std::string &map_,
257 const StorageType type_,
258 const void *pixels_ )
259 : _imgRef(new ImageRef)
263 read( width_, height_, map_.c_str(), type_, pixels_ );
265 catch ( const Warning & /*warning_*/ )
267 // FIXME: need a way to report warnings in constructor
269 catch ( const Error & /*error_*/ )
277 // Default constructor
278 Magick::Image::Image( void )
279 : _imgRef(new ImageRef)
285 Magick::Image::~Image()
287 bool doDelete = false;
289 Lock( &_imgRef->_mutexLock );
290 if ( --_imgRef->_refCount == 0 )
301 // Adaptive-blur image
302 void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
304 ExceptionInfo exceptionInfo;
305 GetExceptionInfo( &exceptionInfo );
306 MagickCore::Image* newImage =
307 AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
308 replaceImage( newImage );
309 throwException( exceptionInfo );
310 (void) DestroyExceptionInfo( &exceptionInfo );
313 // Local adaptive threshold image
314 // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
315 // Width x height define the size of the pixel neighborhood
316 // offset = constant to subtract from pixel neighborhood mean
317 void Magick::Image::adaptiveThreshold ( const size_t width_,
318 const size_t height_,
319 const ssize_t offset_ )
321 ExceptionInfo exceptionInfo;
322 GetExceptionInfo( &exceptionInfo );
323 MagickCore::Image* newImage =
324 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
325 replaceImage( newImage );
326 throwException( exceptionInfo );
327 (void) DestroyExceptionInfo( &exceptionInfo );
330 // Add noise to image
331 void Magick::Image::addNoise( const NoiseType noiseType_ )
333 ExceptionInfo exceptionInfo;
334 GetExceptionInfo( &exceptionInfo );
335 MagickCore::Image* newImage =
336 AddNoiseImage ( image(),
339 replaceImage( newImage );
340 throwException( exceptionInfo );
341 (void) DestroyExceptionInfo( &exceptionInfo );
344 void Magick::Image::addNoiseChannel( const ChannelType channel_,
345 const NoiseType noiseType_ )
347 ExceptionInfo exceptionInfo;
348 GetExceptionInfo( &exceptionInfo );
349 MagickCore::Image* newImage =
350 AddNoiseImageChannel ( image(),
354 replaceImage( newImage );
355 throwException( exceptionInfo );
356 (void) DestroyExceptionInfo( &exceptionInfo );
359 // Affine Transform image
360 void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
362 ExceptionInfo exceptionInfo;
363 GetExceptionInfo( &exceptionInfo );
365 AffineMatrix _affine;
366 _affine.sx = affine_.sx();
367 _affine.sy = affine_.sy();
368 _affine.rx = affine_.rx();
369 _affine.ry = affine_.ry();
370 _affine.tx = affine_.tx();
371 _affine.ty = affine_.ty();
373 MagickCore::Image* newImage =
374 AffineTransformImage( image(), &_affine, &exceptionInfo);
375 replaceImage( newImage );
376 throwException( exceptionInfo );
377 (void) DestroyExceptionInfo( &exceptionInfo );
380 // Annotate using specified text, and placement location
381 void Magick::Image::annotate ( const std::string &text_,
382 const Geometry &location_ )
384 annotate ( text_, location_, NorthWestGravity, 0.0 );
386 // Annotate using specified text, bounding area, and placement gravity
387 void Magick::Image::annotate ( const std::string &text_,
388 const Geometry &boundingArea_,
389 const GravityType gravity_ )
391 annotate ( text_, boundingArea_, gravity_, 0.0 );
393 // Annotate with text using specified text, bounding area, placement
394 // gravity, and rotation.
395 void Magick::Image::annotate ( const std::string &text_,
396 const Geometry &boundingArea_,
397 const GravityType gravity_,
398 const double degrees_ )
403 = options()->drawInfo();
405 drawInfo->text = const_cast<char *>(text_.c_str());
407 char boundingArea[MaxTextExtent];
409 drawInfo->geometry = 0;
410 if ( boundingArea_.isValid() ){
411 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
413 FormatMagickString( boundingArea, MaxTextExtent, "+%u+%u",
414 boundingArea_.xOff(), boundingArea_.yOff() );
418 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
421 drawInfo->geometry = boundingArea;
424 drawInfo->gravity = gravity_;
426 AffineMatrix oaffine = drawInfo->affine;
427 if ( degrees_ != 0.0)
437 AffineMatrix current = drawInfo->affine;
438 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
439 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
440 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
441 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
443 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
444 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
445 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
446 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
447 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
451 AnnotateImage( image(), drawInfo );
453 // Restore original values
454 drawInfo->affine = oaffine;
456 drawInfo->geometry = 0;
458 throwImageException();
460 // Annotate with text (bounding area is entire image) and placement gravity.
461 void Magick::Image::annotate ( const std::string &text_,
462 const GravityType gravity_ )
467 = options()->drawInfo();
469 drawInfo->text = const_cast<char *>(text_.c_str());
471 drawInfo->gravity = gravity_;
473 AnnotateImage( image(), drawInfo );
475 drawInfo->gravity = NorthWestGravity;
478 throwImageException();
482 void Magick::Image::blur( const double radius_, const double sigma_ )
484 ExceptionInfo exceptionInfo;
485 GetExceptionInfo( &exceptionInfo );
486 MagickCore::Image* newImage =
487 BlurImage( image(), radius_, sigma_, &exceptionInfo);
488 replaceImage( newImage );
489 throwException( exceptionInfo );
490 (void) DestroyExceptionInfo( &exceptionInfo );
493 void Magick::Image::blurChannel( const ChannelType channel_,
494 const double radius_, const double sigma_ )
496 ExceptionInfo exceptionInfo;
497 GetExceptionInfo( &exceptionInfo );
498 MagickCore::Image* newImage =
499 BlurImageChannel( image(), channel_,radius_, sigma_, &exceptionInfo);
500 replaceImage( newImage );
501 throwException( exceptionInfo );
502 (void) DestroyExceptionInfo( &exceptionInfo );
505 // Add border to image
506 // Only uses width & height
507 void Magick::Image::border( const Geometry &geometry_ )
509 RectangleInfo borderInfo = geometry_;
510 ExceptionInfo exceptionInfo;
511 GetExceptionInfo( &exceptionInfo );
512 MagickCore::Image* newImage =
513 BorderImage( image(), &borderInfo, &exceptionInfo);
514 replaceImage( newImage );
515 throwException( exceptionInfo );
516 (void) DestroyExceptionInfo( &exceptionInfo );
519 // Extract channel from image
520 void Magick::Image::channel ( const ChannelType channel_ )
523 SeparateImageChannel ( image(), channel_ );
524 throwImageException();
527 // Set or obtain modulus channel depth
528 void Magick::Image::channelDepth ( const ChannelType channel_,
532 SetImageChannelDepth( image(), channel_, depth_);
533 throwImageException();
535 size_t Magick::Image::channelDepth ( const ChannelType channel_ )
537 size_t channel_depth;
539 ExceptionInfo exceptionInfo;
540 GetExceptionInfo( &exceptionInfo );
541 channel_depth=GetImageChannelDepth( constImage(), channel_,
543 throwException( exceptionInfo );
544 (void) DestroyExceptionInfo( &exceptionInfo );
545 return channel_depth;
549 // Charcoal-effect image
550 void Magick::Image::charcoal( const double radius_, const double sigma_ )
552 ExceptionInfo exceptionInfo;
553 GetExceptionInfo( &exceptionInfo );
554 MagickCore::Image* newImage =
555 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
556 replaceImage( newImage );
557 throwException( exceptionInfo );
558 (void) DestroyExceptionInfo( &exceptionInfo );
562 void Magick::Image::chop( const Geometry &geometry_ )
564 RectangleInfo chopInfo = geometry_;
565 ExceptionInfo exceptionInfo;
566 GetExceptionInfo( &exceptionInfo );
567 MagickCore::Image* newImage =
568 ChopImage( image(), &chopInfo, &exceptionInfo);
569 replaceImage( newImage );
570 throwException( exceptionInfo );
571 (void) DestroyExceptionInfo( &exceptionInfo );
574 // contains one or more color corrections and applies the correction to the
576 void Magick::Image::cdl ( const std::string &cdl_ )
579 (void) ColorDecisionListImage( image(), cdl_.c_str() );
580 throwImageException();
584 void Magick::Image::colorize ( const unsigned int opacityRed_,
585 const unsigned int opacityGreen_,
586 const unsigned int opacityBlue_,
587 const Color &penColor_ )
589 if ( !penColor_.isValid() )
591 throwExceptionExplicit( OptionError,
592 "Pen color argument is invalid");
595 char opacity[MaxTextExtent];
596 FormatMagickString(opacity,MaxTextExtent,"%u/%u/%u",opacityRed_,opacityGreen_,opacityBlue_);
598 ExceptionInfo exceptionInfo;
599 GetExceptionInfo( &exceptionInfo );
600 MagickCore::Image* newImage =
601 ColorizeImage ( image(), opacity,
602 penColor_, &exceptionInfo );
603 replaceImage( newImage );
604 throwException( exceptionInfo );
605 (void) DestroyExceptionInfo( &exceptionInfo );
607 void Magick::Image::colorize ( const unsigned int opacity_,
608 const Color &penColor_ )
610 colorize( opacity_, opacity_, opacity_, penColor_ );
613 // Apply a color matrix to the image channels. The user supplied
614 // matrix may be of order 1 to 6 (1x1 through 6x6).
615 void Magick::Image::colorMatrix (const size_t order_,
616 const double *color_matrix_)
621 ExceptionInfo exceptionInfo;
622 GetExceptionInfo( &exceptionInfo );
623 kernel_info=AcquireKernelInfo("1");
624 kernel_info->width=order_;
625 kernel_info->height=order_;
626 kernel_info->values=(double *) color_matrix_;
627 MagickCore::Image* newImage =
628 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
629 kernel_info->values=(double *) NULL;
630 kernel_info=DestroyKernelInfo(kernel_info);
631 replaceImage( newImage );
632 throwException( exceptionInfo );
633 (void) DestroyExceptionInfo( &exceptionInfo );
636 // Compare current image with another image
637 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
638 // in the current image. False is returned if the images are identical.
639 bool Magick::Image::compare ( const Image &reference_ )
642 Image ref = reference_;
644 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
647 // Composite two images
648 void Magick::Image::composite ( const Image &compositeImage_,
649 const ssize_t xOffset_,
650 const ssize_t yOffset_,
651 const CompositeOperator compose_ )
653 // Image supplied as compositeImage is composited with current image and
654 // results in updating current image.
657 CompositeImage( image(),
659 compositeImage_.constImage(),
662 throwImageException();
664 void Magick::Image::composite ( const Image &compositeImage_,
665 const Geometry &offset_,
666 const CompositeOperator compose_ )
670 ssize_t x = offset_.xOff();
671 ssize_t y = offset_.yOff();
672 size_t width = columns();
673 size_t height = rows();
675 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
679 CompositeImage( image(),
681 compositeImage_.constImage(),
683 throwImageException();
685 void Magick::Image::composite ( const Image &compositeImage_,
686 const GravityType gravity_,
687 const CompositeOperator compose_ )
691 RectangleInfo geometry;
693 SetGeometry(compositeImage_.constImage(), &geometry);
694 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
696 CompositeImage( image(),
698 compositeImage_.constImage(),
699 geometry.x, geometry.y );
700 throwImageException();
704 void Magick::Image::contrast ( const size_t sharpen_ )
707 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
708 throwImageException();
711 // Convolve image. Applies a general image convolution kernel to the image.
712 // order_ represents the number of columns and rows in the filter kernel.
713 // kernel_ is an array of doubles representing the convolution kernel.
714 void Magick::Image::convolve ( const size_t order_,
715 const double *kernel_ )
717 ExceptionInfo exceptionInfo;
718 GetExceptionInfo( &exceptionInfo );
719 MagickCore::Image* newImage =
720 ConvolveImage ( image(), order_,
721 kernel_, &exceptionInfo );
722 replaceImage( newImage );
723 throwException( exceptionInfo );
724 (void) DestroyExceptionInfo( &exceptionInfo );
728 void Magick::Image::crop ( const Geometry &geometry_ )
730 RectangleInfo cropInfo = geometry_;
731 ExceptionInfo exceptionInfo;
732 GetExceptionInfo( &exceptionInfo );
733 MagickCore::Image* newImage =
737 replaceImage( newImage );
738 throwException( exceptionInfo );
739 (void) DestroyExceptionInfo( &exceptionInfo );
743 void Magick::Image::cycleColormap ( const ssize_t amount_ )
746 CycleColormapImage( image(), amount_ );
747 throwImageException();
751 void Magick::Image::despeckle ( void )
753 ExceptionInfo exceptionInfo;
754 GetExceptionInfo( &exceptionInfo );
755 MagickCore::Image* newImage =
756 DespeckleImage( image(), &exceptionInfo );
757 replaceImage( newImage );
758 throwException( exceptionInfo );
759 (void) DestroyExceptionInfo( &exceptionInfo );
763 void Magick::Image::display( void )
765 DisplayImages( imageInfo(), image() );
768 // Distort image. distorts an image using various distortion methods, by
769 // mapping color lookups of the source image to a new destination image
770 // usally of the same size as the source image, unless 'bestfit' is set to
772 void Magick::Image::distort ( const DistortImageMethod method_,
773 const size_t number_arguments_,
774 const double *arguments_,
775 const bool bestfit_ )
777 ExceptionInfo exceptionInfo;
778 GetExceptionInfo( &exceptionInfo );
779 MagickCore::Image* newImage = DistortImage ( image(), method_,
780 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
782 replaceImage( newImage );
783 throwException( exceptionInfo );
784 (void) DestroyExceptionInfo( &exceptionInfo );
787 // Draw on image using single drawable
788 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
792 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
796 drawable_.operator()(wand);
798 if( constImage()->exception.severity == UndefinedException)
801 wand=DestroyDrawingWand(wand);
804 throwImageException();
807 // Draw on image using a drawable list
808 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
812 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
816 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
817 p != drawable_.end(); p++ )
820 if( constImage()->exception.severity != UndefinedException)
824 if( constImage()->exception.severity == UndefinedException)
827 wand=DestroyDrawingWand(wand);
830 throwImageException();
833 // Hilight edges in image
834 void Magick::Image::edge ( const double radius_ )
836 ExceptionInfo exceptionInfo;
837 GetExceptionInfo( &exceptionInfo );
838 MagickCore::Image* newImage =
839 EdgeImage( image(), radius_, &exceptionInfo );
840 replaceImage( newImage );
841 throwException( exceptionInfo );
842 (void) DestroyExceptionInfo( &exceptionInfo );
845 // Emboss image (hilight edges)
846 void Magick::Image::emboss ( const double radius_, const double sigma_ )
848 ExceptionInfo exceptionInfo;
849 GetExceptionInfo( &exceptionInfo );
850 MagickCore::Image* newImage =
851 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
852 replaceImage( newImage );
853 throwException( exceptionInfo );
854 (void) DestroyExceptionInfo( &exceptionInfo );
857 // Enhance image (minimize noise)
858 void Magick::Image::enhance ( void )
860 ExceptionInfo exceptionInfo;
861 GetExceptionInfo( &exceptionInfo );
862 MagickCore::Image* newImage =
863 EnhanceImage( image(), &exceptionInfo );
864 replaceImage( newImage );
865 throwException( exceptionInfo );
866 (void) DestroyExceptionInfo( &exceptionInfo );
869 // Equalize image (histogram equalization)
870 void Magick::Image::equalize ( void )
873 EqualizeImage( image() );
874 throwImageException();
877 // Erase image to current "background color"
878 void Magick::Image::erase ( void )
881 SetImageBackgroundColor( image() );
882 throwImageException();
885 // Extends image as defined by the geometry.
887 void Magick::Image::extent ( const Geometry &geometry_ )
889 RectangleInfo extentInfo = geometry_;
891 ExceptionInfo exceptionInfo;
892 GetExceptionInfo( &exceptionInfo );
893 MagickCore::Image* newImage =
894 ExtentImage ( image(), &extentInfo, &exceptionInfo );
895 replaceImage( newImage );
896 throwException( exceptionInfo );
897 (void) DestroyExceptionInfo( &exceptionInfo );
899 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
901 backgroundColor ( backgroundColor_ );
902 extent ( geometry_ );
904 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
906 image()->gravity = gravity_;
907 extent ( geometry_ );
909 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
911 image()->gravity = gravity_;
912 backgroundColor ( backgroundColor_ );
913 extent ( geometry_ );
916 // Flip image (reflect each scanline in the vertical direction)
917 void Magick::Image::flip ( void )
919 ExceptionInfo exceptionInfo;
920 GetExceptionInfo( &exceptionInfo );
921 MagickCore::Image* newImage =
922 FlipImage( image(), &exceptionInfo );
923 replaceImage( newImage );
924 throwException( exceptionInfo );
925 (void) DestroyExceptionInfo( &exceptionInfo );
928 // Flood-fill color across pixels that match the color of the
929 // target pixel and are neighbors of the target pixel.
930 // Uses current fuzz setting when determining color match.
931 void Magick::Image::floodFillColor( const ssize_t x_,
933 const Magick::Color &fillColor_ )
935 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
937 void Magick::Image::floodFillColor( const Geometry &point_,
938 const Magick::Color &fillColor_ )
940 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
943 // Flood-fill color across pixels starting at target-pixel and
944 // stopping at pixels matching specified border color.
945 // Uses current fuzz setting when determining color match.
946 void Magick::Image::floodFillColor( const ssize_t x_,
948 const Magick::Color &fillColor_,
949 const Magick::Color &borderColor_ )
951 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
954 void Magick::Image::floodFillColor( const Geometry &point_,
955 const Magick::Color &fillColor_,
956 const Magick::Color &borderColor_ )
958 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
962 // Floodfill pixels matching color (within fuzz factor) of target
963 // pixel(x,y) with replacement opacity value using method.
964 void Magick::Image::floodFillOpacity( const ssize_t x_,
966 const unsigned int opacity_,
967 const PaintMethod method_ )
970 MagickPixelPacket target;
971 GetMagickPixelPacket(image(),&target);
972 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
973 target.red=pixel.red;
974 target.green=pixel.green;
975 target.blue=pixel.blue;
976 target.opacity=opacity_;
977 FloodfillPaintImage ( image(),
979 options()->drawInfo(), // const DrawInfo *draw_info
981 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
982 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
983 throwImageException();
986 // Flood-fill texture across pixels that match the color of the
987 // target pixel and are neighbors of the target pixel.
988 // Uses current fuzz setting when determining color match.
989 void Magick::Image::floodFillTexture( const ssize_t x_,
991 const Magick::Image &texture_ )
995 // Set drawing pattern
996 options()->fillPattern(texture_.constImage());
999 Pixels pixels(*this);
1001 PixelPacket *p = pixels.get(x_, y_, 1, 1 );
1002 MagickPixelPacket target;
1003 GetMagickPixelPacket(constImage(),&target);
1005 target.green=p->green;
1006 target.blue=p->blue;
1008 FloodfillPaintImage ( image(), // Image *image
1010 options()->drawInfo(), // const DrawInfo *draw_info
1011 &target, // const MagickPacket target
1012 static_cast<ssize_t>(x_), // const ssize_t x_offset
1013 static_cast<ssize_t>(y_), // const ssize_t y_offset
1014 MagickFalse // const PaintMethod method
1017 throwImageException();
1019 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1020 const Magick::Image &texture_ )
1022 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1025 // Flood-fill texture across pixels starting at target-pixel and
1026 // stopping at pixels matching specified border color.
1027 // Uses current fuzz setting when determining color match.
1028 void Magick::Image::floodFillTexture( const ssize_t x_,
1030 const Magick::Image &texture_,
1031 const Magick::Color &borderColor_ )
1035 // Set drawing fill pattern
1036 options()->fillPattern(texture_.constImage());
1038 MagickPixelPacket target;
1039 GetMagickPixelPacket(constImage(),&target);
1040 target.red=static_cast<PixelPacket>(borderColor_).red;
1041 target.green=static_cast<PixelPacket>(borderColor_).green;
1042 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1043 FloodfillPaintImage ( image(),
1045 options()->drawInfo(),
1047 static_cast<ssize_t>(x_),
1048 static_cast<ssize_t>(y_),
1051 throwImageException();
1053 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1054 const Magick::Image &texture_,
1055 const Magick::Color &borderColor_ )
1057 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1060 // Flop image (reflect each scanline in the horizontal direction)
1061 void Magick::Image::flop ( void )
1063 ExceptionInfo exceptionInfo;
1064 GetExceptionInfo( &exceptionInfo );
1065 MagickCore::Image* newImage =
1066 FlopImage( image(), &exceptionInfo );
1067 replaceImage( newImage );
1068 throwException( exceptionInfo );
1069 (void) DestroyExceptionInfo( &exceptionInfo );
1072 // Implements the discrete Fourier transform (DFT) of the image either as a
1073 // magnitude / phase or real / imaginary image pair.
1074 void Magick::Image::forwardFourierTransform ( void )
1076 ExceptionInfo exceptionInfo;
1077 GetExceptionInfo( &exceptionInfo );
1078 MagickCore::Image* newImage = ForwardFourierTransformImage ( image(),
1079 MagickTrue, &exceptionInfo );
1080 replaceImage( newImage );
1081 throwException( exceptionInfo );
1082 (void) DestroyExceptionInfo( &exceptionInfo );
1084 void Magick::Image::forwardFourierTransform ( const bool magnitude_ )
1086 ExceptionInfo exceptionInfo;
1087 GetExceptionInfo( &exceptionInfo );
1088 MagickCore::Image* newImage = ForwardFourierTransformImage ( image(),
1089 magnitude_ == true ? MagickTrue : MagickFalse, &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 FxImageChannel ( image(), DefaultChannels, 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 MagickCore::Image* newImage =
1153 FxImageChannel ( image(), channel, expression.c_str(), &exceptionInfo );
1154 replaceImage( newImage );
1155 throwException( exceptionInfo );
1156 (void) DestroyExceptionInfo( &exceptionInfo );
1159 // Gamma correct image
1160 void Magick::Image::gamma ( const double gamma_ )
1162 char gamma[MaxTextExtent + 1];
1163 FormatMagickString( gamma, MaxTextExtent, "%3.6f", gamma_);
1166 GammaImage ( image(), gamma );
1169 void Magick::Image::gamma ( const double gammaRed_,
1170 const double gammaGreen_,
1171 const double gammaBlue_ )
1173 char gamma[MaxTextExtent + 1];
1174 FormatMagickString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1175 gammaRed_, gammaGreen_, gammaBlue_);
1178 GammaImage ( image(), gamma );
1179 throwImageException();
1182 // Gaussian blur image
1183 // The number of neighbor pixels to be included in the convolution
1184 // mask is specified by 'width_'. The standard deviation of the
1185 // gaussian bell curve is specified by 'sigma_'.
1186 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1188 ExceptionInfo exceptionInfo;
1189 GetExceptionInfo( &exceptionInfo );
1190 MagickCore::Image* newImage =
1191 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1192 replaceImage( newImage );
1193 throwException( exceptionInfo );
1194 (void) DestroyExceptionInfo( &exceptionInfo );
1197 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1198 const double width_,
1199 const double sigma_ )
1201 ExceptionInfo exceptionInfo;
1202 GetExceptionInfo( &exceptionInfo );
1203 MagickCore::Image* newImage =
1204 GaussianBlurImageChannel( image(), channel_, width_, sigma_, &exceptionInfo );
1205 replaceImage( newImage );
1206 throwException( exceptionInfo );
1207 (void) DestroyExceptionInfo( &exceptionInfo );
1210 // Apply a color lookup table (Hald CLUT) to the image.
1211 void Magick::Image::haldClut ( const Image &clutImage_ )
1214 (void) HaldClutImage( image(), clutImage_.constImage() );
1215 throwImageException();
1219 void Magick::Image::implode ( const double factor_ )
1221 ExceptionInfo exceptionInfo;
1222 GetExceptionInfo( &exceptionInfo );
1223 MagickCore::Image* newImage =
1224 ImplodeImage( image(), factor_, &exceptionInfo );
1225 replaceImage( newImage );
1226 throwException( exceptionInfo );
1227 (void) DestroyExceptionInfo( &exceptionInfo );
1230 // implements the inverse discrete Fourier transform (IFT) of the image either
1231 // as a magnitude / phase or real / imaginary image pair.
1232 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1234 ExceptionInfo exceptionInfo;
1235 GetExceptionInfo( &exceptionInfo );
1236 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1237 phase_.constImage(), MagickTrue, &exceptionInfo);
1238 replaceImage( newImage );
1239 throwException( exceptionInfo );
1240 (void) DestroyExceptionInfo( &exceptionInfo );
1242 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1243 const bool magnitude_ )
1245 ExceptionInfo exceptionInfo;
1246 GetExceptionInfo( &exceptionInfo );
1247 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1248 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1250 replaceImage( newImage );
1251 throwException( exceptionInfo );
1252 (void) DestroyExceptionInfo( &exceptionInfo );
1255 // Level image. Adjust the levels of the image by scaling the colors
1256 // falling between specified white and black points to the full
1257 // available quantum range. The parameters provided represent the
1258 // black, mid (gamma), and white points. The black point specifies
1259 // the darkest color in the image. Colors darker than the black point
1260 // are set to zero. Mid point (gamma) specifies a gamma correction to
1261 // apply to the image. White point specifies the lightest color in the
1262 // image. Colors brighter than the white point are set to the maximum
1263 // quantum value. The black and white point have the valid range 0 to
1264 // QuantumRange while gamma has a useful range of 0 to ten.
1265 void Magick::Image::level ( const double black_point,
1266 const double white_point,
1267 const double gamma )
1270 char levels[MaxTextExtent];
1271 FormatMagickString( levels, MaxTextExtent, "%g,%g,%g",black_point,white_point,gamma);
1272 (void) LevelImage( image(), levels );
1273 throwImageException();
1276 // Level image channel. Adjust the levels of the image channel by
1277 // scaling the values falling between specified white and black points
1278 // to the full available quantum range. The parameters provided
1279 // represent the black, mid (gamma), and white points. The black
1280 // point specifies the darkest color in the image. Colors darker than
1281 // the black point are set to zero. Mid point (gamma) specifies a
1282 // gamma correction to apply to the image. White point specifies the
1283 // lightest color in the image. Colors brighter than the white point
1284 // are set to the maximum quantum value. The black and white point
1285 // have the valid range 0 to QuantumRange while gamma has a useful range of
1287 void Magick::Image::levelChannel ( const Magick::ChannelType channel,
1288 const double black_point,
1289 const double white_point,
1290 const double gamma )
1293 (void) LevelImageChannel( image(), channel, black_point, white_point,
1295 throwImageException();
1298 // Magnify image by integral size
1299 void Magick::Image::magnify ( void )
1301 ExceptionInfo exceptionInfo;
1302 GetExceptionInfo( &exceptionInfo );
1303 MagickCore::Image* newImage =
1304 MagnifyImage( image(), &exceptionInfo );
1305 replaceImage( newImage );
1306 throwException( exceptionInfo );
1307 (void) DestroyExceptionInfo( &exceptionInfo );
1310 // Remap image colors with closest color from reference image
1311 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1314 options()->quantizeDither( dither_ );
1315 RemapImage ( options()->quantizeInfo(), image(),
1316 mapImage_.constImage());
1317 throwImageException();
1319 // Floodfill designated area with replacement opacity value
1320 void Magick::Image::matteFloodfill ( const Color &target_ ,
1321 const unsigned int opacity_,
1322 const ssize_t x_, const ssize_t y_,
1323 const Magick::PaintMethod method_ )
1326 MagickPixelPacket target;
1327 GetMagickPixelPacket(constImage(),&target);
1328 target.red=static_cast<PixelPacket>(target_).red;
1329 target.green=static_cast<PixelPacket>(target_).green;
1330 target.blue=static_cast<PixelPacket>(target_).blue;
1331 target.opacity=opacity_;
1332 FloodfillPaintImage ( image(), OpacityChannel, options()->drawInfo(), &target,
1333 x_, y_, method_ == FloodfillMethod ? MagickFalse : MagickTrue);
1334 throwImageException();
1337 // Filter image by replacing each pixel component with the median
1338 // color in a circular neighborhood
1339 void Magick::Image::medianFilter ( const double radius_ )
1341 ExceptionInfo exceptionInfo;
1342 GetExceptionInfo( &exceptionInfo );
1343 MagickCore::Image* newImage =
1344 MedianFilterImage ( image(), radius_, &exceptionInfo );
1345 replaceImage( newImage );
1346 throwException( exceptionInfo );
1347 (void) DestroyExceptionInfo( &exceptionInfo );
1350 // Reduce image by integral size
1351 void Magick::Image::minify ( void )
1353 ExceptionInfo exceptionInfo;
1354 GetExceptionInfo( &exceptionInfo );
1355 MagickCore::Image* newImage =
1356 MinifyImage( image(), &exceptionInfo );
1357 replaceImage( newImage );
1358 throwException( exceptionInfo );
1359 (void) DestroyExceptionInfo( &exceptionInfo );
1362 // Modulate percent hue, saturation, and brightness of an image
1363 void Magick::Image::modulate ( const double brightness_,
1364 const double saturation_,
1367 char modulate[MaxTextExtent + 1];
1368 FormatMagickString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1369 brightness_, saturation_, hue_);
1372 ModulateImage( image(), modulate );
1373 throwImageException();
1376 // Motion blur image with specified blur factor
1377 // The radius_ parameter specifies the radius of the Gaussian, in
1378 // pixels, not counting the center pixel. The sigma_ parameter
1379 // specifies the standard deviation of the Laplacian, in pixels.
1380 // The angle_ parameter specifies the angle the object appears
1381 // to be comming from (zero degrees is from the right).
1382 void Magick::Image::motionBlur ( const double radius_,
1383 const double sigma_,
1384 const double angle_ )
1386 ExceptionInfo exceptionInfo;
1387 GetExceptionInfo( &exceptionInfo );
1388 MagickCore::Image* newImage =
1389 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1390 replaceImage( newImage );
1391 throwException( exceptionInfo );
1392 (void) DestroyExceptionInfo( &exceptionInfo );
1395 // Negate image. Set grayscale_ to true to effect grayscale values
1397 void Magick::Image::negate ( const bool grayscale_ )
1400 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
1401 throwImageException();
1405 void Magick::Image::normalize ( void )
1408 NormalizeImage ( image() );
1409 throwImageException();
1413 void Magick::Image::oilPaint ( const double radius_ )
1415 ExceptionInfo exceptionInfo;
1416 GetExceptionInfo( &exceptionInfo );
1417 MagickCore::Image* newImage =
1418 OilPaintImage( image(), radius_, &exceptionInfo );
1419 replaceImage( newImage );
1420 throwException( exceptionInfo );
1421 (void) DestroyExceptionInfo( &exceptionInfo );
1424 // Set or attenuate the opacity channel. If the image pixels are
1425 // opaque then they are set to the specified opacity value, otherwise
1426 // they are blended with the supplied opacity value. The value of
1427 // opacity_ ranges from 0 (completely opaque) to QuantumRange. The defines
1428 // OpaqueOpacity and TransparentOpacity are available to specify
1429 // completely opaque or completely transparent, respectively.
1430 void Magick::Image::opacity ( const unsigned int opacity_ )
1433 SetImageOpacity( image(), opacity_ );
1436 // Change the color of an opaque pixel to the pen color.
1437 void Magick::Image::opaque ( const Color &opaqueColor_,
1438 const Color &penColor_ )
1440 if ( !opaqueColor_.isValid() )
1442 throwExceptionExplicit( OptionError,
1443 "Opaque color argument is invalid" );
1445 if ( !penColor_.isValid() )
1447 throwExceptionExplicit( OptionError,
1448 "Pen color argument is invalid" );
1452 std::string opaqueColor = opaqueColor_;
1453 std::string penColor = penColor_;
1455 MagickPixelPacket opaque;
1456 MagickPixelPacket pen;
1457 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1458 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1459 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1460 throwImageException();
1463 // Ping is similar to read except only enough of the image is read to
1464 // determine the image columns, rows, and filesize. Access the
1465 // columns(), rows(), and fileSize() attributes after invoking ping.
1466 // The image data is not valid after calling ping.
1467 void Magick::Image::ping ( const std::string &imageSpec_ )
1469 options()->fileName( imageSpec_ );
1470 ExceptionInfo exceptionInfo;
1471 GetExceptionInfo( &exceptionInfo );
1472 MagickCore::Image* image =
1473 PingImage( imageInfo(), &exceptionInfo );
1474 replaceImage( image );
1475 throwException( exceptionInfo );
1476 (void) DestroyExceptionInfo( &exceptionInfo );
1479 // Ping is similar to read except only enough of the image is read
1480 // to determine the image columns, rows, and filesize. Access the
1481 // columns(), rows(), and fileSize() attributes after invoking
1482 // ping. The image data is not valid after calling ping.
1483 void Magick::Image::ping ( const Blob& blob_ )
1485 ExceptionInfo exceptionInfo;
1486 GetExceptionInfo( &exceptionInfo );
1487 MagickCore::Image* image =
1488 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1489 replaceImage( image );
1490 throwException( exceptionInfo );
1491 (void) DestroyExceptionInfo( &exceptionInfo );
1494 // Execute a named process module using an argc/argv syntax similar to
1495 // that accepted by a C 'main' routine. An exception is thrown if the
1496 // requested process module doesn't exist, fails to load, or fails during
1498 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1503 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1504 &image()->exception );
1506 if (status == false)
1507 throwException( image()->exception );
1510 // Quantize colors in image using current quantization settings
1511 // Set measureError_ to true in order to measure quantization error
1512 void Magick::Image::quantize ( const bool measureError_ )
1517 options()->quantizeInfo()->measure_error=MagickTrue;
1519 options()->quantizeInfo()->measure_error=MagickFalse;
1521 QuantizeImage( options()->quantizeInfo(), image() );
1523 throwImageException();
1526 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1527 void Magick::Image::quantumOperator ( const ChannelType channel_,
1528 const MagickEvaluateOperator operator_,
1531 ExceptionInfo exceptionInfo;
1532 GetExceptionInfo( &exceptionInfo );
1533 EvaluateImageChannel( image(), channel_, operator_, rvalue_, &exceptionInfo);
1534 throwException( exceptionInfo );
1535 (void) DestroyExceptionInfo( &exceptionInfo );
1538 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1539 const size_t columns_,
1541 const ChannelType channel_,
1542 const MagickEvaluateOperator operator_,
1543 const double rvalue_)
1545 ExceptionInfo exceptionInfo;
1546 GetExceptionInfo( &exceptionInfo );
1547 RectangleInfo geometry;
1548 geometry.width = columns_;
1549 geometry.height = rows_;
1552 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1554 EvaluateImageChannel( crop_image, channel_, operator_, rvalue_,
1556 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1557 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1558 crop_image = DestroyImageList(crop_image);
1559 throwException( exceptionInfo );
1560 (void) DestroyExceptionInfo( &exceptionInfo );
1563 // Raise image (lighten or darken the edges of an image to give a 3-D
1564 // raised or lowered effect)
1565 void Magick::Image::raise ( const Geometry &geometry_ ,
1566 const bool raisedFlag_ )
1568 RectangleInfo raiseInfo = geometry_;
1570 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1571 throwImageException();
1575 // Random threshold image.
1577 // Changes the value of individual pixels based on the intensity
1578 // of each pixel compared to a random threshold. The result is a
1579 // low-contrast, two color image. The thresholds_ argument is a
1580 // geometry containing LOWxHIGH thresholds. If the string
1581 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1582 // 3, or 4 will be performed instead. If a channel_ argument is
1583 // specified then only the specified channel is altered. This is
1584 // a very fast alternative to 'quantize' based dithering.
1585 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1587 randomThresholdChannel(thresholds_,DefaultChannels);
1589 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1590 const ChannelType channel_ )
1592 ExceptionInfo exceptionInfo;
1593 GetExceptionInfo( &exceptionInfo );
1595 (void) RandomThresholdImageChannel( image(),
1597 static_cast<std::string>(thresholds_).c_str(),
1599 throwImageException();
1600 (void) DestroyExceptionInfo( &exceptionInfo );
1603 // Read image into current object
1604 void Magick::Image::read ( const std::string &imageSpec_ )
1606 options()->fileName( imageSpec_ );
1608 ExceptionInfo exceptionInfo;
1609 GetExceptionInfo( &exceptionInfo );
1610 MagickCore::Image* image =
1611 ReadImage( imageInfo(), &exceptionInfo );
1613 // Ensure that multiple image frames were not read.
1614 if ( image && image->next )
1616 // Destroy any extra image frames
1617 MagickCore::Image* next = image->next;
1620 DestroyImageList( next );
1623 replaceImage( image );
1624 throwException( exceptionInfo );
1626 throwException( image->exception );
1627 (void) DestroyExceptionInfo( &exceptionInfo );
1630 // Read image of specified size into current object
1631 void Magick::Image::read ( const Geometry &size_,
1632 const std::string &imageSpec_ )
1638 // Read image from in-memory BLOB
1639 void Magick::Image::read ( const Blob &blob_ )
1641 ExceptionInfo exceptionInfo;
1642 GetExceptionInfo( &exceptionInfo );
1643 MagickCore::Image* image =
1644 BlobToImage( imageInfo(),
1645 static_cast<const void *>(blob_.data()),
1646 blob_.length(), &exceptionInfo );
1647 replaceImage( image );
1648 throwException( exceptionInfo );
1650 throwException( image->exception );
1651 (void) DestroyExceptionInfo( &exceptionInfo );
1654 // Read image of specified size from in-memory BLOB
1655 void Magick::Image::read ( const Blob &blob_,
1656 const Geometry &size_ )
1664 // Read image of specified size and depth from in-memory BLOB
1665 void Magick::Image::read ( const Blob &blob_,
1666 const Geometry &size_,
1667 const size_t depth_ )
1677 // Read image of specified size, depth, and format from in-memory BLOB
1678 void Magick::Image::read ( const Blob &blob_,
1679 const Geometry &size_,
1680 const size_t depth_,
1681 const std::string &magick_ )
1689 // Set explicit image format
1690 fileName( magick_ + ':');
1695 // Read image of specified size, and format from in-memory BLOB
1696 void Magick::Image::read ( const Blob &blob_,
1697 const Geometry &size_,
1698 const std::string &magick_ )
1704 // Set explicit image format
1705 fileName( magick_ + ':');
1710 // Read image based on raw pixels in memory (ConstituteImage)
1711 void Magick::Image::read ( const size_t width_,
1712 const size_t height_,
1713 const std::string &map_,
1714 const StorageType type_,
1715 const void *pixels_ )
1717 ExceptionInfo exceptionInfo;
1718 GetExceptionInfo( &exceptionInfo );
1719 MagickCore::Image* image =
1720 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1722 replaceImage( image );
1723 throwException( exceptionInfo );
1725 throwException( image->exception );
1726 (void) DestroyExceptionInfo( &exceptionInfo );
1729 // Reduce noise in image
1730 void Magick::Image::reduceNoise ( const double order_ )
1732 ExceptionInfo exceptionInfo;
1733 GetExceptionInfo( &exceptionInfo );
1734 MagickCore::Image* newImage =
1735 ReduceNoiseImage( image(), order_, &exceptionInfo );
1736 replaceImage( newImage );
1737 throwException( exceptionInfo );
1738 (void) DestroyExceptionInfo( &exceptionInfo );
1742 void Magick::Image::resize( const Geometry &geometry_ )
1744 // Calculate new size. This code should be supported using binary arguments
1745 // in the ImageMagick library.
1748 size_t width = columns();
1749 size_t height = rows();
1751 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1755 ExceptionInfo exceptionInfo;
1756 GetExceptionInfo( &exceptionInfo );
1757 MagickCore::Image* newImage =
1758 ResizeImage( image(),
1764 replaceImage( newImage );
1765 throwException( exceptionInfo );
1766 (void) DestroyExceptionInfo( &exceptionInfo );
1770 void Magick::Image::roll ( const Geometry &roll_ )
1772 ssize_t xOff = roll_.xOff();
1773 if ( roll_.xNegative() )
1775 ssize_t yOff = roll_.yOff();
1776 if ( roll_.yNegative() )
1779 ExceptionInfo exceptionInfo;
1780 GetExceptionInfo( &exceptionInfo );
1781 MagickCore::Image* newImage =
1782 RollImage( image(), xOff, yOff, &exceptionInfo );
1783 replaceImage( newImage );
1784 throwException( exceptionInfo );
1785 (void) DestroyExceptionInfo( &exceptionInfo );
1787 void Magick::Image::roll ( const size_t columns_,
1788 const size_t rows_ )
1790 ExceptionInfo exceptionInfo;
1791 GetExceptionInfo( &exceptionInfo );
1792 MagickCore::Image* newImage =
1794 static_cast<ssize_t>(columns_),
1795 static_cast<ssize_t>(rows_), &exceptionInfo );
1796 replaceImage( newImage );
1797 throwException( exceptionInfo );
1798 (void) DestroyExceptionInfo( &exceptionInfo );
1802 void Magick::Image::rotate ( const double degrees_ )
1804 ExceptionInfo exceptionInfo;
1805 GetExceptionInfo( &exceptionInfo );
1806 MagickCore::Image* newImage =
1807 RotateImage( image(), degrees_, &exceptionInfo);
1808 replaceImage( newImage );
1809 throwException( exceptionInfo );
1810 (void) DestroyExceptionInfo( &exceptionInfo );
1814 void Magick::Image::sample ( const Geometry &geometry_ )
1818 size_t width = columns();
1819 size_t height = rows();
1821 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1825 ExceptionInfo exceptionInfo;
1826 GetExceptionInfo( &exceptionInfo );
1827 MagickCore::Image* newImage =
1828 SampleImage( image(), width, height, &exceptionInfo );
1829 replaceImage( newImage );
1830 throwException( exceptionInfo );
1831 (void) DestroyExceptionInfo( &exceptionInfo );
1835 void Magick::Image::scale ( const Geometry &geometry_ )
1839 size_t width = columns();
1840 size_t height = rows();
1842 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1846 ExceptionInfo exceptionInfo;
1847 GetExceptionInfo( &exceptionInfo );
1848 MagickCore::Image* newImage =
1849 ScaleImage( image(), width, height, &exceptionInfo );
1850 replaceImage( newImage );
1851 throwException( exceptionInfo );
1852 (void) DestroyExceptionInfo( &exceptionInfo );
1855 // Segment (coalesce similar image components) by analyzing the
1856 // histograms of the color components and identifying units that are
1857 // homogeneous with the fuzzy c-means technique.
1858 void Magick::Image::segment ( const double clusterThreshold_,
1859 const double smoothingThreshold_ )
1862 SegmentImage ( image(),
1863 options()->quantizeColorSpace(),
1864 (MagickBooleanType) options()->verbose(),
1866 smoothingThreshold_ );
1867 throwImageException();
1868 SyncImage( image() );
1869 throwImageException();
1872 // Shade image using distant light source
1873 void Magick::Image::shade ( const double azimuth_,
1874 const double elevation_,
1875 const bool colorShading_ )
1877 ExceptionInfo exceptionInfo;
1878 GetExceptionInfo( &exceptionInfo );
1879 MagickCore::Image* newImage =
1880 ShadeImage( image(),
1881 colorShading_ == true ? MagickTrue : MagickFalse,
1885 replaceImage( newImage );
1886 throwException( exceptionInfo );
1887 (void) DestroyExceptionInfo( &exceptionInfo );
1890 // Sharpen pixels in image
1891 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1893 ExceptionInfo exceptionInfo;
1894 GetExceptionInfo( &exceptionInfo );
1895 MagickCore::Image* newImage =
1896 SharpenImage( image(),
1900 replaceImage( newImage );
1901 throwException( exceptionInfo );
1902 (void) DestroyExceptionInfo( &exceptionInfo );
1905 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1906 const double radius_, const double sigma_ )
1908 ExceptionInfo exceptionInfo;
1909 GetExceptionInfo( &exceptionInfo );
1910 MagickCore::Image* newImage =
1911 SharpenImageChannel( image(),
1916 replaceImage( newImage );
1917 throwException( exceptionInfo );
1918 (void) DestroyExceptionInfo( &exceptionInfo );
1921 // Shave pixels from image edges.
1922 void Magick::Image::shave ( const Geometry &geometry_ )
1924 RectangleInfo shaveInfo = geometry_;
1925 ExceptionInfo exceptionInfo;
1926 GetExceptionInfo( &exceptionInfo );
1927 MagickCore::Image* newImage =
1928 ShaveImage( image(),
1931 replaceImage( newImage );
1932 throwException( exceptionInfo );
1933 (void) DestroyExceptionInfo( &exceptionInfo );
1937 void Magick::Image::shear ( const double xShearAngle_,
1938 const double yShearAngle_ )
1940 ExceptionInfo exceptionInfo;
1941 GetExceptionInfo( &exceptionInfo );
1942 MagickCore::Image* newImage =
1943 ShearImage( image(),
1947 replaceImage( newImage );
1948 throwException( exceptionInfo );
1949 (void) DestroyExceptionInfo( &exceptionInfo );
1953 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
1956 (void) SigmoidalContrastImageChannel( image(), DefaultChannels, (MagickBooleanType) sharpen_, contrast, midpoint );
1957 throwImageException();
1960 // Solarize image (similar to effect seen when exposing a photographic
1961 // film to light during the development process)
1962 void Magick::Image::solarize ( const double factor_ )
1965 SolarizeImage ( image(), factor_ );
1966 throwImageException();
1969 // Sparse color image, given a set of coordinates, interpolates the colors
1970 // found at those coordinates, across the whole image, using various methods.
1972 void Magick::Image::sparseColor ( const ChannelType channel,
1973 const SparseColorMethod method,
1974 const size_t number_arguments,
1975 const double *arguments )
1977 ExceptionInfo exceptionInfo;
1978 GetExceptionInfo( &exceptionInfo );
1979 MagickCore::Image* newImage = SparseColorImage ( image(), channel, method,
1980 number_arguments, arguments, &exceptionInfo );
1981 replaceImage( newImage );
1982 throwException( exceptionInfo );
1983 (void) DestroyExceptionInfo( &exceptionInfo );
1986 // Spread pixels randomly within image by specified ammount
1987 void Magick::Image::spread ( const size_t amount_ )
1989 ExceptionInfo exceptionInfo;
1990 GetExceptionInfo( &exceptionInfo );
1991 MagickCore::Image* newImage =
1992 SpreadImage( image(),
1995 replaceImage( newImage );
1996 throwException( exceptionInfo );
1997 (void) DestroyExceptionInfo( &exceptionInfo );
2000 // Add a digital watermark to the image (based on second image)
2001 void Magick::Image::stegano ( const Image &watermark_ )
2003 ExceptionInfo exceptionInfo;
2004 GetExceptionInfo( &exceptionInfo );
2005 MagickCore::Image* newImage =
2006 SteganoImage( image(),
2007 watermark_.constImage(),
2009 replaceImage( newImage );
2010 throwException( exceptionInfo );
2011 (void) DestroyExceptionInfo( &exceptionInfo );
2014 // Stereo image (left image is current image)
2015 void Magick::Image::stereo ( const Image &rightImage_ )
2017 ExceptionInfo exceptionInfo;
2018 GetExceptionInfo( &exceptionInfo );
2019 MagickCore::Image* newImage =
2020 StereoImage( image(),
2021 rightImage_.constImage(),
2023 replaceImage( newImage );
2024 throwException( exceptionInfo );
2025 (void) DestroyExceptionInfo( &exceptionInfo );
2029 void Magick::Image::swirl ( const double degrees_ )
2031 ExceptionInfo exceptionInfo;
2032 GetExceptionInfo( &exceptionInfo );
2033 MagickCore::Image* newImage =
2034 SwirlImage( image(), degrees_,
2036 replaceImage( newImage );
2037 throwException( exceptionInfo );
2038 (void) DestroyExceptionInfo( &exceptionInfo );
2042 void Magick::Image::texture ( const Image &texture_ )
2045 TextureImage( image(), texture_.constImage() );
2046 throwImageException();
2050 void Magick::Image::threshold ( const double threshold_ )
2053 BilevelImage( image(), threshold_ );
2054 throwImageException();
2057 // Transform image based on image geometry only
2058 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2061 TransformImage ( &(image()), 0,
2062 std::string(imageGeometry_).c_str() );
2063 throwImageException();
2065 // Transform image based on image and crop geometries
2066 void Magick::Image::transform ( const Geometry &imageGeometry_,
2067 const Geometry &cropGeometry_ )
2070 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2071 std::string(imageGeometry_).c_str() );
2072 throwImageException();
2075 // Add matte image to image, setting pixels matching color to transparent
2076 void Magick::Image::transparent ( const Color &color_ )
2078 if ( !color_.isValid() )
2080 throwExceptionExplicit( OptionError,
2081 "Color argument is invalid" );
2084 std::string color = color_;
2086 MagickPixelPacket target;
2087 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2089 TransparentPaintImage ( image(), &target, TransparentOpacity, MagickFalse );
2090 throwImageException();
2093 // Add matte image to image, setting pixels matching color to transparent
2094 void Magick::Image::transparentChroma(const Color &colorLow_,
2095 const Color &colorHigh_)
2097 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2099 throwExceptionExplicit( OptionError,
2100 "Color argument is invalid" );
2103 std::string colorLow = colorLow_;
2104 std::string colorHigh = colorHigh_;
2106 MagickPixelPacket targetLow;
2107 MagickPixelPacket targetHigh;
2108 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2109 &image()->exception);
2110 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2111 &image()->exception);
2113 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2114 TransparentOpacity, MagickFalse );
2115 throwImageException();
2119 // Trim edges that are the background color from the image
2120 void Magick::Image::trim ( void )
2122 ExceptionInfo exceptionInfo;
2123 GetExceptionInfo( &exceptionInfo );
2124 MagickCore::Image* newImage =
2125 TrimImage( image(), &exceptionInfo);
2126 replaceImage( newImage );
2127 throwException( exceptionInfo );
2128 (void) DestroyExceptionInfo( &exceptionInfo );
2131 // Replace image with a sharpened version of the original image
2132 // using the unsharp mask algorithm.
2134 // the radius of the Gaussian, in pixels, not counting the
2137 // the standard deviation of the Gaussian, in pixels.
2139 // the percentage of the difference between the original and
2140 // the blur image that is added back into the original.
2142 // the threshold in pixels needed to apply the diffence amount.
2143 void Magick::Image::unsharpmask ( const double radius_,
2144 const double sigma_,
2145 const double amount_,
2146 const double threshold_ )
2148 ExceptionInfo exceptionInfo;
2149 GetExceptionInfo( &exceptionInfo );
2150 MagickCore::Image* newImage =
2151 UnsharpMaskImage( image(),
2157 replaceImage( newImage );
2158 throwException( exceptionInfo );
2159 (void) DestroyExceptionInfo( &exceptionInfo );
2162 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2163 const double radius_,
2164 const double sigma_,
2165 const double amount_,
2166 const double threshold_ )
2168 ExceptionInfo exceptionInfo;
2169 GetExceptionInfo( &exceptionInfo );
2170 MagickCore::Image* newImage =
2171 UnsharpMaskImageChannel( image(),
2178 replaceImage( newImage );
2179 throwException( exceptionInfo );
2180 (void) DestroyExceptionInfo( &exceptionInfo );
2183 // Map image pixels to a sine wave
2184 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2186 ExceptionInfo exceptionInfo;
2187 GetExceptionInfo( &exceptionInfo );
2188 MagickCore::Image* newImage =
2193 replaceImage( newImage );
2194 throwException( exceptionInfo );
2195 (void) DestroyExceptionInfo( &exceptionInfo );
2198 // Write image to file
2199 void Magick::Image::write( const std::string &imageSpec_ )
2202 fileName( imageSpec_ );
2203 WriteImage( imageInfo(), image() );
2204 throwImageException();
2207 // Write image to in-memory BLOB
2208 void Magick::Image::write ( Blob *blob_ )
2211 size_t length = 2048; // Efficient size for small images
2212 ExceptionInfo exceptionInfo;
2213 GetExceptionInfo( &exceptionInfo );
2214 void* data = ImageToBlob( imageInfo(),
2218 throwException( exceptionInfo );
2219 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2220 throwImageException();
2221 (void) DestroyExceptionInfo( &exceptionInfo );
2223 void Magick::Image::write ( Blob *blob_,
2224 const std::string &magick_ )
2228 size_t length = 2048; // Efficient size for small images
2229 ExceptionInfo exceptionInfo;
2230 GetExceptionInfo( &exceptionInfo );
2231 void* data = ImageToBlob( imageInfo(),
2235 throwException( exceptionInfo );
2236 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2237 throwImageException();
2238 (void) DestroyExceptionInfo( &exceptionInfo );
2240 void Magick::Image::write ( Blob *blob_,
2241 const std::string &magick_,
2242 const size_t depth_ )
2247 size_t length = 2048; // Efficient size for small images
2248 ExceptionInfo exceptionInfo;
2249 GetExceptionInfo( &exceptionInfo );
2250 void* data = ImageToBlob( imageInfo(),
2254 throwException( exceptionInfo );
2255 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2256 throwImageException();
2257 (void) DestroyExceptionInfo( &exceptionInfo );
2260 // Write image to an array of pixels with storage type specified
2261 // by user (ExportImagePixels), e.g.
2262 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2263 void Magick::Image::write ( const ssize_t x_,
2265 const size_t columns_,
2267 const std::string &map_,
2268 const StorageType type_,
2271 ExceptionInfo exceptionInfo;
2272 GetExceptionInfo( &exceptionInfo );
2273 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2276 throwException( exceptionInfo );
2277 (void) DestroyExceptionInfo( &exceptionInfo );
2281 void Magick::Image::zoom( const Geometry &geometry_ )
2283 // Calculate new size. This code should be supported using binary arguments
2284 // in the ImageMagick library.
2287 size_t width = columns();
2288 size_t height = rows();
2290 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2294 ExceptionInfo exceptionInfo;
2295 GetExceptionInfo( &exceptionInfo );
2296 MagickCore::Image* newImage =
2301 replaceImage( newImage );
2302 throwException( exceptionInfo );
2303 (void) DestroyExceptionInfo( &exceptionInfo );
2307 * Methods for setting image attributes
2311 // Join images into a single multi-image file
2312 void Magick::Image::adjoin ( const bool flag_ )
2315 options()->adjoin( flag_ );
2317 bool Magick::Image::adjoin ( void ) const
2319 return constOptions()->adjoin();
2322 // Remove pixel aliasing
2323 void Magick::Image::antiAlias( const bool flag_ )
2326 options()->antiAlias( static_cast<size_t>(flag_) );
2328 bool Magick::Image::antiAlias( void )
2330 return static_cast<bool>( options()->antiAlias( ) );
2333 // Animation inter-frame delay
2334 void Magick::Image::animationDelay ( const size_t delay_ )
2337 image()->delay = delay_;
2339 size_t Magick::Image::animationDelay ( void ) const
2341 return constImage()->delay;
2344 // Number of iterations to play animation
2345 void Magick::Image::animationIterations ( const size_t iterations_ )
2348 image()->iterations = iterations_;
2350 size_t Magick::Image::animationIterations ( void ) const
2352 return constImage()->iterations;
2355 // Access/Update a named image attribute
2356 void Magick::Image::attribute ( const std::string name_,
2357 const std::string value_ )
2360 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2362 std::string Magick::Image::attribute ( const std::string name_ )
2364 const char *value = GetImageProperty( constImage(), name_.c_str() );
2367 return std::string( value );
2369 return std::string(); // Intentionally no exception
2373 void Magick::Image::backgroundColor ( const Color &color_ )
2377 if ( color_.isValid() )
2379 image()->background_color.red = color_.redQuantum();
2380 image()->background_color.green = color_.greenQuantum();
2381 image()->background_color.blue = color_.blueQuantum();
2382 image()->background_color.opacity = color_.alphaQuantum();
2386 image()->background_color.red = 0;
2387 image()->background_color.green = 0;
2388 image()->background_color.blue = 0;
2389 image()->background_color.opacity = OpaqueOpacity;
2392 options()->backgroundColor( color_ );
2394 Magick::Color Magick::Image::backgroundColor ( void ) const
2396 return constOptions()->backgroundColor( );
2399 // Background fill texture
2400 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2403 options()->backgroundTexture( backgroundTexture_ );
2405 std::string Magick::Image::backgroundTexture ( void ) const
2407 return constOptions()->backgroundTexture( );
2410 // Original image columns
2411 size_t Magick::Image::baseColumns ( void ) const
2413 return constImage()->magick_columns;
2416 // Original image name
2417 std::string Magick::Image::baseFilename ( void ) const
2419 return std::string(constImage()->magick_filename);
2422 // Original image rows
2423 size_t Magick::Image::baseRows ( void ) const
2425 return constImage()->magick_rows;
2429 void Magick::Image::borderColor ( const Color &color_ )
2433 if ( color_.isValid() )
2435 image()->border_color.red = color_.redQuantum();
2436 image()->border_color.green = color_.greenQuantum();
2437 image()->border_color.blue = color_.blueQuantum();
2438 image()->border_color.opacity = color_.alphaQuantum();
2442 image()->border_color.red = 0;
2443 image()->border_color.green = 0;
2444 image()->border_color.blue = 0;
2445 image()->border_color.opacity = OpaqueOpacity;
2448 options()->borderColor( color_ );
2450 Magick::Color Magick::Image::borderColor ( void ) const
2452 return constOptions()->borderColor( );
2455 // Return smallest bounding box enclosing non-border pixels. The
2456 // current fuzz value is used when discriminating between pixels.
2457 // This is the crop bounding box used by crop(Geometry(0,0));
2458 Magick::Geometry Magick::Image::boundingBox ( void ) const
2460 ExceptionInfo exceptionInfo;
2461 GetExceptionInfo( &exceptionInfo );
2462 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2463 throwException( exceptionInfo );
2464 (void) DestroyExceptionInfo( &exceptionInfo );
2465 return Geometry( bbox );
2468 // Text bounding-box base color
2469 void Magick::Image::boxColor ( const Color &boxColor_ )
2472 options()->boxColor( boxColor_ );
2474 Magick::Color Magick::Image::boxColor ( void ) const
2476 return constOptions()->boxColor( );
2479 // Pixel cache threshold. Once this threshold is exceeded, all
2480 // subsequent pixels cache operations are to/from disk.
2481 // This setting is shared by all Image objects.
2483 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2485 SetMagickResourceLimit( MemoryResource, threshold_ );
2488 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2491 image()->chromaticity.blue_primary.x = x_;
2492 image()->chromaticity.blue_primary.y = y_;
2494 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2496 *x_ = constImage()->chromaticity.blue_primary.x;
2497 *y_ = constImage()->chromaticity.blue_primary.y;
2500 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2503 image()->chromaticity.green_primary.x = x_;
2504 image()->chromaticity.green_primary.y = y_;
2506 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2508 *x_ = constImage()->chromaticity.green_primary.x;
2509 *y_ = constImage()->chromaticity.green_primary.y;
2512 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2515 image()->chromaticity.red_primary.x = x_;
2516 image()->chromaticity.red_primary.y = y_;
2518 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2520 *x_ = constImage()->chromaticity.red_primary.x;
2521 *y_ = constImage()->chromaticity.red_primary.y;
2524 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2527 image()->chromaticity.white_point.x = x_;
2528 image()->chromaticity.white_point.y = y_;
2530 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2532 *x_ = constImage()->chromaticity.white_point.x;
2533 *y_ = constImage()->chromaticity.white_point.y;
2536 // Set image storage class
2537 void Magick::Image::classType ( const ClassType class_ )
2539 if ( classType() == PseudoClass && class_ == DirectClass )
2541 // Use SyncImage to synchronize the DirectClass pixels with the
2542 // color map and then set to DirectClass type.
2544 SyncImage( image() );
2545 image()->colormap = (PixelPacket *)
2546 RelinquishMagickMemory( image()->colormap );
2547 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2551 if ( classType() == DirectClass && class_ == PseudoClass )
2553 // Quantize to create PseudoClass color map
2555 quantizeColors(MaxColormapSize);
2557 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2561 // Associate a clip mask with the image. The clip mask must be the
2562 // same dimensions as the image. Pass an invalid image to unset an
2563 // existing clip mask.
2564 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2568 if( clipMask_.isValid() )
2571 SetImageClipMask( image(), clipMask_.constImage() );
2575 // Unset existing clip mask
2576 SetImageClipMask( image(), 0 );
2579 Magick::Image Magick::Image::clipMask ( void ) const
2581 ExceptionInfo exceptionInfo;
2582 GetExceptionInfo( &exceptionInfo );
2583 MagickCore::Image* image =
2584 GetImageClipMask( constImage(), &exceptionInfo );
2585 throwException( exceptionInfo );
2586 (void) DestroyExceptionInfo( &exceptionInfo );
2587 return Magick::Image( image );
2590 void Magick::Image::colorFuzz ( const double fuzz_ )
2593 image()->fuzz = fuzz_;
2594 options()->colorFuzz( fuzz_ );
2596 double Magick::Image::colorFuzz ( void ) const
2598 return constOptions()->colorFuzz( );
2601 // Set color in colormap at index
2602 void Magick::Image::colorMap ( const size_t index_,
2603 const Color &color_ )
2605 MagickCore::Image* imageptr = image();
2607 if (index_ > (MaxColormapSize-1) )
2608 throwExceptionExplicit( OptionError,
2609 "Colormap index must be less than MaxColormapSize" );
2611 if ( !color_.isValid() )
2612 throwExceptionExplicit( OptionError,
2613 "Color argument is invalid");
2616 // Ensure that colormap size is large enough
2617 if ( colorMapSize() < (index_+1) )
2618 colorMapSize( index_ + 1 );
2620 // Set color at index in colormap
2621 (imageptr->colormap)[index_] = color_;
2623 // Return color in colormap at index
2624 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2626 const MagickCore::Image* imageptr = constImage();
2628 if ( !imageptr->colormap )
2629 throwExceptionExplicit( OptionError,
2630 "Image does not contain a colormap");
2632 if ( index_ > imageptr->colors-1 )
2633 throwExceptionExplicit( OptionError,
2634 "Index out of range");
2636 return Magick::Color( (imageptr->colormap)[index_] );
2639 // Colormap size (number of colormap entries)
2640 void Magick::Image::colorMapSize ( const size_t entries_ )
2642 if (entries_ >MaxColormapSize )
2643 throwExceptionExplicit( OptionError,
2644 "Colormap entries must not exceed MaxColormapSize" );
2648 MagickCore::Image* imageptr = image();
2650 if( !imageptr->colormap )
2652 // Allocate colormap
2653 imageptr->colormap =
2654 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2655 imageptr->colors = 0;
2657 else if ( entries_ > imageptr->colors )
2659 // Re-allocate colormap
2660 imageptr->colormap=(PixelPacket *)
2661 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2664 // Initialize any new colormap entries as all black
2666 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2667 (imageptr->colormap)[i] = black;
2669 imageptr->colors = entries_;
2671 size_t Magick::Image::colorMapSize ( void )
2673 const MagickCore::Image* imageptr = constImage();
2675 if ( !imageptr->colormap )
2676 throwExceptionExplicit( OptionError,
2677 "Image does not contain a colormap");
2679 return imageptr->colors;
2683 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2686 if ( image()->colorspace == colorSpace_ )
2691 if ( colorSpace_ != RGBColorspace &&
2692 colorSpace_ != TransparentColorspace &&
2693 colorSpace_ != GRAYColorspace )
2695 if (image()->colorspace != RGBColorspace &&
2696 image()->colorspace != TransparentColorspace &&
2697 image()->colorspace != GRAYColorspace)
2699 /* Transform to RGB colorspace as intermediate step */
2700 TransformRGBImage( image(), image()->colorspace );
2701 throwImageException();
2703 /* Transform to final non-RGB colorspace */
2704 RGBTransformImage( image(), colorSpace_ );
2705 throwImageException();
2709 if ( colorSpace_ == RGBColorspace ||
2710 colorSpace_ == TransparentColorspace ||
2711 colorSpace_ == GRAYColorspace )
2713 /* Transform to a RGB-type colorspace */
2714 TransformRGBImage( image(), image()->colorspace );
2715 throwImageException();
2719 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2721 return constImage()->colorspace;
2724 // Set image colorspace type.
2725 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2728 options()->colorspaceType( colorSpace_ );
2730 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2732 return constOptions()->colorspaceType();
2737 void Magick::Image::comment ( const std::string &comment_ )
2740 SetImageProperty( image(), "Comment", NULL );
2741 if ( comment_.length() > 0 )
2742 SetImageProperty( image(), "Comment", comment_.c_str() );
2743 throwImageException();
2745 std::string Magick::Image::comment ( void ) const
2747 const char *value = GetImageProperty( constImage(), "Comment" );
2750 return std::string( value );
2752 return std::string(); // Intentionally no exception
2755 // Composition operator to be used when composition is implicitly used
2756 // (such as for image flattening).
2757 void Magick::Image::compose (const CompositeOperator compose_)
2759 image()->compose=compose_;
2762 Magick::CompositeOperator Magick::Image::compose ( void ) const
2764 return constImage()->compose;
2767 // Compression algorithm
2768 void Magick::Image::compressType ( const CompressionType compressType_ )
2771 image()->compression = compressType_;
2772 options()->compressType( compressType_ );
2774 Magick::CompressionType Magick::Image::compressType ( void ) const
2776 return constImage()->compression;
2779 // Enable printing of debug messages from ImageMagick
2780 void Magick::Image::debug ( const bool flag_ )
2783 options()->debug( flag_ );
2785 bool Magick::Image::debug ( void ) const
2787 return constOptions()->debug();
2790 // Tagged image format define (set/access coder-specific option) The
2791 // magick_ option specifies the coder the define applies to. The key_
2792 // option provides the key specific to that coder. The value_ option
2793 // provides the value to set (if any). See the defineSet() method if the
2794 // key must be removed entirely.
2795 void Magick::Image::defineValue ( const std::string &magick_,
2796 const std::string &key_,
2797 const std::string &value_ )
2800 std::string format = magick_ + ":" + key_;
2801 std::string option = value_;
2802 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2804 std::string Magick::Image::defineValue ( const std::string &magick_,
2805 const std::string &key_ ) const
2807 std::string definition = magick_ + ":" + key_;
2808 const char *option =
2809 GetImageOption ( constImageInfo(), definition.c_str() );
2811 return std::string( option );
2812 return std::string( );
2815 // Tagged image format define. Similar to the defineValue() method
2816 // except that passing the flag_ value 'true' creates a value-less
2817 // define with that format and key. Passing the flag_ value 'false'
2818 // removes any existing matching definition. The method returns 'true'
2819 // if a matching key exists, and 'false' if no matching key exists.
2820 void Magick::Image::defineSet ( const std::string &magick_,
2821 const std::string &key_,
2825 std::string definition = magick_ + ":" + key_;
2828 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2832 DeleteImageOption( imageInfo(), definition.c_str() );
2835 bool Magick::Image::defineSet ( const std::string &magick_,
2836 const std::string &key_ ) const
2838 std::string key = magick_ + ":" + key_;
2839 const char *option =
2840 GetImageOption ( constImageInfo(), key.c_str() );
2847 void Magick::Image::density ( const Geometry &density_ )
2850 options()->density( density_ );
2851 if ( density_.isValid() )
2853 image()->x_resolution = density_.width();
2854 if ( density_.height() != 0 )
2856 image()->y_resolution = density_.height();
2860 image()->y_resolution = density_.width();
2866 image()->x_resolution = 0;
2867 image()->y_resolution = 0;
2870 Magick::Geometry Magick::Image::density ( void ) const
2874 ssize_t x_resolution=72;
2875 ssize_t y_resolution=72;
2877 if (constImage()->x_resolution > 0.0)
2878 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
2880 if (constImage()->y_resolution > 0.0)
2881 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
2883 return Geometry(x_resolution,y_resolution);
2886 return constOptions()->density( );
2889 // Image depth (bits allocated to red/green/blue components)
2890 void Magick::Image::depth ( const size_t depth_ )
2892 size_t depth = depth_;
2894 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2895 depth=MAGICKCORE_QUANTUM_DEPTH;
2898 image()->depth=depth;
2899 options()->depth( depth );
2901 size_t Magick::Image::depth ( void ) const
2903 return constImage()->depth;
2906 std::string Magick::Image::directory ( void ) const
2908 if ( constImage()->directory )
2909 return std::string( constImage()->directory );
2911 throwExceptionExplicit( CorruptImageWarning,
2912 "Image does not contain a directory");
2914 return std::string();
2917 // Endianness (little like Intel or big like SPARC) for image
2918 // formats which support endian-specific options.
2919 void Magick::Image::endian ( const Magick::EndianType endian_ )
2922 options()->endian( endian_ );
2923 image()->endian = endian_;
2925 Magick::EndianType Magick::Image::endian ( void ) const
2927 return constImage()->endian;
2930 // EXIF profile (BLOB)
2931 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2934 if ( exifProfile_.data() != 0 )
2936 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2937 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2938 (void) SetImageProfile( image(), "exif", exif_profile);
2939 exif_profile =DestroyStringInfo( exif_profile );
2942 Magick::Blob Magick::Image::exifProfile( void ) const
2944 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2945 if ( exif_profile == (StringInfo *) NULL)
2946 return Blob( 0, 0 );
2947 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2951 void Magick::Image::fileName ( const std::string &fileName_ )
2955 fileName_.copy( image()->filename,
2956 sizeof(image()->filename) - 1 );
2957 image()->filename[ fileName_.length() ] = 0; // Null terminate
2959 options()->fileName( fileName_ );
2962 std::string Magick::Image::fileName ( void ) const
2964 return constOptions()->fileName( );
2968 off_t Magick::Image::fileSize ( void ) const
2970 return (off_t) GetBlobSize( constImage() );
2973 // Color to use when drawing inside an object
2974 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2977 options()->fillColor(fillColor_);
2979 Magick::Color Magick::Image::fillColor ( void ) const
2981 return constOptions()->fillColor();
2984 // Rule to use when filling drawn objects
2985 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2988 options()->fillRule(fillRule_);
2990 Magick::FillRule Magick::Image::fillRule ( void ) const
2992 return constOptions()->fillRule();
2995 // Pattern to use while filling drawn objects.
2996 void Magick::Image::fillPattern ( const Image &fillPattern_ )
2999 if(fillPattern_.isValid())
3000 options()->fillPattern( fillPattern_.constImage() );
3002 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3004 Magick::Image Magick::Image::fillPattern ( void ) const
3006 // FIXME: This is inordinately innefficient
3009 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3013 ExceptionInfo exceptionInfo;
3014 GetExceptionInfo( &exceptionInfo );
3015 MagickCore::Image* image =
3016 CloneImage( tmpTexture,
3019 MagickTrue, // orphan
3021 texture.replaceImage( image );
3022 throwException( exceptionInfo );
3023 (void) DestroyExceptionInfo( &exceptionInfo );
3028 // Filter used by zoom
3029 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3032 image()->filter = filterType_;
3034 Magick::FilterTypes Magick::Image::filterType ( void ) const
3036 return constImage()->filter;
3040 void Magick::Image::font ( const std::string &font_ )
3043 options()->font( font_ );
3045 std::string Magick::Image::font ( void ) const
3047 return constOptions()->font( );
3051 void Magick::Image::fontPointsize ( const double pointSize_ )
3054 options()->fontPointsize( pointSize_ );
3056 double Magick::Image::fontPointsize ( void ) const
3058 return constOptions()->fontPointsize( );
3061 // Font type metrics
3062 void Magick::Image::fontTypeMetrics( const std::string &text_,
3063 TypeMetric *metrics )
3065 DrawInfo *drawInfo = options()->drawInfo();
3066 drawInfo->text = const_cast<char *>(text_.c_str());
3067 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3071 // Image format string
3072 std::string Magick::Image::format ( void ) const
3074 ExceptionInfo exceptionInfo;
3075 GetExceptionInfo( &exceptionInfo );
3076 const MagickInfo * magick_info
3077 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3078 throwException( exceptionInfo );
3079 (void) DestroyExceptionInfo( &exceptionInfo );
3081 if (( magick_info != 0 ) &&
3082 ( *magick_info->description != '\0' ))
3083 return std::string(magick_info->description);
3085 throwExceptionExplicit( CorruptImageWarning,
3086 "Unrecognized image magick type" );
3087 return std::string();
3091 double Magick::Image::gamma ( void ) const
3093 return constImage()->gamma;
3096 Magick::Geometry Magick::Image::geometry ( void ) const
3098 if ( constImage()->geometry )
3100 return Geometry(constImage()->geometry);
3103 throwExceptionExplicit( OptionWarning,
3104 "Image does not contain a geometry");
3109 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3112 image()->dispose = (DisposeType) disposeMethod_;
3114 size_t Magick::Image::gifDisposeMethod ( void ) const
3116 // FIXME: It would be better to return an enumeration
3117 return constImage()->dispose;
3120 // ICC ICM color profile (BLOB)
3121 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3123 profile("icm",colorProfile_);
3125 Magick::Blob Magick::Image::iccColorProfile( void ) const
3127 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3128 if ( color_profile == (StringInfo *) NULL)
3129 return Blob( 0, 0 );
3130 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3133 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3136 image()->interlace = interlace_;
3137 options()->interlaceType ( interlace_ );
3139 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3141 return constImage()->interlace;
3144 // IPTC profile (BLOB)
3145 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3148 if ( iptcProfile_.data() != 0 )
3150 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3151 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3152 (void) SetImageProfile( image(), "iptc", iptc_profile);
3153 iptc_profile =DestroyStringInfo( iptc_profile );
3156 Magick::Blob Magick::Image::iptcProfile( void ) const
3158 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3159 if ( iptc_profile == (StringInfo *) NULL)
3160 return Blob( 0, 0 );
3161 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3164 // Does object contain valid image?
3165 void Magick::Image::isValid ( const bool isValid_ )
3170 _imgRef = new ImageRef;
3172 else if ( !isValid() )
3174 // Construct with single-pixel black image to make
3175 // image valid. This is an obvious hack.
3176 size( Geometry(1,1) );
3177 read( "xc:#000000" );
3181 bool Magick::Image::isValid ( void ) const
3183 if ( rows() && columns() )
3190 void Magick::Image::label ( const std::string &label_ )
3193 SetImageProperty ( image(), "Label", NULL );
3194 if ( label_.length() > 0 )
3195 SetImageProperty ( image(), "Label", label_.c_str() );
3196 throwImageException();
3198 std::string Magick::Image::label ( void ) const
3200 const char *value = GetImageProperty( constImage(), "Label" );
3203 return std::string( value );
3205 return std::string();
3208 void Magick::Image::magick ( const std::string &magick_ )
3212 magick_.copy( image()->magick,
3213 sizeof(image()->magick) - 1 );
3214 image()->magick[ magick_.length() ] = 0;
3216 options()->magick( magick_ );
3218 std::string Magick::Image::magick ( void ) const
3220 if ( *(constImage()->magick) != '\0' )
3221 return std::string(constImage()->magick);
3223 return constOptions()->magick( );
3226 void Magick::Image::matte ( const bool matteFlag_ )
3230 // If matte channel is requested, but image doesn't already have a
3231 // matte channel, then create an opaque matte channel. Likewise, if
3232 // the image already has a matte channel but a matte channel is not
3233 // desired, then set the matte channel to opaque.
3234 if ((matteFlag_ && !constImage()->matte) ||
3235 (constImage()->matte && !matteFlag_))
3236 SetImageOpacity(image(),OpaqueOpacity);
3238 image()->matte = (MagickBooleanType) matteFlag_;
3240 bool Magick::Image::matte ( void ) const
3242 if ( constImage()->matte )
3248 void Magick::Image::matteColor ( const Color &matteColor_ )
3252 if ( matteColor_.isValid() )
3254 image()->matte_color.red = matteColor_.redQuantum();
3255 image()->matte_color.green = matteColor_.greenQuantum();
3256 image()->matte_color.blue = matteColor_.blueQuantum();
3257 image()->matte_color.opacity = matteColor_.alphaQuantum();
3259 options()->matteColor( matteColor_ );
3263 // Set to default matte color
3264 Color tmpColor( "#BDBDBD" );
3265 image()->matte_color.red = tmpColor.redQuantum();
3266 image()->matte_color.green = tmpColor.greenQuantum();
3267 image()->matte_color.blue = tmpColor.blueQuantum();
3268 image()->matte_color.opacity = tmpColor.alphaQuantum();
3270 options()->matteColor( tmpColor );
3273 Magick::Color Magick::Image::matteColor ( void ) const
3275 return Color( constImage()->matte_color.red,
3276 constImage()->matte_color.green,
3277 constImage()->matte_color.blue,
3278 constImage()->matte_color.opacity );
3281 double Magick::Image::meanErrorPerPixel ( void ) const
3283 return(constImage()->error.mean_error_per_pixel);
3286 // Image modulus depth (minimum number of bits required to support
3287 // red/green/blue components without loss of accuracy)
3288 void Magick::Image::modulusDepth ( const size_t depth_ )
3291 SetImageDepth( image(), depth_ );
3292 options()->depth( depth_ );
3294 size_t Magick::Image::modulusDepth ( void ) const
3296 ExceptionInfo exceptionInfo;
3297 GetExceptionInfo( &exceptionInfo );
3298 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3299 throwException( exceptionInfo );
3300 (void) DestroyExceptionInfo( &exceptionInfo );
3304 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3307 options()->monochrome( monochromeFlag_ );
3309 bool Magick::Image::monochrome ( void ) const
3311 return constOptions()->monochrome( );
3314 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3316 if ( constImage()->montage )
3317 return Magick::Geometry(constImage()->montage);
3319 throwExceptionExplicit( CorruptImageWarning,
3320 "Image does not contain a montage" );
3322 return Magick::Geometry();
3325 double Magick::Image::normalizedMaxError ( void ) const
3327 return(constImage()->error.normalized_maximum_error);
3330 double Magick::Image::normalizedMeanError ( void ) const
3332 return constImage()->error.normalized_mean_error;
3335 // Image orientation
3336 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3339 image()->orientation = orientation_;
3341 Magick::OrientationType Magick::Image::orientation ( void ) const
3343 return constImage()->orientation;
3346 void Magick::Image::penColor ( const Color &penColor_ )
3349 options()->fillColor(penColor_);
3350 options()->strokeColor(penColor_);
3352 Magick::Color Magick::Image::penColor ( void ) const
3354 return constOptions()->fillColor();
3357 void Magick::Image::penTexture ( const Image &penTexture_ )
3360 if(penTexture_.isValid())
3361 options()->fillPattern( penTexture_.constImage() );
3363 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3366 Magick::Image Magick::Image::penTexture ( void ) const
3368 // FIXME: This is inordinately innefficient
3371 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3375 ExceptionInfo exceptionInfo;
3376 GetExceptionInfo( &exceptionInfo );
3377 MagickCore::Image* image =
3378 CloneImage( tmpTexture,
3381 MagickTrue, // orphan
3383 texture.replaceImage( image );
3384 throwException( exceptionInfo );
3385 (void) DestroyExceptionInfo( &exceptionInfo );
3390 // Set the color of a pixel.
3391 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3392 const Color &color_ )
3394 // Test arguments to ensure they are within the image.
3395 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3396 throwExceptionExplicit( OptionError,
3397 "Access outside of image boundary" );
3401 // Set image to DirectClass
3402 classType( DirectClass );
3405 Pixels pixels(*this);
3407 *(pixels.get(x_, y_, 1, 1 )) = color_;
3408 // Tell ImageMagick that pixels have been updated
3414 // Get the color of a pixel
3415 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3416 const ssize_t y_ ) const
3418 ClassType storage_class;
3419 storage_class = classType();
3421 const PixelPacket* pixel = getConstPixels( x_, y_, 1, 1 );
3422 if ( storage_class == DirectClass )
3425 return Color( *pixel );
3429 if ( storage_class == PseudoClass )
3431 const IndexPacket* indexes = getConstIndexes();
3433 return colorMap( (size_t) *indexes );
3436 return Color(); // invalid
3439 // Preferred size and location of an image canvas.
3440 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3443 options()->page( pageSize_ );
3444 image()->page = pageSize_;
3446 Magick::Geometry Magick::Image::page ( void ) const
3448 return Geometry( constImage()->page.width,
3449 constImage()->page.height,
3450 AbsoluteValue(constImage()->page.x),
3451 AbsoluteValue(constImage()->page.y),
3452 constImage()->page.x < 0 ? true : false,
3453 constImage()->page.y < 0 ? true : false);
3456 // Add a named profile to an image or remove a named profile by
3457 // passing an empty Blob (use default Blob constructor).
3459 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3460 void Magick::Image::profile( const std::string name_,
3461 const Magick::Blob &profile_ )
3464 ssize_t result = ProfileImage( image(), name_.c_str(),
3465 (unsigned char *)profile_.data(),
3466 profile_.length(), MagickTrue);
3469 throwImageException();
3472 // Retrieve a named profile from the image.
3474 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3475 // an existing generic profile name.
3476 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3478 const MagickCore::Image* image = constImage();
3480 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3482 if ( profile != (StringInfo *) NULL)
3483 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3486 Image temp_image = *this;
3487 temp_image.write( &blob, name_ );
3491 void Magick::Image::quality ( const size_t quality_ )
3494 image()->quality = quality_;
3495 options()->quality( quality_ );
3497 size_t Magick::Image::quality ( void ) const
3499 return constImage()->quality;
3502 void Magick::Image::quantizeColors ( const size_t colors_ )
3505 options()->quantizeColors( colors_ );
3507 size_t Magick::Image::quantizeColors ( void ) const
3509 return constOptions()->quantizeColors( );
3512 void Magick::Image::quantizeColorSpace
3513 ( const Magick::ColorspaceType colorSpace_ )
3516 options()->quantizeColorSpace( colorSpace_ );
3518 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3520 return constOptions()->quantizeColorSpace( );
3523 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3526 options()->quantizeDither( ditherFlag_ );
3528 bool Magick::Image::quantizeDither ( void ) const
3530 return constOptions()->quantizeDither( );
3533 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3536 options()->quantizeTreeDepth( treeDepth_ );
3538 size_t Magick::Image::quantizeTreeDepth ( void ) const
3540 return constOptions()->quantizeTreeDepth( );
3543 void Magick::Image::renderingIntent
3544 ( const Magick::RenderingIntent renderingIntent_ )
3547 image()->rendering_intent = renderingIntent_;
3549 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3551 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3554 void Magick::Image::resolutionUnits
3555 ( const Magick::ResolutionType resolutionUnits_ )
3558 image()->units = resolutionUnits_;
3559 options()->resolutionUnits( resolutionUnits_ );
3561 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3563 return constOptions()->resolutionUnits( );
3566 void Magick::Image::scene ( const size_t scene_ )
3569 image()->scene = scene_;
3571 size_t Magick::Image::scene ( void ) const
3573 return constImage()->scene;
3576 std::string Magick::Image::signature ( const bool force_ ) const
3578 Lock( &_imgRef->_mutexLock );
3580 // Re-calculate image signature if necessary
3582 !GetImageProperty(constImage(), "Signature") ||
3583 constImage()->taint )
3585 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3588 const char *property = GetImageProperty(constImage(), "Signature");
3590 return std::string( property );
3593 void Magick::Image::size ( const Geometry &geometry_ )
3596 options()->size( geometry_ );
3597 image()->rows = geometry_.height();
3598 image()->columns = geometry_.width();
3600 Magick::Geometry Magick::Image::size ( void ) const
3602 return Magick::Geometry( constImage()->columns, constImage()->rows );
3606 void Magick::Image::splice( const Geometry &geometry_ )
3608 RectangleInfo spliceInfo = geometry_;
3609 ExceptionInfo exceptionInfo;
3610 GetExceptionInfo( &exceptionInfo );
3611 MagickCore::Image* newImage =
3612 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3613 replaceImage( newImage );
3614 throwException( exceptionInfo );
3615 (void) DestroyExceptionInfo( &exceptionInfo );
3618 // Obtain image statistics. Statistics are normalized to the range of
3619 // 0.0 to 1.0 and are output to the specified ImageStatistics
3621 void Magick::Image::statistics ( ImageStatistics *statistics ) const
3627 ExceptionInfo exceptionInfo;
3628 GetExceptionInfo( &exceptionInfo );
3629 (void) GetImageChannelRange(constImage(),RedChannel,&minimum,&maximum,
3631 statistics->red.minimum=minimum;
3632 statistics->red.maximum=maximum;
3633 (void) GetImageChannelMean(constImage(),RedChannel,
3634 &statistics->red.mean,&statistics->red.standard_deviation,&exceptionInfo);
3635 (void) GetImageChannelKurtosis(constImage(),RedChannel,
3636 &statistics->red.kurtosis,&statistics->red.skewness,&exceptionInfo);
3637 (void) GetImageChannelRange(constImage(),GreenChannel,&minimum,&maximum,
3639 statistics->green.minimum=minimum;
3640 statistics->green.maximum=maximum;
3641 (void) GetImageChannelMean(constImage(),GreenChannel,
3642 &statistics->green.mean,&statistics->green.standard_deviation,
3644 (void) GetImageChannelKurtosis(constImage(),GreenChannel,
3645 &statistics->green.kurtosis,&statistics->green.skewness,&exceptionInfo);
3646 (void) GetImageChannelRange(constImage(),BlueChannel,&minimum,&maximum,
3648 statistics->blue.minimum=minimum;
3649 statistics->blue.maximum=maximum;
3650 (void) GetImageChannelMean(constImage(),BlueChannel,
3651 &statistics->blue.mean,&statistics->blue.standard_deviation,&exceptionInfo);
3652 (void) GetImageChannelKurtosis(constImage(),BlueChannel,
3653 &statistics->blue.kurtosis,&statistics->blue.skewness,&exceptionInfo);
3654 (void) GetImageChannelRange(constImage(),OpacityChannel,&minimum,&maximum,
3656 statistics->opacity.minimum=minimum;
3657 statistics->opacity.maximum=maximum;
3658 (void) GetImageChannelMean(constImage(),OpacityChannel,
3659 &statistics->opacity.mean,&statistics->opacity.standard_deviation,
3661 (void) GetImageChannelKurtosis(constImage(),OpacityChannel,
3662 &statistics->opacity.kurtosis,&statistics->opacity.skewness,&exceptionInfo);
3663 throwException( exceptionInfo );
3664 (void) DestroyExceptionInfo( &exceptionInfo );
3667 // enabled/disable stroke anti-aliasing
3668 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3671 options()->strokeAntiAlias(flag_);
3673 bool Magick::Image::strokeAntiAlias ( void ) const
3675 return constOptions()->strokeAntiAlias();
3678 // Color to use when drawing object outlines
3679 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3682 options()->strokeColor(strokeColor_);
3684 Magick::Color Magick::Image::strokeColor ( void ) const
3686 return constOptions()->strokeColor();
3689 // dash pattern for drawing vector objects (default one)
3690 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3693 options()->strokeDashArray( strokeDashArray_ );
3696 const double* Magick::Image::strokeDashArray ( void ) const
3698 return constOptions()->strokeDashArray( );
3701 // dash offset for drawing vector objects (default one)
3702 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3705 options()->strokeDashOffset( strokeDashOffset_ );
3708 double Magick::Image::strokeDashOffset ( void ) const
3710 return constOptions()->strokeDashOffset( );
3713 // Specify the shape to be used at the end of open subpaths when they
3714 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3716 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3719 options()->strokeLineCap( lineCap_ );
3721 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3723 return constOptions()->strokeLineCap( );
3726 // Specify the shape to be used at the corners of paths (or other
3727 // vector shapes) when they are stroked. Values of LineJoin are
3728 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3729 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3732 options()->strokeLineJoin( lineJoin_ );
3734 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3736 return constOptions()->strokeLineJoin( );
3739 // Specify miter limit. When two line segments meet at a sharp angle
3740 // and miter joins have been specified for 'lineJoin', it is possible
3741 // for the miter to extend far beyond the thickness of the line
3742 // stroking the path. The miterLimit' imposes a limit on the ratio of
3743 // the miter length to the 'lineWidth'. The default value of this
3745 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3748 options()->strokeMiterLimit( strokeMiterLimit_ );
3750 size_t Magick::Image::strokeMiterLimit ( void ) const
3752 return constOptions()->strokeMiterLimit( );
3755 // Pattern to use while stroking drawn objects.
3756 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3759 if(strokePattern_.isValid())
3760 options()->strokePattern( strokePattern_.constImage() );
3762 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3764 Magick::Image Magick::Image::strokePattern ( void ) const
3766 // FIXME: This is inordinately innefficient
3769 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3773 ExceptionInfo exceptionInfo;
3774 GetExceptionInfo( &exceptionInfo );
3775 MagickCore::Image* image =
3776 CloneImage( tmpTexture,
3779 MagickTrue, // orphan
3781 throwException( exceptionInfo );
3782 (void) DestroyExceptionInfo( &exceptionInfo );
3783 texture.replaceImage( image );
3788 // Stroke width for drawing lines, circles, ellipses, etc.
3789 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3792 options()->strokeWidth( strokeWidth_ );
3794 double Magick::Image::strokeWidth ( void ) const
3796 return constOptions()->strokeWidth( );
3799 void Magick::Image::subImage ( const size_t subImage_ )
3802 options()->subImage( subImage_ );
3804 size_t Magick::Image::subImage ( void ) const
3806 return constOptions()->subImage( );
3809 void Magick::Image::subRange ( const size_t subRange_ )
3812 options()->subRange( subRange_ );
3814 size_t Magick::Image::subRange ( void ) const
3816 return constOptions()->subRange( );
3819 // Annotation text encoding (e.g. "UTF-16")
3820 void Magick::Image::textEncoding ( const std::string &encoding_ )
3823 options()->textEncoding( encoding_ );
3825 std::string Magick::Image::textEncoding ( void ) const
3827 return constOptions()->textEncoding( );
3830 void Magick::Image::tileName ( const std::string &tileName_ )
3833 options()->tileName( tileName_ );
3835 std::string Magick::Image::tileName ( void ) const
3837 return constOptions()->tileName( );
3840 size_t Magick::Image::totalColors ( void )
3842 ExceptionInfo exceptionInfo;
3843 GetExceptionInfo( &exceptionInfo );
3844 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3845 throwException( exceptionInfo );
3846 (void) DestroyExceptionInfo( &exceptionInfo );
3850 // Origin of coordinate system to use when annotating with text or drawing
3851 void Magick::Image::transformOrigin ( const double x_, const double y_ )
3854 options()->transformOrigin( x_, y_ );
3857 // Rotation to use when annotating with text or drawing
3858 void Magick::Image::transformRotation ( const double angle_ )
3861 options()->transformRotation( angle_ );
3864 // Reset transformation parameters to default
3865 void Magick::Image::transformReset ( void )
3868 options()->transformReset();
3871 // Scale to use when annotating with text or drawing
3872 void Magick::Image::transformScale ( const double sx_, const double sy_ )
3875 options()->transformScale( sx_, sy_ );
3878 // Skew to use in X axis when annotating with text or drawing
3879 void Magick::Image::transformSkewX ( const double skewx_ )
3882 options()->transformSkewX( skewx_ );
3885 // Skew to use in Y axis when annotating with text or drawing
3886 void Magick::Image::transformSkewY ( const double skewy_ )
3889 options()->transformSkewY( skewy_ );
3892 // Image representation type
3893 Magick::ImageType Magick::Image::type ( void ) const
3896 ExceptionInfo exceptionInfo;
3897 GetExceptionInfo( &exceptionInfo );
3898 ImageType image_type = constOptions()->type();
3899 if ( image_type == UndefinedType )
3900 image_type= GetImageType( constImage(), &exceptionInfo);
3901 throwException( exceptionInfo );
3902 (void) DestroyExceptionInfo( &exceptionInfo );
3905 void Magick::Image::type ( const Magick::ImageType type_)
3908 options()->type( type_ );
3909 SetImageType( image(), type_ );
3912 void Magick::Image::verbose ( const bool verboseFlag_ )
3915 options()->verbose( verboseFlag_ );
3917 bool Magick::Image::verbose ( void ) const
3919 return constOptions()->verbose( );
3922 void Magick::Image::view ( const std::string &view_ )
3925 options()->view( view_ );
3927 std::string Magick::Image::view ( void ) const
3929 return constOptions()->view( );
3932 // Virtual pixel method
3933 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3936 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3937 options()->virtualPixelMethod( virtual_pixel_method_ );
3939 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3941 return GetImageVirtualPixelMethod( constImage() );
3944 void Magick::Image::x11Display ( const std::string &display_ )
3947 options()->x11Display( display_ );
3949 std::string Magick::Image::x11Display ( void ) const
3951 return constOptions()->x11Display( );
3954 double Magick::Image::xResolution ( void ) const
3956 return constImage()->x_resolution;
3958 double Magick::Image::yResolution ( void ) const
3960 return constImage()->y_resolution;
3964 Magick::Image::Image( const Image & image_ )
3965 : _imgRef(image_._imgRef)
3967 Lock( &_imgRef->_mutexLock );
3969 // Increase reference count
3970 ++_imgRef->_refCount;
3973 // Assignment operator
3974 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3976 if( this != &image_ )
3979 Lock( &image_._imgRef->_mutexLock );
3980 ++image_._imgRef->_refCount;
3983 bool doDelete = false;
3985 Lock( &_imgRef->_mutexLock );
3986 if ( --_imgRef->_refCount == 0 )
3992 // Delete old image reference with associated image and options.
3996 // Use new image reference
3997 _imgRef = image_._imgRef;
4003 //////////////////////////////////////////////////////////////////////
4005 // Low-level Pixel Access Routines
4007 // Also see the Pixels class, which provides support for multiple
4008 // cache views. The low-level pixel access routines in the Image
4009 // class are provided in order to support backward compatability.
4011 //////////////////////////////////////////////////////////////////////
4013 // Transfers read-only pixels from the image to the pixel cache as
4014 // defined by the specified region
4015 const Magick::PixelPacket* Magick::Image::getConstPixels
4016 ( const ssize_t x_, const ssize_t y_,
4017 const size_t columns_,
4018 const size_t rows_ ) const
4020 ExceptionInfo exceptionInfo;
4021 GetExceptionInfo( &exceptionInfo );
4022 const PixelPacket* p = (*GetVirtualPixels)( constImage(),
4026 throwException( exceptionInfo );
4027 (void) DestroyExceptionInfo( &exceptionInfo );
4031 // Obtain read-only pixel indexes (valid for PseudoClass images)
4032 const Magick::IndexPacket* Magick::Image::getConstIndexes ( void ) const
4034 const Magick::IndexPacket* result = GetVirtualIndexQueue( constImage() );
4037 throwImageException();
4042 // Obtain image pixel indexes (valid for PseudoClass images)
4043 Magick::IndexPacket* Magick::Image::getIndexes ( void )
4045 Magick::IndexPacket* result = GetAuthenticIndexQueue( image() );
4048 throwImageException();
4053 // Transfers pixels from the image to the pixel cache as defined
4054 // by the specified region. Modified pixels may be subsequently
4055 // transferred back to the image via syncPixels.
4056 Magick::PixelPacket* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4057 const size_t columns_,
4058 const size_t rows_ )
4061 ExceptionInfo exceptionInfo;
4062 GetExceptionInfo( &exceptionInfo );
4063 PixelPacket* result = (*GetAuthenticPixels)( image(),
4065 columns_, rows_, &exceptionInfo );
4066 throwException( exceptionInfo );
4067 (void) DestroyExceptionInfo( &exceptionInfo );
4072 // Allocates a pixel cache region to store image pixels as defined
4073 // by the region rectangle. This area is subsequently transferred
4074 // from the pixel cache to the image via syncPixels.
4075 Magick::PixelPacket* Magick::Image::setPixels ( 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 PixelPacket* result = (*QueueAuthenticPixels)( image(),
4084 columns_, rows_, &exceptionInfo );
4085 throwException( exceptionInfo );
4086 (void) DestroyExceptionInfo( &exceptionInfo );
4091 // Transfers the image cache pixels to the image.
4092 void Magick::Image::syncPixels ( void )
4094 ExceptionInfo exceptionInfo;
4095 GetExceptionInfo( &exceptionInfo );
4096 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4097 throwException( exceptionInfo );
4098 (void) DestroyExceptionInfo( &exceptionInfo );
4101 // Transfers one or more pixel components from a buffer or file
4102 // into the image pixel cache of an image.
4103 // Used to support image decoders.
4104 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4105 const unsigned char *source_ )
4110 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4111 ExceptionInfo exceptionInfo;
4112 GetExceptionInfo( &exceptionInfo );
4113 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4114 quantum_,source_, &exceptionInfo);
4115 throwException( exceptionInfo );
4116 (void) DestroyExceptionInfo( &exceptionInfo );
4117 quantum_info=DestroyQuantumInfo(quantum_info);
4120 // Transfers one or more pixel components from the image pixel
4121 // cache to a buffer or file.
4122 // Used to support image encoders.
4123 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4124 unsigned char *destination_ )
4129 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4130 ExceptionInfo exceptionInfo;
4131 GetExceptionInfo( &exceptionInfo );
4132 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4133 quantum_,destination_, &exceptionInfo);
4134 quantum_info=DestroyQuantumInfo(quantum_info);
4135 throwException( exceptionInfo );
4136 (void) DestroyExceptionInfo( &exceptionInfo );
4139 /////////////////////////////////////////////////////////////////////
4141 // No end-user methods beyond this point
4143 /////////////////////////////////////////////////////////////////////
4147 // Construct using existing image and default options
4149 Magick::Image::Image ( MagickCore::Image* image_ )
4150 : _imgRef(new ImageRef( image_))
4154 // Get Magick::Options*
4155 Magick::Options* Magick::Image::options( void )
4157 return _imgRef->options();
4159 const Magick::Options* Magick::Image::constOptions( void ) const
4161 return _imgRef->options();
4164 // Get MagickCore::Image*
4165 MagickCore::Image*& Magick::Image::image( void )
4167 return _imgRef->image();
4169 const MagickCore::Image* Magick::Image::constImage( void ) const
4171 return _imgRef->image();
4175 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4177 return _imgRef->options()->imageInfo();
4179 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4181 return _imgRef->options()->imageInfo();
4184 // Get QuantizeInfo *
4185 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4187 return _imgRef->options()->quantizeInfo();
4189 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4191 return _imgRef->options()->quantizeInfo();
4195 // Replace current image
4197 MagickCore::Image * Magick::Image::replaceImage
4198 ( MagickCore::Image* replacement_ )
4200 MagickCore::Image* image;
4203 image = replacement_;
4205 image = AcquireImage(constImageInfo());
4208 Lock( &_imgRef->_mutexLock );
4210 if ( _imgRef->_refCount == 1 )
4212 // We own the image, just replace it, and de-register
4214 _imgRef->image(image);
4218 // We don't own the image, dereference and replace with copy
4219 --_imgRef->_refCount;
4220 _imgRef = new ImageRef( image, constOptions() );
4224 return _imgRef->_image;
4228 // Prepare to modify image or image options
4229 // Replace current image and options with copy if reference count > 1
4231 void Magick::Image::modifyImage( void )
4234 Lock( &_imgRef->_mutexLock );
4235 if ( _imgRef->_refCount == 1 )
4237 // De-register image and return
4243 ExceptionInfo exceptionInfo;
4244 GetExceptionInfo( &exceptionInfo );
4245 replaceImage( CloneImage( image(),
4248 MagickTrue, // orphan
4250 throwException( exceptionInfo );
4251 (void) DestroyExceptionInfo( &exceptionInfo );
4256 // Test for an ImageMagick reported error and throw exception if one
4257 // has been reported. Secretly resets image->exception back to default
4258 // state even though this method is const.
4260 void Magick::Image::throwImageException( void ) const
4262 // Throw C++ exception while resetting Image exception to default state
4263 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4266 // Register image with image registry or obtain registration id
4267 ssize_t Magick::Image::registerId( void )
4269 Lock( &_imgRef->_mutexLock );
4270 if( _imgRef->id() < 0 )
4272 char id[MaxTextExtent];
4273 ExceptionInfo exceptionInfo;
4274 GetExceptionInfo( &exceptionInfo );
4275 _imgRef->id(_imgRef->id()+1);
4276 sprintf(id,"%.20g\n",(double) _imgRef->id());
4277 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4278 throwException( exceptionInfo );
4279 (void) DestroyExceptionInfo( &exceptionInfo );
4281 return _imgRef->id();
4284 // Unregister image from image registry
4285 void Magick::Image::unregisterId( void )
4292 // Create a local wrapper around MagickCoreTerminus
4297 void MagickPlusPlusDestroyMagick(void);
4301 void Magick::MagickPlusPlusDestroyMagick(void)
4303 if (magick_initialized)
4305 magick_initialized=false;
4306 MagickCore::MagickCoreTerminus();
4310 // C library initialization routine
4311 void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4313 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4314 if (!magick_initialized)
4315 magick_initialized=true;
4319 // Cleanup class to ensure that ImageMagick singletons are destroyed
4320 // so as to avoid any resemblence to a memory leak (which seems to
4329 MagickCleanUp( void );
4330 ~MagickCleanUp( void );
4333 // The destructor for this object is invoked when the destructors for
4334 // static objects in this translation unit are invoked.
4335 static MagickCleanUp magickCleanUpGuard;
4338 Magick::MagickCleanUp::MagickCleanUp ( void )
4340 // Don't even think about invoking InitializeMagick here!
4343 Magick::MagickCleanUp::~MagickCleanUp ( void )
4345 MagickPlusPlusDestroyMagick();