1 /*
2 * FITS implementation of common functions
3 * Copyright (c) 2017 Paras Chadha
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <inttypes.h>
24 #include <stdio.h>
25 #include <string.h>
30
32 {
40 header->image_extension = 0;
43 header->data_min_found = 0;
44 header->data_max_found = 0;
45 return 0;
46 }
47
49 {
50 if (metadata)
52 return 0;
53 }
54
55 /**
56 * Extract keyword and value from a header line (80 bytes) and store them in keyword and value strings respectively
57 * @param ptr8 pointer to the data
58 * @param keyword pointer to the char array in which keyword is to be stored
59 * @param value pointer to the char array in which value is to be stored
60 * @return 0 if calculated successfully otherwise AVERROR_INVALIDDATA
61 */
63 {
65
66 for (
i = 0;
i < 8 && ptr8[
i] !=
' ';
i++) {
68 }
70
71 if (ptr8[8] == '=') {
73 while (
i < 80 && ptr8[
i] ==
' ') {
75 }
76
80 if (ptr8[
i-1] ==
'\'') {
81 for (;
i < 80 && ptr8[
i] !=
'\'';
i++) {
83 }
85 }
else if (ptr8[
i-1] ==
'(') {
86 for (;
i < 80 && ptr8[
i] !=
')';
i++) {
88 }
90 } else {
91 for (;
i < 80 && ptr8[
i] !=
' ' && ptr8[
i] !=
'/';
i++) {
93 }
94 }
95 }
96 }
98 return 0;
99 }
100
101 #define CHECK_KEYWORD(key) \
102 if (strcmp(keyword, key)) { \
103 av_log(avcl, AV_LOG_ERROR, "expected %s keyword, found %s = %s\n", key, keyword, value); \
104 return AVERROR_INVALIDDATA; \
105 }
106
107 #define CHECK_VALUE(key, val) \
108 if (sscanf(value, "%d", &header->val) != 1) { \
109 av_log(avcl, AV_LOG_ERROR, "invalid value of %s keyword, %s = %s\n", key, keyword, value); \
110 return AVERROR_INVALIDDATA; \
111 }
112
114 {
116 int64_t t;
118 char keyword[10],
value[72],
c;
119
124
125 if (
value[0] ==
'F') {
127 }
else if (
value[0] !=
'T') {
130 }
131
133 break;
136
137 if (!strcmp(
value,
"'IMAGE '")) {
138 header->image_extension = 1;
139 }
140
142 break;
146
148 case 8:
149 case 16:
150 case 32: case -32:
151 case 64: case -64: break;
152 default:
155 }
156
158
160 break;
165
168 } else {
170 }
171 break;
173 ret = sscanf(keyword,
"NAXIS%d", &dim_no);
174 if (
ret != 1 || dim_no !=
header->naxis_index + 1) {
177 }
178
182 }
183
188 }
189 break;
191 if (!strcmp(keyword,
"BLANK") && sscanf(
value,
"%"SCNd64
"", &t) == 1) {
194 }
else if (!strcmp(keyword,
"BSCALE") && sscanf(
value,
"%lf", &
d) == 1) {
198 }
else if (!strcmp(keyword,
"BZERO") && sscanf(
value,
"%lf", &
d) == 1) {
200 }
else if (!strcmp(keyword,
"CTYPE3") && !strncmp(
value,
"'RGB", 4)) {
202 }
else if (!strcmp(keyword,
"DATAMAX") && sscanf(
value,
"%lf", &
d) == 1) {
203 header->data_max_found = 1;
205 }
else if (!strcmp(keyword,
"DATAMIN") && sscanf(
value,
"%lf", &
d) == 1) {
206 header->data_min_found = 1;
208 } else if (!strcmp(keyword, "END")) {
209 return 1;
210 }
else if (!strcmp(keyword,
"GROUPS") && sscanf(
value,
"%c", &
c) == 1) {
212 }
else if (!strcmp(keyword,
"GCOUNT") && sscanf(
value,
"%"SCNd64
"", &t) == 1) {
213 if (t < 0 || t > INT_MAX)
216 }
else if (!strcmp(keyword,
"PCOUNT") && sscanf(
value,
"%"SCNd64
"", &t) == 1) {
217 if (t < 0 || t > INT_MAX)
220 }
222 break;
223 }
224 return 0;
225 }