Some checks failed
API and SemVer surface / api-surface (push) Failing after 1m34s
Native code generation / deterministic (push) Has been cancelled
Concurrency and resource soak audit / soak (push) Has been cancelled
Documentation / documentation (push) Has been cancelled
performance evidence / audit (push) Has been cancelled
First release candidate / non-fuzz-release-gate (push) Has been cancelled
Release platform and feature matrix / audit (push) Has been cancelled
Release platform and feature matrix / matrix (false, linux-stable-minimal, x86_64-unknown-linux-gnu, stable) (push) Has been cancelled
Release platform and feature matrix / matrix (false, macos-stable-portable, x86_64-apple-darwin, stable) (push) Has been cancelled
Release platform and feature matrix / matrix (false, windows-stable-portable, x86_64-pc-windows-gnu, stable) (push) Has been cancelled
Release platform and feature matrix / matrix (true, linux-msrv-portable, x86_64-unknown-linux-gnu, 1.96.0) (push) Has been cancelled
Release platform and feature matrix / matrix (true, linux-stable-default, x86_64-unknown-linux-gnu, stable) (push) Has been cancelled
Release platform and feature matrix / matrix (true, linux-stable-features, x86_64-unknown-linux-gnu, stable) (push) Has been cancelled
Release platform and feature matrix / matrix (true, linux-stable-release-surface, x86_64-unknown-linux-gnu, stable) (push) Has been cancelled
Dependency and supply-chain audit / audit (push) Has been cancelled
Native release artifact audit / audit (push) Has been cancelled
Imaging and meshing gate / native (push) Failing after 53s
JPEG 2000 feature / linux (push) Successful in 2m49s
Native Rust workspace compile / compile (push) Failing after 59s
Skia feature / linux (push) Has been cancelled
123 lines
4.8 KiB
Rust
123 lines
4.8 KiB
Rust
// Exact Rust translations of LibreMetaverse.Tests/BakerTests.cs.
|
|
// Source SHA-256: 7727140f0fbf2c77ed7a6f3f468798d8f7ba96c5d9889246a2bccd2d4bd8def2
|
|
|
|
#![allow(clippy::similar_names)] // Baker/baked terminology matches the API under test.
|
|
|
|
use super::*;
|
|
use libremetaverse_imaging::{ManagedImage, ManagedImageImageChannels};
|
|
use libremetaverse_types::Color4;
|
|
|
|
fn gray_alpha_image(value: u8) -> ManagedImage {
|
|
let channels = ManagedImageImageChannels(
|
|
ManagedImageImageChannels::GRAY.0 | ManagedImageImageChannels::ALPHA.0,
|
|
);
|
|
let mut image = ManagedImage::new(4, 4, channels).unwrap();
|
|
image.red.fill(value);
|
|
image.alpha.fill(255);
|
|
image
|
|
}
|
|
|
|
fn texture_data(
|
|
image: ManagedImage,
|
|
color: Color4,
|
|
index: AvatarTextureIndex,
|
|
) -> AppearanceManagerTextureData {
|
|
let mut data = AppearanceManagerTextureData::new().unwrap();
|
|
data.texture = Some(assets::AssetTexture::new_with_managed_image(image).unwrap());
|
|
data.color = color;
|
|
data.texture_index = index;
|
|
data
|
|
}
|
|
|
|
// parity-case: LibreMetaverse.Tests/BakerTests.cs::BakerTests.Bake_GrayscaleLayerTexture_DoesNotThrow::test c3fc1d2c16b5f8d69678a6cf05a3a275e0b657f3a6e7f6788f350f2a107200b3 translated
|
|
#[test]
|
|
fn bake_grayscale_layer_texture_does_not_throw() {
|
|
let color = Color4::new_with_single_single_single_single(0.5, 0.25, 0.75, 1.0).unwrap();
|
|
let data = texture_data(gray_alpha_image(128), color, AvatarTextureIndex::UpperShirt);
|
|
let mut baker = imaging::Baker::new(BakeType::UpperBody).unwrap();
|
|
baker.add_texture(data).unwrap();
|
|
baker.bake().unwrap();
|
|
let baked = baker.baked_texture().unwrap();
|
|
let image = baked.image.unwrap();
|
|
assert_eq!((image.width, image.height), (1024, 1024));
|
|
assert_eq!((image.red[0], image.green[0], image.blue[0]), (63, 31, 94));
|
|
assert_eq!(image.alpha[0], 255);
|
|
assert_eq!(image.bump[0], 0);
|
|
}
|
|
|
|
// parity-case: LibreMetaverse.Tests/BakerTests.cs::BakerTests.Bake_GrayscaleHairTextureNoSkin_DoesNotThrow::test e48b737d9138e63cda98b5e80bf561a80d1dab5de78901ac9e1bb320ca281eb6 translated
|
|
#[test]
|
|
fn bake_grayscale_hair_texture_no_skin_does_not_throw() {
|
|
let data = texture_data(
|
|
gray_alpha_image(200),
|
|
Color4::white(),
|
|
AvatarTextureIndex::Hair,
|
|
);
|
|
let mut baker = imaging::Baker::new(BakeType::Head).unwrap();
|
|
baker.add_texture(data).unwrap();
|
|
baker.bake().unwrap();
|
|
assert!(baker.baked_texture().is_some());
|
|
}
|
|
|
|
// parity-case: LibreMetaverse.Tests/BakerTests.cs::BakerTests.LoadResourceLayer_HeadColorTga_LoadsFromCharacterDirectory::test 5a9b80005a51f04a227ca392218725d50704d038783e04fc49bb955997c22e76 translated
|
|
#[test]
|
|
fn load_resource_layer_head_color_tga_loads_from_character_directory() {
|
|
assert!(
|
|
imaging::Baker::load_resource_layer("head_color.tga".into())
|
|
.unwrap()
|
|
.is_some()
|
|
);
|
|
}
|
|
|
|
// parity-case: LibreMetaverse.Tests/BakerTests.cs::BakerTests.LoadResourceLayer_CachedResourceNotCorruptedByCallerMutation::test 18b458bbd7bb13d2b68711f7d3495193f1b4edac9c1f776930ad2c172f97cd49 translated
|
|
#[test]
|
|
fn load_resource_layer_cached_resource_not_corrupted_by_caller_mutation() {
|
|
imaging::Baker::load_resource_layer("head_color.tga".into()).unwrap();
|
|
let mut second = imaging::Baker::load_resource_layer("head_color.tga".into())
|
|
.unwrap()
|
|
.unwrap();
|
|
let original_width = second.width;
|
|
let original_height = second.height;
|
|
second
|
|
.resize_nearest_neighbor(original_width / 2, original_height / 2)
|
|
.unwrap();
|
|
let third = imaging::Baker::load_resource_layer("head_color.tga".into())
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(third.width, original_width);
|
|
assert_eq!(third.height, original_height);
|
|
}
|
|
|
|
// parity-case: LibreMetaverse.Tests/BakerTests.cs::BakerTests.ResizeToBakeDimensions_SourceSmallerInOneAxisOnly_ScalesRatherThanTiles::test ce5bd346b48cb19dbc0248403eafefb07309d4e05e675e9a02db5a46d7cd65ff translated
|
|
#[test]
|
|
fn resize_to_bake_dimensions_source_smaller_in_one_axis_only_scales_rather_than_tiles() {
|
|
let mut source = ManagedImage::new(2, 8, ManagedImageImageChannels::COLOR).unwrap();
|
|
for y in 0..8 {
|
|
for x in 0..2 {
|
|
source.red[y * 2 + x] = u8::try_from(y * 10).unwrap();
|
|
}
|
|
}
|
|
let result = imaging::Baker::resize_to_bake_dimensions(source, 4, 4)
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(result.width, 4);
|
|
assert_eq!(result.height, 4);
|
|
assert!(result.red[3 * 4] > 50);
|
|
}
|
|
|
|
#[test]
|
|
fn bake_type_for_preserves_the_reference_base_layer_mapping() {
|
|
assert_eq!(
|
|
imaging::Baker::bake_type_for(AvatarTextureIndex::UpperShirt).unwrap(),
|
|
BakeType::UpperBody
|
|
);
|
|
assert_eq!(
|
|
imaging::Baker::bake_type_for(AvatarTextureIndex::UpperTattoo).unwrap(),
|
|
BakeType::Unknown
|
|
);
|
|
assert_eq!(
|
|
imaging::Baker::bake_type_for(AvatarTextureIndex::Aux1Tattoo).unwrap(),
|
|
BakeType::Unknown
|
|
);
|
|
}
|