1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Implementation of Image
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
16 #include "Magick++/Include.h"
20 #include "Magick++/Image.h"
21 #include "Magick++/Functions.h"
22 #include "Magick++/Pixels.h"
23 #include "Magick++/Options.h"
24 #include "Magick++/ImageRef.h"
26 #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
27 #define DegreesToRadians(x) (MagickPI*(x)/180.0)
29 MagickPPExport const char *Magick::borderGeometryDefault = "6x6+0+0";
30 MagickPPExport const char *Magick::frameGeometryDefault = "25x25+6+6";
31 MagickPPExport const char *Magick::raiseGeometryDefault = "6x6+0+0";
33 static bool magick_initialized=false;
36 // Explicit template instantiations
40 // Friend functions to compare Image objects
43 MagickPPExport int Magick::operator == ( const Magick::Image& left_,
44 const Magick::Image& right_ )
46 // If image pixels and signature are the same, then the image is identical
47 return ( ( left_.rows() == right_.rows() ) &&
48 ( left_.columns() == right_.columns() ) &&
49 ( left_.signature() == right_.signature() )
52 MagickPPExport int Magick::operator != ( const Magick::Image& left_,
53 const Magick::Image& right_ )
55 return ( ! (left_ == right_) );
57 MagickPPExport int Magick::operator > ( const Magick::Image& left_,
58 const Magick::Image& right_ )
60 return ( !( left_ < right_ ) && ( left_ != right_ ) );
62 MagickPPExport int Magick::operator < ( const Magick::Image& left_,
63 const Magick::Image& right_ )
65 // If image pixels are less, then image is smaller
66 return ( ( left_.rows() * left_.columns() ) <
67 ( right_.rows() * right_.columns() )
70 MagickPPExport int Magick::operator >= ( const Magick::Image& left_,
71 const Magick::Image& right_ )
73 return ( ( left_ > right_ ) || ( left_ == right_ ) );
75 MagickPPExport int Magick::operator <= ( const Magick::Image& left_,
76 const Magick::Image& right_ )
78 return ( ( left_ < right_ ) || ( left_ == right_ ) );
82 // Image object implementation
85 // Construct from image file or image specification
86 Magick::Image::Image( const std::string &imageSpec_ )
87 : _imgRef(new ImageRef)
91 // Initialize, Allocate and Read images
94 catch ( const Warning & /*warning_*/ )
96 // FIXME: need a way to report warnings in constructor
98 catch ( const Error & /*error_*/ )
106 // Construct a blank image canvas of specified size and color
107 Magick::Image::Image( const Geometry &size_,
108 const Color &color_ )
109 : _imgRef(new ImageRef)
111 // xc: prefix specifies an X11 color string
112 std::string imageSpec("xc:");
120 // Initialize, Allocate and Read images
123 catch ( const Warning & /*warning_*/ )
125 // FIXME: need a way to report warnings in constructor
127 catch ( const Error & /*error_*/ )
135 // Construct Image from in-memory BLOB
136 Magick::Image::Image ( const Blob &blob_ )
137 : _imgRef(new ImageRef)
141 // Initialize, Allocate and Read images
144 catch ( const Warning & /*warning_*/ )
146 // FIXME: need a way to report warnings in constructor
148 catch ( const Error & /*error_*/ )
156 // Construct Image of specified size from in-memory BLOB
157 Magick::Image::Image ( const Blob &blob_,
158 const Geometry &size_ )
159 : _imgRef(new ImageRef)
164 read( blob_, size_ );
166 catch ( const Warning & /*warning_*/ )
168 // FIXME: need a way to report warnings in constructor
170 catch ( const Error & /*error_*/ )
178 // Construct Image of specified size and depth from in-memory BLOB
179 Magick::Image::Image ( const Blob &blob_,
180 const Geometry &size_,
181 const size_t depth_ )
182 : _imgRef(new ImageRef)
187 read( blob_, size_, depth_ );
189 catch ( const Warning & /*warning_*/ )
191 // FIXME: need a way to report warnings in constructor
193 catch ( const Error & /*error_*/ )
201 // Construct Image of specified size, depth, and format from in-memory BLOB
202 Magick::Image::Image ( const Blob &blob_,
203 const Geometry &size_,
205 const std::string &magick_ )
206 : _imgRef(new ImageRef)
211 read( blob_, size_, depth_, magick_ );
213 catch ( const Warning & /*warning_*/ )
215 // FIXME: need a way to report warnings in constructor
217 catch ( const Error & /*error_*/ )
225 // Construct Image of specified size, and format from in-memory BLOB
226 Magick::Image::Image ( const Blob &blob_,
227 const Geometry &size_,
228 const std::string &magick_ )
229 : _imgRef(new ImageRef)
234 read( blob_, size_, magick_ );
236 catch ( const Warning & /*warning_*/ )
238 // FIXME: need a way to report warnings in constructor
240 catch ( const Error & /*error_*/ )
248 // Construct an image based on an array of raw pixels, of specified
249 // type and mapping, in memory
250 Magick::Image::Image ( const size_t width_,
251 const size_t height_,
252 const std::string &map_,
253 const StorageType type_,
254 const void *pixels_ )
255 : _imgRef(new ImageRef)
259 read( width_, height_, map_.c_str(), type_, pixels_ );
261 catch ( const Warning & /*warning_*/ )
263 // FIXME: need a way to report warnings in constructor
265 catch ( const Error & /*error_*/ )
273 // Default constructor
274 Magick::Image::Image( void )
275 : _imgRef(new ImageRef)
281 Magick::Image::~Image()
283 bool doDelete = false;
285 Lock( &_imgRef->_mutexLock );
286 if ( --_imgRef->_refCount == 0 )
297 // Adaptive-blur image
298 void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
300 ExceptionInfo exceptionInfo;
301 GetExceptionInfo( &exceptionInfo );
302 MagickCore::Image* newImage =
303 AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
304 replaceImage( newImage );
305 throwException( exceptionInfo );
306 (void) DestroyExceptionInfo( &exceptionInfo );
309 // Local adaptive threshold image
310 // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
311 // Width x height define the size of the pixel neighborhood
312 // offset = constant to subtract from pixel neighborhood mean
313 void Magick::Image::adaptiveThreshold ( const size_t width_,
314 const size_t height_,
315 const ssize_t offset_ )
317 ExceptionInfo exceptionInfo;
318 GetExceptionInfo( &exceptionInfo );
319 MagickCore::Image* newImage =
320 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
321 replaceImage( newImage );
322 throwException( exceptionInfo );
323 (void) DestroyExceptionInfo( &exceptionInfo );
326 // Add noise to image
327 void Magick::Image::addNoise( const NoiseType noiseType_ )
329 ExceptionInfo exceptionInfo;
330 GetExceptionInfo( &exceptionInfo );
331 MagickCore::Image* newImage =
332 AddNoiseImage ( image(),
335 replaceImage( newImage );
336 throwException( exceptionInfo );
337 (void) DestroyExceptionInfo( &exceptionInfo );
340 void Magick::Image::addNoiseChannel( const ChannelType channel_,
341 const NoiseType noiseType_ )
343 ExceptionInfo exceptionInfo;
344 GetExceptionInfo( &exceptionInfo );
345 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
346 MagickCore::Image* newImage =
347 AddNoiseImage ( image(),
350 (void) SetPixelChannelMapMask( image(), channel_mask );
351 replaceImage( newImage );
352 throwException( exceptionInfo );
353 (void) DestroyExceptionInfo( &exceptionInfo );
356 // Affine Transform image
357 void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
359 ExceptionInfo exceptionInfo;
360 GetExceptionInfo( &exceptionInfo );
362 AffineMatrix _affine;
363 _affine.sx = affine_.sx();
364 _affine.sy = affine_.sy();
365 _affine.rx = affine_.rx();
366 _affine.ry = affine_.ry();
367 _affine.tx = affine_.tx();
368 _affine.ty = affine_.ty();
370 MagickCore::Image* newImage =
371 AffineTransformImage( image(), &_affine, &exceptionInfo);
372 replaceImage( newImage );
373 throwException( exceptionInfo );
374 (void) DestroyExceptionInfo( &exceptionInfo );
377 // Annotate using specified text, and placement location
378 void Magick::Image::annotate ( const std::string &text_,
379 const Geometry &location_ )
381 annotate ( text_, location_, NorthWestGravity, 0.0 );
383 // Annotate using specified text, bounding area, and placement gravity
384 void Magick::Image::annotate ( const std::string &text_,
385 const Geometry &boundingArea_,
386 const GravityType gravity_ )
388 annotate ( text_, boundingArea_, gravity_, 0.0 );
390 // Annotate with text using specified text, bounding area, placement
391 // gravity, and rotation.
392 void Magick::Image::annotate ( const std::string &text_,
393 const Geometry &boundingArea_,
394 const GravityType gravity_,
395 const double degrees_ )
400 = options()->drawInfo();
402 drawInfo->text = const_cast<char *>(text_.c_str());
404 char boundingArea[MaxTextExtent];
406 drawInfo->geometry = 0;
407 if ( boundingArea_.isValid() ){
408 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
410 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
411 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
415 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
418 drawInfo->geometry = boundingArea;
421 drawInfo->gravity = gravity_;
423 AffineMatrix oaffine = drawInfo->affine;
424 if ( degrees_ != 0.0)
434 AffineMatrix current = drawInfo->affine;
435 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
436 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
437 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
438 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
440 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
441 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
442 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
443 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
444 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
448 ExceptionInfo exceptionInfo;
449 GetExceptionInfo( &exceptionInfo );
450 AnnotateImage( image(), drawInfo, &exceptionInfo );
452 // Restore original values
453 drawInfo->affine = oaffine;
455 drawInfo->geometry = 0;
457 throwException( exceptionInfo );
458 (void) DestroyExceptionInfo( &exceptionInfo );
460 // Annotate with text (bounding area is entire image) and placement gravity.
461 void Magick::Image::annotate ( const std::string &text_,
462 const GravityType gravity_ )
467 = options()->drawInfo();
469 drawInfo->text = const_cast<char *>(text_.c_str());
471 drawInfo->gravity = gravity_;
473 ExceptionInfo exceptionInfo;
474 GetExceptionInfo( &exceptionInfo );
475 AnnotateImage( image(), drawInfo, &exceptionInfo );
477 drawInfo->gravity = NorthWestGravity;
480 throwException( exceptionInfo );
481 (void) DestroyExceptionInfo( &exceptionInfo );
485 void Magick::Image::blur( const double radius_, const double sigma_ )
487 ExceptionInfo exceptionInfo;
488 GetExceptionInfo( &exceptionInfo );
489 MagickCore::Image* newImage =
490 BlurImage( image(), radius_, sigma_, &exceptionInfo);
491 replaceImage( newImage );
492 throwException( exceptionInfo );
493 (void) DestroyExceptionInfo( &exceptionInfo );
496 void Magick::Image::blurChannel( const ChannelType channel_,
497 const double radius_, const double sigma_ )
499 ExceptionInfo exceptionInfo;
500 GetExceptionInfo( &exceptionInfo );
501 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
502 MagickCore::Image* newImage =
503 BlurImage( image(), radius_, sigma_, &exceptionInfo);
504 (void) SetPixelChannelMapMask( image(), channel_mask );
505 replaceImage( newImage );
506 throwException( exceptionInfo );
507 (void) DestroyExceptionInfo( &exceptionInfo );
510 // Add border to image
511 // Only uses width & height
512 void Magick::Image::border( const Geometry &geometry_ )
514 RectangleInfo borderInfo = geometry_;
515 ExceptionInfo exceptionInfo;
516 GetExceptionInfo( &exceptionInfo );
517 MagickCore::Image* newImage =
518 BorderImage( image(), &borderInfo, image()->compose, &exceptionInfo);
519 replaceImage( newImage );
520 throwException( exceptionInfo );
521 (void) DestroyExceptionInfo( &exceptionInfo );
524 // Extract channel from image
525 void Magick::Image::channel ( const ChannelType channel_ )
528 ExceptionInfo exceptionInfo;
529 GetExceptionInfo( &exceptionInfo );
530 MagickCore::Image* newImage =
531 SeparateImage( image(), channel_, &exceptionInfo);
532 replaceImage( newImage );
533 throwException( exceptionInfo );
534 (void) DestroyExceptionInfo( &exceptionInfo );
537 // Set or obtain modulus channel depth
538 void Magick::Image::channelDepth ( const size_t depth_ )
541 ExceptionInfo exceptionInfo;
542 GetExceptionInfo( &exceptionInfo );
543 SetImageDepth( image(), depth_, &exceptionInfo);
544 throwException( exceptionInfo );
545 (void) DestroyExceptionInfo( &exceptionInfo );
547 size_t Magick::Image::channelDepth ( )
549 size_t channel_depth;
551 ExceptionInfo exceptionInfo;
552 GetExceptionInfo( &exceptionInfo );
553 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
554 throwException( exceptionInfo );
555 (void) DestroyExceptionInfo( &exceptionInfo );
556 return channel_depth;
560 // Charcoal-effect image
561 void Magick::Image::charcoal( const double radius_, const double sigma_ )
563 ExceptionInfo exceptionInfo;
564 GetExceptionInfo( &exceptionInfo );
565 MagickCore::Image* newImage =
566 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
567 replaceImage( newImage );
568 throwException( exceptionInfo );
569 (void) DestroyExceptionInfo( &exceptionInfo );
573 void Magick::Image::chop( const Geometry &geometry_ )
575 RectangleInfo chopInfo = geometry_;
576 ExceptionInfo exceptionInfo;
577 GetExceptionInfo( &exceptionInfo );
578 MagickCore::Image* newImage =
579 ChopImage( image(), &chopInfo, &exceptionInfo);
580 replaceImage( newImage );
581 throwException( exceptionInfo );
582 (void) DestroyExceptionInfo( &exceptionInfo );
585 // contains one or more color corrections and applies the correction to the
587 void Magick::Image::cdl ( const std::string &cdl_ )
590 ExceptionInfo exceptionInfo;
591 GetExceptionInfo( &exceptionInfo );
592 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
593 throwException( exceptionInfo );
594 (void) DestroyExceptionInfo( &exceptionInfo );
598 void Magick::Image::colorize ( const unsigned int alphaRed_,
599 const unsigned int alphaGreen_,
600 const unsigned int alphaBlue_,
601 const Color &penColor_ )
603 if ( !penColor_.isValid() )
605 throwExceptionExplicit( OptionError,
606 "Pen color argument is invalid");
609 char blend[MaxTextExtent];
610 FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
612 ExceptionInfo exceptionInfo;
613 GetExceptionInfo( &exceptionInfo );
615 GetPixelInfo(image(),&target);
616 PixelInfo pixel=static_cast<PixelInfo>(penColor_);
617 target.red=pixel.red;
618 target.green=pixel.green;
619 target.blue=pixel.blue;
620 target.alpha=pixel.alpha;
621 MagickCore::Image* newImage =
622 ColorizeImage ( image(), blend, &target, &exceptionInfo );
623 replaceImage( newImage );
624 throwException( exceptionInfo );
625 (void) DestroyExceptionInfo( &exceptionInfo );
627 void Magick::Image::colorize ( const unsigned int alpha_,
628 const Color &penColor_ )
630 colorize( alpha_, alpha_, alpha_, penColor_ );
633 // Apply a color matrix to the image channels. The user supplied
634 // matrix may be of order 1 to 6 (1x1 through 6x6).
635 void Magick::Image::colorMatrix (const size_t order_,
636 const double *color_matrix_)
641 ExceptionInfo exceptionInfo;
642 GetExceptionInfo( &exceptionInfo );
643 kernel_info=AcquireKernelInfo((const char *) NULL);
644 kernel_info->width=order_;
645 kernel_info->height=order_;
646 kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
647 order_*sizeof(*kernel_info->values));
648 if (kernel_info->values != (MagickRealType *) NULL)
650 for (ssize_t i=0; i < (order_*order_); i++)
651 kernel_info->values[i]=color_matrix_[i];
652 MagickCore::Image* newImage =
653 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
654 replaceImage( newImage );
656 kernel_info=DestroyKernelInfo(kernel_info);
657 throwException( exceptionInfo );
658 (void) DestroyExceptionInfo( &exceptionInfo );
661 // Compare current image with another image
662 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
663 // in the current image. False is returned if the images are identical.
664 bool Magick::Image::compare ( const Image &reference_ )
666 ExceptionInfo exceptionInfo;
667 GetExceptionInfo( &exceptionInfo );
669 Image ref = reference_;
672 static_cast<bool>(IsImagesEqual(image(), ref.image(), &exceptionInfo));
673 throwException( exceptionInfo );
674 (void) DestroyExceptionInfo( &exceptionInfo );
678 // Composite two images
679 void Magick::Image::composite ( const Image &compositeImage_,
680 const ssize_t xOffset_,
681 const ssize_t yOffset_,
682 const CompositeOperator compose_ )
684 // Image supplied as compositeImage is composited with current image and
685 // results in updating current image.
688 ExceptionInfo exceptionInfo;
689 GetExceptionInfo( &exceptionInfo );
690 CompositeImage( image(),
691 compositeImage_.constImage(),
692 compose_, MagickFalse,
694 yOffset_, &exceptionInfo );
695 throwException( exceptionInfo );
696 (void) DestroyExceptionInfo( &exceptionInfo );
698 void Magick::Image::composite ( const Image &compositeImage_,
699 const Geometry &offset_,
700 const CompositeOperator compose_ )
704 ssize_t x = offset_.xOff();
705 ssize_t y = offset_.yOff();
706 size_t width = columns();
707 size_t height = rows();
709 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
713 ExceptionInfo exceptionInfo;
714 GetExceptionInfo( &exceptionInfo );
715 CompositeImage( image(),
716 compositeImage_.constImage(),
717 compose_, MagickFalse,
718 x, y, &exceptionInfo );
719 throwException( exceptionInfo );
720 (void) DestroyExceptionInfo( &exceptionInfo );
722 void Magick::Image::composite ( const Image &compositeImage_,
723 const GravityType gravity_,
724 const CompositeOperator compose_ )
728 RectangleInfo geometry;
730 SetGeometry(compositeImage_.constImage(), &geometry);
731 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
733 ExceptionInfo exceptionInfo;
734 GetExceptionInfo( &exceptionInfo );
735 CompositeImage( image(),
736 compositeImage_.constImage(),
737 compose_, MagickFalse,
738 geometry.x, geometry.y, &exceptionInfo );
739 throwException( exceptionInfo );
740 (void) DestroyExceptionInfo( &exceptionInfo );
744 void Magick::Image::contrast ( const size_t sharpen_ )
747 ExceptionInfo exceptionInfo;
748 GetExceptionInfo( &exceptionInfo );
749 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
750 throwException( exceptionInfo );
751 (void) DestroyExceptionInfo( &exceptionInfo );
754 // Convolve image. Applies a general image convolution kernel to the image.
755 // order_ represents the number of columns and rows in the filter kernel.
756 // kernel_ is an array of doubles representing the convolution kernel.
757 void Magick::Image::convolve ( const size_t order_,
758 const double *kernel_ )
763 ExceptionInfo exceptionInfo;
764 GetExceptionInfo( &exceptionInfo );
765 kernel_info=AcquireKernelInfo((const char *) NULL);
766 kernel_info->width=order_;
767 kernel_info->height=order_;
768 kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
769 order_*sizeof(*kernel_info->values));
770 if (kernel_info->values != (MagickRealType *) NULL)
772 for (ssize_t i=0; i < (order_*order_); i++)
773 kernel_info->values[i]=kernel_[i];
774 MagickCore::Image* newImage =
775 ConvolveImage ( image(), kernel_info, &exceptionInfo );
776 replaceImage( newImage );
778 kernel_info=DestroyKernelInfo(kernel_info);
779 throwException( exceptionInfo );
780 (void) DestroyExceptionInfo( &exceptionInfo );
784 void Magick::Image::crop ( const Geometry &geometry_ )
786 RectangleInfo cropInfo = geometry_;
787 ExceptionInfo exceptionInfo;
788 GetExceptionInfo( &exceptionInfo );
789 MagickCore::Image* newImage =
793 replaceImage( newImage );
794 throwException( exceptionInfo );
795 (void) DestroyExceptionInfo( &exceptionInfo );
799 void Magick::Image::cycleColormap ( const ssize_t amount_ )
801 ExceptionInfo exceptionInfo;
802 GetExceptionInfo( &exceptionInfo );
804 CycleColormapImage( image(), amount_, &exceptionInfo );
805 throwException( exceptionInfo );
806 (void) DestroyExceptionInfo( &exceptionInfo );
810 void Magick::Image::despeckle ( void )
812 ExceptionInfo exceptionInfo;
813 GetExceptionInfo( &exceptionInfo );
814 MagickCore::Image* newImage =
815 DespeckleImage( image(), &exceptionInfo );
816 replaceImage( newImage );
817 throwException( exceptionInfo );
818 (void) DestroyExceptionInfo( &exceptionInfo );
822 void Magick::Image::display( void )
824 ExceptionInfo exceptionInfo;
825 GetExceptionInfo( &exceptionInfo );
826 DisplayImages( imageInfo(), image(), &exceptionInfo );
827 throwException( exceptionInfo );
828 (void) DestroyExceptionInfo( &exceptionInfo );
831 // Distort image. distorts an image using various distortion methods, by
832 // mapping color lookups of the source image to a new destination image
833 // usally of the same size as the source image, unless 'bestfit' is set to
835 void Magick::Image::distort ( const DistortImageMethod method_,
836 const size_t number_arguments_,
837 const double *arguments_,
838 const bool bestfit_ )
840 ExceptionInfo exceptionInfo;
841 GetExceptionInfo( &exceptionInfo );
842 MagickCore::Image* newImage = DistortImage ( image(), method_,
843 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
845 replaceImage( newImage );
846 throwException( exceptionInfo );
847 (void) DestroyExceptionInfo( &exceptionInfo );
850 // Draw on image using single drawable
851 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
855 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
859 drawable_.operator()(wand);
863 wand=DestroyDrawingWand(wand);
866 throwImageException();
869 // Draw on image using a drawable list
870 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
874 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
878 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
879 p != drawable_.end(); p++ )
886 wand=DestroyDrawingWand(wand);
889 throwImageException();
892 // Hilight edges in image
893 void Magick::Image::edge ( const double radius_, const double sigma_ )
895 ExceptionInfo exceptionInfo;
896 GetExceptionInfo( &exceptionInfo );
897 MagickCore::Image* newImage =
898 EdgeImage( image(), radius_, sigma_, &exceptionInfo );
899 replaceImage( newImage );
900 throwException( exceptionInfo );
901 (void) DestroyExceptionInfo( &exceptionInfo );
904 // Emboss image (hilight edges)
905 void Magick::Image::emboss ( const double radius_, const double sigma_ )
907 ExceptionInfo exceptionInfo;
908 GetExceptionInfo( &exceptionInfo );
909 MagickCore::Image* newImage =
910 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
911 replaceImage( newImage );
912 throwException( exceptionInfo );
913 (void) DestroyExceptionInfo( &exceptionInfo );
916 // Enhance image (minimize noise)
917 void Magick::Image::enhance ( void )
919 ExceptionInfo exceptionInfo;
920 GetExceptionInfo( &exceptionInfo );
921 MagickCore::Image* newImage =
922 EnhanceImage( image(), &exceptionInfo );
923 replaceImage( newImage );
924 throwException( exceptionInfo );
925 (void) DestroyExceptionInfo( &exceptionInfo );
928 // Equalize image (histogram equalization)
929 void Magick::Image::equalize ( void )
931 ExceptionInfo exceptionInfo;
932 GetExceptionInfo( &exceptionInfo );
934 EqualizeImage( image(), &exceptionInfo );
935 throwException( exceptionInfo );
936 (void) DestroyExceptionInfo( &exceptionInfo );
939 // Erase image to current "background color"
940 void Magick::Image::erase ( void )
943 ExceptionInfo exceptionInfo;
944 GetExceptionInfo( &exceptionInfo );
945 SetImageBackgroundColor( image(), &exceptionInfo );
946 throwException( exceptionInfo );
947 (void) DestroyExceptionInfo( &exceptionInfo );
950 // Extends image as defined by the geometry.
952 void Magick::Image::extent ( const Geometry &geometry_ )
954 RectangleInfo extentInfo = geometry_;
956 ExceptionInfo exceptionInfo;
957 GetExceptionInfo( &exceptionInfo );
958 MagickCore::Image* newImage =
959 ExtentImage ( image(), &extentInfo, &exceptionInfo );
960 replaceImage( newImage );
961 throwException( exceptionInfo );
962 (void) DestroyExceptionInfo( &exceptionInfo );
964 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
966 backgroundColor ( backgroundColor_ );
967 extent ( geometry_ );
969 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
971 RectangleInfo geometry;
973 SetGeometry(image(), &geometry);
974 GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry);
975 extent ( geometry_ );
977 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
979 image()->gravity = gravity_;
980 backgroundColor ( backgroundColor_ );
981 extent ( geometry_ );
984 // Flip image (reflect each scanline in the vertical direction)
985 void Magick::Image::flip ( void )
987 ExceptionInfo exceptionInfo;
988 GetExceptionInfo( &exceptionInfo );
989 MagickCore::Image* newImage =
990 FlipImage( image(), &exceptionInfo );
991 replaceImage( newImage );
992 throwException( exceptionInfo );
993 (void) DestroyExceptionInfo( &exceptionInfo );
996 // Flood-fill color across pixels that match the color of the
997 // target pixel and are neighbors of the target pixel.
998 // Uses current fuzz setting when determining color match.
999 void Magick::Image::floodFillColor( const ssize_t x_,
1001 const Magick::Color &fillColor_ )
1003 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
1005 void Magick::Image::floodFillColor( const Geometry &point_,
1006 const Magick::Color &fillColor_ )
1008 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
1011 // Flood-fill color across pixels starting at target-pixel and
1012 // stopping at pixels matching specified border color.
1013 // Uses current fuzz setting when determining color match.
1014 void Magick::Image::floodFillColor( const ssize_t x_,
1016 const Magick::Color &fillColor_,
1017 const Magick::Color &borderColor_ )
1019 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
1022 void Magick::Image::floodFillColor( const Geometry &point_,
1023 const Magick::Color &fillColor_,
1024 const Magick::Color &borderColor_ )
1026 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
1030 // Floodfill pixels matching color (within fuzz factor) of target
1031 // pixel(x,y) with replacement alpha value using method.
1032 void Magick::Image::floodFillAlpha( const ssize_t x_,
1034 const unsigned int alpha_,
1035 const PaintMethod method_ )
1039 GetPixelInfo(image(),&target);
1040 PixelInfo pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
1041 target.red=pixel.red;
1042 target.green=pixel.green;
1043 target.blue=pixel.blue;
1044 target.alpha=alpha_;
1045 ExceptionInfo exceptionInfo;
1046 GetExceptionInfo( &exceptionInfo );
1047 FloodfillPaintImage ( image(),
1048 options()->drawInfo(), // const DrawInfo *draw_info
1050 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
1051 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1053 throwException( exceptionInfo );
1054 (void) DestroyExceptionInfo( &exceptionInfo );
1057 // Flood-fill texture across pixels that match the color of the
1058 // target pixel and are neighbors of the target pixel.
1059 // Uses current fuzz setting when determining color match.
1060 void Magick::Image::floodFillTexture( const ssize_t x_,
1062 const Magick::Image &texture_ )
1066 // Set drawing pattern
1067 options()->fillPattern(texture_.constImage());
1070 Pixels pixels(*this);
1072 Quantum *p = pixels.get(x_, y_, 1, 1 );
1074 GetPixelInfo(constImage(),&target);
1075 target.red=GetPixelRed(constImage(),p);
1076 target.green=GetPixelGreen(constImage(),p);
1077 target.blue=GetPixelBlue(constImage(),p);
1078 ExceptionInfo exceptionInfo;
1079 GetExceptionInfo( &exceptionInfo );
1081 FloodfillPaintImage ( image(), // Image *image
1082 options()->drawInfo(), // const DrawInfo *draw_info
1083 &target, // const MagickPacket target
1084 static_cast<ssize_t>(x_), // const ssize_t x_offset
1085 static_cast<ssize_t>(y_), // const ssize_t y_offset
1086 MagickFalse, // const PaintMethod method
1088 throwException( exceptionInfo );
1089 (void) DestroyExceptionInfo( &exceptionInfo );
1092 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1093 const Magick::Image &texture_ )
1095 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1098 // Flood-fill texture across pixels starting at target-pixel and
1099 // stopping at pixels matching specified border color.
1100 // Uses current fuzz setting when determining color match.
1101 void Magick::Image::floodFillTexture( const ssize_t x_,
1103 const Magick::Image &texture_,
1104 const Magick::Color &borderColor_ )
1108 // Set drawing fill pattern
1109 options()->fillPattern(texture_.constImage());
1112 GetPixelInfo(constImage(),&target);
1113 target.red=static_cast<PixelInfo>(borderColor_).red;
1114 target.green=static_cast<PixelInfo>(borderColor_).green;
1115 target.blue=static_cast<PixelInfo>(borderColor_).blue;
1116 ExceptionInfo exceptionInfo;
1117 GetExceptionInfo( &exceptionInfo );
1118 FloodfillPaintImage ( image(),
1119 options()->drawInfo(),
1121 static_cast<ssize_t>(x_),
1122 static_cast<ssize_t>(y_),
1123 MagickTrue, &exceptionInfo);
1125 throwException( exceptionInfo );
1126 (void) DestroyExceptionInfo( &exceptionInfo );
1128 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1129 const Magick::Image &texture_,
1130 const Magick::Color &borderColor_ )
1132 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1135 // Flop image (reflect each scanline in the horizontal direction)
1136 void Magick::Image::flop ( void )
1138 ExceptionInfo exceptionInfo;
1139 GetExceptionInfo( &exceptionInfo );
1140 MagickCore::Image* newImage =
1141 FlopImage( image(), &exceptionInfo );
1142 replaceImage( newImage );
1143 throwException( exceptionInfo );
1144 (void) DestroyExceptionInfo( &exceptionInfo );
1148 void Magick::Image::frame ( const Geometry &geometry_ )
1152 info.x = static_cast<ssize_t>(geometry_.width());
1153 info.y = static_cast<ssize_t>(geometry_.height());
1154 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1155 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1156 info.outer_bevel = geometry_.xOff();
1157 info.inner_bevel = geometry_.yOff();
1159 ExceptionInfo exceptionInfo;
1160 GetExceptionInfo( &exceptionInfo );
1161 MagickCore::Image* newImage =
1162 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1163 replaceImage( newImage );
1164 throwException( exceptionInfo );
1165 (void) DestroyExceptionInfo( &exceptionInfo );
1167 void Magick::Image::frame ( const size_t width_,
1168 const size_t height_,
1169 const ssize_t outerBevel_, const ssize_t innerBevel_ )
1172 info.x = static_cast<ssize_t>(width_);
1173 info.y = static_cast<ssize_t>(height_);
1174 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1175 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1176 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1177 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1179 ExceptionInfo exceptionInfo;
1180 GetExceptionInfo( &exceptionInfo );
1181 MagickCore::Image* newImage =
1182 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1183 replaceImage( newImage );
1184 throwException( exceptionInfo );
1185 (void) DestroyExceptionInfo( &exceptionInfo );
1188 // Fx image. Applies a mathematical expression to the image.
1189 void Magick::Image::fx ( const std::string expression )
1191 ExceptionInfo exceptionInfo;
1192 GetExceptionInfo( &exceptionInfo );
1193 MagickCore::Image* newImage =
1194 FxImage ( image(), expression.c_str(), &exceptionInfo );
1195 replaceImage( newImage );
1196 throwException( exceptionInfo );
1197 (void) DestroyExceptionInfo( &exceptionInfo );
1199 void Magick::Image::fx ( const std::string expression,
1200 const Magick::ChannelType channel )
1202 ExceptionInfo exceptionInfo;
1203 GetExceptionInfo( &exceptionInfo );
1204 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
1205 MagickCore::Image* newImage =
1206 FxImage ( image(), expression.c_str(), &exceptionInfo );
1207 (void) SetPixelChannelMapMask( image(), channel_mask );
1208 replaceImage( newImage );
1209 throwException( exceptionInfo );
1210 (void) DestroyExceptionInfo( &exceptionInfo );
1213 // Gamma correct image
1214 void Magick::Image::gamma ( const double gamma_ )
1216 ExceptionInfo exceptionInfo;
1217 GetExceptionInfo( &exceptionInfo );
1219 GammaImage ( image(), gamma_, &exceptionInfo );
1220 throwException( exceptionInfo );
1221 (void) DestroyExceptionInfo( &exceptionInfo );
1224 void Magick::Image::gamma ( const double gammaRed_,
1225 const double gammaGreen_,
1226 const double gammaBlue_ )
1228 char gamma[MaxTextExtent + 1];
1229 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1230 gammaRed_, gammaGreen_, gammaBlue_);
1232 ExceptionInfo exceptionInfo;
1233 GetExceptionInfo( &exceptionInfo );
1235 GammaImage ( image(), atof(gamma), &exceptionInfo );
1236 throwException( exceptionInfo );
1237 (void) DestroyExceptionInfo( &exceptionInfo );
1240 // Gaussian blur image
1241 // The number of neighbor pixels to be included in the convolution
1242 // mask is specified by 'width_'. The standard deviation of the
1243 // gaussian bell curve is specified by 'sigma_'.
1244 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1246 ExceptionInfo exceptionInfo;
1247 GetExceptionInfo( &exceptionInfo );
1248 MagickCore::Image* newImage =
1249 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1250 replaceImage( newImage );
1251 throwException( exceptionInfo );
1252 (void) DestroyExceptionInfo( &exceptionInfo );
1255 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1256 const double width_,
1257 const double sigma_ )
1259 ExceptionInfo exceptionInfo;
1260 GetExceptionInfo( &exceptionInfo );
1261 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1262 MagickCore::Image* newImage =
1263 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1264 (void) SetPixelChannelMapMask( image(), channel_mask );
1265 replaceImage( newImage );
1266 throwException( exceptionInfo );
1267 (void) DestroyExceptionInfo( &exceptionInfo );
1270 // Apply a color lookup table (Hald CLUT) to the image.
1271 void Magick::Image::haldClut ( const Image &clutImage_ )
1273 ExceptionInfo exceptionInfo;
1274 GetExceptionInfo( &exceptionInfo );
1276 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1277 throwException( exceptionInfo );
1278 (void) DestroyExceptionInfo( &exceptionInfo );
1282 void Magick::Image::implode ( const double factor_ )
1284 ExceptionInfo exceptionInfo;
1285 GetExceptionInfo( &exceptionInfo );
1286 MagickCore::Image* newImage =
1287 ImplodeImage( image(), factor_, image()->interpolate, &exceptionInfo );
1288 replaceImage( newImage );
1289 throwException( exceptionInfo );
1290 (void) DestroyExceptionInfo( &exceptionInfo );
1293 // implements the inverse discrete Fourier transform (IFT) of the image either
1294 // as a magnitude / phase or real / imaginary image pair.
1295 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1297 ExceptionInfo exceptionInfo;
1298 GetExceptionInfo( &exceptionInfo );
1299 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1300 phase_.constImage(), MagickTrue, &exceptionInfo);
1301 replaceImage( newImage );
1302 throwException( exceptionInfo );
1303 (void) DestroyExceptionInfo( &exceptionInfo );
1305 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1306 const bool magnitude_ )
1308 ExceptionInfo exceptionInfo;
1309 GetExceptionInfo( &exceptionInfo );
1310 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1311 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1313 replaceImage( newImage );
1314 throwException( exceptionInfo );
1315 (void) DestroyExceptionInfo( &exceptionInfo );
1318 // Level image. Adjust the levels of the image by scaling the colors
1319 // falling between specified white and black points to the full
1320 // available quantum range. The parameters provided represent the
1321 // black, mid (gamma), and white points. The black point specifies
1322 // the darkest color in the image. Colors darker than the black point
1323 // are set to zero. Mid point (gamma) specifies a gamma correction to
1324 // apply to the image. White point specifies the lightest color in the
1325 // image. Colors brighter than the white point are set to the maximum
1326 // quantum value. The black and white point have the valid range 0 to
1327 // QuantumRange while gamma has a useful range of 0 to ten.
1328 void Magick::Image::level ( const double black_point,
1329 const double white_point,
1330 const double gamma )
1332 ExceptionInfo exceptionInfo;
1333 GetExceptionInfo( &exceptionInfo );
1335 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1336 throwException( exceptionInfo );
1337 (void) DestroyExceptionInfo( &exceptionInfo );
1340 // Magnify image by integral size
1341 void Magick::Image::magnify ( void )
1343 ExceptionInfo exceptionInfo;
1344 GetExceptionInfo( &exceptionInfo );
1345 MagickCore::Image* newImage =
1346 MagnifyImage( image(), &exceptionInfo );
1347 replaceImage( newImage );
1348 throwException( exceptionInfo );
1349 (void) DestroyExceptionInfo( &exceptionInfo );
1352 // Remap image colors with closest color from reference image
1353 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1355 ExceptionInfo exceptionInfo;
1356 GetExceptionInfo( &exceptionInfo );
1358 options()->quantizeDither( dither_ );
1359 RemapImage ( options()->quantizeInfo(), image(),
1360 mapImage_.constImage(), &exceptionInfo);
1361 throwException( exceptionInfo );
1362 (void) DestroyExceptionInfo( &exceptionInfo );
1364 // Floodfill designated area with replacement alpha value
1365 void Magick::Image::matteFloodfill ( const Color &target_ ,
1366 const unsigned int alpha_,
1367 const ssize_t x_, const ssize_t y_,
1368 const Magick::PaintMethod method_ )
1372 GetPixelInfo(constImage(),&target);
1373 target.red=static_cast<PixelInfo>(target_).red;
1374 target.green=static_cast<PixelInfo>(target_).green;
1375 target.blue=static_cast<PixelInfo>(target_).blue;
1376 target.alpha=alpha_;
1377 ChannelType channel_mask = SetPixelChannelMask( image(), AlphaChannel );
1378 ExceptionInfo exceptionInfo;
1379 GetExceptionInfo( &exceptionInfo );
1380 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1381 method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
1382 (void) SetPixelChannelMapMask( image(), channel_mask );
1383 throwException( exceptionInfo );
1384 (void) DestroyExceptionInfo( &exceptionInfo );
1387 // Filter image by replacing each pixel component with the median
1388 // color in a circular neighborhood
1389 void Magick::Image::medianFilter ( const double radius_ )
1391 ExceptionInfo exceptionInfo;
1392 GetExceptionInfo( &exceptionInfo );
1393 MagickCore::Image* newImage =
1394 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1395 radius_,&exceptionInfo );
1396 replaceImage( newImage );
1397 throwException( exceptionInfo );
1398 (void) DestroyExceptionInfo( &exceptionInfo );
1401 // Reduce image by integral size
1402 void Magick::Image::minify ( void )
1404 ExceptionInfo exceptionInfo;
1405 GetExceptionInfo( &exceptionInfo );
1406 MagickCore::Image* newImage =
1407 MinifyImage( image(), &exceptionInfo );
1408 replaceImage( newImage );
1409 throwException( exceptionInfo );
1410 (void) DestroyExceptionInfo( &exceptionInfo );
1413 // Modulate percent hue, saturation, and brightness of an image
1414 void Magick::Image::modulate ( const double brightness_,
1415 const double saturation_,
1418 char modulate[MaxTextExtent + 1];
1419 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1420 brightness_, saturation_, hue_);
1422 ExceptionInfo exceptionInfo;
1423 GetExceptionInfo( &exceptionInfo );
1425 ModulateImage( image(), modulate, &exceptionInfo );
1426 throwException( exceptionInfo );
1427 (void) DestroyExceptionInfo( &exceptionInfo );
1430 // Motion blur image with specified blur factor
1431 // The radius_ parameter specifies the radius of the Gaussian, in
1432 // pixels, not counting the center pixel. The sigma_ parameter
1433 // specifies the standard deviation of the Laplacian, in pixels.
1434 // The angle_ parameter specifies the angle the object appears
1435 // to be comming from (zero degrees is from the right).
1436 void Magick::Image::motionBlur ( const double radius_,
1437 const double sigma_,
1438 const double angle_ )
1440 ExceptionInfo exceptionInfo;
1441 GetExceptionInfo( &exceptionInfo );
1442 MagickCore::Image* newImage =
1443 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1444 replaceImage( newImage );
1445 throwException( exceptionInfo );
1446 (void) DestroyExceptionInfo( &exceptionInfo );
1449 // Negate image. Set grayscale_ to true to effect grayscale values
1451 void Magick::Image::negate ( const bool grayscale_ )
1453 ExceptionInfo exceptionInfo;
1454 GetExceptionInfo( &exceptionInfo );
1456 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1458 throwException( exceptionInfo );
1459 (void) DestroyExceptionInfo( &exceptionInfo );
1463 void Magick::Image::normalize ( void )
1466 ExceptionInfo exceptionInfo;
1467 GetExceptionInfo( &exceptionInfo );
1468 NormalizeImage ( image(), &exceptionInfo );
1469 throwException( exceptionInfo );
1470 (void) DestroyExceptionInfo( &exceptionInfo );
1474 void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
1476 ExceptionInfo exceptionInfo;
1477 GetExceptionInfo( &exceptionInfo );
1478 MagickCore::Image* newImage =
1479 OilPaintImage( image(), radius_, sigma_, &exceptionInfo );
1480 replaceImage( newImage );
1481 throwException( exceptionInfo );
1482 (void) DestroyExceptionInfo( &exceptionInfo );
1485 // Set or attenuate the alpha channel. If the image pixels are
1486 // opaque then they are set to the specified alpha value, otherwise
1487 // they are blended with the supplied alpha value. The value of
1488 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1489 // OpaqueAlpha and TransparentAlpha are available to specify
1490 // completely opaque or completely transparent, respectively.
1491 void Magick::Image::alpha ( const unsigned int alpha_ )
1494 ExceptionInfo exceptionInfo;
1495 GetExceptionInfo( &exceptionInfo );
1496 SetImageAlpha( image(), alpha_, &exceptionInfo );
1497 throwException( exceptionInfo );
1498 (void) DestroyExceptionInfo( &exceptionInfo );
1501 // Change the color of an opaque pixel to the pen color.
1502 void Magick::Image::opaque ( const Color &opaqueColor_,
1503 const Color &penColor_ )
1505 if ( !opaqueColor_.isValid() )
1507 throwExceptionExplicit( OptionError,
1508 "Opaque color argument is invalid" );
1510 if ( !penColor_.isValid() )
1512 throwExceptionExplicit( OptionError,
1513 "Pen color argument is invalid" );
1517 std::string opaqueColor = opaqueColor_;
1518 std::string penColor = penColor_;
1522 ExceptionInfo exceptionInfo;
1523 GetExceptionInfo( &exceptionInfo );
1524 (void) QueryColorCompliance(std::string(opaqueColor_).c_str(),
1525 AllCompliance, &opaque, &exceptionInfo);
1526 (void) QueryColorCompliance(std::string(penColor_).c_str(),
1527 AllCompliance, &pen, &exceptionInfo);
1528 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo );
1529 throwException( exceptionInfo );
1530 (void) DestroyExceptionInfo( &exceptionInfo );
1533 // Ping is similar to read except only enough of the image is read to
1534 // determine the image columns, rows, and filesize. Access the
1535 // columns(), rows(), and fileSize() attributes after invoking ping.
1536 // The image data is not valid after calling ping.
1537 void Magick::Image::ping ( const std::string &imageSpec_ )
1539 options()->fileName( imageSpec_ );
1540 ExceptionInfo exceptionInfo;
1541 GetExceptionInfo( &exceptionInfo );
1542 MagickCore::Image* image =
1543 PingImage( imageInfo(), &exceptionInfo );
1544 replaceImage( image );
1545 throwException( exceptionInfo );
1546 (void) DestroyExceptionInfo( &exceptionInfo );
1549 // Ping is similar to read except only enough of the image is read
1550 // to determine the image columns, rows, and filesize. Access the
1551 // columns(), rows(), and fileSize() attributes after invoking
1552 // ping. The image data is not valid after calling ping.
1553 void Magick::Image::ping ( const Blob& blob_ )
1555 ExceptionInfo exceptionInfo;
1556 GetExceptionInfo( &exceptionInfo );
1557 MagickCore::Image* image =
1558 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1559 replaceImage( image );
1560 throwException( exceptionInfo );
1561 (void) DestroyExceptionInfo( &exceptionInfo );
1564 // Execute a named process module using an argc/argv syntax similar to
1565 // that accepted by a C 'main' routine. An exception is thrown if the
1566 // requested process module doesn't exist, fails to load, or fails during
1568 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1572 ExceptionInfo exceptionInfo;
1573 GetExceptionInfo( &exceptionInfo );
1575 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1578 throwException( exceptionInfo );
1579 (void) DestroyExceptionInfo( &exceptionInfo );
1582 // Quantize colors in image using current quantization settings
1583 // Set measureError_ to true in order to measure quantization error
1584 void Magick::Image::quantize ( const bool measureError_ )
1589 options()->quantizeInfo()->measure_error=MagickTrue;
1591 options()->quantizeInfo()->measure_error=MagickFalse;
1593 ExceptionInfo exceptionInfo;
1594 GetExceptionInfo( &exceptionInfo );
1595 QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo );
1597 throwException( exceptionInfo );
1598 (void) DestroyExceptionInfo( &exceptionInfo );
1601 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1602 void Magick::Image::quantumOperator ( const ChannelType channel_,
1603 const MagickEvaluateOperator operator_,
1606 ExceptionInfo exceptionInfo;
1607 GetExceptionInfo( &exceptionInfo );
1608 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1609 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
1610 (void) SetPixelChannelMapMask( image(), channel_mask );
1611 throwException( exceptionInfo );
1612 (void) DestroyExceptionInfo( &exceptionInfo );
1615 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1616 const size_t columns_,
1618 const ChannelType channel_,
1619 const MagickEvaluateOperator operator_,
1620 const double rvalue_)
1622 ExceptionInfo exceptionInfo;
1623 GetExceptionInfo( &exceptionInfo );
1624 RectangleInfo geometry;
1625 geometry.width = columns_;
1626 geometry.height = rows_;
1629 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1631 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1632 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
1633 (void) SetPixelChannelMapMask( image(), channel_mask );
1634 (void) CompositeImage( image(), crop_image, image()->matte != MagickFalse ?
1635 OverCompositeOp : CopyCompositeOp, MagickFalse, geometry.x, geometry.y,
1637 crop_image = DestroyImageList(crop_image);
1638 throwException( exceptionInfo );
1639 (void) DestroyExceptionInfo( &exceptionInfo );
1642 // Raise image (lighten or darken the edges of an image to give a 3-D
1643 // raised or lowered effect)
1644 void Magick::Image::raise ( const Geometry &geometry_ ,
1645 const bool raisedFlag_ )
1647 ExceptionInfo exceptionInfo;
1648 GetExceptionInfo( &exceptionInfo );
1649 RectangleInfo raiseInfo = geometry_;
1651 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
1652 throwException( exceptionInfo );
1653 (void) DestroyExceptionInfo( &exceptionInfo );
1657 // Random threshold image.
1659 // Changes the value of individual pixels based on the intensity
1660 // of each pixel compared to a random threshold. The result is a
1661 // low-contrast, two color image. The thresholds_ argument is a
1662 // geometry containing LOWxHIGH thresholds. If the string
1663 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1664 // 3, or 4 will be performed instead. If a channel_ argument is
1665 // specified then only the specified channel is altered. This is
1666 // a very fast alternative to 'quantize' based dithering.
1667 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1669 randomThresholdChannel(thresholds_,DefaultChannels);
1671 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1672 const ChannelType channel_ )
1674 ExceptionInfo exceptionInfo;
1675 GetExceptionInfo( &exceptionInfo );
1677 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1678 (void) RandomThresholdImage( image(),
1679 static_cast<std::string>(thresholds_).c_str(),
1681 (void) SetPixelChannelMapMask( image(), channel_mask );
1682 throwImageException();
1683 (void) DestroyExceptionInfo( &exceptionInfo );
1686 // Read image into current object
1687 void Magick::Image::read ( const std::string &imageSpec_ )
1689 options()->fileName( imageSpec_ );
1691 ExceptionInfo exceptionInfo;
1692 GetExceptionInfo( &exceptionInfo );
1693 MagickCore::Image* image =
1694 ReadImage( imageInfo(), &exceptionInfo );
1696 // Ensure that multiple image frames were not read.
1697 if ( image && image->next )
1699 // Destroy any extra image frames
1700 MagickCore::Image* next = image->next;
1703 DestroyImageList( next );
1706 replaceImage( image );
1707 throwException( exceptionInfo );
1708 (void) DestroyExceptionInfo( &exceptionInfo );
1711 // Read image of specified size into current object
1712 void Magick::Image::read ( const Geometry &size_,
1713 const std::string &imageSpec_ )
1719 // Read image from in-memory BLOB
1720 void Magick::Image::read ( const Blob &blob_ )
1722 ExceptionInfo exceptionInfo;
1723 GetExceptionInfo( &exceptionInfo );
1724 MagickCore::Image* image =
1725 BlobToImage( imageInfo(),
1726 static_cast<const void *>(blob_.data()),
1727 blob_.length(), &exceptionInfo );
1728 replaceImage( image );
1729 throwException( exceptionInfo );
1730 (void) DestroyExceptionInfo( &exceptionInfo );
1733 // Read image of specified size from in-memory BLOB
1734 void Magick::Image::read ( const Blob &blob_,
1735 const Geometry &size_ )
1743 // Read image of specified size and depth from in-memory BLOB
1744 void Magick::Image::read ( const Blob &blob_,
1745 const Geometry &size_,
1746 const size_t depth_ )
1756 // Read image of specified size, depth, and format from in-memory BLOB
1757 void Magick::Image::read ( const Blob &blob_,
1758 const Geometry &size_,
1759 const size_t depth_,
1760 const std::string &magick_ )
1768 // Set explicit image format
1769 fileName( magick_ + ':');
1774 // Read image of specified size, and format from in-memory BLOB
1775 void Magick::Image::read ( const Blob &blob_,
1776 const Geometry &size_,
1777 const std::string &magick_ )
1783 // Set explicit image format
1784 fileName( magick_ + ':');
1789 // Read image based on raw pixels in memory (ConstituteImage)
1790 void Magick::Image::read ( const size_t width_,
1791 const size_t height_,
1792 const std::string &map_,
1793 const StorageType type_,
1794 const void *pixels_ )
1796 ExceptionInfo exceptionInfo;
1797 GetExceptionInfo( &exceptionInfo );
1798 MagickCore::Image* image =
1799 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1801 replaceImage( image );
1802 throwException( exceptionInfo );
1803 (void) DestroyExceptionInfo( &exceptionInfo );
1806 // Reduce noise in image
1807 void Magick::Image::reduceNoise ( const double order_ )
1809 ExceptionInfo exceptionInfo;
1810 GetExceptionInfo( &exceptionInfo );
1811 MagickCore::Image* newImage =
1812 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1814 replaceImage( newImage );
1815 throwException( exceptionInfo );
1816 (void) DestroyExceptionInfo( &exceptionInfo );
1820 void Magick::Image::resize( const Geometry &geometry_ )
1822 // Calculate new size. This code should be supported using binary arguments
1823 // in the ImageMagick library.
1826 size_t width = columns();
1827 size_t height = rows();
1829 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1833 ExceptionInfo exceptionInfo;
1834 GetExceptionInfo( &exceptionInfo );
1835 MagickCore::Image* newImage =
1836 ResizeImage( image(),
1841 replaceImage( newImage );
1842 throwException( exceptionInfo );
1843 (void) DestroyExceptionInfo( &exceptionInfo );
1847 void Magick::Image::roll ( const Geometry &roll_ )
1849 ssize_t xOff = roll_.xOff();
1850 if ( roll_.xNegative() )
1852 ssize_t yOff = roll_.yOff();
1853 if ( roll_.yNegative() )
1856 ExceptionInfo exceptionInfo;
1857 GetExceptionInfo( &exceptionInfo );
1858 MagickCore::Image* newImage =
1859 RollImage( image(), xOff, yOff, &exceptionInfo );
1860 replaceImage( newImage );
1861 throwException( exceptionInfo );
1862 (void) DestroyExceptionInfo( &exceptionInfo );
1864 void Magick::Image::roll ( const size_t columns_,
1865 const size_t rows_ )
1867 ExceptionInfo exceptionInfo;
1868 GetExceptionInfo( &exceptionInfo );
1869 MagickCore::Image* newImage =
1871 static_cast<ssize_t>(columns_),
1872 static_cast<ssize_t>(rows_), &exceptionInfo );
1873 replaceImage( newImage );
1874 throwException( exceptionInfo );
1875 (void) DestroyExceptionInfo( &exceptionInfo );
1879 void Magick::Image::rotate ( const double degrees_ )
1881 ExceptionInfo exceptionInfo;
1882 GetExceptionInfo( &exceptionInfo );
1883 MagickCore::Image* newImage =
1884 RotateImage( image(), degrees_, &exceptionInfo);
1885 replaceImage( newImage );
1886 throwException( exceptionInfo );
1887 (void) DestroyExceptionInfo( &exceptionInfo );
1891 void Magick::Image::sample ( const Geometry &geometry_ )
1895 size_t width = columns();
1896 size_t height = rows();
1898 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1902 ExceptionInfo exceptionInfo;
1903 GetExceptionInfo( &exceptionInfo );
1904 MagickCore::Image* newImage =
1905 SampleImage( image(), width, height, &exceptionInfo );
1906 replaceImage( newImage );
1907 throwException( exceptionInfo );
1908 (void) DestroyExceptionInfo( &exceptionInfo );
1912 void Magick::Image::scale ( const Geometry &geometry_ )
1916 size_t width = columns();
1917 size_t height = rows();
1919 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1923 ExceptionInfo exceptionInfo;
1924 GetExceptionInfo( &exceptionInfo );
1925 MagickCore::Image* newImage =
1926 ScaleImage( image(), width, height, &exceptionInfo );
1927 replaceImage( newImage );
1928 throwException( exceptionInfo );
1929 (void) DestroyExceptionInfo( &exceptionInfo );
1932 // Segment (coalesce similar image components) by analyzing the
1933 // histograms of the color components and identifying units that are
1934 // homogeneous with the fuzzy c-means technique.
1935 void Magick::Image::segment ( const double clusterThreshold_,
1936 const double smoothingThreshold_ )
1938 ExceptionInfo exceptionInfo;
1939 GetExceptionInfo( &exceptionInfo );
1941 SegmentImage ( image(),
1942 options()->quantizeColorSpace(),
1943 (MagickBooleanType) options()->verbose(),
1945 smoothingThreshold_, &exceptionInfo );
1946 SyncImage( image(), &exceptionInfo );
1947 throwException( exceptionInfo );
1948 (void) DestroyExceptionInfo( &exceptionInfo );
1951 // Shade image using distant light source
1952 void Magick::Image::shade ( const double azimuth_,
1953 const double elevation_,
1954 const bool colorShading_ )
1956 ExceptionInfo exceptionInfo;
1957 GetExceptionInfo( &exceptionInfo );
1958 MagickCore::Image* newImage =
1959 ShadeImage( image(),
1960 colorShading_ == true ? MagickTrue : MagickFalse,
1964 replaceImage( newImage );
1965 throwException( exceptionInfo );
1966 (void) DestroyExceptionInfo( &exceptionInfo );
1969 // Simulate an image shadow
1970 void Magick::Image::shadow( const double percent_opacity_, const double sigma_,
1971 const ssize_t x_, const ssize_t y_ )
1973 ExceptionInfo exceptionInfo;
1974 GetExceptionInfo( &exceptionInfo );
1975 MagickCore::Image* newImage = ShadowImage( image(), percent_opacity_, sigma_,
1976 x_, y_, &exceptionInfo );
1977 replaceImage( newImage );
1978 throwException( exceptionInfo );
1979 (void) DestroyExceptionInfo( &exceptionInfo );
1982 // Sharpen pixels in image
1983 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1985 ExceptionInfo exceptionInfo;
1986 GetExceptionInfo( &exceptionInfo );
1987 MagickCore::Image* newImage =
1988 SharpenImage( image(),
1992 replaceImage( newImage );
1993 throwException( exceptionInfo );
1994 (void) DestroyExceptionInfo( &exceptionInfo );
1997 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1998 const double radius_, const double sigma_ )
2000 ExceptionInfo exceptionInfo;
2001 GetExceptionInfo( &exceptionInfo );
2002 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
2003 MagickCore::Image* newImage =
2004 SharpenImage( image(),
2008 (void) SetPixelChannelMapMask( image(), channel_mask );
2009 replaceImage( newImage );
2010 throwException( exceptionInfo );
2011 (void) DestroyExceptionInfo( &exceptionInfo );
2014 // Shave pixels from image edges.
2015 void Magick::Image::shave ( const Geometry &geometry_ )
2017 RectangleInfo shaveInfo = geometry_;
2018 ExceptionInfo exceptionInfo;
2019 GetExceptionInfo( &exceptionInfo );
2020 MagickCore::Image* newImage =
2021 ShaveImage( image(),
2024 replaceImage( newImage );
2025 throwException( exceptionInfo );
2026 (void) DestroyExceptionInfo( &exceptionInfo );
2030 void Magick::Image::shear ( const double xShearAngle_,
2031 const double yShearAngle_ )
2033 ExceptionInfo exceptionInfo;
2034 GetExceptionInfo( &exceptionInfo );
2035 MagickCore::Image* newImage =
2036 ShearImage( image(),
2040 replaceImage( newImage );
2041 throwException( exceptionInfo );
2042 (void) DestroyExceptionInfo( &exceptionInfo );
2046 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
2048 ExceptionInfo exceptionInfo;
2049 GetExceptionInfo( &exceptionInfo );
2051 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
2052 throwException( exceptionInfo );
2053 (void) DestroyExceptionInfo( &exceptionInfo );
2056 // Solarize image (similar to effect seen when exposing a photographic
2057 // film to light during the development process)
2058 void Magick::Image::solarize ( const double factor_ )
2060 ExceptionInfo exceptionInfo;
2061 GetExceptionInfo( &exceptionInfo );
2063 SolarizeImage ( image(), factor_, &exceptionInfo );
2064 throwException( exceptionInfo );
2065 (void) DestroyExceptionInfo( &exceptionInfo );
2068 // Sparse color image, given a set of coordinates, interpolates the colors
2069 // found at those coordinates, across the whole image, using various methods.
2071 void Magick::Image::sparseColor ( const ChannelType channel,
2072 const SparseColorMethod method,
2073 const size_t number_arguments,
2074 const double *arguments )
2076 ExceptionInfo exceptionInfo;
2077 GetExceptionInfo( &exceptionInfo );
2079 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
2080 MagickCore::Image* newImage = SparseColorImage ( image(), method,
2081 number_arguments, arguments, &exceptionInfo );
2082 (void) SetPixelChannelMapMask( image(), channel_mask );
2083 replaceImage( newImage );
2084 throwException( exceptionInfo );
2085 (void) DestroyExceptionInfo( &exceptionInfo );
2088 // Spread pixels randomly within image by specified ammount
2089 void Magick::Image::spread ( const size_t amount_ )
2091 ExceptionInfo exceptionInfo;
2092 GetExceptionInfo( &exceptionInfo );
2093 MagickCore::Image* newImage =
2094 SpreadImage( image(),
2096 image()->interpolate,
2098 replaceImage( newImage );
2099 throwException( exceptionInfo );
2100 (void) DestroyExceptionInfo( &exceptionInfo );
2103 // Add a digital watermark to the image (based on second image)
2104 void Magick::Image::stegano ( const Image &watermark_ )
2106 ExceptionInfo exceptionInfo;
2107 GetExceptionInfo( &exceptionInfo );
2108 MagickCore::Image* newImage =
2109 SteganoImage( image(),
2110 watermark_.constImage(),
2112 replaceImage( newImage );
2113 throwException( exceptionInfo );
2114 (void) DestroyExceptionInfo( &exceptionInfo );
2117 // Stereo image (left image is current image)
2118 void Magick::Image::stereo ( const Image &rightImage_ )
2120 ExceptionInfo exceptionInfo;
2121 GetExceptionInfo( &exceptionInfo );
2122 MagickCore::Image* newImage =
2123 StereoImage( image(),
2124 rightImage_.constImage(),
2126 replaceImage( newImage );
2127 throwException( exceptionInfo );
2128 (void) DestroyExceptionInfo( &exceptionInfo );
2132 void Magick::Image::swirl ( const double degrees_ )
2134 ExceptionInfo exceptionInfo;
2135 GetExceptionInfo( &exceptionInfo );
2136 MagickCore::Image* newImage =
2137 SwirlImage( image(), degrees_, image()->interpolate,
2139 replaceImage( newImage );
2140 throwException( exceptionInfo );
2141 (void) DestroyExceptionInfo( &exceptionInfo );
2145 void Magick::Image::texture ( const Image &texture_ )
2148 ExceptionInfo exceptionInfo;
2149 GetExceptionInfo( &exceptionInfo );
2150 TextureImage( image(), texture_.constImage(), &exceptionInfo );
2151 throwException( exceptionInfo );
2152 (void) DestroyExceptionInfo( &exceptionInfo );
2156 void Magick::Image::threshold ( const double threshold_ )
2159 ExceptionInfo exceptionInfo;
2160 GetExceptionInfo( &exceptionInfo );
2161 BilevelImage( image(), threshold_, &exceptionInfo );
2162 throwException( exceptionInfo );
2163 (void) DestroyExceptionInfo( &exceptionInfo );
2166 // Transform image based on image geometry only
2167 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2170 ExceptionInfo exceptionInfo;
2171 GetExceptionInfo( &exceptionInfo );
2172 TransformImage ( &(image()), 0,
2173 std::string(imageGeometry_).c_str(), &exceptionInfo );
2174 throwException( exceptionInfo );
2175 (void) DestroyExceptionInfo( &exceptionInfo );
2177 // Transform image based on image and crop geometries
2178 void Magick::Image::transform ( const Geometry &imageGeometry_,
2179 const Geometry &cropGeometry_ )
2182 ExceptionInfo exceptionInfo;
2183 GetExceptionInfo( &exceptionInfo );
2184 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2185 std::string(imageGeometry_).c_str(), &exceptionInfo );
2186 throwException( exceptionInfo );
2187 (void) DestroyExceptionInfo( &exceptionInfo );
2190 // Add matte image to image, setting pixels matching color to transparent
2191 void Magick::Image::transparent ( const Color &color_ )
2193 if ( !color_.isValid() )
2195 throwExceptionExplicit( OptionError,
2196 "Color argument is invalid" );
2199 std::string color = color_;
2202 ExceptionInfo exceptionInfo;
2203 GetExceptionInfo( &exceptionInfo );
2204 (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
2205 &target,&exceptionInfo);
2207 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2209 throwException( exceptionInfo );
2210 (void) DestroyExceptionInfo( &exceptionInfo );
2213 // Add matte image to image, setting pixels matching color to transparent
2214 void Magick::Image::transparentChroma(const Color &colorLow_,
2215 const Color &colorHigh_)
2217 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2219 throwExceptionExplicit( OptionError,
2220 "Color argument is invalid" );
2223 std::string colorLow = colorLow_;
2224 std::string colorHigh = colorHigh_;
2226 PixelInfo targetLow;
2227 PixelInfo targetHigh;
2228 ExceptionInfo exceptionInfo;
2229 GetExceptionInfo( &exceptionInfo );
2230 (void) QueryColorCompliance(std::string(colorLow_).c_str(),
2231 AllCompliance,&targetLow,&exceptionInfo);
2232 (void) QueryColorCompliance(std::string(colorHigh_).c_str(),
2233 AllCompliance,&targetHigh,&exceptionInfo);
2235 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2236 TransparentAlpha, MagickFalse, &exceptionInfo );
2237 throwException( exceptionInfo );
2238 (void) DestroyExceptionInfo( &exceptionInfo );
2242 // Trim edges that are the background color from the image
2243 void Magick::Image::trim ( void )
2245 ExceptionInfo exceptionInfo;
2246 GetExceptionInfo( &exceptionInfo );
2247 MagickCore::Image* newImage =
2248 TrimImage( image(), &exceptionInfo);
2249 replaceImage( newImage );
2250 throwException( exceptionInfo );
2251 (void) DestroyExceptionInfo( &exceptionInfo );
2254 // Replace image with a sharpened version of the original image
2255 // using the unsharp mask algorithm.
2257 // the radius of the Gaussian, in pixels, not counting the
2260 // the standard deviation of the Gaussian, in pixels.
2262 // the percentage of the difference between the original and
2263 // the blur image that is added back into the original.
2265 // the threshold in pixels needed to apply the diffence amount.
2266 void Magick::Image::unsharpmask ( const double radius_,
2267 const double sigma_,
2268 const double amount_,
2269 const double threshold_ )
2271 ExceptionInfo exceptionInfo;
2272 GetExceptionInfo( &exceptionInfo );
2273 MagickCore::Image* newImage =
2274 UnsharpMaskImage( image(),
2280 replaceImage( newImage );
2281 throwException( exceptionInfo );
2282 (void) DestroyExceptionInfo( &exceptionInfo );
2285 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2286 const double radius_,
2287 const double sigma_,
2288 const double amount_,
2289 const double threshold_ )
2291 ExceptionInfo exceptionInfo;
2292 GetExceptionInfo( &exceptionInfo );
2293 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
2294 MagickCore::Image* newImage =
2295 UnsharpMaskImage( image(),
2301 (void) SetPixelChannelMapMask( image(), channel_mask );
2302 replaceImage( newImage );
2303 throwException( exceptionInfo );
2304 (void) DestroyExceptionInfo( &exceptionInfo );
2307 // Map image pixels to a sine wave
2308 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2310 ExceptionInfo exceptionInfo;
2311 GetExceptionInfo( &exceptionInfo );
2312 MagickCore::Image* newImage =
2316 image()->interpolate,
2318 replaceImage( newImage );
2319 throwException( exceptionInfo );
2320 (void) DestroyExceptionInfo( &exceptionInfo );
2323 // Write image to file
2324 void Magick::Image::write( const std::string &imageSpec_ )
2326 ExceptionInfo exceptionInfo;
2327 GetExceptionInfo( &exceptionInfo );
2329 fileName( imageSpec_ );
2330 WriteImage( imageInfo(), image(), &exceptionInfo );
2331 throwException( exceptionInfo );
2332 (void) DestroyExceptionInfo( &exceptionInfo );
2335 // Write image to in-memory BLOB
2336 void Magick::Image::write ( Blob *blob_ )
2339 size_t length = 2048; // Efficient size for small images
2340 ExceptionInfo exceptionInfo;
2341 GetExceptionInfo( &exceptionInfo );
2342 void* data = ImageToBlob( imageInfo(),
2346 throwException( exceptionInfo );
2347 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2348 throwImageException();
2349 (void) DestroyExceptionInfo( &exceptionInfo );
2351 void Magick::Image::write ( Blob *blob_,
2352 const std::string &magick_ )
2356 size_t length = 2048; // Efficient size for small images
2357 ExceptionInfo exceptionInfo;
2358 GetExceptionInfo( &exceptionInfo );
2359 void* data = ImageToBlob( imageInfo(),
2363 throwException( exceptionInfo );
2364 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2365 throwImageException();
2366 (void) DestroyExceptionInfo( &exceptionInfo );
2368 void Magick::Image::write ( Blob *blob_,
2369 const std::string &magick_,
2370 const size_t depth_ )
2375 size_t length = 2048; // Efficient size for small images
2376 ExceptionInfo exceptionInfo;
2377 GetExceptionInfo( &exceptionInfo );
2378 void* data = ImageToBlob( imageInfo(),
2382 throwException( exceptionInfo );
2383 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2384 throwImageException();
2385 (void) DestroyExceptionInfo( &exceptionInfo );
2388 // Write image to an array of pixels with storage type specified
2389 // by user (ExportImagePixels), e.g.
2390 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2391 void Magick::Image::write ( const ssize_t x_,
2393 const size_t columns_,
2395 const std::string &map_,
2396 const StorageType type_,
2399 ExceptionInfo exceptionInfo;
2400 GetExceptionInfo( &exceptionInfo );
2401 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2404 throwException( exceptionInfo );
2405 (void) DestroyExceptionInfo( &exceptionInfo );
2409 void Magick::Image::zoom( const Geometry &geometry_ )
2411 // Calculate new size. This code should be supported using binary arguments
2412 // in the ImageMagick library.
2415 size_t width = columns();
2416 size_t height = rows();
2418 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2422 ExceptionInfo exceptionInfo;
2423 GetExceptionInfo( &exceptionInfo );
2424 MagickCore::Image* newImage =
2425 ResizeImage( image(),
2430 replaceImage( newImage );
2431 throwException( exceptionInfo );
2432 (void) DestroyExceptionInfo( &exceptionInfo );
2436 * Methods for setting image attributes
2440 // Join images into a single multi-image file
2441 void Magick::Image::adjoin ( const bool flag_ )
2444 options()->adjoin( flag_ );
2446 bool Magick::Image::adjoin ( void ) const
2448 return constOptions()->adjoin();
2451 // Remove pixel aliasing
2452 void Magick::Image::antiAlias( const bool flag_ )
2455 options()->antiAlias( static_cast<size_t>(flag_) );
2457 bool Magick::Image::antiAlias( void )
2459 return static_cast<bool>( options()->antiAlias( ) );
2462 // Animation inter-frame delay
2463 void Magick::Image::animationDelay ( const size_t delay_ )
2466 image()->delay = delay_;
2468 size_t Magick::Image::animationDelay ( void ) const
2470 return constImage()->delay;
2473 // Number of iterations to play animation
2474 void Magick::Image::animationIterations ( const size_t iterations_ )
2477 image()->iterations = iterations_;
2479 size_t Magick::Image::animationIterations ( void ) const
2481 return constImage()->iterations;
2484 // Access/Update a named image attribute
2485 void Magick::Image::attribute ( const std::string name_,
2486 const std::string value_ )
2489 ExceptionInfo exceptionInfo;
2490 GetExceptionInfo( &exceptionInfo );
2491 SetImageProperty( image(), name_.c_str(), value_.c_str(), &exceptionInfo );
2492 throwException( exceptionInfo );
2493 (void) DestroyExceptionInfo( &exceptionInfo );
2495 std::string Magick::Image::attribute ( const std::string name_ )
2497 ExceptionInfo exceptionInfo;
2498 GetExceptionInfo( &exceptionInfo );
2499 const char *value = GetImageProperty( constImage(), name_.c_str(),
2501 throwException( exceptionInfo );
2502 (void) DestroyExceptionInfo( &exceptionInfo );
2505 return std::string( value );
2507 return std::string(); // Intentionally no exception
2511 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2515 if ( backgroundColor_.isValid() )
2517 image()->background_color = backgroundColor_;
2521 image()->background_color = Color();
2524 options()->backgroundColor( backgroundColor_ );
2526 Magick::Color Magick::Image::backgroundColor ( void ) const
2528 return constOptions()->backgroundColor( );
2531 // Background fill texture
2532 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2535 options()->backgroundTexture( backgroundTexture_ );
2537 std::string Magick::Image::backgroundTexture ( void ) const
2539 return constOptions()->backgroundTexture( );
2542 // Original image columns
2543 size_t Magick::Image::baseColumns ( void ) const
2545 return constImage()->magick_columns;
2548 // Original image name
2549 std::string Magick::Image::baseFilename ( void ) const
2551 return std::string(constImage()->magick_filename);
2554 // Original image rows
2555 size_t Magick::Image::baseRows ( void ) const
2557 return constImage()->magick_rows;
2561 void Magick::Image::borderColor ( const Color &borderColor_ )
2565 if ( borderColor_.isValid() )
2567 image()->border_color = borderColor_;
2571 image()->border_color = Color();
2574 options()->borderColor( borderColor_ );
2576 Magick::Color Magick::Image::borderColor ( void ) const
2578 return constOptions()->borderColor( );
2581 // Return smallest bounding box enclosing non-border pixels. The
2582 // current fuzz value is used when discriminating between pixels.
2583 // This is the crop bounding box used by crop(Geometry(0,0));
2584 Magick::Geometry Magick::Image::boundingBox ( void ) const
2586 ExceptionInfo exceptionInfo;
2587 GetExceptionInfo( &exceptionInfo );
2588 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2589 throwException( exceptionInfo );
2590 (void) DestroyExceptionInfo( &exceptionInfo );
2591 return Geometry( bbox );
2594 // Text bounding-box base color
2595 void Magick::Image::boxColor ( const Color &boxColor_ )
2598 options()->boxColor( boxColor_ );
2600 Magick::Color Magick::Image::boxColor ( void ) const
2602 return constOptions()->boxColor( );
2605 // Pixel cache threshold. Once this threshold is exceeded, all
2606 // subsequent pixels cache operations are to/from disk.
2607 // This setting is shared by all Image objects.
2609 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2611 SetMagickResourceLimit( MemoryResource, threshold_ );
2614 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2617 image()->chromaticity.blue_primary.x = x_;
2618 image()->chromaticity.blue_primary.y = y_;
2620 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2622 *x_ = constImage()->chromaticity.blue_primary.x;
2623 *y_ = constImage()->chromaticity.blue_primary.y;
2626 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2629 image()->chromaticity.green_primary.x = x_;
2630 image()->chromaticity.green_primary.y = y_;
2632 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2634 *x_ = constImage()->chromaticity.green_primary.x;
2635 *y_ = constImage()->chromaticity.green_primary.y;
2638 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2641 image()->chromaticity.red_primary.x = x_;
2642 image()->chromaticity.red_primary.y = y_;
2644 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2646 *x_ = constImage()->chromaticity.red_primary.x;
2647 *y_ = constImage()->chromaticity.red_primary.y;
2650 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2653 image()->chromaticity.white_point.x = x_;
2654 image()->chromaticity.white_point.y = y_;
2656 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2658 *x_ = constImage()->chromaticity.white_point.x;
2659 *y_ = constImage()->chromaticity.white_point.y;
2662 // Set image storage class
2663 void Magick::Image::classType ( const ClassType class_ )
2665 if ( classType() == PseudoClass && class_ == DirectClass )
2667 // Use SyncImage to synchronize the DirectClass pixels with the
2668 // color map and then set to DirectClass type.
2670 ExceptionInfo exceptionInfo;
2671 GetExceptionInfo( &exceptionInfo );
2672 SyncImage( image(), &exceptionInfo );
2673 throwException( exceptionInfo );
2674 (void) DestroyExceptionInfo( &exceptionInfo );
2675 image()->colormap = (PixelInfo *)
2676 RelinquishMagickMemory( image()->colormap );
2677 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2681 if ( classType() == DirectClass && class_ == PseudoClass )
2683 // Quantize to create PseudoClass color map
2685 quantizeColors(MaxColormapSize);
2687 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2691 // Associate a clip mask with the image. The clip mask must be the
2692 // same dimensions as the image. Pass an invalid image to unset an
2693 // existing clip mask.
2694 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2698 ExceptionInfo exceptionInfo;
2699 GetExceptionInfo( &exceptionInfo );
2700 if( clipMask_.isValid() )
2703 SetImageMask( image(), clipMask_.constImage(), &exceptionInfo );
2707 // Unset existing clip mask
2708 SetImageMask( image(), 0, &exceptionInfo );
2710 throwException( exceptionInfo );
2711 (void) DestroyExceptionInfo( &exceptionInfo );
2713 Magick::Image Magick::Image::clipMask ( void ) const
2715 ExceptionInfo exceptionInfo;
2716 GetExceptionInfo( &exceptionInfo );
2717 MagickCore::Image* image = GetImageMask( constImage(), &exceptionInfo );
2718 throwException( exceptionInfo );
2719 (void) DestroyExceptionInfo( &exceptionInfo );
2720 return Magick::Image( image );
2723 void Magick::Image::colorFuzz ( const double fuzz_ )
2726 image()->fuzz = fuzz_;
2727 options()->colorFuzz( fuzz_ );
2729 double Magick::Image::colorFuzz ( void ) const
2731 return constOptions()->colorFuzz( );
2734 // Set color in colormap at index
2735 void Magick::Image::colorMap ( const size_t index_,
2736 const Color &color_ )
2738 MagickCore::Image* imageptr = image();
2740 if (index_ > (MaxColormapSize-1) )
2741 throwExceptionExplicit( OptionError,
2742 "Colormap index must be less than MaxColormapSize" );
2744 if ( !color_.isValid() )
2745 throwExceptionExplicit( OptionError,
2746 "Color argument is invalid");
2749 // Ensure that colormap size is large enough
2750 if ( colorMapSize() < (index_+1) )
2751 colorMapSize( index_ + 1 );
2753 // Set color at index in colormap
2754 (imageptr->colormap)[index_] = color_;
2756 // Return color in colormap at index
2757 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2759 const MagickCore::Image* imageptr = constImage();
2761 if ( !imageptr->colormap )
2762 throwExceptionExplicit( OptionError,
2763 "Image does not contain a colormap");
2765 if ( index_ > imageptr->colors-1 )
2766 throwExceptionExplicit( OptionError,
2767 "Index out of range");
2769 return Magick::Color( (imageptr->colormap)[index_] );
2772 // Colormap size (number of colormap entries)
2773 void Magick::Image::colorMapSize ( const size_t entries_ )
2775 if (entries_ >MaxColormapSize )
2776 throwExceptionExplicit( OptionError,
2777 "Colormap entries must not exceed MaxColormapSize" );
2781 MagickCore::Image* imageptr = image();
2783 if( !imageptr->colormap )
2785 // Allocate colormap
2786 imageptr->colormap =
2787 static_cast<PixelInfo*>(AcquireMagickMemory(entries_*sizeof(PixelInfo)));
2788 imageptr->colors = 0;
2790 else if ( entries_ > imageptr->colors )
2792 // Re-allocate colormap
2793 imageptr->colormap=(PixelInfo *)
2794 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelInfo));
2797 // Initialize any new colormap entries as all black
2799 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2800 (imageptr->colormap)[i] = black;
2802 imageptr->colors = entries_;
2804 size_t Magick::Image::colorMapSize ( void )
2806 const MagickCore::Image* imageptr = constImage();
2808 if ( !imageptr->colormap )
2809 throwExceptionExplicit( OptionError,
2810 "Image does not contain a colormap");
2812 return imageptr->colors;
2816 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2818 if ( image()->colorspace == colorSpace_ )
2822 ExceptionInfo exceptionInfo;
2823 GetExceptionInfo( &exceptionInfo );
2824 TransformImageColorspace(image(), colorSpace_, &exceptionInfo);
2825 throwException( exceptionInfo );
2826 (void) DestroyExceptionInfo( &exceptionInfo );
2828 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2830 return constImage()->colorspace;
2833 // Set image colorspace type.
2834 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2837 ExceptionInfo exceptionInfo;
2838 GetExceptionInfo( &exceptionInfo );
2839 SetImageColorspace(image(), colorSpace_, &exceptionInfo);
2840 throwException( exceptionInfo );
2841 (void) DestroyExceptionInfo( &exceptionInfo );
2842 options()->colorspaceType( colorSpace_ );
2844 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2846 return constOptions()->colorspaceType();
2851 void Magick::Image::comment ( const std::string &comment_ )
2854 ExceptionInfo exceptionInfo;
2855 GetExceptionInfo( &exceptionInfo );
2856 SetImageProperty( image(), "Comment", NULL, &exceptionInfo );
2857 if ( comment_.length() > 0 )
2858 SetImageProperty( image(), "Comment", comment_.c_str(), &exceptionInfo );
2859 throwException( exceptionInfo );
2860 (void) DestroyExceptionInfo( &exceptionInfo );
2862 std::string Magick::Image::comment ( void ) const
2864 ExceptionInfo exceptionInfo;
2865 GetExceptionInfo( &exceptionInfo );
2866 const char *value = GetImageProperty( constImage(), "Comment",
2868 throwException( exceptionInfo );
2869 (void) DestroyExceptionInfo( &exceptionInfo );
2872 return std::string( value );
2874 return std::string(); // Intentionally no exception
2877 // Composition operator to be used when composition is implicitly used
2878 // (such as for image flattening).
2879 void Magick::Image::compose (const CompositeOperator compose_)
2881 image()->compose=compose_;
2884 Magick::CompositeOperator Magick::Image::compose ( void ) const
2886 return constImage()->compose;
2889 // Compression algorithm
2890 void Magick::Image::compressType ( const CompressionType compressType_ )
2893 image()->compression = compressType_;
2894 options()->compressType( compressType_ );
2896 Magick::CompressionType Magick::Image::compressType ( void ) const
2898 return constImage()->compression;
2901 // Enable printing of debug messages from ImageMagick
2902 void Magick::Image::debug ( const bool flag_ )
2905 options()->debug( flag_ );
2907 bool Magick::Image::debug ( void ) const
2909 return constOptions()->debug();
2912 // Tagged image format define (set/access coder-specific option) The
2913 // magick_ option specifies the coder the define applies to. The key_
2914 // option provides the key specific to that coder. The value_ option
2915 // provides the value to set (if any). See the defineSet() method if the
2916 // key must be removed entirely.
2917 void Magick::Image::defineValue ( const std::string &magick_,
2918 const std::string &key_,
2919 const std::string &value_ )
2922 std::string format = magick_ + ":" + key_;
2923 std::string option = value_;
2924 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2926 std::string Magick::Image::defineValue ( const std::string &magick_,
2927 const std::string &key_ ) const
2929 std::string definition = magick_ + ":" + key_;
2930 const char *option =
2931 GetImageOption ( constImageInfo(), definition.c_str() );
2933 return std::string( option );
2934 return std::string( );
2937 // Tagged image format define. Similar to the defineValue() method
2938 // except that passing the flag_ value 'true' creates a value-less
2939 // define with that format and key. Passing the flag_ value 'false'
2940 // removes any existing matching definition. The method returns 'true'
2941 // if a matching key exists, and 'false' if no matching key exists.
2942 void Magick::Image::defineSet ( const std::string &magick_,
2943 const std::string &key_,
2947 std::string definition = magick_ + ":" + key_;
2950 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2954 DeleteImageOption( imageInfo(), definition.c_str() );
2957 bool Magick::Image::defineSet ( const std::string &magick_,
2958 const std::string &key_ ) const
2960 std::string key = magick_ + ":" + key_;
2961 const char *option =
2962 GetImageOption ( constImageInfo(), key.c_str() );
2969 void Magick::Image::density ( const Geometry &density_ )
2972 options()->density( density_ );
2973 if ( density_.isValid() )
2975 image()->resolution.x = density_.width();
2976 if ( density_.height() != 0 )
2978 image()->resolution.y = density_.height();
2982 image()->resolution.y = density_.width();
2988 image()->resolution.x = 0;
2989 image()->resolution.y = 0;
2992 Magick::Geometry Magick::Image::density ( void ) const
2996 ssize_t x_resolution=72;
2997 ssize_t y_resolution=72;
2999 if (constImage()->resolution.x > 0.0)
3000 x_resolution=static_cast<ssize_t>(constImage()->resolution.x + 0.5);
3002 if (constImage()->resolution.y > 0.0)
3003 y_resolution=static_cast<ssize_t>(constImage()->resolution.y + 0.5);
3005 return Geometry(x_resolution,y_resolution);
3008 return constOptions()->density( );
3011 // Image depth (bits allocated to red/green/blue components)
3012 void Magick::Image::depth ( const size_t depth_ )
3014 size_t depth = depth_;
3016 if (depth > MAGICKCORE_QUANTUM_DEPTH)
3017 depth=MAGICKCORE_QUANTUM_DEPTH;
3020 image()->depth=depth;
3021 options()->depth( depth );
3023 size_t Magick::Image::depth ( void ) const
3025 return constImage()->depth;
3028 std::string Magick::Image::directory ( void ) const
3030 if ( constImage()->directory )
3031 return std::string( constImage()->directory );
3033 throwExceptionExplicit( CorruptImageWarning,
3034 "Image does not contain a directory");
3036 return std::string();
3039 // Endianness (little like Intel or big like SPARC) for image
3040 // formats which support endian-specific options.
3041 void Magick::Image::endian ( const Magick::EndianType endian_ )
3044 options()->endian( endian_ );
3045 image()->endian = endian_;
3047 Magick::EndianType Magick::Image::endian ( void ) const
3049 return constImage()->endian;
3052 // EXIF profile (BLOB)
3053 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
3056 if ( exifProfile_.data() != 0 )
3058 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
3059 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
3060 ExceptionInfo exceptionInfo;
3061 GetExceptionInfo( &exceptionInfo );
3062 (void) SetImageProfile( image(), "exif", exif_profile, &exceptionInfo);
3063 exif_profile =DestroyStringInfo( exif_profile );
3064 throwException( exceptionInfo );
3065 (void) DestroyExceptionInfo( &exceptionInfo );
3068 Magick::Blob Magick::Image::exifProfile( void ) const
3070 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
3071 if ( exif_profile == (StringInfo *) NULL)
3072 return Blob( 0, 0 );
3073 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
3077 void Magick::Image::fileName ( const std::string &fileName_ )
3081 fileName_.copy( image()->filename,
3082 sizeof(image()->filename) - 1 );
3083 image()->filename[ fileName_.length() ] = 0; // Null terminate
3085 options()->fileName( fileName_ );
3088 std::string Magick::Image::fileName ( void ) const
3090 return constOptions()->fileName( );
3094 off_t Magick::Image::fileSize ( void ) const
3096 return (off_t) GetBlobSize( constImage() );
3099 // Color to use when drawing inside an object
3100 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3103 options()->fillColor(fillColor_);
3105 Magick::Color Magick::Image::fillColor ( void ) const
3107 return constOptions()->fillColor();
3110 // Rule to use when filling drawn objects
3111 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3114 options()->fillRule(fillRule_);
3116 Magick::FillRule Magick::Image::fillRule ( void ) const
3118 return constOptions()->fillRule();
3121 // Pattern to use while filling drawn objects.
3122 void Magick::Image::fillPattern ( const Image &fillPattern_ )
3125 if(fillPattern_.isValid())
3126 options()->fillPattern( fillPattern_.constImage() );
3128 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3130 Magick::Image Magick::Image::fillPattern ( void ) const
3132 // FIXME: This is inordinately innefficient
3135 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3139 ExceptionInfo exceptionInfo;
3140 GetExceptionInfo( &exceptionInfo );
3141 MagickCore::Image* image =
3142 CloneImage( tmpTexture,
3145 MagickTrue, // orphan
3147 texture.replaceImage( image );
3148 throwException( exceptionInfo );
3149 (void) DestroyExceptionInfo( &exceptionInfo );
3154 // Filter used by zoom
3155 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3158 image()->filter = filterType_;
3160 Magick::FilterTypes Magick::Image::filterType ( void ) const
3162 return constImage()->filter;
3166 void Magick::Image::font ( const std::string &font_ )
3169 options()->font( font_ );
3171 std::string Magick::Image::font ( void ) const
3173 return constOptions()->font( );
3177 void Magick::Image::fontPointsize ( const double pointSize_ )
3180 options()->fontPointsize( pointSize_ );
3182 double Magick::Image::fontPointsize ( void ) const
3184 return constOptions()->fontPointsize( );
3187 // Font type metrics
3188 void Magick::Image::fontTypeMetrics( const std::string &text_,
3189 TypeMetric *metrics )
3191 DrawInfo *drawInfo = options()->drawInfo();
3192 drawInfo->text = const_cast<char *>(text_.c_str());
3193 ExceptionInfo exceptionInfo;
3194 GetExceptionInfo( &exceptionInfo );
3195 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric), &exceptionInfo );
3197 throwException( exceptionInfo );
3198 (void) DestroyExceptionInfo( &exceptionInfo );
3201 // Image format string
3202 std::string Magick::Image::format ( void ) const
3204 ExceptionInfo exceptionInfo;
3205 GetExceptionInfo( &exceptionInfo );
3206 const MagickInfo * magick_info
3207 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3208 throwException( exceptionInfo );
3209 (void) DestroyExceptionInfo( &exceptionInfo );
3211 if (( magick_info != 0 ) &&
3212 ( *magick_info->description != '\0' ))
3213 return std::string(magick_info->description);
3215 throwExceptionExplicit( CorruptImageWarning,
3216 "Unrecognized image magick type" );
3217 return std::string();
3221 double Magick::Image::gamma ( void ) const
3223 return constImage()->gamma;
3226 Magick::Geometry Magick::Image::geometry ( void ) const
3228 if ( constImage()->geometry )
3230 return Geometry(constImage()->geometry);
3233 throwExceptionExplicit( OptionWarning,
3234 "Image does not contain a geometry");
3239 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3242 image()->dispose = (DisposeType) disposeMethod_;
3244 size_t Magick::Image::gifDisposeMethod ( void ) const
3246 // FIXME: It would be better to return an enumeration
3247 return constImage()->dispose;
3250 // ICC ICM color profile (BLOB)
3251 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3253 profile("icm",colorProfile_);
3255 Magick::Blob Magick::Image::iccColorProfile( void ) const
3257 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3258 if ( color_profile == (StringInfo *) NULL)
3259 return Blob( 0, 0 );
3260 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3263 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3266 image()->interlace = interlace_;
3267 options()->interlaceType ( interlace_ );
3269 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3271 return constImage()->interlace;
3274 // IPTC profile (BLOB)
3275 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3278 if ( iptcProfile_.data() != 0 )
3280 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3281 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3282 ExceptionInfo exceptionInfo;
3283 GetExceptionInfo( &exceptionInfo );
3284 (void) SetImageProfile( image(), "iptc", iptc_profile, &exceptionInfo);
3285 iptc_profile =DestroyStringInfo( iptc_profile );
3286 throwException( exceptionInfo );
3287 (void) DestroyExceptionInfo( &exceptionInfo );
3290 Magick::Blob Magick::Image::iptcProfile( void ) const
3292 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3293 if ( iptc_profile == (StringInfo *) NULL)
3294 return Blob( 0, 0 );
3295 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3298 // Does object contain valid image?
3299 void Magick::Image::isValid ( const bool isValid_ )
3304 _imgRef = new ImageRef;
3306 else if ( !isValid() )
3308 // Construct with single-pixel black image to make
3309 // image valid. This is an obvious hack.
3310 size( Geometry(1,1) );
3311 read( "xc:#000000" );
3315 bool Magick::Image::isValid ( void ) const
3317 if ( rows() && columns() )
3324 void Magick::Image::label ( const std::string &label_ )
3327 ExceptionInfo exceptionInfo;
3328 GetExceptionInfo( &exceptionInfo );
3329 SetImageProperty ( image(), "Label", NULL, &exceptionInfo );
3330 if ( label_.length() > 0 )
3331 SetImageProperty ( image(), "Label", label_.c_str(), &exceptionInfo );
3332 throwException( exceptionInfo );
3333 (void) DestroyExceptionInfo( &exceptionInfo );
3335 std::string Magick::Image::label ( void ) const
3337 ExceptionInfo exceptionInfo;
3338 GetExceptionInfo( &exceptionInfo );
3339 const char *value = GetImageProperty( constImage(), "Label", &exceptionInfo );
3340 throwException( exceptionInfo );
3341 (void) DestroyExceptionInfo( &exceptionInfo );
3344 return std::string( value );
3346 return std::string();
3349 void Magick::Image::magick ( const std::string &magick_ )
3353 magick_.copy( image()->magick,
3354 sizeof(image()->magick) - 1 );
3355 image()->magick[ magick_.length() ] = 0;
3357 options()->magick( magick_ );
3359 std::string Magick::Image::magick ( void ) const
3361 if ( *(constImage()->magick) != '\0' )
3362 return std::string(constImage()->magick);
3364 return constOptions()->magick( );
3367 void Magick::Image::matte ( const bool matteFlag_ )
3371 // If matte channel is requested, but image doesn't already have a
3372 // matte channel, then create an opaque matte channel. Likewise, if
3373 // the image already has a matte channel but a matte channel is not
3374 // desired, then set the matte channel to opaque.
3375 ExceptionInfo exceptionInfo;
3376 GetExceptionInfo( &exceptionInfo );
3377 if ((matteFlag_ && !constImage()->matte) ||
3378 (constImage()->matte && !matteFlag_))
3379 SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo);
3380 throwException( exceptionInfo );
3381 (void) DestroyExceptionInfo( &exceptionInfo );
3383 image()->matte = (MagickBooleanType) matteFlag_;
3385 bool Magick::Image::matte ( void ) const
3387 if ( constImage()->matte )
3393 void Magick::Image::matteColor ( const Color &matteColor_ )
3397 if ( matteColor_.isValid() )
3399 image()->matte_color = matteColor_;
3400 options()->matteColor( matteColor_ );
3404 // Set to default matte color
3405 Color tmpColor( "#BDBDBD" );
3406 image()->matte_color = tmpColor;
3407 options()->matteColor( tmpColor );
3410 Magick::Color Magick::Image::matteColor ( void ) const
3412 return Color( ClampToQuantum( constImage()->matte_color.red ),
3413 ClampToQuantum( constImage()->matte_color.green ),
3414 ClampToQuantum( constImage()->matte_color.blue ) );
3417 double Magick::Image::meanErrorPerPixel ( void ) const
3419 return(constImage()->error.mean_error_per_pixel);
3422 // Image modulus depth (minimum number of bits required to support
3423 // red/green/blue components without loss of accuracy)
3424 void Magick::Image::modulusDepth ( const size_t depth_ )
3427 ExceptionInfo exceptionInfo;
3428 GetExceptionInfo( &exceptionInfo );
3429 SetImageDepth( image(), depth_, &exceptionInfo );
3430 throwException( exceptionInfo );
3431 (void) DestroyExceptionInfo( &exceptionInfo );
3432 options()->depth( depth_ );
3434 size_t Magick::Image::modulusDepth ( void ) const
3436 ExceptionInfo exceptionInfo;
3437 GetExceptionInfo( &exceptionInfo );
3438 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3439 throwException( exceptionInfo );
3440 (void) DestroyExceptionInfo( &exceptionInfo );
3444 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3447 options()->monochrome( monochromeFlag_ );
3449 bool Magick::Image::monochrome ( void ) const
3451 return constOptions()->monochrome( );
3454 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3456 if ( constImage()->montage )
3457 return Magick::Geometry(constImage()->montage);
3459 throwExceptionExplicit( CorruptImageWarning,
3460 "Image does not contain a montage" );
3462 return Magick::Geometry();
3465 double Magick::Image::normalizedMaxError ( void ) const
3467 return(constImage()->error.normalized_maximum_error);
3470 double Magick::Image::normalizedMeanError ( void ) const
3472 return constImage()->error.normalized_mean_error;
3475 // Image orientation
3476 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3479 image()->orientation = orientation_;
3481 Magick::OrientationType Magick::Image::orientation ( void ) const
3483 return constImage()->orientation;
3486 void Magick::Image::penColor ( const Color &penColor_ )
3489 options()->fillColor(penColor_);
3490 options()->strokeColor(penColor_);
3492 Magick::Color Magick::Image::penColor ( void ) const
3494 return constOptions()->fillColor();
3497 void Magick::Image::penTexture ( const Image &penTexture_ )
3500 if(penTexture_.isValid())
3501 options()->fillPattern( penTexture_.constImage() );
3503 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3506 Magick::Image Magick::Image::penTexture ( void ) const
3508 // FIXME: This is inordinately innefficient
3511 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3515 ExceptionInfo exceptionInfo;
3516 GetExceptionInfo( &exceptionInfo );
3517 MagickCore::Image* image =
3518 CloneImage( tmpTexture,
3521 MagickTrue, // orphan
3523 texture.replaceImage( image );
3524 throwException( exceptionInfo );
3525 (void) DestroyExceptionInfo( &exceptionInfo );
3530 // Set the color of a pixel.
3531 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3532 const Color &color_ )
3534 // Test arguments to ensure they are within the image.
3535 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3536 throwExceptionExplicit( OptionError,
3537 "Access outside of image boundary" );
3541 // Set image to DirectClass
3542 classType( DirectClass );
3545 Pixels pixels(*this);
3547 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3548 PixelInfo packet = color_;
3549 MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel);
3550 // Tell ImageMagick that pixels have been updated
3556 // Get the color of a pixel
3557 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3558 const ssize_t y_ ) const
3560 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3564 MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3565 return Color( packet );
3568 return Color(); // invalid
3571 // Preferred size and location of an image canvas.
3572 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3575 options()->page( pageSize_ );
3576 image()->page = pageSize_;
3578 Magick::Geometry Magick::Image::page ( void ) const
3580 return Geometry( constImage()->page.width,
3581 constImage()->page.height,
3582 AbsoluteValue(constImage()->page.x),
3583 AbsoluteValue(constImage()->page.y),
3584 constImage()->page.x < 0 ? true : false,
3585 constImage()->page.y < 0 ? true : false);
3588 // Add a named profile to an image or remove a named profile by
3589 // passing an empty Blob (use default Blob constructor).
3591 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3592 void Magick::Image::profile( const std::string name_,
3593 const Magick::Blob &profile_ )
3596 ExceptionInfo exceptionInfo;
3597 GetExceptionInfo( &exceptionInfo );
3598 ssize_t result = ProfileImage( image(), name_.c_str(),
3599 (unsigned char *)profile_.data(),
3600 profile_.length(), &exceptionInfo);
3602 throwException( exceptionInfo );
3603 (void) DestroyExceptionInfo( &exceptionInfo );
3607 // Retrieve a named profile from the image.
3609 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3610 // an existing generic profile name.
3611 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3613 const MagickCore::Image* image = constImage();
3615 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3617 if ( profile != (StringInfo *) NULL)
3618 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3621 Image temp_image = *this;
3622 temp_image.write( &blob, name_ );
3626 void Magick::Image::quality ( const size_t quality_ )
3629 image()->quality = quality_;
3630 options()->quality( quality_ );
3632 size_t Magick::Image::quality ( void ) const
3634 return constImage()->quality;
3637 void Magick::Image::quantizeColors ( const size_t colors_ )
3640 options()->quantizeColors( colors_ );
3642 size_t Magick::Image::quantizeColors ( void ) const
3644 return constOptions()->quantizeColors( );
3647 void Magick::Image::quantizeColorSpace
3648 ( const Magick::ColorspaceType colorSpace_ )
3651 options()->quantizeColorSpace( colorSpace_ );
3653 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3655 return constOptions()->quantizeColorSpace( );
3658 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3661 options()->quantizeDither( ditherFlag_ );
3663 bool Magick::Image::quantizeDither ( void ) const
3665 return constOptions()->quantizeDither( );
3668 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3671 options()->quantizeTreeDepth( treeDepth_ );
3673 size_t Magick::Image::quantizeTreeDepth ( void ) const
3675 return constOptions()->quantizeTreeDepth( );
3678 void Magick::Image::renderingIntent
3679 ( const Magick::RenderingIntent renderingIntent_ )
3682 image()->rendering_intent = renderingIntent_;
3684 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3686 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3689 void Magick::Image::resolutionUnits
3690 ( const Magick::ResolutionType resolutionUnits_ )
3693 image()->units = resolutionUnits_;
3694 options()->resolutionUnits( resolutionUnits_ );
3696 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3698 return constOptions()->resolutionUnits( );
3701 void Magick::Image::scene ( const size_t scene_ )
3704 image()->scene = scene_;
3706 size_t Magick::Image::scene ( void ) const
3708 return constImage()->scene;
3711 std::string Magick::Image::signature ( const bool force_ ) const
3713 Lock( &_imgRef->_mutexLock );
3715 // Re-calculate image signature if necessary
3716 ExceptionInfo exceptionInfo;
3717 GetExceptionInfo( &exceptionInfo );
3719 !GetImageProperty(constImage(), "Signature", &exceptionInfo) ||
3720 constImage()->taint )
3722 SignatureImage( const_cast<MagickCore::Image *>(constImage()), &exceptionInfo );
3725 const char *property = GetImageProperty(constImage(), "Signature",
3727 throwException( exceptionInfo );
3728 (void) DestroyExceptionInfo( &exceptionInfo );
3730 return std::string( property );
3733 void Magick::Image::size ( const Geometry &geometry_ )
3736 options()->size( geometry_ );
3737 image()->rows = geometry_.height();
3738 image()->columns = geometry_.width();
3740 Magick::Geometry Magick::Image::size ( void ) const
3742 return Magick::Geometry( constImage()->columns, constImage()->rows );
3746 void Magick::Image::splice( const Geometry &geometry_ )
3748 RectangleInfo spliceInfo = geometry_;
3749 ExceptionInfo exceptionInfo;
3750 GetExceptionInfo( &exceptionInfo );
3751 MagickCore::Image* newImage =
3752 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3753 replaceImage( newImage );
3754 throwException( exceptionInfo );
3755 (void) DestroyExceptionInfo( &exceptionInfo );
3758 // Obtain image statistics. Statistics are normalized to the range of
3759 // 0.0 to 1.0 and are output to the specified ImageStatistics
3761 void Magick::Image::statistics ( ImageStatistics *statistics )
3767 ExceptionInfo exceptionInfo;
3768 GetExceptionInfo( &exceptionInfo );
3770 ChannelType channel_mask = SetPixelChannelMask( image(), RedChannel);
3771 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3772 statistics->red.minimum=minimum;
3773 statistics->red.maximum=maximum;
3774 (void) GetImageMean( image(),&statistics->red.mean,
3775 &statistics->red.standard_deviation,&exceptionInfo);
3776 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3777 &statistics->red.skewness,&exceptionInfo);
3778 (void) SetPixelChannelMapMask( image(), channel_mask );
3780 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3781 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3782 statistics->green.minimum=minimum;
3783 statistics->green.maximum=maximum;
3784 (void) GetImageMean( image(),&statistics->green.mean,
3785 &statistics->green.standard_deviation,&exceptionInfo);
3786 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3787 &statistics->green.skewness,&exceptionInfo);
3788 (void) SetPixelChannelMapMask( image(), channel_mask );
3790 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3791 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3792 statistics->blue.minimum=minimum;
3793 statistics->blue.maximum=maximum;
3794 (void) GetImageMean( image(),&statistics->blue.mean,
3795 &statistics->blue.standard_deviation,&exceptionInfo);
3796 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3797 &statistics->blue.skewness,&exceptionInfo);
3798 (void) SetPixelChannelMapMask( image(), channel_mask );
3800 channel_mask = SetPixelChannelMask( image(), AlphaChannel);
3801 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3802 statistics->alpha.minimum=minimum;
3803 statistics->alpha.maximum=maximum;
3804 (void) GetImageMean( image(),&statistics->alpha.mean,
3805 &statistics->alpha.standard_deviation,&exceptionInfo);
3806 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3807 &statistics->alpha.skewness,&exceptionInfo);
3808 (void) SetPixelChannelMapMask( image(), channel_mask );
3810 throwException( exceptionInfo );
3811 (void) DestroyExceptionInfo( &exceptionInfo );
3814 // Strip strips an image of all profiles and comments.
3815 void Magick::Image::strip ( void )
3818 ExceptionInfo exceptionInfo;
3819 GetExceptionInfo( &exceptionInfo );
3820 StripImage( image(), &exceptionInfo );
3821 throwException( exceptionInfo );
3822 (void) DestroyExceptionInfo( &exceptionInfo );
3825 // enabled/disable stroke anti-aliasing
3826 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3829 options()->strokeAntiAlias(flag_);
3831 bool Magick::Image::strokeAntiAlias ( void ) const
3833 return constOptions()->strokeAntiAlias();
3836 // Color to use when drawing object outlines
3837 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3840 options()->strokeColor(strokeColor_);
3842 Magick::Color Magick::Image::strokeColor ( void ) const
3844 return constOptions()->strokeColor();
3847 // dash pattern for drawing vector objects (default one)
3848 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3851 options()->strokeDashArray( strokeDashArray_ );
3854 const double* Magick::Image::strokeDashArray ( void ) const
3856 return constOptions()->strokeDashArray( );
3859 // dash offset for drawing vector objects (default one)
3860 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3863 options()->strokeDashOffset( strokeDashOffset_ );
3866 double Magick::Image::strokeDashOffset ( void ) const
3868 return constOptions()->strokeDashOffset( );
3871 // Specify the shape to be used at the end of open subpaths when they
3872 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3874 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3877 options()->strokeLineCap( lineCap_ );
3879 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3881 return constOptions()->strokeLineCap( );
3884 // Specify the shape to be used at the corners of paths (or other
3885 // vector shapes) when they are stroked. Values of LineJoin are
3886 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3887 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3890 options()->strokeLineJoin( lineJoin_ );
3892 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3894 return constOptions()->strokeLineJoin( );
3897 // Specify miter limit. When two line segments meet at a sharp angle
3898 // and miter joins have been specified for 'lineJoin', it is possible
3899 // for the miter to extend far beyond the thickness of the line
3900 // stroking the path. The miterLimit' imposes a limit on the ratio of
3901 // the miter length to the 'lineWidth'. The default value of this
3903 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3906 options()->strokeMiterLimit( strokeMiterLimit_ );
3908 size_t Magick::Image::strokeMiterLimit ( void ) const
3910 return constOptions()->strokeMiterLimit( );
3913 // Pattern to use while stroking drawn objects.
3914 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3917 if(strokePattern_.isValid())
3918 options()->strokePattern( strokePattern_.constImage() );
3920 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3922 Magick::Image Magick::Image::strokePattern ( void ) const
3924 // FIXME: This is inordinately innefficient
3927 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3931 ExceptionInfo exceptionInfo;
3932 GetExceptionInfo( &exceptionInfo );
3933 MagickCore::Image* image =
3934 CloneImage( tmpTexture,
3937 MagickTrue, // orphan
3939 throwException( exceptionInfo );
3940 (void) DestroyExceptionInfo( &exceptionInfo );
3941 texture.replaceImage( image );
3946 // Stroke width for drawing lines, circles, ellipses, etc.
3947 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3950 options()->strokeWidth( strokeWidth_ );
3952 double Magick::Image::strokeWidth ( void ) const
3954 return constOptions()->strokeWidth( );
3957 void Magick::Image::subImage ( const size_t subImage_ )
3960 options()->subImage( subImage_ );
3962 size_t Magick::Image::subImage ( void ) const
3964 return constOptions()->subImage( );
3967 void Magick::Image::subRange ( const size_t subRange_ )
3970 options()->subRange( subRange_ );
3972 size_t Magick::Image::subRange ( void ) const
3974 return constOptions()->subRange( );
3977 // Annotation text encoding (e.g. "UTF-16")
3978 void Magick::Image::textEncoding ( const std::string &encoding_ )
3981 options()->textEncoding( encoding_ );
3983 std::string Magick::Image::textEncoding ( void ) const
3985 return constOptions()->textEncoding( );
3988 size_t Magick::Image::totalColors ( void )
3990 ExceptionInfo exceptionInfo;
3991 GetExceptionInfo( &exceptionInfo );
3992 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3993 throwException( exceptionInfo );
3994 (void) DestroyExceptionInfo( &exceptionInfo );
3998 // Origin of coordinate system to use when annotating with text or drawing
3999 void Magick::Image::transformOrigin ( const double x_, const double y_ )
4002 options()->transformOrigin( x_, y_ );
4005 // Rotation to use when annotating with text or drawing
4006 void Magick::Image::transformRotation ( const double angle_ )
4009 options()->transformRotation( angle_ );
4012 // Reset transformation parameters to default
4013 void Magick::Image::transformReset ( void )
4016 options()->transformReset();
4019 // Scale to use when annotating with text or drawing
4020 void Magick::Image::transformScale ( const double sx_, const double sy_ )
4023 options()->transformScale( sx_, sy_ );
4026 // Skew to use in X axis when annotating with text or drawing
4027 void Magick::Image::transformSkewX ( const double skewx_ )
4030 options()->transformSkewX( skewx_ );
4033 // Skew to use in Y axis when annotating with text or drawing
4034 void Magick::Image::transformSkewY ( const double skewy_ )
4037 options()->transformSkewY( skewy_ );
4040 // Image representation type
4041 Magick::ImageType Magick::Image::type ( void ) const
4044 ExceptionInfo exceptionInfo;
4045 GetExceptionInfo( &exceptionInfo );
4046 ImageType image_type = constOptions()->type();
4047 if ( image_type == UndefinedType )
4048 image_type= GetImageType( constImage(), &exceptionInfo);
4049 throwException( exceptionInfo );
4050 (void) DestroyExceptionInfo( &exceptionInfo );
4053 void Magick::Image::type ( const Magick::ImageType type_)
4055 ExceptionInfo exceptionInfo;
4056 GetExceptionInfo( &exceptionInfo );
4058 options()->type( type_ );
4059 SetImageType( image(), type_, &exceptionInfo );
4060 throwException( exceptionInfo );
4061 (void) DestroyExceptionInfo( &exceptionInfo );
4064 void Magick::Image::verbose ( const bool verboseFlag_ )
4067 options()->verbose( verboseFlag_ );
4069 bool Magick::Image::verbose ( void ) const
4071 return constOptions()->verbose( );
4074 void Magick::Image::view ( const std::string &view_ )
4077 options()->view( view_ );
4079 std::string Magick::Image::view ( void ) const
4081 return constOptions()->view( );
4084 // Virtual pixel method
4085 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
4088 ExceptionInfo exceptionInfo;
4089 GetExceptionInfo( &exceptionInfo );
4090 SetImageVirtualPixelMethod( image(), virtual_pixel_method_, &exceptionInfo );
4091 throwException( exceptionInfo );
4092 (void) DestroyExceptionInfo( &exceptionInfo );
4094 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
4096 return GetImageVirtualPixelMethod( constImage() );
4099 void Magick::Image::x11Display ( const std::string &display_ )
4102 options()->x11Display( display_ );
4104 std::string Magick::Image::x11Display ( void ) const
4106 return constOptions()->x11Display( );
4109 double Magick::Image::xResolution ( void ) const
4111 return constImage()->resolution.x;
4113 double Magick::Image::yResolution ( void ) const
4115 return constImage()->resolution.y;
4119 Magick::Image::Image( const Image & image_ )
4120 : _imgRef(image_._imgRef)
4122 Lock( &_imgRef->_mutexLock );
4124 // Increase reference count
4125 ++_imgRef->_refCount;
4128 // Assignment operator
4129 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
4131 if( this != &image_ )
4134 Lock( &image_._imgRef->_mutexLock );
4135 ++image_._imgRef->_refCount;
4138 bool doDelete = false;
4140 Lock( &_imgRef->_mutexLock );
4141 if ( --_imgRef->_refCount == 0 )
4147 // Delete old image reference with associated image and options.
4151 // Use new image reference
4152 _imgRef = image_._imgRef;
4158 //////////////////////////////////////////////////////////////////////
4160 // Low-level Pixel Access Routines
4162 // Also see the Pixels class, which provides support for multiple
4163 // cache views. The low-level pixel access routines in the Image
4164 // class are provided in order to support backward compatability.
4166 //////////////////////////////////////////////////////////////////////
4168 // Transfers read-only pixels from the image to the pixel cache as
4169 // defined by the specified region
4170 const Magick::Quantum* Magick::Image::getConstPixels
4171 ( const ssize_t x_, const ssize_t y_,
4172 const size_t columns_,
4173 const size_t rows_ ) const
4175 ExceptionInfo exceptionInfo;
4176 GetExceptionInfo( &exceptionInfo );
4177 const Quantum* p = (*GetVirtualPixels)( constImage(),
4181 throwException( exceptionInfo );
4182 (void) DestroyExceptionInfo( &exceptionInfo );
4186 // Obtain read-only pixel associated pixels channels
4187 const void* Magick::Image::getConstMetacontent ( void ) const
4189 const void* result = GetVirtualMetacontent( constImage() );
4192 throwImageException();
4197 // Obtain image pixel associated pixels channels
4198 void* Magick::Image::getMetacontent ( void )
4200 void* result = GetAuthenticMetacontent( image() );
4203 throwImageException();
4208 // Transfers pixels from the image to the pixel cache as defined
4209 // by the specified region. Modified pixels may be subsequently
4210 // transferred back to the image via syncPixels.
4211 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4212 const size_t columns_,
4213 const size_t rows_ )
4216 ExceptionInfo exceptionInfo;
4217 GetExceptionInfo( &exceptionInfo );
4218 Quantum* result = (*GetAuthenticPixels)( image(),
4220 columns_, rows_, &exceptionInfo );
4221 throwException( exceptionInfo );
4222 (void) DestroyExceptionInfo( &exceptionInfo );
4227 // Allocates a pixel cache region to store image pixels as defined
4228 // by the region rectangle. This area is subsequently transferred
4229 // from the pixel cache to the image via syncPixels.
4230 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4231 const size_t columns_,
4232 const size_t rows_ )
4235 ExceptionInfo exceptionInfo;
4236 GetExceptionInfo( &exceptionInfo );
4237 Quantum* result = (*QueueAuthenticPixels)( image(),
4239 columns_, rows_, &exceptionInfo );
4240 throwException( exceptionInfo );
4241 (void) DestroyExceptionInfo( &exceptionInfo );
4246 // Transfers the image cache pixels to the image.
4247 void Magick::Image::syncPixels ( void )
4249 ExceptionInfo exceptionInfo;
4250 GetExceptionInfo( &exceptionInfo );
4251 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4252 throwException( exceptionInfo );
4253 (void) DestroyExceptionInfo( &exceptionInfo );
4256 // Transfers one or more pixel components from a buffer or file
4257 // into the image pixel cache of an image.
4258 // Used to support image decoders.
4259 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4260 const unsigned char *source_ )
4265 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4266 ExceptionInfo exceptionInfo;
4267 GetExceptionInfo( &exceptionInfo );
4268 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4269 quantum_,source_, &exceptionInfo);
4270 throwException( exceptionInfo );
4271 (void) DestroyExceptionInfo( &exceptionInfo );
4272 quantum_info=DestroyQuantumInfo(quantum_info);
4275 // Transfers one or more pixel components from the image pixel
4276 // cache to a buffer or file.
4277 // Used to support image encoders.
4278 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4279 unsigned char *destination_ )
4284 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4285 ExceptionInfo exceptionInfo;
4286 GetExceptionInfo( &exceptionInfo );
4287 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4288 quantum_,destination_, &exceptionInfo);
4289 quantum_info=DestroyQuantumInfo(quantum_info);
4290 throwException( exceptionInfo );
4291 (void) DestroyExceptionInfo( &exceptionInfo );
4294 /////////////////////////////////////////////////////////////////////
4296 // No end-user methods beyond this point
4298 /////////////////////////////////////////////////////////////////////
4302 // Construct using existing image and default options
4304 Magick::Image::Image ( MagickCore::Image* image_ )
4305 : _imgRef(new ImageRef( image_))
4309 // Get Magick::Options*
4310 Magick::Options* Magick::Image::options( void )
4312 return _imgRef->options();
4314 const Magick::Options* Magick::Image::constOptions( void ) const
4316 return _imgRef->options();
4319 // Get MagickCore::Image*
4320 MagickCore::Image*& Magick::Image::image( void )
4322 return _imgRef->image();
4324 const MagickCore::Image* Magick::Image::constImage( void ) const
4326 return _imgRef->image();
4330 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4332 return _imgRef->options()->imageInfo();
4334 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4336 return _imgRef->options()->imageInfo();
4339 // Get QuantizeInfo *
4340 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4342 return _imgRef->options()->quantizeInfo();
4344 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4346 return _imgRef->options()->quantizeInfo();
4350 // Replace current image
4352 MagickCore::Image * Magick::Image::replaceImage
4353 ( MagickCore::Image* replacement_ )
4355 MagickCore::Image* image;
4358 image = replacement_;
4361 ExceptionInfo exceptionInfo;
4362 GetExceptionInfo( &exceptionInfo );
4363 image = AcquireImage(constImageInfo(), &exceptionInfo);
4364 throwException( exceptionInfo );
4365 (void) DestroyExceptionInfo( &exceptionInfo );
4369 Lock( &_imgRef->_mutexLock );
4371 if ( _imgRef->_refCount == 1 )
4373 // We own the image, just replace it, and de-register
4375 _imgRef->image(image);
4379 // We don't own the image, dereference and replace with copy
4380 --_imgRef->_refCount;
4381 _imgRef = new ImageRef( image, constOptions() );
4385 return _imgRef->_image;
4389 // Prepare to modify image or image options
4390 // Replace current image and options with copy if reference count > 1
4392 void Magick::Image::modifyImage( void )
4395 Lock( &_imgRef->_mutexLock );
4396 if ( _imgRef->_refCount == 1 )
4398 // De-register image and return
4404 ExceptionInfo exceptionInfo;
4405 GetExceptionInfo( &exceptionInfo );
4406 replaceImage( CloneImage( image(),
4409 MagickTrue, // orphan
4411 throwException( exceptionInfo );
4412 (void) DestroyExceptionInfo( &exceptionInfo );
4417 // Test for an ImageMagick reported error and throw exception if one
4418 // has been reported. Secretly resets image->exception back to default
4419 // state even though this method is const.
4421 void Magick::Image::throwImageException( void ) const
4423 // Throw C++ exception while resetting Image exception to default state
4426 // Register image with image registry or obtain registration id
4427 ssize_t Magick::Image::registerId( void )
4429 Lock( &_imgRef->_mutexLock );
4430 if( _imgRef->id() < 0 )
4432 char id[MaxTextExtent];
4433 ExceptionInfo exceptionInfo;
4434 GetExceptionInfo( &exceptionInfo );
4435 _imgRef->id(_imgRef->id()+1);
4436 sprintf(id,"%.20g\n",(double) _imgRef->id());
4437 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4438 throwException( exceptionInfo );
4439 (void) DestroyExceptionInfo( &exceptionInfo );
4441 return _imgRef->id();
4444 // Unregister image from image registry
4445 void Magick::Image::unregisterId( void )
4452 // Create a local wrapper around MagickCoreTerminus
4457 void MagickPlusPlusDestroyMagick(void);
4461 void Magick::MagickPlusPlusDestroyMagick(void)
4463 if (magick_initialized)
4465 magick_initialized=false;
4466 MagickCore::MagickCoreTerminus();
4470 // C library initialization routine
4471 void MagickPPExport Magick::InitializeMagick(const char *path_)
4473 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4474 if (!magick_initialized)
4475 magick_initialized=true;
4479 // Cleanup class to ensure that ImageMagick singletons are destroyed
4480 // so as to avoid any resemblence to a memory leak (which seems to
4489 MagickCleanUp( void );
4490 ~MagickCleanUp( void );
4493 // The destructor for this object is invoked when the destructors for
4494 // static objects in this translation unit are invoked.
4495 static MagickCleanUp magickCleanUpGuard;
4498 Magick::MagickCleanUp::MagickCleanUp ( void )
4500 // Don't even think about invoking InitializeMagick here!
4503 Magick::MagickCleanUp::~MagickCleanUp ( void )
4505 MagickPlusPlusDestroyMagick();