@eyepop.ai/eyepop-render-2d 3.17.3 → 3.19.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/README.md +41 -2
- package/dist/eyepop.render2d.index.d.mts +25 -1
- package/dist/eyepop.render2d.index.d.ts +25 -1
- package/dist/eyepop.render2d.index.js +121 -0
- package/dist/eyepop.render2d.index.js.map +1 -1
- package/dist/eyepop.render2d.index.mjs +120 -0
- package/dist/eyepop.render2d.index.mjs.map +1 -1
- package/dist/eyepop.render2d.min.js +1 -1
- package/package.json +2 -2
|
@@ -4150,6 +4150,121 @@ var RenderClasses = class {
|
|
|
4150
4150
|
}
|
|
4151
4151
|
};
|
|
4152
4152
|
|
|
4153
|
+
// render-depth.ts
|
|
4154
|
+
var TURBO_ANCHORS = [
|
|
4155
|
+
[48, 18, 59],
|
|
4156
|
+
[62, 86, 196],
|
|
4157
|
+
[33, 145, 237],
|
|
4158
|
+
[26, 192, 181],
|
|
4159
|
+
[94, 223, 105],
|
|
4160
|
+
[181, 229, 54],
|
|
4161
|
+
[243, 192, 52],
|
|
4162
|
+
[246, 117, 26],
|
|
4163
|
+
[122, 4, 3]
|
|
4164
|
+
];
|
|
4165
|
+
var SKY_COLOR = [48, 18, 59];
|
|
4166
|
+
var isLittleEndianPlatform = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
4167
|
+
function decodeDepthValues(base64, width, height) {
|
|
4168
|
+
if (!Number.isSafeInteger(width) || width <= 0 || !Number.isSafeInteger(height) || height <= 0 || !Number.isSafeInteger(width * height * 4)) {
|
|
4169
|
+
throw new Error(`invalid depth dimensions: ${width}x${height}`);
|
|
4170
|
+
}
|
|
4171
|
+
const count = width * height;
|
|
4172
|
+
const buffer = Buffer.from(base64, "base64");
|
|
4173
|
+
if (buffer.byteLength !== count * 4) {
|
|
4174
|
+
throw new Error(`depth values hold ${buffer.byteLength} bytes, expected ${count * 4} float32 bytes`);
|
|
4175
|
+
}
|
|
4176
|
+
if (isLittleEndianPlatform) {
|
|
4177
|
+
const aligned = new Uint8Array(buffer);
|
|
4178
|
+
return new Float32Array(aligned.buffer, 0, count);
|
|
4179
|
+
}
|
|
4180
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
4181
|
+
const values = new Float32Array(count);
|
|
4182
|
+
for (let i = 0; i < count; i++) {
|
|
4183
|
+
values[i] = view.getFloat32(i * 4, true);
|
|
4184
|
+
}
|
|
4185
|
+
return values;
|
|
4186
|
+
}
|
|
4187
|
+
function turboColor(position) {
|
|
4188
|
+
const scaled = Math.min(Math.max(position, 0), 1) * (TURBO_ANCHORS.length - 1);
|
|
4189
|
+
const lower = Math.floor(scaled);
|
|
4190
|
+
const upper = Math.min(lower + 1, TURBO_ANCHORS.length - 1);
|
|
4191
|
+
const fraction = scaled - lower;
|
|
4192
|
+
return [
|
|
4193
|
+
TURBO_ANCHORS[lower][0] * (1 - fraction) + TURBO_ANCHORS[upper][0] * fraction,
|
|
4194
|
+
TURBO_ANCHORS[lower][1] * (1 - fraction) + TURBO_ANCHORS[upper][1] * fraction,
|
|
4195
|
+
TURBO_ANCHORS[lower][2] * (1 - fraction) + TURBO_ANCHORS[upper][2] * fraction
|
|
4196
|
+
];
|
|
4197
|
+
}
|
|
4198
|
+
var RenderDepth = class {
|
|
4199
|
+
constructor(options = {}) {
|
|
4200
|
+
this.target = "$";
|
|
4201
|
+
const { target = "$", opacity = 0.5, renderSky = false } = options;
|
|
4202
|
+
this.target = target;
|
|
4203
|
+
this.opacity = Math.min(Math.max(opacity, 0), 1);
|
|
4204
|
+
this.renderSky = renderSky;
|
|
4205
|
+
}
|
|
4206
|
+
start(context, style) {
|
|
4207
|
+
this.context = context;
|
|
4208
|
+
this.style = style;
|
|
4209
|
+
}
|
|
4210
|
+
draw(element, xOffset, yOffset, xScale, yScale, streamTime, color) {
|
|
4211
|
+
const context = this.context;
|
|
4212
|
+
if (!context || !this.style) {
|
|
4213
|
+
throw new Error("render() called before start()");
|
|
4214
|
+
}
|
|
4215
|
+
if (!element.depth) {
|
|
4216
|
+
return;
|
|
4217
|
+
}
|
|
4218
|
+
const depthWidth = element.depth.width;
|
|
4219
|
+
const depthHeight = element.depth.height;
|
|
4220
|
+
const values = decodeDepthValues(element.depth.values, depthWidth, depthHeight);
|
|
4221
|
+
const destWidth = Math.round(element.source_width * xScale);
|
|
4222
|
+
const destHeight = Math.round(element.source_height * yScale);
|
|
4223
|
+
if (destWidth <= 0 || destHeight <= 0) {
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
let finiteMin = Number.POSITIVE_INFINITY;
|
|
4227
|
+
let finiteMax = Number.NEGATIVE_INFINITY;
|
|
4228
|
+
for (let i = 0; i < values.length; i++) {
|
|
4229
|
+
const value = values[i];
|
|
4230
|
+
if (Number.isFinite(value)) {
|
|
4231
|
+
if (value < finiteMin) finiteMin = value;
|
|
4232
|
+
if (value > finiteMax) finiteMax = value;
|
|
4233
|
+
}
|
|
4234
|
+
}
|
|
4235
|
+
const span = finiteMax > finiteMin ? finiteMax - finiteMin : 1;
|
|
4236
|
+
const dest = context.getImageData(xOffset, yOffset, destWidth, destHeight);
|
|
4237
|
+
const pixels = dest.data;
|
|
4238
|
+
for (let y = 0; y < destHeight; y++) {
|
|
4239
|
+
const mapY = Math.min(Math.floor(y * depthHeight / destHeight), depthHeight - 1);
|
|
4240
|
+
const mapRow = mapY * depthWidth;
|
|
4241
|
+
for (let x = 0; x < destWidth; x++) {
|
|
4242
|
+
const mapX = Math.min(Math.floor(x * depthWidth / destWidth), depthWidth - 1);
|
|
4243
|
+
const value = values[mapRow + mapX];
|
|
4244
|
+
let heat;
|
|
4245
|
+
if (Number.isFinite(value)) {
|
|
4246
|
+
const normalized = Number.isFinite(finiteMin) ? (value - finiteMin) / span : 0;
|
|
4247
|
+
heat = turboColor(1 - normalized);
|
|
4248
|
+
} else if (this.renderSky) {
|
|
4249
|
+
heat = SKY_COLOR;
|
|
4250
|
+
} else {
|
|
4251
|
+
continue;
|
|
4252
|
+
}
|
|
4253
|
+
const index = (y * destWidth + x) * 4;
|
|
4254
|
+
const destinationAlpha = pixels[index + 3] / 255 * (1 - this.opacity);
|
|
4255
|
+
const outAlpha = this.opacity + destinationAlpha;
|
|
4256
|
+
if (outAlpha > 0) {
|
|
4257
|
+
pixels[index] = Math.round((heat[0] * this.opacity + pixels[index] * destinationAlpha) / outAlpha);
|
|
4258
|
+
pixels[index + 1] = Math.round((heat[1] * this.opacity + pixels[index + 1] * destinationAlpha) / outAlpha);
|
|
4259
|
+
pixels[index + 2] = Math.round((heat[2] * this.opacity + pixels[index + 2] * destinationAlpha) / outAlpha);
|
|
4260
|
+
}
|
|
4261
|
+
pixels[index + 3] = Math.round(outAlpha * 255);
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
context.putImageData(dest, xOffset, yOffset);
|
|
4265
|
+
}
|
|
4266
|
+
};
|
|
4267
|
+
|
|
4153
4268
|
// index.ts
|
|
4154
4269
|
var Render2d;
|
|
4155
4270
|
((Render2d2) => {
|
|
@@ -4177,6 +4292,10 @@ var Render2d;
|
|
|
4177
4292
|
return new RenderContour(options);
|
|
4178
4293
|
}
|
|
4179
4294
|
Render2d2.renderContour = renderContour;
|
|
4295
|
+
function renderDepth(options = {}) {
|
|
4296
|
+
return new RenderDepth(options);
|
|
4297
|
+
}
|
|
4298
|
+
Render2d2.renderDepth = renderDepth;
|
|
4180
4299
|
function renderFace(options = {}) {
|
|
4181
4300
|
return new RenderFace(options);
|
|
4182
4301
|
}
|
|
@@ -4211,6 +4330,7 @@ export {
|
|
|
4211
4330
|
RenderBox,
|
|
4212
4331
|
RenderClasses,
|
|
4213
4332
|
RenderContour,
|
|
4333
|
+
RenderDepth,
|
|
4214
4334
|
RenderFace,
|
|
4215
4335
|
RenderHand,
|
|
4216
4336
|
RenderKeyPoints,
|