2014-03-27 17:08:32 +01:00
|
|
|
/* Copyright 2014 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2012-08-23 16:12:33 -05:00
|
|
|
|
2020-01-02 12:00:16 +01:00
|
|
|
import { assert, BaseException, warn } from "../shared/util.js";
|
2020-01-07 20:22:14 +01:00
|
|
|
import { readUint16 } from "./core_utils.js";
|
2017-06-28 13:51:31 -07:00
|
|
|
|
2019-10-01 13:10:14 +02:00
|
|
|
class JpegError extends BaseException {
|
|
|
|
constructor(msg) {
|
|
|
|
super(`JPEG error: ${msg}`);
|
2017-06-28 13:51:31 -07:00
|
|
|
}
|
2019-10-01 13:10:14 +02:00
|
|
|
}
|
2017-06-28 13:51:31 -07:00
|
|
|
|
2019-10-01 13:10:14 +02:00
|
|
|
class DNLMarkerError extends BaseException {
|
|
|
|
constructor(message, scanLines) {
|
|
|
|
super(message);
|
2018-02-01 20:43:01 +01:00
|
|
|
this.scanLines = scanLines;
|
|
|
|
}
|
2019-10-01 13:10:14 +02:00
|
|
|
}
|
2018-02-01 20:43:01 +01:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
class EOIMarkerError extends BaseException {}
|
2018-05-16 14:26:12 +02:00
|
|
|
|
2016-09-03 12:17:00 +02:00
|
|
|
/**
|
|
|
|
* This code was forked from https://github.com/notmasteryet/jpgjs.
|
|
|
|
* The original version was created by GitHub user notmasteryet.
|
|
|
|
*
|
|
|
|
* - The JPEG specification can be found in the ITU CCITT Recommendation T.81
|
|
|
|
* (www.w3.org/Graphics/JPEG/itu-t81.pdf)
|
|
|
|
* - The JFIF specification can be found in the JPEG File Interchange Format
|
|
|
|
* (www.w3.org/Graphics/JPEG/jfif3.pdf)
|
|
|
|
* - The Adobe Application-Specific JPEG markers in the
|
|
|
|
* Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
|
|
|
|
* (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
|
|
|
|
*/
|
2011-11-15 15:08:13 -08:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
const JpegImage = (function JpegImageClosure() {
|
2019-12-25 15:54:34 +01:00
|
|
|
// prettier-ignore
|
2021-05-05 12:35:33 +02:00
|
|
|
const dctZigZag = new Uint8Array([
|
2011-11-22 09:32:20 -08:00
|
|
|
0,
|
|
|
|
1, 8,
|
|
|
|
16, 9, 2,
|
|
|
|
3, 10, 17, 24,
|
|
|
|
32, 25, 18, 11, 4,
|
|
|
|
5, 12, 19, 26, 33, 40,
|
|
|
|
48, 41, 34, 27, 20, 13, 6,
|
|
|
|
7, 14, 21, 28, 35, 42, 49, 56,
|
|
|
|
57, 50, 43, 36, 29, 22, 15,
|
|
|
|
23, 30, 37, 44, 51, 58,
|
|
|
|
59, 52, 45, 38, 31,
|
|
|
|
39, 46, 53, 60,
|
|
|
|
61, 54, 47,
|
|
|
|
55, 62,
|
|
|
|
63
|
|
|
|
]);
|
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
const dctCos1 = 4017; // cos(pi/16)
|
|
|
|
const dctSin1 = 799; // sin(pi/16)
|
|
|
|
const dctCos3 = 3406; // cos(3*pi/16)
|
|
|
|
const dctSin3 = 2276; // sin(3*pi/16)
|
|
|
|
const dctCos6 = 1567; // cos(6*pi/16)
|
|
|
|
const dctSin6 = 3784; // sin(6*pi/16)
|
|
|
|
const dctSqrt2 = 5793; // sqrt(2)
|
|
|
|
const dctSqrt1d2 = 2896; // sqrt(2) / 2
|
2011-11-22 09:32:20 -08:00
|
|
|
|
2020-03-25 10:15:50 +01:00
|
|
|
// eslint-disable-next-line no-shadow
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
function JpegImage({ decodeTransform = null, colorTransform = -1 } = {}) {
|
2018-05-16 13:49:01 +02:00
|
|
|
this._decodeTransform = decodeTransform;
|
|
|
|
this._colorTransform = colorTransform;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function buildHuffmanTable(codeLengths, values) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let k = 0,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
i,
|
|
|
|
j,
|
|
|
|
length = 16;
|
2014-03-27 17:08:32 +01:00
|
|
|
while (length > 0 && !codeLengths[length - 1]) {
|
2011-11-15 15:08:13 -08:00
|
|
|
length--;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2021-05-05 12:36:52 +02:00
|
|
|
const code = [{ children: [], index: 0 }];
|
2021-05-05 12:35:33 +02:00
|
|
|
let p = code[0],
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
q;
|
2011-11-15 15:08:13 -08:00
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
for (j = 0; j < codeLengths[i]; j++) {
|
|
|
|
p = code.pop();
|
|
|
|
p.children[p.index] = values[k];
|
|
|
|
while (p.index > 0) {
|
|
|
|
p = code.pop();
|
|
|
|
}
|
|
|
|
p.index++;
|
|
|
|
code.push(p);
|
|
|
|
while (code.length <= i) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
code.push((q = { children: [], index: 0 }));
|
2011-11-15 15:08:13 -08:00
|
|
|
p.children[p.index] = q.children;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
if (i + 1 < length) {
|
|
|
|
// p here points to last code
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
code.push((q = { children: [], index: 0 }));
|
2011-11-15 15:08:13 -08:00
|
|
|
p.children[p.index] = q.children;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return code[0].children;
|
|
|
|
}
|
|
|
|
|
2014-03-20 18:01:28 -05:00
|
|
|
function getBlockBufferOffset(component, row, col) {
|
2014-03-21 09:16:02 -05:00
|
|
|
return 64 * ((component.blocksPerLine + 1) * row + col);
|
2014-03-20 18:01:28 -05:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
function decodeScan(
|
|
|
|
data,
|
|
|
|
offset,
|
|
|
|
frame,
|
|
|
|
components,
|
|
|
|
resetInterval,
|
|
|
|
spectralStart,
|
|
|
|
spectralEnd,
|
|
|
|
successivePrev,
|
|
|
|
successive,
|
|
|
|
parseDNLMarker = false
|
|
|
|
) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const mcusPerLine = frame.mcusPerLine;
|
|
|
|
const progressive = frame.progressive;
|
2011-11-15 15:08:13 -08:00
|
|
|
|
2020-04-17 15:40:02 +02:00
|
|
|
const startOffset = offset;
|
|
|
|
let bitsData = 0,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
bitsCount = 0;
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
function readBit() {
|
|
|
|
if (bitsCount > 0) {
|
|
|
|
bitsCount--;
|
|
|
|
return (bitsData >> bitsCount) & 1;
|
|
|
|
}
|
|
|
|
bitsData = data[offset++];
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (bitsData === 0xff) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const nextByte = data[offset++];
|
2011-11-15 15:08:13 -08:00
|
|
|
if (nextByte) {
|
2020-01-18 12:53:40 +01:00
|
|
|
if (nextByte === /* DNL = */ 0xdc && parseDNLMarker) {
|
2020-01-07 20:22:14 +01:00
|
|
|
offset += 2; // Skip marker length.
|
|
|
|
|
|
|
|
const scanLines = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2018-02-01 20:43:01 +01:00
|
|
|
if (scanLines > 0 && scanLines !== frame.scanLines) {
|
|
|
|
throw new DNLMarkerError(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
"Found DNL marker (0xFFDC) while parsing scan data",
|
|
|
|
scanLines
|
|
|
|
);
|
2018-02-01 20:43:01 +01:00
|
|
|
}
|
2020-01-18 12:53:40 +01:00
|
|
|
} else if (nextByte === /* EOI = */ 0xd9) {
|
|
|
|
if (parseDNLMarker) {
|
|
|
|
// NOTE: only 8-bit JPEG images are supported in this decoder.
|
2020-07-06 13:02:41 +02:00
|
|
|
const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
|
2020-01-18 12:53:40 +01:00
|
|
|
// Heuristic to attempt to handle corrupt JPEG images with too
|
|
|
|
// large `scanLines` parameter, by falling back to the currently
|
2020-07-06 13:02:41 +02:00
|
|
|
// parsed number of scanLines when it's at least (approximately)
|
|
|
|
// one order of magnitude smaller than expected (fixes
|
|
|
|
// issue10880.pdf and issue10989.pdf).
|
|
|
|
if (
|
|
|
|
maybeScanLines > 0 &&
|
|
|
|
Math.round(frame.scanLines / maybeScanLines) >= 10
|
|
|
|
) {
|
2020-01-18 12:53:40 +01:00
|
|
|
throw new DNLMarkerError(
|
|
|
|
"Found EOI marker (0xFFD9) while parsing scan data, " +
|
|
|
|
"possibly caused by incorrect `scanLines` parameter",
|
|
|
|
maybeScanLines
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 14:26:12 +02:00
|
|
|
throw new EOIMarkerError(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
"Found EOI marker (0xFFD9) while parsing scan data"
|
|
|
|
);
|
2018-02-01 20:43:01 +01:00
|
|
|
}
|
2017-06-28 13:51:31 -07:00
|
|
|
throw new JpegError(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
`unexpected marker ${((bitsData << 8) | nextByte).toString(16)}`
|
|
|
|
);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
// unstuff 0
|
|
|
|
}
|
|
|
|
bitsCount = 7;
|
|
|
|
return bitsData >>> 7;
|
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
function decodeHuffman(tree) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let node = tree;
|
2014-10-30 09:18:52 +01:00
|
|
|
while (true) {
|
|
|
|
node = node[readBit()];
|
Make the `decodeHuffman` function, in `src/core/jpg.js`, slightly more efficient
Rather than repeating the `typeof node` check twice, we can use a `switch` statement instead.
This patch was tested using the PDF file from issue 3809, i.e. https://web.archive.org/web/20140801150504/http://vs.twonky.dk/invitation.pdf, with the following manifest file:
```
[
{ "id": "issue3809",
"file": "../web/pdfs/issue3809.pdf",
"md5": "",
"rounds": 50,
"type": "eq"
}
]
```
which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat | Count | Baseline(ms) | Current(ms) | +/- | % | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall | 50 | 12537 | 12451 | -86 | -0.69 | faster
Firefox | Page Request | 50 | 5 | 5 | 0 | 0.77 |
Firefox | Rendering | 50 | 12532 | 12446 | -86 | -0.69 | faster
```
2020-01-28 14:23:58 +01:00
|
|
|
switch (typeof node) {
|
|
|
|
case "number":
|
|
|
|
return node;
|
|
|
|
case "object":
|
|
|
|
continue;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
Make the `decodeHuffman` function, in `src/core/jpg.js`, slightly more efficient
Rather than repeating the `typeof node` check twice, we can use a `switch` statement instead.
This patch was tested using the PDF file from issue 3809, i.e. https://web.archive.org/web/20140801150504/http://vs.twonky.dk/invitation.pdf, with the following manifest file:
```
[
{ "id": "issue3809",
"file": "../web/pdfs/issue3809.pdf",
"md5": "",
"rounds": 50,
"type": "eq"
}
]
```
which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat | Count | Baseline(ms) | Current(ms) | +/- | % | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall | 50 | 12537 | 12451 | -86 | -0.69 | faster
Firefox | Page Request | 50 | 5 | 5 | 0 | 0.77 |
Firefox | Rendering | 50 | 12532 | 12446 | -86 | -0.69 | faster
```
2020-01-28 14:23:58 +01:00
|
|
|
throw new JpegError("invalid huffman sequence");
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
function receive(length) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let n = 0;
|
2011-11-15 15:08:13 -08:00
|
|
|
while (length > 0) {
|
2014-10-30 09:18:52 +01:00
|
|
|
n = (n << 1) | readBit();
|
2011-11-15 15:08:13 -08:00
|
|
|
length--;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
function receiveAndExtend(length) {
|
2014-06-05 12:07:04 +02:00
|
|
|
if (length === 1) {
|
|
|
|
return readBit() === 1 ? 1 : -1;
|
|
|
|
}
|
2021-05-05 12:35:33 +02:00
|
|
|
const n = receive(length);
|
2014-03-27 17:08:32 +01:00
|
|
|
if (n >= 1 << (length - 1)) {
|
2011-11-15 15:08:13 -08:00
|
|
|
return n;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
return n + (-1 << length) + 1;
|
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2020-03-23 17:04:47 +01:00
|
|
|
function decodeBaseline(component, blockOffset) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const t = decodeHuffman(component.huffmanTableDC);
|
|
|
|
const diff = t === 0 ? 0 : receiveAndExtend(t);
|
2020-03-23 17:04:47 +01:00
|
|
|
component.blockData[blockOffset] = component.pred += diff;
|
2021-05-05 12:35:33 +02:00
|
|
|
let k = 1;
|
2011-11-15 15:08:13 -08:00
|
|
|
while (k < 64) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const rs = decodeHuffman(component.huffmanTableAC);
|
|
|
|
const s = rs & 15,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
r = rs >> 4;
|
2011-11-15 15:08:13 -08:00
|
|
|
if (s === 0) {
|
2014-03-27 17:08:32 +01:00
|
|
|
if (r < 15) {
|
2011-11-15 15:08:13 -08:00
|
|
|
break;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
k += 16;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k += r;
|
2021-05-05 12:35:33 +02:00
|
|
|
const z = dctZigZag[k];
|
2020-03-23 17:04:47 +01:00
|
|
|
component.blockData[blockOffset + z] = receiveAndExtend(s);
|
2011-11-15 15:08:13 -08:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2020-03-23 17:04:47 +01:00
|
|
|
function decodeDCFirst(component, blockOffset) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const t = decodeHuffman(component.huffmanTableDC);
|
|
|
|
const diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
|
2020-03-23 17:04:47 +01:00
|
|
|
component.blockData[blockOffset] = component.pred += diff;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2020-03-23 17:04:47 +01:00
|
|
|
function decodeDCSuccessive(component, blockOffset) {
|
|
|
|
component.blockData[blockOffset] |= readBit() << successive;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
let eobrun = 0;
|
2020-03-23 17:04:47 +01:00
|
|
|
function decodeACFirst(component, blockOffset) {
|
2011-11-15 15:08:13 -08:00
|
|
|
if (eobrun > 0) {
|
|
|
|
eobrun--;
|
|
|
|
return;
|
|
|
|
}
|
2021-05-05 12:36:52 +02:00
|
|
|
let k = spectralStart;
|
|
|
|
const e = spectralEnd;
|
2011-11-15 15:08:13 -08:00
|
|
|
while (k <= e) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const rs = decodeHuffman(component.huffmanTableAC);
|
|
|
|
const s = rs & 15,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
r = rs >> 4;
|
2011-11-15 15:08:13 -08:00
|
|
|
if (s === 0) {
|
|
|
|
if (r < 15) {
|
|
|
|
eobrun = receive(r) + (1 << r) - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
k += 16;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k += r;
|
2021-05-05 12:35:33 +02:00
|
|
|
const z = dctZigZag[k];
|
2020-03-23 17:04:47 +01:00
|
|
|
component.blockData[blockOffset + z] =
|
2014-03-27 17:08:32 +01:00
|
|
|
receiveAndExtend(s) * (1 << successive);
|
2011-11-15 15:08:13 -08:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 09:16:02 -05:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
let successiveACState = 0,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
successiveACNextValue;
|
2020-03-23 17:04:47 +01:00
|
|
|
function decodeACSuccessive(component, blockOffset) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let k = spectralStart;
|
|
|
|
const e = spectralEnd;
|
|
|
|
let r = 0;
|
|
|
|
let s;
|
|
|
|
let rs;
|
2011-11-15 15:08:13 -08:00
|
|
|
while (k <= e) {
|
2020-03-23 17:04:47 +01:00
|
|
|
const offsetZ = blockOffset + dctZigZag[k];
|
2020-01-24 09:48:21 +01:00
|
|
|
const sign = component.blockData[offsetZ] < 0 ? -1 : 1;
|
2011-11-15 15:08:13 -08:00
|
|
|
switch (successiveACState) {
|
2017-12-29 14:37:20 +01:00
|
|
|
case 0: // initial state
|
|
|
|
rs = decodeHuffman(component.huffmanTableAC);
|
|
|
|
s = rs & 15;
|
|
|
|
r = rs >> 4;
|
|
|
|
if (s === 0) {
|
|
|
|
if (r < 15) {
|
|
|
|
eobrun = receive(r) + (1 << r);
|
|
|
|
successiveACState = 4;
|
|
|
|
} else {
|
|
|
|
r = 16;
|
|
|
|
successiveACState = 1;
|
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
} else {
|
2017-12-29 14:37:20 +01:00
|
|
|
if (s !== 1) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError("invalid ACn encoding");
|
2017-12-29 14:37:20 +01:00
|
|
|
}
|
|
|
|
successiveACNextValue = receiveAndExtend(s);
|
|
|
|
successiveACState = r ? 2 : 3;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2017-12-29 14:37:20 +01:00
|
|
|
continue;
|
|
|
|
case 1: // skipping r zero items
|
|
|
|
case 2:
|
2017-12-29 14:39:29 +01:00
|
|
|
if (component.blockData[offsetZ]) {
|
|
|
|
component.blockData[offsetZ] += sign * (readBit() << successive);
|
2017-12-29 14:37:20 +01:00
|
|
|
} else {
|
|
|
|
r--;
|
|
|
|
if (r === 0) {
|
|
|
|
successiveACState = successiveACState === 2 ? 3 : 0;
|
|
|
|
}
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2017-12-29 14:37:20 +01:00
|
|
|
break;
|
|
|
|
case 3: // set value for a zero item
|
2017-12-29 14:39:29 +01:00
|
|
|
if (component.blockData[offsetZ]) {
|
|
|
|
component.blockData[offsetZ] += sign * (readBit() << successive);
|
2017-12-29 14:37:20 +01:00
|
|
|
} else {
|
2017-12-29 14:39:29 +01:00
|
|
|
component.blockData[offsetZ] =
|
2017-12-29 14:37:20 +01:00
|
|
|
successiveACNextValue << successive;
|
|
|
|
successiveACState = 0;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2017-12-29 14:37:20 +01:00
|
|
|
break;
|
|
|
|
case 4: // eob
|
2017-12-29 14:39:29 +01:00
|
|
|
if (component.blockData[offsetZ]) {
|
|
|
|
component.blockData[offsetZ] += sign * (readBit() << successive);
|
2017-12-29 14:37:20 +01:00
|
|
|
}
|
|
|
|
break;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
if (successiveACState === 4) {
|
|
|
|
eobrun--;
|
2014-03-27 17:08:32 +01:00
|
|
|
if (eobrun === 0) {
|
2011-11-15 15:08:13 -08:00
|
|
|
successiveACState = 0;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2020-01-18 12:53:40 +01:00
|
|
|
let blockRow = 0;
|
2011-11-15 15:08:13 -08:00
|
|
|
function decodeMcu(component, decode, mcu, row, col) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const mcuRow = (mcu / mcusPerLine) | 0;
|
|
|
|
const mcuCol = mcu % mcusPerLine;
|
2020-01-18 12:53:40 +01:00
|
|
|
blockRow = mcuRow * component.v + row;
|
2021-05-05 12:35:33 +02:00
|
|
|
const blockCol = mcuCol * component.h + col;
|
2020-03-23 17:04:47 +01:00
|
|
|
const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
|
|
|
|
decode(component, blockOffset);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
function decodeBlock(component, decode, mcu) {
|
2020-01-18 12:53:40 +01:00
|
|
|
blockRow = (mcu / component.blocksPerLine) | 0;
|
2021-05-05 12:35:33 +02:00
|
|
|
const blockCol = mcu % component.blocksPerLine;
|
2020-03-23 17:04:47 +01:00
|
|
|
const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
|
|
|
|
decode(component, blockOffset);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
const componentsLength = components.length;
|
|
|
|
let component, i, j, k, n;
|
|
|
|
let decodeFn;
|
2011-11-15 15:08:13 -08:00
|
|
|
if (progressive) {
|
2014-03-27 17:08:32 +01:00
|
|
|
if (spectralStart === 0) {
|
2011-11-15 15:08:13 -08:00
|
|
|
decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
|
2014-03-27 17:08:32 +01:00
|
|
|
} else {
|
2011-11-15 15:08:13 -08:00
|
|
|
decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
} else {
|
|
|
|
decodeFn = decodeBaseline;
|
|
|
|
}
|
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
let mcu = 0,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
fileMarker;
|
2021-05-05 12:35:33 +02:00
|
|
|
let mcuExpected;
|
2014-08-01 22:43:55 +02:00
|
|
|
if (componentsLength === 1) {
|
2011-11-15 15:08:13 -08:00
|
|
|
mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
|
|
|
|
} else {
|
|
|
|
mcuExpected = mcusPerLine * frame.mcusPerColumn;
|
|
|
|
}
|
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
let h, v;
|
2020-04-12 12:27:11 +02:00
|
|
|
while (mcu <= mcuExpected) {
|
2011-11-15 15:08:13 -08:00
|
|
|
// reset interval stuff
|
2021-05-05 12:35:33 +02:00
|
|
|
const mcuToRead = resetInterval
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
? Math.min(mcuExpected - mcu, resetInterval)
|
|
|
|
: mcuExpected;
|
2011-11-15 15:08:13 -08:00
|
|
|
|
2020-04-12 12:27:11 +02:00
|
|
|
// The `mcuToRead === 0` case should only occur when all of the expected
|
|
|
|
// MCU data has been already parsed, i.e. when `mcu === mcuExpected`, but
|
|
|
|
// some corrupt JPEG images contain more data than intended and we thus
|
|
|
|
// want to skip over any extra RSTx markers below (fixes issue11794.pdf).
|
|
|
|
if (mcuToRead > 0) {
|
|
|
|
for (i = 0; i < componentsLength; i++) {
|
|
|
|
components[i].pred = 0;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2020-04-12 12:27:11 +02:00
|
|
|
eobrun = 0;
|
|
|
|
|
|
|
|
if (componentsLength === 1) {
|
|
|
|
component = components[0];
|
|
|
|
for (n = 0; n < mcuToRead; n++) {
|
|
|
|
decodeBlock(component, decodeFn, mcu);
|
|
|
|
mcu++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (n = 0; n < mcuToRead; n++) {
|
|
|
|
for (i = 0; i < componentsLength; i++) {
|
|
|
|
component = components[i];
|
|
|
|
h = component.h;
|
|
|
|
v = component.v;
|
|
|
|
for (j = 0; j < v; j++) {
|
|
|
|
for (k = 0; k < h; k++) {
|
|
|
|
decodeMcu(component, decodeFn, mcu, j, k);
|
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
}
|
2020-04-12 12:27:11 +02:00
|
|
|
mcu++;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find marker
|
|
|
|
bitsCount = 0;
|
2017-03-23 16:08:59 +01:00
|
|
|
fileMarker = findNextFileMarker(data, offset);
|
2019-08-08 10:31:48 +02:00
|
|
|
if (!fileMarker) {
|
2020-04-11 15:49:25 +02:00
|
|
|
break; // Reached the end of the image data without finding any marker.
|
|
|
|
}
|
|
|
|
if (fileMarker.invalid) {
|
2019-08-08 10:31:48 +02:00
|
|
|
// Some bad images seem to pad Scan blocks with e.g. zero bytes, skip
|
|
|
|
// past those to attempt to find a valid marker (fixes issue4090.pdf).
|
2020-04-12 12:27:11 +02:00
|
|
|
const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
warn(
|
2020-04-12 12:27:11 +02:00
|
|
|
`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
);
|
2017-03-23 16:08:59 +01:00
|
|
|
offset = fileMarker.offset;
|
2016-09-22 10:11:27 +02:00
|
|
|
}
|
2020-04-11 15:49:25 +02:00
|
|
|
if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
// RSTx
|
2011-11-15 15:08:13 -08:00
|
|
|
offset += 2;
|
2014-03-21 09:16:02 -05:00
|
|
|
} else {
|
2011-11-15 15:08:13 -08:00
|
|
|
break;
|
2014-03-21 09:16:02 -05:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return offset - startOffset;
|
|
|
|
}
|
|
|
|
|
2014-03-20 18:01:28 -05:00
|
|
|
// A port of poppler's IDCT method which in turn is taken from:
|
|
|
|
// Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
|
2014-03-27 17:08:32 +01:00
|
|
|
// 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
|
2014-03-20 18:01:28 -05:00
|
|
|
// IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
|
|
|
|
// 988-991.
|
|
|
|
function quantizeAndInverse(component, blockBufferOffset, p) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const qt = component.quantizationTable,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
blockData = component.blockData;
|
2021-05-05 12:35:33 +02:00
|
|
|
let v0, v1, v2, v3, v4, v5, v6, v7;
|
|
|
|
let p0, p1, p2, p3, p4, p5, p6, p7;
|
|
|
|
let t;
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2016-06-13 13:29:32 +02:00
|
|
|
if (!qt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError("missing required Quantization Table.");
|
2016-06-13 13:29:32 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 18:01:28 -05:00
|
|
|
// inverse DCT on rows
|
2021-05-05 12:35:33 +02:00
|
|
|
for (let row = 0; row < 64; row += 8) {
|
2014-06-17 10:09:17 +02:00
|
|
|
// gather block data
|
|
|
|
p0 = blockData[blockBufferOffset + row];
|
|
|
|
p1 = blockData[blockBufferOffset + row + 1];
|
|
|
|
p2 = blockData[blockBufferOffset + row + 2];
|
|
|
|
p3 = blockData[blockBufferOffset + row + 3];
|
|
|
|
p4 = blockData[blockBufferOffset + row + 4];
|
|
|
|
p5 = blockData[blockBufferOffset + row + 5];
|
|
|
|
p6 = blockData[blockBufferOffset + row + 6];
|
|
|
|
p7 = blockData[blockBufferOffset + row + 7];
|
|
|
|
|
|
|
|
// dequant p0
|
|
|
|
p0 *= qt[row];
|
2014-03-20 18:01:28 -05:00
|
|
|
|
|
|
|
// check for all-zero AC coefficients
|
2014-06-17 10:09:17 +02:00
|
|
|
if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
|
|
|
|
t = (dctSqrt2 * p0 + 512) >> 10;
|
|
|
|
p[row] = t;
|
|
|
|
p[row + 1] = t;
|
|
|
|
p[row + 2] = t;
|
|
|
|
p[row + 3] = t;
|
|
|
|
p[row + 4] = t;
|
|
|
|
p[row + 5] = t;
|
|
|
|
p[row + 6] = t;
|
|
|
|
p[row + 7] = t;
|
2014-03-20 18:01:28 -05:00
|
|
|
continue;
|
2011-11-22 09:32:20 -08:00
|
|
|
}
|
2014-06-17 10:09:17 +02:00
|
|
|
// dequant p1 ... p7
|
|
|
|
p1 *= qt[row + 1];
|
|
|
|
p2 *= qt[row + 2];
|
|
|
|
p3 *= qt[row + 3];
|
|
|
|
p4 *= qt[row + 4];
|
|
|
|
p5 *= qt[row + 5];
|
|
|
|
p6 *= qt[row + 6];
|
|
|
|
p7 *= qt[row + 7];
|
2011-11-22 09:32:20 -08:00
|
|
|
|
2014-03-20 18:01:28 -05:00
|
|
|
// stage 4
|
2014-06-17 10:09:17 +02:00
|
|
|
v0 = (dctSqrt2 * p0 + 128) >> 8;
|
|
|
|
v1 = (dctSqrt2 * p4 + 128) >> 8;
|
|
|
|
v2 = p2;
|
|
|
|
v3 = p6;
|
|
|
|
v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
|
|
|
|
v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
|
|
|
|
v5 = p3 << 4;
|
|
|
|
v6 = p5 << 4;
|
2014-03-20 18:01:28 -05:00
|
|
|
|
|
|
|
// stage 3
|
|
|
|
v0 = (v0 + v1 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v1 = v0 - v1;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
|
2014-03-20 18:01:28 -05:00
|
|
|
v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
|
|
|
|
v3 = t;
|
|
|
|
v4 = (v4 + v6 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v6 = v4 - v6;
|
|
|
|
v7 = (v7 + v5 + 1) >> 1;
|
|
|
|
v5 = v7 - v5;
|
2014-03-20 18:01:28 -05:00
|
|
|
|
|
|
|
// stage 2
|
|
|
|
v0 = (v0 + v3 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v3 = v0 - v3;
|
2014-03-20 18:01:28 -05:00
|
|
|
v1 = (v1 + v2 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v2 = v1 - v2;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
|
2014-03-20 18:01:28 -05:00
|
|
|
v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
|
|
|
|
v7 = t;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
|
2014-03-20 18:01:28 -05:00
|
|
|
v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
|
|
|
|
v6 = t;
|
|
|
|
|
|
|
|
// stage 1
|
2014-06-17 10:09:17 +02:00
|
|
|
p[row] = v0 + v7;
|
|
|
|
p[row + 7] = v0 - v7;
|
|
|
|
p[row + 1] = v1 + v6;
|
|
|
|
p[row + 6] = v1 - v6;
|
|
|
|
p[row + 2] = v2 + v5;
|
|
|
|
p[row + 5] = v2 - v5;
|
|
|
|
p[row + 3] = v3 + v4;
|
|
|
|
p[row + 4] = v3 - v4;
|
2014-03-20 18:01:28 -05:00
|
|
|
}
|
2011-11-22 09:32:20 -08:00
|
|
|
|
2014-03-20 18:01:28 -05:00
|
|
|
// inverse DCT on columns
|
2021-05-05 12:35:33 +02:00
|
|
|
for (let col = 0; col < 8; ++col) {
|
2014-06-17 10:09:17 +02:00
|
|
|
p0 = p[col];
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
p1 = p[col + 8];
|
2014-06-17 10:09:17 +02:00
|
|
|
p2 = p[col + 16];
|
|
|
|
p3 = p[col + 24];
|
|
|
|
p4 = p[col + 32];
|
|
|
|
p5 = p[col + 40];
|
|
|
|
p6 = p[col + 48];
|
|
|
|
p7 = p[col + 56];
|
2014-03-20 18:01:28 -05:00
|
|
|
|
|
|
|
// check for all-zero AC coefficients
|
2014-06-17 10:09:17 +02:00
|
|
|
if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
|
|
|
|
t = (dctSqrt2 * p0 + 8192) >> 14;
|
2020-01-12 19:47:13 +01:00
|
|
|
// Convert to 8-bit.
|
|
|
|
if (t < -2040) {
|
|
|
|
t = 0;
|
|
|
|
} else if (t >= 2024) {
|
|
|
|
t = 255;
|
|
|
|
} else {
|
|
|
|
t = (t + 2056) >> 4;
|
|
|
|
}
|
2014-06-17 10:09:17 +02:00
|
|
|
blockData[blockBufferOffset + col] = t;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
blockData[blockBufferOffset + col + 8] = t;
|
2014-06-17 10:09:17 +02:00
|
|
|
blockData[blockBufferOffset + col + 16] = t;
|
|
|
|
blockData[blockBufferOffset + col + 24] = t;
|
|
|
|
blockData[blockBufferOffset + col + 32] = t;
|
|
|
|
blockData[blockBufferOffset + col + 40] = t;
|
|
|
|
blockData[blockBufferOffset + col + 48] = t;
|
|
|
|
blockData[blockBufferOffset + col + 56] = t;
|
2014-03-20 18:01:28 -05:00
|
|
|
continue;
|
2011-11-22 09:32:20 -08:00
|
|
|
}
|
|
|
|
|
2014-03-20 18:01:28 -05:00
|
|
|
// stage 4
|
2014-06-17 10:09:17 +02:00
|
|
|
v0 = (dctSqrt2 * p0 + 2048) >> 12;
|
|
|
|
v1 = (dctSqrt2 * p4 + 2048) >> 12;
|
|
|
|
v2 = p2;
|
|
|
|
v3 = p6;
|
|
|
|
v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
|
|
|
|
v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
|
|
|
|
v5 = p3;
|
|
|
|
v6 = p5;
|
2014-03-20 18:01:28 -05:00
|
|
|
|
|
|
|
// stage 3
|
2014-06-17 10:09:17 +02:00
|
|
|
// Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
|
2014-10-30 10:37:21 +01:00
|
|
|
// converting to UInt8 range later.
|
2014-06-17 10:09:17 +02:00
|
|
|
v0 = ((v0 + v1 + 1) >> 1) + 4112;
|
|
|
|
v1 = v0 - v1;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
|
2014-03-20 18:01:28 -05:00
|
|
|
v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
|
|
|
|
v3 = t;
|
|
|
|
v4 = (v4 + v6 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v6 = v4 - v6;
|
|
|
|
v7 = (v7 + v5 + 1) >> 1;
|
|
|
|
v5 = v7 - v5;
|
2014-03-20 18:01:28 -05:00
|
|
|
|
|
|
|
// stage 2
|
|
|
|
v0 = (v0 + v3 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v3 = v0 - v3;
|
2014-03-20 18:01:28 -05:00
|
|
|
v1 = (v1 + v2 + 1) >> 1;
|
2014-06-17 10:09:17 +02:00
|
|
|
v2 = v1 - v2;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
|
2014-03-20 18:01:28 -05:00
|
|
|
v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
|
|
|
|
v7 = t;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
|
2014-03-20 18:01:28 -05:00
|
|
|
v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
|
|
|
|
v6 = t;
|
|
|
|
|
|
|
|
// stage 1
|
2014-06-17 10:09:17 +02:00
|
|
|
p0 = v0 + v7;
|
|
|
|
p7 = v0 - v7;
|
|
|
|
p1 = v1 + v6;
|
|
|
|
p6 = v1 - v6;
|
|
|
|
p2 = v2 + v5;
|
|
|
|
p5 = v2 - v5;
|
|
|
|
p3 = v3 + v4;
|
|
|
|
p4 = v3 - v4;
|
|
|
|
|
2020-01-12 19:47:13 +01:00
|
|
|
// Convert to 8-bit integers.
|
|
|
|
if (p0 < 16) {
|
|
|
|
p0 = 0;
|
|
|
|
} else if (p0 >= 4080) {
|
|
|
|
p0 = 255;
|
|
|
|
} else {
|
|
|
|
p0 >>= 4;
|
|
|
|
}
|
|
|
|
if (p1 < 16) {
|
|
|
|
p1 = 0;
|
|
|
|
} else if (p1 >= 4080) {
|
|
|
|
p1 = 255;
|
|
|
|
} else {
|
|
|
|
p1 >>= 4;
|
|
|
|
}
|
|
|
|
if (p2 < 16) {
|
|
|
|
p2 = 0;
|
|
|
|
} else if (p2 >= 4080) {
|
|
|
|
p2 = 255;
|
|
|
|
} else {
|
|
|
|
p2 >>= 4;
|
|
|
|
}
|
|
|
|
if (p3 < 16) {
|
|
|
|
p3 = 0;
|
|
|
|
} else if (p3 >= 4080) {
|
|
|
|
p3 = 255;
|
|
|
|
} else {
|
|
|
|
p3 >>= 4;
|
|
|
|
}
|
|
|
|
if (p4 < 16) {
|
|
|
|
p4 = 0;
|
|
|
|
} else if (p4 >= 4080) {
|
|
|
|
p4 = 255;
|
|
|
|
} else {
|
|
|
|
p4 >>= 4;
|
|
|
|
}
|
|
|
|
if (p5 < 16) {
|
|
|
|
p5 = 0;
|
|
|
|
} else if (p5 >= 4080) {
|
|
|
|
p5 = 255;
|
|
|
|
} else {
|
|
|
|
p5 >>= 4;
|
|
|
|
}
|
|
|
|
if (p6 < 16) {
|
|
|
|
p6 = 0;
|
|
|
|
} else if (p6 >= 4080) {
|
|
|
|
p6 = 255;
|
|
|
|
} else {
|
|
|
|
p6 >>= 4;
|
|
|
|
}
|
|
|
|
if (p7 < 16) {
|
|
|
|
p7 = 0;
|
|
|
|
} else if (p7 >= 4080) {
|
|
|
|
p7 = 255;
|
|
|
|
} else {
|
|
|
|
p7 >>= 4;
|
|
|
|
}
|
2014-06-17 10:09:17 +02:00
|
|
|
|
|
|
|
// store block data
|
|
|
|
blockData[blockBufferOffset + col] = p0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
blockData[blockBufferOffset + col + 8] = p1;
|
2014-06-17 10:09:17 +02:00
|
|
|
blockData[blockBufferOffset + col + 16] = p2;
|
|
|
|
blockData[blockBufferOffset + col + 24] = p3;
|
|
|
|
blockData[blockBufferOffset + col + 32] = p4;
|
|
|
|
blockData[blockBufferOffset + col + 40] = p5;
|
|
|
|
blockData[blockBufferOffset + col + 48] = p6;
|
|
|
|
blockData[blockBufferOffset + col + 56] = p7;
|
2014-03-20 18:01:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildComponentData(frame, component) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const blocksPerLine = component.blocksPerLine;
|
|
|
|
const blocksPerColumn = component.blocksPerColumn;
|
|
|
|
const computationBuffer = new Int16Array(64);
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
for (let blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
|
|
|
|
for (let blockCol = 0; blockCol < blocksPerLine; blockCol++) {
|
|
|
|
const offset = getBlockBufferOffset(component, blockRow, blockCol);
|
2014-03-25 19:02:58 -05:00
|
|
|
quantizeAndInverse(component, offset, computationBuffer);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
}
|
2014-03-25 19:02:58 -05:00
|
|
|
return component.blockData;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
|
2018-02-01 10:35:38 +01:00
|
|
|
function findNextFileMarker(data, currentPos, startPos = currentPos) {
|
|
|
|
const maxPos = data.length - 1;
|
2021-05-05 12:35:33 +02:00
|
|
|
let newPos = startPos < currentPos ? startPos : currentPos;
|
2017-03-23 16:08:59 +01:00
|
|
|
|
|
|
|
if (currentPos >= maxPos) {
|
|
|
|
return null; // Don't attempt to read non-existent data and just return.
|
|
|
|
}
|
2021-05-05 12:35:33 +02:00
|
|
|
const currentMarker = readUint16(data, currentPos);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) {
|
2017-03-23 16:08:59 +01:00
|
|
|
return {
|
|
|
|
invalid: null,
|
|
|
|
marker: currentMarker,
|
|
|
|
offset: currentPos,
|
|
|
|
};
|
|
|
|
}
|
2021-05-05 12:35:33 +02:00
|
|
|
let newMarker = readUint16(data, newPos);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) {
|
2017-03-23 16:08:59 +01:00
|
|
|
if (++newPos >= maxPos) {
|
|
|
|
return null; // Don't attempt to read non-existent data and just return.
|
|
|
|
}
|
2020-01-07 20:22:14 +01:00
|
|
|
newMarker = readUint16(data, newPos);
|
2017-03-23 16:08:59 +01:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
invalid: currentMarker.toString(16),
|
|
|
|
marker: newMarker,
|
|
|
|
offset: newPos,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-22 14:07:20 +02:00
|
|
|
JpegImage.prototype = {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
parse(data, { dnlScanLines = null } = {}) {
|
2011-11-15 15:08:13 -08:00
|
|
|
function readDataBlock() {
|
2020-01-07 20:22:14 +01:00
|
|
|
const length = readUint16(data, offset);
|
|
|
|
offset += 2;
|
|
|
|
let endOffset = offset + length - 2;
|
2017-03-17 10:29:08 +01:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
const fileMarker = findNextFileMarker(data, endOffset, offset);
|
2017-03-23 16:08:59 +01:00
|
|
|
if (fileMarker && fileMarker.invalid) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
warn(
|
|
|
|
"readDataBlock - incorrect length, current marker is: " +
|
|
|
|
fileMarker.invalid
|
|
|
|
);
|
2017-03-23 16:08:59 +01:00
|
|
|
endOffset = fileMarker.offset;
|
2017-03-17 10:29:08 +01:00
|
|
|
}
|
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
const array = data.subarray(offset, endOffset);
|
2011-11-15 15:08:13 -08:00
|
|
|
offset += array.length;
|
|
|
|
return array;
|
|
|
|
}
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
function prepareComponents(frame) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
|
|
|
|
const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
|
2021-05-05 12:36:52 +02:00
|
|
|
for (let i = 0, ii = frame.components.length; i < ii; i++) {
|
|
|
|
const component = frame.components[i];
|
2021-05-05 12:35:33 +02:00
|
|
|
const blocksPerLine = Math.ceil(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
(Math.ceil(frame.samplesPerLine / 8) * component.h) / frame.maxH
|
|
|
|
);
|
2021-05-05 12:35:33 +02:00
|
|
|
const blocksPerColumn = Math.ceil(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
(Math.ceil(frame.scanLines / 8) * component.v) / frame.maxV
|
|
|
|
);
|
2021-05-05 12:35:33 +02:00
|
|
|
const blocksPerLineForMcu = mcusPerLine * component.h;
|
|
|
|
const blocksPerColumnForMcu = mcusPerColumn * component.v;
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
const blocksBufferSize =
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
|
2014-03-25 19:02:58 -05:00
|
|
|
component.blockData = new Int16Array(blocksBufferSize);
|
2014-03-20 18:01:28 -05:00
|
|
|
component.blocksPerLine = blocksPerLine;
|
|
|
|
component.blocksPerColumn = blocksPerColumn;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
frame.mcusPerLine = mcusPerLine;
|
|
|
|
frame.mcusPerColumn = mcusPerColumn;
|
|
|
|
}
|
2014-03-20 18:01:28 -05:00
|
|
|
|
2021-05-05 12:36:52 +02:00
|
|
|
let offset = 0;
|
2021-05-05 12:35:33 +02:00
|
|
|
let jfif = null;
|
|
|
|
let adobe = null;
|
|
|
|
let frame, resetInterval;
|
2018-02-01 20:43:01 +01:00
|
|
|
let numSOSMarkers = 0;
|
2021-05-05 12:35:33 +02:00
|
|
|
const quantizationTables = [];
|
|
|
|
const huffmanTablesAC = [],
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
huffmanTablesDC = [];
|
2020-01-07 20:22:14 +01:00
|
|
|
|
|
|
|
let fileMarker = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2019-12-25 20:03:46 +01:00
|
|
|
if (fileMarker !== /* SOI (Start of Image) = */ 0xffd8) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError("SOI not found");
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2020-01-07 20:22:14 +01:00
|
|
|
fileMarker = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2011-11-15 15:08:13 -08:00
|
|
|
|
2019-12-25 20:03:46 +01:00
|
|
|
markerLoop: while (fileMarker !== /* EOI (End of Image) = */ 0xffd9) {
|
2021-05-05 12:36:52 +02:00
|
|
|
let i, j, l;
|
2016-11-01 15:04:21 +01:00
|
|
|
switch (fileMarker) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffe0: // APP0 (Application Specific)
|
|
|
|
case 0xffe1: // APP1
|
|
|
|
case 0xffe2: // APP2
|
|
|
|
case 0xffe3: // APP3
|
|
|
|
case 0xffe4: // APP4
|
|
|
|
case 0xffe5: // APP5
|
|
|
|
case 0xffe6: // APP6
|
|
|
|
case 0xffe7: // APP7
|
|
|
|
case 0xffe8: // APP8
|
|
|
|
case 0xffe9: // APP9
|
|
|
|
case 0xffea: // APP10
|
|
|
|
case 0xffeb: // APP11
|
|
|
|
case 0xffec: // APP12
|
|
|
|
case 0xffed: // APP13
|
|
|
|
case 0xffee: // APP14
|
|
|
|
case 0xffef: // APP15
|
|
|
|
case 0xfffe: // COM (Comment)
|
2021-05-05 12:36:52 +02:00
|
|
|
const appData = readDataBlock();
|
2011-11-15 15:08:13 -08:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (fileMarker === 0xffe0) {
|
2019-12-25 20:03:46 +01:00
|
|
|
// 'JFIF\x00'
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (
|
|
|
|
appData[0] === 0x4a &&
|
|
|
|
appData[1] === 0x46 &&
|
|
|
|
appData[2] === 0x49 &&
|
|
|
|
appData[3] === 0x46 &&
|
|
|
|
appData[4] === 0
|
|
|
|
) {
|
2011-11-15 15:08:13 -08:00
|
|
|
jfif = {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
version: { major: appData[5], minor: appData[6] },
|
2011-11-15 15:08:13 -08:00
|
|
|
densityUnits: appData[7],
|
|
|
|
xDensity: (appData[8] << 8) | appData[9],
|
|
|
|
yDensity: (appData[10] << 8) | appData[11],
|
|
|
|
thumbWidth: appData[12],
|
|
|
|
thumbHeight: appData[13],
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
thumbData: appData.subarray(
|
|
|
|
14,
|
|
|
|
14 + 3 * appData[12] * appData[13]
|
|
|
|
),
|
2011-11-15 15:08:13 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO APP1 - Exif
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (fileMarker === 0xffee) {
|
2019-12-25 20:03:46 +01:00
|
|
|
// 'Adobe'
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (
|
|
|
|
appData[0] === 0x41 &&
|
|
|
|
appData[1] === 0x64 &&
|
|
|
|
appData[2] === 0x6f &&
|
|
|
|
appData[3] === 0x62 &&
|
|
|
|
appData[4] === 0x65
|
|
|
|
) {
|
2011-11-15 15:08:13 -08:00
|
|
|
adobe = {
|
2015-03-10 13:07:09 +01:00
|
|
|
version: (appData[5] << 8) | appData[6],
|
2011-11-15 15:08:13 -08:00
|
|
|
flags0: (appData[7] << 8) | appData[8],
|
|
|
|
flags1: (appData[9] << 8) | appData[10],
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint --fix command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 11:16:24 +02:00
|
|
|
transformCode: appData[11],
|
2011-11-15 15:08:13 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffdb: // DQT (Define Quantization Tables)
|
2020-01-07 20:22:14 +01:00
|
|
|
const quantizationTablesLength = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2021-05-05 12:36:52 +02:00
|
|
|
const quantizationTablesEnd = quantizationTablesLength + offset - 2;
|
|
|
|
let z;
|
2012-08-23 16:12:33 -05:00
|
|
|
while (offset < quantizationTablesEnd) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const quantizationTableSpec = data[offset++];
|
|
|
|
const tableData = new Uint16Array(64);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
if (quantizationTableSpec >> 4 === 0) {
|
|
|
|
// 8 bit values
|
2011-11-22 09:32:20 -08:00
|
|
|
for (j = 0; j < 64; j++) {
|
2014-03-27 17:08:32 +01:00
|
|
|
z = dctZigZag[j];
|
2011-11-22 09:32:20 -08:00
|
|
|
tableData[z] = data[offset++];
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
} else if (quantizationTableSpec >> 4 === 1) {
|
|
|
|
// 16 bit values
|
2012-04-28 08:59:05 -05:00
|
|
|
for (j = 0; j < 64; j++) {
|
2014-03-27 17:08:32 +01:00
|
|
|
z = dctZigZag[j];
|
2020-01-07 20:22:14 +01:00
|
|
|
tableData[z] = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2012-04-28 08:59:05 -05:00
|
|
|
}
|
2014-03-27 17:08:32 +01:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError("DQT - invalid table spec");
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
quantizationTables[quantizationTableSpec & 15] = tableData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffc0: // SOF0 (Start of Frame, Baseline DCT)
|
|
|
|
case 0xffc1: // SOF1 (Start of Frame, Extended DCT)
|
|
|
|
case 0xffc2: // SOF2 (Start of Frame, Progressive DCT)
|
2014-03-20 18:01:28 -05:00
|
|
|
if (frame) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError("Only single frame JPEGs supported");
|
2014-03-20 18:01:28 -05:00
|
|
|
}
|
2020-01-07 20:22:14 +01:00
|
|
|
offset += 2; // Skip marker length.
|
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
frame = {};
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
frame.extended = fileMarker === 0xffc1;
|
|
|
|
frame.progressive = fileMarker === 0xffc2;
|
2011-11-15 15:08:13 -08:00
|
|
|
frame.precision = data[offset++];
|
2020-01-07 20:22:14 +01:00
|
|
|
const sofScanLines = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2018-02-01 20:43:01 +01:00
|
|
|
frame.scanLines = dnlScanLines || sofScanLines;
|
2020-01-07 20:22:14 +01:00
|
|
|
frame.samplesPerLine = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2014-03-20 18:01:28 -05:00
|
|
|
frame.components = [];
|
|
|
|
frame.componentIds = {};
|
2021-05-05 12:36:52 +02:00
|
|
|
const componentsCount = data[offset++];
|
|
|
|
let maxH = 0,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
maxV = 0;
|
2011-11-15 15:08:13 -08:00
|
|
|
for (i = 0; i < componentsCount; i++) {
|
2021-05-05 12:36:52 +02:00
|
|
|
const componentId = data[offset];
|
2021-05-05 12:35:33 +02:00
|
|
|
const h = data[offset + 1] >> 4;
|
|
|
|
const v = data[offset + 1] & 15;
|
2014-03-27 17:08:32 +01:00
|
|
|
if (maxH < h) {
|
|
|
|
maxH = h;
|
|
|
|
}
|
|
|
|
if (maxV < v) {
|
|
|
|
maxV = v;
|
|
|
|
}
|
2021-05-05 12:35:33 +02:00
|
|
|
const qId = data[offset + 2];
|
2014-03-27 17:08:32 +01:00
|
|
|
l = frame.components.push({
|
2017-04-27 12:58:44 +02:00
|
|
|
h,
|
|
|
|
v,
|
2016-06-13 13:29:32 +02:00
|
|
|
quantizationId: qId,
|
|
|
|
quantizationTable: null, // See comment below.
|
2014-03-20 18:01:28 -05:00
|
|
|
});
|
|
|
|
frame.componentIds[componentId] = l - 1;
|
2011-11-15 15:08:13 -08:00
|
|
|
offset += 3;
|
|
|
|
}
|
2014-03-20 18:01:28 -05:00
|
|
|
frame.maxH = maxH;
|
|
|
|
frame.maxV = maxV;
|
2011-11-15 15:08:13 -08:00
|
|
|
prepareComponents(frame);
|
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffc4: // DHT (Define Huffman Tables)
|
2020-01-07 20:22:14 +01:00
|
|
|
const huffmanLength = readUint16(data, offset);
|
|
|
|
offset += 2;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
for (i = 2; i < huffmanLength; ) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const huffmanTableSpec = data[offset++];
|
|
|
|
const codeLengths = new Uint8Array(16);
|
|
|
|
let codeLengthSum = 0;
|
2014-03-27 17:08:32 +01:00
|
|
|
for (j = 0; j < 16; j++, offset++) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
codeLengthSum += codeLengths[j] = data[offset];
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2021-05-05 12:35:33 +02:00
|
|
|
const huffmanValues = new Uint8Array(codeLengthSum);
|
2014-03-27 17:08:32 +01:00
|
|
|
for (j = 0; j < codeLengthSum; j++, offset++) {
|
2011-11-15 15:08:13 -08:00
|
|
|
huffmanValues[j] = data[offset];
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
i += 17 + codeLengthSum;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
(huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[
|
|
|
|
huffmanTableSpec & 15
|
|
|
|
] = buildHuffmanTable(codeLengths, huffmanValues);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffdd: // DRI (Define Restart Interval)
|
2020-01-07 20:22:14 +01:00
|
|
|
offset += 2; // Skip marker length.
|
|
|
|
|
|
|
|
resetInterval = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2011-11-15 15:08:13 -08:00
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffda: // SOS (Start of Scan)
|
2018-02-01 20:43:01 +01:00
|
|
|
// A DNL marker (0xFFDC), if it exists, is only allowed at the end
|
|
|
|
// of the first scan segment and may only occur once in an image.
|
|
|
|
// Furthermore, to prevent an infinite loop, do *not* attempt to
|
|
|
|
// parse DNL markers during re-parsing of the JPEG scan data.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
const parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines;
|
2018-02-01 20:43:01 +01:00
|
|
|
|
2020-01-07 20:22:14 +01:00
|
|
|
offset += 2; // Skip marker length.
|
|
|
|
|
2021-05-05 12:36:52 +02:00
|
|
|
const selectorsCount = data[offset++],
|
|
|
|
components = [];
|
2011-11-15 15:08:13 -08:00
|
|
|
for (i = 0; i < selectorsCount; i++) {
|
2020-06-04 08:43:46 +02:00
|
|
|
const index = data[offset++];
|
2021-05-05 12:35:33 +02:00
|
|
|
const componentIndex = frame.componentIds[index];
|
2021-05-05 12:36:52 +02:00
|
|
|
const component = frame.components[componentIndex];
|
2020-06-04 08:43:46 +02:00
|
|
|
component.index = index;
|
2021-05-05 12:35:33 +02:00
|
|
|
const tableSpec = data[offset++];
|
2011-11-15 15:08:13 -08:00
|
|
|
component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
|
|
|
|
component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
|
|
|
|
components.push(component);
|
|
|
|
}
|
2021-05-05 12:36:52 +02:00
|
|
|
const spectralStart = data[offset++],
|
|
|
|
spectralEnd = data[offset++],
|
|
|
|
successiveApproximation = data[offset++];
|
2018-02-01 20:43:01 +01:00
|
|
|
try {
|
2021-05-05 12:35:33 +02:00
|
|
|
const processed = decodeScan(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data,
|
|
|
|
offset,
|
|
|
|
frame,
|
|
|
|
components,
|
|
|
|
resetInterval,
|
|
|
|
spectralStart,
|
|
|
|
spectralEnd,
|
|
|
|
successiveApproximation >> 4,
|
|
|
|
successiveApproximation & 15,
|
|
|
|
parseDNLMarker
|
|
|
|
);
|
2018-02-01 20:43:01 +01:00
|
|
|
offset += processed;
|
|
|
|
} catch (ex) {
|
|
|
|
if (ex instanceof DNLMarkerError) {
|
2018-05-29 11:33:33 +02:00
|
|
|
warn(`${ex.message} -- attempting to re-parse the JPEG image.`);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
return this.parse(data, { dnlScanLines: ex.scanLines });
|
2018-05-16 14:26:12 +02:00
|
|
|
} else if (ex instanceof EOIMarkerError) {
|
|
|
|
warn(`${ex.message} -- ignoring the rest of the image data.`);
|
|
|
|
break markerLoop;
|
2018-02-01 20:43:01 +01:00
|
|
|
}
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffdc: // DNL (Define Number of Lines)
|
2018-02-01 20:43:01 +01:00
|
|
|
// Ignore the marker, since it's being handled in `decodeScan`.
|
|
|
|
offset += 4;
|
2011-11-15 15:08:13 -08:00
|
|
|
break;
|
2015-02-14 00:08:43 +01:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
case 0xffff: // Fill bytes
|
|
|
|
if (data[offset] !== 0xff) {
|
|
|
|
// Avoid skipping a valid marker.
|
2015-02-14 00:08:43 +01:00
|
|
|
offset--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-11-15 15:08:13 -08:00
|
|
|
default:
|
2020-01-13 13:32:23 +01:00
|
|
|
// Could be incorrect encoding -- the last 0xFF byte of the previous
|
|
|
|
// block could have been eaten by the encoder, hence we fallback to
|
|
|
|
// `startPos = offset - 3` when looking for the next valid marker.
|
|
|
|
const nextFileMarker = findNextFileMarker(
|
|
|
|
data,
|
|
|
|
/* currentPos = */ offset - 2,
|
|
|
|
/* startPos = */ offset - 3
|
|
|
|
);
|
2018-02-01 10:35:38 +01:00
|
|
|
if (nextFileMarker && nextFileMarker.invalid) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
warn(
|
|
|
|
"JpegImage.parse - unexpected data, current marker is: " +
|
|
|
|
nextFileMarker.invalid
|
|
|
|
);
|
2018-02-01 10:35:38 +01:00
|
|
|
offset = nextFileMarker.offset;
|
|
|
|
break;
|
|
|
|
}
|
2021-01-09 20:07:08 +01:00
|
|
|
if (!nextFileMarker || offset >= data.length - 1) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
warn(
|
|
|
|
"JpegImage.parse - reached the end of the image data " +
|
|
|
|
"without finding an EOI marker (0xFFD9)."
|
|
|
|
);
|
2019-08-08 10:31:48 +02:00
|
|
|
break markerLoop;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError(
|
|
|
|
"JpegImage.parse - unknown marker: " + fileMarker.toString(16)
|
|
|
|
);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2020-01-07 20:22:14 +01:00
|
|
|
fileMarker = readUint16(data, offset);
|
|
|
|
offset += 2;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.width = frame.samplesPerLine;
|
|
|
|
this.height = frame.scanLines;
|
|
|
|
this.jfif = jfif;
|
|
|
|
this.adobe = adobe;
|
|
|
|
this.components = [];
|
2021-05-05 12:36:52 +02:00
|
|
|
for (let i = 0, ii = frame.components.length; i < ii; i++) {
|
|
|
|
const component = frame.components[i];
|
2016-06-13 13:29:32 +02:00
|
|
|
|
|
|
|
// Prevent errors when DQT markers are placed after SOF{n} markers,
|
|
|
|
// by assigning the `quantizationTable` entry after the entire image
|
|
|
|
// has been parsed (fixes issue7406.pdf).
|
2021-05-05 12:35:33 +02:00
|
|
|
const quantizationTable = quantizationTables[component.quantizationId];
|
2016-06-13 13:29:32 +02:00
|
|
|
if (quantizationTable) {
|
|
|
|
component.quantizationTable = quantizationTable;
|
|
|
|
}
|
|
|
|
|
2012-04-28 08:59:05 -05:00
|
|
|
this.components.push({
|
2020-06-04 08:43:46 +02:00
|
|
|
index: component.index,
|
2014-03-25 19:02:58 -05:00
|
|
|
output: buildComponentData(frame, component),
|
2012-04-28 08:59:05 -05:00
|
|
|
scaleX: component.h / frame.maxH,
|
2014-03-25 19:02:58 -05:00
|
|
|
scaleY: component.v / frame.maxV,
|
|
|
|
blocksPerLine: component.blocksPerLine,
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint --fix command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 11:16:24 +02:00
|
|
|
blocksPerColumn: component.blocksPerColumn,
|
2012-04-28 08:59:05 -05:00
|
|
|
});
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2014-03-27 11:11:28 +01:00
|
|
|
this.numComponents = this.components.length;
|
2019-05-10 12:54:06 +02:00
|
|
|
return undefined;
|
2011-11-15 15:08:13 -08:00
|
|
|
},
|
2014-03-25 19:02:58 -05:00
|
|
|
|
2018-09-02 13:55:27 +02:00
|
|
|
_getLinearizedBlockData(width, height, isSourcePDF = false) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const scaleX = this.width / width,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
scaleY = this.height / height;
|
2011-11-15 15:08:13 -08:00
|
|
|
|
2021-05-05 12:35:33 +02:00
|
|
|
let component, componentScaleX, componentScaleY, blocksPerScanline;
|
|
|
|
let x, y, i, j, k;
|
|
|
|
let index;
|
|
|
|
let offset = 0;
|
|
|
|
let output;
|
|
|
|
const numComponents = this.components.length;
|
|
|
|
const dataLength = width * height * numComponents;
|
|
|
|
const data = new Uint8ClampedArray(dataLength);
|
|
|
|
const xScaleBlockOffset = new Uint32Array(width);
|
|
|
|
const mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
|
2020-02-01 11:42:22 +01:00
|
|
|
let lastComponentScaleX;
|
2014-03-25 19:02:58 -05:00
|
|
|
|
2014-02-18 09:24:59 -06:00
|
|
|
for (i = 0; i < numComponents; i++) {
|
|
|
|
component = this.components[i];
|
|
|
|
componentScaleX = component.scaleX * scaleX;
|
|
|
|
componentScaleY = component.scaleY * scaleY;
|
|
|
|
offset = i;
|
2014-04-29 17:09:54 +02:00
|
|
|
output = component.output;
|
|
|
|
blocksPerScanline = (component.blocksPerLine + 1) << 3;
|
2020-02-01 11:42:22 +01:00
|
|
|
// Precalculate the `xScaleBlockOffset`. Since it doesn't depend on the
|
|
|
|
// component data, that's only necessary when `componentScaleX` changes.
|
|
|
|
if (componentScaleX !== lastComponentScaleX) {
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
j = 0 | (x * componentScaleX);
|
|
|
|
xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
|
|
|
|
}
|
|
|
|
lastComponentScaleX = componentScaleX;
|
2014-04-29 17:09:54 +02:00
|
|
|
}
|
|
|
|
// linearize the blocks of the component
|
2014-02-18 09:24:59 -06:00
|
|
|
for (y = 0; y < height; y++) {
|
2014-04-29 17:09:54 +02:00
|
|
|
j = 0 | (y * componentScaleY);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
index = (blocksPerScanline * (j & mask3LSB)) | ((j & 7) << 3);
|
2014-02-18 09:24:59 -06:00
|
|
|
for (x = 0; x < width; x++) {
|
2014-04-29 17:09:54 +02:00
|
|
|
data[offset] = output[index + xScaleBlockOffset[x]];
|
2014-02-18 09:24:59 -06:00
|
|
|
offset += numComponents;
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2014-02-18 09:24:59 -06:00
|
|
|
}
|
|
|
|
}
|
2014-06-03 08:51:57 -05:00
|
|
|
|
2014-10-30 09:18:52 +01:00
|
|
|
// decodeTransform contains pairs of multiplier (-256..256) and additive
|
2018-09-02 13:55:27 +02:00
|
|
|
let transform = this._decodeTransform;
|
|
|
|
|
|
|
|
// In PDF files, JPEG images with CMYK colour spaces are usually inverted
|
|
|
|
// (this can be observed by extracting the raw image data).
|
|
|
|
// Since the conversion algorithms (see below) were written primarily for
|
|
|
|
// the PDF use-cases, attempting to use `JpegImage` to parse standalone
|
|
|
|
// JPEG (CMYK) images may thus result in inverted images (see issue 9513).
|
|
|
|
//
|
|
|
|
// Unfortunately it's not (always) possible to tell, from the image data
|
|
|
|
// alone, if it needs to be inverted. Thus in an attempt to provide better
|
|
|
|
// out-of-box behaviour when `JpegImage` is used standalone, default to
|
|
|
|
// inverting JPEG (CMYK) images if and only if the image data does *not*
|
|
|
|
// come from a PDF file and no `decodeTransform` was passed by the user.
|
2018-09-12 11:30:59 +02:00
|
|
|
if (!isSourcePDF && numComponents === 4 && !transform) {
|
2019-12-25 15:54:34 +01:00
|
|
|
// prettier-ignore
|
2018-09-02 13:55:27 +02:00
|
|
|
transform = new Int32Array([
|
|
|
|
-256, 255, -256, 255, -256, 255, -256, 255]);
|
|
|
|
}
|
|
|
|
|
2014-06-03 08:51:57 -05:00
|
|
|
if (transform) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
for (i = 0; i < dataLength; ) {
|
2014-06-03 08:51:57 -05:00
|
|
|
for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
|
|
|
|
data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-27 11:11:28 +01:00
|
|
|
return data;
|
|
|
|
},
|
2014-02-18 09:24:59 -06:00
|
|
|
|
2018-09-02 13:06:28 +02:00
|
|
|
get _isColorConversionNeeded() {
|
2017-07-11 16:25:47 +02:00
|
|
|
if (this.adobe) {
|
|
|
|
// The adobe transform marker overrides any previous setting.
|
|
|
|
return !!this.adobe.transformCode;
|
|
|
|
}
|
|
|
|
if (this.numComponents === 3) {
|
2018-05-16 13:49:01 +02:00
|
|
|
if (this._colorTransform === 0) {
|
2016-09-22 14:07:20 +02:00
|
|
|
// If the Adobe transform marker is not present and the image
|
|
|
|
// dictionary has a 'ColorTransform' entry, explicitly set to `0`,
|
|
|
|
// then the colours should *not* be transformed.
|
|
|
|
return false;
|
2020-06-04 08:43:46 +02:00
|
|
|
} else if (
|
|
|
|
this.components[0].index === /* "R" = */ 0x52 &&
|
|
|
|
this.components[1].index === /* "G" = */ 0x47 &&
|
|
|
|
this.components[2].index === /* "B" = */ 0x42
|
|
|
|
) {
|
|
|
|
// If the three components are indexed as RGB in ASCII
|
|
|
|
// then the colours should *not* be transformed.
|
|
|
|
return false;
|
2016-09-22 14:07:20 +02:00
|
|
|
}
|
2014-03-27 11:11:28 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-16 13:05:33 +01:00
|
|
|
// `this.numComponents !== 3`
|
2018-05-16 13:49:01 +02:00
|
|
|
if (this._colorTransform === 1) {
|
2016-12-16 13:05:33 +01:00
|
|
|
// If the Adobe transform marker is not present and the image
|
|
|
|
// dictionary has a 'ColorTransform' entry, explicitly set to `1`,
|
|
|
|
// then the colours should be transformed.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-03-27 11:11:28 +01:00
|
|
|
},
|
2014-02-18 09:24:59 -06:00
|
|
|
|
2014-03-27 11:11:28 +01:00
|
|
|
_convertYccToRgb: function convertYccToRgb(data) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let Y, Cb, Cr;
|
|
|
|
for (let i = 0, length = data.length; i < length; i += 3) {
|
2017-08-14 15:42:11 +02:00
|
|
|
Y = data[i];
|
2014-03-27 11:11:28 +01:00
|
|
|
Cb = data[i + 1];
|
|
|
|
Cr = data[i + 2];
|
2017-08-14 15:42:11 +02:00
|
|
|
data[i] = Y - 179.456 + 1.402 * Cr;
|
|
|
|
data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
|
|
|
|
data[i + 2] = Y - 226.816 + 1.772 * Cb;
|
2014-03-27 11:11:28 +01:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertYcckToRgb: function convertYcckToRgb(data) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let Y, Cb, Cr, k;
|
|
|
|
let offset = 0;
|
|
|
|
for (let i = 0, length = data.length; i < length; i += 4) {
|
2017-08-14 15:42:11 +02:00
|
|
|
Y = data[i];
|
2014-03-27 11:11:28 +01:00
|
|
|
Cb = data[i + 1];
|
|
|
|
Cr = data[i + 2];
|
2014-03-27 17:08:32 +01:00
|
|
|
k = data[i + 3];
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data[offset++] =
|
|
|
|
-122.67195406894 +
|
|
|
|
Cb *
|
|
|
|
(-6.60635669420364e-5 * Cb +
|
|
|
|
0.000437130475926232 * Cr -
|
|
|
|
5.4080610064599e-5 * Y +
|
|
|
|
0.00048449797120281 * k -
|
|
|
|
0.154362151871126) +
|
|
|
|
Cr *
|
|
|
|
(-0.000957964378445773 * Cr +
|
|
|
|
0.000817076911346625 * Y -
|
|
|
|
0.00477271405408747 * k +
|
|
|
|
1.53380253221734) +
|
|
|
|
Y *
|
|
|
|
(0.000961250184130688 * Y -
|
|
|
|
0.00266257332283933 * k +
|
|
|
|
0.48357088451265) +
|
2014-10-30 10:37:21 +01:00
|
|
|
k * (-0.000336197177618394 * k + 0.484791561490776);
|
2014-03-27 17:08:32 +01:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data[offset++] =
|
|
|
|
107.268039397724 +
|
|
|
|
Cb *
|
|
|
|
(2.19927104525741e-5 * Cb -
|
|
|
|
0.000640992018297945 * Cr +
|
|
|
|
0.000659397001245577 * Y +
|
|
|
|
0.000426105652938837 * k -
|
|
|
|
0.176491792462875) +
|
|
|
|
Cr *
|
|
|
|
(-0.000778269941513683 * Cr +
|
|
|
|
0.00130872261408275 * Y +
|
|
|
|
0.000770482631801132 * k -
|
|
|
|
0.151051492775562) +
|
|
|
|
Y *
|
|
|
|
(0.00126935368114843 * Y -
|
|
|
|
0.00265090189010898 * k +
|
|
|
|
0.25802910206845) +
|
2014-10-30 10:37:21 +01:00
|
|
|
k * (-0.000318913117588328 * k - 0.213742400323665);
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data[offset++] =
|
|
|
|
-20.810012546947 +
|
|
|
|
Cb *
|
|
|
|
(-0.000570115196973677 * Cb -
|
|
|
|
2.63409051004589e-5 * Cr +
|
|
|
|
0.0020741088115012 * Y -
|
|
|
|
0.00288260236853442 * k +
|
|
|
|
0.814272968359295) +
|
|
|
|
Cr *
|
|
|
|
(-1.53496057440975e-5 * Cr -
|
|
|
|
0.000132689043961446 * Y +
|
|
|
|
0.000560833691242812 * k -
|
|
|
|
0.195152027534049) +
|
|
|
|
Y *
|
|
|
|
(0.00174418132927582 * Y -
|
|
|
|
0.00255243321439347 * k +
|
|
|
|
0.116935020465145) +
|
2014-10-30 10:37:21 +01:00
|
|
|
k * (-0.000343531996510555 * k + 0.24165260232407);
|
2014-03-27 17:08:32 +01:00
|
|
|
}
|
2018-02-11 13:13:11 +01:00
|
|
|
// Ensure that only the converted RGB data is returned.
|
|
|
|
return data.subarray(0, offset);
|
2014-03-27 11:11:28 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
_convertYcckToCmyk: function convertYcckToCmyk(data) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let Y, Cb, Cr;
|
|
|
|
for (let i = 0, length = data.length; i < length; i += 4) {
|
2017-08-14 15:42:11 +02:00
|
|
|
Y = data[i];
|
2014-03-27 11:11:28 +01:00
|
|
|
Cb = data[i + 1];
|
|
|
|
Cr = data[i + 2];
|
2017-08-14 15:42:11 +02:00
|
|
|
data[i] = 434.456 - Y - 1.402 * Cr;
|
|
|
|
data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr;
|
|
|
|
data[i + 2] = 481.816 - Y - 1.772 * Cb;
|
2014-03-27 11:11:28 +01:00
|
|
|
// K in data[i + 3] is unchanged
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertCmykToRgb: function convertCmykToRgb(data) {
|
2021-05-05 12:35:33 +02:00
|
|
|
let c, m, y, k;
|
|
|
|
let offset = 0;
|
|
|
|
for (let i = 0, length = data.length; i < length; i += 4) {
|
2020-01-29 18:20:26 +01:00
|
|
|
c = data[i];
|
|
|
|
m = data[i + 1];
|
|
|
|
y = data[i + 2];
|
|
|
|
k = data[i + 3];
|
2014-03-27 17:08:32 +01:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data[offset++] =
|
|
|
|
255 +
|
|
|
|
c *
|
2020-01-29 18:20:26 +01:00
|
|
|
(-0.00006747147073602441 * c +
|
|
|
|
0.0008379262121013727 * m +
|
|
|
|
0.0002894718188643294 * y +
|
|
|
|
0.003264231057537806 * k -
|
|
|
|
1.1185611867203937) +
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
m *
|
2020-01-29 18:20:26 +01:00
|
|
|
(0.000026374107616089405 * m -
|
|
|
|
0.00008626949158638572 * y -
|
|
|
|
0.0002748769067499491 * k -
|
|
|
|
0.02155688794978967) +
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
y *
|
2020-01-29 18:20:26 +01:00
|
|
|
(-0.00003878099212869363 * y -
|
|
|
|
0.0003267808279485286 * k +
|
|
|
|
0.0686742238595345) -
|
|
|
|
k * (0.0003361971776183937 * k + 0.7430659151342254);
|
2017-08-14 15:42:11 +02:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data[offset++] =
|
|
|
|
255 +
|
|
|
|
c *
|
2020-01-29 18:20:26 +01:00
|
|
|
(0.00013596372813588848 * c +
|
|
|
|
0.000924537132573585 * m +
|
|
|
|
0.00010567359618683593 * y +
|
|
|
|
0.0004791864687436512 * k -
|
|
|
|
0.3109689587515875) +
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
m *
|
2020-01-29 18:20:26 +01:00
|
|
|
(-0.00023545346108370344 * m +
|
|
|
|
0.0002702845253534714 * y +
|
|
|
|
0.0020200308977307156 * k -
|
|
|
|
0.7488052167015494) +
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
y *
|
2020-01-29 18:20:26 +01:00
|
|
|
(0.00006834815998235662 * y +
|
|
|
|
0.00015168452363460973 * k -
|
|
|
|
0.09751927774728933) -
|
|
|
|
k * (0.00031891311758832814 * k + 0.7364883807733168);
|
2017-08-14 15:42:11 +02:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
data[offset++] =
|
|
|
|
255 +
|
|
|
|
c *
|
2020-01-29 18:20:26 +01:00
|
|
|
(0.000013598650411385307 * c +
|
|
|
|
0.00012423956175490851 * m +
|
|
|
|
0.0004751985097583589 * y -
|
|
|
|
0.0000036729317476630422 * k -
|
|
|
|
0.05562186980264034) +
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
m *
|
2020-01-29 18:20:26 +01:00
|
|
|
(0.00016141380598724676 * m +
|
|
|
|
0.0009692239130725186 * y +
|
|
|
|
0.0007782692450036253 * k -
|
|
|
|
0.44015232367526463) +
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
y *
|
2020-01-29 18:20:26 +01:00
|
|
|
(5.068882914068769e-7 * y +
|
|
|
|
0.0017778369011375071 * k -
|
|
|
|
0.7591454649749609) -
|
|
|
|
k * (0.0003435319965105553 * k + 0.7063770186160144);
|
2014-03-27 11:11:28 +01:00
|
|
|
}
|
2018-02-11 13:13:11 +01:00
|
|
|
// Ensure that only the converted RGB data is returned.
|
|
|
|
return data.subarray(0, offset);
|
2014-03-27 11:11:28 +01:00
|
|
|
},
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
getData({ width, height, forceRGB = false, isSourcePDF = false }) {
|
2020-01-08 15:33:11 +01:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
|
|
|
) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
assert(
|
|
|
|
isSourcePDF === true,
|
|
|
|
'JpegImage.getData: Unexpected "isSourcePDF" value for PDF files.'
|
|
|
|
);
|
2018-09-12 11:30:59 +02:00
|
|
|
}
|
2014-03-27 11:11:28 +01:00
|
|
|
if (this.numComponents > 4) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
throw new JpegError("Unsupported color mode");
|
2014-03-27 11:11:28 +01:00
|
|
|
}
|
2018-09-02 13:55:27 +02:00
|
|
|
// Type of data: Uint8ClampedArray(width * height * numComponents)
|
2021-05-05 12:35:33 +02:00
|
|
|
const data = this._getLinearizedBlockData(width, height, isSourcePDF);
|
2014-03-27 11:11:28 +01:00
|
|
|
|
2018-09-02 13:55:27 +02:00
|
|
|
if (this.numComponents === 1 && forceRGB) {
|
2021-05-05 12:35:33 +02:00
|
|
|
const dataLength = data.length;
|
|
|
|
const rgbData = new Uint8ClampedArray(dataLength * 3);
|
|
|
|
let offset = 0;
|
|
|
|
for (let i = 0; i < dataLength; i++) {
|
|
|
|
const grayColor = data[i];
|
2016-02-08 13:49:30 +01:00
|
|
|
rgbData[offset++] = grayColor;
|
|
|
|
rgbData[offset++] = grayColor;
|
|
|
|
rgbData[offset++] = grayColor;
|
|
|
|
}
|
|
|
|
return rgbData;
|
2018-09-02 13:06:28 +02:00
|
|
|
} else if (this.numComponents === 3 && this._isColorConversionNeeded) {
|
2014-03-27 11:11:28 +01:00
|
|
|
return this._convertYccToRgb(data);
|
|
|
|
} else if (this.numComponents === 4) {
|
2018-09-02 13:06:28 +02:00
|
|
|
if (this._isColorConversionNeeded) {
|
2018-09-02 13:55:27 +02:00
|
|
|
if (forceRGB) {
|
2014-03-27 11:11:28 +01:00
|
|
|
return this._convertYcckToRgb(data);
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
2016-12-16 13:05:33 +01:00
|
|
|
return this._convertYcckToCmyk(data);
|
2018-09-02 13:55:27 +02:00
|
|
|
} else if (forceRGB) {
|
2014-03-27 11:11:28 +01:00
|
|
|
return this._convertCmykToRgb(data);
|
|
|
|
}
|
2011-11-15 15:08:13 -08:00
|
|
|
}
|
|
|
|
return data;
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint --fix command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 11:16:24 +02:00
|
|
|
},
|
2011-11-15 15:08:13 -08:00
|
|
|
};
|
|
|
|
|
2016-09-22 14:07:20 +02:00
|
|
|
return JpegImage;
|
2012-08-31 13:37:44 +02:00
|
|
|
})();
|
2015-11-21 10:32:47 -06:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 15:59:37 +01:00
|
|
|
export { JpegImage };
|