#include "Stdafx.h"
#include "ImageFiltering.h"

namespace Domination {
	namespace Unmanaged {
		namespace OpenCV 
		{
			void ImageFiltering::blur(Mat^ src, Mat^ dst, System::Drawing::Size^ ksize)
			{
				cv::Mat lsrc = *src->ref;
				cv::Mat ldst = *dst->ref;
				cv::blur(lsrc, ldst, cv::Size(ksize->Width, ksize->Height));
			}

			void ImageFiltering::dilate(Mat^ src, Mat^ dst, Mat^ kernel, System::Drawing::Point^ anchor, int iterations, int borderType)
			{
				cv::Mat lsrc = *src->ref;
				cv::Mat ldst = *dst->ref;
				cv::Mat lkernel = *kernel->ref;
				cv::dilate(lsrc, ldst, lkernel, cv::Point(anchor->X, anchor->Y), iterations, borderType);
			}

			void ImageFiltering::erode(Mat^ src, Mat^ dst, Mat^ kernel, System::Drawing::Point^ anchor, int iterations, int borderType)
			{
				cv::Mat lsrc = *src->ref;
				cv::Mat ldst = *dst->ref;
				cv::Mat lkernel = *kernel->ref;
				cv::erode(lsrc, ldst, lkernel, cv::Point(anchor->X, anchor->Y), iterations, borderType);
			}

			void ImageFiltering::GaussianBlur(Mat^ src, Mat^ dst, System::Drawing::Size^ ksize, double sigmaX)
			{
				// double sigmaY=0, int borderType=BORDER_DEFAULT )
				GaussianBlur(src, dst, ksize, sigmaX, 0, 4);
			}
			void ImageFiltering::GaussianBlur(Mat^ src, Mat^ dst, System::Drawing::Size^ ksize, double sigmaX, double sigmaY, int borderType)
			{
				cv::Mat lsrc = *src->ref;
				cv::Mat ldst = *dst->ref;
				cv::GaussianBlur(lsrc, ldst, cv::Size(ksize->Width, ksize->Height), sigmaX, sigmaY, borderType);
			}

			Mat^ ImageFiltering::getStructuringElement(StructuringElement shape, System::Drawing::Size^ ksize, System::Drawing::Point^ anchor)
			{
				Mat^ mat = gcnew Mat();
				*mat->ref = cv::getStructuringElement((int)shape, cv::Size(ksize->Width, ksize->Height), cv::Point(anchor->X, anchor->Y));
				return mat;
			}
		}
	}
}