Image compression codec source and relink package
================================================
Source-built assets for the shared browser compression module. This package is
not an application-wide license, legal opinion, or universal device-capacity claim.

Layout and machine-readable authority
------------------------------------
assets/ preserves each existing loader's relative out/, dist/, build/ URL layout.
manifest.json entrypoints maps integration names to package-relative loader URLs;
files[] gives byte counts/SHA256 for every distributable regular file except the
self-referential manifest/checksum/container. SHA256SUMS additionally hashes the
manifest. notices/index.json maps full content-addressed license/patent/copyright
texts to origins. provenance/sources.json gives exact source/archive/license pins.
provenance/toolchain.json records observed compiler versions and compiler hashes.
source/build-spec.json is the standalone machine-readable extraction/config/patch/
compile/link/restage recipe. Historical records in provenance/original-* are
unmodified evidence, NOT executable relocation recipes; their absolute scratch
paths and old author status sentences do not override this package's file hashes.

Selected assets: BSD libimagequant/libpng writer; strict raw PNG/JPEG decode;
OxiPNG 10.2.1; MozJPEG/libwebp; libavif/AOM/libheif/libde265/lcms; editor-only JXL;
owned GIF/BMP/TIFF still-import modules and worker (no GeoTIFF/Lerc/zstddec).
No modern Rust imagequant/GPL benchmark control, x265/fixture encoders, native
oracles, source image fixtures, whole SDK, or compiler binaries are distributed.
OxiPNG's standalone loader is a prerequisite-package adapter over the existing
owned Wasm ABI, not a claim of final metadata policy or verified production API.

The profile data assets are original CC0 Display-P3 (D65, P3, IEC sRGB transfer)
and exact official ICC sRGB2014.icc. Use the former to interpret eligible NCLX12/13
input only; the latter is output sRGB signaling. No synthetic CMYK fallback or
synthetic sRGB corpus profile is an asset. ICC-NOTICE.txt retains the ICC grant.

Metadata-only original inspection (editor reference)
---------------------------------------------------
In a dedicated worker, await loadCodecAdapter() and call
adapter.inspectFile(file, 'avif' | 'heic' | 'heif'). The immutable browser File is
read through FileReaderSync and real libavif/libheif random-read callbacks. This
API returns the existing facts/sourceIcc/sourceExif/sourceXmp result, not decoded
source pixels. It retains primary-image, sequence, HDR/gain-map, precision, color
and orientation inspection; it is not a way to bypass those decisions.

Metadata mode does not impose the dedicated compressor's 50,000,000-byte or
48,000,000-source-pixel gates. Its offsets/lengths must be exact JavaScript safe
integers; files above 4 GiB are representable, while each compressed AV1 item
extent remains subject to wasm32 SIZE_MAX. The JS read cache is 1 MiB and each
native read is at most 8 MiB. Scoped AVIF allocations are bounded to 32 MiB total
and 8 MiB individually; HEIF parser limits are 64 MiB total/8 MiB per block.
Preserved ICC, EXIF and XMP packets are each limited to 4 MiB. These are separate
parser/read/packet limits, not a total-Wasm-memory promise or an image-byte cap.

Owned still-import modules expose inspectStillMetadata(source) for the editor's
bounded actual-File metadata reader, without decoding original GIF/BMP/TIFF
rasters. Existing byte-array inspect/decode APIs keep their dedicated input and
raster limits. Editor integration retains the separate 16,000,000-pixel edited
output bound and does not add dedicated 20-source/50 MB/48 MP admission caps.

source/owned/avif-heif/avif-file-metadata.patch is an owned patch against the
unchanged pinned libavif 1.4.2 archive/revision c5240fc79fe5c2407e10afd35f5505ef6333ea49.
It installs scoped allocation hooks, bounded CICP-prefix allocation, metadata-only
dimension handling, 64-bit top-level box sizes and an explicit raster-decode
refusal in metadata mode. Normal inspection/decode/encode semantics are unchanged.
Standalone extraction applies this patch with --fuzz=0 before compiling libavif;
source/build-spec.json patchedSources hashes identify the five resulting compiler
inputs. The application adapter object and rebuilt libavif archive must be kept
with their matching glue/Wasm, not substituted with pre-metadata relink inputs.

Generate/restage from current source-built artifacts (repository workspace)
-------------------------------------------------------------------------
python3 .scratch/image-compressor/release-candidate/package.py --archive

After an adapter rebuild in feasibility, rerun the same command: it automatically
copies current owned inputs (including both native patches), current glue/Wasm
and relink inputs from feasibility, then rebuilds notices/source/path manifests
and candidate.tar.gz with fixed gzip timestamp/tar metadata. No separate manual
refresh of release-candidate/source or relink is needed. Default staging rejects
adapter source/object/library/glue bytes that differ from the latest successful
native build-evidence.json. It never selects an older reproduction work tree.
No compiler/build/test runs occur during staging; runtime gates must use the
exact final staged assets.

The metadata patch was normalized to exact pristine-source context without
changing the already-built effective native source. The staged original-builds
records describe the build whose inputs are packaged. Records from earlier builds
may contain an earlier patch-file digest or a pre-metadata sourceManifest patch
list; source/build-spec.json patch list and patchedSources hashes are the
executable source authority. Do not rewrite evidence to imply a later compilation:
a new successful native build records its actual current source/patch inputs.
Earlier archive hashes are historical only: read the new package.py output,
manifest and SHA256SUMS after restaging instead of assuming an old digest is current.

package.py does NOT update static/codecs/image-compressor. In the repository,
explicitly publish the regenerated source kit and the matching runtime layout:
cp -R .scratch/image-compressor/release-candidate/assets/. static/codecs/image-compressor/
cp .scratch/image-compressor/release-candidate/candidate.tar.gz static/codecs/image-compressor/source-and-relink.tgz
cp .scratch/image-compressor/release-candidate/manifest.json static/codecs/image-compressor/source-manifest.json
cp .scratch/image-compressor/release-candidate/SHA256SUMS static/codecs/image-compressor/source-SHA256SUMS
cp .scratch/image-compressor/release-candidate/OWNED-RELINK-PERMISSIONS.txt static/codecs/image-compressor/

Regenerate release.json from the actual published bytes, not historical hashes:
python3 - <<'PY'
import hashlib
import json
from pathlib import Path
package = Path('.scratch/image-compressor/release-candidate')
runtime = Path('static/codecs/image-compressor')
def sha(path):
    with path.open('rb') as stream:
        return hashlib.file_digest(stream, 'sha256').hexdigest()
archive = runtime / 'source-and-relink.tgz'
records = json.loads((package / 'manifest.json').read_text())['files']
assets = [record['path'].removeprefix('assets/') for record in records
          if record['path'].startswith('assets/')]
release = {
    'sourceArchive': {'file': archive.name, 'bytes': archive.stat().st_size,
                      'sha256': sha(archive)},
    'runtimeAssets': [{'path': path, 'sha256': sha(runtime / path)} for path in assets],
    'notice': 'NOTICES.txt',
    'sourceManifest': 'source-manifest.json',
}
(runtime / 'release.json').write_text(json.dumps(release, indent=2) + '\n')
PY

Retain the published NOTICES.txt and owner permissions; if the selected notices
change, rebuild NOTICES.txt from the new notices/index.json/texts as well.
AVIF/HEIF glue/Wasm belong in avif-heif/dist/, matching adapter.mjs defaults;
do not flatten those files into avif-heif/. The package copies do not delete any
obsolete runtime files from an earlier incorrect layout.
The public download deliberately uses .tgz: Vite/sirv treats a .gz suffix as
HTTP Content-Encoding: gzip, transparently decoding the archive and changing its
downloaded bytes. Verify the hosted download against release.json after restaging.

For standalone rebuilt outputs, keep source and object correspondence explicit:
python3 /path/to/package/package.py --feasibility /path/to/original/feasibility \
  --assets-from /path/to/rebuilt-assets --rebuilt-work /path/to/rebuild-work --archive
The feasibility tree supplies historical provenance/source pins/notices only;
--rebuilt-work supplies the actual new owned source and LGPL relink objects.
--assets-from supplies the actual final assets. Supply both together. Changed
codec source revisions/build flags require updating their pins/build records before
restaging; do not replace bytes while retaining someone else's source provenance.
The source package is independently usable for reproduction; package.py is the
workspace restaging tool and intentionally needs the artifact/provenance inputs.

External toolchain acquisition (Linux x86_64 observed host)
----------------------------------------------------------
No SDK/source-binary duplicates are bundled. Use an external location:
git clone https://github.com/emscripten-core/emsdk.git /path/to/emsdk
git -C /path/to/emsdk checkout b1c3a90fb12ff6ce15f06f7e80ee5eafbb88665c
/path/to/emsdk/emsdk install releases-f6264d4a4dd9ba24a9f0a5702835a44d1463de13-64bit
/path/to/emsdk/emsdk activate releases-f6264d4a4dd9ba24a9f0a5702835a44d1463de13-64bit

Expected emcc 6.0.11 source a0014542110d6078c3a1a7941fa1ddb3a2281f16.
The SDK acquisition downloads the release-pinned compiler/runtime. Emscripten port
recipes/source overlays are recorded/preserved; the BSD writer uses the SDK's
pinned libpng1.6.58/zlib1.3.2 port as the original build did. Port archives are also
in source/upstream. No arbitrary mutable system port is silently substituted.

python3 -m venv /path/to/tools
/path/to/tools/bin/python -m pip install 'cmake==4.4.3' 'ninja==1.13.2'
rustup toolchain install 1.97.1 --profile minimal --target wasm32-unknown-unknown
export RUSTUP_TOOLCHAIN=1.97.1

Expected Ninja output is 1.13.2.git.kitware.jobserver-pipe-1, NOT just a semver
claim. Node v24.14.0 and Bun 1.4.0 were observed in the original workspace;
neither is needed for standalone reproduction of these selected assets.
Acquisition versions/revisions are pinned, but no detached-signature
authentication is claimed.

Standalone build (after unpacking candidate.tar.gz anywhere)
------------------------------------------------------------
python3 /path/to/package/reproduce.py \
  --emsdk /path/to/emsdk --cmake /path/to/tools/bin/cmake \
  --ninja /path/to/tools/bin/ninja \
  --work /path/to/new-empty-work --output /path/to/new-rebuilt-assets

Python 3.12+ (safe tarfile extraction), Bash, patch, CMake, Ninja, and the pinned
Emscripten/Rust tools are required. Compiler inputs come from packaged sources;
Cargo uses vendored package archives, frozen/offline Cargo.lock and checksums.
Owned still-import ES modules are staged directly, not bundled with unreachable
third-party decoders. Build/relink writes only explicit work/output paths and
refuses a nonempty reused work tree. Browser codecs
are single-threaded; no deployment-wide cross-origin-isolation/header changes.
A relocated build can differ in path-sensitive glue/code: original byte identity
is not asserted. rebuilt-manifest.json records the new actual outputs for comparison.
Source patches and resulting native compiler-input hashes are enforced before
the build; a clean source build recreates codec_adapter.o and all relink archives,
including metadata-patched libavif.a. --relink-only uses its selected object and
archives and exports _codec_inspect_file alongside the existing Wasm APIs.
The earlier, pre-metadata integration run executed the standalone build
successfully with the pinned toolchain. An original-object relink matched that
build's AVIF/HEIF Wasm exactly. This is historical evidence, not execution of the
metadata-aware source recipe or proof about the current archive/runtime hashes.
A second relink substituted a rebuilt libde265 with version "1.1.3-relink-proof";
the marker appeared only in the replacement Wasm, and both versions decoded the
64x64 HEIC fixture to SHA256
abe48805f12659450a740a1242cee796b54142b91019f9cb7f44ebd84e6a1d4b.
The relocated OxiPNG Wasm had a different binary hash; a real PNG optimization
produced the same 550-byte result under both builds. Full binary reproducibility
is not asserted. Repository evidence is under
.scratch/image-compressor/reproduction/; these records are not required to rebuild.

LGPL user-relink command (no original source checkout required)
--------------------------------------------------------------
Copy relink/avif-heif/ to /path/to/custom-relink, replace libheif.a and/or
libde265.a with modified libraries built using the same Wasm ABI/compiler settings.
Keep codec_adapter.o and the other archives, or rebuild the application adapter
from packaged source when an ABI change requires it. Then:
python3 /path/to/package/reproduce.py \
  --emsdk /path/to/emsdk --cmake /path/to/tools/bin/cmake \
  --ninja /path/to/tools/bin/ninja --work /path/to/unused-work \
  --output /path/to/custom-glue --relink-only --relink-inputs /path/to/custom-relink

This creates codecs.mjs/codecs.wasm without rebuilding the application object.
In a local application checkout, replace
static/codecs/image-compressor/avif-heif/dist/codecs.mjs and codecs.wasm with this
pair. Run the application normally; its module selects these same-origin paths,
without hard-coded hash enforcement or signatures blocking a modified build.
Alternatively load the pair with loadCodecAdapter({moduleUrl,wasmUrl}).
Preserve source/object correspondence and notices when distributing your changes.
OWNED-RELINK-PERMISSIONS.txt supplies the narrow owner-authorized LGPL
recombination/reverse-engineering/debugging grant, not a license to unrelated
application code. Hosted-site installation rights depend on the distributor's
actual delivery; no access to a remote deployment is promised. See COMPLIANCE.txt.

Display-P3 profile reproduction (no fixture/native-oracle tooling required)
-------------------------------------------------------------------------
python3 /path/to/package/generate-profile.py --work /path/to/new-empty-profile-work \
  --cmake /path/to/tools/bin/cmake --cc cc

This hash-checks/extracts the packaged lcms2.19.1 source archive, builds/installs
only its permissive native core (all GPL plugins/tools/tests/optional libraries
disabled), compiles source/profiles/display-p3.c, and emits the profile plus its
actual SHA256. It requires no corpus, fixture tooling or additional dependency.

The source fixes ICC creation date to 2026-10-02T00:00:00 and clears the profile ID;
it emits only Display-P3, not synthetic CMYK or synthetic sRGB. Source is the exact
CC0 generation functions extracted from the local original native-color.c recipe.
The standalone profile generator was executed with pinned lcms. Its output
matched the packaged profile byte-for-byte: SHA256
4ddeb4c1289591acf1d6df9f22c9441b0f59a4102d6bbbe56c8d3d29038a1f28.
Official sRGB2014.icc is acquired unchanged from the pinned libavif source archive,
not regenerated by lcms.
