-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lj92: Use zero bits for the diff value for SSSS=16
See A.5 and H.1.2.2 in the JPEG specification: https://www.w3.org/Graphics/JPEG/itu-t81.pdf
- Loading branch information
1 parent
c283c0d
commit 170ec64
Showing
1 changed file
with
30 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,6 +315,9 @@ static int decode(ljp* self) { | |
} | ||
|
||
static int receive(ljp* self,int ssss) { | ||
if (ssss == 16) { | ||
return 1 << 15; | ||
} | ||
int i = 0; | ||
int v = 0; | ||
while (i != ssss) { | ||
|
@@ -366,24 +369,29 @@ inline static int nextdiff(ljp* self) { | |
cnt -= usedbits; | ||
int keepbitsmask = (1 << cnt)-1; | ||
b &= keepbitsmask; | ||
while (cnt < t) { | ||
next = *(u16*)&self->data[ix]; | ||
int one = next&0xFF; | ||
int two = next>>8; | ||
b = (b<<16)|(one<<8)|two; | ||
cnt += 16; | ||
ix += 2; | ||
if (one==0xFF) { | ||
b >>= 8; | ||
cnt -= 8; | ||
} else if (two==0xFF) ix++; | ||
} | ||
cnt -= t; | ||
int diff = b >> cnt; | ||
int vt = 1<<(t-1); | ||
if (diff < vt) { | ||
vt = (-1 << t) + 1; | ||
diff += vt; | ||
int diff; | ||
if (t == 16) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
diff = 1 << 15; | ||
} else { | ||
while (cnt < t) { | ||
next = *(u16*)&self->data[ix]; | ||
int one = next&0xFF; | ||
int two = next>>8; | ||
b = (b<<16)|(one<<8)|two; | ||
cnt += 16; | ||
ix += 2; | ||
if (one==0xFF) { | ||
b >>= 8; | ||
cnt -= 8; | ||
} else if (two==0xFF) ix++; | ||
} | ||
cnt -= t; | ||
diff = b >> cnt; | ||
int vt = 1<<(t-1); | ||
if (diff < vt) { | ||
vt = (-1 << t) + 1; | ||
diff += vt; | ||
} | ||
} | ||
keepbitsmask = (1 << cnt)-1; | ||
self->b = b & keepbitsmask; | ||
|
@@ -1068,7 +1076,6 @@ int writeBody(lje* self) { | |
int huffcode = self->huffsym[ssss]; | ||
int huffenc = self->huffenc[huffcode]; | ||
int huffbits = self->huffbits[huffcode]; | ||
bitcount += huffbits + ssss; | ||
|
||
int vt = ssss>0?(1<<(ssss-1)):0; | ||
//printf("%d %d %d %d\n",rows[1][col],Px,diff,Px+diff); | ||
|
@@ -1099,7 +1106,10 @@ int writeBody(lje* self) { | |
} | ||
} | ||
// Write the rest of the bits for the value | ||
|
||
if (ssss == 16) { | ||
// Diff values (always -32678) for SSSS=16 are encoded with 0 bits | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SimonSegerblomRex
Author
Contributor
|
||
ssss = 0; | ||
} | ||
while (ssss>0) { | ||
int usebits = ssss>nextbits?nextbits:ssss; | ||
// Add top usebits from huffval to next usebits of nextbits | ||
|
@@ -1207,4 +1217,3 @@ int lj92_encode(uint16_t* image, int width, int height, int bitdepth, | |
return ret; | ||
} | ||
|
||
|
If
t == 16
, the indexingself->sssshist[t]++;
a couple of lines earlier is out-of-bounds:MLV-App/src/mlv/liblj92/lj92.c
Line 52 in f70c45c
MLV-App/src/mlv/liblj92/lj92.c
Lines 367 to 373 in f70c45c