apertaluce 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +139 -2
- package/lib/audio/balance.d.ts +38 -0
- package/lib/audio/balance.js +455 -0
- package/lib/audio/index.d.ts +2 -0
- package/lib/audio/index.js +2 -0
- package/lib/audio/mark.d.ts +83 -0
- package/lib/audio/mark.js +458 -0
- package/lib/audio/resample.d.ts +6 -0
- package/lib/audio/resample.js +77 -0
- package/lib/fft.d.ts +10 -0
- package/lib/fft.js +82 -0
- package/lib/image/fingerprint.d.ts +21 -0
- package/lib/image/fingerprint.js +93 -0
- package/lib/image/index.d.ts +2 -0
- package/lib/image/index.js +2 -0
- package/lib/image/mark.d.ts +163 -0
- package/lib/image/mark.js +1240 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/video/index.d.ts +50 -0
- package/lib/video/index.js +79 -0
- package/package.json +59 -4
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picture mark on moving pictures. A video carries the same keyed tile as a
|
|
3
|
+
* still, at the same place in every frame: an encoder pipeline blends one plane
|
|
4
|
+
* onto the luma of all frames ({@link frameMarkOverlay}), which costs nothing
|
|
5
|
+
* per frame, and the detector reads frames taken from the suspect video
|
|
6
|
+
* ({@link detectFrameMark}).
|
|
7
|
+
*
|
|
8
|
+
* Because the mark stands still while the picture moves, the mean of several
|
|
9
|
+
* frames keeps the mark and blurs the picture away; the detector looks at that
|
|
10
|
+
* mean as well as at the frames themselves. This module does not decode or
|
|
11
|
+
* encode video: frames come from and go to whatever codec the host uses.
|
|
12
|
+
*/
|
|
13
|
+
import { type DetectOptions, type PixelKey, type PixelMarkResult, type RgbaImage } from "../image/mark.ts";
|
|
14
|
+
export interface FrameOverlayOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Standard deviation of the mark in luma levels (of 255). Video compression
|
|
17
|
+
* removes faint detail from flat areas, so a frame needs more than a still.
|
|
18
|
+
*/
|
|
19
|
+
amplitude?: number;
|
|
20
|
+
/** Tiles across the frame's shorter side. */
|
|
21
|
+
tilesPerShortSide?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tuned on H.264 re-encodes (bench/video.ts). At 3 the pattern showed as a film over flat
|
|
25
|
+
* areas of the frame; 2 is the lowest amplitude the bench was run at.
|
|
26
|
+
*/
|
|
27
|
+
export declare const FRAME_MARK_AMPLITUDE = 2;
|
|
28
|
+
export declare const FRAME_MARK_TILES = 4;
|
|
29
|
+
/**
|
|
30
|
+
* One 8-bit grey plane, `width`×`height`, where 128 means "leave the pixel"
|
|
31
|
+
* and other values are added to the frame's luma minus 128 (ffmpeg:
|
|
32
|
+
* `blend=all_mode=grainmerge` on the luma plane).
|
|
33
|
+
*/
|
|
34
|
+
export declare function frameMarkOverlay(width: number, height: number, key: PixelKey, options?: FrameOverlayOptions): Uint8Array;
|
|
35
|
+
/** The same plane as a binary PGM file, which every video tool reads as a grey picture. */
|
|
36
|
+
export declare function frameMarkOverlayPgm(width: number, height: number, key: PixelKey, options?: FrameOverlayOptions): Uint8Array;
|
|
37
|
+
export interface FrameMarkResult extends PixelMarkResult {
|
|
38
|
+
/** What the best score was read from: the mean of the frames, or one of them (its index). */
|
|
39
|
+
source: "mean" | number;
|
|
40
|
+
frames: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Looks for the mark in frames of one video (a dozen spread over its length is
|
|
44
|
+
* plenty). Frames must share one size. `singles` caps how many frames are also
|
|
45
|
+
* tried on their own; every extra look is one more chance for an unmarked
|
|
46
|
+
* video to pass, so keep it small.
|
|
47
|
+
*/
|
|
48
|
+
export declare function detectFrameMark(frames: readonly RgbaImage[], key: PixelKey, options?: DetectOptions & {
|
|
49
|
+
singles?: number;
|
|
50
|
+
}): FrameMarkResult;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picture mark on moving pictures. A video carries the same keyed tile as a
|
|
3
|
+
* still, at the same place in every frame: an encoder pipeline blends one plane
|
|
4
|
+
* onto the luma of all frames ({@link frameMarkOverlay}), which costs nothing
|
|
5
|
+
* per frame, and the detector reads frames taken from the suspect video
|
|
6
|
+
* ({@link detectFrameMark}).
|
|
7
|
+
*
|
|
8
|
+
* Because the mark stands still while the picture moves, the mean of several
|
|
9
|
+
* frames keeps the mark and blurs the picture away; the detector looks at that
|
|
10
|
+
* mean as well as at the frames themselves. This module does not decode or
|
|
11
|
+
* encode video: frames come from and go to whatever codec the host uses.
|
|
12
|
+
*/
|
|
13
|
+
import { detectPixelMark, pixelMarkPlane } from "../image/mark.js";
|
|
14
|
+
/**
|
|
15
|
+
* Tuned on H.264 re-encodes (bench/video.ts). At 3 the pattern showed as a film over flat
|
|
16
|
+
* areas of the frame; 2 is the lowest amplitude the bench was run at.
|
|
17
|
+
*/
|
|
18
|
+
export const FRAME_MARK_AMPLITUDE = 2;
|
|
19
|
+
export const FRAME_MARK_TILES = 4;
|
|
20
|
+
/**
|
|
21
|
+
* One 8-bit grey plane, `width`×`height`, where 128 means "leave the pixel"
|
|
22
|
+
* and other values are added to the frame's luma minus 128 (ffmpeg:
|
|
23
|
+
* `blend=all_mode=grainmerge` on the luma plane).
|
|
24
|
+
*/
|
|
25
|
+
export function frameMarkOverlay(width, height, key, options = {}) {
|
|
26
|
+
const amplitude = options.amplitude ?? FRAME_MARK_AMPLITUDE;
|
|
27
|
+
const plane = pixelMarkPlane(width, height, key, options.tilesPerShortSide ?? FRAME_MARK_TILES);
|
|
28
|
+
const overlay = new Uint8Array(width * height);
|
|
29
|
+
for (let i = 0; i < plane.length; i++)
|
|
30
|
+
overlay[i] = Math.min(255, Math.max(0, Math.round(128 + amplitude * plane[i])));
|
|
31
|
+
return overlay;
|
|
32
|
+
}
|
|
33
|
+
/** The same plane as a binary PGM file, which every video tool reads as a grey picture. */
|
|
34
|
+
export function frameMarkOverlayPgm(width, height, key, options = {}) {
|
|
35
|
+
const header = new TextEncoder().encode(`P5\n${width} ${height}\n255\n`);
|
|
36
|
+
const file = new Uint8Array(header.length + width * height);
|
|
37
|
+
file.set(header);
|
|
38
|
+
file.set(frameMarkOverlay(width, height, key, options), header.length);
|
|
39
|
+
return file;
|
|
40
|
+
}
|
|
41
|
+
/** Mean of same-sized frames as a grey picture. */
|
|
42
|
+
function meanFrame(frames) {
|
|
43
|
+
const { width, height } = frames[0];
|
|
44
|
+
const sum = new Float32Array(width * height);
|
|
45
|
+
for (const frame of frames) {
|
|
46
|
+
const data = frame.data;
|
|
47
|
+
for (let i = 0, p = 0; i < sum.length; i++, p += 4)
|
|
48
|
+
sum[i] += 0.299 * data[p] + 0.587 * data[p + 1] + 0.114 * data[p + 2];
|
|
49
|
+
}
|
|
50
|
+
const data = new Uint8ClampedArray(width * height * 4);
|
|
51
|
+
for (let i = 0, p = 0; i < sum.length; i++, p += 4) {
|
|
52
|
+
data[p] = data[p + 1] = data[p + 2] = sum[i] / frames.length;
|
|
53
|
+
data[p + 3] = 255;
|
|
54
|
+
}
|
|
55
|
+
return { data, width, height };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Looks for the mark in frames of one video (a dozen spread over its length is
|
|
59
|
+
* plenty). Frames must share one size. `singles` caps how many frames are also
|
|
60
|
+
* tried on their own; every extra look is one more chance for an unmarked
|
|
61
|
+
* video to pass, so keep it small.
|
|
62
|
+
*/
|
|
63
|
+
export function detectFrameMark(frames, key, options = {}) {
|
|
64
|
+
if (!frames.length)
|
|
65
|
+
return { detected: false, score: 0, mode: "none", keyId: key.id, source: "mean", frames: 0 };
|
|
66
|
+
const { singles = 2, ...detect } = options;
|
|
67
|
+
let best = { ...detectPixelMark(frames.length > 1 ? meanFrame(frames) : frames[0], key, detect), source: frames.length > 1 ? "mean" : 0, frames: frames.length };
|
|
68
|
+
if (frames.length > 1 && !best.detected) {
|
|
69
|
+
const step = Math.max(1, Math.floor(frames.length / Math.max(1, singles)));
|
|
70
|
+
for (let index = 0, tried = 0; index < frames.length && tried < singles; index += step, tried++) {
|
|
71
|
+
const single = detectPixelMark(frames[index], key, detect);
|
|
72
|
+
if (single.score > best.score)
|
|
73
|
+
best = { ...single, source: index, frames: frames.length };
|
|
74
|
+
if (best.detected)
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return best;
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apertaluce",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Keyed, invisible marks for pictures, sound and video that survive re-encoding and editing. Pure TypeScript, no dependencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"default": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./image": {
|
|
15
|
+
"types": "./lib/image/index.d.ts",
|
|
16
|
+
"default": "./lib/image/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./audio": {
|
|
19
|
+
"types": "./lib/audio/index.d.ts",
|
|
20
|
+
"default": "./lib/audio/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./video": {
|
|
23
|
+
"types": "./lib/video/index.d.ts",
|
|
24
|
+
"default": "./lib/video/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"lib"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "node scripts/clean.mjs && tsc -p tsconfig.build.json",
|
|
33
|
+
"tsc": "tsc -p . --noEmit",
|
|
34
|
+
"test": "node --test \"test/**/*.test.ts\"",
|
|
35
|
+
"prepublishOnly": "npm run build",
|
|
36
|
+
"bootstrap:publish": "node scripts/bootstrap-publish.mjs"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/lofcz/apertaluce.git"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"watermark",
|
|
47
|
+
"steganography",
|
|
48
|
+
"invisible-watermark",
|
|
49
|
+
"image",
|
|
50
|
+
"audio",
|
|
51
|
+
"video",
|
|
52
|
+
"provenance",
|
|
53
|
+
"spread-spectrum",
|
|
54
|
+
"typescript"
|
|
55
|
+
],
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^24.0.0",
|
|
59
|
+
"typescript": "^6.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|