Hello,

I think I found two bugs in src/glu/sgi/libutil/mipmap.c.  They are
actually two bugs that show up in several places.  I've attached a patch
that fixes them.  I realize that the GLU used in Mesa is from SGI so I
am not sure if reporting the bug on this list is appropriate.  If not
could somebody please tell me where to report it.

The first bug emerges when calling gluBuild2DMipmaps when the texture
dimensions are both powers of two and GL_UNPACK_ROW_LENGTH is larger
than the width of the input image (as would be the case if one is
building a texture from a subimage of a larger image).  The problem is
in the halveImage_*() functions where the pointer 't' is not properly
positioned to the beginning of each row before looping over the pixels
in a row.  Interestingly this is handled correctly in the functions
halve1Dimage_*(), halveImageSlice(), and halveImage3D().

The second bug emerges when calling gluBuild3DMipmaps when the texture
dimensions are all powers of two and GL_PACK_IMAGE_HEIGHT is larger than
the height of the input image.  The problem is in halveImageSlice() and
halveImage3D() where the pointer 't' is not properly positioned to the
beginning of each image before looping over the rows in an image.

-Greg

diff -uprN Mesa.orig/src/glu/sgi/libutil/mipmap.c Mesa/src/glu/sgi/libutil/mipmap.c
--- Mesa.orig/src/glu/sgi/libutil/mipmap.c	2006-10-22 20:18:35.000000000 -0600
+++ Mesa/src/glu/sgi/libutil/mipmap.c	2006-10-22 22:46:41.000000000 -0600
@@ -377,6 +377,7 @@ static void halveImage_ubyte(GLint compo
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLubyte *s;
     const char *t;
 
@@ -390,6 +391,7 @@ static void halveImage_ubyte(GLint compo
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -405,6 +407,7 @@ static void halveImage_ubyte(GLint compo
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -476,6 +479,7 @@ static void halveImage_byte(GLint compon
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLbyte *s;
     const char *t;
 
@@ -489,6 +493,7 @@ static void halveImage_byte(GLint compon
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -504,6 +509,7 @@ static void halveImage_byte(GLint compon
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -573,6 +579,7 @@ static void halveImage_ushort(GLint comp
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLushort *s;
     const char *t;
 
@@ -586,6 +593,7 @@ static void halveImage_ushort(GLint comp
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -602,6 +610,7 @@ static void halveImage_ushort(GLint comp
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
     else
@@ -616,6 +625,7 @@ static void halveImage_ushort(GLint comp
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -708,6 +718,7 @@ static void halveImage_short(GLint compo
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLshort *s;
     const char *t;
 
@@ -721,6 +732,7 @@ static void halveImage_short(GLint compo
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -737,6 +749,7 @@ static void halveImage_short(GLint compo
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
     else
@@ -758,6 +771,7 @@ static void halveImage_short(GLint compo
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -850,6 +864,7 @@ static void halveImage_uint(GLint compon
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLuint *s;
     const char *t;
 
@@ -863,6 +878,7 @@ static void halveImage_uint(GLint compon
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -881,6 +897,7 @@ static void halveImage_uint(GLint compon
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
     else
@@ -899,6 +916,7 @@ static void halveImage_uint(GLint compon
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -990,6 +1008,7 @@ static void halveImage_int(GLint compone
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLint *s;
     const char *t;
 
@@ -1003,6 +1022,7 @@ static void halveImage_int(GLint compone
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -1019,6 +1039,7 @@ static void halveImage_int(GLint compone
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
     else
@@ -1041,6 +1062,7 @@ static void halveImage_int(GLint compone
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -1134,6 +1156,7 @@ static void halveImage_float(GLint compo
 {
     int i, j, k;
     int newwidth, newheight;
+    int padBytes;
     GLfloat *s;
     const char *t;
 
@@ -1147,6 +1170,7 @@ static void halveImage_float(GLint compo
 
     newwidth = width / 2;
     newheight = height / 2;
+    padBytes = ysize - (width*group_size);
     s = dataout;
     t = (const char *)datain;
 
@@ -1163,6 +1187,7 @@ static void halveImage_float(GLint compo
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
     else
@@ -1183,6 +1208,7 @@ static void halveImage_float(GLint compo
 	    }
 	    t += group_size;
 	}
+	t += padBytes;
 	t += ysize;
     }
 }
@@ -8643,7 +8669,8 @@ static void halveImageSlice(int componen
    int halfHeight= height / 2;
    int halfDepth= depth / 2;
    const char *src= (const char *)dataIn;
-   int padBytes= rowSizeInBytes - (width * groupSizeInBytes);
+   int rowPadBytes= rowSizeInBytes - (width * groupSizeInBytes);
+   int imagePadBytes= imageSizeInBytes - (width*height*groupSizeInBytes);
    int outIndex= 0;
 
    assert((width == 1 || height == 1) && depth >= 2);
@@ -8727,7 +8754,7 @@ static void halveImageSlice(int componen
 	    /* skip over to next horizontal square of 4 */
 	    src+= groupSizeInBytes;
 	 } /* for jj */
-	 src+= padBytes;
+	 src+= rowPadBytes;
 
 	 src+= rowSizeInBytes;
       } /* for ii */
@@ -8772,11 +8799,12 @@ static void halveImageSlice(int componen
 
 	       src+= elementSizeInBytes;
 	    } /* for cc */
-	    src+= padBytes;
+	    src+= rowPadBytes;
 
 	    /* skip over to next vertical square of 4 */
 	    src+= rowSizeInBytes;
 	 } /* for jj */
+         src+= imagePadBytes;
 
 	 src+= imageSizeInBytes;
       } /* for ii */
@@ -8816,7 +8844,8 @@ static void halveImage3D(int components,
       int halfHeight= height / 2;
       int halfDepth= depth / 2;
       const char *src= (const char *) dataIn;
-      int padBytes= rowSizeInBytes - (width*groupSizeInBytes);
+      int rowPadBytes= rowSizeInBytes - (width*groupSizeInBytes);
+      int imagePadBytes= imageSizeInBytes - (width*height*groupSizeInBytes);
       int outIndex= 0;
 
       for (dd= 0; dd < halfDepth; dd++) {
@@ -8872,7 +8901,7 @@ static void halveImage3D(int components,
 	       src+= groupSizeInBytes;
 	    } /* for jj */
 	    /* skip past pad bytes, if any, to get to next row */
-	    src+= padBytes;
+	    src+= rowPadBytes;
 
 	    /* src is at beginning of a row here, but it's the second row of
 	     * the square block of 4 pixels that we just worked on so we
@@ -8887,6 +8916,9 @@ static void halveImage3D(int components,
 	    src+= rowSizeInBytes;
 	 } /* for ii */
 
+	 /* skip past pad bytes, if any, to get to next image */
+	 src+= imagePadBytes;
+
 	 src+= imageSizeInBytes;
       } /* for dd */
 
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to