| 1 |
#ifndef __PILLOWFIGHT_H |
| 2 |
#define __PILLOWFIGHT_H |
| 3 |
|
| 4 |
#include <stdint.h> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
enum pf_color { |
| 12 |
COLOR_R = 0, |
| 13 |
COLOR_G, |
| 14 |
COLOR_B, |
| 15 |
COLOR_A, |
| 16 |
}; |
| 17 |
#define PF_NB_COLORS 4 |
| 18 |
#define PF_NB_RGB_COLORS 3 |
| 19 |
|
| 20 |
#define PF_WHITE 0xFF |
| 21 |
#define PF_WHOLE_WHITE 0xFFFFFFFF |
| 22 |
#define PF_BLACK 0x00 |
| 23 |
|
| 24 |
|
| 25 |
union pf_pixel { |
| 26 |
uint32_t whole; |
| 27 |
struct { |
| 28 |
uint8_t r; |
| 29 |
uint8_t g; |
| 30 |
uint8_t b; |
| 31 |
uint8_t a; |
| 32 |
} color; |
| 33 |
uint8_t channels[4]; |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
struct pf_bitmap { |
| 38 |
struct { |
| 39 |
int x; |
| 40 |
int y; |
| 41 |
} size; |
| 42 |
union pf_pixel *pixels; |
| 43 |
}; |
| 44 |
|
| 45 |
struct pf_point { |
| 46 |
int x; |
| 47 |
int y; |
| 48 |
}; |
| 49 |
|
| 50 |
struct pf_rectangle { |
| 51 |
struct pf_point a; |
| 52 |
struct pf_point b; |
| 53 |
}; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
#define PF_GET_PIXEL(bitmap, a, b) ((bitmap)->pixels[((b) * (bitmap)->size.x) + (a)]) |
| 60 |
#define PF_GET_PIXEL_DEF(bitmap, a, b, def) \ |
| 61 |
((a < 0 || a >= bitmap->size.x) ? def : \ |
| 62 |
((b < 0 || b >= bitmap->size.y) ? def : \ |
| 63 |
PF_GET_PIXEL(bitmap, a, b))) |
| 64 |
|
| 65 |
#define PF_SET_PIXEL(bitmap, a, b, value) PF_GET_PIXEL(bitmap, a, b).whole = (value); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
#define PF_GET_COLOR(bitmap, a, b, color) (PF_GET_PIXEL(bitmap, a, b).channels[(color)]) |
| 71 |
#define PF_GET_COLOR_DEF(bitmap, a, b, color, def) (PF_GET_PIXEL_DEF(bitmap, a, b, def).channels[(color)]) |
| 72 |
|
| 73 |
#define PF_SET_COLOR(bitmap, a, b, color, value) (PF_GET_PIXEL(bitmap, a, b).channels[(color)]) = (value) |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
struct pf_dbl_matrix { |
| 80 |
struct { |
| 81 |
int x; |
| 82 |
int y; |
| 83 |
} size; |
| 84 |
double *values; |
| 85 |
}; |
| 86 |
|
| 87 |
#define PF_MATRIX_GET(matrix, a, b) ((matrix)->values[((b) * (matrix)->size.x) + (a)]) |
| 88 |
#define PF_MATRIX_SET(matrix, a, b, val) PF_MATRIX_GET(matrix, a, b) = (val); |
| 89 |
|
| 90 |
|
| 91 |
#ifdef NO_PYTHON |
| 92 |
|
| 93 |
#define PF_DEFAULT_ACE_SLOPE 10 |
| 94 |
#define PF_DEFAULT_ACE_LIMIT 1000 |
| 95 |
#define PF_DEFAULT_ACE_NB_SAMPLES 100 |
| 96 |
#define PF_DEFAULT_ACE_NB_THREADS 2 |
| 97 |
extern void pf_ace(const struct pf_bitmap *in, struct pf_bitmap *out, |
| 98 |
int nb_samples, double slope, double limit, |
| 99 |
int nb_threads); |
| 100 |
|
| 101 |
extern void pf_canny(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 102 |
#endif |
| 103 |
|
| 104 |
extern struct pf_dbl_matrix pf_canny_on_matrix(const struct pf_dbl_matrix *in); |
| 105 |
|
| 106 |
#define PF_COMPARE_DEFAULT_TOLERANCE 10 |
| 107 |
|
| 108 |
#ifdef NO_PYTHON |
| 109 |
extern int pf_compare(const struct pf_bitmap *in, const struct pf_bitmap *in2, |
| 110 |
struct pf_bitmap *out, int tolerance); |
| 111 |
#endif |
| 112 |
|
| 113 |
#define PF_GAUSSIAN_DEFAULT_SIGMA 2.0 |
| 114 |
#define PF_GAUSSIAN_DEFAULT_NB_STDDEV 5 |
| 115 |
|
| 116 |
#ifdef NO_PYTHON |
| 117 |
extern void pf_gaussian(const struct pf_bitmap *in, struct pf_bitmap *out, |
| 118 |
double sigma, int nb_stddev); |
| 119 |
#endif |
| 120 |
|
| 121 |
extern struct pf_dbl_matrix pf_gaussian_on_matrix( |
| 122 |
const struct pf_dbl_matrix *grayscale_matrix, |
| 123 |
double sigma, int nb_stddev); |
| 124 |
|
| 125 |
#ifdef NO_PYTHON |
| 126 |
extern void pf_sobel(const struct pf_bitmap *in_img, struct pf_bitmap *out_img); |
| 127 |
#endif |
| 128 |
|
| 129 |
extern const struct pf_dbl_matrix g_pf_kernel_sobel_x; |
| 130 |
extern const struct pf_dbl_matrix g_pf_kernel_sobel_y; |
| 131 |
extern const struct pf_dbl_matrix g_pf_kernel_scharr_x; |
| 132 |
extern const struct pf_dbl_matrix g_pf_kernel_scharr_y; |
| 133 |
|
| 134 |
#define PF_SOBEL_DEFAULT_KERNEL_X (&g_pf_kernel_sobel_x) |
| 135 |
#define PF_SOBEL_DEFAULT_KERNEL_Y (&g_pf_kernel_sobel_y) |
| 136 |
|
| 137 |
struct pf_gradient_matrixes { |
| 138 |
struct pf_dbl_matrix g_x; |
| 139 |
struct pf_dbl_matrix g_y; |
| 140 |
struct pf_dbl_matrix intensity; |
| 141 |
struct pf_dbl_matrix direction; |
| 142 |
}; |
| 143 |
extern struct pf_gradient_matrixes pf_sobel_on_matrix(const struct pf_dbl_matrix *in, |
| 144 |
const struct pf_dbl_matrix *kernel_x, const struct pf_dbl_matrix *kernel_y, |
| 145 |
double gaussian_sigma, int gaussian_stddev); |
| 146 |
|
| 147 |
enum pf_swt_output |
| 148 |
{ |
| 149 |
PF_SWT_OUTPUT_BW_TEXT = 0, |
| 150 |
PF_SWT_OUTPUT_GRAYSCALE_TEXT, |
| 151 |
PF_SWT_OUTPUT_ORIGINAL_BOXES, |
| 152 |
}; |
| 153 |
#define PF_DEFAULT_SWT_OUTPUT PF_SWT_OUTPUT_BW_TEXT |
| 154 |
|
| 155 |
#ifdef NO_PYTHON |
| 156 |
extern void pf_swt(const struct pf_bitmap *in_img, struct pf_bitmap *out_img, |
| 157 |
enum pf_swt_output output_type); |
| 158 |
|
| 159 |
extern void pf_unpaper_blackfilter(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 160 |
|
| 161 |
extern void pf_unpaper_blurfilter(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 162 |
|
| 163 |
extern void pf_unpaper_border(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 164 |
|
| 165 |
extern void pf_unpaper_grayfilter(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 166 |
|
| 167 |
extern void pf_unpaper_masks(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 168 |
|
| 169 |
extern void pf_unpaper_noisefilter(const struct pf_bitmap *in, struct pf_bitmap *out); |
| 170 |
|
| 171 |
extern struct pf_rectangle pf_find_scan_borders(const struct pf_bitmap *img_in); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
extern const char *pf_get_version(void); |
| 177 |
#endif |
| 178 |
|
| 179 |
extern void pf_write_bitmap_to_ppm(const char *filepath, const struct pf_bitmap *in); |
| 180 |
|
| 181 |
#endif |