]> granicus.if.org Git - imagemagick/blobdiff - MagickWand/operation.c
Revert -spread behavior
[imagemagick] / MagickWand / operation.c
index f2bfd74eb9282115f4e1a416606fab677128926a..e2174a8fc1c2b86d7cd25ab1490ffaf0966e3e45 100644 (file)
@@ -237,14 +237,15 @@ static Image *SparseColorOption(const Image *image,
       x++;   /* floating point argument */
   }
   /* control points and color values */
-  error = IsMagickTrue( x % (2+number_colors) );
+  if ((x % (2+number_colors)) != 0)
+    {
+      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+        "InvalidArgument","'%s': %s", "sparse-color",
+        "Invalid number of Arguments");
+      return( (Image *) NULL);
+    }
+  error=MagickFalse;
   number_arguments=x;
-  if ( IfMagickTrue(error) ) {
-    (void) ThrowMagickException(exception,GetMagickModule(),
-               OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
-               "Invalid number of Arguments");
-    return( (Image *) NULL);
-  }
 
   /* Allocate and fill in the floating point arguments */
   sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
@@ -266,7 +267,7 @@ static Image *SparseColorOption(const Image *image,
       (void) ThrowMagickException(exception,GetMagickModule(),
             OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
             "Color found, instead of X-coord");
-      error = MagickTrue;
+      error=MagickTrue;
       break;
     }
     sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
@@ -277,7 +278,7 @@ static Image *SparseColorOption(const Image *image,
       (void) ThrowMagickException(exception,GetMagickModule(),
             OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
             "Color found, instead of Y-coord");
-      error = MagickTrue;
+      error=MagickTrue;
       break;
     }
     sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
@@ -348,15 +349,18 @@ static Image *SparseColorOption(const Image *image,
       }
     }
   }
-  if ( number_arguments != x && !error ) {
-    (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-      "InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error");
-    sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
-    return( (Image *) NULL);
-  }
-  if ( error )
-    return( (Image *) NULL);
-
+  if (error != MagickFalse)
+    {
+      sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
+      return((Image *) NULL);
+    }
+  if (number_arguments != x)
+    {
+      sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
+      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+        "InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error");
+      return((Image *) NULL);
+    }
   /* Call the Sparse Color Interpolation function with the parsed arguments */
   sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
     exception);
@@ -417,8 +421,8 @@ WandPrivate void CLISettingOptionInfo(MagickCLI *cli_wand,
 #define _draw_info        (cli_wand->draw_info)
 #define _quantize_info    (cli_wand->quantize_info)
 #define IfSetOption       (*option=='-')
-#define ArgBoolean        IsMagickTrue(IfSetOption)
-#define ArgBooleanNot     IsMagickFalse(IfSetOption)
+#define ArgBoolean        IfSetOption ? MagickTrue : MagickFalse
+#define ArgBooleanNot     IfSetOption ? MagickFalse : MagickTrue
 #define ArgBooleanString  (IfSetOption?"true":"false")
 #define ArgOption(def)    (IfSetOption?arg1:(const char *)(def))
 
@@ -692,7 +696,7 @@ WandPrivate void CLISettingOptionInfo(MagickCLI *cli_wand,
           /* DefineImageOption() equals SetImageOption() but with '=' */
           if (IfSetOption)
             (void) DefineImageOption(_image_info,arg1);
-          else if (IsMagickFalse(DeleteImageOption(_image_info,arg1)))
+          else if (DeleteImageOption(_image_info,arg1) == MagickFalse)
             CLIWandExceptArgBreak(OptionError,"NoSuchOption",option,arg1);
           break;
         }
@@ -1558,23 +1562,13 @@ WandPrivate void CLISettingOptionInfo(MagickCLI *cli_wand,
     {
       if (LocaleCompare("weight",option+1) == 0)
         {
-          /* Just what does using a font 'weight' do ???
-             There is no "-list weight" output (reference manual says there is)
-          */
-          arg1=ArgOption("all");
-          _draw_info->weight=StringToUnsignedLong(arg1);
-          if (LocaleCompare(arg1,"all") == 0)
-            _draw_info->weight=0;
-          if (LocaleCompare(arg1,"bold") == 0)
-            _draw_info->weight=700;
-          if (LocaleCompare(arg1,"bolder") == 0)
-            if (_draw_info->weight <= 800)
-              _draw_info->weight+=100;
-          if (LocaleCompare(arg1,"lighter") == 0)
-            if (_draw_info->weight >= 100)
-              _draw_info->weight-=100;
-          if (LocaleCompare(arg1,"normal") == 0)
-            _draw_info->weight=400;
+          ssize_t
+            weight;
+
+          weight=ParseCommandOption(MagickWeightOptions,MagickFalse,arg1);
+          if (weight == -1)
+            weight=StringToUnsignedLong(arg1);
+          _draw_info->weight=(size_t) weight;
           break;
         }
       if (LocaleCompare("white-point",option+1) == 0)
@@ -1694,8 +1688,8 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
 #define _option_type      ((CommandOptionFlags) cli_wand->command->flags)
 #define IfNormalOp        (*option=='-')
 #define IfPlusOp          (*option!='-')
-#define IsNormalOp        IsMagickTrue(IfNormalOp)
-#define IsPlusOp          IsMagickFalse(IfNormalOp)
+#define IsNormalOp        IfNormalOp ? MagickTrue : MagickFalse
+#define IsPlusOp          IfNormalOp ? MagickFalse : MagickTrue
 
   assert(cli_wand != (MagickCLI *) NULL);
   assert(cli_wand->signature == MagickWandSignature);
@@ -1986,7 +1980,7 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           if (IfNormalOp)
             (void) ClipImage(_image,_exception);
           else /* "+mask" remove the write mask */
-            (void) SetImageMask(_image,(Image *) NULL,_exception);
+            (void) SetImageMask(_image,ReadPixelMask,(Image *) NULL,_exception);
           break;
         }
       if (LocaleCompare("clip-mask",option+1) == 0)
@@ -2009,7 +2003,7 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
 
           if (IfPlusOp) {
             /* use "+clip-mask" Remove the write mask for -clip-path */
-            (void) SetImageMask(_image,(Image *) NULL,_exception);
+            (void) SetImageMask(_image,ReadPixelMask,(Image *) NULL,_exception);
             break;
           }
           mask_image=GetImageCache(_image_info,arg1,_exception);
@@ -2041,7 +2035,7 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           mask_view=DestroyCacheView(mask_view);
           mask_image->alpha_trait=BlendPixelTrait;
           (void) SetImageColorspace(_image,GRAYColorspace,_exception);
-          (void) SetImageMask(_image,mask_image,_exception);
+          (void) SetImageMask(_image,ReadPixelMask,mask_image,_exception);
           mask_image=DestroyImage(mask_image);
           break;
         }
@@ -2740,21 +2734,9 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
         }
       if (LocaleCompare("mask",option+1) == 0)
         {
-          /* Note: arguments do not have percent escapes expanded */
-          Image
-            *mask;
-
-          if (IfPlusOp)
-            { /* Remove a mask. */
-              (void) SetImageMask(_image,(Image *) NULL,_exception);
-              break;
-            }
-          /* Set the image mask. */
-          mask=GetImageCache(_image_info,arg1,_exception);
-          if (mask == (Image *) NULL)
-            break;
-          (void) SetImageMask(_image,mask,_exception);
-          mask=DestroyImage(mask);
+          CLIWandWarnReplaced("-read-mask");
+          (void) CLISimpleOperatorImage(cli_wand,"-read-mask",NULL,NULL,
+            exception);
           break;
         }
       if (LocaleCompare("matte",option+1) == 0)
@@ -3069,6 +3051,26 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           (void) RandomThresholdImage(_image,arg1,_exception);
           break;
         }
+      if (LocaleCompare("read-mask",option+1) == 0)
+        {
+          /* Note: arguments do not have percent escapes expanded */
+          Image
+            *mask;
+
+          if (IfPlusOp)
+            { /* Remove a mask. */
+              (void) SetImageMask(_image,ReadPixelMask,(Image *) NULL,
+                _exception);
+              break;
+            }
+          /* Set the image mask. */
+          mask=GetImageCache(_image_info,arg1,_exception);
+          if (mask == (Image *) NULL)
+            break;
+          (void) SetImageMask(_image,ReadPixelMask,mask,_exception);
+          mask=DestroyImage(mask);
+          break;
+        }
       if (LocaleCompare("recolor",option+1) == 0)
         {
           CLIWandWarnReplaced("-color-matrix");
@@ -3318,8 +3320,8 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           flags=ParseGeometry(arg1,&geometry_info);
           if ((flags & RhoValue) == 0)
             CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg2);
-          new_image=SpreadImage(_image,geometry_info.rho,_image->interpolate,
-               _exception);
+          new_image=SpreadImage(_image,_image->interpolate,geometry_info.rho,
+           _exception);
           break;
         }
       if (LocaleCompare("statistic",option+1) == 0)
@@ -3518,6 +3520,26 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           (void) WhiteThresholdImage(_image,arg1,_exception);
           break;
         }
+      if (LocaleCompare("write-mask",option+1) == 0)
+        {
+          /* Note: arguments do not have percent escapes expanded */
+          Image
+            *mask;
+
+          if (IfPlusOp)
+            { /* Remove a mask. */
+              (void) SetImageMask(_image,WritePixelMask,(Image *) NULL,
+                _exception);
+              break;
+            }
+          /* Set the image mask. */
+          mask=GetImageCache(_image_info,arg1,_exception);
+          if (mask == (Image *) NULL)
+            break;
+          (void) SetImageMask(_image,WritePixelMask,mask,_exception);
+          mask=DestroyImage(mask);
+          break;
+        }
       CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
     }
     default:
@@ -3643,7 +3665,7 @@ WandPrivate MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
 #define _option_type    ((CommandOptionFlags) cli_wand->command->flags)
 #define IfNormalOp      (*option=='-')
 #define IfPlusOp        (*option!='-')
-#define IsNormalOp       IsMagickTrue(IfNormalOp)
+#define IsNormalOp      IfNormalOp ? MagickTrue : MagickFalse
 
   assert(cli_wand != (MagickCLI *) NULL);
   assert(cli_wand->signature == MagickWandSignature);
@@ -3822,7 +3844,7 @@ WandPrivate MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
           value=GetImageOption(_image_info,"compose:outside-overlay");
           if (value != (const char *) NULL) {   /* or this false */
             /* FUTURE: depreciate warning for "compose:outside-overlay"*/
-            clip_to_self= IsMagickFalse(IsStringNotFalse(value));
+            clip_to_self=IsStringFalse(value);
           }
 
           new_images=RemoveFirstImageFromList(&_images);