#ifndef colconv_h
#define colconv_h

#include "ka_hardware.h"
#include "ka_chroma.h"
#include "ka_drawer.h"
#include "ka_screen.h"
#include "ka_error.h"

typedef enum
{ ka_zoom_05 = 0
, ka_zoom_1  = 1
, ka_zoom_2  = 2
, ka_zoom_3  = 3
, ka_zoom_4  = 4
} ka_zoom;

// YUV -> RGB with brightness, contrast, colour adapation
// Ur = CUr * (u - 128)
// Vb = CVb * (v - 128)
// UVg = CUg * (u - 128) + CVg * (v - 128)
// Yc = CY0 + CYc * y
// r = Yc + Ur  -> [0, 255]
// g = Yc - UVg -> [0, 255]
// b = Yc + Vb  -> [0, 255]
typedef struct
{
  // used in rgb conversion
  int cur;                  // KUr * colour/100
  int cvb;                  // KVb * colour/100
  int cug;                  // KUg * colour/100
  int cvg;                  // KVg * colour/100
  int cy0;                  // 128 * (contrast/100)(brightness - KYc*16 - 228)
  int cyc;                  // KYc * contrast/100
  // used in yuv mapping
  int yfac;                 // 0..128 (64 * contrast) / 100
  int yadd;                 // yfac * (brightness - 100 - 128) + 128*64
  int colfac;               // 0..128 (64 * colour) / 100
  int coladd;               // 128 * (64 - colfac)
} ka_neon_yuv_to_rgb_t;

typedef struct
{
  int brightness;             // 0..200  default 100
  int contrast;               // 0..200  default 100
  int colour;                 // 0..200  default 100
  ka_zoom zoom;               // zoom, is always 1 in multitasking mode
  int config;                 // see cfg.video
  uint32_t hardware;
  ka_chroma_type chroma_type; // source color space type
  ka_neon_yuv_to_rgb_t params;// YUV to RGB params
} ka_colourspace_t;

ka_drawer_f ColourConverter_setup(ka_error_t* pErrorBlock, ka_screen_t* target, ka_colourspace_t* options);
ka_drawer_f ColourConverter_fastsetup(ka_error_t* pErrorBlock, ka_screen_t* target, ka_colourspace_t* options);
const char* ColourConverter_ColourDepthName(ka_col_depth depth);
const char* ColourConverter_ChromaTypeName(ka_chroma_type type);

#endif
