A C library for creating and drawing images using the PPM image format.
at main 1.4 kB view raw
1/** 2 * PPM library for creating and drawing images using the PPM image format. 3 */ 4 5#ifndef PPM_H 6#define PPM_H 7#include <stdint.h> 8 9typedef struct { 10 uint8_t r; 11 uint8_t g; 12 uint8_t b; 13} ppm_rgb; 14 15#define PPM_RED (ppm_rgb){255, 0, 0} 16#define PPM_GREEN (ppm_rgb){0, 255, 0} 17#define PPM_BLUE (ppm_rgb){0, 0, 255} 18#define PPM_WHITE (ppm_rgb){255, 255, 255} 19#define PPM_BLACK (ppm_rgb){0, 0, 0} 20 21typedef struct { 22 uint64_t width; 23 uint64_t height; 24 ppm_rgb *data; 25} ppm_image; 26 27ppm_image *ppm_create(uint64_t height, uint64_t width); 28ppm_image *ppm_create_with_background_color(uint64_t height, uint64_t width, 29 ppm_rgb background_color); 30int ppm_destroy(ppm_image *image); 31int ppm_to_ppm3_file(ppm_image *image, const char *file_path); 32int ppm_to_ppm6_file(ppm_image *image, const char *file_path); 33int ppm_draw_point(ppm_image *image, uint64_t x, uint64_t y, ppm_rgb color); 34int ppm_draw_circle(ppm_image *image, int x, int y, uint64_t radius, 35 ppm_rgb color); 36int ppm_draw_rectangle(ppm_image *image, int x, int y, uint64_t height, 37 uint64_t width, ppm_rgb color); 38int ppm_draw_line(ppm_image *image, int x1, int y1, int x2, int y2, 39 ppm_rgb color); 40int ppm_clear(ppm_image *image); 41int ppm_clear_with_background_color(ppm_image *image, ppm_rgb background_color); 42 43#endif