extern crate discrete_transforms; use discrete_transforms::dct_2d::*; #[test] fn dct_2d_forward_test() { let input = vec![139.0, 144.0, 149.0, 153.0, 155.0, 155.0, 155.0, 155.0, 144.0, 151.0, 153.0, 156.0, 159.0, 156.0, 156.0, 156.0, 150.0, 155.0, 160.0, 163.0, 158.0, 156.0, 156.0, 156.0, 159.0, 161.0, 162.0, 160.0, 160.0, 159.0, 159.0, 159.0, 159.0, 160.0, 161.0, 162.0, 162.0, 155.0, 155.0, 155.0, 161.0, 161.0, 161.0, 161.0, 160.0, 157.0, 157.0, 157.0, 162.0, 162.0, 161.0, 163.0, 162.0, 157.0, 157.0, 157.0, 162.0, 162.0, 161.0, 161.0, 163.0, 158.0, 158.0, 158.0]; let expected = vec![1259.6249999999998, -1.0333282734264215, -12.08089972227818, -5.202897632351193, 2.1250000000000395, -1.6724303924125188, -2.7079719164466214, 1.3238449641647345, -22.59043604867432, -17.484184984963697, -6.240475613706441, -3.157375133336737, -2.85566531990981, -0.06945585634862816, 0.4341651476704207, -1.1855839794560317, -10.949263949383607, -9.262395706197365, -1.5758252147247727, 1.5300904757770628, 0.20294853755482178, -0.9418636259697495, -0.5669417382415787, -0.0629237344895699, -7.08155510708346, -1.907176033199822, 0.22478966756064506, 1.4538889620374085, 0.8962513174481048, -0.07987423319341946, -0.04229084057506394, 0.33153831902135955, -0.6249999999999432, -0.838108358920093, 1.4698833354859264, 1.556281617916448, -0.12499999999999822, -0.66098605785626, 0.6088456126644615, 1.275209526220424, 1.7540818213960137, -0.20285866258103136, 1.620486613351027, -0.34243736611696535, -0.7755381437234861, 1.4759360604641896, 1.0410044136725525, -0.9929624708267335, -1.2825244507344138, -0.3599527941914801, -0.31694173824158023, -1.4600985413244758, -0.4899611118286471, 1.734842538986418, 1.0758252147247698, -0.7613475106449024, -2.5998987210929343, 1.551852887620423, -3.762776290221531, -1.8447577060244742, 1.8716168796703228, 1.213945210222894, -0.567884993512257, -0.44564003753785386]; let mut dct_2d = Dct2D::new(); dct_2d.set_input(input); let forward = dct_2d.forward(); assert_eq!(forward, expected); } #[test] fn dct_2d_inverse_test() { let input = vec![1259.6249999999998, -1.0333282734264215, -12.08089972227818, -5.202897632351193, 2.1250000000000395, -1.6724303924125188, -2.7079719164466214, 1.3238449641647345, -22.59043604867432, -17.484184984963697, -6.240475613706441, -3.157375133336737, -2.85566531990981, -0.06945585634862816, 0.4341651476704207, -1.1855839794560317, -10.949263949383607, -9.262395706197365, -1.5758252147247727, 1.5300904757770628, 0.20294853755482178, -0.9418636259697495, -0.5669417382415787, -0.0629237344895699, -7.08155510708346, -1.907176033199822, 0.22478966756064506, 1.4538889620374085, 0.8962513174481048, -0.07987423319341946, -0.04229084057506394, 0.33153831902135955, -0.6249999999999432, -0.838108358920093, 1.4698833354859264, 1.556281617916448, -0.12499999999999822, -0.66098605785626, 0.6088456126644615, 1.275209526220424, 1.7540818213960137, -0.20285866258103136, 1.620486613351027, -0.34243736611696535, -0.7755381437234861, 1.4759360604641896, 1.0410044136725525, -0.9929624708267335, -1.2825244507344138, -0.3599527941914801, -0.31694173824158023, -1.4600985413244758, -0.4899611118286471, 1.734842538986418, 1.0758252147247698, -0.7613475106449024, -2.5998987210929343, 1.551852887620423, -3.762776290221531, -1.8447577060244742, 1.8716168796703228, 1.213945210222894, -0.567884993512257, -0.44564003753785386]; let expected = vec![139.0, 144.0, 149.0, 153.0, 155.0, 155.0, 155.0, 155.0, 144.0, 151.0, 153.0, 156.0, 159.0, 156.0, 156.0, 156.0, 150.0, 155.0, 160.0, 163.0, 158.0, 156.0, 156.0, 156.0, 159.0, 161.0, 162.0, 160.0, 160.0, 159.0, 159.0, 159.0, 159.0, 160.0, 161.0, 162.0, 162.0, 155.0, 155.0, 155.0, 161.0, 161.0, 161.0, 161.0, 160.0, 157.0, 157.0, 157.0, 162.0, 162.0, 161.0, 163.0, 162.0, 157.0, 157.0, 157.0, 162.0, 162.0, 161.0, 161.0, 163.0, 158.0, 158.0, 158.0]; let mut dct_2d = Dct2D::new(); dct_2d.set_input(input); let mut inverse = dct_2d.inverse(); for x in 0..8 { for y in 0..8 { inverse[x * 8 + y] = inverse[x * 8 + y].round(); } } assert_eq!(inverse, expected) }