1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #19656 from Snuffleupagus/shorten-MeshStreamReader

Slightly shorten a couple of `MeshStreamReader` methods
This commit is contained in:
Tim van der Meij 2025-03-14 19:50:36 +01:00 committed by GitHub
commit 4b2683ecb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -395,10 +395,9 @@ class MeshStreamReader {
}
readCoordinate() {
const bitsPerCoordinate = this.context.bitsPerCoordinate;
const { bitsPerCoordinate, decode } = this.context;
const xi = this.readBits(bitsPerCoordinate);
const yi = this.readBits(bitsPerCoordinate);
const decode = this.context.decode;
const scale =
bitsPerCoordinate < 32
? 1 / ((1 << bitsPerCoordinate) - 1)
@ -410,23 +409,20 @@ class MeshStreamReader {
}
readComponents() {
const numComps = this.context.numComps;
const bitsPerComponent = this.context.bitsPerComponent;
const { bitsPerComponent, colorFn, colorSpace, decode, numComps } =
this.context;
const scale =
bitsPerComponent < 32
? 1 / ((1 << bitsPerComponent) - 1)
: 2.3283064365386963e-10; // 2 ^ -32
const decode = this.context.decode;
const components = this.tmpCompsBuf;
for (let i = 0, j = 4; i < numComps; i++, j += 2) {
const ci = this.readBits(bitsPerComponent);
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
}
const color = this.tmpCsCompsBuf;
if (this.context.colorFn) {
this.context.colorFn(components, 0, color, 0);
}
return this.context.colorSpace.getRgb(color, 0);
colorFn?.(components, 0, color, 0);
return colorSpace.getRgb(color, 0);
}
}