]> granicus.if.org Git - imagemagick/commitdiff
https://www.imagemagick.org/discourse-server/posting.php?mode=reply&f=1&t=29692
authorCristy <urban-warrior@imagemagick.org>
Thu, 28 Jul 2016 21:41:37 +0000 (17:41 -0400)
committerCristy <urban-warrior@imagemagick.org>
Thu, 28 Jul 2016 21:41:37 +0000 (17:41 -0400)
MagickCore/image.c
MagickCore/option.c
MagickWand/mogrify.c
MagickWand/operation.c

index ca66a79f7e6e116c6aa0dcb40c90787bbe230370..69a6f3a6eec0f69148aec484b134e0767a36ca3e 100644 (file)
@@ -3193,20 +3193,23 @@ MagickExport MagickBooleanType SetImageRegionMask(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      MagickRealType
-        intensity;
+      Quantum
+        pixel;
 
-      intensity=0;
+      pixel=0;
+      if (((x >= region->x) && (x < (region->x+region->width))) &&
+          ((y >= region->y) && (y < (region->y+region->height))))
+        pixel=QuantumRange;
       switch (type)
       {
         case WritePixelMask:
         {
-          SetPixelWriteMask(image,ClampToQuantum(QuantumRange-intensity),q);
+          SetPixelWriteMask(image,pixel,q);
           break;
         }
         default:
         {
-          SetPixelReadMask(image,ClampToQuantum(QuantumRange-intensity),q);
+          SetPixelReadMask(image,pixel,q);
           break;
         }
       }
index b2e04e4366afa76610757b98563385fa6c12ec40..9de7ff68f22b9d8c36ba7136e41086768c451e72 100644 (file)
@@ -659,8 +659,8 @@ static const OptionInfo
     { "-recolor", 1L, ReplacedOptionFlag | SimpleOperatorFlag, MagickTrue },
     { "+red-primary", 0L, ImageInfoOptionFlag, MagickFalse },
     { "-red-primary", 1L, ImageInfoOptionFlag, MagickFalse },
-    { "+region", 0L, NoImageOperatorFlag, MagickFalse },
-    { "-region", 1L, NoImageOperatorFlag, MagickFalse },
+    { "+region", 0L, SimpleOperatorFlag, MagickFalse },
+    { "-region", 1L, SimpleOperatorFlag, MagickFalse },
     { "+remap", 0L, ListOperatorFlag | NeverInterpretArgsFlag | FireOptionFlag, MagickFalse },
     { "-remap", 1L, SimpleOperatorFlag | NeverInterpretArgsFlag, MagickFalse },
     { "+remote", 0L, NonMagickOptionFlag, MagickFalse },
index e4b4ffc5f768b4c9d147a61d0e29f46ac1489b52..ec97631713a7b2a1d1872097d220253b375ffd3e 100644 (file)
@@ -147,7 +147,7 @@ WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
   (void) setlocale(LC_ALL,"");
   (void) setlocale(LC_NUMERIC,"C");
   GetPathComponent(argv[0],TailPath,client_name);
-  SetClientName(client_name);
+  (void) SetClientName(client_name);
   concurrent=MagickFalse;
   duration=(-1.0);
   iterations=1;
@@ -690,9 +690,6 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
   GeometryInfo
     geometry_info;
 
-  Image
-    *region_image;
-
   ImageInfo
     *mogrify_info;
 
@@ -740,7 +737,6 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
   interpolate_method=UndefinedInterpolatePixel;
   format=GetImageOption(mogrify_info,"format");
   SetGeometry(*image,&region_geometry);
-  region_image=NewImageList();
   /*
     Transmogrify the image.
   */
@@ -2597,33 +2593,18 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
           }
         if (LocaleCompare("region",option+1) == 0)
           {
+            /*
+              Apply read mask as defined by a region geometry.
+            */
             (void) SyncImageSettings(mogrify_info,*image,exception);
-            if (region_image != (Image *) NULL)
+            if (*option == '+')
               {
-                /*
-                  Composite region.
-                */
-                (void) CompositeImage(region_image,*image,
-                   region_image->alpha_trait != UndefinedPixelTrait ?
-                   CopyCompositeOp : OverCompositeOp,MagickTrue,
-                   region_geometry.x,region_geometry.y,exception);
-                *image=DestroyImage(*image);
-                *image=region_image;
-                region_image = (Image *) NULL;
+                (void) SetImageRegionMask(*image,ReadPixelMask,
+                  (const RectangleInfo *) NULL,exception);
+                break;
               }
-            if (*option == '+')
-              break;
-            /*
-              Apply transformations to a selected region of the image.
-            */
-            (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
-              exception);
-            mogrify_image=CropImage(*image,&region_geometry,exception);
-            if (mogrify_image == (Image *) NULL)
-              break;
-            region_image=(*image);
-            *image=mogrify_image;
-            mogrify_image=(Image *) NULL;
+            (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
+            (void) SetImageRegionMask(*image,ReadPixelMask,&geometry,exception);
             break;
           }
         if (LocaleCompare("render",option+1) == 0)
@@ -3388,20 +3369,6 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
       ReplaceImageInListReturnLast(image,mogrify_image);
     i+=count;
   }
-  if (region_image != (Image *) NULL)
-    {
-      /*
-        Composite transformed region onto image.
-      */
-      (void) SyncImageSettings(mogrify_info,*image,exception);
-      (void) CompositeImage(region_image,*image,
-         region_image->alpha_trait != UndefinedPixelTrait ? CopyCompositeOp :
-         OverCompositeOp,MagickTrue,region_geometry.x,region_geometry.y,
-         exception);
-      *image=DestroyImage(*image);
-      *image=region_image;
-      region_image = (Image *) NULL;
-    }
   /*
     Free resources.
   */
index ec1bc451144b0b7aadd3314cb2073c5d4107ffca..14d3795f6881732e618461d2f32c37061f9ac262 100644 (file)
@@ -3026,14 +3026,6 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
     }
     case 'r':
     {
-      if (LocaleCompare("rotational-blur",option+1) == 0)
-        {
-          flags=ParseGeometry(arg1,&geometry_info);
-          if ((flags & RhoValue) == 0)
-            CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
-          new_image=RotationalBlurImage(_image,geometry_info.rho,_exception);
-          break;
-        }
       if (LocaleCompare("raise",option+1) == 0)
         {
           if (IsGeometry(arg1) == MagickFalse)
@@ -3089,7 +3081,22 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
       if (LocaleCompare("recolor",option+1) == 0)
         {
           CLIWandWarnReplaced("-color-matrix");
-          (void) CLISimpleOperatorImage(cli_wand,"-color-matrix",arg1,NULL,exception);
+          (void) CLISimpleOperatorImage(cli_wand,"-color-matrix",arg1,NULL,
+            exception);
+        }
+      if (LocaleCompare("region",option+1) == 0)
+        {
+          if (IsGeometry(arg1) == MagickFalse)
+            CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+          if (*option == '+')
+            {
+              (void) SetImageRegionMask(_image,ReadPixelMask,
+                (const RectangleInfo *) NULL,_exception);
+              break;
+            }
+          (void) ParseGravityGeometry(_image,arg1,&geometry,_exception);
+          (void) SetImageRegionMask(_image,ReadPixelMask,&geometry,_exception);
+          break;
         }
       if (LocaleCompare("remap",option+1) == 0)
         {
@@ -3158,6 +3165,14 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           new_image=RotateImage(_image,geometry_info.rho,_exception);
           break;
         }
+      if (LocaleCompare("rotational-blur",option+1) == 0)
+        {
+          flags=ParseGeometry(arg1,&geometry_info);
+          if ((flags & RhoValue) == 0)
+            CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+          new_image=RotationalBlurImage(_image,geometry_info.rho,_exception);
+          break;
+        }
       CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
     }
     case 's':