From aab53e70d80b4e78e0ee6ea2b09f8c9b9112a2d1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 27 Sep 2004 01:12:13 +0000 Subject: [PATCH] split RageSurfaceUtils::CorrectBorderPixels --- stepmania/src/RageSurfaceUtils.cpp | 36 +++++++++++++++++++++--------- stepmania/src/RageSurfaceUtils.h | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/stepmania/src/RageSurfaceUtils.cpp b/stepmania/src/RageSurfaceUtils.cpp index 436a3e3f91..53bfa9d7ee 100644 --- a/stepmania/src/RageSurfaceUtils.cpp +++ b/stepmania/src/RageSurfaceUtils.cpp @@ -698,27 +698,43 @@ void RageSurfaceUtils::Blit( const RageSurface *src, RageSurface *dst, int width * Copy the last column (200x... -> 201x...), then the last row (...x200 -> ...x201). */ - if( width < dst->w ) + CorrectBorderPixels( dst, width, height ); +} + +/* + * If only width x height of img is actually going to be used, and there's extra + * space on the surface, duplicate the last row and column to ensure that we don't + * pull in unexpected data when rendering with bilinear filtering. + * + * We do this if there's memory available, even if that space extends outside + * of the image (in the per-line padding or after the end). This way, surfaces + * can be padded to power-of-two dimensions by the image loaders, and if no other + * adjustments are needed, they can be passed directly to the renderer without + * doing any extra copies. + */ +void RageSurfaceUtils::CorrectBorderPixels( RageSurface *img, int width, int height ) +{ + if( width*img->fmt.BytesPerPixel < img->pitch ) { /* Duplicate the last column. */ - int offset = dst->format->BytesPerPixel * (width-1); - uint8_t *p = (uint8_t *) dst->pixels + offset; + int offset = img->format->BytesPerPixel * (width-1); + uint8_t *p = (uint8_t *) img->pixels + offset; for( int y = 0; y < height; ++y ) { - uint32_t pixel = decodepixel( p, dst->format->BytesPerPixel ); - encodepixel( p+dst->format->BytesPerPixel, dst->format->BytesPerPixel, pixel ); + uint32_t pixel = decodepixel( p, img->format->BytesPerPixel ); + encodepixel( p+img->format->BytesPerPixel, img->format->BytesPerPixel, pixel ); - p += dst->pitch; + p += img->pitch; } } - if( height < dst->h ) + if( height < img->h ) { /* Duplicate the last row. */ - uint8_t *srcp = dst->pixels; - srcp += dst->pitch * (height-1); - memcpy( srcp + dst->pitch, srcp, dst->pitch ); + uint8_t *srcp = img->pixels; + srcp += img->pitch * (height-1); + memcpy( srcp + img->pitch, srcp, img->pitch ); } } diff --git a/stepmania/src/RageSurfaceUtils.h b/stepmania/src/RageSurfaceUtils.h index 9f40d30274..1fbd71d041 100644 --- a/stepmania/src/RageSurfaceUtils.h +++ b/stepmania/src/RageSurfaceUtils.h @@ -48,6 +48,7 @@ namespace RageSurfaceUtils const float fCoords[8] /* TL, BR, BL, TR */ ); void Blit( const RageSurface *src, RageSurface *dst, int width = -1, int height = -1 ); + void CorrectBorderPixels( RageSurface *img, int width, int height ); bool SaveSurface( const RageSurface *img, CString file ); RageSurface *LoadSurface( CString file );