rust/mapgen/src/theme.rs
changeset 16102 5d302b12d837
parent 16089 3f73daa3f212
child 16111 669cdf697f16
equal deleted inserted replaced
16101:a4cbc6926439 16102:5d302b12d837
    20     pub fn size(&self) -> Size {
    20     pub fn size(&self) -> Size {
    21         self.pixels.size()
    21         self.pixels.size()
    22     }
    22     }
    23 
    23 
    24     #[inline]
    24     #[inline]
    25     pub fn width(&self) -> usize {
    25     pub fn width(&self) -> u32 {
    26         self.size().width
    26         self.size().width
    27     }
    27     }
    28 
    28 
    29     #[inline]
    29     #[inline]
    30     pub fn height(&self) -> usize {
    30     pub fn height(&self) -> u32 {
    31         self.size().height
    31         self.size().height
    32     }
    32     }
    33 
    33 
    34     #[inline]
    34     #[inline]
    35     pub fn rows(&self) -> impl DoubleEndedIterator<Item = &[u32]> {
    35     pub fn rows(&self) -> impl DoubleEndedIterator<Item = &[u32]> {
    59 
    59 
    60     pub fn to_tiled(&self) -> TiledSprite {
    60     pub fn to_tiled(&self) -> TiledSprite {
    61         let size = self.size();
    61         let size = self.size();
    62         assert!(size.is_power_of_two());
    62         assert!(size.is_power_of_two());
    63         let tile_width_shift = size.width.trailing_zeros() as usize + 2;
    63         let tile_width_shift = size.width.trailing_zeros() as usize + 2;
    64         let mut pixels = vec![0u32; size.area()];
    64         let mut pixels = vec![0u32; size.area() as usize];
    65 
    65 
    66         for (y, row) in self.pixels.rows().enumerate() {
    66         for (y, row) in self.pixels.rows().enumerate() {
    67             for (x, v) in row.iter().enumerate() {
    67             for (x, v) in row.iter().enumerate() {
    68                 pixels[get_tiled_index(x, y, tile_width_shift)] = *v;
    68                 pixels[get_tiled_index(x, y, tile_width_shift)] = *v;
    69             }
    69             }
    93     pub fn size(&self) -> Size {
    93     pub fn size(&self) -> Size {
    94         self.size
    94         self.size
    95     }
    95     }
    96 
    96 
    97     #[inline]
    97     #[inline]
    98     pub fn width(&self) -> usize {
    98     pub fn width(&self) -> u32 {
    99         self.size().width
    99         self.size().width
   100     }
   100     }
   101 
   101 
   102     #[inline]
   102     #[inline]
   103     pub fn height(&self) -> usize {
   103     pub fn height(&self) -> u32 {
   104         self.size().height
   104         self.size().height
   105     }
   105     }
   106 
   106 
   107     #[inline]
   107     #[inline]
   108     pub fn get_pixel(&self, x: usize, y: usize) -> u32 {
   108     pub fn get_pixel(&self, x: usize, y: usize) -> u32 {
   235         return Err(ThemeLoadError::Format(format!(
   235         return Err(ThemeLoadError::Format(format!(
   236             "Unexpected format: {:?}",
   236             "Unexpected format: {:?}",
   237             info.color_type
   237             info.color_type
   238         )));
   238         )));
   239     }
   239     }
   240     let size = Size::new(info.width as usize, info.height as usize);
   240     let size = Size::new(info.width, info.height);
   241 
   241 
   242     let mut pixels: Vec2D<u32> = Vec2D::new(&size, 0);
   242     let mut pixels: Vec2D<u32> = Vec2D::new(&size, 0);
   243     reader.next_frame(slice_u32_to_u8_mut(pixels.as_mut_slice()))?;
   243     reader.next_frame(slice_u32_to_u8_mut(pixels.as_mut_slice()))?;
   244 
   244 
   245     Ok(ThemeSprite { pixels })
   245     Ok(ThemeSprite { pixels })