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 ChannelType channel_,
531 SetImageChannelDepth( image(), channel_, depth_);
532 throwImageException();
534 size_t Magick::Image::channelDepth ( const ChannelType channel_ )
536 size_t channel_depth;
538 ExceptionInfo exceptionInfo;
539 GetExceptionInfo( &exceptionInfo );
540 channel_depth=GetImageChannelDepth( constImage(), channel_,
542 throwException( exceptionInfo );
543 (void) DestroyExceptionInfo( &exceptionInfo );
544 return channel_depth;
548 // Charcoal-effect image
549 void Magick::Image::charcoal( const double radius_, const double sigma_ )
551 ExceptionInfo exceptionInfo;
552 GetExceptionInfo( &exceptionInfo );
553 MagickCore::Image* newImage =
554 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
555 replaceImage( newImage );
556 throwException( exceptionInfo );
557 (void) DestroyExceptionInfo( &exceptionInfo );
561 void Magick::Image::chop( const Geometry &geometry_ )
563 RectangleInfo chopInfo = geometry_;
564 ExceptionInfo exceptionInfo;
565 GetExceptionInfo( &exceptionInfo );
566 MagickCore::Image* newImage =
567 ChopImage( image(), &chopInfo, &exceptionInfo);
568 replaceImage( newImage );
569 throwException( exceptionInfo );
570 (void) DestroyExceptionInfo( &exceptionInfo );
573 // contains one or more color corrections and applies the correction to the
575 void Magick::Image::cdl ( const std::string &cdl_ )
578 (void) ColorDecisionListImage( image(), cdl_.c_str() );
579 throwImageException();
583 void Magick::Image::colorize ( const unsigned int alphaRed_,
584 const unsigned int alphaGreen_,
585 const unsigned int alphaBlue_,
586 const Color &penColor_ )
588 if ( !penColor_.isValid() )
590 throwExceptionExplicit( OptionError,
591 "Pen color argument is invalid");
594 char alpha[MaxTextExtent];
595 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
597 ExceptionInfo exceptionInfo;
598 GetExceptionInfo( &exceptionInfo );
599 MagickCore::Image* newImage =
600 ColorizeImage ( image(), alpha,
601 penColor_, &exceptionInfo );
602 replaceImage( newImage );
603 throwException( exceptionInfo );
604 (void) DestroyExceptionInfo( &exceptionInfo );
606 void Magick::Image::colorize ( const unsigned int alpha_,
607 const Color &penColor_ )
609 colorize( alpha_, alpha_, alpha_, penColor_ );
612 // Apply a color matrix to the image channels. The user supplied
613 // matrix may be of order 1 to 6 (1x1 through 6x6).
614 void Magick::Image::colorMatrix (const size_t order_,
615 const double *color_matrix_)
620 ExceptionInfo exceptionInfo;
621 GetExceptionInfo( &exceptionInfo );
622 kernel_info=AcquireKernelInfo("1");
623 kernel_info->width=order_;
624 kernel_info->height=order_;
625 kernel_info->values=(double *) color_matrix_;
626 MagickCore::Image* newImage =
627 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
628 kernel_info->values=(double *) NULL;
629 kernel_info=DestroyKernelInfo(kernel_info);
630 replaceImage( newImage );
631 throwException( exceptionInfo );
632 (void) DestroyExceptionInfo( &exceptionInfo );
635 // Compare current image with another image
636 // Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
637 // in the current image. False is returned if the images are identical.
638 bool Magick::Image::compare ( const Image &reference_ )
641 Image ref = reference_;
643 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
646 // Composite two images
647 void Magick::Image::composite ( const Image &compositeImage_,
648 const ssize_t xOffset_,
649 const ssize_t yOffset_,
650 const CompositeOperator compose_ )
652 // Image supplied as compositeImage is composited with current image and
653 // results in updating current image.
656 CompositeImage( image(),
658 compositeImage_.constImage(),
661 throwImageException();
663 void Magick::Image::composite ( const Image &compositeImage_,
664 const Geometry &offset_,
665 const CompositeOperator compose_ )
669 ssize_t x = offset_.xOff();
670 ssize_t y = offset_.yOff();
671 size_t width = columns();
672 size_t height = rows();
674 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
678 CompositeImage( image(),
680 compositeImage_.constImage(),
682 throwImageException();
684 void Magick::Image::composite ( const Image &compositeImage_,
685 const GravityType gravity_,
686 const CompositeOperator compose_ )
690 RectangleInfo geometry;
692 SetGeometry(compositeImage_.constImage(), &geometry);
693 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
695 CompositeImage( image(),
697 compositeImage_.constImage(),
698 geometry.x, geometry.y );
699 throwImageException();
703 void Magick::Image::contrast ( const size_t sharpen_ )
706 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
707 throwImageException();
710 // Convolve image. Applies a general image convolution kernel to the image.
711 // order_ represents the number of columns and rows in the filter kernel.
712 // kernel_ is an array of doubles representing the convolution kernel.
713 void Magick::Image::convolve ( const size_t order_,
714 const double *kernel_ )
716 ExceptionInfo exceptionInfo;
717 GetExceptionInfo( &exceptionInfo );
718 MagickCore::Image* newImage =
719 ConvolveImage ( image(), order_,
720 kernel_, &exceptionInfo );
721 replaceImage( newImage );
722 throwException( exceptionInfo );
723 (void) DestroyExceptionInfo( &exceptionInfo );
727 void Magick::Image::crop ( const Geometry &geometry_ )
729 RectangleInfo cropInfo = geometry_;
730 ExceptionInfo exceptionInfo;
731 GetExceptionInfo( &exceptionInfo );
732 MagickCore::Image* newImage =
736 replaceImage( newImage );
737 throwException( exceptionInfo );
738 (void) DestroyExceptionInfo( &exceptionInfo );
742 void Magick::Image::cycleColormap ( const ssize_t amount_ )
745 CycleColormapImage( image(), amount_ );
746 throwImageException();
750 void Magick::Image::despeckle ( void )
752 ExceptionInfo exceptionInfo;
753 GetExceptionInfo( &exceptionInfo );
754 MagickCore::Image* newImage =
755 DespeckleImage( image(), &exceptionInfo );
756 replaceImage( newImage );
757 throwException( exceptionInfo );
758 (void) DestroyExceptionInfo( &exceptionInfo );
762 void Magick::Image::display( void )
764 DisplayImages( imageInfo(), image() );
767 // Distort image. distorts an image using various distortion methods, by
768 // mapping color lookups of the source image to a new destination image
769 // usally of the same size as the source image, unless 'bestfit' is set to
771 void Magick::Image::distort ( const DistortImageMethod method_,
772 const size_t number_arguments_,
773 const double *arguments_,
774 const bool bestfit_ )
776 ExceptionInfo exceptionInfo;
777 GetExceptionInfo( &exceptionInfo );
778 MagickCore::Image* newImage = DistortImage ( image(), method_,
779 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
781 replaceImage( newImage );
782 throwException( exceptionInfo );
783 (void) DestroyExceptionInfo( &exceptionInfo );
786 // Draw on image using single drawable
787 void Magick::Image::draw ( const Magick::Drawable &drawable_ )
791 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
795 drawable_.operator()(wand);
797 if( constImage()->exception.severity == UndefinedException)
800 wand=DestroyDrawingWand(wand);
803 throwImageException();
806 // Draw on image using a drawable list
807 void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
811 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
815 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
816 p != drawable_.end(); p++ )
819 if( constImage()->exception.severity != UndefinedException)
823 if( constImage()->exception.severity == UndefinedException)
826 wand=DestroyDrawingWand(wand);
829 throwImageException();
832 // Hilight edges in image
833 void Magick::Image::edge ( const double radius_ )
835 ExceptionInfo exceptionInfo;
836 GetExceptionInfo( &exceptionInfo );
837 MagickCore::Image* newImage =
838 EdgeImage( image(), radius_, &exceptionInfo );
839 replaceImage( newImage );
840 throwException( exceptionInfo );
841 (void) DestroyExceptionInfo( &exceptionInfo );
844 // Emboss image (hilight edges)
845 void Magick::Image::emboss ( const double radius_, const double sigma_ )
847 ExceptionInfo exceptionInfo;
848 GetExceptionInfo( &exceptionInfo );
849 MagickCore::Image* newImage =
850 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
851 replaceImage( newImage );
852 throwException( exceptionInfo );
853 (void) DestroyExceptionInfo( &exceptionInfo );
856 // Enhance image (minimize noise)
857 void Magick::Image::enhance ( void )
859 ExceptionInfo exceptionInfo;
860 GetExceptionInfo( &exceptionInfo );
861 MagickCore::Image* newImage =
862 EnhanceImage( image(), &exceptionInfo );
863 replaceImage( newImage );
864 throwException( exceptionInfo );
865 (void) DestroyExceptionInfo( &exceptionInfo );
868 // Equalize image (histogram equalization)
869 void Magick::Image::equalize ( void )
872 EqualizeImage( image() );
873 throwImageException();
876 // Erase image to current "background color"
877 void Magick::Image::erase ( void )
880 SetImageBackgroundColor( image() );
881 throwImageException();
884 // Extends image as defined by the geometry.
886 void Magick::Image::extent ( const Geometry &geometry_ )
888 RectangleInfo extentInfo = geometry_;
890 ExceptionInfo exceptionInfo;
891 GetExceptionInfo( &exceptionInfo );
892 MagickCore::Image* newImage =
893 ExtentImage ( image(), &extentInfo, &exceptionInfo );
894 replaceImage( newImage );
895 throwException( exceptionInfo );
896 (void) DestroyExceptionInfo( &exceptionInfo );
898 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
900 backgroundColor ( backgroundColor_ );
901 extent ( geometry_ );
903 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
905 image()->gravity = gravity_;
906 extent ( geometry_ );
908 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
910 image()->gravity = gravity_;
911 backgroundColor ( backgroundColor_ );
912 extent ( geometry_ );
915 // Flip image (reflect each scanline in the vertical direction)
916 void Magick::Image::flip ( void )
918 ExceptionInfo exceptionInfo;
919 GetExceptionInfo( &exceptionInfo );
920 MagickCore::Image* newImage =
921 FlipImage( image(), &exceptionInfo );
922 replaceImage( newImage );
923 throwException( exceptionInfo );
924 (void) DestroyExceptionInfo( &exceptionInfo );
927 // Flood-fill color across pixels that match the color of the
928 // target pixel and are neighbors of the target pixel.
929 // Uses current fuzz setting when determining color match.
930 void Magick::Image::floodFillColor( const ssize_t x_,
932 const Magick::Color &fillColor_ )
934 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
936 void Magick::Image::floodFillColor( const Geometry &point_,
937 const Magick::Color &fillColor_ )
939 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
942 // Flood-fill color across pixels starting at target-pixel and
943 // stopping at pixels matching specified border color.
944 // Uses current fuzz setting when determining color match.
945 void Magick::Image::floodFillColor( const ssize_t x_,
947 const Magick::Color &fillColor_,
948 const Magick::Color &borderColor_ )
950 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
953 void Magick::Image::floodFillColor( const Geometry &point_,
954 const Magick::Color &fillColor_,
955 const Magick::Color &borderColor_ )
957 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
961 // Floodfill pixels matching color (within fuzz factor) of target
962 // pixel(x,y) with replacement alpha value using method.
963 void Magick::Image::floodFillOpacity( const ssize_t x_,
965 const unsigned int alpha_,
966 const PaintMethod method_ )
970 GetPixelInfo(image(),&target);
971 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
972 target.red=pixel.red;
973 target.green=pixel.green;
974 target.blue=pixel.blue;
976 FloodfillPaintImage ( image(),
978 options()->drawInfo(), // const DrawInfo *draw_info
980 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
981 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
982 throwImageException();
985 // Flood-fill texture across pixels that match the color of the
986 // target pixel and are neighbors of the target pixel.
987 // Uses current fuzz setting when determining color match.
988 void Magick::Image::floodFillTexture( const ssize_t x_,
990 const Magick::Image &texture_ )
994 // Set drawing pattern
995 options()->fillPattern(texture_.constImage());
998 Pixels pixels(*this);
1000 Quantum *p = pixels.get(x_, y_, 1, 1 );
1002 GetPixelInfo(constImage(),&target);
1003 target.red=GetPixelRed(constImage(),p);
1004 target.green=GetPixelGreen(constImage(),p);
1005 target.blue=GetPixelBlue(constImage(),p);
1007 FloodfillPaintImage ( image(), // Image *image
1009 options()->drawInfo(), // const DrawInfo *draw_info
1010 &target, // const MagickPacket target
1011 static_cast<ssize_t>(x_), // const ssize_t x_offset
1012 static_cast<ssize_t>(y_), // const ssize_t y_offset
1013 MagickFalse // const PaintMethod method
1016 throwImageException();
1018 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1019 const Magick::Image &texture_ )
1021 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1024 // Flood-fill texture across pixels starting at target-pixel and
1025 // stopping at pixels matching specified border color.
1026 // Uses current fuzz setting when determining color match.
1027 void Magick::Image::floodFillTexture( const ssize_t x_,
1029 const Magick::Image &texture_,
1030 const Magick::Color &borderColor_ )
1034 // Set drawing fill pattern
1035 options()->fillPattern(texture_.constImage());
1038 GetPixelInfo(constImage(),&target);
1039 target.red=static_cast<PixelPacket>(borderColor_).red;
1040 target.green=static_cast<PixelPacket>(borderColor_).green;
1041 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1042 FloodfillPaintImage ( image(),
1044 options()->drawInfo(),
1046 static_cast<ssize_t>(x_),
1047 static_cast<ssize_t>(y_),
1050 throwImageException();
1052 void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1053 const Magick::Image &texture_,
1054 const Magick::Color &borderColor_ )
1056 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1059 // Flop image (reflect each scanline in the horizontal direction)
1060 void Magick::Image::flop ( void )
1062 ExceptionInfo exceptionInfo;
1063 GetExceptionInfo( &exceptionInfo );
1064 MagickCore::Image* newImage =
1065 FlopImage( image(), &exceptionInfo );
1066 replaceImage( newImage );
1067 throwException( exceptionInfo );
1068 (void) DestroyExceptionInfo( &exceptionInfo );
1072 void Magick::Image::frame ( const Geometry &geometry_ )
1076 info.x = static_cast<ssize_t>(geometry_.width());
1077 info.y = static_cast<ssize_t>(geometry_.height());
1078 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1079 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1080 info.outer_bevel = geometry_.xOff();
1081 info.inner_bevel = geometry_.yOff();
1083 ExceptionInfo exceptionInfo;
1084 GetExceptionInfo( &exceptionInfo );
1085 MagickCore::Image* newImage =
1086 FrameImage( image(), &info, &exceptionInfo );
1087 replaceImage( newImage );
1088 throwException( exceptionInfo );
1089 (void) DestroyExceptionInfo( &exceptionInfo );
1091 void Magick::Image::frame ( const size_t width_,
1092 const size_t height_,
1093 const ssize_t outerBevel_, const ssize_t innerBevel_ )
1096 info.x = static_cast<ssize_t>(width_);
1097 info.y = static_cast<ssize_t>(height_);
1098 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1099 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1100 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1101 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
1103 ExceptionInfo exceptionInfo;
1104 GetExceptionInfo( &exceptionInfo );
1105 MagickCore::Image* newImage =
1106 FrameImage( image(), &info, &exceptionInfo );
1107 replaceImage( newImage );
1108 throwException( exceptionInfo );
1109 (void) DestroyExceptionInfo( &exceptionInfo );
1112 // Fx image. Applies a mathematical expression to the image.
1113 void Magick::Image::fx ( const std::string expression )
1115 ExceptionInfo exceptionInfo;
1116 GetExceptionInfo( &exceptionInfo );
1117 MagickCore::Image* newImage =
1118 FxImageChannel ( image(), DefaultChannels, expression.c_str(), &exceptionInfo );
1119 replaceImage( newImage );
1120 throwException( exceptionInfo );
1121 (void) DestroyExceptionInfo( &exceptionInfo );
1123 void Magick::Image::fx ( const std::string expression,
1124 const Magick::ChannelType channel )
1126 ExceptionInfo exceptionInfo;
1127 GetExceptionInfo( &exceptionInfo );
1128 MagickCore::Image* newImage =
1129 FxImageChannel ( image(), channel, expression.c_str(), &exceptionInfo );
1130 replaceImage( newImage );
1131 throwException( exceptionInfo );
1132 (void) DestroyExceptionInfo( &exceptionInfo );
1135 // Gamma correct image
1136 void Magick::Image::gamma ( const double gamma_ )
1138 char gamma[MaxTextExtent + 1];
1139 FormatLocaleString( gamma, MaxTextExtent, "%3.6f", gamma_);
1142 GammaImage ( image(), gamma );
1145 void Magick::Image::gamma ( const double gammaRed_,
1146 const double gammaGreen_,
1147 const double gammaBlue_ )
1149 char gamma[MaxTextExtent + 1];
1150 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
1151 gammaRed_, gammaGreen_, gammaBlue_);
1154 GammaImage ( image(), gamma );
1155 throwImageException();
1158 // Gaussian blur image
1159 // The number of neighbor pixels to be included in the convolution
1160 // mask is specified by 'width_'. The standard deviation of the
1161 // gaussian bell curve is specified by 'sigma_'.
1162 void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1164 ExceptionInfo exceptionInfo;
1165 GetExceptionInfo( &exceptionInfo );
1166 MagickCore::Image* newImage =
1167 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1168 replaceImage( newImage );
1169 throwException( exceptionInfo );
1170 (void) DestroyExceptionInfo( &exceptionInfo );
1173 void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1174 const double width_,
1175 const double sigma_ )
1177 ExceptionInfo exceptionInfo;
1178 GetExceptionInfo( &exceptionInfo );
1179 MagickCore::Image* newImage =
1180 GaussianBlurImageChannel( image(), channel_, width_, sigma_, &exceptionInfo );
1181 replaceImage( newImage );
1182 throwException( exceptionInfo );
1183 (void) DestroyExceptionInfo( &exceptionInfo );
1186 // Apply a color lookup table (Hald CLUT) to the image.
1187 void Magick::Image::haldClut ( const Image &clutImage_ )
1190 (void) HaldClutImage( image(), clutImage_.constImage() );
1191 throwImageException();
1195 void Magick::Image::implode ( const double factor_ )
1197 ExceptionInfo exceptionInfo;
1198 GetExceptionInfo( &exceptionInfo );
1199 MagickCore::Image* newImage =
1200 ImplodeImage( image(), factor_, &exceptionInfo );
1201 replaceImage( newImage );
1202 throwException( exceptionInfo );
1203 (void) DestroyExceptionInfo( &exceptionInfo );
1206 // implements the inverse discrete Fourier transform (IFT) of the image either
1207 // as a magnitude / phase or real / imaginary image pair.
1208 void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1210 ExceptionInfo exceptionInfo;
1211 GetExceptionInfo( &exceptionInfo );
1212 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1213 phase_.constImage(), MagickTrue, &exceptionInfo);
1214 replaceImage( newImage );
1215 throwException( exceptionInfo );
1216 (void) DestroyExceptionInfo( &exceptionInfo );
1218 void Magick::Image::inverseFourierTransform ( const Image &phase_,
1219 const bool magnitude_ )
1221 ExceptionInfo exceptionInfo;
1222 GetExceptionInfo( &exceptionInfo );
1223 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1224 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1226 replaceImage( newImage );
1227 throwException( exceptionInfo );
1228 (void) DestroyExceptionInfo( &exceptionInfo );
1231 // Level image. Adjust the levels of the image by scaling the colors
1232 // falling between specified white and black points to the full
1233 // available quantum range. The parameters provided represent the
1234 // black, mid (gamma), and white points. The black point specifies
1235 // the darkest color in the image. Colors darker than the black point
1236 // are set to zero. Mid point (gamma) specifies a gamma correction to
1237 // apply to the image. White point specifies the lightest color in the
1238 // image. Colors brighter than the white point are set to the maximum
1239 // quantum value. The black and white point have the valid range 0 to
1240 // QuantumRange while gamma has a useful range of 0 to ten.
1241 void Magick::Image::level ( const double black_point,
1242 const double white_point,
1243 const double gamma )
1246 char levels[MaxTextExtent];
1247 FormatLocaleString( levels, MaxTextExtent, "%g,%g,%g",black_point,white_point,gamma);
1248 (void) LevelImage( image(), levels );
1249 throwImageException();
1252 // Level image channel. Adjust the levels of the image channel by
1253 // scaling the values falling between specified white and black points
1254 // to the full available quantum range. The parameters provided
1255 // represent the black, mid (gamma), and white points. The black
1256 // point specifies the darkest color in the image. Colors darker than
1257 // the black point are set to zero. Mid point (gamma) specifies a
1258 // gamma correction to apply to the image. White point specifies the
1259 // lightest color in the image. Colors brighter than the white point
1260 // are set to the maximum quantum value. The black and white point
1261 // have the valid range 0 to QuantumRange while gamma has a useful range of
1263 void Magick::Image::levelChannel ( const Magick::ChannelType channel,
1264 const double black_point,
1265 const double white_point,
1266 const double gamma )
1269 (void) LevelImageChannel( image(), channel, black_point, white_point,
1271 throwImageException();
1274 // Magnify image by integral size
1275 void Magick::Image::magnify ( void )
1277 ExceptionInfo exceptionInfo;
1278 GetExceptionInfo( &exceptionInfo );
1279 MagickCore::Image* newImage =
1280 MagnifyImage( image(), &exceptionInfo );
1281 replaceImage( newImage );
1282 throwException( exceptionInfo );
1283 (void) DestroyExceptionInfo( &exceptionInfo );
1286 // Remap image colors with closest color from reference image
1287 void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1290 options()->quantizeDither( dither_ );
1291 RemapImage ( options()->quantizeInfo(), image(),
1292 mapImage_.constImage());
1293 throwImageException();
1295 // Floodfill designated area with replacement alpha value
1296 void Magick::Image::matteFloodfill ( const Color &target_ ,
1297 const unsigned int alpha_,
1298 const ssize_t x_, const ssize_t y_,
1299 const Magick::PaintMethod method_ )
1303 GetPixelInfo(constImage(),&target);
1304 target.red=static_cast<PixelPacket>(target_).red;
1305 target.green=static_cast<PixelPacket>(target_).green;
1306 target.blue=static_cast<PixelPacket>(target_).blue;
1307 target.alpha=alpha_;
1308 FloodfillPaintImage ( image(), OpacityChannel, options()->drawInfo(), &target,
1309 x_, y_, method_ == FloodfillMethod ? MagickFalse : MagickTrue);
1310 throwImageException();
1313 // Filter image by replacing each pixel component with the median
1314 // color in a circular neighborhood
1315 void Magick::Image::medianFilter ( const double radius_ )
1317 ExceptionInfo exceptionInfo;
1318 GetExceptionInfo( &exceptionInfo );
1319 MagickCore::Image* newImage =
1320 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1321 radius_,&exceptionInfo );
1322 replaceImage( newImage );
1323 throwException( exceptionInfo );
1324 (void) DestroyExceptionInfo( &exceptionInfo );
1327 // Reduce image by integral size
1328 void Magick::Image::minify ( void )
1330 ExceptionInfo exceptionInfo;
1331 GetExceptionInfo( &exceptionInfo );
1332 MagickCore::Image* newImage =
1333 MinifyImage( image(), &exceptionInfo );
1334 replaceImage( newImage );
1335 throwException( exceptionInfo );
1336 (void) DestroyExceptionInfo( &exceptionInfo );
1339 // Modulate percent hue, saturation, and brightness of an image
1340 void Magick::Image::modulate ( const double brightness_,
1341 const double saturation_,
1344 char modulate[MaxTextExtent + 1];
1345 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
1346 brightness_, saturation_, hue_);
1349 ModulateImage( image(), modulate );
1350 throwImageException();
1353 // Motion blur image with specified blur factor
1354 // The radius_ parameter specifies the radius of the Gaussian, in
1355 // pixels, not counting the center pixel. The sigma_ parameter
1356 // specifies the standard deviation of the Laplacian, in pixels.
1357 // The angle_ parameter specifies the angle the object appears
1358 // to be comming from (zero degrees is from the right).
1359 void Magick::Image::motionBlur ( const double radius_,
1360 const double sigma_,
1361 const double angle_ )
1363 ExceptionInfo exceptionInfo;
1364 GetExceptionInfo( &exceptionInfo );
1365 MagickCore::Image* newImage =
1366 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1367 replaceImage( newImage );
1368 throwException( exceptionInfo );
1369 (void) DestroyExceptionInfo( &exceptionInfo );
1372 // Negate image. Set grayscale_ to true to effect grayscale values
1374 void Magick::Image::negate ( const bool grayscale_ )
1377 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
1378 throwImageException();
1382 void Magick::Image::normalize ( void )
1385 NormalizeImage ( image() );
1386 throwImageException();
1390 void Magick::Image::oilPaint ( const double radius_ )
1392 ExceptionInfo exceptionInfo;
1393 GetExceptionInfo( &exceptionInfo );
1394 MagickCore::Image* newImage =
1395 OilPaintImage( image(), radius_, &exceptionInfo );
1396 replaceImage( newImage );
1397 throwException( exceptionInfo );
1398 (void) DestroyExceptionInfo( &exceptionInfo );
1401 // Set or attenuate the alpha channel. If the image pixels are
1402 // opaque then they are set to the specified alpha value, otherwise
1403 // they are blended with the supplied alpha value. The value of
1404 // alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1405 // OpaqueAlpha and TransparentAlpha are available to specify
1406 // completely opaque or completely transparent, respectively.
1407 void Magick::Image::alpha ( const unsigned int alpha_ )
1410 SetImageOpacity( image(), alpha_ );
1413 // Change the color of an opaque pixel to the pen color.
1414 void Magick::Image::opaque ( const Color &opaqueColor_,
1415 const Color &penColor_ )
1417 if ( !opaqueColor_.isValid() )
1419 throwExceptionExplicit( OptionError,
1420 "Opaque color argument is invalid" );
1422 if ( !penColor_.isValid() )
1424 throwExceptionExplicit( OptionError,
1425 "Pen color argument is invalid" );
1429 std::string opaqueColor = opaqueColor_;
1430 std::string penColor = penColor_;
1434 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1435 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1436 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1437 throwImageException();
1440 // Ping is similar to read except only enough of the image is read to
1441 // determine the image columns, rows, and filesize. Access the
1442 // columns(), rows(), and fileSize() attributes after invoking ping.
1443 // The image data is not valid after calling ping.
1444 void Magick::Image::ping ( const std::string &imageSpec_ )
1446 options()->fileName( imageSpec_ );
1447 ExceptionInfo exceptionInfo;
1448 GetExceptionInfo( &exceptionInfo );
1449 MagickCore::Image* image =
1450 PingImage( imageInfo(), &exceptionInfo );
1451 replaceImage( image );
1452 throwException( exceptionInfo );
1453 (void) DestroyExceptionInfo( &exceptionInfo );
1456 // Ping is similar to read except only enough of the image is read
1457 // to determine the image columns, rows, and filesize. Access the
1458 // columns(), rows(), and fileSize() attributes after invoking
1459 // ping. The image data is not valid after calling ping.
1460 void Magick::Image::ping ( const Blob& blob_ )
1462 ExceptionInfo exceptionInfo;
1463 GetExceptionInfo( &exceptionInfo );
1464 MagickCore::Image* image =
1465 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1466 replaceImage( image );
1467 throwException( exceptionInfo );
1468 (void) DestroyExceptionInfo( &exceptionInfo );
1471 // Execute a named process module using an argc/argv syntax similar to
1472 // that accepted by a C 'main' routine. An exception is thrown if the
1473 // requested process module doesn't exist, fails to load, or fails during
1475 void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
1480 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1481 &image()->exception );
1483 if (status == false)
1484 throwException( image()->exception );
1487 // Quantize colors in image using current quantization settings
1488 // Set measureError_ to true in order to measure quantization error
1489 void Magick::Image::quantize ( const bool measureError_ )
1494 options()->quantizeInfo()->measure_error=MagickTrue;
1496 options()->quantizeInfo()->measure_error=MagickFalse;
1498 QuantizeImage( options()->quantizeInfo(), image() );
1500 throwImageException();
1503 // Apply an arithmetic or bitwise operator to the image pixel quantums.
1504 void Magick::Image::quantumOperator ( const ChannelType channel_,
1505 const MagickEvaluateOperator operator_,
1508 ExceptionInfo exceptionInfo;
1509 GetExceptionInfo( &exceptionInfo );
1510 EvaluateImageChannel( image(), channel_, operator_, rvalue_, &exceptionInfo);
1511 throwException( exceptionInfo );
1512 (void) DestroyExceptionInfo( &exceptionInfo );
1515 void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
1516 const size_t columns_,
1518 const ChannelType channel_,
1519 const MagickEvaluateOperator operator_,
1520 const double rvalue_)
1522 ExceptionInfo exceptionInfo;
1523 GetExceptionInfo( &exceptionInfo );
1524 RectangleInfo geometry;
1525 geometry.width = columns_;
1526 geometry.height = rows_;
1529 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1531 EvaluateImageChannel( crop_image, channel_, operator_, rvalue_,
1533 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1534 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1535 crop_image = DestroyImageList(crop_image);
1536 throwException( exceptionInfo );
1537 (void) DestroyExceptionInfo( &exceptionInfo );
1540 // Raise image (lighten or darken the edges of an image to give a 3-D
1541 // raised or lowered effect)
1542 void Magick::Image::raise ( const Geometry &geometry_ ,
1543 const bool raisedFlag_ )
1545 RectangleInfo raiseInfo = geometry_;
1547 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1548 throwImageException();
1552 // Random threshold image.
1554 // Changes the value of individual pixels based on the intensity
1555 // of each pixel compared to a random threshold. The result is a
1556 // low-contrast, two color image. The thresholds_ argument is a
1557 // geometry containing LOWxHIGH thresholds. If the string
1558 // contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1559 // 3, or 4 will be performed instead. If a channel_ argument is
1560 // specified then only the specified channel is altered. This is
1561 // a very fast alternative to 'quantize' based dithering.
1562 void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1564 randomThresholdChannel(thresholds_,DefaultChannels);
1566 void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1567 const ChannelType channel_ )
1569 ExceptionInfo exceptionInfo;
1570 GetExceptionInfo( &exceptionInfo );
1572 (void) RandomThresholdImageChannel( image(),
1574 static_cast<std::string>(thresholds_).c_str(),
1576 throwImageException();
1577 (void) DestroyExceptionInfo( &exceptionInfo );
1580 // Read image into current object
1581 void Magick::Image::read ( const std::string &imageSpec_ )
1583 options()->fileName( imageSpec_ );
1585 ExceptionInfo exceptionInfo;
1586 GetExceptionInfo( &exceptionInfo );
1587 MagickCore::Image* image =
1588 ReadImage( imageInfo(), &exceptionInfo );
1590 // Ensure that multiple image frames were not read.
1591 if ( image && image->next )
1593 // Destroy any extra image frames
1594 MagickCore::Image* next = image->next;
1597 DestroyImageList( next );
1600 replaceImage( image );
1601 throwException( exceptionInfo );
1603 throwException( image->exception );
1604 (void) DestroyExceptionInfo( &exceptionInfo );
1607 // Read image of specified size into current object
1608 void Magick::Image::read ( const Geometry &size_,
1609 const std::string &imageSpec_ )
1615 // Read image from in-memory BLOB
1616 void Magick::Image::read ( const Blob &blob_ )
1618 ExceptionInfo exceptionInfo;
1619 GetExceptionInfo( &exceptionInfo );
1620 MagickCore::Image* image =
1621 BlobToImage( imageInfo(),
1622 static_cast<const void *>(blob_.data()),
1623 blob_.length(), &exceptionInfo );
1624 replaceImage( image );
1625 throwException( exceptionInfo );
1627 throwException( image->exception );
1628 (void) DestroyExceptionInfo( &exceptionInfo );
1631 // Read image of specified size from in-memory BLOB
1632 void Magick::Image::read ( const Blob &blob_,
1633 const Geometry &size_ )
1641 // Read image of specified size and depth from in-memory BLOB
1642 void Magick::Image::read ( const Blob &blob_,
1643 const Geometry &size_,
1644 const size_t depth_ )
1654 // Read image of specified size, depth, and format from in-memory BLOB
1655 void Magick::Image::read ( const Blob &blob_,
1656 const Geometry &size_,
1657 const size_t depth_,
1658 const std::string &magick_ )
1666 // Set explicit image format
1667 fileName( magick_ + ':');
1672 // Read image of specified size, and format from in-memory BLOB
1673 void Magick::Image::read ( const Blob &blob_,
1674 const Geometry &size_,
1675 const std::string &magick_ )
1681 // Set explicit image format
1682 fileName( magick_ + ':');
1687 // Read image based on raw pixels in memory (ConstituteImage)
1688 void Magick::Image::read ( const size_t width_,
1689 const size_t height_,
1690 const std::string &map_,
1691 const StorageType type_,
1692 const void *pixels_ )
1694 ExceptionInfo exceptionInfo;
1695 GetExceptionInfo( &exceptionInfo );
1696 MagickCore::Image* image =
1697 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1699 replaceImage( image );
1700 throwException( exceptionInfo );
1702 throwException( image->exception );
1703 (void) DestroyExceptionInfo( &exceptionInfo );
1706 // Reduce noise in image
1707 void Magick::Image::reduceNoise ( const double order_ )
1709 ExceptionInfo exceptionInfo;
1710 GetExceptionInfo( &exceptionInfo );
1711 MagickCore::Image* newImage =
1712 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1714 replaceImage( newImage );
1715 throwException( exceptionInfo );
1716 (void) DestroyExceptionInfo( &exceptionInfo );
1720 void Magick::Image::resize( const Geometry &geometry_ )
1722 // Calculate new size. This code should be supported using binary arguments
1723 // in the ImageMagick library.
1726 size_t width = columns();
1727 size_t height = rows();
1729 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1733 ExceptionInfo exceptionInfo;
1734 GetExceptionInfo( &exceptionInfo );
1735 MagickCore::Image* newImage =
1736 ResizeImage( image(),
1742 replaceImage( newImage );
1743 throwException( exceptionInfo );
1744 (void) DestroyExceptionInfo( &exceptionInfo );
1748 void Magick::Image::roll ( const Geometry &roll_ )
1750 ssize_t xOff = roll_.xOff();
1751 if ( roll_.xNegative() )
1753 ssize_t yOff = roll_.yOff();
1754 if ( roll_.yNegative() )
1757 ExceptionInfo exceptionInfo;
1758 GetExceptionInfo( &exceptionInfo );
1759 MagickCore::Image* newImage =
1760 RollImage( image(), xOff, yOff, &exceptionInfo );
1761 replaceImage( newImage );
1762 throwException( exceptionInfo );
1763 (void) DestroyExceptionInfo( &exceptionInfo );
1765 void Magick::Image::roll ( const size_t columns_,
1766 const size_t rows_ )
1768 ExceptionInfo exceptionInfo;
1769 GetExceptionInfo( &exceptionInfo );
1770 MagickCore::Image* newImage =
1772 static_cast<ssize_t>(columns_),
1773 static_cast<ssize_t>(rows_), &exceptionInfo );
1774 replaceImage( newImage );
1775 throwException( exceptionInfo );
1776 (void) DestroyExceptionInfo( &exceptionInfo );
1780 void Magick::Image::rotate ( const double degrees_ )
1782 ExceptionInfo exceptionInfo;
1783 GetExceptionInfo( &exceptionInfo );
1784 MagickCore::Image* newImage =
1785 RotateImage( image(), degrees_, &exceptionInfo);
1786 replaceImage( newImage );
1787 throwException( exceptionInfo );
1788 (void) DestroyExceptionInfo( &exceptionInfo );
1792 void Magick::Image::sample ( const Geometry &geometry_ )
1796 size_t width = columns();
1797 size_t height = rows();
1799 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1803 ExceptionInfo exceptionInfo;
1804 GetExceptionInfo( &exceptionInfo );
1805 MagickCore::Image* newImage =
1806 SampleImage( image(), width, height, &exceptionInfo );
1807 replaceImage( newImage );
1808 throwException( exceptionInfo );
1809 (void) DestroyExceptionInfo( &exceptionInfo );
1813 void Magick::Image::scale ( const Geometry &geometry_ )
1817 size_t width = columns();
1818 size_t height = rows();
1820 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1824 ExceptionInfo exceptionInfo;
1825 GetExceptionInfo( &exceptionInfo );
1826 MagickCore::Image* newImage =
1827 ScaleImage( image(), width, height, &exceptionInfo );
1828 replaceImage( newImage );
1829 throwException( exceptionInfo );
1830 (void) DestroyExceptionInfo( &exceptionInfo );
1833 // Segment (coalesce similar image components) by analyzing the
1834 // histograms of the color components and identifying units that are
1835 // homogeneous with the fuzzy c-means technique.
1836 void Magick::Image::segment ( const double clusterThreshold_,
1837 const double smoothingThreshold_ )
1840 SegmentImage ( image(),
1841 options()->quantizeColorSpace(),
1842 (MagickBooleanType) options()->verbose(),
1844 smoothingThreshold_ );
1845 throwImageException();
1846 SyncImage( image() );
1847 throwImageException();
1850 // Shade image using distant light source
1851 void Magick::Image::shade ( const double azimuth_,
1852 const double elevation_,
1853 const bool colorShading_ )
1855 ExceptionInfo exceptionInfo;
1856 GetExceptionInfo( &exceptionInfo );
1857 MagickCore::Image* newImage =
1858 ShadeImage( image(),
1859 colorShading_ == true ? MagickTrue : MagickFalse,
1863 replaceImage( newImage );
1864 throwException( exceptionInfo );
1865 (void) DestroyExceptionInfo( &exceptionInfo );
1868 // Sharpen pixels in image
1869 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1871 ExceptionInfo exceptionInfo;
1872 GetExceptionInfo( &exceptionInfo );
1873 MagickCore::Image* newImage =
1874 SharpenImage( image(),
1878 replaceImage( newImage );
1879 throwException( exceptionInfo );
1880 (void) DestroyExceptionInfo( &exceptionInfo );
1883 void Magick::Image::sharpenChannel ( const ChannelType channel_,
1884 const double radius_, const double sigma_ )
1886 ExceptionInfo exceptionInfo;
1887 GetExceptionInfo( &exceptionInfo );
1888 MagickCore::Image* newImage =
1889 SharpenImageChannel( image(),
1894 replaceImage( newImage );
1895 throwException( exceptionInfo );
1896 (void) DestroyExceptionInfo( &exceptionInfo );
1899 // Shave pixels from image edges.
1900 void Magick::Image::shave ( const Geometry &geometry_ )
1902 RectangleInfo shaveInfo = geometry_;
1903 ExceptionInfo exceptionInfo;
1904 GetExceptionInfo( &exceptionInfo );
1905 MagickCore::Image* newImage =
1906 ShaveImage( image(),
1909 replaceImage( newImage );
1910 throwException( exceptionInfo );
1911 (void) DestroyExceptionInfo( &exceptionInfo );
1915 void Magick::Image::shear ( const double xShearAngle_,
1916 const double yShearAngle_ )
1918 ExceptionInfo exceptionInfo;
1919 GetExceptionInfo( &exceptionInfo );
1920 MagickCore::Image* newImage =
1921 ShearImage( image(),
1925 replaceImage( newImage );
1926 throwException( exceptionInfo );
1927 (void) DestroyExceptionInfo( &exceptionInfo );
1931 void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
1934 (void) SigmoidalContrastImageChannel( image(), DefaultChannels, (MagickBooleanType) sharpen_, contrast, midpoint );
1935 throwImageException();
1938 // Solarize image (similar to effect seen when exposing a photographic
1939 // film to light during the development process)
1940 void Magick::Image::solarize ( const double factor_ )
1943 SolarizeImage ( image(), factor_ );
1944 throwImageException();
1947 // Sparse color image, given a set of coordinates, interpolates the colors
1948 // found at those coordinates, across the whole image, using various methods.
1950 void Magick::Image::sparseColor ( const ChannelType channel,
1951 const SparseColorMethod method,
1952 const size_t number_arguments,
1953 const double *arguments )
1955 ExceptionInfo exceptionInfo;
1956 GetExceptionInfo( &exceptionInfo );
1957 MagickCore::Image* newImage = SparseColorImage ( image(), channel, method,
1958 number_arguments, arguments, &exceptionInfo );
1959 replaceImage( newImage );
1960 throwException( exceptionInfo );
1961 (void) DestroyExceptionInfo( &exceptionInfo );
1964 // Spread pixels randomly within image by specified ammount
1965 void Magick::Image::spread ( const size_t amount_ )
1967 ExceptionInfo exceptionInfo;
1968 GetExceptionInfo( &exceptionInfo );
1969 MagickCore::Image* newImage =
1970 SpreadImage( image(),
1973 replaceImage( newImage );
1974 throwException( exceptionInfo );
1975 (void) DestroyExceptionInfo( &exceptionInfo );
1978 // Add a digital watermark to the image (based on second image)
1979 void Magick::Image::stegano ( const Image &watermark_ )
1981 ExceptionInfo exceptionInfo;
1982 GetExceptionInfo( &exceptionInfo );
1983 MagickCore::Image* newImage =
1984 SteganoImage( image(),
1985 watermark_.constImage(),
1987 replaceImage( newImage );
1988 throwException( exceptionInfo );
1989 (void) DestroyExceptionInfo( &exceptionInfo );
1992 // Stereo image (left image is current image)
1993 void Magick::Image::stereo ( const Image &rightImage_ )
1995 ExceptionInfo exceptionInfo;
1996 GetExceptionInfo( &exceptionInfo );
1997 MagickCore::Image* newImage =
1998 StereoImage( image(),
1999 rightImage_.constImage(),
2001 replaceImage( newImage );
2002 throwException( exceptionInfo );
2003 (void) DestroyExceptionInfo( &exceptionInfo );
2007 void Magick::Image::swirl ( const double degrees_ )
2009 ExceptionInfo exceptionInfo;
2010 GetExceptionInfo( &exceptionInfo );
2011 MagickCore::Image* newImage =
2012 SwirlImage( image(), degrees_,
2014 replaceImage( newImage );
2015 throwException( exceptionInfo );
2016 (void) DestroyExceptionInfo( &exceptionInfo );
2020 void Magick::Image::texture ( const Image &texture_ )
2023 TextureImage( image(), texture_.constImage() );
2024 throwImageException();
2028 void Magick::Image::threshold ( const double threshold_ )
2031 BilevelImage( image(), threshold_ );
2032 throwImageException();
2035 // Transform image based on image geometry only
2036 void Magick::Image::transform ( const Geometry &imageGeometry_ )
2039 TransformImage ( &(image()), 0,
2040 std::string(imageGeometry_).c_str() );
2041 throwImageException();
2043 // Transform image based on image and crop geometries
2044 void Magick::Image::transform ( const Geometry &imageGeometry_,
2045 const Geometry &cropGeometry_ )
2048 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2049 std::string(imageGeometry_).c_str() );
2050 throwImageException();
2053 // Add matte image to image, setting pixels matching color to transparent
2054 void Magick::Image::transparent ( const Color &color_ )
2056 if ( !color_.isValid() )
2058 throwExceptionExplicit( OptionError,
2059 "Color argument is invalid" );
2062 std::string color = color_;
2065 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2067 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse );
2068 throwImageException();
2071 // Add matte image to image, setting pixels matching color to transparent
2072 void Magick::Image::transparentChroma(const Color &colorLow_,
2073 const Color &colorHigh_)
2075 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2077 throwExceptionExplicit( OptionError,
2078 "Color argument is invalid" );
2081 std::string colorLow = colorLow_;
2082 std::string colorHigh = colorHigh_;
2084 PixelInfo targetLow;
2085 PixelInfo targetHigh;
2086 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2087 &image()->exception);
2088 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2089 &image()->exception);
2091 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
2092 TransparentAlpha, MagickFalse );
2093 throwImageException();
2097 // Trim edges that are the background color from the image
2098 void Magick::Image::trim ( void )
2100 ExceptionInfo exceptionInfo;
2101 GetExceptionInfo( &exceptionInfo );
2102 MagickCore::Image* newImage =
2103 TrimImage( image(), &exceptionInfo);
2104 replaceImage( newImage );
2105 throwException( exceptionInfo );
2106 (void) DestroyExceptionInfo( &exceptionInfo );
2109 // Replace image with a sharpened version of the original image
2110 // using the unsharp mask algorithm.
2112 // the radius of the Gaussian, in pixels, not counting the
2115 // the standard deviation of the Gaussian, in pixels.
2117 // the percentage of the difference between the original and
2118 // the blur image that is added back into the original.
2120 // the threshold in pixels needed to apply the diffence amount.
2121 void Magick::Image::unsharpmask ( const double radius_,
2122 const double sigma_,
2123 const double amount_,
2124 const double threshold_ )
2126 ExceptionInfo exceptionInfo;
2127 GetExceptionInfo( &exceptionInfo );
2128 MagickCore::Image* newImage =
2129 UnsharpMaskImage( image(),
2135 replaceImage( newImage );
2136 throwException( exceptionInfo );
2137 (void) DestroyExceptionInfo( &exceptionInfo );
2140 void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2141 const double radius_,
2142 const double sigma_,
2143 const double amount_,
2144 const double threshold_ )
2146 ExceptionInfo exceptionInfo;
2147 GetExceptionInfo( &exceptionInfo );
2148 MagickCore::Image* newImage =
2149 UnsharpMaskImageChannel( image(),
2156 replaceImage( newImage );
2157 throwException( exceptionInfo );
2158 (void) DestroyExceptionInfo( &exceptionInfo );
2161 // Map image pixels to a sine wave
2162 void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2164 ExceptionInfo exceptionInfo;
2165 GetExceptionInfo( &exceptionInfo );
2166 MagickCore::Image* newImage =
2171 replaceImage( newImage );
2172 throwException( exceptionInfo );
2173 (void) DestroyExceptionInfo( &exceptionInfo );
2176 // Write image to file
2177 void Magick::Image::write( const std::string &imageSpec_ )
2180 fileName( imageSpec_ );
2181 WriteImage( imageInfo(), image() );
2182 throwImageException();
2185 // Write image to in-memory BLOB
2186 void Magick::Image::write ( Blob *blob_ )
2189 size_t length = 2048; // Efficient size for small images
2190 ExceptionInfo exceptionInfo;
2191 GetExceptionInfo( &exceptionInfo );
2192 void* data = ImageToBlob( imageInfo(),
2196 throwException( exceptionInfo );
2197 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2198 throwImageException();
2199 (void) DestroyExceptionInfo( &exceptionInfo );
2201 void Magick::Image::write ( Blob *blob_,
2202 const std::string &magick_ )
2206 size_t length = 2048; // Efficient size for small images
2207 ExceptionInfo exceptionInfo;
2208 GetExceptionInfo( &exceptionInfo );
2209 void* data = ImageToBlob( imageInfo(),
2213 throwException( exceptionInfo );
2214 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2215 throwImageException();
2216 (void) DestroyExceptionInfo( &exceptionInfo );
2218 void Magick::Image::write ( Blob *blob_,
2219 const std::string &magick_,
2220 const size_t depth_ )
2225 size_t length = 2048; // Efficient size for small images
2226 ExceptionInfo exceptionInfo;
2227 GetExceptionInfo( &exceptionInfo );
2228 void* data = ImageToBlob( imageInfo(),
2232 throwException( exceptionInfo );
2233 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2234 throwImageException();
2235 (void) DestroyExceptionInfo( &exceptionInfo );
2238 // Write image to an array of pixels with storage type specified
2239 // by user (ExportImagePixels), e.g.
2240 // image.write( 0, 0, 640, 1, "RGB", 0, pixels );
2241 void Magick::Image::write ( const ssize_t x_,
2243 const size_t columns_,
2245 const std::string &map_,
2246 const StorageType type_,
2249 ExceptionInfo exceptionInfo;
2250 GetExceptionInfo( &exceptionInfo );
2251 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2254 throwException( exceptionInfo );
2255 (void) DestroyExceptionInfo( &exceptionInfo );
2259 void Magick::Image::zoom( const Geometry &geometry_ )
2261 // Calculate new size. This code should be supported using binary arguments
2262 // in the ImageMagick library.
2265 size_t width = columns();
2266 size_t height = rows();
2268 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2272 ExceptionInfo exceptionInfo;
2273 GetExceptionInfo( &exceptionInfo );
2274 MagickCore::Image* newImage =
2275 ResizeImage( image(),
2281 replaceImage( newImage );
2282 throwException( exceptionInfo );
2283 (void) DestroyExceptionInfo( &exceptionInfo );
2287 * Methods for setting image attributes
2291 // Join images into a single multi-image file
2292 void Magick::Image::adjoin ( const bool flag_ )
2295 options()->adjoin( flag_ );
2297 bool Magick::Image::adjoin ( void ) const
2299 return constOptions()->adjoin();
2302 // Remove pixel aliasing
2303 void Magick::Image::antiAlias( const bool flag_ )
2306 options()->antiAlias( static_cast<size_t>(flag_) );
2308 bool Magick::Image::antiAlias( void )
2310 return static_cast<bool>( options()->antiAlias( ) );
2313 // Animation inter-frame delay
2314 void Magick::Image::animationDelay ( const size_t delay_ )
2317 image()->delay = delay_;
2319 size_t Magick::Image::animationDelay ( void ) const
2321 return constImage()->delay;
2324 // Number of iterations to play animation
2325 void Magick::Image::animationIterations ( const size_t iterations_ )
2328 image()->iterations = iterations_;
2330 size_t Magick::Image::animationIterations ( void ) const
2332 return constImage()->iterations;
2335 // Access/Update a named image attribute
2336 void Magick::Image::attribute ( const std::string name_,
2337 const std::string value_ )
2340 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2342 std::string Magick::Image::attribute ( const std::string name_ )
2344 const char *value = GetImageProperty( constImage(), name_.c_str() );
2347 return std::string( value );
2349 return std::string(); // Intentionally no exception
2353 void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
2357 if ( backgroundColor_.isValid() )
2359 image()->background_color = backgroundColor_;
2363 image()->background_color = Color();
2366 options()->backgroundColor( backgroundColor_ );
2368 Magick::Color Magick::Image::backgroundColor ( void ) const
2370 return constOptions()->backgroundColor( );
2373 // Background fill texture
2374 void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2377 options()->backgroundTexture( backgroundTexture_ );
2379 std::string Magick::Image::backgroundTexture ( void ) const
2381 return constOptions()->backgroundTexture( );
2384 // Original image columns
2385 size_t Magick::Image::baseColumns ( void ) const
2387 return constImage()->magick_columns;
2390 // Original image name
2391 std::string Magick::Image::baseFilename ( void ) const
2393 return std::string(constImage()->magick_filename);
2396 // Original image rows
2397 size_t Magick::Image::baseRows ( void ) const
2399 return constImage()->magick_rows;
2403 void Magick::Image::borderColor ( const Color &borderColor_ )
2407 if ( borderColor_.isValid() )
2409 image()->border_color = borderColor_;
2413 image()->border_color = Color();
2416 options()->borderColor( borderColor_ );
2418 Magick::Color Magick::Image::borderColor ( void ) const
2420 return constOptions()->borderColor( );
2423 // Return smallest bounding box enclosing non-border pixels. The
2424 // current fuzz value is used when discriminating between pixels.
2425 // This is the crop bounding box used by crop(Geometry(0,0));
2426 Magick::Geometry Magick::Image::boundingBox ( void ) const
2428 ExceptionInfo exceptionInfo;
2429 GetExceptionInfo( &exceptionInfo );
2430 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2431 throwException( exceptionInfo );
2432 (void) DestroyExceptionInfo( &exceptionInfo );
2433 return Geometry( bbox );
2436 // Text bounding-box base color
2437 void Magick::Image::boxColor ( const Color &boxColor_ )
2440 options()->boxColor( boxColor_ );
2442 Magick::Color Magick::Image::boxColor ( void ) const
2444 return constOptions()->boxColor( );
2447 // Pixel cache threshold. Once this threshold is exceeded, all
2448 // subsequent pixels cache operations are to/from disk.
2449 // This setting is shared by all Image objects.
2451 void Magick::Image::cacheThreshold ( const size_t threshold_ )
2453 SetMagickResourceLimit( MemoryResource, threshold_ );
2456 void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2459 image()->chromaticity.blue_primary.x = x_;
2460 image()->chromaticity.blue_primary.y = y_;
2462 void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2464 *x_ = constImage()->chromaticity.blue_primary.x;
2465 *y_ = constImage()->chromaticity.blue_primary.y;
2468 void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2471 image()->chromaticity.green_primary.x = x_;
2472 image()->chromaticity.green_primary.y = y_;
2474 void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2476 *x_ = constImage()->chromaticity.green_primary.x;
2477 *y_ = constImage()->chromaticity.green_primary.y;
2480 void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2483 image()->chromaticity.red_primary.x = x_;
2484 image()->chromaticity.red_primary.y = y_;
2486 void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2488 *x_ = constImage()->chromaticity.red_primary.x;
2489 *y_ = constImage()->chromaticity.red_primary.y;
2492 void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2495 image()->chromaticity.white_point.x = x_;
2496 image()->chromaticity.white_point.y = y_;
2498 void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2500 *x_ = constImage()->chromaticity.white_point.x;
2501 *y_ = constImage()->chromaticity.white_point.y;
2504 // Set image storage class
2505 void Magick::Image::classType ( const ClassType class_ )
2507 if ( classType() == PseudoClass && class_ == DirectClass )
2509 // Use SyncImage to synchronize the DirectClass pixels with the
2510 // color map and then set to DirectClass type.
2512 SyncImage( image() );
2513 image()->colormap = (PixelPacket *)
2514 RelinquishMagickMemory( image()->colormap );
2515 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2519 if ( classType() == DirectClass && class_ == PseudoClass )
2521 // Quantize to create PseudoClass color map
2523 quantizeColors(MaxColormapSize);
2525 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2529 // Associate a clip mask with the image. The clip mask must be the
2530 // same dimensions as the image. Pass an invalid image to unset an
2531 // existing clip mask.
2532 void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2536 if( clipMask_.isValid() )
2539 SetImageClipMask( image(), clipMask_.constImage() );
2543 // Unset existing clip mask
2544 SetImageClipMask( image(), 0 );
2547 Magick::Image Magick::Image::clipMask ( void ) const
2549 ExceptionInfo exceptionInfo;
2550 GetExceptionInfo( &exceptionInfo );
2551 MagickCore::Image* image =
2552 GetImageClipMask( constImage(), &exceptionInfo );
2553 throwException( exceptionInfo );
2554 (void) DestroyExceptionInfo( &exceptionInfo );
2555 return Magick::Image( image );
2558 void Magick::Image::colorFuzz ( const double fuzz_ )
2561 image()->fuzz = fuzz_;
2562 options()->colorFuzz( fuzz_ );
2564 double Magick::Image::colorFuzz ( void ) const
2566 return constOptions()->colorFuzz( );
2569 // Set color in colormap at index
2570 void Magick::Image::colorMap ( const size_t index_,
2571 const Color &color_ )
2573 MagickCore::Image* imageptr = image();
2575 if (index_ > (MaxColormapSize-1) )
2576 throwExceptionExplicit( OptionError,
2577 "Colormap index must be less than MaxColormapSize" );
2579 if ( !color_.isValid() )
2580 throwExceptionExplicit( OptionError,
2581 "Color argument is invalid");
2584 // Ensure that colormap size is large enough
2585 if ( colorMapSize() < (index_+1) )
2586 colorMapSize( index_ + 1 );
2588 // Set color at index in colormap
2589 (imageptr->colormap)[index_] = color_;
2591 // Return color in colormap at index
2592 Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
2594 const MagickCore::Image* imageptr = constImage();
2596 if ( !imageptr->colormap )
2597 throwExceptionExplicit( OptionError,
2598 "Image does not contain a colormap");
2600 if ( index_ > imageptr->colors-1 )
2601 throwExceptionExplicit( OptionError,
2602 "Index out of range");
2604 return Magick::Color( (imageptr->colormap)[index_] );
2607 // Colormap size (number of colormap entries)
2608 void Magick::Image::colorMapSize ( const size_t entries_ )
2610 if (entries_ >MaxColormapSize )
2611 throwExceptionExplicit( OptionError,
2612 "Colormap entries must not exceed MaxColormapSize" );
2616 MagickCore::Image* imageptr = image();
2618 if( !imageptr->colormap )
2620 // Allocate colormap
2621 imageptr->colormap =
2622 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2623 imageptr->colors = 0;
2625 else if ( entries_ > imageptr->colors )
2627 // Re-allocate colormap
2628 imageptr->colormap=(PixelPacket *)
2629 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2632 // Initialize any new colormap entries as all black
2634 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
2635 (imageptr->colormap)[i] = black;
2637 imageptr->colors = entries_;
2639 size_t Magick::Image::colorMapSize ( void )
2641 const MagickCore::Image* imageptr = constImage();
2643 if ( !imageptr->colormap )
2644 throwExceptionExplicit( OptionError,
2645 "Image does not contain a colormap");
2647 return imageptr->colors;
2651 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2654 if ( image()->colorspace == colorSpace_ )
2659 if ( colorSpace_ != RGBColorspace &&
2660 colorSpace_ != TransparentColorspace &&
2661 colorSpace_ != GRAYColorspace )
2663 if (image()->colorspace != RGBColorspace &&
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_ == TransparentColorspace ||
2679 colorSpace_ == GRAYColorspace )
2681 /* Transform to a RGB-type colorspace */
2682 TransformRGBImage( image(), image()->colorspace );
2683 throwImageException();
2687 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2689 return constImage()->colorspace;
2692 // Set image colorspace type.
2693 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2696 options()->colorspaceType( colorSpace_ );
2698 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2700 return constOptions()->colorspaceType();
2705 void Magick::Image::comment ( const std::string &comment_ )
2708 SetImageProperty( image(), "Comment", NULL );
2709 if ( comment_.length() > 0 )
2710 SetImageProperty( image(), "Comment", comment_.c_str() );
2711 throwImageException();
2713 std::string Magick::Image::comment ( void ) const
2715 const char *value = GetImageProperty( constImage(), "Comment" );
2718 return std::string( value );
2720 return std::string(); // Intentionally no exception
2723 // Composition operator to be used when composition is implicitly used
2724 // (such as for image flattening).
2725 void Magick::Image::compose (const CompositeOperator compose_)
2727 image()->compose=compose_;
2730 Magick::CompositeOperator Magick::Image::compose ( void ) const
2732 return constImage()->compose;
2735 // Compression algorithm
2736 void Magick::Image::compressType ( const CompressionType compressType_ )
2739 image()->compression = compressType_;
2740 options()->compressType( compressType_ );
2742 Magick::CompressionType Magick::Image::compressType ( void ) const
2744 return constImage()->compression;
2747 // Enable printing of debug messages from ImageMagick
2748 void Magick::Image::debug ( const bool flag_ )
2751 options()->debug( flag_ );
2753 bool Magick::Image::debug ( void ) const
2755 return constOptions()->debug();
2758 // Tagged image format define (set/access coder-specific option) The
2759 // magick_ option specifies the coder the define applies to. The key_
2760 // option provides the key specific to that coder. The value_ option
2761 // provides the value to set (if any). See the defineSet() method if the
2762 // key must be removed entirely.
2763 void Magick::Image::defineValue ( const std::string &magick_,
2764 const std::string &key_,
2765 const std::string &value_ )
2768 std::string format = magick_ + ":" + key_;
2769 std::string option = value_;
2770 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2772 std::string Magick::Image::defineValue ( const std::string &magick_,
2773 const std::string &key_ ) const
2775 std::string definition = magick_ + ":" + key_;
2776 const char *option =
2777 GetImageOption ( constImageInfo(), definition.c_str() );
2779 return std::string( option );
2780 return std::string( );
2783 // Tagged image format define. Similar to the defineValue() method
2784 // except that passing the flag_ value 'true' creates a value-less
2785 // define with that format and key. Passing the flag_ value 'false'
2786 // removes any existing matching definition. The method returns 'true'
2787 // if a matching key exists, and 'false' if no matching key exists.
2788 void Magick::Image::defineSet ( const std::string &magick_,
2789 const std::string &key_,
2793 std::string definition = magick_ + ":" + key_;
2796 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2800 DeleteImageOption( imageInfo(), definition.c_str() );
2803 bool Magick::Image::defineSet ( const std::string &magick_,
2804 const std::string &key_ ) const
2806 std::string key = magick_ + ":" + key_;
2807 const char *option =
2808 GetImageOption ( constImageInfo(), key.c_str() );
2815 void Magick::Image::density ( const Geometry &density_ )
2818 options()->density( density_ );
2819 if ( density_.isValid() )
2821 image()->x_resolution = density_.width();
2822 if ( density_.height() != 0 )
2824 image()->y_resolution = density_.height();
2828 image()->y_resolution = density_.width();
2834 image()->x_resolution = 0;
2835 image()->y_resolution = 0;
2838 Magick::Geometry Magick::Image::density ( void ) const
2842 ssize_t x_resolution=72;
2843 ssize_t y_resolution=72;
2845 if (constImage()->x_resolution > 0.0)
2846 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
2848 if (constImage()->y_resolution > 0.0)
2849 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
2851 return Geometry(x_resolution,y_resolution);
2854 return constOptions()->density( );
2857 // Image depth (bits allocated to red/green/blue components)
2858 void Magick::Image::depth ( const size_t depth_ )
2860 size_t depth = depth_;
2862 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2863 depth=MAGICKCORE_QUANTUM_DEPTH;
2866 image()->depth=depth;
2867 options()->depth( depth );
2869 size_t Magick::Image::depth ( void ) const
2871 return constImage()->depth;
2874 std::string Magick::Image::directory ( void ) const
2876 if ( constImage()->directory )
2877 return std::string( constImage()->directory );
2879 throwExceptionExplicit( CorruptImageWarning,
2880 "Image does not contain a directory");
2882 return std::string();
2885 // Endianness (little like Intel or big like SPARC) for image
2886 // formats which support endian-specific options.
2887 void Magick::Image::endian ( const Magick::EndianType endian_ )
2890 options()->endian( endian_ );
2891 image()->endian = endian_;
2893 Magick::EndianType Magick::Image::endian ( void ) const
2895 return constImage()->endian;
2898 // EXIF profile (BLOB)
2899 void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2902 if ( exifProfile_.data() != 0 )
2904 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2905 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2906 (void) SetImageProfile( image(), "exif", exif_profile);
2907 exif_profile =DestroyStringInfo( exif_profile );
2910 Magick::Blob Magick::Image::exifProfile( void ) const
2912 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2913 if ( exif_profile == (StringInfo *) NULL)
2914 return Blob( 0, 0 );
2915 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2919 void Magick::Image::fileName ( const std::string &fileName_ )
2923 fileName_.copy( image()->filename,
2924 sizeof(image()->filename) - 1 );
2925 image()->filename[ fileName_.length() ] = 0; // Null terminate
2927 options()->fileName( fileName_ );
2930 std::string Magick::Image::fileName ( void ) const
2932 return constOptions()->fileName( );
2936 off_t Magick::Image::fileSize ( void ) const
2938 return (off_t) GetBlobSize( constImage() );
2941 // Color to use when drawing inside an object
2942 void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2945 options()->fillColor(fillColor_);
2947 Magick::Color Magick::Image::fillColor ( void ) const
2949 return constOptions()->fillColor();
2952 // Rule to use when filling drawn objects
2953 void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2956 options()->fillRule(fillRule_);
2958 Magick::FillRule Magick::Image::fillRule ( void ) const
2960 return constOptions()->fillRule();
2963 // Pattern to use while filling drawn objects.
2964 void Magick::Image::fillPattern ( const Image &fillPattern_ )
2967 if(fillPattern_.isValid())
2968 options()->fillPattern( fillPattern_.constImage() );
2970 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
2972 Magick::Image Magick::Image::fillPattern ( void ) const
2974 // FIXME: This is inordinately innefficient
2977 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
2981 ExceptionInfo exceptionInfo;
2982 GetExceptionInfo( &exceptionInfo );
2983 MagickCore::Image* image =
2984 CloneImage( tmpTexture,
2987 MagickTrue, // orphan
2989 texture.replaceImage( image );
2990 throwException( exceptionInfo );
2991 (void) DestroyExceptionInfo( &exceptionInfo );
2996 // Filter used by zoom
2997 void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3000 image()->filter = filterType_;
3002 Magick::FilterTypes Magick::Image::filterType ( void ) const
3004 return constImage()->filter;
3008 void Magick::Image::font ( const std::string &font_ )
3011 options()->font( font_ );
3013 std::string Magick::Image::font ( void ) const
3015 return constOptions()->font( );
3019 void Magick::Image::fontPointsize ( const double pointSize_ )
3022 options()->fontPointsize( pointSize_ );
3024 double Magick::Image::fontPointsize ( void ) const
3026 return constOptions()->fontPointsize( );
3029 // Font type metrics
3030 void Magick::Image::fontTypeMetrics( const std::string &text_,
3031 TypeMetric *metrics )
3033 DrawInfo *drawInfo = options()->drawInfo();
3034 drawInfo->text = const_cast<char *>(text_.c_str());
3035 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3039 // Image format string
3040 std::string Magick::Image::format ( void ) const
3042 ExceptionInfo exceptionInfo;
3043 GetExceptionInfo( &exceptionInfo );
3044 const MagickInfo * magick_info
3045 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3046 throwException( exceptionInfo );
3047 (void) DestroyExceptionInfo( &exceptionInfo );
3049 if (( magick_info != 0 ) &&
3050 ( *magick_info->description != '\0' ))
3051 return std::string(magick_info->description);
3053 throwExceptionExplicit( CorruptImageWarning,
3054 "Unrecognized image magick type" );
3055 return std::string();
3059 double Magick::Image::gamma ( void ) const
3061 return constImage()->gamma;
3064 Magick::Geometry Magick::Image::geometry ( void ) const
3066 if ( constImage()->geometry )
3068 return Geometry(constImage()->geometry);
3071 throwExceptionExplicit( OptionWarning,
3072 "Image does not contain a geometry");
3077 void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
3080 image()->dispose = (DisposeType) disposeMethod_;
3082 size_t Magick::Image::gifDisposeMethod ( void ) const
3084 // FIXME: It would be better to return an enumeration
3085 return constImage()->dispose;
3088 // ICC ICM color profile (BLOB)
3089 void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3091 profile("icm",colorProfile_);
3093 Magick::Blob Magick::Image::iccColorProfile( void ) const
3095 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3096 if ( color_profile == (StringInfo *) NULL)
3097 return Blob( 0, 0 );
3098 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3101 void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3104 image()->interlace = interlace_;
3105 options()->interlaceType ( interlace_ );
3107 Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3109 return constImage()->interlace;
3112 // IPTC profile (BLOB)
3113 void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3116 if ( iptcProfile_.data() != 0 )
3118 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3119 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3120 (void) SetImageProfile( image(), "iptc", iptc_profile);
3121 iptc_profile =DestroyStringInfo( iptc_profile );
3124 Magick::Blob Magick::Image::iptcProfile( void ) const
3126 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3127 if ( iptc_profile == (StringInfo *) NULL)
3128 return Blob( 0, 0 );
3129 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3132 // Does object contain valid image?
3133 void Magick::Image::isValid ( const bool isValid_ )
3138 _imgRef = new ImageRef;
3140 else if ( !isValid() )
3142 // Construct with single-pixel black image to make
3143 // image valid. This is an obvious hack.
3144 size( Geometry(1,1) );
3145 read( "xc:#000000" );
3149 bool Magick::Image::isValid ( void ) const
3151 if ( rows() && columns() )
3158 void Magick::Image::label ( const std::string &label_ )
3161 SetImageProperty ( image(), "Label", NULL );
3162 if ( label_.length() > 0 )
3163 SetImageProperty ( image(), "Label", label_.c_str() );
3164 throwImageException();
3166 std::string Magick::Image::label ( void ) const
3168 const char *value = GetImageProperty( constImage(), "Label" );
3171 return std::string( value );
3173 return std::string();
3176 void Magick::Image::magick ( const std::string &magick_ )
3180 magick_.copy( image()->magick,
3181 sizeof(image()->magick) - 1 );
3182 image()->magick[ magick_.length() ] = 0;
3184 options()->magick( magick_ );
3186 std::string Magick::Image::magick ( void ) const
3188 if ( *(constImage()->magick) != '\0' )
3189 return std::string(constImage()->magick);
3191 return constOptions()->magick( );
3194 void Magick::Image::matte ( const bool matteFlag_ )
3198 // If matte channel is requested, but image doesn't already have a
3199 // matte channel, then create an opaque matte channel. Likewise, if
3200 // the image already has a matte channel but a matte channel is not
3201 // desired, then set the matte channel to opaque.
3202 if ((matteFlag_ && !constImage()->matte) ||
3203 (constImage()->matte && !matteFlag_))
3204 SetImageOpacity(image(),OpaqueAlpha);
3206 image()->matte = (MagickBooleanType) matteFlag_;
3208 bool Magick::Image::matte ( void ) const
3210 if ( constImage()->matte )
3216 void Magick::Image::matteColor ( const Color &matteColor_ )
3220 if ( matteColor_.isValid() )
3222 image()->matte_color = matteColor_;
3223 options()->matteColor( matteColor_ );
3227 // Set to default matte color
3228 Color tmpColor( "#BDBDBD" );
3229 image()->matte_color = tmpColor;
3230 options()->matteColor( tmpColor );
3233 Magick::Color Magick::Image::matteColor ( void ) const
3235 return Color( constImage()->matte_color.red,
3236 constImage()->matte_color.green,
3237 constImage()->matte_color.blue );
3240 double Magick::Image::meanErrorPerPixel ( void ) const
3242 return(constImage()->error.mean_error_per_pixel);
3245 // Image modulus depth (minimum number of bits required to support
3246 // red/green/blue components without loss of accuracy)
3247 void Magick::Image::modulusDepth ( const size_t depth_ )
3250 SetImageDepth( image(), depth_ );
3251 options()->depth( depth_ );
3253 size_t Magick::Image::modulusDepth ( void ) const
3255 ExceptionInfo exceptionInfo;
3256 GetExceptionInfo( &exceptionInfo );
3257 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
3258 throwException( exceptionInfo );
3259 (void) DestroyExceptionInfo( &exceptionInfo );
3263 void Magick::Image::monochrome ( const bool monochromeFlag_ )
3266 options()->monochrome( monochromeFlag_ );
3268 bool Magick::Image::monochrome ( void ) const
3270 return constOptions()->monochrome( );
3273 Magick::Geometry Magick::Image::montageGeometry ( void ) const
3275 if ( constImage()->montage )
3276 return Magick::Geometry(constImage()->montage);
3278 throwExceptionExplicit( CorruptImageWarning,
3279 "Image does not contain a montage" );
3281 return Magick::Geometry();
3284 double Magick::Image::normalizedMaxError ( void ) const
3286 return(constImage()->error.normalized_maximum_error);
3289 double Magick::Image::normalizedMeanError ( void ) const
3291 return constImage()->error.normalized_mean_error;
3294 // Image orientation
3295 void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3298 image()->orientation = orientation_;
3300 Magick::OrientationType Magick::Image::orientation ( void ) const
3302 return constImage()->orientation;
3305 void Magick::Image::penColor ( const Color &penColor_ )
3308 options()->fillColor(penColor_);
3309 options()->strokeColor(penColor_);
3311 Magick::Color Magick::Image::penColor ( void ) const
3313 return constOptions()->fillColor();
3316 void Magick::Image::penTexture ( const Image &penTexture_ )
3319 if(penTexture_.isValid())
3320 options()->fillPattern( penTexture_.constImage() );
3322 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3325 Magick::Image Magick::Image::penTexture ( void ) const
3327 // FIXME: This is inordinately innefficient
3330 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3334 ExceptionInfo exceptionInfo;
3335 GetExceptionInfo( &exceptionInfo );
3336 MagickCore::Image* image =
3337 CloneImage( tmpTexture,
3340 MagickTrue, // orphan
3342 texture.replaceImage( image );
3343 throwException( exceptionInfo );
3344 (void) DestroyExceptionInfo( &exceptionInfo );
3349 // Set the color of a pixel.
3350 void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
3351 const Color &color_ )
3353 // Test arguments to ensure they are within the image.
3354 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
3355 throwExceptionExplicit( OptionError,
3356 "Access outside of image boundary" );
3360 // Set image to DirectClass
3361 classType( DirectClass );
3364 Pixels pixels(*this);
3366 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3367 PixelPacket packet = color_;
3368 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
3369 // Tell ImageMagick that pixels have been updated
3375 // Get the color of a pixel
3376 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3377 const ssize_t y_ ) const
3379 ClassType storage_class;
3380 storage_class = classType();
3382 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3386 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3387 return Color( packet );
3390 return Color(); // invalid
3393 // Preferred size and location of an image canvas.
3394 void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3397 options()->page( pageSize_ );
3398 image()->page = pageSize_;
3400 Magick::Geometry Magick::Image::page ( void ) const
3402 return Geometry( constImage()->page.width,
3403 constImage()->page.height,
3404 AbsoluteValue(constImage()->page.x),
3405 AbsoluteValue(constImage()->page.y),
3406 constImage()->page.x < 0 ? true : false,
3407 constImage()->page.y < 0 ? true : false);
3410 // Add a named profile to an image or remove a named profile by
3411 // passing an empty Blob (use default Blob constructor).
3413 // "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3414 void Magick::Image::profile( const std::string name_,
3415 const Magick::Blob &profile_ )
3418 ssize_t result = ProfileImage( image(), name_.c_str(),
3419 (unsigned char *)profile_.data(),
3420 profile_.length(), MagickTrue);
3423 throwImageException();
3426 // Retrieve a named profile from the image.
3428 // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3429 // an existing generic profile name.
3430 Magick::Blob Magick::Image::profile( const std::string name_ ) const
3432 const MagickCore::Image* image = constImage();
3434 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3436 if ( profile != (StringInfo *) NULL)
3437 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3440 Image temp_image = *this;
3441 temp_image.write( &blob, name_ );
3445 void Magick::Image::quality ( const size_t quality_ )
3448 image()->quality = quality_;
3449 options()->quality( quality_ );
3451 size_t Magick::Image::quality ( void ) const
3453 return constImage()->quality;
3456 void Magick::Image::quantizeColors ( const size_t colors_ )
3459 options()->quantizeColors( colors_ );
3461 size_t Magick::Image::quantizeColors ( void ) const
3463 return constOptions()->quantizeColors( );
3466 void Magick::Image::quantizeColorSpace
3467 ( const Magick::ColorspaceType colorSpace_ )
3470 options()->quantizeColorSpace( colorSpace_ );
3472 Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3474 return constOptions()->quantizeColorSpace( );
3477 void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3480 options()->quantizeDither( ditherFlag_ );
3482 bool Magick::Image::quantizeDither ( void ) const
3484 return constOptions()->quantizeDither( );
3487 void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
3490 options()->quantizeTreeDepth( treeDepth_ );
3492 size_t Magick::Image::quantizeTreeDepth ( void ) const
3494 return constOptions()->quantizeTreeDepth( );
3497 void Magick::Image::renderingIntent
3498 ( const Magick::RenderingIntent renderingIntent_ )
3501 image()->rendering_intent = renderingIntent_;
3503 Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3505 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3508 void Magick::Image::resolutionUnits
3509 ( const Magick::ResolutionType resolutionUnits_ )
3512 image()->units = resolutionUnits_;
3513 options()->resolutionUnits( resolutionUnits_ );
3515 Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3517 return constOptions()->resolutionUnits( );
3520 void Magick::Image::scene ( const size_t scene_ )
3523 image()->scene = scene_;
3525 size_t Magick::Image::scene ( void ) const
3527 return constImage()->scene;
3530 std::string Magick::Image::signature ( const bool force_ ) const
3532 Lock( &_imgRef->_mutexLock );
3534 // Re-calculate image signature if necessary
3536 !GetImageProperty(constImage(), "Signature") ||
3537 constImage()->taint )
3539 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3542 const char *property = GetImageProperty(constImage(), "Signature");
3544 return std::string( property );
3547 void Magick::Image::size ( const Geometry &geometry_ )
3550 options()->size( geometry_ );
3551 image()->rows = geometry_.height();
3552 image()->columns = geometry_.width();
3554 Magick::Geometry Magick::Image::size ( void ) const
3556 return Magick::Geometry( constImage()->columns, constImage()->rows );
3560 void Magick::Image::splice( const Geometry &geometry_ )
3562 RectangleInfo spliceInfo = geometry_;
3563 ExceptionInfo exceptionInfo;
3564 GetExceptionInfo( &exceptionInfo );
3565 MagickCore::Image* newImage =
3566 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3567 replaceImage( newImage );
3568 throwException( exceptionInfo );
3569 (void) DestroyExceptionInfo( &exceptionInfo );
3572 // Obtain image statistics. Statistics are normalized to the range of
3573 // 0.0 to 1.0 and are output to the specified ImageStatistics
3575 void Magick::Image::statistics ( ImageStatistics *statistics ) const
3581 ExceptionInfo exceptionInfo;
3582 GetExceptionInfo( &exceptionInfo );
3583 (void) GetImageChannelRange(constImage(),RedChannel,&minimum,&maximum,
3585 statistics->red.minimum=minimum;
3586 statistics->red.maximum=maximum;
3587 (void) GetImageChannelMean(constImage(),RedChannel,
3588 &statistics->red.mean,&statistics->red.standard_deviation,&exceptionInfo);
3589 (void) GetImageChannelKurtosis(constImage(),RedChannel,
3590 &statistics->red.kurtosis,&statistics->red.skewness,&exceptionInfo);
3591 (void) GetImageChannelRange(constImage(),GreenChannel,&minimum,&maximum,
3593 statistics->green.minimum=minimum;
3594 statistics->green.maximum=maximum;
3595 (void) GetImageChannelMean(constImage(),GreenChannel,
3596 &statistics->green.mean,&statistics->green.standard_deviation,
3598 (void) GetImageChannelKurtosis(constImage(),GreenChannel,
3599 &statistics->green.kurtosis,&statistics->green.skewness,&exceptionInfo);
3600 (void) GetImageChannelRange(constImage(),BlueChannel,&minimum,&maximum,
3602 statistics->blue.minimum=minimum;
3603 statistics->blue.maximum=maximum;
3604 (void) GetImageChannelMean(constImage(),BlueChannel,
3605 &statistics->blue.mean,&statistics->blue.standard_deviation,&exceptionInfo);
3606 (void) GetImageChannelKurtosis(constImage(),BlueChannel,
3607 &statistics->blue.kurtosis,&statistics->blue.skewness,&exceptionInfo);
3608 (void) GetImageChannelRange(constImage(),OpacityChannel,&minimum,&maximum,
3610 statistics->alpha.minimum=minimum;
3611 statistics->alpha.maximum=maximum;
3612 (void) GetImageChannelMean(constImage(),OpacityChannel,
3613 &statistics->alpha.mean,&statistics->alpha.standard_deviation,
3615 (void) GetImageChannelKurtosis(constImage(),OpacityChannel,
3616 &statistics->alpha.kurtosis,&statistics->alpha.skewness,&exceptionInfo);
3617 throwException( exceptionInfo );
3618 (void) DestroyExceptionInfo( &exceptionInfo );
3621 // Strip strips an image of all profiles and comments.
3622 void Magick::Image::strip ( void )
3625 StripImage( image() );
3626 throwImageException();
3629 // enabled/disable stroke anti-aliasing
3630 void Magick::Image::strokeAntiAlias ( const bool flag_ )
3633 options()->strokeAntiAlias(flag_);
3635 bool Magick::Image::strokeAntiAlias ( void ) const
3637 return constOptions()->strokeAntiAlias();
3640 // Color to use when drawing object outlines
3641 void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3644 options()->strokeColor(strokeColor_);
3646 Magick::Color Magick::Image::strokeColor ( void ) const
3648 return constOptions()->strokeColor();
3651 // dash pattern for drawing vector objects (default one)
3652 void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3655 options()->strokeDashArray( strokeDashArray_ );
3658 const double* Magick::Image::strokeDashArray ( void ) const
3660 return constOptions()->strokeDashArray( );
3663 // dash offset for drawing vector objects (default one)
3664 void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3667 options()->strokeDashOffset( strokeDashOffset_ );
3670 double Magick::Image::strokeDashOffset ( void ) const
3672 return constOptions()->strokeDashOffset( );
3675 // Specify the shape to be used at the end of open subpaths when they
3676 // are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3678 void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3681 options()->strokeLineCap( lineCap_ );
3683 Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3685 return constOptions()->strokeLineCap( );
3688 // Specify the shape to be used at the corners of paths (or other
3689 // vector shapes) when they are stroked. Values of LineJoin are
3690 // UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3691 void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3694 options()->strokeLineJoin( lineJoin_ );
3696 Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3698 return constOptions()->strokeLineJoin( );
3701 // Specify miter limit. When two line segments meet at a sharp angle
3702 // and miter joins have been specified for 'lineJoin', it is possible
3703 // for the miter to extend far beyond the thickness of the line
3704 // stroking the path. The miterLimit' imposes a limit on the ratio of
3705 // the miter length to the 'lineWidth'. The default value of this
3707 void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
3710 options()->strokeMiterLimit( strokeMiterLimit_ );
3712 size_t Magick::Image::strokeMiterLimit ( void ) const
3714 return constOptions()->strokeMiterLimit( );
3717 // Pattern to use while stroking drawn objects.
3718 void Magick::Image::strokePattern ( const Image &strokePattern_ )
3721 if(strokePattern_.isValid())
3722 options()->strokePattern( strokePattern_.constImage() );
3724 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3726 Magick::Image Magick::Image::strokePattern ( void ) const
3728 // FIXME: This is inordinately innefficient
3731 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3735 ExceptionInfo exceptionInfo;
3736 GetExceptionInfo( &exceptionInfo );
3737 MagickCore::Image* image =
3738 CloneImage( tmpTexture,
3741 MagickTrue, // orphan
3743 throwException( exceptionInfo );
3744 (void) DestroyExceptionInfo( &exceptionInfo );
3745 texture.replaceImage( image );
3750 // Stroke width for drawing lines, circles, ellipses, etc.
3751 void Magick::Image::strokeWidth ( const double strokeWidth_ )
3754 options()->strokeWidth( strokeWidth_ );
3756 double Magick::Image::strokeWidth ( void ) const
3758 return constOptions()->strokeWidth( );
3761 void Magick::Image::subImage ( const size_t subImage_ )
3764 options()->subImage( subImage_ );
3766 size_t Magick::Image::subImage ( void ) const
3768 return constOptions()->subImage( );
3771 void Magick::Image::subRange ( const size_t subRange_ )
3774 options()->subRange( subRange_ );
3776 size_t Magick::Image::subRange ( void ) const
3778 return constOptions()->subRange( );
3781 // Annotation text encoding (e.g. "UTF-16")
3782 void Magick::Image::textEncoding ( const std::string &encoding_ )
3785 options()->textEncoding( encoding_ );
3787 std::string Magick::Image::textEncoding ( void ) const
3789 return constOptions()->textEncoding( );
3792 size_t Magick::Image::totalColors ( void )
3794 ExceptionInfo exceptionInfo;
3795 GetExceptionInfo( &exceptionInfo );
3796 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
3797 throwException( exceptionInfo );
3798 (void) DestroyExceptionInfo( &exceptionInfo );
3802 // Origin of coordinate system to use when annotating with text or drawing
3803 void Magick::Image::transformOrigin ( const double x_, const double y_ )
3806 options()->transformOrigin( x_, y_ );
3809 // Rotation to use when annotating with text or drawing
3810 void Magick::Image::transformRotation ( const double angle_ )
3813 options()->transformRotation( angle_ );
3816 // Reset transformation parameters to default
3817 void Magick::Image::transformReset ( void )
3820 options()->transformReset();
3823 // Scale to use when annotating with text or drawing
3824 void Magick::Image::transformScale ( const double sx_, const double sy_ )
3827 options()->transformScale( sx_, sy_ );
3830 // Skew to use in X axis when annotating with text or drawing
3831 void Magick::Image::transformSkewX ( const double skewx_ )
3834 options()->transformSkewX( skewx_ );
3837 // Skew to use in Y axis when annotating with text or drawing
3838 void Magick::Image::transformSkewY ( const double skewy_ )
3841 options()->transformSkewY( skewy_ );
3844 // Image representation type
3845 Magick::ImageType Magick::Image::type ( void ) const
3848 ExceptionInfo exceptionInfo;
3849 GetExceptionInfo( &exceptionInfo );
3850 ImageType image_type = constOptions()->type();
3851 if ( image_type == UndefinedType )
3852 image_type= GetImageType( constImage(), &exceptionInfo);
3853 throwException( exceptionInfo );
3854 (void) DestroyExceptionInfo( &exceptionInfo );
3857 void Magick::Image::type ( const Magick::ImageType type_)
3860 options()->type( type_ );
3861 SetImageType( image(), type_ );
3864 void Magick::Image::verbose ( const bool verboseFlag_ )
3867 options()->verbose( verboseFlag_ );
3869 bool Magick::Image::verbose ( void ) const
3871 return constOptions()->verbose( );
3874 void Magick::Image::view ( const std::string &view_ )
3877 options()->view( view_ );
3879 std::string Magick::Image::view ( void ) const
3881 return constOptions()->view( );
3884 // Virtual pixel method
3885 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3888 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3889 options()->virtualPixelMethod( virtual_pixel_method_ );
3891 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3893 return GetImageVirtualPixelMethod( constImage() );
3896 void Magick::Image::x11Display ( const std::string &display_ )
3899 options()->x11Display( display_ );
3901 std::string Magick::Image::x11Display ( void ) const
3903 return constOptions()->x11Display( );
3906 double Magick::Image::xResolution ( void ) const
3908 return constImage()->x_resolution;
3910 double Magick::Image::yResolution ( void ) const
3912 return constImage()->y_resolution;
3916 Magick::Image::Image( const Image & image_ )
3917 : _imgRef(image_._imgRef)
3919 Lock( &_imgRef->_mutexLock );
3921 // Increase reference count
3922 ++_imgRef->_refCount;
3925 // Assignment operator
3926 Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3928 if( this != &image_ )
3931 Lock( &image_._imgRef->_mutexLock );
3932 ++image_._imgRef->_refCount;
3935 bool doDelete = false;
3937 Lock( &_imgRef->_mutexLock );
3938 if ( --_imgRef->_refCount == 0 )
3944 // Delete old image reference with associated image and options.
3948 // Use new image reference
3949 _imgRef = image_._imgRef;
3955 //////////////////////////////////////////////////////////////////////
3957 // Low-level Pixel Access Routines
3959 // Also see the Pixels class, which provides support for multiple
3960 // cache views. The low-level pixel access routines in the Image
3961 // class are provided in order to support backward compatability.
3963 //////////////////////////////////////////////////////////////////////
3965 // Transfers read-only pixels from the image to the pixel cache as
3966 // defined by the specified region
3967 const Magick::Quantum* Magick::Image::getConstPixels
3968 ( const ssize_t x_, const ssize_t y_,
3969 const size_t columns_,
3970 const size_t rows_ ) const
3972 ExceptionInfo exceptionInfo;
3973 GetExceptionInfo( &exceptionInfo );
3974 const Quantum* p = (*GetVirtualPixels)( constImage(),
3978 throwException( exceptionInfo );
3979 (void) DestroyExceptionInfo( &exceptionInfo );
3983 // Obtain read-only pixel associated pixels channels
3984 const void* Magick::Image::getConstMetacontent ( void ) const
3986 const void* result = GetVirtualMetacontent( constImage() );
3989 throwImageException();
3994 // Obtain image pixel associated pixels channels
3995 void* Magick::Image::getMetacontent ( void )
3997 void* result = GetAuthenticMetacontent( image() );
4000 throwImageException();
4005 // Transfers pixels from the image to the pixel cache as defined
4006 // by the specified region. Modified pixels may be subsequently
4007 // transferred back to the image via syncPixels.
4008 Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
4009 const size_t columns_,
4010 const size_t rows_ )
4013 ExceptionInfo exceptionInfo;
4014 GetExceptionInfo( &exceptionInfo );
4015 Quantum* result = (*GetAuthenticPixels)( image(),
4017 columns_, rows_, &exceptionInfo );
4018 throwException( exceptionInfo );
4019 (void) DestroyExceptionInfo( &exceptionInfo );
4024 // Allocates a pixel cache region to store image pixels as defined
4025 // by the region rectangle. This area is subsequently transferred
4026 // from the pixel cache to the image via syncPixels.
4027 Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
4028 const size_t columns_,
4029 const size_t rows_ )
4032 ExceptionInfo exceptionInfo;
4033 GetExceptionInfo( &exceptionInfo );
4034 Quantum* result = (*QueueAuthenticPixels)( image(),
4036 columns_, rows_, &exceptionInfo );
4037 throwException( exceptionInfo );
4038 (void) DestroyExceptionInfo( &exceptionInfo );
4043 // Transfers the image cache pixels to the image.
4044 void Magick::Image::syncPixels ( void )
4046 ExceptionInfo exceptionInfo;
4047 GetExceptionInfo( &exceptionInfo );
4048 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4049 throwException( exceptionInfo );
4050 (void) DestroyExceptionInfo( &exceptionInfo );
4053 // Transfers one or more pixel components from a buffer or file
4054 // into the image pixel cache of an image.
4055 // Used to support image decoders.
4056 void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4057 const unsigned char *source_ )
4062 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4063 ExceptionInfo exceptionInfo;
4064 GetExceptionInfo( &exceptionInfo );
4065 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4066 quantum_,source_, &exceptionInfo);
4067 throwException( exceptionInfo );
4068 (void) DestroyExceptionInfo( &exceptionInfo );
4069 quantum_info=DestroyQuantumInfo(quantum_info);
4072 // Transfers one or more pixel components from the image pixel
4073 // cache to a buffer or file.
4074 // Used to support image encoders.
4075 void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4076 unsigned char *destination_ )
4081 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4082 ExceptionInfo exceptionInfo;
4083 GetExceptionInfo( &exceptionInfo );
4084 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4085 quantum_,destination_, &exceptionInfo);
4086 quantum_info=DestroyQuantumInfo(quantum_info);
4087 throwException( exceptionInfo );
4088 (void) DestroyExceptionInfo( &exceptionInfo );
4091 /////////////////////////////////////////////////////////////////////
4093 // No end-user methods beyond this point
4095 /////////////////////////////////////////////////////////////////////
4099 // Construct using existing image and default options
4101 Magick::Image::Image ( MagickCore::Image* image_ )
4102 : _imgRef(new ImageRef( image_))
4106 // Get Magick::Options*
4107 Magick::Options* Magick::Image::options( void )
4109 return _imgRef->options();
4111 const Magick::Options* Magick::Image::constOptions( void ) const
4113 return _imgRef->options();
4116 // Get MagickCore::Image*
4117 MagickCore::Image*& Magick::Image::image( void )
4119 return _imgRef->image();
4121 const MagickCore::Image* Magick::Image::constImage( void ) const
4123 return _imgRef->image();
4127 MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4129 return _imgRef->options()->imageInfo();
4131 const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4133 return _imgRef->options()->imageInfo();
4136 // Get QuantizeInfo *
4137 MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4139 return _imgRef->options()->quantizeInfo();
4141 const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4143 return _imgRef->options()->quantizeInfo();
4147 // Replace current image
4149 MagickCore::Image * Magick::Image::replaceImage
4150 ( MagickCore::Image* replacement_ )
4152 MagickCore::Image* image;
4155 image = replacement_;
4157 image = AcquireImage(constImageInfo());
4160 Lock( &_imgRef->_mutexLock );
4162 if ( _imgRef->_refCount == 1 )
4164 // We own the image, just replace it, and de-register
4166 _imgRef->image(image);
4170 // We don't own the image, dereference and replace with copy
4171 --_imgRef->_refCount;
4172 _imgRef = new ImageRef( image, constOptions() );
4176 return _imgRef->_image;
4180 // Prepare to modify image or image options
4181 // Replace current image and options with copy if reference count > 1
4183 void Magick::Image::modifyImage( void )
4186 Lock( &_imgRef->_mutexLock );
4187 if ( _imgRef->_refCount == 1 )
4189 // De-register image and return
4195 ExceptionInfo exceptionInfo;
4196 GetExceptionInfo( &exceptionInfo );
4197 replaceImage( CloneImage( image(),
4200 MagickTrue, // orphan
4202 throwException( exceptionInfo );
4203 (void) DestroyExceptionInfo( &exceptionInfo );
4208 // Test for an ImageMagick reported error and throw exception if one
4209 // has been reported. Secretly resets image->exception back to default
4210 // state even though this method is const.
4212 void Magick::Image::throwImageException( void ) const
4214 // Throw C++ exception while resetting Image exception to default state
4215 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4218 // Register image with image registry or obtain registration id
4219 ssize_t Magick::Image::registerId( void )
4221 Lock( &_imgRef->_mutexLock );
4222 if( _imgRef->id() < 0 )
4224 char id[MaxTextExtent];
4225 ExceptionInfo exceptionInfo;
4226 GetExceptionInfo( &exceptionInfo );
4227 _imgRef->id(_imgRef->id()+1);
4228 sprintf(id,"%.20g\n",(double) _imgRef->id());
4229 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4230 throwException( exceptionInfo );
4231 (void) DestroyExceptionInfo( &exceptionInfo );
4233 return _imgRef->id();
4236 // Unregister image from image registry
4237 void Magick::Image::unregisterId( void )
4244 // Create a local wrapper around MagickCoreTerminus
4249 void MagickPlusPlusDestroyMagick(void);
4253 void Magick::MagickPlusPlusDestroyMagick(void)
4255 if (magick_initialized)
4257 magick_initialized=false;
4258 MagickCore::MagickCoreTerminus();
4262 // C library initialization routine
4263 void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4265 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4266 if (!magick_initialized)
4267 magick_initialized=true;
4271 // Cleanup class to ensure that ImageMagick singletons are destroyed
4272 // so as to avoid any resemblence to a memory leak (which seems to
4281 MagickCleanUp( void );
4282 ~MagickCleanUp( void );
4285 // The destructor for this object is invoked when the destructors for
4286 // static objects in this translation unit are invoked.
4287 static MagickCleanUp magickCleanUpGuard;
4290 Magick::MagickCleanUp::MagickCleanUp ( void )
4292 // Don't even think about invoking InitializeMagick here!
4295 Magick::MagickCleanUp::~MagickCleanUp ( void )
4297 MagickPlusPlusDestroyMagick();