palette handling fixes

don't free pixels passed to CreateSurfaceFrom
This commit is contained in:
Glenn Maynard
2004-07-14 21:02:49 +00:00
parent 2fe0d2021e
commit 17bc5b0025
3 changed files with 31 additions and 8 deletions
+20 -2
View File
@@ -90,6 +90,18 @@ bool RageSurfaceFormat::MapRGBA( uint8_t r, uint8_t g, uint8_t b, uint8_t a, uin
} }
bool RageSurfaceFormat::operator== ( const RageSurfaceFormat &rhs ) const bool RageSurfaceFormat::operator== ( const RageSurfaceFormat &rhs ) const
{
if( !Equivalent(rhs) )
return false;
if( BytesPerPixel == 1 )
if( memcmp( palette, rhs.palette, sizeof(RageSurfaceFormat) ) )
return false;
return true;
}
bool RageSurfaceFormat::Equivalent( const RageSurfaceFormat &rhs ) const
{ {
#define COMP(a) if( a != rhs.a ) return false; #define COMP(a) if( a != rhs.a ) return false;
COMP( BytesPerPixel ); COMP( BytesPerPixel );
@@ -97,8 +109,6 @@ bool RageSurfaceFormat::operator== ( const RageSurfaceFormat &rhs ) const
COMP( Gmask ); COMP( Gmask );
COMP( Bmask ); COMP( Bmask );
COMP( Amask ); COMP( Amask );
if( BytesPerPixel == 1 )
COMP( palette );
return true; return true;
} }
@@ -107,6 +117,7 @@ RageSurface::RageSurface()
{ {
format = &fmt; format = &fmt;
pixels = NULL; pixels = NULL;
pixels_owned = true;
} }
RageSurface::RageSurface( const RageSurface &cpy ) RageSurface::RageSurface( const RageSurface &cpy )
@@ -117,9 +128,15 @@ RageSurface::RageSurface( const RageSurface &cpy )
h = cpy.h; h = cpy.h;
pitch = cpy.pitch; pitch = cpy.pitch;
flags = cpy.flags; flags = cpy.flags;
pixels_owned = true;
if( cpy.pixels )
{
pixels = new uint8_t[ pitch*h ]; pixels = new uint8_t[ pitch*h ];
memcpy( pixels, cpy.pixels, pitch*h ); memcpy( pixels, cpy.pixels, pitch*h );
} }
else
pixels = NULL;
}
RageSurface::~RageSurface() RageSurface::~RageSurface()
{ {
@@ -223,6 +240,7 @@ RageSurface *CreateSurfaceFrom( int width, int height, int BitsPerPixel, uint32_
pImg->flags = 0; pImg->flags = 0;
pImg->pitch = pitch; pImg->pitch = pitch;
pImg->pixels = pPixels; pImg->pixels = pPixels;
pImg->pixels_owned = false;
return pImg; return pImg;
} }
+5
View File
@@ -48,6 +48,10 @@ struct RageSurfaceFormat
uint32_t MapNearestRGBA( uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const; uint32_t MapNearestRGBA( uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const;
bool operator== ( const RageSurfaceFormat &rhs ) const; bool operator== ( const RageSurfaceFormat &rhs ) const;
/* Like operator==, but ignores the palette (which is really a part of the
* surface, not the format). */
bool Equivalent( const RageSurfaceFormat &rhs ) const;
}; };
struct RageSurface struct RageSurface
@@ -56,6 +60,7 @@ struct RageSurface
RageSurfaceFormat fmt; RageSurfaceFormat fmt;
uint8_t *pixels; uint8_t *pixels;
bool pixels_owned;
int32_t w, h, pitch; int32_t w, h, pitch;
int32_t flags; int32_t flags;
+4 -4
View File
@@ -137,8 +137,8 @@ void RageSurfaceUtils::CopySurface( RageSurface *src, RageSurface *dest )
/* Copy the palette, if we have one. */ /* Copy the palette, if we have one. */
if( src->format->BitsPerPixel == 8 && dest->format->BitsPerPixel == 8 ) if( src->format->BitsPerPixel == 8 && dest->format->BitsPerPixel == 8 )
{ {
ASSERT( dest->format->palette ); ASSERT( dest->fmt.palette );
dest->fmt.palette = src->fmt.palette; *dest->fmt.palette = *src->fmt.palette;
} }
Blit( src, dest, -1, -1, false ); Blit( src, dest, -1, -1, false );
@@ -150,8 +150,8 @@ bool RageSurfaceUtils::ConvertSurface( RageSurface *src, RageSurface *&dst,
{ {
dst = CreateSurface( width, height, bpp, R, G, B, A ); dst = CreateSurface( width, height, bpp, R, G, B, A );
/* If the formats are the same, no conversion is needed. */ /* If the formats are the same, no conversion is needed. Ignore the palette. */
if( width == src->w && height == src->h && src->format == dst->format ) if( width == src->w && height == src->h && src->format->Equivalent( *dst->format ) )
{ {
delete dst; delete dst;
dst = NULL; dst = NULL;