rust/mapgen/src/theme.rs
author sheepluva
Fri, 03 Jul 2020 23:51:47 +0200
branchui-scaling
changeset 15663 d92eeb468dad
parent 15120 febccab419b1
child 15914 c571d4b8879c
child 15927 0710feb75c99
permissions -rw-r--r--
Merge branch 1.0.0 into branch ui-scaling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     1
use png::{ColorType, Decoder, DecodingError};
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     2
use std::{
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     3
    fs::{read_dir, File},
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     4
    io,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     5
    io::BufReader,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     6
    path::Path,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     7
    slice::{from_raw_parts, from_raw_parts_mut},
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     8
};
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
     9
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    10
use integral_geometry::Size;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    11
use vec2d::Vec2D;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    12
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    13
pub struct ThemeSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    14
    pixels: Vec2D<u32>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    15
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    16
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    17
impl ThemeSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    18
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    19
    pub fn size(&self) -> Size {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    20
        self.pixels.size()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    21
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    22
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    23
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    24
    pub fn width(&self) -> usize {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    25
        self.size().width
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    26
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    27
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    28
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    29
    pub fn height(&self) -> usize {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    30
        self.size().height
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    31
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    32
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    33
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    34
    pub fn rows(&self) -> impl DoubleEndedIterator<Item = &[u32]> {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    35
        self.pixels.rows()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    36
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    37
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    38
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    39
    pub fn get_row(&self, index: usize) -> &[u32] {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    40
        &self.pixels[index]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    41
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    42
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    43
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    44
    pub fn get_pixel(&self, x: usize, y: usize) -> u32 {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    45
        self.pixels[y][x]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    46
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    47
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    48
    pub fn to_transposed(&self) -> ThemeSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    49
        let size = self.size().transpose();
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    50
        let mut pixels = Vec2D::new(size, 0u32);
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    51
        for (y, row) in self.pixels.rows().enumerate() {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    52
            for (x, v) in row.iter().enumerate() {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    53
                pixels[x][y] = *v;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    54
            }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    55
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    56
        ThemeSprite { pixels }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    57
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    58
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    59
    pub fn to_tiled(&self) -> TiledSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    60
        let size = self.size();
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    61
        assert!(size.is_power_of_two());
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    62
        let tile_width_shift = size.width.trailing_zeros() as usize + 2;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    63
        let mut pixels = vec![0u32; size.area()];
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    64
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    65
        for (y, row) in self.pixels.rows().enumerate() {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    66
            for (x, v) in row.iter().enumerate() {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    67
                pixels[get_tiled_index(x, y, tile_width_shift)] = *v;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    68
            }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    69
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    70
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    71
        TiledSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    72
            tile_width_shift,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    73
            size,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    74
            pixels,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    75
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    76
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    77
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    78
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    79
#[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    80
fn get_tiled_index(x: usize, y: usize, tile_width_shift: usize) -> usize {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    81
    (((y >> 2) << tile_width_shift) + ((x >> 2) << 4)) + ((y & 0b11) << 2) + (x & 0b11)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    82
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    83
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    84
pub struct TiledSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    85
    tile_width_shift: usize,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    86
    size: Size,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    87
    pixels: Vec<u32>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    88
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    89
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    90
impl TiledSprite {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    91
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    92
    pub fn size(&self) -> Size {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    93
        self.size
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    94
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    95
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    96
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    97
    pub fn width(&self) -> usize {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    98
        self.size().width
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
    99
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   100
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   101
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   102
    pub fn height(&self) -> usize {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   103
        self.size().height
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   104
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   105
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   106
    #[inline]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   107
    pub fn get_pixel(&self, x: usize, y: usize) -> u32 {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   108
        self.pixels[get_tiled_index(x, y, self.tile_width_shift)]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   109
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   110
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   111
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   112
pub struct Theme {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   113
    land_texture: Option<ThemeSprite>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   114
    border_texture: Option<ThemeSprite>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   115
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   116
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   117
impl Theme {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   118
    pub fn land_texture(&self) -> Option<&ThemeSprite> {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   119
        self.land_texture.as_ref()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   120
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   121
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   122
    pub fn border_texture(&self) -> Option<&ThemeSprite> {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   123
        self.border_texture.as_ref()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   124
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   125
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   126
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   127
#[derive(Debug)]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   128
pub enum ThemeLoadError {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   129
    File(io::Error),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   130
    Decoding(DecodingError),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   131
    Format(String),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   132
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   133
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   134
impl From<io::Error> for ThemeLoadError {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   135
    fn from(e: io::Error) -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   136
        ThemeLoadError::File(e)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   137
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   138
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   139
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   140
impl From<DecodingError> for ThemeLoadError {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   141
    fn from(e: DecodingError) -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   142
        ThemeLoadError::Decoding(e)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   143
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   144
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   145
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   146
impl Theme {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   147
    pub fn new() -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   148
        Theme {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   149
            land_texture: None,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   150
            border_texture: None,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   151
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   152
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   153
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   154
    pub fn load(path: &Path) -> Result<Theme, ThemeLoadError> {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   155
        let mut theme = Self::new();
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   156
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   157
        for entry in read_dir(path)? {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   158
            let file = entry?;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   159
            if file.file_name() == "LandTex.png" {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   160
                theme.land_texture = Some(load_sprite(&file.path())?)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   161
            } else if file.file_name() == "Border.png" {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   162
                theme.border_texture = Some(load_sprite(&file.path())?)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   163
            }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   164
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   165
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   166
        Ok(theme)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   167
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   168
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   169
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   170
fn load_sprite(path: &Path) -> Result<ThemeSprite, ThemeLoadError> {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   171
    let decoder = Decoder::new(BufReader::new(File::open(path)?));
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   172
    let (info, mut reader) = decoder.read_info()?;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   173
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   174
    if info.color_type != ColorType::RGBA {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   175
        return Err(ThemeLoadError::Format(format!(
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   176
            "Unexpected format: {:?}",
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   177
            info.color_type
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   178
        )));
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   179
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   180
    let size = Size::new(info.width as usize, info.height as usize);
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   181
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   182
    let mut pixels: Vec2D<u32> = Vec2D::new(size, 0);
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   183
    reader.next_frame(slice_u32_to_u8_mut(pixels.as_mut_slice()))?;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   184
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   185
    Ok(ThemeSprite { pixels })
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   186
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   187
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   188
pub fn slice_u32_to_u8(slice_u32: &[u32]) -> &[u8] {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   189
    unsafe { from_raw_parts::<u8>(slice_u32.as_ptr() as *const u8, slice_u32.len() * 4) }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   190
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   191
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   192
pub fn slice_u32_to_u8_mut(slice_u32: &mut [u32]) -> &mut [u8] {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   193
    unsafe { from_raw_parts_mut::<u8>(slice_u32.as_mut_ptr() as *mut u8, slice_u32.len() * 4) }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14710
diff changeset
   194
}