From 250555a7dec8f1a396a20994d28395249eb406d7 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Tue, 5 Feb 2013 11:56:46 +0100 Subject: [PATCH] codecparsers: mpeg2: add helpers to convert quantization matrices. Add utility functions to convert quantization matrices from zigzag scan order (as encoded in the bitstream) into raster scan order. Also provide another function to reverse the operation. https://bugzilla.gnome.org/show_bug.cgi?id=693000 Signed-off-by: Gwenole Beauchesne --- gst-libs/gst/codecparsers/gstmpegvideoparser.c | 50 ++++++++++++++++++++++++++ gst-libs/gst/codecparsers/gstmpegvideoparser.h | 6 ++++ 2 files changed, 56 insertions(+) diff --git a/gst-libs/gst/codecparsers/gstmpegvideoparser.c b/gst-libs/gst/codecparsers/gstmpegvideoparser.c index c841139..25763e8 100644 --- a/gst-libs/gst/codecparsers/gstmpegvideoparser.c +++ b/gst-libs/gst/codecparsers/gstmpegvideoparser.c @@ -819,3 +819,53 @@ failed: GST_WARNING ("error parsing \"GOP\""); return FALSE; } + +/** + * gst_mpeg_video_quant_matrix_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.2 + */ +void +gst_mpeg_video_quant_matrix_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[mpeg_zigzag_8x8[i]] = quant[i]; +} + +/** + * gst_mpeg_video_quant_matrix_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.2 + */ +void +gst_mpeg_video_quant_matrix_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[mpeg_zigzag_8x8[i]]; +} diff --git a/gst-libs/gst/codecparsers/gstmpegvideoparser.h b/gst-libs/gst/codecparsers/gstmpegvideoparser.h index 5685433..daeec60 100644 --- a/gst-libs/gst/codecparsers/gstmpegvideoparser.h +++ b/gst-libs/gst/codecparsers/gstmpegvideoparser.h @@ -428,6 +428,12 @@ gboolean gst_mpeg_video_parse_sequence_display_extension (GstMpegVideoSequenceDi gboolean gst_mpeg_video_parse_quant_matrix_extension (GstMpegVideoQuantMatrixExt * quant, const guint8 * data, gsize size, guint offset); +void gst_mpeg_video_quant_matrix_get_raster_from_zigzag (guint8 out_quant[64], + const guint8 quant[64]); + +void gst_mpeg_video_quant_matrix_get_zigzag_from_raster (guint8 out_quant[64], + const guint8 quant[64]); + G_END_DECLS #endif -- 2.7.4