/*Copyright (C) 2006 Matteo Lucarelli - matteolucarelli@altervista.org
* 
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
******************************************************************************/

#include <opencv/cv.h>

// copy inImg into outImg 
// shifting x pixels from left-most border
// and y pixels from up-most border
void cvShift(IplImage* inImg, IplImage* outImg, int x, int y)
{
	// inImg and outImg must have the same size
	if ((inImg->width!=outImg->width)||(inImg->height!=outImg->height)) return;

	// black background (use cvSet for different colors)
	cvSetZero(outImg);

	cvSetImageROI(inImg,cvRect(x>0?0:-x,y>0?0:-y,inImg->width-abs(x),inImg->height-abs(y)));
	cvSetImageROI(outImg,cvRect(x>0?x:0,y>0?y:0,inImg->width-abs(x),inImg->height-abs(y)));
	
	cvCopy(inImg,outImg);
	
	cvResetImageROI(inImg);
	cvResetImageROI(outImg);
}