X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Ffitsdec.c;h=802aa5b509b648e58c34b66bcef794f4ae754b78;hb=e448a4b4ea535aa2ec06f0aee167820df794a299;hp=88b841a964453fd7ed5988becc7c3edbae1643ac;hpb=cfa193779103c97bbfc28273a0ab12c114b6786d;p=ffmpeg diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c index 88b841a9644..802aa5b509b 100644 --- a/libavcodec/fitsdec.c +++ b/libavcodec/fitsdec.c @@ -63,7 +63,7 @@ static int fill_data_min_max(const uint8_t *ptr8, FITSHeader *header, const uint 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: \ @@ -143,7 +143,7 @@ static int fits_read_header(AVCodecContext *avctx, const uint8_t **ptr, FITSHead size = abs(header->bitpix) >> 3; for (i = 0; i < header->naxis; i++) { - if (size && 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; } @@ -195,7 +195,6 @@ static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, uint8_t *dst8; uint16_t *dst16; uint64_t t; - double scale; FITSHeader header; FITSContext * fitsctx = avctx->priv_data; @@ -205,12 +204,6 @@ static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (ret < 0) return ret; - scale = header.data_max - header.data_min; - if (scale <= 0 || !isfinite(scale)) { - scale = 1; - } - scale = 1/scale; - if (header.rgb) { if (header.bitpix == 8) { if (header.naxisn[2] == 3) { @@ -271,6 +264,13 @@ static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, 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: \ @@ -279,7 +279,7 @@ static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, 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)) * scale; \ + *dst++ = lrint(((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) * scale); \ } else { \ *dst++ = fitsctx->blank_val; \ } \