Scan all buffered data looking for JPEG end
This is much more efficient than looking at two bytes at a time.
This commit is contained in:
@@ -119,18 +119,33 @@ export default class JPEGDecoder {
|
|||||||
let extra = 0;
|
let extra = 0;
|
||||||
if (type === 0xDA) {
|
if (type === 0xDA) {
|
||||||
// start of scan
|
// start of scan
|
||||||
extra += 2;
|
if (sock.rQwait("JPEG", length-2 + 2, 4)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let len = sock.rQlen();
|
||||||
|
let data = sock.rQpeekBytes(len, false);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (sock.rQwait("JPEG", length-2+extra, 4)) {
|
let idx = data.indexOf(0xFF, length-2+extra);
|
||||||
|
if (idx === -1) {
|
||||||
|
sock.rQwait("JPEG", Infinity, 4);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let data = sock.rQpeekBytes(length-2+extra, false);
|
|
||||||
if (data.at(-2) === 0xFF && data.at(-1) !== 0x00 &&
|
if (idx === len-1) {
|
||||||
!(data.at(-1) >= 0xD0 && data.at(-1) <= 0xD7)) {
|
sock.rQwait("JPEG", Infinity, 4);
|
||||||
extra -= 2;
|
return null;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
extra++;
|
|
||||||
|
if (data.at(idx+1) === 0x00 ||
|
||||||
|
(data.at(idx+1) >= 0xD0 && data.at(idx+1) <= 0xD7)) {
|
||||||
|
extra = idx+2 - (length-2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
extra = idx - (length-2);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user