#ifndef _DEMOSAICING_H
#define _DEMOSAICING_H

// set to 1 to save green_interpolated fits
#define BAYER_DEBUG 0
extern const char *filter_pattern[];
extern const size_t num_filter_patterns;
void adjust_Bayer_pattern_orientation(sensor_pattern *pattern, unsigned int ry, gboolean flip);
sensor_pattern get_cfa_pattern_index_from_string(const char *bayer);
sensor_pattern get_validated_cfa_pattern(fits *fit, gboolean force_debayer, gboolean verbose);
int FC_array(int row, int col, BYTE* bpattern, int size);
int get_compiled_pattern(fits *fit, BYTE pattern[36], int *pattern_size, gboolean verbose);
gboolean fit_is_cfa(fits *fit);
gboolean compare_compiled_pattern(BYTE *refpattern, BYTE *pattern, int pattern_size);
void update_bayer_pattern_information(fits *fit, sensor_pattern pattern);
void get_debayer_area(const rectangle *area, rectangle *debayer_area,
		const rectangle *image_area, int *debayer_offset_x,
		int *debayer_offset_y);

int debayer(fits*, interpolation_method, sensor_pattern pattern);


#ifdef __cplusplus
extern "C" {
#endif
int debayer_if_needed(image_type imagetype, fits *fit, gboolean force_debayer);
#ifdef __cplusplus
}
#endif

struct merge_cfa_data {
	sequence *seq0;
	sequence *seq1;
	sequence *seq2;
	sequence *seq3;
	char *seqEntryOut;
	sensor_pattern pattern;
};

void apply_mergecfa_to_sequence(struct merge_cfa_data *merge_cfa_args);

#ifdef __cplusplus
extern "C" {
#endif
/* from demosaicing_rtp.cpp */
WORD *debayer_buffer_new_ushort(WORD *buf, int *width, int *height,
		interpolation_method interpolation, sensor_pattern pattern, unsigned int xtrans[6][6], int bit_depth);

float *debayer_buffer_new_float(float *buf, int *width, int *height,
		interpolation_method interpolation, sensor_pattern pattern, unsigned int xtrans[6][6]);
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
fits* merge_cfa (fits *cfa0, fits *cfa1, fits *cfa2, fits *cfa3, sensor_pattern pattern);
#ifdef __cplusplus
}
#endif
WORD *extract_CFA_buffer_ushort(fits *fit, int layer, size_t *newsize);
WORD *extract_CFA_buffer_area_ushort(fits *fit, int layer, rectangle *bounds, size_t *newsize);
float *extract_CFA_buffer_float(fits *fit, int layer, size_t *newsize);
float *extract_CFA_buffer_area_float(fits *fit, int layer, rectangle *bounds, size_t *newsize);

#endif
