#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int brightness1();
int brightness2();
int brightness3();
int brightness4();
int mosaic();

int main() {
	return brightness4();
}

int brightness1() {
	Mat src = imread("..\\..\\resources\\images\\lenna.bmp", IMREAD_GRAYSCALE);
	if (src.empty()) {
		cerr << "imread()" << endl;
		return 1;
	}
	Mat dst = src + 100;

	imshow("src", src);
	imshow("dst", dst);
	waitKey();
	destroyAllWindows();
	return 0;
}

int brightness2() {
	Mat src = imread("..\\..\\resources\\images\\lenna.bmp", IMREAD_GRAYSCALE);
	if (src.empty()) {
		cerr << "imread()" << endl;
		return 1;
	}
	Mat dst(src.rows, src.cols, src.type());

	for (int j = 0; j < src.rows; j++) {
		for (int i = 0; i < src.cols; i++) {
			dst.at<uchar>(j, i) = src.at<uchar>(j, i) + 100;
		}
	}

	imshow("src", src);
	imshow("dst", dst);
	waitKey();
	destroyAllWindows();
	return 0;
}

int brightness3() {
	Mat src = imread("..\\..\\resources\\images\\lenna.bmp", IMREAD_GRAYSCALE);
	if (src.empty()) {
		cerr << "imread()" << endl;
		return 1;
	}
	Mat dst(src.rows, src.cols, src.type());

	for (int j = 0; j < src.rows; j++) {
		for (int i = 0; i < src.cols; i++) {
			dst.at<uchar>(j, i) = saturate_cast<uchar>(src.at<uchar>(j, i) + 100);
		}
	}

	imshow("src", src);
	imshow("dst", dst);
	waitKey();
	destroyAllWindows();
	return 0;
}

void on_brightness(int pos, void* userdata) {
	Mat src = *(Mat*)userdata;
	Mat dst = src + pos;

	imshow("dst", dst);
}

int brightness4() {
	Mat src = imread("..\\..\\resources\\images\\lenna.bmp", IMREAD_GRAYSCALE);
	if (src.empty()) {
		cerr << "imread()" << endl;
		return 1;
	}
	namedWindow("dst");
	createTrackbar("Brightness", "dst", 0, 100, on_brightness, (void*)&src);

	waitKey();
	destroyAllWindows();
	return 0;
}

int mosaic() {
	Mat src = imread("..\\..\\resources\\images\\lenna.bmp", IMREAD_COLOR_RGB);
	if (src.empty()) {
		cerr << "imread()" << endl;
		return 1;
	}

	const 

	Mat dst(src.rows, src.cols, src.type());

	for (int j = 0; j < src.rows; j++) {
		for (int i = 0; i < src.cols; i++) {
			dst.at<uchar>(j, i) = src.at<uchar>(j, i) + 100;
		}
	}
}