Image::Overlay patch

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
arash
Posts: 2
Joined: Sun Aug 05, 2012 5:59 am

Image::Overlay patch

Post by arash »

here is patch for Image::Overlay() function :

Code: Select all

Index: zm_image.cpp
===================================================================
--- zm_image.cpp	(revision 3688)
+++ zm_image.cpp	(working copy)
@@ -711,12 +711,12 @@
 
 void Image::Overlay( const Image &image, int x, int y )
 {
-	if ( !(width < image.width || height < image.height) )
+	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)) )
+	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 );
     }
Christo
Posts: 89
Joined: Wed Feb 01, 2012 9:48 pm

Re: Image::Overlay patch

Post by Christo »

Hello Arash,

I am curious about your post..

I am looking for a method to get an overlay on one of my camera images.

Could you please explain what update does and how to implement this!?

Kind regards and thanks in advance, Christo
arash
Posts: 2
Joined: Sun Aug 05, 2012 5:59 am

Re: Image::Overlay patch

Post by arash »

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++;
			}
		}
	}
}
Christo
Posts: 89
Joined: Wed Feb 01, 2012 9:48 pm

Re: Image::Overlay patch

Post by Christo »

Hello Arash,

OK, Ill get your point now!!

I have been searching within the WIKI and this forum but found no additional information about how to apply such an overlay.

I asume you did figure this out by yourself? Or was I just looking at the wrong place?

Maybe you can point me out how?

Kind regards and Thanks, Christo
Post Reply