1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

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>
This commit is contained in:
Gautam Ramakrishnan
2020-08-28 00:15:34 +05:30
committed by Michael Niedermayer
parent 87567fc398
commit 3c06045a8b
3 changed files with 28 additions and 17 deletions

View File

@@ -242,27 +242,36 @@ static void j2k_flush(Jpeg2000EncoderContext *s)
static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold) static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
{ {
Jpeg2000TgtNode *stack[30]; Jpeg2000TgtNode *stack[30];
int sp = 1, curval = 0; int sp = -1, curval = 0;
stack[0] = node;
node = node->parent; while(node->parent){
while(node){ stack[++sp] = node;
if (node->vis){
curval = node->val;
break;
}
node->vis++;
stack[sp++] = node;
node = node->parent; 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); put_bits(s, 0, threshold - curval);
break; curval = threshold;
} } else {
put_bits(s, 0, stack[sp]->val - curval); put_bits(s, 0, node->val - curval);
curval = node->val;
if (!node->vis) {
put_bits(s, 1, 1); put_bits(s, 1, 1);
curval = stack[sp]->val; node->vis = 1;
}
}
node->temp_val = curval;
if (sp < 0)
break;
node = stack[sp--];
} }
} }

View File

@@ -88,6 +88,7 @@ void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h)
for (i = 0; i < siz; i++) { for (i = 0; i < siz; i++) {
t[i].val = 0; t[i].val = 0;
t[i].temp_val = 0;
t[i].vis = 0; t[i].vis = 0;
} }
} }

View File

@@ -127,6 +127,7 @@ typedef struct Jpeg2000T1Context {
typedef struct Jpeg2000TgtNode { typedef struct Jpeg2000TgtNode {
uint8_t val; uint8_t val;
uint8_t temp_val;
uint8_t vis; uint8_t vis;
struct Jpeg2000TgtNode *parent; struct Jpeg2000TgtNode *parent;
} Jpeg2000TgtNode; } Jpeg2000TgtNode;