diff options
| author | Brian Paul <brian.paul@tungstengraphics.com> | 2004-05-02 14:30:46 +0000 | 
|---|---|---|
| committer | Brian Paul <brian.paul@tungstengraphics.com> | 2004-05-02 14:30:46 +0000 | 
| commit | 80fc5ea53e0f1dac9df529965687c159acae057f (patch) | |
| tree | 7dd652f29e141ae69871d413fa398081a03837da /src | |
| parent | 883e7a5906b3e287520c1e52bdb76c47ba9bb4a5 (diff) | |
restored _mesa_rescale_teximage2d()
Diffstat (limited to 'src')
| -rw-r--r-- | src/mesa/main/texstore.c | 71 | ||||
| -rw-r--r-- | src/mesa/main/texstore.h | 7 | 
2 files changed, 78 insertions, 0 deletions
| diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index d0529b13c3..3dae1929c4 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -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"); +   } +} diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h index 47775a1bb8..d276ff94e4 100644 --- a/src/mesa/main/texstore.h +++ b/src/mesa/main/texstore.h @@ -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 | 
