@imagemagick/magick-wasm 0.0.8 → 0.0.11

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.
Files changed (51) hide show
  1. package/NOTICE +1161 -59
  2. package/README.md +1 -1
  3. package/auto-threshold-method.d.ts +6 -0
  4. package/auto-threshold-method.js +10 -0
  5. package/drawables/drawable-color.d.ts +10 -0
  6. package/drawables/drawable-color.js +14 -0
  7. package/drawables/drawable-fill-color.d.ts +8 -0
  8. package/drawables/drawable-fill-color.js +12 -0
  9. package/drawables/drawable-fill-opacity.d.ts +8 -0
  10. package/drawables/drawable-fill-opacity.js +12 -0
  11. package/drawables/drawable-font-point-size.d.ts +7 -0
  12. package/drawables/drawable-font-point-size.js +12 -0
  13. package/drawables/drawable-font.d.ts +7 -0
  14. package/drawables/drawable-font.js +14 -0
  15. package/drawables/drawable-text.d.ts +9 -0
  16. package/drawables/drawable-text.js +14 -0
  17. package/drawables/drawable.d.ts +4 -0
  18. package/drawables/drawable.js +2 -0
  19. package/drawables/drawing-wand.d.ts +23 -0
  20. package/drawables/drawing-wand.js +66 -0
  21. package/gravity.js +35 -1
  22. package/image-magick.js +7 -3
  23. package/internal/exception/exception.js +29 -11
  24. package/magick-color.js +1 -1
  25. package/magick-error.d.ts +2 -0
  26. package/magick-error.js +5 -0
  27. package/magick-format-info.d.ts +1 -1
  28. package/magick-format-info.js +2 -2
  29. package/magick-format.d.ts +5 -0
  30. package/magick-format.js +5 -0
  31. package/magick-geometry.js +30 -1
  32. package/magick-image-collection.d.ts +11 -2
  33. package/magick-image-collection.js +53 -8
  34. package/magick-image.d.ts +73 -13
  35. package/magick-image.js +181 -49
  36. package/magick.d.ts +1 -1
  37. package/magick.js +12 -4
  38. package/package.json +1 -1
  39. package/paint-method.d.ts +8 -0
  40. package/paint-method.js +12 -0
  41. package/percentage.js +3 -0
  42. package/pixel-interpolate-method.d.ts +14 -0
  43. package/pixel-interpolate-method.js +18 -0
  44. package/pixels/pixel-collection.js +2 -2
  45. package/settings/drawing-settings.d.ts +9 -0
  46. package/settings/drawing-settings.js +25 -0
  47. package/settings/magick-read-settings.js +1 -1
  48. package/settings/native-drawing-settings.d.ts +1 -0
  49. package/settings/native-drawing-settings.js +35 -0
  50. package/settings/native-magick-settings.js +7 -10
  51. package/wasm/magick.js +2 -2
package/magick-image.js CHANGED
@@ -5,6 +5,7 @@ const alpha_option_1 = require("./alpha-option");
5
5
  const channels_1 = require("./channels");
6
6
  const color_space_1 = require("./color-space");
7
7
  const composite_operator_1 = require("./composite-operator");
8
+ const drawing_wand_1 = require("./drawables/drawing-wand");
8
9
  const exception_1 = require("./internal/exception/exception");
9
10
  const gravity_1 = require("./gravity");
10
11
  const image_magick_1 = require("./image-magick");
@@ -25,6 +26,7 @@ const pointer_1 = require("./internal/pointer/pointer");
25
26
  const quantum_1 = require("./quantum");
26
27
  const string_info_1 = require("./internal/string-info");
27
28
  const string_1 = require("./internal/native/string");
29
+ const gravity_2 = require("./gravity");
28
30
  const array_1 = require("./internal/native/array");
29
31
  class MagickImage extends native_instance_1.NativeInstance {
30
32
  constructor(instance, settings) {
@@ -51,7 +53,18 @@ class MagickImage extends native_instance_1.NativeInstance {
51
53
  image_magick_1.ImageMagick._api._MagickImage_BackgroundColor_Set(this._instance, valuePtr);
52
54
  });
53
55
  }
56
+ get borderColor() {
57
+ const colorPtr = image_magick_1.ImageMagick._api._MagickImage_BorderColor_Get(this._instance);
58
+ return magick_color_1.MagickColor._create(colorPtr);
59
+ }
60
+ set borderColor(value) {
61
+ value._use(valuePtr => {
62
+ image_magick_1.ImageMagick._api._MagickImage_BorderColor_Set(this._instance, valuePtr);
63
+ });
64
+ }
54
65
  get channelCount() { return image_magick_1.ImageMagick._api._MagickImage_ChannelCount_Get(this._instance); }
66
+ get colorFuzz() { return percentage_1.Percentage.fromQuantum(image_magick_1.ImageMagick._api._MagickImage_ColorFuzz_Get(this._instance)); }
67
+ set colorFuzz(value) { image_magick_1.ImageMagick._api._MagickImage_ColorFuzz_Set(this._instance, value.toQuantum()); }
55
68
  get colorSpace() {
56
69
  return exception_1.Exception.usePointer(exception => {
57
70
  return image_magick_1.ImageMagick._api._MagickImage_ColorSpace_Get(this._instance, exception);
@@ -66,8 +79,8 @@ class MagickImage extends native_instance_1.NativeInstance {
66
79
  set depth(value) { image_magick_1.ImageMagick._api._MagickImage_Depth_Set(this._instance, value); }
67
80
  get filterType() { return image_magick_1.ImageMagick._api._MagickImage_FilterType_Get(this._instance); }
68
81
  set filterType(value) { image_magick_1.ImageMagick._api._MagickImage_FilterType_Set(this._instance, value); }
69
- get format() { return string_1._createString(image_magick_1.ImageMagick._api._MagickImage_Format_Get(this._instance), ''); }
70
- set format(value) { string_1._withString(value, instance => image_magick_1.ImageMagick._api._MagickImage_Format_Set(this._instance, instance)); }
82
+ get format() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._MagickImage_Format_Get(this._instance), ''); }
83
+ set format(value) { (0, string_1._withString)(value.toString(), instance => image_magick_1.ImageMagick._api._MagickImage_Format_Set(this._instance, instance)); }
71
84
  get hasAlpha() {
72
85
  return exception_1.Exception.usePointer(exception => {
73
86
  return this.toBool(image_magick_1.ImageMagick._api._MagickImage_HasAlpha_Get(this._instance, exception));
@@ -80,9 +93,24 @@ class MagickImage extends native_instance_1.NativeInstance {
80
93
  image_magick_1.ImageMagick._api._MagickImage_HasAlpha_Set(this._instance, this.fromBool(value), exception);
81
94
  });
82
95
  }
96
+ get interpolate() {
97
+ return image_magick_1.ImageMagick._api._MagickImage_Interpolate_Get(this._instance);
98
+ }
99
+ set interpolate(value) {
100
+ image_magick_1.ImageMagick._api._MagickImage_Interpolate_Set(this._instance, value);
101
+ }
83
102
  get height() { return image_magick_1.ImageMagick._api._MagickImage_Height_Get(this._instance); }
84
103
  get orientation() { return image_magick_1.ImageMagick._api._MagickImage_Orientation_Get(this._instance); }
85
104
  set orientation(value) { image_magick_1.ImageMagick._api._MagickImage_Orientation_Set(this._instance, value); }
105
+ get page() {
106
+ const rectangle = image_magick_1.ImageMagick._api._MagickImage_Page_Get(this._instance);
107
+ return magick_geometry_1.MagickGeometry.fromRectangle(rectangle);
108
+ }
109
+ set page(value) {
110
+ value.toRectangle(rectangle => {
111
+ image_magick_1.ImageMagick._api._MagickImage_Page_Set(this._instance, rectangle);
112
+ });
113
+ }
86
114
  get quality() { return image_magick_1.ImageMagick._api._MagickImage_Quality_Get(this._instance); }
87
115
  set quality(value) {
88
116
  let quality = value < 1 ? 1 : value;
@@ -92,7 +120,7 @@ class MagickImage extends native_instance_1.NativeInstance {
92
120
  }
93
121
  get signature() {
94
122
  return exception_1.Exception.usePointer(exception => {
95
- return string_1._createString(image_magick_1.ImageMagick._api._MagickImage_Signature_Get(this._instance, exception));
123
+ return (0, string_1._createString)(image_magick_1.ImageMagick._api._MagickImage_Signature_Get(this._instance, exception));
96
124
  });
97
125
  }
98
126
  get virtualPixelMethod() {
@@ -117,6 +145,11 @@ class MagickImage extends native_instance_1.NativeInstance {
117
145
  this._setInstance(instance, exception);
118
146
  });
119
147
  }
148
+ autoThreshold(method) {
149
+ exception_1.Exception.use(exception => {
150
+ image_magick_1.ImageMagick._api._MagickImage_AutoThreshold(this._instance, method, exception.ptr);
151
+ });
152
+ }
120
153
  blur(radiusOrChannel, sigma, channels) {
121
154
  let radius = 0;
122
155
  const sigmaValue = this.valueOrDefault(sigma, 1);
@@ -130,6 +163,17 @@ class MagickImage extends native_instance_1.NativeInstance {
130
163
  this._setInstance(instance, exception);
131
164
  });
132
165
  }
166
+ border(sizeOrWidth, height) {
167
+ const widthValue = sizeOrWidth;
168
+ const heightValue = this.valueOrDefault(height, sizeOrWidth);
169
+ const geometry = new magick_geometry_1.MagickGeometry(0, 0, widthValue, heightValue);
170
+ exception_1.Exception.use(exception => {
171
+ geometry.toRectangle(rectangle => {
172
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Border(this._instance, rectangle, exception.ptr);
173
+ this._setInstance(instance, exception);
174
+ });
175
+ });
176
+ }
133
177
  channelOffset(pixelChannel) {
134
178
  if (!image_magick_1.ImageMagick._api._MagickImage_HasChannel(this._instance, pixelChannel))
135
179
  return -1;
@@ -249,6 +293,24 @@ class MagickImage extends native_instance_1.NativeInstance {
249
293
  if (args !== null)
250
294
  this.removeArtifact('compose:args');
251
295
  }
296
+ crop(geometryOrWidth, heightOrGravity, gravity) {
297
+ let geometry;
298
+ let cropGravity;
299
+ if (geometryOrWidth instanceof magick_geometry_1.MagickGeometry) {
300
+ geometry = geometryOrWidth;
301
+ cropGravity = heightOrGravity !== undefined ? heightOrGravity : gravity_1.Gravity.Undefined;
302
+ }
303
+ else if (heightOrGravity !== undefined) {
304
+ geometry = new magick_geometry_1.MagickGeometry(geometryOrWidth, heightOrGravity);
305
+ cropGravity = gravity !== undefined ? gravity : gravity_1.Gravity.Undefined;
306
+ }
307
+ exception_1.Exception.use(exception => {
308
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
309
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Crop(this._instance, geometryPtr, cropGravity, exception.ptr);
310
+ this._setInstance(instance, exception);
311
+ });
312
+ });
313
+ }
252
314
  static create() {
253
315
  return new MagickImage(MagickImage.createInstance(), new magick_settings_1.MagickSettings());
254
316
  }
@@ -277,7 +339,7 @@ class MagickImage extends native_instance_1.NativeInstance {
277
339
  distortArgs = [];
278
340
  }
279
341
  exception_1.Exception.use(exception => {
280
- array_1._withDoubleArray(distortArgs, (distortArgsPtr) => {
342
+ (0, array_1._withDoubleArray)(distortArgs, (distortArgsPtr) => {
281
343
  const instance = image_magick_1.ImageMagick._api._MagickImage_Distort(this._instance, method, bestFit, distortArgsPtr, distortArgs.length, exception.ptr);
282
344
  this._setInstance(instance, exception);
283
345
  });
@@ -285,6 +347,15 @@ class MagickImage extends native_instance_1.NativeInstance {
285
347
  if (settings !== null)
286
348
  settings._removeArtifacts(this);
287
349
  }
350
+ draw(...drawables) {
351
+ const wand = drawing_wand_1.DrawingWand._create(this, this._settings);
352
+ try {
353
+ wand.draw(drawables.flat());
354
+ }
355
+ finally {
356
+ wand.dispose();
357
+ }
358
+ }
288
359
  evaluate(channels, operatorOrGeometry, valueOrPercentageOrOperator, valueOrPercentage) {
289
360
  if (typeof operatorOrGeometry === 'number') {
290
361
  const operator = operatorOrGeometry;
@@ -324,20 +395,20 @@ class MagickImage extends native_instance_1.NativeInstance {
324
395
  else if (backgroundColorOrGravity !== undefined)
325
396
  gravity = backgroundColorOrGravity;
326
397
  exception_1.Exception.use(exception => {
327
- string_1._withString(geometry.toString(), geometryPtr => {
398
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
328
399
  const instance = image_magick_1.ImageMagick._api._MagickImage_Extent(this._instance, geometryPtr, gravity, exception.ptr);
329
400
  this._setInstance(instance, exception);
330
401
  });
331
402
  });
332
403
  }
333
404
  getArtifact(name) {
334
- return string_1._withString(name, namePtr => {
405
+ return (0, string_1._withString)(name, namePtr => {
335
406
  const value = image_magick_1.ImageMagick._api._MagickImage_GetArtifact(this._instance, namePtr);
336
- return string_1._createString(value);
407
+ return (0, string_1._createString)(value);
337
408
  });
338
409
  }
339
410
  getProfile(name) {
340
- return string_1._withString(name, namePtr => {
411
+ return (0, string_1._withString)(name, namePtr => {
341
412
  const value = image_magick_1.ImageMagick._api._MagickImage_GetProfile(this._instance, namePtr);
342
413
  const data = string_info_1.StringInfo.toArray(value);
343
414
  if (data === null)
@@ -357,6 +428,28 @@ class MagickImage extends native_instance_1.NativeInstance {
357
428
  return func(pixels);
358
429
  });
359
430
  }
431
+ histogram() {
432
+ const result = new Map();
433
+ exception_1.Exception.usePointer(exception => {
434
+ pointer_1.Pointer.use(lengthPointer => {
435
+ const histogram = image_magick_1.ImageMagick._api._MagickImage_Histogram(this._instance, lengthPointer.ptr, exception);
436
+ if (histogram !== 0) {
437
+ const length = lengthPointer.value;
438
+ for (let i = 0; i < length; i++) {
439
+ const colorPtr = image_magick_1.ImageMagick._api._MagickColorCollection_GetInstance(histogram, i);
440
+ const color = magick_color_1.MagickColor._create(colorPtr);
441
+ const count = image_magick_1.ImageMagick._api._MagickColor_Count_Get(colorPtr);
442
+ result.set(color.toString(), count);
443
+ }
444
+ image_magick_1.ImageMagick._api._MagickColorCollection_DisposeList(histogram);
445
+ }
446
+ });
447
+ });
448
+ return result;
449
+ }
450
+ inverseSigmoidalContrast(contrast, midpointOrPercentage, channels) {
451
+ this.privateSigmoidalContrast(false, contrast, midpointOrPercentage, channels);
452
+ }
360
453
  level(channelsOrBlackPoint, blackPointOrWhitePoint, whitePointPercentageOrGamma, gamma) {
361
454
  let channels = channels_1.Channels.Composite;
362
455
  let blackPoint;
@@ -378,12 +471,21 @@ class MagickImage extends native_instance_1.NativeInstance {
378
471
  image_magick_1.ImageMagick._api._MagickImage_Level(this._instance, blackPoint.toDouble(), whitePoint.toQuantum(), gammaValue, channels, exception);
379
472
  });
380
473
  }
474
+ liquidRescale(widthOrGeometry, height) {
475
+ const geometry = typeof widthOrGeometry === 'number' ? new magick_geometry_1.MagickGeometry(widthOrGeometry, height) : widthOrGeometry;
476
+ exception_1.Exception.use(exception => {
477
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
478
+ const instance = image_magick_1.ImageMagick._api._MagickImage_LiquidRescale(this._instance, geometryPtr, geometry.x, geometry.y, exception.ptr);
479
+ this._setInstance(instance, exception);
480
+ });
481
+ });
482
+ }
381
483
  modulate(brightness, saturation, hue) {
382
484
  const saturationPercentage = saturation === undefined ? new percentage_1.Percentage(100) : saturation;
383
485
  const huePercentage = hue === undefined ? new percentage_1.Percentage(100) : hue;
384
486
  exception_1.Exception.usePointer(exception => {
385
487
  const modulate = `${brightness.toDouble()}/${saturationPercentage.toDouble()}/${huePercentage.toDouble()}`;
386
- string_1._withString(modulate, modulatePtr => {
488
+ (0, string_1._withString)(modulate, modulatePtr => {
387
489
  image_magick_1.ImageMagick._api._MagickImage_Modulate(this._instance, modulatePtr, exception);
388
490
  });
389
491
  });
@@ -433,7 +535,7 @@ class MagickImage extends native_instance_1.NativeInstance {
433
535
  });
434
536
  }
435
537
  removeArtifact(name) {
436
- string_1._withString(name, namePtr => {
538
+ (0, string_1._withString)(name, namePtr => {
437
539
  image_magick_1.ImageMagick._api._MagickImage_RemoveArtifact(this._instance, namePtr);
438
540
  });
439
541
  }
@@ -442,10 +544,13 @@ class MagickImage extends native_instance_1.NativeInstance {
442
544
  image_magick_1.ImageMagick._api._MagickImage_SetWriteMask(this._instance, 0, exception);
443
545
  });
444
546
  }
547
+ repage() {
548
+ this.page = new magick_geometry_1.MagickGeometry(0, 0, 0, 0);
549
+ }
445
550
  resize(widthOrGeometry, height) {
446
551
  const geometry = typeof widthOrGeometry === 'number' ? new magick_geometry_1.MagickGeometry(widthOrGeometry, height) : widthOrGeometry;
447
552
  exception_1.Exception.use(exception => {
448
- string_1._withString(geometry.toString(), geometryPtr => {
553
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
449
554
  const instance = image_magick_1.ImageMagick._api._MagickImage_Resize(this._instance, geometryPtr, exception.ptr);
450
555
  this._setInstance(instance, exception);
451
556
  });
@@ -466,41 +571,8 @@ class MagickImage extends native_instance_1.NativeInstance {
466
571
  this._setInstance(instance, exception);
467
572
  });
468
573
  }
469
- sigmoidalContrast(sharpenOrConstract, contrastOrMidpointOrPercentage, midpointOrPercentage) {
470
- let sharpen;
471
- let contrast;
472
- let midpoint;
473
- if (midpointOrPercentage !== undefined) {
474
- if (typeof sharpenOrConstract !== 'number')
475
- sharpen = sharpenOrConstract;
476
- if (typeof contrastOrMidpointOrPercentage === 'number')
477
- contrast = contrastOrMidpointOrPercentage;
478
- if (typeof midpointOrPercentage === 'number')
479
- midpoint = midpointOrPercentage;
480
- else
481
- midpoint = midpointOrPercentage.multiply(quantum_1.Quantum.max);
482
- }
483
- else {
484
- if (typeof sharpenOrConstract === 'number') {
485
- sharpen = true;
486
- contrast = sharpenOrConstract;
487
- if (typeof contrastOrMidpointOrPercentage === 'number')
488
- midpoint = contrastOrMidpointOrPercentage;
489
- else if (contrastOrMidpointOrPercentage !== undefined)
490
- midpoint = contrastOrMidpointOrPercentage.multiply(quantum_1.Quantum.max);
491
- else
492
- midpoint = quantum_1.Quantum.max * 0.5;
493
- }
494
- else {
495
- sharpen = sharpenOrConstract;
496
- if (typeof contrastOrMidpointOrPercentage === 'number')
497
- contrast = contrastOrMidpointOrPercentage;
498
- midpoint = quantum_1.Quantum.max * 0.5;
499
- }
500
- }
501
- exception_1.Exception.usePointer(exception => {
502
- image_magick_1.ImageMagick._api._MagickImage_SigmoidalContrast(this._instance, this.fromBool(sharpen), contrast, midpoint, exception);
503
- });
574
+ sigmoidalContrast(contrast, midpointOrPercentage, channels) {
575
+ this.privateSigmoidalContrast(true, contrast, midpointOrPercentage, channels);
504
576
  }
505
577
  separate(func, channels) {
506
578
  return exception_1.Exception.use(exception => {
@@ -517,8 +589,8 @@ class MagickImage extends native_instance_1.NativeInstance {
517
589
  else {
518
590
  strValue = this.fromBool(value).toString();
519
591
  }
520
- string_1._withString(name, namePtr => {
521
- string_1._withString(strValue, valuePtr => {
592
+ (0, string_1._withString)(name, namePtr => {
593
+ (0, string_1._withString)(strValue, valuePtr => {
522
594
  image_magick_1.ImageMagick._api._MagickImage_SetArtifact(this._instance, namePtr, valuePtr);
523
595
  });
524
596
  });
@@ -528,6 +600,44 @@ class MagickImage extends native_instance_1.NativeInstance {
528
600
  image_magick_1.ImageMagick._api._MagickImage_SetWriteMask(this._instance, image._instance, exception);
529
601
  });
530
602
  }
603
+ trim(...args) {
604
+ if (args.length > 0) {
605
+ if (args.length == 1 && args[0] instanceof percentage_1.Percentage) {
606
+ const percentage = args[0];
607
+ this.setArtifact('trim:percent-background', percentage.toDouble().toString());
608
+ }
609
+ else {
610
+ const edges = args;
611
+ const value = [...new Set((0, gravity_2._getEdges)(edges))].join(',');
612
+ this.setArtifact('trim:edges', value);
613
+ }
614
+ }
615
+ exception_1.Exception.use(exception => {
616
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Trim(this._instance, exception.ptr);
617
+ this._setInstance(instance, exception);
618
+ this.removeArtifact('trim:edges');
619
+ this.removeArtifact('trim:percent-background');
620
+ });
621
+ }
622
+ wave(methodOrUndefined, amplitudeOrUndefined, lengthOrUndefined) {
623
+ const method = methodOrUndefined == undefined ? this.interpolate : methodOrUndefined;
624
+ const amplitude = amplitudeOrUndefined == undefined ? 25 : amplitudeOrUndefined;
625
+ const length = lengthOrUndefined == undefined ? 150 : lengthOrUndefined;
626
+ exception_1.Exception.use(exception => {
627
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Wave(this._instance, method, amplitude, length, exception.ptr);
628
+ this._setInstance(instance, exception);
629
+ });
630
+ }
631
+ vignette(radiusOrUndefined, sigmaOrUndefined, xOrUndefined, yOrUndefined) {
632
+ const radius = radiusOrUndefined === undefined ? 0 : radiusOrUndefined;
633
+ const sigma = sigmaOrUndefined === undefined ? 1.0 : sigmaOrUndefined;
634
+ const x = xOrUndefined === undefined ? 0 : xOrUndefined;
635
+ const y = yOrUndefined === undefined ? 0 : yOrUndefined;
636
+ exception_1.Exception.use(exception => {
637
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Vignette(this._instance, radius, sigma, x, y, exception.ptr);
638
+ this._setInstance(instance, exception);
639
+ });
640
+ }
531
641
  write(func, format) {
532
642
  let bytes = new Uint8Array();
533
643
  exception_1.Exception.use(exception => {
@@ -538,7 +648,8 @@ class MagickImage extends native_instance_1.NativeInstance {
538
648
  let data = 0;
539
649
  try {
540
650
  data = image_magick_1.ImageMagick._api._MagickImage_WriteBlob(this._instance, settings._instance, pointer.ptr, exception.ptr);
541
- bytes = image_magick_1.ImageMagick._api.HEAPU8.subarray(data, data + pointer.value);
651
+ if (data !== 0)
652
+ bytes = image_magick_1.ImageMagick._api.HEAPU8.subarray(data, data + pointer.value);
542
653
  }
543
654
  catch (_a) {
544
655
  if (data !== 0)
@@ -572,6 +683,9 @@ class MagickImage extends native_instance_1.NativeInstance {
572
683
  static _createFromImage(instance, settings) {
573
684
  return new MagickImage(instance, settings);
574
685
  }
686
+ _getSettings() {
687
+ return this._settings;
688
+ }
575
689
  _instanceNotInitialized() {
576
690
  throw new magick_error_1.MagickError('no image has been read');
577
691
  }
@@ -584,6 +698,24 @@ class MagickImage extends native_instance_1.NativeInstance {
584
698
  image.dispose();
585
699
  }
586
700
  }
701
+ privateSigmoidalContrast(sharpen, contrast, midpointOrPercentage, channels) {
702
+ let midpoint;
703
+ if (midpointOrPercentage !== undefined) {
704
+ if (typeof midpointOrPercentage === 'number')
705
+ midpoint = midpointOrPercentage;
706
+ else
707
+ midpoint = midpointOrPercentage.multiply(quantum_1.Quantum.max);
708
+ }
709
+ else {
710
+ midpoint = quantum_1.Quantum.max * 0.5;
711
+ }
712
+ let usedChannels = channels_1.Channels.Default;
713
+ if (channels !== undefined)
714
+ usedChannels = channels;
715
+ exception_1.Exception.usePointer(exception => {
716
+ image_magick_1.ImageMagick._api._MagickImage_SigmoidalContrast(this._instance, this.fromBool(sharpen), contrast, midpoint, usedChannels, exception);
717
+ });
718
+ }
587
719
  static createInstance() {
588
720
  return exception_1.Exception.usePointer(exception => {
589
721
  return image_magick_1.ImageMagick._api._MagickImage_Create(0, exception);
package/magick.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare class Magick {
3
3
  static get delegates(): string;
4
4
  static get features(): string;
5
5
  static get imageMagickVersion(): string;
6
- static get supportedFormats(): MagickFormatInfo[];
6
+ static get supportedFormats(): ReadonlyArray<MagickFormatInfo>;
7
7
  static addFont(name: string, data: Uint8Array): void;
8
8
  static setRandomSeed: (seed: number) => void;
9
9
  }
package/magick.js CHANGED
@@ -5,9 +5,9 @@ const image_magick_1 = require("./image-magick");
5
5
  const magick_format_info_1 = require("./magick-format-info");
6
6
  const string_1 = require("./internal/native/string");
7
7
  class Magick {
8
- static get delegates() { return string_1._createString(image_magick_1.ImageMagick._api._Magick_Delegates_Get(), 'Unknown'); }
9
- static get features() { return string_1._createString(image_magick_1.ImageMagick._api._Magick_Features_Get(), ' ').slice(0, -1); }
10
- static get imageMagickVersion() { return string_1._createString(image_magick_1.ImageMagick._api._Magick_ImageMagickVersion_Get(), 'Unknown'); }
8
+ static get delegates() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._Magick_Delegates_Get(), 'Unknown'); }
9
+ static get features() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._Magick_Features_Get(), ' ').slice(0, -1); }
10
+ static get imageMagickVersion() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._Magick_ImageMagickVersion_Get(), 'Unknown'); }
11
11
  static get supportedFormats() { return magick_format_info_1.MagickFormatInfo.all; }
12
12
  static addFont(name, data) {
13
13
  const fileSystem = image_magick_1.ImageMagick._api.FS;
@@ -15,10 +15,18 @@ class Magick {
15
15
  if (!stats.exists) {
16
16
  fileSystem.mkdir('/fonts');
17
17
  }
18
- const stream = fileSystem.open(`/fonts/${name}`, 'w+');
18
+ const stream = fileSystem.open(`/fonts/${name}`, 'w');
19
19
  fileSystem.write(stream, data, 0, data.length);
20
20
  fileSystem.close(stream);
21
21
  }
22
+ static _getFontFileName(name) {
23
+ const fileName = `/fonts/${name}`;
24
+ const stats = image_magick_1.ImageMagick._api.FS.analyzePath(fileName);
25
+ if (!stats.exists) {
26
+ throw `Unable to find a font with the name '${name}', add it with Magick.addFont.`;
27
+ }
28
+ return fileName;
29
+ }
22
30
  }
23
31
  exports.Magick = Magick;
24
32
  Magick.setRandomSeed = (seed) => image_magick_1.ImageMagick._api._Magick_SetRandomSeed(seed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imagemagick/magick-wasm",
3
- "version": "0.0.8",
3
+ "version": "0.0.11",
4
4
  "main": "image-magick.js",
5
5
  "description": "The WASM library for ImageMagick",
6
6
  "repository": {
@@ -0,0 +1,8 @@
1
+ export declare enum PaintMethod {
2
+ Undefined = 0,
3
+ Point = 1,
4
+ Replace = 2,
5
+ Floodfill = 3,
6
+ FillToBorder = 4,
7
+ Reset = 5
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaintMethod = void 0;
4
+ var PaintMethod;
5
+ (function (PaintMethod) {
6
+ PaintMethod[PaintMethod["Undefined"] = 0] = "Undefined";
7
+ PaintMethod[PaintMethod["Point"] = 1] = "Point";
8
+ PaintMethod[PaintMethod["Replace"] = 2] = "Replace";
9
+ PaintMethod[PaintMethod["Floodfill"] = 3] = "Floodfill";
10
+ PaintMethod[PaintMethod["FillToBorder"] = 4] = "FillToBorder";
11
+ PaintMethod[PaintMethod["Reset"] = 5] = "Reset";
12
+ })(PaintMethod = exports.PaintMethod || (exports.PaintMethod = {}));
package/percentage.js CHANGED
@@ -6,6 +6,9 @@ class Percentage {
6
6
  constructor(value) {
7
7
  this._value = value;
8
8
  }
9
+ static fromQuantum(value) {
10
+ return new Percentage((value / quantum_1.Quantum.max) * 100);
11
+ }
9
12
  multiply(value) {
10
13
  return (value * this._value) / 100.0;
11
14
  }
@@ -0,0 +1,14 @@
1
+ export declare enum PixelInterpolateMethod {
2
+ Undefined = 0,
3
+ Average = 1,
4
+ Average9 = 2,
5
+ Average16 = 3,
6
+ Background = 4,
7
+ Bilinear = 5,
8
+ Blend = 6,
9
+ Catrom = 7,
10
+ Integer = 8,
11
+ Mesh = 9,
12
+ Nearest = 10,
13
+ Spline = 11
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PixelInterpolateMethod = void 0;
4
+ var PixelInterpolateMethod;
5
+ (function (PixelInterpolateMethod) {
6
+ PixelInterpolateMethod[PixelInterpolateMethod["Undefined"] = 0] = "Undefined";
7
+ PixelInterpolateMethod[PixelInterpolateMethod["Average"] = 1] = "Average";
8
+ PixelInterpolateMethod[PixelInterpolateMethod["Average9"] = 2] = "Average9";
9
+ PixelInterpolateMethod[PixelInterpolateMethod["Average16"] = 3] = "Average16";
10
+ PixelInterpolateMethod[PixelInterpolateMethod["Background"] = 4] = "Background";
11
+ PixelInterpolateMethod[PixelInterpolateMethod["Bilinear"] = 5] = "Bilinear";
12
+ PixelInterpolateMethod[PixelInterpolateMethod["Blend"] = 6] = "Blend";
13
+ PixelInterpolateMethod[PixelInterpolateMethod["Catrom"] = 7] = "Catrom";
14
+ PixelInterpolateMethod[PixelInterpolateMethod["Integer"] = 8] = "Integer";
15
+ PixelInterpolateMethod[PixelInterpolateMethod["Mesh"] = 9] = "Mesh";
16
+ PixelInterpolateMethod[PixelInterpolateMethod["Nearest"] = 10] = "Nearest";
17
+ PixelInterpolateMethod[PixelInterpolateMethod["Spline"] = 11] = "Spline";
18
+ })(PixelInterpolateMethod = exports.PixelInterpolateMethod || (exports.PixelInterpolateMethod = {}));
@@ -51,7 +51,7 @@ class PixelCollection extends native_instance_1.NativeInstance {
51
51
  setArea(x, y, width, height, quantumPixelsOrNumberPixels) {
52
52
  exception_1.Exception.usePointer(exception => {
53
53
  const pixels = (quantumPixelsOrNumberPixels instanceof Uint8Array) ? quantumPixelsOrNumberPixels : new Uint8Array(quantumPixelsOrNumberPixels);
54
- array_1._withQuantumArray(pixels, pixelsPtr => {
54
+ (0, array_1._withQuantumArray)(pixels, pixelsPtr => {
55
55
  image_magick_1.ImageMagick._api._PixelCollection_SetArea(this._instance, x, y, width, height, pixelsPtr, pixels.length, exception);
56
56
  });
57
57
  });
@@ -79,7 +79,7 @@ class PixelCollection extends native_instance_1.NativeInstance {
79
79
  }
80
80
  }
81
81
  use(x, y, width, height, mapping, func) {
82
- return string_1._withString(mapping, mappingPtr => {
82
+ return (0, string_1._withString)(mapping, mappingPtr => {
83
83
  return exception_1.Exception.use(exception => {
84
84
  const instance = image_magick_1.ImageMagick._api._PixelCollection_ToByteArray(this._instance, x, y, width, height, mappingPtr, exception.ptr);
85
85
  return exception.check(() => {
@@ -0,0 +1,9 @@
1
+ import { MagickColor } from '../magick-color';
2
+ export declare class DrawingSettings {
3
+ backgroundColor?: MagickColor;
4
+ fillColor?: MagickColor;
5
+ font?: string;
6
+ fontPointsize?: number;
7
+ strokeColor?: MagickColor;
8
+ strokeWidth?: number;
9
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DrawingSettings = void 0;
4
+ const native_drawing_settings_1 = require("./native-drawing-settings");
5
+ class DrawingSettings {
6
+ static _create(settings) {
7
+ const instance = new DrawingSettings();
8
+ instance.fillColor = settings.fillColor;
9
+ instance.font = settings.font;
10
+ instance.fontPointsize = settings.fontPointsize;
11
+ instance.strokeColor = settings.strokeColor;
12
+ instance.strokeWidth = settings.strokeWidth;
13
+ return instance;
14
+ }
15
+ _use(func) {
16
+ const settings = new native_drawing_settings_1.NativeDrawingSettings(this);
17
+ try {
18
+ return func(settings);
19
+ }
20
+ finally {
21
+ settings.dispose();
22
+ }
23
+ }
24
+ }
25
+ exports.DrawingSettings = DrawingSettings;
@@ -15,7 +15,7 @@ class MagickReadSettings extends magick_settings_1.MagickSettings {
15
15
  try {
16
16
  const size = this.getSize();
17
17
  if (size !== '') {
18
- string_1._withString(size, sizePtr => {
18
+ (0, string_1._withString)(size, sizePtr => {
19
19
  image_magick_1.ImageMagick._api._MagickSettings_SetSize(settings._instance, sizePtr);
20
20
  });
21
21
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NativeDrawingSettings = void 0;
4
+ const image_magick_1 = require("../image-magick");
5
+ const magick_1 = require("../magick");
6
+ const native_instance_1 = require("../internal/native-instance");
7
+ const string_1 = require("../internal/native/string");
8
+ class NativeDrawingSettings extends native_instance_1.NativeInstance {
9
+ constructor(settings) {
10
+ const instance = image_magick_1.ImageMagick._api._DrawingSettings_Create();
11
+ const disposeMethod = image_magick_1.ImageMagick._api._DrawingSettings_Dispose;
12
+ super(instance, disposeMethod);
13
+ if (settings.fillColor !== undefined) {
14
+ settings.fillColor._use(valuePtr => {
15
+ image_magick_1.ImageMagick._api._DrawingSettings_FillColor_Set(this._instance, valuePtr);
16
+ });
17
+ }
18
+ if (settings.font !== undefined) {
19
+ const fileName = magick_1.Magick._getFontFileName(settings.font);
20
+ (0, string_1._withString)(fileName, ptr => {
21
+ image_magick_1.ImageMagick._api._DrawingSettings_Font_Set(this._instance, ptr);
22
+ });
23
+ }
24
+ if (settings.fontPointsize !== undefined)
25
+ image_magick_1.ImageMagick._api._DrawingSettings_FontPointsize_Set(this._instance, settings.fontPointsize);
26
+ if (settings.strokeColor !== undefined) {
27
+ settings.strokeColor._use(valuePtr => {
28
+ image_magick_1.ImageMagick._api._DrawingSettings_StrokeColor_Set(this._instance, valuePtr);
29
+ });
30
+ }
31
+ if (settings.strokeWidth !== undefined)
32
+ image_magick_1.ImageMagick._api._DrawingSettings_StrokeWidth_Set(this._instance, settings.strokeWidth);
33
+ }
34
+ }
35
+ exports.NativeDrawingSettings = NativeDrawingSettings;