1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
//! Layouts for a pixel format.
use crate::bind;
/// A layout for a packed pixel format.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PackedPixelLayout {
/// A layout is in 8 bits with 4 components, as below:
///
/// ```text
/// 1112 2233
/// ```
_332,
/// A layout is in 16 bits with 4 components with same size, as below:
///
/// ```text
/// 0000 1111 2222 3333
/// ```
_4444,
/// A layout is in 16 bits with 4 components where only one component is 1 bit but others is 5 bits, as below:
///
/// ```text
/// 01111 1222 2233 3333
/// ```
_1555,
/// A layout is in 16 bits with 4 components where only one component is 1 bit but others is 5 bits, as below:
///
/// ```text
/// 0000 0111 1122 2223
/// ```
_5551,
/// A layout is in 16 bits with 3 components where only one component is 6 bits but others is 5 bits, as below:
///
/// ```text
/// 0000 0111 1112 2222
/// ```
_565,
/// A layout is in 32 bits with 4 components with same size, as below:
///
/// ```text
/// 0000 0000 1111 1111 2222 2222 3333 3333
/// ```
_8888,
/// A layout is in 32 bits with 4 components where only one component is 2 bits but others is 10 bits, as below:
///
/// ```text
/// 0011 1111 1111 2222 2222 2233 3333 3333
/// ```
_2101010,
/// A layout is in 32 bits with 4 components where only one component is 2 bits but others is 10 bits, as below:
///
/// ```text
/// 0000 0000 0011 1111 1111 2222 2222 2233
/// ```
_1010102,
}
impl PackedPixelLayout {
#[allow(clippy::unnecessary_cast)]
pub(super) fn as_raw(self) -> u32 {
(match self {
PackedPixelLayout::_332 => bind::SDL_PACKEDLAYOUT_332,
PackedPixelLayout::_4444 => bind::SDL_PACKEDLAYOUT_4444,
PackedPixelLayout::_1555 => bind::SDL_PACKEDLAYOUT_1555,
PackedPixelLayout::_5551 => bind::SDL_PACKEDLAYOUT_5551,
PackedPixelLayout::_565 => bind::SDL_PACKEDLAYOUT_565,
PackedPixelLayout::_8888 => bind::SDL_PACKEDLAYOUT_8888,
PackedPixelLayout::_2101010 => bind::SDL_PACKEDLAYOUT_2101010,
PackedPixelLayout::_1010102 => bind::SDL_PACKEDLAYOUT_1010102,
}) as u32
}
}
impl From<bind::SDL_PixelFormatEnum> for PackedPixelLayout {
fn from(raw: bind::SDL_PixelFormatEnum) -> Self {
match (raw >> 16) & 0xf {
bind::SDL_PACKEDLAYOUT_332 => PackedPixelLayout::_332,
bind::SDL_PACKEDLAYOUT_4444 => PackedPixelLayout::_4444,
bind::SDL_PACKEDLAYOUT_1555 => PackedPixelLayout::_1555,
bind::SDL_PACKEDLAYOUT_5551 => PackedPixelLayout::_5551,
bind::SDL_PACKEDLAYOUT_565 => PackedPixelLayout::_565,
bind::SDL_PACKEDLAYOUT_8888 => PackedPixelLayout::_8888,
bind::SDL_PACKEDLAYOUT_2101010 => PackedPixelLayout::_2101010,
bind::SDL_PACKEDLAYOUT_1010102 => PackedPixelLayout::_1010102,
_ => unreachable!(),
}
}
}