#include <gear/images.h>
#include <string.h>
#include <log.c/log.h>

g_image* g_image_create(u8* pixels, i32 width, i32 height) {
    g_image* p_image = calloc(1, sizeof(g_image));
    if (p_image != NULL) {
        log_info("Image allocated successfully");
        log_debug("Image pointer: %p", p_image);

        p_image->width = width;
        p_image->height = height;
        p_image->channels = G_IMAGE_CHANNELS;
        p_image->pixels = pixels;
    } else {
        log_fatal("Failed to allocate image");
        exit(EXIT_FAILURE);
    }

    return p_image;
}

g_image* g_image_default() {
    g_image* p_image = calloc(1, sizeof(g_image));
    if(p_image != NULL) {
        p_image->width = G_IMAGE_MISSING_DIMENSIONS,
        p_image->height = G_IMAGE_MISSING_DIMENSIONS,
        p_image->channels = G_IMAGE_CHANNELS,
        p_image->pixels = calloc(1, G_IMAGE_MISSING_BYTESIZE);
        memcpy(p_image->pixels, G_IMAGE_MISSING_PIXELS, G_IMAGE_MISSING_BYTESIZE);
    }

    return p_image;
}
