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 1DE8443E0D for ; Sat, 15 Oct 2022 00:53:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D21C968BD62; Sat, 15 Oct 2022 03:53:03 +0300 (EEST) Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1697868BC9F for ; Sat, 15 Oct 2022 03:52:54 +0300 (EEST) Received: from 67b7488e222ec48c0df7f04fd292871a ([1.145.200.216]) (authenticated (0 bits)) by mx.sdf.org (8.15.2/8.14.5) with ESMTPSA id 29F0qmIH004143 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Sat, 15 Oct 2022 00:52:52 GMT Date: Sat, 15 Oct 2022 11:52:43 +1100 From: Peter Ross To: ffmpeg-devel@ffmpeg.org Message-ID: <7ac509f6550637ef793935a30dbaab3db904a0ce.1665794986.git.pross@xvid.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCHv2] 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="===============5595483649165160435==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============5595483649165160435== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="rNj/ZZ0vO8uioG9p" Content-Disposition: inline --rNj/ZZ0vO8uioG9p 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 jpegquanttables.c. --- libavcodec/Makefile | 8 ++--- libavcodec/agm.c | 27 ++++------------- libavcodec/jpegquanttables.c | 58 ++++++++++++++++++++++++++++++++++++ libavcodec/jpegquanttables.h | 29 ++++++++++++++++++ libavcodec/jpegtables.c | 27 ----------------- libavcodec/mss34dsp.c | 25 ++-------------- libavcodec/nuv.c | 27 ++--------------- libavcodec/vp3.c | 3 +- libavcodec/vp3data.h | 13 -------- 9 files changed, 103 insertions(+), 114 deletions(-) create mode 100644 libavcodec/jpegquanttables.c create mode 100644 libavcodec/jpegquanttables.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 37b63cadc2..f53a8b6209 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -142,7 +142,7 @@ OBJS-$(CONFIG_MPEGVIDEOENC) +=3D mpegvideo_e= nc.o mpeg12data.o \ mpegvideoencdsp.o OBJS-$(CONFIG_MSMPEG4DEC) +=3D msmpeg4dec.o msmpeg4.o msmpeg4= data.o OBJS-$(CONFIG_MSMPEG4ENC) +=3D msmpeg4enc.o msmpeg4.o msmpeg4= data.o -OBJS-$(CONFIG_MSS34DSP) +=3D mss34dsp.o +OBJS-$(CONFIG_MSS34DSP) +=3D mss34dsp.o jpegquanttables.o OBJS-$(CONFIG_PIXBLOCKDSP) +=3D pixblockdsp.o OBJS-$(CONFIG_QPELDSP) +=3D qpeldsp.o OBJS-$(CONFIG_QSV) +=3D qsv.o @@ -196,7 +196,7 @@ OBJS-$(CONFIG_AC3_ENCODER) +=3D ac3enc_floa= t.o ac3enc.o ac3tab.o \ OBJS-$(CONFIG_AC3_FIXED_ENCODER) +=3D ac3enc_fixed.o ac3enc.o ac3tab= =2Eo ac3.o kbdwin.o OBJS-$(CONFIG_AC3_MF_ENCODER) +=3D mfenc.o mf_utils.o OBJS-$(CONFIG_ACELP_KELVIN_DECODER) +=3D g729dec.o lsp.o celp_math.o ce= lp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfi= lter.o -OBJS-$(CONFIG_AGM_DECODER) +=3D agm.o +OBJS-$(CONFIG_AGM_DECODER) +=3D agm.o jpegquanttables.o OBJS-$(CONFIG_AIC_DECODER) +=3D aic.o OBJS-$(CONFIG_ALAC_DECODER) +=3D alac.o alac_data.o alacdsp.o OBJS-$(CONFIG_ALAC_ENCODER) +=3D alacenc.o alac_data.o @@ -552,7 +552,7 @@ OBJS-$(CONFIG_MXPEG_DECODER) +=3D mxpegdec.o OBJS-$(CONFIG_NELLYMOSER_DECODER) +=3D nellymoserdec.o nellymoser.o OBJS-$(CONFIG_NELLYMOSER_ENCODER) +=3D nellymoserenc.o nellymoser.o OBJS-$(CONFIG_NOTCHLC_DECODER) +=3D notchlc.o -OBJS-$(CONFIG_NUV_DECODER) +=3D nuv.o rtjpeg.o +OBJS-$(CONFIG_NUV_DECODER) +=3D nuv.o rtjpeg.o jpegquanttables= =2Eo OBJS-$(CONFIG_ON2AVC_DECODER) +=3D on2avc.o on2avcdata.o OBJS-$(CONFIG_OPUS_DECODER) +=3D opusdec.o opusdec_celt.o opus_= celt.o \ opus_pvq.o opus_silk.o opustab.o= vorbis_data.o \ @@ -737,7 +737,7 @@ OBJS-$(CONFIG_VORBIS_DECODER) +=3D vorbisdec.o= vorbisdsp.o vorbis.o \ vorbis_data.o OBJS-$(CONFIG_VORBIS_ENCODER) +=3D vorbisenc.o vorbis.o \ vorbis_data.o -OBJS-$(CONFIG_VP3_DECODER) +=3D vp3.o +OBJS-$(CONFIG_VP3_DECODER) +=3D vp3.o jpegquanttables.o OBJS-$(CONFIG_VP5_DECODER) +=3D vp5.o vp56.o vp56data.o vpx_ra= c.o OBJS-$(CONFIG_VP6_DECODER) +=3D vp6.o vp56.o vp56data.o \ vp6dsp.o vpx_rac.o diff --git a/libavcodec/agm.c b/libavcodec/agm.c index 017aa0e1fa..760760a403 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 "jpegquanttables.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/jpegquanttables.c b/libavcodec/jpegquanttables.c new file mode 100644 index 0000000000..e0221fdb0e --- /dev/null +++ b/libavcodec/jpegquanttables.c @@ -0,0 +1,58 @@ +/* + * MJPEG encoder and decoder + * Copyright (c) 2000, 2001 Fabrice Bellard + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130= 1 USA + */ + +/** + * @file + * MJPEG quantization tables + */ + +#include "jpegquanttables.h" + +/* 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. + */ +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, + 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 +}; +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, + 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 +}; diff --git a/libavcodec/jpegquanttables.h b/libavcodec/jpegquanttables.h new file mode 100644 index 0000000000..70f1cbf96e --- /dev/null +++ b/libavcodec/jpegquanttables.h @@ -0,0 +1,29 @@ +/* + * MJPEG quantization tables + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130= 1 USA + */ + +#ifndef AVCODEC_JPEGQUANTTABLES_H +#define AVCODEC_JPEGQUANTTABLES_H + +#include + +extern const uint8_t ff_mjpeg_std_luminance_quant_tbl[64]; +extern const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64]; + +#endif /* AVCODEC_JPEGQUANTTABLES_H */ diff --git a/libavcodec/jpegtables.c b/libavcodec/jpegtables.c index e453fcf90d..9a15975a95 100644 --- a/libavcodec/jpegtables.c +++ b/libavcodec/jpegtables.c @@ -31,30 +31,3 @@ */ =20 #include "jpegtabs.h" - -#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 { - 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 unsigned char 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, - 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 -}; -#endif diff --git a/libavcodec/mss34dsp.c b/libavcodec/mss34dsp.c index f3405658f7..3f08c03ed7 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 "jpegquanttables.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..1d4f02217c 100644 --- a/libavcodec/nuv.c +++ b/libavcodec/nuv.c @@ -29,6 +29,7 @@ #include "avcodec.h" #include "codec_internal.h" #include "decode.h" +#include "jpegquanttables.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..b731bc0669 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -43,6 +43,7 @@ #include "decode.h" #include "get_bits.h" #include "hpeldsp.h" +#include "jpegquanttables.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) --rNj/ZZ0vO8uioG9p Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQSpB+AvpuUM0jTNINJnYHnFrEDdawUCY0oEVwAKCRBnYHnFrEDd ay08AJ0flIaozmkohlLHXRzkSlVn6pXlwACgkLFHu327Apl9sMRje4J3mRzTL1E= =uuEG -----END PGP SIGNATURE----- --rNj/ZZ0vO8uioG9p-- --===============5595483649165160435== 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". --===============5595483649165160435==--