[FFmpeg-devel] [RFC PATCH v3 2/5] libavcodec/j2kenc: Fix tag tree coding
Michael Niedermayer
michael at niedermayer.cc
Tue Aug 25 01:38:22 EEST 2020
On Mon, Aug 24, 2020 at 11:10:31PM +0530, gautamramk at gmail.com wrote:
> From: Gautam Ramakrishnan <gautamramk at gmail.com>
>
> The implementation of tag tree encoding was incorrect.
> However, this error was not visible as the current j2k
> encoder encodes only 1 layer.
> This patch fixes tag tree coding for JPEG2000 such tag
> tree coding would work for multi layer encoding.
> ---
> libavcodec/j2kenc.c | 41 ++++++++++++++++++++++++-----------------
> libavcodec/jpeg2000.c | 1 +
> libavcodec/jpeg2000.h | 1 +
> 3 files changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
> index 16863f8e8c..d9777fe07f 100644
> --- a/libavcodec/j2kenc.c
> +++ b/libavcodec/j2kenc.c
> @@ -242,27 +242,34 @@ static void j2k_flush(Jpeg2000EncoderContext *s)
> static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
> {
> Jpeg2000TgtNode *stack[30];
> - int sp = 1, curval = 0;
> - stack[0] = node;
> + int sp = -1, curval = 0;
>
> - node = node->parent;
> - while(node){
> - if (node->vis){
> - curval = node->val;
> - break;
> - }
> - node->vis++;
> - stack[sp++] = node;
> + while(node->parent){
> + stack[++sp] = node;
> node = node->parent;
> }
> - while(--sp >= 0){
> - if (stack[sp]->val >= threshold){
> - put_bits(s, 0, threshold - curval);
> - break;
> +
> + while (1) {
> + if (curval > node->temp_val)
> + node->temp_val = curval;
> + else {
> + curval = node->temp_val;
> }
> - put_bits(s, 0, stack[sp]->val - curval);
> - put_bits(s, 1, 1);
> - curval = stack[sp]->val;
> + while (curval < threshold) {
> + if (curval >= node->val) {
> + if (!node->vis) {
> + node->vis = 1;
> + put_bits(s, 1, 1);
> + }
> + break;
> + }
> + put_bits(s, 0, 1);
> + curval++;
> + }
why is the put_bits(s, 0, stack[sp]->val - curval);
changed into 1 bit at a time calls ?
a single call should still work with the modified loop
a single call may be faster ...
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200825/05086f86/attachment.sig>
More information about the ffmpeg-devel
mailing list