#include "workthread.h"
#include "common.h"

WorkThread::~WorkThread()
{
	stop();
	p_image_queue->put(cv::Mat());
	quit();
	wait();
}

void WorkThread::init()
{
	b_quit = false;
}
void WorkThread::start_work()
{
	start(HighestPriority);
}
void WorkThread::stop()
{
	b_quit = true;
}

void WorkThread::run()
{
	uint32_t result_index = 0;
	while (!b_quit) {

		std::pair<int, cv::Mat> element;
		cv::Mat image;
		p_image_queue->take(image);

		if (!image.data)
		{
			continue;
		}
		
		if (0)
		{
			if (image.data)
			{
				QDateTime now_ts = QDateTime::currentDateTime();
				QString file_name = "EmpiricalData/" +
					now_ts.toString("yyyy-MM-dd") +
					now_ts.toString("HH-mm-ss_zzz_") + ".jpg";
				p_save_queue->put(std::make_pair(file_name.toStdString(), image));
			}
		}

		cv::Mat output_image;
		m_alg_ptr->process_2dfft(image,output_image);

		
		emit display_image(image);

	}
}