27 #define DLL_EXPORT extern
30 #if defined __linux__ || defined __CYGWIN__
33 #define __bswap_16(a) __builtin_bswap16(a)
34 #define __bswap_32(a) __builtin_bswap32(a)
35 #define __bswap_64(a) __builtin_bswap64(a)
42 #include <sys/types.h>
68 #define DSP_MAX_STARS 200
72 #define dsp_t_min -dsp_t_max
121 #define DSP_DEBUG_INFO 0
122 #define DSP_DEBUG_ERROR 1
123 #define DSP_DEBUG_WARNING 2
124 #define DSP_DEBUG_DEBUG 3
125 #define pdbg(x, ...) ({ \
127 struct timespec ts; \
128 time_t t = time(NULL); \
129 struct tm tm = *localtime(&t); \
130 clock_gettime(CLOCK_REALTIME, &ts); \
131 sprintf(str, "[%04d-%02d-%02dT%02d:%02d:%02d.%03ld ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec/1000000); \
133 case DSP_DEBUG_ERROR: \
134 sprintf(&str[strlen(str)], "ERRO]"); \
136 case DSP_DEBUG_WARNING: \
137 sprintf(&str[strlen(str)], "WARN]"); \
139 case DSP_DEBUG_DEBUG: \
140 sprintf(&str[strlen(str)], "DEBG]"); \
143 sprintf(&str[strlen(str)], "INFO]"); \
146 if(dsp_get_app_name() != NULL) \
147 sprintf(&str[strlen(str)], "[%s]", dsp_get_app_name()); \
148 sprintf(&str[strlen(str)], " "); \
149 sprintf(&str[strlen(str)], __VA_ARGS__); \
152 #define pinfo(...) pdbg(DSP_DEBUG_INFO, __VA_ARGS__)
153 #define perr(...) pdbg(DSP_DEBUG_ERROR, __VA_ARGS__)
154 #define pwarn(...) pdbg(DSP_DEBUG_WARNING, __VA_ARGS__)
155 #define pgarb(...) pdbg(DSP_DEBUG_DEBUG, __VA_ARGS__)
156 #define pfunc pgarb("%s\n", __func__)
157 #define start_gettime
165 #define start_gettime(...)
166 #define end_gettime(...)
173 ({ __typeof (a) _a = (a); \
174 __typeof (a) _b = (b); \
175 _a < _b ? _a : _b; })
180 ({ __typeof (a) _a = (a); \
181 __typeof (a) _b = (b); \
182 _a > _b ? _a : _b; })
189 #ifndef DSP_ALIGN_TRANSLATED
191 #define DSP_ALIGN_TRANSLATED 1
193 #ifndef DSP_ALIGN_SCALED
195 #define DSP_ALIGN_SCALED 2
197 #ifndef DSP_ALIGN_ROTATED
199 #define DSP_ALIGN_ROTATED 4
201 #ifndef DSP_ALIGN_NO_MATCH
203 #define DSP_ALIGN_NO_MATCH 8
350 typedef void *(*dsp_func_t) (
void *, ...);
519 double HighFrequency);
528 double HighFrequency);
555 #ifndef dsp_stats_min
562 #define dsp_stats_min(buf, len)\
565 __typeof(buf[0]) min = (__typeof(buf[0]))buf[0];\
566 for(i = 0; i < len; i++) {\
567 min = Min(buf[i], min);\
573 #ifndef dsp_stats_max
580 #define dsp_stats_max(buf, len)\
583 __typeof(buf[0]) max = (__typeof(buf[0]))buf[0];\
584 for(i = 0; i < len; i++) {\
585 max = Max(buf[i], max);\
591 #ifndef dsp_stats_mid
598 #define dsp_stats_mid(buf, len)\
601 __typeof(buf[0]) min = dsp_stats_min(buf, len);\
602 (__typeof(buf[0]))(min - dsp_stats_max(buf, len)) / 2.0 + min;\
606 #ifndef dsp_stats_maximum_index
613 #define dsp_stats_minimum_index(buf, len)\
616 __typeof(buf[0]) min = dsp_stats_min(buf, len);\
617 for(i = 0; i < len; i++) {\
618 if(buf[i] == min) break;\
624 #ifndef dsp_stats_maximum_index
631 #define dsp_stats_maximum_index(buf, len)\
634 __typeof(buf[0]) max = dsp_stats_max(buf, len);\
635 for(i = 0; i < len; i++) {\
636 if(buf[i] == max) break;\
642 #ifndef dsp_stats_stddev
649 #define dsp_stats_mean(buf, len)\
652 double __dsp__mean = 0;\
653 for(__dsp__i = 0; __dsp__i < len; __dsp__i++) {\
654 __dsp__mean += buf[__dsp__i];\
661 #ifndef dsp_stats_stddev
667 #define dsp_stats_stddev(buf, len)\
669 double __dsp__mean = dsp_stats_mean(buf, len);\
671 double __dsp__stddev = 0;\
672 for(__dsp__x = 0; __dsp__x < len; __dsp__x++) {\
673 __dsp__stddev += fabs(buf[__dsp__x] - __dsp__mean);\
675 __dsp__stddev /= len;\
680 #ifndef dsp_stats_val_count
688 #define dsp_stats_val_count(buf, len, val) \
692 for(x = 0; x < len; x++) {\
700 #ifndef dsp_stats_val_sum
707 #define dsp_stats_val_sum(buf, len) \
711 for(x = 0; x < len; x++) {\
718 #ifndef dsp_stats_range_count
727 #define dsp_stats_range_count(buf, len, lo, hi) \
731 for(x = 0; x < len; x++) {\
732 if(buf[x] < hi && buf[x] >= lo)\
739 #ifndef dsp_stats_compare
747 #define dsp_stats_compare(in1, in2, len)\
749 __typeof(in1[0]) out = 0;\
750 for(int i = 0; i < len; i++) {\
751 out += in1[i] - (__typeof(in1[0]))in2[i];\
784 #ifndef dsp_buffer_stretch
792 #define dsp_buffer_stretch(buf, len, _mn, _mx)\
795 __typeof(buf[0]) __mn = dsp_stats_min(buf, len);\
796 __typeof(buf[0]) __mx = dsp_stats_max(buf, len);\
797 double oratio = (_mx - _mn);\
798 double iratio = (__mx - __mn);\
799 if(iratio == 0) iratio = 1;\
800 for(k = 0; k < len; k++) {\
802 buf[k] = (__typeof(buf[0]))((double)buf[k] * oratio / iratio);\
808 #ifndef dsp_buffer_set
815 #define dsp_buffer_set(buf, len, _val)\
818 for(k = 0; k < len; k++) {\
819 buf[k] = (__typeof(buf[0]))(_val);\
824 #ifndef dsp_buffer_normalize
832 #define dsp_buffer_normalize(buf, len, mn, mx)\
835 for(k = 0; k < len; k++) {\
836 buf[k] = Max(mn, Min(mx, buf[k]));\
985 #ifndef dsp_buffer_reverse
991 #define dsp_buffer_reverse(buf, len) \
993 int i = (len - 1) / 2; \
995 __typeof(buf[0]) _x; \
1007 #ifndef dsp_buffer_swap
1013 #define dsp_buffer_swap(in, len) \
1016 switch(sizeof(((__typeof (in[0])*)in)[0])) { \
1018 for(k = 0; k < len; k++) \
1019 ((__typeof (in[0])*)in)[k] = __bswap_16(((__typeof (in[0])*)in)[k]); \
1022 for(k = 0; k < len; k++) \
1023 ((__typeof (in[0])*)in)[k] = __bswap_32(((__typeof (in[0])*)in)[k]); \
1029 #ifndef dsp_buffer_copy
1038 #define dsp_buffer_copy(in, out, len) \
1041 for(k = 0; k < len; k++) { \
1042 ((__typeof (out[0])*)out)[k] = (__typeof (out[0]))((__typeof (in[0])*)in)[k]; \
1047 #ifndef dsp_buffer_copy_stepping
1059 #define dsp_buffer_copy_stepping(in, out, inlen, outlen, instep, outstep) \
1063 for(k = 0, t = 0; k < inlen && t < outlen; k+=instep, t+=outstep) { \
1064 ((__typeof (out[0])*)out)[t] = (__typeof (out[0]))((__typeof (in[0])*)in)[k]; \
DLL_EXPORT int dsp_get_debug_level()
get the debug level
DLL_EXPORT void dsp_set_stderr(FILE *f)
set the error log streeam
DLL_EXPORT unsigned long int dsp_max_threads(unsigned long value)
get/set the maximum number of threads allowed
DLL_EXPORT void dsp_set_debug_level(int value)
set the debug level
DLL_EXPORT void dsp_set_stdout(FILE *f)
set the output log streeam
DLL_EXPORT void dsp_print(int x, char *str)
log a message to the error or output streams
DLL_EXPORT char * dsp_get_app_name()
get the application name
DLL_EXPORT void dsp_set_app_name(char *name)
set the application name
void *(* dsp_func_t)(void *,...)
Multi-dimensional processing delegate function.
struct dsp_region_t dsp_region
Delimits a region in a single dimension of a buffer.
struct dsp_offset_t dsp_offset
Indicates an offset.
struct dsp_point_t dsp_point
Indicates a dot or line inside a dsp_stream.
struct dsp_stream_t * dsp_stream_p
struct dsp_triangle_t dsp_triangle
A star or object contained into a buffer.
struct dsp_align_info_t dsp_align_info
Alignment informations needed.
struct dsp_stream_t dsp_stream
Contains a set of informations and data relative to a buffer and how to use it.
union dsp_location_t dsp_location
The location type.
struct dsp_star_t dsp_star
A star or object contained into a buffer.
struct dsp_stream_t * phase
Fourier transform phase.
double samplerate
Sample rate of the buffers.
void * arg
Optional argument for the func() callback.
char name[128]
Friendly name of the stream.
struct dsp_location_t::@216 xyz
The location in xyz coordinates.
double imaginary
Imaginary part of the complex number.
double * pixel_sizes
Sensor size.
dsp_point center
The center of the star.
int frame_number
Frame number (if part of a series)
int triangles_count
Triangles of stars or objects quantity.
int dims
Dimensions limit.
double * factor
Scaling factor.
double wavelength
Wavelength observed, used as reference with signal generators or filters.
double focal_ratio
Focal ratio.
int start
Starting point within the buffer.
double * center
Center of rotation coordinates.
struct dsp_stream_t * parent
The parent stream.
int * sizes
Sizes of each dimension.
double * location
Center of the point.
dsp_complex dft
Fourier transform.
double * radians
Rotational offset.
struct dsp_location_t::@217 geographic
The location in geographic coordinates.
double index
The index of the triangle.
dsp_star * stars
Stars or objects identified into the buffers - TODO.
struct timespec starttimeutc
Time at the beginning of the stream.
dsp_star * stars
The stars of the triangle.
double * sizes
The sizes of the triangle.
double * buf
Linear double array containing complex numbers.
double * target
Target coordinates.
int stars_count
Stars or objects quantity.
struct dsp_stream_t * magnitude
Fourier transform magnitude.
double diameter
The diameter of the star.
int dims
The dimensions of the triangle.
double coordinates[3]
A 3d double array containing the location.
double * theta
The inclination of the triangle.
dsp_align_info align_info
Align/scale/rotation settings.
dsp_triangle * triangles
Triangles of stars or objects.
dsp_func_t func
Callback function.
int dims
Dimensions limit of the point.
char name[150]
The name of the star.
int dims
Number of dimensions of the buffers.
dsp_location * location
Location coordinates pointer, can be extended to the main buffer size as location companion.
double * offset
Center of the point.
struct dsp_stream_t ** children
Children streams.
int len
Length of the region.
int triangles_count
Triangles quantity.
int dims
Dimensions limit of the point.
int child_count
Children streams count.
int is_copy
Increments by one on the copied stream.
double * ratios
The sizes of the triangle.
dsp_triangle triangles[2]
Reference triangles.
dsp_region * ROI
Regions of interest for each dimension.
int len
The buffers length.
pthread_t thread
Thread type for future usage.
double real
Real part of the complex number.
double * offset
Translation offset.
complex_t * pairs
Complex number type array used with libFFTW.
DLL_EXPORT void dsp_buffer_sum(dsp_stream_p stream, dsp_t *in, int len)
Sum elements of one stream to another's.
DLL_EXPORT void dsp_buffer_log(dsp_stream_p stream, dsp_t *in, int len)
Logarithm elements of one stream using another's as base.
DLL_EXPORT void dsp_buffer_median(dsp_stream_p stream, int size, int median)
Median elements of the input stream.
DLL_EXPORT void dsp_buffer_shift(dsp_stream_p stream)
Shift a stream on each dimension.
DLL_EXPORT void dsp_buffer_deviate(dsp_stream_p stream, dsp_t *deviation, dsp_t mindeviation, dsp_t maxdeviation)
Deviate forward the first input stream using the second stream as indexing reference.
DLL_EXPORT void dsp_buffer_div1(dsp_stream_p stream, double val)
Divide elements of the input stream to a value.
DLL_EXPORT void dsp_buffer_removemean(dsp_stream_p stream)
Subtract mean from stream.
DLL_EXPORT void dsp_buffer_1sub(dsp_stream_p stream, dsp_t val)
Subtract each element of the input stream a value.
DLL_EXPORT void dsp_buffer_max(dsp_stream_p stream, dsp_t *in, int len)
Subtract elements of one stream from another's.
DLL_EXPORT void dsp_buffer_sigma(dsp_stream_p stream, int size)
Standard deviation of each element of the input stream within the given size.
DLL_EXPORT void dsp_buffer_div(dsp_stream_p stream, dsp_t *in, int len)
Divide elements of one stream to another's.
DLL_EXPORT void dsp_buffer_sum1(dsp_stream_p stream, dsp_t val)
Sum elements of the input stream to a value.
DLL_EXPORT void dsp_buffer_mul(dsp_stream_p stream, dsp_t *in, int len)
Multiply elements of one stream to another's.
DLL_EXPORT void dsp_buffer_pow1(dsp_stream_p stream, double val)
Expose elements of the input stream to the given power.
DLL_EXPORT void dsp_buffer_log1(dsp_stream_p stream, double val)
Logarithm elements of the input stream using the given base.
DLL_EXPORT void dsp_buffer_pow(dsp_stream_p stream, dsp_t *in, int len)
Expose elements of one stream to another's.
DLL_EXPORT void dsp_buffer_min(dsp_stream_p stream, dsp_t *in, int len)
Sum elements of one stream to another's.
DLL_EXPORT void dsp_buffer_1div(dsp_stream_p stream, double val)
Divide a value to each element of the input stream.
DLL_EXPORT void dsp_buffer_sub(dsp_stream_p stream, dsp_t *in, int len)
Subtract elements of one stream from another's.
DLL_EXPORT void dsp_buffer_sub1(dsp_stream_p stream, dsp_t val)
Subtract a value from elements of the input stream.
DLL_EXPORT void dsp_buffer_mul1(dsp_stream_p stream, double val)
Multiply elements of the input stream to a value.
DLL_EXPORT void dsp_convolution_correlation(dsp_stream_p stream, dsp_stream_p matrix)
A cross-correlation processor.
DLL_EXPORT void dsp_convolution_convolution(dsp_stream_p stream, dsp_stream_p matrix)
A cross-convolution processor.
DLL_EXPORT void dsp_stream_free(dsp_stream_p stream)
Free the DSP stream passed as argument.
DLL_EXPORT void dsp_stream_scale(dsp_stream_p stream)
Scale a stream.
DLL_EXPORT void dsp_stream_set_dim(dsp_stream_p stream, int dim, int size)
Set a dimension size to a DSP stream.
DLL_EXPORT void dsp_stream_rotate(dsp_stream_p stream)
Rotate a stream around an axis and offset.
DLL_EXPORT void dsp_stream_del_triangle(dsp_stream_p stream, int index)
Remove the triangle with index n to a DSP stream.
DLL_EXPORT void * dsp_stream_exec(dsp_stream_p stream, void *args,...)
Execute the function callback pointed by the func field of the passed stream.
DLL_EXPORT int dsp_stream_set_position(dsp_stream_p stream, int *pos)
Obtain the position the DSP stream by parsing multidimensional indexes.
DLL_EXPORT int * dsp_stream_get_position(dsp_stream_p stream, int index)
Return the multidimensional positional indexes of a DSP stream by specify a linear index.
DLL_EXPORT dsp_stream_p dsp_stream_copy(dsp_stream_p stream)
Create a copy of the DSP stream passed as argument.
DLL_EXPORT void dsp_stream_add_triangle(dsp_stream_p stream, dsp_triangle triangle)
Add a triangle to the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_add_child(dsp_stream_p stream, dsp_stream_p child)
Add a child to the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_del_dim(dsp_stream_p stream, int n)
Remove the dimension with index n to a DSP stream.
DLL_EXPORT dsp_t * dsp_stream_get_buffer(dsp_stream_p stream)
Return the buffer of the stream passed as argument.
DLL_EXPORT void dsp_stream_set_buffer(dsp_stream_p stream, void *buffer, int len)
Set the buffer of the stream passed as argument to a specific memory location.
DLL_EXPORT void dsp_stream_del_child(dsp_stream_p stream, int n)
Remove the child with index n to a DSP stream.
DLL_EXPORT dsp_stream_p dsp_stream_new(void)
Allocate a new DSP stream type.
DLL_EXPORT void dsp_stream_add_dim(dsp_stream_p stream, int len)
Add a dimension with length len to a DSP stream.
DLL_EXPORT void dsp_stream_alloc_buffer(dsp_stream_p stream, int len)
Allocate a buffer with length len on the stream passed as argument.
DLL_EXPORT void dsp_stream_crop(dsp_stream_p stream)
Crop the buffers of the stream passed as argument by reading the ROI field.
DLL_EXPORT void dsp_stream_translate(dsp_stream_p stream)
Translate a stream.
DLL_EXPORT void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_del_star(dsp_stream_p stream, int n)
Remove the star with index n to a DSP stream.
DLL_EXPORT void dsp_stream_add_star(dsp_stream_p stream, dsp_star star)
Add a star to the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_calc_triangles(dsp_stream_p stream)
Calculate the triangles in the stream struct.
DLL_EXPORT void dsp_stream_align(dsp_stream_p in)
Perform scale, translate and rotate transformations in-place.
DLL_EXPORT void dsp_buffer_components_to_rgb(dsp_stream_p *stream, void *rgb, int components, int bpp)
Convert a component dsp_stream_p array into an RGB dsp_t array.
DLL_EXPORT void dsp_file_write_jpeg_composite(const char *filename, int components, int quality, dsp_stream_p *stream)
Write the components dsp_stream_p array into a JPEG file,.
DLL_EXPORT dsp_stream_p * dsp_stream_from_components(dsp_t *buf, int dims, int *sizes, int components)
Convert a color component dsp_t array into a dsp_stream_p array each element containing the single co...
DLL_EXPORT int dsp_qsort_double_asc(const void *arg1, const void *arg2)
Callback function for qsort for double type ascending ordering.
DLL_EXPORT dsp_t * dsp_file_bayer_2_gray(dsp_t *src, int width, int height)
Convert a bayer pattern dsp_t array into a grayscale array.
DLL_EXPORT void dsp_file_write_fits_bayer(const char *filename, int components, int bpp, dsp_stream_p *stream)
Write a FITS file from a dsp_stream_p array.
DLL_EXPORT void dsp_file_write_fits_composite(const char *filename, int components, int bpp, dsp_stream_p *stream)
Write the components dsp_stream_p array into a JPEG file,.
DLL_EXPORT dsp_align_info dsp_align_fill_info(dsp_triangle t1, dsp_triangle t2)
Fill a dsp_align_info struct by comparing two triangles.
DLL_EXPORT dsp_t * dsp_file_bayer_2_rgb(dsp_t *src, int red, int width, int height)
Convert a bayer pattern dsp_t array into a ordered 3 RGB array.
DLL_EXPORT void dsp_file_write_jpeg(const char *filename, int quality, dsp_stream_p stream)
Write the stream into a JPEG file,.
DLL_EXPORT int dsp_align_get_offset(dsp_stream_p ref, dsp_stream_p to_align, double tolerance, double target_score)
Calculate offsets, rotation and scaling of two streams giving reference alignment point.
DLL_EXPORT dsp_stream_p * dsp_buffer_rgb_to_components(void *buf, int dims, int *sizes, int components, int bpp, int stretch)
Convert an RGB color dsp_t array into a dsp_stream_p array each element containing the single compone...
DLL_EXPORT dsp_t * dsp_file_composite_2_bayer(dsp_stream_p *src, int red, int width, int height)
Convert a component dsp_stream_p array into a bayer dsp_t array.
DLL_EXPORT dsp_stream_p * dsp_file_read_jpeg(const char *filename, int *channels, int stretch)
Read a JPEG file and fill a array of dsp_stream_p with its content, each color channel has its own st...
DLL_EXPORT int dsp_qsort_star_diameter_asc(const void *arg1, const void *arg2)
Callback function for qsort for dsp_star ascending ordering by their diameters.
DLL_EXPORT dsp_stream_p * dsp_file_read_fits(const char *filename, int *channels, int stretch)
Read a FITS file and fill a dsp_stream_p with its content.
DLL_EXPORT int dsp_qsort_star_diameter_desc(const void *arg1, const void *arg2)
Callback function for qsort for dsp_star descending ordering by their diameters.
DLL_EXPORT void dsp_file_write_fits(const char *filename, int bpp, dsp_stream_p stream)
Write the dsp_stream_p into a FITS file,.
DLL_EXPORT int dsp_qsort_double_desc(const void *arg1, const void *arg2)
Callback function for qsort for double type descending ordering.
DLL_EXPORT dsp_t * dsp_file_bayer_2_composite(dsp_t *src, int red, int width, int height)
Convert a bayer pattern dsp_t array into a contiguos component array.
DLL_EXPORT dsp_triangle dsp_align_calc_triangle(dsp_star *stars)
Create a dsp_triangle struct.
DLL_EXPORT void dsp_filter_lowpass(dsp_stream_p stream, double frequency)
A low pass filter.
DLL_EXPORT void dsp_filter_bandreject(dsp_stream_p stream, double LowFrequency, double HighFrequency)
A band reject filter.
DLL_EXPORT void dsp_filter_bandpass(dsp_stream_p stream, double LowFrequency, double HighFrequency)
A band pass filter.
DLL_EXPORT void dsp_filter_highpass(dsp_stream_p stream, double frequency)
A high pass filter.
DLL_EXPORT void dsp_filter_squarelaw(dsp_stream_p stream)
A square law filter.
DLL_EXPORT void dsp_signals_sawtoothwave(dsp_stream_p stream, double samplefreq, double freq)
Generate a sawtooth wave.
DLL_EXPORT void dsp_signals_sinewave(dsp_stream_p stream, double samplefreq, double freq)
Generate a sinusoidal wave.
DLL_EXPORT void dsp_signals_triwave(dsp_stream_p stream, double samplefreq, double freq)
Generate a triangular wave.
DLL_EXPORT void dsp_modulation_amplitude(dsp_stream_p stream, double samplefreq, double freq)
Generate an amplitude modulated wave.
DLL_EXPORT void dsp_modulation_frequency(dsp_stream_p stream, double samplefreq, double freq, double bandwidth)
Generate a frequency modulated wave.
DLL_EXPORT void dsp_signals_whitenoise(dsp_stream_p stream)
Generate white noise.
DLL_EXPORT double * dsp_stats_histogram(dsp_stream_p stream, int size)
Histogram of the inut stream.
std::vector< uint8_t > buffer
Alignment informations needed.
Indicates a dot or line inside a dsp_stream.
Delimits a region in a single dimension of a buffer.
A star or object contained into a buffer.
Contains a set of informations and data relative to a buffer and how to use it.
A star or object contained into a buffer.
Complex number array struct, used in Fourier Transform functions.