codecparsers: h265: add helpers to convert quantization matrices
authorSreerenj Balachandran <sreerenj.balachandran@intel.com>
Fri, 10 Apr 2015 11:08:43 +0000 (14:08 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 26 Apr 2015 19:46:25 +0000 (21:46 +0200)
Add utility functions to convert quantization matrices from zig-zag scan
order into raster scan order and vice-versa

https://bugzilla.gnome.org/show_bug.cgi?id=747613

gst-libs/gst/codecparsers/gsth265parser.c
gst-libs/gst/codecparsers/gsth265parser.h

index b07d1a4ae74c6d4671a5cc6cea5069de6f7410ee..986e7d8d384d636bb8a7ec85cbd935bc02f3d98c 100644 (file)
@@ -131,6 +131,24 @@ static const guint8 default_scaling_list2[64] = {
   54, 71, 71, 91
 };
 
+static const guint8 zigzag_4x4[16] = {
+  0, 1, 4, 8,
+  5, 2, 3, 6,
+  9, 12, 13, 10,
+  7, 11, 14, 15,
+};
+
+static const guint8 zigzag_8x8[64] = {
+  0, 1, 8, 16, 9, 2, 3, 10,
+  17, 24, 32, 25, 18, 11, 4, 5,
+  12, 19, 26, 33, 40, 48, 41, 34,
+  27, 20, 13, 6, 7, 14, 21, 28,
+  35, 42, 49, 56, 57, 50, 43, 36,
+  29, 22, 15, 23, 30, 37, 44, 51,
+  58, 59, 52, 45, 38, 31, 39, 46,
+  53, 60, 61, 54, 47, 55, 62, 63
+};
+
 typedef struct
 {
   guint par_n, par_d;
@@ -2385,3 +2403,103 @@ gst_h265_sei_free (GstH265SEIMessage * sei)
     pic_timing->du_cpb_removal_delay_increment_minus1 = 0;
   }
 }
+
+/**
+ * gst_h265_quant_matrix_4x4_get_zigzag_from_raster:
+ * @out_quant: (out): The resulting quantization matrix
+ * @quant: The source quantization matrix
+ *
+ * Converts quantization matrix @quant from raster scan order to
+ * zigzag scan order and store the resulting factors into @out_quant.
+ *
+ * Note: it is an error to pass the same table in both @quant and
+ * @out_quant arguments.
+ *
+ * Since: 1.6
+ */
+void
+gst_h265_quant_matrix_4x4_get_zigzag_from_raster (guint8 out_quant[16],
+    const guint8 quant[16])
+{
+  guint i;
+
+  g_return_if_fail (out_quant != quant);
+
+  for (i = 0; i < 16; i++)
+    out_quant[i] = quant[zigzag_4x4[i]];
+}
+
+/**
+ * gst_h265_quant_matrix_4x4_get_raster_from_zigzag:
+ * @out_quant: (out): The resulting quantization matrix
+ * @quant: The source quantization matrix
+ *
+ * Converts quantization matrix @quant from zigzag scan order to
+ * raster scan order and store the resulting factors into @out_quant.
+ *
+ * Note: it is an error to pass the same table in both @quant and
+ * @out_quant arguments.
+ *
+ * Since: 1.6
+ */
+void
+gst_h265_quant_matrix_4x4_get_raster_from_zigzag (guint8 out_quant[16],
+    const guint8 quant[16])
+{
+  guint i;
+
+  g_return_if_fail (out_quant != quant);
+
+  for (i = 0; i < 16; i++)
+    out_quant[zigzag_4x4[i]] = quant[i];
+}
+
+/**
+ * gst_h265_quant_matrix_8x8_get_zigzag_from_raster:
+ * @out_quant: (out): The resulting quantization matrix
+ * @quant: The source quantization matrix
+ *
+ * Converts quantization matrix @quant from raster scan order to
+ * zigzag scan order and store the resulting factors into @out_quant.
+ *
+ * Note: it is an error to pass the same table in both @quant and
+ * @out_quant arguments.
+ *
+ * Since: 1.6
+ */
+void
+gst_h265_quant_matrix_8x8_get_zigzag_from_raster (guint8 out_quant[64],
+    const guint8 quant[64])
+{
+  guint i;
+
+  g_return_if_fail (out_quant != quant);
+
+  for (i = 0; i < 64; i++)
+    out_quant[i] = quant[zigzag_8x8[i]];
+}
+
+/**
+ * gst_h265_quant_matrix_8x8_get_raster_from_zigzag:
+ * @out_quant: (out): The resulting quantization matrix
+ * @quant: The source quantization matrix
+ *
+ * Converts quantization matrix @quant from zigzag scan order to
+ * raster scan order and store the resulting factors into @out_quant.
+ *
+ * Note: it is an error to pass the same table in both @quant and
+ * @out_quant arguments.
+ *
+ * Since: 1.6
+ */
+void
+gst_h265_quant_matrix_8x8_get_raster_from_zigzag (guint8 out_quant[64],
+    const guint8 quant[64])
+{
+  guint i;
+
+  g_return_if_fail (out_quant != quant);
+
+  for (i = 0; i < 64; i++)
+    out_quant[zigzag_8x8[i]] = quant[i];
+}
index 883b7b25db9dcd4ac42ff96346d40f6db700e215..755db3642df7ae7eed84908940b33195599dc54f 100644 (file)
@@ -1061,5 +1061,26 @@ gboolean            gst_h265_sei_copy       (GstH265SEIMessage       * dest_sei,
 
 void                gst_h265_sei_free       (GstH265SEIMessage * sei);
 
+void    gst_h265_quant_matrix_4x4_get_zigzag_from_raster (guint8 out_quant[16],
+                                                          const guint8 quant[16]);
+
+void    gst_h265_quant_matrix_4x4_get_raster_from_zigzag (guint8 out_quant[16],
+                                                          const guint8 quant[16]);
+
+void    gst_h265_quant_matrix_8x8_get_zigzag_from_raster (guint8 out_quant[64],
+                                                          const guint8 quant[64]);
+
+void    gst_h265_quant_matrix_8x8_get_raster_from_zigzag (guint8 out_quant[64],
+                                                          const guint8 quant[64]);
+
+#define gst_h265_quant_matrix_16x16_get_zigzag_from_raster \
+        gst_h265_quant_matrix_8x8_get_zigzag_from_raster
+#define gst_h265_quant_matrix_16x16_get_raster_from_zigzag \
+        gst_h265_quant_matrix_8x8_get_raster_from_zigzag
+#define gst_h265_quant_matrix_32x32_get_zigzag_from_raster \
+        gst_h265_quant_matrix_8x8_get_zigzag_from_raster
+#define gst_h265_quant_matrix_32x32_get_raster_from_zigzag \
+        gst_h265_quant_matrix_8x8_get_raster_from_zigzag
+
 G_END_DECLS
 #endif