[gimp/gimp-2-8] Bug 683153 - Lighting effects - bump mapping: top two rows of pixels are...



commit d53d7291340d0fca7c7dcc483cc07a914501f28a
Author: TÃo Mazars <teo mazars ensimag fr>
Date:   Sat Feb 16 14:09:48 2013 +0100

    Bug 683153 - Lighting effects - bump mapping: top two rows of pixels are...
    
    Init and interpolate the topmost row to avoid the use of a zero array.
    (cherry picked from commit b4b85cf8535bf9f7e8f4b0123f33741c2efdd7d5)

 plug-ins/lighting/lighting-apply.c |    5 +-
 plug-ins/lighting/lighting-shade.c |  105 ++++++++++++++++++++++++++++++++++++
 plug-ins/lighting/lighting-shade.h |    3 +
 3 files changed, 111 insertions(+), 2 deletions(-)
---
diff --git a/plug-ins/lighting/lighting-apply.c b/plug-ins/lighting/lighting-apply.c
index 9c7245d..df46e0d 100644
--- a/plug-ins/lighting/lighting-apply.c
+++ b/plug-ins/lighting/lighting-apply.c
@@ -104,8 +104,9 @@ compute_image (void)
 
   gimp_progress_init (_("Lighting Effects"));
 
-/*  if (mapvals.antialiasing==FALSE)
-    { */
+  /* Init the first row */
+  if (mapvals.bump_mapped == TRUE && mapvals.bumpmap_id != -1 && height >= 2)
+    interpol_row (0, width, 0);
 
   for (ycount = 0; ycount < height; ycount++)
     {
diff --git a/plug-ins/lighting/lighting-shade.c b/plug-ins/lighting/lighting-shade.c
index bad9c4d..ca33b61 100644
--- a/plug-ins/lighting/lighting-shade.c
+++ b/plug-ins/lighting/lighting-shade.c
@@ -167,10 +167,115 @@ precompute_init (gint w,
     }
 }
 
+
+/* Interpol linearly height[2] and triangle_normals[1]
+ * using the next row
+ */
+void
+interpol_row (gint x1,
+              gint x2,
+              gint y)
+{
+  GimpVector3   p1, p2, p3;
+  gint          n, i;
+  guchar        *map = NULL;
+  gint          bpp = 1;
+  guchar* bumprow1 = NULL;
+  guchar* bumprow2 = NULL;
+
+  if (mapvals.bumpmap_id != -1)
+    {
+      bpp = gimp_drawable_bpp(mapvals.bumpmap_id);
+    }
+
+  bumprow1 = g_new (guchar, pre_w * bpp);
+  bumprow2 = g_new (guchar, pre_w * bpp);
+
+  gimp_pixel_rgn_get_row (&bump_region, bumprow1, x1, y, x2 - x1);
+  gimp_pixel_rgn_get_row (&bump_region, bumprow2, x1, y+1, x2 - x1);
+
+  if (mapvals.bumpmaptype > 0)
+    {
+      switch (mapvals.bumpmaptype)
+        {
+        case 1:
+          map = logmap;
+          break;
+        case 2:
+          map = sinemap;
+          break;
+        default:
+          map = spheremap;
+          break;
+        }
+    }
+
+  for (n = 0; n < (x2 - x1); n++)
+    {
+      gdouble diff;
+      guchar mapval;
+      guchar mapval1, mapval2;
+
+      if (bpp>1)
+        {
+          mapval1 = (guchar)((float)((bumprow1[n * bpp] +bumprow1[n * bpp +1] + bumprow1[n * bpp + 2])/3.0 
)) ;
+          mapval2 = (guchar)((float)((bumprow2[n * bpp] +bumprow2[n * bpp +1] + bumprow2[n * bpp + 2])/3.0 
)) ;
+        }
+      else
+        {
+          mapval1 = bumprow1[n * bpp];
+          mapval2 = bumprow2[n * bpp];
+        }
+
+      diff =  mapval1 - mapval2;
+      mapval = (guchar) CLAMP (mapval1 + diff, 0.0, 255.0);
+
+      if (mapvals.bumpmaptype > 0)
+        {
+          heights[1][n] = (gdouble) mapvals.bumpmax * (gdouble) map[mapval1] / 255.0;
+          heights[2][n] = (gdouble) mapvals.bumpmax * (gdouble) map[mapval] / 255.0;
+        }
+      else
+        {
+          heights[1][n] = (gdouble) mapvals.bumpmax * (gdouble) mapval1 / 255.0;
+          heights[2][n] = (gdouble) mapvals.bumpmax * (gdouble) mapval / 255.0;
+        }
+    }
+
+  i = 0;
+  for (n = 0; n < (x2 - x1 - 1); n++)
+    {
+      /* heights rows 1 and 2 are inverted */
+      p1.x = 0.0;
+      p1.y = ystep;
+      p1.z = heights[1][n] - heights[2][n];
+
+      p2.x = xstep;
+      p2.y = ystep;
+      p2.z = heights[1][n+1] - heights[2][n];
+
+      p3.x = xstep;
+      p3.y = 0.0;
+      p3.z = heights[2][n+1] - heights[2][n];
+
+      triangle_normals[1][i] = gimp_vector3_cross_product (&p2, &p1);
+      triangle_normals[1][i+1] = gimp_vector3_cross_product (&p3, &p2);
+
+      gimp_vector3_normalize (&triangle_normals[1][i]);
+      gimp_vector3_normalize (&triangle_normals[1][i+1]);
+
+      i += 2;
+    }
+
+  g_free (bumprow1);
+  g_free (bumprow2);
+}
+
 /********************************************/
 /* Compute triangle and then vertex normals */
 /********************************************/
 
+
 void
 precompute_normals (gint x1,
                     gint x2,
diff --git a/plug-ins/lighting/lighting-shade.h b/plug-ins/lighting/lighting-shade.h
index 600542b..536df95 100644
--- a/plug-ins/lighting/lighting-shade.h
+++ b/plug-ins/lighting/lighting-shade.h
@@ -13,5 +13,8 @@ void    precompute_init               (gint         w,
 void    precompute_normals            (gint         x1,
                                       gint         x2,
                                       gint         y);
+void    interpol_row                  (gint         x1,
+                                       gint         x2,
+                                       gint         y);
 
 #endif  /* __LIGHTING_SHADE_H__ */


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