hello Christo,
existing Overlay function doesn't work at all.
if you look closely at the two 'if' conditions you can see they're reverse.
the rest of the function is fine. I currently use it for image overlaying and it works without a problem.
generally you can use "patch" utility to apply diffs. but for this case you can simply remove the two not ('!') operation from first two "if" statements
here is the patched version of the function :
Code: Select all
void Image::Overlay( const Image &image, int x, int y )
{
if ( width < image.width || height < image.height )
{
Panic( "Attempt to overlay image too big for destination, %dx%d > %dx%d", image.width, image.height, width, height );
}
if ( width < (x+image.width) || height < (y+image.height) )
{
Panic( "Attempt to overlay image outside of destination bounds, %dx%d @ %dx%d > %dx%d", image.width, image.height, x, y, width, height );
}
if ( !(colours == image.colours) )
{
Panic( "Attempt to partial overlay differently coloured images, expected %d, got %d", colours, image.colours );
}
int lo_x = x;
int lo_y = y;
int hi_x = (x+image.width)-1;
int hi_y = (y+image.height-1);
if ( colours == 1 )
{
unsigned char *psrc = image.buffer;
for ( int y = lo_y; y <= hi_y; y++ )
{
unsigned char *pdest = &buffer[(y*width)+lo_x];
for ( int x = lo_x; x <= hi_x; x++ )
{
*pdest++ = *psrc++;
}
}
}
else if ( colours == 3 )
{
unsigned char *psrc = image.buffer;
for ( int y = lo_y; y <= hi_y; y++ )
{
unsigned char *pdest = &buffer[colours*((y*width)+lo_x)];
for ( int x = lo_x; x <= hi_x; x++ )
{
*pdest++ = *psrc++;
*pdest++ = *psrc++;
*pdest++ = *psrc++;
}
}
}
}