Magick++  7.1.2-29
Convert, Edit, Or Compose Bitmap Images
Image.cpp
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4 //
5 // Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // Implementation of Image
9 //
10 
11 #define MAGICKCORE_IMPLEMENTATION 1
12 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
13 
14 #include "Magick++/Include.h"
15 #include <cstdlib>
16 #include <string>
17 #include <string.h>
18 #include <errno.h>
19 #include <math.h>
20 
21 #include "Magick++/Image.h"
22 #include "Magick++/Functions.h"
23 #include "Magick++/Pixels.h"
24 #include "Magick++/Options.h"
25 #include "Magick++/ImageRef.h"
26 
27 using namespace std;
28 
29 #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
30 #define MagickPI 3.14159265358979323846264338327950288419716939937510
31 #define DegreesToRadians(x) (MagickPI*(x)/180.0)
32 #define ThrowImageException ThrowPPException(quiet())
33 
34 MagickPPExport const char *Magick::borderGeometryDefault="6x6+0+0";
35 MagickPPExport const char *Magick::frameGeometryDefault="25x25+6+6";
36 MagickPPExport const char *Magick::raiseGeometryDefault="6x6+0+0";
37 
38 MagickPPExport int Magick::operator == (const Magick::Image &left_,
39  const Magick::Image &right_)
40 {
41  // If image pixels and signature are the same, then the image is identical
42  return((left_.rows() == right_.rows()) &&
43  (left_.columns() == right_.columns()) &&
44  (left_.signature() == right_.signature()));
45 }
46 
47 MagickPPExport int Magick::operator != (const Magick::Image &left_,
48  const Magick::Image &right_)
49 {
50  return(!(left_ == right_));
51 }
52 
53 MagickPPExport int Magick::operator > (const Magick::Image &left_,
54  const Magick::Image &right_)
55 {
56  return(!(left_ < right_) && (left_ != right_));
57 }
58 
59 MagickPPExport int Magick::operator < (const Magick::Image &left_,
60  const Magick::Image &right_)
61 {
62  // If image pixels are less, then image is smaller
63  return((left_.rows() * left_.columns()) <
64  (right_.rows() * right_.columns()));
65 }
66 
67 MagickPPExport int Magick::operator >= (const Magick::Image &left_,
68  const Magick::Image &right_)
69 {
70  return((left_ > right_) || (left_ == right_));
71 }
72 
73 MagickPPExport int Magick::operator <= (const Magick::Image &left_,
74  const Magick::Image &right_)
75 {
76  return((left_ < right_) || ( left_ == right_));
77 }
78 
79 Magick::Image::Image(void)
80  : _imgRef(new ImageRef)
81 {
82 }
83 
84 Magick::Image::Image(const Blob &blob_)
85  : _imgRef(new ImageRef)
86 {
87  try
88  {
89  // Initialize, Allocate and Read images
90  quiet(true);
91  read(blob_);
92  quiet(false);
93  }
94  catch (const Error&)
95  {
96  // Release resources
97  delete _imgRef;
98  throw;
99  }
100 }
101 
102 Magick::Image::Image(const Blob &blob_,const Geometry &size_)
103  : _imgRef(new ImageRef)
104 {
105  try
106  {
107  // Read from Blob
108  quiet(true);
109  read(blob_, size_);
110  quiet(false);
111  }
112  catch(const Error&)
113  {
114  // Release resources
115  delete _imgRef;
116  throw;
117  }
118 }
119 
120 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
121  const size_t depth_)
122  : _imgRef(new ImageRef)
123 {
124  try
125  {
126  // Read from Blob
127  quiet(true);
128  read(blob_,size_,depth_);
129  quiet(false);
130  }
131  catch(const Error&)
132  {
133  // Release resources
134  delete _imgRef;
135  throw;
136  }
137 }
138 
139 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
140  const size_t depth_,const std::string &magick_)
141  : _imgRef(new ImageRef)
142 {
143  try
144  {
145  // Read from Blob
146  quiet(true);
147  read(blob_,size_,depth_,magick_);
148  quiet(false);
149  }
150  catch(const Error&)
151  {
152  // Release resources
153  delete _imgRef;
154  throw;
155  }
156 }
157 
158 Magick::Image::Image(const Blob &blob_,const Geometry &size_,
159  const std::string &magick_)
160  : _imgRef(new ImageRef)
161 {
162  try
163  {
164  // Read from Blob
165  quiet(true);
166  read(blob_,size_,magick_);
167  quiet(false);
168  }
169  catch(const Error&)
170  {
171  // Release resources
172  delete _imgRef;
173  throw;
174  }
175 }
176 
177 Magick::Image::Image(const Geometry &size_,const Color &color_)
178  : _imgRef(new ImageRef)
179 {
180  // xc: prefix specifies an X11 color string
181  std::string imageSpec("xc:");
182  imageSpec+=color_;
183 
184  try
185  {
186  quiet(true);
187  // Set image size
188  size(size_);
189 
190  // Initialize, Allocate and Read images
191  read(imageSpec);
192  quiet(false);
193  }
194  catch(const Error&)
195  {
196  // Release resources
197  delete _imgRef;
198  throw;
199  }
200 }
201 
202 Magick::Image::Image(const Image &image_)
203  : _imgRef(image_._imgRef)
204 {
205  _imgRef->increase();
206 }
207 
208 Magick::Image::Image(const Image &image_,const Geometry &geometry_)
209  : _imgRef(new ImageRef)
210 {
211  const RectangleInfo
212  geometry=geometry_;
213 
214  OffsetInfo
215  offset;
216 
217  MagickCore::Image
218  *image;
219 
220  GetPPException;
221  image=CloneImage(image_.constImage(),geometry_.width(),geometry_.height(),
222  MagickTrue,exceptionInfo);
223  replaceImage(image);
224  _imgRef->options(new Options(*image_.constOptions()));
225  offset.x=0;
226  offset.y=0;
227  (void) CopyImagePixels(image,image_.constImage(),&geometry,&offset,
228  exceptionInfo);
229  ThrowImageException;
230 }
231 
232 Magick::Image::Image(const size_t width_,const size_t height_,
233  const std::string &map_,const StorageType type_,const void *pixels_)
234  : _imgRef(new ImageRef)
235 {
236  try
237  {
238  quiet(true);
239  read(width_,height_,map_.c_str(),type_,pixels_);
240  quiet(false);
241  }
242  catch(const Error&)
243  {
244  // Release resources
245  delete _imgRef;
246  throw;
247  }
248 }
249 
250 Magick::Image::Image(const std::string &imageSpec_)
251  : _imgRef(new ImageRef)
252 {
253  try
254  {
255  // Initialize, Allocate and Read images
256  quiet(true);
257  read(imageSpec_);
258  quiet(false);
259  }
260  catch(const Error&)
261  {
262  // Release resources
263  delete _imgRef;
264  throw;
265  }
266 }
267 
268 Magick::Image::~Image()
269 {
270  try
271  {
272  if (_imgRef->decrease() == 0)
273  delete _imgRef;
274  }
275  catch(Magick::Exception&)
276  {
277  }
278 
279  _imgRef=(Magick::ImageRef *) NULL;
280 }
281 
282 Magick::Image& Magick::Image::operator=(const Magick::Image &image_)
283 {
284  if (this != &image_)
285  {
286  image_._imgRef->increase();
287  if (_imgRef->decrease() == 0)
288  delete _imgRef;
289 
290  // Use new image reference
291  _imgRef=image_._imgRef;
292  }
293  return(*this);
294 }
295 
296 void Magick::Image::adjoin(const bool flag_)
297 {
298  modifyImage();
299  options()->adjoin(flag_);
300 }
301 
302 bool Magick::Image::adjoin(void) const
303 {
304  return(constOptions()->adjoin());
305 }
306 
307 void Magick::Image::alpha(const bool alphaFlag_)
308 {
309  modifyImage();
310 
311  // If matte channel is requested, but image doesn't already have a
312  // matte channel, then create an opaque matte channel. Likewise, if
313  // the image already has a matte channel but a matte channel is not
314  // desired, then set the matte channel to opaque.
315  GetPPException;
316  if (bool(alphaFlag_) != bool(constImage()->alpha_trait))
317  SetImageAlpha(image(),OpaqueAlpha,exceptionInfo);
318  ThrowImageException;
319 
320  image()->alpha_trait=alphaFlag_ ? BlendPixelTrait : UndefinedPixelTrait;
321 }
322 
323 bool Magick::Image::alpha(void) const
324 {
325  if (constImage()->alpha_trait == BlendPixelTrait)
326  return(true);
327  else
328  return(false);
329 }
330 
331 void Magick::Image::matteColor(const Color &matteColor_)
332 {
333  modifyImage();
334 
335  if (matteColor_.isValid())
336  {
337  image()->matte_color=matteColor_;
338  options()->matteColor(matteColor_);
339  }
340  else
341  {
342  // Set to default matte color
343  Color tmpColor("#BDBDBD");
344  image()->matte_color=tmpColor;
345  options()->matteColor(tmpColor);
346  }
347 }
348 
349 Magick::Color Magick::Image::matteColor(void) const
350 {
351  return(Color(constImage()->matte_color));
352 }
353 
354 void Magick::Image::animationDelay(const size_t delay_)
355 {
356  modifyImage();
357  image()->delay=delay_;
358 }
359 
360 size_t Magick::Image::animationDelay(void) const
361 {
362  return(constImage()->delay);
363 }
364 
365 void Magick::Image::animationIterations(const size_t iterations_)
366 {
367  modifyImage();
368  image()->iterations=iterations_;
369 }
370 
371 size_t Magick::Image::animationIterations(void) const
372 {
373  return(constImage()->iterations);
374 }
375 
376 void Magick::Image::backgroundColor(const Color &backgroundColor_)
377 {
378  modifyImage();
379 
380  if (backgroundColor_.isValid())
381  image()->background_color=backgroundColor_;
382  else
383  image()->background_color=Color();
384 
385  options()->backgroundColor(backgroundColor_);
386 }
387 
388 Magick::Color Magick::Image::backgroundColor(void) const
389 {
390  return(constOptions()->backgroundColor());
391 }
392 
393 void Magick::Image::backgroundTexture(const std::string &backgroundTexture_)
394 {
395  modifyImage();
396  options()->backgroundTexture(backgroundTexture_);
397 }
398 
399 std::string Magick::Image::backgroundTexture(void) const
400 {
401  return(constOptions()->backgroundTexture());
402 }
403 
404 size_t Magick::Image::baseColumns(void) const
405 {
406  return(constImage()->magick_columns);
407 }
408 
409 std::string Magick::Image::baseFilename(void) const
410 {
411  return(std::string(constImage()->magick_filename));
412 }
413 
414 size_t Magick::Image::baseRows(void) const
415 {
416  return(constImage()->magick_rows);
417 }
418 
419 void Magick::Image::blackPointCompensation(const bool flag_)
420 {
421  image()->black_point_compensation=(MagickBooleanType) flag_;
422 }
423 
424 bool Magick::Image::blackPointCompensation(void) const
425 {
426  return(static_cast<bool>(constImage()->black_point_compensation));
427 }
428 
429 void Magick::Image::borderColor(const Color &borderColor_)
430 {
431  modifyImage();
432 
433  if (borderColor_.isValid())
434  image()->border_color=borderColor_;
435  else
436  image()->border_color=Color();
437 
438  options()->borderColor(borderColor_);
439 }
440 
441 Magick::Color Magick::Image::borderColor(void) const
442 {
443  return(constOptions()->borderColor());
444 }
445 
446 Magick::Geometry Magick::Image::boundingBox(void) const
447 {
448  RectangleInfo
449  bbox;
450 
451  GetPPException;
452  bbox=GetImageBoundingBox(constImage(),exceptionInfo);
453  ThrowImageException;
454  return(Geometry(bbox));
455 }
456 
457 void Magick::Image::boxColor(const Color &boxColor_)
458 {
459  modifyImage();
460  options()->boxColor(boxColor_);
461 }
462 
463 Magick::Color Magick::Image::boxColor(void) const
464 {
465  return(constOptions()->boxColor());
466 }
467 
468 void Magick::Image::channelDepth(const ChannelType channel_,
469  const size_t depth_)
470 {
471  modifyImage();
472  GetPPException;
473  GetAndSetPPChannelMask(channel_);
474  SetImageDepth(image(),depth_,exceptionInfo);
475  RestorePPChannelMask;
476  ThrowImageException;
477 }
478 
479 size_t Magick::Image::channelDepth(const ChannelType channel_)
480 {
481  size_t
482  channel_depth;
483 
484  GetPPException;
485  GetAndSetPPChannelMask(channel_);
486  channel_depth=GetImageDepth(constImage(),exceptionInfo);
487  RestorePPChannelMask;
488  ThrowImageException;
489  return(channel_depth);
490 }
491 
492 size_t Magick::Image::channels() const
493 {
494  return(constImage()->number_channels);
495 }
496 
497 void Magick::Image::classType(const ClassType class_)
498 {
499  if (classType() == PseudoClass && class_ == DirectClass)
500  {
501  // Use SyncImage to synchronize the DirectClass pixels with the
502  // color map and then set to DirectClass type.
503  modifyImage();
504  GetPPException;
505  SyncImage(image(),exceptionInfo);
506  ThrowImageException;
507  image()->colormap=(PixelInfo *)RelinquishMagickMemory(image()->colormap);
508  image()->storage_class=static_cast<MagickCore::ClassType>(DirectClass);
509  return;
510  }
511 
512  if (classType() == DirectClass && class_ == PseudoClass)
513  {
514  // Quantize to create PseudoClass color map
515  modifyImage();
516  quantizeColors(MaxColormapSize);
517  quantize();
518  image()->storage_class=static_cast<MagickCore::ClassType>(PseudoClass);
519  }
520 }
521 
522 Magick::ClassType Magick::Image::classType(void) const
523 {
524  return static_cast<Magick::ClassType>(constImage()->storage_class);
525 }
526 
527 void Magick::Image::colorFuzz(const double fuzz_)
528 {
529  modifyImage();
530  image()->fuzz=fuzz_;
531  options()->colorFuzz(fuzz_);
532 }
533 
534 double Magick::Image::colorFuzz(void) const
535 {
536  return(constOptions()->colorFuzz());
537 }
538 
539 void Magick::Image::colorMapSize(const size_t entries_)
540 {
541  if (entries_ >MaxColormapSize)
542  throwExceptionExplicit(MagickCore::OptionError,
543  "Colormap entries must not exceed MaxColormapSize");
544 
545  modifyImage();
546  GetPPException;
547  (void) AcquireImageColormap(image(),entries_,exceptionInfo);
548  ThrowImageException;
549 }
550 
551 size_t Magick::Image::colorMapSize(void) const
552 {
553  if (!constImage()->colormap)
554  throwExceptionExplicit(MagickCore::OptionError,
555  "Image does not contain a colormap");
556 
557  return(constImage()->colors);
558 }
559 
560 void Magick::Image::colorSpace(const ColorspaceType colorSpace_)
561 {
562  if (image()->colorspace == colorSpace_)
563  return;
564 
565  modifyImage();
566  GetPPException;
567  TransformImageColorspace(image(),colorSpace_,exceptionInfo);
568  ThrowImageException;
569 }
570 
571 Magick::ColorspaceType Magick::Image::colorSpace(void) const
572 {
573  return (constImage()->colorspace);
574 }
575 
576 void Magick::Image::colorSpaceType(const ColorspaceType colorSpace_)
577 {
578  modifyImage();
579  GetPPException;
580  SetImageColorspace(image(),colorSpace_,exceptionInfo);
581  ThrowImageException;
582  options()->colorspaceType(colorSpace_);
583 }
584 
585 Magick::ColorspaceType Magick::Image::colorSpaceType(void) const
586 {
587  return(constOptions()->colorspaceType());
588 }
589 
590 size_t Magick::Image::columns(void) const
591 {
592  return(constImage()->columns);
593 }
594 
595 void Magick::Image::comment(const std::string &comment_)
596 {
597  modifyImage();
598  GetPPException;
599  SetImageProperty(image(),"Comment",NULL,exceptionInfo);
600  if (comment_.length() > 0)
601  SetImageProperty(image(),"Comment",comment_.c_str(),exceptionInfo);
602  ThrowImageException;
603 }
604 
605 std::string Magick::Image::comment(void) const
606 {
607  const char
608  *value;
609 
610  GetPPException;
611  value=GetImageProperty(constImage(),"Comment",exceptionInfo);
612  ThrowImageException;
613 
614  if (value)
615  return(std::string(value));
616 
617  return(std::string()); // Intentionally no exception
618 }
619 
620 void Magick::Image::compose(const CompositeOperator compose_)
621 {
622  image()->compose=compose_;
623 }
624 
625 Magick::CompositeOperator Magick::Image::compose(void) const
626 {
627  return(constImage()->compose);
628 }
629 
630 void Magick::Image::compressType(const CompressionType compressType_)
631 {
632  modifyImage();
633  image()->compression=compressType_;
634  options()->compressType(compressType_);
635 }
636 
637 Magick::CompressionType Magick::Image::compressType(void) const
638 {
639  return(constImage()->compression);
640 }
641 
642 void Magick::Image::debug(const bool flag_)
643 {
644  modifyImage();
645  options()->debug(flag_);
646 }
647 
648 bool Magick::Image::debug(void) const
649 {
650  return(constOptions()->debug());
651 }
652 
653 void Magick::Image::density(const Point &density_)
654 {
655  modifyImage();
656  options()->density(density_);
657  if (density_.isValid())
658  {
659  image()->resolution.x=density_.x();
660  if (density_.y() != 0.0)
661  image()->resolution.y=density_.y();
662  else
663  image()->resolution.y=density_.x();
664  }
665  else
666  {
667  // Reset to default
668  image()->resolution.x=0.0;
669  image()->resolution.y=0.0;
670  }
671 }
672 
673 Magick::Point Magick::Image::density(void) const
674 {
675  if (isValid())
676  {
677  double
678  x_resolution=72,
679  y_resolution=72;
680 
681  if (constImage()->resolution.x > 0.0)
682  x_resolution=constImage()->resolution.x;
683 
684  if (constImage()->resolution.y > 0.0)
685  y_resolution=constImage()->resolution.y;
686 
687  return(Point(x_resolution, y_resolution));
688  }
689 
690  return(constOptions()->density());
691 }
692 
693 void Magick::Image::depth(const size_t depth_)
694 {
695  modifyImage();
696  image()->depth=depth_;
697  options()->depth(depth_);
698 }
699 
700 size_t Magick::Image::depth(void) const
701 {
702  return(constImage()->depth);
703 }
704 
705 std::string Magick::Image::directory(void) const
706 {
707  if (constImage()->directory)
708  return(std::string(constImage()->directory));
709 
710  if (!quiet())
711  throwExceptionExplicit(MagickCore::CorruptImageWarning,
712  "Image does not contain a directory");
713 
714  return(std::string());
715 }
716 
717 void Magick::Image::endian(const Magick::EndianType endian_)
718 {
719  modifyImage();
720  options()->endian(endian_);
721  image()->endian=endian_;
722 }
723 
724 Magick::EndianType Magick::Image::endian(void) const
725 {
726  return(constImage()->endian);
727 }
728 
729 void Magick::Image::exifProfile(const Magick::Blob &exifProfile_)
730 {
731  modifyImage();
732 
733  if (exifProfile_.data() != 0)
734  {
735  StringInfo
736  *exif_profile;
737 
738  exif_profile=AcquireStringInfo(exifProfile_.length());
739  SetStringInfoDatum(exif_profile,(unsigned char *) exifProfile_.data());
740  GetPPException;
741  (void) SetImageProfile(image(),"exif",exif_profile,exceptionInfo);
742  exif_profile=DestroyStringInfo(exif_profile);
743  ThrowImageException;
744  }
745 }
746 
747 Magick::Blob Magick::Image::exifProfile(void) const
748 {
749  const StringInfo
750  *exif_profile;
751 
752  exif_profile=GetImageProfile(constImage(),"exif");
753  if (exif_profile == (StringInfo *) NULL)
754  return(Blob());
755  return(Blob(GetStringInfoDatum(exif_profile),
756  GetStringInfoLength(exif_profile)));
757 }
758 
759 void Magick::Image::fileName(const std::string &fileName_)
760 {
761  ssize_t
762  max_length;
763 
764  modifyImage();
765 
766  max_length=sizeof(image()->filename)-1;
767  fileName_.copy(image()->filename,(size_t) max_length);
768  if ((ssize_t) fileName_.length() > max_length)
769  image()->filename[max_length]=0;
770  else
771  image()->filename[fileName_.length()]=0;
772 
773  options()->fileName(fileName_);
774 }
775 
776 std::string Magick::Image::fileName(void) const
777 {
778  return(constOptions()->fileName());
779 }
780 
781 MagickCore::MagickSizeType Magick::Image::fileSize(void) const
782 {
783  return(GetBlobSize(constImage()));
784 }
785 
786 void Magick::Image::fillColor(const Magick::Color &fillColor_)
787 {
788  modifyImage();
789  options()->fillColor(fillColor_);
790 }
791 
792 Magick::Color Magick::Image::fillColor(void) const
793 {
794  return(constOptions()->fillColor());
795 }
796 
797 void Magick::Image::fillRule(const Magick::FillRule &fillRule_)
798 {
799  modifyImage();
800  options()->fillRule(fillRule_);
801 }
802 
803 Magick::FillRule Magick::Image::fillRule(void) const
804 {
805  return constOptions()->fillRule();
806 }
807 
808 void Magick::Image::fillPattern(const Image &fillPattern_)
809 {
810  modifyImage();
811  if (fillPattern_.isValid())
812  options()->fillPattern(fillPattern_.constImage());
813  else
814  options()->fillPattern(static_cast<MagickCore::Image*>(NULL));
815 }
816 
817 Magick::Image Magick::Image::fillPattern(void) const
818 {
819  // FIXME: This is inordinately inefficient
820  const MagickCore::Image
821  *tmpTexture;
822 
823  Image
824  texture;
825 
826  tmpTexture=constOptions()->fillPattern();
827 
828  if (tmpTexture)
829  {
830  MagickCore::Image
831  *image;
832 
833  GetPPException;
834  image=CloneImage(tmpTexture,0,0,MagickTrue,exceptionInfo);
835  texture.replaceImage(image);
836  ThrowImageException;
837  }
838  return(texture);
839 }
840 
841 void Magick::Image::filterType(const Magick::FilterType filterType_)
842 {
843  modifyImage();
844  image()->filter=filterType_;
845 }
846 
847 Magick::FilterType Magick::Image::filterType(void) const
848 {
849  return(constImage()->filter);
850 }
851 
852 void Magick::Image::font(const std::string &font_)
853 {
854  modifyImage();
855  options()->font(font_);
856 }
857 
858 std::string Magick::Image::font(void) const
859 {
860  return(constOptions()->font());
861 }
862 
863 void Magick::Image::fontFamily(const std::string &family_)
864 {
865  modifyImage();
866  options()->fontFamily(family_);
867 }
868 
869 std::string Magick::Image::fontFamily(void) const
870 {
871  return(constOptions()->fontFamily());
872 }
873 
874 void Magick::Image::fontPointsize(const double pointSize_)
875 {
876  modifyImage();
877  options()->fontPointsize(pointSize_);
878 }
879 
880 double Magick::Image::fontPointsize(void) const
881 {
882  return(constOptions()->fontPointsize());
883 }
884 
885 void Magick::Image::fontStyle(const StyleType pointSize_)
886 {
887  modifyImage();
888  options()->fontStyle(pointSize_);
889 }
890 
891 Magick::StyleType Magick::Image::fontStyle(void) const
892 {
893  return(constOptions()->fontStyle());
894 }
895 
896 void Magick::Image::fontWeight(const size_t weight_)
897 {
898  modifyImage();
899  options()->fontWeight(weight_);
900 }
901 
902 size_t Magick::Image::fontWeight(void) const
903 {
904  return(constOptions()->fontWeight());
905 }
906 
907 std::string Magick::Image::format(void) const
908 {
909  const MagickInfo
910  *magick_info;
911 
912  GetPPException;
913  magick_info=GetMagickInfo(constImage()->magick,exceptionInfo);
914  ThrowImageException;
915 
916  if ((magick_info != 0) && (*magick_info->description != '\0'))
917  return(std::string(magick_info->description));
918 
919  if (!quiet())
920  throwExceptionExplicit(MagickCore::CorruptImageWarning,
921  "Unrecognized image magick type");
922 
923  return(std::string());
924 }
925 
926 std::string Magick::Image::formatExpression(const std::string expression)
927 {
928  char
929  *text;
930 
931  std::string
932  text_string;
933 
934  GetPPException;
935  modifyImage();
936  text=InterpretImageProperties(imageInfo(),image(),expression.c_str(),
937  exceptionInfo);
938  if (text != (char *) NULL)
939  {
940  text_string=std::string(text);
941  text=DestroyString(text);
942  }
943  ThrowImageException;
944  return(text_string);
945 }
946 
947 double Magick::Image::gamma(void) const
948 {
949  return(constImage()->gamma);
950 }
951 
952 Magick::Geometry Magick::Image::geometry(void) const
953 {
954  if (constImage()->geometry)
955  return Geometry(constImage()->geometry);
956 
957  if (!quiet())
958  throwExceptionExplicit(MagickCore::OptionWarning,
959  "Image does not contain a geometry");
960 
961  return(Geometry());
962 }
963 
964 void Magick::Image::gifDisposeMethod(
965  const MagickCore::DisposeType disposeMethod_)
966 {
967  modifyImage();
968  image()->dispose=disposeMethod_;
969 }
970 
971 MagickCore::DisposeType Magick::Image::gifDisposeMethod(void) const
972 {
973  return(constImage()->dispose);
974 }
975 
976 bool Magick::Image::hasChannel(const PixelChannel channel) const
977 {
978  if (GetPixelChannelTraits(constImage(),channel) == UndefinedPixelTrait)
979  return(false);
980 
981  if (channel == GreenPixelChannel || channel == BluePixelChannel)
982  return (GetPixelChannelOffset(constImage(),channel) == (ssize_t)channel);
983 
984  return(true);
985 }
986 
987 void Magick::Image::highlightColor(const Color color_)
988 {
989  std::string
990  value;
991 
992  value=color_;
993  artifact("compare:highlight-color",value);
994 }
995 
996 void Magick::Image::iccColorProfile(const Magick::Blob &colorProfile_)
997 {
998  profile("icc",colorProfile_);
999 }
1000 
1001 Magick::Blob Magick::Image::iccColorProfile(void) const
1002 {
1003  const StringInfo
1004  *color_profile;
1005 
1006  color_profile=GetImageProfile(constImage(),"icc");
1007  if (color_profile == (StringInfo *) NULL)
1008  return(Blob());
1009  return(Blob(GetStringInfoDatum(color_profile),GetStringInfoLength(
1010  color_profile)));
1011 }
1012 
1013 void Magick::Image::interlaceType(const Magick::InterlaceType interlace_)
1014 {
1015  modifyImage();
1016  image()->interlace=interlace_;
1017  options()->interlaceType(interlace_);
1018 }
1019 
1020 Magick::InterlaceType Magick::Image::interlaceType(void) const
1021 {
1022  return(constImage()->interlace);
1023 }
1024 
1025 void Magick::Image::interpolate(const PixelInterpolateMethod interpolate_)
1026 {
1027  modifyImage();
1028  image()->interpolate=interpolate_;
1029 }
1030 
1031 Magick::PixelInterpolateMethod Magick::Image::interpolate(void) const
1032 {
1033  return constImage()->interpolate;
1034 }
1035 
1036 void Magick::Image::iptcProfile(const Magick::Blob &iptcProfile_)
1037 {
1038  modifyImage();
1039  if (iptcProfile_.data() != 0)
1040  {
1041  StringInfo
1042  *iptc_profile;
1043 
1044  iptc_profile=AcquireStringInfo(iptcProfile_.length());
1045  SetStringInfoDatum(iptc_profile,(unsigned char *) iptcProfile_.data());
1046  GetPPException;
1047  (void) SetImageProfile(image(),"iptc",iptc_profile,exceptionInfo);
1048  iptc_profile=DestroyStringInfo(iptc_profile);
1049  ThrowImageException;
1050  }
1051 }
1052 
1053 Magick::Blob Magick::Image::iptcProfile(void) const
1054 {
1055  const StringInfo
1056  *iptc_profile;
1057 
1058  iptc_profile=GetImageProfile(constImage(),"iptc");
1059  if (iptc_profile == (StringInfo *) NULL)
1060  return(Blob());
1061  return(Blob(GetStringInfoDatum(iptc_profile),GetStringInfoLength(
1062  iptc_profile)));
1063 }
1064 
1065 bool Magick::Image::isOpaque(void) const
1066 {
1067  MagickBooleanType
1068  result;
1069 
1070  GetPPException;
1071  result=IsImageOpaque(constImage(),exceptionInfo);
1072  ThrowImageException;
1073  return(result != MagickFalse ? true : false);
1074 }
1075 
1076 void Magick::Image::isValid(const bool isValid_)
1077 {
1078  if (!isValid_)
1079  {
1080  delete _imgRef;
1081  _imgRef=new ImageRef;
1082  }
1083  else if (!isValid())
1084  {
1085  // Construct with single-pixel black image to make
1086  // image valid. This is an obvious hack.
1087  size(Geometry(1,1));
1088  read("xc:black");
1089  }
1090 }
1091 
1092 bool Magick::Image::isValid(void) const
1093 {
1094  return rows() && columns();
1095 }
1096 
1097 void Magick::Image::label(const std::string &label_)
1098 {
1099  modifyImage();
1100  GetPPException;
1101  (void) SetImageProperty(image(),"Label",NULL,exceptionInfo);
1102  if (label_.length() > 0)
1103  (void) SetImageProperty(image(),"Label",label_.c_str(),exceptionInfo);
1104  ThrowImageException;
1105 }
1106 
1107 std::string Magick::Image::label(void) const
1108 {
1109  const char
1110  *value;
1111 
1112  GetPPException;
1113  value=GetImageProperty(constImage(),"Label",exceptionInfo);
1114  ThrowImageException;
1115 
1116  if (value)
1117  return(std::string(value));
1118 
1119  return(std::string());
1120 }
1121 
1122 void Magick::Image::lowlightColor(const Color color_)
1123 {
1124  std::string
1125  value;
1126 
1127  value=color_;
1128  artifact("compare:lowlight-color",value);
1129 }
1130 
1131 void Magick::Image::magick(const std::string &magick_)
1132 {
1133  size_t
1134  length;
1135 
1136  modifyImage();
1137 
1138  length=sizeof(image()->magick)-1;
1139  if (magick_.length() < length)
1140  length=magick_.length();
1141 
1142  if (!magick_.empty())
1143  magick_.copy(image()->magick,length);
1144  image()->magick[length]=0;
1145 
1146  options()->magick(magick_);
1147 }
1148 
1149 std::string Magick::Image::magick(void) const
1150 {
1151  if (*(constImage()->magick) != '\0')
1152  return(std::string(constImage()->magick));
1153 
1154  return(constOptions()->magick());
1155 }
1156 
1157 void Magick::Image::masklightColor(const Color color_)
1158 {
1159  std::string
1160  value;
1161 
1162  value=color_;
1163  artifact("compare:masklight-color",value);
1164 }
1165 
1166 double Magick::Image::meanErrorPerPixel(void) const
1167 {
1168  return(constImage()->error.mean_error_per_pixel);
1169 }
1170 
1171 void Magick::Image::modulusDepth(const size_t depth_)
1172 {
1173  modifyImage();
1174  GetPPException;
1175  SetImageDepth(image(),depth_,exceptionInfo);
1176  ThrowImageException;
1177  options()->depth(depth_);
1178 }
1179 
1180 size_t Magick::Image::modulusDepth(void) const
1181 {
1182  size_t
1183  depth;
1184 
1185  GetPPException;
1186  depth=GetImageDepth(constImage(),exceptionInfo);
1187  ThrowImageException;
1188  return(depth);
1189 }
1190 
1191 void Magick::Image::monochrome(const bool monochromeFlag_)
1192 {
1193  modifyImage();
1194  options()->monochrome(monochromeFlag_);
1195 }
1196 
1197 bool Magick::Image::monochrome(void) const
1198 {
1199  return(constOptions()->monochrome());
1200 }
1201 
1202 Magick::Geometry Magick::Image::montageGeometry(void) const
1203 {
1204  if (constImage()->montage)
1205  return Magick::Geometry(constImage()->montage);
1206 
1207  if (!quiet())
1208  throwExceptionExplicit(MagickCore::CorruptImageWarning,
1209  "Image does not contain a montage");
1210 
1211  return(Magick::Geometry());
1212 }
1213 
1214 double Magick::Image::normalizedMaxError(void) const
1215 {
1216  return(constImage()->error.normalized_maximum_error);
1217 }
1218 
1219 double Magick::Image::normalizedMeanError(void) const
1220 {
1221  return(constImage()->error.normalized_mean_error);
1222 }
1223 
1224 void Magick::Image::orientation(const Magick::OrientationType orientation_)
1225 {
1226  modifyImage();
1227  image()->orientation=orientation_;
1228 }
1229 
1230 Magick::OrientationType Magick::Image::orientation(void) const
1231 {
1232  return(constImage()->orientation);
1233 }
1234 
1235 void Magick::Image::page(const Magick::Geometry &pageSize_)
1236 {
1237  modifyImage();
1238  options()->page(pageSize_);
1239  image()->page=pageSize_;
1240 }
1241 
1242 Magick::Geometry Magick::Image::page(void) const
1243 {
1244  return(Geometry(constImage()->page.width,constImage()->page.height,
1245  constImage()->page.x,constImage()->page.y));
1246 }
1247 
1248 void Magick::Image::quality(const size_t quality_)
1249 {
1250  modifyImage();
1251  image()->quality=quality_;
1252  options()->quality(quality_);
1253 }
1254 
1255 size_t Magick::Image::quality(void) const
1256 {
1257  return(constImage()->quality);
1258 }
1259 
1260 void Magick::Image::quantizeColors(const size_t colors_)
1261 {
1262  modifyImage();
1263  options()->quantizeColors(colors_);
1264 }
1265 
1266 size_t Magick::Image::quantizeColors(void) const
1267 {
1268  return(constOptions()->quantizeColors());
1269 }
1270 
1271 void Magick::Image::quantizeColorSpace(
1272  const Magick::ColorspaceType colorSpace_)
1273 {
1274  modifyImage();
1275  options()->quantizeColorSpace(colorSpace_);
1276 }
1277 
1278 Magick::ColorspaceType Magick::Image::quantizeColorSpace(void) const
1279 {
1280  return(constOptions()->quantizeColorSpace());
1281 }
1282 
1283 void Magick::Image::quantizeDither(const bool ditherFlag_)
1284 {
1285  modifyImage();
1286  options()->quantizeDither(ditherFlag_);
1287 }
1288 
1289 bool Magick::Image::quantizeDither(void) const
1290 {
1291  return(constOptions()->quantizeDither());
1292 }
1293 
1294 void Magick::Image::quantizeDitherMethod(const DitherMethod ditherMethod_)
1295 {
1296  modifyImage();
1297  options()->quantizeDitherMethod(ditherMethod_);
1298 }
1299 
1300 MagickCore::DitherMethod Magick::Image::quantizeDitherMethod(void) const
1301 {
1302  return(constOptions()->quantizeDitherMethod());
1303 }
1304 
1305 void Magick::Image::quantizeTreeDepth(const size_t treeDepth_)
1306 {
1307  modifyImage();
1308  options()->quantizeTreeDepth(treeDepth_);
1309 }
1310 
1311 size_t Magick::Image::quantizeTreeDepth() const
1312 {
1313  return(constOptions()->quantizeTreeDepth());
1314 }
1315 
1316 void Magick::Image::quiet(const bool quiet_)
1317 {
1318  modifyImage();
1319  options()->quiet(quiet_);
1320 }
1321 
1322 bool Magick::Image::quiet(void) const
1323 {
1324  return(constOptions()->quiet());
1325 }
1326 
1327 void Magick::Image::renderingIntent(
1328  const Magick::RenderingIntent renderingIntent_)
1329 {
1330  modifyImage();
1331  image()->rendering_intent=renderingIntent_;
1332 }
1333 
1334 Magick::RenderingIntent Magick::Image::renderingIntent(void) const
1335 {
1336  return(static_cast<Magick::RenderingIntent>(constImage()->rendering_intent));
1337 }
1338 
1339 void Magick::Image::resolutionUnits(
1340  const Magick::ResolutionType resolutionUnits_)
1341 {
1342  modifyImage();
1343  image()->units=resolutionUnits_;
1344  options()->resolutionUnits(resolutionUnits_);
1345 }
1346 
1347 Magick::ResolutionType Magick::Image::resolutionUnits(void) const
1348 {
1349  return(static_cast<Magick::ResolutionType>(constImage()->units));
1350 }
1351 
1352 size_t Magick::Image::rows(void) const
1353 {
1354  return(constImage()->rows);
1355 }
1356 
1357 void Magick::Image::samplingFactor(const std::string &samplingFactor_)
1358 {
1359  modifyImage();
1360  options()->samplingFactor(samplingFactor_);
1361 }
1362 
1363 std::string Magick::Image::samplingFactor(void) const
1364 {
1365  return(constOptions()->samplingFactor());
1366 }
1367 
1368 void Magick::Image::scene(const size_t scene_)
1369 {
1370  modifyImage();
1371  image()->scene=scene_;
1372 }
1373 
1374 size_t Magick::Image::scene(void) const
1375 {
1376  return(constImage()->scene);
1377 }
1378 
1379 void Magick::Image::size(const Geometry &geometry_)
1380 {
1381  modifyImage();
1382  options()->size(geometry_);
1383  image()->rows=geometry_.height();
1384  image()->columns=geometry_.width();
1385 }
1386 
1387 Magick::Geometry Magick::Image::size(void) const
1388 {
1389  return(Magick::Geometry(constImage()->columns,constImage()->rows));
1390 }
1391 
1392 void Magick::Image::strokeAntiAlias(const bool flag_)
1393 {
1394  modifyImage();
1395  options()->strokeAntiAlias(flag_);
1396 }
1397 
1398 bool Magick::Image::strokeAntiAlias(void) const
1399 {
1400  return(constOptions()->strokeAntiAlias());
1401 }
1402 
1403 void Magick::Image::strokeColor(const Magick::Color &strokeColor_)
1404 {
1405  std::string
1406  value;
1407 
1408  modifyImage();
1409  options()->strokeColor(strokeColor_);
1410  value=strokeColor_;
1411  artifact("stroke",value);
1412 }
1413 
1414 Magick::Color Magick::Image::strokeColor(void) const
1415 {
1416  return(constOptions()->strokeColor());
1417 }
1418 
1419 void Magick::Image::strokeDashArray(const double *strokeDashArray_)
1420 {
1421  modifyImage();
1422  options()->strokeDashArray(strokeDashArray_);
1423 }
1424 
1425 const double* Magick::Image::strokeDashArray(void) const
1426 {
1427  return(constOptions()->strokeDashArray());
1428 }
1429 
1430 void Magick::Image::strokeDashOffset(const double strokeDashOffset_)
1431 {
1432  modifyImage();
1433  options()->strokeDashOffset(strokeDashOffset_);
1434 }
1435 
1436 double Magick::Image::strokeDashOffset(void) const
1437 {
1438  return(constOptions()->strokeDashOffset());
1439 }
1440 
1441 void Magick::Image::strokeLineCap(const Magick::LineCap lineCap_)
1442 {
1443  modifyImage();
1444  options()->strokeLineCap(lineCap_);
1445 }
1446 
1447 Magick::LineCap Magick::Image::strokeLineCap(void) const
1448 {
1449  return(constOptions()->strokeLineCap());
1450 }
1451 
1452 void Magick::Image::strokeLineJoin(const Magick::LineJoin lineJoin_)
1453 {
1454  modifyImage();
1455  options()->strokeLineJoin(lineJoin_);
1456 }
1457 
1458 Magick::LineJoin Magick::Image::strokeLineJoin(void) const
1459 {
1460  return(constOptions()->strokeLineJoin());
1461 }
1462 
1463 void Magick::Image::strokeMiterLimit(const size_t strokeMiterLimit_)
1464 {
1465  modifyImage();
1466  options()->strokeMiterLimit(strokeMiterLimit_);
1467 }
1468 
1469 size_t Magick::Image::strokeMiterLimit(void) const
1470 {
1471  return(constOptions()->strokeMiterLimit());
1472 }
1473 
1474 void Magick::Image::strokePattern(const Image &strokePattern_)
1475 {
1476  modifyImage();
1477  if(strokePattern_.isValid())
1478  options()->strokePattern(strokePattern_.constImage());
1479  else
1480  options()->strokePattern(static_cast<MagickCore::Image*>(NULL));
1481 }
1482 
1483 Magick::Image Magick::Image::strokePattern(void) const
1484 {
1485  // FIXME: This is inordinately inefficient
1486  const MagickCore::Image
1487  *tmpTexture;
1488 
1489  Image
1490  texture;
1491 
1492  tmpTexture=constOptions()->strokePattern();
1493 
1494  if (tmpTexture)
1495  {
1496  MagickCore::Image
1497  *image;
1498 
1499  GetPPException;
1500  image=CloneImage(tmpTexture,0,0,MagickTrue,exceptionInfo);
1501  texture.replaceImage(image);
1502  ThrowImageException;
1503  }
1504  return(texture);
1505 }
1506 
1507 void Magick::Image::strokeWidth(const double strokeWidth_)
1508 {
1509  char
1510  value[MagickPathExtent];
1511 
1512  modifyImage();
1513  options()->strokeWidth(strokeWidth_);
1514  FormatLocaleString(value,MagickPathExtent,"%.17g",strokeWidth_);
1515  (void) SetImageArtifact(image(),"strokewidth",value);
1516 }
1517 
1518 double Magick::Image::strokeWidth(void) const
1519 {
1520  return(constOptions()->strokeWidth());
1521 }
1522 
1523 void Magick::Image::subImage(const size_t subImage_)
1524 {
1525  modifyImage();
1526  options()->subImage(subImage_);
1527 }
1528 
1529 size_t Magick::Image::subImage(void) const
1530 {
1531  return(constOptions()->subImage());
1532 }
1533 
1534 void Magick::Image::subRange(const size_t subRange_)
1535 {
1536  modifyImage();
1537  options()->subRange(subRange_);
1538 }
1539 
1540 size_t Magick::Image::subRange(void) const
1541 {
1542  return(constOptions()->subRange());
1543 }
1544 
1545 void Magick::Image::textAntiAlias(const bool flag_)
1546 {
1547  modifyImage();
1548  options()->textAntiAlias(flag_);
1549 }
1550 
1551 bool Magick::Image::textAntiAlias(void) const
1552 {
1553  return(constOptions()->textAntiAlias());
1554 }
1555 
1556 void Magick::Image::textDirection(DirectionType direction_)
1557 {
1558  modifyImage();
1559  options()->textDirection(direction_);
1560 }
1561 
1562 Magick::DirectionType Magick::Image::textDirection(void) const
1563 {
1564  return(constOptions()->textDirection());
1565 }
1566 
1567 void Magick::Image::textEncoding(const std::string &encoding_)
1568 {
1569  modifyImage();
1570  options()->textEncoding(encoding_);
1571 }
1572 
1573 std::string Magick::Image::textEncoding(void) const
1574 {
1575  return(constOptions()->textEncoding());
1576 }
1577 
1578 void Magick::Image::textGravity(GravityType gravity_)
1579 {
1580  modifyImage();
1581  options()->textGravity(gravity_);
1582 }
1583 
1584 Magick::GravityType Magick::Image::textGravity(void) const
1585 {
1586  return(constOptions()->textGravity());
1587 }
1588 
1589 void Magick::Image::textInterlineSpacing(double spacing_)
1590 {
1591  modifyImage();
1592  options()->textInterlineSpacing(spacing_);
1593 }
1594 
1595 double Magick::Image::textInterlineSpacing(void) const
1596 {
1597  return(constOptions()->textInterlineSpacing());
1598 }
1599 
1600 void Magick::Image::textInterwordSpacing(double spacing_)
1601 {
1602  modifyImage();
1603  options()->textInterwordSpacing(spacing_);
1604 }
1605 
1606 double Magick::Image::textInterwordSpacing(void) const
1607 {
1608  return(constOptions()->textInterwordSpacing());
1609 }
1610 
1611 void Magick::Image::textKerning(double kerning_)
1612 {
1613  modifyImage();
1614  options()->textKerning(kerning_);
1615 }
1616 
1617 double Magick::Image::textKerning(void) const
1618 {
1619  return(constOptions()->textKerning());
1620 }
1621 
1622 void Magick::Image::textUnderColor(const Color &underColor_)
1623 {
1624  modifyImage();
1625  options()->textUnderColor(underColor_);
1626 }
1627 
1628 Magick::Color Magick::Image::textUnderColor(void) const
1629 {
1630  return(constOptions()->textUnderColor());
1631 }
1632 
1633 size_t Magick::Image::totalColors(void) const
1634 {
1635  size_t
1636  colors;
1637 
1638  GetPPException;
1639  colors=GetNumberColors(constImage(),(FILE *) NULL,exceptionInfo);
1640  ThrowImageException;
1641  return colors;
1642 }
1643 
1644 void Magick::Image::transformRotation(const double angle_)
1645 {
1646  modifyImage();
1647  options()->transformRotation(angle_);
1648 }
1649 
1650 void Magick::Image::transformSkewX(const double skewx_)
1651 {
1652  modifyImage();
1653  options()->transformSkewX(skewx_);
1654 }
1655 
1656 void Magick::Image::transformSkewY(const double skewy_)
1657 {
1658  modifyImage();
1659  options()->transformSkewY(skewy_);
1660 }
1661 
1662 Magick::ImageType Magick::Image::type(void) const
1663 {
1664  if (constOptions()->type() != UndefinedType)
1665  return(constOptions()->type());
1666  return(GetImageType(constImage()));
1667 }
1668 
1669 void Magick::Image::type(const Magick::ImageType type_)
1670 {
1671  modifyImage();
1672  options()->type(type_);
1673  GetPPException;
1674  SetImageType(image(),type_,exceptionInfo);
1675  ThrowImageException;
1676 }
1677 
1678 void Magick::Image::verbose(const bool verboseFlag_)
1679 {
1680  modifyImage();
1681  options()->verbose(verboseFlag_);
1682 }
1683 
1684 bool Magick::Image::verbose(void) const
1685 {
1686  return(constOptions()->verbose());
1687 }
1688 
1689 void Magick::Image::virtualPixelMethod(
1690  const VirtualPixelMethod virtualPixelMethod_)
1691 {
1692  modifyImage();
1693  GetPPException;
1694  SetImageVirtualPixelMethod(image(),virtualPixelMethod_,exceptionInfo);
1695  ThrowImageException;
1696 }
1697 
1698 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod(void) const
1699 {
1700  return(GetImageVirtualPixelMethod(constImage()));
1701 }
1702 
1703 void Magick::Image::x11Display(const std::string &display_)
1704 {
1705  modifyImage();
1706  options()->x11Display(display_);
1707 }
1708 
1709 std::string Magick::Image::x11Display(void) const
1710 {
1711  return(constOptions()->x11Display());
1712 }
1713 
1714 double Magick::Image::xResolution(void) const
1715 {
1716  return(constImage()->resolution.x);
1717 }
1718 
1719 double Magick::Image::yResolution(void) const
1720 {
1721  return(constImage()->resolution.y);
1722 }
1723 
1724 void Magick::Image::adaptiveBlur(const double radius_,const double sigma_)
1725 {
1726  MagickCore::Image
1727  *newImage;
1728 
1729  GetPPException;
1730  newImage=AdaptiveBlurImage(constImage(),radius_,sigma_,exceptionInfo);
1731  replaceImage(newImage);
1732  ThrowImageException;
1733 }
1734 
1735 void Magick::Image::adaptiveResize(const Geometry &geometry_)
1736 {
1737  MagickCore::Image
1738  *newImage;
1739 
1740  size_t
1741  height=rows(),
1742  width=columns();
1743 
1744  ssize_t
1745  x=0,
1746  y=0;
1747 
1748  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
1749  &height);
1750 
1751  GetPPException;
1752  newImage=AdaptiveResizeImage(constImage(),width,height,exceptionInfo);
1753  replaceImage(newImage);
1754  ThrowImageException;
1755 }
1756 
1757 void Magick::Image::adaptiveSharpen(const double radius_,const double sigma_)
1758 {
1759  MagickCore::Image
1760  *newImage;
1761 
1762  GetPPException;
1763  newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,exceptionInfo);
1764  replaceImage(newImage);
1765  ThrowImageException;
1766 }
1767 
1768 void Magick::Image::adaptiveSharpenChannel(const ChannelType channel_,
1769  const double radius_,const double sigma_ )
1770 {
1771  MagickCore::Image
1772  *newImage;
1773 
1774  GetPPException;
1775  GetAndSetPPChannelMask(channel_);
1776  newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,exceptionInfo);
1777  RestorePPChannelMask;
1778  replaceImage(newImage);
1779  ThrowImageException;
1780 }
1781 
1782 void Magick::Image::adaptiveThreshold(const size_t width_,const size_t height_,
1783  const double bias_)
1784 {
1785 
1786  MagickCore::Image
1787  *newImage;
1788 
1789  GetPPException;
1790  newImage=AdaptiveThresholdImage(constImage(),width_,height_,bias_,
1791  exceptionInfo);
1792  replaceImage(newImage);
1793  ThrowImageException;
1794 }
1795 
1796 void Magick::Image::addNoise(const NoiseType noiseType_,const double attenuate_)
1797 {
1798  MagickCore::Image
1799  *newImage;
1800 
1801  GetPPException;
1802  newImage=AddNoiseImage(constImage(),noiseType_,attenuate_,exceptionInfo);
1803  replaceImage(newImage);
1804  ThrowImageException;
1805 }
1806 
1807 void Magick::Image::addNoiseChannel(const ChannelType channel_,
1808  const NoiseType noiseType_,const double attenuate_)
1809 {
1810  MagickCore::Image
1811  *newImage;
1812 
1813  GetPPException;
1814  GetAndSetPPChannelMask(channel_);
1815  newImage=AddNoiseImage(constImage(),noiseType_,attenuate_,exceptionInfo);
1816  RestorePPChannelMask;
1817  replaceImage(newImage);
1818  ThrowImageException;
1819 }
1820 
1821 void Magick::Image::affineTransform(const DrawableAffine &affine_)
1822 {
1823  AffineMatrix
1824  _affine;
1825 
1826  MagickCore::Image
1827  *newImage;
1828 
1829  _affine.sx=affine_.sx();
1830  _affine.sy=affine_.sy();
1831  _affine.rx=affine_.rx();
1832  _affine.ry=affine_.ry();
1833  _affine.tx=affine_.tx();
1834  _affine.ty=affine_.ty();
1835 
1836  GetPPException;
1837  newImage=AffineTransformImage(constImage(),&_affine,exceptionInfo);
1838  replaceImage(newImage);
1839  ThrowImageException;
1840 }
1841 
1842 void Magick::Image::alpha(const unsigned int alpha_)
1843 {
1844  modifyImage();
1845  GetPPException;
1846  SetImageAlpha(image(),(Quantum) alpha_,exceptionInfo);
1847  ThrowImageException;
1848 }
1849 
1850 void Magick::Image::alphaChannel(AlphaChannelOption alphaOption_)
1851 {
1852  modifyImage();
1853  GetPPException;
1854  SetImageAlphaChannel(image(),alphaOption_,exceptionInfo);
1855  ThrowImageException;
1856 }
1857 
1858 void Magick::Image::annotate(const std::string &text_,
1859  const Geometry &location_)
1860 {
1861  annotate(text_,location_,NorthWestGravity,0.0);
1862 }
1863 
1864 void Magick::Image::annotate(const std::string &text_,
1865  const Geometry &boundingArea_,const GravityType gravity_)
1866 {
1867  annotate(text_,boundingArea_,gravity_,0.0);
1868 }
1869 
1870 void Magick::Image::annotate(const std::string &text_,
1871  const Geometry &boundingArea_,const GravityType gravity_,
1872  const double degrees_)
1873 {
1874  AffineMatrix
1875  oaffine;
1876 
1877  char
1878  boundingArea[MagickPathExtent];
1879 
1880  DrawInfo
1881  *drawInfo;
1882 
1883  modifyImage();
1884 
1885  drawInfo=options()->drawInfo();
1886  drawInfo->text=DestroyString(drawInfo->text);
1887  drawInfo->text=const_cast<char *>(text_.c_str());
1888  drawInfo->geometry=DestroyString(drawInfo->geometry);
1889 
1890  if (boundingArea_.isValid())
1891  {
1892  if (boundingArea_.width() == 0 || boundingArea_.height() == 0)
1893  {
1894  FormatLocaleString(boundingArea,MagickPathExtent,"%+.20g%+.20g",
1895  (double) boundingArea_.xOff(),(double) boundingArea_.yOff());
1896  }
1897  else
1898  {
1899  (void) CopyMagickString(boundingArea,
1900  std::string(boundingArea_).c_str(), MagickPathExtent);
1901  }
1902  drawInfo->geometry=boundingArea;
1903  }
1904 
1905  drawInfo->gravity=gravity_;
1906 
1907  oaffine=drawInfo->affine;
1908  if (degrees_ != 0.0)
1909  {
1910  AffineMatrix
1911  affine,
1912  current;
1913 
1914  affine.sx=1.0;
1915  affine.rx=0.0;
1916  affine.ry=0.0;
1917  affine.sy=1.0;
1918  affine.tx=0.0;
1919  affine.ty=0.0;
1920 
1921  current=drawInfo->affine;
1922  affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
1923  affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
1924  affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
1925  affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
1926 
1927  drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
1928  drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
1929  drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
1930  drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
1931  drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
1932  +current.tx;
1933  }
1934 
1935  GetPPException;
1936  AnnotateImage(image(),drawInfo,exceptionInfo);
1937 
1938  // Restore original values
1939  drawInfo->affine=oaffine;
1940  drawInfo->text=(char *) NULL;
1941  drawInfo->geometry=(char *) NULL;
1942 
1943  ThrowImageException;
1944 }
1945 
1946 void Magick::Image::annotate(const std::string &text_,
1947  const GravityType gravity_)
1948 {
1949  DrawInfo
1950  *drawInfo;
1951 
1952  modifyImage();
1953 
1954  drawInfo=options()->drawInfo();
1955  drawInfo->text=DestroyString(drawInfo->text);
1956  drawInfo->text=const_cast<char *>(text_.c_str());
1957  drawInfo->gravity=gravity_;
1958 
1959  GetPPException;
1960  AnnotateImage(image(),drawInfo,exceptionInfo);
1961 
1962  drawInfo->gravity=NorthWestGravity;
1963  drawInfo->text=(char *) NULL;
1964 
1965  ThrowImageException;
1966 }
1967 
1968 void Magick::Image::artifact(const std::string &name_,const std::string &value_)
1969 {
1970  modifyImage();
1971  (void) SetImageArtifact(image(),name_.c_str(),value_.c_str());
1972 }
1973 
1974 std::string Magick::Image::artifact(const std::string &name_) const
1975 {
1976  const char
1977  *value;
1978 
1979  value=GetImageArtifact(constImage(),name_.c_str());
1980  if (value)
1981  return(std::string(value));
1982  return(std::string());
1983 }
1984 
1985 void Magick::Image::attribute(const std::string name_,const char *value_)
1986 {
1987  modifyImage();
1988  GetPPException;
1989  SetImageProperty(image(),name_.c_str(),value_,exceptionInfo);
1990  ThrowImageException;
1991 }
1992 
1993 void Magick::Image::attribute(const std::string name_,const std::string value_)
1994 {
1995  modifyImage();
1996  GetPPException;
1997  SetImageProperty(image(),name_.c_str(),value_.c_str(),exceptionInfo);
1998  ThrowImageException;
1999 }
2000 
2001 std::string Magick::Image::attribute(const std::string name_) const
2002 {
2003  const char
2004  *value;
2005 
2006  GetPPException;
2007  value=GetImageProperty(constImage(),name_.c_str(),exceptionInfo);
2008  ThrowImageException;
2009 
2010  if (value)
2011  return(std::string(value));
2012 
2013  return(std::string()); // Intentionally no exception
2014 }
2015 
2016 void Magick::Image::autoGamma(void)
2017 {
2018  modifyImage();
2019  GetPPException;
2020  (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
2021  (void) AutoGammaImage(image(),exceptionInfo);
2022  ThrowImageException;
2023 }
2024 
2025 void Magick::Image::autoGammaChannel(const ChannelType channel_)
2026 {
2027  modifyImage();
2028  GetPPException;
2029  GetAndSetPPChannelMask(channel_);
2030  (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
2031  (void) AutoGammaImage(image(),exceptionInfo);
2032  RestorePPChannelMask;
2033  ThrowImageException;
2034 }
2035 
2036 void Magick::Image::autoLevel(void)
2037 {
2038  modifyImage();
2039  GetPPException;
2040  (void) AutoLevelImage(image(),exceptionInfo);
2041  ThrowImageException;
2042 }
2043 
2044 void Magick::Image::autoLevelChannel(const ChannelType channel_)
2045 {
2046  modifyImage();
2047  GetPPException;
2048  GetAndSetPPChannelMask(channel_);
2049  (void) AutoLevelImage(image(),exceptionInfo);
2050  RestorePPChannelMask;
2051  ThrowImageException;
2052 }
2053 
2054 void Magick::Image::autoOrient(void)
2055 {
2056  MagickCore::Image
2057  *newImage;
2058 
2059  if (image()->orientation == UndefinedOrientation ||
2060  image()->orientation == TopLeftOrientation)
2061  return;
2062 
2063  GetPPException;
2064  newImage=AutoOrientImage(constImage(),image()->orientation,exceptionInfo);
2065  replaceImage(newImage);
2066  ThrowImageException;
2067 }
2068 
2069 void Magick::Image::autoThreshold(const AutoThresholdMethod method_)
2070 {
2071  modifyImage();
2072  GetPPException;
2073  AutoThresholdImage(image(),method_, exceptionInfo);
2074  ThrowImageException;
2075 }
2076 
2077 void Magick::Image::blackThreshold(const std::string &threshold_)
2078 {
2079  modifyImage();
2080  GetPPException;
2081  BlackThresholdImage(image(),threshold_.c_str(),exceptionInfo);
2082  ThrowImageException;
2083 }
2084 
2085 void Magick::Image::blackThresholdChannel(const ChannelType channel_,
2086  const std::string &threshold_)
2087 {
2088  modifyImage();
2089  GetPPException;
2090  GetAndSetPPChannelMask(channel_);
2091  BlackThresholdImage(image(),threshold_.c_str(),exceptionInfo);
2092  RestorePPChannelMask;
2093  ThrowImageException;
2094 }
2095 
2096 void Magick::Image::blueShift(const double factor_)
2097 {
2098  MagickCore::Image
2099  *newImage;
2100 
2101  GetPPException;
2102  newImage=BlueShiftImage(constImage(),factor_,exceptionInfo);
2103  replaceImage(newImage);
2104  ThrowImageException;
2105 }
2106 
2107 void Magick::Image::blur(const double radius_,const double sigma_)
2108 {
2109  MagickCore::Image
2110  *newImage;
2111 
2112  GetPPException;
2113  newImage=BlurImage(constImage(),radius_,sigma_,exceptionInfo);
2114  replaceImage(newImage);
2115  ThrowImageException;
2116 }
2117 
2118 void Magick::Image::blurChannel(const ChannelType channel_,
2119  const double radius_,const double sigma_)
2120 {
2121  MagickCore::Image
2122  *newImage;
2123 
2124  GetPPException;
2125  GetAndSetPPChannelMask(channel_);
2126  newImage=BlurImage(constImage(),radius_,sigma_,exceptionInfo);
2127  RestorePPChannelMask;
2128  replaceImage(newImage);
2129  ThrowImageException;
2130 }
2131 
2132 void Magick::Image::border(const Geometry &geometry_)
2133 {
2134  MagickCore::Image
2135  *newImage;
2136 
2137  RectangleInfo
2138  borderInfo=geometry_;
2139 
2140  GetPPException;
2141  newImage=BorderImage(constImage(),&borderInfo,image()->compose,
2142  exceptionInfo);
2143  replaceImage(newImage);
2144  ThrowImageException;
2145 }
2146 
2147 void Magick::Image::brightnessContrast(const double brightness_,
2148  const double contrast_)
2149 {
2150  modifyImage();
2151  GetPPException;
2152  BrightnessContrastImage(image(),brightness_,contrast_,exceptionInfo);
2153  ThrowImageException;
2154 }
2155 
2156 void Magick::Image::brightnessContrastChannel(const ChannelType channel_,
2157  const double brightness_,const double contrast_)
2158 {
2159  modifyImage();
2160  GetPPException;
2161  GetAndSetPPChannelMask(channel_);
2162  BrightnessContrastImage(image(),brightness_,contrast_,exceptionInfo);
2163  RestorePPChannelMask;
2164  ThrowImageException;
2165 }
2166 
2167 void Magick::Image::cannyEdge(const double radius_,const double sigma_,
2168  const double lowerPercent_,const double upperPercent_)
2169 {
2170  MagickCore::Image
2171  *newImage;
2172 
2173  modifyImage();
2174  GetPPException;
2175  newImage=CannyEdgeImage(constImage(),radius_,sigma_,lowerPercent_,
2176  upperPercent_,exceptionInfo);
2177  replaceImage(newImage);
2178  ThrowImageException;
2179 }
2180 
2181 void Magick::Image::cdl(const std::string &cdl_)
2182 {
2183  modifyImage();
2184  GetPPException;
2185  (void) ColorDecisionListImage(image(),cdl_.c_str(),exceptionInfo);
2186  ThrowImageException;
2187 }
2188 
2189 void Magick::Image::channel(const ChannelType channel_)
2190 {
2191  MagickCore::Image
2192  *newImage;
2193 
2194  GetPPException;
2195  newImage=SeparateImage(constImage(),channel_,exceptionInfo);
2196  replaceImage(newImage);
2197  ThrowImageException;
2198 }
2199 
2200 void Magick::Image::charcoal(const double radius_,const double sigma_)
2201 {
2202  MagickCore::Image
2203  *newImage;
2204 
2205  GetPPException;
2206  newImage=CharcoalImage(image(),radius_,sigma_,exceptionInfo);
2207  replaceImage(newImage);
2208  ThrowImageException;
2209 }
2210 
2211 void Magick::Image::charcoalChannel(const ChannelType channel_,
2212  const double radius_,const double sigma_)
2213 {
2214  MagickCore::Image
2215  *newImage;
2216 
2217  GetPPException;
2218  GetAndSetPPChannelMask(channel_);
2219  newImage=CharcoalImage(image(),radius_,sigma_,exceptionInfo);
2220  RestorePPChannelMask;
2221  replaceImage(newImage);
2222  ThrowImageException;
2223 }
2224 
2225 void Magick::Image::chop(const Geometry &geometry_)
2226 {
2227  MagickCore::Image
2228  *newImage;
2229 
2230  RectangleInfo
2231  chopInfo=geometry_;
2232 
2233  GetPPException;
2234  newImage=ChopImage(image(),&chopInfo,exceptionInfo);
2235  replaceImage(newImage);
2236  ThrowImageException;
2237 }
2238 
2239 void Magick::Image::chromaBluePrimary(const double x_,const double y_,
2240  const double z_)
2241 {
2242  modifyImage();
2243  image()->chromaticity.blue_primary.x=x_;
2244  image()->chromaticity.blue_primary.y=y_;
2245  image()->chromaticity.blue_primary.z=z_;
2246 }
2247 
2248 void Magick::Image::chromaBluePrimary(double *x_,double *y_,double *z_) const
2249 {
2250  *x_=constImage()->chromaticity.blue_primary.x;
2251  *y_=constImage()->chromaticity.blue_primary.y;
2252  *z_=constImage()->chromaticity.blue_primary.z;
2253 }
2254 
2255 void Magick::Image::chromaGreenPrimary(const double x_,const double y_,
2256  const double z_)
2257 {
2258  modifyImage();
2259  image()->chromaticity.green_primary.x=x_;
2260  image()->chromaticity.green_primary.y=y_;
2261  image()->chromaticity.green_primary.z=z_;
2262 }
2263 
2264 void Magick::Image::chromaGreenPrimary(double *x_,double *y_,double *z_) const
2265 {
2266  *x_=constImage()->chromaticity.green_primary.x;
2267  *y_=constImage()->chromaticity.green_primary.y;
2268  *z_=constImage()->chromaticity.green_primary.z;
2269 }
2270 
2271 void Magick::Image::chromaRedPrimary(const double x_,const double y_,
2272  const double z_)
2273 {
2274  modifyImage();
2275  image()->chromaticity.red_primary.x=x_;
2276  image()->chromaticity.red_primary.y=y_;
2277  image()->chromaticity.red_primary.z=z_;
2278 }
2279 
2280 void Magick::Image::chromaRedPrimary(double *x_,double *y_,double *z_) const
2281 {
2282  *x_=constImage()->chromaticity.red_primary.x;
2283  *y_=constImage()->chromaticity.red_primary.y;
2284  *z_=constImage()->chromaticity.red_primary.z;
2285 }
2286 
2287 void Magick::Image::chromaWhitePoint(const double x_,const double y_,
2288  const double z_)
2289 {
2290  modifyImage();
2291  image()->chromaticity.white_point.x=x_;
2292  image()->chromaticity.white_point.y=y_;
2293  image()->chromaticity.white_point.z=z_;
2294 }
2295 
2296 void Magick::Image::chromaWhitePoint(double *x_,double *y_,double *z_) const
2297 {
2298  *x_=constImage()->chromaticity.white_point.x;
2299  *y_=constImage()->chromaticity.white_point.y;
2300  *z_=constImage()->chromaticity.white_point.z;
2301 }
2302 
2303 void Magick::Image::clamp(void)
2304 {
2305  modifyImage();
2306  GetPPException;
2307  ClampImage(image(),exceptionInfo);
2308  ThrowImageException;
2309 }
2310 
2311 void Magick::Image::clampChannel(const ChannelType channel_)
2312 {
2313  modifyImage();
2314  GetPPException;
2315  GetAndSetPPChannelMask(channel_);
2316  ClampImage(image(),exceptionInfo);
2317  RestorePPChannelMask;
2318  ThrowImageException;
2319 }
2320 
2321 void Magick::Image::clip(void)
2322 {
2323  modifyImage();
2324  GetPPException;
2325  ClipImage(image(),exceptionInfo);
2326  ThrowImageException;
2327 }
2328 
2329 void Magick::Image::clipPath(const std::string pathname_,const bool inside_)
2330 {
2331  modifyImage();
2332  GetPPException;
2333  ClipImagePath(image(),pathname_.c_str(),(MagickBooleanType) inside_,
2334  exceptionInfo);
2335  ThrowImageException;
2336 }
2337 
2338 void Magick::Image::clut(const Image &clutImage_,
2339  const PixelInterpolateMethod method)
2340 {
2341  modifyImage();
2342  GetPPException;
2343  ClutImage(image(),clutImage_.constImage(),method,exceptionInfo);
2344  ThrowImageException;
2345 }
2346 
2347 void Magick::Image::clutChannel(const ChannelType channel_,
2348  const Image &clutImage_,const PixelInterpolateMethod method)
2349 {
2350  modifyImage();
2351  GetPPException;
2352  GetAndSetPPChannelMask(channel_);
2353  ClutImage(image(),clutImage_.constImage(),method,exceptionInfo);
2354  RestorePPChannelMask;
2355  ThrowImageException;
2356 }
2357 
2358 void Magick::Image::colorize(const unsigned int alpha_,const Color &penColor_)
2359 {
2360  colorize(alpha_,alpha_,alpha_,penColor_);
2361 }
2362 
2363 void Magick::Image::colorize(const unsigned int alphaRed_,
2364  const unsigned int alphaGreen_,const unsigned int alphaBlue_,
2365  const Color &penColor_)
2366 {
2367  char
2368  blend[MagickPathExtent];
2369 
2370  MagickCore::Image
2371  *newImage;
2372 
2373  PixelInfo
2374  target;
2375 
2376  if (!penColor_.isValid())
2377  throwExceptionExplicit(MagickCore::OptionError,
2378  "Pen color argument is invalid");
2379 
2380  FormatLocaleString(blend,MagickPathExtent,"%u/%u/%u",alphaRed_,alphaGreen_,
2381  alphaBlue_);
2382 
2383  target=static_cast<PixelInfo>(penColor_);
2384  GetPPException;
2385  newImage=ColorizeImage(image(),blend,&target,exceptionInfo);
2386  replaceImage(newImage);
2387  ThrowImageException;
2388 }
2389 
2390 void Magick::Image::colorMap(const size_t index_,const Color &color_)
2391 {
2392  MagickCore::Image
2393  *imageptr;
2394 
2395  imageptr=image();
2396 
2397  if (index_ > (MaxColormapSize-1))
2398  throwExceptionExplicit(MagickCore::OptionError,
2399  "Colormap index must be less than MaxColormapSize");
2400 
2401  if (!color_.isValid())
2402  throwExceptionExplicit(MagickCore::OptionError,
2403  "Color argument is invalid");
2404 
2405  modifyImage();
2406 
2407  // Ensure that colormap size is large enough
2408  if (colorMapSize() < (index_+1))
2409  colorMapSize(index_+1);
2410 
2411  // Set color at index in colormap
2412  (imageptr->colormap)[index_]=color_;
2413 }
2414 
2415 Magick::Color Magick::Image::colorMap(const size_t index_) const
2416 {
2417  if (!constImage()->colormap)
2418  {
2419  throwExceptionExplicit(MagickCore::OptionError,
2420  "Image does not contain a colormap");
2421  return(Color());
2422  }
2423 
2424  if (index_ > constImage()->colors-1)
2425  throwExceptionExplicit(MagickCore::OptionError,"Index out of range");
2426 
2427  return(Magick::Color((constImage()->colormap)[index_]));
2428 }
2429 
2430 void Magick::Image::colorMatrix(const size_t order_,
2431  const double *color_matrix_)
2432 {
2433  KernelInfo
2434  *kernel_info;
2435 
2436  GetPPException;
2437  kernel_info=AcquireKernelInfo((const char *) NULL,exceptionInfo);
2438  if (kernel_info != (KernelInfo *) NULL)
2439  {
2440  kernel_info->width=order_;
2441  kernel_info->height=order_;
2442  kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
2443  order_*sizeof(*kernel_info->values));
2444  if (kernel_info->values != (MagickRealType *) NULL)
2445  {
2446  MagickCore::Image
2447  *newImage;
2448 
2449  for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
2450  kernel_info->values[i]=color_matrix_[i];
2451  newImage=ColorMatrixImage(image(),kernel_info,exceptionInfo);
2452  replaceImage(newImage);
2453  }
2454  kernel_info=DestroyKernelInfo(kernel_info);
2455  }
2456  ThrowImageException;
2457 }
2458 
2459 bool Magick::Image::compare(const Image &reference_) const
2460 {
2461  bool
2462  status;
2463 
2464  Image
2465  ref=reference_;
2466 
2467  GetPPException;
2468  status=static_cast<bool>(IsImagesEqual(constImage(),ref.constImage(),
2469  exceptionInfo));
2470  ThrowImageException;
2471  return(status);
2472 }
2473 
2474 double Magick::Image::compare(const Image &reference_,const MetricType metric_)
2475 {
2476  double
2477  distortion=0.0;
2478 
2479  GetPPException;
2480  GetImageDistortion(image(),reference_.constImage(),metric_,&distortion,
2481  exceptionInfo);
2482  ThrowImageException;
2483  return(distortion);
2484 }
2485 
2486 double Magick::Image::compareChannel(const ChannelType channel_,
2487  const Image &reference_,const MetricType metric_)
2488 {
2489  double
2490  distortion=0.0;
2491 
2492  GetPPException;
2493  GetAndSetPPChannelMask(channel_);
2494  GetImageDistortion(image(),reference_.constImage(),metric_,&distortion,
2495  exceptionInfo);
2496  RestorePPChannelMask;
2497  ThrowImageException;
2498  return(distortion);
2499 }
2500 
2501 Magick::Image Magick::Image::compare(const Image &reference_,
2502  const MetricType metric_,double *distortion)
2503 {
2504  MagickCore::Image
2505  *newImage;
2506 
2507  GetPPException;
2508  newImage=CompareImages(image(),reference_.constImage(),metric_,distortion,
2509  exceptionInfo);
2510  ThrowImageException;
2511  if (newImage == (MagickCore::Image *) NULL)
2512  return(Magick::Image());
2513  else
2514  return(Magick::Image(newImage));
2515 }
2516 
2517 Magick::Image Magick::Image::compareChannel(const ChannelType channel_,
2518  const Image &reference_,const MetricType metric_,double *distortion)
2519 {
2520  MagickCore::Image
2521  *newImage;
2522 
2523  GetPPException;
2524  GetAndSetPPChannelMask(channel_);
2525  newImage=CompareImages(image(),reference_.constImage(),metric_,distortion,
2526  exceptionInfo);
2527  RestorePPChannelMask;
2528  ThrowImageException;
2529  if (newImage == (MagickCore::Image *) NULL)
2530  return(Magick::Image());
2531  else
2532  return(Magick::Image(newImage));
2533 }
2534 
2535 void Magick::Image::composite(const Image &compositeImage_,
2536  const Geometry &offset_,const CompositeOperator compose_)
2537 {
2538  size_t
2539  height=rows(),
2540  width=columns();
2541 
2542  ssize_t
2543  x=offset_.xOff(),
2544  y=offset_.yOff();
2545 
2546  ParseMetaGeometry(static_cast<std::string>(offset_).c_str(),&x,&y,&width,
2547  &height);
2548 
2549  modifyImage();
2550  GetPPException;
2551  CompositeImage(image(),compositeImage_.constImage(),compose_,MagickTrue,
2552  x,y,exceptionInfo);
2553  ThrowImageException;
2554 }
2555 
2556 void Magick::Image::composite(const Image &compositeImage_,
2557  const GravityType gravity_,const CompositeOperator compose_)
2558 {
2559  RectangleInfo
2560  geometry;
2561 
2562  modifyImage();
2563  SetGeometry(compositeImage_.constImage(),&geometry);
2564  GravityAdjustGeometry(columns(),rows(),gravity_,&geometry);
2565 
2566  GetPPException;
2567  CompositeImage(image(),compositeImage_.constImage(),compose_,MagickTrue,
2568  geometry.x,geometry.y,exceptionInfo);
2569  ThrowImageException;
2570 }
2571 
2572 void Magick::Image::composite(const Image &compositeImage_,
2573  const ssize_t xOffset_,const ssize_t yOffset_,
2574  const CompositeOperator compose_)
2575 {
2576  // Image supplied as compositeImage is composited with current image and
2577  // results in updating current image.
2578  modifyImage();
2579  GetPPException;
2580  CompositeImage(image(),compositeImage_.constImage(),compose_,MagickTrue,
2581  xOffset_,yOffset_,exceptionInfo);
2582  ThrowImageException;
2583 }
2584 
2585 void Magick::Image::connectedComponents(const size_t connectivity_)
2586 {
2587  MagickCore::Image
2588  *newImage;
2589 
2590  GetPPException;
2591  newImage=ConnectedComponentsImage(constImage(),connectivity_,
2592  (CCObjectInfo **) NULL,exceptionInfo);
2593  replaceImage(newImage);
2594  ThrowImageException;
2595 }
2596 
2597 void Magick::Image::contrast(const bool sharpen_)
2598 {
2599  modifyImage();
2600  GetPPException;
2601  ContrastImage(image(),(MagickBooleanType) sharpen_,exceptionInfo);
2602  ThrowImageException;
2603 }
2604 
2605 void Magick::Image::contrastStretch(const double blackPoint_,
2606  const double whitePoint_)
2607 {
2608  modifyImage();
2609  GetPPException;
2610  ContrastStretchImage(image(),blackPoint_,whitePoint_,exceptionInfo);
2611  ThrowImageException;
2612 }
2613 
2614 void Magick::Image::contrastStretchChannel(const ChannelType channel_,
2615  const double blackPoint_,const double whitePoint_)
2616 {
2617  modifyImage();
2618  GetPPException;
2619  GetAndSetPPChannelMask(channel_);
2620  ContrastStretchImage(image(),blackPoint_,whitePoint_,exceptionInfo);
2621  RestorePPChannelMask;
2622  ThrowImageException;
2623 }
2624 
2625 void Magick::Image::convolve(const size_t order_,const double *kernel_)
2626 {
2627  KernelInfo
2628  *kernel_info;
2629 
2630  GetPPException;
2631  kernel_info=AcquireKernelInfo((const char *) NULL,exceptionInfo);
2632  kernel_info->width=order_;
2633  kernel_info->height=order_;
2634  kernel_info->x=(ssize_t) (order_-1)/2;
2635  kernel_info->y=(ssize_t) (order_-1)/2;
2636  kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_,
2637  order_*sizeof(*kernel_info->values));
2638  if (kernel_info->values != (MagickRealType *) NULL)
2639  {
2640  MagickCore::Image
2641  *newImage;
2642 
2643  for (ssize_t i=0; i < (ssize_t) (order_*order_); i++)
2644  kernel_info->values[i]=kernel_[i];
2645  newImage=ConvolveImage(image(),kernel_info,exceptionInfo);
2646  replaceImage(newImage);
2647  }
2648  kernel_info=DestroyKernelInfo(kernel_info);
2649  ThrowImageException;
2650 }
2651 
2652 void Magick::Image::copyPixels(const Image &source_,const Geometry &geometry_,
2653  const Offset &offset_)
2654 {
2655  const OffsetInfo
2656  offset=offset_;
2657 
2658  const RectangleInfo
2659  geometry=geometry_;
2660 
2661  GetPPException;
2662  (void) CopyImagePixels(image(),source_.constImage(),&geometry,&offset,
2663  exceptionInfo);
2664  ThrowImageException;
2665 }
2666 
2667 void Magick::Image::crop(const Geometry &geometry_)
2668 {
2669  MagickCore::Image
2670  *newImage;
2671 
2672  RectangleInfo
2673  cropInfo=geometry_;
2674 
2675  GetPPException;
2676  newImage=CropImage(constImage(),&cropInfo,exceptionInfo);
2677  replaceImage(newImage);
2678  ThrowImageException;
2679 }
2680 
2681 void Magick::Image::cycleColormap(const ssize_t amount_)
2682 {
2683  modifyImage();
2684  GetPPException;
2685  CycleColormapImage(image(),amount_,exceptionInfo);
2686  ThrowImageException;
2687 }
2688 
2689 void Magick::Image::decipher(const std::string &passphrase_)
2690 {
2691  modifyImage();
2692  GetPPException;
2693  DecipherImage(image(),passphrase_.c_str(),exceptionInfo);
2694  ThrowImageException;
2695 }
2696 
2697 void Magick::Image::defineSet(const std::string &magick_,
2698  const std::string &key_,bool flag_)
2699 {
2700  std::string
2701  definition;
2702 
2703  modifyImage();
2704  definition=magick_ + ":" + key_;
2705  if (flag_)
2706  (void) SetImageOption(imageInfo(),definition.c_str(),"");
2707  else
2708  DeleteImageOption(imageInfo(),definition.c_str());
2709 }
2710 
2711 bool Magick::Image::defineSet(const std::string &magick_,
2712  const std::string &key_ ) const
2713 {
2714  const char
2715  *option;
2716 
2717  std::string
2718  key;
2719 
2720  key=magick_ + ":" + key_;
2721  option=GetImageOption(constImageInfo(),key.c_str());
2722  if (option)
2723  return(true);
2724  return(false);
2725 }
2726 
2727 void Magick::Image::defineValue(const std::string &magick_,
2728  const std::string &key_,const std::string &value_)
2729 {
2730  std::string
2731  format,
2732  option;
2733 
2734  modifyImage();
2735  format=magick_ + ":" + key_;
2736  option=value_;
2737  (void) SetImageOption(imageInfo(),format.c_str(),option.c_str());
2738 }
2739 
2740 std::string Magick::Image::defineValue(const std::string &magick_,
2741  const std::string &key_) const
2742 {
2743  const char
2744  *option;
2745 
2746  std::string
2747  definition;
2748 
2749  definition=magick_ + ":" + key_;
2750  option=GetImageOption(constImageInfo(),definition.c_str());
2751  if (option)
2752  return(std::string(option));
2753  return(std::string());
2754 }
2755 
2756 void Magick::Image::deskew(const double threshold_)
2757 {
2758  MagickCore::Image
2759  *newImage;
2760 
2761  GetPPException;
2762  newImage=DeskewImage(constImage(),threshold_,exceptionInfo);
2763  replaceImage(newImage);
2764  ThrowImageException;
2765 }
2766 
2767 void Magick::Image::despeckle(void)
2768 {
2769  MagickCore::Image
2770  *newImage;
2771 
2772  GetPPException;
2773  newImage=DespeckleImage(constImage(),exceptionInfo);
2774  replaceImage(newImage);
2775  ThrowImageException;
2776 }
2777 
2778 void Magick::Image::display(void)
2779 {
2780  GetPPException;
2781  DisplayImages(imageInfo(),image(),exceptionInfo);
2782  ThrowImageException;
2783 }
2784 
2785 void Magick::Image::distort(const DistortMethod method_,
2786  const size_t numberArguments_,const double *arguments_,const bool bestfit_)
2787 {
2788  MagickCore::Image
2789  *newImage;
2790 
2791  GetPPException;
2792  newImage=DistortImage(constImage(), method_,numberArguments_,arguments_,
2793  bestfit_ == true ? MagickTrue : MagickFalse,exceptionInfo);
2794  replaceImage(newImage);
2795  ThrowImageException;
2796 }
2797 
2798 void Magick::Image::draw(const Magick::Drawable &drawable_)
2799 {
2800  DrawingWand
2801  *wand;
2802 
2803  modifyImage();
2804 
2805  wand=AcquireDrawingWand(options()->drawInfo(),image());
2806 
2807  if(wand)
2808  {
2809  drawable_.operator()(wand);
2810 
2811  DrawRender(wand);
2812 
2813  ClonePPDrawException(wand);
2814  wand=DestroyDrawingWand(wand);
2815  ThrowPPDrawException(quiet());
2816  }
2817 }
2818 
2819 void Magick::Image::draw(const std::vector<Magick::Drawable> &drawable_)
2820 {
2821  DrawingWand
2822  *wand;
2823 
2824  modifyImage();
2825 
2826  wand= AcquireDrawingWand(options()->drawInfo(),image());
2827 
2828  if(wand)
2829  {
2830  for (std::vector<Magick::Drawable>::const_iterator p = drawable_.begin();
2831  p != drawable_.end(); p++ )
2832  {
2833  p->operator()(wand);
2834  if (DrawGetExceptionType(wand) != MagickCore::UndefinedException)
2835  break;
2836  }
2837 
2838  if (DrawGetExceptionType(wand) == MagickCore::UndefinedException)
2839  DrawRender(wand);
2840 
2841  ClonePPDrawException(wand);
2842  wand=DestroyDrawingWand(wand);
2843  ThrowPPDrawException(quiet());
2844  }
2845 }
2846 
2847 void Magick::Image::edge(const double radius_)
2848 {
2849  MagickCore::Image
2850  *newImage;
2851 
2852  GetPPException;
2853  newImage=EdgeImage(constImage(),radius_,exceptionInfo);
2854  replaceImage(newImage);
2855  ThrowImageException;
2856 }
2857 
2858 void Magick::Image::emboss(const double radius_,const double sigma_)
2859 {
2860  MagickCore::Image
2861  *newImage;
2862 
2863  GetPPException;
2864  newImage=EmbossImage(constImage(),radius_,sigma_,exceptionInfo);
2865  replaceImage(newImage);
2866  ThrowImageException;
2867 }
2868 
2869 void Magick::Image::encipher(const std::string &passphrase_)
2870 {
2871  modifyImage();
2872  GetPPException;
2873  EncipherImage(image(),passphrase_.c_str(),exceptionInfo);
2874  ThrowImageException;
2875 }
2876 
2877 void Magick::Image::enhance(void)
2878 {
2879  MagickCore::Image
2880  *newImage;
2881 
2882  GetPPException;
2883  newImage=EnhanceImage(constImage(),exceptionInfo);
2884  replaceImage(newImage);
2885  ThrowImageException;
2886 }
2887 
2888 void Magick::Image::equalize(void)
2889 {
2890  modifyImage();
2891  GetPPException;
2892  EqualizeImage(image(),exceptionInfo);
2893  ThrowImageException;
2894 }
2895 
2896 void Magick::Image::erase(void)
2897 {
2898  modifyImage();
2899  GetPPException;
2900  (void) SetImageBackgroundColor(image(),exceptionInfo);
2901  ThrowImageException;
2902 }
2903 
2904 void Magick::Image::evaluate(const ChannelType channel_,
2905  const MagickEvaluateOperator operator_,double rvalue_)
2906 {
2907  GetPPException;
2908  GetAndSetPPChannelMask(channel_);
2909  EvaluateImage(image(),operator_,rvalue_,exceptionInfo);
2910  RestorePPChannelMask;
2911  ThrowImageException;
2912 }
2913 
2914 void Magick::Image::evaluate(const ChannelType channel_,
2915  const MagickFunction function_,const size_t number_parameters_,
2916  const double *parameters_)
2917 {
2918  GetPPException;
2919  GetAndSetPPChannelMask(channel_);
2920  FunctionImage(image(),function_,number_parameters_,parameters_,
2921  exceptionInfo);
2922  RestorePPChannelMask;
2923  ThrowImageException;
2924 }
2925 
2926 void Magick::Image::evaluate(const ChannelType channel_,const ssize_t x_,
2927  const ssize_t y_,const size_t columns_,const size_t rows_,
2928  const MagickEvaluateOperator operator_,const double rvalue_)
2929 {
2930  RectangleInfo
2931  geometry;
2932 
2933  MagickCore::Image
2934  *cropImage;
2935 
2936  geometry.width = columns_;
2937  geometry.height = rows_;
2938  geometry.x = x_;
2939  geometry.y = y_;
2940 
2941  GetPPException;
2942  cropImage=CropImage(image(),&geometry,exceptionInfo);
2943  GetAndSetPPChannelMask(channel_);
2944  EvaluateImage(cropImage,operator_,rvalue_,exceptionInfo);
2945  RestorePPChannelMask;
2946  (void) CompositeImage(image(),cropImage,image()->alpha_trait ==
2947  BlendPixelTrait ? OverCompositeOp : CopyCompositeOp,MagickFalse,
2948  geometry.x,geometry.y,exceptionInfo );
2949  cropImage=DestroyImageList(cropImage);
2950  ThrowImageException;
2951 }
2952 
2953 void Magick::Image::extent(const Geometry &geometry_ )
2954 {
2955  MagickCore::Image
2956  *newImage;
2957 
2958  RectangleInfo
2959  extentInfo=geometry_;
2960 
2961  modifyImage();
2962  extentInfo.x=geometry_.xOff();
2963  extentInfo.y=geometry_.yOff();
2964  GetPPException;
2965  newImage=ExtentImage(image(),&extentInfo,exceptionInfo);
2966  replaceImage(newImage);
2967  ThrowImageException;
2968 }
2969 
2970 void Magick::Image::extent(const Geometry &geometry_,
2971  const Color &backgroundColor_)
2972 {
2973  backgroundColor(backgroundColor_);
2974  extent(geometry_);
2975 }
2976 
2977 void Magick::Image::extent(const Geometry &geometry_,
2978  const Color &backgroundColor_,const GravityType gravity_)
2979 {
2980  backgroundColor(backgroundColor_);
2981  extent(geometry_,gravity_);
2982 }
2983 
2984 void Magick::Image::extent(const Geometry &geometry_,
2985  const GravityType gravity_)
2986 {
2987  RectangleInfo
2988  geometry;
2989 
2990  SetGeometry(image(),&geometry);
2991  geometry.width=geometry_.width();
2992  geometry.height=geometry_.height();
2993  GravityAdjustGeometry(image()->columns,image()->rows,gravity_,&geometry);
2994  extent(geometry);
2995 }
2996 
2997 void Magick::Image::flip(void)
2998 {
2999  MagickCore::Image
3000  *newImage;
3001 
3002  GetPPException;
3003  newImage=FlipImage(constImage(),exceptionInfo);
3004  replaceImage(newImage);
3005  ThrowImageException;
3006 }
3007 
3008 void Magick::Image::floodFillAlpha(const ssize_t x_,const ssize_t y_,
3009  const unsigned int alpha_,const bool invert_)
3010 {
3011  PixelInfo
3012  target;
3013 
3014  modifyImage();
3015 
3016  target=static_cast<PixelInfo>(pixelColor(x_,y_));
3017  target.alpha=alpha_;
3018  GetPPException;
3019  GetAndSetPPChannelMask(AlphaChannel);
3020  FloodfillPaintImage(image(),options()->drawInfo(),&target,x_,y_,
3021  (MagickBooleanType)invert_,exceptionInfo);
3022  RestorePPChannelMask;
3023  ThrowImageException;
3024 }
3025 
3026 void Magick::Image::floodFillAlpha(const ssize_t x_,const ssize_t y_,
3027  const unsigned int alpha_,const Color &target_,const bool invert_)
3028 {
3029  PixelInfo
3030  target;
3031 
3032  modifyImage();
3033 
3034  target=static_cast<PixelInfo>(target_);
3035  target.alpha=alpha_;
3036  GetPPException;
3037  GetAndSetPPChannelMask(AlphaChannel);
3038  FloodfillPaintImage(image(),options()->drawInfo(),&target,x_,y_,
3039  (MagickBooleanType)invert_,exceptionInfo);
3040  RestorePPChannelMask;
3041  ThrowImageException;
3042 }
3043 
3044 void Magick::Image::floodFillColor(const Geometry &point_,
3045  const Magick::Color &fillColor_,const bool invert_)
3046 {
3047  floodFillColor(point_.xOff(),point_.yOff(),fillColor_,invert_);
3048 }
3049 
3050 void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_,
3051  const Magick::Color &fillColor_,const bool invert_)
3052 {
3053  PixelInfo
3054  pixel;
3055 
3056  modifyImage();
3057 
3058  pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
3059  floodFill(x_,y_,(Magick::Image *)NULL,fillColor_,&pixel,invert_);
3060 }
3061 
3062 void Magick::Image::floodFillColor(const Geometry &point_,
3063  const Magick::Color &fillColor_,const Magick::Color &borderColor_,
3064  const bool invert_)
3065 {
3066  floodFillColor(point_.xOff(),point_.yOff(),fillColor_,borderColor_,invert_);
3067 }
3068 
3069 void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_,
3070  const Magick::Color &fillColor_,const Magick::Color &borderColor_,
3071  const bool invert_)
3072 {
3073  PixelInfo
3074  pixel;
3075 
3076  modifyImage();
3077 
3078  pixel=static_cast<PixelInfo>(borderColor_);
3079  floodFill(x_,y_,(Magick::Image *)NULL,fillColor_,&pixel,invert_);
3080 }
3081 
3082 void Magick::Image::floodFillTexture(const Magick::Geometry &point_,
3083  const Magick::Image &texture_,const bool invert_)
3084 {
3085  floodFillTexture(point_.xOff(),point_.yOff(),texture_,invert_);
3086 }
3087 
3088 void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_,
3089  const Magick::Image &texture_,const bool invert_)
3090 {
3091  PixelInfo
3092  pixel;
3093 
3094  modifyImage();
3095 
3096  pixel=static_cast<PixelInfo>(pixelColor(x_,y_));
3097  floodFill(x_,y_,&texture_,Magick::Color(),&pixel,invert_);
3098 }
3099 
3100 void Magick::Image::floodFillTexture(const Magick::Geometry &point_,
3101  const Magick::Image &texture_,const Magick::Color &borderColor_,
3102  const bool invert_)
3103 {
3104  floodFillTexture(point_.xOff(),point_.yOff(),texture_,borderColor_,invert_);
3105 }
3106 
3107 void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_,
3108  const Magick::Image &texture_,const Magick::Color &borderColor_,
3109  const bool invert_)
3110 {
3111  PixelInfo
3112  pixel;
3113 
3114  modifyImage();
3115 
3116  pixel=static_cast<PixelInfo>(borderColor_);
3117  floodFill(x_,y_,&texture_,Magick::Color(),&pixel,invert_);
3118 }
3119 
3120 void Magick::Image::flop(void)
3121 {
3122  MagickCore::Image
3123  *newImage;
3124 
3125  GetPPException;
3126  newImage=FlopImage(constImage(),exceptionInfo);
3127  replaceImage(newImage);
3128  ThrowImageException;
3129 }
3130 
3131 void Magick::Image::fontTypeMetrics(const std::string &text_,
3132  TypeMetric *metrics)
3133 {
3134  DrawInfo
3135  *drawInfo;
3136 
3137  drawInfo=options()->drawInfo();
3138  drawInfo->text=DestroyString(drawInfo->text);
3139  drawInfo->text=const_cast<char *>(text_.c_str());
3140  GetPPException;
3141  GetTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),exceptionInfo);
3142  drawInfo->text=(char *) NULL;
3143  ThrowImageException;
3144 }
3145 
3146 void Magick::Image::fontTypeMetricsMultiline(const std::string &text_,
3147  TypeMetric *metrics)
3148 {
3149  DrawInfo
3150  *drawInfo;
3151 
3152  drawInfo=options()->drawInfo();
3153  drawInfo->text=DestroyString(drawInfo->text);
3154  drawInfo->text=const_cast<char *>(text_.c_str());
3155  GetPPException;
3156  (void) GetMultilineTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),
3157  exceptionInfo);
3158  drawInfo->text=(char *) NULL;
3159  ThrowImageException;
3160 }
3161 
3162 void Magick::Image::frame(const Geometry &geometry_)
3163 {
3164  FrameInfo
3165  info;
3166 
3167  MagickCore::Image
3168  *newImage;
3169 
3170  info.x=static_cast<ssize_t>(geometry_.width());
3171  info.y=static_cast<ssize_t>(geometry_.height());
3172  info.width=columns() + (static_cast<size_t>(info.x) << 1);
3173  info.height=rows() + (static_cast<size_t>(info.y) << 1);
3174  info.outer_bevel=geometry_.xOff();
3175  info.inner_bevel=geometry_.yOff();
3176 
3177  GetPPException;
3178  newImage=FrameImage(constImage(),&info,image()->compose,exceptionInfo);
3179  replaceImage(newImage);
3180  ThrowImageException;
3181 }
3182 
3183 void Magick::Image::frame(const size_t width_,const size_t height_,
3184  const ssize_t innerBevel_,const ssize_t outerBevel_)
3185 {
3186  FrameInfo
3187  info;
3188 
3189  MagickCore::Image
3190  *newImage;
3191 
3192  info.x=static_cast<ssize_t>(width_);
3193  info.y=static_cast<ssize_t>(height_);
3194  info.width=columns() + (static_cast<size_t>(info.x) << 1);
3195  info.height=rows() + (static_cast<size_t>(info.y) << 1);
3196  info.outer_bevel=static_cast<ssize_t>(outerBevel_);
3197  info.inner_bevel=static_cast<ssize_t>(innerBevel_);
3198 
3199  GetPPException;
3200  newImage=FrameImage(constImage(),&info,image()->compose,exceptionInfo);
3201  replaceImage(newImage);
3202  ThrowImageException;
3203 }
3204 
3205 void Magick::Image::fx(const std::string expression_)
3206 {
3207  MagickCore::Image
3208  *newImage;
3209 
3210  GetPPException;
3211  newImage=FxImage(constImage(),expression_.c_str(),exceptionInfo);
3212  replaceImage(newImage);
3213  ThrowImageException;
3214 }
3215 
3216 void Magick::Image::fx(const std::string expression_,
3217  const Magick::ChannelType channel_)
3218 {
3219  MagickCore::Image
3220  *newImage;
3221 
3222  GetPPException;
3223  GetAndSetPPChannelMask(channel_);
3224  newImage=FxImage(constImage(),expression_.c_str(),exceptionInfo);
3225  RestorePPChannelMask;
3226  replaceImage(newImage);
3227  ThrowImageException;
3228 }
3229 
3230 void Magick::Image::gamma(const double gamma_)
3231 {
3232  modifyImage();
3233  GetPPException;
3234  GammaImage(image(),gamma_,exceptionInfo);
3235  ThrowImageException;
3236 }
3237 
3238 void Magick::Image::gamma(const double gammaRed_,const double gammaGreen_,
3239  const double gammaBlue_)
3240 {
3241  modifyImage();
3242  GetPPException;
3243  GetAndSetPPChannelMask(RedChannel);
3244  (void) GammaImage(image(),gammaRed_,exceptionInfo);
3245  SetPPChannelMask(GreenChannel);
3246  (void) GammaImage(image(),gammaGreen_,exceptionInfo);
3247  SetPPChannelMask(BlueChannel);
3248  (void) GammaImage(image(),gammaBlue_,exceptionInfo);
3249  RestorePPChannelMask;
3250  ThrowImageException;
3251 }
3252 
3253 void Magick::Image::gaussianBlur(const double radius_,const double sigma_)
3254 {
3255  MagickCore::Image
3256  *newImage;
3257 
3258  GetPPException;
3259  newImage=GaussianBlurImage(constImage(),radius_,sigma_,exceptionInfo);
3260  replaceImage(newImage);
3261  ThrowImageException;
3262 }
3263 
3264 void Magick::Image::gaussianBlurChannel(const ChannelType channel_,
3265  const double radius_,const double sigma_)
3266 {
3267  MagickCore::Image
3268  *newImage;
3269 
3270  GetPPException;
3271  GetAndSetPPChannelMask(channel_);
3272  newImage=GaussianBlurImage(constImage(),radius_,sigma_,exceptionInfo);
3273  RestorePPChannelMask;
3274  replaceImage(newImage);
3275  ThrowImageException;
3276 }
3277 
3278 const Magick::Quantum *Magick::Image::getConstPixels(const ssize_t x_,
3279  const ssize_t y_,const size_t columns_,const size_t rows_) const
3280 {
3281  const Quantum
3282  *p;
3283 
3284  GetPPException;
3285  p=GetVirtualPixels(constImage(),x_, y_,columns_, rows_,exceptionInfo);
3286  ThrowImageException;
3287  return(p);
3288 }
3289 
3290 const void *Magick::Image::getConstMetacontent(void) const
3291 {
3292  const void
3293  *result;
3294 
3295  result=GetVirtualMetacontent(constImage());
3296 
3297  if(!result)
3298  throwExceptionExplicit(MagickCore::OptionError,
3299  "Unable to retrieve meta content.");
3300 
3301  return(result);
3302 }
3303 
3304 void *Magick::Image::getMetacontent(void )
3305 {
3306  void
3307  *result;
3308 
3309  result=GetAuthenticMetacontent(image());
3310 
3311  if(!result)
3312  throwExceptionExplicit(MagickCore::OptionError,
3313  "Unable to retrieve meta content.");
3314 
3315  return(result);
3316 }
3317 
3318 Magick::Quantum *Magick::Image::getPixels(const ssize_t x_,const ssize_t y_,
3319  const size_t columns_,const size_t rows_)
3320 {
3321  Quantum
3322  *result;
3323 
3324  modifyImage();
3325  GetPPException;
3326  result=GetAuthenticPixels(image(),x_, y_,columns_,rows_,exceptionInfo);
3327  ThrowImageException;
3328 
3329  return(result);
3330 }
3331 
3332 void Magick::Image::grayscale(const PixelIntensityMethod method_)
3333 {
3334  modifyImage();
3335  GetPPException;
3336  (void) GrayscaleImage(image(),method_,exceptionInfo);
3337  ThrowImageException;
3338 }
3339 
3340 void Magick::Image::haldClut(const Image &clutImage_)
3341 {
3342  modifyImage();
3343  GetPPException;
3344  (void) HaldClutImage(image(),clutImage_.constImage(),exceptionInfo);
3345  ThrowImageException;
3346 }
3347 
3348 void Magick::Image::houghLine(const size_t width_,const size_t height_,
3349  const size_t threshold_)
3350 {
3351  MagickCore::Image
3352  *newImage;
3353 
3354  GetPPException;
3355  newImage=HoughLineImage(constImage(),width_,height_,threshold_,
3356  exceptionInfo);
3357  replaceImage(newImage);
3358  ThrowImageException;
3359 }
3360 
3361 Magick::ImageType Magick::Image::identifyType(void) const
3362 {
3363  ImageType
3364  image_type;
3365 
3366  GetPPException;
3367  image_type=IdentifyImageType(constImage(),exceptionInfo);
3368  ThrowImageException;
3369  return(image_type);
3370 }
3371 
3372 void Magick::Image::implode(const double factor_)
3373 {
3374  MagickCore::Image
3375  *newImage;
3376 
3377  GetPPException;
3378  newImage=ImplodeImage(constImage(),factor_,image()->interpolate,
3379  exceptionInfo);
3380  replaceImage(newImage);
3381  ThrowImageException;
3382 }
3383 
3384 void Magick::Image::inverseFourierTransform(const Image &phase_)
3385 {
3386  inverseFourierTransform(phase_,true);
3387 }
3388 
3389 void Magick::Image::inverseFourierTransform(const Image &phase_,
3390  const bool magnitude_)
3391 {
3392  MagickCore::Image
3393  *newImage;
3394 
3395  GetPPException;
3396  newImage=InverseFourierTransformImage(constImage(),phase_.constImage(),
3397  magnitude_ == true ? MagickTrue : MagickFalse,exceptionInfo);
3398  replaceImage(newImage);
3399  ThrowImageException;
3400 }
3401 
3402 void Magick::Image::kuwahara(const double radius_,const double sigma_)
3403 {
3404  MagickCore::Image
3405  *newImage;
3406 
3407  GetPPException;
3408  newImage=KuwaharaImage(constImage(),radius_,sigma_,exceptionInfo);
3409  replaceImage(newImage);
3410  ThrowImageException;
3411 }
3412 
3413 void Magick::Image::kuwaharaChannel(const ChannelType channel_,
3414  const double radius_,const double sigma_)
3415 {
3416  MagickCore::Image
3417  *newImage;
3418 
3419  GetPPException;
3420  GetAndSetPPChannelMask(channel_);
3421  newImage=KuwaharaImage(constImage(),radius_,sigma_,exceptionInfo);
3422  replaceImage(newImage);
3423  RestorePPChannelMask;
3424  ThrowImageException;
3425 }
3426 
3427 void Magick::Image::level(const double blackPoint_,const double whitePoint_,
3428  const double gamma_)
3429 {
3430  modifyImage();
3431  GetPPException;
3432  (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
3433  ThrowImageException;
3434 }
3435 
3436 void Magick::Image::levelChannel(const ChannelType channel_,
3437  const double blackPoint_,const double whitePoint_,const double gamma_)
3438 {
3439  modifyImage();
3440  GetPPException;
3441  GetAndSetPPChannelMask(channel_);
3442  (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
3443  RestorePPChannelMask;
3444  ThrowImageException;
3445 }
3446 
3447 void Magick::Image::levelColors(const Color &blackColor_,
3448  const Color &whiteColor_,const bool invert_)
3449 {
3450  PixelInfo
3451  black,
3452  white;
3453 
3454  modifyImage();
3455 
3456  black=static_cast<PixelInfo>(blackColor_);
3457  white=static_cast<PixelInfo>(whiteColor_);
3458  GetPPException;
3459  (void) LevelImageColors(image(),&black,&white,invert_ == true ?
3460  MagickTrue : MagickFalse,exceptionInfo);
3461  ThrowImageException;
3462 }
3463 
3464 void Magick::Image::levelColorsChannel(const ChannelType channel_,
3465  const Color &blackColor_,const Color &whiteColor_,const bool invert_)
3466 {
3467  PixelInfo
3468  black,
3469  white;
3470 
3471  modifyImage();
3472 
3473  black=static_cast<PixelInfo>(blackColor_);
3474  white=static_cast<PixelInfo>(whiteColor_);
3475  GetPPException;
3476  GetAndSetPPChannelMask(channel_);
3477  (void) LevelImageColors(image(),&black,&white,invert_ == true ?
3478  MagickTrue : MagickFalse,exceptionInfo);
3479  RestorePPChannelMask;
3480  ThrowImageException;
3481 }
3482 
3483 void Magick::Image::levelize(const double blackPoint_,const double whitePoint_,
3484  const double gamma_)
3485 {
3486  modifyImage();
3487  GetPPException;
3488  (void) LevelizeImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
3489  ThrowImageException;
3490 }
3491 
3492 void Magick::Image::levelizeChannel(const ChannelType channel_,
3493  const double blackPoint_,const double whitePoint_,const double gamma_)
3494 {
3495  modifyImage();
3496  GetPPException;
3497  GetAndSetPPChannelMask(channel_);
3498  (void) LevelizeImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
3499  RestorePPChannelMask;
3500  ThrowImageException;
3501 }
3502 
3503 void Magick::Image::linearStretch(const double blackPoint_,
3504  const double whitePoint_)
3505 {
3506  modifyImage();
3507  GetPPException;
3508  LinearStretchImage(image(),blackPoint_,whitePoint_,exceptionInfo);
3509  ThrowImageException;
3510 }
3511 
3512 void Magick::Image::liquidRescale(const Geometry &geometry_)
3513 {
3514  MagickCore::Image
3515  *newImage;
3516 
3517  size_t
3518  height=rows(),
3519  width=columns();
3520 
3521  ssize_t
3522  x=0,
3523  y=0;
3524 
3525  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
3526  &height);
3527 
3528  GetPPException;
3529  newImage=LiquidRescaleImage(image(),width,height,(double) x,(double) y,exceptionInfo);
3530  replaceImage(newImage);
3531  ThrowImageException;
3532 }
3533 
3534 void Magick::Image::localContrast(const double radius_,const double strength_)
3535 {
3536  MagickCore::Image
3537  *newImage;
3538 
3539  GetPPException;
3540  newImage=LocalContrastImage(constImage(),radius_,strength_,exceptionInfo);
3541  replaceImage(newImage);
3542  ThrowImageException;
3543 }
3544 
3545 void Magick::Image::localContrastChannel(const ChannelType channel_,
3546  const double radius_,const double strength_)
3547 {
3548  MagickCore::Image
3549  *newImage;
3550 
3551  GetPPException;
3552  GetAndSetPPChannelMask(channel_);
3553  newImage=LocalContrastImage(constImage(),radius_,strength_,exceptionInfo);
3554  RestorePPChannelMask;
3555  replaceImage(newImage);
3556  ThrowImageException;
3557 }
3558 
3559 void Magick::Image::magnify(void)
3560 {
3561  MagickCore::Image
3562  *newImage;
3563 
3564  GetPPException;
3565  newImage=MagnifyImage(constImage(),exceptionInfo);
3566  replaceImage(newImage);
3567  ThrowImageException;
3568 }
3569 
3570 void Magick::Image::map(const Image &mapImage_,const bool dither_)
3571 {
3572  map(mapImage_, dither_ ? RiemersmaDitherMethod : NoDitherMethod);
3573 }
3574 
3575 void Magick::Image::map(const Image &mapImage_,const DitherMethod ditherMethod_)
3576 {
3577  modifyImage();
3578  GetPPException;
3579  options()->quantizeDither(ditherMethod_);
3580  RemapImage(options()->quantizeInfo(),image(),mapImage_.constImage(),
3581  exceptionInfo);
3582  ThrowImageException;
3583 }
3584 
3585 void Magick::Image::meanShift(const size_t width_,const size_t height_,
3586  const double color_distance_)
3587 {
3588  MagickCore::Image
3589  *newImage;
3590 
3591  GetPPException;
3592  newImage=MeanShiftImage(constImage(),width_,height_,color_distance_,
3593  exceptionInfo);
3594  replaceImage(newImage);
3595  ThrowImageException;
3596 }
3597 
3598 void Magick::Image::medianFilter(const double radius_)
3599 {
3600  MagickCore::Image
3601  *newImage;
3602 
3603  GetPPException;
3604  newImage=StatisticImage(image(),MedianStatistic,(size_t) radius_,
3605  (size_t) radius_,exceptionInfo);
3606  replaceImage(newImage);
3607  ThrowImageException;
3608 }
3609 
3610 void Magick::Image::minify(void)
3611 {
3612  MagickCore::Image
3613  *newImage;
3614 
3615  GetPPException;
3616  newImage=MinifyImage(constImage(),exceptionInfo);
3617  replaceImage(newImage);
3618  ThrowImageException;
3619 }
3620 
3621 void Magick::Image::modulate(const double brightness_,const double saturation_,
3622  const double hue_)
3623 {
3624  char
3625  modulate[MagickPathExtent + 1];
3626 
3627  FormatLocaleString(modulate,MagickPathExtent,"%3.6f,%3.6f,%3.6f",brightness_,
3628  saturation_,hue_);
3629 
3630  modifyImage();
3631  GetPPException;
3632  ModulateImage(image(),modulate,exceptionInfo);
3633  ThrowImageException;
3634 }
3635 
3636 Magick::ImageMoments Magick::Image::moments(void) const
3637 {
3638  return(ImageMoments(*this));
3639 }
3640 
3641 void Magick::Image::morphology(const MorphologyMethod method_,
3642  const std::string kernel_,const ssize_t iterations_)
3643 {
3644  KernelInfo
3645  *kernel;
3646 
3647  MagickCore::Image
3648  *newImage;
3649 
3650  GetPPException;
3651  kernel=AcquireKernelInfo(kernel_.c_str(),exceptionInfo);
3652  if (kernel == (KernelInfo *) NULL)
3653  throwExceptionExplicit(MagickCore::OptionError,"Unable to parse kernel.");
3654  newImage=MorphologyImage(constImage(),method_,iterations_,kernel,
3655  exceptionInfo);
3656  replaceImage(newImage);
3657  kernel=DestroyKernelInfo(kernel);
3658  ThrowImageException;
3659 }
3660 
3661 void Magick::Image::morphology(const MorphologyMethod method_,
3662  const KernelInfoType kernel_,const std::string arguments_,
3663  const ssize_t iterations_)
3664 {
3665  const char
3666  *option;
3667 
3668  std::string
3669  kernel;
3670 
3671  option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
3672  if (option == (const char *)NULL)
3673  {
3674  throwExceptionExplicit(MagickCore::OptionError,
3675  "Unable to determine kernel type.");
3676  return;
3677  }
3678  kernel=std::string(option);
3679  if (!arguments_.empty())
3680  kernel+=":"+arguments_;
3681 
3682  morphology(method_,kernel,iterations_);
3683 }
3684 
3685 void Magick::Image::morphologyChannel(const ChannelType channel_,
3686  const MorphologyMethod method_,const std::string kernel_,
3687  const ssize_t iterations_)
3688 {
3689  KernelInfo
3690  *kernel;
3691 
3692  MagickCore::Image
3693  *newImage;
3694 
3695 
3696  GetPPException;
3697  kernel=AcquireKernelInfo(kernel_.c_str(),exceptionInfo);
3698  if (kernel == (KernelInfo *)NULL)
3699  {
3700  throwExceptionExplicit(MagickCore::OptionError,
3701  "Unable to parse kernel.");
3702  return;
3703  }
3704  GetAndSetPPChannelMask(channel_);
3705  newImage=MorphologyImage(constImage(),method_,iterations_,kernel,
3706  exceptionInfo);
3707  RestorePPChannelMask;
3708  replaceImage(newImage);
3709  kernel=DestroyKernelInfo(kernel);
3710  ThrowImageException;
3711 }
3712 
3713 void Magick::Image::morphologyChannel(const ChannelType channel_,
3714  const MorphologyMethod method_,const KernelInfoType kernel_,
3715  const std::string arguments_,const ssize_t iterations_)
3716 {
3717  const char
3718  *option;
3719 
3720  std::string
3721  kernel;
3722 
3723  option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
3724  if (option == (const char *)NULL)
3725  {
3726  throwExceptionExplicit(MagickCore::OptionError,
3727  "Unable to determine kernel type.");
3728  return;
3729  }
3730 
3731  kernel=std::string(option);
3732  if (!arguments_.empty())
3733  kernel+=":"+arguments_;
3734 
3735  morphologyChannel(channel_,method_,kernel,iterations_);
3736 }
3737 
3738 void Magick::Image::motionBlur(const double radius_,const double sigma_,
3739  const double angle_)
3740 {
3741  MagickCore::Image
3742  *newImage;
3743 
3744  GetPPException;
3745  newImage=MotionBlurImage(constImage(),radius_,sigma_,angle_,exceptionInfo);
3746  replaceImage(newImage);
3747  ThrowImageException;
3748 }
3749 
3750 void Magick::Image::negate(const bool grayscale_)
3751 {
3752  modifyImage();
3753  GetPPException;
3754  NegateImage(image(),(MagickBooleanType) grayscale_,exceptionInfo);
3755  ThrowImageException;
3756 }
3757 
3758 void Magick::Image::negateChannel(const ChannelType channel_,
3759  const bool grayscale_)
3760 {
3761  modifyImage();
3762  GetPPException;
3763  GetAndSetPPChannelMask(channel_);
3764  NegateImage(image(),(MagickBooleanType) grayscale_,exceptionInfo);
3765  RestorePPChannelMask;
3766  ThrowImageException;
3767 }
3768 
3769 void Magick::Image::normalize(void)
3770 {
3771  modifyImage();
3772  GetPPException;
3773  NormalizeImage(image(),exceptionInfo);
3774  ThrowImageException;
3775 }
3776 
3777 void Magick::Image::oilPaint(const double radius_,const double sigma_)
3778 {
3779  MagickCore::Image
3780  *newImage;
3781 
3782  GetPPException;
3783  newImage=OilPaintImage(constImage(),radius_,sigma_,exceptionInfo);
3784  replaceImage(newImage);
3785  ThrowImageException;
3786 }
3787 
3788 void Magick::Image::opaque(const Color &opaqueColor_,const Color &penColor_,
3789  const bool invert_)
3790 {
3791  std::string
3792  opaqueColor,
3793  penColor;
3794 
3795  PixelInfo
3796  opaque,
3797  pen;
3798 
3799  if (!opaqueColor_.isValid())
3800  throwExceptionExplicit(MagickCore::OptionError,
3801  "Opaque color argument is invalid");
3802 
3803  if (!penColor_.isValid())
3804  throwExceptionExplicit(MagickCore::OptionError,
3805  "Pen color argument is invalid");
3806 
3807  modifyImage();
3808  opaqueColor=opaqueColor_;
3809  penColor=penColor_;
3810 
3811  GetPPException;
3812  (void) QueryColorCompliance(opaqueColor.c_str(),AllCompliance,&opaque,
3813  exceptionInfo);
3814  (void) QueryColorCompliance(penColor.c_str(),AllCompliance,&pen,
3815  exceptionInfo);
3816  OpaquePaintImage(image(),&opaque,&pen,invert_ ? MagickTrue : MagickFalse,
3817  exceptionInfo);
3818  ThrowImageException;
3819 }
3820 
3821 void Magick::Image::orderedDither(std::string thresholdMap_)
3822 {
3823  modifyImage();
3824  GetPPException;
3825  (void) OrderedDitherImage(image(),thresholdMap_.c_str(),exceptionInfo);
3826  ThrowImageException;
3827 }
3828 
3829 void Magick::Image::orderedDitherChannel(const ChannelType channel_,
3830  std::string thresholdMap_)
3831 {
3832  modifyImage();
3833  GetPPException;
3834  GetAndSetPPChannelMask(channel_);
3835  (void)OrderedDitherImage(image(),thresholdMap_.c_str(),exceptionInfo);
3836  RestorePPChannelMask;
3837  ThrowImageException;
3838 }
3839 
3840 void Magick::Image::perceptible(const double epsilon_)
3841 {
3842  modifyImage();
3843  GetPPException;
3844  PerceptibleImage(image(),epsilon_,exceptionInfo);
3845  ThrowImageException;
3846 }
3847 
3848 void Magick::Image::perceptibleChannel(const ChannelType channel_,
3849  const double epsilon_)
3850 {
3851  modifyImage();
3852  GetPPException;
3853  GetAndSetPPChannelMask(channel_);
3854  PerceptibleImage(image(),epsilon_,exceptionInfo);
3855  RestorePPChannelMask;
3856  ThrowImageException;
3857 }
3858 
3859  Magick::ImagePerceptualHash Magick::Image::perceptualHash() const
3860 {
3861  return(ImagePerceptualHash(*this));
3862 }
3863 
3864 void Magick::Image::ping(const std::string &imageSpec_)
3865 {
3866  MagickCore::Image
3867  *newImage;
3868 
3869  GetPPException;
3870  options()->fileName(imageSpec_);
3871  newImage=PingImage(imageInfo(),exceptionInfo);
3872  read(newImage,exceptionInfo);
3873 }
3874 
3875 void Magick::Image::ping(const Blob& blob_)
3876 {
3877  MagickCore::Image
3878  *newImage;
3879 
3880  GetPPException;
3881  newImage=PingBlob(imageInfo(),blob_.data(),blob_.length(),exceptionInfo);
3882  read(newImage,exceptionInfo);
3883 }
3884 
3885 void Magick::Image::pixelColor(const ssize_t x_,const ssize_t y_,
3886  const Color &color_)
3887 {
3888  PixelInfo
3889  packet;
3890 
3891  Quantum
3892  *pixel;
3893 
3894  // Test arguments to ensure they are within the image.
3895  if (y_ > (ssize_t) rows() || x_ > (ssize_t) columns())
3896  throwExceptionExplicit(MagickCore::OptionError,
3897  "Access outside of image boundary");
3898 
3899  modifyImage();
3900 
3901  // Set image to DirectClass
3902  classType(DirectClass );
3903 
3904  // Get pixel view
3905  Pixels pixels(*this);
3906  // Set pixel value
3907  pixel=pixels.get(x_, y_, 1, 1 );
3908  packet=color_;
3909  MagickCore::SetPixelViaPixelInfo(constImage(),&packet,pixel);
3910  // Tell ImageMagick that pixels have been updated
3911  pixels.sync();
3912 }
3913 
3914 Magick::Color Magick::Image::pixelColor(const ssize_t x_,
3915  const ssize_t y_) const
3916 {
3917  const Quantum
3918  *pixel;
3919 
3920  pixel=getConstPixels(x_,y_,1,1);
3921  if (pixel)
3922  {
3923  PixelInfo
3924  packet;
3925 
3926  MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet);
3927  return(Color(packet));
3928  }
3929 
3930  return(Color()); // invalid
3931 }
3932 
3933 void Magick::Image::polaroid(const std::string &caption_,const double angle_,
3934  const PixelInterpolateMethod method_)
3935 {
3936  MagickCore::Image
3937  *newImage;
3938 
3939  GetPPException;
3940  newImage=PolaroidImage(constImage(),options()->drawInfo(),caption_.c_str(),
3941  angle_,method_,exceptionInfo);
3942  replaceImage(newImage);
3943  ThrowImageException;
3944 }
3945 
3946 void Magick::Image::posterize(const size_t levels_,const DitherMethod method_)
3947 {
3948  modifyImage();
3949  GetPPException;
3950  PosterizeImage(image(),levels_,method_,exceptionInfo);
3951  ThrowImageException;
3952 }
3953 
3954 void Magick::Image::posterizeChannel(const ChannelType channel_,
3955  const size_t levels_,const DitherMethod method_)
3956 {
3957  modifyImage();
3958  GetPPException;
3959  GetAndSetPPChannelMask(channel_);
3960  PosterizeImage(image(),levels_,method_,exceptionInfo);
3961  RestorePPChannelMask;
3962  ThrowImageException;
3963 }
3964 
3965 void Magick::Image::process(std::string name_,const ssize_t argc,
3966  const char **argv)
3967 {
3968  modifyImage();
3969 
3970  GetPPException;
3971  (void) InvokeDynamicImageFilter(name_.c_str(),&image(),(int) argc,argv,
3972  exceptionInfo);
3973  ThrowImageException;
3974 }
3975 
3976 void Magick::Image::profile(const std::string name_,
3977  const Magick::Blob &profile_)
3978 {
3979  modifyImage();
3980  GetPPException;
3981  (void) ProfileImage(image(),name_.c_str(),(unsigned char *)profile_.data(),
3982  profile_.length(),exceptionInfo);
3983  ThrowImageException;
3984 }
3985 
3986 Magick::Blob Magick::Image::profile(const std::string name_) const
3987 {
3988  const StringInfo
3989  *profile;
3990 
3991  profile=GetImageProfile(constImage(),name_.c_str());
3992 
3993  if (profile == (StringInfo *) NULL)
3994  return(Blob());
3995  return(Blob((void*) GetStringInfoDatum(profile),GetStringInfoLength(
3996  profile)));
3997 }
3998 
3999 void Magick::Image::quantize(const bool measureError_)
4000 {
4001  modifyImage();
4002 
4003  if (measureError_)
4004  options()->quantizeInfo()->measure_error=MagickTrue;
4005  else
4006  options()->quantizeInfo()->measure_error=MagickFalse;
4007 
4008  GetPPException;
4009  QuantizeImage(options()->quantizeInfo(),image(),exceptionInfo);
4010  ThrowImageException;
4011 }
4012 
4013 void Magick::Image::raise(const Geometry &geometry_,const bool raisedFlag_)
4014 {
4015  RectangleInfo
4016  raiseInfo=geometry_;
4017 
4018  GetPPException;
4019  modifyImage();
4020  RaiseImage(image(),&raiseInfo,raisedFlag_ == true ? MagickTrue : MagickFalse,
4021  exceptionInfo);
4022  ThrowImageException;
4023 }
4024 
4025 void Magick::Image::randomThreshold(const double low_,const double high_)
4026 {
4027  GetPPException;
4028  (void) RandomThresholdImage(image(),low_,high_,exceptionInfo);
4029  ThrowImageException;
4030 }
4031 
4032 void Magick::Image::randomThresholdChannel(const ChannelType channel_,
4033  const double low_,const double high_)
4034 {
4035  modifyImage();
4036  GetPPException;
4037  GetAndSetPPChannelMask(channel_);
4038  (void) RandomThresholdImage(image(),low_,high_,exceptionInfo);
4039  RestorePPChannelMask;
4040  ThrowImageException;
4041 }
4042 
4043 void Magick::Image::read(const Blob &blob_)
4044 {
4045  MagickCore::Image
4046  *newImage;
4047 
4048  GetPPException;
4049  newImage=BlobToImage(imageInfo(),static_cast<const void *>(blob_.data()),
4050  blob_.length(),exceptionInfo);
4051  read(newImage,exceptionInfo);
4052 }
4053 
4054 void Magick::Image::read(const Blob &blob_,const Geometry &size_)
4055 {
4056  size(size_);
4057  read(blob_);
4058 }
4059 
4060 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
4061  const size_t depth_)
4062 {
4063  size(size_);
4064  depth(depth_);
4065  read(blob_);
4066 }
4067 
4068 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
4069  const size_t depth_,const std::string &magick_)
4070 {
4071  size(size_);
4072  depth(depth_);
4073  magick(magick_);
4074  // Set explicit image format
4075  fileName(magick_ + ':');
4076  read(blob_);
4077 }
4078 
4079 void Magick::Image::read(const Blob &blob_,const Geometry &size_,
4080  const std::string &magick_)
4081 {
4082  size(size_);
4083  magick(magick_);
4084  // Set explicit image format
4085  fileName(magick_ + ':');
4086  read(blob_);
4087 }
4088 
4089 void Magick::Image::read(const Geometry &size_,const std::string &imageSpec_)
4090 {
4091  size(size_);
4092  read(imageSpec_);
4093 }
4094 
4095 void Magick::Image::read(const size_t width_,const size_t height_,
4096  const std::string &map_,const StorageType type_,const void *pixels_)
4097 {
4098  MagickCore::Image
4099  *newImage;
4100 
4101  GetPPException;
4102  newImage=ConstituteImage(width_,height_,map_.c_str(),type_, pixels_,
4103  exceptionInfo);
4104  replaceImage(newImage);
4105  ThrowImageException;
4106 }
4107 
4108 void Magick::Image::read(const std::string &imageSpec_)
4109 {
4110  MagickCore::Image
4111  *newImage;
4112 
4113  GetPPException;
4114  options()->fileName(imageSpec_);
4115  newImage=ReadImage(imageInfo(),exceptionInfo);
4116  read(newImage,exceptionInfo);
4117 }
4118 
4119 void Magick::Image::readMask(const Magick::Image &mask_)
4120 {
4121  mask(mask_,ReadPixelMask);
4122 }
4123 
4124 Magick::Image Magick::Image::readMask(void) const
4125 {
4126  return(mask(ReadPixelMask));
4127 }
4128 
4129 void Magick::Image::readPixels(const Magick::QuantumType quantum_,
4130  const unsigned char *source_)
4131 {
4132  QuantumInfo
4133  *quantum_info;
4134 
4135  quantum_info=AcquireQuantumInfo(imageInfo(),image());
4136  GetPPException;
4137  ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4138  quantum_,source_,exceptionInfo);
4139  quantum_info=DestroyQuantumInfo(quantum_info);
4140  ThrowImageException;
4141 }
4142 
4143 void Magick::Image::reduceNoise(void)
4144 {
4145  reduceNoise(3);
4146 }
4147 
4148 void Magick::Image::reduceNoise(const size_t order_)
4149 {
4150  MagickCore::Image
4151  *newImage;
4152 
4153  GetPPException;
4154  newImage=StatisticImage(constImage(),NonpeakStatistic,order_,
4155  order_,exceptionInfo);
4156  replaceImage(newImage);
4157  ThrowImageException;
4158 }
4159 
4160 void Magick::Image::repage()
4161 {
4162  modifyImage();
4163  options()->page(Geometry());
4164  image()->page.width = 0;
4165  image()->page.height = 0;
4166  image()->page.x = 0;
4167  image()->page.y = 0;
4168 }
4169 
4170 void Magick::Image::resample(const Point &density_)
4171 {
4172  MagickCore::Image
4173  *newImage;
4174 
4175  GetPPException;
4176  newImage=ResampleImage(constImage(),density_.x(),density_.y(),
4177  image()->filter,exceptionInfo);
4178  replaceImage(newImage);
4179  ThrowImageException;
4180 }
4181 
4182 void Magick::Image::resize(const Geometry &geometry_)
4183 {
4184  MagickCore::Image
4185  *newImage;
4186 
4187  size_t
4188  height=rows(),
4189  width=columns();
4190 
4191  ssize_t
4192  x=0,
4193  y=0;
4194 
4195  // Calculate new size. This code should be supported using binary arguments
4196  // in the ImageMagick library.
4197  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4198  &height);
4199 
4200  GetPPException;
4201  newImage=ResizeImage(constImage(),width,height,image()->filter,
4202  exceptionInfo);
4203  replaceImage(newImage);
4204  ThrowImageException;
4205 }
4206 
4207 void Magick::Image::roll(const Geometry &roll_)
4208 {
4209  MagickCore::Image
4210  *newImage;
4211 
4212  GetPPException;
4213  newImage=RollImage(constImage(),roll_.xOff(),roll_.yOff(),exceptionInfo);
4214  replaceImage(newImage);
4215  ThrowImageException;
4216 }
4217 
4218 void Magick::Image::roll(const ssize_t columns_,const ssize_t rows_)
4219 {
4220  MagickCore::Image
4221  *newImage;
4222 
4223  GetPPException;
4224  newImage=RollImage(constImage(),columns_, rows_,exceptionInfo);
4225  replaceImage(newImage);
4226  ThrowImageException;
4227 }
4228 
4229 void Magick::Image::rotate(const double degrees_)
4230 {
4231  MagickCore::Image
4232  *newImage;
4233 
4234  GetPPException;
4235  newImage=RotateImage(constImage(),degrees_,exceptionInfo);
4236  replaceImage(newImage);
4237  ThrowImageException;
4238 }
4239 
4240 void Magick::Image::rotationalBlur(const double angle_)
4241 {
4242  MagickCore::Image
4243  *newImage;
4244 
4245  GetPPException;
4246  newImage=RotationalBlurImage(constImage(),angle_,exceptionInfo);
4247  replaceImage(newImage);
4248  ThrowImageException;
4249 }
4250 
4251 void Magick::Image::rotationalBlurChannel(const ChannelType channel_,
4252  const double angle_)
4253 {
4254  MagickCore::Image
4255  *newImage;
4256 
4257  GetPPException;
4258  GetAndSetPPChannelMask(channel_);
4259  newImage=RotationalBlurImage(constImage(),angle_,exceptionInfo);
4260  RestorePPChannelMask;
4261  replaceImage(newImage);
4262  ThrowImageException;
4263 }
4264 
4265 void Magick::Image::sample(const Geometry &geometry_)
4266 {
4267  MagickCore::Image
4268  *newImage;
4269 
4270  size_t
4271  height=rows(),
4272  width=columns();
4273 
4274  ssize_t
4275  x=0,
4276  y=0;
4277 
4278  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4279  &height);
4280 
4281  GetPPException;
4282  newImage=SampleImage(constImage(),width,height,exceptionInfo);
4283  replaceImage(newImage);
4284  ThrowImageException;
4285 }
4286 
4287 void Magick::Image::scale(const Geometry &geometry_)
4288 {
4289  MagickCore::Image
4290  *newImage;
4291 
4292  size_t
4293  height=rows(),
4294  width=columns();
4295 
4296  ssize_t
4297  x=0,
4298  y=0;
4299 
4300  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4301  &height);
4302 
4303  GetPPException;
4304  newImage=ScaleImage(constImage(),width,height,exceptionInfo);
4305  replaceImage(newImage);
4306  ThrowImageException;
4307 }
4308 
4309 void Magick::Image::segment(const double clusterThreshold_,
4310  const double smoothingThreshold_)
4311 {
4312  modifyImage();
4313  GetPPException;
4314  SegmentImage(image(),options()->quantizeColorSpace(),
4315  (MagickBooleanType) options()->verbose(),clusterThreshold_,
4316  smoothingThreshold_,exceptionInfo);
4317  SyncImage(image(),exceptionInfo);
4318  ThrowImageException;
4319 }
4320 
4321 void Magick::Image::selectiveBlur(const double radius_,const double sigma_,
4322  const double threshold_)
4323 {
4324  MagickCore::Image
4325  *newImage;
4326 
4327  GetPPException;
4328  newImage=SelectiveBlurImage(constImage(),radius_,sigma_,threshold_,
4329  exceptionInfo);
4330  replaceImage(newImage);
4331  ThrowImageException;
4332 }
4333 
4334 void Magick::Image::selectiveBlurChannel(const ChannelType channel_,
4335  const double radius_,const double sigma_,const double threshold_)
4336 {
4337  MagickCore::Image
4338  *newImage;
4339 
4340  GetPPException;
4341  GetAndSetPPChannelMask(channel_);
4342  newImage=SelectiveBlurImage(constImage(),radius_,sigma_,threshold_,
4343  exceptionInfo);
4344  RestorePPChannelMask;
4345  replaceImage(newImage);
4346  ThrowImageException;
4347 }
4348 
4349 Magick::Image Magick::Image::separate(const ChannelType channel_) const
4350 {
4351  MagickCore::Image
4352  *image;
4353 
4354  GetPPException;
4355  image=SeparateImage(constImage(),channel_,exceptionInfo);
4356  ThrowImageException;
4357  if (image == (MagickCore::Image *) NULL)
4358  return(Magick::Image());
4359  else
4360  return(Magick::Image(image));
4361 }
4362 
4363 void Magick::Image::sepiaTone(const double threshold_)
4364 {
4365  MagickCore::Image
4366  *newImage;
4367 
4368  GetPPException;
4369  newImage=SepiaToneImage(constImage(),threshold_,exceptionInfo);
4370  replaceImage(newImage);
4371  ThrowImageException;
4372 }
4373 
4374 bool Magick::Image::setColorMetric(const Image &reference_)
4375 {
4376  bool
4377  status;
4378 
4379  Image
4380  ref=reference_;
4381 
4382  GetPPException;
4383  modifyImage();
4384  status=static_cast<bool>(SetImageColorMetric(image(),ref.constImage(),
4385  exceptionInfo));
4386  ThrowImageException;
4387  return(status);
4388 }
4389 
4390 Magick::Quantum *Magick::Image::setPixels(const ssize_t x_,const ssize_t y_,
4391  const size_t columns_,const size_t rows_)
4392 {
4393  Quantum
4394  *result;
4395 
4396  modifyImage();
4397  GetPPException;
4398  result=QueueAuthenticPixels(image(),x_,y_,columns_,rows_,exceptionInfo);
4399  ThrowImageException;
4400  return(result);
4401 }
4402 
4403 void Magick::Image::shade(const double azimuth_,const double elevation_,
4404  const bool colorShading_)
4405 {
4406  MagickCore::Image
4407  *newImage;
4408 
4409  GetPPException;
4410  newImage=ShadeImage(constImage(),colorShading_ == true ?
4411  MagickTrue : MagickFalse,azimuth_,elevation_,exceptionInfo);
4412  replaceImage(newImage);
4413  ThrowImageException;
4414 }
4415 
4416 void Magick::Image::shadow(const double percent_opacity_,const double sigma_,
4417  const ssize_t x_,const ssize_t y_)
4418 {
4419  MagickCore::Image
4420  *newImage;
4421 
4422  GetPPException;
4423  newImage=ShadowImage(constImage(),percent_opacity_, sigma_,x_, y_,
4424  exceptionInfo);
4425  replaceImage(newImage);
4426  ThrowImageException;
4427 }
4428 
4429 void Magick::Image::sharpen(const double radius_,const double sigma_)
4430 {
4431  MagickCore::Image
4432  *newImage;
4433 
4434  GetPPException;
4435  newImage=SharpenImage(constImage(),radius_,sigma_,exceptionInfo);
4436  replaceImage(newImage);
4437  ThrowImageException;
4438 }
4439 
4440 void Magick::Image::sharpenChannel(const ChannelType channel_,
4441  const double radius_,const double sigma_)
4442 {
4443  MagickCore::Image
4444  *newImage;
4445 
4446  GetPPException;
4447  GetAndSetPPChannelMask(channel_);
4448  newImage=SharpenImage(constImage(),radius_,sigma_,exceptionInfo);
4449  RestorePPChannelMask;
4450  replaceImage(newImage);
4451  ThrowImageException;
4452 }
4453 
4454 void Magick::Image::shave(const Geometry &geometry_)
4455 {
4456  MagickCore::Image
4457  *newImage;
4458 
4459  RectangleInfo
4460  shaveInfo=geometry_;
4461 
4462  GetPPException;
4463  newImage=ShaveImage(constImage(),&shaveInfo,exceptionInfo);
4464  replaceImage(newImage);
4465  ThrowImageException;
4466 }
4467 
4468 void Magick::Image::shear(const double xShearAngle_,const double yShearAngle_)
4469 {
4470  MagickCore::Image
4471  *newImage;
4472 
4473  GetPPException;
4474  newImage=ShearImage(constImage(),xShearAngle_,yShearAngle_,exceptionInfo);
4475  replaceImage(newImage);
4476  ThrowImageException;
4477 }
4478 
4479 void Magick::Image::sigmoidalContrast(const bool sharpen_,
4480  const double contrast,const double midpoint)
4481 {
4482  modifyImage();
4483  GetPPException;
4484  (void) SigmoidalContrastImage(image(),(MagickBooleanType) sharpen_,contrast,
4485  midpoint,exceptionInfo);
4486  ThrowImageException;
4487 }
4488 
4489 std::string Magick::Image::signature(const bool force_) const
4490 {
4491  return(_imgRef->signature(force_));
4492 }
4493 
4494 void Magick::Image::sketch(const double radius_,const double sigma_,
4495  const double angle_)
4496 {
4497  MagickCore::Image
4498  *newImage;
4499 
4500  GetPPException;
4501  newImage=SketchImage(constImage(),radius_,sigma_,angle_,exceptionInfo);
4502  replaceImage(newImage);
4503  ThrowImageException;
4504 }
4505 
4506 void Magick::Image::solarize(const double factor_)
4507 {
4508  modifyImage();
4509  GetPPException;
4510  SolarizeImage(image(),factor_,exceptionInfo);
4511  ThrowImageException;
4512 }
4513 
4514 void Magick::Image::sparseColor(const ChannelType channel_,
4515  const SparseColorMethod method_,const size_t numberArguments_,
4516  const double *arguments_)
4517 {
4518  MagickCore::Image
4519  *newImage;
4520 
4521  GetPPException;
4522  GetAndSetPPChannelMask(channel_);
4523  newImage=SparseColorImage(constImage(),method_,numberArguments_,arguments_,
4524  exceptionInfo);
4525  RestorePPChannelMask;
4526  replaceImage(newImage);
4527  ThrowImageException;
4528 }
4529 
4530 void Magick::Image::splice(const Geometry &geometry_)
4531 {
4532  MagickCore::Image
4533  *newImage;
4534 
4535  RectangleInfo
4536  spliceInfo=geometry_;
4537 
4538  GetPPException;
4539  newImage=SpliceImage(constImage(),&spliceInfo,exceptionInfo);
4540  replaceImage(newImage);
4541  ThrowImageException;
4542 }
4543 
4544 void Magick::Image::splice(const Geometry &geometry_,
4545  const Color &backgroundColor_)
4546 {
4547  backgroundColor(backgroundColor_);
4548  splice(geometry_);
4549 }
4550 
4551 void Magick::Image::splice(const Geometry &geometry_,
4552  const Color &backgroundColor_,const GravityType gravity_)
4553 {
4554  backgroundColor(backgroundColor_);
4555  image()->gravity=gravity_;
4556  splice(geometry_);
4557 }
4558 
4559 void Magick::Image::spread(const double amount_)
4560 {
4561  MagickCore::Image
4562  *newImage;
4563 
4564  GetPPException;
4565  newImage=SpreadImage(constImage(),image()->interpolate,amount_,exceptionInfo);
4566  replaceImage(newImage);
4567  ThrowImageException;
4568 }
4569 
4570 Magick::ImageStatistics Magick::Image::statistics() const
4571 {
4572  return(ImageStatistics(*this));
4573 }
4574 
4575 void Magick::Image::stegano(const Image &watermark_)
4576 {
4577  MagickCore::Image
4578  *newImage;
4579 
4580  GetPPException;
4581  newImage=SteganoImage(constImage(),watermark_.constImage(),exceptionInfo);
4582  replaceImage(newImage);
4583  ThrowImageException;
4584 }
4585 
4586 void Magick::Image::stereo(const Image &rightImage_)
4587 {
4588  MagickCore::Image
4589  *newImage;
4590 
4591  GetPPException;
4592  newImage=StereoImage(constImage(),rightImage_.constImage(),exceptionInfo);
4593  replaceImage(newImage);
4594  ThrowImageException;
4595 }
4596 
4597 void Magick::Image::strip(void)
4598 {
4599  modifyImage();
4600  GetPPException;
4601  StripImage(image(),exceptionInfo);
4602  ThrowImageException;
4603 }
4604 
4605 Magick::Image Magick::Image::subImageSearch(const Image &reference_,
4606  const MetricType metric_,Geometry *offset_,double *similarityMetric_,
4607  const double similarityThreshold)
4608 {
4609  MagickCore::Image
4610  *newImage;
4611 
4612  RectangleInfo
4613  offset;
4614 
4615  GetPPException;
4616  newImage=SimilarityImage(image(),reference_.constImage(),metric_,
4617  similarityThreshold,&offset,similarityMetric_,exceptionInfo);
4618  ThrowImageException;
4619  if (offset_ != (Geometry *) NULL)
4620  *offset_=offset;
4621  if (newImage == (MagickCore::Image *) NULL)
4622  return(Magick::Image());
4623  else
4624  return(Magick::Image(newImage));
4625 }
4626 
4627 void Magick::Image::swirl(const double degrees_)
4628 {
4629  MagickCore::Image
4630  *newImage;
4631 
4632  GetPPException;
4633  newImage=SwirlImage(constImage(),degrees_,image()->interpolate,
4634  exceptionInfo);
4635  replaceImage(newImage);
4636  ThrowImageException;
4637 }
4638 
4639 void Magick::Image::syncPixels(void)
4640 {
4641  GetPPException;
4642  (void) SyncAuthenticPixels(image(),exceptionInfo);
4643  ThrowImageException;
4644 }
4645 
4646 void Magick::Image::texture(const Image &texture_)
4647 {
4648  modifyImage();
4649  GetPPException;
4650  TextureImage(image(),texture_.constImage(),exceptionInfo);
4651  ThrowImageException;
4652 }
4653 
4654 void Magick::Image::threshold(const double threshold_)
4655 {
4656  modifyImage();
4657  GetPPException;
4658  BilevelImage(image(),threshold_,exceptionInfo);
4659  ThrowImageException;
4660 }
4661 
4662 void Magick::Image::thumbnail(const Geometry &geometry_)
4663 {
4664  MagickCore::Image
4665  *newImage;
4666 
4667  size_t
4668  height=rows(),
4669  width=columns();
4670 
4671  ssize_t
4672  x=0,
4673  y=0;
4674 
4675  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
4676  &height);
4677 
4678  GetPPException;
4679  newImage=ThumbnailImage(constImage(),width,height,exceptionInfo);
4680  replaceImage(newImage);
4681  ThrowImageException;
4682 }
4683 
4684 void Magick::Image::tint(const std::string opacity_)
4685 {
4686  MagickCore::Image
4687  *newImage;
4688 
4689  PixelInfo
4690  color;
4691 
4692  GetPPException;
4693  color=static_cast<PixelInfo>(constOptions()->fillColor());
4694  newImage=TintImage(constImage(),opacity_.c_str(),&color,exceptionInfo);
4695  replaceImage(newImage);
4696  ThrowImageException;
4697 }
4698 
4699 void Magick::Image::transformOrigin(const double x_,const double y_)
4700 {
4701  modifyImage();
4702  options()->transformOrigin(x_,y_);
4703 }
4704 
4705 void Magick::Image::transformReset(void)
4706 {
4707  modifyImage();
4708  options()->transformReset();
4709 }
4710 
4711 void Magick::Image::transformScale(const double sx_,const double sy_)
4712 {
4713  modifyImage();
4714  options()->transformScale(sx_,sy_);
4715 }
4716 
4717 void Magick::Image::transparent(const Color &color_,const bool inverse_)
4718 {
4719  PixelInfo
4720  target;
4721 
4722  std::string
4723  color;
4724 
4725  if (!color_.isValid())
4726  throwExceptionExplicit(MagickCore::OptionError,
4727  "Color argument is invalid");
4728 
4729  color=color_;
4730  GetPPException;
4731  (void) QueryColorCompliance(color.c_str(),AllCompliance,&target,
4732  exceptionInfo);
4733  modifyImage();
4734  TransparentPaintImage(image(),&target,TransparentAlpha,
4735  inverse_ == true ? MagickTrue : MagickFalse,exceptionInfo);
4736  ThrowImageException;
4737 }
4738 
4739 void Magick::Image::transparentChroma(const Color &colorLow_,
4740  const Color &colorHigh_)
4741 {
4742  std::string
4743  colorHigh,
4744  colorLow;
4745 
4746  PixelInfo
4747  targetHigh,
4748  targetLow;
4749 
4750  if (!colorLow_.isValid() || !colorHigh_.isValid())
4751  throwExceptionExplicit(MagickCore::OptionError,
4752  "Color argument is invalid");
4753 
4754  colorLow=colorLow_;
4755  colorHigh=colorHigh_;
4756 
4757  GetPPException;
4758  (void) QueryColorCompliance(colorLow.c_str(),AllCompliance,&targetLow,
4759  exceptionInfo);
4760  (void) QueryColorCompliance(colorHigh.c_str(),AllCompliance,&targetHigh,
4761  exceptionInfo);
4762  modifyImage();
4763  TransparentPaintImageChroma(image(),&targetLow,&targetHigh,TransparentAlpha,
4764  MagickFalse,exceptionInfo);
4765  ThrowImageException;
4766 }
4767 
4768 void Magick::Image::transpose(void)
4769 {
4770  MagickCore::Image
4771  *newImage;
4772 
4773  GetPPException;
4774  newImage=TransposeImage(constImage(),exceptionInfo);
4775  replaceImage(newImage);
4776  ThrowImageException;
4777 }
4778 
4779 void Magick::Image::transverse(void)
4780 {
4781  MagickCore::Image
4782  *newImage;
4783 
4784  GetPPException;
4785  newImage=TransverseImage(constImage(),exceptionInfo);
4786  replaceImage(newImage);
4787  ThrowImageException;
4788 }
4789 
4790 void Magick::Image::trim(void)
4791 {
4792  MagickCore::Image
4793  *newImage;
4794 
4795  GetPPException;
4796  newImage=TrimImage(constImage(),exceptionInfo);
4797  replaceImage(newImage);
4798  ThrowImageException;
4799 }
4800 
4801 Magick::Image Magick::Image::uniqueColors(void) const
4802 {
4803  MagickCore::Image
4804  *image;
4805 
4806  GetPPException;
4807  image=UniqueImageColors(constImage(),exceptionInfo);
4808  ThrowImageException;
4809  if (image == (MagickCore::Image *) NULL)
4810  return(Magick::Image());
4811  else
4812  return(Magick::Image(image));
4813 }
4814 
4815 void Magick::Image::unsharpmask(const double radius_,const double sigma_,
4816  const double amount_,const double threshold_)
4817 {
4818  MagickCore::Image
4819  *newImage;
4820 
4821  GetPPException;
4822  newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_,
4823  exceptionInfo);
4824  replaceImage(newImage);
4825  ThrowImageException;
4826 }
4827 
4828 void Magick::Image::unsharpmaskChannel(const ChannelType channel_,
4829  const double radius_,const double sigma_,const double amount_,
4830  const double threshold_)
4831 {
4832  MagickCore::Image
4833  *newImage;
4834 
4835  GetPPException;
4836  GetAndSetPPChannelMask(channel_);
4837  newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_,
4838  exceptionInfo);
4839  RestorePPChannelMask;
4840  replaceImage(newImage);
4841  ThrowImageException;
4842 }
4843 
4844 void Magick::Image::vignette(const double radius_,const double sigma_,
4845  const ssize_t x_,const ssize_t y_)
4846 {
4847  MagickCore::Image
4848  *newImage;
4849 
4850  GetPPException;
4851  newImage=VignetteImage(constImage(),radius_,sigma_,x_,y_,exceptionInfo);
4852  replaceImage(newImage);
4853  ThrowImageException;
4854 }
4855 
4856 void Magick::Image::wave(const double amplitude_,const double wavelength_)
4857 {
4858  MagickCore::Image
4859  *newImage;
4860 
4861  GetPPException;
4862  newImage=WaveImage(constImage(),amplitude_,wavelength_,image()->interpolate,
4863  exceptionInfo);
4864  replaceImage(newImage);
4865  ThrowImageException;
4866 }
4867 
4868 void Magick::Image::waveletDenoise(const double threshold_,
4869  const double softness_)
4870 {
4871  MagickCore::Image
4872  *newImage;
4873 
4874  GetPPException;
4875  newImage=WaveletDenoiseImage(constImage(),threshold_,softness_,
4876  exceptionInfo);
4877  replaceImage(newImage);
4878  ThrowImageException;
4879 }
4880 
4881 void Magick::Image::whiteThreshold(const std::string &threshold_)
4882 {
4883  modifyImage();
4884  GetPPException;
4885  WhiteThresholdImage(image(),threshold_.c_str(),exceptionInfo);
4886  ThrowImageException;
4887 }
4888 
4889 void Magick::Image::whiteThresholdChannel(const ChannelType channel_,
4890  const std::string &threshold_)
4891 {
4892  modifyImage();
4893  GetPPException;
4894  GetAndSetPPChannelMask(channel_);
4895  WhiteThresholdImage(image(),threshold_.c_str(),exceptionInfo);
4896  RestorePPChannelMask;
4897  ThrowImageException;
4898 }
4899 
4900 void Magick::Image::write(Blob *blob_)
4901 {
4902  size_t
4903  length=0;
4904 
4905  void
4906  *data;
4907 
4908  modifyImage();
4909  GetPPException;
4910  data=ImagesToBlob(constImageInfo(),image(),&length,exceptionInfo);
4911  if (length > 0)
4912  blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4913  else
4914  data=RelinquishMagickMemory(data);
4915  ThrowImageException;
4916 }
4917 
4918 void Magick::Image::write(Blob *blob_,const std::string &magick_)
4919 {
4920  size_t
4921  length=0;
4922 
4923  void
4924  *data;
4925 
4926  modifyImage();
4927  magick(magick_);
4928  GetPPException;
4929  data=ImagesToBlob(constImageInfo(),image(),&length,exceptionInfo);
4930  if (length > 0)
4931  blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4932  else
4933  data=RelinquishMagickMemory(data);
4934  ThrowImageException;
4935 }
4936 
4937 void Magick::Image::write(Blob *blob_,const std::string &magick_,
4938  const size_t depth_)
4939 {
4940  size_t
4941  length=0;
4942 
4943  void
4944  *data;
4945 
4946  modifyImage();
4947  magick(magick_);
4948  depth(depth_);
4949  GetPPException;
4950  data=ImagesToBlob(constImageInfo(),image(),&length,exceptionInfo);
4951  if (length > 0)
4952  blob_->updateNoCopy(data,length,Blob::MallocAllocator);
4953  else
4954  data=RelinquishMagickMemory(data);
4955  ThrowImageException;
4956 }
4957 
4958 void Magick::Image::write(const ssize_t x_,const ssize_t y_,
4959  const size_t columns_,const size_t rows_,const std::string &map_,
4960  const StorageType type_,void *pixels_)
4961 {
4962  GetPPException;
4963  ExportImagePixels(image(),x_,y_,columns_,rows_,map_.c_str(),type_,pixels_,
4964  exceptionInfo);
4965  ThrowImageException;
4966 }
4967 
4968 void Magick::Image::write(const std::string &imageSpec_)
4969 {
4970  modifyImage();
4971  fileName(imageSpec_);
4972  GetPPException;
4973  WriteImage(constImageInfo(),image(),exceptionInfo);
4974  ThrowImageException;
4975 }
4976 
4977 void Magick::Image::writeMask(const Magick::Image &mask_)
4978 {
4979  mask(mask_,WritePixelMask);
4980 }
4981 
4982 Magick::Image Magick::Image::writeMask(void) const
4983 {
4984  return(mask(WritePixelMask));
4985 }
4986 
4987 void Magick::Image::writePixels(const Magick::QuantumType quantum_,
4988  unsigned char *destination_)
4989 {
4990  QuantumInfo
4991  *quantum_info;
4992 
4993  quantum_info=AcquireQuantumInfo(imageInfo(),image());
4994  GetPPException;
4995  ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4996  quantum_,destination_, exceptionInfo);
4997  quantum_info=DestroyQuantumInfo(quantum_info);
4998  ThrowImageException;
4999 }
5000 
5001 void Magick::Image::zoom(const Geometry &geometry_)
5002 {
5003  MagickCore::Image
5004  *newImage;
5005 
5006  size_t
5007  height=rows(),
5008  width=columns();
5009 
5010  ssize_t
5011  x=0,
5012  y=0;
5013 
5014  ParseMetaGeometry(static_cast<std::string>(geometry_).c_str(),&x,&y,&width,
5015  &height);
5016 
5017  GetPPException;
5018  newImage=ResizeImage(constImage(),width,height,image()->filter,exceptionInfo);
5019  replaceImage(newImage);
5020  ThrowImageException;
5021 }
5022 
5023 Magick::Image::Image(MagickCore::Image *image_)
5024  : _imgRef(new ImageRef(image_))
5025 {
5026 }
5027 
5028 MagickCore::Image *&Magick::Image::image(void)
5029 {
5030  return(_imgRef->image());
5031 }
5032 
5033 const MagickCore::Image *Magick::Image::constImage(void) const
5034 {
5035  return(_imgRef->image());
5036 }
5037 
5038 MagickCore::ImageInfo *Magick::Image::imageInfo(void)
5039 {
5040  return(_imgRef->options()->imageInfo());
5041 }
5042 
5043 const MagickCore::ImageInfo *Magick::Image::constImageInfo(void) const
5044 {
5045  return(_imgRef->options()->imageInfo());
5046 }
5047 
5048 Magick::Options *Magick::Image::options(void)
5049 {
5050  return(_imgRef->options());
5051 }
5052 
5053 const Magick::Options *Magick::Image::constOptions(void) const
5054 {
5055  return(_imgRef->options());
5056 }
5057 
5058 MagickCore::QuantizeInfo *Magick::Image::quantizeInfo(void)
5059 {
5060  return(_imgRef->options()->quantizeInfo());
5061 }
5062 
5063 const MagickCore::QuantizeInfo *Magick::Image::constQuantizeInfo(void) const
5064 {
5065  return(_imgRef->options()->quantizeInfo());
5066 }
5067 
5068 void Magick::Image::modifyImage(void)
5069 {
5070  if (!_imgRef->isShared())
5071  return;
5072 
5073  GetPPException;
5074  replaceImage(CloneImage(image(),0,0,MagickTrue,exceptionInfo));
5075  ThrowImageException;
5076 }
5077 
5078 MagickCore::Image *Magick::Image::replaceImage(MagickCore::Image *replacement_)
5079 {
5080  MagickCore::Image
5081  *image;
5082 
5083  if (replacement_)
5084  image=replacement_;
5085  else
5086  {
5087  GetPPException;
5088  image=AcquireImage(constImageInfo(),exceptionInfo);
5089  ThrowImageException;
5090  }
5091 
5092  _imgRef=ImageRef::replaceImage(_imgRef,image);
5093  return(image);
5094 }
5095 
5096 void Magick::Image::read(MagickCore::Image *image,
5097  MagickCore::ExceptionInfo *exceptionInfo)
5098 {
5099  // Ensure that multiple image frames were not read.
5100  if (image != (MagickCore::Image *) NULL &&
5101  image->next != (MagickCore::Image *) NULL)
5102  {
5103  MagickCore::Image
5104  *next;
5105 
5106  // Destroy any extra image frames
5107  next=image->next;
5108  image->next=(MagickCore::Image *) NULL;
5109  next->previous=(MagickCore::Image *) NULL;
5110  DestroyImageList(next);
5111  }
5112  replaceImage(image);
5113  if (exceptionInfo->severity == MagickCore::UndefinedException &&
5114  image == (MagickCore::Image *) NULL)
5115  {
5116  (void) MagickCore::DestroyExceptionInfo(exceptionInfo);
5117  if (!quiet())
5118  throwExceptionExplicit(MagickCore::ImageWarning,
5119  "No image was loaded.");
5120  return;
5121  }
5122  ThrowImageException;
5123 }
5124 
5125 void Magick::Image::floodFill(const ssize_t x_,const ssize_t y_,
5126  const Magick::Image *fillPattern_,const Magick::Color &fill_,
5127  const MagickCore::PixelInfo *target_,const bool invert_)
5128 {
5130  fillColor;
5131 
5132  MagickCore::Image
5133  *fillPattern;
5134 
5135  // Set drawing fill pattern or fill color
5136  fillColor=options()->fillColor();
5137  fillPattern=(MagickCore::Image *)NULL;
5138  if (options()->fillPattern() != (MagickCore::Image *)NULL)
5139  {
5140  GetPPException;
5141  fillPattern=CloneImage(options()->fillPattern(),0,0,MagickTrue,
5142  exceptionInfo);
5143  ThrowImageException;
5144  }
5145 
5146  if (fillPattern_ == (Magick::Image *)NULL)
5147  {
5148  options()->fillPattern((MagickCore::Image *)NULL);
5149  options()->fillColor(fill_);
5150  }
5151  else
5152  options()->fillPattern(fillPattern_->constImage());
5153 
5154  GetPPException;
5155  (void) FloodfillPaintImage(image(),options()->drawInfo(),
5156  target_,static_cast<ssize_t>(x_),static_cast<ssize_t>(y_),
5157  (MagickBooleanType) invert_,exceptionInfo);
5158 
5159  options()->fillColor(fillColor);
5160  options()->fillPattern(fillPattern);
5161  ThrowImageException;
5162 }
5163 
5164 void Magick::Image::mask(const Magick::Image &mask_,const PixelMask type)
5165 {
5166  modifyImage();
5167 
5168  GetPPException;
5169  if (mask_.isValid())
5170  SetImageMask(image(),type,mask_.constImage(),exceptionInfo);
5171  else
5172  SetImageMask(image(),type,(MagickCore::Image *) NULL,exceptionInfo);
5173  ThrowImageException;
5174 }
5175 
5176 Magick::Image Magick::Image::mask(const PixelMask type) const
5177 {
5178  MagickCore::Image
5179  *image;
5180 
5181  GetPPException;
5182  image = GetImageMask(constImage(),type,exceptionInfo);
5183  ThrowImageException;
5184 
5185  if (image == (MagickCore::Image *) NULL)
5186  return(Magick::Image());
5187  else
5188  return(Magick::Image(image));
5189 }