#pragma once

#include <stdint.h>
#include <js.h>

#define GRAPHICS_INIT JS_EXPORT image_data_t* canvas_init(void)
#define GRAPHICS_FRAME JS_EXPORT void canvas_frame(void)

#ifdef __cplusplus
extern "C" {
#endif

typedef union {
    uint32_t color;
    struct {
        uint8_t r;
        uint8_t g;
        uint8_t b;
        uint8_t a;
    };
} image_color_t;

typedef struct {
    uint16_t width;
    uint16_t height;
    image_color_t* pixels;
} image_data_t;

image_data_t image_create(uint16_t width, uint16_t height);
void image_free(image_data_t image);

void image_draw_point(image_data_t image, int16_t x, int16_t y, image_color_t color);
void image_draw_hline(image_data_t image, int16_t x1, int16_t x2, int16_t y, image_color_t color);
void image_draw_vline(image_data_t image, int16_t x, int16_t y1, int16_t y2, image_color_t color);
void image_draw_line(image_data_t image, int16_t x1, int16_t y1, int16_t x2, int16_t y2, image_color_t color);
void image_draw_rect(image_data_t image, int16_t x, int16_t y, int16_t w, int16_t h, image_color_t color);
void image_fill_rect(image_data_t image, int16_t x, int16_t y, int16_t w, int16_t h, image_color_t color);

#ifdef __cplusplus
}
#endif
