Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

1
vendor/ktx2/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"f023866f02f54f53fb4621f7faf5cc171989719a61e87def00d77033cfa987a7","Cargo.lock":"54d0646f4650ec5c1d556bf3f58c9fdeedb822246c141a307006399be160c527","Cargo.toml":"d913190dc54445c57ffcaa96a0a58a4103132ed6e0511e437a982d68796d11eb","LICENSE":"9590ea0a83fc96e5f33b98975f3e2a20040781210014ca22a5beb9946511ed5a","README.md":"e07bbabc4818e37c40084dff4e19ae4824da814c5a3dd823b95420a85d955a98","README.tpl":"758cbedaf6ffe7ec9a66b6ad96ff2217520a258b1f3ad882ac23d09ed649ed94","deny.toml":"305a47047b6bd8ad30bb6e6ff0694a8f363dce048ff3d3da2142adbff494adf9","examples/load.rs":"f90ac162287432a7db317c0da62f3a199fffe00d4a5e934ebd6fddf2b400e230","release.toml":"f562acdd1084bcac341e4336e1a6889009449a4769bb3cf0b4ef8ef3306f757d","src/enums.rs":"9b5eea07eb02963419caa2eef7f70b0e281f74ec422a41e925b6aa41464bee0e","src/error.rs":"291792b8736da34a61a2d048a5081d67561b360f901099880fb93db810018ad6","src/lib.rs":"0dac05c8f5ef50cfab5ec7b69d6bcf3b833e7f7e72ac3628f84eb75aa269e319"},"package":"87d65e08a9ec02e409d27a0139eaa6b9756b4d81fe7cde71f6941a83730ce838"}

37
vendor/ktx2/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,37 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to cargo's version of [Semantic Versioning](https://doc.rust-lang.org/cargo/reference/semver.html).
Per Keep a Changelog there are 6 main categories of changes:
- Added
- Changed
- Deprecated
- Removed
- Fixed
- Security
#### Table of Contents
- [Unreleased](#unreleased)
- [v0.3.0](#v030)
- [Diffs](#diffs)
## Unreleased
## v0.3.0
Released 2022-02-03
Initial release under new ownership.
- Added support for Data Format Descriptor parsing (Rob Swain [@superdump](https://github.com/superdump))
### Changed
- Cleaned up a signifigant portion of the crate.
## Diffs
- [Unreleased](https://github.com/BVE-Reborn/ktx2/compare/v0.3.0...HEAD)

16
vendor/ktx2/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "ktx2"
version = "0.3.0"
dependencies = [
"bitflags",
]

58
vendor/ktx2/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,58 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "ktx2"
version = "0.3.0"
authors = ["Benjamin Saunders <ben.e.saunders@gmail.com>", "Connor Fitzgerald <connorwadefitzgerald@gmail.com>", "f3kilo <f3kilo@yandex.ru>"]
exclude = ["data/*"]
description = "Parser for the ktx2 texture container format"
readme = "README.md"
keywords = []
categories = []
license = "Apache-2.0"
repository = "https://github.com/BVE-Reborn/ktx2"
[package.metadata.release]
pre-release-hook = ["cargo", "readme", "-o", "README.md", "-t", "README.tpl"]
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
replace = "[Unreleased](#unreleased)\n- [v{{version}}](#v{{version}})"
search = "\\[Unreleased\\]\\(#unreleased\\)"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
replace = "[v$1.$2.$3](#v$1$2$3)"
search = "\\[v([0-9]+)\\.([0-9]+)\\.([0-9]+)\\]\\(#v[0-9\\.]+\\)"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
replace = "## Unreleased\n\n## v{{version}}\n\nReleased {{date}}"
search = "## Unreleased"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
min = 0
replace = "[Unreleased](https://github.com/BVE-Reborn/ktx2/compare/v{{version}}...HEAD)\n- [v{{version}}](https://github.com/BVE-Reborn/ktx2/compare/v$1...v{{version}})"
search = "\\[Unreleased\\]\\(https://github.com/BVE-Reborn/ktx2/compare/v([a-z0-9.-]+)\\.\\.\\.HEAD\\)"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
min = 0
replace = "- [Unreleased](https://github.com/BVE-Reborn/ktx2/compare/v{{version}}...HEAD)"
search = "<!-- Begin Diffs -->"
[dependencies.bitflags]
version = "1.3.2"
[features]
default = ["std"]
std = []

201
vendor/ktx2/LICENSE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2021 The BVE-Reborn Developers
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

18
vendor/ktx2/README.md vendored Normal file
View File

@@ -0,0 +1,18 @@
# ktx2
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/BVE-Reborn/ktx2/Build)
[![Crates.io](https://img.shields.io/crates/v/ktx2)](https://crates.io/crates/ktx2)
[![Documentation](https://docs.rs/ktx2/badge.svg)](https://docs.rs/ktx2)
![License](https://img.shields.io/crates/l/ktx2)
Parser for the [ktx2](https://github.khronos.org/KTX-Specification/) texture container format.
### Features
- [x] Async reading
- [x] Parsing
- [x] Validating
- [x] [Data format description](https://github.khronos.org/KTX-Specification/#_data_format_descriptor)
- [ ] [Key/value data](https://github.khronos.org/KTX-Specification/#_keyvalue_data)
License: Apache-2.0

12
vendor/ktx2/README.tpl vendored Normal file
View File

@@ -0,0 +1,12 @@
# ktx2
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/BVE-Reborn/ktx2/Build)
[![Crates.io](https://img.shields.io/crates/v/ktx2)](https://crates.io/crates/ktx2)
[![Documentation](https://docs.rs/ktx2/badge.svg)](https://docs.rs/ktx2)
![License](https://img.shields.io/crates/l/ktx2)
{{readme}}
License: {{license}}

20
vendor/ktx2/deny.toml vendored Normal file
View File

@@ -0,0 +1,20 @@
[licenses]
unlicensed = "deny"
allow-osi-fsf-free = "either"
allow = [
]
[bans]
multiple-versions = "deny"
skip = [
]
[advisories]
vulnerability = "deny"
unmaintained = "deny"
ignore = [
]
[sources]
unknown-registry = "deny"
unknown-git = "allow"

34
vendor/ktx2/examples/load.rs vendored Normal file
View File

@@ -0,0 +1,34 @@
use ktx2::{Format, Header, Reader};
fn main() {
let file = include_bytes!("../data/test_tex.ktx2");
let reader = Reader::new(file).expect("Can't create reader");
let header = reader.header();
println!("Header: {:#?}", header);
assert_head(header);
let levels = reader.levels().collect::<Vec<_>>();
assert_eq!(levels.len(), header.level_count.max(1) as usize);
let data = reader.data();
println!("Data len: {:?}", data.len());
test_data(&levels);
}
fn test_data(info: &[&[u8]]) {
for (i, region) in info.iter().enumerate() {
println!("Bytes for level {:?}: {:?}", i, &region[..4]);
}
}
fn assert_head(header: Header) {
assert_eq!(header.format, Some(Format::R8G8B8A8_UINT));
assert_eq!(header.type_size, 1);
assert_eq!(header.pixel_width, 1024);
assert_eq!(header.pixel_height, 512);
assert_eq!(header.pixel_depth, 0);
assert_eq!(header.layer_count, 0);
assert_eq!(header.face_count, 1);
assert_eq!(header.level_count, 11);
assert_eq!(header.supercompression_scheme, None);
}

4
vendor/ktx2/release.toml vendored Normal file
View File

@@ -0,0 +1,4 @@
consolidate-commits = true
dev-version = false
tag = false
pre-release-commit-message = "Bump version for release"

273
vendor/ktx2/src/enums.rs vendored Normal file
View File

@@ -0,0 +1,273 @@
use core::{fmt, num::NonZeroU32};
macro_rules! pseudo_enum {
($(#[$attr:meta])* $name:ident { $($case:ident = $value:literal,)* }) => {
$(#[$attr])*
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct $name(pub NonZeroU32);
#[allow(non_upper_case_globals)]
impl $name {
pub fn new(x: u32) -> Option<Self> {
Some(Self(NonZeroU32::new(x)?))
}
$(
pub const $case: Self = Self(unsafe { NonZeroU32::new_unchecked($value) });
)*
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let name = match self.0.get() {
$($value => Some(stringify!($case)),)*
_ => None,
};
match name {
Some(name) => f.pad(name),
None => write!(f, concat!(stringify!($name), "({})"), self.0.get()),
}
}
}
};
}
pseudo_enum! {
/// Known texture formats
Format {
R4G4_UNORM_PACK8 = 1,
R4G4B4A4_UNORM_PACK16 = 2,
B4G4R4A4_UNORM_PACK16 = 3,
R5G6B5_UNORM_PACK16 = 4,
B5G6R5_UNORM_PACK16 = 5,
R5G5B5A1_UNORM_PACK16 = 6,
B5G5R5A1_UNORM_PACK16 = 7,
A1R5G5B5_UNORM_PACK16 = 8,
R8_UNORM = 9,
R8_SNORM = 10,
R8_UINT = 13,
R8_SINT = 14,
R8_SRGB = 15,
R8G8_UNORM = 16,
R8G8_SNORM = 17,
R8G8_UINT = 20,
R8G8_SINT = 21,
R8G8_SRGB = 22,
R8G8B8_UNORM = 23,
R8G8B8_SNORM = 24,
R8G8B8_UINT = 27,
R8G8B8_SINT = 28,
R8G8B8_SRGB = 29,
B8G8R8_UNORM = 30,
B8G8R8_SNORM = 31,
B8G8R8_UINT = 34,
B8G8R8_SINT = 35,
B8G8R8_SRGB = 36,
R8G8B8A8_UNORM = 37,
R8G8B8A8_SNORM = 38,
R8G8B8A8_UINT = 41,
R8G8B8A8_SINT = 42,
R8G8B8A8_SRGB = 43,
B8G8R8A8_UNORM = 44,
B8G8R8A8_SNORM = 45,
B8G8R8A8_UINT = 48,
B8G8R8A8_SINT = 49,
B8G8R8A8_SRGB = 50,
A2R10G10B10_UNORM_PACK32 = 58,
A2R10G10B10_SNORM_PACK32 = 59,
A2R10G10B10_UINT_PACK32 = 62,
A2R10G10B10_SINT_PACK32 = 63,
A2B10G10R10_UNORM_PACK32 = 64,
A2B10G10R10_SNORM_PACK32 = 65,
A2B10G10R10_UINT_PACK32 = 68,
A2B10G10R10_SINT_PACK32 = 69,
R16_UNORM = 70,
R16_SNORM = 71,
R16_UINT = 74,
R16_SINT = 75,
R16_SFLOAT = 76,
R16G16_UNORM = 77,
R16G16_SNORM = 78,
R16G16_UINT = 81,
R16G16_SINT = 82,
R16G16_SFLOAT = 83,
R16G16B16_UNORM = 84,
R16G16B16_SNORM = 85,
R16G16B16_UINT = 88,
R16G16B16_SINT = 89,
R16G16B16_SFLOAT = 90,
R16G16B16A16_UNORM = 91,
R16G16B16A16_SNORM = 92,
R16G16B16A16_UINT = 95,
R16G16B16A16_SINT = 96,
R16G16B16A16_SFLOAT = 97,
R32_UINT = 98,
R32_SINT = 99,
R32_SFLOAT = 100,
R32G32_UINT = 101,
R32G32_SINT = 102,
R32G32_SFLOAT = 103,
R32G32B32_UINT = 104,
R32G32B32_SINT = 105,
R32G32B32_SFLOAT = 106,
R32G32B32A32_UINT = 107,
R32G32B32A32_SINT = 108,
R32G32B32A32_SFLOAT = 109,
R64_UINT = 110,
R64_SINT = 111,
R64_SFLOAT = 112,
R64G64_UINT = 113,
R64G64_SINT = 114,
R64G64_SFLOAT = 115,
R64G64B64_UINT = 116,
R64G64B64_SINT = 117,
R64G64B64_SFLOAT = 118,
R64G64B64A64_UINT = 119,
R64G64B64A64_SINT = 120,
R64G64B64A64_SFLOAT = 121,
B10G11R11_UFLOAT_PACK32 = 122,
E5B9G9R9_UFLOAT_PACK32 = 123,
D16_UNORM = 124,
X8_D24_UNORM_PACK32 = 125,
D32_SFLOAT = 126,
S8_UINT = 127,
D16_UNORM_S8_UINT = 128,
D24_UNORM_S8_UINT = 129,
D32_SFLOAT_S8_UINT = 130,
BC1_RGB_UNORM_BLOCK = 131,
BC1_RGB_SRGB_BLOCK = 132,
BC1_RGBA_UNORM_BLOCK = 133,
BC1_RGBA_SRGB_BLOCK = 134,
BC2_UNORM_BLOCK = 135,
BC2_SRGB_BLOCK = 136,
BC3_UNORM_BLOCK = 137,
BC3_SRGB_BLOCK = 138,
BC4_UNORM_BLOCK = 139,
BC4_SNORM_BLOCK = 140,
BC5_UNORM_BLOCK = 141,
BC5_SNORM_BLOCK = 142,
BC6H_UFLOAT_BLOCK = 143,
BC6H_SFLOAT_BLOCK = 144,
BC7_UNORM_BLOCK = 145,
BC7_SRGB_BLOCK = 146,
ETC2_R8G8B8_UNORM_BLOCK = 147,
ETC2_R8G8B8_SRGB_BLOCK = 148,
ETC2_R8G8B8A1_UNORM_BLOCK = 149,
ETC2_R8G8B8A1_SRGB_BLOCK = 150,
ETC2_R8G8B8A8_UNORM_BLOCK = 151,
ETC2_R8G8B8A8_SRGB_BLOCK = 152,
EAC_R11_UNORM_BLOCK = 153,
EAC_R11_SNORM_BLOCK = 154,
EAC_R11G11_UNORM_BLOCK = 155,
EAC_R11G11_SNORM_BLOCK = 156,
ASTC_4x4_UNORM_BLOCK = 157,
ASTC_4x4_SRGB_BLOCK = 158,
ASTC_5x4_UNORM_BLOCK = 159,
ASTC_5x4_SRGB_BLOCK = 160,
ASTC_5x5_UNORM_BLOCK = 161,
ASTC_5x5_SRGB_BLOCK = 162,
ASTC_6x5_UNORM_BLOCK = 163,
ASTC_6x5_SRGB_BLOCK = 164,
ASTC_6x6_UNORM_BLOCK = 165,
ASTC_6x6_SRGB_BLOCK = 166,
ASTC_8x5_UNORM_BLOCK = 167,
ASTC_8x5_SRGB_BLOCK = 168,
ASTC_8x6_UNORM_BLOCK = 169,
ASTC_8x6_SRGB_BLOCK = 170,
ASTC_8x8_UNORM_BLOCK = 171,
ASTC_8x8_SRGB_BLOCK = 172,
ASTC_10x5_UNORM_BLOCK = 173,
ASTC_10x5_SRGB_BLOCK = 174,
ASTC_10x6_UNORM_BLOCK = 175,
ASTC_10x6_SRGB_BLOCK = 176,
ASTC_10x8_UNORM_BLOCK = 177,
ASTC_10x8_SRGB_BLOCK = 178,
ASTC_10x10_UNORM_BLOCK = 179,
ASTC_10x10_SRGB_BLOCK = 180,
ASTC_12x10_UNORM_BLOCK = 181,
ASTC_12x10_SRGB_BLOCK = 182,
ASTC_12x12_UNORM_BLOCK = 183,
ASTC_12x12_SRGB_BLOCK = 184,
}
}
pseudo_enum! {
/// Known supercompression schemes
SupercompressionScheme {
BasisLZ = 1,
Zstandard = 2,
ZLIB = 3,
}
}
pseudo_enum! {
ColorModel {
RGBSDA = 1,
YUVSDA = 2,
YIQSDA = 3,
LabSDA = 4,
CMYKA = 5,
XYZW = 6,
HSVAAng = 7,
HSLAAng = 8,
HSVAHex = 9,
HSLAHex = 10,
YCgCoA = 11,
YcCbcCrc = 12,
ICtCp = 13,
CIEXYZ = 14,
CIEXYY = 15,
BC1A = 128,
BC2 = 129,
BC3 = 130,
BC4 = 131,
BC5 = 132,
BC6H = 133,
BC7 = 134,
ETC1 = 160,
ETC2 = 161,
ASTC = 162,
ETC1S = 163,
PVRTC = 164,
PVRTC2 = 165,
UASTC = 166,
}
}
pseudo_enum! {
ColorPrimaries {
BT709 = 1,
BT601EBU = 2,
BT601SMPTE = 3,
BT2020 = 4,
CIEXYZ = 5,
ACES = 6,
ACESCC = 7,
NTSC1953 = 8,
PAL525 = 9,
DISPLAYP3 = 10,
AdobeRGB = 11,
}
}
pseudo_enum! {
TransferFunction {
Linear = 1,
SRGB = 2,
ITU = 3,
NTSC = 4,
SLOG = 5,
SLOG2 = 6,
BT1886 = 7,
HLGOETF = 8,
HLGEOTF = 9,
PQEOTF = 10,
PQOETF = 11,
DCIP3 = 12,
PALOETF = 13,
PAL625EOTF = 14,
ST240 = 15,
ACESCC = 16,
ACESCCT = 17,
AdobeRGB = 18,
}
}

31
vendor/ktx2/src/error.rs vendored Normal file
View File

@@ -0,0 +1,31 @@
use core::fmt;
#[cfg(feature = "std")]
use std::error::Error;
/// Error, that happend when data doesn't satisfy expected parameters.
#[derive(Debug)]
#[non_exhaustive]
pub enum ParseError {
/// Unexpected magic numbers
BadMagic,
/// Zero pixel width
ZeroWidth,
/// Zero face count
ZeroFaceCount,
/// Unexpected end of buffer
UnexpectedEnd,
}
#[cfg(feature = "std")]
impl Error for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
ParseError::BadMagic => f.pad("unexpected magic numbers"),
ParseError::ZeroWidth => f.pad("zero pixel width"),
ParseError::ZeroFaceCount => f.pad("zero face count"),
ParseError::UnexpectedEnd => f.pad("unexpected end of buffer"),
}
}
}

426
vendor/ktx2/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,426 @@
//! Parser for the [ktx2](https://github.khronos.org/KTX-Specification/) texture container format.
//!
//! ## Features
//! - [x] Async reading
//! - [x] Parsing
//! - [x] Validating
//! - [x] [Data format description](https://github.khronos.org/KTX-Specification/#_data_format_descriptor)
//! - [ ] [Key/value data](https://github.khronos.org/KTX-Specification/#_keyvalue_data)
//
//! ## Example
//! ```rust
//! // Crate instance of reader. This validates the header
//! # let file = include_bytes!("../data/test_tex.ktx2");
//! let mut reader = ktx2::Reader::new(file).expect("Can't create reader"); // Crate instance of reader.
//!
//! // Get general texture information.
//! let header = reader.header();
//!
//! // Read iterator over slices of each mipmap level.
//! let levels = reader.levels().collect::<Vec<_>>();
//! # let _ = (header, levels);
//! ```
#![no_std]
#[cfg(feature = "std")]
extern crate std;
mod enums;
mod error;
pub use crate::{
enums::{ColorModel, ColorPrimaries, Format, SupercompressionScheme, TransferFunction},
error::ParseError,
};
use core::convert::TryInto;
/// Decodes KTX2 texture data
pub struct Reader<Data: AsRef<[u8]>> {
input: Data,
}
impl<Data: AsRef<[u8]>> Reader<Data> {
/// Decode KTX2 data from `input`
pub fn new(input: Data) -> Result<Self, ParseError> {
if input.as_ref().len() < Header::LENGTH {
return Err(ParseError::UnexpectedEnd);
}
if !input.as_ref().starts_with(&KTX2_MAGIC) {
return Err(ParseError::BadMagic);
}
let header_data = input.as_ref()[0..Header::LENGTH].try_into().unwrap();
let header = Header::from_bytes(header_data);
header.validate()?;
if (header.dfd_byte_offset + header.dfd_byte_length) as usize >= input.as_ref().len() {
return Err(ParseError::UnexpectedEnd);
}
let result = Self { input };
result.level_index()?; // Check index integrity
// Check level data integrity
let trailing = result.level_index().unwrap().max_by_key(|l| l.offset).unwrap();
if trailing.offset + trailing.length_bytes > result.input.as_ref().len() as u64 {
return Err(ParseError::UnexpectedEnd);
}
Ok(result)
}
fn level_index(&self) -> ParseResult<impl ExactSizeIterator<Item = LevelIndex> + '_> {
let level_count = self.header().level_count.max(1) as usize;
let level_index_end_byte = Header::LENGTH + level_count * LevelIndex::LENGTH;
let level_index_bytes = self
.input
.as_ref()
.get(Header::LENGTH..level_index_end_byte)
.ok_or(ParseError::UnexpectedEnd)?;
Ok(level_index_bytes
.chunks_exact(LevelIndex::LENGTH)
.map(LevelIndex::from_bytes))
}
/// Access underlying raw bytes
pub fn data(&self) -> &[u8] {
self.input.as_ref()
}
/// Container-level metadata
pub fn header(&self) -> Header {
let bytes = self.input.as_ref()[0..Header::LENGTH].try_into().unwrap();
Header::from_bytes(bytes)
}
/// Iterator over the texture's mip levels
pub fn levels(&self) -> impl ExactSizeIterator<Item = &[u8]> + '_ {
self.level_index()
.unwrap()
.map(move |level| &self.input.as_ref()[level.offset as usize..(level.offset + level.length_bytes) as usize])
}
pub fn supercompression_global_data(&self) -> &[u8] {
let header = self.header();
let start = header.sgd_byte_offset as usize;
let end = (header.sgd_byte_offset + header.sgd_byte_length) as usize;
&self.input.as_ref()[start..end]
}
pub fn data_format_descriptors(&self) -> impl Iterator<Item = DataFormatDescriptor> {
let header = self.header();
let start = header.dfd_byte_offset as usize;
let end = (header.dfd_byte_offset + header.dfd_byte_length) as usize;
DataFormatDescriptorIterator {
// start + 4 to skip the data format descriptors total length
data: &self.input.as_ref()[start + 4..end],
}
}
}
struct DataFormatDescriptorIterator<'data> {
data: &'data [u8],
}
impl<'data> Iterator for DataFormatDescriptorIterator<'data> {
type Item = DataFormatDescriptor<'data>;
fn next(&mut self) -> Option<Self::Item> {
if self.data.len() < DataFormatDescriptorHeader::LENGTH {
return None;
}
DataFormatDescriptorHeader::parse(&self.data[..DataFormatDescriptorHeader::LENGTH]).map_or(
None,
|(header, descriptor_block_size)| {
if descriptor_block_size == 0 || self.data.len() < descriptor_block_size {
return None;
}
let data = &self.data[DataFormatDescriptorHeader::LENGTH..descriptor_block_size];
self.data = &self.data[descriptor_block_size..];
Some(DataFormatDescriptor { header, data })
},
)
}
}
/// Identifier, expected in start of input texture data.
const KTX2_MAGIC: [u8; 12] = [0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A];
/// Result of parsing data operation.
type ParseResult<T> = Result<T, ParseError>;
/// Container-level metadata
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct Header {
pub format: Option<Format>,
pub type_size: u32,
pub pixel_width: u32,
pub pixel_height: u32,
pub pixel_depth: u32,
pub layer_count: u32,
pub face_count: u32,
pub level_count: u32,
pub supercompression_scheme: Option<SupercompressionScheme>,
dfd_byte_offset: u32,
dfd_byte_length: u32,
kvd_byte_offset: u32,
kvd_byte_length: u32,
sgd_byte_offset: u64,
sgd_byte_length: u64,
}
impl Header {
const LENGTH: usize = 80;
fn from_bytes(data: &[u8; Self::LENGTH]) -> Self {
Self {
format: Format::new(u32::from_le_bytes(data[12..16].try_into().unwrap())),
type_size: u32::from_le_bytes(data[16..20].try_into().unwrap()),
pixel_width: u32::from_le_bytes(data[20..24].try_into().unwrap()),
pixel_height: u32::from_le_bytes(data[24..28].try_into().unwrap()),
pixel_depth: u32::from_le_bytes(data[28..32].try_into().unwrap()),
layer_count: u32::from_le_bytes(data[32..36].try_into().unwrap()),
face_count: u32::from_le_bytes(data[36..40].try_into().unwrap()),
level_count: u32::from_le_bytes(data[40..44].try_into().unwrap()),
supercompression_scheme: SupercompressionScheme::new(u32::from_le_bytes(data[44..48].try_into().unwrap())),
dfd_byte_offset: u32::from_le_bytes(data[48..52].try_into().unwrap()),
dfd_byte_length: u32::from_le_bytes(data[52..56].try_into().unwrap()),
kvd_byte_offset: u32::from_le_bytes(data[56..60].try_into().unwrap()),
kvd_byte_length: u32::from_le_bytes(data[60..64].try_into().unwrap()),
sgd_byte_offset: u64::from_le_bytes(data[64..72].try_into().unwrap()),
sgd_byte_length: u64::from_le_bytes(data[72..80].try_into().unwrap()),
}
}
fn validate(&self) -> ParseResult<()> {
if self.pixel_width == 0 {
return Err(ParseError::ZeroWidth);
}
if self.face_count == 0 {
return Err(ParseError::ZeroFaceCount);
}
Ok(())
}
}
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
struct LevelIndex {
offset: u64,
length_bytes: u64,
uncompressed_length_bytes: u64,
}
impl LevelIndex {
const LENGTH: usize = 24;
pub fn from_bytes(data: &[u8]) -> Self {
Self {
offset: u64::from_le_bytes(data[0..8].try_into().unwrap()),
length_bytes: u64::from_le_bytes(data[8..16].try_into().unwrap()),
uncompressed_length_bytes: u64::from_le_bytes(data[16..24].try_into().unwrap()),
}
}
}
bitflags::bitflags! {
#[repr(transparent)]
pub struct ChannelTypeQualifiers: u32 {
const LINEAR = (1 << 0);
const EXPONENT = (1 << 1);
const SIGNED = (1 << 2);
const FLOAT = (1 << 3);
}
}
bitflags::bitflags! {
#[derive(Default)]
#[repr(transparent)]
pub struct DataFormatFlags: u32 {
const STRAIGHT_ALPHA = 0;
const ALPHA_PREMULTIPLIED = (1 << 0);
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct DataFormatDescriptorHeader {
pub vendor_id: u32, //: 17;
pub descriptor_type: u32, //: 15;
pub version_number: u32, //: 16;
}
impl DataFormatDescriptorHeader {
const LENGTH: usize = 8;
pub const BASIC: Self = Self {
vendor_id: 0,
descriptor_type: 0,
version_number: 2,
};
fn parse(bytes: &[u8]) -> Result<(Self, usize), ParseError> {
let mut offset = 0;
let v = bytes_to_u32(bytes, &mut offset)?;
let vendor_id = shift_and_mask_lower(0, 17, v);
let descriptor_type = shift_and_mask_lower(17, 15, v);
let v = bytes_to_u32(bytes, &mut offset)?;
let version_number = shift_and_mask_lower(0, 16, v);
let descriptor_block_size = shift_and_mask_lower(16, 16, v);
Ok((
Self {
vendor_id,
descriptor_type,
version_number,
},
descriptor_block_size as usize,
))
}
}
pub struct DataFormatDescriptor<'data> {
pub header: DataFormatDescriptorHeader,
pub data: &'data [u8],
}
pub struct BasicDataFormatDescriptor<'data> {
/// None means Unspecified or is an otherwise unknown value
pub color_model: Option<ColorModel>, //: 8;
/// None means Unspecified or is an otherwise unknown value
pub color_primaries: Option<ColorPrimaries>, //: 8;
/// None means Unspecified or is an otherwise unknown value
pub transfer_function: Option<TransferFunction>, //: 8;
pub flags: DataFormatFlags, //: 8;
pub texel_block_dimensions: [u32; 4], //: 8 x 4;
pub bytes_planes: [u32; 8], //: 8 x 8;
sample_data: &'data [u8],
}
impl<'data> BasicDataFormatDescriptor<'data> {
pub fn parse(bytes: &'data [u8]) -> Result<Self, ParseError> {
let mut offset = 0;
let v = bytes_to_u32(bytes, &mut offset)?;
let model = shift_and_mask_lower(0, 8, v);
let primaries = shift_and_mask_lower(8, 8, v);
let transfer = shift_and_mask_lower(16, 8, v);
let flags = shift_and_mask_lower(24, 8, v);
let v = bytes_to_u32(bytes, &mut offset)?;
let texel_block_dimensions = [
shift_and_mask_lower(0, 8, v) + 1,
shift_and_mask_lower(8, 8, v) + 1,
shift_and_mask_lower(16, 8, v) + 1,
shift_and_mask_lower(24, 8, v) + 1,
];
let v = bytes_to_u32(bytes, &mut offset)?;
let mut bytes_planes = [0u32; 8];
bytes_planes[0] = shift_and_mask_lower(0, 8, v);
bytes_planes[1] = shift_and_mask_lower(8, 8, v);
bytes_planes[2] = shift_and_mask_lower(16, 8, v);
bytes_planes[3] = shift_and_mask_lower(24, 8, v);
let v = bytes_to_u32(bytes, &mut offset)?;
bytes_planes[4] = shift_and_mask_lower(0, 8, v);
bytes_planes[5] = shift_and_mask_lower(8, 8, v);
bytes_planes[6] = shift_and_mask_lower(16, 8, v);
bytes_planes[7] = shift_and_mask_lower(24, 8, v);
Ok(Self {
color_model: ColorModel::new(model),
color_primaries: ColorPrimaries::new(primaries),
transfer_function: TransferFunction::new(transfer),
flags: DataFormatFlags::from_bits_truncate(flags),
texel_block_dimensions,
bytes_planes,
sample_data: &bytes[offset..],
})
}
pub fn sample_information(&self) -> impl Iterator<Item = SampleInformation> + 'data {
SampleInformationIterator { data: self.sample_data }
}
}
struct SampleInformationIterator<'data> {
data: &'data [u8],
}
impl<'data> Iterator for SampleInformationIterator<'data> {
type Item = SampleInformation;
fn next(&mut self) -> Option<Self::Item> {
if self.data.len() < SampleInformation::LENGTH {
return None;
}
SampleInformation::parse(&self.data[..SampleInformation::LENGTH]).map_or(None, |sample_information| {
self.data = &self.data[SampleInformation::LENGTH..];
Some(sample_information)
})
}
}
#[derive(Debug)]
pub struct SampleInformation {
pub bit_offset: u32, //: 16;
pub bit_length: u32, //: 8;
pub channel_type: u32, //: 4;
pub channel_type_qualifiers: ChannelTypeQualifiers, //: 4;
pub sample_positions: [u32; 4], //: 8 x 4;
pub lower: u32, //;
pub upper: u32, //;
}
impl SampleInformation {
const LENGTH: usize = 16;
fn parse(bytes: &[u8]) -> Result<Self, ParseError> {
let mut offset = 0;
let v = bytes_to_u32(bytes, &mut offset)?;
let bit_offset = shift_and_mask_lower(0, 16, v);
let bit_length = shift_and_mask_lower(16, 8, v) + 1;
let channel_type = shift_and_mask_lower(24, 4, v);
let channel_type_qualifiers = ChannelTypeQualifiers::from_bits_truncate(shift_and_mask_lower(28, 4, v));
let v = bytes_to_u32(bytes, &mut offset)?;
let sample_positions = [
shift_and_mask_lower(0, 8, v),
shift_and_mask_lower(8, 8, v),
shift_and_mask_lower(16, 8, v),
shift_and_mask_lower(24, 8, v),
];
let lower = bytes_to_u32(bytes, &mut offset)?;
let upper = bytes_to_u32(bytes, &mut offset)?;
Ok(Self {
bit_offset,
bit_length,
channel_type,
channel_type_qualifiers,
sample_positions,
lower,
upper,
})
}
}
fn bytes_to_u32(bytes: &[u8], offset: &mut usize) -> Result<u32, ParseError> {
let v = u32::from_le_bytes(
bytes
.get(*offset..*offset + 4)
.ok_or(ParseError::UnexpectedEnd)?
.try_into()
.unwrap(),
);
*offset += 4;
Ok(v)
}
fn shift_and_mask_lower(shift: u32, mask: u32, value: u32) -> u32 {
(value >> shift) & ((1 << mask) - 1)
}