Move Image struct and add clear image, set pixel and draw_line functions

This commit is contained in:
2024-07-20 17:23:24 +01:00
parent 52d79817ad
commit 4baf837256
3 changed files with 116 additions and 9 deletions

View File

@@ -1,26 +1,34 @@
#include "aliases.h"
#include "img.h"
#include "mem_arena.h"
#include "mem_utils.h"
#include "pam.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct img Image;
struct img {
u64 width;
u64 height;
u8 *buf;
enum {
TINY_EXIT_SUCCESS,
TINY_EXIT_ARENA_INIT_FAILED,
TINY_EXIT_IMAGE_INIT_FAILED,
};
int main(void) {
Arena *arena = NULL;
if (!wapp_mem_arena_init(&arena, 10ul * 1024ul * 1024ul * 1024ul,
WAPP_MEM_ALLOC_RESERVE, false)) {
return -1;
return TINY_EXIT_ARENA_INIT_FAILED;
}
Colour cyan = {.r = 0, .g = 255, .b = 255, .a = 255};
Colour red = {.r = 255, .g = 0, .b = 0, .a = 255};
Image img = {.width = 200, .height = 200};
if (!init_image(arena, &img)) {
return TINY_EXIT_IMAGE_INIT_FAILED;
}
clear_image(&img, cyan);
save_image(&img, "result.pam");
wapp_mem_arena_destroy(&arena);
return 0;
return TINY_EXIT_SUCCESS;
}