]> git.sesse.net Git - x264/blobdiff - common/set.c
move quant_mf[] from x264_t to the heap, and merge duplicate entries
[x264] / common / set.c
index d72763ff1328426f0dc9e248d69a1287e6c40d57..f6dc7c3d8284bfe58b04de8d0bdac82712f33d2e 100644 (file)
@@ -72,7 +72,27 @@ void x264_cqm_init( x264_t *h )
     int def_quant8[6][64];
     int def_dequant4[6][16];
     int def_dequant8[6][64];
-    int q, i, i_list;
+    int q, i, j, i_list;
+
+    for( i = 0; i < 6; i++ )
+    {
+        int size = i<4 ? 16 : 64;
+        for( j = (i<4 ? 0 : 4); j < i; j++ )
+            if( !memcmp( h->pps->scaling_list[i], h->pps->scaling_list[j], size*sizeof(uint8_t) ) )
+                break;
+        if( j < i )
+        {
+            h->  quant4_mf[i] = h->  quant4_mf[j];
+            h->dequant4_mf[i] = h->dequant4_mf[j];
+            h->unquant4_mf[i] = h->unquant4_mf[j];
+        }
+        else
+        {
+            h->  quant4_mf[i] = x264_malloc( 6*size*sizeof(int) );
+            h->dequant4_mf[i] = x264_malloc( 6*size*sizeof(int) );
+            h->unquant4_mf[i] = x264_malloc(52*size*sizeof(int) );
+        }
+    }
 
     for( q = 0; q < 6; q++ )
     {
@@ -116,6 +136,23 @@ void x264_cqm_init( x264_t *h )
     }
 }
 
+void x264_cqm_delete( x264_t *h )
+{
+    int i, j;
+    for( i = 0; i < 6; i++ )
+    {
+        for( j = 0; j < i; j++ )
+            if( h->quant4_mf[i] == h->quant4_mf[j] )
+                break;
+        if( j == i )
+        {
+            x264_free( h->  quant4_mf[i] );
+            x264_free( h->dequant4_mf[i] );
+            x264_free( h->unquant4_mf[i] );
+        }
+    }
+}
+
 int x264_cqm_parse_jmlist( x264_t *h, const char *buf, const char *name,
                            uint8_t *cqm, const uint8_t *jvt, int length )
 {