-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoutput_range.c
More file actions
125 lines (115 loc) · 3.08 KB
/
Copy pathoutput_range.c
File metadata and controls
125 lines (115 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*-
*
* JSON range output functions
*
* Author: Rick White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <errno.h>
#include "getopt.h"
#include <signal.h>
#include <ctype.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#else /* Not STDC_HEADERS */
extern void exit ();
extern char *malloc ();
#endif /* STDC_HEADERS */
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include "fitscut.h"
#include "output_range.h"
#include "revision.h"
/*
* Write image pixel value ranges in JSON format
*
* The format is a dictionary with a list of values:
*
* {'min': [0.0, 0.0, 0.0], 'max': [0.0, 0.0, 0.0]}
*
* The (up to) 3 values are for the red, green, blue bands.
*/
int write_range(FitsCutImage *Image)
{
FILE *outfile;
long k;
double *datamin, *datamax;
if (to_stdout) {
outfile = stdout;
} else {
outfile = fopen(Image->output_filename, "w");
}
if (!outfile) return ERROR;
switch (Image->output_scale_mode) {
case SCALE_MODE_AUTO:
case SCALE_MODE_FULL:
datamin = Image->autoscale_min;
datamax = Image->autoscale_max;
/* check for user overrides */
if (Image->user_min_set == 1) {
fitscut_message (1, "user min takes precedent over auto scale min\n");
datamin = Image->user_min;
}
if (Image->user_max_set == 1) {
fitscut_message (1, "user max takes precedent over auto scale max\n");
datamax = Image->user_max;
}
break;
case SCALE_MODE_USER:
if (Image->user_min_set == 1)
datamin = Image->user_min;
else
datamin = Image->data_min;
if (Image->user_max_set == 1)
datamax = Image->user_max;
else
datamax = Image->data_max;
break;
case SCALE_MODE_MINMAX:
default:
datamin = Image->data_min;
datamax = Image->data_max;
break;
}
fprintf(outfile, "{ 'min': [");
for (k=0; k<Image->channels; k++) {
if (Image->data[k] != NULL) {
if (k > 0) fprintf(outfile, ", ");
fprintf(outfile, "%.17e", datamin[k]);
}
}
fprintf(outfile, "], 'max': [");
for (k=0; k<Image->channels; k++) {
if (Image->data[k] != NULL) {
if (k > 0) fprintf(outfile, ", ");
fprintf(outfile, "%.17e", datamax[k]);
}
}
fprintf(outfile, "]}\n");
fflush(stdout);
return OK;
}