restored _mesa_rescale_teximage2d()
authorBrian Paul <brian.paul@tungstengraphics.com>
Sun, 2 May 2004 14:30:46 +0000 (14:30 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sun, 2 May 2004 14:30:46 +0000 (14:30 +0000)
src/mesa/main/texstore.c
src/mesa/main/texstore.h

index d0529b13c3e8431a8af0c0d2372b2543463b9be9..3dae1929c4dc3ca594b7de80f48ccb3ea688c38f 100644 (file)
@@ -3209,3 +3209,74 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
 
    } /* loop over mipmap levels */
 }
+
+
+/**
+ * Helper function for drivers which need to rescale texture images to
+ * certain aspect ratios.
+ * Nearest filtering only (for broken hardware that can't support
+ * all aspect ratios).  This can be made a lot faster, but I don't
+ * really care enough...
+ */
+void _mesa_rescale_teximage2d( GLuint bytesPerPixel, GLuint dstRowStride,
+                              GLint srcWidth, GLint srcHeight,
+                              GLint dstWidth, GLint dstHeight,
+                              const GLvoid *srcImage, GLvoid *dstImage )
+{
+   GLint row, col;
+
+#define INNER_LOOP( TYPE, HOP, WOP )                                   \
+   for ( row = 0 ; row < dstHeight ; row++ ) {                         \
+      GLint srcRow = row HOP hScale;                                   \
+      for ( col = 0 ; col < dstWidth ; col++ ) {                       \
+        GLint srcCol = col WOP wScale;                                 \
+        dst[col] = src[srcRow * srcWidth + srcCol];                    \
+      }                                                                        \
+      dst = (TYPE *) ((GLubyte *) dst + dstRowStride);                 \
+   }                                                                   \
+
+#define RESCALE_IMAGE( TYPE )                                          \
+do {                                                                   \
+   const TYPE *src = (const TYPE *)srcImage;                           \
+   TYPE *dst = (TYPE *)dstImage;                                       \
+                                                                       \
+   if ( srcHeight <= dstHeight ) {                                     \
+      const GLint hScale = dstHeight / srcHeight;                      \
+      if ( srcWidth <= dstWidth ) {                                    \
+        const GLint wScale = dstWidth / srcWidth;                      \
+        INNER_LOOP( TYPE, /, / );                                      \
+      }                                                                        \
+      else {                                                           \
+        const GLint wScale = srcWidth / dstWidth;                      \
+        INNER_LOOP( TYPE, /, * );                                      \
+      }                                                                        \
+   }                                                                   \
+   else {                                                              \
+      const GLint hScale = srcHeight / dstHeight;                      \
+      if ( srcWidth <= dstWidth ) {                                    \
+        const GLint wScale = dstWidth / srcWidth;                      \
+        INNER_LOOP( TYPE, *, / );                                      \
+      }                                                                        \
+      else {                                                           \
+        const GLint wScale = srcWidth / dstWidth;                      \
+        INNER_LOOP( TYPE, *, * );                                      \
+      }                                                                        \
+   }                                                                   \
+} while (0)
+
+   switch ( bytesPerPixel ) {
+   case 4:
+      RESCALE_IMAGE( GLuint );
+      break;
+
+   case 2:
+      RESCALE_IMAGE( GLushort );
+      break;
+
+   case 1:
+      RESCALE_IMAGE( GLubyte );
+      break;
+   default:
+      _mesa_problem(NULL,"unexpected bytes/pixel in _mesa_rescale_teximage2d");
+   }
+}
index 47775a1bb81413cc82b04b83567cf54b1730e869..d276ff94e47b979dec0c7bb9d303c333c39d2cf2 100644 (file)
@@ -225,4 +225,11 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
                       const struct gl_texture_unit *texUnit,
                       struct gl_texture_object *texObj);
 
+
+extern void
+_mesa_rescale_teximage2d(GLuint bytesPerPixel, GLuint dstRowStride,
+                         GLint srcWidth, GLint srcHeight,
+                         GLint dstWidth, GLint dstHeight,
+                         const GLvoid *srcImage, GLvoid *dstImage);
+
 #endif