diff options
author | Gautam Ramakrishnan <gautamramk@gmail.com> | 2020-08-28 00:15:34 +0530 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2020-08-30 16:18:37 +0200 |
commit | 3c06045a8b584a8d569547c2f4d108588cce6a37 (patch) | |
tree | b744bd94633ee00430f65b8bfed46f696b046176 /libavcodec/j2kenc.c | |
parent | 87567fc398a8a35536c7df0378eecb86dcb6fbf9 (diff) |
libavcodec/j2kenc: Fix tag tree coding
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.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/j2kenc.c')
-rw-r--r-- | libavcodec/j2kenc.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index 16863f8e8c..87acd2d5c9 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -242,27 +242,36 @@ 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){ + + while (1) { + if (curval > node->temp_val) + node->temp_val = curval; + else { + curval = node->temp_val; + } + + if (node->val >= threshold) { put_bits(s, 0, threshold - curval); - break; + curval = threshold; + } else { + put_bits(s, 0, node->val - curval); + curval = node->val; + if (!node->vis) { + put_bits(s, 1, 1); + node->vis = 1; + } } - put_bits(s, 0, stack[sp]->val - curval); - put_bits(s, 1, 1); - curval = stack[sp]->val; + + node->temp_val = curval; + if (sp < 0) + break; + node = stack[sp--]; } } |