#ifndef ka_subtitles_h
#define ka_subtitles_h

#include "inttypes.h"
#include "ka_block.h"
#include "ka_vars.h"
#include "ka_vinfo.h"
#include "ka_error.h"

typedef struct
{
  uint8_t  y;
  uint8_t  u;
  uint8_t  v;
  uint8_t  a;
} ka_subcolor;

typedef struct ka_sub_rect
{
  struct ka_sub_rect* prev;
  struct ka_sub_rect* next;
  uint32_t typ;
  uint32_t section;
  uint8_t  displayed;
  uint8_t  forceDisplay;
  uint8_t  nrColors;
  uint32_t startDate;
  uint32_t endDate;
  uint32_t x0;
  uint32_t y0;
  uint32_t x1; // exclusive
  uint32_t y1; // exclusive
  uint8_t* data;
  uint32_t bpr;
  ka_subcolor palette[256];
} ka_sub_rect;

typedef struct ka_subtitles_s ka_subtitles_t;

ka_subtitles_t* ka_new_subtitles(ka_error_t* pErrorBlock, ka_vars_t* vars);
void ka_delete_subtitles(ka_subtitles_t**);
void ka_subtitles_reset(ka_subtitles_t*);
int ka_subtitles_decode(ka_subtitles_t*, ka_block_t* b);
ka_sub_rect* ka_subtitles_getNewRect(ka_subtitles_t*);
void ka_subtitles_rectStatus(ka_subtitles_t*, ka_sub_rect*, int valid);
const ka_sub_rect* ka_subtitles_getMatch(ka_subtitles_t*, uint32_t pts, const ka_sub_rect* prev);
void ka_subtitles_render(const ka_vinfo_t* info, const ka_vframe_t* pframe, const ka_sub_rect* rect);

#endif
