]> granicus.if.org Git - imagemagick/blobdiff - Magick++/lib/Image.cpp
Added setColorMetric to Magick++.
[imagemagick] / Magick++ / lib / Image.cpp
index 84df690f2f443bc7709ccb8eb144da45ace4ef77..b51e850302189187bb0adb31bd7cec2f2d954b85 100644 (file)
@@ -203,6 +203,30 @@ Magick::Image::Image(const Image &image_)
   _imgRef->increase();
 }
 
+Magick::Image::Image(const Image &image_,const Geometry &geometry_)
+  : _imgRef(new ImageRef)
+{
+  const RectangleInfo
+    geometry=geometry_;
+
+  OffsetInfo
+    offset;
+
+  MagickCore::Image
+    *image;
+
+  GetPPException;
+  image=CloneImage(image_.constImage(),geometry_.width(),geometry_.height(),
+    MagickTrue,exceptionInfo);
+  replaceImage(image);
+  _imgRef->options(new Options(*image_.constOptions()));
+  offset.x=0;
+  offset.y=0;
+  (void) CopyImagePixels(image,image_.constImage(),&geometry,&offset,
+    exceptionInfo);
+  ThrowImageException;
+}
+
 Magick::Image::Image(const size_t width_,const size_t height_,
   const std::string &map_,const StorageType type_,const void *pixels_)
   : _imgRef(new ImageRef)
@@ -320,17 +344,6 @@ Magick::Color Magick::Image::alphaColor(void) const
   return(Color(constImage()->matte_color));
 }
 
-void Magick::Image::antiAlias(const bool flag_)
-{
-  modifyImage();
-  options()->antiAlias(flag_);
-}
-
-bool Magick::Image::antiAlias(void) const
-{
-  return(constOptions()->antiAlias());
-}
-
 void Magick::Image::animationDelay(const size_t delay_)
 {
   modifyImage();
@@ -774,13 +787,8 @@ MagickCore::MagickSizeType Magick::Image::fileSize(void) const
 
 void Magick::Image::fillColor(const Magick::Color &fillColor_)
 {
-  std::string
-    value;
-
   modifyImage();
   options()->fillColor(fillColor_);
-  value=fillColor_;
-  artifact("fill",value);
 }
 
 Magick::Color Magick::Image::fillColor(void) const
@@ -854,6 +862,17 @@ std::string Magick::Image::font(void) const
   return(constOptions()->font());
 }
 
+void Magick::Image::fontFamily(const std::string &family_)
+{
+  modifyImage();
+  options()->fontFamily(family_);
+}
+
+std::string Magick::Image::fontFamily(void) const
+{
+  return(constOptions()->fontFamily());
+}
+
 void Magick::Image::fontPointsize(const double pointSize_)
 {
   modifyImage();
@@ -865,6 +884,28 @@ double Magick::Image::fontPointsize(void) const
   return(constOptions()->fontPointsize());
 }
 
+void Magick::Image::fontStyle(const StyleType pointSize_)
+{
+  modifyImage();
+  options()->fontStyle(pointSize_);
+}
+
+Magick::StyleType Magick::Image::fontStyle(void) const
+{
+  return(constOptions()->fontStyle());
+}
+
+void Magick::Image::fontWeight(const size_t weight_)
+{
+  modifyImage();
+  options()->fontWeight(weight_);
+}
+
+size_t Magick::Image::fontWeight(void) const
+{
+  return(constOptions()->fontWeight());
+}
+
 std::string Magick::Image::format(void) const
 {
   const MagickInfo 
@@ -1095,9 +1136,10 @@ void Magick::Image::mask(const Magick::Image &mask_)
 
   GetPPException;
   if (mask_.isValid())
-    SetImageMask(image(),mask_.constImage(),exceptionInfo);
+    SetImageMask(image(),ReadPixelMask,mask_.constImage(),exceptionInfo);
   else
-    SetImageMask(image(),(MagickCore::Image *) NULL,exceptionInfo);
+    SetImageMask(image(),ReadPixelMask,(MagickCore::Image *) NULL,
+      exceptionInfo);
   ThrowImageException;
 }
 
@@ -1510,6 +1552,17 @@ size_t Magick::Image::subRange(void) const
   return(constOptions()->subRange());
 }
 
+void Magick::Image::textAntiAlias(const bool flag_)
+{
+  modifyImage();
+  options()->textAntiAlias(flag_);
+}
+
+bool Magick::Image::textAntiAlias(void) const
+{
+  return(constOptions()->textAntiAlias());
+}
+
 void Magick::Image::textDirection(DirectionType direction_)
 {
   modifyImage();
@@ -1576,6 +1629,17 @@ double Magick::Image::textKerning(void) const
   return(constOptions()->textKerning());
 }
 
+void Magick::Image::textUnderColor(const Color &underColor_)
+{
+  modifyImage();
+  options()->textUnderColor(underColor_);
+}
+
+Magick::Color Magick::Image::textUnderColor(void) const
+{
+  return(constOptions()->textUnderColor());
+}
+
 size_t Magick::Image::totalColors(void) const
 {
   size_t
@@ -1609,10 +1673,7 @@ Magick::ImageType Magick::Image::type(void) const
 {
   if (constOptions()->type() != UndefinedType)
     return(constOptions()->type());
-  else if (constImage()->type != UndefinedType)
-    return(constImage()->type);
-  else
-    return(determineType());
+  return(GetImageType(constImage()));
 }
 
 void Magick::Image::type(const Magick::ImageType type_)
@@ -1987,7 +2048,6 @@ void Magick::Image::autoLevel(void)
 {
   modifyImage();
   GetPPException;
-  (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
   (void) AutoLevelImage(image(),exceptionInfo);
   ThrowImageException;
 }
@@ -1997,7 +2057,6 @@ void Magick::Image::autoLevelChannel(const ChannelType channel_)
   modifyImage();
   GetPPException;
   GetAndSetPPChannelMask(channel_);
-  (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
   (void) AutoLevelImage(image(),exceptionInfo);
   RestorePPChannelMask;
   ThrowImageException;
@@ -2013,7 +2072,6 @@ void Magick::Image::autoOrient(void)
     return;
 
   GetPPException;
-  (void) SyncImageSettings(imageInfo(),image(),exceptionInfo);
   newImage=AutoOrientImage(constImage(),image()->orientation,exceptionInfo);
   replaceImage(newImage);
   ThrowImageException;
@@ -2123,6 +2181,14 @@ void Magick::Image::cannyEdge(const double radius_,const double sigma_,
   ThrowImageException;
 }
 
+void Magick::Image::cdl(const std::string &cdl_)
+{
+  modifyImage();
+  GetPPException;
+  (void) ColorDecisionListImage(image(),cdl_.c_str(),exceptionInfo);
+  ThrowImageException;
+}
+
 void Magick::Image::channel(const ChannelType channel_)
 {
   MagickCore::Image
@@ -2211,14 +2277,6 @@ void Magick::Image::chromaWhitePoint(double *x_,double *y_) const
   *y_=constImage()->chromaticity.white_point.y;
 }
 
-void Magick::Image::cdl(const std::string &cdl_)
-{
-  modifyImage();
-  GetPPException;
-  (void) ColorDecisionListImage(image(),cdl_.c_str(),exceptionInfo);
-  ThrowImageException;
-}
-
 void Magick::Image::clamp(void)
 {
   modifyImage();
@@ -2375,7 +2433,7 @@ void Magick::Image::colorMatrix(const size_t order_,
   ThrowImageException;
 }
 
-bool Magick::Image::compare(const Image &reference_)
+bool Magick::Image::compare(const Image &reference_) const
 {
   bool
     status;
@@ -2384,8 +2442,7 @@ bool Magick::Image::compare(const Image &reference_)
     ref=reference_;
 
   GetPPException;
-  modifyImage();
-  status=static_cast<bool>(IsImagesEqual(image(),ref.constImage(),
+  status=static_cast<bool>(IsImagesEqual(constImage(),ref.constImage(),
     exceptionInfo));
   ThrowImageException;
   return(status);
@@ -2566,6 +2623,21 @@ void Magick::Image::convolve(const size_t order_,const double *kernel_)
   ThrowImageException;
 }
 
+void Magick::Image::copyPixels(const Image &source_,const Geometry &geometry_,
+  const Offset &offset_)
+{
+  const OffsetInfo
+    offset=offset_;
+
+  const RectangleInfo
+    geometry=geometry_;
+
+  GetPPException;
+  (void) CopyImagePixels(image(),source_.constImage(),&geometry,&offset,
+    exceptionInfo);
+  ThrowImageException;
+}
+
 void Magick::Image::crop(const Geometry &geometry_)
 {
   MagickCore::Image
@@ -2677,17 +2749,6 @@ void Magick::Image::despeckle(void)
   ThrowImageException;
 }
 
-Magick::ImageType Magick::Image::determineType(void) const
-{
-  ImageType
-    image_type;
-
-  GetPPException;
-  image_type=GetImageType(constImage(),exceptionInfo);
-  ThrowImageException;
-  return(image_type);
-}
-
 void Magick::Image::display(void)
 {
   GetPPException;
@@ -2814,6 +2875,55 @@ void Magick::Image::erase(void)
   ThrowImageException;
 }
 
+void Magick::Image::evaluate(const ChannelType channel_,
+  const MagickEvaluateOperator operator_,double rvalue_)
+{
+  GetPPException;
+  GetAndSetPPChannelMask(channel_);
+  EvaluateImage(image(),operator_,rvalue_,exceptionInfo);
+  RestorePPChannelMask;
+  ThrowImageException;
+}
+
+void Magick::Image::evaluate(const ChannelType channel_,
+  const MagickFunction function_,const size_t number_parameters_,
+  const double *parameters_)
+{
+  GetPPException;
+  GetAndSetPPChannelMask(channel_);
+  FunctionImage(image(),function_,number_parameters_,parameters_,
+    exceptionInfo);
+  RestorePPChannelMask;
+  ThrowImageException;
+}
+
+void Magick::Image::evaluate(const ChannelType channel_,const ssize_t x_,
+  const ssize_t y_,const size_t columns_,const size_t rows_,
+  const MagickEvaluateOperator operator_,const double rvalue_)
+{
+  RectangleInfo
+    geometry;
+
+  MagickCore::Image
+    *cropImage;
+
+  geometry.width = columns_;
+  geometry.height = rows_;
+  geometry.x = x_;
+  geometry.y = y_;
+
+  GetPPException;
+  cropImage=CropImage(image(),&geometry,exceptionInfo);
+  GetAndSetPPChannelMask(channel_);
+  EvaluateImage(cropImage,operator_,rvalue_,exceptionInfo);
+  RestorePPChannelMask;
+  (void) CompositeImage(image(),cropImage,image()->alpha_trait == 
+    BlendPixelTrait ? OverCompositeOp : CopyCompositeOp,MagickFalse,
+    geometry.x,geometry.y,exceptionInfo );
+  cropImage=DestroyImageList(cropImage);
+  ThrowImageException;
+}
+
 void Magick::Image::extent(const Geometry &geometry_ )
 {
   MagickCore::Image
@@ -3219,6 +3329,17 @@ void Magick::Image::houghLine(const size_t width_,const size_t height_,
   ThrowImageException;
 }
 
+Magick::ImageType Magick::Image::identifyType(void) const
+{
+  ImageType
+    image_type;
+
+  GetPPException;
+  image_type=IdentifyImageType(constImage(),exceptionInfo);
+  ThrowImageException;
+  return(image_type);
+}
+
 void Magick::Image::implode(const double factor_)
 {
   MagickCore::Image
@@ -3330,6 +3451,26 @@ void Magick::Image::levelColorsChannel(const ChannelType channel_,
   ThrowImageException;
 }
 
+void Magick::Image::levelize(const double blackPoint_,const double whitePoint_,
+  const double gamma_)
+{
+  modifyImage();
+  GetPPException;
+  (void) LevelizeImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
+  ThrowImageException;
+}
+
+void Magick::Image::levelizeChannel(const ChannelType channel_,
+  const double blackPoint_,const double whitePoint_,const double gamma_)
+{
+  modifyImage();
+  GetPPException;
+  GetAndSetPPChannelMask(channel_);
+  (void) LevelizeImage(image(),blackPoint_,whitePoint_,gamma_,exceptionInfo);
+  RestorePPChannelMask;
+  ThrowImageException;
+}
+
 void Magick::Image::linearStretch(const double blackPoint_,
   const double whitePoint_)
 {
@@ -3361,6 +3502,17 @@ void Magick::Image::liquidRescale(const Geometry &geometry_)
   ThrowImageException;
 }
 
+void Magick::Image::localContrast(const double radius_,const double strength_)
+{
+  MagickCore::Image
+    *newImage;
+
+  GetPPException;
+  newImage=LocalContrastImage(constImage(),radius_,strength_,exceptionInfo);
+  replaceImage(newImage);
+  ThrowImageException;
+}
+
 void Magick::Image::magnify(void)
 {
   MagickCore::Image
@@ -3457,9 +3609,11 @@ void Magick::Image::morphology(const MorphologyMethod method_,
 
   option=CommandOptionToMnemonic(MagickKernelOptions,kernel_);
   if (option == (const char *)NULL)
-    throwExceptionExplicit(MagickCore::OptionError,
-      "Unable to determine kernel type.");
-
+    {
+      throwExceptionExplicit(MagickCore::OptionError,
+        "Unable to determine kernel type.");
+      return;
+    }
   kernel=std::string(option);
   if (!arguments_.empty())
     kernel+=":"+arguments_;
@@ -3795,43 +3949,6 @@ void Magick::Image::quantize(const bool measureError_)
   ThrowImageException;
 }
 
-void Magick::Image::quantumOperator(const ChannelType channel_,
-  const MagickEvaluateOperator operator_,double rvalue_)
-{
-  GetPPException;
-  GetAndSetPPChannelMask(channel_);
-  EvaluateImage(image(),operator_,rvalue_,exceptionInfo);
-  RestorePPChannelMask;
-  ThrowImageException;
-}
-
-void Magick::Image::quantumOperator(const ssize_t x_,const ssize_t y_,
-  const size_t columns_,const size_t rows_,const ChannelType channel_,
-  const MagickEvaluateOperator operator_,const double rvalue_)
-{
-  RectangleInfo
-    geometry;
-
-  MagickCore::Image
-    *cropImage;
-
-  geometry.width = columns_;
-  geometry.height = rows_;
-  geometry.x = x_;
-  geometry.y = y_;
-
-  GetPPException;
-  cropImage=CropImage(image(),&geometry,exceptionInfo);
-  GetAndSetPPChannelMask(channel_);
-  EvaluateImage(cropImage,operator_,rvalue_,exceptionInfo);
-  RestorePPChannelMask;
-  (void) CompositeImage(image(),cropImage,image()->alpha_trait == 
-    BlendPixelTrait ? OverCompositeOp : CopyCompositeOp,MagickFalse,
-    geometry.x,geometry.y,exceptionInfo );
-  cropImage=DestroyImageList(cropImage);
-  ThrowImageException;
-}
-
 void Magick::Image::raise(const Geometry &geometry_,const bool raisedFlag_)
 {
   RectangleInfo
@@ -4186,6 +4303,22 @@ void Magick::Image::sepiaTone(const double threshold_)
   ThrowImageException;
 }
 
+bool Magick::Image::setColorMetric(const Image &reference_)
+{
+  bool
+    status;
+
+  Image
+    ref=reference_;
+
+  GetPPException;
+  modifyImage();
+  status=static_cast<bool>(SetImageColorMetric(image(),ref.constImage(),
+    exceptionInfo));
+  ThrowImageException;
+  return(status);
+}
+
 Magick::Quantum *Magick::Image::setPixels(const ssize_t x_,const ssize_t y_,
   const size_t columns_,const size_t rows_)
 {
@@ -4287,7 +4420,7 @@ void Magick::Image::sigmoidalContrast(const bool sharpen_,
 
 std::string Magick::Image::signature(const bool force_) const
 {
-  return(_imgRef->signature());
+  return(_imgRef->signature(force_));
 }
 
 void Magick::Image::sketch(const double radius_,const double sigma_,
@@ -4361,8 +4494,7 @@ void Magick::Image::spread(const size_t amount_)
     *newImage;
 
   GetPPException;
-  newImage=SpreadImage(constImage(),amount_,image()->interpolate,
-    exceptionInfo);
+  newImage=SpreadImage(constImage(),image()->interpolate,amount_,exceptionInfo);
   replaceImage(newImage);
   ThrowImageException;
 }
@@ -4533,7 +4665,7 @@ void Magick::Image::transformScale(const double sx_,const double sy_)
   options()->transformScale(sx_,sy_);
 }
 
-void Magick::Image::transparent(const Color &color_)
+void Magick::Image::transparent(const Color &color_,const bool inverse_)
 {
   PixelInfo
     target;
@@ -4550,8 +4682,8 @@ void Magick::Image::transparent(const Color &color_)
   (void) QueryColorCompliance(color.c_str(),AllCompliance,&target,
     exceptionInfo);
   modifyImage();
-  TransparentPaintImage(image(),&target,TransparentAlpha,MagickFalse,
-    exceptionInfo);
+  TransparentPaintImage(image(),&target,TransparentAlpha,
+    inverse_ == true ? MagickTrue : MagickFalse,exceptionInfo);
   ThrowImageException;
 }