lj92: Fix decoding of 16 bit diff values (#6190)

This is a port of the fix discussed here:
https://github.com/ilia3101/MLV-App/pull/221
This commit is contained in:
Simon Segerblom Rex
2021-04-18 08:03:53 +02:00
committed by GitHub
parent 2eaccc40af
commit cfbc8a632d

View File

@@ -313,6 +313,9 @@ static int decode(ljp* self) {
} }
static int receive(ljp* self,int ssss) { static int receive(ljp* self,int ssss) {
if (ssss == 16) {
return 1 << 15;
}
int i = 0; int i = 0;
int v = 0; int v = 0;
while (i != ssss) { while (i != ssss) {
@@ -365,6 +368,10 @@ inline static int nextdiff(ljp* self, int Px) {
cnt -= usedbits; cnt -= usedbits;
int keepbitsmask = (1 << cnt)-1; int keepbitsmask = (1 << cnt)-1;
b &= keepbitsmask; b &= keepbitsmask;
int diff;
if (t == 16) {
diff = 1 << 15;
} else {
while (cnt < t) { while (cnt < t) {
next = *(u16*)&self->data[ix]; next = *(u16*)&self->data[ix];
int one = next&0xFF; int one = next&0xFF;
@@ -378,12 +385,13 @@ inline static int nextdiff(ljp* self, int Px) {
} else if (two==0xFF) ix++; } else if (two==0xFF) ix++;
} }
cnt -= t; cnt -= t;
int diff = b >> cnt; diff = b >> cnt;
int vt = 1<<(t-1); int vt = 1<<(t-1);
if (diff < vt) { if (diff < vt) {
vt = (-1 << t) + 1; vt = (-1 << t) + 1;
diff += vt; diff += vt;
} }
}
keepbitsmask = (1 << cnt)-1; keepbitsmask = (1 << cnt)-1;
self->b = b & keepbitsmask; self->b = b & keepbitsmask;
self->cnt = cnt; self->cnt = cnt;
@@ -424,6 +432,7 @@ static int parsePred6(ljp* self) {
diff = nextdiff(self,0); diff = nextdiff(self,0);
Px = 1 << (self->bits-1); Px = 1 << (self->bits-1);
left = Px + diff; left = Px + diff;
left = (u16) (left % 65536);
if (self->linearize) if (self->linearize)
linear = self->linearize[left]; linear = self->linearize[left];
else else
@@ -437,6 +446,7 @@ static int parsePred6(ljp* self) {
diff = nextdiff(self,0); diff = nextdiff(self,0);
Px = left; Px = left;
left = Px + diff; left = Px + diff;
left = (u16) (left % 65536);
if (self->linearize) if (self->linearize)
linear = self->linearize[left]; linear = self->linearize[left];
else else
@@ -460,6 +470,7 @@ static int parsePred6(ljp* self) {
diff = nextdiff(self,0); diff = nextdiff(self,0);
Px = lastrow[col]; // Use value above for first pixel in row Px = lastrow[col]; // Use value above for first pixel in row
left = Px + diff; left = Px + diff;
left = (u16) (left % 65536);
if (self->linearize) { if (self->linearize) {
if (left>self->linlen) return LJ92_ERROR_CORRUPT; if (left>self->linlen) return LJ92_ERROR_CORRUPT;
linear = self->linearize[left]; linear = self->linearize[left];
@@ -478,6 +489,7 @@ static int parsePred6(ljp* self) {
diff = nextdiff(self,0); diff = nextdiff(self,0);
Px = lastrow[col] + ((left - lastrow[col-1])>>1); Px = lastrow[col] + ((left - lastrow[col-1])>>1);
left = Px + diff; left = Px + diff;
left = (u16) (left % 65536);
//printf("%d %d %d %d %d %x\n",col,diff,left,lastrow[col],lastrow[col-1],&lastrow[col]); //printf("%d %d %d %d %d %x\n",col,diff,left,lastrow[col],lastrow[col-1],&lastrow[col]);
if (self->linearize) { if (self->linearize) {
if (left>self->linlen) return LJ92_ERROR_CORRUPT; if (left>self->linlen) return LJ92_ERROR_CORRUPT;
@@ -556,6 +568,7 @@ static int parseScan(ljp* self) {
} }
diff = nextdiff(self,Px); diff = nextdiff(self,Px);
left = Px + diff; left = Px + diff;
left = (u16) (left % 65536);
//printf("%d %d %d\n",c,diff,left); //printf("%d %d %d\n",c,diff,left);
int linear; int linear;
if (self->linearize) { if (self->linearize) {