The DX10 header's alpha mode (miscFlags2, low three bits) was never
read, so RGBA, BGRA, BC2 and BC3 files marked premultiplied were read
as straight alpha. They are refused as Unsupported, like the legacy
DXT2/DXT4 FourCCs. Alpha modes 0, 1, 3 and 4 and the formats without
alpha are unchanged.
An ignored test beside the encode timings: the best of five decodes of
the same texture written with each compression. It uses only the API
the reader had before, so it runs on the old code for comparison.
BC4 is one block of 16 single-channel values and BC5 two of them, the
block BC3 already stores its alpha in, so the alpha block encoder and
decoder now serve all three (BC3's output stays the same).
Reading: ATI1 and BC4U, and DXGI 79 (typeless) and 80, open as gray;
ATI2 and BC5U, and DXGI 82 (typeless, as Pillow writes it) and 83,
open as RGB with blue 0. ATI2 follows Microsoft's mapping, red in the
first block. Signed BC4S/BC5S and DXGI 81/84 are refused, naming SNORM.
Writing: DdsCompression::Bc4 (bc4, ati1) from gray and Bc5 (bc5, ati2)
from RGB, with the DX10 header (BC4_UNORM, BC5_UNORM, one 2D texture),
mip chains included. The encode plan converts other layouts to gray
and RGB, so the fidelity warnings report colour to gray and dropped
alpha; BC5's dropped blue is documented under LossyCompression.
DdsCompression is now #[non_exhaustive] and ALL has six entries.
A power-iteration step that gives back the same axis bit for bit gives
it back on every later step, so stopping there keeps the output. Kept
only if the timings show a gain.
Encoding:
- colour blocks keep their colours and endpoint candidates on the stack
instead of in per-block vectors (the idea of storytold/photocraft#10669)
- a refinement round whose endpoint pair was already fitted ends the
search, which could not change the block any more
- a block of one colour skips the principal-axis search, whose result
for it is that colour at both ends
- the alpha block gathers its 16 values once, finds both ranges in one
pass and picks indices in a plain loop with the same tie-break
- the nearest palette colour is found the same way
- interior blocks are gathered as four rows of four texels, and
interior mip pixels average their 2x2 source pixels directly
Decoding:
- block-compressed data is decoded one row of blocks per task, copying
whole texel rows and checking bounds only on the right edge
- uncompressed rows are decoded one per task; when every channel is a
whole byte (RGBA, BGRA, BGRX, luminance), pixels are a byte shuffle
The f32 arithmetic and its order are unchanged; the digest oracle pins
the output.
craft-dds holds the header parsing, the uncompressed and BC1-BC3
readers and writers and the block encoder, with its own pixel layout
and error types and rayon behind a `parallel` feature. It parses the
header first (Texture::parse) so a caller can check the size against
its limits before anything is allocated.
craft-image-codecs reads and writes DDS through it, re-exports its
DdsCompression and DdsOptions and maps its errors onto CodecError with
the same messages, so its API and output stay the same. Apps that only
need DDS can depend on craft-dds without the other codecs and their
licences.
Digests of uncompressed, BC1, BC2 and BC3 textures, with and without
mip chains, from deterministic odd-sized pictures (ramps, noise, flat
tiles, alpha at 0, 255 and in between) in RGBA, RGB, gray with alpha
and gray, and of decoding those files and hand-built ones in the other
stored layouts. The table is filled from the unchanged code; on a
mismatch the test prints every digest it computed.
The package layer of DeckCraft's native format, moved from storytold/deckcraft
crates/format at 0d5c0b85 (lib.rs, finite.rs): the mimetype and legacy
SlideCraft type, sniffing, the presentation.json envelope (generic over the
app's presentation), the NaN-safe JSON writer (Finite), the reader that patches
null numbers in older files, member names and compression choice, and the
bounded, budget-charged member reads with the format's limits.
The presentation model, repair, media and chart-part mapping, and outline/RTF
stay in DeckCraft. Writes go through craft-zip's deterministic writer; the
consumer's golden test shows the package bytes are unchanged.
Part of #778.
* image-codecs: decode AVIF pixels with craft-video's pure-Rust AV1 decoder
New optional `avif-decode` feature (native targets) reads still AVIF
files: the HEIF/ISOBMFF item graph, grids, clap/irot/imir, alpha
auxiliary images (including premultiplied), 8/10/12-bit 4:0:0, 4:2:0,
4:2:2 and 4:4:4, nclx/ICC colour, Exif and XMP, and PQ/HLG to linear
F32 through cicp::linearize as the HEIF path does.
The container walk follows LightCraft #3017 by @emmertex. Every size is
checked against the caller's Limits before the AV1 decoder runs, the
decoder's memory budget is capped by max_alloc, and the decode is
wrapped in catch_unwind so a decoder panic becomes an error.
Fixtures are tiny ffmpeg/libaom files; the 4:2:0 planes match libdav1d
bit for bit. Adds a decode_avif fuzz target.
Part of storytold/craft-libs#778.
* image-codecs, video: address review on the AVIF decoder
- clap: width and height are unsigned fractions, the offsets have signed
numerators, so 0x80000000/0x40000000 is a width of 2, not -2.
- An item with clap, irot or imir more than once (repeated ipma records)
is refused before any canvas work, instead of rotating 261120 times.
- Matrix coefficients 10 (BT.2020 constant luminance) is refused rather
than converted with the non-constant-luminance equations.
- An alpha plane whose own transforms differ from the colour's is refused
rather than composed in the wrong place; none, or the colour's, still
decode.
- craft-video: Decoder::set_shown_budget lowers the per-chunk byte cap on
shown pictures (never above 1 GiB), and the AVIF decoder sets it to
max_alloc, so a payload of many shown pictures is refused before they
are built.
* audio: pure-Rust Vorbis encoder, and an Ogg page writer in craft-media
Replace the libvorbis wrapper (vorbis_rs, C, desktop only) behind
`vorbis-encode` with FilmCraft's clean-room Vorbis I encoder by
@JordyUSA (storytold/filmcraft#4481), and move its Ogg page writer into
craft-media's `ogg` module.
craft-audio:
- `vorbis::encoder::{Encoder, EncoderConfig, Error}`: 1-8 channels in
Vorbis order, any sample rate, quality -1 to 10 (VBR), streaming
packets with granule positions.
- `encode_ogg_vorbis` with `OggVorbisOptions` (quality, vendor, tags,
serial) writes a whole Ogg Vorbis file with a comment header.
- `encode_ogg(buf, kbps)` and `OGG_BITRATES` keep working: the bit rate
picks the quality whose nominal rate it is (`quality_for_bitrate`).
- `encode` with `EncodeFormat::Ogg` takes 1-8 channel WAV-order layouts
and writes them in Vorbis order, and `RateControl::Quality`.
- Ogg is built on wasm32 too.
- Residue partitions hold whole sample frames (48, 40, 48 or 56 values
for 3, 5, 6 and 7 channels): libvorbis decodes each partition from
channel 0, so 32-value partitions came out scrambled for those counts.
- The first audio packet gets a page of its own, so a short file's
first audio page is never also its last (ffmpeg then kept the padding).
craft-media: `ogg::PageWriter`, `opus_tags`, `vorbis_comment`.
Part of storytold/craft-libs#778.
* audio, media: address review on the Vorbis encoder and Ogg writer
- Encoder: read cursor into the pending input, compacted once per call,
so a large encode() call no longer moves the tail on every block.
- Tests: check ffmpeg's libvorbis decoder only when ffmpeg has it.
- PageWriter::finish: the end granule replaces the last page's only when
a packet completes on it (RFC 7845 4.4); documented and tested.
- README: Ogg Opus packet granules are the samples decoded so far.
* audio: pick Ogg by extension on wasm32 too
The Vorbis encoder is pure Rust now, so encode_format_for("ogg") follows
the vorbis-encode feature alone, as EncodeFormat::Ogg.is_built() and
ENCODE_EXTENSIONS already do.
Extract framing from PhotoCraft 16941f7198da9ae1811a8928f4c256b5cb37c1cb, retaining the overflow protection added by 3b45e8baee7117e53847523b5bc3ae2b337966d4. Allocation-free adaptation leaves text policy with callers.
Co-authored-by: Valentin Klein <vangel1976@googlemail.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
Source: storytold/texturecraft bdbb52c9b66b221a55b370105b42f485a76e6fc7. Preserve chunk framing and output cap policy, with fallible allocation and checked offsets.
Port raw framing from PhotoCraft f7f8fdcd89 and 9a390661b5; preserve tolerant import semantics and keep colour policy with consumers.
Co-authored-by: Khawar Zamman Wani <wanikhawar@gmail.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
Extract the TextureCraft writer originally introduced in 59f0ab48508e2dc5a812acd1aee00d5d59a528d8, retaining caller colour and timestamp policy. Preserve the is_multiple_of cleanup from 59a3018.
Co-authored-by: bflatastic <bflat@storyteller.ai>