diff --git a/assets/filter/click.px_filter.png b/assets/filter/click.px_filter.png index 85ada80..25fe2ab 100644 Binary files a/assets/filter/click.px_filter.png and b/assets/filter/click.px_filter.png differ diff --git a/assets/filter/dim.px_filter.png b/assets/filter/dim.px_filter.png index 862dd12..42f5ace 100644 Binary files a/assets/filter/dim.px_filter.png and b/assets/filter/dim.px_filter.png differ diff --git a/assets/filter/fade_to_black.px_filter.png b/assets/filter/fade_to_black.px_filter.png index addfdde..0e153e7 100644 Binary files a/assets/filter/fade_to_black.px_filter.png and b/assets/filter/fade_to_black.px_filter.png differ diff --git a/assets/filter/hover.px_filter.png b/assets/filter/hover.px_filter.png index b3709b6..2e4a8e9 100644 Binary files a/assets/filter/hover.px_filter.png and b/assets/filter/hover.px_filter.png differ diff --git a/assets/filter/invert.px_filter.png b/assets/filter/invert.px_filter.png index cbf7328..56ea4c0 100644 Binary files a/assets/filter/invert.px_filter.png and b/assets/filter/invert.px_filter.png differ diff --git a/assets/filter/invert_dim.px_filter.png b/assets/filter/invert_dim.px_filter.png index 9ecddb1..087bd70 100644 Binary files a/assets/filter/invert_dim.px_filter.png and b/assets/filter/invert_dim.px_filter.png differ diff --git a/assets/palette/palette_1.palette.png b/assets/palette/palette_1.palette.png index 0f65e37..3acabf4 100644 Binary files a/assets/palette/palette_1.palette.png and b/assets/palette/palette_1.palette.png differ diff --git a/assets/palette/palette_2.palette.png b/assets/palette/palette_2.palette.png index 41328c2..a82ee9c 100644 Binary files a/assets/palette/palette_2.palette.png and b/assets/palette/palette_2.palette.png differ diff --git a/assets/sprite/mage_cast.px_sprite.png b/assets/sprite/mage_cast.px_sprite.png index 0b53564..6be2900 100644 Binary files a/assets/sprite/mage_cast.px_sprite.png and b/assets/sprite/mage_cast.px_sprite.png differ diff --git a/assets/sprite/runner.px_sprite.png b/assets/sprite/runner.px_sprite.png index 412c75e..5ae397d 100644 Binary files a/assets/sprite/runner.px_sprite.png and b/assets/sprite/runner.px_sprite.png differ diff --git a/assets/sprite/snow_1.px_sprite.png b/assets/sprite/snow_1.px_sprite.png index 3041768..9f47bfa 100644 Binary files a/assets/sprite/snow_1.px_sprite.png and b/assets/sprite/snow_1.px_sprite.png differ diff --git a/assets/sprite/snow_2.px_sprite.png b/assets/sprite/snow_2.px_sprite.png index 85c2635..2cd2041 100644 Binary files a/assets/sprite/snow_2.px_sprite.png and b/assets/sprite/snow_2.px_sprite.png differ diff --git a/assets/tileset/tileset.px_tileset.png b/assets/tileset/tileset.px_tileset.png index 3ecc6fe..f54addb 100644 Binary files a/assets/tileset/tileset.px_tileset.png and b/assets/tileset/tileset.px_tileset.png differ diff --git a/assets/typeface/animated_typeface.px_typeface.png b/assets/typeface/animated_typeface.px_typeface.png index 7bf8a7e..d01f06f 100644 Binary files a/assets/typeface/animated_typeface.px_typeface.png and b/assets/typeface/animated_typeface.px_typeface.png differ diff --git a/assets/typeface/typeface.px_typeface.png b/assets/typeface/typeface.px_typeface.png index 34e3ae1..c7a24ec 100644 Binary files a/assets/typeface/typeface.px_typeface.png and b/assets/typeface/typeface.px_typeface.png differ diff --git a/src/animation.rs b/src/animation.rs index c2d00b1..9c58ff5 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -278,10 +278,12 @@ pub(crate) fn draw_spatial<'a, A: Animation + Spatial>( PxCanvas::World => position - *camera, PxCanvas::Camera => position, }; + let position = IVec2::new(position.x, image.size().y as i32 - position.y); + let size = size.as_ivec2(); let mut image = image.slice_mut(IRect { - min: position, - max: position + size.as_ivec2(), + min: position - IVec2::new(0, size.y), + max: position + IVec2::new(size.x, 0), }); draw_animation(spatial, param, &mut image, animation, filters); diff --git a/src/cursor.rs b/src/cursor.rs index 5423d37..267e8a2 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -132,7 +132,10 @@ fn draw_cursor( let mut image = PxImageSliceMut::from_image_mut(images.get_mut(&screen.image).unwrap()); - if let Some(pixel) = image.get_pixel_mut(cursor_pos.as_ivec2()) { + if let Some(pixel) = image.get_pixel_mut(IVec2::new( + cursor_pos.x as i32, + image.height() as i32 - 1 - cursor_pos.y as i32, + )) { *pixel = filter .get_pixel(IVec2::new(*pixel as i32, 0)) .expect("filter is incorrect size"); diff --git a/src/filter.rs b/src/filter.rs index bd1c95a..cca59a6 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -100,7 +100,7 @@ impl AssetLoader for PxFilterLoader { /// and an image file. The image should have pixels in the same positions as the palette. /// The position of each pixel describes the mapping of colors. The image must only contain colors /// that are also in the palette. For animated filters, arrange a number of filters -/// from the bottom-left corner, moving rightwards, wrapping upwards when it gets to the edge +/// from the top-left corner, moving rightwards, wrapping downwards when it gets to the edge /// of the image. For examples, see the `assets/` directory in this repository. `fade_to_black.png` /// is an animated filter. #[derive(Asset, Reflect, Debug)] @@ -116,7 +116,7 @@ impl Animation for PxFilter { fn draw( &self, - _: Self::Param, + (): (), image: &mut PxImageSliceMut, frame: impl Fn(UVec2) -> usize, _: impl Fn(u8) -> u8, diff --git a/src/image.rs b/src/image.rs index 95b036b..7902e57 100644 --- a/src/image.rs +++ b/src/image.rs @@ -79,19 +79,6 @@ impl PxImage

{ } } - pub(crate) fn flip_vert(&self) -> Self { - PxImage { - image: self - .image - .chunks_exact(self.width) - .rev() - .flatten() - .copied() - .collect(), - width: self.width, - } - } - pub(crate) fn split_vert(self, chunk_height: usize) -> Vec { self.image .chunks_exact(chunk_height * self.width) @@ -149,11 +136,6 @@ impl PxImage> { .convert(TextureFormat::Rgba8UnormSrgb) .ok_or_else(|| anyhow!("could not convert image to `Rgba8UnormSrgb`"))? .data - .chunks_exact(image.texture_descriptor.size.width as usize * 4) - .rev() - .flatten() - .copied() - .collect::>() .chunks_exact(4) .map(|color| { (color[3] != 0) @@ -179,31 +161,6 @@ impl PxImage> { }) } - pub(crate) fn palette_indices_unaligned(palette: &Palette, image: &Image) -> Result { - Ok(Self { - image: image - .convert(TextureFormat::Rgba8UnormSrgb) - .unwrap() - .data - .chunks_exact(4) - .map(|color| { - (color[3] != 0) - .then(|| { - palette - .indices - .get(&[color[0], color[1], color[2]]) - .copied() - .ok_or_else(|| { - anyhow!("a sprite contained a color that wasn't in the palette") - }) - }) - .transpose() - }) - .collect::>()?, - width: image.texture_descriptor.size.width as usize, - }) - } - pub(crate) fn trim_right(&mut self) { while (0..self.height()).all(|row| self.image[self.width * (row + 1) - 1].is_none()) { for row in (0..self.height()).rev() { @@ -265,6 +222,10 @@ impl<'a, P: Pixel> PxImageSliceMut<'a, P> { self.slice.size().x as u32 } + pub(crate) fn height(&self) -> u32 { + self.slice.size().y as u32 + } + pub(crate) fn image_width(&self) -> usize { self.width } diff --git a/src/palette.rs b/src/palette.rs index fcd39e2..c3a359c 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -93,9 +93,7 @@ impl Palette { .convert(TextureFormat::Rgba8UnormSrgb) .unwrap() .data - .chunks_exact(palette.texture_descriptor.size.width as usize * 4) - .rev() - .flatten() + .iter() .copied() // TODO Should use chunks here .fold( diff --git a/src/sprite.rs b/src/sprite.rs index 8ffc013..089b53c 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -386,13 +386,13 @@ fn dither_slice, const MAP_SIZE: usize>( // TODO Use more helpers // TODO Feature gate +// TODO Immediate function version fn image_to_sprite( mut to_sprites: Query<(&ImageToSprite, &mut Handle)>, images: Res>, palette: PaletteParam, mut sprites: ResMut>, ) { - let span = info_span!("init", name = "init").entered(); if to_sprites.iter().next().is_none() { return; } @@ -413,10 +413,8 @@ fn image_to_sprite( .map(|&color| color.into()) .collect::>()[..], ); - drop(span); to_sprites.iter_mut().for_each(|(image, mut sprite)| { - let span = info_span!("making_images", name = "making_images").entered(); let dither = &image.dither; let image = images.get(&image.image).unwrap(); @@ -446,7 +444,6 @@ fn image_to_sprite( .zip(sprite.data.iter_mut()) .enumerate() .collect::>(); - drop(span); pixels.par_chunk_map_mut(ComputeTaskPool::get(), 20, |_, pixels| { use DitherAlgorithm::*; diff --git a/src/text.rs b/src/text.rs index 041386f..cb0191a 100644 --- a/src/text.rs +++ b/src/text.rs @@ -71,7 +71,7 @@ impl AssetLoader for PxTypefaceLoader { .load(reader, &settings.image_loader_settings, load_context) .await?; let palette = asset_palette().await; - let indices = PxImage::palette_indices_unaligned(palette, &image)?; + let indices = PxImage::palette_indices(palette, &image)?; let height = indices.height(); let character_count = settings.characters.chars().count(); @@ -81,14 +81,8 @@ impl AssetLoader for PxTypefaceLoader { settings .characters .chars() - .zip( - indices - .split_vert(height / character_count) - .into_iter() - .rev(), - ) - .map(|(character, image)| { - let mut image = image.flip_vert(); + .zip(indices.split_vert(height / character_count).into_iter()) + .map(|(character, mut image)| { image.trim_right(); let image_width = image.width(); let image_area = image.area();