image-js 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +9 -2
- package/lib/browser/environment.js +3 -2
- package/lib/image/core/environment.js +3 -2
- package/lib/image/core/kind.js +2 -2
- package/lib/image/core/kindNames.js +1 -1
- package/lib/image/core/load.js +16 -11
- package/lib/image/internal/checks.js +2 -2
- package/lib/image/model/model.js +1 -1
- package/lib/index.js +9 -8
- package/lib/util/base64.js +1 -1
- package/lib/util/color.js +1 -1
- package/lib/util/converter.js +1 -1
- package/lib/util/histogram.js +1 -1
- package/lib/util/kernels.js +1 -1
- package/lib/util/points.js +7 -7
- package/package.json +14 -14
- package/src/browser/worker/worker.js +2 -0
- package/src/image/core/export.js +2 -0
- package/src/image/core/load.js +31 -11
- package/src/image/roi/creator/fromMask.js +1 -0
- package/src/image/transform/mask/minimum.js +3 -0
package/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class Image {
|
|
|
32
32
|
static createFrom(other: Image, options: ImageConstructorOptions): Image;
|
|
33
33
|
static load(
|
|
34
34
|
image: string | ArrayBuffer | Uint8Array,
|
|
35
|
-
options?: RequestInit,
|
|
35
|
+
options?: RequestInit & { ignorePalette: boolean },
|
|
36
36
|
): Promise<Image>;
|
|
37
37
|
|
|
38
38
|
getRoiManager(): RoiManager;
|
|
@@ -149,7 +149,14 @@ export declare class Image {
|
|
|
149
149
|
// paintPoints
|
|
150
150
|
// paintPolyline
|
|
151
151
|
// paintPolylines
|
|
152
|
-
|
|
152
|
+
paintPolygon(
|
|
153
|
+
points: Array<Array<number>>,
|
|
154
|
+
options?: {
|
|
155
|
+
color?: Array<number>;
|
|
156
|
+
filled?: boolean;
|
|
157
|
+
},
|
|
158
|
+
): Image;
|
|
159
|
+
|
|
153
160
|
// paintPolygons
|
|
154
161
|
|
|
155
162
|
// countAlphaPixels
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.ImageData = exports.DOMImage = void 0;
|
|
6
7
|
exports.createCanvas = createCanvas;
|
|
7
|
-
exports.fetchBinary = fetchBinary;
|
|
8
8
|
exports.createWriteStream = createWriteStream;
|
|
9
|
+
exports.env = void 0;
|
|
10
|
+
exports.fetchBinary = fetchBinary;
|
|
9
11
|
exports.writeFile = writeFile;
|
|
10
|
-
exports.DOMImage = exports.ImageData = exports.env = void 0;
|
|
11
12
|
const env = 'browser';
|
|
12
13
|
exports.env = env;
|
|
13
14
|
const ImageData = self.ImageData;
|
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createCanvas = exports.ImageData = exports.DOMImage = void 0;
|
|
7
7
|
Object.defineProperty(exports, "createWriteStream", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function () {
|
|
10
10
|
return _fs.createWriteStream;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
+
exports.env = void 0;
|
|
14
|
+
exports.fetchBinary = fetchBinary;
|
|
13
15
|
Object.defineProperty(exports, "writeFile", {
|
|
14
16
|
enumerable: true,
|
|
15
17
|
get: function () {
|
|
16
18
|
return _fs.writeFile;
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
|
-
exports.DOMImage = exports.ImageData = exports.createCanvas = exports.env = void 0;
|
|
20
21
|
|
|
21
22
|
var _fs = require("fs");
|
|
22
23
|
|
package/lib/image/core/kind.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.createPixelArray = createPixelArray;
|
|
6
7
|
exports.getKind = getKind;
|
|
7
|
-
exports.verifyKindDefinition = verifyKindDefinition;
|
|
8
8
|
exports.getTheoreticalPixelArraySize = getTheoreticalPixelArraySize;
|
|
9
|
-
exports.
|
|
9
|
+
exports.verifyKindDefinition = verifyKindDefinition;
|
|
10
10
|
|
|
11
11
|
var ColorModel = _interopRequireWildcard(require("../model/model"));
|
|
12
12
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.RGBA = exports.RGB = exports.GREYA = exports.GREY = exports.CMYKA = exports.CMYK = exports.BINARY = void 0;
|
|
7
7
|
// Shortcuts for common image kinds
|
|
8
8
|
const BINARY = 'BINARY';
|
|
9
9
|
exports.BINARY = BINARY;
|
package/lib/image/core/load.js
CHANGED
|
@@ -34,7 +34,10 @@ const isDataURL = /^data:[a-z]+\/(?:[a-z]+);base64,/;
|
|
|
34
34
|
* @static
|
|
35
35
|
* @param {string|ArrayBuffer|Buffer|Uint8Array} image - URL of the image (browser, can be a dataURL) or path (Node.js)
|
|
36
36
|
* or buffer containing the binary data
|
|
37
|
-
* @param {object} [options] - In the browser, the options object is passed to the underlying `fetch` call
|
|
37
|
+
* @param {object} [options] - In the browser, the options object is passed to the underlying `fetch` call, along with
|
|
38
|
+
* the data URL. For binary data, the option specify decoding options.
|
|
39
|
+
* @param {boolean} [options.ignorePalette] - When set to true and loading a tiff from binary data, if the tiff is of
|
|
40
|
+
* type 3 (palette), load as single channel greyscale rather than as a pseudo-colored RGB.
|
|
38
41
|
* @return {Promise<Image>}
|
|
39
42
|
* @example
|
|
40
43
|
* const image = await Image.load('https://example.com/image.png');
|
|
@@ -44,15 +47,15 @@ function load(image, options) {
|
|
|
44
47
|
if (typeof image === 'string') {
|
|
45
48
|
return loadURL(image, options);
|
|
46
49
|
} else if (image instanceof ArrayBuffer) {
|
|
47
|
-
return Promise.resolve(loadBinary(new Uint8Array(image)));
|
|
50
|
+
return Promise.resolve(loadBinary(new Uint8Array(image), undefined, options && options.ignorePalette));
|
|
48
51
|
} else if (image.buffer) {
|
|
49
|
-
return Promise.resolve(loadBinary(image));
|
|
52
|
+
return Promise.resolve(loadBinary(image, undefined, options && options.ignorePalette));
|
|
50
53
|
} else {
|
|
51
54
|
throw new Error('argument to "load" must be a string or buffer.');
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
function loadBinary(image, base64Url) {
|
|
58
|
+
function loadBinary(image, base64Url, ignorePalette) {
|
|
56
59
|
const type = (0, _imageType.default)(image);
|
|
57
60
|
|
|
58
61
|
if (type) {
|
|
@@ -64,7 +67,7 @@ function loadBinary(image, base64Url) {
|
|
|
64
67
|
return loadJPEG(image);
|
|
65
68
|
|
|
66
69
|
case 'image/tiff':
|
|
67
|
-
return loadTIFF(image);
|
|
70
|
+
return loadTIFF(image, ignorePalette);
|
|
68
71
|
|
|
69
72
|
default:
|
|
70
73
|
return loadGeneric(getBase64(type.mime));
|
|
@@ -94,7 +97,7 @@ function loadURL(url, options) {
|
|
|
94
97
|
|
|
95
98
|
return binaryDataP.then(binaryData => {
|
|
96
99
|
const uint8 = new Uint8Array(binaryData);
|
|
97
|
-
return loadBinary(uint8, dataURL ? url : undefined);
|
|
100
|
+
return loadBinary(uint8, dataURL ? url : undefined, options && options.ignorePalette);
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
|
|
@@ -195,13 +198,15 @@ function loadJPEG(data) {
|
|
|
195
198
|
return image;
|
|
196
199
|
}
|
|
197
200
|
|
|
198
|
-
function loadTIFF(data) {
|
|
201
|
+
function loadTIFF(data, ignorePalette) {
|
|
199
202
|
let result = (0, _tiff.decode)(data);
|
|
200
203
|
|
|
201
204
|
if (result.length === 1) {
|
|
202
|
-
return getImageFromIFD(result[0]);
|
|
205
|
+
return getImageFromIFD(result[0], ignorePalette);
|
|
203
206
|
} else {
|
|
204
|
-
return new _Stack.default(result.map(
|
|
207
|
+
return new _Stack.default(result.map(function (image) {
|
|
208
|
+
return getImageFromIFD(image, ignorePalette);
|
|
209
|
+
}));
|
|
205
210
|
}
|
|
206
211
|
}
|
|
207
212
|
|
|
@@ -224,8 +229,8 @@ function getMetadata(image) {
|
|
|
224
229
|
return metadata;
|
|
225
230
|
}
|
|
226
231
|
|
|
227
|
-
function getImageFromIFD(image) {
|
|
228
|
-
if (image.type === 3) {
|
|
232
|
+
function getImageFromIFD(image, ignorePalette) {
|
|
233
|
+
if (!ignorePalette && image.type === 3) {
|
|
229
234
|
// Palette
|
|
230
235
|
const data = new Uint16Array(3 * image.width * image.height);
|
|
231
236
|
const palette = image.palette;
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.checkRow = checkRow;
|
|
7
|
-
exports.checkColumn = checkColumn;
|
|
8
6
|
exports.checkChannel = checkChannel;
|
|
7
|
+
exports.checkColumn = checkColumn;
|
|
9
8
|
exports.checkInterpolation = checkInterpolation;
|
|
9
|
+
exports.checkRow = checkRow;
|
|
10
10
|
exports.validInterpolations = void 0;
|
|
11
11
|
|
|
12
12
|
function checkRow(image, row) {
|
package/lib/image/model/model.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.RGB = exports.HSV = exports.HSL = exports.GREY = exports.CMYK = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Color model of an image
|
package/lib/index.js
CHANGED
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "Image", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
9
|
return _Image.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
exports.Kernel = void 0;
|
|
13
|
+
Object.defineProperty(exports, "Shape", {
|
|
13
14
|
enumerable: true,
|
|
14
15
|
get: function () {
|
|
15
|
-
return
|
|
16
|
+
return _Shape.default;
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
19
|
Object.defineProperty(exports, "Stack", {
|
|
@@ -21,19 +22,19 @@ Object.defineProperty(exports, "Stack", {
|
|
|
21
22
|
return _Stack.default;
|
|
22
23
|
}
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
+
exports.Static = void 0;
|
|
26
|
+
Object.defineProperty(exports, "Worker", {
|
|
25
27
|
enumerable: true,
|
|
26
28
|
get: function () {
|
|
27
|
-
return
|
|
29
|
+
return _worker.default;
|
|
28
30
|
}
|
|
29
31
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
32
|
+
Object.defineProperty(exports, "default", {
|
|
31
33
|
enumerable: true,
|
|
32
34
|
get: function () {
|
|
33
|
-
return
|
|
35
|
+
return _Image.default;
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
|
-
exports.Kernel = exports.Static = void 0;
|
|
37
38
|
|
|
38
39
|
var _Image = _interopRequireDefault(require("./image/Image"));
|
|
39
40
|
|
package/lib/util/base64.js
CHANGED
package/lib/util/color.js
CHANGED
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.css2array = css2array;
|
|
7
|
+
exports.getColors = getColors;
|
|
7
8
|
exports.getDistinctColors = getDistinctColors;
|
|
8
9
|
exports.getRandomColor = getRandomColor;
|
|
9
|
-
exports.getColors = getColors;
|
|
10
10
|
|
|
11
11
|
var _colorFns = require("@swiftcarrot/color-fns");
|
|
12
12
|
|
package/lib/util/converter.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.factorDimensions = factorDimensions;
|
|
6
7
|
exports.getFactor = getFactor;
|
|
7
8
|
exports.getThreshold = getThreshold;
|
|
8
|
-
exports.factorDimensions = factorDimensions;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Converts a factor value to a number between 0 and 1
|
package/lib/util/histogram.js
CHANGED
package/lib/util/kernels.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.SOBEL_Y = exports.SOBEL_X = exports.SECOND_DERIVATIVE_INV = exports.SECOND_DERIVATIVE = exports.SCHARR_Y = exports.SCHARR_X = exports.DISCRETE_LAPLACE_8 = exports.DISCRETE_LAPLACE_4 = void 0;
|
|
7
7
|
const DISCRETE_LAPLACE_4 = [[0, 1, 0], [1, -4, 1], [0, 1, 0]];
|
|
8
8
|
exports.DISCRETE_LAPLACE_4 = DISCRETE_LAPLACE_4;
|
|
9
9
|
const DISCRETE_LAPLACE_8 = [[1, 1, 1], [1, -8, 1], [1, 1, 1]];
|
package/lib/util/points.js
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.round = round;
|
|
7
|
-
exports.difference = difference;
|
|
8
|
-
exports.normalize = normalize;
|
|
9
|
-
exports.rotate = rotate;
|
|
10
|
-
exports.dot = dot;
|
|
11
6
|
exports.angle = angle;
|
|
12
7
|
exports.boundary = boundary;
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
8
|
+
exports.difference = difference;
|
|
9
|
+
exports.dot = dot;
|
|
15
10
|
exports.minMax = minMax;
|
|
16
11
|
exports.moveToZeroZero = moveToZeroZero;
|
|
12
|
+
exports.normalize = normalize;
|
|
13
|
+
exports.perimeter = perimeter;
|
|
14
|
+
exports.rotate = rotate;
|
|
15
|
+
exports.round = round;
|
|
16
|
+
exports.surface = surface;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Rounds all the x and y values of an array of points
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Image processing and manipulation in JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image",
|
|
@@ -59,21 +59,21 @@
|
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@babel/cli": "^7.
|
|
63
|
-
"@babel/core": "^7.
|
|
64
|
-
"@babel/plugin-transform-block-scoping": "^7.
|
|
65
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
66
|
-
"@babel/preset-env": "^7.
|
|
67
|
-
"@types/jest": "^
|
|
62
|
+
"@babel/cli": "^7.16.0",
|
|
63
|
+
"@babel/core": "^7.16.0",
|
|
64
|
+
"@babel/plugin-transform-block-scoping": "^7.16.0",
|
|
65
|
+
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
|
|
66
|
+
"@babel/preset-env": "^7.16.0",
|
|
67
|
+
"@types/jest": "^27.0.2",
|
|
68
68
|
"benchmark": "^2.1.4",
|
|
69
69
|
"cheminfo-build": "^1.1.11",
|
|
70
70
|
"cross-env": "^7.0.3",
|
|
71
|
-
"eslint": "^
|
|
72
|
-
"eslint-config-cheminfo": "^
|
|
71
|
+
"eslint": "^8.1.0",
|
|
72
|
+
"eslint-config-cheminfo": "^7.1.2",
|
|
73
73
|
"esm": "^3.2.25",
|
|
74
|
-
"jest": "^27.
|
|
75
|
-
"jest-matcher-deep-close-to": "^
|
|
76
|
-
"prettier": "^2.
|
|
74
|
+
"jest": "^27.3.1",
|
|
75
|
+
"jest-matcher-deep-close-to": "^3.0.2",
|
|
76
|
+
"prettier": "^2.4.1",
|
|
77
77
|
"rimraf": "^3.0.2",
|
|
78
78
|
"sha.js": "^2.4.11"
|
|
79
79
|
},
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"fast-bmp": "^1.0.0",
|
|
85
85
|
"fast-jpeg": "^1.0.1",
|
|
86
86
|
"fast-list": "^1.0.3",
|
|
87
|
-
"fast-png": "^
|
|
87
|
+
"fast-png": "^6.1.0",
|
|
88
88
|
"has-own": "^1.0.1",
|
|
89
89
|
"image-type": "^4.1.0",
|
|
90
90
|
"is-array-type": "^1.0.0",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"monotone-chain-convex-hull": "^1.0.0",
|
|
102
102
|
"new-array": "^1.0.0",
|
|
103
103
|
"robust-point-in-polygon": "^1.0.3",
|
|
104
|
-
"tiff": "^5.0.
|
|
104
|
+
"tiff": "^5.0.2",
|
|
105
105
|
"web-worker-manager": "^0.2.0"
|
|
106
106
|
},
|
|
107
107
|
"engines": {
|
|
@@ -26,6 +26,7 @@ class Worker {
|
|
|
26
26
|
let manager;
|
|
27
27
|
let url;
|
|
28
28
|
let runner = {};
|
|
29
|
+
|
|
29
30
|
function run(...args) {
|
|
30
31
|
if (!manager) {
|
|
31
32
|
this.checkUrl();
|
|
@@ -35,6 +36,7 @@ class Worker {
|
|
|
35
36
|
}
|
|
36
37
|
return method.run.call(runner, ...args);
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
run.reset = function () {
|
|
39
41
|
if (manager) {
|
|
40
42
|
manager.terminate();
|
package/src/image/core/export.js
CHANGED
|
@@ -125,10 +125,12 @@ const exportMethods = {
|
|
|
125
125
|
}
|
|
126
126
|
const { useCanvas = false, encoder: encoderOptions = undefined } = options;
|
|
127
127
|
type = getType(type);
|
|
128
|
+
|
|
128
129
|
function dataUrl(encoder, ctx) {
|
|
129
130
|
const u8 = encoder(ctx, encoderOptions);
|
|
130
131
|
return toBase64URL(u8, type);
|
|
131
132
|
}
|
|
133
|
+
|
|
132
134
|
if (type === 'image/bmp') {
|
|
133
135
|
return dataUrl(encodeBmp, this);
|
|
134
136
|
} else if (type === 'image/png' && !useCanvas) {
|
package/src/image/core/load.js
CHANGED
|
@@ -19,7 +19,10 @@ const isDataURL = /^data:[a-z]+\/(?:[a-z]+);base64,/;
|
|
|
19
19
|
* @static
|
|
20
20
|
* @param {string|ArrayBuffer|Buffer|Uint8Array} image - URL of the image (browser, can be a dataURL) or path (Node.js)
|
|
21
21
|
* or buffer containing the binary data
|
|
22
|
-
* @param {object} [options] - In the browser, the options object is passed to the underlying `fetch` call
|
|
22
|
+
* @param {object} [options] - In the browser, the options object is passed to the underlying `fetch` call, along with
|
|
23
|
+
* the data URL. For binary data, the option specify decoding options.
|
|
24
|
+
* @param {boolean} [options.ignorePalette] - When set to true and loading a tiff from binary data, if the tiff is of
|
|
25
|
+
* type 3 (palette), load as single channel greyscale rather than as a pseudo-colored RGB.
|
|
23
26
|
* @return {Promise<Image>}
|
|
24
27
|
* @example
|
|
25
28
|
* const image = await Image.load('https://example.com/image.png');
|
|
@@ -28,15 +31,23 @@ export default function load(image, options) {
|
|
|
28
31
|
if (typeof image === 'string') {
|
|
29
32
|
return loadURL(image, options);
|
|
30
33
|
} else if (image instanceof ArrayBuffer) {
|
|
31
|
-
return Promise.resolve(
|
|
34
|
+
return Promise.resolve(
|
|
35
|
+
loadBinary(
|
|
36
|
+
new Uint8Array(image),
|
|
37
|
+
undefined,
|
|
38
|
+
options && options.ignorePalette,
|
|
39
|
+
),
|
|
40
|
+
);
|
|
32
41
|
} else if (image.buffer) {
|
|
33
|
-
return Promise.resolve(
|
|
42
|
+
return Promise.resolve(
|
|
43
|
+
loadBinary(image, undefined, options && options.ignorePalette),
|
|
44
|
+
);
|
|
34
45
|
} else {
|
|
35
46
|
throw new Error('argument to "load" must be a string or buffer.');
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
function loadBinary(image, base64Url) {
|
|
50
|
+
function loadBinary(image, base64Url, ignorePalette) {
|
|
40
51
|
const type = imageType(image);
|
|
41
52
|
if (type) {
|
|
42
53
|
switch (type.mime) {
|
|
@@ -45,12 +56,13 @@ function loadBinary(image, base64Url) {
|
|
|
45
56
|
case 'image/jpeg':
|
|
46
57
|
return loadJPEG(image);
|
|
47
58
|
case 'image/tiff':
|
|
48
|
-
return loadTIFF(image);
|
|
59
|
+
return loadTIFF(image, ignorePalette);
|
|
49
60
|
default:
|
|
50
61
|
return loadGeneric(getBase64(type.mime));
|
|
51
62
|
}
|
|
52
63
|
}
|
|
53
64
|
return loadGeneric(getBase64('application/octet-stream'));
|
|
65
|
+
|
|
54
66
|
function getBase64(type) {
|
|
55
67
|
if (base64Url) {
|
|
56
68
|
return base64Url;
|
|
@@ -70,7 +82,11 @@ function loadURL(url, options) {
|
|
|
70
82
|
}
|
|
71
83
|
return binaryDataP.then((binaryData) => {
|
|
72
84
|
const uint8 = new Uint8Array(binaryData);
|
|
73
|
-
return loadBinary(
|
|
85
|
+
return loadBinary(
|
|
86
|
+
uint8,
|
|
87
|
+
dataURL ? url : undefined,
|
|
88
|
+
options && options.ignorePalette,
|
|
89
|
+
);
|
|
74
90
|
});
|
|
75
91
|
}
|
|
76
92
|
|
|
@@ -159,12 +175,16 @@ function loadJPEG(data) {
|
|
|
159
175
|
return image;
|
|
160
176
|
}
|
|
161
177
|
|
|
162
|
-
function loadTIFF(data) {
|
|
178
|
+
function loadTIFF(data, ignorePalette) {
|
|
163
179
|
let result = decodeTiff(data);
|
|
164
180
|
if (result.length === 1) {
|
|
165
|
-
return getImageFromIFD(result[0]);
|
|
181
|
+
return getImageFromIFD(result[0], ignorePalette);
|
|
166
182
|
} else {
|
|
167
|
-
return new Stack(
|
|
183
|
+
return new Stack(
|
|
184
|
+
result.map(function (image) {
|
|
185
|
+
return getImageFromIFD(image, ignorePalette);
|
|
186
|
+
}),
|
|
187
|
+
);
|
|
168
188
|
}
|
|
169
189
|
}
|
|
170
190
|
|
|
@@ -184,8 +204,8 @@ function getMetadata(image) {
|
|
|
184
204
|
return metadata;
|
|
185
205
|
}
|
|
186
206
|
|
|
187
|
-
function getImageFromIFD(image) {
|
|
188
|
-
if (image.type === 3) {
|
|
207
|
+
function getImageFromIFD(image, ignorePalette) {
|
|
208
|
+
if (!ignorePalette && image.type === 3) {
|
|
189
209
|
// Palette
|
|
190
210
|
const data = new Uint16Array(3 * image.width * image.height);
|
|
191
211
|
const palette = image.palette;
|
|
@@ -31,6 +31,7 @@ export default function minimum(histogram) {
|
|
|
31
31
|
threshold = minimumBetweenPeeks(histogramCopy, max);
|
|
32
32
|
return threshold;
|
|
33
33
|
}
|
|
34
|
+
|
|
34
35
|
function smoothed(histogram) {
|
|
35
36
|
// Smooth with a 3 point running mean filter
|
|
36
37
|
let auHistogram = new Array(histogram.length); // a copy of the histograma for the smoothing process
|
|
@@ -42,6 +43,7 @@ function smoothed(histogram) {
|
|
|
42
43
|
(histogram[histogram.length - 2] + histogram[histogram.length - 1]) / 3;
|
|
43
44
|
return auHistogram;
|
|
44
45
|
}
|
|
46
|
+
|
|
45
47
|
function minimumBetweenPeeks(histogramBimodal, max) {
|
|
46
48
|
let threshold;
|
|
47
49
|
for (let i = 1; i < max; i++) {
|
|
@@ -55,6 +57,7 @@ function minimumBetweenPeeks(histogramBimodal, max) {
|
|
|
55
57
|
}
|
|
56
58
|
return threshold;
|
|
57
59
|
}
|
|
60
|
+
|
|
58
61
|
function bimodalTest(histogram) {
|
|
59
62
|
// It is responsible for determining if a histogram is bimodal
|
|
60
63
|
let len = histogram.length;
|