Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ impl Config {
"Parent zoom level number needs to be bigger than the input image zoom level."
)
}
if indexforzoom > (1 << ((parentzoomlevelvalue - zoomlevel) * 2)) - 1 {
panic!("indexforzoom value is larger than allowed.")
let max_allowed = (1u64 << ((parentzoomlevelvalue - zoomlevel) * 2)) - 1;
if (indexforzoom as u64) > max_allowed {
panic!("indexforzoom value is larger than allowed.");
}
Config {
tilesize,
Expand Down Expand Up @@ -113,7 +114,7 @@ impl Config {
}
}

pub fn resize_range(&self, img: &DynamicImage) -> Vec<(TileImage, u8)> {
pub fn resize_range(&self, img: &DynamicImage) -> Vec<(TileImage<'_>, u8)> {
<RangeInclusive<u8> as Clone>::clone(&self.zoomrangetoslice)
.into_par_iter()
.map(|x: u8| {
Expand Down Expand Up @@ -287,6 +288,14 @@ mod tests {
assert_eq!(config.targetrangetoslice, 0..=1023);
}

#[test]
// allow indexforzoom values greater than 63 when parent zoom is much larger
fn sub_image_large_index() {
let config = Config::new(256, 3, Some(7), 212, None, None, Some(2));
assert_eq!(config.zoomrangetoslice, 3..=3);
assert_eq!(config.targetrangetoslice, 0..=63);
}

#[test]
#[should_panic]
// should panic if zoomlevel is larger than parentzoomlevel
Expand Down
11 changes: 4 additions & 7 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ pub struct TileImage<'c> {
}

impl<'c> TileImage<'c> {
pub fn slice_tiles(&self, index: u8) -> Vec<Tile> {
pub fn slice_tiles(&self, index: u8) -> Vec<Tile<'_>> {
let tiles_per_row = 1 << index;
let morton_idx_max = tiles_per_row * tiles_per_row;
let tileimage_coord: (u16, u16) = match &self.config.parentzoomlevel {
None => (0, 0),
Some(parentzoomlevel) => {
if parentzoomlevel > &self.config.zoomlevel {
coord_of(self.config.indexforzoom.into())
} else {
(0, 0)
}
Some(parentzoomlevel) if parentzoomlevel > &self.config.zoomlevel => {
coord_of(self.config.indexforzoom.into())
}
_ => (0, 0),
};
let output_level = match &self.config.parentzoomlevel {
None => index,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn main() {
if args.preset.is_some() && &args.tileformat != "png" {
eprintln!(
"Error: The --preset argument cannot be used with --tileformat set to '{}'",
&args.tileformat
args.tileformat
);
std::process::exit(2);
}
Expand Down Expand Up @@ -136,7 +136,7 @@ fn main() {
let path = &args.output_dir.join(format!(
"{name}.{fmt}",
name = tile.name,
fmt = &args.tileformat
fmt = args.tileformat
));
img.to_image().save(path).unwrap();
}
Expand Down
Loading