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,12 +1,10 @@
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
- import assert$1 from 'node:assert';
9
-
10
8
  function getDefaultExportFromCjs (x) {
11
9
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
12
10
  }
@@ -14083,7 +14081,7 @@ function getContourMoore(mask) {
14083
14081
  contour.push(currentPoint);
14084
14082
  }
14085
14083
  const next = findNextPoint(mask, currentPoint, backtrackPoint);
14086
- assert$1.ok(next, 'Next border point is undefined.');
14084
+ assert(next, 'Next border point is undefined.');
14087
14085
  backtrackPoint = next.prevPoint;
14088
14086
  currentPoint = next.currPoint;
14089
14087
  if (currentPoint.column === startingPoint.column && currentPoint.row === startingPoint.row) {
@@ -23800,7 +23798,7 @@ function getAffineTransform(source, destination, options = {}) {
23800
23798
  },
23801
23799
  maxRansacNbIterations,
23802
23800
  debug = false,
23803
- debugImagePath = `${import.meta.dirname}/montage.png`
23801
+ debugImagePath
23804
23802
  } = options;
23805
23803
  if (source.colorModel !== ImageColorModel.GREY) {
23806
23804
  source = source.grey();
@@ -23880,6 +23878,9 @@ function getAffineTransform(source, destination, options = {}) {
23880
23878
  }
23881
23879
  // create debug image
23882
23880
  if (debug) {
23881
+ if (!debugImagePath) {
23882
+ throw new RangeError('Debug image file path is not specified.');
23883
+ }
23883
23884
  const montage = new Montage(source, destination, {
23884
23885
  disposition: MontageDisposition.VERTICAL
23885
23886
  });
@@ -25053,10 +25054,27 @@ function decodeBmp(data) {
25053
25054
  }
25054
25055
  return new Image(decodedData.width, decodedData.height, {
25055
25056
  colorModel,
25056
- data: decodedData.data
25057
+ data: decodedData.data,
25058
+ resolution: getBmpResolution(decodedData)
25057
25059
  });
25058
25060
  }
25059
25061
  }
25062
+ /**
25063
+ * Gets image's resolution from its parsed data. BMP stores resolution in
25064
+ * pixels per meter.
25065
+ * @param bmp - Parsed BMP image.
25066
+ * @returns Object with resolution data if it is defined.
25067
+ */
25068
+ function getBmpResolution(bmp) {
25069
+ if (!bmp.xPixelsPerMeter || !bmp.yPixelsPerMeter) {
25070
+ return undefined;
25071
+ }
25072
+ return {
25073
+ x: bmp.xPixelsPerMeter,
25074
+ y: bmp.yPixelsPerMeter,
25075
+ unit: 'meter'
25076
+ };
25077
+ }
25060
25078
 
25061
25079
  const tagsById$2 = {
25062
25080
  0x829a: 'ExposureTime',
@@ -26356,18 +26374,7 @@ function decodePng(buffer) {
26356
26374
  default:
26357
26375
  throw new RangeError(`invalid number of channels: ${png.channels}`);
26358
26376
  }
26359
- let resolution;
26360
- if (png.resolution) {
26361
- resolution = png.resolution.unit === 1 ? /*If the resolution unit is meters*/{
26362
- x: png.resolution.x,
26363
- y: png.resolution.y,
26364
- unit: 'meter'
26365
- } : /*If resolution unit is unknown */{
26366
- x: png.resolution.x,
26367
- y: png.resolution.y,
26368
- unit: 'unknown'
26369
- };
26370
- }
26377
+ const resolution = getResolution(png);
26371
26378
  return new Image(png.width, png.height, {
26372
26379
  colorModel,
26373
26380
  bitDepth,
@@ -26399,9 +26406,11 @@ function loadPalettePng(png) {
26399
26406
  data[dataIndex++] = paletteChannel;
26400
26407
  }
26401
26408
  }
26409
+ const resolution = getResolution(png);
26402
26410
  return new Image(png.width, png.height, {
26403
26411
  data,
26404
- colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB'
26412
+ colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB',
26413
+ resolution
26405
26414
  });
26406
26415
  }
26407
26416
  function decodeBinary(png) {
@@ -26421,6 +26430,26 @@ function decodeBinary(png) {
26421
26430
  }
26422
26431
  return result;
26423
26432
  }
26433
+ /**
26434
+ * Gets image's resolution from its parsed data.
26435
+ * @param png - Parsed .png image.
26436
+ * @returns Object with resolution data if exists.
26437
+ */
26438
+ function getResolution(png) {
26439
+ if (png.resolution) {
26440
+ return png.resolution.unit === 1 ? /*If the resolution unit is meters*/{
26441
+ x: png.resolution.x,
26442
+ y: png.resolution.y,
26443
+ unit: 'meter'
26444
+ } : /*If resolution unit is unknown */{
26445
+ x: png.resolution.x,
26446
+ y: png.resolution.y,
26447
+ unit: 'unknown'
26448
+ };
26449
+ } else {
26450
+ return undefined;
26451
+ }
26452
+ }
26424
26453
 
26425
26454
  /**
26426
26455
  * Decode a TIFF. See the tiff module.