[FFmpeg-devel] [PATCH 09/13] lavc/jpeg2000: Speed up ff_jpeg2000_tag_tree_init() using stereotypes for sizes <= 4x4
Anton Khirnov
anton at khirnov.net
Sat Jun 18 18:00:08 EEST 2022
Quoting Tomas Härdin (2022-06-14 16:43:38)
>
>
> From 03b806f89453571310dcb14edbd9f51e059b7476 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git at haerdin.se>
> Date: Wed, 8 Jun 2022 10:08:15 +0200
> Subject: [PATCH 09/13] lavc/jpeg2000: Speed up ff_jpeg2000_tag_tree_init()
> using stereotypes for sizes <= 4x4
>
> ---
> libavcodec/jpeg2000.c | 35 +++++++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
> index 0bec2e187d..b80e68bcba 100644
> --- a/libavcodec/jpeg2000.c
> +++ b/libavcodec/jpeg2000.c
> @@ -51,6 +51,31 @@ static int32_t tag_tree_size(int w, int h)
> return (int32_t)(res + 1);
> }
>
> +#define T(x) (x*sizeof(Jpeg2000TgtNode))
> +
> +static const size_t tt_sizes[16] = {
> + T(1),T(3),T(6),T(7),T(3),T(5),T(9),T(11),T(6),T(9),T(14),T(17),T(7),T(11),T(17),T(21),
> +};
> +
> +static const Jpeg2000TgtNode tt_stereotypes[16][21] = {
> + {{-1},},
> + {{2},{2},{-1},},
> + {{3},{3},{4},{5},{5},{-1},},
> + {{4},{4},{5},{5},{6},{6},{-1},},
> + {{2},{2},{-1},},
> + {{4},{4},{4},{4},{-1},},
> + {{6},{6},{7},{6},{6},{7},{8},{8},{-1},},
> + {{8},{8},{9},{9},{8},{8},{9},{9},{10},{10},{-1},},
> + {{3},{3},{4},{5},{5},{-1},},
> + {{6},{6},{6},{6},{7},{7},{8},{8},{-1},},
> + {{9},{9},{10},{9},{9},{10},{11},{11},{12},{13},{13},{13},{13},{-1},},
> + {{12},{12},{13},{13},{12},{12},{13},{13},{14},{14},{15},{15},{16},{16},{16},{16},{-1},},
> + {{4},{4},{5},{5},{6},{6},{-1},},
> + {{8},{8},{8},{8},{9},{9},{9},{9},{10},{10},{-1},},
> + {{12},{12},{13},{12},{12},{13},{14},{14},{15},{14},{14},{15},{16},{16},{16},{16},{-1},},
> + {{16},{16},{17},{17},{16},{16},{17},{17},{18},{18},{19},{19},{18},{18},{19},{19},{20},{20},{20},{20},{-1},},
> +};
> +
> /* allocate the memory for tag tree */
> static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, int w, int h)
> {
> @@ -59,6 +84,15 @@ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size,
> int32_t tt_size, ofs = 0;
> size_t prod;
>
> + if (w <= 4 && h <= 4) {
> + int idx = w-1 + (h-1)*4;
> + size_t sz = tt_sizes[idx];
> + av_fast_malloc(old, size, sz);
Unchecked mallocs are of the beast.
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list