]> git.sesse.net Git - ffmpeg/commitdiff
avformat/fitsenc: write DATAMIN/DATAMAX to encoded output
authorPaul B Mahol <onemda@gmail.com>
Mon, 8 Feb 2021 17:46:36 +0000 (18:46 +0100)
committerPaul B Mahol <onemda@gmail.com>
Tue, 9 Feb 2021 23:03:38 +0000 (00:03 +0100)
There is no point in doing normalization when such files are decoded.

Update fate test with new results.

libavformat/fitsenc.c
tests/ref/fate/fits-demux
tests/ref/fate/fitsdec-gray
tests/ref/lavf/gbrap.fits
tests/ref/lavf/gbrap16be.fits
tests/ref/lavf/gbrp.fits
tests/ref/lavf/gbrp16be.fits
tests/ref/lavf/gray.fits
tests/ref/lavf/gray16be.fits

index cc3999aa8a0c7144e5b239166238d832443e7741..212c769df1cd93d6cfd28b29d02d64ba121ac60d 100644 (file)
@@ -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);
index 85605ab11aea858da18d7278ee76b0e474287422..de7aa11d5d1f3904d3598cceac9e7b34f54cf264 100644 (file)
@@ -3,8 +3,8 @@
 #codec_id 0: fits
 #dimensions 0: 72x36
 #sar 0: 0/1
-0,          0,          0,        1,    14320, 0x0ecf72e0
-0,          1,          1,        1,    14320, 0xd94af6eb
-0,          2,          2,        1,    14320, 0x15c21892
-0,          3,          3,        1,    14320, 0xb18adc01
-0,          4,          4,        1,    14320, 0xc2be706d
+0,          0,          0,        1,    14320, 0xa9ee75a4
+0,          1,          1,        1,    14320, 0xb9daf9af
+0,          2,          2,        1,    14320, 0xf6431b56
+0,          3,          3,        1,    14320, 0x921adec5
+0,          4,          4,        1,    14320, 0xa34e7331
index d0807324526272a9c205888fc67c09a3e1a80ab8..488ee71022181029aedfd8f363a6aa4e6d78e43c 100644 (file)
@@ -3,4 +3,4 @@
 #codec_id 0: rawvideo
 #dimensions 0: 128x128
 #sar 0: 0/1
-0,          0,          0,        1,    16384, 0x353dbacd
+0,          0,          0,        1,    16384, 0xeff50901
index 57c71e179d01860ecdd9a7890c9a5894615764e8..4662c3e6ccc7eb1dcd7c7a71b56c300620053c49 100644 (file)
@@ -1,3 +1,3 @@
-28eb102547b82acca57ef097a6c639d8 *tests/data/lavf/lavf.gbrap.fits
+d953a6a2c719de9d922d0624a7eb796b *tests/data/lavf/lavf.gbrap.fits
 10224000 tests/data/lavf/lavf.gbrap.fits
 tests/data/lavf/lavf.gbrap.fits CRC=0x883af247
index 030a6d90ed8d2a9bcd1187bb13f018cccaafaaeb..7206d242cda9e4afb75038db92360cafab51c20b 100644 (file)
@@ -1,3 +1,3 @@
-ff5fb24a67aeabd4f56088ca8b03d8b0 *tests/data/lavf/lavf.gbrap16be.fits
+e9a04d25104fc43ddc62b58eb33ecd08 *tests/data/lavf/lavf.gbrap16be.fits
 20376000 tests/data/lavf/lavf.gbrap16be.fits
 tests/data/lavf/lavf.gbrap16be.fits CRC=0xa981271b
index 2b60ddb3365943bc64e182b4ea6728014d0b777f..54c239687e9f2ba3f4e59a7a9716b852b2d7c5a8 100644 (file)
@@ -1,3 +1,3 @@
-dae49b5f6eb58981ba91e3e108355717 *tests/data/lavf/lavf.gbrp.fits
+3952247f7f9669f968826c909852bbd7 *tests/data/lavf/lavf.gbrp.fits
 7704000 tests/data/lavf/lavf.gbrp.fits
 tests/data/lavf/lavf.gbrp.fits CRC=0x80745c5e
index 9aa9db60a28933740be2e884f61b9dbfe36b2519..5bec5e80f9f4f5386486222fc73b83e654e6e07e 100644 (file)
@@ -1,3 +1,3 @@
-693ea80c33eb9b348db27a0bc4a5cc8a *tests/data/lavf/lavf.gbrp16be.fits
+caf72fec125df9c7a1d59c9d1bc70b80 *tests/data/lavf/lavf.gbrp16be.fits
 15336000 tests/data/lavf/lavf.gbrp16be.fits
 tests/data/lavf/lavf.gbrp16be.fits CRC=0x9573fb2b
index ce6783b7c1cc07acf55286a7837ec0eb256b5180..410467506f72411b71157997d4189bfa443f94df 100644 (file)
@@ -1,3 +1,3 @@
-d76b46a5a336b56f73451817cdf3897c *tests/data/lavf/lavf.gray.fits
+e690dc6db533b87f5f843737007ed070 *tests/data/lavf/lavf.gray.fits
 2664000 tests/data/lavf/lavf.gray.fits
 tests/data/lavf/lavf.gray.fits CRC=0x7aa0122f
index 058fa4ad19cc86eaefd64bec5700f955d62e406a..a0526f3db825c4d12a169cc7011880314fe353d8 100644 (file)
@@ -1,3 +1,3 @@
-15e85a553bbd07783f92377ed369308b *tests/data/lavf/lavf.gray16be.fits
+262658f437a256cd843db2b401bc20a9 *tests/data/lavf/lavf.gray16be.fits
 5184000 tests/data/lavf/lavf.gray16be.fits
-tests/data/lavf/lavf.gray16be.fits CRC=0x8cdcbeb2
+tests/data/lavf/lavf.gray16be.fits CRC=0x737e8998