]> granicus.if.org Git - imagemagick/commitdiff
Trial of "-subimage" operator.
authoranthony <anthony@git.imagemagick.org>
Mon, 16 Apr 2012 13:59:03 +0000 (13:59 +0000)
committeranthony <anthony@git.imagemagick.org>
Mon, 16 Apr 2012 13:59:03 +0000 (13:59 +0000)
MagickCore/option.c
MagickWand/operation.c

index d6c162b01136680bdb3176e2d0ed227ad4946279..9ce40324a5f499202fbf52b6234e1e42cba02c20 100644 (file)
@@ -486,8 +486,8 @@ static const OptionInfo
     { "-maximum", 0L, DeprecateOptionFlag | FireOptionFlag, MagickTrue },
     { "+median", 1L, DeprecateOptionFlag, MagickTrue },
     { "-median", 1L, ReplacedOptionFlag | SimpleOperatorOptionFlag | FireOptionFlag, MagickTrue },
-    { "+metric", 0L, NonMagickOptionFlag, MagickFalse },
-    { "-metric", 1L, NonMagickOptionFlag, MagickFalse },
+    { "+metric", 0L, ImageInfoOptionFlag, MagickFalse },
+    { "-metric", 1L, ImageInfoOptionFlag, MagickFalse },
     { "+minimum", 0L, DeprecateOptionFlag | FireOptionFlag, MagickTrue },
     { "-minimum", 0L, DeprecateOptionFlag | FireOptionFlag, MagickTrue },
     { "+mode", 1L, NonMagickOptionFlag, MagickFalse },
@@ -667,8 +667,9 @@ static const OptionInfo
     { "-strokewidth", 1L, ImageInfoOptionFlag | DrawInfoOptionFlag, MagickFalse },
     { "+style", 0L, DrawInfoOptionFlag, MagickFalse },
     { "-style", 1L, DrawInfoOptionFlag, MagickFalse },
-    { "+subimage-search", 0L, NonMagickOptionFlag | ImageInfoOptionFlag, MagickFalse },
-    { "-subimage-search", 0L, NonMagickOptionFlag | ImageInfoOptionFlag, MagickFalse },
+//  { "+subimage-search", 0L, NonMagickOptionFlag | ImageInfoOptionFlag, MagickFalse },
+//  { "-subimage-search", 0L, NonMagickOptionFlag | ImageInfoOptionFlag, MagickFalse },
+    { "-subimage", 0L, ListOperatorOptionFlag, MagickFalse },
     { "+swap", 0L, ListOperatorOptionFlag | FireOptionFlag, MagickFalse },
     { "-swap", 1L, ListOperatorOptionFlag | FireOptionFlag, MagickFalse },
     { "+swirl", 1L, DeprecateOptionFlag, MagickTrue },
index f587b6cf7b219149bc847152093865afe4a7ff67..180df673991752a82106690d1c9c117ad60d6e19 100644 (file)
@@ -1061,7 +1061,7 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
           (void) QueryColorCompliance(ArgOption(MatteColor),AllCompliance,
              &_image_info->matte_color,_exception);
           break;
-        } 
+        }
       if (LocaleCompare("metric",option+1) == 0)
         {
           /* FUTURE: this is only used by CompareImages() which is used
@@ -1071,6 +1071,7 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
             CLIWandExceptArgBreak(OptionError,"UnrecognizedMetricType",
                 option,arg1);
           (void) SetImageOption(_image_info,option+1,ArgOption(NULL));
+          break;
         }
       if (LocaleCompare("monitor",option+1) == 0)
         {
@@ -1364,6 +1365,7 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
           _draw_info->style=(StyleType) parse;
           break;
         }
+#if 0
       if (LocaleCompare("subimage-search",option+1) == 0)
         {
         /* FUTURE: this is only used by CompareImages() which is used
@@ -1371,6 +1373,7 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
           (void) SetImageOption(_image_info,option+1,ArgBooleanString);
           break;
         }
+#endif
       if (LocaleCompare("synchronize",option+1) == 0)
         {
           /* FUTURE: syncronize to storage - but what does that mean? */
@@ -4142,20 +4145,68 @@ WandExport void CLIListOperatorImages(MagickCLI *cli_wand,
     {
       if (LocaleCompare("smush",option+1) == 0)
         {
-          Image
-            *smush_image;
-
+          /* FUTURE: this option needs more work to make better */
           ssize_t
             offset;
 
           if (IfMagickFalse(IsGeometry(arg1)))
             CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
           offset=(ssize_t) StringToLong(arg1);
-          smush_image=SmushImages(_images,normal_op,offset,_exception);
-          if (smush_image == (Image *) NULL)
-            break;
-          _images=DestroyImageList(_images);
-          _images=smush_image;
+          new_images=SmushImages(_images,normal_op,offset,_exception);
+          break;
+        }
+      if (LocaleCompare("subimage",option+1) == 0)
+        {
+          Image
+            *base_image,
+            *compare_image;
+
+          const char *
+            value;
+
+          MetricType
+            metric;
+
+          double
+            similarity;
+
+          RectangleInfo
+            offset;
+
+          base_image=GetImageFromList(_images,0);
+          compare_image=GetImageFromList(_images,1);
+
+          /* Comparision Metric */
+          metric=UndefinedMetric;
+          value=GetImageOption(_image_info,"metric");
+          if (value != (const char *) NULL)
+            metric=(MetricType) ParseCommandOption(MagickMetricOptions,
+              MagickFalse,value);
+
+          new_images=SimilarityImage(base_image,compare_image,metric,
+               &offset,&similarity,_exception);
+
+          if ( new_images != (Image *)NULL ) {
+            char
+              result[MaxTextExtent];
+
+            (void) FormatLocaleString(result,MaxTextExtent,"%lf",similarity);
+            (void) SetImageProperty(new_images,"subimage:similarity",result,
+                 _exception);
+            (void) FormatLocaleString(result,MaxTextExtent,"%+ld",
+                (long) offset.x);
+            (void) SetImageProperty(new_images,"subimage:x",result,
+                 _exception);
+            (void) FormatLocaleString(result,MaxTextExtent,"%+ld",
+                (long) offset.y);
+            (void) SetImageProperty(new_images,"subimage:y",result,
+                 _exception);
+            (void) FormatLocaleString(result,MaxTextExtent,"%lux%lu%+ld%+ld",
+                (unsigned long) offset.width,(unsigned long) offset.height,
+                (long) offset.x,(long) offset.y);
+            (void) SetImageProperty(new_images,"subimage:offset",result,
+                 _exception);
+          }
           break;
         }
       if (LocaleCompare("swap",option+1) == 0) {