cross-image 0.2.2 → 0.2.4

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 (88) hide show
  1. package/README.md +333 -168
  2. package/esm/mod.d.ts +2 -0
  3. package/esm/mod.js +2 -0
  4. package/esm/src/formats/apng.d.ts +13 -1
  5. package/esm/src/formats/apng.js +97 -0
  6. package/esm/src/formats/ascii.d.ts +11 -1
  7. package/esm/src/formats/ascii.js +24 -0
  8. package/esm/src/formats/avif.d.ts +96 -0
  9. package/esm/src/formats/avif.js +607 -0
  10. package/esm/src/formats/bmp.d.ts +11 -1
  11. package/esm/src/formats/bmp.js +73 -0
  12. package/esm/src/formats/dng.d.ts +13 -1
  13. package/esm/src/formats/dng.js +26 -4
  14. package/esm/src/formats/gif.d.ts +15 -2
  15. package/esm/src/formats/gif.js +146 -4
  16. package/esm/src/formats/heic.d.ts +96 -0
  17. package/esm/src/formats/heic.js +608 -0
  18. package/esm/src/formats/ico.d.ts +11 -1
  19. package/esm/src/formats/ico.js +28 -0
  20. package/esm/src/formats/jpeg.d.ts +19 -1
  21. package/esm/src/formats/jpeg.js +709 -4
  22. package/esm/src/formats/pam.d.ts +11 -1
  23. package/esm/src/formats/pam.js +66 -0
  24. package/esm/src/formats/pcx.d.ts +11 -1
  25. package/esm/src/formats/pcx.js +45 -0
  26. package/esm/src/formats/png.d.ts +13 -1
  27. package/esm/src/formats/png.js +87 -0
  28. package/esm/src/formats/png_base.d.ts +8 -0
  29. package/esm/src/formats/png_base.js +176 -3
  30. package/esm/src/formats/ppm.d.ts +11 -1
  31. package/esm/src/formats/ppm.js +34 -0
  32. package/esm/src/formats/tiff.d.ts +13 -1
  33. package/esm/src/formats/tiff.js +165 -0
  34. package/esm/src/formats/webp.d.ts +16 -2
  35. package/esm/src/formats/webp.js +303 -62
  36. package/esm/src/image.d.ts +60 -0
  37. package/esm/src/image.js +253 -5
  38. package/esm/src/types.d.ts +59 -1
  39. package/esm/src/utils/image_processing.d.ts +55 -0
  40. package/esm/src/utils/image_processing.js +210 -0
  41. package/esm/src/utils/metadata/xmp.d.ts +52 -0
  42. package/esm/src/utils/metadata/xmp.js +325 -0
  43. package/esm/src/utils/resize.d.ts +4 -0
  44. package/esm/src/utils/resize.js +74 -0
  45. package/package.json +18 -1
  46. package/script/mod.d.ts +2 -0
  47. package/script/mod.js +5 -1
  48. package/script/src/formats/apng.d.ts +13 -1
  49. package/script/src/formats/apng.js +97 -0
  50. package/script/src/formats/ascii.d.ts +11 -1
  51. package/script/src/formats/ascii.js +24 -0
  52. package/script/src/formats/avif.d.ts +96 -0
  53. package/script/src/formats/avif.js +611 -0
  54. package/script/src/formats/bmp.d.ts +11 -1
  55. package/script/src/formats/bmp.js +73 -0
  56. package/script/src/formats/dng.d.ts +13 -1
  57. package/script/src/formats/dng.js +26 -4
  58. package/script/src/formats/gif.d.ts +15 -2
  59. package/script/src/formats/gif.js +146 -4
  60. package/script/src/formats/heic.d.ts +96 -0
  61. package/script/src/formats/heic.js +612 -0
  62. package/script/src/formats/ico.d.ts +11 -1
  63. package/script/src/formats/ico.js +28 -0
  64. package/script/src/formats/jpeg.d.ts +19 -1
  65. package/script/src/formats/jpeg.js +709 -4
  66. package/script/src/formats/pam.d.ts +11 -1
  67. package/script/src/formats/pam.js +66 -0
  68. package/script/src/formats/pcx.d.ts +11 -1
  69. package/script/src/formats/pcx.js +45 -0
  70. package/script/src/formats/png.d.ts +13 -1
  71. package/script/src/formats/png.js +87 -0
  72. package/script/src/formats/png_base.d.ts +8 -0
  73. package/script/src/formats/png_base.js +176 -3
  74. package/script/src/formats/ppm.d.ts +11 -1
  75. package/script/src/formats/ppm.js +34 -0
  76. package/script/src/formats/tiff.d.ts +13 -1
  77. package/script/src/formats/tiff.js +165 -0
  78. package/script/src/formats/webp.d.ts +16 -2
  79. package/script/src/formats/webp.js +303 -62
  80. package/script/src/image.d.ts +60 -0
  81. package/script/src/image.js +251 -3
  82. package/script/src/types.d.ts +59 -1
  83. package/script/src/utils/image_processing.d.ts +55 -0
  84. package/script/src/utils/image_processing.js +216 -0
  85. package/script/src/utils/metadata/xmp.d.ts +52 -0
  86. package/script/src/utils/metadata/xmp.js +333 -0
  87. package/script/src/utils/resize.d.ts +4 -0
  88. package/script/src/utils/resize.js +75 -0
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resizeBilinear = resizeBilinear;
4
4
  exports.resizeNearest = resizeNearest;
5
+ exports.resizeBicubic = resizeBicubic;
5
6
  /**
6
7
  * Bilinear interpolation resize
7
8
  */
@@ -54,3 +55,77 @@ function resizeNearest(src, srcWidth, srcHeight, dstWidth, dstHeight) {
54
55
  }
55
56
  return dst;
56
57
  }
58
+ /**
59
+ * Cubic interpolation kernel (Catmull-Rom)
60
+ *
61
+ * The Catmull-Rom spline provides smooth interpolation through control points.
62
+ * It's a special case of the cubic Hermite spline with specific tangent values.
63
+ *
64
+ * @param x Distance from the sample point
65
+ * @returns Weight for the sample at distance x
66
+ */
67
+ function cubicKernel(x) {
68
+ const absX = Math.abs(x);
69
+ if (absX <= 1) {
70
+ return 1.5 * absX * absX * absX - 2.5 * absX * absX + 1;
71
+ }
72
+ else if (absX < 2) {
73
+ return -0.5 * absX * absX * absX + 2.5 * absX * absX - 4 * absX + 2;
74
+ }
75
+ return 0;
76
+ }
77
+ /**
78
+ * Get pixel value with bounds checking
79
+ *
80
+ * Clamps coordinates to valid image bounds to prevent out-of-bounds access.
81
+ * This ensures that edge pixels are repeated when sampling outside the image.
82
+ *
83
+ * @param src Source image data
84
+ * @param x X coordinate (may be outside bounds)
85
+ * @param y Y coordinate (may be outside bounds)
86
+ * @param width Image width
87
+ * @param height Image height
88
+ * @param channel Channel index (0=R, 1=G, 2=B, 3=A)
89
+ * @returns Pixel value at the clamped coordinates
90
+ */
91
+ function getPixel(src, x, y, width, height, channel) {
92
+ const clampedX = Math.max(0, Math.min(width - 1, x));
93
+ const clampedY = Math.max(0, Math.min(height - 1, y));
94
+ return src[(clampedY * width + clampedX) * 4 + channel];
95
+ }
96
+ /**
97
+ * Bicubic interpolation resize (Catmull-Rom)
98
+ */
99
+ function resizeBicubic(src, srcWidth, srcHeight, dstWidth, dstHeight) {
100
+ const dst = new Uint8Array(dstWidth * dstHeight * 4);
101
+ const xRatio = srcWidth / dstWidth;
102
+ const yRatio = srcHeight / dstHeight;
103
+ for (let y = 0; y < dstHeight; y++) {
104
+ for (let x = 0; x < dstWidth; x++) {
105
+ const srcX = x * xRatio;
106
+ const srcY = y * yRatio;
107
+ const x0 = Math.floor(srcX);
108
+ const y0 = Math.floor(srcY);
109
+ const dx = srcX - x0;
110
+ const dy = srcY - y0;
111
+ // Process each channel separately
112
+ for (let c = 0; c < 4; c++) {
113
+ let value = 0;
114
+ // Sample 4x4 neighborhood
115
+ for (let j = -1; j <= 2; j++) {
116
+ for (let i = -1; i <= 2; i++) {
117
+ const px = x0 + i;
118
+ const py = y0 + j;
119
+ const pixelValue = getPixel(src, px, py, srcWidth, srcHeight, c);
120
+ const weight = cubicKernel(i - dx) * cubicKernel(j - dy);
121
+ value += pixelValue * weight;
122
+ }
123
+ }
124
+ // Clamp to valid range
125
+ const dstIdx = (y * dstWidth + x) * 4 + c;
126
+ dst[dstIdx] = Math.max(0, Math.min(255, Math.round(value)));
127
+ }
128
+ }
129
+ }
130
+ return dst;
131
+ }