add darks processing

This commit is contained in:
eddyem 2017-03-22 10:23:53 +03:00
parent f08fe7fc31
commit b7654b2569
7 changed files with 45 additions and 11 deletions

View File

@ -57,6 +57,8 @@ glob_pars const Gdefault = {
.port = "4444",
.once = 0,
.timestamp = 0,
.dark_interval = 1800,
.min_dark_exp = 30,
};
/*
@ -99,6 +101,8 @@ myoption cmdlnopts[] = {
{"timestamp",NO_ARGS, NULL, 't', arg_int, APTR(&G.timestamp), _("add timestamp to filename")},
#endif
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("port to connect (default: 4444)")},
{"dark-interval",NEED_ARG,NULL, 'D', arg_double, APTR(&G.dark_interval),_("time interval (in seconds) between dark images taken (default: 1800)")},
{"min-dark-exp",NEED_ARG,NULL, 'E', arg_double, APTR(&G.min_dark_exp),_("minimal exposition (in seconds) at which darks would be taken (default: 30)")},
#endif
end_option
};

View File

@ -50,6 +50,8 @@ typedef struct{
char *imformat; // output file format
char *hostname; // hostname to connect
char *port; // port to connect
double dark_interval; // time interval (in seconds) between dark images taken
double min_dark_exp; // minimal exposition (in seconds) @ which darks would be taken
char** rest_pars; // the rest parameters: array of char*
} glob_pars;

View File

@ -52,7 +52,8 @@ static int write_jpeg(const char *fname, const uint8_t *data, imstorage *img){
char date[256];
strftime(date, 256, "%d/%m/%y\n%H:%M:%S", localtime(&img->exposetime));
gdFTUseFontConfig(1);
char *ret = gdImageStringFT(im, NULL, 0xffffff, "monotype", 10, 0., 2, 12, date);
char *font = (char*)"monotype";
char *ret = gdImageStringFT(im, NULL, 0xffffff, font, 10, 0., 2, 12, date);
if(ret) fprintf(stderr, "Error: %s\n", ret);
const char *prefx = "";
double ex = img->exptime;
@ -66,7 +67,7 @@ static int write_jpeg(const char *fname, const uint8_t *data, imstorage *img){
}
}
snprintf(date, 256, "exp=%.3g %ss", ex, prefx);
gdImageStringFT(im, NULL, 0xffffff, "monotype", 10, 0., 2, img->H-4, date);
gdImageStringFT(im, NULL, 0xffffff, font, 10, 0., 2, img->H-4, date);
im->tpixels[10][10] = 0XFF0000;
im->tpixels[15][15] = 0XFF0000;
gdImageJpeg(im, fp, 90);

View File

@ -297,7 +297,7 @@ int writefits(imstorage *img){
WRITEKEY(TSTRING, "FIELD", "180 degrees", "Camera field of view");
switch(img->imtype){
case IMTYPE_AUTODARK:
sprintf(buf, "object without dark");
sprintf(buf, "obj.-dark");
break;
case IMTYPE_DARK:
sprintf(buf, "dark");
@ -345,7 +345,13 @@ int writefits(imstorage *img){
snprintf(buf, 80, "(%d, %d)", img->subframe->Xstart, img->subframe->Ystart);
WRITEKEY(TSTRING, "SUBFRAME", buf, "Subframe start coordinates (Xstart, Ystart)");
}
TRYFITS(fits_write_img, fp, TUSHORT, 1, img->W * img->H, img->imdata);
// flip image around OX
size_t W = img->W, Wb = sizeof(uint16_t)*W, H = img->H, imsz = img->W * H, y;
uint16_t *image = MALLOC(uint16_t, imsz), *optr = image, *iptr = &img->imdata[W*(H-1)];
for(y = 0; y < H; ++y, optr += W, iptr -= W)
memcpy(optr, iptr, Wb);
TRYFITS(fits_write_img, fp, TUSHORT, 1, imsz, image);
FREE(image);
TRYFITS(fits_close_file, fp);
if(*filename == '!') ++filename; // remove '!' from filename
modifytimestamp(filename, img);
@ -483,6 +489,7 @@ int store_image(imstorage *img){
if(img->imformat & FORMAT_FITS){ // save FITS
if(writefits(img)) status |= 4;
}
if(img->imtype != IMTYPE_DARK) // store debayer only if image type isn't dark
if(write_debayer(img, glob_min)) status |= 8; // and save colour image
return status;
}

3
main.c
View File

@ -120,6 +120,9 @@ int main(int argc, char **argv){
img->timestamp = G->timestamp;
#endif
#if defined CLIENT || defined DAEMON
#ifdef DAEMON
set_darks(G->min_dark_exp, G->dark_interval);
#endif
daemonize(img, G->hostname, G->port);
#endif
if(img){

View File

@ -24,8 +24,6 @@
#include "usefull_macros.h"
#include "socket.h"
#include "term.h"
//#include <sys/socket.h>
//#include <netinet/in.h>
#include <netdb.h> // addrinfo
#include <arpa/inet.h> // inet_ntop
#include <pthread.h>
@ -106,9 +104,15 @@ static int getdpar(uint8_t *str, char *parameter, double *ret){
/**************** CLIENT/SERVER FUNCTIONS ****************/
#ifdef DAEMON
static double min_dark_exp, dark_interval;
static imstorage *storedima = NULL;
static uint64_t imctr = 0; // image counter
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
// setter for min_dark_exp, dark_interval
void set_darks(double exp, double dt){
min_dark_exp = exp;
dark_interval = dt;
}
static void clearimstorage(){
if(!storedima) return;
FREE(storedima->imname);
@ -296,6 +300,7 @@ static void daemon_(imstorage *img, int sock){
FNAME();
if(sock < 0) return;
pthread_t sock_thread;
static double lastDT = 0.; // last time dark was taken
if(pthread_create(&sock_thread, NULL, server, (void*) &sock))
ERR("pthread_create()");
int errcntr = 0;
@ -307,6 +312,15 @@ static void daemon_(imstorage *img, int sock){
ERR("pthread_create()");
}
if(exp_calculated > 0.) img->exptime = exp_calculated;
if(img->imtype != IMTYPE_AUTODARK){ // check for darks
if(img->imtype == IMTYPE_DARK) img->imtype = IMTYPE_LIGHT; // last was dark
else if(img->exptime > min_dark_exp){ // need to store dark frame?
if(dtime() - lastDT > dark_interval){
lastDT = dtime();
img->imtype = IMTYPE_DARK;
}
}
}
if(start_exposition(img, NULL)){
WARNX(_("Error starting exposition, try later"));
++errcntr;

View File

@ -27,5 +27,8 @@
#include "imfunctions.h"
void daemonize(imstorage *img, char *hostname, char *port);
#ifdef DAEMON
void set_darks(double exp, double dt);
#endif
#endif // __SOCKET_H__