///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004 Intel Corporation 
// All rights reserved. 
//
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions are met: 
//
// * Redistributions of source code must retain the above copyright notice, 
// this list of conditions and the following disclaimer. 
// * Redistributions in binary form must reproduce the above copyright notice, 
// this list of conditions and the following disclaimer in the documentation 
// and/or other materials provided with the distribution. 
// * Neither name of Intel Corporation nor the names of its contributors 
// may be used to endorse or promote products derived from this software 
// without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <fstream.h>

#include "stdafx.h"
#include "ipp.h"
#include "tools.h"

#include "ROI.h"

ROI::ROI(const Image8u* pImage, IppiRect roi) : isROI_(0), Image8u(pImage)
{
	roi_ = roi;
	isROI_ = 1;
}

ROI::ROI() : Image8u()
{
	isROI_ = 0;
}

//  Destructor
ROI::~ROI() {}

IppiSize ROI::GetSize() const
{
	if (isROI_)
	{
		IppiSize size = { roi_.width, roi_.height };
		return size;
	}
	else
		return Image8u::GetSize();
}

Ipp8u* ROI::GetData()
{
	if (isROI_)
		return Image8u::GetData(roi_.x, roi_.y);
	else
		return Image8u::GetData();
}

Ipp8u* ROI::GetData(int x, int y)
{
	if(isROI_)
		return Image8u::GetData(roi_.x+x, roi_.y+y);
	else
		return Image8u::GetData(x,y);
}

const Ipp8u* ROI::GetConstData() const
{
	if(isROI_)
		return Image8u::GetConstData(roi_.x,roi_.y);
	else
		return Image8u::GetConstData();
}

const Ipp8u* ROI::GetConstData(int x, int y) const
{
	if(isROI_)
		return Image8u::GetConstData(roi_.x+x, roi_.y+y);
	else
		return Image8u::GetConstData(x,y);
}

void ROI::SetROI(IppiRect roi) { roi_ = roi; isROI_ = 1;}
