// Copyright 2026 Gabriel Bjørnager Jensen.
//
// This file is part of LOOKLOOK.
//
// LOOKLOOK is free software: you can redistribute
// it and/or modify it under the terms of the GNU
// Affero General Public License as published by
// the Free Software Foundation, either version 3
// of the License, or (at your option) any later
// version.
//
// LOOKLOOK is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Af-
// fero General Public License along with LOOKLOOK.
// If not, see <https://www.gnu.org/licenses/>.

//! The [`PixelLayout`] enumeration.

use std::fmt::{self, Display, Formatter};

/// A pixel layout.
#[derive(Copy, Debug)]
#[derive_const(Clone, Default, Eq, PartialEq)]
pub enum PixelLayout {
	/// A greyscale (1-channel) layout.
	Grey,

	/// A greyscale-alpha (2-channel) layout.
	GreyAlpha,

	/// A red-green-blue (3-channel) layout.
	#[default]
	Rgb,

	/// A red-green-blue-alpha (4-channel) layout.
	Rgba,
}

impl PixelLayout {
	/// Retrieves the amount of channels per pixel.
	pub const fn channel_count(self) -> usize {
		match self {
			Self::Grey      => 1,
			Self::GreyAlpha => 2,
			Self::Rgb       => 3,
			Self::Rgba      => 4,
		}
	}

	/// Retrieves an identifier for the pixel layout.
	#[inline]
	#[must_use]
	pub const fn as_str(self) -> &'static str {
		match self {
			Self::Grey      => "greyscale",
			Self::GreyAlpha => "greyscale-alpha",
			Self::Rgb       => "rgb",
			Self::Rgba      => "rgba",
		}
	}
}

impl Display for PixelLayout {
	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
		f.write_str(self.as_str())
	}
}
