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.
| Bits | Field | Meaning |
|---|---|---|
| 32 | picture_type | picture type |
| 32 | media type len | media type length, in bytes |
media type len×8 | media_type | picture’s MIME type |
| 32 | description len | description length, in bytes |
description len×8 | description | description of picture, in UTF-8 |
| 32 | width | width of picture, in pixels |
| 32 | height | height of picture, in pixels |
| 32 | color_depth | color depth of picture in bits-per-pixel |
| 32 | colors_used | for indexed-color pictures, number of colors used |
| 32 | data len | length of picture data, in bytes |
data len×8 | data | raw 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: PictureTypeThe picture type
media_type: StringThe media type string as specified by RFC2046
description: StringThe description of the picture
width: u32The width of the picture in pixels
height: u32The height of the picture in pixels
color_depth: u32The 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
impl Picture
Sourcepub fn new<S, V>(
picture_type: PictureType,
description: S,
data: V,
) -> Result<Self, InvalidPicture>
pub fn new<S, V>( picture_type: PictureType, description: S, data: V, ) -> Result<Self, InvalidPicture>
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.
Sourcepub fn open<S, P>(
picture_type: PictureType,
description: S,
path: P,
) -> Result<Self, InvalidPicture>
pub fn open<S, P>( picture_type: PictureType, description: S, path: P, ) -> Result<Self, InvalidPicture>
Attempt to create new PICTURE block from file on disk