//HDR READER
//https://www.flipcode.com/archives/HDR_Image_Reader.shtml

#include "pch.h"

#include <iostream>
#include <chrono>
#include <cstdlib>
#include <vector>
#include <ctime>

#include <Eigen/Core>
#include <unsupported/Eigen/Splines>

#include "ImageHDR.hpp"
#include "YCurve.hpp"
#include "Conversion.hpp"
#include "Full_process.hpp"



float* exposure(float* data, unsigned int width, unsigned int height, float exposure)
{
  ImageHDR img(data, width, height);

  img.exposure(exposure);

  float* ret = new float[width * height * 3];
  memcpy(ret, img.data, width * height * 3 * sizeof(float));

  return ret;
}



float* full_process(float* data, unsigned int width, unsigned int height,
  float exposure,
  float contrast,
  float yCs, float yCb, float yCm, float yCw, float yCh,
  bool lms, bool lmb, bool lmm, bool lmw, bool lmh,
  float saturation,
  float ce_sel_light_l, float ce_sel_light_h, float ce_sel_chr_l, float ce_sel_chr_h, float ce_sel_hue_l, float ce_sel_hue_h, float ce_tol, float ce_edit_hue, float ce_edit_expo, float ce_edit_con, float ce_edit_sat, bool ce_mask)
{
  ImageHDR img(data, width, height);

  // ******************************************
  img.exposure(exposure);
  // ******************************************

  // ******************************************
  img.contrast(contrast);
  // ******************************************

  // ******************************************
  img.yCurve(yCs, yCb, yCm, yCw, yCh);
  // ******************************************

  // ******************************************
  img.lightnessMask(lms, lmb, lmm, lmw, lmh);
  // ******************************************

  // ******************************************
  img.saturation(saturation);
  // ******************************************

  // ******************************************
  float sel_light[2] = {ce_sel_light_l, ce_sel_light_h};
  float sel_chr[2] = {ce_sel_chr_l, ce_sel_chr_h};
  float sel_hue[2] = {ce_sel_hue_l, ce_sel_hue_h};

  img.colorEditor(sel_light, sel_chr, sel_hue, ce_tol, ce_edit_hue, ce_edit_expo, ce_edit_con, ce_edit_sat, ce_mask);
  // ******************************************

  float *ret = new float[width*height*3];
  memcpy(ret, img.data, width * height * 3 * sizeof(float));
  
  return ret;
}
