86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
#ifndef _CAMMY_IMAGE_H
|
|
#define _CAMMY_IMAGE_H
|
|
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
|
|
#define CAMMY_IMAGE_Y_COEFFICIENT_R 0.2126
|
|
#define CAMMY_IMAGE_Y_COEFFICIENT_G 0.7152
|
|
#define CAMMY_IMAGE_Y_COEFFICIENT_B 0.0722
|
|
|
|
#define CAMMY_IMAGE_CHUNK_SIZE 4096
|
|
|
|
#define CAMMY_IMAGE_MAGIC_PNG "\x89PNG"
|
|
|
|
typedef enum {
|
|
CAMMY_IMAGE_NONE,
|
|
CAMMY_IMAGE_TILE,
|
|
CAMMY_IMAGE_BITMAP
|
|
} cammy_image_format;
|
|
|
|
typedef enum {
|
|
CAMMY_IMAGE_2BPP = 2,
|
|
CAMMY_IMAGE_24BPP_RGB = 24,
|
|
CAMMY_IMAGE_32BPP_RGBA = 32
|
|
} cammy_image_depth;
|
|
|
|
typedef struct _cammy_image_color {
|
|
uint8_t r, g, b, a;
|
|
} cammy_image_color;
|
|
|
|
typedef struct _cammy_image {
|
|
cammy_image_format format;
|
|
cammy_image_depth depth;
|
|
|
|
cammy_image_color palette[4];
|
|
|
|
size_t size,
|
|
width,
|
|
height;
|
|
|
|
uint8_t *buf;
|
|
} cammy_image;
|
|
|
|
typedef struct _cammy_image_point {
|
|
size_t x, y;
|
|
} cammy_image_point;
|
|
|
|
typedef struct _cammy_image_region {
|
|
size_t x, y, width, height;
|
|
} cammy_image_region;
|
|
|
|
int cammy_image_init(cammy_image *image,
|
|
cammy_image_format format,
|
|
cammy_image_depth depth,
|
|
cammy_image_color *palette,
|
|
size_t width,
|
|
size_t height,
|
|
uint8_t *buf);
|
|
|
|
cammy_image *cammy_image_new(cammy_image_format format,
|
|
cammy_image_depth depth,
|
|
cammy_image_color *palette,
|
|
size_t width,
|
|
size_t height);
|
|
|
|
void cammy_image_destroy(cammy_image *image);
|
|
|
|
cammy_image *cammy_image_open(const char *filename);
|
|
|
|
int cammy_image_save(cammy_image *image, const char *filename);
|
|
|
|
void cammy_image_copy(cammy_image *dest,
|
|
cammy_image *src,
|
|
cammy_image_point *to,
|
|
cammy_image_region *from);
|
|
|
|
int cammy_image_split(cammy_image *image,
|
|
cammy_image **r,
|
|
cammy_image **g,
|
|
cammy_image **b);
|
|
|
|
cammy_image *cammy_image_merge(cammy_image *r,
|
|
cammy_image *g,
|
|
cammy_image *b);
|
|
|
|
#endif /* _CAMMY_IMAGE_H */
|