2016-05-14 23:40:28 -05:00
|
|
|
#ifndef _CAMMY_IMAGE_H
|
|
|
|
#define _CAMMY_IMAGE_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cammy/tile.h>
|
|
|
|
|
2016-05-17 17:01:57 -05:00
|
|
|
#define CAMMY_IMAGE_Y_COEFFICIENT_R 0.2126
|
|
|
|
#define CAMMY_IMAGE_Y_COEFFICIENT_G 0.7152
|
|
|
|
#define CAMMY_IMAGE_Y_COEFFICIENT_B 0.0722
|
|
|
|
|
2016-06-07 00:07:58 -05:00
|
|
|
#define CAMMY_IMAGE_CHUNK_SIZE 4096
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CAMMY_IMAGE_NONE,
|
|
|
|
CAMMY_IMAGE_TILE,
|
|
|
|
CAMMY_IMAGE_RGB,
|
|
|
|
CAMMY_IMAGE_RGBA
|
|
|
|
} cammy_image_format;
|
|
|
|
|
|
|
|
typedef struct _cammy_image {
|
|
|
|
cammy_image_format format;
|
|
|
|
|
2016-06-07 22:45:13 -05:00
|
|
|
size_t size,
|
|
|
|
width,
|
2016-06-07 00:07:58 -05:00
|
|
|
height;
|
|
|
|
|
|
|
|
union {
|
|
|
|
uint8_t *buf;
|
2016-06-07 19:38:33 -05:00
|
|
|
cammy_tile *tiles;
|
2016-06-07 00:07:58 -05:00
|
|
|
};
|
|
|
|
} cammy_image;
|
|
|
|
|
2021-11-26 13:40:41 -05:00
|
|
|
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;
|
|
|
|
|
2016-06-07 22:45:13 -05:00
|
|
|
cammy_image *cammy_image_new(cammy_image_format format,
|
|
|
|
size_t width,
|
|
|
|
size_t height);
|
|
|
|
|
2016-06-07 00:07:58 -05:00
|
|
|
cammy_image *cammy_image_open_tile(const char *filename,
|
|
|
|
size_t width,
|
|
|
|
size_t height);
|
|
|
|
|
2016-06-07 22:45:13 -05:00
|
|
|
int cammy_image_save_tile(cammy_image *image, const char *filename);
|
|
|
|
|
2016-06-07 00:07:58 -05:00
|
|
|
void cammy_image_close(cammy_image *image);
|
|
|
|
|
2016-06-07 22:45:13 -05:00
|
|
|
void cammy_image_destroy(cammy_image *image);
|
|
|
|
|
2016-06-07 00:07:58 -05:00
|
|
|
int cammy_image_save(cammy_image *image, const char *filename);
|
|
|
|
|
2016-05-17 02:23:19 -05:00
|
|
|
void cammy_image_dither(uint8_t *dest,
|
|
|
|
uint8_t *src,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
int depth,
|
|
|
|
cammy_tile_palette *palette);
|
|
|
|
|
|
|
|
void cammy_image_dither_to_tile(cammy_tile *dest,
|
|
|
|
uint8_t *src,
|
2016-06-09 01:12:06 -05:00
|
|
|
size_t x_dest,
|
|
|
|
size_t y_dest,
|
|
|
|
size_t x_src,
|
|
|
|
size_t y_src,
|
2016-05-17 02:23:19 -05:00
|
|
|
size_t width,
|
|
|
|
size_t height,
|
2016-06-09 01:12:06 -05:00
|
|
|
size_t dest_width,
|
|
|
|
size_t dest_height,
|
|
|
|
size_t src_width,
|
|
|
|
size_t src_height,
|
2016-05-17 02:23:19 -05:00
|
|
|
int depth);
|
|
|
|
|
2016-05-20 22:24:11 +00:00
|
|
|
void cammy_image_split_to_tiles(cammy_tile *destr,
|
|
|
|
cammy_tile *destg,
|
|
|
|
cammy_tile *destb,
|
|
|
|
uint8_t *src,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
int depth);
|
|
|
|
|
2016-05-17 02:23:19 -05:00
|
|
|
void cammy_image_copy_from_tile(uint8_t *dest,
|
|
|
|
cammy_tile *src,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
int depth,
|
|
|
|
cammy_tile_palette *palette);
|
2016-05-14 23:40:28 -05:00
|
|
|
|
2016-05-20 22:24:11 +00:00
|
|
|
void cammy_image_merge_tiles(uint8_t *dest,
|
|
|
|
cammy_tile *srcr,
|
|
|
|
cammy_tile *srcg,
|
|
|
|
cammy_tile *srcb,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
int depth);
|
|
|
|
|
2016-06-07 20:54:42 -05:00
|
|
|
void cammy_image_copy(cammy_image *dest,
|
|
|
|
cammy_image *src,
|
|
|
|
size_t x_dest,
|
|
|
|
size_t y_dest,
|
|
|
|
size_t x_src,
|
|
|
|
size_t y_src,
|
|
|
|
size_t width,
|
|
|
|
size_t height);
|
2016-06-07 00:07:58 -05:00
|
|
|
|
2016-07-04 18:28:01 -05:00
|
|
|
int cammy_image_slice(uint8_t *buf,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
size_t x_pad,
|
|
|
|
size_t y_pad,
|
|
|
|
int depth);
|
2016-06-09 01:12:06 -05:00
|
|
|
|
2016-05-14 23:40:28 -05:00
|
|
|
#endif /* _CAMMY_IMAGE_H */
|