gimp r26751 - in trunk: . app/paint-funcs



Author: neo
Date: Mon Aug 25 08:03:44 2008
New Revision: 26751
URL: http://svn.gnome.org/viewvc/gimp?rev=26751&view=rev

Log:
2008-08-25  Sven Neumann  <sven gimp org>

	* app/paint-funcs/scale-region.c: fixed progress feedback.



Modified:
   trunk/ChangeLog
   trunk/app/paint-funcs/scale-region.c

Modified: trunk/app/paint-funcs/scale-region.c
==============================================================================
--- trunk/app/paint-funcs/scale-region.c	(original)
+++ trunk/app/paint-funcs/scale-region.c	Mon Aug 25 08:03:44 2008
@@ -114,11 +114,14 @@
                                                const gdouble  xfrac,
                                                const gdouble  yfrac,
                                                guchar        *pixel);
-static void           determine_scale         (PixelRegion   *srcPR,
+static void           determine_levels        (PixelRegion   *srcPR,
                                                PixelRegion   *dstPR,
                                                gint          *levelx,
-                                               gint          *levely,
-                                               gint          *max_progress);
+                                               gint          *levely);
+static gint           determine_progress      (PixelRegion   *srcPR,
+                                               PixelRegion   *dstPR,
+                                               gint           levelx,
+                                               gint           levely);
 static inline void    gaussan_lanczos2        (const guchar  *pixels,
                                                const gint     bytes,
                                                guchar        *pixel);
@@ -160,26 +163,22 @@
 
 
 static void
-determine_scale (PixelRegion *srcPR,
-                 PixelRegion *dstPR,
-                 gint        *levelx,
-                 gint        *levely,
-                 gint        *max_progress)
+determine_levels (PixelRegion *srcPR,
+                  PixelRegion *dstPR,
+                  gint        *levelx,
+                  gint        *levely)
 {
   gdouble scalex = (gdouble) dstPR->w / (gdouble) srcPR->w;
   gdouble scaley = (gdouble) dstPR->h / (gdouble) srcPR->h;
   gint    width  = srcPR->w;
   gint    height = srcPR->h;
 
-  *max_progress = NUM_TILES (dstPR->w, dstPR->h);
-
   /* determine scaling levels */
   while (scalex > 2)
     {
       scalex  /= 2;
       width   *= 2;
       *levelx -= 1;
-      *max_progress += NUM_TILES (width, height);
     }
 
   while (scaley > 2)
@@ -187,7 +186,6 @@
       scaley  /= 2;
       height  *= 2;
       *levely -= 1;
-      *max_progress += NUM_TILES (width, height);
     }
 
   while (scalex < 0.5)
@@ -195,7 +193,6 @@
       scalex  *= 2;
       width   /= 2;
       *levelx += 1;
-      *max_progress += NUM_TILES (width, height);
     }
 
   while (scaley < 0.5)
@@ -203,10 +200,76 @@
       scaley  *= 2;
       height  *= 2;
       *levely += 1;
-      *max_progress += NUM_TILES (width, height);
     }
 }
 
+static gint
+determine_progress (PixelRegion *srcPR,
+                    PixelRegion *dstPR,
+                    gint         levelx,
+                    gint         levely)
+{
+  gint width  = srcPR->w;
+  gint height = srcPR->h;
+  gint tiles  = 0;
+
+  while (levelx < 0 && levely < 0)
+    {
+      width  <<= 1;
+      height <<= 1;
+      levelx++;
+      levely++;
+
+      tiles += NUM_TILES (width, height);
+    }
+
+  while (levelx < 0)
+    {
+      width <<= 1;
+      levelx++;
+
+      tiles += NUM_TILES (width, height);
+    }
+
+  while (levely < 0)
+    {
+      height <<= 1;
+      levely++;
+
+      tiles += NUM_TILES (width, height);
+    }
+
+  while (levelx > 0 && levely > 0)
+    {
+      width  >>= 1;
+      height >>= 1;
+      levelx--;
+      levely--;
+
+      tiles += NUM_TILES (width, height);
+    }
+
+  while (levelx > 0)
+    {
+      width <<= 1;
+      levelx--;
+
+      tiles += NUM_TILES (width, height);
+    }
+
+  while (levely > 0)
+    {
+      height <<= 1;
+      levely--;
+
+      tiles += NUM_TILES (width, height);
+    }
+
+  tiles += NUM_TILES (dstPR->w, dstPR->h);
+
+  return tiles;
+}
+
 static void
 scale_region_buffer (PixelRegion           *srcPR,
                      PixelRegion           *dstPR,
@@ -224,7 +287,8 @@
   gint         levely       = 0;
 
   /* determine scaling levels */
-  determine_scale (srcPR, dstPR, &levelx, &levely, &max_progress);
+  determine_levels (srcPR, dstPR, &levelx, &levely);
+  max_progress = determine_progress (srcPR, dstPR, levelx, levely);
 
   pixel_region_init_data (&tmpPR0,
                           g_memdup (srcPR->data, width * height * bytes),
@@ -367,7 +431,8 @@
   gint         levely       = 0;
 
   /* determine scaling levels */
-  determine_scale (srcPR, dstPR, &levelx, &levely, &max_progress);
+  determine_levels (srcPR, dstPR, &levelx, &levely);
+  max_progress = determine_progress (srcPR, dstPR, levelx, levely);
 
   if (levelx == 0 && levely == 0)
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]