70 lines
1.8 KiB
Plaintext
70 lines
1.8 KiB
Plaintext
#![allow(unreachable_code)]
|
|
|
|
use gif::{DecodeOptions, Frame};
|
|
use std::fs::OpenOptions;
|
|
use x11rb::connection::Connection;
|
|
use x11rb::protocol::xproto::ConnectionExt;
|
|
use x11rb::protocol::xproto::CreateGCAux;
|
|
|
|
fn main() {
|
|
let (conn, screen_num) = x11rb::connect(None).unwrap();
|
|
let screen = &conn.setup().roots[screen_num];
|
|
let root = screen.root;
|
|
let depth = screen.root_depth;
|
|
|
|
let pixmap = conn.generate_id().unwrap();
|
|
conn.create_pixmap(depth, pixmap, root, 400, 400).unwrap();
|
|
|
|
let gc = conn.generate_id().unwrap();
|
|
let gc_aux = CreateGCAux::new().foreground(screen.white_pixel);
|
|
conn.create_gc(gc, root, &gc_aux).unwrap();
|
|
|
|
let arg = std::env::args().next().unwrap();
|
|
let input = OpenOptions::new()
|
|
.read(true)
|
|
.open("/home/gallant/Downloads/test3.gif")
|
|
.unwrap();
|
|
|
|
input.sync_all().unwrap();
|
|
|
|
let mut de_options = DecodeOptions::new();
|
|
de_options.set_color_output(gif::ColorOutput::RGBA);
|
|
let mut decoder = de_options.read_info(input).unwrap();
|
|
let mut v_frames: Vec<Frame> = Vec::new();
|
|
while let Some(frame) = decoder.read_next_frame().unwrap() {
|
|
v_frames.push(frame.clone());
|
|
}
|
|
let size = v_frames.len();
|
|
|
|
conn.flush().unwrap();
|
|
|
|
loop {
|
|
let mut index = 0;
|
|
if index == size {
|
|
index = 0;
|
|
}
|
|
let buffer = &v_frames.get(index).unwrap().buffer;
|
|
conn.put_image(
|
|
x11rb::protocol::xproto::ImageFormat::Z_PIXMAP,
|
|
root,
|
|
gc,
|
|
400,
|
|
400,
|
|
200,
|
|
200,
|
|
20,
|
|
0,
|
|
&buffer,
|
|
)
|
|
.unwrap();
|
|
conn.copy_area(pixmap, root, gc, 0, 0, 0, 0, 400, 400)
|
|
.unwrap();
|
|
conn.flush().unwrap();
|
|
index += 1;
|
|
}
|
|
|
|
// unreachable but whatever
|
|
conn.free_pixmap(pixmap).unwrap();
|
|
conn.free_gc(gc).unwrap();
|
|
}
|