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,24 +368,29 @@ 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;
while (cnt < t) { int diff;
next = *(u16*)&self->data[ix]; if (t == 16) {
int one = next&0xFF; diff = 1 << 15;
int two = next>>8; } else {
b = (b<<16)|(one<<8)|two; while (cnt < t) {
cnt += 16; next = *(u16*)&self->data[ix];
ix += 2; int one = next&0xFF;
if (one==0xFF) { int two = next>>8;
b >>= 8; b = (b<<16)|(one<<8)|two;
cnt -= 8; cnt += 16;
} else if (two==0xFF) ix++; ix += 2;
} if (one==0xFF) {
cnt -= t; b >>= 8;
int diff = b >> cnt; cnt -= 8;
int vt = 1<<(t-1); } else if (two==0xFF) ix++;
if (diff < vt) { }
vt = (-1 << t) + 1; cnt -= t;
diff += vt; diff = b >> cnt;
int vt = 1<<(t-1);
if (diff < vt) {
vt = (-1 << t) + 1;
diff += vt;
}
} }
keepbitsmask = (1 << cnt)-1; keepbitsmask = (1 << cnt)-1;
self->b = b & keepbitsmask; self->b = b & keepbitsmask;
@@ -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) {