// Copyright (c) 2020 Emmanuel Gil Peyrot // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. use std::fs::File; use std::io::{Read, BufWriter}; use std::error::Error; fn main() -> Result<(), Box> { let args: Vec<_> = std::env::args().collect(); if args.len() != 5 { eprintln!("Usage: {} ", args[0]); panic!(); } let filename = &args[1]; let output = &args[2]; let width = args[3].parse()?; let height = args[4].parse()?; let mut file = File::open(filename)?; let mut data = Vec::new(); file.read_to_end(&mut data)?; let layer = krita::PaintLayer::parse(&data).unwrap().1; let file = File::create(output)?; let ref mut w = BufWriter::new(file); let mut encoder = png::Encoder::new(w, width as u32, height as u32); encoder.set_color(png::ColorType::RGBA); encoder.set_depth(png::BitDepth::Eight); let mut writer = encoder.write_header()?; let pixels = layer.assemble_tiles([0, 0, 0, 0], width, height); writer.write_image_data(&pixels)?; // Save Ok(()) }