1 #ifndef _PROCESSING_H_
2 #define _PROCESSING_H_
3 
4 #include "sequence_filtering.h"
5 #include "io/fits_sequence.h"
6 
7 /**
8  *
9  * \file processing.h
10  * \brief
11  *
12  */
13 
14 /** Main structure of the generic function */
15 struct generic_seq_args {
16 	/** sequence that will be processed */
17 	sequence *seq;
18 	/** read images as float data in all cases */
19 	gboolean force_float;
20 
21 	/** process a partial image read from area instead of full-frame reading */
22 	gboolean partial_image;
23 	/** area of the partial image */
24 	rectangle area;
25 	/** in case of partial image reading, only one layer is read too */
26 	int layer_for_partial;
27 	/** in case of partial, we may use registration data to move the area */
28 	gboolean regdata_for_partial;
29 	/** flag to get photometry data */
30 	gboolean get_photometry_data_for_partial;
31 
32 	/** filtering the images from the sequence, maybe we don't want them all */
33 	seq_image_filter filtering_criterion;
34 	/** filtering parameter */
35 	double filtering_parameter;
36 	/** if already known, the number of images after filtering, for smoother
37 	 *  progress report. < 1 is unknown */
38 	int nb_filtered_images;
39 
40 	/** function called to compute the required disk size if has_output */
41 	gint64 (*compute_size_hook)(struct generic_seq_args *, int);
42 	/** function called to compute how many images fit in memory in parallel */
43 	int (*compute_mem_limits_hook)(struct generic_seq_args *, gboolean);
44 	/** function called before iterating through the sequence */
45 	int (*prepare_hook)(struct generic_seq_args *);
46 	/** function called for each image with image index in sequence, number
47 	 *  of image currently processed and the image, area if partial */
48 	int (*image_hook)(struct generic_seq_args *, int, int, fits *, rectangle *);
49 	/** saving the processed image, the one passed to the image_hook, so
50 	 * in-place editing, if the image_hook succeeded. Only used if
51 	 * has_output, set to NULL to get default behaviour */
52 	int (*save_hook)(struct generic_seq_args *, int, int, fits *);
53 	/** function called after iterating through the sequence, or on
54 	 * clean-up, even in case of error */
55 	int (*finalize_hook)(struct generic_seq_args *);
56 
57 	/** idle function to register at the end. If NULL, the default ending
58 	 *  that stops the thread is queued. Return false for single execution.
59 	 *  It should free its argument. */
60 	GSourceFunc idle_function;
61 	/** retval, useful for the idle_function, set by the worker */
62 	int retval;
63 
64 	/** if false, ignore image_hook errors, unselect failing image from the
65 	    sequence and continue processing other images */
66 	gboolean stop_on_error;
67 
68 	/** string description for progress and logs */
69 	const char *description;
70 
71 	/** some processing may create a new image sequence */
72 	gboolean has_output;
73 	/** the type of the created sequence, for disk space checks only */
74 	data_type output_type;
75 	/** size ratio of output images for memory evaluation */
76 	double upscale_ratio;
77 	/** output files: prefix for the new sequence and automatic loading */
78 	const char *new_seq_prefix;
79 	/** flag to load or not a new sequence */
80 	gboolean load_new_sequence;
81 	/** flag to force output to be SER file */
82 	gboolean force_ser_output;
83 	/** new output SER if seq->type == SEQ_SER or force_ser_output (internal) */
84 	struct ser_struct *new_ser;
85 	/** flag to force output to be FITS sequence file */
86 	gboolean force_fitseq_output;
87 	/** new output SER if seq->type == SEQ_FITSEQ or force_fitseq_output (internal) */
88 	fitseq *new_fitseq;
89 
90 	/** user data: pointer to operation-specific data */
91 	void *user;
92 
93 	/** if the generic sequence processing is run from an existing thread,
94 	 * the idle function is not executed in the GTK+ main thread but in this
95 	 * same thread. If this is false, the generic idle function is run. */
96 	gboolean already_in_a_thread;
97 	/** activate parallel execution */
98 	gboolean parallel;
99 	/** number of threads to run in parallel - defaults to com.max_thread */
100 	int max_thread;
101 #ifdef _OPENMP
102 	/** for in-hook synchronization (internal init, public use) */
103 	omp_lock_t lock;
104 #endif
105 };
106 
107 gpointer generic_sequence_worker(gpointer p);
108 gboolean end_generic_sequence(gpointer p);
109 
110 /* default functions for some hooks */
111 int seq_compute_mem_limits(struct generic_seq_args *args, gboolean for_writer);
112 int seq_prepare_hook(struct generic_seq_args *args);
113 int seq_prepare_writer(struct generic_seq_args *args);
114 int seq_finalize_hook(struct generic_seq_args *args);
115 int generic_save(struct generic_seq_args *, int, int, fits *);
116 
117 void start_in_new_thread(gpointer(*f)(gpointer p), gpointer p);
118 gpointer waiting_for_thread();
119 void stop_processing_thread();
120 void set_thread_run(gboolean b);
121 gboolean get_thread_run();
122 
123 void start_in_reserved_thread(gpointer (*f)(gpointer), gpointer p);
124 gboolean reserve_thread();
125 void unreserve_thread();
126 
127 gboolean end_generic(gpointer arg);
128 guint siril_add_idle(GSourceFunc idle_function, gpointer data);
129 
130 struct generic_seq_args *create_default_seqargs();
131 
132 #endif
133