2014-03-28 01:08:32 +09: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.
|
|
|
|
*/
|
Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*
ESLint has a number of advantageous properties, compared to JSHint. Among those are:
- The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
- Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
- Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
- The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
- More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.
By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.
I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.
Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).
A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
- `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
- `object-curly-spacing`, controls spacing inside of Objects.
- `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)
Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.
Useful links:
- http://eslint.org/docs/user-guide/configuring
- http://eslint.org/docs/rules/
2016-12-15 23:52:29 +09:00
|
|
|
/* eslint-disable no-multi-spaces */
|
2012-08-24 06:12:33 +09:00
|
|
|
|
2018-09-12 18:30:59 +09:00
|
|
|
import { assert, warn } from '../shared/util';
|
2017-06-29 05:51:31 +09:00
|
|
|
|
|
|
|
let JpegError = (function JpegErrorClosure() {
|
|
|
|
function JpegError(msg) {
|
|
|
|
this.message = 'JPEG error: ' + msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
JpegError.prototype = new Error();
|
|
|
|
JpegError.prototype.name = 'JpegError';
|
|
|
|
JpegError.constructor = JpegError;
|
|
|
|
|
|
|
|
return JpegError;
|
|
|
|
})();
|
2014-03-28 01:08:32 +09:00
|
|
|
|
2018-02-02 04:43:01 +09:00
|
|
|
let DNLMarkerError = (function DNLMarkerErrorClosure() {
|
|
|
|
function DNLMarkerError(message, scanLines) {
|
|
|
|
this.message = message;
|
|
|
|
this.scanLines = scanLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
DNLMarkerError.prototype = new Error();
|
|
|
|
DNLMarkerError.prototype.name = 'DNLMarkerError';
|
|
|
|
DNLMarkerError.constructor = DNLMarkerError;
|
|
|
|
|
|
|
|
return DNLMarkerError;
|
|
|
|
})();
|
|
|
|
|
2018-05-16 21:26:12 +09:00
|
|
|
let EOIMarkerError = (function EOIMarkerErrorClosure() {
|
|
|
|
function EOIMarkerError(message) {
|
|
|
|
this.message = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOIMarkerError.prototype = new Error();
|
|
|
|
EOIMarkerError.prototype.name = 'EOIMarkerError';
|
|
|
|
EOIMarkerError.constructor = EOIMarkerError;
|
|
|
|
|
|
|
|
return EOIMarkerError;
|
|
|
|
})();
|
|
|
|
|
2016-09-03 19:17:00 +09: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-16 08:08:13 +09:00
|
|
|
|
2016-09-22 21:07:20 +09:00
|
|
|
var JpegImage = (function JpegImageClosure() {
|
2014-06-17 17:09:17 +09:00
|
|
|
var dctZigZag = new Uint8Array([
|
2011-11-23 02:32:20 +09: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
|
|
|
|
]);
|
|
|
|
|
2014-03-28 01:08:32 +09:00
|
|
|
var dctCos1 = 4017; // cos(pi/16)
|
|
|
|
var dctSin1 = 799; // sin(pi/16)
|
|
|
|
var dctCos3 = 3406; // cos(3*pi/16)
|
|
|
|
var dctSin3 = 2276; // sin(3*pi/16)
|
|
|
|
var dctCos6 = 1567; // cos(6*pi/16)
|
|
|
|
var dctSin6 = 3784; // sin(6*pi/16)
|
|
|
|
var dctSqrt2 = 5793; // sqrt(2)
|
|
|
|
var dctSqrt1d2 = 2896; // sqrt(2) / 2
|
2011-11-23 02:32:20 +09:00
|
|
|
|
2018-05-16 20:49:01 +09:00
|
|
|
function JpegImage({ decodeTransform = null, colorTransform = -1, } = {}) {
|
|
|
|
this._decodeTransform = decodeTransform;
|
|
|
|
this._colorTransform = colorTransform;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function buildHuffmanTable(codeLengths, values) {
|
|
|
|
var k = 0, code = [], i, j, length = 16;
|
2014-03-28 01:08:32 +09:00
|
|
|
while (length > 0 && !codeLengths[length - 1]) {
|
2011-11-16 08:08:13 +09:00
|
|
|
length--;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
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 18:16:24 +09:00
|
|
|
code.push({ children: [], index: 0, });
|
2011-11-16 08:08:13 +09:00
|
|
|
var p = code[0], q;
|
|
|
|
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) {
|
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 18:16:24 +09:00
|
|
|
code.push(q = { children: [], index: 0, });
|
2011-11-16 08:08:13 +09:00
|
|
|
p.children[p.index] = q.children;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
if (i + 1 < length) {
|
|
|
|
// p here points to last code
|
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 18:16:24 +09:00
|
|
|
code.push(q = { children: [], index: 0, });
|
2011-11-16 08:08:13 +09:00
|
|
|
p.children[p.index] = q.children;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return code[0].children;
|
|
|
|
}
|
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
function getBlockBufferOffset(component, row, col) {
|
2014-03-21 23:16:02 +09:00
|
|
|
return 64 * ((component.blocksPerLine + 1) * row + col);
|
2014-03-21 08:01:28 +09:00
|
|
|
}
|
|
|
|
|
2014-06-17 17:09:17 +09:00
|
|
|
function decodeScan(data, offset, frame, components, resetInterval,
|
2018-02-02 04:43:01 +09:00
|
|
|
spectralStart, spectralEnd, successivePrev, successive,
|
|
|
|
parseDNLMarker = false) {
|
2011-11-16 08:08:13 +09:00
|
|
|
var mcusPerLine = frame.mcusPerLine;
|
|
|
|
var progressive = frame.progressive;
|
|
|
|
|
|
|
|
var startOffset = offset, bitsData = 0, bitsCount = 0;
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function readBit() {
|
|
|
|
if (bitsCount > 0) {
|
|
|
|
bitsCount--;
|
|
|
|
return (bitsData >> bitsCount) & 1;
|
|
|
|
}
|
|
|
|
bitsData = data[offset++];
|
2014-08-02 05:43:55 +09:00
|
|
|
if (bitsData === 0xFF) {
|
2011-11-16 08:08:13 +09:00
|
|
|
var nextByte = data[offset++];
|
|
|
|
if (nextByte) {
|
2018-02-02 04:43:01 +09:00
|
|
|
if (nextByte === 0xDC && parseDNLMarker) { // DNL == 0xFFDC
|
|
|
|
offset += 2; // Skip data length.
|
|
|
|
const scanLines = (data[offset++] << 8) | data[offset++];
|
|
|
|
if (scanLines > 0 && scanLines !== frame.scanLines) {
|
|
|
|
throw new DNLMarkerError(
|
|
|
|
'Found DNL marker (0xFFDC) while parsing scan data', scanLines);
|
|
|
|
}
|
2018-05-16 21:26:12 +09:00
|
|
|
} else if (nextByte === 0xD9) { // EOI == 0xFFD9
|
|
|
|
throw new EOIMarkerError(
|
|
|
|
'Found EOI marker (0xFFD9) while parsing scan data');
|
2018-02-02 04:43:01 +09:00
|
|
|
}
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError(
|
|
|
|
`unexpected marker ${((bitsData << 8) | nextByte).toString(16)}`);
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
// unstuff 0
|
|
|
|
}
|
|
|
|
bitsCount = 7;
|
|
|
|
return bitsData >>> 7;
|
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function decodeHuffman(tree) {
|
2014-03-21 23:16:02 +09:00
|
|
|
var node = tree;
|
2014-10-30 17:18:52 +09:00
|
|
|
while (true) {
|
|
|
|
node = node[readBit()];
|
2014-03-28 01:08:32 +09:00
|
|
|
if (typeof node === 'number') {
|
2011-11-16 08:08:13 +09:00
|
|
|
return node;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
|
|
|
if (typeof node !== 'object') {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError('invalid huffman sequence');
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function receive(length) {
|
|
|
|
var n = 0;
|
|
|
|
while (length > 0) {
|
2014-10-30 17:18:52 +09:00
|
|
|
n = (n << 1) | readBit();
|
2011-11-16 08:08:13 +09:00
|
|
|
length--;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function receiveAndExtend(length) {
|
2014-06-05 19:07:04 +09:00
|
|
|
if (length === 1) {
|
|
|
|
return readBit() === 1 ? 1 : -1;
|
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
var n = receive(length);
|
2014-03-28 01:08:32 +09:00
|
|
|
if (n >= 1 << (length - 1)) {
|
2011-11-16 08:08:13 +09:00
|
|
|
return n;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
return n + (-1 << length) + 1;
|
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
function decodeBaseline(component, offset) {
|
2011-11-16 08:08:13 +09:00
|
|
|
var t = decodeHuffman(component.huffmanTableDC);
|
|
|
|
var diff = t === 0 ? 0 : receiveAndExtend(t);
|
2014-03-26 09:02:58 +09:00
|
|
|
component.blockData[offset] = (component.pred += diff);
|
2011-11-16 08:08:13 +09:00
|
|
|
var k = 1;
|
|
|
|
while (k < 64) {
|
|
|
|
var rs = decodeHuffman(component.huffmanTableAC);
|
|
|
|
var s = rs & 15, r = rs >> 4;
|
|
|
|
if (s === 0) {
|
2014-03-28 01:08:32 +09:00
|
|
|
if (r < 15) {
|
2011-11-16 08:08:13 +09:00
|
|
|
break;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
k += 16;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k += r;
|
2011-11-23 02:32:20 +09:00
|
|
|
var z = dctZigZag[k];
|
2014-03-26 09:02:58 +09:00
|
|
|
component.blockData[offset + z] = receiveAndExtend(s);
|
2011-11-16 08:08:13 +09:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
function decodeDCFirst(component, offset) {
|
2011-11-16 08:08:13 +09:00
|
|
|
var t = decodeHuffman(component.huffmanTableDC);
|
|
|
|
var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
|
2014-03-26 09:02:58 +09:00
|
|
|
component.blockData[offset] = (component.pred += diff);
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
function decodeDCSuccessive(component, offset) {
|
2014-03-26 09:02:58 +09:00
|
|
|
component.blockData[offset] |= readBit() << successive;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
var eobrun = 0;
|
2014-03-21 08:01:28 +09:00
|
|
|
function decodeACFirst(component, offset) {
|
2011-11-16 08:08:13 +09:00
|
|
|
if (eobrun > 0) {
|
|
|
|
eobrun--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var k = spectralStart, e = spectralEnd;
|
|
|
|
while (k <= e) {
|
|
|
|
var rs = decodeHuffman(component.huffmanTableAC);
|
|
|
|
var s = rs & 15, r = rs >> 4;
|
|
|
|
if (s === 0) {
|
|
|
|
if (r < 15) {
|
|
|
|
eobrun = receive(r) + (1 << r) - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
k += 16;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k += r;
|
2011-11-23 02:32:20 +09:00
|
|
|
var z = dctZigZag[k];
|
2014-03-28 01:08:32 +09:00
|
|
|
component.blockData[offset + z] =
|
|
|
|
receiveAndExtend(s) * (1 << successive);
|
2011-11-16 08:08:13 +09:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 23:16:02 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
var successiveACState = 0, successiveACNextValue;
|
2014-03-21 08:01:28 +09:00
|
|
|
function decodeACSuccessive(component, offset) {
|
2014-03-28 01:08:32 +09:00
|
|
|
var k = spectralStart;
|
|
|
|
var e = spectralEnd;
|
|
|
|
var r = 0;
|
|
|
|
var s;
|
|
|
|
var rs;
|
2011-11-16 08:08:13 +09:00
|
|
|
while (k <= e) {
|
2017-12-29 22:39:29 +09:00
|
|
|
let offsetZ = offset + dctZigZag[k];
|
|
|
|
let sign = component.blockData[offsetZ] < 0 ? -1 : 1;
|
2011-11-16 08:08:13 +09:00
|
|
|
switch (successiveACState) {
|
2017-12-29 22:37:20 +09: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-16 08:08:13 +09:00
|
|
|
} else {
|
2017-12-29 22:37:20 +09:00
|
|
|
if (s !== 1) {
|
|
|
|
throw new JpegError('invalid ACn encoding');
|
|
|
|
}
|
|
|
|
successiveACNextValue = receiveAndExtend(s);
|
|
|
|
successiveACState = r ? 2 : 3;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2017-12-29 22:37:20 +09:00
|
|
|
continue;
|
|
|
|
case 1: // skipping r zero items
|
|
|
|
case 2:
|
2017-12-29 22:39:29 +09:00
|
|
|
if (component.blockData[offsetZ]) {
|
|
|
|
component.blockData[offsetZ] += sign * (readBit() << successive);
|
2017-12-29 22:37:20 +09:00
|
|
|
} else {
|
|
|
|
r--;
|
|
|
|
if (r === 0) {
|
|
|
|
successiveACState = successiveACState === 2 ? 3 : 0;
|
|
|
|
}
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2017-12-29 22:37:20 +09:00
|
|
|
break;
|
|
|
|
case 3: // set value for a zero item
|
2017-12-29 22:39:29 +09:00
|
|
|
if (component.blockData[offsetZ]) {
|
|
|
|
component.blockData[offsetZ] += sign * (readBit() << successive);
|
2017-12-29 22:37:20 +09:00
|
|
|
} else {
|
2017-12-29 22:39:29 +09:00
|
|
|
component.blockData[offsetZ] =
|
2017-12-29 22:37:20 +09:00
|
|
|
successiveACNextValue << successive;
|
|
|
|
successiveACState = 0;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2017-12-29 22:37:20 +09:00
|
|
|
break;
|
|
|
|
case 4: // eob
|
2017-12-29 22:39:29 +09:00
|
|
|
if (component.blockData[offsetZ]) {
|
|
|
|
component.blockData[offsetZ] += sign * (readBit() << successive);
|
2017-12-29 22:37:20 +09:00
|
|
|
}
|
|
|
|
break;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
if (successiveACState === 4) {
|
|
|
|
eobrun--;
|
2014-03-28 01:08:32 +09:00
|
|
|
if (eobrun === 0) {
|
2011-11-16 08:08:13 +09:00
|
|
|
successiveACState = 0;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
}
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function decodeMcu(component, decode, mcu, row, col) {
|
|
|
|
var mcuRow = (mcu / mcusPerLine) | 0;
|
|
|
|
var mcuCol = mcu % mcusPerLine;
|
|
|
|
var blockRow = mcuRow * component.v + row;
|
|
|
|
var blockCol = mcuCol * component.h + col;
|
2014-03-21 23:16:02 +09:00
|
|
|
var offset = getBlockBufferOffset(component, blockRow, blockCol);
|
|
|
|
decode(component, offset);
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function decodeBlock(component, decode, mcu) {
|
|
|
|
var blockRow = (mcu / component.blocksPerLine) | 0;
|
|
|
|
var blockCol = mcu % component.blocksPerLine;
|
2014-03-21 23:16:02 +09:00
|
|
|
var offset = getBlockBufferOffset(component, blockRow, blockCol);
|
|
|
|
decode(component, offset);
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
var componentsLength = components.length;
|
|
|
|
var component, i, j, k, n;
|
|
|
|
var decodeFn;
|
|
|
|
if (progressive) {
|
2014-03-28 01:08:32 +09:00
|
|
|
if (spectralStart === 0) {
|
2011-11-16 08:08:13 +09:00
|
|
|
decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
|
2014-03-28 01:08:32 +09:00
|
|
|
} else {
|
2011-11-16 08:08:13 +09:00
|
|
|
decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
} else {
|
|
|
|
decodeFn = decodeBaseline;
|
|
|
|
}
|
|
|
|
|
2017-03-24 00:08:59 +09:00
|
|
|
var mcu = 0, fileMarker;
|
2011-11-16 08:08:13 +09:00
|
|
|
var mcuExpected;
|
2014-08-02 05:43:55 +09:00
|
|
|
if (componentsLength === 1) {
|
2011-11-16 08:08:13 +09:00
|
|
|
mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
|
|
|
|
} else {
|
|
|
|
mcuExpected = mcusPerLine * frame.mcusPerColumn;
|
|
|
|
}
|
|
|
|
|
|
|
|
var h, v;
|
|
|
|
while (mcu < mcuExpected) {
|
|
|
|
// reset interval stuff
|
Don't read past the EOI marker for JPEG images with non-default restart interval (issue 7828)
*After browsing through (a version of) the JPEG specification, see https://www.w3.org/Graphics/JPEG/itu-t81.pdf, I hope that this patch makes sense.*
Note that while issue 7828 became a problem after PR 7661, it isn't really a regression from than PR. The explanation is rather that we're now relying on `core/jpg.js` instead of the Native Image decoder in more situations than before, which thus exposed an *existing* issue in our JPEG decoder.
Another factor also seems to be that in many JPEG images, the DRI (Define Restart Interval) marker isn't present, in which case this bug won't manifest either.
According to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=89 (at the bottom of the page):
"NOTE – The final restart interval may be smaller than the size specified by the DRI marker segment, as it includes only the number of MCUs remaining in the scan."
Furthermore, according to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=39 (in the middle of the page):
"[...] If restart is enabled and the restart interval is defined to be Ri, each entropy-coded segment except the last one shall contain Ri MCUs. The last one shall contain whatever number of MCUs completes the scan."
Based on the above, it thus seem to me that we should simply ensure that we're not attempting to continue to parse Scan data once we've found all MCUs (Minimum Coded Unit) of the image.
Fixes 7828.
2017-03-16 00:36:28 +09:00
|
|
|
var mcuToRead = resetInterval ?
|
|
|
|
Math.min(mcuExpected - mcu, resetInterval) : mcuExpected;
|
2014-03-21 23:16:02 +09:00
|
|
|
for (i = 0; i < componentsLength; i++) {
|
2011-11-16 08:08:13 +09:00
|
|
|
components[i].pred = 0;
|
2014-03-21 23:16:02 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
eobrun = 0;
|
|
|
|
|
2014-08-02 05:43:55 +09:00
|
|
|
if (componentsLength === 1) {
|
2011-11-16 08:08:13 +09:00
|
|
|
component = components[0];
|
Don't read past the EOI marker for JPEG images with non-default restart interval (issue 7828)
*After browsing through (a version of) the JPEG specification, see https://www.w3.org/Graphics/JPEG/itu-t81.pdf, I hope that this patch makes sense.*
Note that while issue 7828 became a problem after PR 7661, it isn't really a regression from than PR. The explanation is rather that we're now relying on `core/jpg.js` instead of the Native Image decoder in more situations than before, which thus exposed an *existing* issue in our JPEG decoder.
Another factor also seems to be that in many JPEG images, the DRI (Define Restart Interval) marker isn't present, in which case this bug won't manifest either.
According to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=89 (at the bottom of the page):
"NOTE – The final restart interval may be smaller than the size specified by the DRI marker segment, as it includes only the number of MCUs remaining in the scan."
Furthermore, according to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=39 (in the middle of the page):
"[...] If restart is enabled and the restart interval is defined to be Ri, each entropy-coded segment except the last one shall contain Ri MCUs. The last one shall contain whatever number of MCUs completes the scan."
Based on the above, it thus seem to me that we should simply ensure that we're not attempting to continue to parse Scan data once we've found all MCUs (Minimum Coded Unit) of the image.
Fixes 7828.
2017-03-16 00:36:28 +09:00
|
|
|
for (n = 0; n < mcuToRead; n++) {
|
2011-11-16 08:08:13 +09:00
|
|
|
decodeBlock(component, decodeFn, mcu);
|
|
|
|
mcu++;
|
|
|
|
}
|
|
|
|
} else {
|
Don't read past the EOI marker for JPEG images with non-default restart interval (issue 7828)
*After browsing through (a version of) the JPEG specification, see https://www.w3.org/Graphics/JPEG/itu-t81.pdf, I hope that this patch makes sense.*
Note that while issue 7828 became a problem after PR 7661, it isn't really a regression from than PR. The explanation is rather that we're now relying on `core/jpg.js` instead of the Native Image decoder in more situations than before, which thus exposed an *existing* issue in our JPEG decoder.
Another factor also seems to be that in many JPEG images, the DRI (Define Restart Interval) marker isn't present, in which case this bug won't manifest either.
According to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=89 (at the bottom of the page):
"NOTE – The final restart interval may be smaller than the size specified by the DRI marker segment, as it includes only the number of MCUs remaining in the scan."
Furthermore, according to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=39 (in the middle of the page):
"[...] If restart is enabled and the restart interval is defined to be Ri, each entropy-coded segment except the last one shall contain Ri MCUs. The last one shall contain whatever number of MCUs completes the scan."
Based on the above, it thus seem to me that we should simply ensure that we're not attempting to continue to parse Scan data once we've found all MCUs (Minimum Coded Unit) of the image.
Fixes 7828.
2017-03-16 00:36:28 +09:00
|
|
|
for (n = 0; n < mcuToRead; n++) {
|
2011-11-16 08:08:13 +09:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mcu++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find marker
|
|
|
|
bitsCount = 0;
|
2017-03-24 00:08:59 +09:00
|
|
|
fileMarker = findNextFileMarker(data, offset);
|
2019-08-08 17:31:48 +09:00
|
|
|
if (!fileMarker) {
|
|
|
|
// Reached the end of the image data without finding an EOI marker.
|
|
|
|
break;
|
|
|
|
} else if (fileMarker.invalid) {
|
|
|
|
// 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).
|
2018-02-01 18:35:38 +09:00
|
|
|
warn('decodeScan - unexpected MCU data, current marker is: ' +
|
2017-03-24 00:08:59 +09:00
|
|
|
fileMarker.invalid);
|
|
|
|
offset = fileMarker.offset;
|
2016-09-22 17:11:27 +09:00
|
|
|
}
|
2017-03-24 00:08:59 +09:00
|
|
|
var marker = fileMarker && fileMarker.marker;
|
|
|
|
if (!marker || marker <= 0xFF00) {
|
2019-08-08 17:31:48 +09:00
|
|
|
throw new JpegError('decodeScan - a valid marker was not found.');
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
|
|
|
|
offset += 2;
|
2014-03-21 23:16:02 +09:00
|
|
|
} else {
|
2011-11-16 08:08:13 +09:00
|
|
|
break;
|
2014-03-21 23:16:02 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
|
2017-03-24 00:08:59 +09:00
|
|
|
fileMarker = findNextFileMarker(data, offset);
|
|
|
|
// Some images include more Scan blocks than expected, skip past those and
|
|
|
|
// attempt to find the next valid marker (fixes issue8182.pdf).
|
|
|
|
if (fileMarker && fileMarker.invalid) {
|
2018-02-01 18:35:38 +09:00
|
|
|
warn('decodeScan - unexpected Scan data, current marker is: ' +
|
2017-03-24 00:08:59 +09:00
|
|
|
fileMarker.invalid);
|
|
|
|
offset = fileMarker.offset;
|
|
|
|
}
|
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
return offset - startOffset;
|
|
|
|
}
|
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
// A port of poppler's IDCT method which in turn is taken from:
|
|
|
|
// Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
|
2014-03-28 01:08:32 +09:00
|
|
|
// 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
|
2014-03-21 08:01:28 +09:00
|
|
|
// IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
|
|
|
|
// 988-991.
|
|
|
|
function quantizeAndInverse(component, blockBufferOffset, p) {
|
2014-06-17 17:09:17 +09:00
|
|
|
var qt = component.quantizationTable, blockData = component.blockData;
|
|
|
|
var v0, v1, v2, v3, v4, v5, v6, v7;
|
|
|
|
var p0, p1, p2, p3, p4, p5, p6, p7;
|
|
|
|
var t;
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2016-06-13 20:29:32 +09:00
|
|
|
if (!qt) {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError('missing required Quantization Table.');
|
2016-06-13 20:29:32 +09:00
|
|
|
}
|
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
// inverse DCT on rows
|
2014-06-17 17:09:17 +09:00
|
|
|
for (var row = 0; row < 64; row += 8) {
|
|
|
|
// 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-21 08:01:28 +09:00
|
|
|
|
|
|
|
// check for all-zero AC coefficients
|
2014-06-17 17:09:17 +09: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-21 08:01:28 +09:00
|
|
|
continue;
|
2011-11-23 02:32:20 +09:00
|
|
|
}
|
2014-06-17 17:09:17 +09: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-23 02:32:20 +09:00
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
// stage 4
|
2014-06-17 17:09:17 +09: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-21 08:01:28 +09:00
|
|
|
|
|
|
|
// stage 3
|
|
|
|
v0 = (v0 + v1 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v1 = v0 - v1;
|
|
|
|
t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
|
2014-03-21 08:01:28 +09:00
|
|
|
v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
|
|
|
|
v3 = t;
|
|
|
|
v4 = (v4 + v6 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v6 = v4 - v6;
|
|
|
|
v7 = (v7 + v5 + 1) >> 1;
|
|
|
|
v5 = v7 - v5;
|
2014-03-21 08:01:28 +09:00
|
|
|
|
|
|
|
// stage 2
|
|
|
|
v0 = (v0 + v3 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v3 = v0 - v3;
|
2014-03-21 08:01:28 +09:00
|
|
|
v1 = (v1 + v2 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v2 = v1 - v2;
|
|
|
|
t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
|
2014-03-21 08:01:28 +09:00
|
|
|
v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
|
|
|
|
v7 = t;
|
2014-06-17 17:09:17 +09:00
|
|
|
t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
|
2014-03-21 08:01:28 +09:00
|
|
|
v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
|
|
|
|
v6 = t;
|
|
|
|
|
|
|
|
// stage 1
|
2014-06-17 17:09:17 +09: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-21 08:01:28 +09:00
|
|
|
}
|
2011-11-23 02:32:20 +09:00
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
// inverse DCT on columns
|
2014-06-17 17:09:17 +09:00
|
|
|
for (var col = 0; col < 8; ++col) {
|
|
|
|
p0 = p[col];
|
|
|
|
p1 = p[col + 8];
|
|
|
|
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-21 08:01:28 +09:00
|
|
|
|
|
|
|
// check for all-zero AC coefficients
|
2014-06-17 17:09:17 +09:00
|
|
|
if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
|
|
|
|
t = (dctSqrt2 * p0 + 8192) >> 14;
|
|
|
|
// convert to 8 bit
|
|
|
|
t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
|
|
|
|
blockData[blockBufferOffset + col] = t;
|
|
|
|
blockData[blockBufferOffset + col + 8] = t;
|
|
|
|
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-21 08:01:28 +09:00
|
|
|
continue;
|
2011-11-23 02:32:20 +09:00
|
|
|
}
|
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
// stage 4
|
2014-06-17 17:09:17 +09: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-21 08:01:28 +09:00
|
|
|
|
|
|
|
// stage 3
|
2014-06-17 17:09:17 +09:00
|
|
|
// Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
|
2014-10-30 18:37:21 +09:00
|
|
|
// converting to UInt8 range later.
|
2014-06-17 17:09:17 +09:00
|
|
|
v0 = ((v0 + v1 + 1) >> 1) + 4112;
|
|
|
|
v1 = v0 - v1;
|
|
|
|
t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
|
2014-03-21 08:01:28 +09:00
|
|
|
v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
|
|
|
|
v3 = t;
|
|
|
|
v4 = (v4 + v6 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v6 = v4 - v6;
|
|
|
|
v7 = (v7 + v5 + 1) >> 1;
|
|
|
|
v5 = v7 - v5;
|
2014-03-21 08:01:28 +09:00
|
|
|
|
|
|
|
// stage 2
|
|
|
|
v0 = (v0 + v3 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v3 = v0 - v3;
|
2014-03-21 08:01:28 +09:00
|
|
|
v1 = (v1 + v2 + 1) >> 1;
|
2014-06-17 17:09:17 +09:00
|
|
|
v2 = v1 - v2;
|
|
|
|
t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
|
2014-03-21 08:01:28 +09:00
|
|
|
v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
|
|
|
|
v7 = t;
|
2014-06-17 17:09:17 +09:00
|
|
|
t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
|
2014-03-21 08:01:28 +09:00
|
|
|
v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
|
|
|
|
v6 = t;
|
|
|
|
|
|
|
|
// stage 1
|
2014-06-17 17:09:17 +09: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;
|
|
|
|
|
|
|
|
// convert to 8-bit integers
|
|
|
|
p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
|
|
|
|
p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
|
|
|
|
p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
|
|
|
|
p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
|
|
|
|
p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
|
|
|
|
p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
|
|
|
|
p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
|
|
|
|
p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
|
|
|
|
|
|
|
|
// store block data
|
|
|
|
blockData[blockBufferOffset + col] = p0;
|
|
|
|
blockData[blockBufferOffset + col + 8] = p1;
|
|
|
|
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-21 08:01:28 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildComponentData(frame, component) {
|
|
|
|
var blocksPerLine = component.blocksPerLine;
|
|
|
|
var blocksPerColumn = component.blocksPerColumn;
|
2014-06-17 17:09:17 +09:00
|
|
|
var computationBuffer = new Int16Array(64);
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
|
|
|
|
for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
|
2014-03-28 01:08:32 +09:00
|
|
|
var offset = getBlockBufferOffset(component, blockRow, blockCol);
|
2014-03-26 09:02:58 +09:00
|
|
|
quantizeAndInverse(component, offset, computationBuffer);
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
}
|
2014-03-26 09:02:58 +09:00
|
|
|
return component.blockData;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
|
2018-02-01 18:35:38 +09:00
|
|
|
function findNextFileMarker(data, currentPos, startPos = currentPos) {
|
2017-03-24 00:08:59 +09:00
|
|
|
function peekUint16(pos) {
|
|
|
|
return (data[pos] << 8) | data[pos + 1];
|
|
|
|
}
|
|
|
|
|
2018-02-01 18:35:38 +09:00
|
|
|
const maxPos = data.length - 1;
|
2017-03-24 00:08:59 +09:00
|
|
|
var newPos = startPos < currentPos ? startPos : currentPos;
|
|
|
|
|
|
|
|
if (currentPos >= maxPos) {
|
|
|
|
return null; // Don't attempt to read non-existent data and just return.
|
|
|
|
}
|
|
|
|
var currentMarker = peekUint16(currentPos);
|
|
|
|
if (currentMarker >= 0xFFC0 && currentMarker <= 0xFFFE) {
|
|
|
|
return {
|
|
|
|
invalid: null,
|
|
|
|
marker: currentMarker,
|
|
|
|
offset: currentPos,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
var newMarker = peekUint16(newPos);
|
|
|
|
while (!(newMarker >= 0xFFC0 && newMarker <= 0xFFFE)) {
|
|
|
|
if (++newPos >= maxPos) {
|
|
|
|
return null; // Don't attempt to read non-existent data and just return.
|
|
|
|
}
|
|
|
|
newMarker = peekUint16(newPos);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
invalid: currentMarker.toString(16),
|
|
|
|
marker: newMarker,
|
|
|
|
offset: newPos,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-22 21:07:20 +09:00
|
|
|
JpegImage.prototype = {
|
2018-02-02 04:43:01 +09:00
|
|
|
parse(data, { dnlScanLines = null, } = {}) {
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function readUint16() {
|
|
|
|
var value = (data[offset] << 8) | data[offset + 1];
|
|
|
|
offset += 2;
|
|
|
|
return value;
|
|
|
|
}
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function readDataBlock() {
|
|
|
|
var length = readUint16();
|
2017-03-17 18:29:08 +09:00
|
|
|
var endOffset = offset + length - 2;
|
|
|
|
|
2017-03-24 00:08:59 +09:00
|
|
|
var fileMarker = findNextFileMarker(data, endOffset, offset);
|
|
|
|
if (fileMarker && fileMarker.invalid) {
|
2018-02-01 18:35:38 +09:00
|
|
|
warn('readDataBlock - incorrect length, current marker is: ' +
|
2017-03-24 00:08:59 +09:00
|
|
|
fileMarker.invalid);
|
|
|
|
endOffset = fileMarker.offset;
|
2017-03-17 18:29:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
var array = data.subarray(offset, endOffset);
|
2011-11-16 08:08:13 +09:00
|
|
|
offset += array.length;
|
|
|
|
return array;
|
|
|
|
}
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
function prepareComponents(frame) {
|
2014-03-21 23:16:02 +09:00
|
|
|
var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
|
|
|
|
var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
|
2014-03-21 08:01:28 +09:00
|
|
|
for (var i = 0; i < frame.components.length; i++) {
|
|
|
|
component = frame.components[i];
|
2014-03-28 01:08:32 +09:00
|
|
|
var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
|
|
|
|
component.h / frame.maxH);
|
2016-12-10 22:28:27 +09:00
|
|
|
var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
|
2014-03-28 01:08:32 +09:00
|
|
|
component.v / frame.maxV);
|
2014-03-21 08:01:28 +09:00
|
|
|
var blocksPerLineForMcu = mcusPerLine * component.h;
|
|
|
|
var blocksPerColumnForMcu = mcusPerColumn * component.v;
|
|
|
|
|
2014-03-28 01:08:32 +09:00
|
|
|
var blocksBufferSize = 64 * blocksPerColumnForMcu *
|
|
|
|
(blocksPerLineForMcu + 1);
|
2014-03-26 09:02:58 +09:00
|
|
|
component.blockData = new Int16Array(blocksBufferSize);
|
2014-03-21 08:01:28 +09:00
|
|
|
component.blocksPerLine = blocksPerLine;
|
|
|
|
component.blocksPerColumn = blocksPerColumn;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
frame.mcusPerLine = mcusPerLine;
|
|
|
|
frame.mcusPerColumn = mcusPerColumn;
|
|
|
|
}
|
2014-03-21 08:01:28 +09:00
|
|
|
|
2015-12-17 06:31:30 +09:00
|
|
|
var offset = 0;
|
2011-11-16 08:08:13 +09:00
|
|
|
var jfif = null;
|
|
|
|
var adobe = null;
|
|
|
|
var frame, resetInterval;
|
2018-02-02 04:43:01 +09:00
|
|
|
let numSOSMarkers = 0;
|
2014-03-21 08:01:28 +09:00
|
|
|
var quantizationTables = [];
|
2011-11-16 08:08:13 +09:00
|
|
|
var huffmanTablesAC = [], huffmanTablesDC = [];
|
|
|
|
var fileMarker = readUint16();
|
2014-08-02 05:43:55 +09:00
|
|
|
if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError('SOI not found');
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
fileMarker = readUint16();
|
2018-05-16 21:26:12 +09:00
|
|
|
markerLoop: while (fileMarker !== 0xFFD9) { // EOI (End of image)
|
2011-11-16 08:08:13 +09:00
|
|
|
var i, j, l;
|
2016-11-01 23:04:21 +09:00
|
|
|
switch (fileMarker) {
|
2011-11-16 08:08:13 +09: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)
|
|
|
|
var appData = readDataBlock();
|
|
|
|
|
|
|
|
if (fileMarker === 0xFFE0) {
|
2014-03-28 01:08:32 +09:00
|
|
|
if (appData[0] === 0x4A && appData[1] === 0x46 &&
|
|
|
|
appData[2] === 0x49 && appData[3] === 0x46 &&
|
|
|
|
appData[4] === 0) { // 'JFIF\x00'
|
2011-11-16 08:08:13 +09:00
|
|
|
jfif = {
|
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 18:16:24 +09:00
|
|
|
version: { major: appData[5], minor: appData[6], },
|
2011-11-16 08:08:13 +09:00
|
|
|
densityUnits: appData[7],
|
|
|
|
xDensity: (appData[8] << 8) | appData[9],
|
|
|
|
yDensity: (appData[10] << 8) | appData[11],
|
|
|
|
thumbWidth: appData[12],
|
|
|
|
thumbHeight: appData[13],
|
2014-03-28 01:08:32 +09:00
|
|
|
thumbData: appData.subarray(14, 14 +
|
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 18:16:24 +09:00
|
|
|
3 * appData[12] * appData[13]),
|
2011-11-16 08:08:13 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO APP1 - Exif
|
|
|
|
if (fileMarker === 0xFFEE) {
|
2014-03-28 01:08:32 +09:00
|
|
|
if (appData[0] === 0x41 && appData[1] === 0x64 &&
|
|
|
|
appData[2] === 0x6F && appData[3] === 0x62 &&
|
2015-03-10 21:07:09 +09:00
|
|
|
appData[4] === 0x65) { // 'Adobe'
|
2011-11-16 08:08:13 +09:00
|
|
|
adobe = {
|
2015-03-10 21:07:09 +09:00
|
|
|
version: (appData[5] << 8) | appData[6],
|
2011-11-16 08:08:13 +09: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 18:16:24 +09:00
|
|
|
transformCode: appData[11],
|
2011-11-16 08:08:13 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFDB: // DQT (Define Quantization Tables)
|
2012-08-24 06:12:33 +09:00
|
|
|
var quantizationTablesLength = readUint16();
|
|
|
|
var quantizationTablesEnd = quantizationTablesLength + offset - 2;
|
2014-03-28 01:08:32 +09:00
|
|
|
var z;
|
2012-08-24 06:12:33 +09:00
|
|
|
while (offset < quantizationTablesEnd) {
|
2011-11-16 08:08:13 +09:00
|
|
|
var quantizationTableSpec = data[offset++];
|
2014-06-17 17:09:17 +09:00
|
|
|
var tableData = new Uint16Array(64);
|
2011-11-16 08:08:13 +09:00
|
|
|
if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
|
2011-11-23 02:32:20 +09:00
|
|
|
for (j = 0; j < 64; j++) {
|
2014-03-28 01:08:32 +09:00
|
|
|
z = dctZigZag[j];
|
2011-11-23 02:32:20 +09:00
|
|
|
tableData[z] = data[offset++];
|
|
|
|
}
|
2017-01-20 00:26:32 +09:00
|
|
|
} else if ((quantizationTableSpec >> 4) === 1) { // 16 bit values
|
2012-04-28 22:59:05 +09:00
|
|
|
for (j = 0; j < 64; j++) {
|
2014-03-28 01:08:32 +09:00
|
|
|
z = dctZigZag[j];
|
2012-04-28 22:59:05 +09:00
|
|
|
tableData[z] = readUint16();
|
|
|
|
}
|
2014-03-28 01:08:32 +09:00
|
|
|
} else {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError('DQT - invalid table spec');
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
quantizationTables[quantizationTableSpec & 15] = tableData;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
|
2013-06-26 02:35:34 +09:00
|
|
|
case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
|
2011-11-16 08:08:13 +09:00
|
|
|
case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
|
2014-03-21 08:01:28 +09:00
|
|
|
if (frame) {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError('Only single frame JPEGs supported');
|
2014-03-21 08:01:28 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
readUint16(); // skip data length
|
|
|
|
frame = {};
|
2013-06-26 02:35:34 +09:00
|
|
|
frame.extended = (fileMarker === 0xFFC1);
|
2011-11-16 08:08:13 +09:00
|
|
|
frame.progressive = (fileMarker === 0xFFC2);
|
|
|
|
frame.precision = data[offset++];
|
2018-02-02 04:43:01 +09:00
|
|
|
const sofScanLines = readUint16();
|
|
|
|
frame.scanLines = dnlScanLines || sofScanLines;
|
2011-11-16 08:08:13 +09:00
|
|
|
frame.samplesPerLine = readUint16();
|
2014-03-21 08:01:28 +09:00
|
|
|
frame.components = [];
|
|
|
|
frame.componentIds = {};
|
2011-11-16 08:08:13 +09:00
|
|
|
var componentsCount = data[offset++], componentId;
|
|
|
|
var maxH = 0, maxV = 0;
|
|
|
|
for (i = 0; i < componentsCount; i++) {
|
|
|
|
componentId = data[offset];
|
|
|
|
var h = data[offset + 1] >> 4;
|
|
|
|
var v = data[offset + 1] & 15;
|
2014-03-28 01:08:32 +09:00
|
|
|
if (maxH < h) {
|
|
|
|
maxH = h;
|
|
|
|
}
|
|
|
|
if (maxV < v) {
|
|
|
|
maxV = v;
|
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
var qId = data[offset + 2];
|
2014-03-28 01:08:32 +09:00
|
|
|
l = frame.components.push({
|
2017-04-27 19:58:44 +09:00
|
|
|
h,
|
|
|
|
v,
|
2016-06-13 20:29:32 +09:00
|
|
|
quantizationId: qId,
|
|
|
|
quantizationTable: null, // See comment below.
|
2014-03-21 08:01:28 +09:00
|
|
|
});
|
|
|
|
frame.componentIds[componentId] = l - 1;
|
2011-11-16 08:08:13 +09:00
|
|
|
offset += 3;
|
|
|
|
}
|
2014-03-21 08:01:28 +09:00
|
|
|
frame.maxH = maxH;
|
|
|
|
frame.maxV = maxV;
|
2011-11-16 08:08:13 +09:00
|
|
|
prepareComponents(frame);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFC4: // DHT (Define Huffman Tables)
|
|
|
|
var huffmanLength = readUint16();
|
|
|
|
for (i = 2; i < huffmanLength;) {
|
|
|
|
var huffmanTableSpec = data[offset++];
|
|
|
|
var codeLengths = new Uint8Array(16);
|
|
|
|
var codeLengthSum = 0;
|
2014-03-28 01:08:32 +09:00
|
|
|
for (j = 0; j < 16; j++, offset++) {
|
2011-11-16 08:08:13 +09:00
|
|
|
codeLengthSum += (codeLengths[j] = data[offset]);
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
var huffmanValues = new Uint8Array(codeLengthSum);
|
2014-03-28 01:08:32 +09:00
|
|
|
for (j = 0; j < codeLengthSum; j++, offset++) {
|
2011-11-16 08:08:13 +09:00
|
|
|
huffmanValues[j] = data[offset];
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2011-11-16 08:08:13 +09:00
|
|
|
i += 17 + codeLengthSum;
|
|
|
|
|
2014-03-21 08:01:28 +09:00
|
|
|
((huffmanTableSpec >> 4) === 0 ?
|
2011-11-16 08:08:13 +09:00
|
|
|
huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
|
|
|
|
buildHuffmanTable(codeLengths, huffmanValues);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFDD: // DRI (Define Restart Interval)
|
|
|
|
readUint16(); // skip data length
|
|
|
|
resetInterval = readUint16();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFDA: // SOS (Start of Scan)
|
2018-02-02 04:43:01 +09: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.
|
|
|
|
const parseDNLMarker = (++numSOSMarkers) === 1 && !dnlScanLines;
|
|
|
|
|
2017-01-19 22:00:36 +09:00
|
|
|
readUint16(); // scanLength
|
2011-11-16 08:08:13 +09:00
|
|
|
var selectorsCount = data[offset++];
|
|
|
|
var components = [], component;
|
|
|
|
for (i = 0; i < selectorsCount; i++) {
|
2014-03-21 08:01:28 +09:00
|
|
|
var componentIndex = frame.componentIds[data[offset++]];
|
|
|
|
component = frame.components[componentIndex];
|
2011-11-16 08:08:13 +09:00
|
|
|
var tableSpec = data[offset++];
|
|
|
|
component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
|
|
|
|
component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
|
|
|
|
components.push(component);
|
|
|
|
}
|
|
|
|
var spectralStart = data[offset++];
|
|
|
|
var spectralEnd = data[offset++];
|
|
|
|
var successiveApproximation = data[offset++];
|
2018-02-02 04:43:01 +09:00
|
|
|
try {
|
|
|
|
var processed = decodeScan(data, offset,
|
|
|
|
frame, components, resetInterval,
|
|
|
|
spectralStart, spectralEnd,
|
|
|
|
successiveApproximation >> 4, successiveApproximation & 15,
|
|
|
|
parseDNLMarker);
|
|
|
|
offset += processed;
|
|
|
|
} catch (ex) {
|
|
|
|
if (ex instanceof DNLMarkerError) {
|
2018-05-29 18:33:33 +09:00
|
|
|
warn(`${ex.message} -- attempting to re-parse the JPEG image.`);
|
2018-02-02 04:43:01 +09:00
|
|
|
return this.parse(data, { dnlScanLines: ex.scanLines, });
|
2018-05-16 21:26:12 +09:00
|
|
|
} else if (ex instanceof EOIMarkerError) {
|
|
|
|
warn(`${ex.message} -- ignoring the rest of the image data.`);
|
|
|
|
break markerLoop;
|
2018-02-02 04:43:01 +09:00
|
|
|
}
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFDC: // DNL (Define Number of Lines)
|
|
|
|
// Ignore the marker, since it's being handled in `decodeScan`.
|
|
|
|
offset += 4;
|
2011-11-16 08:08:13 +09:00
|
|
|
break;
|
2015-02-14 08:08:43 +09:00
|
|
|
|
|
|
|
case 0xFFFF: // Fill bytes
|
|
|
|
if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
|
|
|
|
offset--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-11-16 08:08:13 +09:00
|
|
|
default:
|
2014-08-02 05:43:55 +09:00
|
|
|
if (data[offset - 3] === 0xFF &&
|
2012-08-24 06:12:33 +09:00
|
|
|
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
|
|
|
|
// could be incorrect encoding -- last 0xFF byte of the previous
|
|
|
|
// block was eaten by the encoder
|
|
|
|
offset -= 3;
|
|
|
|
break;
|
|
|
|
}
|
2018-02-01 18:35:38 +09:00
|
|
|
let nextFileMarker = findNextFileMarker(data, offset - 2);
|
|
|
|
if (nextFileMarker && nextFileMarker.invalid) {
|
|
|
|
warn('JpegImage.parse - unexpected data, current marker is: ' +
|
|
|
|
nextFileMarker.invalid);
|
|
|
|
offset = nextFileMarker.offset;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-08 17:31:48 +09:00
|
|
|
if (offset > (data.length - 2)) {
|
|
|
|
warn('JpegImage.parse - reached the end of the image data ' +
|
|
|
|
'without finding an EOI marker (0xFFD9).');
|
|
|
|
break markerLoop;
|
|
|
|
}
|
|
|
|
throw new JpegError('JpegImage.parse - unknown marker: ' +
|
|
|
|
fileMarker.toString(16));
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
|
|
|
fileMarker = readUint16();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.width = frame.samplesPerLine;
|
|
|
|
this.height = frame.scanLines;
|
|
|
|
this.jfif = jfif;
|
|
|
|
this.adobe = adobe;
|
|
|
|
this.components = [];
|
2014-03-28 01:08:32 +09:00
|
|
|
for (i = 0; i < frame.components.length; i++) {
|
|
|
|
component = frame.components[i];
|
2016-06-13 20:29:32 +09: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).
|
|
|
|
var quantizationTable = quantizationTables[component.quantizationId];
|
|
|
|
if (quantizationTable) {
|
|
|
|
component.quantizationTable = quantizationTable;
|
|
|
|
}
|
|
|
|
|
2012-04-28 22:59:05 +09:00
|
|
|
this.components.push({
|
2014-03-26 09:02:58 +09:00
|
|
|
output: buildComponentData(frame, component),
|
2012-04-28 22:59:05 +09:00
|
|
|
scaleX: component.h / frame.maxH,
|
2014-03-26 09:02:58 +09: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 18:16:24 +09:00
|
|
|
blocksPerColumn: component.blocksPerColumn,
|
2012-04-28 22:59:05 +09:00
|
|
|
});
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2014-03-27 19:11:28 +09:00
|
|
|
this.numComponents = this.components.length;
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2011-11-16 08:08:13 +09:00
|
|
|
},
|
2014-03-26 09:02:58 +09:00
|
|
|
|
2018-09-02 20:55:27 +09:00
|
|
|
_getLinearizedBlockData(width, height, isSourcePDF = false) {
|
2011-11-16 08:08:13 +09:00
|
|
|
var scaleX = this.width / width, scaleY = this.height / height;
|
|
|
|
|
2014-04-30 00:09:54 +09:00
|
|
|
var component, componentScaleX, componentScaleY, blocksPerScanline;
|
2014-06-03 22:51:57 +09:00
|
|
|
var x, y, i, j, k;
|
2014-04-30 00:09:54 +09:00
|
|
|
var index;
|
2011-11-16 08:08:13 +09:00
|
|
|
var offset = 0;
|
2014-04-30 00:09:54 +09:00
|
|
|
var output;
|
2014-02-19 00:24:59 +09:00
|
|
|
var numComponents = this.components.length;
|
|
|
|
var dataLength = width * height * numComponents;
|
2017-08-14 22:42:11 +09:00
|
|
|
var data = new Uint8ClampedArray(dataLength);
|
2014-04-30 00:09:54 +09:00
|
|
|
var xScaleBlockOffset = new Uint32Array(width);
|
|
|
|
var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
|
2014-03-26 09:02:58 +09:00
|
|
|
|
2014-02-19 00:24:59 +09:00
|
|
|
for (i = 0; i < numComponents; i++) {
|
|
|
|
component = this.components[i];
|
|
|
|
componentScaleX = component.scaleX * scaleX;
|
|
|
|
componentScaleY = component.scaleY * scaleY;
|
|
|
|
offset = i;
|
2014-04-30 00:09:54 +09:00
|
|
|
output = component.output;
|
|
|
|
blocksPerScanline = (component.blocksPerLine + 1) << 3;
|
|
|
|
// precalculate the xScaleBlockOffset
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
j = 0 | (x * componentScaleX);
|
|
|
|
xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
|
|
|
|
}
|
|
|
|
// linearize the blocks of the component
|
2014-02-19 00:24:59 +09:00
|
|
|
for (y = 0; y < height; y++) {
|
2014-04-30 00:09:54 +09:00
|
|
|
j = 0 | (y * componentScaleY);
|
|
|
|
index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
|
2014-02-19 00:24:59 +09:00
|
|
|
for (x = 0; x < width; x++) {
|
2014-04-30 00:09:54 +09:00
|
|
|
data[offset] = output[index + xScaleBlockOffset[x]];
|
2014-02-19 00:24:59 +09:00
|
|
|
offset += numComponents;
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2014-02-19 00:24:59 +09:00
|
|
|
}
|
|
|
|
}
|
2014-06-03 22:51:57 +09:00
|
|
|
|
2014-10-30 17:18:52 +09:00
|
|
|
// decodeTransform contains pairs of multiplier (-256..256) and additive
|
2018-09-02 20:55:27 +09: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 18:30:59 +09:00
|
|
|
if (!isSourcePDF && numComponents === 4 && !transform) {
|
2018-09-02 20:55:27 +09:00
|
|
|
transform = new Int32Array([
|
|
|
|
-256, 255, -256, 255, -256, 255, -256, 255]);
|
|
|
|
}
|
|
|
|
|
2014-06-03 22:51:57 +09:00
|
|
|
if (transform) {
|
|
|
|
for (i = 0; i < dataLength;) {
|
|
|
|
for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
|
|
|
|
data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-27 19:11:28 +09:00
|
|
|
return data;
|
|
|
|
},
|
2014-02-19 00:24:59 +09:00
|
|
|
|
2018-09-02 20:06:28 +09:00
|
|
|
get _isColorConversionNeeded() {
|
2017-07-11 23:25:47 +09:00
|
|
|
if (this.adobe) {
|
|
|
|
// The adobe transform marker overrides any previous setting.
|
|
|
|
return !!this.adobe.transformCode;
|
|
|
|
}
|
|
|
|
if (this.numComponents === 3) {
|
2018-05-16 20:49:01 +09:00
|
|
|
if (this._colorTransform === 0) {
|
2016-09-22 21:07:20 +09: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;
|
|
|
|
}
|
2014-03-27 19:11:28 +09:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-16 21:05:33 +09:00
|
|
|
// `this.numComponents !== 3`
|
2018-05-16 20:49:01 +09:00
|
|
|
if (this._colorTransform === 1) {
|
2016-12-16 21:05:33 +09: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 19:11:28 +09:00
|
|
|
},
|
2014-02-19 00:24:59 +09:00
|
|
|
|
2014-03-27 19:11:28 +09:00
|
|
|
_convertYccToRgb: function convertYccToRgb(data) {
|
|
|
|
var Y, Cb, Cr;
|
2014-06-04 17:02:47 +09:00
|
|
|
for (var i = 0, length = data.length; i < length; i += 3) {
|
2017-08-14 22:42:11 +09:00
|
|
|
Y = data[i];
|
2014-03-27 19:11:28 +09:00
|
|
|
Cb = data[i + 1];
|
|
|
|
Cr = data[i + 2];
|
2017-08-14 22:42:11 +09: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 19:11:28 +09:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertYcckToRgb: function convertYcckToRgb(data) {
|
2014-10-30 18:37:21 +09:00
|
|
|
var Y, Cb, Cr, k;
|
2014-03-27 19:11:28 +09:00
|
|
|
var offset = 0;
|
2014-06-04 17:02:47 +09:00
|
|
|
for (var i = 0, length = data.length; i < length; i += 4) {
|
2017-08-14 22:42:11 +09:00
|
|
|
Y = data[i];
|
2014-03-27 19:11:28 +09:00
|
|
|
Cb = data[i + 1];
|
|
|
|
Cr = data[i + 2];
|
2014-03-28 01:08:32 +09:00
|
|
|
k = data[i + 3];
|
|
|
|
|
2017-08-14 22:42:11 +09:00
|
|
|
data[offset++] = -122.67195406894 +
|
2014-10-30 18:37:21 +09:00
|
|
|
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) +
|
|
|
|
k * (-0.000336197177618394 * k + 0.484791561490776);
|
2014-03-28 01:08:32 +09:00
|
|
|
|
2017-08-14 22:42:11 +09:00
|
|
|
data[offset++] = 107.268039397724 +
|
2014-10-30 18:37:21 +09:00
|
|
|
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) +
|
|
|
|
k * (-0.000318913117588328 * k - 0.213742400323665);
|
|
|
|
|
2017-08-14 22:42:11 +09:00
|
|
|
data[offset++] = -20.810012546947 +
|
2014-10-30 18:37:21 +09:00
|
|
|
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) +
|
|
|
|
k * (-0.000343531996510555 * k + 0.24165260232407);
|
2014-03-28 01:08:32 +09:00
|
|
|
}
|
2018-02-11 21:13:11 +09:00
|
|
|
// Ensure that only the converted RGB data is returned.
|
|
|
|
return data.subarray(0, offset);
|
2014-03-27 19:11:28 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
_convertYcckToCmyk: function convertYcckToCmyk(data) {
|
|
|
|
var Y, Cb, Cr;
|
2014-06-04 17:02:47 +09:00
|
|
|
for (var i = 0, length = data.length; i < length; i += 4) {
|
2017-08-14 22:42:11 +09:00
|
|
|
Y = data[i];
|
2014-03-27 19:11:28 +09:00
|
|
|
Cb = data[i + 1];
|
|
|
|
Cr = data[i + 2];
|
2017-08-14 22:42:11 +09: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 19:11:28 +09:00
|
|
|
// K in data[i + 3] is unchanged
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertCmykToRgb: function convertCmykToRgb(data) {
|
2014-03-28 01:08:32 +09:00
|
|
|
var c, m, y, k;
|
2014-03-27 19:11:28 +09:00
|
|
|
var offset = 0;
|
2017-08-14 22:42:11 +09:00
|
|
|
var scale = 1 / 255;
|
2014-06-04 17:02:47 +09:00
|
|
|
for (var i = 0, length = data.length; i < length; i += 4) {
|
2017-08-14 22:42:11 +09:00
|
|
|
c = data[i] * scale;
|
|
|
|
m = data[i + 1] * scale;
|
|
|
|
y = data[i + 2] * scale;
|
|
|
|
k = data[i + 3] * scale;
|
2014-03-28 01:08:32 +09:00
|
|
|
|
2017-08-14 22:42:11 +09:00
|
|
|
data[offset++] = 255 +
|
2014-03-28 01:08:32 +09:00
|
|
|
c * (-4.387332384609988 * c + 54.48615194189176 * m +
|
2014-04-30 22:54:31 +09:00
|
|
|
18.82290502165302 * y + 212.25662451639585 * k -
|
2017-08-14 22:42:11 +09:00
|
|
|
285.2331026137004) +
|
2014-04-30 22:54:31 +09:00
|
|
|
m * (1.7149763477362134 * m - 5.6096736904047315 * y -
|
2017-08-14 22:42:11 +09:00
|
|
|
17.873870861415444 * k - 5.497006427196366) +
|
2014-03-28 01:08:32 +09:00
|
|
|
y * (-2.5217340131683033 * y - 21.248923337353073 * k +
|
2017-08-14 22:42:11 +09:00
|
|
|
17.5119270841813) -
|
|
|
|
k * (21.86122147463605 * k + 189.48180835922747);
|
|
|
|
|
|
|
|
data[offset++] = 255 +
|
2014-03-28 01:08:32 +09:00
|
|
|
c * (8.841041422036149 * c + 60.118027045597366 * m +
|
2014-04-30 22:54:31 +09:00
|
|
|
6.871425592049007 * y + 31.159100130055922 * k -
|
2017-08-14 22:42:11 +09:00
|
|
|
79.2970844816548) +
|
2014-03-28 01:08:32 +09:00
|
|
|
m * (-15.310361306967817 * m + 17.575251261109482 * y +
|
2017-08-14 22:42:11 +09:00
|
|
|
131.35250912493976 * k - 190.9453302588951) +
|
2014-04-30 22:54:31 +09:00
|
|
|
y * (4.444339102852739 * y + 9.8632861493405 * k -
|
2017-08-14 22:42:11 +09:00
|
|
|
24.86741582555878) -
|
|
|
|
k * (20.737325471181034 * k + 187.80453709719578);
|
|
|
|
|
|
|
|
data[offset++] = 255 +
|
2014-03-28 01:08:32 +09:00
|
|
|
c * (0.8842522430003296 * c + 8.078677503112928 * m +
|
2014-04-30 22:54:31 +09:00
|
|
|
30.89978309703729 * y - 0.23883238689178934 * k -
|
2017-08-14 22:42:11 +09:00
|
|
|
14.183576799673286) +
|
2014-03-28 01:08:32 +09:00
|
|
|
m * (10.49593273432072 * m + 63.02378494754052 * y +
|
2017-08-14 22:42:11 +09:00
|
|
|
50.606957656360734 * k - 112.23884253719248) +
|
2014-04-30 22:54:31 +09:00
|
|
|
y * (0.03296041114873217 * y + 115.60384449646641 * k -
|
2017-08-14 22:42:11 +09:00
|
|
|
193.58209356861505) -
|
|
|
|
k * (22.33816807309886 * k + 180.12613974708367);
|
2014-03-27 19:11:28 +09:00
|
|
|
}
|
2018-02-11 21:13:11 +09:00
|
|
|
// Ensure that only the converted RGB data is returned.
|
|
|
|
return data.subarray(0, offset);
|
2014-03-27 19:11:28 +09:00
|
|
|
},
|
|
|
|
|
2018-09-02 20:55:27 +09:00
|
|
|
getData({ width, height, forceRGB = false, isSourcePDF = false, }) {
|
2018-09-12 18:30:59 +09:00
|
|
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('TESTING && !LIB')) {
|
|
|
|
assert(isSourcePDF === true,
|
|
|
|
'JpegImage.getData: Unexpected "isSourcePDF" value for PDF files.');
|
|
|
|
}
|
2014-03-27 19:11:28 +09:00
|
|
|
if (this.numComponents > 4) {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new JpegError('Unsupported color mode');
|
2014-03-27 19:11:28 +09:00
|
|
|
}
|
2018-09-02 20:55:27 +09:00
|
|
|
// Type of data: Uint8ClampedArray(width * height * numComponents)
|
|
|
|
var data = this._getLinearizedBlockData(width, height, isSourcePDF);
|
2014-03-27 19:11:28 +09:00
|
|
|
|
2018-09-02 20:55:27 +09:00
|
|
|
if (this.numComponents === 1 && forceRGB) {
|
2016-02-08 21:49:30 +09:00
|
|
|
var dataLength = data.length;
|
2017-08-14 22:42:11 +09:00
|
|
|
var rgbData = new Uint8ClampedArray(dataLength * 3);
|
2016-02-08 21:49:30 +09:00
|
|
|
var offset = 0;
|
|
|
|
for (var i = 0; i < dataLength; i++) {
|
|
|
|
var grayColor = data[i];
|
|
|
|
rgbData[offset++] = grayColor;
|
|
|
|
rgbData[offset++] = grayColor;
|
|
|
|
rgbData[offset++] = grayColor;
|
|
|
|
}
|
|
|
|
return rgbData;
|
2018-09-02 20:06:28 +09:00
|
|
|
} else if (this.numComponents === 3 && this._isColorConversionNeeded) {
|
2014-03-27 19:11:28 +09:00
|
|
|
return this._convertYccToRgb(data);
|
|
|
|
} else if (this.numComponents === 4) {
|
2018-09-02 20:06:28 +09:00
|
|
|
if (this._isColorConversionNeeded) {
|
2018-09-02 20:55:27 +09:00
|
|
|
if (forceRGB) {
|
2014-03-27 19:11:28 +09:00
|
|
|
return this._convertYcckToRgb(data);
|
2011-11-16 08:08:13 +09:00
|
|
|
}
|
2016-12-16 21:05:33 +09:00
|
|
|
return this._convertYcckToCmyk(data);
|
2018-09-02 20:55:27 +09:00
|
|
|
} else if (forceRGB) {
|
2014-03-27 19:11:28 +09:00
|
|
|
return this._convertCmykToRgb(data);
|
|
|
|
}
|
2011-11-16 08:08:13 +09: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 18:16:24 +09:00
|
|
|
},
|
2011-11-16 08:08:13 +09:00
|
|
|
};
|
|
|
|
|
2016-09-22 21:07:20 +09:00
|
|
|
return JpegImage;
|
2012-08-31 20:37:44 +09:00
|
|
|
})();
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2017-04-02 23:14:30 +09:00
|
|
|
export {
|
|
|
|
JpegImage,
|
|
|
|
};
|