Created
April 20, 2018 20:59
-
-
Save ablwr/651cdc91682b3525d7529ad731159450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::Write; | |
use std::io::Read; | |
const luma_width: usize=128; | |
const luma_height: usize=96; | |
const chroma_width: usize=luma_width / 2; | |
const chroma_height: usize=luma_height / 2; | |
// H.264 bitstreams | |
static sps: [u8; 11] = [ 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x0a, 0xf8, 0x41, 0xa2 ]; | |
static pps: [u8; 8] = [ 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x38, 0x80 ]; | |
static slice_header: [u8; 9] = [ 0x00, 0x00, 0x00, 0x01, 0x05, 0x88, 0x84, 0x21, 0xa0 ]; | |
static macroblock_header: [u8; 2] = [ 0x0d, 0x00 ]; | |
pub struct Frame { | |
y: [[u8; 96]; 128], | |
cb: [[u8; 96 / 2]; 128 / 2], | |
cr: [[u8; 96 / 2]; 128 / 2], | |
} | |
// Write a macroblock's worth of YUV data in I_PCM mode | |
pub fn macroblock(i: usize, j: usize, mut f: &File, frame: &Frame) { | |
if i != 0 && j != 0 { | |
f.write_all(¯oblock_header); | |
} | |
// luma / y | |
for x in (i * 16)..((i + 1) * 16) { | |
for y in (j * 16)..((j + 1) * 16) { | |
// println!("it's important"); | |
// f.write_all(); | |
// fwrite(&frame.Y[x][y], 1, 1, stdout); | |
} | |
} | |
// cb / chroma blue | |
for x in (i * 8)..((i + 1) * 8) { | |
for y in (j * 8)..((j + 1) * 8) { | |
// println!("it's important"); | |
// fwrite(&frame.Y[x][y], 1, 1, stdout); | |
} | |
} | |
// cr / chroma red | |
for x in (i * 8)..((i + 1) * 8) { | |
for y in (j * 8)..((j + 1) * 8) { | |
// println!("it's important"); | |
// fwrite(&frame.Y[x][y], 1, 1, stdout); | |
} | |
} | |
} | |
/* Write out PPS, SPS, and loop over input, writing out I slices */ | |
pub fn main() { | |
let mut buffer = [0; 96*128]; | |
let mut readf = File::open("mandelbrot.yuv").expect("unable to open file"); | |
readf.read(&mut buffer); | |
let mut f = File::create("foo").expect("unable to create file"); | |
for i in 0..(luma_height/16) { | |
for j in 0..(luma_width/16) { | |
macroblock(i, j, &f, buffer); | |
} | |
} | |
f.write_all(&sps); | |
f.write_all(&pps); | |
println!("{}", buffer.to_string()); | |
// while (! feof(stdin)) | |
// { | |
// fread(&frame, 1, sizeof(frame), stdin); | |
// fwrite(slice_header, 1, sizeof(slice_header), stdout); | |
// for (i = 0; i < luma_height/16 ; i++) | |
// for (j = 0; j < luma_width/16; j++) | |
// macroblock(i, j); | |
// fputc(0x80, stdout); /* slice stop bit */ | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment