summaryrefslogtreecommitdiff
path: root/libavformat/fitsenc.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2021-02-08 18:46:36 +0100
committerPaul B Mahol <onemda@gmail.com>2021-02-10 00:03:38 +0100
commite0fd35d867752e6fcc7329a7d4f5e5fc619f2634 (patch)
tree24218f69b5edf9fa8d86d2c44b5f16194ba29a9f /libavformat/fitsenc.c
parent4aef642cfdd0cb9a351709a5f57fd48a4d587c9f (diff)
downloadffmpeg-e0fd35d867752e6fcc7329a7d4f5e5fc619f2634.tar.gz
avformat/fitsenc: write DATAMIN/DATAMAX to encoded output
There is no point in doing normalization when such files are decoded. Update fate test with new results.
Diffstat (limited to 'libavformat/fitsenc.c')
-rw-r--r--libavformat/fitsenc.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/libavformat/fitsenc.c b/libavformat/fitsenc.c
index cc3999aa8a..212c769df1 100644
--- a/libavformat/fitsenc.c
+++ b/libavformat/fitsenc.c
@@ -45,7 +45,8 @@ static int fits_write_header(AVFormatContext *s)
* @param lines_written to keep track of lines written so far
* @return 0
*/
-static int write_keyword_value(AVFormatContext *s, const char *keyword, int value, int *lines_written)
+static int write_keyword_value(AVFormatContext *s, const char *fmt,
+ const char *keyword, void *value, int *lines_written)
{
int len, ret;
uint8_t header[80];
@@ -57,7 +58,12 @@ static int write_keyword_value(AVFormatContext *s, const char *keyword, int valu
header[8] = '=';
header[9] = ' ';
- ret = snprintf(header + 10, 70, "%d", value);
+ if (!strcmp(fmt, "%d")) {
+ ret = snprintf(header + 10, 70, fmt, *(int *)value);
+ } else {
+ ret = snprintf(header + 10, 70, fmt, *(float *)value);
+ }
+
memset(&header[ret + 10], ' ', sizeof(header) - (ret + 10));
avio_write(s->pb, header, sizeof(header));
@@ -72,16 +78,22 @@ static int write_image_header(AVFormatContext *s)
FITSContext *fitsctx = s->priv_data;
uint8_t buffer[80];
int bitpix, naxis, naxis3 = 1, bzero = 0, rgb = 0, lines_written = 0, lines_left;
+ int pcount = 0, gcount = 1;
+ float datamax, datamin;
switch (encctx->format) {
case AV_PIX_FMT_GRAY8:
bitpix = 8;
naxis = 2;
+ datamin = 0;
+ datamax = 255;
break;
case AV_PIX_FMT_GRAY16BE:
bitpix = 16;
naxis = 2;
bzero = 32768;
+ datamin = 0;
+ datamax = 65535;
break;
case AV_PIX_FMT_GBRP:
case AV_PIX_FMT_GBRAP:
@@ -93,6 +105,8 @@ static int write_image_header(AVFormatContext *s)
} else {
naxis3 = 4;
}
+ datamin = 0;
+ datamax = 255;
break;
case AV_PIX_FMT_GBRP16BE:
case AV_PIX_FMT_GBRAP16BE:
@@ -105,6 +119,8 @@ static int write_image_header(AVFormatContext *s)
naxis3 = 4;
}
bzero = 32768;
+ datamin = 0;
+ datamax = 65535;
break;
default:
return AVERROR(EINVAL);
@@ -122,28 +138,31 @@ static int write_image_header(AVFormatContext *s)
}
lines_written++;
- write_keyword_value(s, "BITPIX", bitpix, &lines_written); // no of bits per pixel
- write_keyword_value(s, "NAXIS", naxis, &lines_written); // no of dimensions of image
- write_keyword_value(s, "NAXIS1", encctx->width, &lines_written); // first dimension i.e. width
- write_keyword_value(s, "NAXIS2", encctx->height, &lines_written); // second dimension i.e. height
+ write_keyword_value(s, "%d", "BITPIX", &bitpix, &lines_written); // no of bits per pixel
+ write_keyword_value(s, "%d", "NAXIS", &naxis, &lines_written); // no of dimensions of image
+ write_keyword_value(s, "%d", "NAXIS1", &encctx->width, &lines_written); // first dimension i.e. width
+ write_keyword_value(s, "%d", "NAXIS2", &encctx->height, &lines_written); // second dimension i.e. height
if (rgb)
- write_keyword_value(s, "NAXIS3", naxis3, &lines_written); // third dimension to store RGBA planes
+ write_keyword_value(s, "%d", "NAXIS3", &naxis3, &lines_written); // third dimension to store RGBA planes
if (!fitsctx->first_image) {
- write_keyword_value(s, "PCOUNT", 0, &lines_written);
- write_keyword_value(s, "GCOUNT", 1, &lines_written);
+ write_keyword_value(s, "%d", "PCOUNT", &pcount, &lines_written);
+ write_keyword_value(s, "%d", "GCOUNT", &gcount, &lines_written);
} else {
fitsctx->first_image = 0;
}
+ write_keyword_value(s, "%g", "DATAMIN", &datamin, &lines_written);
+ write_keyword_value(s, "%g", "DATAMAX", &datamax, &lines_written);
+
/*
* Since FITS does not support unsigned 16 bit integers,
* BZERO = 32768 is used to store unsigned 16 bit integers as
* signed integers so that it can be read properly.
*/
if (bitpix == 16)
- write_keyword_value(s, "BZERO", bzero, &lines_written);
+ write_keyword_value(s, "%d", "BZERO", &bzero, &lines_written);
if (rgb) {
memcpy(buffer, "CTYPE3 = 'RGB '", 20);