Finished explantion comments

This commit is contained in:
Oliver Atkinson 2023-09-05 08:29:48 -06:00
parent 7d905adf10
commit 0f3c3453ac

View File

@ -46,25 +46,27 @@ pub fn print_square(frame: &ffmpeg::frame::Video, lines_format: LinesFormat, vid
let mut stdout = stdout();
let mut lock = stdout.lock();
// Entire frame, as rgb data
let buf = frame.data(video_index);
// How many bytes per line
let step = buf.len() / frame.height() as usize;
// Explanation?: (12x12 image:)
// EXPLANATION: (12x12 image)
// The full buffer will be 1152 bytes.
//
// 1152/12=96 Buffer length / Pixels high = 96 Bytes per line.
// 96/12=8 Bytes per line / Pixels per line = 8 Bytes per pixel.
//
// But RGB24 should only use 3 bytes per pixel.
// The other 5 we just discard.
// But RGB24 should only use 3 bytes per pixel. The other 5 we just discard.
// They might be alpha, or grayscale overlay, I'm not really sure.
//
// 8-5=3 Bytes per pixel - Discarded bytes = Used bytes
// 3*12=36 Used bytes * Pixels per line = Slice length
//
// This is because all the extra data (the 5 extra bytes) are at the end
// of each line. So we just take the first (Pixel width)*3 bytes.
let buf = frame.data(video_index);
let step = buf.len() / frame.height() as usize;
// (Assuming square) Step thru buffer.
for i in 0..pixels_wide {
let j = i*step;
// Only take the size*3 of bytes, ignoring alpha(?) values which are stored after.
// Have to take ownership, by implicilty Cloning the data. (Copying?)
let mut slice = Vec::from(&buf[j..j+pixels_wide*3]);