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
+22 -4
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
{
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;
COMP( BytesPerPixel );
@@ -97,8 +109,6 @@ bool RageSurfaceFormat::operator== ( const RageSurfaceFormat &rhs ) const
COMP( Gmask );
COMP( Bmask );
COMP( Amask );
if( BytesPerPixel == 1 )
COMP( palette );
return true;
}
@@ -107,6 +117,7 @@ RageSurface::RageSurface()
{
format = &fmt;
pixels = NULL;
pixels_owned = true;
}
RageSurface::RageSurface( const RageSurface &cpy )
@@ -117,8 +128,14 @@ RageSurface::RageSurface( const RageSurface &cpy )
h = cpy.h;
pitch = cpy.pitch;
flags = cpy.flags;
pixels = new uint8_t[ pitch*h ];
memcpy( pixels, cpy.pixels, pitch*h );
pixels_owned = true;
if( cpy.pixels )
{
pixels = new uint8_t[ pitch*h ];
memcpy( pixels, cpy.pixels, pitch*h );
}
else
pixels = NULL;
}
RageSurface::~RageSurface()
@@ -223,6 +240,7 @@ RageSurface *CreateSurfaceFrom( int width, int height, int BitsPerPixel, uint32_
pImg->flags = 0;
pImg->pitch = pitch;
pImg->pixels = pPixels;
pImg->pixels_owned = false;
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;
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
@@ -56,6 +60,7 @@ struct RageSurface
RageSurfaceFormat fmt;
uint8_t *pixels;
bool pixels_owned;
int32_t w, h, pitch;
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. */
if( src->format->BitsPerPixel == 8 && dest->format->BitsPerPixel == 8 )
{
ASSERT( dest->format->palette );
dest->fmt.palette = src->fmt.palette;
ASSERT( dest->fmt.palette );
*dest->fmt.palette = *src->fmt.palette;
}
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 );
/* If the formats are the same, no conversion is needed. */
if( width == src->w && height == src->h && src->format == dst->format )
/* If the formats are the same, no conversion is needed. Ignore the palette. */
if( width == src->w && height == src->h && src->format->Equivalent( *dst->format ) )
{
delete dst;
dst = NULL;