Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created May 9, 2015 08:54
Show Gist options
  • Select an option

  • Save XMPPwocky/3083b7a13181525898c0 to your computer and use it in GitHub Desktop.

Select an option

Save XMPPwocky/3083b7a13181525898c0 to your computer and use it in GitHub Desktop.
fn cksh(a: u32, sh: u32) -> u32 {
let result = a >> sh;
if result > 0 {
result
} else {
1
}
}
fn mipsize(w: u32, h: u32, d: u32, x: u32) -> u32 {
(cksh(w, x).wrapping_mul(cksh(h, x)))
.wrapping_mul(cksh(d, x))
}
fn moffset(w: u32, h: u32, d: u32) -> u32 {
let mut x = 0u32;
for k in 0..MIP {
x = x.wrapping_add(mipsize(w, h, d, k));
}
x
}
fn main() {
let args = std::env::args().collect::<Vec<_>>();
let w = u32::from_str_radix(&args[1], 16).unwrap();
let h = u32::from_str_radix(&args[2], 16).unwrap();
let d = u32::from_str_radix(&args[3], 16).unwrap();
println!("{:x} {:x}", mipsize(w, h, d, 3), moffset(w, h, d));
let a = std::thread::spawn(|| work(0));
let b = std::thread::spawn(|| work(1));
let c = std::thread::spawn(|| work(2));
let d = std::thread::spawn(|| work(3));
d.join();
c.join();
b.join();
a.join();
}
fn work(n: u32) {
let scale = 1<<(MIP - 1);
for w in (0xFFFF / 4 * n)/scale ..(0xFFFF / 4 * (n + 1))/scale {
let w = w*scale;
for h in w/scale..0xFFFF/scale{
let h = scale*h;
for d in h/scale..0xFFFF/scale {
let d = scale*d;
let u = mipsize(w, h, d, MIP-1);
if u >= 0x388e5970 && u < 0x38900000 {
let v = mipsize(w, h, d, MIP);
if v < 0x8_0000 {
println!("!!!!FOUND {:x} {:x} {:x} {:x} {:x}", u, v, w, h, d);
}
}
}
}
if w % 4096 == 0 {
println!("-- {:x}", w);
}
}
}
const MIP: u32 = 3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment