mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 18:14:00 +01:00
Refuse an export size that would scale a tall set's tile past the largest image side, before any buffer is allocated
This commit is contained in:
1 parent
1dd4b9758b
commit
2ffa8bfa6a
2 files changed
+24
No files matched your search
@@ -614,6 +614,7 @@ pub fn list_outputs(project: &Project, ts: usize, mesh_name: &str, opts: &Export
|
||||
let grid = set.tile_grid();
|
||||
let (block_resolution, block_size) = (set.block_resolution(), set.block_size());
|
||||
let scale = |side| scale_export_side(side, block_resolution, opts.size);
|
||||
check_scaled_size(set, (scale(block_size.0), scale(block_size.1)))?;
|
||||
for (i, map) in opts.preset.maps.iter().enumerate() {
|
||||
if !map.channels.iter().any(|(_, s)| source_present(set, s)) {
|
||||
continue;
|
||||
@@ -923,6 +924,9 @@ pub fn render_planned_maps(input: &ExportInput, options: &ExportOptions, planned
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
// Before any image buffer is allocated
|
||||
check_scaled_size(set, (scale_export_side(tile_res, tile_res, options.size), scale_export_side(tile_height, tile_res, options.size)))?;
|
||||
|
||||
// Padding stays inside each UV tile
|
||||
let padding_maps = |max_dist| PaddingMaps::new(set.uv_padding, input.coverage, (width, height), max_dist, (tile_res, tile_height), input.seams);
|
||||
let padding = match options.padding {
|
||||
@@ -1052,6 +1056,14 @@ fn tile_side(set: &TextureSet, tile: u32, block_resolution: u32) -> u32 {
|
||||
((block_resolution as f32 * set.tile_scale(tile)).round() as u32).clamp(1, block_resolution.max(1))
|
||||
}
|
||||
|
||||
/// Refuse an export size that scales a non-square set's UV tile past the largest image side
|
||||
fn check_scaled_size(set: &TextureSet, (width, height): (u32, u32)) -> Result<()> {
|
||||
if width.max(height) > MAX_IMAGE_SIZE {
|
||||
return Err(FormatError::Invalid(format!("export size makes texture set \"{}\" {width}×{height}, over {MAX_IMAGE_SIZE} texels a side", set.name)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Scale an image side relative to the source block, keeping a pixel for any nonempty source.
|
||||
pub fn scale_export_side(source_side: u32, block_resolution: u32, export_size: Option<u32>) -> u32 {
|
||||
let export_size = export_size.unwrap_or(block_resolution);
|
||||
|
||||
@@ -1169,6 +1169,18 @@ fn psd_holds_the_merged_image_planar() {
|
||||
assert!(samples[2 * 64 * 64..].as_chunks::<2>().0.iter().all(|sample| *sample == [128, 0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_export_size_that_scales_a_tall_set_past_the_largest_side_is_refused() {
|
||||
let mut fx = Fx::new(&default_channels());
|
||||
fx.project.texture_sets[0].set_size(RES, RES * 4);
|
||||
let mut options = one_map(FileFormat::Png, 8, roughness());
|
||||
options.size = Some(MAX_IMAGE_SIZE / 2);
|
||||
assert!(list_outputs(&fx.project, 0, "sphere", &options).is_err(), "the height would be twice the largest side");
|
||||
|
||||
options.size = Some(MAX_IMAGE_SIZE / 4);
|
||||
assert_eq!(list_outputs(&fx.project, 0, "sphere", &options).unwrap().len(), 1, "a tall export within the largest side is kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn psd_plan_rejects_a_version_one_atlas_over_its_dimension_limit() {
|
||||
let mut fx = Fx::new(&default_channels());
|
||||
|
||||
Reference in new issue
Block a user