@meta-sam/graphics 0.1.6 → 0.1.7
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 +3 -3
- package/dist/renderer.js +22 -25
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -153,8 +153,7 @@ complete current view to every `update()` call.
|
|
|
153
153
|
|
|
154
154
|
- `update()` calls are serialized in invocation order. Always await the update that
|
|
155
155
|
must be visible before calling `render()`.
|
|
156
|
-
- Masks and boxes are retained. Text
|
|
157
|
-
drawn.
|
|
156
|
+
- Masks and boxes are retained. Text records are accepted but are not drawn.
|
|
158
157
|
- Mask records are collapsed by `identity`; the greatest per-mask `revision` wins.
|
|
159
158
|
At the same revision, conflicting mask data is rejected.
|
|
160
159
|
- Boxes are collapsed by frame and `objectId`; the last box in the accepted view
|
|
@@ -174,7 +173,8 @@ collapsed.
|
|
|
174
173
|
|
|
175
174
|
Graphics accepts only complete masks with this shape, where `encoding` is
|
|
176
175
|
`lossless` (the SAM API default, payloads starting with `~`) or `one_bit`
|
|
177
|
-
(payloads starting with `!`)
|
|
176
|
+
(payloads starting with `!`) and `payload` is the opaque base85 text from the
|
|
177
|
+
wire, passed through unchanged:
|
|
178
178
|
|
|
179
179
|
```ts
|
|
180
180
|
{
|
package/dist/renderer.js
CHANGED
|
@@ -52,8 +52,6 @@ export function objectColor(objectId) {
|
|
|
52
52
|
*/
|
|
53
53
|
const RETAINED_MASK_OVERHEAD = 64;
|
|
54
54
|
function sameBounds(left, right) {
|
|
55
|
-
if (left === undefined || right === undefined)
|
|
56
|
-
return left === right;
|
|
57
55
|
return (left.left === right.left &&
|
|
58
56
|
left.top === right.top &&
|
|
59
57
|
left.right === right.right &&
|
|
@@ -150,7 +148,7 @@ function retainMask(record) {
|
|
|
150
148
|
...(record.frame === undefined ? {} : { frameIndex: record.frame.frameIndex }),
|
|
151
149
|
width: record.mask.width,
|
|
152
150
|
height: record.mask.height,
|
|
153
|
-
|
|
151
|
+
bounds: record.bounds,
|
|
154
152
|
};
|
|
155
153
|
}
|
|
156
154
|
function traceMask(mask, limit) {
|
|
@@ -375,22 +373,18 @@ export class SegmentationRenderer {
|
|
|
375
373
|
continue;
|
|
376
374
|
const color = colorFor(mask.objectId);
|
|
377
375
|
context.fillStyle = color;
|
|
378
|
-
|
|
379
|
-
|
|
376
|
+
// The raster covers the record's box: scale width × height into bounds.
|
|
377
|
+
context.save();
|
|
378
|
+
try {
|
|
379
|
+
const boundsScaleX = (mask.bounds.right - mask.bounds.left) / mask.width;
|
|
380
|
+
const boundsScaleY = (mask.bounds.bottom - mask.bounds.top) / mask.height;
|
|
381
|
+
context.translate(mask.bounds.left, mask.bounds.top);
|
|
382
|
+
context.scale(boundsScaleX, boundsScaleY);
|
|
383
|
+
this.#paintMask(context, traced.path, color, outlineWidth /
|
|
384
|
+
Math.max(Math.abs(boundsScaleX), Math.abs(boundsScaleY), Number.MIN_VALUE));
|
|
380
385
|
}
|
|
381
|
-
|
|
382
|
-
context.
|
|
383
|
-
try {
|
|
384
|
-
const boundsScaleX = (mask.bounds.right - mask.bounds.left) / mask.width;
|
|
385
|
-
const boundsScaleY = (mask.bounds.bottom - mask.bounds.top) / mask.height;
|
|
386
|
-
context.translate(mask.bounds.left, mask.bounds.top);
|
|
387
|
-
context.scale(boundsScaleX, boundsScaleY);
|
|
388
|
-
this.#paintMask(context, traced.path, color, outlineWidth /
|
|
389
|
-
Math.max(Math.abs(boundsScaleX), Math.abs(boundsScaleY), Number.MIN_VALUE));
|
|
390
|
-
}
|
|
391
|
-
finally {
|
|
392
|
-
context.restore();
|
|
393
|
-
}
|
|
386
|
+
finally {
|
|
387
|
+
context.restore();
|
|
394
388
|
}
|
|
395
389
|
}
|
|
396
390
|
for (const box of state.boxes.values()) {
|
|
@@ -555,13 +549,16 @@ export class SegmentationRenderer {
|
|
|
555
549
|
mask.height <= 0) {
|
|
556
550
|
throw new InvalidMaskPayloadError('Mask dimensions must be positive safe integers.');
|
|
557
551
|
}
|
|
558
|
-
if (record.bounds
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
552
|
+
if (record.bounds === undefined ||
|
|
553
|
+
![
|
|
554
|
+
record.bounds.left,
|
|
555
|
+
record.bounds.top,
|
|
556
|
+
record.bounds.right,
|
|
557
|
+
record.bounds.bottom,
|
|
558
|
+
].every(Number.isFinite) ||
|
|
559
|
+
record.bounds.right <= record.bounds.left ||
|
|
560
|
+
record.bounds.bottom <= record.bounds.top) {
|
|
561
|
+
throw new InvalidMaskPayloadError('Mask bounds are invalid.');
|
|
565
562
|
}
|
|
566
563
|
const area = mask.width * mask.height;
|
|
567
564
|
if (!Number.isSafeInteger(area) || area > this.#limits.maxMaskArea) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meta-sam/graphics",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Retained Canvas 2D renderer for SAM 3 segmentation",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"homepage": "https://github.com/meta-models/meta-sam#readme",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": "^20.17.0 || >=22.9.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@meta-sam/parser": "0.0.
|
|
36
|
+
"@meta-sam/parser": "0.0.10"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -b",
|