Convert src/core/jpg.js to use standard classes

*Please note:* Ignoring whitespace-only changes is probably necessary in order to review this.
This commit is contained in:
Jonas Jenwald 2021-05-05 12:43:28 +02:00
parent d0a299713c
commit 69dea39a42

View File

@ -44,7 +44,6 @@ class EOIMarkerError extends BaseException {}
* (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
*/
const JpegImage = (function JpegImageClosure() {
// prettier-ignore
const dctZigZag = new Uint8Array([
0,
@ -73,12 +72,6 @@ const JpegImage = (function JpegImageClosure() {
const dctSqrt2 = 5793; // sqrt(2)
const dctSqrt1d2 = 2896; // sqrt(2) / 2
// eslint-disable-next-line no-shadow
function JpegImage({ decodeTransform = null, colorTransform = -1 } = {}) {
this._decodeTransform = decodeTransform;
this._colorTransform = colorTransform;
}
function buildHuffmanTable(codeLengths, values) {
let k = 0,
i,
@ -335,8 +328,7 @@ const JpegImage = (function JpegImageClosure() {
if (component.blockData[offsetZ]) {
component.blockData[offsetZ] += sign * (readBit() << successive);
} else {
component.blockData[offsetZ] =
successiveACNextValue << successive;
component.blockData[offsetZ] = successiveACNextValue << successive;
successiveACState = 0;
}
break;
@ -749,7 +741,12 @@ const JpegImage = (function JpegImageClosure() {
};
}
JpegImage.prototype = {
class JpegImage {
constructor({ decodeTransform = null, colorTransform = -1 } = {}) {
this._decodeTransform = decodeTransform;
this._colorTransform = colorTransform;
}
parse(data, { dnlScanLines = null } = {}) {
function readDataBlock() {
const length = readUint16(data, offset);
@ -1101,7 +1098,7 @@ const JpegImage = (function JpegImageClosure() {
}
this.numComponents = this.components.length;
return undefined;
},
}
_getLinearizedBlockData(width, height, isSourcePDF = false) {
const scaleX = this.width / width,
@ -1174,7 +1171,7 @@ const JpegImage = (function JpegImageClosure() {
}
}
return data;
},
}
get _isColorConversionNeeded() {
if (this.adobe) {
@ -1206,9 +1203,9 @@ const JpegImage = (function JpegImageClosure() {
return true;
}
return false;
},
}
_convertYccToRgb: function convertYccToRgb(data) {
_convertYccToRgb(data) {
let Y, Cb, Cr;
for (let i = 0, length = data.length; i < length; i += 3) {
Y = data[i];
@ -1219,9 +1216,9 @@ const JpegImage = (function JpegImageClosure() {
data[i + 2] = Y - 226.816 + 1.772 * Cb;
}
return data;
},
}
_convertYcckToRgb: function convertYcckToRgb(data) {
_convertYcckToRgb(data) {
let Y, Cb, Cr, k;
let offset = 0;
for (let i = 0, length = data.length; i < length; i += 4) {
@ -1289,9 +1286,9 @@ const JpegImage = (function JpegImageClosure() {
}
// Ensure that only the converted RGB data is returned.
return data.subarray(0, offset);
},
}
_convertYcckToCmyk: function convertYcckToCmyk(data) {
_convertYcckToCmyk(data) {
let Y, Cb, Cr;
for (let i = 0, length = data.length; i < length; i += 4) {
Y = data[i];
@ -1303,9 +1300,9 @@ const JpegImage = (function JpegImageClosure() {
// K in data[i + 3] is unchanged
}
return data;
},
}
_convertCmykToRgb: function convertCmykToRgb(data) {
_convertCmykToRgb(data) {
let c, m, y, k;
let offset = 0;
for (let i = 0, length = data.length; i < length; i += 4) {
@ -1373,7 +1370,7 @@ const JpegImage = (function JpegImageClosure() {
}
// Ensure that only the converted RGB data is returned.
return data.subarray(0, offset);
},
}
getData({ width, height, forceRGB = false, isSourcePDF = false }) {
if (
@ -1415,10 +1412,7 @@ const JpegImage = (function JpegImageClosure() {
}
}
return data;
},
};
return JpegImage;
})();
}
}
export { JpegImage };