use crate::Surface;
use crate::convert::{PixelConverter, u8_to_f32};
#[cfg(feature = "softbuffer")]
use crate::sb::Zrgb;

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> PixelConverter<[u8; 2]> for Surface<'_, S, [u8; 2]> {
    fn pixel_to_l8(pixel: &[u8; 2]) -> u8 {
        pixel[0]
    }

    fn pixel_to_la8(pixel: &[u8; 2]) -> [u8; 2] {
        *pixel
    }

    fn pixel_to_l32(pixel: &[u8; 2]) -> f32 {
        u8_to_f32(pixel[0])
    }

    fn pixel_to_la32(pixel: &[u8; 2]) -> [f32; 2] {
        [u8_to_f32(pixel[0]), u8_to_f32(pixel[1])]
    }

    fn pixel_to_rgb8(pixel: &[u8; 2]) -> [u8; 3] {
        [pixel[0]; 3]
    }

    fn pixel_to_rgba8(pixel: &[u8; 2]) -> [u8; 4] {
        [pixel[0]; 4]
    }

    fn pixel_to_rgba32(pixel: &[u8; 2]) -> [f32; 4] {
        let p = u8_to_f32(pixel[0]);
        let a = u8_to_f32(pixel[1]);
        [p, p, p, a]
    }

    #[cfg(feature = "softbuffer")]
    fn pixel_to_zrgb(pixel: &[u8; 2]) -> Zrgb {
        let p = pixel[0];
        Zrgb::new(p, p, p)
    }
}
