From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id ED6D4444B8 for ; Fri, 14 Oct 2022 06:28:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8E27D68BD63; Fri, 14 Oct 2022 09:28:13 +0300 (EEST) Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E2AA368BC63 for ; Fri, 14 Oct 2022 09:28:06 +0300 (EEST) Received: from 3b7b885f604c642d38de04408b9aa972 ([1.145.200.216]) (authenticated (0 bits)) by mx.sdf.org (8.15.2/8.14.5) with ESMTPSA id 29E6RuQJ029245 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Fri, 14 Oct 2022 06:28:00 GMT Date: Fri, 14 Oct 2022 17:27:50 +1100 From: Peter Ross To: ffmpeg-devel@ffmpeg.org Message-ID: <5781e37ed86f8c9554a5754103d6a7ea5dcd6661.1665728570.git.pross@xvid.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/jpegtables: remove duplicate luma and chroma quantization tables X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============2452152095538635140==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2452152095538635140== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kXplYeHZ82QqFjp3" Content-Disposition: inline --kXplYeHZ82QqFjp3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Duplicates of the standard JPEG quantization tables were found in the AGM, MSS34(dsp), NUV and VP31 codecs. This patch elimates those duplicates, placing a single copy in jpegtables. --- configure | 6 ++++-- libavcodec/agm.c | 27 +++++---------------------- libavcodec/jpegtables.c | 6 ++---- libavcodec/jpegtables.h | 3 +++ libavcodec/mss34dsp.c | 25 ++----------------------- libavcodec/nuv.c | 27 +++------------------------ libavcodec/vp3.c | 3 ++- libavcodec/vp3data.h | 13 ------------- 8 files changed, 21 insertions(+), 89 deletions(-) diff --git a/configure b/configure index f3fd91f592..2271e9b485 100755 --- a/configure +++ b/configure @@ -2758,6 +2758,7 @@ mpegvideodec_select=3D"mpegvideo mpeg_er" mpegvideoenc_select=3D"aandcttables fdctdsp me_cmp mpegvideo pixblockdsp q= peldsp" msmpeg4dec_select=3D"h263_decoder" msmpeg4enc_select=3D"h263_encoder" +mss34dsp_select=3D"jpegtables" vc1dsp_select=3D"h264chroma qpeldsp startcode" rdft_select=3D"fft" =20 @@ -2773,6 +2774,7 @@ ac3_fixed_encoder_select=3D"ac3dsp audiodsp mdct me_c= mp" acelp_kelvin_decoder_select=3D"audiodsp" adpcm_g722_decoder_select=3D"g722dsp" adpcm_g722_encoder_select=3D"g722dsp" +agm_decoder_select=3D"jpegtables" aic_decoder_select=3D"golomb idctdsp" alac_encoder_select=3D"lpc" als_decoder_select=3D"bswapdsp mpeg4audio" @@ -2918,7 +2920,7 @@ mxpeg_decoder_select=3D"mjpeg_decoder" nellymoser_decoder_select=3D"mdct sinewin" nellymoser_encoder_select=3D"audio_frame_queue mdct sinewin" notchlc_decoder_select=3D"lzf" -nuv_decoder_select=3D"idctdsp" +nuv_decoder_select=3D"idctdsp jpegtables" on2avc_decoder_select=3D"mdct" opus_decoder_deps=3D"swresample" opus_encoder_select=3D"audio_frame_queue" @@ -2983,7 +2985,7 @@ vc1_decoder_select=3D"blockdsp h264qpel intrax8 mpegv= ideodec msmpeg4dec vc1dsp" vc1image_decoder_select=3D"vc1_decoder" vorbis_decoder_select=3D"mdct" vorbis_encoder_select=3D"audio_frame_queue mdct" -vp3_decoder_select=3D"hpeldsp vp3dsp videodsp" +vp3_decoder_select=3D"hpeldsp jpegtables vp3dsp videodsp" vp4_decoder_select=3D"vp3_decoder" vp5_decoder_select=3D"h264chroma hpeldsp videodsp vp3dsp vp56dsp" vp6_decoder_select=3D"h264chroma hpeldsp huffman videodsp vp3dsp vp56dsp" diff --git a/libavcodec/agm.c b/libavcodec/agm.c index 017aa0e1fa..614bf92d97 100644 --- a/libavcodec/agm.c +++ b/libavcodec/agm.c @@ -33,24 +33,7 @@ #include "decode.h" #include "get_bits.h" #include "idctdsp.h" - -static const uint8_t unscaled_luma[64] =3D { - 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, - 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, - 68,109,103, 77, 24, 35, 55, 64, 81,104,113, 92, - 49, 64, 78, 87,103,121,120,101, 72, 92, 95, 98, - 112,100,103,99 -}; - -static const uint8_t unscaled_chroma[64] =3D { - 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, - 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99 -}; +#include "jpegtables.h" =20 typedef struct MotionVector { int16_t x, y; @@ -550,13 +533,13 @@ static void compute_quant_matrix(AGMContext *s, doubl= e qscale) } else { if (qscale >=3D 0.0) { for (int i =3D 0; i < 64; i++) { - luma[i] =3D FFMAX(1, unscaled_luma [(i & 7) * 8 + (i >>= 3)] * f); - chroma[i] =3D FFMAX(1, unscaled_chroma[(i & 7) * 8 + (i >>= 3)] * f); + luma[i] =3D FFMAX(1, ff_mjpeg_std_luminance_quant_tbl [= (i & 7) * 8 + (i >> 3)] * f); + chroma[i] =3D FFMAX(1, ff_mjpeg_std_chrominance_quant_tbl[= (i & 7) * 8 + (i >> 3)] * f); } } else { for (int i =3D 0; i < 64; i++) { - luma[i] =3D FFMAX(1, 255.0 - (255 - unscaled_luma [(i &= 7) * 8 + (i >> 3)]) * f); - chroma[i] =3D FFMAX(1, 255.0 - (255 - unscaled_chroma[(i &= 7) * 8 + (i >> 3)]) * f); + luma[i] =3D FFMAX(1, 255.0 - (255 - ff_mjpeg_std_luminan= ce_quant_tbl [(i & 7) * 8 + (i >> 3)]) * f); + chroma[i] =3D FFMAX(1, 255.0 - (255 - ff_mjpeg_std_chromin= ance_quant_tbl[(i & 7) * 8 + (i >> 3)]) * f); } } } diff --git a/libavcodec/jpegtables.c b/libavcodec/jpegtables.c index e453fcf90d..fadb40527e 100644 --- a/libavcodec/jpegtables.c +++ b/libavcodec/jpegtables.c @@ -32,12 +32,11 @@ =20 #include "jpegtabs.h" =20 -#if 0 /* These are the sample quantization tables given in JPEG spec section K.1. * The spec says that the values given produce "good" quality, and * when divided by 2, "very good" quality. */ -static const unsigned char std_luminance_quant_tbl[64] =3D { +const uint8_t ff_mjpeg_std_luminance_quant_tbl[64] =3D { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, @@ -47,7 +46,7 @@ static const unsigned char std_luminance_quant_tbl[64] = =3D { 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99 }; -static const unsigned char std_chrominance_quant_tbl[64] =3D { +const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64] =3D { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, @@ -57,4 +56,3 @@ static const unsigned char std_chrominance_quant_tbl[64] = =3D { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 }; -#endif diff --git a/libavcodec/jpegtables.h b/libavcodec/jpegtables.h index 49b5ecdeb0..08c99cde13 100644 --- a/libavcodec/jpegtables.h +++ b/libavcodec/jpegtables.h @@ -34,4 +34,7 @@ extern const uint8_t ff_mjpeg_val_ac_luminance[]; extern const uint8_t ff_mjpeg_bits_ac_chrominance[]; extern const uint8_t ff_mjpeg_val_ac_chrominance[]; =20 +extern const uint8_t ff_mjpeg_std_luminance_quant_tbl[64]; +extern const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64]; + #endif /* AVCODEC_JPEGTABLES_H */ diff --git a/libavcodec/mss34dsp.c b/libavcodec/mss34dsp.c index f3405658f7..b6bfc6501c 100644 --- a/libavcodec/mss34dsp.c +++ b/libavcodec/mss34dsp.c @@ -22,33 +22,12 @@ #include #include "libavutil/common.h" #include "mss34dsp.h" - -static const uint8_t luma_quant[64] =3D { - 16, 11, 10, 16, 24, 40, 51, 61, - 12, 12, 14, 19, 26, 58, 60, 55, - 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, - 18, 22, 37, 56, 68, 109, 103, 77, - 24, 35, 55, 64, 81, 104, 113, 92, - 49, 64, 78, 87, 103, 121, 120, 101, - 72, 92, 95, 98, 112, 100, 103, 99 -}; - -static const uint8_t chroma_quant[64] =3D { - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 -}; +#include "jpegtables.h" =20 void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma) { int i; - const uint8_t *qsrc =3D luma ? luma_quant : chroma_quant; + const uint8_t *qsrc =3D luma ? ff_mjpeg_std_luminance_quant_tbl : ff_m= jpeg_std_chrominance_quant_tbl; =20 if (quality >=3D 50) { int scale =3D 200 - 2 * quality; diff --git a/libavcodec/nuv.c b/libavcodec/nuv.c index ccd47586b5..a2e5d5c2c6 100644 --- a/libavcodec/nuv.c +++ b/libavcodec/nuv.c @@ -29,6 +29,7 @@ #include "avcodec.h" #include "codec_internal.h" #include "decode.h" +#include "jpegtables.h" #include "rtjpeg.h" =20 typedef struct NuvContext { @@ -42,28 +43,6 @@ typedef struct NuvContext { RTJpegContext rtj; } NuvContext; =20 -static const uint8_t fallback_lquant[] =3D { - 16, 11, 10, 16, 24, 40, 51, 61, - 12, 12, 14, 19, 26, 58, 60, 55, - 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, - 18, 22, 37, 56, 68, 109, 103, 77, - 24, 35, 55, 64, 81, 104, 113, 92, - 49, 64, 78, 87, 103, 121, 120, 101, - 72, 92, 95, 98, 112, 100, 103, 99 -}; - -static const uint8_t fallback_cquant[] =3D { - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 -}; - /** * @brief copy frame data from buffer to AVFrame, handling stride. * @param f destination AVFrame @@ -107,8 +86,8 @@ static void get_quant_quality(NuvContext *c, int quality) int i; quality =3D FFMAX(quality, 1); for (i =3D 0; i < 64; i++) { - c->lq[i] =3D (fallback_lquant[i] << 7) / quality; - c->cq[i] =3D (fallback_cquant[i] << 7) / quality; + c->lq[i] =3D (ff_mjpeg_std_luminance_quant_tbl[i] << 7) / quality; + c->cq[i] =3D (ff_mjpeg_std_chrominance_quant_tbl[i] << 7) / qualit= y; } } =20 diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 31775455a4..7db46936d0 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -43,6 +43,7 @@ #include "decode.h" #include "get_bits.h" #include "hpeldsp.h" +#include "jpegtables.h" #include "mathops.h" #include "thread.h" #include "threadframe.h" @@ -2418,7 +2419,7 @@ static av_cold int vp3_decode_init(AVCodecContext *av= ctx) s->coded_dc_scale_factor[1][i] =3D s->version < 2 ? vp31_dc_sc= ale_factor[i] : vp4_uv_dc_scale_factor[i]; s->coded_ac_scale_factor[i] =3D s->version < 2 ? vp31_ac_scale= _factor[i] : vp4_ac_scale_factor[i]; s->base_matrix[0][i] =3D s->version < 2 ? vp31_intra_y_= dequant[i] : vp4_generic_dequant[i]; - s->base_matrix[1][i] =3D s->version < 2 ? vp31_intra_c_= dequant[i] : vp4_generic_dequant[i]; + s->base_matrix[1][i] =3D s->version < 2 ? ff_mjpeg_std_= chrominance_quant_tbl[i] : vp4_generic_dequant[i]; s->base_matrix[2][i] =3D s->version < 2 ? vp31_inter_de= quant[i] : vp4_generic_dequant[i]; s->filter_limit_values[i] =3D s->version < 2 ? vp31_filter_l= imit_values[i] : vp4_filter_limit_values[i]; } diff --git a/libavcodec/vp3data.h b/libavcodec/vp3data.h index 272af4e3a0..317797a697 100644 --- a/libavcodec/vp3data.h +++ b/libavcodec/vp3data.h @@ -37,19 +37,6 @@ static const uint8_t vp31_intra_y_dequant[64] =3D { 72, 92, 95, 98, 112, 100, 103, 99 }; =20 -/* these coefficients dequantize intraframe C plane coefficients - * (note: same as JPEG) */ -static const uint8_t vp31_intra_c_dequant[64] =3D { - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 -}; - /* these coefficients dequantize interframe coefficients (all planes) */ static const uint8_t vp31_inter_dequant[64] =3D { 16, 16, 16, 20, 24, 28, 32, 40, --=20 2.35.1 -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B) --kXplYeHZ82QqFjp3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQSpB+AvpuUM0jTNINJnYHnFrEDdawUCY0kBYgAKCRBnYHnFrEDd axPXAKCoRYce3pXnq9TaN3dbO5zPzGUj8wCfTewZQ2XUe6m68LFUeneS4WYHxs0= =AH1w -----END PGP SIGNATURE----- --kXplYeHZ82QqFjp3-- --===============2452152095538635140== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --===============2452152095538635140==--