Просмотр исходного кода

Add work-in-progress png example

Lucas Stadler лет назад: 10
Родитель
Сommit
6e15c8137c
1 измененных файлов с 32 добавлено и 0 удалено
  1. 32 0
      rust/coffi/src/main.rs

+ 32 - 0
rust/coffi/src/main.rs

1
#![feature(libc)]
2
extern crate libc;
3
1
#[link(name = "m")]
4
#[link(name = "m")]
2
extern {
5
extern {
3
    fn cos(d: f64) -> f64;
6
    fn cos(d: f64) -> f64;
4
}
7
}
5
8
9
#[repr(C)]
10
struct png_opaque;
11
12
#[repr(C)]
13
struct png_image {
14
    opaque: *mut png_opaque,
15
    version: libc::uint32_t,
16
    width: libc::uint32_t,
17
    height: libc::uint32_t,
18
    format: libc::uint32_t,
19
    flags: libc::uint32_t,
20
    colormap_entries: libc::uint32_t,
21
    warning_or_error:  libc::uint32_t,
22
    message: [u8; 64],
23
}
24
25
#[link(name = "png")]
26
extern {
27
    fn png_image_begin_read_from_file(img: *mut png_image, file_name: *const u8) -> libc::c_int;
28
}
29
6
fn main() {
30
fn main() {
7
    let x = unsafe { cos(3.1415) };
31
    let x = unsafe { cos(3.1415) };
8
    println!("cos(3.1415) = {}", x);
32
    println!("cos(3.1415) = {}", x);
33
34
    let mut img: png_image;
35
    unsafe {
36
        img = std::mem::uninitialized();
37
        let res = png_image_begin_read_from_file(&mut img, "mei.png".as_ptr());
38
        println!("read_from_file: {}", res);
39
        println!("{}x{}", img.width, img.height);
40
    }
9
}
41
}