]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cfhdenc.c
avcodec/dynamic_hdr10_plus: don't take a GetBitContext as input argument
[ffmpeg] / libavcodec / cfhdenc.c
index d53604ae110d5475b818c3aa8ca646ef8d23656b..5554baefa3fd4f379fbaab097340d9af45e563e8 100644 (file)
@@ -94,8 +94,11 @@ static const unsigned codebook[256][2] = {
 };
 
 /* Derived by extracting runcodes from existing tables from decoder */
-static const uint16_t runbook[8][3] = {
-    {1,  0x0000,   1}, {7,  0x0069,  12}, {8,  0x00D1,  20}, {9,  0x018A,  32},
+static const uint16_t runbook[18][3] = {
+    {1,  0x0000,   1}, {2,  0x0000,   2}, {3,  0x0000,   3}, {4,  0x0000,   4},
+    {5,  0x0000,   5}, {6,  0x0000,   6}, {7,  0x0000,   7}, {8,  0x0000,   8},
+    {9,  0x0000,   9}, {10, 0x0000,  10}, {11, 0x0000,  11},
+    {7,  0x0069,  12}, {8,  0x00D1,  20}, {9,  0x018A,  32},
     {10, 0x0343,  60}, {11, 0x0685, 100}, {13, 0x18BF, 180}, {13, 0x1BA5, 320},
 };
 
@@ -105,94 +108,94 @@ static const uint16_t runbook[8][3] = {
  */
 static const uint16_t quantization_per_subband[2][3][13][9] = {
     {{
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, }, // film3+
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, }, // film3
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, }, // film2+
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, }, // film2
-        { 16, 16,  8,  4,  4,  2,   8,   8,  12, }, // film1++
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, }, // film1+
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, }, // film1
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, }, // high+
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, }, // high
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, }, // medium+
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, }, // medium
-        { 64, 64, 48, 16, 16, 12,  48,  48,  64, }, // low+
-        { 64, 64, 48, 16, 16, 12,  64,  64,  96, }, // low
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3+
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3
+        { 16, 16,  8,  4,  4,  2,   7,   7,  10, }, // film2+
+        { 16, 16,  8,  4,  4,  2,   8,   8,  12, }, // film2
+        { 16, 16,  8,  4,  4,  2,  16,  16,  26, }, // film1++
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1+
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high+
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium+
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium
+        { 64, 64, 48, 16, 16, 12,  96,  96, 144, }, // low+
+        { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
     },
     {
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, },
-        { 16, 16,  8,  4,  4,  2,   3,   3,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   8, },
-        { 16, 16,  8,  4,  4,  2,   8,   8,  16, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  24, },
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, },
-        { 48, 48, 32, 12, 12,  8,  16,  16,  32, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  64, },
-        { 64, 64, 48, 16, 16, 12,  48,  48,  64, },
-        { 64, 64, 48, 16, 16, 12,  64,  64,  96, },
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3+
+        { 16, 16,  8,  4,  4,  2,   6,   6,  12, }, // film3
+        { 16, 16,  8,  4,  4,  2,   7,   7,  14, }, // film2+
+        { 16, 16,  8,  4,  4,  2,   8,   8,  16, }, // film2
+        { 16, 16,  8,  4,  4,  2,  16,  16,  26, }, // film1++
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1+
+        { 24, 24, 12,  6,  6,  3,  24,  24,  48, }, // film1
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high+
+        { 48, 48, 32, 12, 12,  8,  32,  32,  64, }, // high
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium+
+        { 48, 48, 32, 12, 12,  8,  64,  64, 128, }, // medium
+        { 64, 64, 48, 16, 16, 12,  96,  96, 160, }, // low+
+        { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
     },
     {
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, },
-        { 16, 16,  8,  4,  4,  2,   3,   3,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   8, },
-        { 16, 16,  8,  4,  4,  2,   8,   8,  16, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  24, },
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, },
-        { 48, 48, 32, 12, 12,  8,  16,  16,  32, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  64, },
-        { 64, 64, 48, 16, 16, 12,  48,  48,  64, },
-        { 64, 64, 48, 16, 16, 12,  64,  64,  96, },
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3+
+        { 16, 16,  8,  4,  4,  2,   6,   6,  12, }, // film3
+        { 16, 16,  8,  4,  4,  2,   7,   7,  14, }, // film2+
+        { 16, 16,  8,  4,  4,  2,   8,   8,  16, }, // film2
+        { 16, 16,  8,  4,  4,  2,  16,  16,  26, }, // film1++
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1+
+        { 24, 24, 12,  6,  6,  3,  24,  24,  48, }, // film1
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high+
+        { 48, 48, 32, 12, 12,  8,  32,  32,  64, }, // high
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium+
+        { 48, 48, 32, 12, 12,  8,  64,  64, 128, }, // medium
+        { 64, 64, 48, 16, 16, 12,  96,  96, 160, }, // low+
+        { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
     }},
     {{
-        { 16, 16,  8, 16, 16,  8,  24,  24,  36, },
-        { 16, 16,  8, 16, 16,  8,  32,  32,  48, },
-        { 16, 16,  8, 16, 16,  8,  48,  48,  72, },
-        { 16, 16,  8, 16, 16,  8,  64,  64,  96, },
-        { 16, 16,  8, 20, 20, 10,  80,  80, 128, },
-        { 24, 24, 12, 24, 24, 12,  96,  96, 144, },
-        { 24, 24, 12, 24, 24, 12, 128, 128, 192, },
-        { 32, 32, 24, 32, 32, 24, 192, 192, 288, },
-        { 32, 32, 24, 32, 32, 24, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 512, 512, 768, },
-        { 56, 56, 40, 56, 56, 40, 512, 512, 768, },
-        { 64, 64, 48, 64, 64, 48, 512, 512, 768, },
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3+
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3
+        { 16, 16,  8, 16, 16,  8,  32,  32,  48, }, // film2+
+        { 16, 16,  8, 16, 16,  8,  32,  32,  48, }, // film2
+        { 16, 16,  8, 20, 20, 10,  80,  80, 128, }, // film1++
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1+
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium
+        { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
+        { 64, 64, 48, 64, 64, 48, 512, 512, 768, }, // low
     },
     {
-        { 16, 16,  8, 16, 16,  8,  24,  24,  36, },
-        { 16, 16,  8, 16, 16,  8,  32,  32,  48, },
-        { 16, 16,  8, 16, 16,  8,  48,  48,  72, },
-        { 16, 16,  8, 16, 16,  8,  64,  64,  96, },
-        { 16, 16,  8, 20, 20, 10,  80,  80, 128, },
-        { 24, 24, 12, 24, 24, 12,  96,  96, 144, },
-        { 24, 24, 12, 24, 24, 12, 128, 128, 192, },
-        { 32, 32, 24, 32, 32, 24, 192, 192, 288, },
-        { 32, 32, 24, 32, 32, 24, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 512, 512, 768, },
-        { 56, 56, 40, 56, 56, 40, 512, 512, 768, },
-        { 64, 64, 48, 64, 64, 48, 512, 512, 768, },
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3+
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film3
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film2+
+        { 16, 16,  8, 16, 16,  8,  64,  64,  96, }, // film2
+        { 16, 16,  8, 20, 20, 10,  80,  80, 128, }, // film1++
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1+
+        { 24, 24, 12, 24, 24, 12, 192, 192, 288, }, // film1
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
+        { 32, 32, 24, 32, 32, 24, 256, 256, 384, }, // high
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
+        { 48, 48, 32, 48, 48, 32, 512, 512, 768, }, // medium
+        { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
+        { 64, 64, 48, 64, 64, 48,1024,1024,1536, }, // low
     },
     {
-        { 16, 16,  8, 16, 16,  8,  24,  24,  36, },
-        { 16, 16,  8, 16, 16,  8,  32,  32,  48, },
-        { 16, 16,  8, 16, 16,  8,  48,  48,  72, },
-        { 16, 16,  8, 16, 16,  8,  64,  64,  96, },
-        { 16, 16, 10, 20, 20, 10,  80,  80, 128, },
-        { 24, 24, 12, 24, 24, 12,  96,  96, 144, },
-        { 24, 24, 12, 24, 24, 12, 128, 128, 192, },
-        { 32, 32, 24, 32, 32, 24, 192, 192, 288, },
-        { 32, 32, 24, 32, 32, 24, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 512, 512, 768, },
-        { 56, 56, 40, 56, 56, 40, 512, 512, 768, },
-        { 64, 64, 48, 64, 64, 48, 512, 512, 768, },
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3+
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film3
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film2+
+        { 16, 16,  8, 16, 16,  8,  64,  64,  96, }, // film2
+        { 16, 16, 10, 20, 20, 10,  80,  80, 128, }, // film1++
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1+
+        { 24, 24, 12, 24, 24, 12, 192, 192, 288, }, // film1
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
+        { 32, 32, 24, 32, 32, 24, 256, 256, 384, }, // high
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
+        { 48, 48, 32, 48, 48, 32, 512, 512, 768, }, // medium
+        { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
+        { 64, 64, 48, 64, 64, 48,1024,1024,1536, }, // low
     }},
 };
 
@@ -329,7 +332,7 @@ static av_cold int cfhd_encode_init(AVCodecContext *avctx)
 
     s->rb[0].run = 0;
 
-    for (int i = 1, j = 0; i < 320 && j < 7; j++) {
+    for (int i = 1, j = 0; i < 320 && j < 17; j++) {
         int run = runbook[j][2];
         int end = runbook[j+1][2];
 
@@ -340,8 +343,8 @@ static av_cold int cfhd_encode_init(AVCodecContext *avctx)
         }
     }
 
-    s->rb[320].bits = runbook[7][1];
-    s->rb[320].size = runbook[7][0];
+    s->rb[320].bits = runbook[17][1];
+    s->rb[320].size = runbook[17][0];
     s->rb[320].run = 320;
 
     for (int i = 0; i < 256; i++) {
@@ -366,7 +369,7 @@ static av_cold int cfhd_encode_init(AVCodecContext *avctx)
     return 0;
 }
 
-static inline void filter(int16_t *input, ptrdiff_t in_stride,
+static av_always_inline void filter(int16_t *input, ptrdiff_t in_stride,
                           int16_t *low, ptrdiff_t low_stride,
                           int16_t *high, ptrdiff_t high_stride,
                           int len)
@@ -405,11 +408,11 @@ static void vert_filter(int16_t *input, ptrdiff_t in_stride,
 static void quantize_band(int16_t *input, int width, int a_width,
                           int height, unsigned quantization)
 {
-    const int factor = (1 << 16) / quantization;
+    const int16_t factor = (uint32_t)(1U << 15) / quantization;
 
     for (int i = 0; i < height; i++) {
         for (int j = 0; j < width; j++)
-            input[j] = av_clip_intp2((input[j] * factor) / 65536, 10);
+            input[j] = av_clip_intp2(((input[j] * factor + 16384 * FFSIGN(input[j])) / 32768), 10);
         input += a_width;
     }
 }
@@ -901,7 +904,7 @@ static const AVClass cfhd_class = {
 
 AVCodec ff_cfhd_encoder = {
     .name             = "cfhd",
-    .long_name        = NULL_IF_CONFIG_SMALL("Cineform HD"),
+    .long_name        = NULL_IF_CONFIG_SMALL("GoPro CineForm HD"),
     .type             = AVMEDIA_TYPE_VIDEO,
     .id               = AV_CODEC_ID_CFHD,
     .priv_data_size   = sizeof(CFHDEncContext),
@@ -916,4 +919,5 @@ AVCodec ff_cfhd_encoder = {
                           AV_PIX_FMT_GBRAP12,
                           AV_PIX_FMT_NONE
                         },
+    .caps_internal    = FF_CODEC_CAP_INIT_CLEANUP,
 };