+/**
+ * Adjust pixel unpack params and image dimensions to strip off the
+ * one-pixel texture border.
+ *
+ * Gallium and intel don't support texture borders. They've seldem been used
+ * and seldom been implemented correctly anyway.
+ *
+ * \param unpackNew returns the new pixel unpack parameters
+ */
+static void
+strip_texture_border(GLenum target,
+ GLint *width, GLint *height, GLint *depth,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_pixelstore_attrib *unpackNew)
+{
+ assert(width);
+ assert(height);
+ assert(depth);
+
+ *unpackNew = *unpack;
+
+ if (unpackNew->RowLength == 0)
+ unpackNew->RowLength = *width;
+
+ if (unpackNew->ImageHeight == 0)
+ unpackNew->ImageHeight = *height;
+
+ assert(*width >= 3);
+ unpackNew->SkipPixels++; /* skip the border */
+ *width = *width - 2; /* reduce the width by two border pixels */
+
+ /* The min height of a texture with a border is 3 */
+ if (*height >= 3 && target != GL_TEXTURE_1D_ARRAY) {
+ unpackNew->SkipRows++; /* skip the border */
+ *height = *height - 2; /* reduce the height by two border pixels */
+ }
+
+ if (*depth >= 3 && target != GL_TEXTURE_2D_ARRAY) {
+ unpackNew->SkipImages++; /* skip the border */
+ *depth = *depth - 2; /* reduce the depth by two border pixels */
+ }
+}