[prev in list] [next in list] [prev in thread] [next in thread] 

List:       graphicsmagick-commit
Subject:    [GM-commit] GraphicsMagick: EnhanceImage(): Eliminate use of ugly Enhance ma...
From:       GraphicsMagick Commits <graphicsmagick-commit () lists ! sourceforge ! net>
Date:       2012-07-29 16:11:47
Message-ID: hg.92cdb169cf07.1343578307.-1602079902 () blade ! simplesystems ! org
[Download RAW message or body]

changeset 92cdb169cf07 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=92cdb169cf07
                
summary: EnhanceImage(): Eliminate use of ugly Enhance macro.  Only filter based on \
color channels (ignore opacity).

diffstat:

 ChangeLog                              |    5 +
 VisualMagick/installer/inc/version.isx |    4 +-
 magick/effect.c                        |  125 ++++++++++++++++++--------------
 magick/version.h                       |    4 +-
 www/Changelog.html                     |    7 +
 www/api/effect.html                    |    5 +-
 6 files changed, 88 insertions(+), 62 deletions(-)

diffs (238 lines):

diff -r 257e79fb7f6d -r 92cdb169cf07 ChangeLog
--- a/ChangeLog	Sat Jul 28 18:19:51 2012 -0500
+++ b/ChangeLog	Sun Jul 29 11:11:41 2012 -0500
@@ -1,3 +1,8 @@
+2012-07-29  Bob Friesenhahn  <bfriesen@simple.dallas.tx.us>
+
+	* magick/effect.c (EnhanceImage): Eliminate use of ugly Enhance
+	macro.  Only filter based on color channels (ignore opacity).
+
 2012-07-28  Bob Friesenhahn  <bfriesen@simple.dallas.tx.us>
 
 	* magick/studio.h (MAGICK_CACHE_LINE_SIZE): Assume a cache line
diff -r 257e79fb7f6d -r 92cdb169cf07 VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx	Sat Jul 28 18:19:51 2012 -0500
+++ b/VisualMagick/installer/inc/version.isx	Sun Jul 29 11:11:41 2012 -0500
@@ -10,5 +10,5 @@
 
 #define public MagickPackageName "GraphicsMagick"
 #define public MagickPackageVersion "1.4"
-#define public MagickPackageVersionAddendum ".020120728"
-#define public MagickPackageReleaseDate "snapshot-20120728"
+#define public MagickPackageVersionAddendum ".020120729"
+#define public MagickPackageReleaseDate "snapshot-20120729"
diff -r 257e79fb7f6d -r 92cdb169cf07 magick/effect.c
--- a/magick/effect.c	Sat Jul 28 18:19:51 2012 -0500
+++ b/magick/effect.c	Sun Jul 29 11:11:41 2012 -0500
@@ -1836,8 +1836,9 @@
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  EnhanceImage() applies a digital filter that improves the quality of a
-%  noisy image.
+%  EnhanceImage() applies a digital filter to the image color channels that
+%  improves the quality of a noisy image.  The opacity channel is preserved
+%  but is otherwise ignored.
 %
 %  The format of the EnhanceImage method is:
 %
@@ -1851,36 +1852,20 @@
 %
 %
 */
-#define Enhance(weight)                                                 \
-  mean=((double) r->red+pixel.red)/2.0;                                 \
-  distance=r->red-(double) pixel.red;                                   \
-  distance_squared=(2.0*((double) MaxRGBDouble+1.0)+mean)*distance*     \
-    distance/MaxRGBDouble;                                              \
-  mean=((double) r->green+pixel.green)/2.0;                             \
-  distance=r->green-(double) pixel.green;                               \
-  distance_squared+=4.0*distance*distance;                              \
-  mean=((double) r->blue+pixel.blue)/2.0;                               \
-  distance=r->blue-(double) pixel.blue;                                 \
-  distance_squared+=                                                    \
-  (3.0*(MaxRGBDouble+1.0)-1.0-mean)*distance*distance/MaxRGBDouble;     \
-  mean=((double) r->opacity+pixel.opacity)/2.0;                         \
-  distance=r->opacity-(double) pixel.opacity;                           \
-  distance_squared+=                                                    \
-  (3.0*((double) MaxRGBDouble+1.0)-1.0-mean)*distance*                  \
-    distance/MaxRGBDouble;                                              \
-  if (distance_squared < ((double) MaxRGBDouble*MaxRGBDouble/25.0))     \
-    {                                                                   \
-      aggregate.red+=(weight)*r->red;                                   \
-      aggregate.green+=(weight)*r->green;                               \
-      aggregate.blue+=(weight)*r->blue;                                 \
-      aggregate.opacity+=(weight)*r->opacity;                           \
-      total_weight+=(weight);                                           \
-    }                                                                   \
-  r++;
 #define EnhanceImageText "[%s] Enhance...  "
 
 MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
 {
+  static const double
+    Weights[5][5] =
+    {
+      {  5.0,  8.0, 10.0,  8.0,  5.0 },
+      {  8.0, 20.0, 40.0, 20.0,  8.0 },
+      { 10.0, 40.0, 80.0, 40.0, 10.0 },
+      {  8.0, 20.0, 40.0, 20.0,  8.0 },
+      {  5.0,  8.0, 10.0,  8.0,  5.0 }
+    };
+
   Image
     *enhance_image;
 
@@ -1955,6 +1940,27 @@
           thread_status=MagickFail;
         if (thread_status != MagickFail)
           {
+	    DoublePixelPacket
+	      aggregate;
+
+	    double
+	      pixel_red,
+	      pixel_green,
+	      pixel_blue,
+	      total_weight;
+
+	    register const PixelPacket
+	      *r;
+
+	    double
+	      distance,
+	      distance_squared,
+	      mean;
+
+	    unsigned long
+	      i,
+	      j;
+
             /*
               Transfer first 2 pixels of the scanline.
             */
@@ -1962,43 +1968,50 @@
             *q++=(*(p+2*image->columns+1));
             for (x=2; x < (long) (image->columns-2); x++)
               {
-                DoublePixelPacket
-                  aggregate;
-
-                double
-                  distance,
-                  distance_squared,
-                  mean,
-                  total_weight;
-
-                PixelPacket
-                  pixel;
-
-                register const PixelPacket
-                  *r;
-
                 /*
                   Compute weighted average of target pixel color components.
                 */
                 aggregate=zero;
                 total_weight=0.0;
                 r=p+2*image->columns+2;
-                pixel=(*r);
-                r=p;
-                Enhance(5.0);  Enhance(8.0);  Enhance(10.0); Enhance(8.0);  \
                Enhance(5.0);
-                r=p+image->columns;
-                Enhance(8.0);  Enhance(20.0); Enhance(40.0); Enhance(20.0); \
                Enhance(8.0);
-                r=p+2*image->columns;
-                Enhance(10.0); Enhance(40.0); Enhance(80.0); Enhance(40.0); \
                Enhance(10.0);
-                r=p+3*image->columns;
-                Enhance(8.0);  Enhance(20.0); Enhance(40.0); Enhance(20.0); \
                Enhance(8.0);
-                r=p+4*image->columns;
-                Enhance(5.0);  Enhance(8.0);  Enhance(10.0); Enhance(8.0);  \
Enhance(5.0); +		pixel_red=r->red;
+		pixel_green=r->green;
+		pixel_blue=r->blue;
+
+		for (i=0 ; i < 5; i++)
+		  {
+		    r=p+i*image->columns;
+		    for (j = 0; j < 5; j++)
+		      {
+			const double red = (double) r->red;
+			const double green = (double) r->green;
+			const double blue = (double) r->blue;
+			mean=(red+pixel_red)/2.0;
+			distance=red-pixel_red;
+			distance_squared=(2.0*(MaxRGBDouble+1.0)+mean)*distance*
+			  distance/MaxRGBDouble;
+			mean=(green+pixel_green)/2.0;
+			distance=green-pixel_green;
+			distance_squared+=4.0*distance*distance;
+			mean=(blue+pixel_blue)/2.0;
+			distance=blue-pixel_blue;
+			distance_squared+=
+			  (3.0*(MaxRGBDouble+1.0)-1.0-mean)*distance*distance/MaxRGBDouble;
+			if (distance_squared < ((MaxRGBDouble*MaxRGBDouble/25.0)))
+			  {
+			    const double weight = Weights[i][j];
+			    aggregate.red+=weight*red;
+			    aggregate.green+=weight*green;
+			    aggregate.blue+=weight*blue;
+			    total_weight+=weight;
+			  }
+			r++;
+		      }
+		  }
                 q->red=(Quantum) \
                ((aggregate.red+(total_weight/2.0)-1.0)/total_weight);
                 q->green=(Quantum) \
                ((aggregate.green+(total_weight/2.0)-1.0)/total_weight);
                 q->blue=(Quantum) \
                ((aggregate.blue+(total_weight/2.0)-1.0)/total_weight);
-                q->opacity=(Quantum)
-                  ((aggregate.opacity+(total_weight/2.0)-1.0)/total_weight);
+		q->opacity=p->opacity;
                 p++;
                 q++;
               }
diff -r 257e79fb7f6d -r 92cdb169cf07 magick/version.h
--- a/magick/version.h	Sat Jul 28 18:19:51 2012 -0500
+++ b/magick/version.h	Sun Jul 29 11:11:41 2012 -0500
@@ -38,8 +38,8 @@
 #define MagickLibVersion  0x120900
 #define MagickLibVersionText  "1.4"
 #define MagickLibVersionNumber 12,9,0
-#define MagickChangeDate   "20120728"
-#define MagickReleaseDate  "snapshot-20120728"
+#define MagickChangeDate   "20120729"
+#define MagickReleaseDate  "snapshot-20120729"
 	
 /*
   The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines
diff -r 257e79fb7f6d -r 92cdb169cf07 www/Changelog.html
--- a/www/Changelog.html	Sat Jul 28 18:19:51 2012 -0500
+++ b/www/Changelog.html	Sun Jul 29 11:11:41 2012 -0500
@@ -36,6 +36,13 @@
 <div class="document">
 
 
+<p>2012-07-29  Bob Friesenhahn  &lt;<a class="reference external" \
href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#6 \
4;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 +<blockquote>
+<ul class="simple">
+<li>magick/effect.c (EnhanceImage): Eliminate use of ugly Enhance
+macro.  Only filter based on color channels (ignore opacity).</li>
+</ul>
+</blockquote>
 <p>2012-07-28  Bob Friesenhahn  &lt;<a class="reference external" \
href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#6 \
4;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
  <blockquote>
 <ul class="simple">
diff -r 257e79fb7f6d -r 92cdb169cf07 www/api/effect.html
--- a/www/api/effect.html	Sat Jul 28 18:19:51 2012 -0500
+++ b/www/api/effect.html	Sun Jul 29 11:11:41 2012 -0500
@@ -413,8 +413,9 @@
 </div>
 <div class="section" id="id22">
 <h2>Description</h2>
-<p>EnhanceImage() applies a digital filter that improves the quality of a
-noisy image.</p>
+<p>EnhanceImage() applies a digital filter to the image color channels that
+improves the quality of a noisy image.  The opacity channel is preserved
+but is otherwise ignored.</p>
 <p>The format of the EnhanceImage method is:</p>
 <pre class="literal-block">
 <a class="reference external" href="../api/types.html#image">Image</a> \
*EnhanceImage( const <a class="reference external" \
href="../api/types.html#image">Image</a> *image, <a class="reference external" \
href="../api/types.html#exceptioninfo">ExceptionInfo</a> *exception );

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Graphicsmagick-commit mailing list
Graphicsmagick-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-commit


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic