Instrument Neutral Distributed Interface INDI  2.0.2
stream.c
Go to the documentation of this file.
1 /*
2 * DSP API - a digital signal processing library for astronomy usage
3 * Copyright © 2017-2022 Ilia Platone
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "dsp.h"
21 static int dsp_debug = 0;
22 static char* dsp_app_name = NULL;
23 
24 static int DSP_MAX_THREADS = 1;
25 
26 static unsigned long MAX_THREADS = 1;
27 
28 static FILE *out = NULL;
29 static FILE *err = NULL;
30 
31 unsigned long int dsp_max_threads(unsigned long value)
32 {
33  if(value>0) {
34  MAX_THREADS = value;
35  DSP_MAX_THREADS = value;
36  }
37  return MAX_THREADS;
38 }
39 
40 void dsp_set_stdout(FILE *f)
41 {
42  out = f;
43 }
44 
45 void dsp_set_stderr(FILE *f)
46 {
47  err = f;
48 }
49 
50 void dsp_print(int x, char* str)
51 {
52  if(x == DSP_DEBUG_INFO && out != NULL)
53  fprintf(out, "%s", str);
54  else if(x <= dsp_get_debug_level() && err != NULL)
55  fprintf(err, "%s", str);
56 }
57 
58 void dsp_set_debug_level(int value)
59 {
60  dsp_debug = value;
61 }
62 
63 void dsp_set_app_name(char* name)
64 {
65  dsp_app_name = name;
66 }
67 
69 {
70  return dsp_debug;
71 }
72 
74 {
75  return dsp_app_name;
76 }
77 
79 {
80  if(stream->buf != NULL) {
81  stream->buf = (dsp_t*)realloc(stream->buf, sizeof(dsp_t) * len);
82  } else {
83  stream->buf = (dsp_t*)malloc(sizeof(dsp_t) * len);
84  }
85  if(stream->dft.buf != NULL) {
86  stream->dft.buf = (double*)realloc(stream->dft.buf, sizeof(double) * len * 2);
87  } else {
88  stream->dft.buf = (double*)malloc(sizeof(double) * len * 2);
89  }
90  if(stream->location != NULL) {
91  stream->location = (dsp_location*)realloc(stream->location, sizeof(dsp_location) * (stream->len));
92  } else {
93  stream->location = (dsp_location*)malloc(sizeof(dsp_location) * (stream->len));
94  }
95  if(stream->magnitude != NULL)
96  dsp_stream_alloc_buffer(stream->magnitude, len);
97  if(stream->phase != NULL)
98  dsp_stream_alloc_buffer(stream->phase, len);
99 }
100 
101 void dsp_stream_set_buffer(dsp_stream_p stream, void *buffer, int len)
102 {
103  stream->buf = (dsp_t*)buffer;
104  stream->len = len;
105 }
106 
108 {
109  return stream->buf;
110 }
111 
113 {
114  if(stream->buf != NULL)
115  free(stream->buf);
116  if(stream->dft.buf != NULL)
117  free(stream->dft.buf);
118 }
119 
125 {
126  dsp_stream_p stream = (dsp_stream_p)malloc(sizeof(dsp_stream) * 1);
127  stream->is_copy = 0;
128  stream->buf = (dsp_t*)malloc(sizeof(dsp_t) * 0);
129  stream->dft.buf = (double*)malloc(sizeof(dsp_t) * 0);
130  stream->magnitude = NULL;
131  stream->phase = NULL;
132  stream->sizes = (int*)malloc(sizeof(int) * 1);
133  stream->pixel_sizes = (double*)malloc(sizeof(double) * 1);
134  stream->children = (dsp_stream_p*)malloc(sizeof(dsp_stream_p) * 1);
135  stream->ROI = (dsp_region*)malloc(sizeof(dsp_region) * 1);
136  stream->location = (dsp_location*)malloc(sizeof(dsp_location) * 1);
137  stream->target = (double*)malloc(sizeof(double) * 3);
138  stream->stars = (dsp_star*)malloc(sizeof(dsp_star) * 1);
139  stream->triangles = (dsp_triangle*)malloc(sizeof(dsp_triangle) * 1);
140  stream->align_info.offset = (double*)malloc(sizeof(double)*1);
141  stream->align_info.center = (double*)malloc(sizeof(double)*1);
142  stream->align_info.radians = (double*)malloc(sizeof(double)*1);
143  stream->align_info.factor = (double*)malloc(sizeof(double)*1);
144  stream->stars_count = 0;
145  stream->triangles_count = 0;
146  stream->child_count = 0;
147  stream->frame_number = 0;
148  stream->parent = NULL;
149  stream->dims = 0;
150  stream->red = -1;
151  stream->len = 1;
152  stream->wavelength = 0;
153  stream->diameter = 1;
154  stream->focal_ratio = 1;
155  stream->samplerate = 0;
156  return stream;
157 }
158 
164 {
165  if(stream == NULL)
166  return;
167  if(stream->sizes != NULL)
168  free(stream->sizes);
169  if(stream->pixel_sizes != NULL)
170  free(stream->pixel_sizes);
171  if(stream->children != NULL)
172  free(stream->children);
173  if(stream->ROI != NULL)
174  free(stream->ROI);
175  if(stream->location != NULL)
176  free(stream->location);
177  if(stream->target != NULL)
178  free(stream->target);
179  if(stream->stars != NULL)
180  free(stream->stars);
181  if(stream->triangles != NULL)
182  free(stream->triangles);
183  free(stream);
184  stream = NULL;
185 }
186 
193 {
194  dsp_stream_p dest = dsp_stream_new();
195  int i;
196  for(i = 0; i < stream->dims; i++)
197  dsp_stream_add_dim(dest, abs(stream->sizes[i]));
198  for(i = 0; i < stream->stars_count; i++)
199  dsp_stream_add_star(dest, stream->stars[i]);
200  for(i = 0; i < stream->triangles_count; i++)
201  dsp_stream_add_triangle(dest, stream->triangles[i]);
202  dest->is_copy = stream->is_copy + 1;
203  dsp_stream_alloc_buffer(dest, dest->len);
204  dest->wavelength = stream->wavelength;
205  dest->samplerate = stream->samplerate;
206  dest->diameter = stream->diameter;
207  dest->focal_ratio = stream->focal_ratio;
208  memcpy(&dest->starttimeutc, &stream->starttimeutc, sizeof(struct timespec));
209  memcpy(&dest->align_info, &stream->align_info, sizeof(dsp_align_info));
210  memcpy(dest->ROI, stream->ROI, sizeof(dsp_region) * stream->dims);
211  memcpy(dest->pixel_sizes, stream->pixel_sizes, sizeof(double) * stream->dims);
212  memcpy(dest->target, stream->target, sizeof(double) * 3);
213  if(dest->location != NULL)
214  memcpy(dest->location, stream->location, sizeof(dsp_location) * stream->len);
215  if(dest->buf != NULL)
216  memcpy(dest->buf, stream->buf, sizeof(dsp_t) * stream->len);
217  if(dest->dft.buf != NULL)
218  memcpy(dest->dft.buf, stream->dft.buf, sizeof(complex_t) * stream->len);
219  return dest;
220 }
221 
227 void dsp_stream_add_dim(dsp_stream_p stream, int size)
228 {
229  stream->sizes[stream->dims] = size;
230  stream->len *= size;
231  stream->dims ++;
232  stream->ROI = (dsp_region*)realloc(stream->ROI, sizeof(dsp_region) * (stream->dims + 1));
233  stream->sizes = (int*)realloc(stream->sizes, sizeof(int) * (stream->dims + 1));
234  stream->pixel_sizes = (double*)realloc(stream->pixel_sizes, sizeof(double) * (stream->dims + 1));
235  stream->align_info.dims = stream->dims;
236  stream->align_info.offset = (double*)realloc(stream->align_info.offset, sizeof(double)*stream->dims);
237  stream->align_info.center = (double*)realloc(stream->align_info.center, sizeof(double)*stream->dims);
238  stream->align_info.radians = (double*)realloc(stream->align_info.radians, sizeof(double)*(stream->dims-1));
239  stream->align_info.factor = (double*)realloc(stream->align_info.factor, sizeof(double)*stream->dims);
240  if(stream->magnitude != NULL)
241  dsp_stream_add_dim(stream->magnitude, size);
242  if(stream->phase != NULL)
243  dsp_stream_add_dim(stream->phase, size);
244 }
245 
252 void dsp_stream_set_dim(dsp_stream_p stream, int dim, int size)
253 {
254  int d = 0;
255  if(dim < stream->dims) {
256  stream->sizes[dim] = size;
257  stream->len = 1;
258  for(d = 0; d < stream->dims; d++)
259  stream->len *= stream->sizes[d];
260  if(stream->magnitude != NULL)
261  dsp_stream_set_dim(stream->magnitude, dim, size);
262  if(stream->phase != NULL)
263  dsp_stream_set_dim(stream->phase, dim, size);
264  }
265 }
266 
272 void dsp_stream_del_dim(dsp_stream_p stream, int index)
273 {
274  int* sizes = (int*)malloc(sizeof(int) * stream->dims);
275  int dims = stream->dims;
276  memcpy(sizes, stream->sizes, sizeof(int) * stream->dims);
277  free(stream->sizes);
278  stream->dims = 0;
279  int i;
280  for(i = 0; i < dims; i++) {
281  if(i != index) {
282  dsp_stream_add_dim(stream, abs(sizes[i]));
283  }
284  }
285  if(stream->magnitude != NULL)
286  dsp_stream_del_dim(stream->magnitude, index);
287  if(stream->phase != NULL)
288  dsp_stream_del_dim(stream->phase, index);
289 }
290 
297 {
298  child->parent = stream;
299  stream->children[stream->child_count] = child;
300  stream->child_count++;
301  stream->children = (dsp_stream_p*)realloc(stream->children, sizeof(dsp_stream_p) * (stream->child_count + 1));
302 }
303 
309 void dsp_stream_del_child(dsp_stream_p stream, int index)
310 {
311  dsp_stream_p* children = (dsp_stream_p*)malloc(sizeof(dsp_stream_p) * stream->child_count);
312  int child_count = stream->child_count;
313  memcpy(children, stream->children, sizeof(dsp_stream_p*) * stream->child_count);
314  free(stream->children);
315  stream->child_count = 0;
316  int i;
317  for(i = 0; i < child_count; i++) {
318  if(i != index) {
319  dsp_stream_add_child(stream, children[i]);
320  }
321  }
322 }
323 
330 {
331  int d;
332  stream->stars = (dsp_star*)realloc(stream->stars, sizeof(dsp_star)*(stream->stars_count+1));
333  strcpy(stream->stars[stream->stars_count].name, star.name);
334  stream->stars[stream->stars_count].diameter = star.diameter;
335  stream->stars[stream->stars_count].center.dims = star.center.dims;
336  stream->stars[stream->stars_count].center.location = (double*)malloc(sizeof(double)*star.center.dims);
337  for(d = 0; d < star.center.dims; d++)
338  stream->stars[stream->stars_count].center.location[d] = star.center.location[d];
339  stream->stars_count++;
340 }
341 
347 void dsp_stream_del_star(dsp_stream_p stream, int index)
348 {
349  dsp_star* stars = (dsp_star*)malloc(sizeof(dsp_star) * stream->stars_count);
350  int stars_count = stream->stars_count;
351  memcpy(stars, stream->stars, sizeof(dsp_star*) * stream->stars_count);
352  free(stream->stars);
353  stream->stars_count = 0;
354  int i;
355  for(i = 0; i < stars_count; i++) {
356  if(i != index) {
357  dsp_stream_add_star(stream, stars[i]);
358  }
359  }
360 }
361 
368 {
369  int s;
370  int d;
371  stream->triangles = (dsp_triangle*)realloc(stream->triangles, sizeof(dsp_triangle)*(stream->triangles_count+1));
372  stream->triangles[stream->triangles_count].dims = triangle.dims;
373  stream->triangles[stream->triangles_count].index = triangle.index;
374  stream->triangles[stream->triangles_count].theta = (double*)malloc(sizeof(double)*(stream->dims-1));
375  stream->triangles[stream->triangles_count].ratios = (double*)malloc(sizeof(double)*triangle.dims);
376  stream->triangles[stream->triangles_count].sizes = (double*)malloc(sizeof(double)*triangle.dims);
377  stream->triangles[stream->triangles_count].stars = (dsp_star*)malloc(sizeof(dsp_star)*triangle.dims);
378  for (s = 0; s < triangle.dims; s++) {
379  if(s < stream->dims - 1) {
380  stream->triangles[stream->triangles_count].theta[s] = triangle.theta[s];
381  }
382  stream->triangles[stream->triangles_count].sizes[s] = triangle.sizes[s];
383  stream->triangles[stream->triangles_count].ratios[s] = triangle.ratios[s];
384  stream->triangles[stream->triangles_count].stars[s].center.dims = triangle.stars[s].center.dims;
385  stream->triangles[stream->triangles_count].stars[s].diameter = triangle.stars[s].diameter;
386  stream->triangles[stream->triangles_count].stars[s].center.location = (double*)malloc(sizeof(double)*stream->dims);
387  for(d = 0; d < triangle.stars[s].center.dims; d++) {
388  stream->triangles[stream->triangles_count].stars[s].center.location[d] = triangle.stars[s].center.location[d];
389  }
390  }
391  stream->triangles_count++;
392 }
393 
399 void dsp_stream_del_triangle(dsp_stream_p stream, int index)
400 {
401  dsp_triangle* triangles = (dsp_triangle*)malloc(sizeof(dsp_triangle) * stream->triangles_count);
402  int triangles_count = stream->triangles_count;
403  memcpy(triangles, stream->triangles, sizeof(dsp_triangle*) * stream->triangles_count);
404  free(stream->triangles);
405  stream->triangles_count = 0;
406  int i;
407  for(i = 0; i < triangles_count; i++) {
408  if(i != index) {
409  dsp_stream_add_triangle(stream, triangles[i]);
410  }
411  }
412 }
413 
420 int* dsp_stream_get_position(dsp_stream_p stream, int index) {
421  int dim = 0;
422  int y = 0;
423  int m = 1;
424  int* pos = (int*)malloc(sizeof(int) * stream->dims);
425  for (dim = 0; dim < stream->dims; dim++) {
426  y = index / m;
427  y %= stream->sizes[dim];
428  m *= stream->sizes[dim];
429  pos[dim] = y;
430  }
431  return pos;
432 }
433 
440 int dsp_stream_set_position(dsp_stream_p stream, int* pos) {
441  int dim = 0;
442  int index = 0;
443  int m = 1;
444  for (dim = 0; dim < stream->dims; dim++) {
445  index += m * pos[dim];
446  m *= stream->sizes[dim];
447  }
448  return index;
449 }
450 
451 static void* dsp_stream_align_th(void* arg)
452 {
453  struct {
454  int cur_th;
455  dsp_stream_p stream;
456  } *arguments = arg;
457  dsp_stream_p stream = arguments->stream;
458  dsp_stream_p in = stream->parent;
459  int cur_th = arguments->cur_th;
460  int start = cur_th * stream->len / dsp_max_threads(0);
461  int end = start + stream->len / dsp_max_threads(0);
462  end = Min(stream->len, end);
463  int y;
464  for(y = start; y < end; y++)
465  {
466  int *pos = dsp_stream_get_position(stream, y);
467  int dim;
468  for (dim = 1; dim < stream->dims; dim++) {
469  pos[dim] -= stream->align_info.center[dim];
470  pos[dim-1] -= stream->align_info.center[dim-1];
471  pos[dim] += stream->align_info.offset[dim];
472  pos[dim-1] += stream->align_info.offset[dim-1];
473  double r1 = stream->align_info.radians[dim-1];
474  double x = pos[dim-1];
475  double y = pos[dim];
476  double h = pow(pow(x, 2)+pow(y, 2), 0.5);
477  double r2 = acos(x/h);
478  if(y < 0)
479  r2 = - r2;
480  pos[dim] = sin(r2-r1)*h;
481  pos[dim-1] = cos(r2-r1)*h;
482  pos[dim] /= stream->align_info.factor[dim];
483  pos[dim-1] /= stream->align_info.factor[dim-1];
484  pos[dim] += stream->align_info.center[dim];
485  pos[dim-1] += stream->align_info.center[dim-1];
486  }
487  int x = dsp_stream_set_position(in, pos);
488  free(pos);
489  if(x >= 0 && x < in->len)
490  stream->buf[y] = in->buf[x];
491  }
492  return NULL;
493 }
494 
496 {
497  dsp_stream_p stream = dsp_stream_copy(in);
498  dsp_buffer_set(stream->buf, stream->len, 0);
499  stream->parent = in;
500  size_t y;
501  pthread_t *th = (pthread_t*)malloc(sizeof(pthread_t)*dsp_max_threads(0));
502  struct {
503  int cur_th;
504  dsp_stream_p stream;
505  } thread_arguments[dsp_max_threads(0)];
506  for(y = 0; y < dsp_max_threads(0); y++) {
507  thread_arguments[y].cur_th = y;
508  thread_arguments[y].stream = stream;
509  pthread_create(&th[y], NULL, dsp_stream_align_th, &thread_arguments[y]);
510  }
511  for(y = 0; y < dsp_max_threads(0); y++)
512  pthread_join(th[y], NULL);
513  free(th);
514  dsp_buffer_copy(stream->buf, in->buf, stream->len);
515  dsp_stream_free_buffer(stream);
516  dsp_stream_free(stream);
517 }
518 
524 static void* dsp_stream_crop_th(void* arg)
525 {
526  struct {
527  int cur_th;
528  dsp_stream_p stream;
529  } *arguments = arg;
530  dsp_stream_p stream = arguments->stream;
531  dsp_stream_p in = stream->parent;
532  int cur_th = arguments->cur_th;
533  int start = cur_th * stream->len / dsp_max_threads(0);
534  int end = start + stream->len / dsp_max_threads(0);
535  end = Min(stream->len, end);
536  int y;
537  for(y = start; y < end; y++)
538  {
539  int *pos = dsp_stream_get_position(stream, y);
540  int dim;
541  int allow = 1;
542  for (dim = 0; dim < stream->dims; dim++) {
543  pos[dim] += in->ROI[dim].start;
544  if(pos[dim] < in->ROI[dim].start || pos[dim] > in->ROI[dim].start + in->ROI[dim].len || pos[dim] < 0 || pos[dim] >= in->sizes[dim])
545  allow &= 0;
546  }
547  if(allow) {
548  int x = dsp_stream_set_position(in, pos);
549  stream->buf[y] = in->buf[x];
550  }
551  else
552  stream->buf[y] = 0;
553  free(pos);
554  }
555  return NULL;
556 }
557 
559 {
560  dsp_stream_p stream = dsp_stream_copy(in);
561  dsp_buffer_set(stream->buf, stream->len, 0);
562  stream->parent = in;
563  size_t y;
564  pthread_t *th = (pthread_t*)malloc(sizeof(pthread_t)*dsp_max_threads(0));
565  struct {
566  int cur_th;
567  dsp_stream_p stream;
568  } thread_arguments[dsp_max_threads(0)];
569  for(y = 0; y < dsp_max_threads(0); y++) {
570  thread_arguments[y].cur_th = y;
571  thread_arguments[y].stream = stream;
572  pthread_create(&th[y], NULL, dsp_stream_crop_th, &thread_arguments[y]);
573  }
574  for(y = 0; y < dsp_max_threads(0); y++)
575  pthread_join(th[y], NULL);
576  free(th);
577  dsp_buffer_copy(stream->buf, in->buf, stream->len);
578  dsp_stream_free_buffer(stream);
579  dsp_stream_free(stream);
580 }
581 
583 {
584  dsp_stream_p stream = dsp_stream_copy(in);
585  int* offset = (int*)malloc(sizeof(int)*stream->dims);
586  dsp_buffer_copy(in->align_info.offset, offset, in->dims);
587  int z = dsp_stream_set_position(stream, offset);
588  free(offset);
589  int k = -z;
590  z = Max(0, z);
591  k = Max(0, k);
592  int len = stream->len-z-k;
593  dsp_t *buf = &stream->buf[z];
594  dsp_t *data = &in->buf[k];
595  memset(in->buf, 0, sizeof(dsp_t)*in->len);
596  memcpy(data, buf, sizeof(dsp_t)*len);
597  dsp_stream_free_buffer(stream);
598  dsp_stream_free(stream);
599 }
600 
606 static void* dsp_stream_scale_th(void* arg)
607 {
608  struct {
609  int cur_th;
610  dsp_stream_p stream;
611  } *arguments = arg;
612  dsp_stream_p stream = arguments->stream;
613  dsp_stream_p in = stream->parent;
614  int cur_th = arguments->cur_th;
615  int start = cur_th * stream->len / dsp_max_threads(0);
616  int end = start + stream->len / dsp_max_threads(0);
617  end = Min(stream->len, end);
618  int y, d;
619  for(y = start; y < end; y++)
620  {
621  int* pos = dsp_stream_get_position(stream, y);
622  double factor = 0.0;
623  for(d = 0; d < stream->dims; d++) {
624  pos[d] -= stream->align_info.center[d];
625  pos[d] /= stream->align_info.factor[d];
626  pos[d] += stream->align_info.center[d];
627  factor += pow(stream->align_info.factor[d], 2);
628  }
629  factor = sqrt(factor);
630  int x = dsp_stream_set_position(in, pos);
631  if(x >= 0 && x < in->len)
632  stream->buf[y] += in->buf[x]/(factor*stream->dims);
633  free(pos);
634  }
635  return NULL;
636 }
637 
639 {
640  dsp_stream_p stream = dsp_stream_copy(in);
641  dsp_buffer_set(stream->buf, stream->len, 0);
642  stream->parent = in;
643  size_t y;
644  pthread_t *th = (pthread_t*)malloc(sizeof(pthread_t)*dsp_max_threads(0));
645  struct {
646  int cur_th;
647  dsp_stream_p stream;
648  } thread_arguments[dsp_max_threads(0)];
649  for(y = 0; y < dsp_max_threads(0); y++) {
650  thread_arguments[y].cur_th = y;
651  thread_arguments[y].stream = stream;
652  pthread_create(&th[y], NULL, dsp_stream_scale_th, &thread_arguments[y]);
653  }
654  for(y = 0; y < dsp_max_threads(0); y++)
655  pthread_join(th[y], NULL);
656  free(th);
657  dsp_buffer_copy(stream->buf, in->buf, stream->len);
658  dsp_stream_free_buffer(stream);
659  dsp_stream_free(stream);
660 }
661 
662 static void* dsp_stream_rotate_th(void* arg)
663 {
664  struct {
665  int cur_th;
666  dsp_stream_p stream;
667  } *arguments = arg;
668  dsp_stream_p stream = arguments->stream;
669  dsp_stream_p in = stream->parent;
670  int cur_th = arguments->cur_th;
671  int start = cur_th * stream->len / dsp_max_threads(0);
672  int end = start + stream->len / dsp_max_threads(0);
673  end = Min(stream->len, end);
674  int y;
675  for(y = start; y < end; y++)
676  {
677  int *pos = dsp_stream_get_position(stream, y);
678  int dim;
679  for (dim = 1; dim < stream->dims; dim++) {
680  pos[dim] -= stream->align_info.center[dim];
681  pos[dim-1] -= stream->align_info.center[dim-1];
682  double r = stream->align_info.radians[dim-1];
683  double x = pos[dim-1];
684  double y = pos[dim];
685  pos[dim] = x*-sin(r);
686  pos[dim-1] = x*cos(r);
687  pos[dim] += y*cos(r);
688  pos[dim-1] += y*sin(r);
689  pos[dim] += stream->align_info.center[dim];
690  pos[dim-1] += stream->align_info.center[dim-1];
691  }
692  int x = dsp_stream_set_position(in, pos);
693  free(pos);
694  if(x >= 0 && x < in->len)
695  stream->buf[y] = in->buf[x];
696  }
697  return NULL;
698 }
699 
701 {
702  dsp_stream_p stream = dsp_stream_copy(in);
703  dsp_buffer_set(stream->buf, stream->len, 0);
704  stream->parent = in;
705  size_t y;
706  pthread_t *th = (pthread_t*)malloc(sizeof(pthread_t)*dsp_max_threads(0));
707  struct {
708  int cur_th;
709  dsp_stream_p stream;
710  } thread_arguments[dsp_max_threads(0)];
711  for(y = 0; y < dsp_max_threads(0); y++) {
712  thread_arguments[y].cur_th = y;
713  thread_arguments[y].stream = stream;
714  pthread_create(&th[y], NULL, dsp_stream_rotate_th, &thread_arguments[y]);
715  }
716  for(y = 0; y < dsp_max_threads(0); y++)
717  pthread_join(th[y], NULL);
718  free(th);
719  dsp_buffer_copy(stream->buf, in->buf, stream->len);
720  dsp_stream_free_buffer(stream);
721  dsp_stream_free(stream);
722 }
std::thread th
int dsp_get_debug_level()
get the debug level
Definition: stream.c:68
void dsp_set_stderr(FILE *f)
set the error log streeam
Definition: stream.c:45
#define Max(a, b)
if max() is not present you can use this one
Definition: dsp.h:179
unsigned long int dsp_max_threads(unsigned long value)
get/set the maximum number of threads allowed
Definition: stream.c:31
double dsp_t
Definition: dsp.h:69
#define DSP_DEBUG_INFO
Definition: dsp.h:121
double complex_t[2]
Definition: dsp.h:70
void dsp_set_debug_level(int value)
set the debug level
Definition: stream.c:58
#define Min(a, b)
if min() is not present you can use this one
Definition: dsp.h:172
void dsp_set_stdout(FILE *f)
set the output log streeam
Definition: stream.c:40
void dsp_print(int x, char *str)
log a message to the error or output streams
Definition: stream.c:50
char * dsp_get_app_name()
get the application name
Definition: stream.c:73
void dsp_set_app_name(char *name)
set the application name
Definition: stream.c:63
struct dsp_stream_t * dsp_stream_p
struct dsp_stream_t * phase
Fourier transform phase.
Definition: dsp.h:413
double samplerate
Sample rate of the buffers.
Definition: dsp.h:405
double * pixel_sizes
Sensor size.
Definition: dsp.h:403
dsp_point center
The center of the star.
Definition: dsp.h:240
int frame_number
Frame number (if part of a series)
Definition: dsp.h:427
int triangles_count
Triangles of stars or objects quantity.
Definition: dsp.h:423
int dims
Dimensions limit.
Definition: dsp.h:280
double * factor
Scaling factor.
Definition: dsp.h:278
double wavelength
Wavelength observed, used as reference with signal generators or filters.
Definition: dsp.h:393
double focal_ratio
Focal ratio.
Definition: dsp.h:395
int start
Starting point within the buffer.
Definition: dsp.h:319
double * center
Center of rotation coordinates.
Definition: dsp.h:274
struct dsp_stream_t * parent
The parent stream.
Definition: dsp.h:381
int * sizes
Sizes of each dimension.
Definition: dsp.h:373
double * location
Center of the point.
Definition: dsp.h:218
dsp_complex dft
Fourier transform.
Definition: dsp.h:377
int red
Red pixel (Bayer)
Definition: dsp.h:401
double * radians
Rotational offset.
Definition: dsp.h:276
double index
The index of the triangle.
Definition: dsp.h:253
dsp_star * stars
Stars or objects identified into the buffers - TODO.
Definition: dsp.h:417
struct timespec starttimeutc
Time at the beginning of the stream.
Definition: dsp.h:391
dsp_star * stars
The stars of the triangle.
Definition: dsp.h:263
double * sizes
The sizes of the triangle.
Definition: dsp.h:259
double * buf
Linear double array containing complex numbers.
Definition: dsp.h:310
double * target
Target coordinates.
Definition: dsp.h:389
int stars_count
Stars or objects quantity.
Definition: dsp.h:419
struct dsp_stream_t * magnitude
Fourier transform magnitude.
Definition: dsp.h:411
double diameter
The diameter of the star.
Definition: dsp.h:242
int dims
The dimensions of the triangle.
Definition: dsp.h:255
double * theta
The inclination of the triangle.
Definition: dsp.h:257
double diameter
Diameter.
Definition: dsp.h:397
dsp_align_info align_info
Align/scale/rotation settings.
Definition: dsp.h:425
dsp_triangle * triangles
Triangles of stars or objects.
Definition: dsp.h:421
char name[150]
The name of the star.
Definition: dsp.h:244
int dims
Number of dimensions of the buffers.
Definition: dsp.h:371
dsp_location * location
Location coordinates pointer, can be extended to the main buffer size as location companion.
Definition: dsp.h:387
struct dsp_stream_t ** children
Children streams.
Definition: dsp.h:383
dsp_t * buf
buffer
Definition: dsp.h:375
int len
Length of the region.
Definition: dsp.h:321
int dims
Dimensions limit of the point.
Definition: dsp.h:220
int child_count
Children streams count.
Definition: dsp.h:385
int is_copy
Increments by one on the copied stream.
Definition: dsp.h:367
double * ratios
The sizes of the triangle.
Definition: dsp.h:261
dsp_region * ROI
Regions of interest for each dimension.
Definition: dsp.h:415
int len
The buffers length.
Definition: dsp.h:369
double * offset
Translation offset.
Definition: dsp.h:272
#define dsp_buffer_copy(in, out, len)
Fill the output buffer with the values of the elements of the input stream by casting them to the out...
Definition: dsp.h:1038
#define dsp_buffer_set(buf, len, _val)
Fill the buffer with the passed value.
Definition: dsp.h:815
void dsp_stream_free(dsp_stream_p stream)
dsp_stream_free
Definition: stream.c:163
void dsp_stream_scale(dsp_stream_p in)
Scale a stream.
Definition: stream.c:638
void dsp_stream_set_dim(dsp_stream_p stream, int dim, int size)
dsp_stream_set_dim
Definition: stream.c:252
void dsp_stream_rotate(dsp_stream_p in)
Rotate a stream around an axis and offset.
Definition: stream.c:700
void dsp_stream_del_triangle(dsp_stream_p stream, int index)
dsp_stream_del_triangle
Definition: stream.c:399
int dsp_stream_set_position(dsp_stream_p stream, int *pos)
dsp_stream_set_position
Definition: stream.c:440
int * dsp_stream_get_position(dsp_stream_p stream, int index)
dsp_stream_get_position
Definition: stream.c:420
dsp_stream_p dsp_stream_copy(dsp_stream_p stream)
dsp_stream_copy
Definition: stream.c:192
void dsp_stream_add_triangle(dsp_stream_p stream, dsp_triangle triangle)
dsp_stream_add_triangle
Definition: stream.c:367
void dsp_stream_add_child(dsp_stream_p stream, dsp_stream_p child)
dsp_stream_add_child
Definition: stream.c:296
void dsp_stream_del_dim(dsp_stream_p stream, int index)
dsp_stream_del_dim
Definition: stream.c:272
dsp_t * dsp_stream_get_buffer(dsp_stream_p stream)
Return the buffer of the stream passed as argument.
Definition: stream.c:107
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.
Definition: stream.c:101
void dsp_stream_del_child(dsp_stream_p stream, int index)
dsp_stream_del_child
Definition: stream.c:309
dsp_stream_p dsp_stream_new()
dsp_stream_new
Definition: stream.c:124
void dsp_stream_add_dim(dsp_stream_p stream, int size)
dsp_stream_add_dim
Definition: stream.c:227
void dsp_stream_alloc_buffer(dsp_stream_p stream, int len)
Allocate a buffer with length len on the stream passed as argument.
Definition: stream.c:78
void dsp_stream_crop(dsp_stream_p in)
Crop the buffers of the stream passed as argument by reading the ROI field.
Definition: stream.c:558
void dsp_stream_translate(dsp_stream_p in)
Translate a stream.
Definition: stream.c:582
void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
Definition: stream.c:112
void dsp_stream_del_star(dsp_stream_p stream, int index)
dsp_stream_del_star
Definition: stream.c:347
void dsp_stream_add_star(dsp_stream_p stream, dsp_star star)
dsp_stream_add_star
Definition: stream.c:329
void dsp_stream_align(dsp_stream_p in)
Perform scale, translate and rotate transformations in-place.
Definition: stream.c:495
std::vector< uint8_t > buffer
Alignment informations needed.
Definition: dsp.h:270
Delimits a region in a single dimension of a buffer.
Definition: dsp.h:317
A star or object contained into a buffer.
Definition: dsp.h:238
Contains a set of informations and data relative to a buffer and how to use it.
Definition: dsp.h:363
A star or object contained into a buffer.
Definition: dsp.h:251
The location type.
Definition: dsp.h:328