1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Implementation of Image
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
16 #if !defined(MAGICKCORE_WINDOWS_SUPPORT)
19 #include "Magick++/Include.h"
23 #include "Magick++/Image.h"
24 #include "Magick++/Functions.h"
25 #include "Magick++/Pixels.h"
26 #include "Magick++/Options.h"
27 #include "Magick++/ImageRef.h"
29 #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
30 #define DegreesToRadians(x) (MagickPI*(x)/180.0)
32 MagickDLLDeclExtern const char *Magick::borderGeometryDefault = "6x6+0+0";
33 MagickDLLDeclExtern const char *Magick::frameGeometryDefault = "25x25+6+6";
34 MagickDLLDeclExtern const char *Magick::raiseGeometryDefault = "6x6+0+0";
36 static bool magick_initialized=false;
39 // Explicit template instantiations
43 // Friend functions to compare Image objects
46 MagickDLLDecl int Magick::operator == ( const Magick::Image& left_,
47 const Magick::Image& right_ )
49 // If image pixels and signature are the same, then the image is identical
50 return ( ( left_.rows() == right_.rows() ) &&
51 ( left_.columns() == right_.columns() ) &&
52 ( left_.signature() == right_.signature() )
55 MagickDLLDecl int Magick::operator != ( const Magick::Image& left_,
56 const Magick::Image& right_ )
58 return ( ! (left_ == right_) );
60 MagickDLLDecl int Magick::operator > ( const Magick::Image& left_,
61 const Magick::Image& right_ )
63 return ( !( left_ < right_ ) && ( left_ != right_ ) );
65 MagickDLLDecl int Magick::operator < ( const Magick::Image& left_,
66 const Magick::Image& right_ )
68 // If image pixels are less, then image is smaller
69 return ( ( left_.rows() * left_.columns() ) <
70 ( right_.rows() * right_.columns() )
73 MagickDLLDecl int Magick::operator >= ( const Magick::Image& left_,
74 const Magick::Image& right_ )
76 return ( ( left_ > right_ ) || ( left_ == right_ ) );
78 MagickDLLDecl int Magick::operator <= ( const Magick::Image& left_,
79 const Magick::Image& right_ )
81 return ( ( left_ < right_ ) || ( left_ == right_ ) );
85 // Image object implementation
88 // Construct from image file or image specification
89 Magick::Image::Image( const std::string &imageSpec_ )
90 : _imgRef(new ImageRef)
94 // Initialize, Allocate and Read images
97 catch ( const Warning & /*warning_*/ )
99 // FIXME: need a way to report warnings in constructor
101 catch ( const Error & /*error_*/ )
109 // Construct a blank image canvas of specified size and color
110 Magick::Image::Image( const Geometry &size_,
111 const Color &color_ )
112 : _imgRef(new ImageRef)
114 // xc: prefix specifies an X11 color string
115 std::string imageSpec("xc:");
123 // Initialize, Allocate and Read images
126 catch ( const Warning & /*warning_*/ )
128 // FIXME: need a way to report warnings in constructor
130 catch ( const Error & /*error_*/ )
138 // Construct Image from in-memory BLOB
139 Magick::Image::Image ( const Blob &blob_ )
140 : _imgRef(new ImageRef)
144 // Initialize, Allocate and Read images
147 catch ( const Warning & /*warning_*/ )
149 // FIXME: need a way to report warnings in constructor
151 catch ( const Error & /*error_*/ )
159 // Construct Image of specified size from in-memory BLOB
160 Magick::Image::Image ( const Blob &blob_,
161 const Geometry &size_ )
162 : _imgRef(new ImageRef)
167 read( blob_, size_ );
169 catch ( const Warning & /*warning_*/ )
171 // FIXME: need a way to report warnings in constructor
173 catch ( const Error & /*error_*/ )
181 // Construct Image of specified size and depth from in-memory BLOB
182 Magick::Image::Image ( const Blob &blob_,
183 const Geometry &size_,
184 const size_t depth_ )
185 : _imgRef(new ImageRef)
190 read( blob_, size_, depth_ );
192 catch ( const Warning & /*warning_*/ )
194 // FIXME: need a way to report warnings in constructor
196 catch ( const Error & /*error_*/ )
204 // Construct Image of specified size, depth, and format from in-memory BLOB
205 Magick::Image::Image ( const Blob &blob_,
206 const Geometry &size_,
208 const std::string &magick_ )
209 : _imgRef(new ImageRef)
214 read( blob_, size_, depth_, magick_ );
216 catch ( const Warning & /*warning_*/ )
218 // FIXME: need a way to report warnings in constructor
220 catch ( const Error & /*error_*/ )
228 // Construct Image of specified size, and format from in-memory BLOB
229 Magick::Image::Image ( const Blob &blob_,
230 const Geometry &size_,
231 const std::string &magick_ )
232 : _imgRef(new ImageRef)
237 read( blob_, size_, magick_ );
239 catch ( const Warning & /*warning_*/ )
241 // FIXME: need a way to report warnings in constructor
243 catch ( const Error & /*error_*/ )
251 // Construct an image based on an array of raw pixels, of specified
252 // type and mapping, in memory
253 Magick::Image::Image ( const size_t width_,
254 const size_t height_,
255 const std::string &map_,
256 const StorageType type_,
257 const void *pixels_ )
258 : _imgRef(new ImageRef)
262 read( width_, height_, map_.c_str(), type_, pixels_ );
264 catch ( const Warning & /*warning_*/ )
266 // FIXME: need a way to report warnings in constructor
268 catch ( const Error & /*error_*/ )
276 // Default constructor
277 Magick::Image::Image( void )
278 : _imgRef(new ImageRef)
284 Magick::Image::~Image()
286 bool doDelete = false;
288 Lock( &_imgRef->_mutexLock );
289 if ( --_imgRef->_refCount == 0 )
300 // Adaptive-blur image
301 void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
303 ExceptionInfo exceptionInfo;
304 GetExceptionInfo( &exceptionInfo );
305 MagickCore::Image* newImage =
306 AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
307 replaceImage( newImage );
308 throwException( exceptionInfo );
309 (void) DestroyExceptionInfo( &exceptionInfo );
312 // Local adaptive threshold image
313 // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
314 // Width x height define the size of the pixel neighborhood
315 // offset = constant to subtract from pixel neighborhood mean
316 void Magick::Image::adaptiveThreshold ( const size_t width_,
317 const size_t height_,
318 const ssize_t offset_ )
320 ExceptionInfo exceptionInfo;
321 GetExceptionInfo( &exceptionInfo );
322 MagickCore::Image* newImage =
323 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
324 replaceImage( newImage );
325 throwException( exceptionInfo );
326 (void) DestroyExceptionInfo( &exceptionInfo );
329 // Add noise to image
330 void Magick::Image::addNoise( const NoiseType noiseType_ )
332 ExceptionInfo exceptionInfo;
333 GetExceptionInfo( &exceptionInfo );
334 MagickCore::Image* newImage =
335 AddNoiseImage ( image(),
338 replaceImage( newImage );
339 throwException( exceptionInfo );
340 (void) DestroyExceptionInfo( &exceptionInfo );
343 void Magick::Image::addNoiseChannel( const ChannelType channel_,
344 const NoiseType noiseType_ )
346 ExceptionInfo exceptionInfo;
347 GetExceptionInfo( &exceptionInfo );
348 MagickCore::Image* newImage =
349 AddNoiseImageChannel ( image(),
353 replaceImage( newImage );
354 throwException( exceptionInfo );
355 (void) DestroyExceptionInfo( &exceptionInfo );
358 // Affine Transform image
359 void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
361 ExceptionInfo exceptionInfo;
362 GetExceptionInfo( &exceptionInfo );
364 AffineMatrix _affine;
365 _affine.sx = affine_.sx();
366 _affine.sy = affine_.sy();
367 _affine.rx = affine_.rx();
368 _affine.ry = affine_.ry();
369 _affine.tx = affine_.tx();
370 _affine.ty = affine_.ty();
372 MagickCore::Image* newImage =
373 AffineTransformImage( image(), &_affine, &exceptionInfo);
374 replaceImage( newImage );
375 throwException( exceptionInfo );
376 (void) DestroyExceptionInfo( &exceptionInfo );
379 // Annotate using specified text, and placement location
380 void Magick::Image::annotate ( const std::string &text_,
381 const Geometry &location_ )
383 annotate ( text_, location_, NorthWestGravity, 0.0 );
385 // Annotate using specified text, bounding area, and placement gravity
386 void Magick::Image::annotate ( const std::string &text_,
387 const Geometry &boundingArea_,
388 const GravityType gravity_ )
390 annotate ( text_, boundingArea_, gravity_, 0.0 );
392 // Annotate with text using specified text, bounding area, placement
393 // gravity, and rotation.
394 void Magick::Image::annotate ( const std::string &text_,
395 const Geometry &boundingArea_,
396 const GravityType gravity_,
397 const double degrees_ )
402 = options()->drawInfo();
404 drawInfo->text = const_cast<char *>(text_.c_str());
406 char boundingArea[MaxTextExtent];
408 drawInfo->geometry = 0;
409 if ( boundingArea_.isValid() ){
410 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
412 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
413 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
417 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
420 drawInfo->geometry = boundingArea;
423 drawInfo->gravity = gravity_;
425 AffineMatrix oaffine = drawInfo->affine;
426 if ( degrees_ != 0.0)
436 AffineMatrix current = drawInfo->affine;
437 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
438 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
439 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
440 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
442 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
443 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
444 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
445 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
446 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
450 AnnotateImage( image(), drawInfo );
452 // Restore original values
453 drawInfo->affine = oaffine;
455 drawInfo->geometry = 0;
457 throwImageException();
459 // Annotate with text (bounding area is entire image) and placement gravity.
460 void Magick::Image::annotate ( const std::string &text_,
461 const GravityType gravity_ )
466 = options()->drawInfo();
468 drawInfo->text = const_cast<char *>(text_.c_str());
470 drawInfo->gravity = gravity_;
472 AnnotateImage( image(), drawInfo );
474 drawInfo->gravity = NorthWestGravity;
477 throwImageException();
481 void Magick::Image::blur( const double radius_, const double sigma_ )
483 ExceptionInfo exceptionInfo;
484 GetExceptionInfo( &exceptionInfo );
485 MagickCore::Image* newImage =
486 BlurImage( image(), radius_, sigma_, &exceptionInfo);
487 replaceImage( newImage );
488 throwException( exceptionInfo );
489 (void) DestroyExceptionInfo( &exceptionInfo );
492 void Magick::Image::blurChannel( const ChannelType channel_,
493 const double radius_, const double sigma_ )
495 ExceptionInfo exceptionInfo;
496 GetExceptionInfo( &exceptionInfo );
497 MagickCore::Image* newImage =
498 BlurImageChannel( image(), channel_,radius_, sigma_, &exceptionInfo);
499 replaceImage( newImage );
500 throwException( exceptionInfo );
501 (void) DestroyExceptionInfo( &exceptionInfo );
504 // Add border to image
505 // Only uses width & height
506 void Magick::Image::border( const Geometry &geometry_ )
508 RectangleInfo borderInfo = geometry_;
509 ExceptionInfo exceptionInfo;
510 GetExceptionInfo( &exceptionInfo );
511 MagickCore::Image* newImage =
512 BorderImage( image(), &borderInfo, &exceptionInfo);
513 replaceImage( newImage );
514 throwException( exceptionInfo );
515 (void) DestroyExceptionInfo( &exceptionInfo );
518 // Extract channel from image
519 void Magick::Image::channel ( const ChannelType channel_ )
522 SeparateImageChannel ( image(), channel_ );
523 throwImageException();
526 // Set or obtain modulus channel depth
527 void Magick::Image::channelDepth ( const size_t depth_ )
530 SetImageDepth( image(), depth_);
531 throwImageException();
533 size_t Magick::Image::channelDepth ( )
535 size_t channel_depth;
537 ExceptionInfo exceptionInfo;
538 GetExceptionInfo( &exceptionInfo );
539 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
540 throwException( exceptionInfo );
541 (void) DestroyExceptionInfo( &exceptionInfo );
542 return channel_depth;
546 // Charcoal-effect image
547 void Magick::Image::charcoal( const double radius_, const double sigma_ )
549 ExceptionInfo exceptionInfo;
550 GetExceptionInfo( &exceptionInfo );
551 MagickCore::Image* newImage =
552 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
553 replaceImage( newImage );
554 throwException( exceptionInfo );
555 (void) DestroyExceptionInfo( &exceptionInfo );
559 void Magick::Image::chop( const Geometry &geometry_ )
561 RectangleInfo chopInfo = geometry_;
562 ExceptionInfo exceptionInfo;
563 GetExceptionInfo( &exceptionInfo );
564 MagickCore::Image* newImage =
565 ChopImage( image(), &chopInfo, &exceptionInfo);
566 replaceImage( newImage );
567 throwException( exceptionInfo );
568 (void) DestroyExceptionInfo( &exceptionInfo );
571 // contains one or more color corrections and applies the correction to the
573 void Magick::Image::cdl ( const std::string &cdl_ )
576 (void) ColorDecisionListImage( image(), cdl_.c_str() );
577 throwImageException();
581 void Magick::Image::colorize ( const unsigned int alphaRed_,
582 const unsigned int alphaGreen_,
583 const unsigned int alphaBlue_,
584 const Color &penColor_ )
586 if ( !penColor_.isValid() )
588 throwExceptionExplicit( OptionError,
589 "Pen color argument is invalid");
592 char alpha[MaxTextExtent];
593 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
595 ExceptionInfo exceptionInfo;
596 GetExceptionInfo( &exceptionInfo );
597 MagickCore::Image* newImage =
598 ColorizeImage ( image(), alpha,
599 penColor_, &exceptionInfo );
600 replaceImage( newImage );
601 throwException( exceptionInfo );
602 (void) DestroyExceptionInfo( &exceptionInfo );
604 void Magick::Image::colorize ( const unsigned int alpha_,
605 const Color &penColor_ )
607 colorize( alpha_, alpha_, alpha_, penColor_ );
610 // Apply a color matrix to the image channels. The user supplied
611 // matrix may be of order 1 to 6 (1x1 through 6x6).
612 void Magick::Image::colorMatrix (const size_t order_,
613 const double *color_matrix_)
618 ExceptionInfo exceptionInfo;
619 GetExceptionInfo( &exceptionInfo );
620 kernel_info=AcquireKernelInfo("1");
621 kernel_info->width=order_;
622 kernel_info->height=order_;
623 kernel_info->values=(double *) color_matrix_;
624 MagickCore::Image* newImage =
625 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
626 kernel_info->values=(double *) NULL;
627 kernel_info=DestroyKernelInfo(kernel_info);
628 replaceImage( newImage );
629 throwException( exceptionInfo );
630 (void) DestroyExceptionInfo( &exceptionInfo );
633 // Compare current image with another image
634 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
635 // in the current image. False is returned if the images are identical.
636 bool Magick::Image::compare ( const Image &reference_ )
639 Image ref = reference_;
641 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
644 // Composite two images
645 void Magick::Image::composite ( const Image &compositeImage_,
646 const ssize_t xOffset_,
647 const ssize_t yOffset_,
648 const CompositeOperator compose_ )
650 // Image supplied as compositeImage is composited with current image and
651 // results in updating current image.
654 CompositeImage( image(),
656 compositeImage_.constImage(),
659 throwImageException();
661 void Magick::Image::composite ( const Image &compositeImage_,
662 const Geometry &offset_,
663 const CompositeOperator compose_ )
667 ssize_t x = offset_.xOff();
668 ssize_t y = offset_.yOff();
669 size_t width = columns();
670 size_t height = rows();
672 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
676 CompositeImage( image(),
678 compositeImage_.constImage(),
680 throwImageException();
682 void Magick::Image::composite ( const Image &compositeImage_,
683 const GravityType gravity_,
684 const CompositeOperator compose_ )
688 RectangleInfo geometry;
690 SetGeometry(compositeImage_.constImage(), &geometry);
691 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
693 CompositeImage( image(),
695 compositeImage_.constImage(),
696 geometry.x, geometry.y );
697 throwImageException();
701 void Magick::Image::contrast ( const size_t sharpen_ )
704 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
705 throwImageException();
708 // Convolve image. Applies a general image convolution kernel to the image.
709 // order_ represents the number of columns and rows in the filter kernel.
710 // kernel_ is an array of doubles representing the convolution kernel.
711 void Magick::Image::convolve ( const size_t order_,
712 const double *kernel_ )
714 ExceptionInfo exceptionInfo;
715 GetExceptionInfo( &exceptionInfo );
716 MagickCore::Image* newImage =
717 ConvolveImage ( image(), order_,
718 kernel_, &exceptionInfo );
719 replaceImage( newImage );
720 throwException( exceptionInfo );
721 (void) DestroyExceptionInfo( &exceptionInfo );
725 void Magick::Image::crop ( const Geometry &geometry_ )
727 RectangleInfo cropInfo = geometry_;
728 ExceptionInfo exceptionInfo;
729 GetExceptionInfo( &exceptionInfo );
730 MagickCore::Image* newImage =
734 replaceImage( newImage );
735 throwException( exceptionInfo );
736 (void) DestroyExceptionInfo( &exceptionInfo );
740 void Magick::Image::cycleColormap ( const ssize_t amount_ )
743 CycleColormapImage( image(), amount_ );
744 throwImageException();
748 void Magick::Image::despeckle ( void )
750 ExceptionInfo exceptionInfo;
751 GetExceptionInfo( &exceptionInfo );
752 MagickCore::Image* newImage =
753 DespeckleImage( image(), &exceptionInfo );
754 replaceImage( newImage );
755 throwException( exceptionInfo );
756 (void) DestroyExceptionInfo( &exceptionInfo );
760 void Magick::Image::display( void )
762 DisplayImages( imageInfo(), image() );
765 // Distort image. distorts an image using various distortion methods, by
766 // mapping color lookups of the source image to a new destination image
767 // usally of the same size as the source image, unless 'bestfit' is set to
769 void Magick::Image::distort ( const DistortImageMethod method_,
770 const size_t number_arguments_,
771 const double *arguments_,
772 const bool bestfit_ )
774 ExceptionInfo exceptionInfo;
775 GetExceptionInfo( &exceptionInfo );
776 MagickCore::Image* newImage = DistortImage ( image(), method_,
777 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
779 replaceImage( newImage );
780 throwException( exceptionInfo );
781 (void) DestroyExceptionInfo( &exceptionInfo );
784 // Draw on image using single drawable
785 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
789 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
793 drawable_.operator()(wand);
795 if( constImage()->exception.severity == UndefinedException)
798 wand=DestroyDrawingWand(wand);
801 throwImageException();
804 // Draw on image using a drawable list
805 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
809 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
813 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
814 p != drawable_.end(); p++ )
817 if( constImage()->exception.severity != UndefinedException)
821 if( constImage()->exception.severity == UndefinedException)
824 wand=DestroyDrawingWand(wand);
827 throwImageException();
830 // Hilight edges in image
831 void Magick::Image::edge ( const double radius_ )
833 ExceptionInfo exceptionInfo;
834 GetExceptionInfo( &exceptionInfo );
835 MagickCore::Image* newImage =
836 EdgeImage( image(), radius_, &exceptionInfo );
837 replaceImage( newImage );
838 throwException( exceptionInfo );
839 (void) DestroyExceptionInfo( &exceptionInfo );
842 // Emboss image (hilight edges)
843 void Magick::Image::emboss ( const double radius_, const double sigma_ )
845 ExceptionInfo exceptionInfo;
846 GetExceptionInfo( &exceptionInfo );
847 MagickCore::Image* newImage =
848 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
849 replaceImage( newImage );
850 throwException( exceptionInfo );
851 (void) DestroyExceptionInfo( &exceptionInfo );
854 // Enhance image (minimize noise)
855 void Magick::Image::enhance ( void )
857 ExceptionInfo exceptionInfo;
858 GetExceptionInfo( &exceptionInfo );
859 MagickCore::Image* newImage =
860 EnhanceImage( image(), &exceptionInfo );
861 replaceImage( newImage );
862 throwException( exceptionInfo );
863 (void) DestroyExceptionInfo( &exceptionInfo );
866 // Equalize image (histogram equalization)
867 void Magick::Image::equalize ( void )
870 EqualizeImage( image() );
871 throwImageException();
874 // Erase image to current "background color"
875 void Magick::Image::erase ( void )
878 SetImageBackgroundColor( image() );
879 throwImageException();
882 // Extends image as defined by the geometry.
884 void Magick::Image::extent ( const Geometry &geometry_ )
886 RectangleInfo extentInfo = geometry_;
888 ExceptionInfo exceptionInfo;
889 GetExceptionInfo( &exceptionInfo );
890 MagickCore::Image* newImage =
891 ExtentImage ( image(), &extentInfo, &exceptionInfo );
892 replaceImage( newImage );
893 throwException( exceptionInfo );
894 (void) DestroyExceptionInfo( &exceptionInfo );
896 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
898 backgroundColor ( backgroundColor_ );
899 extent ( geometry_ );
901 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
903 image()->gravity = gravity_;
904 extent ( geometry_ );
906 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
908 image()->gravity = gravity_;
909 backgroundColor ( backgroundColor_ );
910 extent ( geometry_ );
913 // Flip image (reflect each scanline in the vertical direction)
914 void Magick::Image::flip ( void )
916 ExceptionInfo exceptionInfo;
917 GetExceptionInfo( &exceptionInfo );
918 MagickCore::Image* newImage =
919 FlipImage( image(), &exceptionInfo );
920 replaceImage( newImage );
921 throwException( exceptionInfo );
922 (void) DestroyExceptionInfo( &exceptionInfo );
925 // Flood-fill color across pixels that match the color of the
926 // target pixel and are neighbors of the target pixel.
927 // Uses current fuzz setting when determining color match.
928 void Magick::Image::floodFillColor( const ssize_t x_,
930 const Magick::Color &fillColor_ )
932 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
934 void Magick::Image::floodFillColor( const Geometry &point_,
935 const Magick::Color &fillColor_ )
937 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
940 // Flood-fill color across pixels starting at target-pixel and
941 // stopping at pixels matching specified border color.
942 // Uses current fuzz setting when determining color match.
943 void Magick::Image::floodFillColor( const ssize_t x_,
945 const Magick::Color &fillColor_,
946 const Magick::Color &borderColor_ )
948 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
951 void Magick::Image::floodFillColor( const Geometry &point_,
952 const Magick::Color &fillColor_,
953 const Magick::Color &borderColor_ )
955 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
959 // Floodfill pixels matching color (within fuzz factor) of target
960 // pixel(x,y) with replacement alpha value using method.
961 void Magick::Image::floodFillOpacity( const ssize_t x_,
963 const unsigned int alpha_,
964 const PaintMethod method_ )
968 GetPixelInfo(image(),&target);
969 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
970 target.red=pixel.red;
971 target.green=pixel.green;
972 target.blue=pixel.blue;
974 FloodfillPaintImage ( image(),
976 options()->drawInfo(), // const DrawInfo *draw_info
978 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
979 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
980 throwImageException();
983 // Flood-fill texture across pixels that match the color of the
984 // target pixel and are neighbors of the target pixel.
985 // Uses current fuzz setting when determining color match.
986 void Magick::Image::floodFillTexture( const ssize_t x_,
988 const Magick::Image &texture_ )
992 // Set drawing pattern
993 options()->fillPattern(texture_.constImage());
996 Pixels pixels(*this);
998 Quantum *p = pixels.get(x_, y_, 1, 1 );
1000 GetPixelInfo(constImage(),&target);
1001 target.red=GetPixelRed(constImage(),p);
1002 target.green=GetPixelGreen(constImage(),p);
1003 target.blue=GetPixelBlue(constImage(),p);
1005 FloodfillPaintImage ( image(), // Image *image
1007 options()->drawInfo(), // const DrawInfo *draw_info
1008 &target, // const MagickPacket target
1009 static_cast<ssize_t>(x_), // const ssize_t x_offset
1010 static_cast<ssize_t>(y_), // const ssize_t y_offset
1011 MagickFalse // const PaintMethod method
1014 throwImageException();
1016 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1017 const Magick::Image &texture_ )
1019 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1022 // Flood-fill texture across pixels starting at target-pixel and
1023 // stopping at pixels matching specified border color.
1024 // Uses current fuzz setting when determining color match.
1025 void Magick::Image::floodFillTexture( const ssize_t x_,
1027 const Magick::Image &texture_,
1028 const Magick::Color &borderColor_ )
1032 // Set drawing fill pattern
1033 options()->fillPattern(texture_.constImage());
1036 GetPixelInfo(constImage(),&target);
1037 target.red=static_cast<PixelPacket>(borderColor_).red;
1038 target.green=static_cast<PixelPacket>(borderColor_).green;
1039 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1040 FloodfillPaintImage ( image(),
1042 options()->drawInfo(),
1044 static_cast<ssize_t>(x_),
1045 static_cast<ssize_t>(y_),
1048 throwImageException();
1050 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1051 const Magick::Image &texture_,
1052 const Magick::Color &borderColor_ )
1054 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1057 // Flop image (reflect each scanline in the horizontal direction)
1058 void Magick::Image::flop ( void )
1060 ExceptionInfo exceptionInfo;
1061 GetExceptionInfo( &exceptionInfo );
1062 MagickCore::Image* newImage =
1063 FlopImage( image(), &exceptionInfo );
1064 replaceImage( newImage );
1065 throwException( exceptionInfo );
1066 (void) DestroyExceptionInfo( &exceptionInfo );
1070 void Magick::Image::frame ( const Geometry &geometry_ )
1074 info.x = static_cast<ssize_t>(geometry_.width());
1075 info.y = static_cast<ssize_t>(geometry_.height());
1076 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1077 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1078 info.outer_bevel = geometry_.xOff();
1079 info.inner_bevel = geometry_.yOff();
1081 ExceptionInfo exceptionInfo;
1082 GetExceptionInfo( &exceptionInfo );
1083 MagickCore::Image* newImage =
1084 FrameImage( image(), &info, &exceptionInfo );
1085 replaceImage( newImage );
1086 throwException( exceptionInfo );
1087 (void) DestroyExceptionInfo( &exceptionInfo );
1089 void Magick::Image::frame ( const size_t width_,
1090 const size_t height_,
1091 const ssize_t outerBevel_, const ssize_t innerBevel_ )
1094 info.x = static_cast<ssize_t>(width_);
1095 info.y = static_cast<ssize_t>(height_);
1096 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1097 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1098 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1099 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1101 ExceptionInfo exceptionInfo;
1102 GetExceptionInfo( &exceptionInfo );
1103 MagickCore::Image* newImage =
1104 FrameImage( image(), &info, &exceptionInfo );
1105 replaceImage( newImage );
1106 throwException( exceptionInfo );
1107 (void) DestroyExceptionInfo( &exceptionInfo );
1110 // Fx image. Applies a mathematical expression to the image.
1111 void Magick::Image::fx ( const std::string expression )
1113 ExceptionInfo exceptionInfo;
1114 GetExceptionInfo( &exceptionInfo );
1115 MagickCore::Image* newImage =
1116 FxImageChannel ( image(), DefaultChannels, expression.c_str(), &exceptionInfo );
1117 replaceImage( newImage );
1118 throwException( exceptionInfo );
1119 (void) DestroyExceptionInfo( &exceptionInfo );
1121 void Magick::Image::fx ( const std::string expression,
1122 const Magick::ChannelType channel )
1124 ExceptionInfo exceptionInfo;
1125 GetExceptionInfo( &exceptionInfo );
1126 MagickCore::Image* newImage =
1127 FxImageChannel ( image(), channel, expression.c_str(), &exceptionInfo );
1128 replaceImage( newImage );
1129 throwException( exceptionInfo );
1130 (void) DestroyExceptionInfo( &exceptionInfo );
1133 // Gamma correct image
1134 void Magick::Image::gamma ( const double gamma_ )
1136 char gamma[MaxTextExtent + 1];
1137 FormatLocaleString( gamma, MaxTextExtent, "%3.6f", gamma_);
1140 GammaImage ( image(), gamma );
1143 void Magick::Image::gamma ( const double gammaRed_,
1144 const double gammaGreen_,
1145 const double gammaBlue_ )
1147 char gamma[MaxTextExtent + 1];
1148 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1149 gammaRed_, gammaGreen_, gammaBlue_);
1152 GammaImage ( image(), gamma );
1153 throwImageException();
1156 // Gaussian blur image
1157 // The number of neighbor pixels to be included in the convolution
1158 // mask is specified by 'width_'. The standard deviation of the
1159 // gaussian bell curve is specified by 'sigma_'.
1160 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1162 ExceptionInfo exceptionInfo;
1163 GetExceptionInfo( &exceptionInfo );
1164 MagickCore::Image* newImage =
1165 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1166 replaceImage( newImage );
1167 throwException( exceptionInfo );
1168 (void) DestroyExceptionInfo( &exceptionInfo );
1171 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1172 const double width_,
1173 const double sigma_ )
1175 ExceptionInfo exceptionInfo;
1176 GetExceptionInfo( &exceptionInfo );
1177 MagickCore::Image* newImage =
1178 GaussianBlurImageChannel( image(), channel_, width_, sigma_, &exceptionInfo );
1179 replaceImage( newImage );
1180 throwException( exceptionInfo );
1181 (void) DestroyExceptionInfo( &exceptionInfo );
1184 // Apply a color lookup table (Hald CLUT) to the image.
1185 void Magick::Image::haldClut ( const Image &clutImage_ )
1188 (void) HaldClutImage( image(), clutImage_.constImage() );
1189 throwImageException();
1193 void Magick::Image::implode ( const double factor_ )
1195 ExceptionInfo exceptionInfo;
1196 GetExceptionInfo( &exceptionInfo );
1197 MagickCore::Image* newImage =
1198 ImplodeImage( image(), factor_, &exceptionInfo );
1199 replaceImage( newImage );
1200 throwException( exceptionInfo );
1201 (void) DestroyExceptionInfo( &exceptionInfo );
1204 // implements the inverse discrete Fourier transform (IFT) of the image either
1205 // as a magnitude / phase or real / imaginary image pair.
1206 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1208 ExceptionInfo exceptionInfo;
1209 GetExceptionInfo( &exceptionInfo );
1210 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1211 phase_.constImage(), MagickTrue, &exceptionInfo);
1212 replaceImage( newImage );
1213 throwException( exceptionInfo );
1214 (void) DestroyExceptionInfo( &exceptionInfo );
1216 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1217 const bool magnitude_ )
1219 ExceptionInfo exceptionInfo;
1220 GetExceptionInfo( &exceptionInfo );
1221 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1222 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1224 replaceImage( newImage );
1225 throwException( exceptionInfo );
1226 (void) DestroyExceptionInfo( &exceptionInfo );
1229 // Level image. Adjust the levels of the image by scaling the colors
1230 // falling between specified white and black points to the full
1231 // available quantum range. The parameters provided represent the
1232 // black, mid (gamma), and white points. The black point specifies
1233 // the darkest color in the image. Colors darker than the black point
1234 // are set to zero. Mid point (gamma) specifies a gamma correction to
1235 // apply to the image. White point specifies the lightest color in the
1236 // image. Colors brighter than the white point are set to the maximum
1237 // quantum value. The black and white point have the valid range 0 to
1238 // QuantumRange while gamma has a useful range of 0 to ten.
1239 void Magick::Image::level ( const double black_point,
1240 const double white_point,
1241 const double gamma )
1244 char levels[MaxTextExtent];
1245 FormatLocaleString( levels, MaxTextExtent, "%g,%g,%g",black_point,white_point,gamma);
1246 (void) LevelImage( image(), levels );
1247 throwImageException();
1250 // Level image channel. Adjust the levels of the image channel by
1251 // scaling the values falling between specified white and black points
1252 // to the full available quantum range. The parameters provided
1253 // represent the black, mid (gamma), and white points. The black
1254 // point specifies the darkest color in the image. Colors darker than
1255 // the black point are set to zero. Mid point (gamma) specifies a
1256 // gamma correction to apply to the image. White point specifies the
1257 // lightest color in the image. Colors brighter than the white point
1258 // are set to the maximum quantum value. The black and white point
1259 // have the valid range 0 to QuantumRange while gamma has a useful range of
1261 void Magick::Image::levelChannel ( const Magick::ChannelType channel,
1262 const double black_point,
1263 const double white_point,
1264 const double gamma )
1267 (void) LevelImageChannel( image(), channel, black_point, white_point,
1269 throwImageException();
1272 // Magnify image by integral size
1273 void Magick::Image::magnify ( void )
1275 ExceptionInfo exceptionInfo;
1276 GetExceptionInfo( &exceptionInfo );
1277 MagickCore::Image* newImage =
1278 MagnifyImage( image(), &exceptionInfo );
1279 replaceImage( newImage );
1280 throwException( exceptionInfo );
1281 (void) DestroyExceptionInfo( &exceptionInfo );
1284 // Remap image colors with closest color from reference image
1285 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1288 options()->quantizeDither( dither_ );
1289 RemapImage ( options()->quantizeInfo(), image(),
1290 mapImage_.constImage());
1291 throwImageException();
1293 // Floodfill designated area with replacement alpha value
1294 void Magick::Image::matteFloodfill ( const Color &target_ ,
1295 const unsigned int alpha_,
1296 const ssize_t x_, const ssize_t y_,
1297 const Magick::PaintMethod method_ )
1301 GetPixelInfo(constImage(),&target);
1302 target.red=static_cast<PixelPacket>(target_).red;
1303 target.green=static_cast<PixelPacket>(target_).green;
1304 target.blue=static_cast<PixelPacket>(target_).blue;
1305 target.alpha=alpha_;
1306 FloodfillPaintImage ( image(), OpacityChannel, options()->drawInfo(), &target,
1307 x_, y_, method_ == FloodfillMethod ? MagickFalse : MagickTrue);
1308 throwImageException();
1311 // Filter image by replacing each pixel component with the median
1312 // color in a circular neighborhood
1313 void Magick::Image::medianFilter ( const double radius_ )
1315 ExceptionInfo exceptionInfo;
1316 GetExceptionInfo( &exceptionInfo );
1317 MagickCore::Image* newImage =
1318 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1319 radius_,&exceptionInfo );
1320 replaceImage( newImage );
1321 throwException( exceptionInfo );
1322 (void) DestroyExceptionInfo( &exceptionInfo );
1325 // Reduce image by integral size
1326 void Magick::Image::minify ( void )
1328 ExceptionInfo exceptionInfo;
1329 GetExceptionInfo( &exceptionInfo );
1330 MagickCore::Image* newImage =
1331 MinifyImage( image(), &exceptionInfo );
1332 replaceImage( newImage );
1333 throwException( exceptionInfo );
1334 (void) DestroyExceptionInfo( &exceptionInfo );
1337 // Modulate percent hue, saturation, and brightness of an image
1338 void Magick::Image::modulate ( const double brightness_,
1339 const double saturation_,
1342 char modulate[MaxTextExtent + 1];
1343 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1344 brightness_, saturation_, hue_);
1347 ModulateImage( image(), modulate );
1348 throwImageException();
1351 // Motion blur image with specified blur factor
1352 // The radius_ parameter specifies the radius of the Gaussian, in
1353 // pixels, not counting the center pixel. The sigma_ parameter
1354 // specifies the standard deviation of the Laplacian, in pixels.
1355 // The angle_ parameter specifies the angle the object appears
1356 // to be comming from (zero degrees is from the right).
1357 void Magick::Image::motionBlur ( const double radius_,
1358 const double sigma_,
1359 const double angle_ )
1361 ExceptionInfo exceptionInfo;
1362 GetExceptionInfo( &exceptionInfo );
1363 MagickCore::Image* newImage =
1364 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1365 replaceImage( newImage );
1366 throwException( exceptionInfo );
1367 (void) DestroyExceptionInfo( &exceptionInfo );
1370 // Negate image. Set grayscale_ to true to effect grayscale values
1372 void Magick::Image::negate ( const bool grayscale_ )
1375 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
1376 throwImageException();
1380 void Magick::Image::normalize ( void )
1383 NormalizeImage ( image() );
1384 throwImageException();
1388 void Magick::Image::oilPaint ( const double radius_ )
1390 ExceptionInfo exceptionInfo;
1391 GetExceptionInfo( &exceptionInfo );
1392 MagickCore::Image* newImage =
1393 OilPaintImage( image(), radius_, &exceptionInfo );
1394 replaceImage( newImage );
1395 throwException( exceptionInfo );
1396 (void) DestroyExceptionInfo( &exceptionInfo );
1399 // Set or attenuate the alpha channel. If the image pixels are
1400 // opaque then they are set to the specified alpha value, otherwise
1401 // they are blended with the supplied alpha value. The value of
1402 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1403 // OpaqueAlpha and TransparentAlpha are available to specify
1404 // completely opaque or completely transparent, respectively.
1405 void Magick::Image::alpha ( const unsigned int alpha_ )
1408 SetImageOpacity( image(), alpha_ );
1411 // Change the color of an opaque pixel to the pen color.
1412 void Magick::Image::opaque ( const Color &opaqueColor_,
1413 const Color &penColor_ )
1415 if ( !opaqueColor_.isValid() )
1417 throwExceptionExplicit( OptionError,
1418 "Opaque color argument is invalid" );
1420 if ( !penColor_.isValid() )
1422 throwExceptionExplicit( OptionError,
1423 "Pen color argument is invalid" );
1427 std::string opaqueColor = opaqueColor_;
1428 std::string penColor = penColor_;
1432 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1433 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1434 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1435 throwImageException();
1438 // Ping is similar to read except only enough of the image is read to
1439 // determine the image columns, rows, and filesize. Access the
1440 // columns(), rows(), and fileSize() attributes after invoking ping.
1441 // The image data is not valid after calling ping.
1442 void Magick::Image::ping ( const std::string &imageSpec_ )
1444 options()->fileName( imageSpec_ );
1445 ExceptionInfo exceptionInfo;
1446 GetExceptionInfo( &exceptionInfo );
1447 MagickCore::Image* image =
1448 PingImage( imageInfo(), &exceptionInfo );
1449 replaceImage( image );
1450 throwException( exceptionInfo );
1451 (void) DestroyExceptionInfo( &exceptionInfo );
1454 // Ping is similar to read except only enough of the image is read
1455 // to determine the image columns, rows, and filesize. Access the
1456 // columns(), rows(), and fileSize() attributes after invoking
1457 // ping. The image data is not valid after calling ping.
1458 void Magick::Image::ping ( const Blob& blob_ )
1460 ExceptionInfo exceptionInfo;
1461 GetExceptionInfo( &exceptionInfo );
1462 MagickCore::Image* image =
1463 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1464 replaceImage( image );
1465 throwException( exceptionInfo );
1466 (void) DestroyExceptionInfo( &exceptionInfo );
1469 // Execute a named process module using an argc/argv syntax similar to
1470 // that accepted by a C 'main' routine. An exception is thrown if the
1471 // requested process module doesn't exist, fails to load, or fails during
1473 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1478 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1479 &image()->exception );
1481 if (status == false)
1482 throwException( image()->exception );
1485 // Quantize colors in image using current quantization settings
1486 // Set measureError_ to true in order to measure quantization error
1487 void Magick::Image::quantize ( const bool measureError_ )
1492 options()->quantizeInfo()->measure_error=MagickTrue;
1494 options()->quantizeInfo()->measure_error=MagickFalse;
1496 QuantizeImage( options()->quantizeInfo(), image() );
1498 throwImageException();
1501 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1502 void Magick::Image::quantumOperator ( const ChannelType channel_,
1503 const MagickEvaluateOperator operator_,
1506 ExceptionInfo exceptionInfo;
1507 GetExceptionInfo( &exceptionInfo );
1508 EvaluateImageChannel( image(), channel_, operator_, rvalue_, &exceptionInfo);
1509 throwException( exceptionInfo );
1510 (void) DestroyExceptionInfo( &exceptionInfo );
1513 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1514 const size_t columns_,
1516 const ChannelType channel_,
1517 const MagickEvaluateOperator operator_,
1518 const double rvalue_)
1520 ExceptionInfo exceptionInfo;
1521 GetExceptionInfo( &exceptionInfo );
1522 RectangleInfo geometry;
1523 geometry.width = columns_;
1524 geometry.height = rows_;
1527 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1529 EvaluateImageChannel( crop_image, channel_, operator_, rvalue_,
1531 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1532 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1533 crop_image = DestroyImageList(crop_image);
1534 throwException( exceptionInfo );
1535 (void) DestroyExceptionInfo( &exceptionInfo );
1538 // Raise image (lighten or darken the edges of an image to give a 3-D
1539 // raised or lowered effect)
1540 void Magick::Image::raise ( const Geometry &geometry_ ,
1541 const bool raisedFlag_ )
1543 RectangleInfo raiseInfo = geometry_;
1545 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1546 throwImageException();
1550 // Random threshold image.
1552 // Changes the value of individual pixels based on the intensity
1553 // of each pixel compared to a random threshold. The result is a
1554 // low-contrast, two color image. The thresholds_ argument is a
1555 // geometry containing LOWxHIGH thresholds. If the string
1556 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1557 // 3, or 4 will be performed instead. If a channel_ argument is
1558 // specified then only the specified channel is altered. This is
1559 // a very fast alternative to 'quantize' based dithering.
1560 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1562 randomThresholdChannel(thresholds_,DefaultChannels);
1564 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1565 const ChannelType channel_ )
1567 ExceptionInfo exceptionInfo;
1568 GetExceptionInfo( &exceptionInfo );
1570 (void) RandomThresholdImageChannel( image(),
1572 static_cast<std::string>(thresholds_).c_str(),
1574 throwImageException();
1575 (void) DestroyExceptionInfo( &exceptionInfo );
1578 // Read image into current object
1579 void Magick::Image::read ( const std::string &imageSpec_ )
1581 options()->fileName( imageSpec_ );
1583 ExceptionInfo exceptionInfo;
1584 GetExceptionInfo( &exceptionInfo );
1585 MagickCore::Image* image =
1586 ReadImage( imageInfo(), &exceptionInfo );
1588 // Ensure that multiple image frames were not read.
1589 if ( image && image->next )
1591 // Destroy any extra image frames
1592 MagickCore::Image* next = image->next;
1595 DestroyImageList( next );
1598 replaceImage( image );
1599 throwException( exceptionInfo );
1601 throwException( image->exception );
1602 (void) DestroyExceptionInfo( &exceptionInfo );
1605 // Read image of specified size into current object
1606 void Magick::Image::read ( const Geometry &size_,
1607 const std::string &imageSpec_ )
1613 // Read image from in-memory BLOB
1614 void Magick::Image::read ( const Blob &blob_ )
1616 ExceptionInfo exceptionInfo;
1617 GetExceptionInfo( &exceptionInfo );
1618 MagickCore::Image* image =
1619 BlobToImage( imageInfo(),
1620 static_cast<const void *>(blob_.data()),
1621 blob_.length(), &exceptionInfo );
1622 replaceImage( image );
1623 throwException( exceptionInfo );
1625 throwException( image->exception );
1626 (void) DestroyExceptionInfo( &exceptionInfo );
1629 // Read image of specified size from in-memory BLOB
1630 void Magick::Image::read ( const Blob &blob_,
1631 const Geometry &size_ )
1639 // Read image of specified size and depth from in-memory BLOB
1640 void Magick::Image::read ( const Blob &blob_,
1641 const Geometry &size_,
1642 const size_t depth_ )
1652 // Read image of specified size, depth, and format from in-memory BLOB
1653 void Magick::Image::read ( const Blob &blob_,
1654 const Geometry &size_,
1655 const size_t depth_,
1656 const std::string &magick_ )
1664 // Set explicit image format
1665 fileName( magick_ + ':');
1670 // Read image of specified size, and format from in-memory BLOB
1671 void Magick::Image::read ( const Blob &blob_,
1672 const Geometry &size_,
1673 const std::string &magick_ )
1679 // Set explicit image format
1680 fileName( magick_ + ':');
1685 // Read image based on raw pixels in memory (ConstituteImage)
1686 void Magick::Image::read ( const size_t width_,
1687 const size_t height_,
1688 const std::string &map_,
1689 const StorageType type_,
1690 const void *pixels_ )
1692 ExceptionInfo exceptionInfo;
1693 GetExceptionInfo( &exceptionInfo );
1694 MagickCore::Image* image =
1695 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1697 replaceImage( image );
1698 throwException( exceptionInfo );
1700 throwException( image->exception );
1701 (void) DestroyExceptionInfo( &exceptionInfo );
1704 // Reduce noise in image
1705 void Magick::Image::reduceNoise ( const double order_ )
1707 ExceptionInfo exceptionInfo;
1708 GetExceptionInfo( &exceptionInfo );
1709 MagickCore::Image* newImage =
1710 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1712 replaceImage( newImage );
1713 throwException( exceptionInfo );
1714 (void) DestroyExceptionInfo( &exceptionInfo );
1718 void Magick::Image::resize( const Geometry &geometry_ )
1720 // Calculate new size. This code should be supported using binary arguments
1721 // in the ImageMagick library.
1724 size_t width = columns();
1725 size_t height = rows();
1727 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1731 ExceptionInfo exceptionInfo;
1732 GetExceptionInfo( &exceptionInfo );
1733 MagickCore::Image* newImage =
1734 ResizeImage( image(),
1740 replaceImage( newImage );
1741 throwException( exceptionInfo );
1742 (void) DestroyExceptionInfo( &exceptionInfo );
1746 void Magick::Image::roll ( const Geometry &roll_ )
1748 ssize_t xOff = roll_.xOff();
1749 if ( roll_.xNegative() )
1751 ssize_t yOff = roll_.yOff();
1752 if ( roll_.yNegative() )
1755 ExceptionInfo exceptionInfo;
1756 GetExceptionInfo( &exceptionInfo );
1757 MagickCore::Image* newImage =
1758 RollImage( image(), xOff, yOff, &exceptionInfo );
1759 replaceImage( newImage );
1760 throwException( exceptionInfo );
1761 (void) DestroyExceptionInfo( &exceptionInfo );
1763 void Magick::Image::roll ( const size_t columns_,
1764 const size_t rows_ )
1766 ExceptionInfo exceptionInfo;
1767 GetExceptionInfo( &exceptionInfo );
1768 MagickCore::Image* newImage =
1770 static_cast<ssize_t>(columns_),
1771 static_cast<ssize_t>(rows_), &exceptionInfo );
1772 replaceImage( newImage );
1773 throwException( exceptionInfo );
1774 (void) DestroyExceptionInfo( &exceptionInfo );
1778 void Magick::Image::rotate ( const double degrees_ )
1780 ExceptionInfo exceptionInfo;
1781 GetExceptionInfo( &exceptionInfo );
1782 MagickCore::Image* newImage =
1783 RotateImage( image(), degrees_, &exceptionInfo);
1784 replaceImage( newImage );
1785 throwException( exceptionInfo );
1786 (void) DestroyExceptionInfo( &exceptionInfo );
1790 void Magick::Image::sample ( const Geometry &geometry_ )
1794 size_t width = columns();
1795 size_t height = rows();
1797 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1801 ExceptionInfo exceptionInfo;
1802 GetExceptionInfo( &exceptionInfo );
1803 MagickCore::Image* newImage =
1804 SampleImage( image(), width, height, &exceptionInfo );
1805 replaceImage( newImage );
1806 throwException( exceptionInfo );
1807 (void) DestroyExceptionInfo( &exceptionInfo );
1811 void Magick::Image::scale ( const Geometry &geometry_ )
1815 size_t width = columns();
1816 size_t height = rows();
1818 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1822 ExceptionInfo exceptionInfo;
1823 GetExceptionInfo( &exceptionInfo );
1824 MagickCore::Image* newImage =
1825 ScaleImage( image(), width, height, &exceptionInfo );
1826 replaceImage( newImage );
1827 throwException( exceptionInfo );
1828 (void) DestroyExceptionInfo( &exceptionInfo );
1831 // Segment (coalesce similar image components) by analyzing the
1832 // histograms of the color components and identifying units that are
1833 // homogeneous with the fuzzy c-means technique.
1834 void Magick::Image::segment ( const double clusterThreshold_,
1835 const double smoothingThreshold_ )
1838 SegmentImage ( image(),
1839 options()->quantizeColorSpace(),
1840 (MagickBooleanType) options()->verbose(),
1842 smoothingThreshold_ );
1843 throwImageException();
1844 SyncImage( image() );
1845 throwImageException();
1848 // Shade image using distant light source
1849 void Magick::Image::shade ( const double azimuth_,
1850 const double elevation_,
1851 const bool colorShading_ )
1853 ExceptionInfo exceptionInfo;
1854 GetExceptionInfo( &exceptionInfo );
1855 MagickCore::Image* newImage =
1856 ShadeImage( image(),
1857 colorShading_ == true ? MagickTrue : MagickFalse,
1861 replaceImage( newImage );
1862 throwException( exceptionInfo );
1863 (void) DestroyExceptionInfo( &exceptionInfo );
1866 // Sharpen pixels in image
1867 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1869 ExceptionInfo exceptionInfo;
1870 GetExceptionInfo( &exceptionInfo );
1871 MagickCore::Image* newImage =
1872 SharpenImage( image(),
1876 replaceImage( newImage );
1877 throwException( exceptionInfo );
1878 (void) DestroyExceptionInfo( &exceptionInfo );
1881 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1882 const double radius_, const double sigma_ )
1884 ExceptionInfo exceptionInfo;
1885 GetExceptionInfo( &exceptionInfo );
1886 MagickCore::Image* newImage =
1887 SharpenImageChannel( image(),
1892 replaceImage( newImage );
1893 throwException( exceptionInfo );
1894 (void) DestroyExceptionInfo( &exceptionInfo );
1897 // Shave pixels from image edges.
1898 void Magick::Image::shave ( const Geometry &geometry_ )
1900 RectangleInfo shaveInfo = geometry_;
1901 ExceptionInfo exceptionInfo;
1902 GetExceptionInfo( &exceptionInfo );
1903 MagickCore::Image* newImage =
1904 ShaveImage( image(),
1907 replaceImage( newImage );
1908 throwException( exceptionInfo );
1909 (void) DestroyExceptionInfo( &exceptionInfo );
1913 void Magick::Image::shear ( const double xShearAngle_,
1914 const double yShearAngle_ )
1916 ExceptionInfo exceptionInfo;
1917 GetExceptionInfo( &exceptionInfo );
1918 MagickCore::Image* newImage =
1919 ShearImage( image(),
1923 replaceImage( newImage );
1924 throwException( exceptionInfo );
1925 (void) DestroyExceptionInfo( &exceptionInfo );
1929 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
1932 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint );
1933 throwImageException();
1936 // Solarize image (similar to effect seen when exposing a photographic
1937 // film to light during the development process)
1938 void Magick::Image::solarize ( const double factor_ )
1941 SolarizeImage ( image(), factor_ );
1942 throwImageException();
1945 // Sparse color image, given a set of coordinates, interpolates the colors
1946 // found at those coordinates, across the whole image, using various methods.
1948 void Magick::Image::sparseColor ( const ChannelType channel,
1949 const SparseColorMethod method,
1950 const size_t number_arguments,
1951 const double *arguments )
1953 ExceptionInfo exceptionInfo;
1954 GetExceptionInfo( &exceptionInfo );
1955 MagickCore::Image* newImage = SparseColorImage ( image(), channel, method,
1956 number_arguments, arguments, &exceptionInfo );
1957 replaceImage( newImage );
1958 throwException( exceptionInfo );
1959 (void) DestroyExceptionInfo( &exceptionInfo );
1962 // Spread pixels randomly within image by specified ammount
1963 void Magick::Image::spread ( const size_t amount_ )
1965 ExceptionInfo exceptionInfo;
1966 GetExceptionInfo( &exceptionInfo );
1967 MagickCore::Image* newImage =
1968 SpreadImage( image(),
1971 replaceImage( newImage );
1972 throwException( exceptionInfo );
1973 (void) DestroyExceptionInfo( &exceptionInfo );
1976 // Add a digital watermark to the image (based on second image)
1977 void Magick::Image::stegano ( const Image &watermark_ )
1979 ExceptionInfo exceptionInfo;
1980 GetExceptionInfo( &exceptionInfo );
1981 MagickCore::Image* newImage =
1982 SteganoImage( image(),
1983 watermark_.constImage(),
1985 replaceImage( newImage );
1986 throwException( exceptionInfo );
1987 (void) DestroyExceptionInfo( &exceptionInfo );
1990 // Stereo image (left image is current image)
1991 void Magick::Image::stereo ( const Image &rightImage_ )
1993 ExceptionInfo exceptionInfo;
1994 GetExceptionInfo( &exceptionInfo );
1995 MagickCore::Image* newImage =
1996 StereoImage( image(),
1997 rightImage_.constImage(),
1999 replaceImage( newImage );
2000 throwException( exceptionInfo );
2001 (void) DestroyExceptionInfo( &exceptionInfo );
2005 void Magick::Image::swirl ( const double degrees_ )
2007 ExceptionInfo exceptionInfo;
2008 GetExceptionInfo( &exceptionInfo );
2009 MagickCore::Image* newImage =
2010 SwirlImage( image(), degrees_,
2012 replaceImage( newImage );
2013 throwException( exceptionInfo );
2014 (void) DestroyExceptionInfo( &exceptionInfo );
2018 void Magick::Image::texture ( const Image &texture_ )
2021 TextureImage( image(), texture_.constImage() );
2022 throwImageException();
2026 void Magick::Image::threshold ( const double threshold_ )
2029 BilevelImage( image(), threshold_ );
2030 throwImageException();
2033 // Transform image based on image geometry only
2034 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2037 TransformImage ( &(image()), 0,
2038 std::string(imageGeometry_).c_str() );
2039 throwImageException();
2041 // Transform image based on image and crop geometries
2042 void Magick::Image::transform ( const Geometry &imageGeometry_,
2043 const Geometry &cropGeometry_ )
2046 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2047 std::string(imageGeometry_).c_str() );
2048 throwImageException();
2051 // Add matte image to image, setting pixels matching color to transparent
2052 void Magick::Image::transparent ( const Color &color_ )
2054 if ( !color_.isValid() )
2056 throwExceptionExplicit( OptionError,
2057 "Color argument is invalid" );
2060 std::string color = color_;
2063 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2065 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse );
2066 throwImageException();
2069 // Add matte image to image, setting pixels matching color to transparent
2070 void Magick::Image::transparentChroma(const Color &colorLow_,
2071 const Color &colorHigh_)
2073 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2075 throwExceptionExplicit( OptionError,
2076 "Color argument is invalid" );
2079 std::string colorLow = colorLow_;
2080 std::string colorHigh = colorHigh_;
2082 PixelInfo targetLow;
2083 PixelInfo targetHigh;
2084 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2085 &image()->exception);
2086 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2087 &image()->exception);
2089 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2090 TransparentAlpha, MagickFalse );
2091 throwImageException();
2095 // Trim edges that are the background color from the image
2096 void Magick::Image::trim ( void )
2098 ExceptionInfo exceptionInfo;
2099 GetExceptionInfo( &exceptionInfo );
2100 MagickCore::Image* newImage =
2101 TrimImage( image(), &exceptionInfo);
2102 replaceImage( newImage );
2103 throwException( exceptionInfo );
2104 (void) DestroyExceptionInfo( &exceptionInfo );
2107 // Replace image with a sharpened version of the original image
2108 // using the unsharp mask algorithm.
2110 // the radius of the Gaussian, in pixels, not counting the
2113 // the standard deviation of the Gaussian, in pixels.
2115 // the percentage of the difference between the original and
2116 // the blur image that is added back into the original.
2118 // the threshold in pixels needed to apply the diffence amount.
2119 void Magick::Image::unsharpmask ( const double radius_,
2120 const double sigma_,
2121 const double amount_,
2122 const double threshold_ )
2124 ExceptionInfo exceptionInfo;
2125 GetExceptionInfo( &exceptionInfo );
2126 MagickCore::Image* newImage =
2127 UnsharpMaskImage( image(),
2133 replaceImage( newImage );
2134 throwException( exceptionInfo );
2135 (void) DestroyExceptionInfo( &exceptionInfo );
2138 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2139 const double radius_,
2140 const double sigma_,
2141 const double amount_,
2142 const double threshold_ )
2144 ExceptionInfo exceptionInfo;
2145 GetExceptionInfo( &exceptionInfo );
2146 MagickCore::Image* newImage =
2147 UnsharpMaskImageChannel( image(),
2154 replaceImage( newImage );
2155 throwException( exceptionInfo );
2156 (void) DestroyExceptionInfo( &exceptionInfo );
2159 // Map image pixels to a sine wave
2160 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2162 ExceptionInfo exceptionInfo;
2163 GetExceptionInfo( &exceptionInfo );
2164 MagickCore::Image* newImage =
2169 replaceImage( newImage );
2170 throwException( exceptionInfo );
2171 (void) DestroyExceptionInfo( &exceptionInfo );
2174 // Write image to file
2175 void Magick::Image::write( const std::string &imageSpec_ )
2178 fileName( imageSpec_ );
2179 WriteImage( imageInfo(), image() );
2180 throwImageException();
2183 // Write image to in-memory BLOB
2184 void Magick::Image::write ( Blob *blob_ )
2187 size_t length = 2048; // Efficient size for small images
2188 ExceptionInfo exceptionInfo;
2189 GetExceptionInfo( &exceptionInfo );
2190 void* data = ImageToBlob( imageInfo(),
2194 throwException( exceptionInfo );
2195 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2196 throwImageException();
2197 (void) DestroyExceptionInfo( &exceptionInfo );
2199 void Magick::Image::write ( Blob *blob_,
2200 const std::string &magick_ )
2204 size_t length = 2048; // Efficient size for small images
2205 ExceptionInfo exceptionInfo;
2206 GetExceptionInfo( &exceptionInfo );
2207 void* data = ImageToBlob( imageInfo(),
2211 throwException( exceptionInfo );
2212 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2213 throwImageException();
2214 (void) DestroyExceptionInfo( &exceptionInfo );
2216 void Magick::Image::write ( Blob *blob_,
2217 const std::string &magick_,
2218 const size_t depth_ )
2223 size_t length = 2048; // Efficient size for small images
2224 ExceptionInfo exceptionInfo;
2225 GetExceptionInfo( &exceptionInfo );
2226 void* data = ImageToBlob( imageInfo(),
2230 throwException( exceptionInfo );
2231 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2232 throwImageException();
2233 (void) DestroyExceptionInfo( &exceptionInfo );
2236 // Write image to an array of pixels with storage type specified
2237 // by user (ExportImagePixels), e.g.
2238 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2239 void Magick::Image::write ( const ssize_t x_,
2241 const size_t columns_,
2243 const std::string &map_,
2244 const StorageType type_,
2247 ExceptionInfo exceptionInfo;
2248 GetExceptionInfo( &exceptionInfo );
2249 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2252 throwException( exceptionInfo );
2253 (void) DestroyExceptionInfo( &exceptionInfo );
2257 void Magick::Image::zoom( const Geometry &geometry_ )
2259 // Calculate new size. This code should be supported using binary arguments
2260 // in the ImageMagick library.
2263 size_t width = columns();
2264 size_t height = rows();
2266 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2270 ExceptionInfo exceptionInfo;
2271 GetExceptionInfo( &exceptionInfo );
2272 MagickCore::Image* newImage =
2273 ResizeImage( image(),
2279 replaceImage( newImage );
2280 throwException( exceptionInfo );
2281 (void) DestroyExceptionInfo( &exceptionInfo );
2285 * Methods for setting image attributes
2289 // Join images into a single multi-image file
2290 void Magick::Image::adjoin ( const bool flag_ )
2293 options()->adjoin( flag_ );
2295 bool Magick::Image::adjoin ( void ) const
2297 return constOptions()->adjoin();
2300 // Remove pixel aliasing
2301 void Magick::Image::antiAlias( const bool flag_ )
2304 options()->antiAlias( static_cast<size_t>(flag_) );
2306 bool Magick::Image::antiAlias( void )
2308 return static_cast<bool>( options()->antiAlias( ) );
2311 // Animation inter-frame delay
2312 void Magick::Image::animationDelay ( const size_t delay_ )
2315 image()->delay = delay_;
2317 size_t Magick::Image::animationDelay ( void ) const
2319 return constImage()->delay;
2322 // Number of iterations to play animation
2323 void Magick::Image::animationIterations ( const size_t iterations_ )
2326 image()->iterations = iterations_;
2328 size_t Magick::Image::animationIterations ( void ) const
2330 return constImage()->iterations;
2333 // Access/Update a named image attribute
2334 void Magick::Image::attribute ( const std::string name_,
2335 const std::string value_ )
2338 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2340 std::string Magick::Image::attribute ( const std::string name_ )
2342 const char *value = GetImageProperty( constImage(), name_.c_str() );
2345 return std::string( value );
2347 return std::string(); // Intentionally no exception
2351 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2355 if ( backgroundColor_.isValid() )
2357 image()->background_color = backgroundColor_;
2361 image()->background_color = Color();
2364 options()->backgroundColor( backgroundColor_ );
2366 Magick::Color Magick::Image::backgroundColor ( void ) const
2368 return constOptions()->backgroundColor( );
2371 // Background fill texture
2372 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2375 options()->backgroundTexture( backgroundTexture_ );
2377 std::string Magick::Image::backgroundTexture ( void ) const
2379 return constOptions()->backgroundTexture( );
2382 // Original image columns
2383 size_t Magick::Image::baseColumns ( void ) const
2385 return constImage()->magick_columns;
2388 // Original image name
2389 std::string Magick::Image::baseFilename ( void ) const
2391 return std::string(constImage()->magick_filename);
2394 // Original image rows
2395 size_t Magick::Image::baseRows ( void ) const
2397 return constImage()->magick_rows;
2401 void Magick::Image::borderColor ( const Color &borderColor_ )
2405 if ( borderColor_.isValid() )
2407 image()->border_color = borderColor_;
2411 image()->border_color = Color();
2414 options()->borderColor( borderColor_ );
2416 Magick::Color Magick::Image::borderColor ( void ) const
2418 return constOptions()->borderColor( );
2421 // Return smallest bounding box enclosing non-border pixels. The
2422 // current fuzz value is used when discriminating between pixels.
2423 // This is the crop bounding box used by crop(Geometry(0,0));
2424 Magick::Geometry Magick::Image::boundingBox ( void ) const
2426 ExceptionInfo exceptionInfo;
2427 GetExceptionInfo( &exceptionInfo );
2428 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2429 throwException( exceptionInfo );
2430 (void) DestroyExceptionInfo( &exceptionInfo );
2431 return Geometry( bbox );
2434 // Text bounding-box base color
2435 void Magick::Image::boxColor ( const Color &boxColor_ )
2438 options()->boxColor( boxColor_ );
2440 Magick::Color Magick::Image::boxColor ( void ) const
2442 return constOptions()->boxColor( );
2445 // Pixel cache threshold. Once this threshold is exceeded, all
2446 // subsequent pixels cache operations are to/from disk.
2447 // This setting is shared by all Image objects.
2449 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2451 SetMagickResourceLimit( MemoryResource, threshold_ );
2454 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2457 image()->chromaticity.blue_primary.x = x_;
2458 image()->chromaticity.blue_primary.y = y_;
2460 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2462 *x_ = constImage()->chromaticity.blue_primary.x;
2463 *y_ = constImage()->chromaticity.blue_primary.y;
2466 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2469 image()->chromaticity.green_primary.x = x_;
2470 image()->chromaticity.green_primary.y = y_;
2472 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2474 *x_ = constImage()->chromaticity.green_primary.x;
2475 *y_ = constImage()->chromaticity.green_primary.y;
2478 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2481 image()->chromaticity.red_primary.x = x_;
2482 image()->chromaticity.red_primary.y = y_;
2484 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2486 *x_ = constImage()->chromaticity.red_primary.x;
2487 *y_ = constImage()->chromaticity.red_primary.y;
2490 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2493 image()->chromaticity.white_point.x = x_;
2494 image()->chromaticity.white_point.y = y_;
2496 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2498 *x_ = constImage()->chromaticity.white_point.x;
2499 *y_ = constImage()->chromaticity.white_point.y;
2502 // Set image storage class
2503 void Magick::Image::classType ( const ClassType class_ )
2505 if ( classType() == PseudoClass && class_ == DirectClass )
2507 // Use SyncImage to synchronize the DirectClass pixels with the
2508 // color map and then set to DirectClass type.
2510 SyncImage( image() );
2511 image()->colormap = (PixelPacket *)
2512 RelinquishMagickMemory( image()->colormap );
2513 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2517 if ( classType() == DirectClass && class_ == PseudoClass )
2519 // Quantize to create PseudoClass color map
2521 quantizeColors(MaxColormapSize);
2523 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2527 // Associate a clip mask with the image. The clip mask must be the
2528 // same dimensions as the image. Pass an invalid image to unset an
2529 // existing clip mask.
2530 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2534 if( clipMask_.isValid() )
2537 SetImageClipMask( image(), clipMask_.constImage() );
2541 // Unset existing clip mask
2542 SetImageClipMask( image(), 0 );
2545 Magick::Image Magick::Image::clipMask ( void ) const
2547 ExceptionInfo exceptionInfo;
2548 GetExceptionInfo( &exceptionInfo );
2549 MagickCore::Image* image =
2550 GetImageClipMask( constImage(), &exceptionInfo );
2551 throwException( exceptionInfo );
2552 (void) DestroyExceptionInfo( &exceptionInfo );
2553 return Magick::Image( image );
2556 void Magick::Image::colorFuzz ( const double fuzz_ )
2559 image()->fuzz = fuzz_;
2560 options()->colorFuzz( fuzz_ );
2562 double Magick::Image::colorFuzz ( void ) const
2564 return constOptions()->colorFuzz( );
2567 // Set color in colormap at index
2568 void Magick::Image::colorMap ( const size_t index_,
2569 const Color &color_ )
2571 MagickCore::Image* imageptr = image();
2573 if (index_ > (MaxColormapSize-1) )
2574 throwExceptionExplicit( OptionError,
2575 "Colormap index must be less than MaxColormapSize" );
2577 if ( !color_.isValid() )
2578 throwExceptionExplicit( OptionError,
2579 "Color argument is invalid");
2582 // Ensure that colormap size is large enough
2583 if ( colorMapSize() < (index_+1) )
2584 colorMapSize( index_ + 1 );
2586 // Set color at index in colormap
2587 (imageptr->colormap)[index_] = color_;
2589 // Return color in colormap at index
2590 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2592 const MagickCore::Image* imageptr = constImage();
2594 if ( !imageptr->colormap )
2595 throwExceptionExplicit( OptionError,
2596 "Image does not contain a colormap");
2598 if ( index_ > imageptr->colors-1 )
2599 throwExceptionExplicit( OptionError,
2600 "Index out of range");
2602 return Magick::Color( (imageptr->colormap)[index_] );
2605 // Colormap size (number of colormap entries)
2606 void Magick::Image::colorMapSize ( const size_t entries_ )
2608 if (entries_ >MaxColormapSize )
2609 throwExceptionExplicit( OptionError,
2610 "Colormap entries must not exceed MaxColormapSize" );
2614 MagickCore::Image* imageptr = image();
2616 if( !imageptr->colormap )
2618 // Allocate colormap
2619 imageptr->colormap =
2620 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2621 imageptr->colors = 0;
2623 else if ( entries_ > imageptr->colors )
2625 // Re-allocate colormap
2626 imageptr->colormap=(PixelPacket *)
2627 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2630 // Initialize any new colormap entries as all black
2632 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2633 (imageptr->colormap)[i] = black;
2635 imageptr->colors = entries_;
2637 size_t Magick::Image::colorMapSize ( void )
2639 const MagickCore::Image* imageptr = constImage();
2641 if ( !imageptr->colormap )
2642 throwExceptionExplicit( OptionError,
2643 "Image does not contain a colormap");
2645 return imageptr->colors;
2649 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2652 if ( image()->colorspace == colorSpace_ )
2657 if ( colorSpace_ != RGBColorspace &&
2658 colorSpace_ != sRGBColorspace &&
2659 colorSpace_ != TransparentColorspace &&
2660 colorSpace_ != GRAYColorspace )
2662 if (image()->colorspace != RGBColorspace &&
2663 image()->colorspace != sRGBColorspace &&
2664 image()->colorspace != TransparentColorspace &&
2665 image()->colorspace != GRAYColorspace)
2667 /* Transform to RGB colorspace as intermediate step */
2668 TransformRGBImage( image(), image()->colorspace );
2669 throwImageException();
2671 /* Transform to final non-RGB colorspace */
2672 RGBTransformImage( image(), colorSpace_ );
2673 throwImageException();
2677 if ( colorSpace_ == RGBColorspace ||
2678 colorSpace_ == sRGBColorspace ||
2679 colorSpace_ == TransparentColorspace ||
2680 colorSpace_ == GRAYColorspace )
2682 /* Transform to a RGB-type colorspace */
2683 TransformRGBImage( image(), image()->colorspace );
2684 throwImageException();
2688 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2690 return constImage()->colorspace;
2693 // Set image colorspace type.
2694 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2697 options()->colorspaceType( colorSpace_ );
2699 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2701 return constOptions()->colorspaceType();
2706 void Magick::Image::comment ( const std::string &comment_ )
2709 SetImageProperty( image(), "Comment", NULL );
2710 if ( comment_.length() > 0 )
2711 SetImageProperty( image(), "Comment", comment_.c_str() );
2712 throwImageException();
2714 std::string Magick::Image::comment ( void ) const
2716 const char *value = GetImageProperty( constImage(), "Comment" );
2719 return std::string( value );
2721 return std::string(); // Intentionally no exception
2724 // Composition operator to be used when composition is implicitly used
2725 // (such as for image flattening).
2726 void Magick::Image::compose (const CompositeOperator compose_)
2728 image()->compose=compose_;
2731 Magick::CompositeOperator Magick::Image::compose ( void ) const
2733 return constImage()->compose;
2736 // Compression algorithm
2737 void Magick::Image::compressType ( const CompressionType compressType_ )
2740 image()->compression = compressType_;
2741 options()->compressType( compressType_ );
2743 Magick::CompressionType Magick::Image::compressType ( void ) const
2745 return constImage()->compression;
2748 // Enable printing of debug messages from ImageMagick
2749 void Magick::Image::debug ( const bool flag_ )
2752 options()->debug( flag_ );
2754 bool Magick::Image::debug ( void ) const
2756 return constOptions()->debug();
2759 // Tagged image format define (set/access coder-specific option) The
2760 // magick_ option specifies the coder the define applies to. The key_
2761 // option provides the key specific to that coder. The value_ option
2762 // provides the value to set (if any). See the defineSet() method if the
2763 // key must be removed entirely.
2764 void Magick::Image::defineValue ( const std::string &magick_,
2765 const std::string &key_,
2766 const std::string &value_ )
2769 std::string format = magick_ + ":" + key_;
2770 std::string option = value_;
2771 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2773 std::string Magick::Image::defineValue ( const std::string &magick_,
2774 const std::string &key_ ) const
2776 std::string definition = magick_ + ":" + key_;
2777 const char *option =
2778 GetImageOption ( constImageInfo(), definition.c_str() );
2780 return std::string( option );
2781 return std::string( );
2784 // Tagged image format define. Similar to the defineValue() method
2785 // except that passing the flag_ value 'true' creates a value-less
2786 // define with that format and key. Passing the flag_ value 'false'
2787 // removes any existing matching definition. The method returns 'true'
2788 // if a matching key exists, and 'false' if no matching key exists.
2789 void Magick::Image::defineSet ( const std::string &magick_,
2790 const std::string &key_,
2794 std::string definition = magick_ + ":" + key_;
2797 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2801 DeleteImageOption( imageInfo(), definition.c_str() );
2804 bool Magick::Image::defineSet ( const std::string &magick_,
2805 const std::string &key_ ) const
2807 std::string key = magick_ + ":" + key_;
2808 const char *option =
2809 GetImageOption ( constImageInfo(), key.c_str() );
2816 void Magick::Image::density ( const Geometry &density_ )
2819 options()->density( density_ );
2820 if ( density_.isValid() )
2822 image()->x_resolution = density_.width();
2823 if ( density_.height() != 0 )
2825 image()->y_resolution = density_.height();
2829 image()->y_resolution = density_.width();
2835 image()->x_resolution = 0;
2836 image()->y_resolution = 0;
2839 Magick::Geometry Magick::Image::density ( void ) const
2843 ssize_t x_resolution=72;
2844 ssize_t y_resolution=72;
2846 if (constImage()->x_resolution > 0.0)
2847 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
2849 if (constImage()->y_resolution > 0.0)
2850 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
2852 return Geometry(x_resolution,y_resolution);
2855 return constOptions()->density( );
2858 // Image depth (bits allocated to red/green/blue components)
2859 void Magick::Image::depth ( const size_t depth_ )
2861 size_t depth = depth_;
2863 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2864 depth=MAGICKCORE_QUANTUM_DEPTH;
2867 image()->depth=depth;
2868 options()->depth( depth );
2870 size_t Magick::Image::depth ( void ) const
2872 return constImage()->depth;
2875 std::string Magick::Image::directory ( void ) const
2877 if ( constImage()->directory )
2878 return std::string( constImage()->directory );
2880 throwExceptionExplicit( CorruptImageWarning,
2881 "Image does not contain a directory");
2883 return std::string();
2886 // Endianness (little like Intel or big like SPARC) for image
2887 // formats which support endian-specific options.
2888 void Magick::Image::endian ( const Magick::EndianType endian_ )
2891 options()->endian( endian_ );
2892 image()->endian = endian_;
2894 Magick::EndianType Magick::Image::endian ( void ) const
2896 return constImage()->endian;
2899 // EXIF profile (BLOB)
2900 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2903 if ( exifProfile_.data() != 0 )
2905 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2906 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2907 (void) SetImageProfile( image(), "exif", exif_profile);
2908 exif_profile =DestroyStringInfo( exif_profile );
2911 Magick::Blob Magick::Image::exifProfile( void ) const
2913 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2914 if ( exif_profile == (StringInfo *) NULL)
2915 return Blob( 0, 0 );
2916 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2920 void Magick::Image::fileName ( const std::string &fileName_ )
2924 fileName_.copy( image()->filename,
2925 sizeof(image()->filename) - 1 );
2926 image()->filename[ fileName_.length() ] = 0; // Null terminate
2928 options()->fileName( fileName_ );
2931 std::string Magick::Image::fileName ( void ) const
2933 return constOptions()->fileName( );
2937 off_t Magick::Image::fileSize ( void ) const
2939 return (off_t) GetBlobSize( constImage() );
2942 // Color to use when drawing inside an object
2943 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2946 options()->fillColor(fillColor_);
2948 Magick::Color Magick::Image::fillColor ( void ) const
2950 return constOptions()->fillColor();
2953 // Rule to use when filling drawn objects
2954 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2957 options()->fillRule(fillRule_);
2959 Magick::FillRule Magick::Image::fillRule ( void ) const
2961 return constOptions()->fillRule();
2964 // Pattern to use while filling drawn objects.
2965 void Magick::Image::fillPattern ( const Image &fillPattern_ )
2968 if(fillPattern_.isValid())
2969 options()->fillPattern( fillPattern_.constImage() );
2971 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
2973 Magick::Image Magick::Image::fillPattern ( void ) const
2975 // FIXME: This is inordinately innefficient
2978 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
2982 ExceptionInfo exceptionInfo;
2983 GetExceptionInfo( &exceptionInfo );
2984 MagickCore::Image* image =
2985 CloneImage( tmpTexture,
2988 MagickTrue, // orphan
2990 texture.replaceImage( image );
2991 throwException( exceptionInfo );
2992 (void) DestroyExceptionInfo( &exceptionInfo );
2997 // Filter used by zoom
2998 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3001 image()->filter = filterType_;
3003 Magick::FilterTypes Magick::Image::filterType ( void ) const
3005 return constImage()->filter;
3009 void Magick::Image::font ( const std::string &font_ )
3012 options()->font( font_ );
3014 std::string Magick::Image::font ( void ) const
3016 return constOptions()->font( );
3020 void Magick::Image::fontPointsize ( const double pointSize_ )
3023 options()->fontPointsize( pointSize_ );
3025 double Magick::Image::fontPointsize ( void ) const
3027 return constOptions()->fontPointsize( );
3030 // Font type metrics
3031 void Magick::Image::fontTypeMetrics( const std::string &text_,
3032 TypeMetric *metrics )
3034 DrawInfo *drawInfo = options()->drawInfo();
3035 drawInfo->text = const_cast<char *>(text_.c_str());
3036 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3040 // Image format string
3041 std::string Magick::Image::format ( void ) const
3043 ExceptionInfo exceptionInfo;
3044 GetExceptionInfo( &exceptionInfo );
3045 const MagickInfo * magick_info
3046 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3047 throwException( exceptionInfo );
3048 (void) DestroyExceptionInfo( &exceptionInfo );
3050 if (( magick_info != 0 ) &&
3051 ( *magick_info->description != '\0' ))
3052 return std::string(magick_info->description);
3054 throwExceptionExplicit( CorruptImageWarning,
3055 "Unrecognized image magick type" );
3056 return std::string();
3060 double Magick::Image::gamma ( void ) const
3062 return constImage()->gamma;
3065 Magick::Geometry Magick::Image::geometry ( void ) const
3067 if ( constImage()->geometry )
3069 return Geometry(constImage()->geometry);
3072 throwExceptionExplicit( OptionWarning,
3073 "Image does not contain a geometry");
3078 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3081 image()->dispose = (DisposeType) disposeMethod_;
3083 size_t Magick::Image::gifDisposeMethod ( void ) const
3085 // FIXME: It would be better to return an enumeration
3086 return constImage()->dispose;
3089 // ICC ICM color profile (BLOB)
3090 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3092 profile("icm",colorProfile_);
3094 Magick::Blob Magick::Image::iccColorProfile( void ) const
3096 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3097 if ( color_profile == (StringInfo *) NULL)
3098 return Blob( 0, 0 );
3099 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3102 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3105 image()->interlace = interlace_;
3106 options()->interlaceType ( interlace_ );
3108 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3110 return constImage()->interlace;
3113 // IPTC profile (BLOB)
3114 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3117 if ( iptcProfile_.data() != 0 )
3119 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3120 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3121 (void) SetImageProfile( image(), "iptc", iptc_profile);
3122 iptc_profile =DestroyStringInfo( iptc_profile );
3125 Magick::Blob Magick::Image::iptcProfile( void ) const
3127 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3128 if ( iptc_profile == (StringInfo *) NULL)
3129 return Blob( 0, 0 );
3130 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3133 // Does object contain valid image?
3134 void Magick::Image::isValid ( const bool isValid_ )
3139 _imgRef = new ImageRef;
3141 else if ( !isValid() )
3143 // Construct with single-pixel black image to make
3144 // image valid. This is an obvious hack.
3145 size( Geometry(1,1) );
3146 read( "xc:#000000" );
3150 bool Magick::Image::isValid ( void ) const
3152 if ( rows() && columns() )
3159 void Magick::Image::label ( const std::string &label_ )
3162 SetImageProperty ( image(), "Label", NULL );
3163 if ( label_.length() > 0 )
3164 SetImageProperty ( image(), "Label", label_.c_str() );
3165 throwImageException();
3167 std::string Magick::Image::label ( void ) const
3169 const char *value = GetImageProperty( constImage(), "Label" );
3172 return std::string( value );
3174 return std::string();
3177 void Magick::Image::magick ( const std::string &magick_ )
3181 magick_.copy( image()->magick,
3182 sizeof(image()->magick) - 1 );
3183 image()->magick[ magick_.length() ] = 0;
3185 options()->magick( magick_ );
3187 std::string Magick::Image::magick ( void ) const
3189 if ( *(constImage()->magick) != '\0' )
3190 return std::string(constImage()->magick);
3192 return constOptions()->magick( );
3195 void Magick::Image::matte ( const bool matteFlag_ )
3199 // If matte channel is requested, but image doesn't already have a
3200 // matte channel, then create an opaque matte channel. Likewise, if
3201 // the image already has a matte channel but a matte channel is not
3202 // desired, then set the matte channel to opaque.
3203 if ((matteFlag_ && !constImage()->matte) ||
3204 (constImage()->matte && !matteFlag_))
3205 SetImageOpacity(image(),OpaqueAlpha);
3207 image()->matte = (MagickBooleanType) matteFlag_;
3209 bool Magick::Image::matte ( void ) const
3211 if ( constImage()->matte )
3217 void Magick::Image::matteColor ( const Color &matteColor_ )
3221 if ( matteColor_.isValid() )
3223 image()->matte_color = matteColor_;
3224 options()->matteColor( matteColor_ );
3228 // Set to default matte color
3229 Color tmpColor( "#BDBDBD" );
3230 image()->matte_color = tmpColor;
3231 options()->matteColor( tmpColor );
3234 Magick::Color Magick::Image::matteColor ( void ) const
3236 return Color( constImage()->matte_color.red,
3237 constImage()->matte_color.green,
3238 constImage()->matte_color.blue );
3241 double Magick::Image::meanErrorPerPixel ( void ) const
3243 return(constImage()->error.mean_error_per_pixel);
3246 // Image modulus depth (minimum number of bits required to support
3247 // red/green/blue components without loss of accuracy)
3248 void Magick::Image::modulusDepth ( const size_t depth_ )
3251 SetImageDepth( image(), depth_ );
3252 options()->depth( depth_ );
3254 size_t Magick::Image::modulusDepth ( void ) const
3256 ExceptionInfo exceptionInfo;
3257 GetExceptionInfo( &exceptionInfo );
3258 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3259 throwException( exceptionInfo );
3260 (void) DestroyExceptionInfo( &exceptionInfo );
3264 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3267 options()->monochrome( monochromeFlag_ );
3269 bool Magick::Image::monochrome ( void ) const
3271 return constOptions()->monochrome( );
3274 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3276 if ( constImage()->montage )
3277 return Magick::Geometry(constImage()->montage);
3279 throwExceptionExplicit( CorruptImageWarning,
3280 "Image does not contain a montage" );
3282 return Magick::Geometry();
3285 double Magick::Image::normalizedMaxError ( void ) const
3287 return(constImage()->error.normalized_maximum_error);
3290 double Magick::Image::normalizedMeanError ( void ) const
3292 return constImage()->error.normalized_mean_error;
3295 // Image orientation
3296 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3299 image()->orientation = orientation_;
3301 Magick::OrientationType Magick::Image::orientation ( void ) const
3303 return constImage()->orientation;
3306 void Magick::Image::penColor ( const Color &penColor_ )
3309 options()->fillColor(penColor_);
3310 options()->strokeColor(penColor_);
3312 Magick::Color Magick::Image::penColor ( void ) const
3314 return constOptions()->fillColor();
3317 void Magick::Image::penTexture ( const Image &penTexture_ )
3320 if(penTexture_.isValid())
3321 options()->fillPattern( penTexture_.constImage() );
3323 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3326 Magick::Image Magick::Image::penTexture ( void ) const
3328 // FIXME: This is inordinately innefficient
3331 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3335 ExceptionInfo exceptionInfo;
3336 GetExceptionInfo( &exceptionInfo );
3337 MagickCore::Image* image =
3338 CloneImage( tmpTexture,
3341 MagickTrue, // orphan
3343 texture.replaceImage( image );
3344 throwException( exceptionInfo );
3345 (void) DestroyExceptionInfo( &exceptionInfo );
3350 // Set the color of a pixel.
3351 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3352 const Color &color_ )
3354 // Test arguments to ensure they are within the image.
3355 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3356 throwExceptionExplicit( OptionError,
3357 "Access outside of image boundary" );
3361 // Set image to DirectClass
3362 classType( DirectClass );
3365 Pixels pixels(*this);
3367 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3368 PixelPacket packet = color_;
3369 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
3370 // Tell ImageMagick that pixels have been updated
3376 // Get the color of a pixel
3377 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3378 const ssize_t y_ ) const
3380 ClassType storage_class;
3381 storage_class = classType();
3383 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3387 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3388 return Color( packet );
3391 return Color(); // invalid
3394 // Preferred size and location of an image canvas.
3395 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3398 options()->page( pageSize_ );
3399 image()->page = pageSize_;
3401 Magick::Geometry Magick::Image::page ( void ) const
3403 return Geometry( constImage()->page.width,
3404 constImage()->page.height,
3405 AbsoluteValue(constImage()->page.x),
3406 AbsoluteValue(constImage()->page.y),
3407 constImage()->page.x < 0 ? true : false,
3408 constImage()->page.y < 0 ? true : false);
3411 // Add a named profile to an image or remove a named profile by
3412 // passing an empty Blob (use default Blob constructor).
3414 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3415 void Magick::Image::profile( const std::string name_,
3416 const Magick::Blob &profile_ )
3419 ssize_t result = ProfileImage( image(), name_.c_str(),
3420 (unsigned char *)profile_.data(),
3421 profile_.length(), MagickTrue);
3424 throwImageException();
3427 // Retrieve a named profile from the image.
3429 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3430 // an existing generic profile name.
3431 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3433 const MagickCore::Image* image = constImage();
3435 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3437 if ( profile != (StringInfo *) NULL)
3438 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3441 Image temp_image = *this;
3442 temp_image.write( &blob, name_ );
3446 void Magick::Image::quality ( const size_t quality_ )
3449 image()->quality = quality_;
3450 options()->quality( quality_ );
3452 size_t Magick::Image::quality ( void ) const
3454 return constImage()->quality;
3457 void Magick::Image::quantizeColors ( const size_t colors_ )
3460 options()->quantizeColors( colors_ );
3462 size_t Magick::Image::quantizeColors ( void ) const
3464 return constOptions()->quantizeColors( );
3467 void Magick::Image::quantizeColorSpace
3468 ( const Magick::ColorspaceType colorSpace_ )
3471 options()->quantizeColorSpace( colorSpace_ );
3473 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3475 return constOptions()->quantizeColorSpace( );
3478 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3481 options()->quantizeDither( ditherFlag_ );
3483 bool Magick::Image::quantizeDither ( void ) const
3485 return constOptions()->quantizeDither( );
3488 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3491 options()->quantizeTreeDepth( treeDepth_ );
3493 size_t Magick::Image::quantizeTreeDepth ( void ) const
3495 return constOptions()->quantizeTreeDepth( );
3498 void Magick::Image::renderingIntent
3499 ( const Magick::RenderingIntent renderingIntent_ )
3502 image()->rendering_intent = renderingIntent_;
3504 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3506 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3509 void Magick::Image::resolutionUnits
3510 ( const Magick::ResolutionType resolutionUnits_ )
3513 image()->units = resolutionUnits_;
3514 options()->resolutionUnits( resolutionUnits_ );
3516 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3518 return constOptions()->resolutionUnits( );
3521 void Magick::Image::scene ( const size_t scene_ )
3524 image()->scene = scene_;
3526 size_t Magick::Image::scene ( void ) const
3528 return constImage()->scene;
3531 std::string Magick::Image::signature ( const bool force_ ) const
3533 Lock( &_imgRef->_mutexLock );
3535 // Re-calculate image signature if necessary
3537 !GetImageProperty(constImage(), "Signature") ||
3538 constImage()->taint )
3540 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3543 const char *property = GetImageProperty(constImage(), "Signature");
3545 return std::string( property );
3548 void Magick::Image::size ( const Geometry &geometry_ )
3551 options()->size( geometry_ );
3552 image()->rows = geometry_.height();
3553 image()->columns = geometry_.width();
3555 Magick::Geometry Magick::Image::size ( void ) const
3557 return Magick::Geometry( constImage()->columns, constImage()->rows );
3561 void Magick::Image::splice( const Geometry &geometry_ )
3563 RectangleInfo spliceInfo = geometry_;
3564 ExceptionInfo exceptionInfo;
3565 GetExceptionInfo( &exceptionInfo );
3566 MagickCore::Image* newImage =
3567 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3568 replaceImage( newImage );
3569 throwException( exceptionInfo );
3570 (void) DestroyExceptionInfo( &exceptionInfo );
3573 // Obtain image statistics. Statistics are normalized to the range of
3574 // 0.0 to 1.0 and are output to the specified ImageStatistics
3576 void Magick::Image::statistics ( ImageStatistics *statistics ) const
3582 ExceptionInfo exceptionInfo;
3583 GetExceptionInfo( &exceptionInfo );
3584 (void) GetImageChannelRange(constImage(),RedChannel,&minimum,&maximum,
3586 statistics->red.minimum=minimum;
3587 statistics->red.maximum=maximum;
3588 (void) GetImageChannelMean(constImage(),RedChannel,
3589 &statistics->red.mean,&statistics->red.standard_deviation,&exceptionInfo);
3590 (void) GetImageChannelKurtosis(constImage(),RedChannel,
3591 &statistics->red.kurtosis,&statistics->red.skewness,&exceptionInfo);
3592 (void) GetImageChannelRange(constImage(),GreenChannel,&minimum,&maximum,
3594 statistics->green.minimum=minimum;
3595 statistics->green.maximum=maximum;
3596 (void) GetImageChannelMean(constImage(),GreenChannel,
3597 &statistics->green.mean,&statistics->green.standard_deviation,
3599 (void) GetImageChannelKurtosis(constImage(),GreenChannel,
3600 &statistics->green.kurtosis,&statistics->green.skewness,&exceptionInfo);
3601 (void) GetImageChannelRange(constImage(),BlueChannel,&minimum,&maximum,
3603 statistics->blue.minimum=minimum;
3604 statistics->blue.maximum=maximum;
3605 (void) GetImageChannelMean(constImage(),BlueChannel,
3606 &statistics->blue.mean,&statistics->blue.standard_deviation,&exceptionInfo);
3607 (void) GetImageChannelKurtosis(constImage(),BlueChannel,
3608 &statistics->blue.kurtosis,&statistics->blue.skewness,&exceptionInfo);
3609 (void) GetImageChannelRange(constImage(),OpacityChannel,&minimum,&maximum,
3611 statistics->alpha.minimum=minimum;
3612 statistics->alpha.maximum=maximum;
3613 (void) GetImageChannelMean(constImage(),OpacityChannel,
3614 &statistics->alpha.mean,&statistics->alpha.standard_deviation,
3616 (void) GetImageChannelKurtosis(constImage(),OpacityChannel,
3617 &statistics->alpha.kurtosis,&statistics->alpha.skewness,&exceptionInfo);
3618 throwException( exceptionInfo );
3619 (void) DestroyExceptionInfo( &exceptionInfo );
3622 // Strip strips an image of all profiles and comments.
3623 void Magick::Image::strip ( void )
3626 StripImage( image() );
3627 throwImageException();
3630 // enabled/disable stroke anti-aliasing
3631 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3634 options()->strokeAntiAlias(flag_);
3636 bool Magick::Image::strokeAntiAlias ( void ) const
3638 return constOptions()->strokeAntiAlias();
3641 // Color to use when drawing object outlines
3642 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3645 options()->strokeColor(strokeColor_);
3647 Magick::Color Magick::Image::strokeColor ( void ) const
3649 return constOptions()->strokeColor();
3652 // dash pattern for drawing vector objects (default one)
3653 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3656 options()->strokeDashArray( strokeDashArray_ );
3659 const double* Magick::Image::strokeDashArray ( void ) const
3661 return constOptions()->strokeDashArray( );
3664 // dash offset for drawing vector objects (default one)
3665 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3668 options()->strokeDashOffset( strokeDashOffset_ );
3671 double Magick::Image::strokeDashOffset ( void ) const
3673 return constOptions()->strokeDashOffset( );
3676 // Specify the shape to be used at the end of open subpaths when they
3677 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3679 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3682 options()->strokeLineCap( lineCap_ );
3684 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3686 return constOptions()->strokeLineCap( );
3689 // Specify the shape to be used at the corners of paths (or other
3690 // vector shapes) when they are stroked. Values of LineJoin are
3691 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3692 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3695 options()->strokeLineJoin( lineJoin_ );
3697 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3699 return constOptions()->strokeLineJoin( );
3702 // Specify miter limit. When two line segments meet at a sharp angle
3703 // and miter joins have been specified for 'lineJoin', it is possible
3704 // for the miter to extend far beyond the thickness of the line
3705 // stroking the path. The miterLimit' imposes a limit on the ratio of
3706 // the miter length to the 'lineWidth'. The default value of this
3708 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3711 options()->strokeMiterLimit( strokeMiterLimit_ );
3713 size_t Magick::Image::strokeMiterLimit ( void ) const
3715 return constOptions()->strokeMiterLimit( );
3718 // Pattern to use while stroking drawn objects.
3719 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3722 if(strokePattern_.isValid())
3723 options()->strokePattern( strokePattern_.constImage() );
3725 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3727 Magick::Image Magick::Image::strokePattern ( void ) const
3729 // FIXME: This is inordinately innefficient
3732 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3736 ExceptionInfo exceptionInfo;
3737 GetExceptionInfo( &exceptionInfo );
3738 MagickCore::Image* image =
3739 CloneImage( tmpTexture,
3742 MagickTrue, // orphan
3744 throwException( exceptionInfo );
3745 (void) DestroyExceptionInfo( &exceptionInfo );
3746 texture.replaceImage( image );
3751 // Stroke width for drawing lines, circles, ellipses, etc.
3752 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3755 options()->strokeWidth( strokeWidth_ );
3757 double Magick::Image::strokeWidth ( void ) const
3759 return constOptions()->strokeWidth( );
3762 void Magick::Image::subImage ( const size_t subImage_ )
3765 options()->subImage( subImage_ );
3767 size_t Magick::Image::subImage ( void ) const
3769 return constOptions()->subImage( );
3772 void Magick::Image::subRange ( const size_t subRange_ )
3775 options()->subRange( subRange_ );
3777 size_t Magick::Image::subRange ( void ) const
3779 return constOptions()->subRange( );
3782 // Annotation text encoding (e.g. "UTF-16")
3783 void Magick::Image::textEncoding ( const std::string &encoding_ )
3786 options()->textEncoding( encoding_ );
3788 std::string Magick::Image::textEncoding ( void ) const
3790 return constOptions()->textEncoding( );
3793 size_t Magick::Image::totalColors ( void )
3795 ExceptionInfo exceptionInfo;
3796 GetExceptionInfo( &exceptionInfo );
3797 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3798 throwException( exceptionInfo );
3799 (void) DestroyExceptionInfo( &exceptionInfo );
3803 // Origin of coordinate system to use when annotating with text or drawing
3804 void Magick::Image::transformOrigin ( const double x_, const double y_ )
3807 options()->transformOrigin( x_, y_ );
3810 // Rotation to use when annotating with text or drawing
3811 void Magick::Image::transformRotation ( const double angle_ )
3814 options()->transformRotation( angle_ );
3817 // Reset transformation parameters to default
3818 void Magick::Image::transformReset ( void )
3821 options()->transformReset();
3824 // Scale to use when annotating with text or drawing
3825 void Magick::Image::transformScale ( const double sx_, const double sy_ )
3828 options()->transformScale( sx_, sy_ );
3831 // Skew to use in X axis when annotating with text or drawing
3832 void Magick::Image::transformSkewX ( const double skewx_ )
3835 options()->transformSkewX( skewx_ );
3838 // Skew to use in Y axis when annotating with text or drawing
3839 void Magick::Image::transformSkewY ( const double skewy_ )
3842 options()->transformSkewY( skewy_ );
3845 // Image representation type
3846 Magick::ImageType Magick::Image::type ( void ) const
3849 ExceptionInfo exceptionInfo;
3850 GetExceptionInfo( &exceptionInfo );
3851 ImageType image_type = constOptions()->type();
3852 if ( image_type == UndefinedType )
3853 image_type= GetImageType( constImage(), &exceptionInfo);
3854 throwException( exceptionInfo );
3855 (void) DestroyExceptionInfo( &exceptionInfo );
3858 void Magick::Image::type ( const Magick::ImageType type_)
3861 options()->type( type_ );
3862 SetImageType( image(), type_ );
3865 void Magick::Image::verbose ( const bool verboseFlag_ )
3868 options()->verbose( verboseFlag_ );
3870 bool Magick::Image::verbose ( void ) const
3872 return constOptions()->verbose( );
3875 void Magick::Image::view ( const std::string &view_ )
3878 options()->view( view_ );
3880 std::string Magick::Image::view ( void ) const
3882 return constOptions()->view( );
3885 // Virtual pixel method
3886 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3889 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3890 options()->virtualPixelMethod( virtual_pixel_method_ );
3892 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3894 return GetImageVirtualPixelMethod( constImage() );
3897 void Magick::Image::x11Display ( const std::string &display_ )
3900 options()->x11Display( display_ );
3902 std::string Magick::Image::x11Display ( void ) const
3904 return constOptions()->x11Display( );
3907 double Magick::Image::xResolution ( void ) const
3909 return constImage()->x_resolution;
3911 double Magick::Image::yResolution ( void ) const
3913 return constImage()->y_resolution;
3917 Magick::Image::Image( const Image & image_ )
3918 : _imgRef(image_._imgRef)
3920 Lock( &_imgRef->_mutexLock );
3922 // Increase reference count
3923 ++_imgRef->_refCount;
3926 // Assignment operator
3927 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3929 if( this != &image_ )
3932 Lock( &image_._imgRef->_mutexLock );
3933 ++image_._imgRef->_refCount;
3936 bool doDelete = false;
3938 Lock( &_imgRef->_mutexLock );
3939 if ( --_imgRef->_refCount == 0 )
3945 // Delete old image reference with associated image and options.
3949 // Use new image reference
3950 _imgRef = image_._imgRef;
3956 //////////////////////////////////////////////////////////////////////
3958 // Low-level Pixel Access Routines
3960 // Also see the Pixels class, which provides support for multiple
3961 // cache views. The low-level pixel access routines in the Image
3962 // class are provided in order to support backward compatability.
3964 //////////////////////////////////////////////////////////////////////
3966 // Transfers read-only pixels from the image to the pixel cache as
3967 // defined by the specified region
3968 const Magick::Quantum* Magick::Image::getConstPixels
3969 ( const ssize_t x_, const ssize_t y_,
3970 const size_t columns_,
3971 const size_t rows_ ) const
3973 ExceptionInfo exceptionInfo;
3974 GetExceptionInfo( &exceptionInfo );
3975 const Quantum* p = (*GetVirtualPixels)( constImage(),
3979 throwException( exceptionInfo );
3980 (void) DestroyExceptionInfo( &exceptionInfo );
3984 // Obtain read-only pixel associated pixels channels
3985 const void* Magick::Image::getConstMetacontent ( void ) const
3987 const void* result = GetVirtualMetacontent( constImage() );
3990 throwImageException();
3995 // Obtain image pixel associated pixels channels
3996 void* Magick::Image::getMetacontent ( void )
3998 void* result = GetAuthenticMetacontent( image() );
4001 throwImageException();
4006 // Transfers pixels from the image to the pixel cache as defined
4007 // by the specified region. Modified pixels may be subsequently
4008 // transferred back to the image via syncPixels.
4009 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4010 const size_t columns_,
4011 const size_t rows_ )
4014 ExceptionInfo exceptionInfo;
4015 GetExceptionInfo( &exceptionInfo );
4016 Quantum* result = (*GetAuthenticPixels)( image(),
4018 columns_, rows_, &exceptionInfo );
4019 throwException( exceptionInfo );
4020 (void) DestroyExceptionInfo( &exceptionInfo );
4025 // Allocates a pixel cache region to store image pixels as defined
4026 // by the region rectangle. This area is subsequently transferred
4027 // from the pixel cache to the image via syncPixels.
4028 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4029 const size_t columns_,
4030 const size_t rows_ )
4033 ExceptionInfo exceptionInfo;
4034 GetExceptionInfo( &exceptionInfo );
4035 Quantum* result = (*QueueAuthenticPixels)( image(),
4037 columns_, rows_, &exceptionInfo );
4038 throwException( exceptionInfo );
4039 (void) DestroyExceptionInfo( &exceptionInfo );
4044 // Transfers the image cache pixels to the image.
4045 void Magick::Image::syncPixels ( void )
4047 ExceptionInfo exceptionInfo;
4048 GetExceptionInfo( &exceptionInfo );
4049 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4050 throwException( exceptionInfo );
4051 (void) DestroyExceptionInfo( &exceptionInfo );
4054 // Transfers one or more pixel components from a buffer or file
4055 // into the image pixel cache of an image.
4056 // Used to support image decoders.
4057 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4058 const unsigned char *source_ )
4063 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4064 ExceptionInfo exceptionInfo;
4065 GetExceptionInfo( &exceptionInfo );
4066 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4067 quantum_,source_, &exceptionInfo);
4068 throwException( exceptionInfo );
4069 (void) DestroyExceptionInfo( &exceptionInfo );
4070 quantum_info=DestroyQuantumInfo(quantum_info);
4073 // Transfers one or more pixel components from the image pixel
4074 // cache to a buffer or file.
4075 // Used to support image encoders.
4076 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4077 unsigned char *destination_ )
4082 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4083 ExceptionInfo exceptionInfo;
4084 GetExceptionInfo( &exceptionInfo );
4085 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4086 quantum_,destination_, &exceptionInfo);
4087 quantum_info=DestroyQuantumInfo(quantum_info);
4088 throwException( exceptionInfo );
4089 (void) DestroyExceptionInfo( &exceptionInfo );
4092 /////////////////////////////////////////////////////////////////////
4094 // No end-user methods beyond this point
4096 /////////////////////////////////////////////////////////////////////
4100 // Construct using existing image and default options
4102 Magick::Image::Image ( MagickCore::Image* image_ )
4103 : _imgRef(new ImageRef( image_))
4107 // Get Magick::Options*
4108 Magick::Options* Magick::Image::options( void )
4110 return _imgRef->options();
4112 const Magick::Options* Magick::Image::constOptions( void ) const
4114 return _imgRef->options();
4117 // Get MagickCore::Image*
4118 MagickCore::Image*& Magick::Image::image( void )
4120 return _imgRef->image();
4122 const MagickCore::Image* Magick::Image::constImage( void ) const
4124 return _imgRef->image();
4128 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4130 return _imgRef->options()->imageInfo();
4132 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4134 return _imgRef->options()->imageInfo();
4137 // Get QuantizeInfo *
4138 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4140 return _imgRef->options()->quantizeInfo();
4142 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4144 return _imgRef->options()->quantizeInfo();
4148 // Replace current image
4150 MagickCore::Image * Magick::Image::replaceImage
4151 ( MagickCore::Image* replacement_ )
4153 MagickCore::Image* image;
4156 image = replacement_;
4158 image = AcquireImage(constImageInfo());
4161 Lock( &_imgRef->_mutexLock );
4163 if ( _imgRef->_refCount == 1 )
4165 // We own the image, just replace it, and de-register
4167 _imgRef->image(image);
4171 // We don't own the image, dereference and replace with copy
4172 --_imgRef->_refCount;
4173 _imgRef = new ImageRef( image, constOptions() );
4177 return _imgRef->_image;
4181 // Prepare to modify image or image options
4182 // Replace current image and options with copy if reference count > 1
4184 void Magick::Image::modifyImage( void )
4187 Lock( &_imgRef->_mutexLock );
4188 if ( _imgRef->_refCount == 1 )
4190 // De-register image and return
4196 ExceptionInfo exceptionInfo;
4197 GetExceptionInfo( &exceptionInfo );
4198 replaceImage( CloneImage( image(),
4201 MagickTrue, // orphan
4203 throwException( exceptionInfo );
4204 (void) DestroyExceptionInfo( &exceptionInfo );
4209 // Test for an ImageMagick reported error and throw exception if one
4210 // has been reported. Secretly resets image->exception back to default
4211 // state even though this method is const.
4213 void Magick::Image::throwImageException( void ) const
4215 // Throw C++ exception while resetting Image exception to default state
4216 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4219 // Register image with image registry or obtain registration id
4220 ssize_t Magick::Image::registerId( void )
4222 Lock( &_imgRef->_mutexLock );
4223 if( _imgRef->id() < 0 )
4225 char id[MaxTextExtent];
4226 ExceptionInfo exceptionInfo;
4227 GetExceptionInfo( &exceptionInfo );
4228 _imgRef->id(_imgRef->id()+1);
4229 sprintf(id,"%.20g\n",(double) _imgRef->id());
4230 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4231 throwException( exceptionInfo );
4232 (void) DestroyExceptionInfo( &exceptionInfo );
4234 return _imgRef->id();
4237 // Unregister image from image registry
4238 void Magick::Image::unregisterId( void )
4245 // Create a local wrapper around MagickCoreTerminus
4250 void MagickPlusPlusDestroyMagick(void);
4254 void Magick::MagickPlusPlusDestroyMagick(void)
4256 if (magick_initialized)
4258 magick_initialized=false;
4259 MagickCore::MagickCoreTerminus();
4263 // C library initialization routine
4264 void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4266 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4267 if (!magick_initialized)
4268 magick_initialized=true;
4272 // Cleanup class to ensure that ImageMagick singletons are destroyed
4273 // so as to avoid any resemblence to a memory leak (which seems to
4282 MagickCleanUp( void );
4283 ~MagickCleanUp( void );
4286 // The destructor for this object is invoked when the destructors for
4287 // static objects in this translation unit are invoked.
4288 static MagickCleanUp magickCleanUpGuard;
4291 Magick::MagickCleanUp::MagickCleanUp ( void )
4293 // Don't even think about invoking InitializeMagick here!
4296 Magick::MagickCleanUp::~MagickCleanUp ( void )
4298 MagickPlusPlusDestroyMagick();