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_, image()->bias, &exceptionInfo);
304 replaceImage( newImage );
305 throwException( exceptionInfo );
306 (void) DestroyExceptionInfo( &exceptionInfo );
309 // Local adaptive threshold image
310 // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
311 // Width x height define the size of the pixel neighborhood
312 // offset = constant to subtract from pixel neighborhood mean
313 void Magick::Image::adaptiveThreshold ( const size_t width_,
314 const size_t height_,
315 const ssize_t offset_ )
317 ExceptionInfo exceptionInfo;
318 GetExceptionInfo( &exceptionInfo );
319 MagickCore::Image* newImage =
320 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
321 replaceImage( newImage );
322 throwException( exceptionInfo );
323 (void) DestroyExceptionInfo( &exceptionInfo );
326 // Add noise to image
327 void Magick::Image::addNoise( const NoiseType noiseType_ )
329 ExceptionInfo exceptionInfo;
330 GetExceptionInfo( &exceptionInfo );
331 MagickCore::Image* newImage =
332 AddNoiseImage ( image(),
335 replaceImage( newImage );
336 throwException( exceptionInfo );
337 (void) DestroyExceptionInfo( &exceptionInfo );
340 void Magick::Image::addNoiseChannel( const ChannelType channel_,
341 const NoiseType noiseType_ )
343 ExceptionInfo exceptionInfo;
344 GetExceptionInfo( &exceptionInfo );
345 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
346 MagickCore::Image* newImage =
347 AddNoiseImage ( image(),
350 (void) SetPixelChannelMap( image(), channel_mask );
351 replaceImage( newImage );
352 throwException( exceptionInfo );
353 (void) DestroyExceptionInfo( &exceptionInfo );
356 // Affine Transform image
357 void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
359 ExceptionInfo exceptionInfo;
360 GetExceptionInfo( &exceptionInfo );
362 AffineMatrix _affine;
363 _affine.sx = affine_.sx();
364 _affine.sy = affine_.sy();
365 _affine.rx = affine_.rx();
366 _affine.ry = affine_.ry();
367 _affine.tx = affine_.tx();
368 _affine.ty = affine_.ty();
370 MagickCore::Image* newImage =
371 AffineTransformImage( image(), &_affine, &exceptionInfo);
372 replaceImage( newImage );
373 throwException( exceptionInfo );
374 (void) DestroyExceptionInfo( &exceptionInfo );
377 // Annotate using specified text, and placement location
378 void Magick::Image::annotate ( const std::string &text_,
379 const Geometry &location_ )
381 annotate ( text_, location_, NorthWestGravity, 0.0 );
383 // Annotate using specified text, bounding area, and placement gravity
384 void Magick::Image::annotate ( const std::string &text_,
385 const Geometry &boundingArea_,
386 const GravityType gravity_ )
388 annotate ( text_, boundingArea_, gravity_, 0.0 );
390 // Annotate with text using specified text, bounding area, placement
391 // gravity, and rotation.
392 void Magick::Image::annotate ( const std::string &text_,
393 const Geometry &boundingArea_,
394 const GravityType gravity_,
395 const double degrees_ )
400 = options()->drawInfo();
402 drawInfo->text = const_cast<char *>(text_.c_str());
404 char boundingArea[MaxTextExtent];
406 drawInfo->geometry = 0;
407 if ( boundingArea_.isValid() ){
408 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
410 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
411 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
415 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
418 drawInfo->geometry = boundingArea;
421 drawInfo->gravity = gravity_;
423 AffineMatrix oaffine = drawInfo->affine;
424 if ( degrees_ != 0.0)
434 AffineMatrix current = drawInfo->affine;
435 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
436 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
437 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
438 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
440 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
441 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
442 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
443 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
444 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
448 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_, image()->bias, &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_, image()->bias, &exceptionInfo);
504 (void) SetPixelChannelMap( 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 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
529 ExceptionInfo exceptionInfo;
530 GetExceptionInfo( &exceptionInfo );
531 SeparateImage ( image(), &exceptionInfo );
532 throwException( exceptionInfo );
533 (void) DestroyExceptionInfo( &exceptionInfo );
534 (void) SetPixelChannelMap( image(), channel_mask );
537 // Set or obtain modulus channel depth
538 void Magick::Image::channelDepth ( const size_t depth_ )
541 SetImageDepth( image(), depth_);
542 throwImageException();
544 size_t Magick::Image::channelDepth ( )
546 size_t channel_depth;
548 ExceptionInfo exceptionInfo;
549 GetExceptionInfo( &exceptionInfo );
550 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
551 throwException( exceptionInfo );
552 (void) DestroyExceptionInfo( &exceptionInfo );
553 return channel_depth;
557 // Charcoal-effect image
558 void Magick::Image::charcoal( const double radius_, const double sigma_ )
560 ExceptionInfo exceptionInfo;
561 GetExceptionInfo( &exceptionInfo );
562 MagickCore::Image* newImage =
563 CharcoalImage( image(), radius_, sigma_, image()->bias, &exceptionInfo );
564 replaceImage( newImage );
565 throwException( exceptionInfo );
566 (void) DestroyExceptionInfo( &exceptionInfo );
570 void Magick::Image::chop( const Geometry &geometry_ )
572 RectangleInfo chopInfo = geometry_;
573 ExceptionInfo exceptionInfo;
574 GetExceptionInfo( &exceptionInfo );
575 MagickCore::Image* newImage =
576 ChopImage( image(), &chopInfo, &exceptionInfo);
577 replaceImage( newImage );
578 throwException( exceptionInfo );
579 (void) DestroyExceptionInfo( &exceptionInfo );
582 // contains one or more color corrections and applies the correction to the
584 void Magick::Image::cdl ( const std::string &cdl_ )
587 ExceptionInfo exceptionInfo;
588 GetExceptionInfo( &exceptionInfo );
589 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
590 throwException( exceptionInfo );
591 (void) DestroyExceptionInfo( &exceptionInfo );
595 void Magick::Image::colorize ( const unsigned int alphaRed_,
596 const unsigned int alphaGreen_,
597 const unsigned int alphaBlue_,
598 const Color &penColor_ )
600 if ( !penColor_.isValid() )
602 throwExceptionExplicit( OptionError,
603 "Pen color argument is invalid");
606 char blend[MaxTextExtent];
607 FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
609 ExceptionInfo exceptionInfo;
610 GetExceptionInfo( &exceptionInfo );
612 GetPixelInfo(image(),&target);
613 PixelInfo pixel=static_cast<PixelInfo>(penColor_);
614 target.red=pixel.red;
615 target.green=pixel.green;
616 target.blue=pixel.blue;
617 target.alpha=pixel.alpha;
618 MagickCore::Image* newImage =
619 ColorizeImage ( image(), blend, &target, &exceptionInfo );
620 replaceImage( newImage );
621 throwException( exceptionInfo );
622 (void) DestroyExceptionInfo( &exceptionInfo );
624 void Magick::Image::colorize ( const unsigned int alpha_,
625 const Color &penColor_ )
627 colorize( alpha_, alpha_, alpha_, penColor_ );
630 // Apply a color matrix to the image channels. The user supplied
631 // matrix may be of order 1 to 6 (1x1 through 6x6).
632 void Magick::Image::colorMatrix (const size_t order_,
633 const double *color_matrix_)
638 ExceptionInfo exceptionInfo;
639 GetExceptionInfo( &exceptionInfo );
640 kernel_info=AcquireKernelInfo((const char *) NULL);
641 kernel_info->width=order_;
642 kernel_info->height=order_;
643 kernel_info->values=(double *) color_matrix_;
644 MagickCore::Image* newImage =
645 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
646 kernel_info->values=(double *) NULL;
647 kernel_info=DestroyKernelInfo(kernel_info);
648 replaceImage( newImage );
649 throwException( exceptionInfo );
650 (void) DestroyExceptionInfo( &exceptionInfo );
653 // Compare current image with another image
654 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
655 // in the current image. False is returned if the images are identical.
656 bool Magick::Image::compare ( const Image &reference_ )
658 ExceptionInfo exceptionInfo;
659 GetExceptionInfo( &exceptionInfo );
661 Image ref = reference_;
664 static_cast<bool>(IsImagesEqual(image(), ref.image(), &exceptionInfo));
665 throwException( exceptionInfo );
666 (void) DestroyExceptionInfo( &exceptionInfo );
670 // Composite two images
671 void Magick::Image::composite ( const Image &compositeImage_,
672 const ssize_t xOffset_,
673 const ssize_t yOffset_,
674 const CompositeOperator compose_ )
676 // Image supplied as compositeImage is composited with current image and
677 // results in updating current image.
680 ExceptionInfo exceptionInfo;
681 GetExceptionInfo( &exceptionInfo );
682 CompositeImage( image(),
684 compositeImage_.constImage(),
686 yOffset_, &exceptionInfo );
687 throwException( exceptionInfo );
688 (void) DestroyExceptionInfo( &exceptionInfo );
690 void Magick::Image::composite ( const Image &compositeImage_,
691 const Geometry &offset_,
692 const CompositeOperator compose_ )
696 ssize_t x = offset_.xOff();
697 ssize_t y = offset_.yOff();
698 size_t width = columns();
699 size_t height = rows();
701 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
705 ExceptionInfo exceptionInfo;
706 GetExceptionInfo( &exceptionInfo );
707 CompositeImage( image(),
709 compositeImage_.constImage(),
710 x, y, &exceptionInfo );
711 throwException( exceptionInfo );
712 (void) DestroyExceptionInfo( &exceptionInfo );
714 void Magick::Image::composite ( const Image &compositeImage_,
715 const GravityType gravity_,
716 const CompositeOperator compose_ )
720 RectangleInfo geometry;
722 SetGeometry(compositeImage_.constImage(), &geometry);
723 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
725 ExceptionInfo exceptionInfo;
726 GetExceptionInfo( &exceptionInfo );
727 CompositeImage( image(),
729 compositeImage_.constImage(),
730 geometry.x, geometry.y, &exceptionInfo );
731 throwException( exceptionInfo );
732 (void) DestroyExceptionInfo( &exceptionInfo );
736 void Magick::Image::contrast ( const size_t sharpen_ )
739 ExceptionInfo exceptionInfo;
740 GetExceptionInfo( &exceptionInfo );
741 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
742 throwException( exceptionInfo );
743 (void) DestroyExceptionInfo( &exceptionInfo );
746 // Convolve image. Applies a general image convolution kernel to the image.
747 // order_ represents the number of columns and rows in the filter kernel.
748 // kernel_ is an array of doubles representing the convolution kernel.
749 void Magick::Image::convolve ( const size_t order_,
750 const double *kernel_ )
755 ExceptionInfo exceptionInfo;
756 GetExceptionInfo( &exceptionInfo );
757 kernel_info=AcquireKernelInfo((const char *) NULL);
758 kernel_info->width=order_;
759 kernel_info->height=order_;
760 kernel_info->values=(double *) kernel_;
761 kernel_info->bias=image()->bias;
762 MagickCore::Image* newImage =
763 ConvolveImage ( image(), kernel_info, &exceptionInfo );
764 kernel_info->values=(double *) NULL;
765 kernel_info=DestroyKernelInfo(kernel_info);
766 replaceImage( newImage );
767 throwException( exceptionInfo );
768 (void) DestroyExceptionInfo( &exceptionInfo );
772 void Magick::Image::crop ( const Geometry &geometry_ )
774 RectangleInfo cropInfo = geometry_;
775 ExceptionInfo exceptionInfo;
776 GetExceptionInfo( &exceptionInfo );
777 MagickCore::Image* newImage =
781 replaceImage( newImage );
782 throwException( exceptionInfo );
783 (void) DestroyExceptionInfo( &exceptionInfo );
787 void Magick::Image::cycleColormap ( const ssize_t amount_ )
789 ExceptionInfo exceptionInfo;
790 GetExceptionInfo( &exceptionInfo );
792 CycleColormapImage( image(), amount_, &exceptionInfo );
793 throwException( exceptionInfo );
794 (void) DestroyExceptionInfo( &exceptionInfo );
798 void Magick::Image::despeckle ( void )
800 ExceptionInfo exceptionInfo;
801 GetExceptionInfo( &exceptionInfo );
802 MagickCore::Image* newImage =
803 DespeckleImage( image(), &exceptionInfo );
804 replaceImage( newImage );
805 throwException( exceptionInfo );
806 (void) DestroyExceptionInfo( &exceptionInfo );
810 void Magick::Image::display( void )
812 ExceptionInfo exceptionInfo;
813 GetExceptionInfo( &exceptionInfo );
814 DisplayImages( imageInfo(), image(), &exceptionInfo );
815 throwException( exceptionInfo );
816 (void) DestroyExceptionInfo( &exceptionInfo );
819 // Distort image. distorts an image using various distortion methods, by
820 // mapping color lookups of the source image to a new destination image
821 // usally of the same size as the source image, unless 'bestfit' is set to
823 void Magick::Image::distort ( const DistortImageMethod method_,
824 const size_t number_arguments_,
825 const double *arguments_,
826 const bool bestfit_ )
828 ExceptionInfo exceptionInfo;
829 GetExceptionInfo( &exceptionInfo );
830 MagickCore::Image* newImage = DistortImage ( image(), method_,
831 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
833 replaceImage( newImage );
834 throwException( exceptionInfo );
835 (void) DestroyExceptionInfo( &exceptionInfo );
838 // Draw on image using single drawable
839 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
843 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
847 drawable_.operator()(wand);
849 if( constImage()->exception.severity == UndefinedException)
852 wand=DestroyDrawingWand(wand);
855 throwImageException();
858 // Draw on image using a drawable list
859 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
863 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
867 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
868 p != drawable_.end(); p++ )
871 if( constImage()->exception.severity != UndefinedException)
875 if( constImage()->exception.severity == UndefinedException)
878 wand=DestroyDrawingWand(wand);
881 throwImageException();
884 // Hilight edges in image
885 void Magick::Image::edge ( const double radius_, const double sigma_ )
887 ExceptionInfo exceptionInfo;
888 GetExceptionInfo( &exceptionInfo );
889 MagickCore::Image* newImage =
890 EdgeImage( image(), radius_, sigma_, &exceptionInfo );
891 replaceImage( newImage );
892 throwException( exceptionInfo );
893 (void) DestroyExceptionInfo( &exceptionInfo );
896 // Emboss image (hilight edges)
897 void Magick::Image::emboss ( const double radius_, const double sigma_ )
899 ExceptionInfo exceptionInfo;
900 GetExceptionInfo( &exceptionInfo );
901 MagickCore::Image* newImage =
902 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
903 replaceImage( newImage );
904 throwException( exceptionInfo );
905 (void) DestroyExceptionInfo( &exceptionInfo );
908 // Enhance image (minimize noise)
909 void Magick::Image::enhance ( void )
911 ExceptionInfo exceptionInfo;
912 GetExceptionInfo( &exceptionInfo );
913 MagickCore::Image* newImage =
914 EnhanceImage( image(), &exceptionInfo );
915 replaceImage( newImage );
916 throwException( exceptionInfo );
917 (void) DestroyExceptionInfo( &exceptionInfo );
920 // Equalize image (histogram equalization)
921 void Magick::Image::equalize ( void )
923 ExceptionInfo exceptionInfo;
924 GetExceptionInfo( &exceptionInfo );
926 EqualizeImage( image(), &exceptionInfo );
927 throwException( exceptionInfo );
930 // Erase image to current "background color"
931 void Magick::Image::erase ( void )
934 SetImageBackgroundColor( image() );
935 throwImageException();
938 // Extends image as defined by the geometry.
940 void Magick::Image::extent ( const Geometry &geometry_ )
942 RectangleInfo extentInfo = geometry_;
944 ExceptionInfo exceptionInfo;
945 GetExceptionInfo( &exceptionInfo );
946 MagickCore::Image* newImage =
947 ExtentImage ( image(), &extentInfo, &exceptionInfo );
948 replaceImage( newImage );
949 throwException( exceptionInfo );
950 (void) DestroyExceptionInfo( &exceptionInfo );
952 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
954 backgroundColor ( backgroundColor_ );
955 extent ( geometry_ );
957 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
959 image()->gravity = gravity_;
960 extent ( geometry_ );
962 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
964 image()->gravity = gravity_;
965 backgroundColor ( backgroundColor_ );
966 extent ( geometry_ );
969 // Flip image (reflect each scanline in the vertical direction)
970 void Magick::Image::flip ( void )
972 ExceptionInfo exceptionInfo;
973 GetExceptionInfo( &exceptionInfo );
974 MagickCore::Image* newImage =
975 FlipImage( image(), &exceptionInfo );
976 replaceImage( newImage );
977 throwException( exceptionInfo );
978 (void) DestroyExceptionInfo( &exceptionInfo );
981 // Flood-fill color across pixels that match the color of the
982 // target pixel and are neighbors of the target pixel.
983 // Uses current fuzz setting when determining color match.
984 void Magick::Image::floodFillColor( const ssize_t x_,
986 const Magick::Color &fillColor_ )
988 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
990 void Magick::Image::floodFillColor( const Geometry &point_,
991 const Magick::Color &fillColor_ )
993 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
996 // Flood-fill color across pixels starting at target-pixel and
997 // stopping at pixels matching specified border color.
998 // Uses current fuzz setting when determining color match.
999 void Magick::Image::floodFillColor( const ssize_t x_,
1001 const Magick::Color &fillColor_,
1002 const Magick::Color &borderColor_ )
1004 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
1007 void Magick::Image::floodFillColor( const Geometry &point_,
1008 const Magick::Color &fillColor_,
1009 const Magick::Color &borderColor_ )
1011 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
1015 // Floodfill pixels matching color (within fuzz factor) of target
1016 // pixel(x,y) with replacement alpha value using method.
1017 void Magick::Image::floodFillAlpha( const ssize_t x_,
1019 const unsigned int alpha_,
1020 const PaintMethod method_ )
1024 GetPixelInfo(image(),&target);
1025 PixelInfo pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
1026 target.red=pixel.red;
1027 target.green=pixel.green;
1028 target.blue=pixel.blue;
1029 target.alpha=alpha_;
1030 ExceptionInfo exceptionInfo;
1031 GetExceptionInfo( &exceptionInfo );
1032 FloodfillPaintImage ( image(),
1033 options()->drawInfo(), // const DrawInfo *draw_info
1035 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
1036 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1038 throwException( exceptionInfo );
1039 (void) DestroyExceptionInfo( &exceptionInfo );
1042 // Flood-fill texture across pixels that match the color of the
1043 // target pixel and are neighbors of the target pixel.
1044 // Uses current fuzz setting when determining color match.
1045 void Magick::Image::floodFillTexture( const ssize_t x_,
1047 const Magick::Image &texture_ )
1051 // Set drawing pattern
1052 options()->fillPattern(texture_.constImage());
1055 Pixels pixels(*this);
1057 Quantum *p = pixels.get(x_, y_, 1, 1 );
1059 GetPixelInfo(constImage(),&target);
1060 target.red=GetPixelRed(constImage(),p);
1061 target.green=GetPixelGreen(constImage(),p);
1062 target.blue=GetPixelBlue(constImage(),p);
1063 ExceptionInfo exceptionInfo;
1064 GetExceptionInfo( &exceptionInfo );
1066 FloodfillPaintImage ( image(), // Image *image
1067 options()->drawInfo(), // const DrawInfo *draw_info
1068 &target, // const MagickPacket target
1069 static_cast<ssize_t>(x_), // const ssize_t x_offset
1070 static_cast<ssize_t>(y_), // const ssize_t y_offset
1071 MagickFalse, // const PaintMethod method
1073 throwException( exceptionInfo );
1074 (void) DestroyExceptionInfo( &exceptionInfo );
1077 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1078 const Magick::Image &texture_ )
1080 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1083 // Flood-fill texture across pixels starting at target-pixel and
1084 // stopping at pixels matching specified border color.
1085 // Uses current fuzz setting when determining color match.
1086 void Magick::Image::floodFillTexture( const ssize_t x_,
1088 const Magick::Image &texture_,
1089 const Magick::Color &borderColor_ )
1093 // Set drawing fill pattern
1094 options()->fillPattern(texture_.constImage());
1097 GetPixelInfo(constImage(),&target);
1098 target.red=static_cast<PixelInfo>(borderColor_).red;
1099 target.green=static_cast<PixelInfo>(borderColor_).green;
1100 target.blue=static_cast<PixelInfo>(borderColor_).blue;
1101 ExceptionInfo exceptionInfo;
1102 GetExceptionInfo( &exceptionInfo );
1103 FloodfillPaintImage ( image(),
1104 options()->drawInfo(),
1106 static_cast<ssize_t>(x_),
1107 static_cast<ssize_t>(y_),
1108 MagickTrue, &exceptionInfo);
1110 throwException( exceptionInfo );
1111 (void) DestroyExceptionInfo( &exceptionInfo );
1113 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1114 const Magick::Image &texture_,
1115 const Magick::Color &borderColor_ )
1117 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1120 // Flop image (reflect each scanline in the horizontal direction)
1121 void Magick::Image::flop ( void )
1123 ExceptionInfo exceptionInfo;
1124 GetExceptionInfo( &exceptionInfo );
1125 MagickCore::Image* newImage =
1126 FlopImage( image(), &exceptionInfo );
1127 replaceImage( newImage );
1128 throwException( exceptionInfo );
1129 (void) DestroyExceptionInfo( &exceptionInfo );
1133 void Magick::Image::frame ( const Geometry &geometry_ )
1137 info.x = static_cast<ssize_t>(geometry_.width());
1138 info.y = static_cast<ssize_t>(geometry_.height());
1139 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1140 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1141 info.outer_bevel = geometry_.xOff();
1142 info.inner_bevel = geometry_.yOff();
1144 ExceptionInfo exceptionInfo;
1145 GetExceptionInfo( &exceptionInfo );
1146 MagickCore::Image* newImage =
1147 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1148 replaceImage( newImage );
1149 throwException( exceptionInfo );
1150 (void) DestroyExceptionInfo( &exceptionInfo );
1152 void Magick::Image::frame ( const size_t width_,
1153 const size_t height_,
1154 const ssize_t outerBevel_, const ssize_t innerBevel_ )
1157 info.x = static_cast<ssize_t>(width_);
1158 info.y = static_cast<ssize_t>(height_);
1159 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1160 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1161 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1162 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1164 ExceptionInfo exceptionInfo;
1165 GetExceptionInfo( &exceptionInfo );
1166 MagickCore::Image* newImage =
1167 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1168 replaceImage( newImage );
1169 throwException( exceptionInfo );
1170 (void) DestroyExceptionInfo( &exceptionInfo );
1173 // Fx image. Applies a mathematical expression to the image.
1174 void Magick::Image::fx ( const std::string expression )
1176 ExceptionInfo exceptionInfo;
1177 GetExceptionInfo( &exceptionInfo );
1178 MagickCore::Image* newImage =
1179 FxImage ( image(), expression.c_str(), &exceptionInfo );
1180 replaceImage( newImage );
1181 throwException( exceptionInfo );
1182 (void) DestroyExceptionInfo( &exceptionInfo );
1184 void Magick::Image::fx ( const std::string expression,
1185 const Magick::ChannelType channel )
1187 ExceptionInfo exceptionInfo;
1188 GetExceptionInfo( &exceptionInfo );
1189 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
1190 MagickCore::Image* newImage =
1191 FxImage ( image(), expression.c_str(), &exceptionInfo );
1192 (void) SetPixelChannelMap( image(), channel_mask );
1193 replaceImage( newImage );
1194 throwException( exceptionInfo );
1195 (void) DestroyExceptionInfo( &exceptionInfo );
1198 // Gamma correct image
1199 void Magick::Image::gamma ( const double gamma_ )
1201 ExceptionInfo exceptionInfo;
1202 GetExceptionInfo( &exceptionInfo );
1204 GammaImage ( image(), gamma_, &exceptionInfo );
1205 throwException( exceptionInfo );
1206 (void) DestroyExceptionInfo( &exceptionInfo );
1209 void Magick::Image::gamma ( const double gammaRed_,
1210 const double gammaGreen_,
1211 const double gammaBlue_ )
1213 char gamma[MaxTextExtent + 1];
1214 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1215 gammaRed_, gammaGreen_, gammaBlue_);
1217 ExceptionInfo exceptionInfo;
1218 GetExceptionInfo( &exceptionInfo );
1220 GammaImage ( image(), atof(gamma), &exceptionInfo );
1221 throwException( exceptionInfo );
1222 (void) DestroyExceptionInfo( &exceptionInfo );
1225 // Gaussian blur image
1226 // The number of neighbor pixels to be included in the convolution
1227 // mask is specified by 'width_'. The standard deviation of the
1228 // gaussian bell curve is specified by 'sigma_'.
1229 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1231 ExceptionInfo exceptionInfo;
1232 GetExceptionInfo( &exceptionInfo );
1233 MagickCore::Image* newImage =
1234 GaussianBlurImage( image(), width_, sigma_, image()->bias, &exceptionInfo );
1235 replaceImage( newImage );
1236 throwException( exceptionInfo );
1237 (void) DestroyExceptionInfo( &exceptionInfo );
1240 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1241 const double width_,
1242 const double sigma_ )
1244 ExceptionInfo exceptionInfo;
1245 GetExceptionInfo( &exceptionInfo );
1246 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1247 MagickCore::Image* newImage =
1248 GaussianBlurImage( image(), width_, sigma_, image()->bias, &exceptionInfo );
1249 (void) SetPixelChannelMap( image(), channel_mask );
1250 replaceImage( newImage );
1251 throwException( exceptionInfo );
1252 (void) DestroyExceptionInfo( &exceptionInfo );
1255 // Apply a color lookup table (Hald CLUT) to the image.
1256 void Magick::Image::haldClut ( const Image &clutImage_ )
1258 ExceptionInfo exceptionInfo;
1259 GetExceptionInfo( &exceptionInfo );
1261 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1262 throwException( exceptionInfo );
1263 (void) DestroyExceptionInfo( &exceptionInfo );
1267 void Magick::Image::implode ( const double factor_ )
1269 ExceptionInfo exceptionInfo;
1270 GetExceptionInfo( &exceptionInfo );
1271 MagickCore::Image* newImage =
1272 ImplodeImage( image(), factor_, image()->interpolate, &exceptionInfo );
1273 replaceImage( newImage );
1274 throwException( exceptionInfo );
1275 (void) DestroyExceptionInfo( &exceptionInfo );
1278 // implements the inverse discrete Fourier transform (IFT) of the image either
1279 // as a magnitude / phase or real / imaginary image pair.
1280 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1282 ExceptionInfo exceptionInfo;
1283 GetExceptionInfo( &exceptionInfo );
1284 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1285 phase_.constImage(), MagickTrue, &exceptionInfo);
1286 replaceImage( newImage );
1287 throwException( exceptionInfo );
1288 (void) DestroyExceptionInfo( &exceptionInfo );
1290 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1291 const bool magnitude_ )
1293 ExceptionInfo exceptionInfo;
1294 GetExceptionInfo( &exceptionInfo );
1295 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1296 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1298 replaceImage( newImage );
1299 throwException( exceptionInfo );
1300 (void) DestroyExceptionInfo( &exceptionInfo );
1303 // Level image. Adjust the levels of the image by scaling the colors
1304 // falling between specified white and black points to the full
1305 // available quantum range. The parameters provided represent the
1306 // black, mid (gamma), and white points. The black point specifies
1307 // the darkest color in the image. Colors darker than the black point
1308 // are set to zero. Mid point (gamma) specifies a gamma correction to
1309 // apply to the image. White point specifies the lightest color in the
1310 // image. Colors brighter than the white point are set to the maximum
1311 // quantum value. The black and white point have the valid range 0 to
1312 // QuantumRange while gamma has a useful range of 0 to ten.
1313 void Magick::Image::level ( const double black_point,
1314 const double white_point,
1315 const double gamma )
1317 ExceptionInfo exceptionInfo;
1318 GetExceptionInfo( &exceptionInfo );
1320 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1321 throwException( exceptionInfo );
1322 (void) DestroyExceptionInfo( &exceptionInfo );
1325 // Magnify image by integral size
1326 void Magick::Image::magnify ( void )
1328 ExceptionInfo exceptionInfo;
1329 GetExceptionInfo( &exceptionInfo );
1330 MagickCore::Image* newImage =
1331 MagnifyImage( image(), &exceptionInfo );
1332 replaceImage( newImage );
1333 throwException( exceptionInfo );
1334 (void) DestroyExceptionInfo( &exceptionInfo );
1337 // Remap image colors with closest color from reference image
1338 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1340 ExceptionInfo exceptionInfo;
1341 GetExceptionInfo( &exceptionInfo );
1343 options()->quantizeDither( dither_ );
1344 RemapImage ( options()->quantizeInfo(), image(),
1345 mapImage_.constImage(), &exceptionInfo);
1346 throwException( exceptionInfo );
1347 (void) DestroyExceptionInfo( &exceptionInfo );
1349 // Floodfill designated area with replacement alpha value
1350 void Magick::Image::matteFloodfill ( const Color &target_ ,
1351 const unsigned int alpha_,
1352 const ssize_t x_, const ssize_t y_,
1353 const Magick::PaintMethod method_ )
1357 GetPixelInfo(constImage(),&target);
1358 target.red=static_cast<PixelInfo>(target_).red;
1359 target.green=static_cast<PixelInfo>(target_).green;
1360 target.blue=static_cast<PixelInfo>(target_).blue;
1361 target.alpha=alpha_;
1362 ChannelType channel_mask = SetPixelChannelMask( image(), AlphaChannel );
1363 ExceptionInfo exceptionInfo;
1364 GetExceptionInfo( &exceptionInfo );
1365 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1366 method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
1367 (void) SetPixelChannelMap( image(), channel_mask );
1368 throwException( exceptionInfo );
1369 (void) DestroyExceptionInfo( &exceptionInfo );
1372 // Filter image by replacing each pixel component with the median
1373 // color in a circular neighborhood
1374 void Magick::Image::medianFilter ( const double radius_ )
1376 ExceptionInfo exceptionInfo;
1377 GetExceptionInfo( &exceptionInfo );
1378 MagickCore::Image* newImage =
1379 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1380 radius_,&exceptionInfo );
1381 replaceImage( newImage );
1382 throwException( exceptionInfo );
1383 (void) DestroyExceptionInfo( &exceptionInfo );
1386 // Reduce image by integral size
1387 void Magick::Image::minify ( void )
1389 ExceptionInfo exceptionInfo;
1390 GetExceptionInfo( &exceptionInfo );
1391 MagickCore::Image* newImage =
1392 MinifyImage( image(), &exceptionInfo );
1393 replaceImage( newImage );
1394 throwException( exceptionInfo );
1395 (void) DestroyExceptionInfo( &exceptionInfo );
1398 // Modulate percent hue, saturation, and brightness of an image
1399 void Magick::Image::modulate ( const double brightness_,
1400 const double saturation_,
1403 char modulate[MaxTextExtent + 1];
1404 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1405 brightness_, saturation_, hue_);
1407 ExceptionInfo exceptionInfo;
1408 GetExceptionInfo( &exceptionInfo );
1410 ModulateImage( image(), modulate, &exceptionInfo );
1411 throwException( exceptionInfo );
1412 (void) DestroyExceptionInfo( &exceptionInfo );
1415 // Motion blur image with specified blur factor
1416 // The radius_ parameter specifies the radius of the Gaussian, in
1417 // pixels, not counting the center pixel. The sigma_ parameter
1418 // specifies the standard deviation of the Laplacian, in pixels.
1419 // The angle_ parameter specifies the angle the object appears
1420 // to be comming from (zero degrees is from the right).
1421 void Magick::Image::motionBlur ( const double radius_,
1422 const double sigma_,
1423 const double angle_ )
1425 ExceptionInfo exceptionInfo;
1426 GetExceptionInfo( &exceptionInfo );
1427 MagickCore::Image* newImage =
1428 MotionBlurImage( image(), radius_, sigma_, angle_, 0.0, &exceptionInfo);
1429 replaceImage( newImage );
1430 throwException( exceptionInfo );
1431 (void) DestroyExceptionInfo( &exceptionInfo );
1434 // Negate image. Set grayscale_ to true to effect grayscale values
1436 void Magick::Image::negate ( const bool grayscale_ )
1438 ExceptionInfo exceptionInfo;
1439 GetExceptionInfo( &exceptionInfo );
1441 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1443 throwException( exceptionInfo );
1444 (void) DestroyExceptionInfo( &exceptionInfo );
1448 void Magick::Image::normalize ( void )
1451 ExceptionInfo exceptionInfo;
1452 GetExceptionInfo( &exceptionInfo );
1453 NormalizeImage ( image(), &exceptionInfo );
1454 throwException( exceptionInfo );
1455 (void) DestroyExceptionInfo( &exceptionInfo );
1459 void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
1461 ExceptionInfo exceptionInfo;
1462 GetExceptionInfo( &exceptionInfo );
1463 MagickCore::Image* newImage =
1464 OilPaintImage( image(), radius_, sigma_, &exceptionInfo );
1465 replaceImage( newImage );
1466 throwException( exceptionInfo );
1467 (void) DestroyExceptionInfo( &exceptionInfo );
1470 // Set or attenuate the alpha channel. If the image pixels are
1471 // opaque then they are set to the specified alpha value, otherwise
1472 // they are blended with the supplied alpha value. The value of
1473 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1474 // OpaqueAlpha and TransparentAlpha are available to specify
1475 // completely opaque or completely transparent, respectively.
1476 void Magick::Image::alpha ( const unsigned int alpha_ )
1479 ExceptionInfo exceptionInfo;
1480 GetExceptionInfo( &exceptionInfo );
1481 SetImageAlpha( image(), alpha_, &exceptionInfo );
1482 throwException( exceptionInfo );
1483 (void) DestroyExceptionInfo( &exceptionInfo );
1486 // Change the color of an opaque pixel to the pen color.
1487 void Magick::Image::opaque ( const Color &opaqueColor_,
1488 const Color &penColor_ )
1490 if ( !opaqueColor_.isValid() )
1492 throwExceptionExplicit( OptionError,
1493 "Opaque color argument is invalid" );
1495 if ( !penColor_.isValid() )
1497 throwExceptionExplicit( OptionError,
1498 "Pen color argument is invalid" );
1502 std::string opaqueColor = opaqueColor_;
1503 std::string penColor = penColor_;
1507 ExceptionInfo exceptionInfo;
1508 GetExceptionInfo( &exceptionInfo );
1509 (void) QueryColorCompliance(std::string(opaqueColor_).c_str(),
1510 AllCompliance, &opaque, &exceptionInfo);
1511 (void) QueryColorCompliance(std::string(penColor_).c_str(),
1512 AllCompliance, &pen, &exceptionInfo);
1513 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo );
1514 throwException( exceptionInfo );
1515 (void) DestroyExceptionInfo( &exceptionInfo );
1518 // Ping is similar to read except only enough of the image is read to
1519 // determine the image columns, rows, and filesize. Access the
1520 // columns(), rows(), and fileSize() attributes after invoking ping.
1521 // The image data is not valid after calling ping.
1522 void Magick::Image::ping ( const std::string &imageSpec_ )
1524 options()->fileName( imageSpec_ );
1525 ExceptionInfo exceptionInfo;
1526 GetExceptionInfo( &exceptionInfo );
1527 MagickCore::Image* image =
1528 PingImage( imageInfo(), &exceptionInfo );
1529 replaceImage( image );
1530 throwException( exceptionInfo );
1531 (void) DestroyExceptionInfo( &exceptionInfo );
1534 // Ping is similar to read except only enough of the image is read
1535 // to determine the image columns, rows, and filesize. Access the
1536 // columns(), rows(), and fileSize() attributes after invoking
1537 // ping. The image data is not valid after calling ping.
1538 void Magick::Image::ping ( const Blob& blob_ )
1540 ExceptionInfo exceptionInfo;
1541 GetExceptionInfo( &exceptionInfo );
1542 MagickCore::Image* image =
1543 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1544 replaceImage( image );
1545 throwException( exceptionInfo );
1546 (void) DestroyExceptionInfo( &exceptionInfo );
1549 // Execute a named process module using an argc/argv syntax similar to
1550 // that accepted by a C 'main' routine. An exception is thrown if the
1551 // requested process module doesn't exist, fails to load, or fails during
1553 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1558 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1559 &image()->exception );
1561 if (status == false)
1562 throwException( image()->exception );
1565 // Quantize colors in image using current quantization settings
1566 // Set measureError_ to true in order to measure quantization error
1567 void Magick::Image::quantize ( const bool measureError_ )
1572 options()->quantizeInfo()->measure_error=MagickTrue;
1574 options()->quantizeInfo()->measure_error=MagickFalse;
1576 ExceptionInfo exceptionInfo;
1577 GetExceptionInfo( &exceptionInfo );
1578 QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo );
1580 throwException( exceptionInfo );
1581 (void) DestroyExceptionInfo( &exceptionInfo );
1584 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1585 void Magick::Image::quantumOperator ( const ChannelType channel_,
1586 const MagickEvaluateOperator operator_,
1589 ExceptionInfo exceptionInfo;
1590 GetExceptionInfo( &exceptionInfo );
1591 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1592 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
1593 (void) SetPixelChannelMap( image(), channel_mask );
1594 throwException( exceptionInfo );
1595 (void) DestroyExceptionInfo( &exceptionInfo );
1598 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1599 const size_t columns_,
1601 const ChannelType channel_,
1602 const MagickEvaluateOperator operator_,
1603 const double rvalue_)
1605 ExceptionInfo exceptionInfo;
1606 GetExceptionInfo( &exceptionInfo );
1607 RectangleInfo geometry;
1608 geometry.width = columns_;
1609 geometry.height = rows_;
1612 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1614 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1615 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
1616 (void) SetPixelChannelMap( image(), channel_mask );
1617 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1618 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y,
1620 crop_image = DestroyImageList(crop_image);
1621 throwException( exceptionInfo );
1622 (void) DestroyExceptionInfo( &exceptionInfo );
1625 // Raise image (lighten or darken the edges of an image to give a 3-D
1626 // raised or lowered effect)
1627 void Magick::Image::raise ( const Geometry &geometry_ ,
1628 const bool raisedFlag_ )
1630 ExceptionInfo exceptionInfo;
1631 GetExceptionInfo( &exceptionInfo );
1632 RectangleInfo raiseInfo = geometry_;
1634 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
1635 throwException( exceptionInfo );
1636 (void) DestroyExceptionInfo( &exceptionInfo );
1640 // Random threshold image.
1642 // Changes the value of individual pixels based on the intensity
1643 // of each pixel compared to a random threshold. The result is a
1644 // low-contrast, two color image. The thresholds_ argument is a
1645 // geometry containing LOWxHIGH thresholds. If the string
1646 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1647 // 3, or 4 will be performed instead. If a channel_ argument is
1648 // specified then only the specified channel is altered. This is
1649 // a very fast alternative to 'quantize' based dithering.
1650 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1652 randomThresholdChannel(thresholds_,DefaultChannels);
1654 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1655 const ChannelType channel_ )
1657 ExceptionInfo exceptionInfo;
1658 GetExceptionInfo( &exceptionInfo );
1660 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
1661 (void) RandomThresholdImage( image(),
1662 static_cast<std::string>(thresholds_).c_str(),
1664 (void) SetPixelChannelMap( image(), channel_mask );
1665 throwImageException();
1666 (void) DestroyExceptionInfo( &exceptionInfo );
1669 // Read image into current object
1670 void Magick::Image::read ( const std::string &imageSpec_ )
1672 options()->fileName( imageSpec_ );
1674 ExceptionInfo exceptionInfo;
1675 GetExceptionInfo( &exceptionInfo );
1676 MagickCore::Image* image =
1677 ReadImage( imageInfo(), &exceptionInfo );
1679 // Ensure that multiple image frames were not read.
1680 if ( image && image->next )
1682 // Destroy any extra image frames
1683 MagickCore::Image* next = image->next;
1686 DestroyImageList( next );
1689 replaceImage( image );
1690 throwException( exceptionInfo );
1692 throwException( image->exception );
1693 (void) DestroyExceptionInfo( &exceptionInfo );
1696 // Read image of specified size into current object
1697 void Magick::Image::read ( const Geometry &size_,
1698 const std::string &imageSpec_ )
1704 // Read image from in-memory BLOB
1705 void Magick::Image::read ( const Blob &blob_ )
1707 ExceptionInfo exceptionInfo;
1708 GetExceptionInfo( &exceptionInfo );
1709 MagickCore::Image* image =
1710 BlobToImage( imageInfo(),
1711 static_cast<const void *>(blob_.data()),
1712 blob_.length(), &exceptionInfo );
1713 replaceImage( image );
1714 throwException( exceptionInfo );
1716 throwException( image->exception );
1717 (void) DestroyExceptionInfo( &exceptionInfo );
1720 // Read image of specified size from in-memory BLOB
1721 void Magick::Image::read ( const Blob &blob_,
1722 const Geometry &size_ )
1730 // Read image of specified size and depth from in-memory BLOB
1731 void Magick::Image::read ( const Blob &blob_,
1732 const Geometry &size_,
1733 const size_t depth_ )
1743 // Read image of specified size, depth, and format from in-memory BLOB
1744 void Magick::Image::read ( const Blob &blob_,
1745 const Geometry &size_,
1746 const size_t depth_,
1747 const std::string &magick_ )
1755 // Set explicit image format
1756 fileName( magick_ + ':');
1761 // Read image of specified size, and format from in-memory BLOB
1762 void Magick::Image::read ( const Blob &blob_,
1763 const Geometry &size_,
1764 const std::string &magick_ )
1770 // Set explicit image format
1771 fileName( magick_ + ':');
1776 // Read image based on raw pixels in memory (ConstituteImage)
1777 void Magick::Image::read ( const size_t width_,
1778 const size_t height_,
1779 const std::string &map_,
1780 const StorageType type_,
1781 const void *pixels_ )
1783 ExceptionInfo exceptionInfo;
1784 GetExceptionInfo( &exceptionInfo );
1785 MagickCore::Image* image =
1786 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1788 replaceImage( image );
1789 throwException( exceptionInfo );
1791 throwException( image->exception );
1792 (void) DestroyExceptionInfo( &exceptionInfo );
1795 // Reduce noise in image
1796 void Magick::Image::reduceNoise ( const double order_ )
1798 ExceptionInfo exceptionInfo;
1799 GetExceptionInfo( &exceptionInfo );
1800 MagickCore::Image* newImage =
1801 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1803 replaceImage( newImage );
1804 throwException( exceptionInfo );
1805 (void) DestroyExceptionInfo( &exceptionInfo );
1809 void Magick::Image::resize( const Geometry &geometry_ )
1811 // Calculate new size. This code should be supported using binary arguments
1812 // in the ImageMagick library.
1815 size_t width = columns();
1816 size_t height = rows();
1818 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1822 ExceptionInfo exceptionInfo;
1823 GetExceptionInfo( &exceptionInfo );
1824 MagickCore::Image* newImage =
1825 ResizeImage( image(),
1831 replaceImage( newImage );
1832 throwException( exceptionInfo );
1833 (void) DestroyExceptionInfo( &exceptionInfo );
1837 void Magick::Image::roll ( const Geometry &roll_ )
1839 ssize_t xOff = roll_.xOff();
1840 if ( roll_.xNegative() )
1842 ssize_t yOff = roll_.yOff();
1843 if ( roll_.yNegative() )
1846 ExceptionInfo exceptionInfo;
1847 GetExceptionInfo( &exceptionInfo );
1848 MagickCore::Image* newImage =
1849 RollImage( image(), xOff, yOff, &exceptionInfo );
1850 replaceImage( newImage );
1851 throwException( exceptionInfo );
1852 (void) DestroyExceptionInfo( &exceptionInfo );
1854 void Magick::Image::roll ( const size_t columns_,
1855 const size_t rows_ )
1857 ExceptionInfo exceptionInfo;
1858 GetExceptionInfo( &exceptionInfo );
1859 MagickCore::Image* newImage =
1861 static_cast<ssize_t>(columns_),
1862 static_cast<ssize_t>(rows_), &exceptionInfo );
1863 replaceImage( newImage );
1864 throwException( exceptionInfo );
1865 (void) DestroyExceptionInfo( &exceptionInfo );
1869 void Magick::Image::rotate ( const double degrees_ )
1871 ExceptionInfo exceptionInfo;
1872 GetExceptionInfo( &exceptionInfo );
1873 MagickCore::Image* newImage =
1874 RotateImage( image(), degrees_, &exceptionInfo);
1875 replaceImage( newImage );
1876 throwException( exceptionInfo );
1877 (void) DestroyExceptionInfo( &exceptionInfo );
1881 void Magick::Image::sample ( const Geometry &geometry_ )
1885 size_t width = columns();
1886 size_t height = rows();
1888 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1892 ExceptionInfo exceptionInfo;
1893 GetExceptionInfo( &exceptionInfo );
1894 MagickCore::Image* newImage =
1895 SampleImage( image(), width, height, &exceptionInfo );
1896 replaceImage( newImage );
1897 throwException( exceptionInfo );
1898 (void) DestroyExceptionInfo( &exceptionInfo );
1902 void Magick::Image::scale ( const Geometry &geometry_ )
1906 size_t width = columns();
1907 size_t height = rows();
1909 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1913 ExceptionInfo exceptionInfo;
1914 GetExceptionInfo( &exceptionInfo );
1915 MagickCore::Image* newImage =
1916 ScaleImage( image(), width, height, &exceptionInfo );
1917 replaceImage( newImage );
1918 throwException( exceptionInfo );
1919 (void) DestroyExceptionInfo( &exceptionInfo );
1922 // Segment (coalesce similar image components) by analyzing the
1923 // histograms of the color components and identifying units that are
1924 // homogeneous with the fuzzy c-means technique.
1925 void Magick::Image::segment ( const double clusterThreshold_,
1926 const double smoothingThreshold_ )
1928 ExceptionInfo exceptionInfo;
1929 GetExceptionInfo( &exceptionInfo );
1931 SegmentImage ( image(),
1932 options()->quantizeColorSpace(),
1933 (MagickBooleanType) options()->verbose(),
1935 smoothingThreshold_, &exceptionInfo );
1936 throwException( exceptionInfo );
1937 (void) DestroyExceptionInfo( &exceptionInfo );
1938 SyncImage( image() );
1941 // Shade image using distant light source
1942 void Magick::Image::shade ( const double azimuth_,
1943 const double elevation_,
1944 const bool colorShading_ )
1946 ExceptionInfo exceptionInfo;
1947 GetExceptionInfo( &exceptionInfo );
1948 MagickCore::Image* newImage =
1949 ShadeImage( image(),
1950 colorShading_ == true ? MagickTrue : MagickFalse,
1954 replaceImage( newImage );
1955 throwException( exceptionInfo );
1956 (void) DestroyExceptionInfo( &exceptionInfo );
1959 // Sharpen pixels in image
1960 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1962 ExceptionInfo exceptionInfo;
1963 GetExceptionInfo( &exceptionInfo );
1964 MagickCore::Image* newImage =
1965 SharpenImage( image(),
1970 replaceImage( newImage );
1971 throwException( exceptionInfo );
1972 (void) DestroyExceptionInfo( &exceptionInfo );
1975 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1976 const double radius_, const double sigma_ )
1978 ExceptionInfo exceptionInfo;
1979 GetExceptionInfo( &exceptionInfo );
1980 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
1981 MagickCore::Image* newImage =
1982 SharpenImage( image(),
1987 (void) SetPixelChannelMap( image(), channel_mask );
1988 replaceImage( newImage );
1989 throwException( exceptionInfo );
1990 (void) DestroyExceptionInfo( &exceptionInfo );
1993 // Shave pixels from image edges.
1994 void Magick::Image::shave ( const Geometry &geometry_ )
1996 RectangleInfo shaveInfo = geometry_;
1997 ExceptionInfo exceptionInfo;
1998 GetExceptionInfo( &exceptionInfo );
1999 MagickCore::Image* newImage =
2000 ShaveImage( image(),
2003 replaceImage( newImage );
2004 throwException( exceptionInfo );
2005 (void) DestroyExceptionInfo( &exceptionInfo );
2009 void Magick::Image::shear ( const double xShearAngle_,
2010 const double yShearAngle_ )
2012 ExceptionInfo exceptionInfo;
2013 GetExceptionInfo( &exceptionInfo );
2014 MagickCore::Image* newImage =
2015 ShearImage( image(),
2019 replaceImage( newImage );
2020 throwException( exceptionInfo );
2021 (void) DestroyExceptionInfo( &exceptionInfo );
2025 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
2027 ExceptionInfo exceptionInfo;
2028 GetExceptionInfo( &exceptionInfo );
2030 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
2031 throwException( exceptionInfo );
2032 (void) DestroyExceptionInfo( &exceptionInfo );
2035 // Solarize image (similar to effect seen when exposing a photographic
2036 // film to light during the development process)
2037 void Magick::Image::solarize ( const double factor_ )
2039 ExceptionInfo exceptionInfo;
2040 GetExceptionInfo( &exceptionInfo );
2042 SolarizeImage ( image(), factor_, &exceptionInfo );
2043 throwException( exceptionInfo );
2044 (void) DestroyExceptionInfo( &exceptionInfo );
2047 // Sparse color image, given a set of coordinates, interpolates the colors
2048 // found at those coordinates, across the whole image, using various methods.
2050 void Magick::Image::sparseColor ( const ChannelType channel,
2051 const SparseColorMethod method,
2052 const size_t number_arguments,
2053 const double *arguments )
2055 ExceptionInfo exceptionInfo;
2056 GetExceptionInfo( &exceptionInfo );
2058 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
2059 MagickCore::Image* newImage = SparseColorImage ( image(), method,
2060 number_arguments, arguments, &exceptionInfo );
2061 (void) SetPixelChannelMap( image(), channel_mask );
2062 replaceImage( newImage );
2063 throwException( exceptionInfo );
2064 (void) DestroyExceptionInfo( &exceptionInfo );
2067 // Spread pixels randomly within image by specified ammount
2068 void Magick::Image::spread ( const size_t amount_ )
2070 ExceptionInfo exceptionInfo;
2071 GetExceptionInfo( &exceptionInfo );
2072 MagickCore::Image* newImage =
2073 SpreadImage( image(),
2075 image()->interpolate,
2077 replaceImage( newImage );
2078 throwException( exceptionInfo );
2079 (void) DestroyExceptionInfo( &exceptionInfo );
2082 // Add a digital watermark to the image (based on second image)
2083 void Magick::Image::stegano ( const Image &watermark_ )
2085 ExceptionInfo exceptionInfo;
2086 GetExceptionInfo( &exceptionInfo );
2087 MagickCore::Image* newImage =
2088 SteganoImage( image(),
2089 watermark_.constImage(),
2091 replaceImage( newImage );
2092 throwException( exceptionInfo );
2093 (void) DestroyExceptionInfo( &exceptionInfo );
2096 // Stereo image (left image is current image)
2097 void Magick::Image::stereo ( const Image &rightImage_ )
2099 ExceptionInfo exceptionInfo;
2100 GetExceptionInfo( &exceptionInfo );
2101 MagickCore::Image* newImage =
2102 StereoImage( image(),
2103 rightImage_.constImage(),
2105 replaceImage( newImage );
2106 throwException( exceptionInfo );
2107 (void) DestroyExceptionInfo( &exceptionInfo );
2111 void Magick::Image::swirl ( const double degrees_ )
2113 ExceptionInfo exceptionInfo;
2114 GetExceptionInfo( &exceptionInfo );
2115 MagickCore::Image* newImage =
2116 SwirlImage( image(), degrees_, image()->interpolate,
2118 replaceImage( newImage );
2119 throwException( exceptionInfo );
2120 (void) DestroyExceptionInfo( &exceptionInfo );
2124 void Magick::Image::texture ( const Image &texture_ )
2127 ExceptionInfo exceptionInfo;
2128 GetExceptionInfo( &exceptionInfo );
2129 TextureImage( image(), texture_.constImage(), &exceptionInfo );
2130 throwException( exceptionInfo );
2131 (void) DestroyExceptionInfo( &exceptionInfo );
2135 void Magick::Image::threshold ( const double threshold_ )
2138 ExceptionInfo exceptionInfo;
2139 GetExceptionInfo( &exceptionInfo );
2140 BilevelImage( image(), threshold_, &exceptionInfo );
2141 throwException( exceptionInfo );
2142 (void) DestroyExceptionInfo( &exceptionInfo );
2145 // Transform image based on image geometry only
2146 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2149 ExceptionInfo exceptionInfo;
2150 GetExceptionInfo( &exceptionInfo );
2151 TransformImage ( &(image()), 0,
2152 std::string(imageGeometry_).c_str(), &exceptionInfo );
2153 throwException( exceptionInfo );
2154 (void) DestroyExceptionInfo( &exceptionInfo );
2156 // Transform image based on image and crop geometries
2157 void Magick::Image::transform ( const Geometry &imageGeometry_,
2158 const Geometry &cropGeometry_ )
2161 ExceptionInfo exceptionInfo;
2162 GetExceptionInfo( &exceptionInfo );
2163 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2164 std::string(imageGeometry_).c_str(), &exceptionInfo );
2165 throwException( exceptionInfo );
2166 (void) DestroyExceptionInfo( &exceptionInfo );
2169 // Add matte image to image, setting pixels matching color to transparent
2170 void Magick::Image::transparent ( const Color &color_ )
2172 if ( !color_.isValid() )
2174 throwExceptionExplicit( OptionError,
2175 "Color argument is invalid" );
2178 std::string color = color_;
2181 (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
2182 &target,&image()->exception);
2183 ExceptionInfo exceptionInfo;
2184 GetExceptionInfo( &exceptionInfo );
2186 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2188 throwException( exceptionInfo );
2189 (void) DestroyExceptionInfo( &exceptionInfo );
2192 // Add matte image to image, setting pixels matching color to transparent
2193 void Magick::Image::transparentChroma(const Color &colorLow_,
2194 const Color &colorHigh_)
2196 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2198 throwExceptionExplicit( OptionError,
2199 "Color argument is invalid" );
2202 std::string colorLow = colorLow_;
2203 std::string colorHigh = colorHigh_;
2205 PixelInfo targetLow;
2206 PixelInfo targetHigh;
2207 (void) QueryColorCompliance(std::string(colorLow_).c_str(),
2208 AllCompliance,&targetLow,&image()->exception);
2209 (void) QueryColorCompliance(std::string(colorHigh_).c_str(),
2210 AllCompliance,&targetHigh,&image()->exception);
2211 ExceptionInfo exceptionInfo;
2212 GetExceptionInfo( &exceptionInfo );
2214 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2215 TransparentAlpha, MagickFalse, &exceptionInfo );
2216 throwException( exceptionInfo );
2217 (void) DestroyExceptionInfo( &exceptionInfo );
2221 // Trim edges that are the background color from the image
2222 void Magick::Image::trim ( void )
2224 ExceptionInfo exceptionInfo;
2225 GetExceptionInfo( &exceptionInfo );
2226 MagickCore::Image* newImage =
2227 TrimImage( image(), &exceptionInfo);
2228 replaceImage( newImage );
2229 throwException( exceptionInfo );
2230 (void) DestroyExceptionInfo( &exceptionInfo );
2233 // Replace image with a sharpened version of the original image
2234 // using the unsharp mask algorithm.
2236 // the radius of the Gaussian, in pixels, not counting the
2239 // the standard deviation of the Gaussian, in pixels.
2241 // the percentage of the difference between the original and
2242 // the blur image that is added back into the original.
2244 // the threshold in pixels needed to apply the diffence amount.
2245 void Magick::Image::unsharpmask ( const double radius_,
2246 const double sigma_,
2247 const double amount_,
2248 const double threshold_ )
2250 ExceptionInfo exceptionInfo;
2251 GetExceptionInfo( &exceptionInfo );
2252 MagickCore::Image* newImage =
2253 UnsharpMaskImage( image(),
2259 replaceImage( newImage );
2260 throwException( exceptionInfo );
2261 (void) DestroyExceptionInfo( &exceptionInfo );
2264 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2265 const double radius_,
2266 const double sigma_,
2267 const double amount_,
2268 const double threshold_ )
2270 ExceptionInfo exceptionInfo;
2271 GetExceptionInfo( &exceptionInfo );
2272 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
2273 MagickCore::Image* newImage =
2274 UnsharpMaskImage( image(),
2280 (void) SetPixelChannelMap( image(), channel_mask );
2281 replaceImage( newImage );
2282 throwException( exceptionInfo );
2283 (void) DestroyExceptionInfo( &exceptionInfo );
2286 // Map image pixels to a sine wave
2287 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2289 ExceptionInfo exceptionInfo;
2290 GetExceptionInfo( &exceptionInfo );
2291 MagickCore::Image* newImage =
2295 image()->interpolate,
2297 replaceImage( newImage );
2298 throwException( exceptionInfo );
2299 (void) DestroyExceptionInfo( &exceptionInfo );
2302 // Write image to file
2303 void Magick::Image::write( const std::string &imageSpec_ )
2305 ExceptionInfo exceptionInfo;
2306 GetExceptionInfo( &exceptionInfo );
2308 fileName( imageSpec_ );
2309 WriteImage( imageInfo(), image(), &exceptionInfo );
2310 throwException( exceptionInfo );
2311 (void) DestroyExceptionInfo( &exceptionInfo );
2314 // Write image to in-memory BLOB
2315 void Magick::Image::write ( Blob *blob_ )
2318 size_t length = 2048; // Efficient size for small images
2319 ExceptionInfo exceptionInfo;
2320 GetExceptionInfo( &exceptionInfo );
2321 void* data = ImageToBlob( imageInfo(),
2325 throwException( exceptionInfo );
2326 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2327 throwImageException();
2328 (void) DestroyExceptionInfo( &exceptionInfo );
2330 void Magick::Image::write ( Blob *blob_,
2331 const std::string &magick_ )
2335 size_t length = 2048; // Efficient size for small images
2336 ExceptionInfo exceptionInfo;
2337 GetExceptionInfo( &exceptionInfo );
2338 void* data = ImageToBlob( imageInfo(),
2342 throwException( exceptionInfo );
2343 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2344 throwImageException();
2345 (void) DestroyExceptionInfo( &exceptionInfo );
2347 void Magick::Image::write ( Blob *blob_,
2348 const std::string &magick_,
2349 const size_t depth_ )
2354 size_t length = 2048; // Efficient size for small images
2355 ExceptionInfo exceptionInfo;
2356 GetExceptionInfo( &exceptionInfo );
2357 void* data = ImageToBlob( imageInfo(),
2361 throwException( exceptionInfo );
2362 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2363 throwImageException();
2364 (void) DestroyExceptionInfo( &exceptionInfo );
2367 // Write image to an array of pixels with storage type specified
2368 // by user (ExportImagePixels), e.g.
2369 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2370 void Magick::Image::write ( const ssize_t x_,
2372 const size_t columns_,
2374 const std::string &map_,
2375 const StorageType type_,
2378 ExceptionInfo exceptionInfo;
2379 GetExceptionInfo( &exceptionInfo );
2380 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2383 throwException( exceptionInfo );
2384 (void) DestroyExceptionInfo( &exceptionInfo );
2388 void Magick::Image::zoom( const Geometry &geometry_ )
2390 // Calculate new size. This code should be supported using binary arguments
2391 // in the ImageMagick library.
2394 size_t width = columns();
2395 size_t height = rows();
2397 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2401 ExceptionInfo exceptionInfo;
2402 GetExceptionInfo( &exceptionInfo );
2403 MagickCore::Image* newImage =
2404 ResizeImage( image(),
2410 replaceImage( newImage );
2411 throwException( exceptionInfo );
2412 (void) DestroyExceptionInfo( &exceptionInfo );
2416 * Methods for setting image attributes
2420 // Join images into a single multi-image file
2421 void Magick::Image::adjoin ( const bool flag_ )
2424 options()->adjoin( flag_ );
2426 bool Magick::Image::adjoin ( void ) const
2428 return constOptions()->adjoin();
2431 // Remove pixel aliasing
2432 void Magick::Image::antiAlias( const bool flag_ )
2435 options()->antiAlias( static_cast<size_t>(flag_) );
2437 bool Magick::Image::antiAlias( void )
2439 return static_cast<bool>( options()->antiAlias( ) );
2442 // Animation inter-frame delay
2443 void Magick::Image::animationDelay ( const size_t delay_ )
2446 image()->delay = delay_;
2448 size_t Magick::Image::animationDelay ( void ) const
2450 return constImage()->delay;
2453 // Number of iterations to play animation
2454 void Magick::Image::animationIterations ( const size_t iterations_ )
2457 image()->iterations = iterations_;
2459 size_t Magick::Image::animationIterations ( void ) const
2461 return constImage()->iterations;
2464 // Access/Update a named image attribute
2465 void Magick::Image::attribute ( const std::string name_,
2466 const std::string value_ )
2469 ExceptionInfo exceptionInfo;
2470 GetExceptionInfo( &exceptionInfo );
2471 SetImageProperty( image(), name_.c_str(), value_.c_str(), &exceptionInfo );
2472 throwException( exceptionInfo );
2473 (void) DestroyExceptionInfo( &exceptionInfo );
2475 std::string Magick::Image::attribute ( const std::string name_ )
2477 ExceptionInfo exceptionInfo;
2478 GetExceptionInfo( &exceptionInfo );
2479 const char *value = GetImageProperty( constImage(), name_.c_str(),
2481 throwException( exceptionInfo );
2482 (void) DestroyExceptionInfo( &exceptionInfo );
2485 return std::string( value );
2487 return std::string(); // Intentionally no exception
2491 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2495 if ( backgroundColor_.isValid() )
2497 image()->background_color = backgroundColor_;
2501 image()->background_color = Color();
2504 options()->backgroundColor( backgroundColor_ );
2506 Magick::Color Magick::Image::backgroundColor ( void ) const
2508 return constOptions()->backgroundColor( );
2511 // Background fill texture
2512 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2515 options()->backgroundTexture( backgroundTexture_ );
2517 std::string Magick::Image::backgroundTexture ( void ) const
2519 return constOptions()->backgroundTexture( );
2522 // Original image columns
2523 size_t Magick::Image::baseColumns ( void ) const
2525 return constImage()->magick_columns;
2528 // Original image name
2529 std::string Magick::Image::baseFilename ( void ) const
2531 return std::string(constImage()->magick_filename);
2534 // Original image rows
2535 size_t Magick::Image::baseRows ( void ) const
2537 return constImage()->magick_rows;
2541 void Magick::Image::borderColor ( const Color &borderColor_ )
2545 if ( borderColor_.isValid() )
2547 image()->border_color = borderColor_;
2551 image()->border_color = Color();
2554 options()->borderColor( borderColor_ );
2556 Magick::Color Magick::Image::borderColor ( void ) const
2558 return constOptions()->borderColor( );
2561 // Return smallest bounding box enclosing non-border pixels. The
2562 // current fuzz value is used when discriminating between pixels.
2563 // This is the crop bounding box used by crop(Geometry(0,0));
2564 Magick::Geometry Magick::Image::boundingBox ( void ) const
2566 ExceptionInfo exceptionInfo;
2567 GetExceptionInfo( &exceptionInfo );
2568 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2569 throwException( exceptionInfo );
2570 (void) DestroyExceptionInfo( &exceptionInfo );
2571 return Geometry( bbox );
2574 // Text bounding-box base color
2575 void Magick::Image::boxColor ( const Color &boxColor_ )
2578 options()->boxColor( boxColor_ );
2580 Magick::Color Magick::Image::boxColor ( void ) const
2582 return constOptions()->boxColor( );
2585 // Pixel cache threshold. Once this threshold is exceeded, all
2586 // subsequent pixels cache operations are to/from disk.
2587 // This setting is shared by all Image objects.
2589 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2591 SetMagickResourceLimit( MemoryResource, threshold_ );
2594 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2597 image()->chromaticity.blue_primary.x = x_;
2598 image()->chromaticity.blue_primary.y = y_;
2600 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2602 *x_ = constImage()->chromaticity.blue_primary.x;
2603 *y_ = constImage()->chromaticity.blue_primary.y;
2606 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2609 image()->chromaticity.green_primary.x = x_;
2610 image()->chromaticity.green_primary.y = y_;
2612 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2614 *x_ = constImage()->chromaticity.green_primary.x;
2615 *y_ = constImage()->chromaticity.green_primary.y;
2618 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2621 image()->chromaticity.red_primary.x = x_;
2622 image()->chromaticity.red_primary.y = y_;
2624 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2626 *x_ = constImage()->chromaticity.red_primary.x;
2627 *y_ = constImage()->chromaticity.red_primary.y;
2630 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2633 image()->chromaticity.white_point.x = x_;
2634 image()->chromaticity.white_point.y = y_;
2636 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2638 *x_ = constImage()->chromaticity.white_point.x;
2639 *y_ = constImage()->chromaticity.white_point.y;
2642 // Set image storage class
2643 void Magick::Image::classType ( const ClassType class_ )
2645 if ( classType() == PseudoClass && class_ == DirectClass )
2647 // Use SyncImage to synchronize the DirectClass pixels with the
2648 // color map and then set to DirectClass type.
2650 SyncImage( image() );
2651 image()->colormap = (PixelInfo *)
2652 RelinquishMagickMemory( image()->colormap );
2653 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2657 if ( classType() == DirectClass && class_ == PseudoClass )
2659 // Quantize to create PseudoClass color map
2661 quantizeColors(MaxColormapSize);
2663 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2667 // Associate a clip mask with the image. The clip mask must be the
2668 // same dimensions as the image. Pass an invalid image to unset an
2669 // existing clip mask.
2670 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2674 ExceptionInfo exceptionInfo;
2675 GetExceptionInfo( &exceptionInfo );
2676 if( clipMask_.isValid() )
2679 SetImageClipMask( image(), clipMask_.constImage(), &exceptionInfo );
2683 // Unset existing clip mask
2684 SetImageClipMask( image(), 0, &exceptionInfo );
2686 throwException( exceptionInfo );
2687 (void) DestroyExceptionInfo( &exceptionInfo );
2689 Magick::Image Magick::Image::clipMask ( void ) const
2691 ExceptionInfo exceptionInfo;
2692 GetExceptionInfo( &exceptionInfo );
2693 MagickCore::Image* image =
2694 GetImageClipMask( constImage(), &exceptionInfo );
2695 throwException( exceptionInfo );
2696 (void) DestroyExceptionInfo( &exceptionInfo );
2697 return Magick::Image( image );
2700 void Magick::Image::colorFuzz ( const double fuzz_ )
2703 image()->fuzz = fuzz_;
2704 options()->colorFuzz( fuzz_ );
2706 double Magick::Image::colorFuzz ( void ) const
2708 return constOptions()->colorFuzz( );
2711 // Set color in colormap at index
2712 void Magick::Image::colorMap ( const size_t index_,
2713 const Color &color_ )
2715 MagickCore::Image* imageptr = image();
2717 if (index_ > (MaxColormapSize-1) )
2718 throwExceptionExplicit( OptionError,
2719 "Colormap index must be less than MaxColormapSize" );
2721 if ( !color_.isValid() )
2722 throwExceptionExplicit( OptionError,
2723 "Color argument is invalid");
2726 // Ensure that colormap size is large enough
2727 if ( colorMapSize() < (index_+1) )
2728 colorMapSize( index_ + 1 );
2730 // Set color at index in colormap
2731 (imageptr->colormap)[index_] = color_;
2733 // Return color in colormap at index
2734 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2736 const MagickCore::Image* imageptr = constImage();
2738 if ( !imageptr->colormap )
2739 throwExceptionExplicit( OptionError,
2740 "Image does not contain a colormap");
2742 if ( index_ > imageptr->colors-1 )
2743 throwExceptionExplicit( OptionError,
2744 "Index out of range");
2746 return Magick::Color( (imageptr->colormap)[index_] );
2749 // Colormap size (number of colormap entries)
2750 void Magick::Image::colorMapSize ( const size_t entries_ )
2752 if (entries_ >MaxColormapSize )
2753 throwExceptionExplicit( OptionError,
2754 "Colormap entries must not exceed MaxColormapSize" );
2758 MagickCore::Image* imageptr = image();
2760 if( !imageptr->colormap )
2762 // Allocate colormap
2763 imageptr->colormap =
2764 static_cast<PixelInfo*>(AcquireMagickMemory(entries_*sizeof(PixelInfo)));
2765 imageptr->colors = 0;
2767 else if ( entries_ > imageptr->colors )
2769 // Re-allocate colormap
2770 imageptr->colormap=(PixelInfo *)
2771 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelInfo));
2774 // Initialize any new colormap entries as all black
2776 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2777 (imageptr->colormap)[i] = black;
2779 imageptr->colors = entries_;
2781 size_t Magick::Image::colorMapSize ( void )
2783 const MagickCore::Image* imageptr = constImage();
2785 if ( !imageptr->colormap )
2786 throwExceptionExplicit( OptionError,
2787 "Image does not contain a colormap");
2789 return imageptr->colors;
2793 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2796 if ( image()->colorspace == colorSpace_ )
2801 if ( colorSpace_ != RGBColorspace &&
2802 colorSpace_ != sRGBColorspace &&
2803 colorSpace_ != TransparentColorspace &&
2804 colorSpace_ != GRAYColorspace )
2806 if (image()->colorspace != RGBColorspace &&
2807 image()->colorspace != sRGBColorspace &&
2808 image()->colorspace != TransparentColorspace &&
2809 image()->colorspace != GRAYColorspace)
2811 /* Transform to RGB colorspace as intermediate step */
2812 TransformRGBImage( image(), image()->colorspace );
2813 throwImageException();
2815 /* Transform to final non-RGB colorspace */
2816 RGBTransformImage( image(), colorSpace_ );
2817 throwImageException();
2821 if ( colorSpace_ == RGBColorspace ||
2822 colorSpace_ == sRGBColorspace ||
2823 colorSpace_ == TransparentColorspace ||
2824 colorSpace_ == GRAYColorspace )
2826 /* Transform to a RGB-type colorspace */
2827 TransformRGBImage( image(), image()->colorspace );
2828 throwImageException();
2832 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2834 return constImage()->colorspace;
2837 // Set image colorspace type.
2838 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2841 options()->colorspaceType( colorSpace_ );
2843 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2845 return constOptions()->colorspaceType();
2850 void Magick::Image::comment ( const std::string &comment_ )
2853 ExceptionInfo exceptionInfo;
2854 GetExceptionInfo( &exceptionInfo );
2855 SetImageProperty( image(), "Comment", NULL, &exceptionInfo );
2856 if ( comment_.length() > 0 )
2857 SetImageProperty( image(), "Comment", comment_.c_str(), &exceptionInfo );
2858 throwException( exceptionInfo );
2859 (void) DestroyExceptionInfo( &exceptionInfo );
2861 std::string Magick::Image::comment ( void ) const
2863 ExceptionInfo exceptionInfo;
2864 GetExceptionInfo( &exceptionInfo );
2865 const char *value = GetImageProperty( constImage(), "Comment",
2867 throwException( exceptionInfo );
2868 (void) DestroyExceptionInfo( &exceptionInfo );
2871 return std::string( value );
2873 return std::string(); // Intentionally no exception
2876 // Composition operator to be used when composition is implicitly used
2877 // (such as for image flattening).
2878 void Magick::Image::compose (const CompositeOperator compose_)
2880 image()->compose=compose_;
2883 Magick::CompositeOperator Magick::Image::compose ( void ) const
2885 return constImage()->compose;
2888 // Compression algorithm
2889 void Magick::Image::compressType ( const CompressionType compressType_ )
2892 image()->compression = compressType_;
2893 options()->compressType( compressType_ );
2895 Magick::CompressionType Magick::Image::compressType ( void ) const
2897 return constImage()->compression;
2900 // Enable printing of debug messages from ImageMagick
2901 void Magick::Image::debug ( const bool flag_ )
2904 options()->debug( flag_ );
2906 bool Magick::Image::debug ( void ) const
2908 return constOptions()->debug();
2911 // Tagged image format define (set/access coder-specific option) The
2912 // magick_ option specifies the coder the define applies to. The key_
2913 // option provides the key specific to that coder. The value_ option
2914 // provides the value to set (if any). See the defineSet() method if the
2915 // key must be removed entirely.
2916 void Magick::Image::defineValue ( const std::string &magick_,
2917 const std::string &key_,
2918 const std::string &value_ )
2921 std::string format = magick_ + ":" + key_;
2922 std::string option = value_;
2923 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2925 std::string Magick::Image::defineValue ( const std::string &magick_,
2926 const std::string &key_ ) const
2928 std::string definition = magick_ + ":" + key_;
2929 const char *option =
2930 GetImageOption ( constImageInfo(), definition.c_str() );
2932 return std::string( option );
2933 return std::string( );
2936 // Tagged image format define. Similar to the defineValue() method
2937 // except that passing the flag_ value 'true' creates a value-less
2938 // define with that format and key. Passing the flag_ value 'false'
2939 // removes any existing matching definition. The method returns 'true'
2940 // if a matching key exists, and 'false' if no matching key exists.
2941 void Magick::Image::defineSet ( const std::string &magick_,
2942 const std::string &key_,
2946 std::string definition = magick_ + ":" + key_;
2949 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2953 DeleteImageOption( imageInfo(), definition.c_str() );
2956 bool Magick::Image::defineSet ( const std::string &magick_,
2957 const std::string &key_ ) const
2959 std::string key = magick_ + ":" + key_;
2960 const char *option =
2961 GetImageOption ( constImageInfo(), key.c_str() );
2968 void Magick::Image::density ( const Geometry &density_ )
2971 options()->density( density_ );
2972 if ( density_.isValid() )
2974 image()->x_resolution = density_.width();
2975 if ( density_.height() != 0 )
2977 image()->y_resolution = density_.height();
2981 image()->y_resolution = density_.width();
2987 image()->x_resolution = 0;
2988 image()->y_resolution = 0;
2991 Magick::Geometry Magick::Image::density ( void ) const
2995 ssize_t x_resolution=72;
2996 ssize_t y_resolution=72;
2998 if (constImage()->x_resolution > 0.0)
2999 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
3001 if (constImage()->y_resolution > 0.0)
3002 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
3004 return Geometry(x_resolution,y_resolution);
3007 return constOptions()->density( );
3010 // Image depth (bits allocated to red/green/blue components)
3011 void Magick::Image::depth ( const size_t depth_ )
3013 size_t depth = depth_;
3015 if (depth > MAGICKCORE_QUANTUM_DEPTH)
3016 depth=MAGICKCORE_QUANTUM_DEPTH;
3019 image()->depth=depth;
3020 options()->depth( depth );
3022 size_t Magick::Image::depth ( void ) const
3024 return constImage()->depth;
3027 std::string Magick::Image::directory ( void ) const
3029 if ( constImage()->directory )
3030 return std::string( constImage()->directory );
3032 throwExceptionExplicit( CorruptImageWarning,
3033 "Image does not contain a directory");
3035 return std::string();
3038 // Endianness (little like Intel or big like SPARC) for image
3039 // formats which support endian-specific options.
3040 void Magick::Image::endian ( const Magick::EndianType endian_ )
3043 options()->endian( endian_ );
3044 image()->endian = endian_;
3046 Magick::EndianType Magick::Image::endian ( void ) const
3048 return constImage()->endian;
3051 // EXIF profile (BLOB)
3052 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
3055 if ( exifProfile_.data() != 0 )
3057 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
3058 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
3059 ExceptionInfo exceptionInfo;
3060 GetExceptionInfo( &exceptionInfo );
3061 (void) SetImageProfile( image(), "exif", exif_profile, &exceptionInfo);
3062 exif_profile =DestroyStringInfo( exif_profile );
3063 throwException( exceptionInfo );
3064 (void) DestroyExceptionInfo( &exceptionInfo );
3067 Magick::Blob Magick::Image::exifProfile( void ) const
3069 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
3070 if ( exif_profile == (StringInfo *) NULL)
3071 return Blob( 0, 0 );
3072 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
3076 void Magick::Image::fileName ( const std::string &fileName_ )
3080 fileName_.copy( image()->filename,
3081 sizeof(image()->filename) - 1 );
3082 image()->filename[ fileName_.length() ] = 0; // Null terminate
3084 options()->fileName( fileName_ );
3087 std::string Magick::Image::fileName ( void ) const
3089 return constOptions()->fileName( );
3093 off_t Magick::Image::fileSize ( void ) const
3095 return (off_t) GetBlobSize( constImage() );
3098 // Color to use when drawing inside an object
3099 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3102 options()->fillColor(fillColor_);
3104 Magick::Color Magick::Image::fillColor ( void ) const
3106 return constOptions()->fillColor();
3109 // Rule to use when filling drawn objects
3110 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3113 options()->fillRule(fillRule_);
3115 Magick::FillRule Magick::Image::fillRule ( void ) const
3117 return constOptions()->fillRule();
3120 // Pattern to use while filling drawn objects.
3121 void Magick::Image::fillPattern ( const Image &fillPattern_ )
3124 if(fillPattern_.isValid())
3125 options()->fillPattern( fillPattern_.constImage() );
3127 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3129 Magick::Image Magick::Image::fillPattern ( void ) const
3131 // FIXME: This is inordinately innefficient
3134 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3138 ExceptionInfo exceptionInfo;
3139 GetExceptionInfo( &exceptionInfo );
3140 MagickCore::Image* image =
3141 CloneImage( tmpTexture,
3144 MagickTrue, // orphan
3146 texture.replaceImage( image );
3147 throwException( exceptionInfo );
3148 (void) DestroyExceptionInfo( &exceptionInfo );
3153 // Filter used by zoom
3154 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3157 image()->filter = filterType_;
3159 Magick::FilterTypes Magick::Image::filterType ( void ) const
3161 return constImage()->filter;
3165 void Magick::Image::font ( const std::string &font_ )
3168 options()->font( font_ );
3170 std::string Magick::Image::font ( void ) const
3172 return constOptions()->font( );
3176 void Magick::Image::fontPointsize ( const double pointSize_ )
3179 options()->fontPointsize( pointSize_ );
3181 double Magick::Image::fontPointsize ( void ) const
3183 return constOptions()->fontPointsize( );
3186 // Font type metrics
3187 void Magick::Image::fontTypeMetrics( const std::string &text_,
3188 TypeMetric *metrics )
3190 DrawInfo *drawInfo = options()->drawInfo();
3191 drawInfo->text = const_cast<char *>(text_.c_str());
3192 ExceptionInfo exceptionInfo;
3193 GetExceptionInfo( &exceptionInfo );
3194 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric), &exceptionInfo );
3196 throwException( exceptionInfo );
3197 (void) DestroyExceptionInfo( &exceptionInfo );
3200 // Image format string
3201 std::string Magick::Image::format ( void ) const
3203 ExceptionInfo exceptionInfo;
3204 GetExceptionInfo( &exceptionInfo );
3205 const MagickInfo * magick_info
3206 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3207 throwException( exceptionInfo );
3208 (void) DestroyExceptionInfo( &exceptionInfo );
3210 if (( magick_info != 0 ) &&
3211 ( *magick_info->description != '\0' ))
3212 return std::string(magick_info->description);
3214 throwExceptionExplicit( CorruptImageWarning,
3215 "Unrecognized image magick type" );
3216 return std::string();
3220 double Magick::Image::gamma ( void ) const
3222 return constImage()->gamma;
3225 Magick::Geometry Magick::Image::geometry ( void ) const
3227 if ( constImage()->geometry )
3229 return Geometry(constImage()->geometry);
3232 throwExceptionExplicit( OptionWarning,
3233 "Image does not contain a geometry");
3238 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3241 image()->dispose = (DisposeType) disposeMethod_;
3243 size_t Magick::Image::gifDisposeMethod ( void ) const
3245 // FIXME: It would be better to return an enumeration
3246 return constImage()->dispose;
3249 // ICC ICM color profile (BLOB)
3250 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3252 profile("icm",colorProfile_);
3254 Magick::Blob Magick::Image::iccColorProfile( void ) const
3256 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3257 if ( color_profile == (StringInfo *) NULL)
3258 return Blob( 0, 0 );
3259 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3262 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3265 image()->interlace = interlace_;
3266 options()->interlaceType ( interlace_ );
3268 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3270 return constImage()->interlace;
3273 // IPTC profile (BLOB)
3274 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3277 if ( iptcProfile_.data() != 0 )
3279 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3280 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3281 ExceptionInfo exceptionInfo;
3282 GetExceptionInfo( &exceptionInfo );
3283 (void) SetImageProfile( image(), "iptc", iptc_profile, &exceptionInfo);
3284 iptc_profile =DestroyStringInfo( iptc_profile );
3285 throwException( exceptionInfo );
3286 (void) DestroyExceptionInfo( &exceptionInfo );
3289 Magick::Blob Magick::Image::iptcProfile( void ) const
3291 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3292 if ( iptc_profile == (StringInfo *) NULL)
3293 return Blob( 0, 0 );
3294 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3297 // Does object contain valid image?
3298 void Magick::Image::isValid ( const bool isValid_ )
3303 _imgRef = new ImageRef;
3305 else if ( !isValid() )
3307 // Construct with single-pixel black image to make
3308 // image valid. This is an obvious hack.
3309 size( Geometry(1,1) );
3310 read( "xc:#000000" );
3314 bool Magick::Image::isValid ( void ) const
3316 if ( rows() && columns() )
3323 void Magick::Image::label ( const std::string &label_ )
3326 ExceptionInfo exceptionInfo;
3327 GetExceptionInfo( &exceptionInfo );
3328 SetImageProperty ( image(), "Label", NULL, &exceptionInfo );
3329 if ( label_.length() > 0 )
3330 SetImageProperty ( image(), "Label", label_.c_str(), &exceptionInfo );
3331 throwException( exceptionInfo );
3332 (void) DestroyExceptionInfo( &exceptionInfo );
3334 std::string Magick::Image::label ( void ) const
3336 ExceptionInfo exceptionInfo;
3337 GetExceptionInfo( &exceptionInfo );
3338 const char *value = GetImageProperty( constImage(), "Label", &exceptionInfo );
3339 throwException( exceptionInfo );
3340 (void) DestroyExceptionInfo( &exceptionInfo );
3343 return std::string( value );
3345 return std::string();
3348 void Magick::Image::magick ( const std::string &magick_ )
3352 magick_.copy( image()->magick,
3353 sizeof(image()->magick) - 1 );
3354 image()->magick[ magick_.length() ] = 0;
3356 options()->magick( magick_ );
3358 std::string Magick::Image::magick ( void ) const
3360 if ( *(constImage()->magick) != '\0' )
3361 return std::string(constImage()->magick);
3363 return constOptions()->magick( );
3366 void Magick::Image::matte ( const bool matteFlag_ )
3370 // If matte channel is requested, but image doesn't already have a
3371 // matte channel, then create an opaque matte channel. Likewise, if
3372 // the image already has a matte channel but a matte channel is not
3373 // desired, then set the matte channel to opaque.
3374 ExceptionInfo exceptionInfo;
3375 GetExceptionInfo( &exceptionInfo );
3376 if ((matteFlag_ && !constImage()->matte) ||
3377 (constImage()->matte && !matteFlag_))
3378 SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo);
3379 throwException( exceptionInfo );
3380 (void) DestroyExceptionInfo( &exceptionInfo );
3382 image()->matte = (MagickBooleanType) matteFlag_;
3384 bool Magick::Image::matte ( void ) const
3386 if ( constImage()->matte )
3392 void Magick::Image::matteColor ( const Color &matteColor_ )
3396 if ( matteColor_.isValid() )
3398 image()->matte_color = matteColor_;
3399 options()->matteColor( matteColor_ );
3403 // Set to default matte color
3404 Color tmpColor( "#BDBDBD" );
3405 image()->matte_color = tmpColor;
3406 options()->matteColor( tmpColor );
3409 Magick::Color Magick::Image::matteColor ( void ) const
3411 return Color( constImage()->matte_color.red,
3412 constImage()->matte_color.green,
3413 constImage()->matte_color.blue );
3416 double Magick::Image::meanErrorPerPixel ( void ) const
3418 return(constImage()->error.mean_error_per_pixel);
3421 // Image modulus depth (minimum number of bits required to support
3422 // red/green/blue components without loss of accuracy)
3423 void Magick::Image::modulusDepth ( const size_t depth_ )
3426 SetImageDepth( image(), depth_ );
3427 options()->depth( depth_ );
3429 size_t Magick::Image::modulusDepth ( void ) const
3431 ExceptionInfo exceptionInfo;
3432 GetExceptionInfo( &exceptionInfo );
3433 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3434 throwException( exceptionInfo );
3435 (void) DestroyExceptionInfo( &exceptionInfo );
3439 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3442 options()->monochrome( monochromeFlag_ );
3444 bool Magick::Image::monochrome ( void ) const
3446 return constOptions()->monochrome( );
3449 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3451 if ( constImage()->montage )
3452 return Magick::Geometry(constImage()->montage);
3454 throwExceptionExplicit( CorruptImageWarning,
3455 "Image does not contain a montage" );
3457 return Magick::Geometry();
3460 double Magick::Image::normalizedMaxError ( void ) const
3462 return(constImage()->error.normalized_maximum_error);
3465 double Magick::Image::normalizedMeanError ( void ) const
3467 return constImage()->error.normalized_mean_error;
3470 // Image orientation
3471 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3474 image()->orientation = orientation_;
3476 Magick::OrientationType Magick::Image::orientation ( void ) const
3478 return constImage()->orientation;
3481 void Magick::Image::penColor ( const Color &penColor_ )
3484 options()->fillColor(penColor_);
3485 options()->strokeColor(penColor_);
3487 Magick::Color Magick::Image::penColor ( void ) const
3489 return constOptions()->fillColor();
3492 void Magick::Image::penTexture ( const Image &penTexture_ )
3495 if(penTexture_.isValid())
3496 options()->fillPattern( penTexture_.constImage() );
3498 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3501 Magick::Image Magick::Image::penTexture ( void ) const
3503 // FIXME: This is inordinately innefficient
3506 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3510 ExceptionInfo exceptionInfo;
3511 GetExceptionInfo( &exceptionInfo );
3512 MagickCore::Image* image =
3513 CloneImage( tmpTexture,
3516 MagickTrue, // orphan
3518 texture.replaceImage( image );
3519 throwException( exceptionInfo );
3520 (void) DestroyExceptionInfo( &exceptionInfo );
3525 // Set the color of a pixel.
3526 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3527 const Color &color_ )
3529 // Test arguments to ensure they are within the image.
3530 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3531 throwExceptionExplicit( OptionError,
3532 "Access outside of image boundary" );
3536 // Set image to DirectClass
3537 classType( DirectClass );
3540 Pixels pixels(*this);
3542 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3543 PixelInfo packet = color_;
3544 MagickCore::SetPixelPixelInfo(constImage(),&packet,pixel);
3545 // Tell ImageMagick that pixels have been updated
3551 // Get the color of a pixel
3552 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3553 const ssize_t y_ ) const
3555 ClassType storage_class;
3556 storage_class = classType();
3558 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3562 MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3563 return Color( packet );
3566 return Color(); // invalid
3569 // Preferred size and location of an image canvas.
3570 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3573 options()->page( pageSize_ );
3574 image()->page = pageSize_;
3576 Magick::Geometry Magick::Image::page ( void ) const
3578 return Geometry( constImage()->page.width,
3579 constImage()->page.height,
3580 AbsoluteValue(constImage()->page.x),
3581 AbsoluteValue(constImage()->page.y),
3582 constImage()->page.x < 0 ? true : false,
3583 constImage()->page.y < 0 ? true : false);
3586 // Add a named profile to an image or remove a named profile by
3587 // passing an empty Blob (use default Blob constructor).
3589 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3590 void Magick::Image::profile( const std::string name_,
3591 const Magick::Blob &profile_ )
3594 ExceptionInfo exceptionInfo;
3595 GetExceptionInfo( &exceptionInfo );
3596 ssize_t result = ProfileImage( image(), name_.c_str(),
3597 (unsigned char *)profile_.data(),
3598 profile_.length(), &exceptionInfo);
3599 throwException( exceptionInfo );
3600 (void) DestroyExceptionInfo( &exceptionInfo );
3604 // Retrieve a named profile from the image.
3606 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3607 // an existing generic profile name.
3608 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3610 const MagickCore::Image* image = constImage();
3612 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3614 if ( profile != (StringInfo *) NULL)
3615 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3618 Image temp_image = *this;
3619 temp_image.write( &blob, name_ );
3623 void Magick::Image::quality ( const size_t quality_ )
3626 image()->quality = quality_;
3627 options()->quality( quality_ );
3629 size_t Magick::Image::quality ( void ) const
3631 return constImage()->quality;
3634 void Magick::Image::quantizeColors ( const size_t colors_ )
3637 options()->quantizeColors( colors_ );
3639 size_t Magick::Image::quantizeColors ( void ) const
3641 return constOptions()->quantizeColors( );
3644 void Magick::Image::quantizeColorSpace
3645 ( const Magick::ColorspaceType colorSpace_ )
3648 options()->quantizeColorSpace( colorSpace_ );
3650 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3652 return constOptions()->quantizeColorSpace( );
3655 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3658 options()->quantizeDither( ditherFlag_ );
3660 bool Magick::Image::quantizeDither ( void ) const
3662 return constOptions()->quantizeDither( );
3665 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3668 options()->quantizeTreeDepth( treeDepth_ );
3670 size_t Magick::Image::quantizeTreeDepth ( void ) const
3672 return constOptions()->quantizeTreeDepth( );
3675 void Magick::Image::renderingIntent
3676 ( const Magick::RenderingIntent renderingIntent_ )
3679 image()->rendering_intent = renderingIntent_;
3681 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3683 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3686 void Magick::Image::resolutionUnits
3687 ( const Magick::ResolutionType resolutionUnits_ )
3690 image()->units = resolutionUnits_;
3691 options()->resolutionUnits( resolutionUnits_ );
3693 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3695 return constOptions()->resolutionUnits( );
3698 void Magick::Image::scene ( const size_t scene_ )
3701 image()->scene = scene_;
3703 size_t Magick::Image::scene ( void ) const
3705 return constImage()->scene;
3708 std::string Magick::Image::signature ( const bool force_ ) const
3710 Lock( &_imgRef->_mutexLock );
3712 // Re-calculate image signature if necessary
3713 ExceptionInfo exceptionInfo;
3714 GetExceptionInfo( &exceptionInfo );
3716 !GetImageProperty(constImage(), "Signature", &exceptionInfo) ||
3717 constImage()->taint )
3719 SignatureImage( const_cast<MagickCore::Image *>(constImage()), &exceptionInfo );
3722 const char *property = GetImageProperty(constImage(), "Signature",
3724 throwException( exceptionInfo );
3725 (void) DestroyExceptionInfo( &exceptionInfo );
3727 return std::string( property );
3730 void Magick::Image::size ( const Geometry &geometry_ )
3733 options()->size( geometry_ );
3734 image()->rows = geometry_.height();
3735 image()->columns = geometry_.width();
3737 Magick::Geometry Magick::Image::size ( void ) const
3739 return Magick::Geometry( constImage()->columns, constImage()->rows );
3743 void Magick::Image::splice( const Geometry &geometry_ )
3745 RectangleInfo spliceInfo = geometry_;
3746 ExceptionInfo exceptionInfo;
3747 GetExceptionInfo( &exceptionInfo );
3748 MagickCore::Image* newImage =
3749 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3750 replaceImage( newImage );
3751 throwException( exceptionInfo );
3752 (void) DestroyExceptionInfo( &exceptionInfo );
3755 // Obtain image statistics. Statistics are normalized to the range of
3756 // 0.0 to 1.0 and are output to the specified ImageStatistics
3758 void Magick::Image::statistics ( ImageStatistics *statistics )
3764 ExceptionInfo exceptionInfo;
3765 GetExceptionInfo( &exceptionInfo );
3767 ChannelType channel_mask = SetPixelChannelMask( image(), RedChannel);
3768 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3769 statistics->red.minimum=minimum;
3770 statistics->red.maximum=maximum;
3771 (void) GetImageMean( image(),&statistics->red.mean,
3772 &statistics->red.standard_deviation,&exceptionInfo);
3773 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3774 &statistics->red.skewness,&exceptionInfo);
3775 (void) SetPixelChannelMap( image(), channel_mask );
3777 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3778 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3779 statistics->green.minimum=minimum;
3780 statistics->green.maximum=maximum;
3781 (void) GetImageMean( image(),&statistics->green.mean,
3782 &statistics->green.standard_deviation,&exceptionInfo);
3783 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3784 &statistics->green.skewness,&exceptionInfo);
3785 (void) SetPixelChannelMap( image(), channel_mask );
3787 channel_mask = SetPixelChannelMask( image(), GreenChannel);
3788 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3789 statistics->blue.minimum=minimum;
3790 statistics->blue.maximum=maximum;
3791 (void) GetImageMean( image(),&statistics->blue.mean,
3792 &statistics->blue.standard_deviation,&exceptionInfo);
3793 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3794 &statistics->blue.skewness,&exceptionInfo);
3795 (void) SetPixelChannelMap( image(), channel_mask );
3797 channel_mask = SetPixelChannelMask( image(), AlphaChannel);
3798 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
3799 statistics->alpha.minimum=minimum;
3800 statistics->alpha.maximum=maximum;
3801 (void) GetImageMean( image(),&statistics->alpha.mean,
3802 &statistics->alpha.standard_deviation,&exceptionInfo);
3803 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3804 &statistics->alpha.skewness,&exceptionInfo);
3805 (void) SetPixelChannelMap( image(), channel_mask );
3807 throwException( exceptionInfo );
3808 (void) DestroyExceptionInfo( &exceptionInfo );
3811 // Strip strips an image of all profiles and comments.
3812 void Magick::Image::strip ( void )
3815 ExceptionInfo exceptionInfo;
3816 GetExceptionInfo( &exceptionInfo );
3817 StripImage( image(), &exceptionInfo );
3818 throwException( exceptionInfo );
3819 (void) DestroyExceptionInfo( &exceptionInfo );
3822 // enabled/disable stroke anti-aliasing
3823 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3826 options()->strokeAntiAlias(flag_);
3828 bool Magick::Image::strokeAntiAlias ( void ) const
3830 return constOptions()->strokeAntiAlias();
3833 // Color to use when drawing object outlines
3834 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3837 options()->strokeColor(strokeColor_);
3839 Magick::Color Magick::Image::strokeColor ( void ) const
3841 return constOptions()->strokeColor();
3844 // dash pattern for drawing vector objects (default one)
3845 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3848 options()->strokeDashArray( strokeDashArray_ );
3851 const double* Magick::Image::strokeDashArray ( void ) const
3853 return constOptions()->strokeDashArray( );
3856 // dash offset for drawing vector objects (default one)
3857 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3860 options()->strokeDashOffset( strokeDashOffset_ );
3863 double Magick::Image::strokeDashOffset ( void ) const
3865 return constOptions()->strokeDashOffset( );
3868 // Specify the shape to be used at the end of open subpaths when they
3869 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3871 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3874 options()->strokeLineCap( lineCap_ );
3876 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3878 return constOptions()->strokeLineCap( );
3881 // Specify the shape to be used at the corners of paths (or other
3882 // vector shapes) when they are stroked. Values of LineJoin are
3883 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3884 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3887 options()->strokeLineJoin( lineJoin_ );
3889 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3891 return constOptions()->strokeLineJoin( );
3894 // Specify miter limit. When two line segments meet at a sharp angle
3895 // and miter joins have been specified for 'lineJoin', it is possible
3896 // for the miter to extend far beyond the thickness of the line
3897 // stroking the path. The miterLimit' imposes a limit on the ratio of
3898 // the miter length to the 'lineWidth'. The default value of this
3900 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3903 options()->strokeMiterLimit( strokeMiterLimit_ );
3905 size_t Magick::Image::strokeMiterLimit ( void ) const
3907 return constOptions()->strokeMiterLimit( );
3910 // Pattern to use while stroking drawn objects.
3911 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3914 if(strokePattern_.isValid())
3915 options()->strokePattern( strokePattern_.constImage() );
3917 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3919 Magick::Image Magick::Image::strokePattern ( void ) const
3921 // FIXME: This is inordinately innefficient
3924 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3928 ExceptionInfo exceptionInfo;
3929 GetExceptionInfo( &exceptionInfo );
3930 MagickCore::Image* image =
3931 CloneImage( tmpTexture,
3934 MagickTrue, // orphan
3936 throwException( exceptionInfo );
3937 (void) DestroyExceptionInfo( &exceptionInfo );
3938 texture.replaceImage( image );
3943 // Stroke width for drawing lines, circles, ellipses, etc.
3944 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3947 options()->strokeWidth( strokeWidth_ );
3949 double Magick::Image::strokeWidth ( void ) const
3951 return constOptions()->strokeWidth( );
3954 void Magick::Image::subImage ( const size_t subImage_ )
3957 options()->subImage( subImage_ );
3959 size_t Magick::Image::subImage ( void ) const
3961 return constOptions()->subImage( );
3964 void Magick::Image::subRange ( const size_t subRange_ )
3967 options()->subRange( subRange_ );
3969 size_t Magick::Image::subRange ( void ) const
3971 return constOptions()->subRange( );
3974 // Annotation text encoding (e.g. "UTF-16")
3975 void Magick::Image::textEncoding ( const std::string &encoding_ )
3978 options()->textEncoding( encoding_ );
3980 std::string Magick::Image::textEncoding ( void ) const
3982 return constOptions()->textEncoding( );
3985 size_t Magick::Image::totalColors ( void )
3987 ExceptionInfo exceptionInfo;
3988 GetExceptionInfo( &exceptionInfo );
3989 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3990 throwException( exceptionInfo );
3991 (void) DestroyExceptionInfo( &exceptionInfo );
3995 // Origin of coordinate system to use when annotating with text or drawing
3996 void Magick::Image::transformOrigin ( const double x_, const double y_ )
3999 options()->transformOrigin( x_, y_ );
4002 // Rotation to use when annotating with text or drawing
4003 void Magick::Image::transformRotation ( const double angle_ )
4006 options()->transformRotation( angle_ );
4009 // Reset transformation parameters to default
4010 void Magick::Image::transformReset ( void )
4013 options()->transformReset();
4016 // Scale to use when annotating with text or drawing
4017 void Magick::Image::transformScale ( const double sx_, const double sy_ )
4020 options()->transformScale( sx_, sy_ );
4023 // Skew to use in X axis when annotating with text or drawing
4024 void Magick::Image::transformSkewX ( const double skewx_ )
4027 options()->transformSkewX( skewx_ );
4030 // Skew to use in Y axis when annotating with text or drawing
4031 void Magick::Image::transformSkewY ( const double skewy_ )
4034 options()->transformSkewY( skewy_ );
4037 // Image representation type
4038 Magick::ImageType Magick::Image::type ( void ) const
4041 ExceptionInfo exceptionInfo;
4042 GetExceptionInfo( &exceptionInfo );
4043 ImageType image_type = constOptions()->type();
4044 if ( image_type == UndefinedType )
4045 image_type= GetImageType( constImage(), &exceptionInfo);
4046 throwException( exceptionInfo );
4047 (void) DestroyExceptionInfo( &exceptionInfo );
4050 void Magick::Image::type ( const Magick::ImageType type_)
4052 ExceptionInfo exceptionInfo;
4053 GetExceptionInfo( &exceptionInfo );
4055 options()->type( type_ );
4056 SetImageType( image(), type_, &exceptionInfo );
4057 throwException( exceptionInfo );
4058 (void) DestroyExceptionInfo( &exceptionInfo );
4061 void Magick::Image::verbose ( const bool verboseFlag_ )
4064 options()->verbose( verboseFlag_ );
4066 bool Magick::Image::verbose ( void ) const
4068 return constOptions()->verbose( );
4071 void Magick::Image::view ( const std::string &view_ )
4074 options()->view( view_ );
4076 std::string Magick::Image::view ( void ) const
4078 return constOptions()->view( );
4081 // Virtual pixel method
4082 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
4085 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
4086 options()->virtualPixelMethod( virtual_pixel_method_ );
4088 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
4090 return GetImageVirtualPixelMethod( constImage() );
4093 void Magick::Image::x11Display ( const std::string &display_ )
4096 options()->x11Display( display_ );
4098 std::string Magick::Image::x11Display ( void ) const
4100 return constOptions()->x11Display( );
4103 double Magick::Image::xResolution ( void ) const
4105 return constImage()->x_resolution;
4107 double Magick::Image::yResolution ( void ) const
4109 return constImage()->y_resolution;
4113 Magick::Image::Image( const Image & image_ )
4114 : _imgRef(image_._imgRef)
4116 Lock( &_imgRef->_mutexLock );
4118 // Increase reference count
4119 ++_imgRef->_refCount;
4122 // Assignment operator
4123 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
4125 if( this != &image_ )
4128 Lock( &image_._imgRef->_mutexLock );
4129 ++image_._imgRef->_refCount;
4132 bool doDelete = false;
4134 Lock( &_imgRef->_mutexLock );
4135 if ( --_imgRef->_refCount == 0 )
4141 // Delete old image reference with associated image and options.
4145 // Use new image reference
4146 _imgRef = image_._imgRef;
4152 //////////////////////////////////////////////////////////////////////
4154 // Low-level Pixel Access Routines
4156 // Also see the Pixels class, which provides support for multiple
4157 // cache views. The low-level pixel access routines in the Image
4158 // class are provided in order to support backward compatability.
4160 //////////////////////////////////////////////////////////////////////
4162 // Transfers read-only pixels from the image to the pixel cache as
4163 // defined by the specified region
4164 const Magick::Quantum* Magick::Image::getConstPixels
4165 ( const ssize_t x_, const ssize_t y_,
4166 const size_t columns_,
4167 const size_t rows_ ) const
4169 ExceptionInfo exceptionInfo;
4170 GetExceptionInfo( &exceptionInfo );
4171 const Quantum* p = (*GetVirtualPixels)( constImage(),
4175 throwException( exceptionInfo );
4176 (void) DestroyExceptionInfo( &exceptionInfo );
4180 // Obtain read-only pixel associated pixels channels
4181 const void* Magick::Image::getConstMetacontent ( void ) const
4183 const void* result = GetVirtualMetacontent( constImage() );
4186 throwImageException();
4191 // Obtain image pixel associated pixels channels
4192 void* Magick::Image::getMetacontent ( void )
4194 void* result = GetAuthenticMetacontent( image() );
4197 throwImageException();
4202 // Transfers pixels from the image to the pixel cache as defined
4203 // by the specified region. Modified pixels may be subsequently
4204 // transferred back to the image via syncPixels.
4205 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4206 const size_t columns_,
4207 const size_t rows_ )
4210 ExceptionInfo exceptionInfo;
4211 GetExceptionInfo( &exceptionInfo );
4212 Quantum* result = (*GetAuthenticPixels)( image(),
4214 columns_, rows_, &exceptionInfo );
4215 throwException( exceptionInfo );
4216 (void) DestroyExceptionInfo( &exceptionInfo );
4221 // Allocates a pixel cache region to store image pixels as defined
4222 // by the region rectangle. This area is subsequently transferred
4223 // from the pixel cache to the image via syncPixels.
4224 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4225 const size_t columns_,
4226 const size_t rows_ )
4229 ExceptionInfo exceptionInfo;
4230 GetExceptionInfo( &exceptionInfo );
4231 Quantum* result = (*QueueAuthenticPixels)( image(),
4233 columns_, rows_, &exceptionInfo );
4234 throwException( exceptionInfo );
4235 (void) DestroyExceptionInfo( &exceptionInfo );
4240 // Transfers the image cache pixels to the image.
4241 void Magick::Image::syncPixels ( void )
4243 ExceptionInfo exceptionInfo;
4244 GetExceptionInfo( &exceptionInfo );
4245 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4246 throwException( exceptionInfo );
4247 (void) DestroyExceptionInfo( &exceptionInfo );
4250 // Transfers one or more pixel components from a buffer or file
4251 // into the image pixel cache of an image.
4252 // Used to support image decoders.
4253 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4254 const unsigned char *source_ )
4259 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4260 ExceptionInfo exceptionInfo;
4261 GetExceptionInfo( &exceptionInfo );
4262 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4263 quantum_,source_, &exceptionInfo);
4264 throwException( exceptionInfo );
4265 (void) DestroyExceptionInfo( &exceptionInfo );
4266 quantum_info=DestroyQuantumInfo(quantum_info);
4269 // Transfers one or more pixel components from the image pixel
4270 // cache to a buffer or file.
4271 // Used to support image encoders.
4272 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4273 unsigned char *destination_ )
4278 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4279 ExceptionInfo exceptionInfo;
4280 GetExceptionInfo( &exceptionInfo );
4281 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4282 quantum_,destination_, &exceptionInfo);
4283 quantum_info=DestroyQuantumInfo(quantum_info);
4284 throwException( exceptionInfo );
4285 (void) DestroyExceptionInfo( &exceptionInfo );
4288 /////////////////////////////////////////////////////////////////////
4290 // No end-user methods beyond this point
4292 /////////////////////////////////////////////////////////////////////
4296 // Construct using existing image and default options
4298 Magick::Image::Image ( MagickCore::Image* image_ )
4299 : _imgRef(new ImageRef( image_))
4303 // Get Magick::Options*
4304 Magick::Options* Magick::Image::options( void )
4306 return _imgRef->options();
4308 const Magick::Options* Magick::Image::constOptions( void ) const
4310 return _imgRef->options();
4313 // Get MagickCore::Image*
4314 MagickCore::Image*& Magick::Image::image( void )
4316 return _imgRef->image();
4318 const MagickCore::Image* Magick::Image::constImage( void ) const
4320 return _imgRef->image();
4324 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4326 return _imgRef->options()->imageInfo();
4328 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4330 return _imgRef->options()->imageInfo();
4333 // Get QuantizeInfo *
4334 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4336 return _imgRef->options()->quantizeInfo();
4338 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4340 return _imgRef->options()->quantizeInfo();
4344 // Replace current image
4346 MagickCore::Image * Magick::Image::replaceImage
4347 ( MagickCore::Image* replacement_ )
4349 MagickCore::Image* image;
4352 image = replacement_;
4355 ExceptionInfo exceptionInfo;
4356 GetExceptionInfo( &exceptionInfo );
4357 image = AcquireImage(constImageInfo(), &exceptionInfo);
4358 throwException( exceptionInfo );
4359 (void) DestroyExceptionInfo( &exceptionInfo );
4363 Lock( &_imgRef->_mutexLock );
4365 if ( _imgRef->_refCount == 1 )
4367 // We own the image, just replace it, and de-register
4369 _imgRef->image(image);
4373 // We don't own the image, dereference and replace with copy
4374 --_imgRef->_refCount;
4375 _imgRef = new ImageRef( image, constOptions() );
4379 return _imgRef->_image;
4383 // Prepare to modify image or image options
4384 // Replace current image and options with copy if reference count > 1
4386 void Magick::Image::modifyImage( void )
4389 Lock( &_imgRef->_mutexLock );
4390 if ( _imgRef->_refCount == 1 )
4392 // De-register image and return
4398 ExceptionInfo exceptionInfo;
4399 GetExceptionInfo( &exceptionInfo );
4400 replaceImage( CloneImage( image(),
4403 MagickTrue, // orphan
4405 throwException( exceptionInfo );
4406 (void) DestroyExceptionInfo( &exceptionInfo );
4411 // Test for an ImageMagick reported error and throw exception if one
4412 // has been reported. Secretly resets image->exception back to default
4413 // state even though this method is const.
4415 void Magick::Image::throwImageException( void ) const
4417 // Throw C++ exception while resetting Image exception to default state
4418 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4421 // Register image with image registry or obtain registration id
4422 ssize_t Magick::Image::registerId( void )
4424 Lock( &_imgRef->_mutexLock );
4425 if( _imgRef->id() < 0 )
4427 char id[MaxTextExtent];
4428 ExceptionInfo exceptionInfo;
4429 GetExceptionInfo( &exceptionInfo );
4430 _imgRef->id(_imgRef->id()+1);
4431 sprintf(id,"%.20g\n",(double) _imgRef->id());
4432 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4433 throwException( exceptionInfo );
4434 (void) DestroyExceptionInfo( &exceptionInfo );
4436 return _imgRef->id();
4439 // Unregister image from image registry
4440 void Magick::Image::unregisterId( void )
4447 // Create a local wrapper around MagickCoreTerminus
4452 void MagickPlusPlusDestroyMagick(void);
4456 void Magick::MagickPlusPlusDestroyMagick(void)
4458 if (magick_initialized)
4460 magick_initialized=false;
4461 MagickCore::MagickCoreTerminus();
4465 // C library initialization routine
4466 void MagickPPExport Magick::InitializeMagick(const char *path_)
4468 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4469 if (!magick_initialized)
4470 magick_initialized=true;
4474 // Cleanup class to ensure that ImageMagick singletons are destroyed
4475 // so as to avoid any resemblence to a memory leak (which seems to
4484 MagickCleanUp( void );
4485 ~MagickCleanUp( void );
4488 // The destructor for this object is invoked when the destructors for
4489 // static objects in this translation unit are invoked.
4490 static MagickCleanUp magickCleanUpGuard;
4493 Magick::MagickCleanUp::MagickCleanUp ( void )
4495 // Don't even think about invoking InitializeMagick here!
4498 Magick::MagickCleanUp::~MagickCleanUp ( void )
4500 MagickPlusPlusDestroyMagick();