Commit Graph
35 Commits
Author SHA1 Message Date
dotCooCoo 0ca8b8e141 texture: check the HDR side limit in craft-hdr
Set craft_hdr::Limits::max_axis from Limits::max_side and drop the
separate resolution-line parser. A side over the limit is now
DecodeError::LimitExceeded ("axis length"), reported before any pixel
memory is allocated.
2026-11-28 02:33:21 -08:00
dotCooCoo ac39a088e7 Merge main into feat/craft-texture-decode 2026-11-28 01:39:11 -08:00
BFlat 28d8116033 Merge pull request #2833 from dotCooCoo/feat/texture-set-names
craft-texture: recognize texture sets and map roles from file names
2026-11-28 11:48:53 +07:00
dotCooCoo 9e157ea44c Merge main into feat/texture-set-names 2026-11-26 17:04:03 -08:00
dotCooCoo ba2f2a8eda image-codecs: bound TIFF compressed chunks by the allocation limit 2026-11-26 17:03:28 -08:00
dotCooCoo 405b1bec92 Merge main into feat/craft-texture-srgb-pair 2026-11-25 23:06:44 -08:00
dotCooCoo 3aa852b092 texture: say that 64-bit TIFF floats are narrowed to f32
The README and the decode module docs said float samples are kept as
stored. The TIFF codec narrows 64-bit float samples to f32, so both now
name that exception.
2026-11-25 20:55:04 -08:00
dotCooCoo 49beb72dbe Merge main into feat/texture-set-names 2026-11-25 19:52:41 -08:00
dotCooCoo 7ea59fff8b Merge main into feat/craft-texture-decode 2026-11-25 19:28:34 -08:00
dotCooCoo c0f1c226e3 craft-texture: sRGB tests check the standard only, under tests/it/
The comparisons with craft-cms, craft-mesh and craft-psd and their
dev-dependencies are removed. The tests of the pair against
IEC 61966-2-1 move to tests/it/srgb.rs, linked through tests/it/main.rs.
2026-11-25 19:25:15 -08:00
dotCooCoo 7fb92dd0b2 craft-texture: read a ._ prefix on the leaf only and keep rooted names apart
- A `._` prefix marks archive metadata only on the leaf, so a name inside
  a folder such as `._materials` is read; a `__MACOSX` folder is still
  ignored.
- A name directly under the root (`/brick_normal.png`) has the separator
  as its folder and no longer joins the set of a bare name.
- `normalgl` and `normaldx` in normal words next to the role words state a
  convention too, so `brick_normalgl_normaldx.png` is a conflict. Every
  word next to the role words that names the same role goes with them and
  is no longer in the stem, so `brick_normal_normaldx.png` and
  `brick_diffuse_color_albedo.png` join the set `brick`.
- `d3d` is a DirectX word only when its letters touch, so
  `panel_d_3_d_normal_gl.png` is an OpenGL normal map of `panel_d_3_d`.
- The docs say that finding a list over `max_names` takes one name past
  the limit from the iterator without reading it, and that duplicates
  share a role and a tile.
2026-11-21 05:33:13 -08:00
dotCooCoo 38374c295c craft-texture: pick the higher level just above a nearest-mip tie
MipChain::select added the half-level offset in f32, so an LOD one ULP above a tie (0.5 + 2^-24, or 1.5 + 2^-23) rounded back to the tie and selected the lower level. The offset is now added in f64, where it is exact for every f32 LOD.
2026-11-21 04:53:41 -08:00
dotCooCoo eb0518362b craft-texture: recognize texture sets and map roles from file names
texture_set::recognize groups a list of image file names into texture
sets by shared folder and stem, and gives each name its map role: base
color, normal (with the OpenGL or DirectX convention the name states),
roughness, metallic, ambient occlusion, height, emissive, opacity,
glossiness or packed ORM/ARM, and its UDIM tile. Words are matched at
the end or the start of the stem in any ASCII case, with any separator
or a case change between them; resolution, bit depth, convention and
tile words are left out of the stem.

Two names of one set with the same role and tile are both kept and
listed as duplicates. Unknown, unsupported, ambiguous, preview and
archive metadata names are returned with a reason.

The function reads names only: it opens no file and joins no path.
NameLimits caps the names (4096) and the bytes of each (1024), and a
list over either returns an error without reading further.

The README lists every accepted word with its role, and a test checks
the table against the code.
2026-11-21 04:52:23 -08:00
dotCooCoo ce361b210d craft-texture: add mip chains with footprint-based level choice
mip::MipChain builds every level below an image down to 1 x 1 with a
box filter in f64. Each side is halved and rounded down to at least 1,
as the Vulkan specification (section 12.4.4) and
ARB_texture_non_power_of_two size levels; on an odd side the last
texel averages the last three source texels. Channels, alpha included,
are averaged on their own as linear data.

lod() takes the screen-space derivatives of (u, v) and returns
log2 of the longer scaled footprint plus the sampler bias, clamped to
min_lod..=max_lod, as section 20.3.7 defines it. select() picks the
nearest level (a tie takes the lower-numbered level) or two levels and
their blend, and sample_grad() and sample_lod() read them with the
per-axis wrap modes and the magnification or minification texel filter
of section 20.6.3. MipMinFilter::from_gltf and TexelFilter::from_gltf
read the glTF 2.0 sampler codes. from_levels() takes levels made
elsewhere and checks their sizes and kinds.

Every level is checked against MipLimits::image and the bytes of all
levels against max_chain_bytes (default 1.5 GiB) before anything is
allocated; required_bytes() makes the same check for a size alone.
NaN or infinite derivatives, LODs, biases and bounds, and min_lod above
max_lod, return a MipError.
2026-11-21 04:38:47 -08:00
FredApps 2dc55f4341 test(texture): make preserved golden float type explicit (#2131) 2026-11-18 13:35:40 +07:00
dotCooCoo 8c9ff8a38c Merge main into feat/craft-texture-decode 2026-11-16 19:51:07 -08:00
dotCooCoo 9a6f11d0e2 Merge main into feat/craft-texture-srgb-pair 2026-11-16 19:36:57 -08:00
.CooCoo e36f7973da craft-texture: add height to normal and ORM packing over row-read sources (#1403) 2026-11-16 21:32:18 -05:00
dotCooCoo 750d4b49f4 texture: refuse every deep EXR part and read CR-only HDR header ends
`decode::exr` now refuses a file when any part is deep, not only when the
picked color part is, as its documentation says. A file with a flat RGB
part beside a deep part decoded before.

`hdr_size` now treats a line of carriage returns alone as the empty line
that ends a Radiance header, as `craft_hdr::decode` does. A header ending
in `\r\r\n` skipped the side check before the decoder ran.
2026-11-16 10:30:40 -08:00
dotCooCoo d87d22463b Merge main into feat/craft-texture-decode 2026-11-16 09:53:33 -08:00
FredApps a341e86b6d Merge pull request #1709 from dotCooCoo/feat/craft-texture-axis-sampling
craft-texture: add per-axis wrapping and MaterialCraft's stored sampling
2026-11-16 18:37:03 +01:00
dotCooCoo 259549fe93 craft-texture: sRGB tests fail on a difference that is not finite
worst() now asserts that each difference is finite and names the code it
is at. Before, a NaN difference never replaced the maximum, so a pair that
returned NaN at every code passed the tolerance checks. A new test checks
that worst() fails on a NaN difference.
2026-11-15 17:09:26 -08:00
dotCooCoo 88a7265c02 Merge main into feat/craft-texture-decode 2026-11-15 16:46:56 -08:00
dotCooCoo e2aa074106 Merge main into feat/craft-texture-srgb-pair 2026-11-15 16:45:41 -08:00
Dylan M. Taylor 8ef4542960 Fix DDS test fixture Header module path 2026-11-15 14:39:53 -05:00
Dylan M. Taylor 726ad0f829 Document DDS result fields and errors 2026-11-15 13:59:20 -05:00
Dylan M. Taylor 2797955187 Cover compressed half-float and first-face DDS behavior 2026-11-15 13:55:19 -05:00
chasse20 eeaa77c081 Share bounded DDS float surface decoding
Adapt MaterialCraft DDS backend integration from cc052aeaa8c61fbe6975674b6d5e28bb3c597b9d; retain float precision and first-surface behavior, keep transfer policy app-local.
2026-11-15 13:54:31 -05:00
dotCooCoo 92fb3fa8ac craft-texture: add per-axis wrapping and MaterialCraft's stored sampling
MaterialCraft's `crates/image` gained per-axis wrap modes and the texture
read of its function graphs. This adds them to craft-texture so the app
can switch to the crate.

- `get_axes`, `sample_axes` and `sample_nearest_axes` take
  `tiling: [bool; 2]`, the wrap mode of `u` and of `v` on their own. With
  equal entries they give the same results as `get`, `sample` and
  `sample_nearest`, which now call them.
- `sample_stored` rounds the bilinear weights to multiples of 1/256 and
  blends by linear interpolation in `f32`. With the image's
  integer-sampling flag on, it clamps each channel to 0..=1 and rounds it
  to a multiple of 1/65535. A channel whose interpolation is not finite
  is taken from the `f64` weighted sum, so finite texels give a finite
  sample.
- `with_integer_sampling` and `integer_sampling` set and read the flag.
  New images start with it off, clones keep it, and `PartialEq` compares
  it.
2026-11-15 10:27:00 -08:00
dotCooCoo a536024711 craft-texture: decode PNG, TIFF, Radiance HDR and OpenEXR into float planes
New optional features png, tiff, hdr and exr (decode enables all four) add
the decode module. decode::png and decode::tiff read through
craft-image-codecs at the stored sample depth, so 16-bit samples become
v / 65535 and keep all 65536 levels instead of passing through 8 bits.
decode::hdr reads through craft-hdr and decode::exr through craft-exr;
values above 1, negative values and OpenEXR NaN and infinities are kept.

Each result carries a transfer tag (Encoded, Linear or Unknown, from the
PNG cICP chunk, an ICC profile or the format) and an alpha tag (OpenEXR is
premultiplied, TIFF associated alpha is converted to straight). No
transfer function is applied.

The plane is checked against Limits before it is reserved, with one
fallible allocation. The format decoders get the same side, pixel and byte
limits; a Radiance HDR side over max_side is refused from the header, and
OpenEXR counts every declared channel toward max_bytes. A TIFF whose image
data ends early, CMYK and Lab TIFF, and OpenEXR files with a deep part are
errors. The decoding features build for wasm32-unknown-unknown.
2026-11-14 15:11:28 -08:00
dotCooCoo 3a710e4c62 craft-texture: tests check the sRGB pair against the standard, craft-cms, craft-mesh and craft-psd
The new tests in crates/texture/tests/srgb.rs compare linear_to_srgb and
srgb_to_linear with the IEC 61966-2-1 formulas at every 8-bit and 16-bit
code, check both thresholds (0.0031308 and 0.04045) and their neighbors,
round trips, and that the outputs do not decrease over the code grids.
They pin the behavior outside [0, 1]: negative values stay on the linear
segment, values above 1 follow the power segment, infinities keep their
sign and NaN stays NaN.

craft-mesh's pair and craft-psd's float::srgb_encode must match bit for
bit, and craft-cms's srgb_trc() curve within 2.4e-7. craft-cms,
craft-mesh and craft-psd are dev-dependencies of craft-texture.
2026-11-14 13:41:12 -08:00
dotCooCoo 47baffee9d craft-texture: compare images by value whether or not the buffer is shared
Image equality no longer short-cuts on a shared buffer. An image holding
NaN compared equal to its clone but unequal to the same image built
again; it is now unequal to both, as f32 comparison gives.
2026-11-13 19:55:39 -08:00
dotCooCoo 316db97052 craft-texture: keep bilinear samples of finite texels finite
The four weighted texels are summed in f64 and a finite sum is clamped
to the f32 range. Rounded weights can add up to slightly more than 1,
which made a constant image of f32::MAX sample to infinity at some
coordinates. Infinite texels still give an infinite or NaN sample.

The crate docs and README now limit the OutOfMemory guarantee of the
try_ forms to the pixel buffer, and name the Arc and the try_resize
resampler as allocations that are not fallible.
2026-11-13 19:52:40 -08:00
dotCooCoo 261e7a4c5c craft-texture: keep image planes within isize::MAX bytes when limits are raised
With raised Limits, a gray image over 512 MiB could be converted to
color on wasm32, where the color plane needs more than isize::MAX bytes
and vec! panics with capacity overflow.

- Limits::check returns TooLarge when the byte count is over isize::MAX,
  so the try_ forms report the size instead of OutOfMemory.
- map, to_color and to_kind clamp each side to 1..=MAX_SIDE when the
  result would be over isize::MAX bytes, and map the top-left part.
- The size checks are pure functions that take the bound as a value, and
  three tests check them against the 32-bit bound without allocating.
2026-11-13 13:28:35 -08:00
dotCooCoo 3c3a83151d craft-texture: add bounded float image planes and texture sampling
Adds crates/texture (craft-texture), the first step of RFC-0032
(storytold/craft-contrib#50). The code comes from MaterialCraft
crates/image/src/lib.rs at 31330629, with its six tests unchanged. No app
uses the crate yet.

Changes from the source:
- Image fields are private; from_data checks the size and the buffer
  length, so a zero side can no longer reach a panic and a short buffer
  is rejected instead of read with defaults.
- Limits caps the side, pixels and bytes; the try_ constructors and
  try_map, try_to_kind, try_resize and try_to_rgba8_display reserve
  memory first and return an error.
- Repeat sampling reduces the coordinate to its fractional part, so the
  period holds at large coordinates.
- Bilinear sampling sums the four weighted texels and skips zero weights;
  box shrinking sums in f64.
- generate_uv clamps the size before computing pixel centers.
- linear_to_srgb(NaN) returns NaN.
- rayon is behind the parallel feature.
2026-11-13 13:14:55 -08:00