Created
February 27, 2023 11:18
-
-
Save jakobrs/adfec471fb00a48cc70dd74419f2ce84 to your computer and use it in GitHub Desktop.
This file contains hidden or 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::path::PathBuf; | |
use anyhow::Result; | |
use clap::Parser; | |
use gix::date::Time; | |
use image::{GrayImage, Luma}; | |
#[derive(Parser)] | |
struct Opts { | |
image: PathBuf, | |
#[clap(long)] | |
top_left: u32, | |
#[clap(long, default_value_t = 20)] | |
intensity: u32, | |
#[clap(long)] | |
repo: PathBuf, | |
} | |
const SECONDS_PER_DAY: u32 = 86400; | |
const SECONDS_PER_WEEK: u32 = SECONDS_PER_DAY * 7; | |
fn main() -> Result<()> { | |
let opts = Opts::parse(); | |
let image: GrayImage = image::io::Reader::open(opts.image)?.decode()?.into_luma8(); | |
assert!(image.height() == 7); | |
let repo = gix::open(opts.repo)?; | |
let committer = repo.committer().unwrap()?; | |
let author = repo.author().unwrap()?; | |
let tree = gix::objs::Tree::empty(); | |
let mut prev = repo.head_commit()?.id(); | |
for (x, y, &Luma([value])) in image.enumerate_pixels() { | |
let repetitions = value as u32 * opts.intensity / 255; | |
let mut author = author.clone(); | |
author.time = Time { | |
seconds_since_unix_epoch: opts.top_left + SECONDS_PER_DAY * y + SECONDS_PER_WEEK * x, | |
offset_in_seconds: 0, | |
sign: gix::actor::Sign::Plus, | |
}; | |
for _i in 0..repetitions { | |
let tree_id = repo.write_object(&tree)?; | |
prev = repo.commit_as(committer, author, "HEAD", "yoo", tree_id, [prev])?; | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment