Change the signature of the JpegImage constructor, to allow passing in various options directly

This commit is contained in:
Jonas Jenwald 2018-05-16 13:49:01 +02:00
parent 620da6f4df
commit 682672db8e
2 changed files with 13 additions and 9 deletions

View File

@ -63,7 +63,10 @@ let JpegStream = (function JpegStreamClosure() {
if (this.eof) { if (this.eof) {
return; return;
} }
let jpegImage = new JpegImage(); let jpegOptions = {
decodeTransform: undefined,
colorTransform: undefined,
};
// Checking if values need to be transformed before conversion. // Checking if values need to be transformed before conversion.
let decodeArr = this.dict.getArray('Decode', 'D'); let decodeArr = this.dict.getArray('Decode', 'D');
@ -81,16 +84,17 @@ let JpegStream = (function JpegStreamClosure() {
} }
} }
if (transformNeeded) { if (transformNeeded) {
jpegImage.decodeTransform = transform; jpegOptions.decodeTransform = transform;
} }
} }
// Fetching the 'ColorTransform' entry, if it exists. // Fetching the 'ColorTransform' entry, if it exists.
if (isDict(this.params)) { if (isDict(this.params)) {
let colorTransform = this.params.get('ColorTransform'); let colorTransform = this.params.get('ColorTransform');
if (Number.isInteger(colorTransform)) { if (Number.isInteger(colorTransform)) {
jpegImage.colorTransform = colorTransform; jpegOptions.colorTransform = colorTransform;
} }
} }
const jpegImage = new JpegImage(jpegOptions);
jpegImage.parse(this.bytes); jpegImage.parse(this.bytes);
let data = jpegImage.getData(this.drawWidth, this.drawHeight, let data = jpegImage.getData(this.drawWidth, this.drawHeight,

View File

@ -94,9 +94,9 @@ var JpegImage = (function JpegImageClosure() {
var dctSqrt2 = 5793; // sqrt(2) var dctSqrt2 = 5793; // sqrt(2)
var dctSqrt1d2 = 2896; // sqrt(2) / 2 var dctSqrt1d2 = 2896; // sqrt(2) / 2
function JpegImage() { function JpegImage({ decodeTransform = null, colorTransform = -1, } = {}) {
this.decodeTransform = null; this._decodeTransform = decodeTransform;
this.colorTransform = -1; this._colorTransform = colorTransform;
} }
function buildHuffmanTable(codeLengths, values) { function buildHuffmanTable(codeLengths, values) {
@ -1013,7 +1013,7 @@ var JpegImage = (function JpegImageClosure() {
} }
// decodeTransform contains pairs of multiplier (-256..256) and additive // decodeTransform contains pairs of multiplier (-256..256) and additive
var transform = this.decodeTransform; const transform = this._decodeTransform;
if (transform) { if (transform) {
for (i = 0; i < dataLength;) { for (i = 0; i < dataLength;) {
for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) { for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
@ -1030,7 +1030,7 @@ var JpegImage = (function JpegImageClosure() {
return !!this.adobe.transformCode; return !!this.adobe.transformCode;
} }
if (this.numComponents === 3) { if (this.numComponents === 3) {
if (this.colorTransform === 0) { if (this._colorTransform === 0) {
// If the Adobe transform marker is not present and the image // If the Adobe transform marker is not present and the image
// dictionary has a 'ColorTransform' entry, explicitly set to `0`, // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
// then the colours should *not* be transformed. // then the colours should *not* be transformed.
@ -1039,7 +1039,7 @@ var JpegImage = (function JpegImageClosure() {
return true; return true;
} }
// `this.numComponents !== 3` // `this.numComponents !== 3`
if (this.colorTransform === 1) { if (this._colorTransform === 1) {
// If the Adobe transform marker is not present and the image // If the Adobe transform marker is not present and the image
// dictionary has a 'ColorTransform' entry, explicitly set to `1`, // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
// then the colours should be transformed. // then the colours should be transformed.