image-js 1.6.0 → 1.6.2

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.
@@ -1,15 +1,15 @@
1
1
  /*
2
- * image-js v1.6.0
2
+ * image-js v1.6.2
3
3
  * Image processing and manipulation in JavaScript
4
4
  * https://github.com/image-js/image-js#readme
5
5
  *
6
6
  * Licensed under the MIT license.
7
7
  */
8
8
  (function (global, factory) {
9
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('node:assert')) :
10
- typeof define === 'function' && define.amd ? define(['exports', 'node:assert'], factory) :
11
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IJS = {}, global.assert$1));
12
- })(this, (function (exports, assert$1) { 'use strict';
9
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
10
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
11
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IJS = {}));
12
+ })(this, (function (exports) { 'use strict';
13
13
 
14
14
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
15
  function getDefaultExportFromCjs (x) {
@@ -14088,7 +14088,7 @@ ${indent}columns: ${matrix.columns}
14088
14088
  contour.push(currentPoint);
14089
14089
  }
14090
14090
  const next = findNextPoint(mask, currentPoint, backtrackPoint);
14091
- assert$1.ok(next, 'Next border point is undefined.');
14091
+ assert(next, 'Next border point is undefined.');
14092
14092
  backtrackPoint = next.prevPoint;
14093
14093
  currentPoint = next.currPoint;
14094
14094
  if (currentPoint.column === startingPoint.column && currentPoint.row === startingPoint.row) {
@@ -23805,7 +23805,7 @@ ${indent}columns: ${matrix.columns}
23805
23805
  },
23806
23806
  maxRansacNbIterations,
23807
23807
  debug = false,
23808
- debugImagePath = `${undefined}/montage.png`
23808
+ debugImagePath
23809
23809
  } = options;
23810
23810
  if (source.colorModel !== ImageColorModel.GREY) {
23811
23811
  source = source.grey();
@@ -23885,6 +23885,9 @@ ${indent}columns: ${matrix.columns}
23885
23885
  }
23886
23886
  // create debug image
23887
23887
  if (debug) {
23888
+ if (!debugImagePath) {
23889
+ throw new RangeError('Debug image file path is not specified.');
23890
+ }
23888
23891
  const montage = new Montage(source, destination, {
23889
23892
  disposition: MontageDisposition.VERTICAL
23890
23893
  });
@@ -25058,10 +25061,27 @@ ${indent}columns: ${matrix.columns}
25058
25061
  }
25059
25062
  return new Image(decodedData.width, decodedData.height, {
25060
25063
  colorModel,
25061
- data: decodedData.data
25064
+ data: decodedData.data,
25065
+ resolution: getBmpResolution(decodedData)
25062
25066
  });
25063
25067
  }
25064
25068
  }
25069
+ /**
25070
+ * Gets image's resolution from its parsed data. BMP stores resolution in
25071
+ * pixels per meter.
25072
+ * @param bmp - Parsed BMP image.
25073
+ * @returns Object with resolution data if it is defined.
25074
+ */
25075
+ function getBmpResolution(bmp) {
25076
+ if (!bmp.xPixelsPerMeter || !bmp.yPixelsPerMeter) {
25077
+ return undefined;
25078
+ }
25079
+ return {
25080
+ x: bmp.xPixelsPerMeter,
25081
+ y: bmp.yPixelsPerMeter,
25082
+ unit: 'meter'
25083
+ };
25084
+ }
25065
25085
 
25066
25086
  const tagsById$2 = {
25067
25087
  0x829a: 'ExposureTime',
@@ -26361,18 +26381,7 @@ ${indent}columns: ${matrix.columns}
26361
26381
  default:
26362
26382
  throw new RangeError(`invalid number of channels: ${png.channels}`);
26363
26383
  }
26364
- let resolution;
26365
- if (png.resolution) {
26366
- resolution = png.resolution.unit === 1 ? /*If the resolution unit is meters*/{
26367
- x: png.resolution.x,
26368
- y: png.resolution.y,
26369
- unit: 'meter'
26370
- } : /*If resolution unit is unknown */{
26371
- x: png.resolution.x,
26372
- y: png.resolution.y,
26373
- unit: 'unknown'
26374
- };
26375
- }
26384
+ const resolution = getResolution(png);
26376
26385
  return new Image(png.width, png.height, {
26377
26386
  colorModel,
26378
26387
  bitDepth,
@@ -26404,9 +26413,11 @@ ${indent}columns: ${matrix.columns}
26404
26413
  data[dataIndex++] = paletteChannel;
26405
26414
  }
26406
26415
  }
26416
+ const resolution = getResolution(png);
26407
26417
  return new Image(png.width, png.height, {
26408
26418
  data,
26409
- colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB'
26419
+ colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB',
26420
+ resolution
26410
26421
  });
26411
26422
  }
26412
26423
  function decodeBinary(png) {
@@ -26426,6 +26437,26 @@ ${indent}columns: ${matrix.columns}
26426
26437
  }
26427
26438
  return result;
26428
26439
  }
26440
+ /**
26441
+ * Gets image's resolution from its parsed data.
26442
+ * @param png - Parsed .png image.
26443
+ * @returns Object with resolution data if exists.
26444
+ */
26445
+ function getResolution(png) {
26446
+ if (png.resolution) {
26447
+ return png.resolution.unit === 1 ? /*If the resolution unit is meters*/{
26448
+ x: png.resolution.x,
26449
+ y: png.resolution.y,
26450
+ unit: 'meter'
26451
+ } : /*If resolution unit is unknown */{
26452
+ x: png.resolution.x,
26453
+ y: png.resolution.y,
26454
+ unit: 'unknown'
26455
+ };
26456
+ } else {
26457
+ return undefined;
26458
+ }
26459
+ }
26429
26460
 
26430
26461
  /**
26431
26462
  * Decode a TIFF. See the tiff module.