mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 20:03:11 +00:00
Merge storytold main into next (17 Nov sync)
storytold main 83cb1133dd (291 commits) into the integration head bab1a99b85; 47 conflicted files.
- Domain test files (metafile, prepress, pdf plates, settings store, heif, media-testkit, atomic): tests next cut stay cut; tests new on main are kept, as trials where the crate's test target runs trials.
- atomic: main's group-bits test and Faulty::set_group go to src/tests.rs. audio: main's GSM and SBC oracles join tests/main.rs. cms constructors, pdf knockout_backdrop and testing_pdf join their crates' one test binary; timeline's preflight tests become src/preflight_tests.rs trials.
- update: main's changes to detect, install (linux, macos) and the tests land in next's split modules. The app's own offer is inspected on a thread of its own, picked up by tick's polling; settle_for_tests settles offers too. Later on a ready update drops the close it asked for. updater_pin_tests.rs stays deleted; its new pin test is in tests/it/update.rs.
- craft-color: main added a different crate at crates/color (the colour tags of compositor and display frames); it is next's craft-color module `tags`, re-exported at the root.
- Old crates/ui (combo, docking, testing, README) and keymap's ui/view.rs stay deleted; main's new crates/ui/src/testing files are dropped with them.
- New crates in the craft facade: ai, control, dds, frame, ipc, media-source, palette, press-print, score, ssip. testkit and xtask are listed outside it.
- Cargo.lock: the union of both locks, resolved by cargo metadata. Workflow: main's nextest Windows leg, with next's --keep-going clippy.
This commit is contained in:
@@ -24,6 +24,7 @@ heif = ["dep:craft-heif"]
|
||||
avif-decode = ["dep:craft-video", "craft-video/av1-decode"]
|
||||
|
||||
[dependencies]
|
||||
craft-dds = { workspace = true }
|
||||
crc32fast = "1.5"
|
||||
thiserror = { workspace = true }
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "tiff", "gif", "bmp", "tga", "ico", "qoi", "hdr"] }
|
||||
@@ -48,6 +49,8 @@ avif-serialize = { version = "0.8", optional = true }
|
||||
hayro-jpeg2000 = { version = "=0.3.5", default-features = false, features = ["std", "simd"] }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
# DDS encodes rows of blocks on several threads, as the other parallel codecs here do on native targets.
|
||||
craft-dds = { workspace = true, features = ["parallel"] }
|
||||
rayon = { workspace = true }
|
||||
craft-video = { workspace = true, optional = true }
|
||||
exr = { version = "1.73", default-features = false, features = ["rayon"] }
|
||||
|
||||
@@ -46,7 +46,7 @@ craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "<
|
||||
| BMP | yes | yes | U8 | RGB, RGBA | yes | no | no | no | yes (header pixels per metre) | no | no | `image` |
|
||||
| TGA | yes | yes | U8 | Gray, GrayA, RGB, RGBA | yes | no | no | no | no | no | no | `image` (read) / built in (RLE write, one scanline per packet) |
|
||||
| ICO | yes | yes | U8 | RGBA (at most 256×256) | yes | no | no | no | no | no | no | `image` |
|
||||
| DDS | yes | yes | U8 | Gray, GrayA, RGB, RGBA | yes | no | no | no | no | no | yes (BC1–BC3, when `EncodeOptions::dds` asks for one) | built in |
|
||||
| DDS | yes | yes | U8 | Gray, GrayA, RGB, RGBA | yes | no | no | no | no | no | yes (BC1–BC5, when `EncodeOptions::dds` asks for one) | [`craft-dds`](../dds/README.md) |
|
||||
| Netpbm (PBM/PGM/PPM/PAM/PFM) | yes | yes | U8, U16, F32 (float: PFM gray/RGB only) | all six (PAM `CMYK`/`CMYK_ALPHA`) | yes (PAM) | no | no | no | no | no | no | built in |
|
||||
| QOI | yes | yes | U8 | RGB, RGBA | yes | no | no | no | no | no | no | `image` |
|
||||
| OpenEXR | yes | yes | F16, F32 | Y, YA, RGB, RGBA | yes | no | no | no | no | no | no | `exr` |
|
||||
@@ -95,20 +95,29 @@ embedded table (and a PNG's transparent entry) so `photocraft-io` can open them
|
||||
Reading remains in the separate #2868 PR. The `ASYMMETRIC_EXCEPTIONS`
|
||||
entry stays until import is merged.
|
||||
|
||||
* **DDS.** The top mip level of a 2D texture: uncompressed pixels described by channel masks
|
||||
(8, 16, 24 or 32 bits, RGB or luminance, with or without alpha) or BC1/BC2/BC3 (DXT1/DXT3/DXT5),
|
||||
with the legacy header or the DX10 one. Uncompressed row padding follows the header's
|
||||
`DDSD_PITCH` stride; without that flag, rows are tightly packed. Everything opens as U8; the
|
||||
other mip levels are ignored. Cubemaps, texture arrays, volume textures, premultiplied DXT2/DXT4 and other formats
|
||||
(BC4–BC7, float) are refused with `CodecError::Unsupported`. Writing (`EncodeOptions::dds`) makes
|
||||
a 2D texture with the legacy header: uncompressed by default (BGRA, BGRX, or luminance with or
|
||||
without alpha, so it reads back exactly), or BC1/BC2/BC3. The block encoder is our own, from
|
||||
* **DDS** (through [`craft-dds`](../dds/README.md), whose `DdsCompression` and `DdsOptions` are
|
||||
re-exported). The top mip level of a 2D texture: uncompressed pixels described by channel masks
|
||||
(8, 16, 24 or 32 bits, RGB or luminance, with or without alpha), BC1/BC2/BC3 (DXT1/DXT3/DXT5) or
|
||||
unsigned BC4/BC5 (ATI1/ATI2, BC4U/BC5U, DXGI 79, 80, 82 and 83), with the legacy header or the
|
||||
DX10 one. BC4 opens as Gray and BC5 as RGB with blue 0 (BC5 stores only red and green; a normal
|
||||
map's Z is not reconstructed). ATI2 is read as Microsoft reads it, red in the first block.
|
||||
Uncompressed row padding follows the header's `DDSD_PITCH` stride; without that flag, rows are
|
||||
tightly packed. Everything opens as U8; the other mip levels are ignored. Cubemaps, texture
|
||||
arrays, volume textures, premultiplied-alpha textures (DXT2/DXT4, or DX10 alpha mode 2), signed (SNORM) BC4/BC5 and other formats
|
||||
(BC6H, BC7, float) are refused with `CodecError::Unsupported`. Writing (`EncodeOptions::dds`)
|
||||
makes a 2D texture: uncompressed by default (BGRA, BGRX, or luminance with or without alpha, so
|
||||
it reads back exactly), BC1/BC2/BC3 (from RGBA) with the legacy header, or BC4 (from gray, for
|
||||
roughness, height and other single-channel maps) and BC5 (from RGB, blue dropped, for normal
|
||||
maps) with the DX10 header (`BC4_UNORM`, `BC5_UNORM`). The plan converts other layouts to what
|
||||
the compression stores, so `fidelity_warnings` reports colour to gray for BC4 and dropped alpha
|
||||
for both; BC5's dropped blue comes under `LossyCompression`. The block encoder is our own, from
|
||||
Microsoft's public block-compression documentation: RGB565 endpoints fitted along each block's
|
||||
principal axis and refined by least squares, indices picked against the palette the reader
|
||||
decodes; BC1 turns texels under half opacity into its transparent black, and BC3 picks
|
||||
whichever alpha mode fits. `mipmaps` adds the full chain down to 1×1, each level a box filter
|
||||
of the one above (the last column and row of an odd-sized level average three pixels, so none
|
||||
is dropped). Cubemaps, arrays, BC4–BC7 and sRGB (DX10-only) formats aren't written.
|
||||
decodes; BC1 turns texels under half opacity into its transparent black, and BC3, BC4 and BC5
|
||||
pick whichever mode of their value blocks fits. `mipmaps` adds the full chain down to 1×1, each
|
||||
level a box filter of the one above (the last column and row of an odd-sized level average
|
||||
three pixels, so none is dropped). Cubemaps, arrays, BC6H, BC7 and sRGB (DX10-only) formats
|
||||
aren't written.
|
||||
|
||||
* **FITS.** The image in the primary HDU, or the first `IMAGE` extension, is read; `NAXIS3 = 3`
|
||||
opens as RGB and any other plane count opens the first plane with `DecodeWarning::MorePages`.
|
||||
@@ -344,8 +353,16 @@ Rec. 2020 RGB as 16-bit BT.2100 PQ, with measured content-light levels and the r
|
||||
* Adam7 PNG against progressive PNG and against the `image` crate as an oracle;
|
||||
* limit enforcement.
|
||||
|
||||
If `corpus/pngsuite/*.png` exists at the repo root, every file in it is compared against the
|
||||
`image` crate's decoder. Without it, that test is skipped.
|
||||
With the `corpus` feature, the PngSuite tests read `corpus/pngsuite/` at the repo root. They
|
||||
take the PNGs that `tests/it/common/pngsuite.tsv` lists (one `sha256<TAB>name` row per file),
|
||||
check each file's SHA-256 before decoding it, and compare it against the `image` crate's
|
||||
decoder. A listed PNG that is missing or changed fails the tests; a file the list does not name is
|
||||
not read. To fill the folder, download
|
||||
[PngSuite-2017jul19.tgz](http://www.schaik.com/pngsuite/PngSuite-2017jul19.tgz) from the
|
||||
[PngSuite page](http://www.schaik.com/pngsuite/), check that its SHA-256 is
|
||||
`0294b244c95a8342c01b00010cf34abdcabc7c6a34fd0fe1bd963917537bfdc8`, and extract it into
|
||||
`corpus/pngsuite/`. No PngSuite file is committed here; the list links the suite's
|
||||
[terms](http://www.schaik.com/pngsuite/PngSuite.LICENSE).
|
||||
|
||||
With the `corpus` feature, the deep EXR test reads `11.deep.exr`, `42.deep.exr`, `64.deep.exr`,
|
||||
`multivariate.deep.exr` and `objectid.deep.exr` from `corpus/exr/` at the repo root. These are the
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
//! Header-only BMP dimensions and pixel-data coverage, without allocating a canvas.
|
||||
|
||||
/// Recognize a BMP file header with a supported DIB header kind.
|
||||
///
|
||||
/// This is a format-routing check, not full validation: dimensions and pixel data may still
|
||||
/// be invalid. Unlike the broad signature detector, it requires the minimum 26-byte core
|
||||
/// header and a known DIB size, preserving callers that reject arbitrary `BM` prefixes.
|
||||
pub fn is_supported_header(b: &[u8]) -> bool {
|
||||
if b.len() >= 26 && b.starts_with(b"BM") {
|
||||
let dib = u32::from_le_bytes([b[14], b[15], b[16], b[17]]);
|
||||
return matches!(dib, 12 | 16 | 40 | 52 | 56 | 64 | 108 | 124);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Coverage of the declared pixel array. Row byte counts include row padding; RLE coverage
|
||||
/// counts the pixels drawn by commands and may be smaller than the canvas.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -142,4 +155,23 @@ mod tests {
|
||||
let nibble = bmp(2, &[0, 3, 0x12, 0x30, 0, 1]);
|
||||
assert_eq!(coverage(&nibble, 4, 2).pixels, 3);
|
||||
}
|
||||
#[test]
|
||||
fn supported_header_recognition_preserves_length_signature_and_dib_rules() {
|
||||
let mut b = [0_u8; 26];
|
||||
b[..2].copy_from_slice(b"BM");
|
||||
for dib in [12_u32, 16, 40, 52, 56, 64, 108, 124] {
|
||||
b[14..18].copy_from_slice(&dib.to_le_bytes());
|
||||
assert!(is_supported_header(&b), "DIB {dib}");
|
||||
for n in 0..26 {
|
||||
assert!(!is_supported_header(&b[..n]), "prefix {n}");
|
||||
}
|
||||
}
|
||||
for dib in [0_u32, 13, 39, 41, 125, u32::MAX] {
|
||||
b[14..18].copy_from_slice(&dib.to_le_bytes());
|
||||
assert!(!is_supported_header(&b), "DIB {dib}");
|
||||
}
|
||||
b[14..18].copy_from_slice(&40_u32.to_le_bytes());
|
||||
b[0] = b'X';
|
||||
assert!(!is_supported_header(&b));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ pub(crate) mod avif;
|
||||
pub(crate) mod avif_decode;
|
||||
pub(crate) mod bmp;
|
||||
pub(crate) mod dds;
|
||||
pub(crate) mod dds_bc;
|
||||
pub(crate) mod deep_exr;
|
||||
pub(crate) mod dicom;
|
||||
pub(crate) mod dpx;
|
||||
|
||||
@@ -1,557 +1,60 @@
|
||||
//! DirectDraw Surface (DDS) textures, after Microsoft's public DDS documentation ("DDS",
|
||||
//! "DDS_HEADER", "DDS_PIXELFORMAT", "DDS_HEADER_DXT10").
|
||||
//!
|
||||
//! Reading: the top mip level of a 2D texture, either uncompressed (8 to 32 bits per pixel
|
||||
//! described by channel masks, RGB or luminance) or block-compressed BC1/BC2/BC3
|
||||
//! (DXT1/DXT3/DXT5), with or without the DX10 header. Cubemaps, texture arrays and volume
|
||||
//! textures are refused rather than flattened to one face or slice.
|
||||
//!
|
||||
//! Writing: a 2D texture, uncompressed (BGRA or BGRX, luminance with or without alpha) or
|
||||
//! BC1/BC2/BC3, optionally with its full mip chain. The legacy header describes all of these,
|
||||
//! so no DX10 header is written; formats only DXGI can name (BC4–BC7, sRGB) aren't written.
|
||||
//! DirectDraw Surface (DDS) textures through [`craft_dds`]: its errors and pixel layouts mapped
|
||||
//! onto this crate's, and the decoder's size checked against [`Limits`] before it allocates.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::dds_bc::{self, Block, Mask};
|
||||
use crate::SampleType;
|
||||
use crate::error::CodecError;
|
||||
use crate::fidelity::Plan;
|
||||
use crate::format::Format;
|
||||
use crate::image::{ChannelLayout, Image};
|
||||
use crate::options::{DdsCompression, EncodeOptions, Limits};
|
||||
use crate::options::{EncodeOptions, Limits};
|
||||
use craft_dds::{DdsError, Layout, Texture};
|
||||
|
||||
/// `DDS ` plus the 124-byte DDS_HEADER.
|
||||
const HEADER: usize = 128;
|
||||
/// DDS_HEADER_DXT10, present when the FourCC is `DX10`.
|
||||
const DX10_HEADER: usize = 20;
|
||||
|
||||
const DDSD_DEPTH: u32 = 0x80_0000;
|
||||
const DDPF_ALPHAPIXELS: u32 = 0x1;
|
||||
const DDPF_FOURCC: u32 = 0x4;
|
||||
const DDPF_RGB: u32 = 0x40;
|
||||
const DDPF_LUMINANCE: u32 = 0x2_0000;
|
||||
const DDSCAPS2_CUBEMAP: u32 = 0x200;
|
||||
const DDSCAPS2_CUBEMAP_FACES: u32 = 0xfc00;
|
||||
const DDSCAPS2_VOLUME: u32 = 0x20_0000;
|
||||
const DIMENSION_TEXTURE2D: u32 = 3;
|
||||
const MISC_TEXTURECUBE: u32 = 0x4;
|
||||
|
||||
fn bad(reason: impl std::fmt::Display) -> CodecError {
|
||||
CodecError::malformed(Format::Dds, reason)
|
||||
fn error(e: DdsError) -> CodecError {
|
||||
match e {
|
||||
DdsError::Malformed(reason) => CodecError::malformed(Format::Dds, reason),
|
||||
DdsError::Unsupported(reason) => CodecError::unsupported(Format::Dds, reason),
|
||||
DdsError::Encode(reason) => CodecError::encode(Format::Dds, reason),
|
||||
DdsError::Alloc(len) => CodecError::LimitExceeded(format!("cannot allocate {len} elements for the image")),
|
||||
DdsError::LimitExceeded { required, limit } => {
|
||||
CodecError::LimitExceeded(format!("decoded texture requires {required} bytes, exceeding limit {limit}"))
|
||||
}
|
||||
other => CodecError::malformed(Format::Dds, other),
|
||||
}
|
||||
}
|
||||
fn unsupported(reason: impl Into<String>) -> CodecError {
|
||||
CodecError::unsupported(Format::Dds, reason)
|
||||
}
|
||||
fn le32(b: &[u8], at: usize) -> Result<u32, CodecError> {
|
||||
let bytes = b.get(at..at + 4).and_then(|s| <[u8; 4]>::try_from(s).ok()).ok_or_else(|| bad("truncated header"))?;
|
||||
Ok(u32::from_le_bytes(bytes))
|
||||
|
||||
pub(crate) fn channel_layout(layout: Layout) -> ChannelLayout {
|
||||
match layout {
|
||||
Layout::Gray => ChannelLayout::Gray,
|
||||
Layout::GrayA => ChannelLayout::GrayA,
|
||||
Layout::Rgb => ChannelLayout::Rgb,
|
||||
Layout::Rgba => ChannelLayout::Rgba,
|
||||
}
|
||||
}
|
||||
|
||||
/// Header-declared extra subresources cannot survive a single-image rewrite, even without presence flags.
|
||||
pub(crate) fn has_additional_images(bytes: &[u8]) -> Result<bool, CodecError> {
|
||||
let depth = le32(bytes, 24)?;
|
||||
let mips = le32(bytes, 28)?;
|
||||
let faces = (le32(bytes, 112)? & DDSCAPS2_CUBEMAP_FACES).count_ones();
|
||||
let dx10 = le32(bytes, 80)? & DDPF_FOURCC != 0 && bytes.get(84..88) == Some(b"DX10");
|
||||
let (cube, array) = if dx10 { (le32(bytes, 136)? & MISC_TEXTURECUBE != 0, le32(bytes, 140)?) } else { (false, 0) };
|
||||
Ok(depth > 1 || mips > 1 || faces > 1 || cube || array > 1)
|
||||
}
|
||||
|
||||
/// A FourCC as text when it is printable, else as the number legacy writers store there.
|
||||
fn fourcc_name(fourcc: u32) -> String {
|
||||
let bytes = fourcc.to_le_bytes();
|
||||
if bytes.iter().all(|c| c.is_ascii_graphic() || *c == b' ') { bytes.iter().map(|&c| char::from(c)).collect() } else { fourcc.to_string() }
|
||||
}
|
||||
|
||||
/// One channel of an uncompressed pixel: where it sits and its largest value.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Field {
|
||||
shift: u32,
|
||||
max: u32,
|
||||
}
|
||||
|
||||
impl Field {
|
||||
/// `None` for an empty mask; an error for one with gaps or wider than the pixel.
|
||||
fn new(mask: u32, bits: u32) -> Result<Option<Field>, CodecError> {
|
||||
if mask == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
let shift = mask.trailing_zeros();
|
||||
let max = mask >> shift;
|
||||
if max & max.wrapping_add(1) != 0 || (bits < 32 && mask >> bits != 0) {
|
||||
return Err(bad(format!("channel mask {mask:#x} is not a contiguous field of a {bits}-bit pixel")));
|
||||
}
|
||||
Ok(Some(Field { shift, max }))
|
||||
}
|
||||
|
||||
fn get(self, pixel: u32) -> u8 {
|
||||
let v = u64::from((pixel >> self.shift) & self.max);
|
||||
let max = u64::from(self.max);
|
||||
((v * 255 + max / 2) / max) as u8
|
||||
}
|
||||
}
|
||||
|
||||
enum Encoding {
|
||||
/// Uncompressed: bytes per pixel, then red (or luminance), green, blue and alpha.
|
||||
Masks {
|
||||
bytes: usize,
|
||||
gray: bool,
|
||||
fields: [Option<Field>; 4],
|
||||
},
|
||||
Bc1,
|
||||
Bc2,
|
||||
Bc3,
|
||||
}
|
||||
|
||||
impl Encoding {
|
||||
fn masks(bits: u32, masks: [u32; 4], gray: bool) -> Result<Encoding, CodecError> {
|
||||
if !matches!(bits, 8 | 16 | 24 | 32) {
|
||||
return Err(bad(format!("{bits} bits per pixel is not 8, 16, 24 or 32")));
|
||||
}
|
||||
let mut fields = [None; 4];
|
||||
for (field, mask) in fields.iter_mut().zip(masks) {
|
||||
*field = Field::new(mask, bits)?;
|
||||
}
|
||||
let colour = if gray { fields[0].is_some() } else { fields[..3].iter().any(Option::is_some) };
|
||||
if !colour {
|
||||
return Err(bad("the pixel format has no colour channel masks"));
|
||||
}
|
||||
Ok(Encoding::Masks { bytes: bits as usize / 8, gray, fields })
|
||||
}
|
||||
|
||||
fn layout(&self) -> ChannelLayout {
|
||||
match self {
|
||||
Encoding::Masks { gray: true, fields, .. } if fields[3].is_some() => ChannelLayout::GrayA,
|
||||
Encoding::Masks { gray: true, .. } => ChannelLayout::Gray,
|
||||
Encoding::Masks { fields, .. } if fields[3].is_none() => ChannelLayout::Rgb,
|
||||
_ => ChannelLayout::Rgba,
|
||||
}
|
||||
}
|
||||
|
||||
/// Stored row stride and byte size of the top mip level (block rows for BC).
|
||||
fn level_layout(&self, width: u32, height: u32, pitch: Option<u32>) -> Result<(usize, usize), CodecError> {
|
||||
let overflow = || bad("pixel data size overflow");
|
||||
let (w, h) = (usize::try_from(width).map_err(|_| overflow())?, usize::try_from(height).map_err(|_| overflow())?);
|
||||
let (row_bytes, rows) = match self {
|
||||
Encoding::Masks { bytes, .. } => {
|
||||
let packed = w.checked_mul(*bytes).ok_or_else(overflow)?;
|
||||
let row_bytes = match pitch {
|
||||
Some(pitch) => usize::try_from(pitch).map_err(|_| overflow())?,
|
||||
None => packed,
|
||||
};
|
||||
if row_bytes < packed {
|
||||
return Err(bad(format!("row pitch {row_bytes} is smaller than the {packed}-byte pixel row")));
|
||||
}
|
||||
(row_bytes, h)
|
||||
}
|
||||
Encoding::Bc1 | Encoding::Bc2 | Encoding::Bc3 => {
|
||||
let block = if matches!(self, Encoding::Bc1) { 8 } else { 16 };
|
||||
(w.div_ceil(4).checked_mul(block).ok_or_else(overflow)?, h.div_ceil(4))
|
||||
}
|
||||
};
|
||||
let size = row_bytes.checked_mul(rows).ok_or_else(overflow)?;
|
||||
Ok((row_bytes, size))
|
||||
}
|
||||
}
|
||||
|
||||
/// The legacy pixel format: a FourCC, or channel masks.
|
||||
fn legacy_encoding(b: &[u8]) -> Result<Encoding, CodecError> {
|
||||
let (flags, fourcc, bits) = (le32(b, 80)?, le32(b, 84)?, le32(b, 88)?);
|
||||
let alpha = if flags & DDPF_ALPHAPIXELS != 0 { le32(b, 104)? } else { 0 };
|
||||
if flags & DDPF_FOURCC != 0 {
|
||||
return match &fourcc.to_le_bytes() {
|
||||
b"DXT1" => Ok(Encoding::Bc1),
|
||||
b"DXT3" => Ok(Encoding::Bc2),
|
||||
b"DXT5" => Ok(Encoding::Bc3),
|
||||
b"DXT2" | b"DXT4" => Err(unsupported("premultiplied-alpha DXT2/DXT4 textures are not supported")),
|
||||
_ => Err(unsupported(format!("compression `{}` is not supported (DXT1, DXT3 and DXT5 are)", fourcc_name(fourcc)))),
|
||||
};
|
||||
}
|
||||
if flags & DDPF_RGB != 0 {
|
||||
return Encoding::masks(bits, [le32(b, 92)?, le32(b, 96)?, le32(b, 100)?, alpha], false);
|
||||
}
|
||||
if flags & DDPF_LUMINANCE != 0 {
|
||||
return Encoding::masks(bits, [le32(b, 92)?, 0, 0, alpha], true);
|
||||
}
|
||||
Err(unsupported(format!("pixel format flags {flags:#x} are not RGB, luminance or a supported compression")))
|
||||
}
|
||||
|
||||
/// The DX10 header's DXGI format, refusing anything but a single 2D texture.
|
||||
fn dx10_encoding(b: &[u8]) -> Result<Encoding, CodecError> {
|
||||
let (dxgi, dimension, misc, array) = (le32(b, HEADER)?, le32(b, HEADER + 4)?, le32(b, HEADER + 8)?, le32(b, HEADER + 12)?);
|
||||
if misc & MISC_TEXTURECUBE != 0 {
|
||||
return Err(unsupported("cubemaps are not supported"));
|
||||
}
|
||||
if dimension != DIMENSION_TEXTURE2D {
|
||||
return Err(unsupported(format!("only 2D textures are supported (resource dimension {dimension})")));
|
||||
}
|
||||
if array > 1 {
|
||||
return Err(unsupported(format!("texture arrays are not supported ({array} textures)")));
|
||||
}
|
||||
const RGBA: [u32; 4] = [0xff, 0xff00, 0xff_0000, 0xff00_0000];
|
||||
const BGRA: [u32; 4] = [0xff_0000, 0xff00, 0xff, 0xff00_0000];
|
||||
const BGRX: [u32; 4] = [0xff_0000, 0xff00, 0xff, 0];
|
||||
match dxgi {
|
||||
27..=29 => Encoding::masks(32, RGBA, false),
|
||||
87 | 90 | 91 => Encoding::masks(32, BGRA, false),
|
||||
88 | 92 | 93 => Encoding::masks(32, BGRX, false),
|
||||
70..=72 => Ok(Encoding::Bc1),
|
||||
73..=75 => Ok(Encoding::Bc2),
|
||||
76..=78 => Ok(Encoding::Bc3),
|
||||
_ => Err(unsupported(format!("DXGI format {dxgi} is not supported (BC1, BC2, BC3 and 8-bit RGBA or BGRA are)"))),
|
||||
}
|
||||
craft_dds::has_additional_images(bytes).map_err(error)
|
||||
}
|
||||
|
||||
pub(crate) fn decode(b: &[u8], limits: &Limits) -> Result<Image, CodecError> {
|
||||
if !b.starts_with(b"DDS ") {
|
||||
return Err(bad("missing the `DDS ` signature"));
|
||||
}
|
||||
if le32(b, 4)? != 124 {
|
||||
return Err(bad("header size is not 124"));
|
||||
}
|
||||
let (flags, height, width, depth, caps2) = (le32(b, 8)?, le32(b, 12)?, le32(b, 16)?, le32(b, 24)?, le32(b, 112)?);
|
||||
if caps2 & DDSCAPS2_CUBEMAP != 0 {
|
||||
return Err(unsupported("cubemaps are not supported"));
|
||||
}
|
||||
if caps2 & DDSCAPS2_VOLUME != 0 || (flags & DDSD_DEPTH != 0 && depth > 1) {
|
||||
return Err(unsupported("volume textures are not supported"));
|
||||
}
|
||||
let dx10 = le32(b, 80)? & DDPF_FOURCC != 0 && &le32(b, 84)?.to_le_bytes() == b"DX10";
|
||||
let (encoding, start) = if dx10 { (dx10_encoding(b)?, HEADER + DX10_HEADER) } else { (legacy_encoding(b)?, HEADER) };
|
||||
let layout = encoding.layout();
|
||||
limits.check(width, height, layout, SampleType::U8)?;
|
||||
// The same header field is a total level size for BC, but a row stride when DDSD_PITCH is set.
|
||||
let pitch = if flags & DDSD_PITCH != 0 { Some(le32(b, 20)?) } else { None };
|
||||
let (row_pitch, size) = encoding.level_layout(width, height, pitch)?;
|
||||
let data = b.get(start..).and_then(|d| d.get(..size)).ok_or_else(|| bad(format!("truncated pixel data: {size} bytes needed")))?;
|
||||
let (w, h) = (width as usize, height as usize);
|
||||
let channels = layout.channels();
|
||||
let row_size = w.checked_mul(channels).ok_or_else(|| bad("pixel size overflow"))?;
|
||||
let total = row_size.checked_mul(h).ok_or_else(|| bad("pixel size overflow"))?;
|
||||
let mut pixels = vec![0u8; total];
|
||||
match encoding {
|
||||
Encoding::Masks { bytes, gray, fields } => {
|
||||
for (src_row, dst_row) in data.chunks_exact(row_pitch).zip(pixels.chunks_exact_mut(row_size)) {
|
||||
// Stop at the output width, leaving any stored row padding unread.
|
||||
for (src, dst) in src_row.chunks_exact(bytes).zip(dst_row.chunks_exact_mut(channels)) {
|
||||
let pixel = src.iter().rev().fold(0u32, |v, &byte| v << 8 | u32::from(byte));
|
||||
let channel = |i: usize| fields[i].map_or(0, |f| f.get(pixel));
|
||||
let values = if gray { [channel(0), channel(3), 0, 0] } else { [channel(0), channel(1), channel(2), channel(3)] };
|
||||
dst.copy_from_slice(&values[..channels]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Encoding::Bc1 | Encoding::Bc2 | Encoding::Bc3 => {
|
||||
let block_size = if matches!(encoding, Encoding::Bc1) { 8 } else { 16 };
|
||||
let blocks_x = w.div_ceil(4);
|
||||
for (i, block) in data.chunks_exact(block_size).enumerate() {
|
||||
let texels = match encoding {
|
||||
Encoding::Bc1 => bc1(block, true),
|
||||
Encoding::Bc2 => with_alpha(bc1(block.get(8..).unwrap_or_default(), false), bc2_alpha(block)),
|
||||
_ => with_alpha(bc1(block.get(8..).unwrap_or_default(), false), bc3_alpha(block)),
|
||||
};
|
||||
let (bx, by) = ((i % blocks_x) * 4, (i / blocks_x) * 4);
|
||||
for (t, texel) in texels.iter().enumerate() {
|
||||
let (x, y) = (bx + t % 4, by + t / 4);
|
||||
if x < w && y < h {
|
||||
let at = (y * w + x) * 4;
|
||||
if let Some(dst) = pixels.get_mut(at..at + 4) {
|
||||
dst.copy_from_slice(texel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Image::from_u8(width, height, layout, pixels)
|
||||
}
|
||||
|
||||
/// A BC1 colour block. BC2 and BC3 colour blocks always have four colours; only BC1's
|
||||
/// `c0 <= c1` order selects three colours and transparent black.
|
||||
fn bc1(block: &[u8], one_bit_alpha: bool) -> [[u8; 4]; 16] {
|
||||
let byte = |i: usize| block.get(i).copied().unwrap_or(0);
|
||||
let (c0, c1) = (u16::from_le_bytes([byte(0), byte(1)]), u16::from_le_bytes([byte(2), byte(3)]));
|
||||
let palette = dds_bc::colour_palette(c0, c1, c0 > c1 || !one_bit_alpha);
|
||||
let indices = u32::from_le_bytes([byte(4), byte(5), byte(6), byte(7)]);
|
||||
std::array::from_fn(|t| palette[(indices >> (2 * t)) as usize & 3])
|
||||
}
|
||||
|
||||
/// BC2: four explicit bits of alpha per texel.
|
||||
fn bc2_alpha(block: &[u8]) -> [u8; 16] {
|
||||
let bits = u64::from_le_bytes(std::array::from_fn(|i| block.get(i).copied().unwrap_or(0)));
|
||||
std::array::from_fn(|t| ((bits >> (4 * t)) & 0xf) as u8 * 17)
|
||||
}
|
||||
|
||||
/// BC3: two alpha endpoints and a 3-bit index per texel into eight values, or into six plus
|
||||
/// 0 and 255 when `a0 <= a1`.
|
||||
fn bc3_alpha(block: &[u8]) -> [u8; 16] {
|
||||
let byte = |i: usize| block.get(i).copied().unwrap_or(0);
|
||||
let palette = dds_bc::alpha_palette(byte(0), byte(1));
|
||||
let bits = u64::from_le_bytes([byte(2), byte(3), byte(4), byte(5), byte(6), byte(7), 0, 0]);
|
||||
std::array::from_fn(|t| palette[((bits >> (3 * t)) & 7) as usize])
|
||||
}
|
||||
|
||||
fn with_alpha(mut texels: [[u8; 4]; 16], alpha: [u8; 16]) -> [[u8; 4]; 16] {
|
||||
for (texel, a) in texels.iter_mut().zip(alpha) {
|
||||
texel[3] = a;
|
||||
}
|
||||
texels
|
||||
}
|
||||
|
||||
const DDSD_CAPS: u32 = 0x1;
|
||||
const DDSD_HEIGHT: u32 = 0x2;
|
||||
const DDSD_WIDTH: u32 = 0x4;
|
||||
const DDSD_PITCH: u32 = 0x8;
|
||||
const DDSD_PIXELFORMAT: u32 = 0x1000;
|
||||
const DDSD_MIPMAPCOUNT: u32 = 0x2_0000;
|
||||
const DDSD_LINEARSIZE: u32 = 0x8_0000;
|
||||
const DDSCAPS_COMPLEX: u32 = 0x8;
|
||||
const DDSCAPS_TEXTURE: u32 = 0x1000;
|
||||
const DDSCAPS_MIPMAP: u32 = 0x40_0000;
|
||||
|
||||
fn encode_err(reason: impl std::fmt::Display) -> CodecError {
|
||||
CodecError::encode(Format::Dds, reason)
|
||||
}
|
||||
|
||||
/// How a written texture stores its pixels.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Store {
|
||||
/// 8-bit luminance.
|
||||
Luminance,
|
||||
/// 8-bit luminance, then 8-bit alpha.
|
||||
LuminanceAlpha,
|
||||
/// Blue, green, red and an unused byte (written as 255, so a reader that takes it for
|
||||
/// alpha still sees an opaque texture).
|
||||
Bgrx,
|
||||
Bgra,
|
||||
Bc1,
|
||||
Bc2,
|
||||
Bc3,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
/// The storage for an image of `layout`, as [`crate::fidelity::plan`] chose it.
|
||||
fn new(compression: DdsCompression, layout: ChannelLayout) -> Result<Store, CodecError> {
|
||||
Ok(match (compression, layout) {
|
||||
(DdsCompression::None, ChannelLayout::Gray) => Store::Luminance,
|
||||
(DdsCompression::None, ChannelLayout::GrayA) => Store::LuminanceAlpha,
|
||||
(DdsCompression::None, ChannelLayout::Rgb) => Store::Bgrx,
|
||||
(DdsCompression::None, ChannelLayout::Rgba) => Store::Bgra,
|
||||
(DdsCompression::Bc1, ChannelLayout::Rgba) => Store::Bc1,
|
||||
(DdsCompression::Bc2, ChannelLayout::Rgba) => Store::Bc2,
|
||||
(DdsCompression::Bc3, ChannelLayout::Rgba) => Store::Bc3,
|
||||
(_, layout) => return Err(encode_err(format!("{layout:?} pixels can't be written as `{}`", compression.name()))),
|
||||
})
|
||||
}
|
||||
|
||||
/// Bytes per pixel, or per 4×4 block for a block compression.
|
||||
fn unit(self) -> usize {
|
||||
match self {
|
||||
Store::Luminance => 1,
|
||||
Store::LuminanceAlpha => 2,
|
||||
Store::Bgrx | Store::Bgra => 4,
|
||||
Store::Bc1 => 8,
|
||||
Store::Bc2 | Store::Bc3 => 16,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_block(self) -> bool {
|
||||
matches!(self, Store::Bc1 | Store::Bc2 | Store::Bc3)
|
||||
}
|
||||
|
||||
/// Bytes of one row of pixels (or of 4×4 blocks) of a level `width` wide.
|
||||
fn row_bytes(self, width: usize) -> Option<usize> {
|
||||
if self.is_block() { width.div_ceil(4).checked_mul(self.unit()) } else { width.checked_mul(self.unit()) }
|
||||
}
|
||||
|
||||
fn level_bytes(self, width: usize, height: usize) -> Option<usize> {
|
||||
let rows = if self.is_block() { height.div_ceil(4) } else { height };
|
||||
self.row_bytes(width)?.checked_mul(rows)
|
||||
}
|
||||
|
||||
/// DDS_PIXELFORMAT: flags, FourCC, bits per pixel and the red, green, blue and alpha masks.
|
||||
fn pixel_format(self) -> (u32, [u8; 4], u32, [u32; 4]) {
|
||||
match self {
|
||||
Store::Luminance => (DDPF_LUMINANCE, [0; 4], 8, [0xff, 0, 0, 0]),
|
||||
Store::LuminanceAlpha => (DDPF_LUMINANCE | DDPF_ALPHAPIXELS, [0; 4], 16, [0xff, 0, 0, 0xff00]),
|
||||
Store::Bgrx => (DDPF_RGB, [0; 4], 32, [0xff_0000, 0xff00, 0xff, 0]),
|
||||
Store::Bgra => (DDPF_RGB | DDPF_ALPHAPIXELS, [0; 4], 32, [0xff_0000, 0xff00, 0xff, 0xff00_0000]),
|
||||
Store::Bc1 => (DDPF_FOURCC, *b"DXT1", 0, [0; 4]),
|
||||
Store::Bc2 => (DDPF_FOURCC, *b"DXT3", 0, [0; 4]),
|
||||
Store::Bc3 => (DDPF_FOURCC, *b"DXT5", 0, [0; 4]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Levels in a full mip chain: the larger side halves down to 1.
|
||||
fn mip_levels(width: u32, height: u32) -> u32 {
|
||||
32 - width.max(height).max(1).leading_zeros()
|
||||
}
|
||||
|
||||
fn half((w, h): (usize, usize)) -> (usize, usize) {
|
||||
((w / 2).max(1), (h / 2).max(1))
|
||||
let texture = Texture::parse(b).map_err(error)?;
|
||||
let layout = channel_layout(texture.layout());
|
||||
limits.check(texture.width(), texture.height(), layout, SampleType::U8)?;
|
||||
let pixels = texture.decode_with_limit(limits.max_alloc).map_err(error)?;
|
||||
Image::from_u8(texture.width(), texture.height(), layout, pixels)
|
||||
}
|
||||
|
||||
pub(crate) fn encode(image: &Image, plan: Plan, opts: &EncodeOptions) -> Result<Vec<u8>, CodecError> {
|
||||
let img = image.converted(plan.layout, SampleType::U8);
|
||||
let pixels = img.as_u8().ok_or_else(|| encode_err("the image was not converted to 8 bits per channel"))?;
|
||||
let store = Store::new(opts.dds.compression, img.layout())?;
|
||||
let (width, height) = img.dimensions();
|
||||
let levels = if opts.dds.mipmaps { mip_levels(width, height) } else { 1 };
|
||||
let top = (width as usize, height as usize);
|
||||
// Every level's size, checked before anything is allocated.
|
||||
let mut sizes = Vec::new();
|
||||
let mut size = top;
|
||||
for _ in 0..levels {
|
||||
sizes.push(store.level_bytes(size.0, size.1).ok_or_else(|| encode_err("texture size overflow"))?);
|
||||
size = half(size);
|
||||
}
|
||||
let total = sizes.iter().try_fold(HEADER, |total, &s| total.checked_add(s)).ok_or_else(|| encode_err("texture size overflow"))?;
|
||||
let header = header(width, height, store, levels, sizes.first().copied().unwrap_or(0))?;
|
||||
let mut out = crate::options::alloc_zeroed::<u8>(total)?;
|
||||
out.get_mut(..HEADER).ok_or_else(|| encode_err("output buffer too small"))?.copy_from_slice(&header);
|
||||
|
||||
let channels = img.layout().channels();
|
||||
let mut level = Cow::Borrowed(pixels);
|
||||
let (mut size, mut at) = (top, HEADER);
|
||||
for (i, &bytes) in sizes.iter().enumerate() {
|
||||
let dst = out.get_mut(at..at + bytes).ok_or_else(|| encode_err("output buffer too small"))?;
|
||||
write_level(store, &level, size, dst)?;
|
||||
at += bytes;
|
||||
if i + 1 < sizes.len() {
|
||||
let next = half(size);
|
||||
level = Cow::Owned(downsample(&level, size, next, channels)?);
|
||||
size = next;
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The `DDS ` signature and DDS_HEADER. `top` is the top level's size in bytes.
|
||||
fn header(width: u32, height: u32, store: Store, levels: u32, top: usize) -> Result<[u8; HEADER], CodecError> {
|
||||
let mut b = [0u8; HEADER];
|
||||
let mut put = |at: usize, v: u32| {
|
||||
if let Some(d) = b.get_mut(at..at + 4) {
|
||||
d.copy_from_slice(&v.to_le_bytes());
|
||||
}
|
||||
let pixels = img.as_u8().ok_or_else(|| CodecError::encode(Format::Dds, "the image was not converted to 8 bits per channel"))?;
|
||||
let layout = match img.layout() {
|
||||
ChannelLayout::Gray => Layout::Gray,
|
||||
ChannelLayout::GrayA => Layout::GrayA,
|
||||
ChannelLayout::Rgb => Layout::Rgb,
|
||||
ChannelLayout::Rgba => Layout::Rgba,
|
||||
// `fidelity::plan` only picks the four layouts above for DDS.
|
||||
other => return Err(CodecError::encode(Format::Dds, format!("{other:?} pixels can't be written as `{}`", opts.dds.compression.name()))),
|
||||
};
|
||||
// Uncompressed: the pitch of one row. Compressed: the whole top level (its "linear size").
|
||||
let (size_flag, pitch_or_size) = if store.is_block() { (DDSD_LINEARSIZE, Some(top)) } else { (DDSD_PITCH, store.row_bytes(width as usize)) };
|
||||
let pitch_or_size = pitch_or_size
|
||||
.and_then(|v| u32::try_from(v).ok())
|
||||
.ok_or_else(|| encode_err(format!("a {width}x{height} level is too large for a DDS header")))?;
|
||||
let mipmapped = levels > 1;
|
||||
put(4, 124);
|
||||
put(8, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | size_flag | if mipmapped { DDSD_MIPMAPCOUNT } else { 0 });
|
||||
put(12, height);
|
||||
put(16, width);
|
||||
put(20, pitch_or_size);
|
||||
put(28, levels);
|
||||
let (flags, fourcc, bits, masks) = store.pixel_format();
|
||||
put(76, 32);
|
||||
put(80, flags);
|
||||
put(84, u32::from_le_bytes(fourcc));
|
||||
put(88, bits);
|
||||
for (i, mask) in masks.into_iter().enumerate() {
|
||||
put(92 + 4 * i, mask);
|
||||
}
|
||||
put(108, DDSCAPS_TEXTURE | if mipmapped { DDSCAPS_COMPLEX | DDSCAPS_MIPMAP } else { 0 });
|
||||
b[..4].copy_from_slice(b"DDS ");
|
||||
Ok(b)
|
||||
}
|
||||
|
||||
/// Runs `f` on each `len`-byte row of `out` with its index, in parallel on native targets.
|
||||
fn rows(out: &mut [u8], len: usize, f: impl Fn(usize, &mut [u8]) + Send + Sync) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
use rayon::prelude::*;
|
||||
out.par_chunks_mut(len.max(1)).enumerate().for_each(|(i, row)| f(i, row));
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
for (i, row) in out.chunks_mut(len.max(1)).enumerate() {
|
||||
f(i, row);
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes one level of `width` × `height` pixels (in the image's layout) into `dst`.
|
||||
fn write_level(store: Store, pixels: &[u8], (width, height): (usize, usize), dst: &mut [u8]) -> Result<(), CodecError> {
|
||||
let row_bytes = store.row_bytes(width).ok_or_else(|| encode_err("texture size overflow"))?;
|
||||
match store {
|
||||
Store::Luminance | Store::LuminanceAlpha => {
|
||||
// The image's gray (and alpha) samples, in the same order.
|
||||
let src = pixels.get(..dst.len()).ok_or_else(|| encode_err("the level is smaller than its size"))?;
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
Store::Bgrx | Store::Bgra => {
|
||||
let channels = if store == Store::Bgra { 4 } else { 3 };
|
||||
rows(dst, row_bytes, |y, row| {
|
||||
let src = pixels.get(y * width * channels..).unwrap_or_default();
|
||||
for (d, s) in row.as_chunks_mut::<4>().0.iter_mut().zip(src.chunks_exact(channels)) {
|
||||
let byte = |i: usize| s.get(i).copied().unwrap_or(255);
|
||||
*d = [byte(2), byte(1), byte(0), byte(3)];
|
||||
}
|
||||
});
|
||||
}
|
||||
Store::Bc1 | Store::Bc2 | Store::Bc3 => {
|
||||
let (texels, _) = pixels.as_chunks::<4>();
|
||||
rows(dst, row_bytes, |by, row| {
|
||||
for (bx, d) in row.chunks_exact_mut(store.unit()).enumerate() {
|
||||
let (block, inside) = gather(texels, (width, height), bx, by);
|
||||
let encoded: &[u8] = match store {
|
||||
Store::Bc1 => &dds_bc::encode_bc1(&block, inside),
|
||||
Store::Bc2 => &dds_bc::encode_bc2(&block, inside),
|
||||
_ => &dds_bc::encode_bc3(&block, inside),
|
||||
};
|
||||
for (d, s) in d.iter_mut().zip(encoded) {
|
||||
*d = *s;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Block (`bx`, `by`)'s texels, and which of them lie inside the image.
|
||||
fn gather(texels: &[[u8; 4]], (width, height): (usize, usize), bx: usize, by: usize) -> (Block, Mask) {
|
||||
let mut block = [[0u8; 4]; 16];
|
||||
let mut inside: Mask = 0;
|
||||
for (t, texel) in block.iter_mut().enumerate() {
|
||||
let (x, y) = (bx * 4 + t % 4, by * 4 + t / 4);
|
||||
if x < width
|
||||
&& y < height
|
||||
&& let Some(p) = texels.get(y * width + x)
|
||||
{
|
||||
*texel = *p;
|
||||
inside |= 1 << t;
|
||||
}
|
||||
}
|
||||
(block, inside)
|
||||
}
|
||||
|
||||
/// The next mip level: each pixel the average of the 2×2 pixels it covers, or of 2×3, 3×2 or
|
||||
/// 3×3 along the last column and row of an odd-sized level, so no pixel is dropped.
|
||||
fn downsample(src: &[u8], (w, h): (usize, usize), (nw, nh): (usize, usize), channels: usize) -> Result<Vec<u8>, CodecError> {
|
||||
let len = nw.checked_mul(nh).and_then(|n| n.checked_mul(channels)).ok_or_else(|| encode_err("mip level size overflow"))?;
|
||||
let mut dst = crate::options::alloc_zeroed::<u8>(len)?;
|
||||
let span = |i: usize, n: usize, size: usize| 2 * i..=if i + 1 == n { size.saturating_sub(1) } else { 2 * i + 1 };
|
||||
rows(&mut dst, nw * channels, |y, row| {
|
||||
let ys = span(y, nh, h);
|
||||
for (x, px) in row.chunks_exact_mut(channels.max(1)).enumerate() {
|
||||
let xs = span(x, nw, w);
|
||||
for (c, v) in px.iter_mut().enumerate() {
|
||||
let (mut sum, mut n) = (0u32, 0u32);
|
||||
for sy in ys.clone() {
|
||||
for sx in xs.clone() {
|
||||
if let Some(&s) = src.get((sy * w + sx) * channels + c) {
|
||||
sum += u32::from(s);
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*v = ((sum + n / 2) / n.max(1)) as u8;
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(dst)
|
||||
let (width, height) = img.dimensions();
|
||||
craft_dds::encode(width, height, layout, pixels, opts.dds).map_err(error)
|
||||
}
|
||||
|
||||
@@ -1,369 +0,0 @@
|
||||
//! BC1, BC2 and BC3 (DXT1, DXT3, DXT5) blocks, after Microsoft's public block compression
|
||||
//! documentation ("Block Compression (Direct3D 10)" and "Texture Block Compression in Direct3D
|
||||
//! 11"): the palettes the DDS reader decodes with, and the block encoder the DDS writer uses.
|
||||
//!
|
||||
//! The encoder fits a block's colours with two RGB565 endpoints along their principal axis,
|
||||
//! refines them by least squares, and scores every candidate against the exact palette the
|
||||
//! reader rebuilds, so the indices it picks are the best ones for what a decoder shows.
|
||||
|
||||
/// The 16 texels of a 4×4 block, row by row, as RGBA.
|
||||
pub(crate) type Block = [[u8; 4]; 16];
|
||||
|
||||
/// Bit `t` set for each texel `t` of a block that counts: edge blocks of a texture whose size is
|
||||
/// not a multiple of four have texels outside the image.
|
||||
pub(crate) type Mask = u16;
|
||||
|
||||
pub(crate) fn rgb565(c: u16) -> [u8; 3] {
|
||||
let scale = |v: u16, max: u16| ((u32::from(v) * 255 + u32::from(max) / 2) / u32::from(max)) as u8;
|
||||
[scale(c >> 11, 31), scale((c >> 5) & 63, 63), scale(c & 31, 31)]
|
||||
}
|
||||
|
||||
/// The colours a colour block's indices select. Four-colour mode (BC1 with `c0 > c1`, and every
|
||||
/// BC2 and BC3 block) adds two colours at thirds; three-colour mode adds the midpoint and
|
||||
/// transparent black.
|
||||
pub(crate) fn colour_palette(c0: u16, c1: u16, four: bool) -> [[u8; 4]; 4] {
|
||||
let (a, b) = (rgb565(c0), rgb565(c1));
|
||||
let mix = |wa: u32, wb: u32| {
|
||||
let d = wa + wb;
|
||||
let at = |i: usize| ((wa * u32::from(a[i]) + wb * u32::from(b[i]) + d / 2) / d) as u8;
|
||||
[at(0), at(1), at(2), 255]
|
||||
};
|
||||
if four {
|
||||
[[a[0], a[1], a[2], 255], [b[0], b[1], b[2], 255], mix(2, 1), mix(1, 2)]
|
||||
} else {
|
||||
[[a[0], a[1], a[2], 255], [b[0], b[1], b[2], 255], mix(1, 1), [0; 4]]
|
||||
}
|
||||
}
|
||||
|
||||
/// A BC3 alpha block's eight values: six interpolated at sevenths when `a0 > a1`, else four
|
||||
/// interpolated at fifths followed by 0 and 255.
|
||||
pub(crate) fn alpha_palette(a0: u8, a1: u8) -> [u8; 8] {
|
||||
let (a0, a1) = (u32::from(a0), u32::from(a1));
|
||||
let mut palette = [a0, a1, 0, 0, 0, 0, 0, 255];
|
||||
if a0 > a1 {
|
||||
for (k, v) in palette.iter_mut().enumerate().skip(2) {
|
||||
let k = k as u32;
|
||||
*v = ((8 - k) * a0 + (k - 1) * a1 + 3) / 7;
|
||||
}
|
||||
} else {
|
||||
for (k, v) in palette.iter_mut().enumerate().take(6).skip(2) {
|
||||
let k = k as u32;
|
||||
*v = ((6 - k) * a0 + (k - 1) * a1 + 2) / 5;
|
||||
}
|
||||
}
|
||||
palette.map(|v| v as u8)
|
||||
}
|
||||
|
||||
/// A BC1 block. Texels under half opacity become BC1's transparent black, which needs the
|
||||
/// three-colour mode; an opaque block takes whichever mode fits its colours better.
|
||||
pub(crate) fn encode_bc1(block: &Block, inside: Mask) -> [u8; 8] {
|
||||
let transparent = select(block, inside, |t| t[3] < 128);
|
||||
colour_block(block, inside & !transparent, transparent, true)
|
||||
}
|
||||
|
||||
/// A BC2 block: four bits of alpha per texel, then a four-colour block.
|
||||
pub(crate) fn encode_bc2(block: &Block, inside: Mask) -> [u8; 16] {
|
||||
let bits = block.iter().enumerate().fold(0u64, |bits, (t, texel)| bits | ((u64::from(texel[3]) * 15 + 127) / 255) << (4 * t));
|
||||
join(bits.to_le_bytes(), colour_block(block, inside, 0, false))
|
||||
}
|
||||
|
||||
/// A BC3 block: an interpolated alpha block, then a four-colour block.
|
||||
pub(crate) fn encode_bc3(block: &Block, inside: Mask) -> [u8; 16] {
|
||||
join(alpha_block(block, inside), colour_block(block, inside, 0, false))
|
||||
}
|
||||
|
||||
fn join(a: [u8; 8], b: [u8; 8]) -> [u8; 16] {
|
||||
std::array::from_fn(|i| if i < 8 { a.get(i) } else { b.get(i - 8) }.copied().unwrap_or(0))
|
||||
}
|
||||
|
||||
/// The texels of `inside` for which `f` holds.
|
||||
fn select(block: &Block, inside: Mask, f: impl Fn(&[u8; 4]) -> bool) -> Mask {
|
||||
block.iter().enumerate().filter(|(t, texel)| inside >> t & 1 != 0 && f(texel)).fold(0, |m, (t, _)| m | 1 << t)
|
||||
}
|
||||
|
||||
fn rgb_of(texel: &[u8; 4]) -> [f32; 3] {
|
||||
[f32::from(texel[0]), f32::from(texel[1]), f32::from(texel[2])]
|
||||
}
|
||||
|
||||
/// RGB565 of a colour, rounding each channel to the nearest level.
|
||||
fn to565(c: [f32; 3]) -> u16 {
|
||||
let q = |v: f32, max: f32| (v.clamp(0.0, 255.0) * max / 255.0).round() as u16;
|
||||
q(c[0], 31.0) << 11 | q(c[1], 63.0) << 5 | q(c[2], 31.0)
|
||||
}
|
||||
|
||||
fn distance(a: &[u8; 4], b: &[u8; 4]) -> u32 {
|
||||
(0..3).map(|i| u32::from(a[i].abs_diff(b[i])).pow(2)).sum()
|
||||
}
|
||||
|
||||
/// A colour block (endpoints, then 2-bit indices) for the `opaque` texels' colours, with the
|
||||
/// `transparent` ones on BC1's transparent index. `bc1` allows the three-colour mode; BC2 and
|
||||
/// BC3 always decode four colours.
|
||||
fn colour_block(block: &Block, opaque: Mask, transparent: Mask, bc1: bool) -> [u8; 8] {
|
||||
let colours: Vec<[f32; 3]> = block.iter().enumerate().filter(|(t, _)| opaque >> t & 1 != 0).map(|(_, texel)| rgb_of(texel)).collect();
|
||||
if colours.is_empty() {
|
||||
// Nothing visible: every texel on the transparent index (or index 0 of black).
|
||||
let indices = if transparent != 0 { u32::MAX } else { 0 };
|
||||
return pack(0, 0, indices);
|
||||
}
|
||||
let (lo, hi) = principal_endpoints(&colours);
|
||||
let mut candidates = vec![(to565(lo), to565(hi))];
|
||||
let modes: &[bool] = if transparent != 0 {
|
||||
&[false]
|
||||
} else if bc1 {
|
||||
&[true, false]
|
||||
} else {
|
||||
&[true]
|
||||
};
|
||||
let mut best: Option<(u32, [u8; 8])> = None;
|
||||
// Each refinement starts from the best block so far: its indices give the least-squares
|
||||
// endpoints, which become one more candidate.
|
||||
for round in 0..3 {
|
||||
for &(e0, e1) in &candidates {
|
||||
for &four in modes {
|
||||
let (bytes, error) = fit(block, opaque, transparent, e0, e1, four);
|
||||
if best.is_none_or(|(e, _)| error < e) {
|
||||
best = Some((error, bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some((error, bytes)) = best else { break };
|
||||
if error == 0 || round == 2 {
|
||||
break;
|
||||
}
|
||||
candidates = least_squares(block, opaque, &bytes).into_iter().collect();
|
||||
if candidates.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
best.map_or([0; 8], |(_, bytes)| bytes)
|
||||
}
|
||||
|
||||
/// Orders endpoints `e0`, `e1` for the mode (`c0 > c1` for four colours, `c0 <= c1` for three)
|
||||
/// and picks each texel's nearest palette colour. Returns the block and its squared error.
|
||||
fn fit(block: &Block, opaque: Mask, transparent: Mask, e0: u16, e1: u16, four: bool) -> ([u8; 8], u32) {
|
||||
let (c0, c1) = if four == (e0 >= e1) { (e0, e1) } else { (e1, e0) };
|
||||
// Equal endpoints can't be in four-colour order; the palette is then one colour either way.
|
||||
let palette = colour_palette(c0, c1, four && c0 > c1);
|
||||
let choices = if four && c0 > c1 { 4 } else { 3 };
|
||||
let mut indices = 0u32;
|
||||
let mut error = 0u32;
|
||||
for (t, texel) in block.iter().enumerate() {
|
||||
let index = if transparent >> t & 1 != 0 {
|
||||
3
|
||||
} else if opaque >> t & 1 != 0 {
|
||||
let (i, d) = palette.iter().take(choices).enumerate().map(|(i, p)| (i, distance(texel, p))).min_by_key(|&(_, d)| d).unwrap_or((0, 0));
|
||||
error += d;
|
||||
i as u32
|
||||
} else {
|
||||
0
|
||||
};
|
||||
indices |= index << (2 * t);
|
||||
}
|
||||
(pack(c0, c1, indices), error)
|
||||
}
|
||||
|
||||
fn pack(c0: u16, c1: u16, indices: u32) -> [u8; 8] {
|
||||
let (c0, c1, i) = (c0.to_le_bytes(), c1.to_le_bytes(), indices.to_le_bytes());
|
||||
[c0[0], c0[1], c1[0], c1[1], i[0], i[1], i[2], i[3]]
|
||||
}
|
||||
|
||||
/// The ends of the colours' spread along their principal axis (the covariance's dominant
|
||||
/// eigenvector, by power iteration), clamped to the RGB cube.
|
||||
fn principal_endpoints(colours: &[[f32; 3]]) -> ([f32; 3], [f32; 3]) {
|
||||
let n = colours.len().max(1) as f32;
|
||||
let mean = [0, 1, 2].map(|i| colours.iter().map(|c| c[i]).sum::<f32>() / n);
|
||||
let mut cov = [[0f32; 3]; 3];
|
||||
for c in colours {
|
||||
let d = [c[0] - mean[0], c[1] - mean[1], c[2] - mean[2]];
|
||||
for (i, row) in cov.iter_mut().enumerate() {
|
||||
for (j, v) in row.iter_mut().enumerate() {
|
||||
*v += d[i] * d[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
let times = |a: [f32; 3]| [0, 1, 2].map(|i| cov[i][0] * a[0] + cov[i][1] * a[1] + cov[i][2] * a[2]);
|
||||
let iterate = |start: usize| {
|
||||
let mut axis = [0f32; 3];
|
||||
axis[start] = 1.0;
|
||||
for _ in 0..8 {
|
||||
let next = times(axis);
|
||||
let len = next.iter().map(|v| v * v).sum::<f32>().sqrt();
|
||||
if !len.is_normal() {
|
||||
break;
|
||||
}
|
||||
axis = next.map(|v| v / len);
|
||||
}
|
||||
axis
|
||||
};
|
||||
// From each channel's axis, keeping the one the colours spread along most: a channel that
|
||||
// varies on its own is already an eigenvector, so a single start there would never leave it
|
||||
// even when the others vary more together.
|
||||
let spread = |a: [f32; 3]| times(a).iter().zip(a).map(|(x, y)| x * y).sum::<f32>();
|
||||
let axis = [0, 1, 2].map(iterate).into_iter().max_by(|&a, &b| spread(a).total_cmp(&spread(b))).unwrap_or([1.0, 0.0, 0.0]);
|
||||
let along = |c: &[f32; 3]| (c[0] - mean[0]) * axis[0] + (c[1] - mean[1]) * axis[1] + (c[2] - mean[2]) * axis[2];
|
||||
let (lo, hi) = colours.iter().map(along).fold((f32::MAX, f32::MIN), |(lo, hi), t| (lo.min(t), hi.max(t)));
|
||||
let at = |t: f32| [0, 1, 2].map(|i| (mean[i] + t * axis[i]).clamp(0.0, 255.0));
|
||||
if lo > hi { (mean, mean) } else { (at(lo), at(hi)) }
|
||||
}
|
||||
|
||||
/// The endpoints that minimise the squared error for the indices `bytes` already chose: each
|
||||
/// texel's index fixes its weights between the endpoints, giving 2×2 normal equations per
|
||||
/// channel. `None` when the indices don't constrain both endpoints.
|
||||
fn least_squares(block: &Block, opaque: Mask, bytes: &[u8; 8]) -> Option<(u16, u16)> {
|
||||
let (c0, c1) = (u16::from_le_bytes([bytes[0], bytes[1]]), u16::from_le_bytes([bytes[2], bytes[3]]));
|
||||
let indices = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
|
||||
let four = c0 > c1;
|
||||
// How much of c0 each index holds.
|
||||
let weight = |i: u32| match (four, i) {
|
||||
(_, 0) => Some(1.0f32),
|
||||
(_, 1) => Some(0.0),
|
||||
(true, 2) => Some(2.0 / 3.0),
|
||||
(true, _) => Some(1.0 / 3.0),
|
||||
(false, 2) => Some(0.5),
|
||||
(false, _) => None,
|
||||
};
|
||||
let (mut aa, mut ab, mut bb) = (0f32, 0f32, 0f32);
|
||||
let (mut ax, mut bx) = ([0f32; 3], [0f32; 3]);
|
||||
for (t, texel) in block.iter().enumerate() {
|
||||
if opaque >> t & 1 == 0 {
|
||||
continue;
|
||||
}
|
||||
let Some(a) = weight(indices >> (2 * t) & 3) else { continue };
|
||||
let b = 1.0 - a;
|
||||
let c = rgb_of(texel);
|
||||
aa += a * a;
|
||||
ab += a * b;
|
||||
bb += b * b;
|
||||
for ((x0, x1), v) in ax.iter_mut().zip(bx.iter_mut()).zip(c) {
|
||||
*x0 += a * v;
|
||||
*x1 += b * v;
|
||||
}
|
||||
}
|
||||
let det = aa * bb - ab * ab;
|
||||
if det.abs() < 1e-3 {
|
||||
return None;
|
||||
}
|
||||
let e0 = [0, 1, 2].map(|i| (ax[i] * bb - bx[i] * ab) / det);
|
||||
let e1 = [0, 1, 2].map(|i| (bx[i] * aa - ax[i] * ab) / det);
|
||||
Some((to565(e0), to565(e1)))
|
||||
}
|
||||
|
||||
/// A BC3 alpha block: whichever of the two modes (eight values between the extremes, or six
|
||||
/// between the extremes other than 0 and 255, plus exact 0 and 255) fits better.
|
||||
fn alpha_block(block: &Block, inside: Mask) -> [u8; 8] {
|
||||
let alphas = || block.iter().enumerate().filter(move |(t, _)| inside >> t & 1 != 0).map(|(_, texel)| texel[3]);
|
||||
let range =
|
||||
|values: &mut dyn Iterator<Item = u8>| values.fold(None, |r: Option<(u8, u8)>, a| Some(r.map_or((a, a), |(lo, hi)| (lo.min(a), hi.max(a)))));
|
||||
let (lo, hi) = range(&mut alphas()).unwrap_or((0, 0));
|
||||
// Eight values need a0 > a1; equal ends fall to the six-value mode, which starts with a0 too.
|
||||
let eight = alpha_fit(block, inside, hi, lo);
|
||||
let (mid_lo, mid_hi) = range(&mut alphas().filter(|a| !matches!(a, 0 | 255))).unwrap_or((0, 0));
|
||||
let six = alpha_fit(block, inside, mid_lo, mid_hi);
|
||||
if six.1 < eight.1 { six.0 } else { eight.0 }
|
||||
}
|
||||
|
||||
fn alpha_fit(block: &Block, inside: Mask, a0: u8, a1: u8) -> ([u8; 8], u32) {
|
||||
let palette = alpha_palette(a0, a1);
|
||||
let mut bits = 0u64;
|
||||
let mut error = 0u32;
|
||||
for (t, texel) in block.iter().enumerate() {
|
||||
if inside >> t & 1 == 0 {
|
||||
continue;
|
||||
}
|
||||
let (i, d) = palette.iter().enumerate().map(|(i, &p)| (i, u32::from(p.abs_diff(texel[3])).pow(2))).min_by_key(|&(_, d)| d).unwrap_or((0, 0));
|
||||
error += d;
|
||||
bits |= (i as u64) << (3 * t);
|
||||
}
|
||||
let b = bits.to_le_bytes();
|
||||
([a0, a1, b[0], b[1], b[2], b[3], b[4], b[5]], error)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn decode_colour(bytes: &[u8; 8], bc1: bool) -> Block {
|
||||
let (c0, c1) = (u16::from_le_bytes([bytes[0], bytes[1]]), u16::from_le_bytes([bytes[2], bytes[3]]));
|
||||
let palette = colour_palette(c0, c1, c0 > c1 || !bc1);
|
||||
let indices = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]);
|
||||
std::array::from_fn(|t| palette[(indices >> (2 * t)) as usize & 3])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solid_blocks_land_on_the_nearest_565_colour() {
|
||||
for colour in [[0, 0, 0, 255], [255, 255, 255, 255], [12, 200, 77, 255]] {
|
||||
let block = [colour; 16];
|
||||
let out = decode_colour(&encode_bc1(&block, u16::MAX), true);
|
||||
for texel in out {
|
||||
assert!(texel.iter().zip(colour).all(|(a, b)| a.abs_diff(b) <= 4), "{texel:?} for {colour:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_colour_blocks_are_exact_when_the_colours_are_565() {
|
||||
let (a, b) = ([255, 0, 0, 255], [0, 0, 255, 255]);
|
||||
let block: Block = std::array::from_fn(|t| if t % 3 == 0 { a } else { b });
|
||||
for bc1 in [true, false] {
|
||||
let bytes = if bc1 { encode_bc1(&block, u16::MAX) } else { colour_block(&block, u16::MAX, 0, false) };
|
||||
assert_eq!(decode_colour(&bytes, bc1), block);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bc1_punches_through_texels_under_half_alpha() {
|
||||
let block: Block = std::array::from_fn(|t| if t < 8 { [200, 100, 50, 255] } else { [9, 9, 9, 127] });
|
||||
let bytes = encode_bc1(&block, u16::MAX);
|
||||
let (c0, c1) = (u16::from_le_bytes([bytes[0], bytes[1]]), u16::from_le_bytes([bytes[2], bytes[3]]));
|
||||
assert!(c0 <= c1, "three-colour mode");
|
||||
let out = decode_colour(&bytes, true);
|
||||
assert!(out[..8].iter().all(|t| t[3] == 255) && out[8..].iter().all(|t| *t == [0; 4]), "{out:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn four_colour_blocks_keep_c0_above_c1() {
|
||||
// A ramp needs all four colours; BC2 and BC3 blocks must not rely on the order, but
|
||||
// older decoders read c0 <= c1 as three colours, so the encoder never writes that.
|
||||
let block: Block = std::array::from_fn(|t| [(t * 16) as u8, 0, 0, 255]);
|
||||
let bytes = colour_block(&block, u16::MAX, 0, false);
|
||||
assert!(u16::from_le_bytes([bytes[0], bytes[1]]) > u16::from_le_bytes([bytes[2], bytes[3]]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alpha_blocks_pick_the_mode_that_keeps_0_and_255() {
|
||||
// 0, 255 and a cluster in between: the six-value mode stores 0 and 255 exactly.
|
||||
let block: Block = std::array::from_fn(|t| [0, 0, 0, [0, 255, 100, 110][t % 4]]);
|
||||
let bytes = alpha_block(&block, u16::MAX);
|
||||
assert!(bytes[0] <= bytes[1], "six-value mode");
|
||||
let palette = alpha_palette(bytes[0], bytes[1]);
|
||||
let bits = u64::from_le_bytes([bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], 0, 0]);
|
||||
for (t, texel) in block.iter().enumerate() {
|
||||
let got = palette[(bits >> (3 * t)) as usize & 7];
|
||||
assert!(got.abs_diff(texel[3]) <= 2, "texel {t}: {got} for {}", texel[3]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_principal_axis_is_found_when_one_channel_varies_on_its_own() {
|
||||
// Red alternates on its own (variance 64); green and blue alternate together (variance 49
|
||||
// each, 98 along their shared axis), uncorrelated with red. Starting on red alone would
|
||||
// keep red's axis and flatten green and blue; the block must do better than its bounding box.
|
||||
let block: Block = std::array::from_fn(|t| {
|
||||
let gb = if (t / 2) % 2 == 0 { 121 } else { 135 };
|
||||
[if t % 2 == 0 { 120 } else { 136 }, gb, gb, 255]
|
||||
});
|
||||
let error = |bytes: &[u8; 8]| decode_colour(bytes, false).iter().zip(&block).map(|(a, b)| distance(a, b)).sum::<u32>();
|
||||
let (_, bounding_box) = fit(&block, u16::MAX, 0, to565([120.0, 121.0, 121.0]), to565([136.0, 135.0, 135.0]), true);
|
||||
let ours = error(&colour_block(&block, u16::MAX, 0, false));
|
||||
assert!(ours < bounding_box, "{ours} vs the bounding box's {bounding_box}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn texels_outside_the_image_are_ignored() {
|
||||
// Only the top-left texel is inside: its colour alone decides the endpoints.
|
||||
let mut block: Block = [[0, 255, 0, 255]; 16];
|
||||
block[0] = [255, 0, 255, 255];
|
||||
let out = decode_colour(&encode_bc1(&block, 1), true);
|
||||
assert_eq!(out[0], [255, 0, 255, 255]);
|
||||
}
|
||||
}
|
||||
@@ -207,8 +207,10 @@ fn camera_raw_mode(b: &[u8], legacy: bool) -> bool {
|
||||
}
|
||||
TAG_SUB_IFDS if count == 1 => queue.extend(value(e)),
|
||||
TAG_SUB_IFDS => {
|
||||
// More than one offset: they are stored at the entry's offset.
|
||||
let at = u32_at(e.saturating_add(8)).unwrap_or(0) as usize;
|
||||
// More than one offset: they are stored at the entry's offset. A cut-off
|
||||
// offset field means no array, not one at the start of the file.
|
||||
let Some(at) = u32_at(e.saturating_add(8)) else { continue };
|
||||
let at = at as usize;
|
||||
for k in 0..count.min(8) as usize {
|
||||
queue.extend(u32_at(at.saturating_add(4 * k)));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::codecs::dpx;
|
||||
use crate::codecs::{dds, dpx};
|
||||
use crate::format::{Format, caps};
|
||||
use crate::image::{ChannelLayout, Image, SampleType};
|
||||
use crate::options::{DdsCompression, EncodeOptions};
|
||||
@@ -45,7 +45,8 @@ pub enum FidelityWarning {
|
||||
ColorToGray,
|
||||
/// The image will be quantized to a 256-colour palette.
|
||||
PaletteQuantized,
|
||||
/// The format's encoder is lossy.
|
||||
/// The format's encoder is lossy. DDS BC5 also keeps only red and green: blue is dropped and
|
||||
/// reads back as 0 (for a normal map, the renderer rebuilds Z from X and Y).
|
||||
LossyCompression,
|
||||
IccDropped,
|
||||
ExifDropped,
|
||||
@@ -175,8 +176,12 @@ pub(crate) fn plan(image: &Image, format: Format, opts: &EncodeOptions) -> Plan
|
||||
},
|
||||
// CIELab has no float form: float Lab is written with 16 bits.
|
||||
Format::Tiff if layout.is_lab() && sample.is_float() => Plan { layout: pick_layout(layout, c.layouts, c.alpha), sample: SampleType::U16 },
|
||||
// A block-compressed DDS stores RGBA whatever the source; uncompressed keeps gray and RGB.
|
||||
Format::Dds if opts.dds.compression.is_block() => Plan { layout: ChannelLayout::Rgba, sample: SampleType::U8 },
|
||||
// A block-compressed DDS stores what its compression holds whatever the source: gray for
|
||||
// BC4, red and green for BC5 (written from RGB, blue dropped), RGBA for BC1 to BC3.
|
||||
// Uncompressed keeps gray and RGB.
|
||||
Format::Dds if opts.dds.compression.is_block() => {
|
||||
Plan { layout: opts.dds.compression.layout().map_or(ChannelLayout::Rgba, dds::channel_layout), sample: SampleType::U8 }
|
||||
}
|
||||
_ => Plan { layout: pick_layout(layout, c.layouts, c.alpha), sample: pick_sample(sample, c.depths) },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub enum Format {
|
||||
Pcx,
|
||||
/// X PixMap icons (XPM2 plain text and XPM3 C-string arrays).
|
||||
Xpm,
|
||||
/// DirectDraw Surface: a 2D texture, uncompressed or BC1–BC3. Reading takes the top mip
|
||||
/// DirectDraw Surface: a 2D texture, uncompressed or BC1–BC5. Reading takes the top mip
|
||||
/// level; writing can add the full mip chain ([`crate::DdsOptions`]).
|
||||
Dds,
|
||||
Qoi,
|
||||
|
||||
@@ -235,60 +235,8 @@ impl DpxBits {
|
||||
}
|
||||
}
|
||||
|
||||
/// How a DDS texture stores its pixels.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum DdsCompression {
|
||||
/// Uncompressed, 8 bits per channel: BGRA (BGRX without alpha), or luminance with or
|
||||
/// without alpha for grayscale. Lossless.
|
||||
#[default]
|
||||
None,
|
||||
/// BC1 (DXT1): 4 bits per pixel. Alpha is on or off: texels under half opacity become
|
||||
/// transparent black.
|
||||
Bc1,
|
||||
/// BC2 (DXT3): 8 bits per pixel, with 4 bits of explicit alpha per texel.
|
||||
Bc2,
|
||||
/// BC3 (DXT5): 8 bits per pixel, with smooth interpolated alpha.
|
||||
Bc3,
|
||||
}
|
||||
|
||||
impl DdsCompression {
|
||||
pub const ALL: [DdsCompression; 4] = [DdsCompression::None, DdsCompression::Bc1, DdsCompression::Bc2, DdsCompression::Bc3];
|
||||
|
||||
/// The name scripts and the CLI use: `none`, `bc1`, `bc2` or `bc3`.
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
DdsCompression::None => "none",
|
||||
DdsCompression::Bc1 => "bc1",
|
||||
DdsCompression::Bc2 => "bc2",
|
||||
DdsCompression::Bc3 => "bc3",
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Self::name`] back to a compression, also taking the DXT names (`dxt1`, `dxt3`,
|
||||
/// `dxt5`), in any case. Anything else is `None`.
|
||||
pub fn from_name(name: &str) -> Option<Self> {
|
||||
match name.to_ascii_lowercase().as_str() {
|
||||
"none" => Some(DdsCompression::None),
|
||||
"bc1" | "dxt1" => Some(DdsCompression::Bc1),
|
||||
"bc2" | "dxt3" => Some(DdsCompression::Bc2),
|
||||
"bc3" | "dxt5" => Some(DdsCompression::Bc3),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A block compression (lossy), not uncompressed pixels.
|
||||
pub fn is_block(self) -> bool {
|
||||
self != DdsCompression::None
|
||||
}
|
||||
}
|
||||
|
||||
/// What a DDS file is written with.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct DdsOptions {
|
||||
pub compression: DdsCompression,
|
||||
/// Write the full mip chain down to 1×1, each level a box filter of the one above.
|
||||
pub mipmaps: bool,
|
||||
}
|
||||
/// How a DDS texture stores its pixels and whether it carries a mip chain, from [`craft_dds`].
|
||||
pub use craft_dds::{DdsCompression, DdsOptions};
|
||||
|
||||
/// The longer side, in pixels, at which a TIFF image pyramid stops: the last level written is
|
||||
/// the first one no longer than this ([`EncodeOptions::tiff_pyramid`]).
|
||||
|
||||
@@ -25,9 +25,10 @@ pub fn header(bytes: &[u8]) -> Result<(u32, u32, u16), CodecError> {
|
||||
if !has_image {
|
||||
return Err(err("no image data"));
|
||||
}
|
||||
let (w, h) = crate::probe_size(bytes)?;
|
||||
// Read stored dimensions directly. Undoing probe_size with the compatibility EXIF
|
||||
// orientation is incorrect when its lenient parser disagrees with the strict one.
|
||||
let (w, h, _) = crate::codecs::webp::probe(bytes, &crate::Limits::default())?;
|
||||
let orientation = exif.map_or(1, craft_metadata::compat_orientation::orientation);
|
||||
let (w, h) = if (5..=8).contains(&orientation) { (h, w) } else { (w, h) };
|
||||
Ok((w, h, orientation))
|
||||
}
|
||||
|
||||
@@ -47,6 +48,20 @@ mod tests {
|
||||
assert_eq!(header(&bytes).unwrap(), (2, 3, 6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_exif_does_not_swap_stored_dimensions() {
|
||||
let mut image = crate::Image::from_u8(2, 3, crate::ChannelLayout::Rgb, vec![42; 18]).unwrap();
|
||||
image.meta.exif = Some(b"II\x2a\x00\x08\x00\x00\x00\x01\x00\x12\x01\x03\x00\x01\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00".to_vec());
|
||||
let mut bytes = crate::encode(&image, Format::WebP, &crate::EncodeOptions::default()).unwrap();
|
||||
let exif = bytes.windows(4).position(|v| v == b"EXIF").unwrap() + 8;
|
||||
bytes[exif + 18] = 6;
|
||||
// Compatibility metadata preserves orientation despite a malformed count;
|
||||
// the strict orientation used by probe_size rejects it. Stored size is neither.
|
||||
bytes[exif + 14..exif + 18].copy_from_slice(&0u32.to_le_bytes());
|
||||
assert_eq!(crate::probe_size(&bytes).unwrap(), (2, 3));
|
||||
assert_eq!(header(&bytes).unwrap(), (2, 3, 6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_missing_and_truncated_image_chunks() {
|
||||
let mut bytes = b"RIFF\x00\x00\x00\x00WEBP".to_vec();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! image generators, comparison metrics.
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub mod pngsuite;
|
||||
pub mod tiffgen;
|
||||
|
||||
use craft_image_codecs::*;
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
//! The pinned PngSuite. `pngsuite.tsv` lists every file of the suite as a `sha256<TAB>name` row,
|
||||
//! with `#` comment lines; further tab-separated columns are allowed and ignored. The corpus tests
|
||||
//! read only the listed PNGs from `corpus/pngsuite/` at the repo root, and only after each file's
|
||||
//! SHA-256 matches its row. A file the list does not name is never read.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// The pinned list.
|
||||
pub const MANIFEST: &str = include_str!("pngsuite.tsv");
|
||||
|
||||
/// The largest file read from the corpus folder. The suite's largest file is under 5 KiB.
|
||||
pub const MAX_FILE_BYTES: u64 = 4 * 1024 * 1024;
|
||||
|
||||
/// `corpus/pngsuite` at the repo root.
|
||||
pub fn dir() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/pngsuite")
|
||||
}
|
||||
|
||||
/// The rows of `manifest` as name to lowercase hex SHA-256. A row needs a 64-digit lowercase hex
|
||||
/// digest and a plain file name (ASCII letters, digits, `.`, `_` and `-`, not starting with `.`),
|
||||
/// and each name may appear once.
|
||||
pub fn parse(manifest: &str) -> Result<BTreeMap<&str, &str>, String> {
|
||||
let mut rows = BTreeMap::new();
|
||||
for (number, line) in manifest.lines().enumerate().map(|(i, l)| (i + 1, l)) {
|
||||
if line.is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
let mut cols = line.split('\t');
|
||||
let (Some(digest), Some(name)) = (cols.next(), cols.next()) else {
|
||||
return Err(format!("line {number}: expected a SHA-256, a tab and a name"));
|
||||
};
|
||||
if digest.len() != 64 || !digest.bytes().all(|c| matches!(c, b'0'..=b'9' | b'a'..=b'f')) {
|
||||
return Err(format!("line {number}: invalid SHA-256 for {name:?}"));
|
||||
}
|
||||
if name.is_empty() || name.starts_with('.') || !name.bytes().all(|c| c.is_ascii_alphanumeric() || b"._-".contains(&c)) {
|
||||
return Err(format!("line {number}: invalid file name {name:?}"));
|
||||
}
|
||||
if rows.insert(name, digest).is_some() {
|
||||
return Err(format!("line {number}: {name} is listed twice"));
|
||||
}
|
||||
}
|
||||
if rows.is_empty() {
|
||||
return Err("the manifest lists no files".into());
|
||||
}
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
/// The lowercase hex SHA-256 of `bytes`.
|
||||
pub fn sha256_hex(bytes: &[u8]) -> String {
|
||||
Sha256::digest(bytes).iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
/// Reads a regular file of at most `limit` bytes. A symbolic link, a folder or a larger file is an
|
||||
/// error, and a file that grows during the read is cut off at `limit + 1` bytes and refused.
|
||||
fn read_file(path: &Path, limit: u64) -> Result<Vec<u8>, String> {
|
||||
let meta = std::fs::symlink_metadata(path).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
if !meta.is_file() || meta.len() > limit {
|
||||
return Err(format!("{}: expected a regular file of at most {limit} bytes", path.display()));
|
||||
}
|
||||
let mut bytes = Vec::new();
|
||||
std::fs::File::open(path).and_then(|f| f.take(limit + 1).read_to_end(&mut bytes)).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
if bytes.len() as u64 > limit {
|
||||
return Err(format!("{}: exceeds {limit} bytes", path.display()));
|
||||
}
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
/// Every `.png` that `manifest` lists, read from `dir` in name order with its bytes. A listed PNG
|
||||
/// that is missing, is not a regular file or does not match its SHA-256 is an error.
|
||||
pub fn pinned_pngs(dir: &Path, manifest: &str) -> Result<Vec<(String, Vec<u8>)>, String> {
|
||||
let rows = parse(manifest)?;
|
||||
let mut out = Vec::new();
|
||||
for (name, digest) in rows.into_iter().filter(|(name, _)| name.ends_with(".png")) {
|
||||
let bytes = read_file(&dir.join(name), MAX_FILE_BYTES)?;
|
||||
let got = sha256_hex(&bytes);
|
||||
if got != digest {
|
||||
return Err(format!("{name}: SHA-256 {got} does not match the pinned {digest}"));
|
||||
}
|
||||
out.push((name.to_string(), bytes));
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The pinned PNGs of `corpus/pngsuite/`. A missing or changed file fails the calling test.
|
||||
pub fn pngs() -> Vec<(String, Vec<u8>)> {
|
||||
let dir = dir();
|
||||
pinned_pngs(&dir, MANIFEST).unwrap_or_else(|e| {
|
||||
panic!("{}: {e}; extract the archive named in tests/it/common/pngsuite.tsv into this folder (see the crate README)", dir.display())
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
# PngSuite original PNGs and redistribution notice
|
||||
# Source: https://github.com/lunapaint/pngsuite/tree/8cd768dd0d0063195174d0d01cacbd5a7d1e5605
|
||||
# Archive: http://www.schaik.com/pngsuite/PngSuite-2017jul19.tgz
|
||||
# Archive SHA-256: 0294b244c95a8342c01b00010cf34abdcabc7c6a34fd0fe1bd963917537bfdc8
|
||||
# Terms: http://www.schaik.com/pngsuite/PngSuite.LICENSE
|
||||
# LICENSE holds the same bytes as the archive's PngSuite.LICENSE.
|
||||
# sha256 name
|
||||
71e1f5bf865131b5d9996e76a78372146283e5089e50f900ae927a6458b62101 LICENSE
|
||||
71e1f5bf865131b5d9996e76a78372146283e5089e50f900ae927a6458b62101 PngSuite.LICENSE
|
||||
a2853f2be68e460dcb9992819125b74503a01383e79f79a04b971ffa9d248544 PngSuite.README
|
||||
6cf3bcd1757bfad2a7ce9c9659d4f609297a0828cafc7c9eddee18c5576ba9e9 PngSuite.png
|
||||
9bf1c4610280efecc291361e2b7b026d602d03a7137f476ff84af626bb7b3a62 basi0g01.png
|
||||
50ed4ff9c1c80578ae58ead6fb28ea2e44016b5b56a7b3e95c235ec86f97c0d8 basi0g02.png
|
||||
0cce4212157dae7c0f71f5f72cef39cecab3347de455da0ace7de83eebd47849 basi0g04.png
|
||||
b9300750e7414c9fed68cc7f4f531f5e2cdd2724f50142e8aa3a0070836bece9 basi0g08.png
|
||||
d354026bdd0aa6ed7bedea7c92e5eef2ebbd4854848b8a0a48f562cc71bfe80f basi0g16.png
|
||||
b2690d4475cdc39faf5a7d2de20de4e14eb96c6360fa791ec2003b4085ecacde basi2c08.png
|
||||
ae13eba5fabbf7cbe8c01ec4458cdaa7e6bfdfcbd5109e831efaac9f39096027 basi2c16.png
|
||||
8e1edfbc0382e0b545c70209271cedead2d530df1ce40f5296f0749226b36006 basi3p01.png
|
||||
85f304eaaf6831b2bcc2c08892b947fef52f06337aaf23312d6326e367d73f77 basi3p02.png
|
||||
78890ee2c4da71e460b5a1527efe7dc17d673ebe997f49ca1b4dcd7347d21e56 basi3p04.png
|
||||
ca103eef7a7c50abc7af9d5ec0dc9fdc07668e2f030adbce226e050dcec9eea3 basi3p08.png
|
||||
dfae01a4548e30519157bb51ce29d4de3b35b74288e9568b4d5911de01c6048b basi4a08.png
|
||||
ef7df23ccd912309a4f89ca3c3094bf5ab55add25218e571e51cc6cb11cfad9e basi4a16.png
|
||||
fe70ea20c8447e82abb7bc9dd05344a61a4631cc69e0974378df8f6263af0337 basi6a08.png
|
||||
7fdd6bf08f04692bcf06b5c4262e7f76c49d8adb992789fd3f05aa0435645cd8 basi6a16.png
|
||||
c8b1364d7771dd2f5a1b2d7d633abcf3f48dafee608558ecd2e5fc98f61894cd basn0g01.png
|
||||
ca172e92d179c77b3d321ad501e452a59bdaafafde8ebd74fd0669c4eae58efc basn0g02.png
|
||||
fb2d42c4c8f5c51590e675994a9b0c718fbf71c80e28142f231cfa7c5b0e26e8 basn0g04.png
|
||||
268d061075d1dd2eeec62b31303d09f6998549e1bfb447a5f09c80a2b0978ac3 basn0g08.png
|
||||
1a1fe155f40c11d79350b3f84c7eb2b29719037e57073cb7ae2ab9e8323f9360 basn0g16.png
|
||||
c90e86090a625661b19960cafdde6e347d6e32d73837aaae533f66dd3f099506 basn2c08.png
|
||||
1e1c28ec0ee5da6224404b4005076dd30e2335a1a80c0ca722046a245c4a2b3b basn2c16.png
|
||||
c2d7cd682df5f74506b33a5d70c344aaee248fda79fdfef8e873426fd6f2b75b basn3p01.png
|
||||
0466bb7ed9984cf03b70704564bcffab1df8ec0e8167473ba0f75e4fedce5a8f basn3p02.png
|
||||
e1fc7be978d3149b98533d0076245ae64353b7967290f4204c1282ecb4ec1aba basn3p04.png
|
||||
d58256cd2eb16b5740d4c1403d25ce43d8dd03e270627ab709d2fb141e3d904c basn3p08.png
|
||||
7be24b618bfd437b921ae0caf9341d112338c6290cc62466deb19d2c7a512968 basn4a08.png
|
||||
1c92ffd11d2fc89a36f170d0239668436407f5c8e3f8d93483fb3fc6bca361d7 basn4a16.png
|
||||
559c594166eb156f461c9beff0f053196730dc998fdb0d2b801c89e6680860a5 basn6a08.png
|
||||
8f9d81060aebf4576461403c5057de7f23f73157016b659402b906df805845aa basn6a16.png
|
||||
dfae01a4548e30519157bb51ce29d4de3b35b74288e9568b4d5911de01c6048b bgai4a08.png
|
||||
ef7df23ccd912309a4f89ca3c3094bf5ab55add25218e571e51cc6cb11cfad9e bgai4a16.png
|
||||
559c594166eb156f461c9beff0f053196730dc998fdb0d2b801c89e6680860a5 bgan6a08.png
|
||||
8f9d81060aebf4576461403c5057de7f23f73157016b659402b906df805845aa bgan6a16.png
|
||||
71d041df5c8949ce07d5e93b3c9f752cefc75ef7326c49df05ae73915f1a755f bgbn4a08.png
|
||||
c45de44d3442bd33072d68456541b10e0cc57c5d8bfc809208995d939091eb2d bggn4a16.png
|
||||
2da3c3efa01bf166958852a104ece92daaede8ffb5e0452a55d40526258a8bf5 bgwn6a08.png
|
||||
875bc2b44a4355551c51260def9664da68be1af8c14b82f76173aaf01ddb1929 bgyn6a16.png
|
||||
c88909e74e039dd3df829bf24144b487171e53b17f5c5c07cbc08688247d24b5 ccwn2c08.png
|
||||
dc365b39d49c287669d837872dd59aef30763a611dfc8c046c481e35e49a390a ccwn3p08.png
|
||||
438018f19c85e582cb586ac7cca2220008ecb7fc70ce50e8f2a76b494c128a20 cdfn2c08.png
|
||||
a068eaf1f7040490e08eda3259befb6689849dd0ff8bb4cc03c705d117cb2b9f cdhn2c08.png
|
||||
ee08dfa303a3c09171280fc1821180dc0a4c3591af7e9077e8ce0435642c76d2 cdsn2c08.png
|
||||
a849d89ba3d92146940d7c56d2fe74c9c3ec96725c7f24eefaf44160a6304de2 cdun2c08.png
|
||||
587a8624228d3f605f475bd751a1f3a97f0bbab590c0ff518bce5da3abcb6f2b ch1n3p04.png
|
||||
e3cace549047c6e5e693b9b135d53f7f9ca5b1088bf30cc408634598ba53758a ch2n3p08.png
|
||||
79ccaf4abe5091e1f65f8a61496363ed3312ebb9ea1aaa98affadac3d98507de cm0n0g04.png
|
||||
127bb50d224ac3ebff36160482a03b9e6686072e86c8ff4cd43e3ce2271b2315 cm7n0g04.png
|
||||
774b384d0ad73698e7d93fc5a29976b332c619045e5966276c609b11459a4152 cm9n0g04.png
|
||||
bc812de2b83abc9ae2a6d1ae01e91f9090214b9ed8fee1d56cdfea58f4f259d0 cs3n2c16.png
|
||||
267104dced0858dd828cdd41edc0e87042c7094c77191565192a67045064b23f cs3n3p08.png
|
||||
028fa49fbba3954c2eba27a4c3607196e87c1dae74192df3b3ad7afe5e0a3f0c cs5n2c08.png
|
||||
a7a4021983d6b22685529cbafb65cd087c9e1af1c5d205c2e13e3efc4ae87b6a cs5n3p08.png
|
||||
d90ddab7313e4e1fd7f20f16a6c546b449697fbcac1a7776298a74896f4662da cs8n2c08.png
|
||||
5bffdb88e307a851f8e85b137a69c59e557a881db816e990061934c0155c894c cs8n3p08.png
|
||||
081d1ec26b4157fbc032b76dc716321420f2d032a425de046557c7842766826d ct0n0g04.png
|
||||
259116f8ecf849d83d824688eb02b4575aed11980f02ab6fb123281c25a6459d ct1n0g04.png
|
||||
4583e63d1bdfa18b6abb47439dee9a73bed311ed1b0a71d22bed75fe4767832b cten0g04.png
|
||||
d0607280c3539a8934c5cfd22788b382cdc31321cdedc75ae8a29e3948580ba6 ctfn0g04.png
|
||||
5f4c87f5a8f589d029a908050880ac5d6aed3810e55e75444802d6d3fb27cf33 ctgn0g04.png
|
||||
8ef799e59871755578e563c5b411bc3895c2f7112c115aaa921b6c04fe255bf2 cthn0g04.png
|
||||
ca91332ecc04e5faac1f39ca4df4996b072a93f3e574e7f4b50d52aafbfe67b6 ctjn0g04.png
|
||||
c0765e635a6423ec64f0314400c3df20745c4a4469ffcc323c7b00ba66b4aceb ctzn0g04.png
|
||||
d04140d74bc60597c47b5aac371a3553d3add9354437bbd8c57007d94e197809 exif2c08.png
|
||||
d055cc0bb505b37c6ecf88a808d71675eca5dd0ee683d70ebc9c0be0e1bb8e57 f00n0g08.png
|
||||
0fe92b2aa2da04c885d1dbd85c834716f6cdd946364d97dcd597bb79d9e14427 f00n2c08.png
|
||||
956ddaf133e6d9a8d36f1e00604d87fbc2d0295e933bb8caaef517e7d87e5342 f01n0g08.png
|
||||
ef072ec6815ebf9b33e0553d2e4e4e7ed6911860a2512c67bcd10a9f0f09b9de f01n2c08.png
|
||||
1f5b49c06ecc2a1756f0423b3de936bd18497866d035ac8eded78a6f17408a2c f02n0g08.png
|
||||
ca4b937b3c587d5c007f193a2eec14dc96b0d23ff7d6aa9004e3badd1af9fe8f f02n2c08.png
|
||||
d0563ae30c6ce7a01eae7a5cdc0ef780175bfa7653888ed93f17bef5fe4b2107 f03n0g08.png
|
||||
2d101e3ef4f78a69437034671e93fe11faac0cfc4d44210dcca1b944caa886f7 f03n2c08.png
|
||||
fec1a3c53833d0ddefa4486a98934c393cb4335b2dc31da70e6540a4686f1457 f04n0g08.png
|
||||
c365c24153cb69fd3c162f00b296ae23a71a1595645d1aeb0ad23af680d7b4be f04n2c08.png
|
||||
8ac0f095d2a943157e820fa121bccde08d5230af1b5830c3041d5f4da3524eba f99n0g04.png
|
||||
3494b914dd1b094afa9a74a89bfa75219030e21af6fca3ed66c9d45032a047e9 g03n0g16.png
|
||||
abce774b9624952c2d0c57ff681790ba620cf5616fe7e0ef0600600cdce3c22a g03n2c08.png
|
||||
541389db0c72721c6c49501e1dbf6e32df41b4fcfa318676955e278f3f4332b3 g03n3p04.png
|
||||
72350a2d9db2df09b626f1f1dd48061e9c749d471bf19814d2c5c10acbf007e5 g04n0g16.png
|
||||
bfd3edfc4d85a43383556a51023533fa3888184aa53a6b43769910782beebfce g04n2c08.png
|
||||
5ea85ebefb58b2ab113fc05bf1cb79ffb068359e3a5620843590a0a7b59bd49a g04n3p04.png
|
||||
be19721d28e0b268af1e29e8190c952b94315bd08899383ae2c91e6dc8c4f889 g05n0g16.png
|
||||
74ab5b8477992d65e220eeaff8df466522c1b392fa90c6f9935da5bdb7113c9d g05n2c08.png
|
||||
2f46afd7ec15836b523cbce6965f34d89833b8d777afffaf0f53bce620d5f65e g05n3p04.png
|
||||
9070f843981f765cc8e26a63751be5d58631d85a8a7b4e826358f80e8a679d03 g07n0g16.png
|
||||
ca4cd32d222f65fb7beb7c9f40d8b6833b36d552b830ff1a1d67dae73b8ed0d8 g07n2c08.png
|
||||
b8e7abeabcfd50b71cca78b6cdff7372310cfc179cd63304c3e904f469b333cb g07n3p04.png
|
||||
a22486acb74ee5f947db3a20b1f314a9dd8aca3339840049ee559f4d676a6b5c g10n0g16.png
|
||||
4ac23729aea109e8f6b1e831448115cf02dcd97559e9403847cbe6dd7e5c7347 g10n2c08.png
|
||||
36cc2ea4b5b33cd18e0a01c7de85dbcaf7161d258cd0f2265a90cd835b15cf6d g10n3p04.png
|
||||
1fae707d809296d2cf0d6aa653bead6199644fb1c859558ec7d2d69e709a423a g25n0g16.png
|
||||
9b128cfa1bb417dd99251914d729062621fcea9f346168549b16a75fe030b0f6 g25n2c08.png
|
||||
4197a0a25c4f74d42c2285d75b9fabe1eedbed45bc224ff1ec1784f5797e9dbf g25n3p04.png
|
||||
1a1fe155f40c11d79350b3f84c7eb2b29719037e57073cb7ae2ab9e8323f9360 oi1n0g16.png
|
||||
1e1c28ec0ee5da6224404b4005076dd30e2335a1a80c0ca722046a245c4a2b3b oi1n2c16.png
|
||||
142bc4b1e9f8a9e3b0ba3d2c2025e485bf7e76df88f914bf8c9041b4562cc080 oi2n0g16.png
|
||||
2c523f138e0ade1bed8f31d59ec0f34b82660b192d6af8b8f395f82b9ba9dabb oi2n2c16.png
|
||||
aa2d77723ba44f654a41a2ab97e01271fe942fecd2f299c0a81da90acb2887ac oi4n0g16.png
|
||||
661220a0ed03ca6d63ec8dcaac738d4a9fd089b491c40dd896267ffb6cf5015d oi4n2c16.png
|
||||
ae70c9effd0d9957a0d42771bc987529a1f3715e068057fae63f0c7e50d5c53a oi9n0g16.png
|
||||
fef98e9bebe6c4046c29f2568f7a735305c8661aa01f9c37a718135e5bc4f941 oi9n2c16.png
|
||||
72406b6173ec20dd059e8cea594ef5bc8f81bac5e416e2b53058d2debd51d195 pp0n2c16.png
|
||||
d5a6f964a601a5e1815525117c12c32b61e2aa09fd6040776d35f2f7115b7110 pp0n6a08.png
|
||||
b321b9ac8f2aa641475b6936365954181726dcb8662dbf641284d82a83cc22a5 ps1n0g08.png
|
||||
6c59d673032fe2d04dbd2ea91cc9bc7bebe7d5ab84911f00e36fb28994793576 ps1n2c16.png
|
||||
bd2ae1b45fd771aaa8c57dccd183f3834fc9742f6dfc692606865049efb116e5 ps2n0g08.png
|
||||
120c62ce9d014f7772c4b38a446991b5bbe6a22ef5ea59239d32e023bc167585 ps2n2c16.png
|
||||
235eb82f1337e3fcefbdca566a53af3d3523db7588ba3cd7fa5dab19afe48a41 s01i3p01.png
|
||||
6a4f6da9fe36d195219ad2beeac1a0423e2ee6de03dfb064a3b6fa31623eb230 s01n3p01.png
|
||||
e7d26ab4b31e7066b0674a4374c093967a9f1761b96836aa3dbe624acd73ab52 s02i3p01.png
|
||||
f4b324f2b1d013ee77f632e42129c7cd3eca55da846e775e744a1f224ad1efcd s02n3p01.png
|
||||
4513dec80f54ffd04a28834b114254d6e6d66e52e32e0059174474f2fb15d6bc s03i3p01.png
|
||||
4dee297bd7f747f87488509af11a1e1e0531fa67e6e8d0f8ab7f4df7940f0ff3 s03n3p01.png
|
||||
918f94f3557e10de91efa680df507c8eafc347fa5023af43037701398128ad0f s04i3p01.png
|
||||
e73c52f764b684ec5133cce11f7f18cc60065acdd308e2c3d871e0a792a1080e s04n3p01.png
|
||||
77fe040e17167f9656afe46cf0031832e635745e4e7f19ba12dee32f5ec03d96 s05i3p02.png
|
||||
1b9e244a5c1d6cc9830391fff4eac565ada026d000e60faf7525c8add6bdc726 s05n3p02.png
|
||||
cf8d5fdb34c0afd38b1b4745bed6167771767ccdfe847c4d8766f7fcc5c41176 s06i3p02.png
|
||||
5caabfc4b147fad5e49e558143faaab91888324240acf45e5db8fc49f7a7f667 s06n3p02.png
|
||||
d9874bfad10353a9ea2876ee388c3e7f81f697ed141d0d79c5c2019d62a7a698 s07i3p02.png
|
||||
e7d447394f5fa64c27353216af387352a77a1fb534922a2d974e60d965d4e414 s07n3p02.png
|
||||
62adf855c6b1e3a007f9dcf3ce2ba244616c089269a511dd939e89a4b0853453 s08i3p02.png
|
||||
544fdd476e566e8aef4c98604124ae05acef48be20d1aebb9b6674b08b2abbb6 s08n3p02.png
|
||||
f2cf5b3109690704d106a0b22ea079e36064cc6077e1fb9a1ba87397d0bbcca1 s09i3p02.png
|
||||
6be8f58b638e7f7114750f5796f66f650db8fb7242a36183850f02117f4eaa65 s09n3p02.png
|
||||
a27e0dbf923ef868e7399560b76c23a50b2d8926cddd9775e2bc4e050273f205 s32i3p04.png
|
||||
c80d9fc7ded0b7834ec11d0e324540c7be74016b61bc302a1d167218fa35fbf9 s32n3p04.png
|
||||
cc6ad98dcf686d92f1165d951f90fac70e568cedb1fcbba33e8890d0e6cdad4d s33i3p04.png
|
||||
998d08e084e3eea288984475bfed0d48ee2d8250e20b96755898b59152e36a34 s33n3p04.png
|
||||
83eb2e82eb14ae3c608833ef371a6f472c4c6e63b7e9f4f92f5472f975793b97 s34i3p04.png
|
||||
a25451168c0b03ab8f52dcc60c6b9c12bc5df5d55afabe1892b87d0a856bb4a0 s34n3p04.png
|
||||
db5988c27ad577de1e494cb50229dc2772678531adde2db84493907eae003e54 s35i3p04.png
|
||||
cd99fc4cc69bda1ff8e8697d8b423ae8d9e84a58ba1d2b480751953b6869e3b3 s35n3p04.png
|
||||
a36b40927b730a31d60c7818fb4a32e67ace06393cdaa26edc09520b6cee066d s36i3p04.png
|
||||
ebc08f6a1e0918c5d3a9a08e184c23019a3cf90d8843e4b71bf2ae16040b1a84 s36n3p04.png
|
||||
565c79404c4b9e46c27edb2f93d7b26b93ec0a0481ab7a21fc405152a21f53ba s37i3p04.png
|
||||
964078b1f3f472268b8ac97a8976b4d1cdb6a47e6243d67eddcb0205e65b9f61 s37n3p04.png
|
||||
b107f120ffaffcb949ac4547e0f91555ac681f78c7e68c724e7ceddfd8e5387b s38i3p04.png
|
||||
045b0f5ea35874741bf6cac40f2e63ec8726450ab241475df4b7e9303c39e339 s38n3p04.png
|
||||
4b5a6d8c04c8c70e1de3bcb6f7b5cc3ba359b13e28de6f52e21a291d4bc8a937 s39i3p04.png
|
||||
2115b6cad0140ea97fe6ec056b47307ef1e8b5c00db5f08707a0572b165e5f08 s39n3p04.png
|
||||
48a3f19b5c3b2f7eca17fd34765a2a3e385d770f24c357bc66bd74417eb60a5a s40i3p04.png
|
||||
c4598ea73b1ec015bef7dcfd7f67bc7bfc41546619953d1a92cd9b8657a7033a s40n3p04.png
|
||||
c5e7eeaffa677bfac002ee968a0423e0fea3be7701d39ccd6a015df1d2d85e40 tbbn0g04.png
|
||||
8fcfd031a5b716201854fdab25691feed6cd3ed7b713a51b94e1f43fc63fe0c1 tbbn2c16.png
|
||||
8eb43a6020fda8ed7c8c9b88b974ef794ee8452db29212ae7e5c11003bfd76a3 tbbn3p08.png
|
||||
49711ee271f96099521b83b75d58ed2f76d42ed46cb3c06656fde2cad697cf59 tbgn2c16.png
|
||||
6f798628935a021fe446dce3d62861d1f7369aaf01bad10daa4917c5abccad7d tbgn3p08.png
|
||||
8223d8b0c5f84b149f0c1f0e1f658346e07fcbd03ffc02b2e9eeea1481eb19bf tbrn2c08.png
|
||||
01e86f108b244bdee4d72e384aced8a62369965ca2993ee6ef88f131c647f7d1 tbwn0g16.png
|
||||
978b28cec43bd219517083b63661bb30a7b9cdf9fd4476ab4e70844565980d51 tbwn3p08.png
|
||||
7b4eb64b4bd7eb36417752873ddaca027ce77a07f474b2af569f4eea1e984111 tbyn3p08.png
|
||||
f05e317f64a038123faf96fdbd6fc3ab3eec14e1fc1eb87fd7da4d996be63526 tm3n3p02.png
|
||||
a253e055d8cd94049cd95e9392e7aa60f3d5c922a8f0cccb84762b0c5f547545 tp0n0g08.png
|
||||
5dced3fde56b950e61ce86f4ad54458336f66389ce8ca68524d4fd8ec546ff5b tp0n2c08.png
|
||||
da40ddb18bd45db32ed03dc89e2250b096d808efe975a88477e4f5a91a4677c9 tp0n3p08.png
|
||||
50bc927fe6cf1816454a7c27f8c743734be8db45e37e5ee3ede540f4e895e6c5 tp1n3p08.png
|
||||
4059f7e6a1c5bac1801f70e09f9ec1e1297dcdce34055c13ab2703d6d9613c7e xc1n0g08.png
|
||||
e252a0e7df3e794e52ce4a831edafef76e7043d0d8d84019db0f7fd0b30e20f4 xc9n2c08.png
|
||||
3c0c2a68dd416a7be79400e0e2ceb358ba3191d5309d4bad9dd04b32ff6d5b60 xcrn0g04.png
|
||||
71e4b2826f61556eda39f3a93c8769b14d3ac90f135177b9373061199dbef39a xcsn0g01.png
|
||||
c1287690808e809dc5d4fb89d8a7fd69ed93521f290abd42021ca00a061a1ba4 xd0n2c08.png
|
||||
00b53c3bbd0641454521b982bc6f6bcfda7c91f1874cefb3a9bac37d80a1a269 xd3n2c08.png
|
||||
16e5b40fb2600db1af20fb79ff715c2869255e2d4bef20702f16534e5dd6a847 xd9n2c08.png
|
||||
f9d1fb2a708703518368c392c74765a6e3e5b49dbb9717df3974452291032df9 xdtn0g01.png
|
||||
318864720c8fc0dbe4884035f2183cc3bd3d92ec60d447879982942600e9fe2e xhdn0g08.png
|
||||
968fd21abb8acf40fbca90676de3abcb3a6e35b01ba7a3b9190184eafb99c83d xlfn0g04.png
|
||||
776701227c7094dd10b78f508430b8ea4f03471d072096382cbcca628dea1d2b xs1n0g01.png
|
||||
9dd7e93ba9211f0caee09d8f12e37742936c469f45fcad21e577c9f0640cf99e xs2n0g01.png
|
||||
166c8633d116d1c26631cb98f3a75340cf4385fa7ae6a67913bc78e709bcb30d xs4n0g01.png
|
||||
7a380568beeac969908196ac89cd2347c96ac2f26fdc2b8e0314b62c59f0e308 xs7n0g01.png
|
||||
e4767d3259e1b331c9ece9fb07fc30f385879ac12b3cd0e1cb923f3bfac81dcf z00n2c08.png
|
||||
939abfc6e0a3e349bb5bcd8c4e427a6cdb2c7e0c23a773aefa1c4fc9f07e4cb4 z03n2c08.png
|
||||
21652fe42f472acd83dcb207806add5737db0020b21d6b38b0a00be3e9e37990 z06n2c08.png
|
||||
98d90a7e61aa1a9ac9d99af44dd25c70cd5a7b4a11a85da60f82923e18a78f9f z09n2c08.png
|
||||
|
@@ -318,10 +318,112 @@ fn refuses_cubemaps_arrays_and_volumes() {
|
||||
unsupported(&dx10(4, 4, 71, 3, 0, 6), "array");
|
||||
unsupported(&dx10(4, 4, 71, 4, 0, 1), "2D");
|
||||
unsupported(&dx10(4, 4, 98, 3, 0, 1), "98"); // BC7_UNORM
|
||||
unsupported(&compressed(4, 4, b"ATI2"), "ATI2");
|
||||
unsupported(&compressed(4, 4, b"ATI3"), "ATI3");
|
||||
unsupported(&compressed(4, 4, b"DXT2"), "premultiplied");
|
||||
}
|
||||
|
||||
/// A BC4 block of 200 everywhere (eight-value mode, a0 = 200 > a1 = 50, every index 0).
|
||||
const BC4_200: [u8; 8] = [0xc8, 0x32, 0, 0, 0, 0, 0, 0];
|
||||
/// A value block of 250 everywhere (six-value mode, a0 = 10 <= a1 = 250, every index 1).
|
||||
const VALUES_250: [u8; 8] = [0x0a, 0xfa, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24];
|
||||
|
||||
/// A DX10 file of one 1x1 level of `dxgi` with DDS_ALPHA_MODE `alpha_mode` (miscFlags2) and zeroed pixel data.
|
||||
fn dx10_alpha_mode(dxgi: u32, alpha_mode: u32) -> Vec<u8> {
|
||||
let mut b = dx10(1, 1, dxgi, 3, 0, 1);
|
||||
let n = b.len();
|
||||
b[n - 4..].copy_from_slice(&alpha_mode.to_le_bytes());
|
||||
b.extend([0u8; 16]);
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_premultiplied_alpha_dx10_textures() {
|
||||
// RGBA, BGRA (typeless, UNORM, sRGB) and BC2/BC3: alpha mode 2 is premultiplied, like DXT2/DXT4.
|
||||
for dxgi in [27, 28, 29, 87, 90, 91, 73, 74, 75, 76, 77, 78] {
|
||||
match decode_as(Format::Dds, &dx10_alpha_mode(dxgi, 2)) {
|
||||
Err(CodecError::Unsupported { reason, .. }) => assert!(reason.contains("premultiplied"), "{dxgi}: {reason}"),
|
||||
other => panic!("DXGI {dxgi}: {:?}", other.map(|_| ())),
|
||||
}
|
||||
}
|
||||
// Straight, unknown, opaque and custom alpha modes, and formats without alpha, still decode.
|
||||
for dxgi in [28, 87, 74, 77] {
|
||||
for mode in [0, 1, 3, 4] {
|
||||
assert!(decode_as(Format::Dds, &dx10_alpha_mode(dxgi, mode)).is_ok(), "{dxgi} mode {mode}");
|
||||
}
|
||||
}
|
||||
for dxgi in [88, 71, 80, 83] {
|
||||
assert!(decode_as(Format::Dds, &dx10_alpha_mode(dxgi, 2)).is_ok(), "{dxgi}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decodes_bc4_as_gray_from_every_name() {
|
||||
// 5×3: two blocks across, one down; the second block's texels outside the image are dropped.
|
||||
let blocks = [BC4_200, BC4_200].concat();
|
||||
let mut files = vec![];
|
||||
for fourcc in [b"ATI1", b"BC4U"] {
|
||||
let mut b = compressed(5, 3, fourcc);
|
||||
b.extend(&blocks);
|
||||
files.push((String::from_utf8_lossy(fourcc).into_owned(), b));
|
||||
}
|
||||
for dxgi in [79, 80] {
|
||||
let mut b = dx10(5, 3, dxgi, 3, 0, 1); // BC4_TYPELESS, BC4_UNORM
|
||||
b.extend(&blocks);
|
||||
files.push((format!("DXGI {dxgi}"), b));
|
||||
}
|
||||
for (name, b) in files {
|
||||
let im = decode(&b).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
assert_eq!((im.dimensions(), im.layout()), ((5, 3), ChannelLayout::Gray), "{name}");
|
||||
assert_eq!(im.data(), &[200; 15], "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decodes_bc5_as_red_and_green_with_blue_zero() {
|
||||
let block = [BC4_200, VALUES_250].concat();
|
||||
let mut files = vec![];
|
||||
// ATI2 is BC5 as Microsoft reads it: red in the first block, not swapped as FFmpeg does.
|
||||
for fourcc in [b"ATI2", b"BC5U"] {
|
||||
let mut b = compressed(3, 2, fourcc);
|
||||
b.extend(&block);
|
||||
files.push((String::from_utf8_lossy(fourcc).into_owned(), b));
|
||||
}
|
||||
// BC5_TYPELESS (what Pillow writes) and BC5_UNORM.
|
||||
for dxgi in [82, 83] {
|
||||
let mut b = dx10(3, 2, dxgi, 3, 0, 1);
|
||||
b.extend(&block);
|
||||
files.push((format!("DXGI {dxgi}"), b));
|
||||
}
|
||||
for (name, b) in files {
|
||||
let im = decode(&b).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
assert_eq!((im.dimensions(), im.layout()), ((3, 2), ChannelLayout::Rgb), "{name}");
|
||||
assert!(im.data().chunks(3).all(|p| p == [200, 250, 0]), "{name}: {:?}", &im.data()[..3]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_signed_bc4_and_bc5() {
|
||||
for mut b in [compressed(4, 4, b"BC4S"), compressed(4, 4, b"BC5S"), dx10(4, 4, 81, 3, 0, 1), dx10(4, 4, 84, 3, 0, 1)] {
|
||||
b.extend([0; 16]);
|
||||
match decode_as(Format::Dds, &b) {
|
||||
Err(CodecError::Unsupported { reason, .. }) => assert!(reason.contains("SNORM"), "{reason}"),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truncated_bc4_and_bc5_data_is_refused() {
|
||||
let mut b = dx10(5, 5, 83, 3, 0, 1); // four 16-byte blocks
|
||||
b.extend([0x5a; 64]);
|
||||
assert!(decode(&b).is_ok());
|
||||
assert!(matches!(decode_as(Format::Dds, &b[..b.len() - 1]), Err(CodecError::Malformed { .. })));
|
||||
let mut b = compressed(5, 5, b"ATI1"); // four 8-byte blocks
|
||||
b.extend([0x5a; 32]);
|
||||
assert!(decode(&b).is_ok());
|
||||
assert!(matches!(decode_as(Format::Dds, &b[..b.len() - 1]), Err(CodecError::Malformed { .. })));
|
||||
}
|
||||
|
||||
/// Face declarations matter even when the general cube flag is absent; padding does not.
|
||||
#[test]
|
||||
fn source_probe_distinguishes_extra_faces_from_single_images_and_padding() {
|
||||
|
||||
@@ -0,0 +1,520 @@
|
||||
//! Byte-for-byte oracle for the DDS reader and writer: SHA-256 digests of what the writer makes
|
||||
//! for uncompressed, BC1, BC2 and BC3 textures, with and without mip chains, from deterministic
|
||||
//! synthetic images, and of what the reader decodes from those files and from hand-built files
|
||||
//! in the other stored layouts. The digests were taken from the code before the block encoder and
|
||||
//! decoder were sped up; any change to them is a change of output.
|
||||
//!
|
||||
//! On a mismatch the test prints every digest it computed in the form of [`PINNED`], so a new
|
||||
//! table can be pasted in once a change of output is intended.
|
||||
|
||||
use craft_image_codecs::{ChannelLayout, DdsCompression, DdsOptions, EncodeOptions, Format, Image, decode, encode};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// `(case, SHA-256)`, taken from the code before the speed-ups.
|
||||
const PINNED: &[(&str, &str)] = &[
|
||||
("Rgba-517x389-none-mips0-encode", "e2aee5dcc86cc36e9735cb75e61852324210960092bfb2f2aec6cee9ba54ad16"),
|
||||
("Rgba-517x389-none-mips0-decode", "e0d9e319f260fa29481495313cfa8c3d224a27ad311e7aabd32f7cda8dfb81d2"),
|
||||
("Rgba-517x389-none-mips1-encode", "7611e8174d32962c9643e8f3208b8f30eba2cb85cfe16538c4321e419f3a98ce"),
|
||||
("Rgba-517x389-none-mips1-decode", "e0d9e319f260fa29481495313cfa8c3d224a27ad311e7aabd32f7cda8dfb81d2"),
|
||||
("Rgba-517x389-bc1-mips0-encode", "b6883d729a1eebbdc96176c9264754378d4f7f6bc19d355a12419c0ccfd3ac2a"),
|
||||
("Rgba-517x389-bc1-mips0-decode", "e23704d5f72ba4f2c63d815d5bff3d4c79433fa38122e1e21f1003fa1b12476a"),
|
||||
("Rgba-517x389-bc1-mips1-encode", "554ed42ba6b7c206f779324670629538d8ce12d85ef495ad36954aae2b952917"),
|
||||
("Rgba-517x389-bc1-mips1-decode", "e23704d5f72ba4f2c63d815d5bff3d4c79433fa38122e1e21f1003fa1b12476a"),
|
||||
("Rgba-517x389-bc2-mips0-encode", "473f389b464d2f74b05d44ab2d8c31d4d4cd64648d389e4fe27c27491003821b"),
|
||||
("Rgba-517x389-bc2-mips0-decode", "9d81c15d7f5f0dbc897063726fac6e2f3863818346e1c878326c22ed332ae328"),
|
||||
("Rgba-517x389-bc2-mips1-encode", "1eb8c1a73cb4e6965c60a5ca4322fb66f071cad7439d97d77dbea1a46231724a"),
|
||||
("Rgba-517x389-bc2-mips1-decode", "9d81c15d7f5f0dbc897063726fac6e2f3863818346e1c878326c22ed332ae328"),
|
||||
("Rgba-517x389-bc3-mips0-encode", "0b133915d5ac0376f8b4425cb2dd4a1ace609cf7c1d635be0ff46a37529363e2"),
|
||||
("Rgba-517x389-bc3-mips0-decode", "9c5aeecab34af4c04dd603cf5c379060e6615c07df05ae4e93058bca13a61bc9"),
|
||||
("Rgba-517x389-bc3-mips1-encode", "130e5657e870ee5c03bcfcc2c5e2befbc8a67fc0df1b7e7b71dbb67cc3f0b5e7"),
|
||||
("Rgba-517x389-bc3-mips1-decode", "9c5aeecab34af4c04dd603cf5c379060e6615c07df05ae4e93058bca13a61bc9"),
|
||||
("Rgb-517x389-none-mips0-encode", "6df9ec01a5ae0a8e0fe3b563a7ff670477446682cadd21c24ca5e0cff2b41ed8"),
|
||||
("Rgb-517x389-none-mips0-decode", "7f181edc81e2e38d56c2ed5c81edf480d52caa746e0bef90f0070e171ead89d1"),
|
||||
("Rgb-517x389-none-mips1-encode", "5a48af2cfa7d48455fe49105fc5d0173c6f4fd8187483af923f0af2fbf0af9ef"),
|
||||
("Rgb-517x389-none-mips1-decode", "7f181edc81e2e38d56c2ed5c81edf480d52caa746e0bef90f0070e171ead89d1"),
|
||||
("Rgb-517x389-bc1-mips0-encode", "1e8bf3d0ba485d0892ce771698868bf7029d2c4e63057f327ae3ab39bc57cd4a"),
|
||||
("Rgb-517x389-bc1-mips0-decode", "96feb4a7a3b7416ebc0d5e42271a9d6304131e6cbed25f745d3eef6a40279f8d"),
|
||||
("Rgb-517x389-bc1-mips1-encode", "76f866a8bbb0b3cad335c604cba97d173d01dcbfff4c8930a1d8af7c60924494"),
|
||||
("Rgb-517x389-bc1-mips1-decode", "96feb4a7a3b7416ebc0d5e42271a9d6304131e6cbed25f745d3eef6a40279f8d"),
|
||||
("Rgb-517x389-bc2-mips0-encode", "a8eaab96cf9c6f7926526069ed71f5df8c7f7d43f3ef40a85f1403639c09ac97"),
|
||||
("Rgb-517x389-bc2-mips0-decode", "8e00407a44922477b8d7c05b371f05c18ac3471095990b44aba438bf39db57b2"),
|
||||
("Rgb-517x389-bc2-mips1-encode", "d6fee09087b9a4c9a055051e7aa212a9a0a3b2660e1dfa49697c6fc9754a9aae"),
|
||||
("Rgb-517x389-bc2-mips1-decode", "8e00407a44922477b8d7c05b371f05c18ac3471095990b44aba438bf39db57b2"),
|
||||
("Rgb-517x389-bc3-mips0-encode", "2e177ad42c89f6662ebf2b834b691e10bfaea32a565b740e1bd48c7e4b39cb68"),
|
||||
("Rgb-517x389-bc3-mips0-decode", "8e00407a44922477b8d7c05b371f05c18ac3471095990b44aba438bf39db57b2"),
|
||||
("Rgb-517x389-bc3-mips1-encode", "0b53960adcf0844b47ed5927862901c95fb632af4e85cd94b5ceae59eccd78cd"),
|
||||
("Rgb-517x389-bc3-mips1-decode", "8e00407a44922477b8d7c05b371f05c18ac3471095990b44aba438bf39db57b2"),
|
||||
("GrayA-517x389-none-mips0-encode", "3f8e56201cb76990b3e25b62631666ac113a5340877acd57cdcb1c229127d3f4"),
|
||||
("GrayA-517x389-none-mips0-decode", "43503ba84a7d7579b1ebbe6ba522146f5e63f0116f8dd0eba095364cfba37c5d"),
|
||||
("GrayA-517x389-none-mips1-encode", "6282214743c82e3f74f2347c859ecfd79447cfbc87a2016a238e714f2d150b87"),
|
||||
("GrayA-517x389-none-mips1-decode", "43503ba84a7d7579b1ebbe6ba522146f5e63f0116f8dd0eba095364cfba37c5d"),
|
||||
("GrayA-517x389-bc1-mips0-encode", "32d7065b40986561349f0d76db148b1b62afedb1ce8be6a4e0b209c60c9d861f"),
|
||||
("GrayA-517x389-bc1-mips0-decode", "1cc1cbd355033b5674cc1000b879d4dc8cbb4b53b8dd38d90d8b439550e2be7c"),
|
||||
("GrayA-517x389-bc1-mips1-encode", "4b5e5c9db8ec9847b55e0c51b2e1c1cb41bb277517ef5a7bf59ace7581a7696a"),
|
||||
("GrayA-517x389-bc1-mips1-decode", "1cc1cbd355033b5674cc1000b879d4dc8cbb4b53b8dd38d90d8b439550e2be7c"),
|
||||
("GrayA-517x389-bc2-mips0-encode", "91fd37653f090668328d8feff0407c5998ef2ab96d220bd49e311faf7d768e00"),
|
||||
("GrayA-517x389-bc2-mips0-decode", "ac73339602e5062f78cf76694bde0a4ca538b355170eb424f0bd1cf7d2c12096"),
|
||||
("GrayA-517x389-bc2-mips1-encode", "05d77863968b0086ddf4a1c21ccbc8e1f2d9638ed4dffd114107a1d793ea3311"),
|
||||
("GrayA-517x389-bc2-mips1-decode", "ac73339602e5062f78cf76694bde0a4ca538b355170eb424f0bd1cf7d2c12096"),
|
||||
("GrayA-517x389-bc3-mips0-encode", "bb4057b77e0fa2959d6e79b77ff67090c9dd4d08f3c105b57ebbaea214ffc8c7"),
|
||||
("GrayA-517x389-bc3-mips0-decode", "fdcbd158c32404d09cf1ee38005b2870882e620bcd67c77332d492d07099d665"),
|
||||
("GrayA-517x389-bc3-mips1-encode", "65b2021ea2a385b349d2a6f3a44305e3655f35f3bee39fba5d177bb8c7a5d66a"),
|
||||
("GrayA-517x389-bc3-mips1-decode", "fdcbd158c32404d09cf1ee38005b2870882e620bcd67c77332d492d07099d665"),
|
||||
("Gray-517x389-none-mips0-encode", "fc6cf28e9220780d752ac3be0c9b9bf75412dbea4a54ab603577f78000f235d3"),
|
||||
("Gray-517x389-none-mips0-decode", "13df79103435da32999dff6deac57b02a872aef3fe7dafe580625a554258db30"),
|
||||
("Gray-517x389-none-mips1-encode", "e6f1bb2eb28353a1ead1b72e6e0c78f9490f9e933ee2fe464044ba2804d0a595"),
|
||||
("Gray-517x389-none-mips1-decode", "13df79103435da32999dff6deac57b02a872aef3fe7dafe580625a554258db30"),
|
||||
("Gray-517x389-bc1-mips0-encode", "ba3b1a2567ff1571dfb855b7c5ff8e2da276eb80f5f97db0fae661449bb51822"),
|
||||
("Gray-517x389-bc1-mips0-decode", "7df1ebd46f395e515af2763a0bf7189072a64f20ff811973098ea109df1ed832"),
|
||||
("Gray-517x389-bc1-mips1-encode", "e34896e52b393aa3035e641b43881df1a25ae4aa6261c9bdca34889ec42ea6ac"),
|
||||
("Gray-517x389-bc1-mips1-decode", "7df1ebd46f395e515af2763a0bf7189072a64f20ff811973098ea109df1ed832"),
|
||||
("Gray-517x389-bc2-mips0-encode", "2ebe06ad3ca05dc993a60c58dbae1d36c56516147176b4799648f534e9318b3a"),
|
||||
("Gray-517x389-bc2-mips0-decode", "2adde466f9a4c2c4905d50490bbed4cd5c4de0e3b951d63028702f7ab51d7927"),
|
||||
("Gray-517x389-bc2-mips1-encode", "8730c500b41e9b628cab1c789b2e2a2e4a4ad0350b6c3faaca5e3acd8b423ca7"),
|
||||
("Gray-517x389-bc2-mips1-decode", "2adde466f9a4c2c4905d50490bbed4cd5c4de0e3b951d63028702f7ab51d7927"),
|
||||
("Gray-517x389-bc3-mips0-encode", "e8b62246e29504bbbc92f1c5344846577232e2c12f5c6ab6fae68199bbcf5c3a"),
|
||||
("Gray-517x389-bc3-mips0-decode", "2adde466f9a4c2c4905d50490bbed4cd5c4de0e3b951d63028702f7ab51d7927"),
|
||||
("Gray-517x389-bc3-mips1-encode", "2b1122c5091c8a62c897fa4a133b2a21d19ec14a3ec2c5e0d4855570824e6211"),
|
||||
("Gray-517x389-bc3-mips1-decode", "2adde466f9a4c2c4905d50490bbed4cd5c4de0e3b951d63028702f7ab51d7927"),
|
||||
("Rgba-1x1-none-mips0-encode", "c059322936202ed846ae95243325c1756b3ca2734a310b9b58e957e7f6ecb65c"),
|
||||
("Rgba-1x1-none-mips0-decode", "ac6d8249b868a4df487ad3d4bc2bffa4ec32afed5bb89bcb916dc390872c00a4"),
|
||||
("Rgba-1x1-none-mips1-encode", "c059322936202ed846ae95243325c1756b3ca2734a310b9b58e957e7f6ecb65c"),
|
||||
("Rgba-1x1-none-mips1-decode", "ac6d8249b868a4df487ad3d4bc2bffa4ec32afed5bb89bcb916dc390872c00a4"),
|
||||
("Rgba-1x1-bc1-mips0-encode", "b128a04da98b6d855fd98c6908f9ba47d0acf2e79c1b39d0cf3e5787ee52b23c"),
|
||||
("Rgba-1x1-bc1-mips0-decode", "2c1567f9329e7d7046ebcba26c8b66a872a36d2140c47be6d8ee3fd1bdc7aa26"),
|
||||
("Rgba-1x1-bc1-mips1-encode", "b128a04da98b6d855fd98c6908f9ba47d0acf2e79c1b39d0cf3e5787ee52b23c"),
|
||||
("Rgba-1x1-bc1-mips1-decode", "2c1567f9329e7d7046ebcba26c8b66a872a36d2140c47be6d8ee3fd1bdc7aa26"),
|
||||
("Rgba-1x1-bc2-mips0-encode", "d53707f0da90291d459df619c204c09d0e5537b96055b7c5a7eebb164965a30c"),
|
||||
("Rgba-1x1-bc2-mips0-decode", "e41eb1f8866a8a844c5627ec9e119ea9b5b2c2afb62c2cc40d0b3463e191181f"),
|
||||
("Rgba-1x1-bc2-mips1-encode", "d53707f0da90291d459df619c204c09d0e5537b96055b7c5a7eebb164965a30c"),
|
||||
("Rgba-1x1-bc2-mips1-decode", "e41eb1f8866a8a844c5627ec9e119ea9b5b2c2afb62c2cc40d0b3463e191181f"),
|
||||
("Rgba-1x1-bc3-mips0-encode", "b7a5261aeaa590ee27d74e1ec40688cebfd95a8b32bad510dcf4889659bced99"),
|
||||
("Rgba-1x1-bc3-mips0-decode", "ac6d8249b868a4df487ad3d4bc2bffa4ec32afed5bb89bcb916dc390872c00a4"),
|
||||
("Rgba-1x1-bc3-mips1-encode", "b7a5261aeaa590ee27d74e1ec40688cebfd95a8b32bad510dcf4889659bced99"),
|
||||
("Rgba-1x1-bc3-mips1-decode", "ac6d8249b868a4df487ad3d4bc2bffa4ec32afed5bb89bcb916dc390872c00a4"),
|
||||
("Gray-1x1-none-mips0-encode", "9acce63d02641780f46268c15cb62bdf84b68edc091801d02f62d8840b90e76f"),
|
||||
("Gray-1x1-none-mips0-decode", "5ef973abd913579530066461f86da91115474c93b5a6cf1b73327feeb3650b83"),
|
||||
("Gray-1x1-none-mips1-encode", "9acce63d02641780f46268c15cb62bdf84b68edc091801d02f62d8840b90e76f"),
|
||||
("Gray-1x1-none-mips1-decode", "5ef973abd913579530066461f86da91115474c93b5a6cf1b73327feeb3650b83"),
|
||||
("Gray-1x1-bc1-mips0-encode", "ffec653603d347468446a15fe4101fda9cb34efb48dc69a8d0f403ce2e2fd9d7"),
|
||||
("Gray-1x1-bc1-mips0-decode", "bf04357a38e992a2513e373d00f664b687669a14e1405a2d1b95fb0de6e9a89b"),
|
||||
("Gray-1x1-bc1-mips1-encode", "ffec653603d347468446a15fe4101fda9cb34efb48dc69a8d0f403ce2e2fd9d7"),
|
||||
("Gray-1x1-bc1-mips1-decode", "bf04357a38e992a2513e373d00f664b687669a14e1405a2d1b95fb0de6e9a89b"),
|
||||
("Gray-1x1-bc2-mips0-encode", "3c36aac2c17a7aad99b2c1fa0f4e5b256a9b4421c38406f61961b09c64290178"),
|
||||
("Gray-1x1-bc2-mips0-decode", "bf04357a38e992a2513e373d00f664b687669a14e1405a2d1b95fb0de6e9a89b"),
|
||||
("Gray-1x1-bc2-mips1-encode", "3c36aac2c17a7aad99b2c1fa0f4e5b256a9b4421c38406f61961b09c64290178"),
|
||||
("Gray-1x1-bc2-mips1-decode", "bf04357a38e992a2513e373d00f664b687669a14e1405a2d1b95fb0de6e9a89b"),
|
||||
("Gray-1x1-bc3-mips0-encode", "73704fca801476ab72bf69b80a395de711e9a3fa4f476ce5481ae3858f844922"),
|
||||
("Gray-1x1-bc3-mips0-decode", "bf04357a38e992a2513e373d00f664b687669a14e1405a2d1b95fb0de6e9a89b"),
|
||||
("Gray-1x1-bc3-mips1-encode", "73704fca801476ab72bf69b80a395de711e9a3fa4f476ce5481ae3858f844922"),
|
||||
("Gray-1x1-bc3-mips1-decode", "bf04357a38e992a2513e373d00f664b687669a14e1405a2d1b95fb0de6e9a89b"),
|
||||
("Rgba-2x3-none-mips0-encode", "1f641b8e1cc01924b0d1a06d2d81ad22c759b44a4f640a83ba6339446e13fc6c"),
|
||||
("Rgba-2x3-none-mips0-decode", "af815e7ba5ce6369171335ae94e553524db701f94d152b903f220ee64b9373a6"),
|
||||
("Rgba-2x3-none-mips1-encode", "9be390b308b0961125828ca53894a87101983eafaf54e3c7e3da7b1f992fb518"),
|
||||
("Rgba-2x3-none-mips1-decode", "af815e7ba5ce6369171335ae94e553524db701f94d152b903f220ee64b9373a6"),
|
||||
("Rgba-2x3-bc1-mips0-encode", "743a3d25313924d68732ab399ed92c8e3f693ef26a415a12532918b80db085c4"),
|
||||
("Rgba-2x3-bc1-mips0-decode", "570f9feaf2d322a568b2a87ca652aa0606ff96cde281e24d247d071a9dc4e827"),
|
||||
("Rgba-2x3-bc1-mips1-encode", "711b0088c7c8083760921c3620d9d1adc02d47b5c3b0eb9e674d974fd1d6d641"),
|
||||
("Rgba-2x3-bc1-mips1-decode", "570f9feaf2d322a568b2a87ca652aa0606ff96cde281e24d247d071a9dc4e827"),
|
||||
("Rgba-2x3-bc2-mips0-encode", "b4facaf715dd8208fe02961fb99584b58c219117a99f2b1d15d10a556a9e5251"),
|
||||
("Rgba-2x3-bc2-mips0-decode", "66112c3066ef59936784fa938c26eb0e86772da586442237de5336c48558afbe"),
|
||||
("Rgba-2x3-bc2-mips1-encode", "cad117a2ddd6fe91876efd1dd0b80da0b393f3af21209efc3c1b0f165606a129"),
|
||||
("Rgba-2x3-bc2-mips1-decode", "66112c3066ef59936784fa938c26eb0e86772da586442237de5336c48558afbe"),
|
||||
("Rgba-2x3-bc3-mips0-encode", "b68ced41c6b33037f08b74c492da5688e9d80555c5843f9f323a74d7c86e114e"),
|
||||
("Rgba-2x3-bc3-mips0-decode", "051b60ea47094987d71180aeaa00b3f1b5427429e54812ea28b40f8e945044c8"),
|
||||
("Rgba-2x3-bc3-mips1-encode", "88e0fd6d04c896880d03731d6df1528f22290c1738b303eb2b09fe84d7882a64"),
|
||||
("Rgba-2x3-bc3-mips1-decode", "051b60ea47094987d71180aeaa00b3f1b5427429e54812ea28b40f8e945044c8"),
|
||||
("Gray-2x3-none-mips0-encode", "7e9d26894ca9a800b93f5dae0e5b58b18a6cbcaea56eacc657aba40a1933c476"),
|
||||
("Gray-2x3-none-mips0-decode", "d21c9cddccb970575eba36093410245f0a0fb15049fc96311874191f868de0d5"),
|
||||
("Gray-2x3-none-mips1-encode", "d2ee41ea49462e1d7be568cfcbf867c6395646710ba321c2dac9db319294bb5e"),
|
||||
("Gray-2x3-none-mips1-decode", "d21c9cddccb970575eba36093410245f0a0fb15049fc96311874191f868de0d5"),
|
||||
("Gray-2x3-bc1-mips0-encode", "000d5d9121042f7b88411d8e08a548a2c804b8b4b73b40bf317cff61899a5445"),
|
||||
("Gray-2x3-bc1-mips0-decode", "1a8f46dd535383398fbeebe5fdfca9bb256fa3b3a7b8552af34b67b09865e89d"),
|
||||
("Gray-2x3-bc1-mips1-encode", "07346ec09eb8d9b489e7dd50bd73851342205594ac985544bfe58b6bda73b21b"),
|
||||
("Gray-2x3-bc1-mips1-decode", "1a8f46dd535383398fbeebe5fdfca9bb256fa3b3a7b8552af34b67b09865e89d"),
|
||||
("Gray-2x3-bc2-mips0-encode", "5db43dcd4adec962a7a12c6f8da8bf05d3dc2e3d608ca3fa341e36b43c218c3d"),
|
||||
("Gray-2x3-bc2-mips0-decode", "afabd75898a95baac868e9e14905c2d89e90767750217e4c9ac84b1caeef41bc"),
|
||||
("Gray-2x3-bc2-mips1-encode", "3effae05c47854dfb5f20ed12e2c1588236464f17fbf5dd13e61958e5097a796"),
|
||||
("Gray-2x3-bc2-mips1-decode", "afabd75898a95baac868e9e14905c2d89e90767750217e4c9ac84b1caeef41bc"),
|
||||
("Gray-2x3-bc3-mips0-encode", "11c48dce5b7545cf3eafd1f01fc6b977b13cb7c7e8f2ef7ea1406a8f04b86cf9"),
|
||||
("Gray-2x3-bc3-mips0-decode", "afabd75898a95baac868e9e14905c2d89e90767750217e4c9ac84b1caeef41bc"),
|
||||
("Gray-2x3-bc3-mips1-encode", "6b7540afc583554e70f4131b4a0d8648eed65100293ab9b7060afcbd33751e64"),
|
||||
("Gray-2x3-bc3-mips1-decode", "afabd75898a95baac868e9e14905c2d89e90767750217e4c9ac84b1caeef41bc"),
|
||||
("Rgba-3x2-none-mips0-encode", "e821c1620e4e53588908268da45702924911ed756f3257cb0a21727748b736a6"),
|
||||
("Rgba-3x2-none-mips0-decode", "d4583449852070512fa3cb16c5132834ccee2f9dd3a6c0d6c8fa5bbbc2935e8d"),
|
||||
("Rgba-3x2-none-mips1-encode", "f79a699612ef8d8347a5e83af2fd9ee915eda35388bc86b4243b265f988fc3d8"),
|
||||
("Rgba-3x2-none-mips1-decode", "d4583449852070512fa3cb16c5132834ccee2f9dd3a6c0d6c8fa5bbbc2935e8d"),
|
||||
("Rgba-3x2-bc1-mips0-encode", "1c106b532f6afc132538b2bb2c1eb9e6bb075a448d19b6af2c67b4c31415e3b2"),
|
||||
("Rgba-3x2-bc1-mips0-decode", "f0e63ce55598b6c58c601a5cf3415522113181a08bc28f4d8cd499d160352cdd"),
|
||||
("Rgba-3x2-bc1-mips1-encode", "23d86eba138f7c4492f9955dd0a29eb1a675d69f1e612b54e783837d9414cb14"),
|
||||
("Rgba-3x2-bc1-mips1-decode", "f0e63ce55598b6c58c601a5cf3415522113181a08bc28f4d8cd499d160352cdd"),
|
||||
("Rgba-3x2-bc2-mips0-encode", "74a68d7b1cc0173f1e8a6e0f6101ffa010757df0434fcf5636db808ca20b341e"),
|
||||
("Rgba-3x2-bc2-mips0-decode", "bc63bba15c1bbe19cdef66535870c7dfeeae26a4686557e1530ae64a2b2253a5"),
|
||||
("Rgba-3x2-bc2-mips1-encode", "d28d7a4a7ee17d0f58f27ebef8d682a7fed42778a60e09186af523198a2f3562"),
|
||||
("Rgba-3x2-bc2-mips1-decode", "bc63bba15c1bbe19cdef66535870c7dfeeae26a4686557e1530ae64a2b2253a5"),
|
||||
("Rgba-3x2-bc3-mips0-encode", "fa0a02ba9822a007f1654d618b5225332f3934e5f07c51f8ca474e26658e2c45"),
|
||||
("Rgba-3x2-bc3-mips0-decode", "ee0221751e1d96bf76552df65a7e54d7711f834cf0431fd17a3a6542473b4ceb"),
|
||||
("Rgba-3x2-bc3-mips1-encode", "3a3c51f596a82ae666c6157da4266c3330e8e2e0744947e0ce663deb66e67ad6"),
|
||||
("Rgba-3x2-bc3-mips1-decode", "ee0221751e1d96bf76552df65a7e54d7711f834cf0431fd17a3a6542473b4ceb"),
|
||||
("Gray-3x2-none-mips0-encode", "6e1e49ee238e40108f1e934946b0d2498eb97f6824a82d4d71011759a58b83a4"),
|
||||
("Gray-3x2-none-mips0-decode", "e333fde639747f66aa4d74dbeae648566d6735ecc47de220e07b9da351e1bf37"),
|
||||
("Gray-3x2-none-mips1-encode", "906e16afa18db0290bec758a1a124de7a99255871344d462f797db54dbd30b4b"),
|
||||
("Gray-3x2-none-mips1-decode", "e333fde639747f66aa4d74dbeae648566d6735ecc47de220e07b9da351e1bf37"),
|
||||
("Gray-3x2-bc1-mips0-encode", "df204b170cd24f0375772d65b4f0548a824a4602c453cf891c9cc4aafc4b32ad"),
|
||||
("Gray-3x2-bc1-mips0-decode", "869a8202b3721a8d2bf232e75e9a91a271cf2ebad85c8df6a5260cb9c9b6b1ab"),
|
||||
("Gray-3x2-bc1-mips1-encode", "d06f38b5c40156888fe2ea04343f46d4753a80f83f63d80b3fd7ce82c5d7fe94"),
|
||||
("Gray-3x2-bc1-mips1-decode", "869a8202b3721a8d2bf232e75e9a91a271cf2ebad85c8df6a5260cb9c9b6b1ab"),
|
||||
("Gray-3x2-bc2-mips0-encode", "1832e5006137ae1583d34ba1bfab9c7b85f55791996f7cdf21ed799f3939c4f4"),
|
||||
("Gray-3x2-bc2-mips0-decode", "869a8202b3721a8d2bf232e75e9a91a271cf2ebad85c8df6a5260cb9c9b6b1ab"),
|
||||
("Gray-3x2-bc2-mips1-encode", "41d49c9cce6cbbdf1676033a9233ed774f339d92e8159d1d1b0cbc8503cfe72b"),
|
||||
("Gray-3x2-bc2-mips1-decode", "869a8202b3721a8d2bf232e75e9a91a271cf2ebad85c8df6a5260cb9c9b6b1ab"),
|
||||
("Gray-3x2-bc3-mips0-encode", "377e3d02919641d634bbe02cadb513237fcd90f540b8769c5e2a214d5ccf05e4"),
|
||||
("Gray-3x2-bc3-mips0-decode", "869a8202b3721a8d2bf232e75e9a91a271cf2ebad85c8df6a5260cb9c9b6b1ab"),
|
||||
("Gray-3x2-bc3-mips1-encode", "70b03c1901946a24abf34c60dd7bd9cc124df43a251a82622c15d56b0e2b2588"),
|
||||
("Gray-3x2-bc3-mips1-decode", "869a8202b3721a8d2bf232e75e9a91a271cf2ebad85c8df6a5260cb9c9b6b1ab"),
|
||||
("Rgba-5x5-none-mips0-encode", "be7677f4c86d5f3c0ba75ec04d36bcfd708bca44c9f6720c4b7494c290014491"),
|
||||
("Rgba-5x5-none-mips0-decode", "00dc5f1020a7de3a3bc5ee21e7a767d09dab9c9831e840290277af90d1e1e3be"),
|
||||
("Rgba-5x5-none-mips1-encode", "284c04f628c256ba546815e46df2b837ee997d90834b8a0f095f20e17ba36102"),
|
||||
("Rgba-5x5-none-mips1-decode", "00dc5f1020a7de3a3bc5ee21e7a767d09dab9c9831e840290277af90d1e1e3be"),
|
||||
("Rgba-5x5-bc1-mips0-encode", "a5350786ccbd004a88ca541c0d4d7cdf313f71fec9485a45acd380f318846435"),
|
||||
("Rgba-5x5-bc1-mips0-decode", "26559d0fc43534fad7318b66672ef9de924b6408b2528c00cb6be76a56a94654"),
|
||||
("Rgba-5x5-bc1-mips1-encode", "67e06000b2ee88a6e8e749b20ee6ec0016d294f2fba57e9773aea3a7addd1883"),
|
||||
("Rgba-5x5-bc1-mips1-decode", "26559d0fc43534fad7318b66672ef9de924b6408b2528c00cb6be76a56a94654"),
|
||||
("Rgba-5x5-bc2-mips0-encode", "6cf909177531b9ed88be4ffd031055a7b1cbcfab0c6082ca33913720d631f834"),
|
||||
("Rgba-5x5-bc2-mips0-decode", "060ad06944e973f57c866137f9bd8c903a4edd30af275f9ee92fadff54a0a4bb"),
|
||||
("Rgba-5x5-bc2-mips1-encode", "0590d1aa5b074abb89262432a3b6b5c3ff12edca0d454069dadfe20be690e727"),
|
||||
("Rgba-5x5-bc2-mips1-decode", "060ad06944e973f57c866137f9bd8c903a4edd30af275f9ee92fadff54a0a4bb"),
|
||||
("Rgba-5x5-bc3-mips0-encode", "8d24e90ef90f819353e1bbbb1ab1163463dbdf8d9aaeb89b3acbc8cf2d3dd625"),
|
||||
("Rgba-5x5-bc3-mips0-decode", "d3238486581875abcd37dfbe03e8fbea7aa4fcadb1fef866899deafb67ac38f9"),
|
||||
("Rgba-5x5-bc3-mips1-encode", "2c331cbc46a45536bc1ae50cff9a692bae969748aebfa13e93c0269055ad5031"),
|
||||
("Rgba-5x5-bc3-mips1-decode", "d3238486581875abcd37dfbe03e8fbea7aa4fcadb1fef866899deafb67ac38f9"),
|
||||
("Gray-5x5-none-mips0-encode", "8527392cacb17a19b3e1c0f7cbe05ea4abd7fba93a7952d30967047a2e317f3b"),
|
||||
("Gray-5x5-none-mips0-decode", "70193f4748cd97b7676693076afe2f1c20afa0dc37b4eb89ff3752114a0e0321"),
|
||||
("Gray-5x5-none-mips1-encode", "6c5bd6095bbed4d39c15a6b50dcb5da8d5da48aabf696d2fbfcaf9bd1954c69d"),
|
||||
("Gray-5x5-none-mips1-decode", "70193f4748cd97b7676693076afe2f1c20afa0dc37b4eb89ff3752114a0e0321"),
|
||||
("Gray-5x5-bc1-mips0-encode", "fc7740ff5a801fdcc82e645d25240b44899a64117e70d739c8cba1c17c5a0841"),
|
||||
("Gray-5x5-bc1-mips0-decode", "65a82c1c1048d612c3b5e947603206571f088d1348e6acc42b9e2c014121e227"),
|
||||
("Gray-5x5-bc1-mips1-encode", "3953cd92035a27902d5feaf61ba11b4696c8593fb139fbdb6fda0167ac6d7a58"),
|
||||
("Gray-5x5-bc1-mips1-decode", "65a82c1c1048d612c3b5e947603206571f088d1348e6acc42b9e2c014121e227"),
|
||||
("Gray-5x5-bc2-mips0-encode", "4b2c26f66303f83c35c4f0ca8e306afbde35cfac5e9986cb6dc2ab33696a21c1"),
|
||||
("Gray-5x5-bc2-mips0-decode", "65a82c1c1048d612c3b5e947603206571f088d1348e6acc42b9e2c014121e227"),
|
||||
("Gray-5x5-bc2-mips1-encode", "047e4d8df50b60f8936e8da938b7c62217da128aaf88a25a9384aa69a3701ce9"),
|
||||
("Gray-5x5-bc2-mips1-decode", "65a82c1c1048d612c3b5e947603206571f088d1348e6acc42b9e2c014121e227"),
|
||||
("Gray-5x5-bc3-mips0-encode", "9c31c80f1e254a0e590927faf77fe88007d01c93d7a99280b7d632c4d680a8c4"),
|
||||
("Gray-5x5-bc3-mips0-decode", "65a82c1c1048d612c3b5e947603206571f088d1348e6acc42b9e2c014121e227"),
|
||||
("Gray-5x5-bc3-mips1-encode", "e046981ea9208a3da3cabbb6dd3f3f439db09d8713e6594e099bd7a3ebcd50dc"),
|
||||
("Gray-5x5-bc3-mips1-decode", "65a82c1c1048d612c3b5e947603206571f088d1348e6acc42b9e2c014121e227"),
|
||||
("Rgba-1x9-none-mips0-encode", "94676df714a0e07fd91981b3f9795da76df174319d551573bf62a7324ceae4fb"),
|
||||
("Rgba-1x9-none-mips0-decode", "dbcf64981f64ab690faa081bf7a90405bc9710ca5789f2bbf63d643469d1dd78"),
|
||||
("Rgba-1x9-none-mips1-encode", "2614a6ecc2aa845cab81819cd8bcd8b84624d693df6979cba3df91e100f27361"),
|
||||
("Rgba-1x9-none-mips1-decode", "dbcf64981f64ab690faa081bf7a90405bc9710ca5789f2bbf63d643469d1dd78"),
|
||||
("Rgba-1x9-bc1-mips0-encode", "b7f1466fcebfb73bd6e3b6288d3a8adde258fd9801c694fd44d0f92fbde26c61"),
|
||||
("Rgba-1x9-bc1-mips0-decode", "7d3471a56c9ca5332bccb8943e9d5a01105e0ddfd432b403e77841137f927787"),
|
||||
("Rgba-1x9-bc1-mips1-encode", "4c7c22ba8e2653f31cd9114857d8ba63db6ac180507e40e8c567b61b9c6781d9"),
|
||||
("Rgba-1x9-bc1-mips1-decode", "7d3471a56c9ca5332bccb8943e9d5a01105e0ddfd432b403e77841137f927787"),
|
||||
("Rgba-1x9-bc2-mips0-encode", "9dc6e68ae27d0709f8859d6efa0dfc4028d9fbba2cc0aef106973c998417f5d1"),
|
||||
("Rgba-1x9-bc2-mips0-decode", "c9dd7bf6d44932b599eeb73b54c6f778880db038768110b005f1886f6993e1db"),
|
||||
("Rgba-1x9-bc2-mips1-encode", "5ca6d64da612af3b9018cefa50e98cb9097c2eb3dbda8f862571057ba02d4312"),
|
||||
("Rgba-1x9-bc2-mips1-decode", "c9dd7bf6d44932b599eeb73b54c6f778880db038768110b005f1886f6993e1db"),
|
||||
("Rgba-1x9-bc3-mips0-encode", "f1d5194773bea0b427702900c928d6829f35cbfd32ec0e76b3ee882670597a81"),
|
||||
("Rgba-1x9-bc3-mips0-decode", "feda0633d1e41776c56257893bbe2be5317f57bb771152e1a4336558c16c013c"),
|
||||
("Rgba-1x9-bc3-mips1-encode", "4faa40254411822689f7d6b356c447e58f89a00ea05de3f7c43253164d83823c"),
|
||||
("Rgba-1x9-bc3-mips1-decode", "feda0633d1e41776c56257893bbe2be5317f57bb771152e1a4336558c16c013c"),
|
||||
("Gray-1x9-none-mips0-encode", "deb41e75756b10819d44b9840171a088a5d0169f56962a055939131986b7ebd1"),
|
||||
("Gray-1x9-none-mips0-decode", "2713191d6e180f74fa7825564575abcf7cc40c34f09c2cb8ccd4d2b02a675bb0"),
|
||||
("Gray-1x9-none-mips1-encode", "2d0f36be14a693e7c0380d70841d56cc857e4b81d1a4acbd94eeb18fca0c9216"),
|
||||
("Gray-1x9-none-mips1-decode", "2713191d6e180f74fa7825564575abcf7cc40c34f09c2cb8ccd4d2b02a675bb0"),
|
||||
("Gray-1x9-bc1-mips0-encode", "0723a0ecd94984d4a24890abc427611135b5add4c8ced0cd570867abe49217df"),
|
||||
("Gray-1x9-bc1-mips0-decode", "dcac5ac2d759bc4166ec0d061863f6bf9a34a03a382ac1d88ebdec3e750ecf3e"),
|
||||
("Gray-1x9-bc1-mips1-encode", "b1c38854773fde2bf2fc6e0c13ea5d8f6c92a19c1cb7af5c2986851522f2c5c2"),
|
||||
("Gray-1x9-bc1-mips1-decode", "dcac5ac2d759bc4166ec0d061863f6bf9a34a03a382ac1d88ebdec3e750ecf3e"),
|
||||
("Gray-1x9-bc2-mips0-encode", "b55d775f6f6029fa6d58ea4bea1abeaed349478665874ae2d5a53be14389c595"),
|
||||
("Gray-1x9-bc2-mips0-decode", "dcac5ac2d759bc4166ec0d061863f6bf9a34a03a382ac1d88ebdec3e750ecf3e"),
|
||||
("Gray-1x9-bc2-mips1-encode", "2e90ad054e173a392042126fd8674516fd8dc928c098238f92b7d434181a5895"),
|
||||
("Gray-1x9-bc2-mips1-decode", "dcac5ac2d759bc4166ec0d061863f6bf9a34a03a382ac1d88ebdec3e750ecf3e"),
|
||||
("Gray-1x9-bc3-mips0-encode", "3316e2f5db9bccd337b9dfede5d8c7a4555a645939682f4fc323e746722ef850"),
|
||||
("Gray-1x9-bc3-mips0-decode", "dcac5ac2d759bc4166ec0d061863f6bf9a34a03a382ac1d88ebdec3e750ecf3e"),
|
||||
("Gray-1x9-bc3-mips1-encode", "0ce9b894539c7e6d22531884a6e352aef26fc899ccf97d8a86878f6f5a68d969"),
|
||||
("Gray-1x9-bc3-mips1-decode", "dcac5ac2d759bc4166ec0d061863f6bf9a34a03a382ac1d88ebdec3e750ecf3e"),
|
||||
("Rgba-9x1-none-mips0-encode", "29bc4ef0ce9120982b331bf34a460a75f7c086b630ea6710ddd907b01125cc30"),
|
||||
("Rgba-9x1-none-mips0-decode", "666aa0014607ab13b7141c423c1fb137bda8a5c92973b3252c0556247383d80b"),
|
||||
("Rgba-9x1-none-mips1-encode", "455e7e2173deb612b28ac2ea2cacaf66c740150b3702e2d027bf51dc1123217f"),
|
||||
("Rgba-9x1-none-mips1-decode", "666aa0014607ab13b7141c423c1fb137bda8a5c92973b3252c0556247383d80b"),
|
||||
("Rgba-9x1-bc1-mips0-encode", "8e21b90879f2768fe0341375245b42a1645bc776ef88f81d700cd7e4f538ece3"),
|
||||
("Rgba-9x1-bc1-mips0-decode", "f6b1a1af12998d9db067870ff988d9b527df09ebfbe6a06710474247155655a8"),
|
||||
("Rgba-9x1-bc1-mips1-encode", "034c32c5a3025a72161e02ea5422ead0253490df2abf37030a048c93a301b386"),
|
||||
("Rgba-9x1-bc1-mips1-decode", "f6b1a1af12998d9db067870ff988d9b527df09ebfbe6a06710474247155655a8"),
|
||||
("Rgba-9x1-bc2-mips0-encode", "7d9fbf241277124a62bd0bc466e687d915435cbc083cf0f228694546b612f75e"),
|
||||
("Rgba-9x1-bc2-mips0-decode", "5360be17f525cac699135d57837231fbeb993a906c0f7efbffea6c18da4bb9b4"),
|
||||
("Rgba-9x1-bc2-mips1-encode", "c7fb6cb488b40b0d08f9958d8d19e3e3f8ac19ce96cd67f99b4bf6d65fb7b0fa"),
|
||||
("Rgba-9x1-bc2-mips1-decode", "5360be17f525cac699135d57837231fbeb993a906c0f7efbffea6c18da4bb9b4"),
|
||||
("Rgba-9x1-bc3-mips0-encode", "1e9ad28a5057cd576ad5f47625ccbdd836e683fd321428ac30760a15753a3b0e"),
|
||||
("Rgba-9x1-bc3-mips0-decode", "a367950e128431e9c0728de32358905486a9f53efef56827cf8f7fa71c9382af"),
|
||||
("Rgba-9x1-bc3-mips1-encode", "0f36472c2a24a64e07893879b60a1fc15e492038a669a4fdf0f586942ff7d197"),
|
||||
("Rgba-9x1-bc3-mips1-decode", "a367950e128431e9c0728de32358905486a9f53efef56827cf8f7fa71c9382af"),
|
||||
("Gray-9x1-none-mips0-encode", "4d65e2aad9e331cfc4edf2c0aaa58673c7ba90f1ad37cfa9c6a31095976ebc0a"),
|
||||
("Gray-9x1-none-mips0-decode", "105c3ae0c54915506d98a823112f37182f15e2cbed571b5161c4dfa1007575b5"),
|
||||
("Gray-9x1-none-mips1-encode", "0943b2616b8800af4415b53893ea301f1020e062b20f37095f1be9653a31e9bd"),
|
||||
("Gray-9x1-none-mips1-decode", "105c3ae0c54915506d98a823112f37182f15e2cbed571b5161c4dfa1007575b5"),
|
||||
("Gray-9x1-bc1-mips0-encode", "2c41ef37fc366203a20e1970feecdc8b619659215412a916221ccaa2b273430e"),
|
||||
("Gray-9x1-bc1-mips0-decode", "afd18b30efff0e3eb4b59cf01dcbbb06691c3af6028596f8de9efdf370ea915a"),
|
||||
("Gray-9x1-bc1-mips1-encode", "d2de0189a1e7a6a70f9a5d4ea7c7a53e064b7d1511f9b183a8dc31268ddb6ac6"),
|
||||
("Gray-9x1-bc1-mips1-decode", "afd18b30efff0e3eb4b59cf01dcbbb06691c3af6028596f8de9efdf370ea915a"),
|
||||
("Gray-9x1-bc2-mips0-encode", "766180145e22838dc950a136791fb350d51821e39c58270be394357228462fc1"),
|
||||
("Gray-9x1-bc2-mips0-decode", "afd18b30efff0e3eb4b59cf01dcbbb06691c3af6028596f8de9efdf370ea915a"),
|
||||
("Gray-9x1-bc2-mips1-encode", "476abc493a613766ad73fdc6a89ab765a68677ef6623370472dfea2e3d531847"),
|
||||
("Gray-9x1-bc2-mips1-decode", "afd18b30efff0e3eb4b59cf01dcbbb06691c3af6028596f8de9efdf370ea915a"),
|
||||
("Gray-9x1-bc3-mips0-encode", "b2f6f7f90bd0530857b272a6b39ac60e20ff2c65f5c0f71de543276d48fc5a30"),
|
||||
("Gray-9x1-bc3-mips0-decode", "afd18b30efff0e3eb4b59cf01dcbbb06691c3af6028596f8de9efdf370ea915a"),
|
||||
("Gray-9x1-bc3-mips1-encode", "4376a76e8467759cd485d2241c6e1553b6d49e6eb2f83a466d71ca68754776cd"),
|
||||
("Gray-9x1-bc3-mips1-decode", "afd18b30efff0e3eb4b59cf01dcbbb06691c3af6028596f8de9efdf370ea915a"),
|
||||
("Rgba-6x13-none-mips0-encode", "f603fdcab8e987e1f4b023ec68a14d8c03808952fe429338669977f33131c5a8"),
|
||||
("Rgba-6x13-none-mips0-decode", "35c18e04c37154e00ba7a544476335c4e234d8390803eb8f370351551652e49c"),
|
||||
("Rgba-6x13-none-mips1-encode", "5254f124be9189174a400affb9192419d6350f6f3361d24cf417ea42c8d33411"),
|
||||
("Rgba-6x13-none-mips1-decode", "35c18e04c37154e00ba7a544476335c4e234d8390803eb8f370351551652e49c"),
|
||||
("Rgba-6x13-bc1-mips0-encode", "f1b5e39e9a7308be64aa3531cfd487116a4e7f3ea309b694292c9738721ac872"),
|
||||
("Rgba-6x13-bc1-mips0-decode", "0a63216b434cd9b24807ea58c6d63888d68e84fa4834a34a8068f7fbf054449d"),
|
||||
("Rgba-6x13-bc1-mips1-encode", "13e5b50aa32a32d3dc71d75426c773bb36b191bd97c16c6f2ee0d76f4ee4f54b"),
|
||||
("Rgba-6x13-bc1-mips1-decode", "0a63216b434cd9b24807ea58c6d63888d68e84fa4834a34a8068f7fbf054449d"),
|
||||
("Rgba-6x13-bc2-mips0-encode", "0e0f5815d03c6ec3b8d58715beacdbe67a3dde10bf3f3b635425dc93073dbb4d"),
|
||||
("Rgba-6x13-bc2-mips0-decode", "14d744c8aff8c596f409a6a5c7599bca6479e8e084aa63d99660a44bfe55be6e"),
|
||||
("Rgba-6x13-bc2-mips1-encode", "4d007cb53697f394feb540a4745818c1f8a9df4a47819eac38b2102039e9421c"),
|
||||
("Rgba-6x13-bc2-mips1-decode", "14d744c8aff8c596f409a6a5c7599bca6479e8e084aa63d99660a44bfe55be6e"),
|
||||
("Rgba-6x13-bc3-mips0-encode", "db7fc9607849f169b3e1a7a8e100a7515bdce53ff4f1db7a5fbb6cfc1d1b8162"),
|
||||
("Rgba-6x13-bc3-mips0-decode", "33ba59f2acc8ab6877b8474a4b2cf063a0ae54b4a27afc64fde51313ba4ca6bc"),
|
||||
("Rgba-6x13-bc3-mips1-encode", "c985feb0187e7ac21aa829e25c5e5fe08970c58e10aaf71b96416a7969c55e68"),
|
||||
("Rgba-6x13-bc3-mips1-decode", "33ba59f2acc8ab6877b8474a4b2cf063a0ae54b4a27afc64fde51313ba4ca6bc"),
|
||||
("Gray-6x13-none-mips0-encode", "f63bb759c82a74584022a92fa9dfb64f36f3709446e279157942bafef6edc9b9"),
|
||||
("Gray-6x13-none-mips0-decode", "71201dd954c691aff18dab0a886cb7f10c15dbb33fca26dcc9f1047d28382190"),
|
||||
("Gray-6x13-none-mips1-encode", "435bedffe3efccd86a63533671dd55c7cdc982ea176383adb7e56c4745d38d28"),
|
||||
("Gray-6x13-none-mips1-decode", "71201dd954c691aff18dab0a886cb7f10c15dbb33fca26dcc9f1047d28382190"),
|
||||
("Gray-6x13-bc1-mips0-encode", "f8cb01936384bbff861cbebfd7149753b31f185b52de437e03074102b1056abf"),
|
||||
("Gray-6x13-bc1-mips0-decode", "48669b49d5aec2ab69c120c938838ba206d4e2d589399d2bccf0df5580b48194"),
|
||||
("Gray-6x13-bc1-mips1-encode", "f09c7c8bc3def200c72ed32545de294bbcb5436dbc46e249e5d5d2b8ac987a64"),
|
||||
("Gray-6x13-bc1-mips1-decode", "48669b49d5aec2ab69c120c938838ba206d4e2d589399d2bccf0df5580b48194"),
|
||||
("Gray-6x13-bc2-mips0-encode", "a2b00acf35735c638e07c7468dd8d5ab3405a8d69c653cf95a369538168b8e85"),
|
||||
("Gray-6x13-bc2-mips0-decode", "48669b49d5aec2ab69c120c938838ba206d4e2d589399d2bccf0df5580b48194"),
|
||||
("Gray-6x13-bc2-mips1-encode", "40769615b4e3117ade50c33e69a51a3f2f1601018c49ea216971955bed74b2ea"),
|
||||
("Gray-6x13-bc2-mips1-decode", "48669b49d5aec2ab69c120c938838ba206d4e2d589399d2bccf0df5580b48194"),
|
||||
("Gray-6x13-bc3-mips0-encode", "a429bc2f9725fb23f84ac6bff8bd6a1faaf0ab2808912515069b90c002bbf460"),
|
||||
("Gray-6x13-bc3-mips0-decode", "48669b49d5aec2ab69c120c938838ba206d4e2d589399d2bccf0df5580b48194"),
|
||||
("Gray-6x13-bc3-mips1-encode", "df1d533175cc807a8474701fe4cbdecd694fadd03082d506be50d8716e3e138f"),
|
||||
("Gray-6x13-bc3-mips1-decode", "48669b49d5aec2ab69c120c938838ba206d4e2d589399d2bccf0df5580b48194"),
|
||||
("dx10-rgba8-decode", "154284a9d25eef84bb2ee0b8b1c2d3cd95149dbae9a61cbe0ddb0f4e59cd1482"),
|
||||
("dx10-bgra8-decode", "ec571c9b54af06a0e63fed4b8b00a878d634f62297e72a22372c38fec561b08f"),
|
||||
("dx10-bgrx8-decode", "1e9e7678fcd37dcb5c61047cadac102a2053c9d738fab17c55d9d4af573aea99"),
|
||||
("legacy-rgba8-decode", "387f6d2b46545aa0188614c6c407a4c7498f065f3124964b92992a304c4e997d"),
|
||||
("legacy-bgra8-padded-decode", "5d4a59bd952afd03eb206aa2e3eaeb652d1d6abd1bf2ada8d8bc67e153fd0b3b"),
|
||||
("legacy-rgb24-decode", "0d33d20540b8d8714fb2f50193505188a60a743edbca6729806210a990bcebb7"),
|
||||
("legacy-rgb565-decode", "e0529a28e87837cea810bee99263a4d3c1ec99bfa6547bff583fc5848b7319e9"),
|
||||
("legacy-argb4444-decode", "0cf215d8c21faeff39c8b4e37acb8a72c69a873b7d132746c66c2f4a6277d58a"),
|
||||
("legacy-l8-padded-decode", "0c72254df5d58d8a1b4c62d1da03548c10a058dab179d7486a1e1c394a4b1cee"),
|
||||
("legacy-l8a8-decode", "066ff8e0a187094a1feb4bdc57e1cb8a99bc6ed3d69647c87c9d54a093b6815a"),
|
||||
("legacy-dxt1-noise-decode", "78d4ec7cec69249f8b065667eb66a23b23e82a6b7ab167043539976ae874c433"),
|
||||
("legacy-dxt3-noise-decode", "2dae7a8abe345ca37af54ad56e65dcb8a6fc1837f233cc81b5693b0b547babc8"),
|
||||
("legacy-dxt5-noise-decode", "5a6edeb62a5d6043a474de25da0611a550cf81716a8960dbf57feaebddf7d950"),
|
||||
("dx10-bc1-noise-decode", "5c6ea27a01ccb2a1ab3badea75551a9d3209a0176335871186362cc7e1923ead"),
|
||||
("dx10-bc3-noise-decode", "9c5376a1d714471d575344920380755e40f5be6cd4cb54add5b982d833276823"),
|
||||
];
|
||||
|
||||
/// The compressions the digests cover, listed here rather than taken from `DdsCompression::ALL`
|
||||
/// so a compression added later doesn't change the set.
|
||||
const COMPRESSIONS: [DdsCompression; 4] = [DdsCompression::None, DdsCompression::Bc1, DdsCompression::Bc2, DdsCompression::Bc3];
|
||||
|
||||
/// A 64-bit LCG (Knuth's MMIX constants) with a fixed seed: the same noise on every run.
|
||||
struct Lcg(u64);
|
||||
|
||||
impl Lcg {
|
||||
fn next(&mut self) -> u8 {
|
||||
self.0 = self.0.wrapping_mul(6_364_136_223_846_793_005).wrapping_add(1_442_695_040_888_963_407);
|
||||
(self.0 >> 33) as u8
|
||||
}
|
||||
}
|
||||
|
||||
/// An RGBA test picture in four vertical bands: smooth ramps with mid alpha, noise in every
|
||||
/// channel, flat 8×8 tiles of a few colours (whole blocks of one colour, opaque), and a band
|
||||
/// where alpha jumps between 0, 255 and in-between values over gentle colour.
|
||||
fn picture(w: u32, h: u32, seed: u64) -> Vec<u8> {
|
||||
let mut rng = Lcg(seed);
|
||||
let tiles: [[u8; 4]; 5] = [[12, 200, 77, 255], [255, 255, 255, 255], [0, 0, 0, 255], [255, 0, 255, 255], [90, 91, 92, 255]];
|
||||
let band = w.div_ceil(4).max(1);
|
||||
let mut data = Vec::with_capacity(w as usize * h as usize * 4);
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
let noise = [rng.next(), rng.next(), rng.next(), rng.next()];
|
||||
let px = match x / band {
|
||||
0 => [(x * 2) as u8, (y * 3) as u8, (x + y) as u8, (64 + y % 128) as u8],
|
||||
1 => noise,
|
||||
2 => tiles[((x / 8 + y / 8) % 5) as usize],
|
||||
_ => {
|
||||
let alpha = match (x / 3 + y / 5) % 4 {
|
||||
0 => 0,
|
||||
1 => 255,
|
||||
2 => 128,
|
||||
_ => noise[3],
|
||||
};
|
||||
[(y % 256) as u8, 128, (255 - y % 256) as u8, alpha]
|
||||
}
|
||||
};
|
||||
data.extend(px);
|
||||
}
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
/// The picture in `layout`, its channels picked from the RGBA picture without any conversion
|
||||
/// formula: gray is red, and gray's alpha is alpha.
|
||||
fn image(w: u32, h: u32, layout: ChannelLayout, seed: u64) -> Image {
|
||||
let rgba = picture(w, h, seed);
|
||||
let data = rgba
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.flat_map(|p| match layout {
|
||||
ChannelLayout::Gray => vec![p[0]],
|
||||
ChannelLayout::GrayA => vec![p[0], p[3]],
|
||||
ChannelLayout::Rgb => vec![p[0], p[1], p[2]],
|
||||
_ => p.to_vec(),
|
||||
})
|
||||
.collect();
|
||||
Image::from_u8(w, h, layout, data).unwrap()
|
||||
}
|
||||
|
||||
fn sha256_hex(bytes: &[u8]) -> String {
|
||||
Sha256::digest(bytes).iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
/// A decoded image's digest: its size and layout, then its samples.
|
||||
fn image_digest(img: &Image) -> String {
|
||||
let mut h = Sha256::new();
|
||||
h.update(img.width().to_le_bytes());
|
||||
h.update(img.height().to_le_bytes());
|
||||
h.update(format!("{:?}", img.layout()).as_bytes());
|
||||
h.update(img.data());
|
||||
h.finalize().iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
const DDPF_ALPHAPIXELS: u32 = 0x1;
|
||||
const DDPF_FOURCC: u32 = 0x4;
|
||||
const DDPF_RGB: u32 = 0x40;
|
||||
const DDPF_LUMINANCE: u32 = 0x2_0000;
|
||||
const DDSD_PITCH: u32 = 0x8;
|
||||
|
||||
/// A DDS_HEADER for a single-level 2D texture, with `pitch` set (and flagged) when given.
|
||||
fn header(width: u32, height: u32, pf_flags: u32, fourcc: &[u8; 4], bits: u32, masks: [u32; 4], pitch: Option<u32>) -> Vec<u8> {
|
||||
let mut b = vec![0u8; 128];
|
||||
b[0..4].copy_from_slice(b"DDS ");
|
||||
let mut put = |at: usize, v: u32| b[at..at + 4].copy_from_slice(&v.to_le_bytes());
|
||||
put(4, 124);
|
||||
put(8, 0x1007 | if pitch.is_some() { DDSD_PITCH } else { 0 });
|
||||
put(12, height);
|
||||
put(16, width);
|
||||
put(20, pitch.unwrap_or(0));
|
||||
put(76, 32);
|
||||
put(80, pf_flags);
|
||||
put(88, bits);
|
||||
for (i, m) in masks.into_iter().enumerate() {
|
||||
put(92 + 4 * i, m);
|
||||
}
|
||||
put(108, 0x1000);
|
||||
b[84..88].copy_from_slice(fourcc);
|
||||
b
|
||||
}
|
||||
|
||||
/// A DX10 texture header for DXGI format `dxgi`.
|
||||
fn dx10(width: u32, height: u32, dxgi: u32) -> Vec<u8> {
|
||||
let mut b = header(width, height, DDPF_FOURCC, b"DX10", 0, [0; 4], None);
|
||||
for v in [dxgi, 3, 0, 1, 0] {
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
/// `len` bytes of noise.
|
||||
fn noise(len: usize, seed: u64) -> Vec<u8> {
|
||||
let mut rng = Lcg(seed);
|
||||
(0..len).map(|_| rng.next()).collect()
|
||||
}
|
||||
|
||||
/// Hand-built files in the layouts the writer never makes: RGBA and BGRA through the DX10
|
||||
/// header, padded rows, 24- and 16-bit masks, and block data of pure noise (which reaches BC1's
|
||||
/// three-colour mode and BC3's six-value mode as often as their other modes).
|
||||
fn foreign_files() -> Vec<(String, Vec<u8>)> {
|
||||
let (w, h) = (37u32, 23u32);
|
||||
let px = (w * h) as usize;
|
||||
let blocks = (w.div_ceil(4) * h.div_ceil(4)) as usize;
|
||||
let mut files = Vec::new();
|
||||
let mut add = |name: &str, mut head: Vec<u8>, body: Vec<u8>| {
|
||||
head.extend(body);
|
||||
files.push((name.to_string(), head));
|
||||
};
|
||||
add("dx10-rgba8", dx10(w, h, 28), noise(px * 4, 1));
|
||||
add("dx10-bgra8", dx10(w, h, 87), noise(px * 4, 2));
|
||||
add("dx10-bgrx8", dx10(w, h, 88), noise(px * 4, 3));
|
||||
add("legacy-rgba8", header(w, h, DDPF_RGB | DDPF_ALPHAPIXELS, &[0; 4], 32, [0xff, 0xff00, 0xff_0000, 0xff00_0000], None), noise(px * 4, 4));
|
||||
add(
|
||||
"legacy-bgra8-padded",
|
||||
header(w, h, DDPF_RGB | DDPF_ALPHAPIXELS, &[0; 4], 32, [0xff_0000, 0xff00, 0xff, 0xff00_0000], Some(w * 4 + 12)),
|
||||
noise((w * 4 + 12) as usize * h as usize, 5),
|
||||
);
|
||||
add("legacy-rgb24", header(w, h, DDPF_RGB, &[0; 4], 24, [0xff_0000, 0xff00, 0xff, 0], None), noise(px * 3, 6));
|
||||
add("legacy-rgb565", header(w, h, DDPF_RGB, &[0; 4], 16, [0xf800, 0x07e0, 0x001f, 0], None), noise(px * 2, 7));
|
||||
add("legacy-argb4444", header(w, h, DDPF_RGB | DDPF_ALPHAPIXELS, &[0; 4], 16, [0x0f00, 0x00f0, 0x000f, 0xf000], None), noise(px * 2, 8));
|
||||
add("legacy-l8-padded", header(w, h, DDPF_LUMINANCE, &[0; 4], 8, [0xff, 0, 0, 0], Some(w + 3)), noise((w + 3) as usize * h as usize, 9));
|
||||
add("legacy-l8a8", header(w, h, DDPF_LUMINANCE | DDPF_ALPHAPIXELS, &[0; 4], 16, [0xff, 0, 0, 0xff00], None), noise(px * 2, 10));
|
||||
add("legacy-dxt1-noise", header(w, h, DDPF_FOURCC, b"DXT1", 0, [0; 4], None), noise(blocks * 8, 11));
|
||||
add("legacy-dxt3-noise", header(w, h, DDPF_FOURCC, b"DXT3", 0, [0; 4], None), noise(blocks * 16, 12));
|
||||
add("legacy-dxt5-noise", header(w, h, DDPF_FOURCC, b"DXT5", 0, [0; 4], None), noise(blocks * 16, 13));
|
||||
add("dx10-bc1-noise", dx10(w, h, 71), noise(blocks * 8, 14));
|
||||
add("dx10-bc3-noise", dx10(w, h, 77), noise(blocks * 16, 15));
|
||||
files
|
||||
}
|
||||
|
||||
/// Every case and its digest, in a fixed order.
|
||||
fn digests() -> Vec<(String, String)> {
|
||||
let mut out = Vec::new();
|
||||
// Odd sizes, the sub-block sizes and the one-pixel strips whose mip chains reach the
|
||||
// downsampler's edge spans in only one direction.
|
||||
let sizes = [(517u32, 389u32), (1, 1), (2, 3), (3, 2), (5, 5), (1, 9), (9, 1), (6, 13)];
|
||||
let layouts = [ChannelLayout::Rgba, ChannelLayout::Rgb, ChannelLayout::GrayA, ChannelLayout::Gray];
|
||||
for (i, &(w, h)) in sizes.iter().enumerate() {
|
||||
for layout in layouts {
|
||||
// The large picture in every layout; the small ones in RGBA and gray.
|
||||
if i > 0 && !matches!(layout, ChannelLayout::Rgba | ChannelLayout::Gray) {
|
||||
continue;
|
||||
}
|
||||
let img = image(w, h, layout, 0x5eed + i as u64);
|
||||
for compression in COMPRESSIONS {
|
||||
for mipmaps in [false, true] {
|
||||
let name = format!("{layout:?}-{w}x{h}-{}-mips{}", compression.name(), u8::from(mipmaps));
|
||||
let opts = EncodeOptions { dds: DdsOptions { compression, mipmaps }, ..Default::default() };
|
||||
let file = encode(&img, Format::Dds, &opts).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
out.push((format!("{name}-encode"), sha256_hex(&file)));
|
||||
let back = decode(&file).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
out.push((format!("{name}-decode"), image_digest(&back)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (name, file) in foreign_files() {
|
||||
let back = decode(&file).unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
out.push((format!("{name}-decode"), image_digest(&back)));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dds_output_matches_the_pinned_digests() {
|
||||
let got = digests();
|
||||
let pinned = |name: &str| PINNED.iter().find(|(n, _)| *n == name).map(|(_, d)| *d);
|
||||
let mismatched: Vec<&str> = got.iter().filter(|(name, digest)| pinned(name) != Some(digest.as_str())).map(|(n, _)| n.as_str()).collect();
|
||||
let stale: Vec<&str> = PINNED.iter().filter(|(n, _)| !got.iter().any(|(g, _)| g == n)).map(|(n, _)| *n).collect();
|
||||
if !mismatched.is_empty() || !stale.is_empty() {
|
||||
eprintln!("const PINNED: &[(&str, &str)] = &[");
|
||||
for (name, digest) in &got {
|
||||
eprintln!(" (\"{name}\", \"{digest}\"),");
|
||||
}
|
||||
eprintln!("];");
|
||||
panic!("{} digests differ or are new: {mismatched:?}; {} pinned cases are gone: {stale:?}", mismatched.len(), stale.len());
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ const DDPF_ALPHAPIXELS: u32 = 0x1;
|
||||
const DDPF_FOURCC: u32 = 0x4;
|
||||
const DDPF_RGB: u32 = 0x40;
|
||||
const DDPF_LUMINANCE: u32 = 0x2_0000;
|
||||
const DXGI_BC4_UNORM: u32 = 80;
|
||||
const DXGI_BC5_UNORM: u32 = 83;
|
||||
|
||||
const BLOCKS: [DdsCompression; 3] = [DdsCompression::Bc1, DdsCompression::Bc2, DdsCompression::Bc3];
|
||||
|
||||
@@ -80,11 +82,21 @@ fn psnr(a: &Image, b: &Image) -> f64 {
|
||||
if mse == 0.0 { f64::INFINITY } else { 10.0 * (255.0f64.powi(2) / mse).log10() }
|
||||
}
|
||||
|
||||
/// Whether a written texture has the DX10 header after the legacy one.
|
||||
fn has_dx10(file: &[u8]) -> bool {
|
||||
le32(file, 80) & DDPF_FOURCC != 0 && &file[84..88] == b"DX10"
|
||||
}
|
||||
|
||||
/// Bytes of the headers before the first level.
|
||||
fn head(file: &[u8]) -> usize {
|
||||
if has_dx10(file) { 148 } else { 128 }
|
||||
}
|
||||
|
||||
/// Bytes of one level as a reader computes them from the header's pixel format.
|
||||
fn level_bytes(file: &[u8], w: usize, h: usize) -> usize {
|
||||
if le32(file, 80) & DDPF_FOURCC != 0 {
|
||||
let block = if &file[84..88] == b"DXT1" { 8 } else { 16 };
|
||||
w.div_ceil(4) * h.div_ceil(4) * block
|
||||
let eight = &file[84..88] == b"DXT1" || (has_dx10(file) && le32(file, 128) == DXGI_BC4_UNORM);
|
||||
w.div_ceil(4) * h.div_ceil(4) * if eight { 8 } else { 16 }
|
||||
} else {
|
||||
w * h * le32(file, 88) as usize / 8
|
||||
}
|
||||
@@ -94,9 +106,9 @@ fn level_bytes(file: &[u8], w: usize, h: usize) -> usize {
|
||||
fn level(file: &[u8], i: u32) -> Image {
|
||||
let (w, h) = (le32(file, 16) as usize, le32(file, 12) as usize);
|
||||
let size = |i: u32| ((w >> i).max(1), (h >> i).max(1));
|
||||
let start = 128 + (0..i).map(|j| level_bytes(file, size(j).0, size(j).1)).sum::<usize>();
|
||||
let start = head(file) + (0..i).map(|j| level_bytes(file, size(j).0, size(j).1)).sum::<usize>();
|
||||
let (lw, lh) = size(i);
|
||||
let mut b = file[..128].to_vec();
|
||||
let mut b = file[..head(file)].to_vec();
|
||||
b[12..16].copy_from_slice(&(lh as u32).to_le_bytes());
|
||||
b[16..20].copy_from_slice(&(lw as u32).to_le_bytes());
|
||||
b[28..32].copy_from_slice(&1u32.to_le_bytes());
|
||||
@@ -338,15 +350,122 @@ fn fidelity_warnings_follow_the_compression() {
|
||||
}
|
||||
assert!(warns(DdsCompression::Bc1).contains(&FidelityWarning::AlphaBinarized));
|
||||
assert!(!warns(DdsCompression::Bc3).contains(&FidelityWarning::AlphaBinarized));
|
||||
// BC4 is gray and BC5 has no alpha: translucent colour loses what they don't hold.
|
||||
let bc4 = warns(DdsCompression::Bc4);
|
||||
for w in [FidelityWarning::LossyCompression, FidelityWarning::ColorToGray, FidelityWarning::AlphaDiscarded] {
|
||||
assert!(bc4.contains(&w), "BC4: {w:?} missing from {bc4:?}");
|
||||
}
|
||||
let bc5 = warns(DdsCompression::Bc5);
|
||||
assert!(bc5.contains(&FidelityWarning::LossyCompression) && bc5.contains(&FidelityWarning::AlphaDiscarded), "{bc5:?}");
|
||||
assert!(!bc5.contains(&FidelityWarning::ColorToGray) && !bc5.contains(&FidelityWarning::AlphaBinarized), "{bc5:?}");
|
||||
// A gray map written as BC4 loses only to the compression.
|
||||
let gray = ramp(8, 8, ChannelLayout::Gray);
|
||||
assert_eq!(fidelity_warnings_with(&gray, Format::Dds, &opts(DdsCompression::Bc4, false)), [FidelityWarning::LossyCompression]);
|
||||
}
|
||||
|
||||
/// The largest difference in channel `c` between two images of `channels` channels.
|
||||
fn max_diff(a: &Image, b: &Image, channels: usize, c: usize) -> u8 {
|
||||
a.data().chunks(channels).zip(b.data().chunks(channels)).map(|(x, y)| x[c].abs_diff(y[c])).max().unwrap_or(0)
|
||||
}
|
||||
|
||||
/// `gradient`'s red as gray, or its red, green and blue.
|
||||
fn gradient_as(w: u32, h: u32, layout: ChannelLayout) -> Image {
|
||||
let rgba = gradient(w, h);
|
||||
let data = rgba.data().chunks(4).flat_map(|p| if layout == ChannelLayout::Gray { vec![p[0]] } else { p[..3].to_vec() }).collect();
|
||||
Image::from_u8(w, h, layout, data).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bc4_and_bc5_are_written_with_the_dx10_header() {
|
||||
for (compression, dxgi, block, layout) in
|
||||
[(DdsCompression::Bc4, DXGI_BC4_UNORM, 8, ChannelLayout::Gray), (DdsCompression::Bc5, DXGI_BC5_UNORM, 16, ChannelLayout::Rgb)]
|
||||
{
|
||||
for (w, h) in [(1, 1), (2, 2), (5, 3), (33, 17)] {
|
||||
let img = ramp(w, h, layout);
|
||||
let b = encode(&img, Format::Dds, &opts(compression, false)).unwrap();
|
||||
let linear = w.div_ceil(4) * h.div_ceil(4) * block;
|
||||
assert_eq!(&b[84..88], b"DX10");
|
||||
assert_eq!((le32(&b, 80), le32(&b, 88)), (DDPF_FOURCC, 0));
|
||||
assert_eq!(le32(&b, 8), REQUIRED | DDSD_LINEARSIZE, "linear size, not pitch");
|
||||
assert_eq!(le32(&b, 20), linear, "{compression:?} {w}x{h}: the top level's size");
|
||||
// DXGI format, a 2D texture, no misc flags, one texture, alpha mode unknown.
|
||||
assert_eq!([le32(&b, 128), le32(&b, 132), le32(&b, 136), le32(&b, 140), le32(&b, 144)], [dxgi, 3, 0, 1, 0]);
|
||||
assert_eq!(b.len(), 148 + linear as usize);
|
||||
assert!(!craft_image_codecs::has_unretained_source_data(&b).unwrap());
|
||||
let back = decode(&b).unwrap();
|
||||
assert_eq!((back.dimensions(), back.layout()), ((w, h), layout), "{compression:?} {w}x{h}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bc4_and_bc5_error_on_gradients_is_bounded() {
|
||||
// Each block of the gradient spans 12 levels in a channel: eight values (or six and the
|
||||
// extremes) are under two levels apart.
|
||||
let gray = gradient_as(64, 64, ChannelLayout::Gray);
|
||||
let back = decode(&encode(&gray, Format::Dds, &opts(DdsCompression::Bc4, false)).unwrap()).unwrap();
|
||||
assert_eq!(back.layout(), ChannelLayout::Gray);
|
||||
let err = max_diff(&gray, &back, 1, 0);
|
||||
assert!(err <= 2, "BC4 off by {err}");
|
||||
|
||||
let rgb = gradient_as(64, 64, ChannelLayout::Rgb);
|
||||
let back = decode(&encode(&rgb, Format::Dds, &opts(DdsCompression::Bc5, false)).unwrap()).unwrap();
|
||||
assert_eq!(back.layout(), ChannelLayout::Rgb);
|
||||
let (red, green) = (max_diff(&rgb, &back, 3, 0), max_diff(&rgb, &back, 3, 1));
|
||||
assert!(red <= 2 && green <= 2, "BC5 red off by {red}, green by {green}");
|
||||
assert!(back.data().chunks(3).all(|p| p[2] == 0), "BC5 has no blue");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bc4_and_bc5_take_any_source_layout() {
|
||||
// RGBA to BC4 goes through gray; to BC5 through RGB, dropping alpha and then blue.
|
||||
let img = gradient(9, 7);
|
||||
for (compression, layout) in [(DdsCompression::Bc4, ChannelLayout::Gray), (DdsCompression::Bc5, ChannelLayout::Rgb)] {
|
||||
let back = decode(&encode(&img, Format::Dds, &opts(compression, true)).unwrap()).unwrap();
|
||||
let want = img.convert(layout, img.sample_type());
|
||||
let ch = layout.channels();
|
||||
assert_eq!((back.dimensions(), back.layout()), ((9, 7), layout));
|
||||
for c in 0..ch.min(2) {
|
||||
let err = max_diff(&want, &back, ch, c);
|
||||
assert!(err <= 8, "{compression:?} channel {c} off by {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bc4_and_bc5_mip_chains_follow_the_box_filter() {
|
||||
for (compression, layout, block) in [(DdsCompression::Bc4, ChannelLayout::Gray, 8), (DdsCompression::Bc5, ChannelLayout::Rgb, 16)] {
|
||||
let img = gradient_as(12, 6, layout);
|
||||
let b = encode(&img, Format::Dds, &opts(compression, true)).unwrap();
|
||||
// 12×6, 6×3, 3×1, 1×1: 3×2, 2×1, 1 and 1 blocks after both headers.
|
||||
assert_eq!(le32(&b, 28), 4);
|
||||
assert_eq!(le32(&b, 8), REQUIRED | DDSD_LINEARSIZE | DDSD_MIPMAPCOUNT);
|
||||
assert_eq!(b.len(), 148 + (6 + 2 + 1 + 1) * block);
|
||||
let mut want = img.clone();
|
||||
for i in 0..4 {
|
||||
let got = level(&b, i);
|
||||
assert_eq!((got.dimensions(), got.layout()), (want.dimensions(), layout), "{compression:?} level {i}");
|
||||
for c in 0..layout.channels().min(2) {
|
||||
// Smaller levels are steeper (8, then 16 levels a pixel), so a block's values
|
||||
// sit up to a few levels off its palette.
|
||||
let err = max_diff(&want, &got, layout.channels(), c);
|
||||
assert!(err <= 4, "{compression:?} level {i} channel {c} off by {err}");
|
||||
}
|
||||
want = box_filter(&want);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compression_names_round_trip() {
|
||||
assert_eq!(DdsCompression::ALL.len(), 6);
|
||||
for c in DdsCompression::ALL {
|
||||
assert_eq!(DdsCompression::from_name(c.name()), Some(c));
|
||||
}
|
||||
assert_eq!(DdsCompression::from_name("DXT5"), Some(DdsCompression::Bc3));
|
||||
assert_eq!(DdsCompression::from_name("dxt1"), Some(DdsCompression::Bc1));
|
||||
assert_eq!(DdsCompression::from_name("ATI1"), Some(DdsCompression::Bc4));
|
||||
assert_eq!(DdsCompression::from_name("ati2"), Some(DdsCompression::Bc5));
|
||||
for bad in ["", "bc7", "dxt2", "uncompressed "] {
|
||||
assert_eq!(DdsCompression::from_name(bad), None, "{bad:?}");
|
||||
}
|
||||
@@ -360,6 +479,18 @@ fn compression_names_round_trip() {
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn dds_encode_timings_on_30_mp() {
|
||||
let img = texture_30_mp();
|
||||
for compression in DdsCompression::ALL {
|
||||
for mipmaps in [false, true] {
|
||||
let t = std::time::Instant::now();
|
||||
let b = encode(&img, Format::Dds, &opts(compression, mipmaps)).unwrap();
|
||||
eprintln!("{compression:?} mipmaps={mipmaps}: {:.0} ms, {} MB", t.elapsed().as_secs_f64() * 1e3, b.len() >> 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A synthetic ~30 MP RGBA texture (6336×4752): gentle ramps with a little noise.
|
||||
fn texture_30_mp() -> Image {
|
||||
let (w, h) = (6336u32, 4752u32);
|
||||
let mut s = 0x1234_5678u32;
|
||||
let mut data = Vec::with_capacity(w as usize * h as usize * 4);
|
||||
@@ -371,12 +502,28 @@ fn dds_encode_timings_on_30_mp() {
|
||||
data.extend([(x / 25 + y / 19) as u8, (x / 31) as u8 ^ (s as u8 & 3), (y / 23) as u8, (255 - x / 25) as u8]);
|
||||
}
|
||||
}
|
||||
let img = Image::from_u8(w, h, ChannelLayout::Rgba, data).unwrap();
|
||||
Image::from_u8(w, h, ChannelLayout::Rgba, data).unwrap()
|
||||
}
|
||||
|
||||
/// Decode timings of the same texture written with each compression: the best of five runs, so
|
||||
/// one slow run doesn't decide. Ignored by default; run in release:
|
||||
///
|
||||
/// ```sh
|
||||
/// cargo test --release -p craft-image-codecs --test it -- dds_write:: --ignored --nocapture
|
||||
/// ```
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn dds_decode_timings_on_30_mp() {
|
||||
let img = texture_30_mp();
|
||||
for compression in DdsCompression::ALL {
|
||||
for mipmaps in [false, true] {
|
||||
let b = encode(&img, Format::Dds, &opts(compression, false)).unwrap();
|
||||
let mut best = f64::INFINITY;
|
||||
for _ in 0..5 {
|
||||
let t = std::time::Instant::now();
|
||||
let b = encode(&img, Format::Dds, &opts(compression, mipmaps)).unwrap();
|
||||
eprintln!("{compression:?} mipmaps={mipmaps}: {:.0} ms, {} MB", t.elapsed().as_secs_f64() * 1e3, b.len() >> 20);
|
||||
let back = decode(&b).unwrap();
|
||||
best = best.min(t.elapsed().as_secs_f64());
|
||||
assert_eq!(back.dimensions(), img.dimensions());
|
||||
}
|
||||
eprintln!("{compression:?} decode: {:.0} ms, {} MB", best * 1e3, b.len() >> 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ mod bmp_resolution;
|
||||
mod camera_raw;
|
||||
mod common;
|
||||
mod dds;
|
||||
mod dds_oracle;
|
||||
mod dds_write;
|
||||
mod decode_warnings;
|
||||
mod deep_exr;
|
||||
|
||||
@@ -490,37 +490,103 @@ fn png_rows_fail_like_decode_on_damaged_files() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// PngSuite corpus (repo-root corpus/pngsuite/*.png; feature `corpus`, fetched by
|
||||
// `cargo xtask corpus --all`; missing = failure)
|
||||
// PngSuite corpus (repo-root corpus/pngsuite/; feature `corpus`). The tests read the PNGs that
|
||||
// tests/it/common/pngsuite.tsv lists, each checked against its SHA-256 first; a missing or changed
|
||||
// listed file fails the test, and an unlisted file is not read.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[cfg(feature = "corpus")]
|
||||
#[test]
|
||||
fn pngsuite_corpus_matches_oracle() {
|
||||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/pngsuite");
|
||||
let Ok(entries) = std::fs::read_dir(&dir) else {
|
||||
panic!("{} is missing: run `cargo xtask corpus --all`", dir.display());
|
||||
};
|
||||
let mut checked = 0;
|
||||
for e in entries.flatten() {
|
||||
let p = e.path();
|
||||
if p.extension().and_then(|s| s.to_str()) != Some("png") {
|
||||
continue;
|
||||
}
|
||||
let bytes = std::fs::read(&p).unwrap();
|
||||
for (name, bytes) in common::pngsuite::pngs() {
|
||||
let oracle = image::load_from_memory_with_format(&bytes, image::ImageFormat::Png);
|
||||
let ours = decode(&bytes);
|
||||
match (ours, oracle) {
|
||||
(Ok(a), Ok(b)) => {
|
||||
assert_eq!(a.to_rgba16(), b.into_rgba16().into_raw(), "{}", p.display());
|
||||
assert_eq!(a.to_rgba16(), b.into_rgba16().into_raw(), "{name}");
|
||||
checked += 1;
|
||||
}
|
||||
(Err(e), Ok(_)) => panic!("{}: we failed but oracle decoded: {e}", p.display()),
|
||||
(Err(e), Ok(_)) => panic!("{name}: we failed but oracle decoded: {e}"),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
eprintln!("pngsuite: {checked} files compared");
|
||||
assert!(checked > 100, "{}: only {checked} PNGs compared: run `cargo xtask corpus --all`", dir.display());
|
||||
assert!(checked > 100, "only {checked} PNGs compared");
|
||||
}
|
||||
|
||||
/// The pinned list names the 178 files of the 2017 archive and `LICENSE`, a copy of the archive's
|
||||
/// `PngSuite.LICENSE` with the same SHA-256: 179 names, 176 of them PNGs, every name once.
|
||||
#[test]
|
||||
fn pngsuite_manifest_lists_the_whole_suite() {
|
||||
use common::pngsuite::{MANIFEST, parse};
|
||||
let rows = parse(MANIFEST).unwrap();
|
||||
assert_eq!(rows.len(), 179);
|
||||
assert_eq!(rows.keys().filter(|n| n.ends_with(".png")).count(), 176);
|
||||
assert_eq!(rows["LICENSE"], rows["PngSuite.LICENSE"]);
|
||||
for name in ["PngSuite.README", "PngSuite.png", "basn0g01.png", "xs7n0g01.png", "z09n2c08.png"] {
|
||||
assert!(rows.contains_key(name), "{name}");
|
||||
}
|
||||
assert_eq!(MANIFEST.lines().filter(|l| l.starts_with('#')).count(), 7);
|
||||
}
|
||||
|
||||
/// A row with a bad digest, a path, a hidden name or a repeated name is refused, and so is a list
|
||||
/// with no rows. Extra columns, blank lines and comments are accepted.
|
||||
#[test]
|
||||
fn pngsuite_manifest_refuses_bad_rows() {
|
||||
use common::pngsuite::parse;
|
||||
let d = "a".repeat(64);
|
||||
assert_eq!(parse(&format!("# note\n\n{d}\tx.png\tCC0-1.0\thttps://example.com/x.png\n")).unwrap().len(), 1);
|
||||
for bad in [
|
||||
format!("{d}\tx.png\n{d}\tx.png\n"),
|
||||
format!("{d}\t../x.png\n"),
|
||||
format!("{d}\tdir/x.png\n"),
|
||||
format!("{d}\tdir\\x.png\n"),
|
||||
format!("{d}\t.x.png\n"),
|
||||
format!("{d}\t\n"),
|
||||
format!("{d} x.png\n"),
|
||||
format!("{}\tx.png\n", "a".repeat(63)),
|
||||
format!("{}\tx.png\n", "A".repeat(64)),
|
||||
format!("{}\tx.png\n", "g".repeat(64)),
|
||||
"# only a comment\n".to_string(),
|
||||
String::new(),
|
||||
] {
|
||||
assert!(parse(&bad).is_err(), "{bad:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The corpus reader returns every listed PNG with its bytes and nothing else: an unlisted PNG in
|
||||
/// the folder is not read, and a listed PNG that is missing, changed or not a regular file fails.
|
||||
#[test]
|
||||
fn pngsuite_reader_takes_only_listed_files_that_match() {
|
||||
use common::pngsuite::{pinned_pngs, sha256_hex};
|
||||
let dir = std::env::temp_dir().join(format!("craft-image-codecs-pngsuite-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let a = encode(&synth(5, 4, ChannelLayout::Rgb, SampleType::U8, 1, 0.5), Format::Png, &EncodeOptions::default()).unwrap();
|
||||
let b = encode(&synth(3, 7, ChannelLayout::Gray, SampleType::U16, 2, 0.5), Format::Png, &EncodeOptions::default()).unwrap();
|
||||
std::fs::write(dir.join("a.png"), &a).unwrap();
|
||||
std::fs::write(dir.join("b.png"), &b).unwrap();
|
||||
std::fs::write(dir.join("unlisted.png"), &a).unwrap();
|
||||
let manifest = format!("# test\n{}\ta.png\n{}\tb.png\n{}\tnotes.txt\n", sha256_hex(&a), sha256_hex(&b), "0".repeat(64));
|
||||
|
||||
let got = pinned_pngs(&dir, &manifest).unwrap();
|
||||
assert_eq!(got, vec![("a.png".to_string(), a.clone()), ("b.png".to_string(), b.clone())]);
|
||||
|
||||
let mut changed = b.clone();
|
||||
let last = changed.len() - 1;
|
||||
changed[last] ^= 1;
|
||||
std::fs::write(dir.join("b.png"), &changed).unwrap();
|
||||
let err = pinned_pngs(&dir, &manifest).unwrap_err();
|
||||
assert!(err.contains("b.png") && err.contains("does not match"), "{err}");
|
||||
std::fs::write(dir.join("b.png"), &b).unwrap();
|
||||
|
||||
std::fs::remove_file(dir.join("a.png")).unwrap();
|
||||
assert!(pinned_pngs(&dir, &manifest).unwrap_err().contains("a.png"));
|
||||
std::fs::create_dir(dir.join("a.png")).unwrap();
|
||||
assert!(pinned_pngs(&dir, &manifest).unwrap_err().contains("regular file"));
|
||||
|
||||
std::fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
/// The preflight charges the decoded layout's bytes per pixel: a 1000×1000 Gray8 PNG (1 MB) fits a
|
||||
@@ -539,21 +605,12 @@ fn png_preflight_uses_the_output_layout() {
|
||||
#[cfg(feature = "corpus")]
|
||||
#[test]
|
||||
fn png_rows_equal_decode_on_the_pngsuite_corpus() {
|
||||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/pngsuite");
|
||||
let Ok(entries) = std::fs::read_dir(&dir) else {
|
||||
panic!("{} is missing: run `cargo xtask corpus --all`", dir.display());
|
||||
};
|
||||
let mut checked = 0;
|
||||
for e in entries.flatten() {
|
||||
let p = e.path();
|
||||
if p.extension().and_then(|s| s.to_str()) != Some("png") {
|
||||
continue;
|
||||
}
|
||||
let bytes = std::fs::read(&p).unwrap();
|
||||
assert_steps_equal_decode(&bytes, &p.display().to_string());
|
||||
for (name, bytes) in common::pngsuite::pngs() {
|
||||
assert_steps_equal_decode(&bytes, &name);
|
||||
checked += 1;
|
||||
}
|
||||
assert!(checked > 100, "{}: only {checked} PNGs compared: run `cargo xtask corpus --all`", dir.display());
|
||||
assert!(checked > 100, "only {checked} PNGs compared");
|
||||
}
|
||||
|
||||
/// Row-by-row decoding gives `decode`'s pixels and metadata for every PngSuite file it takes (all
|
||||
@@ -561,18 +618,9 @@ fn png_rows_equal_decode_on_the_pngsuite_corpus() {
|
||||
#[cfg(feature = "corpus")]
|
||||
#[test]
|
||||
fn pngsuite_corpus_rows_match_the_whole_decode() {
|
||||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/pngsuite");
|
||||
let Ok(entries) = std::fs::read_dir(&dir) else {
|
||||
panic!("{} is missing: run `cargo xtask corpus --all`", dir.display());
|
||||
};
|
||||
let opts = DecodeOptions { keep_orientation: true, ..Default::default() };
|
||||
let (mut streamed, mut refused, mut skipped) = (0, 0, 0);
|
||||
for e in entries.flatten() {
|
||||
let p = e.path();
|
||||
if p.extension().and_then(|s| s.to_str()) != Some("png") {
|
||||
continue;
|
||||
}
|
||||
let bytes = std::fs::read(&p).unwrap();
|
||||
for (name, bytes) in common::pngsuite::pngs() {
|
||||
// The importer only streams files `detect` takes for PNG.
|
||||
if detect(&bytes) != Some(Format::Png) {
|
||||
skipped += 1;
|
||||
@@ -596,24 +644,23 @@ fn pngsuite_corpus_rows_match_the_whole_decode() {
|
||||
match (whole, rows) {
|
||||
(Ok(img), Ok(Some(x))) => {
|
||||
let h = header.unwrap();
|
||||
assert_eq!((img.width(), img.height(), img.layout(), img.sample_type()), (h.width, h.height, h.layout, h.sample), "{}", p.display());
|
||||
assert!(img.data() == data, "{}: pixels", p.display());
|
||||
assert_eq!((img.width(), img.height(), img.layout(), img.sample_type()), (h.width, h.height, h.layout, h.sample), "{name}");
|
||||
assert!(img.data() == data, "{name}: pixels");
|
||||
assert_eq!(
|
||||
(&img.icc, &img.meta.exif, &img.meta.text, &img.meta.xmp, &img.warnings),
|
||||
(&x.icc, &x.meta.exif, &x.meta.text, &x.meta.xmp, &x.warnings),
|
||||
"{}",
|
||||
p.display()
|
||||
"{name}"
|
||||
);
|
||||
assert_eq!(img.meta.dpi, x.meta.dpi, "{}", p.display());
|
||||
assert_eq!(img.meta.dpi, x.meta.dpi, "{name}");
|
||||
streamed += 1;
|
||||
}
|
||||
(Ok(_), Ok(None)) => refused += 1,
|
||||
(Err(a), Err(b)) => assert_eq!(a.to_string(), b.to_string(), "{}", p.display()),
|
||||
(a, b) => panic!("{}: whole {:?}, rows {:?}", p.display(), a.map(|_| ()), b.map(|r| r.map(|_| ()))),
|
||||
(Err(a), Err(b)) => assert_eq!(a.to_string(), b.to_string(), "{name}"),
|
||||
(a, b) => panic!("{name}: whole {:?}, rows {:?}", a.map(|_| ()), b.map(|r| r.map(|_| ()))),
|
||||
}
|
||||
}
|
||||
eprintln!("pngsuite: {streamed} streamed, {refused} refused (interlaced), {skipped} skipped (not detected as PNG)");
|
||||
assert!(streamed > 100, "only {streamed} PNGs streamed: run `cargo xtask corpus --all`");
|
||||
assert!(streamed > 100, "only {streamed} PNGs streamed");
|
||||
}
|
||||
|
||||
/// Streaming a PNG's rows a group at a time gives the pixels and metadata `decode` gives, holds
|
||||
|
||||
@@ -63,3 +63,23 @@ fn oversized_or_cut_directories_are_skipped() {
|
||||
cut.truncate(20);
|
||||
assert!(!legacy_tiff_raw_hint(&cut));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_subifds_array_without_its_offset_is_skipped() {
|
||||
// IFD0 at 64 holds one SubIFDs entry (LONG, count 3) whose offset field is cut off. A DNG
|
||||
// directory sits at 32, and the bytes at 8 point to it. Reading the missing offset as 0
|
||||
// would treat the TIFF header as the pointer array and follow 8 -> 32.
|
||||
let mut b = vec![0u8; 64];
|
||||
b[..8].copy_from_slice(b"II\x2a\0\x40\0\0\0");
|
||||
b[8..12].copy_from_slice(&32u32.to_le_bytes());
|
||||
b[32..34].copy_from_slice(&1u16.to_le_bytes());
|
||||
b[34..46].copy_from_slice(&[0x12, 0xc6, 1, 0, 4, 0, 0, 0, 1, 4, 0, 0]);
|
||||
b.extend_from_slice(&1u16.to_le_bytes());
|
||||
b.extend_from_slice(&[0x4a, 0x01, 4, 0, 3, 0, 0, 0]);
|
||||
assert_eq!(b.len(), 74);
|
||||
assert!(!legacy_tiff_raw_hint(&b));
|
||||
// With the offset present (the array at 8), the same SubIFD is followed.
|
||||
let mut whole = b.clone();
|
||||
whole.extend_from_slice(&8u32.to_le_bytes());
|
||||
assert!(legacy_tiff_raw_hint(&whole));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user