Struct Picture

Source
pub struct Picture {
    pub picture_type: PictureType,
    pub media_type: String,
    pub description: String,
    pub width: u32,
    pub height: u32,
    pub color_depth: u32,
    pub colors_used: Option<NonZero<u32>>,
    pub data: Vec<u8>,
}
Expand description

A PICTURE metadata block

Picture blocks are for embedding artwork such as album covers, liner notes, etc.

This block may occur multiple times in a FLAC file.

BitsFieldMeaning
32picture_typepicture type
32media type lenmedia type length, in bytes
media type len×8media_typepicture’s MIME type
32description lendescription length, in bytes
description len×8descriptiondescription of picture, in UTF-8
32widthwidth of picture, in pixels
32heightheight of picture, in pixels
32color_depthcolor depth of picture in bits-per-pixel
32colors_usedfor indexed-color pictures, number of colors used
32data lenlength of picture data, in bytes
data len×8dataraw picture data

§Example

use bitstream_io::{BitReader, BitRead, BigEndian};
use flac_codec::metadata::{Picture, PictureType};

let data: &[u8] = &[
    0x00, 0x00, 0x00, 0x03,  // picture type
    0x00, 0x00, 0x00, 0x09,  // media type len (9 bytes)
    0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67,
    0x00, 0x00, 0x00, 0x0a,  // description len (10 bytes)
    0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6d, 0x61, 0x67, 0x65,
    0x00, 0x00, 0x00, 0x10,  // width
    0x00, 0x00, 0x00, 0x09,  // height
    0x00, 0x00, 0x00, 0x18,  // color depth
    0x00, 0x00, 0x00, 0x00,  // color count
    0x00, 0x00, 0x00, 0x5c,  // data len (92 bytes)
    0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
    0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
    0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x09,
    0x08, 0x02, 0x00, 0x00, 0x00, 0xb4, 0x48, 0x3b,
    0x65, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59,
    0x73, 0x00, 0x00, 0x2e, 0x23, 0x00, 0x00, 0x2e,
    0x23, 0x01, 0x78, 0xa5, 0x3f, 0x76, 0x00, 0x00,
    0x00, 0x0e, 0x49, 0x44, 0x41, 0x54, 0x18, 0xd3,
    0x63, 0x60, 0x18, 0x05, 0x43, 0x12, 0x00, 0x00,
    0x01, 0xb9, 0x00, 0x01, 0xed, 0x78, 0x29, 0x25,
    0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
    0xae, 0x42, 0x60, 0x82,
];

let mut r = BitReader::endian(data, BigEndian);
assert_eq!(
    r.parse::<Picture>().unwrap(),
    Picture {
        picture_type: PictureType::FrontCover,  // type 3
        media_type: "image/png".to_owned(),
        description: "Test Image".to_owned(),
        width: 0x00_00_00_10,                   // 16 pixels
        height: 0x00_00_00_09,                  // 9 pixels
        color_depth: 0x00_00_00_18,             // 24 bits-per-pixel
        colors_used: None,                      // not indexed
        data: vec![
            0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
            0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
            0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x09,
            0x08, 0x02, 0x00, 0x00, 0x00, 0xb4, 0x48, 0x3b,
            0x65, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59,
            0x73, 0x00, 0x00, 0x2e, 0x23, 0x00, 0x00, 0x2e,
            0x23, 0x01, 0x78, 0xa5, 0x3f, 0x76, 0x00, 0x00,
            0x00, 0x0e, 0x49, 0x44, 0x41, 0x54, 0x18, 0xd3,
            0x63, 0x60, 0x18, 0x05, 0x43, 0x12, 0x00, 0x00,
            0x01, 0xb9, 0x00, 0x01, 0xed, 0x78, 0x29, 0x25,
            0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
            0xae, 0x42, 0x60, 0x82,
        ],
    },
);

Fields§

§picture_type: PictureType

The picture type

§media_type: String

The media type string as specified by RFC2046

§description: String

The description of the picture

§width: u32

The width of the picture in pixels

§height: u32

The height of the picture in pixels

§color_depth: u32

The color depth of the picture in bits per pixel

§colors_used: Option<NonZero<u32>>

For indexed-color pictures, the number of colors used

§data: Vec<u8>

The binary picture data

Implementations§

Source§

impl Picture

Source

pub fn new<S, V>( picture_type: PictureType, description: S, data: V, ) -> Result<Self, InvalidPicture>
where S: Into<String>, V: Into<Vec<u8>> + AsRef<[u8]>,

Attempt to create a new PICTURE block from raw image data

Currently supported image types for this method are:

  • JPEG
  • PNG
  • GIF

Any type of image data may be placed in a PICTURE block, but the user may have to use external crates to determine their proper image metrics to build a block from.

§Errors

Returns an error if some problem occurs reading or identifying the file.

Source

pub fn open<S, P>( picture_type: PictureType, description: S, path: P, ) -> Result<Self, InvalidPicture>
where S: Into<String>, P: AsRef<Path>,

Attempt to create new PICTURE block from file on disk

Trait Implementations§

Source§

impl AsBlockRef for Picture

Source§

fn as_block_ref(&self) -> BlockRef<'_>

Returns fresh reference to ourself.
Source§

impl Clone for Picture

Source§

fn clone(&self) -> Picture

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Picture

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Picture> for Block

Source§

fn from(b: Picture) -> Self

Converts to this type from the input type.
Source§

impl FromBitStream for Picture

Source§

type Error = Error

Error generated during parsing, such as io::Error
Source§

fn from_reader<R: BitRead + ?Sized>(r: &mut R) -> Result<Self, Error>

Parse Self from reader
Source§

impl MetadataBlock for Picture

Source§

const TYPE: BlockType = BlockType::Picture

The metadata block’s type
Source§

const MULTIPLE: bool = true

Whether the block can occur multiple times in a file
Source§

fn bytes(&self) -> Option<BlockSize>

Size of block, in bytes, not including header
Source§

fn total_size(&self) -> Option<BlockSize>

Size of block, in bytes, including block header
Source§

impl OptionalMetadataBlock for Picture

Source§

const OPTIONAL_TYPE: OptionalBlockType = OptionalBlockType::Picture

Our optional block type
Source§

impl PartialEq for Picture

Source§

fn eq(&self, other: &Picture) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToBitStream for Picture

Source§

type Error = Error

Error generated during building, such as io::Error
Source§

fn to_writer<W: BitWrite + ?Sized>(&self, w: &mut W) -> Result<(), Error>

Generate self to writer
Source§

fn bits<C>(&self) -> Result<C, Self::Error>
where C: Counter, Self: Sized,

Returns length of self in bits, if possible
Source§

fn bits_len<C, E>(&self) -> Result<C, Self::Error>
where C: Counter, E: Endianness, Self: Sized,

👎Deprecated since 4.0.0: use of bits() is preferred
Returns total length of self, if possible
Source§

impl TryFrom<Block> for Picture

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(block: Block) -> Result<Self, ()>

Performs the conversion.
Source§

impl Eq for Picture

Source§

impl StructuralPartialEq for Picture

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.