1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Implementation of Image
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11 #include "Magick++/Include.h"
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( constImage(), radius_, sigma_, &exceptionInfo );
304 replaceImage( newImage );
305 throwException( exceptionInfo );
306 (void) DestroyExceptionInfo( &exceptionInfo );
309 void Magick::Image::adaptiveResize ( const Geometry &geometry_ )
313 size_t width = columns();
314 size_t height = rows();
316 ParseMetaGeometry( static_cast<std::string>(geometry_).c_str(),
320 ExceptionInfo exceptionInfo;
321 GetExceptionInfo( &exceptionInfo );
322 MagickCore::Image* newImage =
323 AdaptiveResizeImage( constImage(), width, height, &exceptionInfo );
324 replaceImage( newImage );
325 throwException( exceptionInfo );
326 (void) DestroyExceptionInfo( &exceptionInfo );
329 void Magick::Image::adaptiveSharpen ( const double radius_,
330 const double sigma_ )
332 ExceptionInfo exceptionInfo;
333 GetExceptionInfo( &exceptionInfo );
334 MagickCore::Image* newImage =
335 AdaptiveSharpenImage( constImage(), radius_, sigma_, &exceptionInfo );
336 replaceImage( newImage );
337 throwException( exceptionInfo );
338 (void) DestroyExceptionInfo( &exceptionInfo );
341 void Magick::Image::adaptiveSharpenChannel ( const ChannelType channel_,
342 const double radius_,
343 const double sigma_ )
345 ExceptionInfo exceptionInfo;
346 GetExceptionInfo( &exceptionInfo );
347 ChannelType channel_mask = SetImageChannelMask( image(), channel_);
348 MagickCore::Image* newImage =
349 AdaptiveSharpenImage( constImage(), radius_, sigma_, &exceptionInfo );
350 SetPixelChannelMask( image(), channel_mask );
351 replaceImage( newImage );
352 throwException( exceptionInfo );
353 (void) DestroyExceptionInfo( &exceptionInfo );
356 // Local adaptive threshold image
357 // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
358 // Width x height define the size of the pixel neighborhood
359 // offset = constant to subtract from pixel neighborhood mean
360 void Magick::Image::adaptiveThreshold ( const size_t width_,
361 const size_t height_,
362 const ssize_t offset_ )
364 ExceptionInfo exceptionInfo;
365 GetExceptionInfo( &exceptionInfo );
366 MagickCore::Image* newImage =
367 AdaptiveThresholdImage( constImage(), width_, height_, offset_,
369 replaceImage( newImage );
370 throwException( exceptionInfo );
371 (void) DestroyExceptionInfo( &exceptionInfo );
374 // Add noise to image
375 void Magick::Image::addNoise ( const NoiseType noiseType_ )
377 ExceptionInfo exceptionInfo;
378 GetExceptionInfo( &exceptionInfo );
379 MagickCore::Image* newImage =
380 AddNoiseImage ( constImage(), noiseType_, 1.0, &exceptionInfo );
381 replaceImage( newImage );
382 throwException( exceptionInfo );
383 (void) DestroyExceptionInfo( &exceptionInfo );
386 void Magick::Image::addNoiseChannel ( const ChannelType channel_,
387 const NoiseType noiseType_ )
389 ExceptionInfo exceptionInfo;
390 GetExceptionInfo( &exceptionInfo );
391 ChannelType channel_mask = SetImageChannelMask( image(), channel_);
392 MagickCore::Image* newImage =
393 AddNoiseImage ( constImage(), noiseType_, 1.0, &exceptionInfo );
394 SetPixelChannelMask( image(), channel_mask );
395 replaceImage( newImage );
396 throwException( exceptionInfo );
397 (void) DestroyExceptionInfo( &exceptionInfo );
400 // Affine Transform image
401 void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
403 ExceptionInfo exceptionInfo;
404 GetExceptionInfo( &exceptionInfo );
406 AffineMatrix _affine;
407 _affine.sx = affine_.sx();
408 _affine.sy = affine_.sy();
409 _affine.rx = affine_.rx();
410 _affine.ry = affine_.ry();
411 _affine.tx = affine_.tx();
412 _affine.ty = affine_.ty();
414 MagickCore::Image* newImage =
415 AffineTransformImage( constImage(), &_affine, &exceptionInfo );
416 replaceImage( newImage );
417 throwException( exceptionInfo );
418 (void) DestroyExceptionInfo( &exceptionInfo );
421 // Set or attenuate the alpha channel. If the image pixels are
422 // opaque then they are set to the specified alpha value, otherwise
423 // they are blended with the supplied alpha value. The value of
424 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
425 // OpaqueAlpha and TransparentAlpha are available to specify
426 // completely opaque or completely transparent, respectively.
427 void Magick::Image::alpha ( const unsigned int alpha_ )
430 ExceptionInfo exceptionInfo;
431 GetExceptionInfo( &exceptionInfo );
432 SetImageAlpha( image(), alpha_, &exceptionInfo );
433 throwException( exceptionInfo );
434 (void) DestroyExceptionInfo( &exceptionInfo );
437 void Magick::Image::alphaChannel ( AlphaChannelOption alphaOption_ )
440 ExceptionInfo exceptionInfo;
441 GetExceptionInfo( &exceptionInfo );
442 SetImageAlphaChannel( image(), alphaOption_, &exceptionInfo );
443 throwException( exceptionInfo );
444 (void) DestroyExceptionInfo( &exceptionInfo );
447 // Annotate using specified text, and placement location
448 void Magick::Image::annotate ( const std::string &text_,
449 const Geometry &location_ )
451 annotate ( text_, location_, NorthWestGravity, 0.0 );
454 // Annotate using specified text, bounding area, and placement gravity
455 void Magick::Image::annotate ( const std::string &text_,
456 const Geometry &boundingArea_,
457 const GravityType gravity_ )
459 annotate ( text_, boundingArea_, gravity_, 0.0 );
462 // Annotate with text using specified text, bounding area, placement
463 // gravity, and rotation.
464 void Magick::Image::annotate ( const std::string &text_,
465 const Geometry &boundingArea_,
466 const GravityType gravity_,
467 const double degrees_ )
472 = options()->drawInfo();
474 drawInfo->text = const_cast<char *>(text_.c_str());
476 char boundingArea[MaxTextExtent];
478 drawInfo->geometry = 0;
479 if ( boundingArea_.isValid() )
481 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
483 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
484 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
488 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
491 drawInfo->geometry = boundingArea;
494 drawInfo->gravity = gravity_;
496 AffineMatrix oaffine = drawInfo->affine;
497 if ( degrees_ != 0.0)
507 AffineMatrix current = drawInfo->affine;
508 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
509 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
510 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
511 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
513 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
514 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
515 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
516 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
517 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
521 ExceptionInfo exceptionInfo;
522 GetExceptionInfo( &exceptionInfo );
523 AnnotateImage( image(), drawInfo, &exceptionInfo );
525 // Restore original values
526 drawInfo->affine = oaffine;
528 drawInfo->geometry = 0;
530 throwException( exceptionInfo );
531 (void) DestroyExceptionInfo( &exceptionInfo );
534 // Annotate with text (bounding area is entire image) and placement gravity.
535 void Magick::Image::annotate ( const std::string &text_,
536 const GravityType gravity_ )
541 = options()->drawInfo();
543 drawInfo->text = const_cast<char *>(text_.c_str());
545 drawInfo->gravity = gravity_;
547 ExceptionInfo exceptionInfo;
548 GetExceptionInfo( &exceptionInfo );
549 AnnotateImage( image(), drawInfo, &exceptionInfo );
551 drawInfo->gravity = NorthWestGravity;
554 throwException( exceptionInfo );
555 (void) DestroyExceptionInfo( &exceptionInfo );
558 void Magick::Image::artifact ( const std::string &name_,
559 const std::string &value_ )
562 (void) SetImageArtifact ( image(), name_.c_str(), value_.c_str() );
565 std::string Magick::Image::artifact ( const std::string &name_ )
567 const char *value = GetImageArtifact ( image(), name_.c_str() );
569 return std::string( value );
570 return std::string( );
573 void Magick::Image::autoGamma ( void )
576 ExceptionInfo exceptionInfo;
577 GetExceptionInfo( &exceptionInfo );
578 AutoGammaImage( image(), &exceptionInfo );
579 throwException( exceptionInfo );
580 (void) DestroyExceptionInfo( &exceptionInfo );
583 void Magick::Image::autoGammaChannel ( const ChannelType channel_ )
586 ExceptionInfo exceptionInfo;
587 GetExceptionInfo( &exceptionInfo );
588 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
589 AutoGammaImage( image(), &exceptionInfo );
590 SetPixelChannelMask( image(), channel_mask );
591 throwException( exceptionInfo );
592 (void) DestroyExceptionInfo( &exceptionInfo );
595 void Magick::Image::autoLevel ( void )
598 ExceptionInfo exceptionInfo;
599 GetExceptionInfo( &exceptionInfo );
600 AutoLevelImage( image(), &exceptionInfo);
601 throwException( exceptionInfo );
602 (void) DestroyExceptionInfo( &exceptionInfo );
605 void Magick::Image::autoLevelChannel ( const ChannelType channel_ )
608 ExceptionInfo exceptionInfo;
609 GetExceptionInfo( &exceptionInfo );
610 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
611 AutoLevelImage( image(), &exceptionInfo);
612 SetPixelChannelMask( image(), channel_mask );
613 throwException( exceptionInfo );
614 (void) DestroyExceptionInfo( &exceptionInfo );
617 void Magick::Image::autoOrient ( void )
619 if (image()->orientation == UndefinedOrientation ||
620 image()->orientation == TopLeftOrientation)
623 ExceptionInfo exceptionInfo;
624 GetExceptionInfo( &exceptionInfo );
625 MagickCore::Image* newImage =
626 AutoOrientImage( constImage(), image()->orientation, &exceptionInfo );
627 replaceImage( newImage );
628 throwException( exceptionInfo );
629 (void) DestroyExceptionInfo( &exceptionInfo );
632 void Magick::Image::blackThreshold ( const std::string &threshold_ )
635 ExceptionInfo exceptionInfo;
636 GetExceptionInfo( &exceptionInfo );
637 BlackThresholdImage( image(), threshold_.c_str(), &exceptionInfo );
638 throwException( exceptionInfo );
639 (void) DestroyExceptionInfo( &exceptionInfo );
642 void Magick::Image::blackThresholdChannel ( const ChannelType channel_,
643 const std::string &threshold_ )
646 ExceptionInfo exceptionInfo;
647 GetExceptionInfo( &exceptionInfo );
648 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
649 BlackThresholdImage( image(), threshold_.c_str(), &exceptionInfo );
650 SetPixelChannelMask( image(), channel_mask );
651 throwException( exceptionInfo );
652 (void) DestroyExceptionInfo( &exceptionInfo );
655 void Magick::Image::blueShift ( const double factor_ )
657 ExceptionInfo exceptionInfo;
658 GetExceptionInfo( &exceptionInfo );
659 MagickCore::Image* newImage =
660 BlueShiftImage( constImage(), factor_, &exceptionInfo );
661 replaceImage( newImage );
662 throwException( exceptionInfo );
663 (void) DestroyExceptionInfo( &exceptionInfo );
667 void Magick::Image::blur ( const double radius_, const double sigma_ )
669 ExceptionInfo exceptionInfo;
670 GetExceptionInfo( &exceptionInfo );
671 MagickCore::Image* newImage =
672 BlurImage( constImage(), radius_, sigma_, &exceptionInfo );
673 replaceImage( newImage );
674 throwException( exceptionInfo );
675 (void) DestroyExceptionInfo( &exceptionInfo );
678 void Magick::Image::blurChannel ( const ChannelType channel_,
679 const double radius_, const double sigma_ )
681 ExceptionInfo exceptionInfo;
682 GetExceptionInfo( &exceptionInfo );
683 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
684 MagickCore::Image* newImage =
685 BlurImage( constImage(), radius_, sigma_, &exceptionInfo );
686 SetPixelChannelMask( image(), channel_mask );
687 replaceImage( newImage );
688 throwException( exceptionInfo );
689 (void) DestroyExceptionInfo( &exceptionInfo );
692 // Add border to image
693 // Only uses width & height
694 void Magick::Image::border( const Geometry &geometry_ )
696 RectangleInfo borderInfo = geometry_;
697 ExceptionInfo exceptionInfo;
698 GetExceptionInfo( &exceptionInfo );
699 MagickCore::Image* newImage =
700 BorderImage( image(), &borderInfo, image()->compose, &exceptionInfo );
701 replaceImage( newImage );
702 throwException( exceptionInfo );
703 (void) DestroyExceptionInfo( &exceptionInfo );
706 void Magick::Image::brightnessContrast ( const double brightness_,
707 const double contrast_ )
710 ExceptionInfo exceptionInfo;
711 GetExceptionInfo( &exceptionInfo );
712 BrightnessContrastImage( image(), brightness_, contrast_, &exceptionInfo );
713 throwException( exceptionInfo );
714 (void) DestroyExceptionInfo( &exceptionInfo );
717 void Magick::Image::brightnessContrastChannel ( const ChannelType channel_,
718 const double brightness_,
719 const double contrast_ )
722 ExceptionInfo exceptionInfo;
723 GetExceptionInfo( &exceptionInfo );
724 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
725 BrightnessContrastImage( image(), brightness_, contrast_, &exceptionInfo );
726 SetPixelChannelMask( image(), channel_mask );
727 throwException( exceptionInfo );
728 (void) DestroyExceptionInfo( &exceptionInfo );
731 // Extract channel from image
732 void Magick::Image::channel ( const ChannelType channel_ )
734 ExceptionInfo exceptionInfo;
735 GetExceptionInfo( &exceptionInfo );
736 MagickCore::Image* newImage =
737 SeparateImage( image(), channel_, &exceptionInfo );
738 replaceImage( newImage );
739 throwException( exceptionInfo );
740 (void) DestroyExceptionInfo( &exceptionInfo );
743 // Set or obtain modulus channel depth
744 void Magick::Image::channelDepth ( const size_t depth_ )
747 ExceptionInfo exceptionInfo;
748 GetExceptionInfo( &exceptionInfo );
749 SetImageDepth( image(), depth_, &exceptionInfo );
750 throwException( exceptionInfo );
751 (void) DestroyExceptionInfo( &exceptionInfo );
754 size_t Magick::Image::channelDepth ( )
756 size_t channel_depth;
758 ExceptionInfo exceptionInfo;
759 GetExceptionInfo( &exceptionInfo );
760 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
761 throwException( exceptionInfo );
762 (void) DestroyExceptionInfo( &exceptionInfo );
763 return channel_depth;
766 // Charcoal-effect image
767 void Magick::Image::charcoal ( const double radius_, const double sigma_ )
769 ExceptionInfo exceptionInfo;
770 GetExceptionInfo( &exceptionInfo );
771 MagickCore::Image* newImage =
772 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
773 replaceImage( newImage );
774 throwException( exceptionInfo );
775 (void) DestroyExceptionInfo( &exceptionInfo );
779 void Magick::Image::chop ( const Geometry &geometry_ )
781 RectangleInfo chopInfo = geometry_;
782 ExceptionInfo exceptionInfo;
783 GetExceptionInfo( &exceptionInfo );
784 MagickCore::Image* newImage =
785 ChopImage( image(), &chopInfo, &exceptionInfo );
786 replaceImage( newImage );
787 throwException( exceptionInfo );
788 (void) DestroyExceptionInfo( &exceptionInfo );
791 // contains one or more color corrections and applies the correction to the
793 void Magick::Image::cdl ( const std::string &cdl_ )
796 ExceptionInfo exceptionInfo;
797 GetExceptionInfo( &exceptionInfo );
798 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
799 throwException( exceptionInfo );
800 (void) DestroyExceptionInfo( &exceptionInfo );
803 void Magick::Image::clamp ( void )
806 ExceptionInfo exceptionInfo;
807 GetExceptionInfo( &exceptionInfo );
808 ClampImage( image(), &exceptionInfo );
809 throwException( exceptionInfo );
810 (void) DestroyExceptionInfo( &exceptionInfo );
813 void Magick::Image::clampChannel ( const ChannelType channel_ )
816 ExceptionInfo exceptionInfo;
817 GetExceptionInfo( &exceptionInfo );
818 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
819 ClampImage( image(), &exceptionInfo );
820 SetPixelChannelMask( image(), channel_mask );
821 throwException( exceptionInfo );
822 (void) DestroyExceptionInfo( &exceptionInfo );
825 void Magick::Image::clut ( const Image &clutImage_,
826 const PixelInterpolateMethod method )
829 ExceptionInfo exceptionInfo;
830 GetExceptionInfo( &exceptionInfo );
831 ClutImage( image(), clutImage_.constImage(), method, &exceptionInfo );
832 throwException( exceptionInfo );
833 (void) DestroyExceptionInfo( &exceptionInfo );
836 void Magick::Image::clutChannel ( const ChannelType channel_,
837 const Image &clutImage_,
838 const PixelInterpolateMethod method)
841 ExceptionInfo exceptionInfo;
842 GetExceptionInfo( &exceptionInfo );
843 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
844 ClutImage( image(), clutImage_.constImage(), method, &exceptionInfo );
845 SetPixelChannelMask( image(), channel_mask );
846 throwException( exceptionInfo );
847 (void) DestroyExceptionInfo( &exceptionInfo );
851 void Magick::Image::colorize ( const unsigned int alphaRed_,
852 const unsigned int alphaGreen_,
853 const unsigned int alphaBlue_,
854 const Color &penColor_ )
856 if ( !penColor_.isValid() )
857 throwExceptionExplicit( OptionError, "Pen color argument is invalid" );
859 char blend[MaxTextExtent];
860 FormatLocaleString( blend, MaxTextExtent, "%u/%u/%u",
861 alphaRed_, alphaGreen_, alphaBlue_ );
863 ExceptionInfo exceptionInfo;
864 GetExceptionInfo( &exceptionInfo );
866 GetPixelInfo(image(),&target);
867 PixelInfo pixel=static_cast<PixelInfo>(penColor_);
868 target.red=pixel.red;
869 target.green=pixel.green;
870 target.blue=pixel.blue;
871 target.alpha=pixel.alpha;
872 MagickCore::Image* newImage =
873 ColorizeImage ( image(), blend, &target, &exceptionInfo );
874 replaceImage( newImage );
875 throwException( exceptionInfo );
876 (void) DestroyExceptionInfo( &exceptionInfo );
879 void Magick::Image::colorize ( const unsigned int alpha_,
880 const Color &penColor_ )
882 colorize( alpha_, alpha_, alpha_, penColor_ );
885 // Apply a color matrix to the image channels. The user supplied
886 // matrix may be of order 1 to 6 (1x1 through 6x6).
887 void Magick::Image::colorMatrix ( const size_t order_,
888 const double *color_matrix_ )
893 ExceptionInfo exceptionInfo;
894 GetExceptionInfo( &exceptionInfo );
895 kernel_info=AcquireKernelInfo((const char *) NULL);
896 kernel_info->width=order_;
897 kernel_info->height=order_;
898 kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
899 order_*sizeof(*kernel_info->values));
900 if (kernel_info->values != (MagickRealType *) NULL)
902 for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
903 kernel_info->values[i]=color_matrix_[i];
904 MagickCore::Image* newImage =
905 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
906 replaceImage( newImage );
908 kernel_info=DestroyKernelInfo(kernel_info);
909 throwException( exceptionInfo );
910 (void) DestroyExceptionInfo( &exceptionInfo );
913 // Compare current image with another image
914 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
915 // in the current image. False is returned if the images are identical.
916 bool Magick::Image::compare ( const Image &reference_ )
918 ExceptionInfo exceptionInfo;
919 GetExceptionInfo( &exceptionInfo );
921 Image ref = reference_;
924 static_cast<bool>(IsImagesEqual(image(), ref.image(), &exceptionInfo));
925 throwException( exceptionInfo );
926 (void) DestroyExceptionInfo( &exceptionInfo );
930 // Composite two images
931 void Magick::Image::composite ( const Image &compositeImage_,
932 const ssize_t xOffset_,
933 const ssize_t yOffset_,
934 const CompositeOperator compose_ )
936 // Image supplied as compositeImage is composited with current image and
937 // results in updating current image.
940 ExceptionInfo exceptionInfo;
941 GetExceptionInfo( &exceptionInfo );
942 CompositeImage( image(), compositeImage_.constImage(), compose_, MagickFalse,
943 xOffset_, yOffset_, &exceptionInfo );
944 throwException( exceptionInfo );
945 (void) DestroyExceptionInfo( &exceptionInfo );
948 void Magick::Image::composite ( const Image &compositeImage_,
949 const Geometry &offset_,
950 const CompositeOperator compose_ )
954 ssize_t x = offset_.xOff();
955 ssize_t y = offset_.yOff();
956 size_t width = columns();
957 size_t height = rows();
959 ParseMetaGeometry ( static_cast<std::string>(offset_).c_str(),
963 ExceptionInfo exceptionInfo;
964 GetExceptionInfo( &exceptionInfo );
965 CompositeImage( image(), compositeImage_.constImage(), compose_, MagickFalse,
966 x, y, &exceptionInfo );
967 throwException( exceptionInfo );
968 (void) DestroyExceptionInfo( &exceptionInfo );
971 void Magick::Image::composite ( const Image &compositeImage_,
972 const GravityType gravity_,
973 const CompositeOperator compose_ )
977 RectangleInfo geometry;
979 SetGeometry(compositeImage_.constImage(), &geometry);
980 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
982 ExceptionInfo exceptionInfo;
983 GetExceptionInfo( &exceptionInfo );
984 CompositeImage( image(), compositeImage_.constImage(), compose_, MagickFalse,
985 geometry.x, geometry.y, &exceptionInfo );
986 throwException( exceptionInfo );
987 (void) DestroyExceptionInfo( &exceptionInfo );
991 void Magick::Image::contrast ( const size_t sharpen_ )
994 ExceptionInfo exceptionInfo;
995 GetExceptionInfo( &exceptionInfo );
996 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
997 throwException( exceptionInfo );
998 (void) DestroyExceptionInfo( &exceptionInfo );
1001 void Magick::Image::contrastStretch ( const double black_point_,
1002 const double white_point_ )
1005 ExceptionInfo exceptionInfo;
1006 GetExceptionInfo( &exceptionInfo );
1007 ContrastStretchImage ( image(), black_point_, white_point_, &exceptionInfo );
1008 throwException( exceptionInfo );
1009 (void) DestroyExceptionInfo( &exceptionInfo );
1012 void Magick::Image::contrastStretchChannel ( const ChannelType channel_,
1013 const double black_point_,
1014 const double white_point_ )
1017 ExceptionInfo exceptionInfo;
1018 GetExceptionInfo( &exceptionInfo );
1019 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
1020 ContrastStretchImage ( image(), black_point_, white_point_, &exceptionInfo );
1021 SetPixelChannelMask( image(), channel_mask );
1022 throwException( exceptionInfo );
1023 (void) DestroyExceptionInfo( &exceptionInfo );
1026 // Convolve image. Applies a general image convolution kernel to the image.
1027 // order_ represents the number of columns and rows in the filter kernel.
1028 // kernel_ is an array of doubles representing the convolution kernel.
1029 void Magick::Image::convolve ( const size_t order_,
1030 const double *kernel_ )
1035 ExceptionInfo exceptionInfo;
1036 GetExceptionInfo( &exceptionInfo );
1037 kernel_info=AcquireKernelInfo((const char *) NULL);
1038 kernel_info->width=order_;
1039 kernel_info->height=order_;
1040 kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
1041 order_*sizeof(*kernel_info->values));
1042 if (kernel_info->values != (MagickRealType *) NULL)
1044 for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
1045 kernel_info->values[i]=kernel_[i];
1046 MagickCore::Image* newImage =
1047 ConvolveImage ( image(), kernel_info, &exceptionInfo );
1048 replaceImage( newImage );
1050 kernel_info=DestroyKernelInfo(kernel_info);
1051 throwException( exceptionInfo );
1052 (void) DestroyExceptionInfo( &exceptionInfo );
1056 void Magick::Image::crop ( const Geometry &geometry_ )
1058 RectangleInfo cropInfo = geometry_;
1059 ExceptionInfo exceptionInfo;
1060 GetExceptionInfo( &exceptionInfo );
1061 MagickCore::Image* newImage =
1062 CropImage( image(), &cropInfo, &exceptionInfo );
1063 replaceImage( newImage );
1064 throwException( exceptionInfo );
1065 (void) DestroyExceptionInfo( &exceptionInfo );
1069 void Magick::Image::cycleColormap ( const ssize_t amount_ )
1072 ExceptionInfo exceptionInfo;
1073 GetExceptionInfo( &exceptionInfo );
1074 CycleColormapImage( image(), amount_, &exceptionInfo );
1075 throwException( exceptionInfo );
1076 (void) DestroyExceptionInfo( &exceptionInfo );
1079 void Magick::Image::decipher ( const std::string &passphrase_ )
1082 ExceptionInfo exceptionInfo;
1083 GetExceptionInfo( &exceptionInfo );
1084 DecipherImage( image(), passphrase_.c_str(), &exceptionInfo );
1085 throwException( exceptionInfo );
1086 (void) DestroyExceptionInfo( &exceptionInfo );
1090 void Magick::Image::despeckle ( void )
1092 ExceptionInfo exceptionInfo;
1093 GetExceptionInfo( &exceptionInfo );
1094 MagickCore::Image* newImage =
1095 DespeckleImage( image(), &exceptionInfo );
1096 replaceImage( newImage );
1097 throwException( exceptionInfo );
1098 (void) DestroyExceptionInfo( &exceptionInfo );
1101 void Magick::Image::deskew ( const double threshold_ )
1103 ExceptionInfo exceptionInfo;
1104 GetExceptionInfo( &exceptionInfo );
1105 MagickCore::Image* newImage =
1106 DeskewImage( image(), threshold_, &exceptionInfo );
1107 replaceImage( newImage );
1108 throwException( exceptionInfo );
1109 (void) DestroyExceptionInfo( &exceptionInfo );
1113 void Magick::Image::display( void )
1115 ExceptionInfo exceptionInfo;
1116 GetExceptionInfo( &exceptionInfo );
1117 DisplayImages( imageInfo(), image(), &exceptionInfo );
1118 throwException( exceptionInfo );
1119 (void) DestroyExceptionInfo( &exceptionInfo );
1122 // Distort image. distorts an image using various distortion methods, by
1123 // mapping color lookups of the source image to a new destination image
1124 // usally of the same size as the source image, unless 'bestfit' is set to
1126 void Magick::Image::distort ( const DistortImageMethod method_,
1127 const size_t number_arguments_,
1128 const double *arguments_,
1129 const bool bestfit_ )
1131 ExceptionInfo exceptionInfo;
1132 GetExceptionInfo( &exceptionInfo );
1133 MagickCore::Image* newImage = DistortImage ( image(), method_,
1134 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
1136 replaceImage( newImage );
1137 throwException( exceptionInfo );
1138 (void) DestroyExceptionInfo( &exceptionInfo );
1141 // Draw on image using single drawable
1142 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
1146 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
1150 drawable_.operator()(wand);
1154 wand=DestroyDrawingWand(wand);
1157 throwImageException();
1160 // Draw on image using a drawable list
1161 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
1165 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
1169 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
1170 p != drawable_.end(); p++ )
1172 p->operator()(wand);
1177 wand=DestroyDrawingWand(wand);
1180 throwImageException();
1183 // Hilight edges in image
1184 void Magick::Image::edge ( const double radius_ )
1186 ExceptionInfo exceptionInfo;
1187 GetExceptionInfo( &exceptionInfo );
1188 MagickCore::Image* newImage =
1189 EdgeImage( image(), radius_, &exceptionInfo );
1190 replaceImage( newImage );
1191 throwException( exceptionInfo );
1192 (void) DestroyExceptionInfo( &exceptionInfo );
1195 // Emboss image (hilight edges)
1196 void Magick::Image::emboss ( const double radius_, const double sigma_ )
1198 ExceptionInfo exceptionInfo;
1199 GetExceptionInfo( &exceptionInfo );
1200 MagickCore::Image* newImage =
1201 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
1202 replaceImage( newImage );
1203 throwException( exceptionInfo );
1204 (void) DestroyExceptionInfo( &exceptionInfo );
1207 void Magick::Image::encipher ( const std::string &passphrase_ )
1210 ExceptionInfo exceptionInfo;
1211 GetExceptionInfo( &exceptionInfo );
1212 EncipherImage( image(), passphrase_.c_str(), &exceptionInfo );
1213 throwException( exceptionInfo );
1214 (void) DestroyExceptionInfo( &exceptionInfo );
1217 // Enhance image (minimize noise)
1218 void Magick::Image::enhance ( void )
1220 ExceptionInfo exceptionInfo;
1221 GetExceptionInfo( &exceptionInfo );
1222 MagickCore::Image* newImage =
1223 EnhanceImage( image(), &exceptionInfo );
1224 replaceImage( newImage );
1225 throwException( exceptionInfo );
1226 (void) DestroyExceptionInfo( &exceptionInfo );
1229 // Equalize image (histogram equalization)
1230 void Magick::Image::equalize ( void )
1232 ExceptionInfo exceptionInfo;
1233 GetExceptionInfo( &exceptionInfo );
1235 EqualizeImage( image(), &exceptionInfo );
1236 throwException( exceptionInfo );
1237 (void) DestroyExceptionInfo( &exceptionInfo );
1240 // Erase image to current "background color"
1241 void Magick::Image::erase ( void )
1244 ExceptionInfo exceptionInfo;
1245 GetExceptionInfo( &exceptionInfo );
1246 SetImageBackgroundColor( image(), &exceptionInfo );
1247 throwException( exceptionInfo );
1248 (void) DestroyExceptionInfo( &exceptionInfo );
1251 // Extends image as defined by the geometry.
1252 void Magick::Image::extent ( const Geometry &geometry_ )
1255 ExceptionInfo exceptionInfo;
1256 GetExceptionInfo( &exceptionInfo );
1257 RectangleInfo extentInfo = geometry_;
1258 extentInfo.x = geometry_.xOff();
1259 extentInfo.y = geometry_.yOff();
1260 MagickCore::Image* newImage =
1261 ExtentImage ( image(), &extentInfo, &exceptionInfo );
1262 replaceImage( newImage );
1263 throwException( exceptionInfo );
1264 (void) DestroyExceptionInfo( &exceptionInfo );
1267 void Magick::Image::extent ( const Geometry &geometry_,
1268 const Color &backgroundColor_ )
1270 backgroundColor ( backgroundColor_ );
1271 extent ( geometry_ );
1274 void Magick::Image::extent ( const Geometry &geometry_,
1275 const GravityType gravity_ )
1277 RectangleInfo geometry;
1279 SetGeometry(image(), &geometry);
1280 geometry.width = geometry_.width();
1281 geometry.height = geometry_.height();
1282 GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry);
1283 extent ( geometry );
1286 void Magick::Image::extent ( const Geometry &geometry_,
1287 const Color &backgroundColor_,
1288 const GravityType gravity_ )
1290 backgroundColor ( backgroundColor_ );
1291 extent ( geometry_, gravity_ );
1294 // Flip image (reflect each scanline in the vertical direction)
1295 void Magick::Image::flip ( void )
1297 ExceptionInfo exceptionInfo;
1298 GetExceptionInfo( &exceptionInfo );
1299 MagickCore::Image* newImage =
1300 FlipImage( image(), &exceptionInfo );
1301 replaceImage( newImage );
1302 throwException( exceptionInfo );
1303 (void) DestroyExceptionInfo( &exceptionInfo );
1306 // Flood-fill color across pixels that match the color of the
1307 // target pixel and are neighbors of the target pixel.
1308 // Uses current fuzz setting when determining color match.
1309 void Magick::Image::floodFillColor ( const ssize_t x_,
1311 const Magick::Color &fillColor_ )
1313 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
1316 void Magick::Image::floodFillColor ( const Geometry &point_,
1317 const Magick::Color &fillColor_ )
1319 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
1322 // Flood-fill color across pixels starting at target-pixel and
1323 // stopping at pixels matching specified border color.
1324 // Uses current fuzz setting when determining color match.
1325 void Magick::Image::floodFillColor ( const ssize_t x_,
1327 const Magick::Color &fillColor_,
1328 const Magick::Color &borderColor_ )
1330 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
1334 void Magick::Image::floodFillColor ( const Geometry &point_,
1335 const Magick::Color &fillColor_,
1336 const Magick::Color &borderColor_ )
1338 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
1342 // Floodfill pixels matching color (within fuzz factor) of target
1343 // pixel(x,y) with replacement alpha value using method.
1344 void Magick::Image::floodFillAlpha ( const ssize_t x_,
1346 const unsigned int alpha_,
1347 const PaintMethod method_ )
1351 GetPixelInfo(image(),&target);
1352 PixelInfo pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
1353 target.red=pixel.red;
1354 target.green=pixel.green;
1355 target.blue=pixel.blue;
1356 target.alpha=alpha_;
1357 ExceptionInfo exceptionInfo;
1358 GetExceptionInfo( &exceptionInfo );
1359 FloodfillPaintImage ( image(),
1360 options()->drawInfo(), // const DrawInfo *draw_info
1362 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
1363 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1365 throwException( exceptionInfo );
1366 (void) DestroyExceptionInfo( &exceptionInfo );
1369 // Flood-fill texture across pixels that match the color of the
1370 // target pixel and are neighbors of the target pixel.
1371 // Uses current fuzz setting when determining color match.
1372 void Magick::Image::floodFillTexture ( const ssize_t x_,
1374 const Magick::Image &texture_ )
1378 // Set drawing pattern
1379 options()->fillPattern(texture_.constImage());
1382 Pixels pixels(*this);
1384 Quantum *p = pixels.get(x_, y_, 1, 1 );
1386 GetPixelInfo(constImage(),&target);
1387 target.red=GetPixelRed(constImage(),p);
1388 target.green=GetPixelGreen(constImage(),p);
1389 target.blue=GetPixelBlue(constImage(),p);
1390 ExceptionInfo exceptionInfo;
1391 GetExceptionInfo( &exceptionInfo );
1393 FloodfillPaintImage ( image(), // Image *image
1394 options()->drawInfo(), // const DrawInfo *draw_info
1395 &target, // const MagickPacket target
1396 static_cast<ssize_t>(x_), // const ssize_t x_offset
1397 static_cast<ssize_t>(y_), // const ssize_t y_offset
1398 MagickFalse, // const PaintMethod method
1400 throwException( exceptionInfo );
1401 (void) DestroyExceptionInfo( &exceptionInfo );
1404 void Magick::Image::floodFillTexture ( const Magick::Geometry &point_,
1405 const Magick::Image &texture_ )
1407 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1410 // Flood-fill texture across pixels starting at target-pixel and
1411 // stopping at pixels matching specified border color.
1412 // Uses current fuzz setting when determining color match.
1413 void Magick::Image::floodFillTexture ( const ssize_t x_,
1415 const Magick::Image &texture_,
1416 const Magick::Color &borderColor_ )
1420 // Set drawing fill pattern
1421 options()->fillPattern(texture_.constImage());
1424 GetPixelInfo(constImage(),&target);
1425 target.red=static_cast<PixelInfo>(borderColor_).red;
1426 target.green=static_cast<PixelInfo>(borderColor_).green;
1427 target.blue=static_cast<PixelInfo>(borderColor_).blue;
1428 ExceptionInfo exceptionInfo;
1429 GetExceptionInfo( &exceptionInfo );
1430 FloodfillPaintImage ( image(),
1431 options()->drawInfo(),
1433 static_cast<ssize_t>(x_),
1434 static_cast<ssize_t>(y_),
1435 MagickTrue, &exceptionInfo);
1437 throwException( exceptionInfo );
1438 (void) DestroyExceptionInfo( &exceptionInfo );
1441 void Magick::Image::floodFillTexture ( const Magick::Geometry &point_,
1442 const Magick::Image &texture_,
1443 const Magick::Color &borderColor_ )
1445 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1448 // Flop image (reflect each scanline in the horizontal direction)
1449 void Magick::Image::flop ( void )
1451 ExceptionInfo exceptionInfo;
1452 GetExceptionInfo( &exceptionInfo );
1453 MagickCore::Image* newImage =
1454 FlopImage( image(), &exceptionInfo );
1455 replaceImage( newImage );
1456 throwException( exceptionInfo );
1457 (void) DestroyExceptionInfo( &exceptionInfo );
1461 void Magick::Image::frame ( const Geometry &geometry_ )
1465 info.x = static_cast<ssize_t>(geometry_.width());
1466 info.y = static_cast<ssize_t>(geometry_.height());
1467 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1468 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1469 info.outer_bevel = geometry_.xOff();
1470 info.inner_bevel = geometry_.yOff();
1472 ExceptionInfo exceptionInfo;
1473 GetExceptionInfo( &exceptionInfo );
1474 MagickCore::Image* newImage =
1475 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1476 replaceImage( newImage );
1477 throwException( exceptionInfo );
1478 (void) DestroyExceptionInfo( &exceptionInfo );
1481 void Magick::Image::frame ( const size_t width_,
1482 const size_t height_,
1483 const ssize_t outerBevel_,
1484 const ssize_t innerBevel_ )
1487 info.x = static_cast<ssize_t>(width_);
1488 info.y = static_cast<ssize_t>(height_);
1489 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1490 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1491 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1492 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1494 ExceptionInfo exceptionInfo;
1495 GetExceptionInfo( &exceptionInfo );
1496 MagickCore::Image* newImage =
1497 FrameImage( image(), &info, image()->compose, &exceptionInfo );
1498 replaceImage( newImage );
1499 throwException( exceptionInfo );
1500 (void) DestroyExceptionInfo( &exceptionInfo );
1503 // Fx image. Applies a mathematical expression to the image.
1504 void Magick::Image::fx ( const std::string expression )
1506 ExceptionInfo exceptionInfo;
1507 GetExceptionInfo( &exceptionInfo );
1508 MagickCore::Image* newImage =
1509 FxImage ( image(), expression.c_str(), &exceptionInfo );
1510 replaceImage( newImage );
1511 throwException( exceptionInfo );
1512 (void) DestroyExceptionInfo( &exceptionInfo );
1515 void Magick::Image::fx ( const std::string expression,
1516 const Magick::ChannelType channel )
1518 ExceptionInfo exceptionInfo;
1519 GetExceptionInfo( &exceptionInfo );
1520 ChannelType channel_mask = SetImageChannelMask( image(), channel );
1521 MagickCore::Image* newImage =
1522 FxImage ( image(), expression.c_str(), &exceptionInfo );
1523 SetPixelChannelMask( image(), channel_mask );
1524 replaceImage( newImage );
1525 throwException( exceptionInfo );
1526 (void) DestroyExceptionInfo( &exceptionInfo );
1529 // Gamma correct image
1530 void Magick::Image::gamma ( const double gamma_ )
1532 ExceptionInfo exceptionInfo;
1533 GetExceptionInfo( &exceptionInfo );
1535 GammaImage ( image(), gamma_, &exceptionInfo );
1536 throwException( exceptionInfo );
1537 (void) DestroyExceptionInfo( &exceptionInfo );
1540 void Magick::Image::gamma ( const double gammaRed_,
1541 const double gammaGreen_,
1542 const double gammaBlue_ )
1544 char gamma[MaxTextExtent + 1];
1545 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1546 gammaRed_, gammaGreen_, gammaBlue_);
1548 ExceptionInfo exceptionInfo;
1549 GetExceptionInfo( &exceptionInfo );
1551 GammaImage ( image(), atof(gamma), &exceptionInfo );
1552 throwException( exceptionInfo );
1553 (void) DestroyExceptionInfo( &exceptionInfo );
1556 // Gaussian blur image
1557 // The number of neighbor pixels to be included in the convolution
1558 // mask is specified by 'width_'. The standard deviation of the
1559 // gaussian bell curve is specified by 'sigma_'.
1560 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1562 ExceptionInfo exceptionInfo;
1563 GetExceptionInfo( &exceptionInfo );
1564 MagickCore::Image* newImage =
1565 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1566 replaceImage( newImage );
1567 throwException( exceptionInfo );
1568 (void) DestroyExceptionInfo( &exceptionInfo );
1571 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1572 const double width_,
1573 const double sigma_ )
1575 ExceptionInfo exceptionInfo;
1576 GetExceptionInfo( &exceptionInfo );
1577 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
1578 MagickCore::Image* newImage =
1579 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1580 SetPixelChannelMask( image(), channel_mask );
1581 replaceImage( newImage );
1582 throwException( exceptionInfo );
1583 (void) DestroyExceptionInfo( &exceptionInfo );
1586 // Apply a color lookup table (Hald CLUT) to the image.
1587 void Magick::Image::haldClut ( const Image &clutImage_ )
1589 ExceptionInfo exceptionInfo;
1590 GetExceptionInfo( &exceptionInfo );
1592 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1593 throwException( exceptionInfo );
1594 (void) DestroyExceptionInfo( &exceptionInfo );
1598 void Magick::Image::implode ( const double factor_ )
1600 ExceptionInfo exceptionInfo;
1601 GetExceptionInfo( &exceptionInfo );
1602 MagickCore::Image* newImage =
1603 ImplodeImage( image(), factor_, image()->interpolate, &exceptionInfo );
1604 replaceImage( newImage );
1605 throwException( exceptionInfo );
1606 (void) DestroyExceptionInfo( &exceptionInfo );
1609 // implements the inverse discrete Fourier transform (IFT) of the image either
1610 // as a magnitude / phase or real / imaginary image pair.
1611 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1613 ExceptionInfo exceptionInfo;
1614 GetExceptionInfo( &exceptionInfo );
1615 MagickCore::Image* newImage =
1616 InverseFourierTransformImage( image(), phase_.constImage(), MagickTrue,
1618 replaceImage( newImage );
1619 throwException( exceptionInfo );
1620 (void) DestroyExceptionInfo( &exceptionInfo );
1623 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1624 const bool magnitude_ )
1626 ExceptionInfo exceptionInfo;
1627 GetExceptionInfo( &exceptionInfo );
1628 MagickCore::Image* newImage =
1629 InverseFourierTransformImage( image(), phase_.constImage(),
1630 magnitude_ == true ? MagickTrue : MagickFalse,
1632 replaceImage( newImage );
1633 throwException( exceptionInfo );
1634 (void) DestroyExceptionInfo( &exceptionInfo );
1637 // Level image. Adjust the levels of the image by scaling the colors
1638 // falling between specified white and black points to the full
1639 // available quantum range. The parameters provided represent the
1640 // black, mid (gamma), and white points. The black point specifies
1641 // the darkest color in the image. Colors darker than the black point
1642 // are set to zero. Mid point (gamma) specifies a gamma correction to
1643 // apply to the image. White point specifies the lightest color in the
1644 // image. Colors brighter than the white point are set to the maximum
1645 // quantum value. The black and white point have the valid range 0 to
1646 // QuantumRange while gamma has a useful range of 0 to ten.
1647 void Magick::Image::level ( const double blackPoint_,
1648 const double whitePoint_,
1649 const double gamma_ )
1652 ExceptionInfo exceptionInfo;
1653 GetExceptionInfo( &exceptionInfo );
1654 (void) LevelImage( image(), blackPoint_, whitePoint_, gamma_,
1656 throwException( exceptionInfo );
1657 (void) DestroyExceptionInfo( &exceptionInfo );
1660 void Magick::Image::levelChannel ( const ChannelType channel_,
1661 const double blackPoint_,
1662 const double whitePoint_,
1663 const double gamma_ )
1666 ExceptionInfo exceptionInfo;
1667 GetExceptionInfo( &exceptionInfo );
1668 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
1669 (void) LevelImage( image(), blackPoint_, whitePoint_, gamma_,
1671 SetPixelChannelMask( image(), channel_mask );
1672 throwException( exceptionInfo );
1673 (void) DestroyExceptionInfo( &exceptionInfo );
1676 void Magick::Image::levelColors ( const Color &blackColor_,
1677 const Color &whiteColor_,
1678 const bool invert_ )
1681 ExceptionInfo exceptionInfo;
1682 GetExceptionInfo( &exceptionInfo );
1685 GetPixelInfo(image(), &black);
1686 PixelInfo pixel=static_cast<PixelInfo>(blackColor_);
1687 black.red=pixel.red;
1688 black.green=pixel.green;
1689 black.blue=pixel.blue;
1690 black.alpha=pixel.alpha;
1693 GetPixelInfo(image(), &white);
1694 pixel=static_cast<PixelInfo>(whiteColor_);
1695 white.red=pixel.red;
1696 white.green=pixel.green;
1697 white.blue=pixel.blue;
1698 white.alpha=pixel.alpha;
1700 (void) LevelImageColors( image(), &black, &white,
1701 invert_ == true ? MagickTrue : MagickFalse,
1703 throwException( exceptionInfo );
1704 (void) DestroyExceptionInfo( &exceptionInfo );
1707 void Magick::Image::levelColorsChannel ( const ChannelType channel_,
1708 const Color &blackColor_,
1709 const Color &whiteColor_,
1710 const bool invert_ )
1713 ExceptionInfo exceptionInfo;
1714 GetExceptionInfo( &exceptionInfo );
1717 GetPixelInfo(image(), &black);
1718 PixelInfo pixel=static_cast<PixelInfo>(blackColor_);
1719 black.red=pixel.red;
1720 black.green=pixel.green;
1721 black.blue=pixel.blue;
1722 black.alpha=pixel.alpha;
1725 GetPixelInfo(image(), &white);
1726 pixel=static_cast<PixelInfo>(whiteColor_);
1727 white.red=pixel.red;
1728 white.green=pixel.green;
1729 white.blue=pixel.blue;
1730 white.alpha=pixel.alpha;
1732 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
1733 (void) LevelImageColors( image(), &black, &white,
1734 invert_ == true ? MagickTrue : MagickFalse,
1736 SetPixelChannelMask( image(), channel_mask );
1737 throwException( exceptionInfo );
1738 (void) DestroyExceptionInfo( &exceptionInfo );
1741 void Magick::Image::linearStretch ( const double blackPoint_,
1742 const double whitePoint_ )
1745 ExceptionInfo exceptionInfo;
1746 GetExceptionInfo( &exceptionInfo );
1747 LinearStretchImage( image(), blackPoint_, whitePoint_, &exceptionInfo );
1748 throwException( exceptionInfo );
1749 (void) DestroyExceptionInfo( &exceptionInfo );
1752 void Magick::Image::liquidRescale ( const Geometry &geometry_ )
1756 size_t width = columns();
1757 size_t height = rows();
1759 ParseMetaGeometry( static_cast<std::string>(geometry_).c_str(),
1764 ExceptionInfo exceptionInfo;
1765 GetExceptionInfo( &exceptionInfo );
1766 LiquidRescaleImage( image(), width, height, x, y, &exceptionInfo );
1767 throwException( exceptionInfo );
1768 (void) DestroyExceptionInfo( &exceptionInfo );
1771 // Magnify image by integral size
1772 void Magick::Image::magnify ( void )
1774 ExceptionInfo exceptionInfo;
1775 GetExceptionInfo( &exceptionInfo );
1776 MagickCore::Image* newImage =
1777 MagnifyImage( image(), &exceptionInfo );
1778 replaceImage( newImage );
1779 throwException( exceptionInfo );
1780 (void) DestroyExceptionInfo( &exceptionInfo );
1783 // Remap image colors with closest color from reference image
1784 void Magick::Image::map ( const Image &mapImage_, const bool dither_ )
1786 ExceptionInfo exceptionInfo;
1787 GetExceptionInfo( &exceptionInfo );
1789 options()->quantizeDither( dither_ );
1790 RemapImage ( options()->quantizeInfo(), image(),
1791 mapImage_.constImage(), &exceptionInfo);
1792 throwException( exceptionInfo );
1793 (void) DestroyExceptionInfo( &exceptionInfo );
1796 // Floodfill designated area with replacement alpha value
1797 void Magick::Image::matteFloodfill ( const Color &target_,
1798 const unsigned int alpha_,
1799 const ssize_t x_, const ssize_t y_,
1800 const Magick::PaintMethod method_ )
1804 GetPixelInfo(constImage(),&target);
1805 target.red=static_cast<PixelInfo>(target_).red;
1806 target.green=static_cast<PixelInfo>(target_).green;
1807 target.blue=static_cast<PixelInfo>(target_).blue;
1808 target.alpha=alpha_;
1809 ChannelType channel_mask = SetImageChannelMask( image(), AlphaChannel );
1810 ExceptionInfo exceptionInfo;
1811 GetExceptionInfo( &exceptionInfo );
1812 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1813 method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
1814 SetPixelChannelMask( image(), channel_mask );
1815 throwException( exceptionInfo );
1816 (void) DestroyExceptionInfo( &exceptionInfo );
1819 // Filter image by replacing each pixel component with the median
1820 // color in a circular neighborhood
1821 void Magick::Image::medianFilter ( const double radius_ )
1823 ExceptionInfo exceptionInfo;
1824 GetExceptionInfo( &exceptionInfo );
1825 MagickCore::Image* newImage =
1826 StatisticImage ( image(), MedianStatistic, (size_t) radius_,
1827 (size_t) radius_, &exceptionInfo );
1828 replaceImage( newImage );
1829 throwException( exceptionInfo );
1830 (void) DestroyExceptionInfo( &exceptionInfo );
1833 // Reduce image by integral size
1834 void Magick::Image::minify ( void )
1836 ExceptionInfo exceptionInfo;
1837 GetExceptionInfo( &exceptionInfo );
1838 MagickCore::Image* newImage =
1839 MinifyImage( image(), &exceptionInfo );
1840 replaceImage( newImage );
1841 throwException( exceptionInfo );
1842 (void) DestroyExceptionInfo( &exceptionInfo );
1845 // Modulate percent hue, saturation, and brightness of an image
1846 void Magick::Image::modulate ( const double brightness_,
1847 const double saturation_,
1850 char modulate[MaxTextExtent + 1];
1851 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1852 brightness_, saturation_, hue_);
1854 ExceptionInfo exceptionInfo;
1855 GetExceptionInfo( &exceptionInfo );
1857 ModulateImage( image(), modulate, &exceptionInfo );
1858 throwException( exceptionInfo );
1859 (void) DestroyExceptionInfo( &exceptionInfo );
1862 // Motion blur image with specified blur factor
1863 // The radius_ parameter specifies the radius of the Gaussian, in
1864 // pixels, not counting the center pixel. The sigma_ parameter
1865 // specifies the standard deviation of the Laplacian, in pixels.
1866 // The angle_ parameter specifies the angle the object appears
1867 // to be comming from (zero degrees is from the right).
1868 void Magick::Image::motionBlur ( const double radius_,
1869 const double sigma_,
1870 const double angle_ )
1872 ExceptionInfo exceptionInfo;
1873 GetExceptionInfo( &exceptionInfo );
1874 MagickCore::Image* newImage =
1875 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1876 replaceImage( newImage );
1877 throwException( exceptionInfo );
1878 (void) DestroyExceptionInfo( &exceptionInfo );
1881 // Negate image. Set grayscale_ to true to effect grayscale values
1883 void Magick::Image::negate ( const bool grayscale_ )
1885 ExceptionInfo exceptionInfo;
1886 GetExceptionInfo( &exceptionInfo );
1888 NegateImage( image(), (MagickBooleanType) grayscale_, &exceptionInfo );
1889 throwException( exceptionInfo );
1890 (void) DestroyExceptionInfo( &exceptionInfo );
1893 void Magick::Image::negateChannel ( const ChannelType channel_,
1894 const bool grayscale_ )
1896 ExceptionInfo exceptionInfo;
1897 GetExceptionInfo( &exceptionInfo );
1899 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
1900 NegateImage( image(), (MagickBooleanType) grayscale_, &exceptionInfo );
1901 SetPixelChannelMask( image(), channel_mask );
1902 throwException( exceptionInfo );
1903 (void) DestroyExceptionInfo( &exceptionInfo );
1907 void Magick::Image::normalize ( void )
1910 ExceptionInfo exceptionInfo;
1911 GetExceptionInfo( &exceptionInfo );
1912 NormalizeImage ( image(), &exceptionInfo );
1913 throwException( exceptionInfo );
1914 (void) DestroyExceptionInfo( &exceptionInfo );
1918 void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
1920 ExceptionInfo exceptionInfo;
1921 GetExceptionInfo( &exceptionInfo );
1922 MagickCore::Image* newImage =
1923 OilPaintImage( image(), radius_, sigma_, &exceptionInfo );
1924 replaceImage( newImage );
1925 throwException( exceptionInfo );
1926 (void) DestroyExceptionInfo( &exceptionInfo );
1929 // Change the color of an opaque pixel to the pen color.
1930 void Magick::Image::opaque ( const Color &opaqueColor_,
1931 const Color &penColor_ )
1933 if ( !opaqueColor_.isValid() )
1934 throwExceptionExplicit( OptionError, "Opaque color argument is invalid" );
1936 if ( !penColor_.isValid() )
1937 throwExceptionExplicit( OptionError, "Pen color argument is invalid" );
1940 std::string opaqueColor = opaqueColor_;
1941 std::string penColor = penColor_;
1945 ExceptionInfo exceptionInfo;
1946 GetExceptionInfo( &exceptionInfo );
1947 (void) QueryColorCompliance( std::string(opaqueColor_).c_str(),
1948 AllCompliance, &opaque, &exceptionInfo );
1949 (void) QueryColorCompliance( std::string(penColor_).c_str(),
1950 AllCompliance, &pen, &exceptionInfo );
1951 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo );
1952 throwException( exceptionInfo );
1953 (void) DestroyExceptionInfo( &exceptionInfo );
1956 void Magick::Image::perceptible ( const double epsilon_ )
1959 ExceptionInfo exceptionInfo;
1960 GetExceptionInfo( &exceptionInfo );
1961 PerceptibleImage( image(), epsilon_, &exceptionInfo );
1962 throwException( exceptionInfo );
1963 (void) DestroyExceptionInfo( &exceptionInfo );
1966 void Magick::Image::perceptibleChannel ( const ChannelType channel_,
1967 const double epsilon_ )
1970 ExceptionInfo exceptionInfo;
1971 GetExceptionInfo( &exceptionInfo );
1972 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
1973 PerceptibleImage( image(), epsilon_, &exceptionInfo );
1974 SetPixelChannelMask( image(), channel_mask );
1975 throwException( exceptionInfo );
1976 (void) DestroyExceptionInfo( &exceptionInfo );
1979 // Ping is similar to read except only enough of the image is read to
1980 // determine the image columns, rows, and filesize. Access the
1981 // columns(), rows(), and fileSize() attributes after invoking ping.
1982 // The image data is not valid after calling ping.
1983 void Magick::Image::ping ( const std::string &imageSpec_ )
1985 options()->fileName( imageSpec_ );
1986 ExceptionInfo exceptionInfo;
1987 GetExceptionInfo( &exceptionInfo );
1988 MagickCore::Image* image =
1989 PingImage( imageInfo(), &exceptionInfo );
1990 replaceImage( image );
1991 throwException( exceptionInfo );
1992 (void) DestroyExceptionInfo( &exceptionInfo );
1995 // Ping is similar to read except only enough of the image is read
1996 // to determine the image columns, rows, and filesize. Access the
1997 // columns(), rows(), and fileSize() attributes after invoking
1998 // ping. The image data is not valid after calling ping.
1999 void Magick::Image::ping ( const Blob& blob_ )
2001 ExceptionInfo exceptionInfo;
2002 GetExceptionInfo( &exceptionInfo );
2003 MagickCore::Image* image =
2004 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
2005 replaceImage( image );
2006 throwException( exceptionInfo );
2007 (void) DestroyExceptionInfo( &exceptionInfo );
2010 void Magick::Image::polaroid ( const std::string &caption_,
2011 const double angle_,
2012 const PixelInterpolateMethod method_ )
2014 ExceptionInfo exceptionInfo;
2015 GetExceptionInfo( &exceptionInfo );
2016 MagickCore::Image* image =
2017 PolaroidImage( constImage(), options()->drawInfo(), caption_.c_str(),
2018 angle_, method_, &exceptionInfo );
2019 replaceImage( image );
2020 throwException( exceptionInfo );
2021 (void) DestroyExceptionInfo( &exceptionInfo );
2024 void Magick::Image::posterize ( const size_t levels_,
2025 const DitherMethod method_ )
2028 ExceptionInfo exceptionInfo;
2029 GetExceptionInfo( &exceptionInfo );
2030 PosterizeImage( image(), levels_, method_, &exceptionInfo );
2031 throwException( exceptionInfo );
2032 (void) DestroyExceptionInfo( &exceptionInfo );
2035 void Magick::Image::posterizeChannel ( const ChannelType channel_,
2036 const size_t levels_,
2037 const DitherMethod method_ )
2040 ExceptionInfo exceptionInfo;
2041 GetExceptionInfo( &exceptionInfo );
2042 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2043 PosterizeImage( image(), levels_, method_, &exceptionInfo );
2044 SetPixelChannelMask( image(), channel_mask );
2045 throwException( exceptionInfo );
2046 (void) DestroyExceptionInfo( &exceptionInfo );
2049 // Execute a named process module using an argc/argv syntax similar to
2050 // that accepted by a C 'main' routine. An exception is thrown if the
2051 // requested process module doesn't exist, fails to load, or fails during
2053 void Magick::Image::process( std::string name_,
2059 ExceptionInfo exceptionInfo;
2060 GetExceptionInfo( &exceptionInfo );
2062 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
2065 throwException( exceptionInfo );
2066 (void) DestroyExceptionInfo( &exceptionInfo );
2069 // Quantize colors in image using current quantization settings
2070 // Set measureError_ to true in order to measure quantization error
2071 void Magick::Image::quantize ( const bool measureError_ )
2076 options()->quantizeInfo()->measure_error=MagickTrue;
2078 options()->quantizeInfo()->measure_error=MagickFalse;
2080 ExceptionInfo exceptionInfo;
2081 GetExceptionInfo( &exceptionInfo );
2082 QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo );
2084 throwException( exceptionInfo );
2085 (void) DestroyExceptionInfo( &exceptionInfo );
2088 // Apply an arithmetic or bitwise operator to the image pixel quantums.
2089 void Magick::Image::quantumOperator ( const ChannelType channel_,
2090 const MagickEvaluateOperator operator_,
2093 ExceptionInfo exceptionInfo;
2094 GetExceptionInfo( &exceptionInfo );
2095 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2096 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
2097 SetPixelChannelMask( image(), channel_mask );
2098 throwException( exceptionInfo );
2099 (void) DestroyExceptionInfo( &exceptionInfo );
2102 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
2103 const size_t columns_,
2105 const ChannelType channel_,
2106 const MagickEvaluateOperator operator_,
2107 const double rvalue_)
2109 ExceptionInfo exceptionInfo;
2110 GetExceptionInfo( &exceptionInfo );
2111 RectangleInfo geometry;
2112 geometry.width = columns_;
2113 geometry.height = rows_;
2116 MagickCore::Image *crop_image = CropImage( image(), &geometry,
2118 ChannelType channel_mask = SetImageChannelMask( image(), channel_);
2119 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
2120 SetPixelChannelMask( image(), channel_mask );
2121 (void) CompositeImage( image(), crop_image, image()->alpha_trait == BlendPixelTrait ?
2122 OverCompositeOp : CopyCompositeOp, MagickFalse, geometry.x, geometry.y,
2124 crop_image = DestroyImageList(crop_image);
2125 throwException( exceptionInfo );
2126 (void) DestroyExceptionInfo( &exceptionInfo );
2129 // Raise image (lighten or darken the edges of an image to give a 3-D
2130 // raised or lowered effect)
2131 void Magick::Image::raise ( const Geometry &geometry_ ,
2132 const bool raisedFlag_ )
2134 ExceptionInfo exceptionInfo;
2135 GetExceptionInfo( &exceptionInfo );
2136 RectangleInfo raiseInfo = geometry_;
2138 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
2139 throwException( exceptionInfo );
2140 (void) DestroyExceptionInfo( &exceptionInfo );
2144 // Random threshold image.
2146 // Changes the value of individual pixels based on the intensity
2147 // of each pixel compared to a random threshold. The result is a
2148 // low-contrast, two color image. The thresholds_ argument is a
2149 // geometry containing LOWxHIGH thresholds. If the string
2150 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
2151 // 3, or 4 will be performed instead. If a channel_ argument is
2152 // specified then only the specified channel is altered. This is
2153 // a very fast alternative to 'quantize' based dithering.
2154 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
2156 randomThresholdChannel(thresholds_,DefaultChannels);
2158 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
2159 const ChannelType channel_ )
2161 ExceptionInfo exceptionInfo;
2162 GetExceptionInfo( &exceptionInfo );
2164 ChannelType channel_mask = SetImageChannelMask( image(), channel_);
2165 (void) RandomThresholdImage( image(),
2166 static_cast<std::string>(thresholds_).c_str(),
2168 SetPixelChannelMask( image(), channel_mask );
2169 throwImageException();
2170 (void) DestroyExceptionInfo( &exceptionInfo );
2173 // Read image into current object
2174 void Magick::Image::read ( const std::string &imageSpec_ )
2176 options()->fileName( imageSpec_ );
2178 ExceptionInfo exceptionInfo;
2179 GetExceptionInfo( &exceptionInfo );
2180 MagickCore::Image* image =
2181 ReadImage( imageInfo(), &exceptionInfo );
2183 // Ensure that multiple image frames were not read.
2184 if ( image && image->next )
2186 // Destroy any extra image frames
2187 MagickCore::Image* next = image->next;
2190 DestroyImageList( next );
2193 replaceImage( image );
2194 throwException( exceptionInfo );
2195 (void) DestroyExceptionInfo( &exceptionInfo );
2198 // Read image of specified size into current object
2199 void Magick::Image::read ( const Geometry &size_,
2200 const std::string &imageSpec_ )
2206 // Read image from in-memory BLOB
2207 void Magick::Image::read ( const Blob &blob_ )
2209 ExceptionInfo exceptionInfo;
2210 GetExceptionInfo( &exceptionInfo );
2211 MagickCore::Image* image =
2212 BlobToImage( imageInfo(),
2213 static_cast<const void *>(blob_.data()),
2214 blob_.length(), &exceptionInfo );
2215 replaceImage( image );
2216 throwException( exceptionInfo );
2217 (void) DestroyExceptionInfo( &exceptionInfo );
2220 // Read image of specified size from in-memory BLOB
2221 void Magick::Image::read ( const Blob &blob_,
2222 const Geometry &size_ )
2230 // Read image of specified size and depth from in-memory BLOB
2231 void Magick::Image::read ( const Blob &blob_,
2232 const Geometry &size_,
2233 const size_t depth_ )
2243 // Read image of specified size, depth, and format from in-memory BLOB
2244 void Magick::Image::read ( const Blob &blob_,
2245 const Geometry &size_,
2246 const size_t depth_,
2247 const std::string &magick_ )
2255 // Set explicit image format
2256 fileName( magick_ + ':');
2261 // Read image of specified size, and format from in-memory BLOB
2262 void Magick::Image::read ( const Blob &blob_,
2263 const Geometry &size_,
2264 const std::string &magick_ )
2270 // Set explicit image format
2271 fileName( magick_ + ':');
2276 // Read image based on raw pixels in memory (ConstituteImage)
2277 void Magick::Image::read ( const size_t width_,
2278 const size_t height_,
2279 const std::string &map_,
2280 const StorageType type_,
2281 const void *pixels_ )
2283 ExceptionInfo exceptionInfo;
2284 GetExceptionInfo( &exceptionInfo );
2285 MagickCore::Image* image =
2286 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
2288 replaceImage( image );
2289 throwException( exceptionInfo );
2290 (void) DestroyExceptionInfo( &exceptionInfo );
2293 // Reduce noise in image
2294 void Magick::Image::reduceNoise ( const double order_ )
2296 ExceptionInfo exceptionInfo;
2297 GetExceptionInfo( &exceptionInfo );
2298 MagickCore::Image* newImage =
2299 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
2301 replaceImage( newImage );
2302 throwException( exceptionInfo );
2303 (void) DestroyExceptionInfo( &exceptionInfo );
2307 void Magick::Image::resize( const Geometry &geometry_ )
2309 // Calculate new size. This code should be supported using binary arguments
2310 // in the ImageMagick library.
2313 size_t width = columns();
2314 size_t height = rows();
2316 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2320 ExceptionInfo exceptionInfo;
2321 GetExceptionInfo( &exceptionInfo );
2322 MagickCore::Image* newImage =
2323 ResizeImage( image(),
2328 replaceImage( newImage );
2329 throwException( exceptionInfo );
2330 (void) DestroyExceptionInfo( &exceptionInfo );
2334 void Magick::Image::roll ( const Geometry &roll_ )
2336 ssize_t xOff = roll_.xOff();
2337 if ( roll_.xNegative() )
2339 ssize_t yOff = roll_.yOff();
2340 if ( roll_.yNegative() )
2343 ExceptionInfo exceptionInfo;
2344 GetExceptionInfo( &exceptionInfo );
2345 MagickCore::Image* newImage =
2346 RollImage( image(), xOff, yOff, &exceptionInfo );
2347 replaceImage( newImage );
2348 throwException( exceptionInfo );
2349 (void) DestroyExceptionInfo( &exceptionInfo );
2351 void Magick::Image::roll ( const size_t columns_,
2352 const size_t rows_ )
2354 ExceptionInfo exceptionInfo;
2355 GetExceptionInfo( &exceptionInfo );
2356 MagickCore::Image* newImage =
2358 static_cast<ssize_t>(columns_),
2359 static_cast<ssize_t>(rows_), &exceptionInfo );
2360 replaceImage( newImage );
2361 throwException( exceptionInfo );
2362 (void) DestroyExceptionInfo( &exceptionInfo );
2366 void Magick::Image::rotate ( const double degrees_ )
2368 ExceptionInfo exceptionInfo;
2369 GetExceptionInfo( &exceptionInfo );
2370 MagickCore::Image* newImage =
2371 RotateImage( image(), degrees_, &exceptionInfo);
2372 replaceImage( newImage );
2373 throwException( exceptionInfo );
2374 (void) DestroyExceptionInfo( &exceptionInfo );
2378 void Magick::Image::sample ( const Geometry &geometry_ )
2382 size_t width = columns();
2383 size_t height = rows();
2385 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2389 ExceptionInfo exceptionInfo;
2390 GetExceptionInfo( &exceptionInfo );
2391 MagickCore::Image* newImage =
2392 SampleImage( image(), width, height, &exceptionInfo );
2393 replaceImage( newImage );
2394 throwException( exceptionInfo );
2395 (void) DestroyExceptionInfo( &exceptionInfo );
2399 void Magick::Image::scale ( const Geometry &geometry_ )
2403 size_t width = columns();
2404 size_t height = rows();
2406 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2410 ExceptionInfo exceptionInfo;
2411 GetExceptionInfo( &exceptionInfo );
2412 MagickCore::Image* newImage =
2413 ScaleImage( image(), width, height, &exceptionInfo );
2414 replaceImage( newImage );
2415 throwException( exceptionInfo );
2416 (void) DestroyExceptionInfo( &exceptionInfo );
2419 // Segment (coalesce similar image components) by analyzing the
2420 // histograms of the color components and identifying units that are
2421 // homogeneous with the fuzzy c-means technique.
2422 void Magick::Image::segment ( const double clusterThreshold_,
2423 const double smoothingThreshold_ )
2425 ExceptionInfo exceptionInfo;
2426 GetExceptionInfo( &exceptionInfo );
2428 SegmentImage ( image(),
2429 options()->quantizeColorSpace(),
2430 (MagickBooleanType) options()->verbose(),
2432 smoothingThreshold_, &exceptionInfo );
2433 SyncImage( image(), &exceptionInfo );
2434 throwException( exceptionInfo );
2435 (void) DestroyExceptionInfo( &exceptionInfo );
2438 // Shade image using distant light source
2439 void Magick::Image::shade ( const double azimuth_,
2440 const double elevation_,
2441 const bool colorShading_ )
2443 ExceptionInfo exceptionInfo;
2444 GetExceptionInfo( &exceptionInfo );
2445 MagickCore::Image* newImage =
2446 ShadeImage( image(),
2447 colorShading_ == true ? MagickTrue : MagickFalse,
2451 replaceImage( newImage );
2452 throwException( exceptionInfo );
2453 (void) DestroyExceptionInfo( &exceptionInfo );
2456 // Simulate an image shadow
2457 void Magick::Image::shadow( const double percent_opacity_, const double sigma_,
2458 const ssize_t x_, const ssize_t y_ )
2460 ExceptionInfo exceptionInfo;
2461 GetExceptionInfo( &exceptionInfo );
2462 MagickCore::Image* newImage = ShadowImage( image(), percent_opacity_, sigma_,
2463 x_, y_, &exceptionInfo );
2464 replaceImage( newImage );
2465 throwException( exceptionInfo );
2466 (void) DestroyExceptionInfo( &exceptionInfo );
2469 // Sharpen pixels in image
2470 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
2472 ExceptionInfo exceptionInfo;
2473 GetExceptionInfo( &exceptionInfo );
2474 MagickCore::Image* newImage =
2475 SharpenImage( image(),
2479 replaceImage( newImage );
2480 throwException( exceptionInfo );
2481 (void) DestroyExceptionInfo( &exceptionInfo );
2484 void Magick::Image::sharpenChannel ( const ChannelType channel_,
2485 const double radius_, const double sigma_ )
2487 ExceptionInfo exceptionInfo;
2488 GetExceptionInfo( &exceptionInfo );
2489 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2490 MagickCore::Image* newImage =
2491 SharpenImage( image(),
2495 SetPixelChannelMask( image(), channel_mask );
2496 replaceImage( newImage );
2497 throwException( exceptionInfo );
2498 (void) DestroyExceptionInfo( &exceptionInfo );
2501 // Shave pixels from image edges.
2502 void Magick::Image::shave ( const Geometry &geometry_ )
2504 RectangleInfo shaveInfo = geometry_;
2505 ExceptionInfo exceptionInfo;
2506 GetExceptionInfo( &exceptionInfo );
2507 MagickCore::Image* newImage =
2508 ShaveImage( image(),
2511 replaceImage( newImage );
2512 throwException( exceptionInfo );
2513 (void) DestroyExceptionInfo( &exceptionInfo );
2517 void Magick::Image::shear ( const double xShearAngle_,
2518 const double yShearAngle_ )
2520 ExceptionInfo exceptionInfo;
2521 GetExceptionInfo( &exceptionInfo );
2522 MagickCore::Image* newImage =
2523 ShearImage( image(),
2527 replaceImage( newImage );
2528 throwException( exceptionInfo );
2529 (void) DestroyExceptionInfo( &exceptionInfo );
2533 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
2535 ExceptionInfo exceptionInfo;
2536 GetExceptionInfo( &exceptionInfo );
2538 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
2539 throwException( exceptionInfo );
2540 (void) DestroyExceptionInfo( &exceptionInfo );
2543 // Solarize image (similar to effect seen when exposing a photographic
2544 // film to light during the development process)
2545 void Magick::Image::solarize ( const double factor_ )
2547 ExceptionInfo exceptionInfo;
2548 GetExceptionInfo( &exceptionInfo );
2550 SolarizeImage ( image(), factor_, &exceptionInfo );
2551 throwException( exceptionInfo );
2552 (void) DestroyExceptionInfo( &exceptionInfo );
2555 // Sparse color image, given a set of coordinates, interpolates the colors
2556 // found at those coordinates, across the whole image, using various methods.
2558 void Magick::Image::sparseColor ( const ChannelType channel,
2559 const SparseColorMethod method,
2560 const size_t number_arguments,
2561 const double *arguments )
2563 ExceptionInfo exceptionInfo;
2564 GetExceptionInfo( &exceptionInfo );
2566 ChannelType channel_mask = SetImageChannelMask( image(), channel );
2567 MagickCore::Image* newImage = SparseColorImage ( image(), method,
2568 number_arguments, arguments, &exceptionInfo );
2569 SetPixelChannelMask( image(), channel_mask );
2570 replaceImage( newImage );
2571 throwException( exceptionInfo );
2572 (void) DestroyExceptionInfo( &exceptionInfo );
2575 // Spread pixels randomly within image by specified ammount
2576 void Magick::Image::spread ( const size_t amount_ )
2578 ExceptionInfo exceptionInfo;
2579 GetExceptionInfo( &exceptionInfo );
2580 MagickCore::Image* newImage =
2581 SpreadImage( image(),
2583 image()->interpolate,
2585 replaceImage( newImage );
2586 throwException( exceptionInfo );
2587 (void) DestroyExceptionInfo( &exceptionInfo );
2590 // Add a digital watermark to the image (based on second image)
2591 void Magick::Image::stegano ( const Image &watermark_ )
2593 ExceptionInfo exceptionInfo;
2594 GetExceptionInfo( &exceptionInfo );
2595 MagickCore::Image* newImage =
2596 SteganoImage( image(),
2597 watermark_.constImage(),
2599 replaceImage( newImage );
2600 throwException( exceptionInfo );
2601 (void) DestroyExceptionInfo( &exceptionInfo );
2604 // Stereo image (left image is current image)
2605 void Magick::Image::stereo ( const Image &rightImage_ )
2607 ExceptionInfo exceptionInfo;
2608 GetExceptionInfo( &exceptionInfo );
2609 MagickCore::Image* newImage =
2610 StereoImage( image(),
2611 rightImage_.constImage(),
2613 replaceImage( newImage );
2614 throwException( exceptionInfo );
2615 (void) DestroyExceptionInfo( &exceptionInfo );
2619 void Magick::Image::swirl ( const double degrees_ )
2621 ExceptionInfo exceptionInfo;
2622 GetExceptionInfo( &exceptionInfo );
2623 MagickCore::Image* newImage =
2624 SwirlImage( image(), degrees_, image()->interpolate,
2626 replaceImage( newImage );
2627 throwException( exceptionInfo );
2628 (void) DestroyExceptionInfo( &exceptionInfo );
2632 void Magick::Image::texture ( const Image &texture_ )
2635 ExceptionInfo exceptionInfo;
2636 GetExceptionInfo( &exceptionInfo );
2637 TextureImage( image(), texture_.constImage(), &exceptionInfo );
2638 throwException( exceptionInfo );
2639 (void) DestroyExceptionInfo( &exceptionInfo );
2643 void Magick::Image::threshold ( const double threshold_ )
2646 ExceptionInfo exceptionInfo;
2647 GetExceptionInfo( &exceptionInfo );
2648 BilevelImage( image(), threshold_, &exceptionInfo );
2649 throwException( exceptionInfo );
2650 (void) DestroyExceptionInfo( &exceptionInfo );
2653 // Transform image based on image geometry only
2654 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2657 ExceptionInfo exceptionInfo;
2658 GetExceptionInfo( &exceptionInfo );
2659 TransformImage ( &(image()), 0,
2660 std::string(imageGeometry_).c_str(), &exceptionInfo );
2661 throwException( exceptionInfo );
2662 (void) DestroyExceptionInfo( &exceptionInfo );
2664 // Transform image based on image and crop geometries
2665 void Magick::Image::transform ( const Geometry &imageGeometry_,
2666 const Geometry &cropGeometry_ )
2669 ExceptionInfo exceptionInfo;
2670 GetExceptionInfo( &exceptionInfo );
2671 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2672 std::string(imageGeometry_).c_str(), &exceptionInfo );
2673 throwException( exceptionInfo );
2674 (void) DestroyExceptionInfo( &exceptionInfo );
2677 // Add matte image to image, setting pixels matching color to transparent
2678 void Magick::Image::transparent ( const Color &color_ )
2680 if ( !color_.isValid() )
2682 throwExceptionExplicit( OptionError,
2683 "Color argument is invalid" );
2686 std::string color = color_;
2689 ExceptionInfo exceptionInfo;
2690 GetExceptionInfo( &exceptionInfo );
2691 (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
2692 &target,&exceptionInfo);
2694 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2696 throwException( exceptionInfo );
2697 (void) DestroyExceptionInfo( &exceptionInfo );
2700 // Add matte image to image, setting pixels matching color to transparent
2701 void Magick::Image::transparentChroma(const Color &colorLow_,
2702 const Color &colorHigh_)
2704 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2706 throwExceptionExplicit( OptionError,
2707 "Color argument is invalid" );
2710 std::string colorLow = colorLow_;
2711 std::string colorHigh = colorHigh_;
2713 PixelInfo targetLow;
2714 PixelInfo targetHigh;
2715 ExceptionInfo exceptionInfo;
2716 GetExceptionInfo( &exceptionInfo );
2717 (void) QueryColorCompliance(std::string(colorLow_).c_str(),
2718 AllCompliance,&targetLow,&exceptionInfo);
2719 (void) QueryColorCompliance(std::string(colorHigh_).c_str(),
2720 AllCompliance,&targetHigh,&exceptionInfo);
2722 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2723 TransparentAlpha, MagickFalse, &exceptionInfo );
2724 throwException( exceptionInfo );
2725 (void) DestroyExceptionInfo( &exceptionInfo );
2729 // Trim edges that are the background color from the image
2730 void Magick::Image::trim ( void )
2732 ExceptionInfo exceptionInfo;
2733 GetExceptionInfo( &exceptionInfo );
2734 MagickCore::Image* newImage =
2735 TrimImage( image(), &exceptionInfo);
2736 replaceImage( newImage );
2737 throwException( exceptionInfo );
2738 (void) DestroyExceptionInfo( &exceptionInfo );
2741 // Replace image with a sharpened version of the original image
2742 // using the unsharp mask algorithm.
2744 // the radius of the Gaussian, in pixels, not counting the
2747 // the standard deviation of the Gaussian, in pixels.
2749 // the percentage of the difference between the original and
2750 // the blur image that is added back into the original.
2752 // the threshold in pixels needed to apply the diffence amount.
2753 void Magick::Image::unsharpmask ( const double radius_,
2754 const double sigma_,
2755 const double amount_,
2756 const double threshold_ )
2758 ExceptionInfo exceptionInfo;
2759 GetExceptionInfo( &exceptionInfo );
2760 MagickCore::Image* newImage =
2761 UnsharpMaskImage( image(),
2767 replaceImage( newImage );
2768 throwException( exceptionInfo );
2769 (void) DestroyExceptionInfo( &exceptionInfo );
2772 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2773 const double radius_,
2774 const double sigma_,
2775 const double amount_,
2776 const double threshold_ )
2778 ExceptionInfo exceptionInfo;
2779 GetExceptionInfo( &exceptionInfo );
2780 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2781 MagickCore::Image* newImage =
2782 UnsharpMaskImage( image(),
2788 SetPixelChannelMask( image(), channel_mask );
2789 replaceImage( newImage );
2790 throwException( exceptionInfo );
2791 (void) DestroyExceptionInfo( &exceptionInfo );
2794 // Map image pixels to a sine wave
2795 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2797 ExceptionInfo exceptionInfo;
2798 GetExceptionInfo( &exceptionInfo );
2799 MagickCore::Image* newImage =
2800 WaveImage( constImage(), amplitude_, wavelength_, image()->interpolate,
2802 replaceImage( newImage );
2803 throwException( exceptionInfo );
2804 (void) DestroyExceptionInfo( &exceptionInfo );
2807 void Magick::Image::whiteThreshold ( const std::string &threshold_ )
2810 ExceptionInfo exceptionInfo;
2811 GetExceptionInfo( &exceptionInfo );
2812 WhiteThresholdImage( image(), threshold_.c_str(), &exceptionInfo );
2813 throwException( exceptionInfo );
2814 (void) DestroyExceptionInfo( &exceptionInfo );
2817 void Magick::Image::whiteThresholdChannel ( const ChannelType channel_,
2818 const std::string &threshold_ )
2821 ExceptionInfo exceptionInfo;
2822 GetExceptionInfo( &exceptionInfo );
2823 ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
2824 WhiteThresholdImage( image(), threshold_.c_str(), &exceptionInfo );
2825 SetPixelChannelMask( image(), channel_mask );
2826 throwException( exceptionInfo );
2827 (void) DestroyExceptionInfo( &exceptionInfo );
2830 // Write image to file
2831 void Magick::Image::write ( const std::string &imageSpec_ )
2833 ExceptionInfo exceptionInfo;
2834 GetExceptionInfo( &exceptionInfo );
2836 fileName( imageSpec_ );
2837 WriteImage( constImageInfo(), image(), &exceptionInfo );
2838 throwException( exceptionInfo );
2839 (void) DestroyExceptionInfo( &exceptionInfo );
2842 // Write image to in-memory BLOB
2843 void Magick::Image::write ( Blob *blob_ )
2846 size_t length = 2048; // Efficient size for small images
2847 ExceptionInfo exceptionInfo;
2848 GetExceptionInfo( &exceptionInfo );
2849 void* data = ImagesToBlob( constImageInfo(), image(), &length,
2851 throwException( exceptionInfo );
2852 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2853 throwImageException();
2854 (void) DestroyExceptionInfo( &exceptionInfo );
2856 void Magick::Image::write ( Blob *blob_,
2857 const std::string &magick_ )
2861 size_t length = 2048; // Efficient size for small images
2862 ExceptionInfo exceptionInfo;
2863 GetExceptionInfo( &exceptionInfo );
2864 void* data = ImagesToBlob( constImageInfo(), image(), &length,
2866 throwException( exceptionInfo );
2867 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2868 throwImageException();
2869 (void) DestroyExceptionInfo( &exceptionInfo );
2871 void Magick::Image::write ( Blob *blob_,
2872 const std::string &magick_,
2873 const size_t depth_ )
2878 size_t length = 2048; // Efficient size for small images
2879 ExceptionInfo exceptionInfo;
2880 GetExceptionInfo( &exceptionInfo );
2881 void* data = ImagesToBlob( constImageInfo(), image(), &length,
2883 throwException( exceptionInfo );
2884 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2885 throwImageException();
2886 (void) DestroyExceptionInfo( &exceptionInfo );
2889 // Write image to an array of pixels with storage type specified
2890 // by user (ExportImagePixels), e.g.
2891 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2892 void Magick::Image::write ( const ssize_t x_,
2894 const size_t columns_,
2896 const std::string &map_,
2897 const StorageType type_,
2900 ExceptionInfo exceptionInfo;
2901 GetExceptionInfo( &exceptionInfo );
2902 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2905 throwException( exceptionInfo );
2906 (void) DestroyExceptionInfo( &exceptionInfo );
2910 void Magick::Image::zoom ( const Geometry &geometry_ )
2912 // Calculate new size. This code should be supported using binary arguments
2913 // in the ImageMagick library.
2916 size_t width = columns();
2917 size_t height = rows();
2919 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2923 ExceptionInfo exceptionInfo;
2924 GetExceptionInfo( &exceptionInfo );
2925 MagickCore::Image* newImage =
2926 ResizeImage( constImage(), width, height, image()->filter, &exceptionInfo );
2927 replaceImage( newImage );
2928 throwException( exceptionInfo );
2929 (void) DestroyExceptionInfo( &exceptionInfo );
2933 * Methods for setting image attributes
2937 // Join images into a single multi-image file
2938 void Magick::Image::adjoin ( const bool flag_ )
2941 options()->adjoin( flag_ );
2943 bool Magick::Image::adjoin ( void ) const
2945 return constOptions()->adjoin();
2948 // Remove pixel aliasing
2949 void Magick::Image::antiAlias( const bool flag_ )
2952 options()->antiAlias( static_cast<size_t>(flag_) );
2954 bool Magick::Image::antiAlias( void )
2956 return static_cast<bool>( options()->antiAlias( ) );
2959 // Animation inter-frame delay
2960 void Magick::Image::animationDelay ( const size_t delay_ )
2963 image()->delay = delay_;
2965 size_t Magick::Image::animationDelay ( void ) const
2967 return constImage()->delay;
2970 // Number of iterations to play animation
2971 void Magick::Image::animationIterations ( const size_t iterations_ )
2974 image()->iterations = iterations_;
2976 size_t Magick::Image::animationIterations ( void ) const
2978 return constImage()->iterations;
2981 // Access/Update a named image attribute
2982 void Magick::Image::attribute ( const std::string name_,
2983 const std::string value_ )
2986 ExceptionInfo exceptionInfo;
2987 GetExceptionInfo( &exceptionInfo );
2988 SetImageProperty( image(), name_.c_str(), value_.c_str(), &exceptionInfo );
2989 throwException( exceptionInfo );
2990 (void) DestroyExceptionInfo( &exceptionInfo );
2992 std::string Magick::Image::attribute ( const std::string name_ )
2994 ExceptionInfo exceptionInfo;
2995 GetExceptionInfo( &exceptionInfo );
2996 const char *value = GetImageProperty( constImage(), name_.c_str(),
2998 throwException( exceptionInfo );
2999 (void) DestroyExceptionInfo( &exceptionInfo );
3002 return std::string( value );
3004 return std::string(); // Intentionally no exception
3008 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
3012 if ( backgroundColor_.isValid() )
3014 image()->background_color = backgroundColor_;
3018 image()->background_color = Color();
3021 options()->backgroundColor( backgroundColor_ );
3023 Magick::Color Magick::Image::backgroundColor ( void ) const
3025 return constOptions()->backgroundColor( );
3028 // Background fill texture
3029 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
3032 options()->backgroundTexture( backgroundTexture_ );
3034 std::string Magick::Image::backgroundTexture ( void ) const
3036 return constOptions()->backgroundTexture( );
3039 // Original image columns
3040 size_t Magick::Image::baseColumns ( void ) const
3042 return constImage()->magick_columns;
3045 // Original image name
3046 std::string Magick::Image::baseFilename ( void ) const
3048 return std::string(constImage()->magick_filename);
3051 // Original image rows
3052 size_t Magick::Image::baseRows ( void ) const
3054 return constImage()->magick_rows;
3058 void Magick::Image::borderColor ( const Color &borderColor_ )
3062 if ( borderColor_.isValid() )
3064 image()->border_color = borderColor_;
3068 image()->border_color = Color();
3071 options()->borderColor( borderColor_ );
3073 Magick::Color Magick::Image::borderColor ( void ) const
3075 return constOptions()->borderColor( );
3078 // Return smallest bounding box enclosing non-border pixels. The
3079 // current fuzz value is used when discriminating between pixels.
3080 // This is the crop bounding box used by crop(Geometry(0,0));
3081 Magick::Geometry Magick::Image::boundingBox ( void ) const
3083 ExceptionInfo exceptionInfo;
3084 GetExceptionInfo( &exceptionInfo );
3085 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
3086 throwException( exceptionInfo );
3087 (void) DestroyExceptionInfo( &exceptionInfo );
3088 return Geometry( bbox );
3091 // Text bounding-box base color
3092 void Magick::Image::boxColor ( const Color &boxColor_ )
3095 options()->boxColor( boxColor_ );
3097 Magick::Color Magick::Image::boxColor ( void ) const
3099 return constOptions()->boxColor( );
3102 // Pixel cache threshold. Once this threshold is exceeded, all
3103 // subsequent pixels cache operations are to/from disk.
3104 // This setting is shared by all Image objects.
3106 void Magick::Image::cacheThreshold ( const size_t threshold_ )
3108 SetMagickResourceLimit( MemoryResource, threshold_ );
3111 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
3114 image()->chromaticity.blue_primary.x = x_;
3115 image()->chromaticity.blue_primary.y = y_;
3117 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
3119 *x_ = constImage()->chromaticity.blue_primary.x;
3120 *y_ = constImage()->chromaticity.blue_primary.y;
3123 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
3126 image()->chromaticity.green_primary.x = x_;
3127 image()->chromaticity.green_primary.y = y_;
3129 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
3131 *x_ = constImage()->chromaticity.green_primary.x;
3132 *y_ = constImage()->chromaticity.green_primary.y;
3135 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
3138 image()->chromaticity.red_primary.x = x_;
3139 image()->chromaticity.red_primary.y = y_;
3141 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
3143 *x_ = constImage()->chromaticity.red_primary.x;
3144 *y_ = constImage()->chromaticity.red_primary.y;
3147 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
3150 image()->chromaticity.white_point.x = x_;
3151 image()->chromaticity.white_point.y = y_;
3153 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
3155 *x_ = constImage()->chromaticity.white_point.x;
3156 *y_ = constImage()->chromaticity.white_point.y;
3159 // Set image storage class
3160 void Magick::Image::classType ( const ClassType class_ )
3162 if ( classType() == PseudoClass && class_ == DirectClass )
3164 // Use SyncImage to synchronize the DirectClass pixels with the
3165 // color map and then set to DirectClass type.
3167 ExceptionInfo exceptionInfo;
3168 GetExceptionInfo( &exceptionInfo );
3169 SyncImage( image(), &exceptionInfo );
3170 throwException( exceptionInfo );
3171 (void) DestroyExceptionInfo( &exceptionInfo );
3172 image()->colormap = (PixelInfo *)
3173 RelinquishMagickMemory( image()->colormap );
3174 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
3178 if ( classType() == DirectClass && class_ == PseudoClass )
3180 // Quantize to create PseudoClass color map
3182 quantizeColors(MaxColormapSize);
3184 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
3188 // Associate a clip mask with the image. The clip mask must be the
3189 // same dimensions as the image. Pass an invalid image to unset an
3190 // existing clip mask.
3191 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
3195 ExceptionInfo exceptionInfo;
3196 GetExceptionInfo( &exceptionInfo );
3197 if( clipMask_.isValid() )
3200 SetImageMask( image(), clipMask_.constImage(), &exceptionInfo );
3204 // Unset existing clip mask
3205 SetImageMask( image(), 0, &exceptionInfo );
3207 throwException( exceptionInfo );
3208 (void) DestroyExceptionInfo( &exceptionInfo );
3210 Magick::Image Magick::Image::clipMask ( void ) const
3212 ExceptionInfo exceptionInfo;
3213 GetExceptionInfo( &exceptionInfo );
3214 MagickCore::Image* image = GetImageMask( constImage(), &exceptionInfo );
3215 throwException( exceptionInfo );
3216 (void) DestroyExceptionInfo( &exceptionInfo );
3217 if (image == (MagickCore::Image *) NULL)
3218 return Magick::Image();
3220 return Magick::Image( image );
3223 void Magick::Image::colorFuzz ( const double fuzz_ )
3226 image()->fuzz = fuzz_;
3227 options()->colorFuzz( fuzz_ );
3229 double Magick::Image::colorFuzz ( void ) const
3231 return constOptions()->colorFuzz( );
3234 // Set color in colormap at index
3235 void Magick::Image::colorMap ( const size_t index_,
3236 const Color &color_ )
3238 MagickCore::Image* imageptr = image();
3240 if (index_ > (MaxColormapSize-1) )
3241 throwExceptionExplicit( OptionError,
3242 "Colormap index must be less than MaxColormapSize" );
3244 if ( !color_.isValid() )
3245 throwExceptionExplicit( OptionError,
3246 "Color argument is invalid");
3249 // Ensure that colormap size is large enough
3250 if ( colorMapSize() < (index_+1) )
3251 colorMapSize( index_ + 1 );
3253 // Set color at index in colormap
3254 (imageptr->colormap)[index_] = color_;
3256 // Return color in colormap at index
3257 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
3259 const MagickCore::Image* imageptr = constImage();
3261 if ( !imageptr->colormap )
3262 throwExceptionExplicit( OptionError,
3263 "Image does not contain a colormap");
3265 if ( index_ > imageptr->colors-1 )
3266 throwExceptionExplicit( OptionError,
3267 "Index out of range");
3269 return Magick::Color( (imageptr->colormap)[index_] );
3272 // Colormap size (number of colormap entries)
3273 void Magick::Image::colorMapSize ( const size_t entries_ )
3275 if (entries_ >MaxColormapSize )
3276 throwExceptionExplicit( OptionError,
3277 "Colormap entries must not exceed MaxColormapSize" );
3281 MagickCore::Image* imageptr = image();
3283 if( !imageptr->colormap )
3285 // Allocate colormap
3286 imageptr->colormap =
3287 static_cast<PixelInfo*>(AcquireMagickMemory(entries_*sizeof(PixelInfo)));
3288 imageptr->colors = 0;
3290 else if ( entries_ > imageptr->colors )
3292 // Re-allocate colormap
3293 imageptr->colormap=(PixelInfo *)
3294 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelInfo));
3297 // Initialize any new colormap entries as all black
3299 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
3300 (imageptr->colormap)[i] = black;
3302 imageptr->colors = entries_;
3304 size_t Magick::Image::colorMapSize ( void )
3306 const MagickCore::Image* imageptr = constImage();
3308 if ( !imageptr->colormap )
3309 throwExceptionExplicit( OptionError,
3310 "Image does not contain a colormap");
3312 return imageptr->colors;
3316 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
3318 if ( image()->colorspace == colorSpace_ )
3322 ExceptionInfo exceptionInfo;
3323 GetExceptionInfo( &exceptionInfo );
3324 TransformImageColorspace(image(), colorSpace_, &exceptionInfo);
3325 throwException( exceptionInfo );
3326 (void) DestroyExceptionInfo( &exceptionInfo );
3328 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
3330 return constImage()->colorspace;
3333 // Set image colorspace type.
3334 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
3337 ExceptionInfo exceptionInfo;
3338 GetExceptionInfo( &exceptionInfo );
3339 SetImageColorspace(image(), colorSpace_, &exceptionInfo);
3340 throwException( exceptionInfo );
3341 (void) DestroyExceptionInfo( &exceptionInfo );
3342 options()->colorspaceType( colorSpace_ );
3344 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
3346 return constOptions()->colorspaceType();
3351 void Magick::Image::comment ( const std::string &comment_ )
3354 ExceptionInfo exceptionInfo;
3355 GetExceptionInfo( &exceptionInfo );
3356 SetImageProperty( image(), "Comment", NULL, &exceptionInfo );
3357 if ( comment_.length() > 0 )
3358 SetImageProperty( image(), "Comment", comment_.c_str(), &exceptionInfo );
3359 throwException( exceptionInfo );
3360 (void) DestroyExceptionInfo( &exceptionInfo );
3362 std::string Magick::Image::comment ( void ) const
3364 ExceptionInfo exceptionInfo;
3365 GetExceptionInfo( &exceptionInfo );
3366 const char *value = GetImageProperty( constImage(), "Comment",
3368 throwException( exceptionInfo );
3369 (void) DestroyExceptionInfo( &exceptionInfo );
3372 return std::string( value );
3374 return std::string(); // Intentionally no exception
3377 // Composition operator to be used when composition is implicitly used
3378 // (such as for image flattening).
3379 void Magick::Image::compose (const CompositeOperator compose_)
3381 image()->compose=compose_;
3384 Magick::CompositeOperator Magick::Image::compose ( void ) const
3386 return constImage()->compose;
3389 // Compression algorithm
3390 void Magick::Image::compressType ( const CompressionType compressType_ )
3393 image()->compression = compressType_;
3394 options()->compressType( compressType_ );
3396 Magick::CompressionType Magick::Image::compressType ( void ) const
3398 return constImage()->compression;
3401 // Enable printing of debug messages from ImageMagick
3402 void Magick::Image::debug ( const bool flag_ )
3405 options()->debug( flag_ );
3407 bool Magick::Image::debug ( void ) const
3409 return constOptions()->debug();
3412 // Tagged image format define (set/access coder-specific option) The
3413 // magick_ option specifies the coder the define applies to. The key_
3414 // option provides the key specific to that coder. The value_ option
3415 // provides the value to set (if any). See the defineSet() method if the
3416 // key must be removed entirely.
3417 void Magick::Image::defineValue ( const std::string &magick_,
3418 const std::string &key_,
3419 const std::string &value_ )
3422 std::string format = magick_ + ":" + key_;
3423 std::string option = value_;
3424 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
3426 std::string Magick::Image::defineValue ( const std::string &magick_,
3427 const std::string &key_ ) const
3429 std::string definition = magick_ + ":" + key_;
3430 const char *option =
3431 GetImageOption ( constImageInfo(), definition.c_str() );
3433 return std::string( option );
3434 return std::string( );
3437 // Tagged image format define. Similar to the defineValue() method
3438 // except that passing the flag_ value 'true' creates a value-less
3439 // define with that format and key. Passing the flag_ value 'false'
3440 // removes any existing matching definition. The method returns 'true'
3441 // if a matching key exists, and 'false' if no matching key exists.
3442 void Magick::Image::defineSet ( const std::string &magick_,
3443 const std::string &key_,
3447 std::string definition = magick_ + ":" + key_;
3450 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
3454 DeleteImageOption( imageInfo(), definition.c_str() );
3457 bool Magick::Image::defineSet ( const std::string &magick_,
3458 const std::string &key_ ) const
3460 std::string key = magick_ + ":" + key_;
3461 const char *option =
3462 GetImageOption ( constImageInfo(), key.c_str() );
3469 void Magick::Image::density ( const Geometry &density_ )
3472 options()->density( density_ );
3473 if ( density_.isValid() )
3475 image()->resolution.x = density_.width();
3476 if ( density_.height() != 0 )
3478 image()->resolution.y = density_.height();
3482 image()->resolution.y = density_.width();
3488 image()->resolution.x = 0;
3489 image()->resolution.y = 0;
3492 Magick::Geometry Magick::Image::density ( void ) const
3496 ssize_t x_resolution=72;
3497 ssize_t y_resolution=72;
3499 if (constImage()->resolution.x > 0.0)
3500 x_resolution=static_cast<ssize_t>(constImage()->resolution.x + 0.5);
3502 if (constImage()->resolution.y > 0.0)
3503 y_resolution=static_cast<ssize_t>(constImage()->resolution.y + 0.5);
3505 return Geometry(x_resolution,y_resolution);
3508 return constOptions()->density( );
3511 // Image depth (bits allocated to red/green/blue components)
3512 void Magick::Image::depth ( const size_t depth_ )
3514 size_t depth = depth_;
3516 if (depth > MAGICKCORE_QUANTUM_DEPTH)
3517 depth=MAGICKCORE_QUANTUM_DEPTH;
3520 image()->depth=depth;
3521 options()->depth( depth );
3523 size_t Magick::Image::depth ( void ) const
3525 return constImage()->depth;
3528 std::string Magick::Image::directory ( void ) const
3530 if ( constImage()->directory )
3531 return std::string( constImage()->directory );
3533 throwExceptionExplicit( CorruptImageWarning,
3534 "Image does not contain a directory");
3536 return std::string();
3539 // Endianness (little like Intel or big like SPARC) for image
3540 // formats which support endian-specific options.
3541 void Magick::Image::endian ( const Magick::EndianType endian_ )
3544 options()->endian( endian_ );
3545 image()->endian = endian_;
3547 Magick::EndianType Magick::Image::endian ( void ) const
3549 return constImage()->endian;
3552 // EXIF profile (BLOB)
3553 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
3556 if ( exifProfile_.data() != 0 )
3558 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
3559 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
3560 ExceptionInfo exceptionInfo;
3561 GetExceptionInfo( &exceptionInfo );
3562 (void) SetImageProfile( image(), "exif", exif_profile, &exceptionInfo);
3563 exif_profile =DestroyStringInfo( exif_profile );
3564 throwException( exceptionInfo );
3565 (void) DestroyExceptionInfo( &exceptionInfo );
3568 Magick::Blob Magick::Image::exifProfile( void ) const
3570 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
3571 if ( exif_profile == (StringInfo *) NULL)
3572 return Blob( 0, 0 );
3573 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
3577 void Magick::Image::fileName ( const std::string &fileName_ )
3581 fileName_.copy( image()->filename,
3582 sizeof(image()->filename) - 1 );
3583 image()->filename[ fileName_.length() ] = 0; // Null terminate
3585 options()->fileName( fileName_ );
3588 std::string Magick::Image::fileName ( void ) const
3590 return constOptions()->fileName( );
3594 off_t Magick::Image::fileSize ( void ) const
3596 return (off_t) GetBlobSize( constImage() );
3599 // Color to use when drawing inside an object
3600 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3603 options()->fillColor(fillColor_);
3605 Magick::Color Magick::Image::fillColor ( void ) const
3607 return constOptions()->fillColor();
3610 // Rule to use when filling drawn objects
3611 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3614 options()->fillRule(fillRule_);
3616 Magick::FillRule Magick::Image::fillRule ( void ) const
3618 return constOptions()->fillRule();
3621 // Pattern to use while filling drawn objects.
3622 void Magick::Image::fillPattern ( const Image &fillPattern_ )
3625 if(fillPattern_.isValid())
3626 options()->fillPattern( fillPattern_.constImage() );
3628 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3630 Magick::Image Magick::Image::fillPattern ( void ) const
3632 // FIXME: This is inordinately innefficient
3635 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3639 ExceptionInfo exceptionInfo;
3640 GetExceptionInfo( &exceptionInfo );
3641 MagickCore::Image* image =
3642 CloneImage( tmpTexture,
3645 MagickTrue, // orphan
3647 texture.replaceImage( image );
3648 throwException( exceptionInfo );
3649 (void) DestroyExceptionInfo( &exceptionInfo );
3654 // Filter used by zoom
3655 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3658 image()->filter = filterType_;
3660 Magick::FilterTypes Magick::Image::filterType ( void ) const
3662 return constImage()->filter;
3666 void Magick::Image::font ( const std::string &font_ )
3669 options()->font( font_ );
3671 std::string Magick::Image::font ( void ) const
3673 return constOptions()->font( );
3677 void Magick::Image::fontPointsize ( const double pointSize_ )
3680 options()->fontPointsize( pointSize_ );
3682 double Magick::Image::fontPointsize ( void ) const
3684 return constOptions()->fontPointsize( );
3687 // Font type metrics
3688 void Magick::Image::fontTypeMetrics( const std::string &text_,
3689 TypeMetric *metrics )
3691 DrawInfo *drawInfo = options()->drawInfo();
3692 drawInfo->text = const_cast<char *>(text_.c_str());
3693 ExceptionInfo exceptionInfo;
3694 GetExceptionInfo( &exceptionInfo );
3695 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric), &exceptionInfo );
3697 throwException( exceptionInfo );
3698 (void) DestroyExceptionInfo( &exceptionInfo );
3701 // Image format string
3702 std::string Magick::Image::format ( void ) const
3704 ExceptionInfo exceptionInfo;
3705 GetExceptionInfo( &exceptionInfo );
3706 const MagickInfo * magick_info
3707 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3708 throwException( exceptionInfo );
3709 (void) DestroyExceptionInfo( &exceptionInfo );
3711 if (( magick_info != 0 ) &&
3712 ( *magick_info->description != '\0' ))
3713 return std::string(magick_info->description);
3715 throwExceptionExplicit( CorruptImageWarning,
3716 "Unrecognized image magick type" );
3717 return std::string();
3721 double Magick::Image::gamma ( void ) const
3723 return constImage()->gamma;
3726 Magick::Geometry Magick::Image::geometry ( void ) const
3728 if ( constImage()->geometry )
3730 return Geometry(constImage()->geometry);
3733 throwExceptionExplicit( OptionWarning,
3734 "Image does not contain a geometry");
3739 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3742 image()->dispose = (DisposeType) disposeMethod_;
3744 size_t Magick::Image::gifDisposeMethod ( void ) const
3746 // FIXME: It would be better to return an enumeration
3747 return constImage()->dispose;
3750 // ICC ICM color profile (BLOB)
3751 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3753 profile("icm",colorProfile_);
3755 Magick::Blob Magick::Image::iccColorProfile( void ) const
3757 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3758 if ( color_profile == (StringInfo *) NULL)
3759 return Blob( 0, 0 );
3760 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3763 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3766 image()->interlace = interlace_;
3767 options()->interlaceType ( interlace_ );
3769 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3771 return constImage()->interlace;
3774 // IPTC profile (BLOB)
3775 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3778 if ( iptcProfile_.data() != 0 )
3780 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3781 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3782 ExceptionInfo exceptionInfo;
3783 GetExceptionInfo( &exceptionInfo );
3784 (void) SetImageProfile( image(), "iptc", iptc_profile, &exceptionInfo);
3785 iptc_profile =DestroyStringInfo( iptc_profile );
3786 throwException( exceptionInfo );
3787 (void) DestroyExceptionInfo( &exceptionInfo );
3790 Magick::Blob Magick::Image::iptcProfile( void ) const
3792 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3793 if ( iptc_profile == (StringInfo *) NULL)
3794 return Blob( 0, 0 );
3795 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3798 // Does object contain valid image?
3799 void Magick::Image::isValid ( const bool isValid_ )
3804 _imgRef = new ImageRef;
3806 else if ( !isValid() )
3808 // Construct with single-pixel black image to make
3809 // image valid. This is an obvious hack.
3810 size( Geometry(1,1) );
3811 read( "xc:#000000" );
3815 bool Magick::Image::isValid ( void ) const
3817 if ( rows() && columns() )
3824 void Magick::Image::label ( const std::string &label_ )
3827 ExceptionInfo exceptionInfo;
3828 GetExceptionInfo( &exceptionInfo );
3829 SetImageProperty ( image(), "Label", NULL, &exceptionInfo );
3830 if ( label_.length() > 0 )
3831 SetImageProperty ( image(), "Label", label_.c_str(), &exceptionInfo );
3832 throwException( exceptionInfo );
3833 (void) DestroyExceptionInfo( &exceptionInfo );
3835 std::string Magick::Image::label ( void ) const
3837 ExceptionInfo exceptionInfo;
3838 GetExceptionInfo( &exceptionInfo );
3839 const char *value = GetImageProperty( constImage(), "Label", &exceptionInfo );
3840 throwException( exceptionInfo );
3841 (void) DestroyExceptionInfo( &exceptionInfo );
3844 return std::string( value );
3846 return std::string();
3849 void Magick::Image::magick ( const std::string &magick_ )
3853 magick_.copy( image()->magick,
3854 sizeof(image()->magick) - 1 );
3855 image()->magick[ magick_.length() ] = 0;
3857 options()->magick( magick_ );
3859 std::string Magick::Image::magick ( void ) const
3861 if ( *(constImage()->magick) != '\0' )
3862 return std::string(constImage()->magick);
3864 return constOptions()->magick( );
3867 void Magick::Image::matte ( const bool matteFlag_ )
3871 // If matte channel is requested, but image doesn't already have a
3872 // matte channel, then create an opaque matte channel. Likewise, if
3873 // the image already has a matte channel but a matte channel is not
3874 // desired, then set the matte channel to opaque.
3875 ExceptionInfo exceptionInfo;
3876 GetExceptionInfo( &exceptionInfo );
3877 if ((matteFlag_ && !constImage()->alpha_trait) ||
3878 (constImage()->alpha_trait && !matteFlag_))
3879 SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo);
3880 throwException( exceptionInfo );
3881 (void) DestroyExceptionInfo( &exceptionInfo );
3883 image()->alpha_trait = matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait;
3885 bool Magick::Image::matte ( void ) const
3887 if ( constImage()->alpha_trait == BlendPixelTrait )
3893 void Magick::Image::matteColor ( const Color &matteColor_ )
3897 if ( matteColor_.isValid() )
3899 image()->matte_color = matteColor_;
3900 options()->matteColor( matteColor_ );
3904 // Set to default matte color
3905 Color tmpColor( "#BDBDBD" );
3906 image()->matte_color = tmpColor;
3907 options()->matteColor( tmpColor );
3910 Magick::Color Magick::Image::matteColor ( void ) const
3912 return Color( ClampToQuantum( constImage()->matte_color.red ),
3913 ClampToQuantum( constImage()->matte_color.green ),
3914 ClampToQuantum( constImage()->matte_color.blue ) );
3917 double Magick::Image::meanErrorPerPixel ( void ) const
3919 return(constImage()->error.mean_error_per_pixel);
3922 // Image modulus depth (minimum number of bits required to support
3923 // red/green/blue components without loss of accuracy)
3924 void Magick::Image::modulusDepth ( const size_t depth_ )
3927 ExceptionInfo exceptionInfo;
3928 GetExceptionInfo( &exceptionInfo );
3929 SetImageDepth( image(), depth_, &exceptionInfo );
3930 throwException( exceptionInfo );
3931 (void) DestroyExceptionInfo( &exceptionInfo );
3932 options()->depth( depth_ );
3934 size_t Magick::Image::modulusDepth ( void ) const
3936 ExceptionInfo exceptionInfo;
3937 GetExceptionInfo( &exceptionInfo );
3938 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3939 throwException( exceptionInfo );
3940 (void) DestroyExceptionInfo( &exceptionInfo );
3944 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3947 options()->monochrome( monochromeFlag_ );
3949 bool Magick::Image::monochrome ( void ) const
3951 return constOptions()->monochrome( );
3954 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3956 if ( constImage()->montage )
3957 return Magick::Geometry(constImage()->montage);
3959 throwExceptionExplicit( CorruptImageWarning,
3960 "Image does not contain a montage" );
3962 return Magick::Geometry();
3965 double Magick::Image::normalizedMaxError ( void ) const
3967 return(constImage()->error.normalized_maximum_error);
3970 double Magick::Image::normalizedMeanError ( void ) const
3972 return constImage()->error.normalized_mean_error;
3975 // Image orientation
3976 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3979 image()->orientation = orientation_;
3981 Magick::OrientationType Magick::Image::orientation ( void ) const
3983 return constImage()->orientation;
3986 void Magick::Image::penColor ( const Color &penColor_ )
3989 options()->fillColor(penColor_);
3990 options()->strokeColor(penColor_);
3992 Magick::Color Magick::Image::penColor ( void ) const
3994 return constOptions()->fillColor();
3997 void Magick::Image::penTexture ( const Image &penTexture_ )
4000 if(penTexture_.isValid())
4001 options()->fillPattern( penTexture_.constImage() );
4003 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
4006 Magick::Image Magick::Image::penTexture ( void ) const
4008 // FIXME: This is inordinately innefficient
4011 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
4015 ExceptionInfo exceptionInfo;
4016 GetExceptionInfo( &exceptionInfo );
4017 MagickCore::Image* image =
4018 CloneImage( tmpTexture,
4021 MagickTrue, // orphan
4023 texture.replaceImage( image );
4024 throwException( exceptionInfo );
4025 (void) DestroyExceptionInfo( &exceptionInfo );
4030 // Set the color of a pixel.
4031 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
4032 const Color &color_ )
4034 // Test arguments to ensure they are within the image.
4035 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
4036 throwExceptionExplicit( OptionError,
4037 "Access outside of image boundary" );
4041 // Set image to DirectClass
4042 classType( DirectClass );
4045 Pixels pixels(*this);
4047 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
4048 PixelInfo packet = color_;
4049 MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel);
4050 // Tell ImageMagick that pixels have been updated
4056 // Get the color of a pixel
4057 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
4058 const ssize_t y_ ) const
4060 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
4064 MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
4065 return Color( packet );
4068 return Color(); // invalid
4071 // Preferred size and location of an image canvas.
4072 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
4075 options()->page( pageSize_ );
4076 image()->page = pageSize_;
4078 Magick::Geometry Magick::Image::page ( void ) const
4080 return Geometry( constImage()->page.width,
4081 constImage()->page.height,
4082 AbsoluteValue(constImage()->page.x),
4083 AbsoluteValue(constImage()->page.y),
4084 constImage()->page.x < 0 ? true : false,
4085 constImage()->page.y < 0 ? true : false);
4088 // Add a named profile to an image or remove a named profile by
4089 // passing an empty Blob (use default Blob constructor).
4091 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
4092 void Magick::Image::profile( const std::string name_,
4093 const Magick::Blob &profile_ )
4096 ExceptionInfo exceptionInfo;
4097 GetExceptionInfo( &exceptionInfo );
4098 ssize_t result = ProfileImage( image(), name_.c_str(),
4099 (unsigned char *)profile_.data(),
4100 profile_.length(), &exceptionInfo);
4102 throwException( exceptionInfo );
4103 (void) DestroyExceptionInfo( &exceptionInfo );
4107 // Retrieve a named profile from the image.
4109 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
4110 // an existing generic profile name.
4111 Magick::Blob Magick::Image::profile( const std::string name_ ) const
4113 const StringInfo * profile = GetImageProfile( constImage(), name_.c_str() );
4115 if ( profile == (StringInfo *) NULL)
4116 return Blob( 0, 0 );
4117 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
4120 void Magick::Image::quality ( const size_t quality_ )
4123 image()->quality = quality_;
4124 options()->quality( quality_ );
4126 size_t Magick::Image::quality ( void ) const
4128 return constImage()->quality;
4131 void Magick::Image::quantizeColors ( const size_t colors_ )
4134 options()->quantizeColors( colors_ );
4136 size_t Magick::Image::quantizeColors ( void ) const
4138 return constOptions()->quantizeColors( );
4141 void Magick::Image::quantizeColorSpace
4142 ( const Magick::ColorspaceType colorSpace_ )
4145 options()->quantizeColorSpace( colorSpace_ );
4147 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
4149 return constOptions()->quantizeColorSpace( );
4152 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
4155 options()->quantizeDither( ditherFlag_ );
4157 bool Magick::Image::quantizeDither ( void ) const
4159 return constOptions()->quantizeDither( );
4162 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
4165 options()->quantizeTreeDepth( treeDepth_ );
4167 size_t Magick::Image::quantizeTreeDepth ( void ) const
4169 return constOptions()->quantizeTreeDepth( );
4172 void Magick::Image::renderingIntent
4173 ( const Magick::RenderingIntent renderingIntent_ )
4176 image()->rendering_intent = renderingIntent_;
4178 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
4180 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
4183 void Magick::Image::resolutionUnits
4184 ( const Magick::ResolutionType resolutionUnits_ )
4187 image()->units = resolutionUnits_;
4188 options()->resolutionUnits( resolutionUnits_ );
4190 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
4192 return constOptions()->resolutionUnits( );
4195 void Magick::Image::scene ( const size_t scene_ )
4198 image()->scene = scene_;
4200 size_t Magick::Image::scene ( void ) const
4202 return constImage()->scene;
4205 std::string Magick::Image::signature ( const bool force_ ) const
4207 Lock( &_imgRef->_mutexLock );
4209 // Re-calculate image signature if necessary
4210 ExceptionInfo exceptionInfo;
4211 GetExceptionInfo( &exceptionInfo );
4213 !GetImageProperty(constImage(), "Signature", &exceptionInfo) ||
4214 constImage()->taint )
4216 SignatureImage( const_cast<MagickCore::Image *>(constImage()), &exceptionInfo );
4219 const char *property = GetImageProperty(constImage(), "Signature",
4221 throwException( exceptionInfo );
4222 (void) DestroyExceptionInfo( &exceptionInfo );
4224 return std::string( property );
4227 void Magick::Image::size ( const Geometry &geometry_ )
4230 options()->size( geometry_ );
4231 image()->rows = geometry_.height();
4232 image()->columns = geometry_.width();
4234 Magick::Geometry Magick::Image::size ( void ) const
4236 return Magick::Geometry( constImage()->columns, constImage()->rows );
4240 void Magick::Image::splice( const Geometry &geometry_ )
4242 RectangleInfo spliceInfo = geometry_;
4243 ExceptionInfo exceptionInfo;
4244 GetExceptionInfo( &exceptionInfo );
4245 MagickCore::Image* newImage =
4246 SpliceImage( image(), &spliceInfo, &exceptionInfo);
4247 replaceImage( newImage );
4248 throwException( exceptionInfo );
4249 (void) DestroyExceptionInfo( &exceptionInfo );
4252 // Obtain image statistics. Statistics are normalized to the range of
4253 // 0.0 to 1.0 and are output to the specified ImageStatistics
4255 void Magick::Image::statistics ( ImageStatistics *statistics )
4261 ExceptionInfo exceptionInfo;
4262 GetExceptionInfo( &exceptionInfo );
4264 ChannelType channel_mask = SetImageChannelMask( image(), RedChannel);
4265 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
4266 statistics->red.minimum=minimum;
4267 statistics->red.maximum=maximum;
4268 (void) GetImageMean( image(),&statistics->red.mean,
4269 &statistics->red.standard_deviation,&exceptionInfo);
4270 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
4271 &statistics->red.skewness,&exceptionInfo);
4272 SetPixelChannelMask( image(), channel_mask );
4274 channel_mask = SetImageChannelMask( image(), GreenChannel);
4275 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
4276 statistics->green.minimum=minimum;
4277 statistics->green.maximum=maximum;
4278 (void) GetImageMean( image(),&statistics->green.mean,
4279 &statistics->green.standard_deviation,&exceptionInfo);
4280 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
4281 &statistics->green.skewness,&exceptionInfo);
4282 SetPixelChannelMask( image(), channel_mask );
4284 channel_mask = SetImageChannelMask( image(), GreenChannel);
4285 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
4286 statistics->blue.minimum=minimum;
4287 statistics->blue.maximum=maximum;
4288 (void) GetImageMean( image(),&statistics->blue.mean,
4289 &statistics->blue.standard_deviation,&exceptionInfo);
4290 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
4291 &statistics->blue.skewness,&exceptionInfo);
4292 SetPixelChannelMask( image(), channel_mask );
4294 channel_mask = SetImageChannelMask( image(), AlphaChannel);
4295 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
4296 statistics->alpha.minimum=minimum;
4297 statistics->alpha.maximum=maximum;
4298 (void) GetImageMean( image(),&statistics->alpha.mean,
4299 &statistics->alpha.standard_deviation,&exceptionInfo);
4300 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
4301 &statistics->alpha.skewness,&exceptionInfo);
4302 SetPixelChannelMask( image(), channel_mask );
4304 throwException( exceptionInfo );
4305 (void) DestroyExceptionInfo( &exceptionInfo );
4308 // Strip strips an image of all profiles and comments.
4309 void Magick::Image::strip ( void )
4312 ExceptionInfo exceptionInfo;
4313 GetExceptionInfo( &exceptionInfo );
4314 StripImage( image(), &exceptionInfo );
4315 throwException( exceptionInfo );
4316 (void) DestroyExceptionInfo( &exceptionInfo );
4319 // enabled/disable stroke anti-aliasing
4320 void Magick::Image::strokeAntiAlias ( const bool flag_ )
4323 options()->strokeAntiAlias(flag_);
4325 bool Magick::Image::strokeAntiAlias ( void ) const
4327 return constOptions()->strokeAntiAlias();
4330 // Color to use when drawing object outlines
4331 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
4334 options()->strokeColor(strokeColor_);
4336 Magick::Color Magick::Image::strokeColor ( void ) const
4338 return constOptions()->strokeColor();
4341 // dash pattern for drawing vector objects (default one)
4342 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
4345 options()->strokeDashArray( strokeDashArray_ );
4348 const double* Magick::Image::strokeDashArray ( void ) const
4350 return constOptions()->strokeDashArray( );
4353 // dash offset for drawing vector objects (default one)
4354 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
4357 options()->strokeDashOffset( strokeDashOffset_ );
4360 double Magick::Image::strokeDashOffset ( void ) const
4362 return constOptions()->strokeDashOffset( );
4365 // Specify the shape to be used at the end of open subpaths when they
4366 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
4368 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
4371 options()->strokeLineCap( lineCap_ );
4373 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
4375 return constOptions()->strokeLineCap( );
4378 // Specify the shape to be used at the corners of paths (or other
4379 // vector shapes) when they are stroked. Values of LineJoin are
4380 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
4381 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
4384 options()->strokeLineJoin( lineJoin_ );
4386 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
4388 return constOptions()->strokeLineJoin( );
4391 // Specify miter limit. When two line segments meet at a sharp angle
4392 // and miter joins have been specified for 'lineJoin', it is possible
4393 // for the miter to extend far beyond the thickness of the line
4394 // stroking the path. The miterLimit' imposes a limit on the ratio of
4395 // the miter length to the 'lineWidth'. The default value of this
4397 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
4400 options()->strokeMiterLimit( strokeMiterLimit_ );
4402 size_t Magick::Image::strokeMiterLimit ( void ) const
4404 return constOptions()->strokeMiterLimit( );
4407 // Pattern to use while stroking drawn objects.
4408 void Magick::Image::strokePattern ( const Image &strokePattern_ )
4411 if(strokePattern_.isValid())
4412 options()->strokePattern( strokePattern_.constImage() );
4414 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
4416 Magick::Image Magick::Image::strokePattern ( void ) const
4418 // FIXME: This is inordinately innefficient
4421 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
4425 ExceptionInfo exceptionInfo;
4426 GetExceptionInfo( &exceptionInfo );
4427 MagickCore::Image* image =
4428 CloneImage( tmpTexture,
4431 MagickTrue, // orphan
4433 throwException( exceptionInfo );
4434 (void) DestroyExceptionInfo( &exceptionInfo );
4435 texture.replaceImage( image );
4440 // Stroke width for drawing lines, circles, ellipses, etc.
4441 void Magick::Image::strokeWidth ( const double strokeWidth_ )
4444 options()->strokeWidth( strokeWidth_ );
4446 double Magick::Image::strokeWidth ( void ) const
4448 return constOptions()->strokeWidth( );
4451 void Magick::Image::subImage ( const size_t subImage_ )
4454 options()->subImage( subImage_ );
4456 size_t Magick::Image::subImage ( void ) const
4458 return constOptions()->subImage( );
4461 void Magick::Image::subRange ( const size_t subRange_ )
4464 options()->subRange( subRange_ );
4466 size_t Magick::Image::subRange ( void ) const
4468 return constOptions()->subRange( );
4471 // Annotation text encoding (e.g. "UTF-16")
4472 void Magick::Image::textEncoding ( const std::string &encoding_ )
4475 options()->textEncoding( encoding_ );
4477 std::string Magick::Image::textEncoding ( void ) const
4479 return constOptions()->textEncoding( );
4482 size_t Magick::Image::totalColors ( void )
4484 ExceptionInfo exceptionInfo;
4485 GetExceptionInfo( &exceptionInfo );
4486 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
4487 throwException( exceptionInfo );
4488 (void) DestroyExceptionInfo( &exceptionInfo );
4492 // Origin of coordinate system to use when annotating with text or drawing
4493 void Magick::Image::transformOrigin ( const double x_, const double y_ )
4496 options()->transformOrigin( x_, y_ );
4499 // Rotation to use when annotating with text or drawing
4500 void Magick::Image::transformRotation ( const double angle_ )
4503 options()->transformRotation( angle_ );
4506 // Reset transformation parameters to default
4507 void Magick::Image::transformReset ( void )
4510 options()->transformReset();
4513 // Scale to use when annotating with text or drawing
4514 void Magick::Image::transformScale ( const double sx_, const double sy_ )
4517 options()->transformScale( sx_, sy_ );
4520 // Skew to use in X axis when annotating with text or drawing
4521 void Magick::Image::transformSkewX ( const double skewx_ )
4524 options()->transformSkewX( skewx_ );
4527 // Skew to use in Y axis when annotating with text or drawing
4528 void Magick::Image::transformSkewY ( const double skewy_ )
4531 options()->transformSkewY( skewy_ );
4534 // Image representation type
4535 Magick::ImageType Magick::Image::type ( void ) const
4538 ExceptionInfo exceptionInfo;
4539 GetExceptionInfo( &exceptionInfo );
4540 ImageType image_type = constOptions()->type();
4541 if ( image_type == UndefinedType )
4542 image_type= GetImageType( constImage(), &exceptionInfo);
4543 throwException( exceptionInfo );
4544 (void) DestroyExceptionInfo( &exceptionInfo );
4547 void Magick::Image::type ( const Magick::ImageType type_)
4549 ExceptionInfo exceptionInfo;
4550 GetExceptionInfo( &exceptionInfo );
4552 options()->type( type_ );
4553 SetImageType( image(), type_, &exceptionInfo );
4554 throwException( exceptionInfo );
4555 (void) DestroyExceptionInfo( &exceptionInfo );
4558 void Magick::Image::verbose ( const bool verboseFlag_ )
4561 options()->verbose( verboseFlag_ );
4563 bool Magick::Image::verbose ( void ) const
4565 return constOptions()->verbose( );
4568 void Magick::Image::view ( const std::string &view_ )
4571 options()->view( view_ );
4573 std::string Magick::Image::view ( void ) const
4575 return constOptions()->view( );
4578 // Virtual pixel method
4579 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
4582 ExceptionInfo exceptionInfo;
4583 GetExceptionInfo( &exceptionInfo );
4584 SetImageVirtualPixelMethod( image(), virtual_pixel_method_, &exceptionInfo );
4585 throwException( exceptionInfo );
4586 (void) DestroyExceptionInfo( &exceptionInfo );
4588 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
4590 return GetImageVirtualPixelMethod( constImage() );
4593 void Magick::Image::x11Display ( const std::string &display_ )
4596 options()->x11Display( display_ );
4598 std::string Magick::Image::x11Display ( void ) const
4600 return constOptions()->x11Display( );
4603 double Magick::Image::xResolution ( void ) const
4605 return constImage()->resolution.x;
4607 double Magick::Image::yResolution ( void ) const
4609 return constImage()->resolution.y;
4613 Magick::Image::Image( const Image & image_ )
4614 : _imgRef(image_._imgRef)
4616 Lock( &_imgRef->_mutexLock );
4618 // Increase reference count
4619 ++_imgRef->_refCount;
4622 // Assignment operator
4623 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
4625 if( this != &image_ )
4628 Lock( &image_._imgRef->_mutexLock );
4629 ++image_._imgRef->_refCount;
4632 bool doDelete = false;
4634 Lock( &_imgRef->_mutexLock );
4635 if ( --_imgRef->_refCount == 0 )
4641 // Delete old image reference with associated image and options.
4645 // Use new image reference
4646 _imgRef = image_._imgRef;
4652 //////////////////////////////////////////////////////////////////////
4654 // Low-level Pixel Access Routines
4656 // Also see the Pixels class, which provides support for multiple
4657 // cache views. The low-level pixel access routines in the Image
4658 // class are provided in order to support backward compatability.
4660 //////////////////////////////////////////////////////////////////////
4662 // Transfers read-only pixels from the image to the pixel cache as
4663 // defined by the specified region
4664 const Magick::Quantum* Magick::Image::getConstPixels
4665 ( const ssize_t x_, const ssize_t y_,
4666 const size_t columns_,
4667 const size_t rows_ ) const
4669 ExceptionInfo exceptionInfo;
4670 GetExceptionInfo( &exceptionInfo );
4671 const Quantum* p = (*GetVirtualPixels)( constImage(),
4675 throwException( exceptionInfo );
4676 (void) DestroyExceptionInfo( &exceptionInfo );
4680 // Obtain read-only pixel associated pixels channels
4681 const void* Magick::Image::getConstMetacontent ( void ) const
4683 const void* result = GetVirtualMetacontent( constImage() );
4686 throwImageException();
4691 // Obtain image pixel associated pixels channels
4692 void* Magick::Image::getMetacontent ( void )
4694 void* result = GetAuthenticMetacontent( image() );
4697 throwImageException();
4702 // Transfers pixels from the image to the pixel cache as defined
4703 // by the specified region. Modified pixels may be subsequently
4704 // transferred back to the image via syncPixels.
4705 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4706 const size_t columns_,
4707 const size_t rows_ )
4710 ExceptionInfo exceptionInfo;
4711 GetExceptionInfo( &exceptionInfo );
4712 Quantum* result = (*GetAuthenticPixels)( image(),
4714 columns_, rows_, &exceptionInfo );
4715 throwException( exceptionInfo );
4716 (void) DestroyExceptionInfo( &exceptionInfo );
4721 // Allocates a pixel cache region to store image pixels as defined
4722 // by the region rectangle. This area is subsequently transferred
4723 // from the pixel cache to the image via syncPixels.
4724 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4725 const size_t columns_,
4726 const size_t rows_ )
4729 ExceptionInfo exceptionInfo;
4730 GetExceptionInfo( &exceptionInfo );
4731 Quantum* result = (*QueueAuthenticPixels)( image(),
4733 columns_, rows_, &exceptionInfo );
4734 throwException( exceptionInfo );
4735 (void) DestroyExceptionInfo( &exceptionInfo );
4740 // Transfers the image cache pixels to the image.
4741 void Magick::Image::syncPixels ( void )
4743 ExceptionInfo exceptionInfo;
4744 GetExceptionInfo( &exceptionInfo );
4745 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4746 throwException( exceptionInfo );
4747 (void) DestroyExceptionInfo( &exceptionInfo );
4750 // Transfers one or more pixel components from a buffer or file
4751 // into the image pixel cache of an image.
4752 // Used to support image decoders.
4753 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4754 const unsigned char *source_ )
4759 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4760 ExceptionInfo exceptionInfo;
4761 GetExceptionInfo( &exceptionInfo );
4762 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4763 quantum_,source_, &exceptionInfo);
4764 throwException( exceptionInfo );
4765 (void) DestroyExceptionInfo( &exceptionInfo );
4766 quantum_info=DestroyQuantumInfo(quantum_info);
4769 // Transfers one or more pixel components from the image pixel
4770 // cache to a buffer or file.
4771 // Used to support image encoders.
4772 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4773 unsigned char *destination_ )
4778 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4779 ExceptionInfo exceptionInfo;
4780 GetExceptionInfo( &exceptionInfo );
4781 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4782 quantum_,destination_, &exceptionInfo);
4783 quantum_info=DestroyQuantumInfo(quantum_info);
4784 throwException( exceptionInfo );
4785 (void) DestroyExceptionInfo( &exceptionInfo );
4788 /////////////////////////////////////////////////////////////////////
4790 // No end-user methods beyond this point
4792 /////////////////////////////////////////////////////////////////////
4796 // Construct using existing image and default options
4798 Magick::Image::Image ( MagickCore::Image* image_ )
4799 : _imgRef(new ImageRef( image_))
4803 // Get Magick::Options*
4804 Magick::Options* Magick::Image::options( void )
4806 return _imgRef->options();
4808 const Magick::Options* Magick::Image::constOptions( void ) const
4810 return _imgRef->options();
4813 // Get MagickCore::Image*
4814 MagickCore::Image*& Magick::Image::image( void )
4816 return _imgRef->image();
4818 const MagickCore::Image* Magick::Image::constImage( void ) const
4820 return _imgRef->image();
4824 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4826 return _imgRef->options()->imageInfo();
4828 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4830 return _imgRef->options()->imageInfo();
4833 // Get QuantizeInfo *
4834 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4836 return _imgRef->options()->quantizeInfo();
4838 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4840 return _imgRef->options()->quantizeInfo();
4844 // Replace current image
4846 MagickCore::Image * Magick::Image::replaceImage
4847 ( MagickCore::Image* replacement_ )
4849 MagickCore::Image* image;
4852 image = replacement_;
4855 ExceptionInfo exceptionInfo;
4856 GetExceptionInfo( &exceptionInfo );
4857 image = AcquireImage(constImageInfo(), &exceptionInfo);
4858 throwException( exceptionInfo );
4859 (void) DestroyExceptionInfo( &exceptionInfo );
4863 Lock( &_imgRef->_mutexLock );
4865 if ( _imgRef->_refCount == 1 )
4867 // We own the image, just replace it, and de-register
4869 _imgRef->image(image);
4873 // We don't own the image, dereference and replace with copy
4874 --_imgRef->_refCount;
4875 _imgRef = new ImageRef( image, constOptions() );
4879 return _imgRef->_image;
4883 // Prepare to modify image or image options
4884 // Replace current image and options with copy if reference count > 1
4886 void Magick::Image::modifyImage( void )
4889 Lock( &_imgRef->_mutexLock );
4890 if ( _imgRef->_refCount == 1 )
4892 // De-register image and return
4898 ExceptionInfo exceptionInfo;
4899 GetExceptionInfo( &exceptionInfo );
4900 replaceImage( CloneImage( image(),
4903 MagickTrue, // orphan
4905 throwException( exceptionInfo );
4906 (void) DestroyExceptionInfo( &exceptionInfo );
4911 // Test for an ImageMagick reported error and throw exception if one
4912 // has been reported. Secretly resets image->exception back to default
4913 // state even though this method is const.
4915 void Magick::Image::throwImageException( void ) const
4917 // Throw C++ exception while resetting Image exception to default state
4920 // Register image with image registry or obtain registration id
4921 ssize_t Magick::Image::registerId( void )
4923 Lock( &_imgRef->_mutexLock );
4924 if( _imgRef->id() < 0 )
4926 char id[MaxTextExtent];
4927 ExceptionInfo exceptionInfo;
4928 GetExceptionInfo( &exceptionInfo );
4929 _imgRef->id(_imgRef->id()+1);
4930 sprintf(id,"%.20g\n",(double) _imgRef->id());
4931 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4932 throwException( exceptionInfo );
4933 (void) DestroyExceptionInfo( &exceptionInfo );
4935 return _imgRef->id();
4938 // Unregister image from image registry
4939 void Magick::Image::unregisterId( void )
4946 // Create a local wrapper around MagickCoreTerminus
4951 void MagickPlusPlusDestroyMagick(void);
4955 void Magick::MagickPlusPlusDestroyMagick(void)
4957 if (magick_initialized)
4959 magick_initialized=false;
4960 MagickCore::MagickCoreTerminus();
4964 // C library initialization routine
4965 void MagickPPExport Magick::InitializeMagick(const char *path_)
4967 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4968 if (!magick_initialized)
4969 magick_initialized=true;
4973 // Cleanup class to ensure that ImageMagick singletons are destroyed
4974 // so as to avoid any resemblence to a memory leak (which seems to
4983 MagickCleanUp( void );
4984 ~MagickCleanUp( void );
4987 // The destructor for this object is invoked when the destructors for
4988 // static objects in this translation unit are invoked.
4989 static MagickCleanUp magickCleanUpGuard;
4992 Magick::MagickCleanUp::MagickCleanUp ( void )
4994 // Don't even think about invoking InitializeMagick here!
4997 Magick::MagickCleanUp::~MagickCleanUp ( void )
4999 MagickPlusPlusDestroyMagick();