pub struct Palette {
pub colors: [Color; 256],
}Expand description
A color palette. This contains colors indexec by u8. It is used to look up
colors of a voxel.
If you need MagicaVoxel’s default palette, you can either use
crate::default_palette::DEFAULT_PALETTE, or Palette::default.
Fields§
§colors: [Color; 256]The colors of the palette.
MagicaVoxel always set color 0 to be fully transparent. We don’t enfore
this, but this palette entry will never be written to a .VOX file.
Implementations§
Source§impl Palette
impl Palette
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Tests whether this is the crate::default_palette::DEFAULT_PALETTE.
Sourcepub fn get(&self, color_index: ColorIndex) -> Color
pub fn get(&self, color_index: ColorIndex) -> Color
Returns the color for an index. Since all color indices are valid, this
always returns a value. This is equivalent to palette[index].
Sourcepub fn iter(&self) -> PaletteIter<'_> ⓘ
pub fn iter(&self) -> PaletteIter<'_> ⓘ
Creates an iterator over all colors.
for (index, color) in palette.iter() {
println!("{} -> {:?}", index, color);
}Sourcepub fn read<R: Read>(reader: R) -> Result<Self, ReadError>
pub fn read<R: Read>(reader: R) -> Result<Self, ReadError>
Reads a color palette from a std::io::Read.
Sourcepub fn write<W: Write>(&self, writer: W) -> Result<(), WriteError>
pub fn write<W: Write>(&self, writer: W) -> Result<(), WriteError>
Writes the color palette to a std::io::Write.
MagicaVoxel fixes color 0 to be always fully transparent, and doesn’t include it in the file. Therefore this method will ignore the value for color 0.
Source§impl Palette
impl Palette
Sourcepub fn as_image(&self) -> RgbaImage
pub fn as_image(&self) -> RgbaImage
Converts the palette into an RGBA image. The image will have dimensions 256 (width) x 1 (height).
Sourcepub fn from_image(image: &RgbaImage) -> Palette
pub fn from_image(image: &RgbaImage) -> Palette
Converts a RGBA image to a color palette. Regardless of shape of the image, the first 256 pixels (row-first order) will be used. If there aren’t enough pixels, the rest of the palette will be transparent.
§Note
VOX palettes have 256 colors, but VOX files only store the last 255 colors. The first color is always assumed to be fully transparent. Thus any color for the first palette entry will be lost once the palette is written to file.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Palette
impl<'de> Deserialize<'de> for Palette
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Index<ColorIndex> for Palette
impl Index<ColorIndex> for Palette
Auto Trait Implementations§
impl Freeze for Palette
impl RefUnwindSafe for Palette
impl Send for Palette
impl Sync for Palette
impl Unpin for Palette
impl UnsafeUnpin for Palette
impl UnwindSafe for Palette
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more