int i, j;
header->data_min = DBL_MAX;
- header->data_max = DBL_MIN;
+ header->data_max = -DBL_MAX;
switch (header->bitpix) {
#define CASE_N(a, t, rd) \
case a: \
size = abs(header->bitpix) >> 3;
for (i = 0; i < header->naxis; i++) {
- if (header->naxisn[i] > SIZE_MAX / size) {
+ if (size == 0 || header->naxisn[i] > SIZE_MAX / size) {
av_log(avctx, AV_LOG_ERROR, "unsupported size of FITS image");
return AVERROR_INVALIDDATA;
}
header->data_min = (header->data_min - header->bzero) / header->bscale;
header->data_max = (header->data_max - header->bzero) / header->bscale;
}
+ if (!header->rgb && header->data_min >= header->data_max) {
+ if (header->data_min > header->data_max) {
+ av_log(avctx, AV_LOG_ERROR, "data min/max (%g %g) is invalid\n", header->data_min, header->data_max);
+ return AVERROR_INVALIDDATA;
+ }
+ av_log(avctx, AV_LOG_WARNING, "data min/max indicates a blank image\n");
+ header->data_max ++;
+ }
return 0;
}
CASE_RGB(16, dst16, uint16_t, AV_RB16);
}
} else {
+ double scale = header.data_max - header.data_min;
+
+ if (scale <= 0 || !isfinite(scale)) {
+ scale = 1;
+ }
+ scale = 1/scale;
+
switch (header.bitpix) {
#define CASE_GRAY(cas, dst, type, t, rd) \
case cas: \
for (j = 0; j < avctx->width; j++) { \
t = rd; \
if (!header.blank_found || t != header.blank) { \
- *dst++ = ((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) / (header.data_max - header.data_min); \
+ *dst++ = lrint(((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) * scale); \
} else { \
*dst++ = fitsctx->blank_val; \
} \
.version = LIBAVUTIL_VERSION_INT,
};
-AVCodec ff_fits_decoder = {
+const AVCodec ff_fits_decoder = {
.name = "fits",
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_FITS,