formatting
parent
892efbdb13
commit
ec106d3224
|
@ -61,12 +61,8 @@ macro_rules! _durandal_read_impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
// no endianness
|
// no endianness
|
||||||
($_:ident $b:ident $nam:ident u8 $n:expr) => {
|
($_:ident $b:ident $nam:ident u8 $n:expr) => {let $nam = $b[$n];};
|
||||||
let $nam = $b[$n];
|
($_:ident $b:ident $nam:ident slice u8 $n:expr) => {let $nam = &$b[$n];};
|
||||||
};
|
|
||||||
($_:ident $b:ident $nam:ident slice u8 $n:expr) => {
|
|
||||||
let $nam = &$b[$n];
|
|
||||||
};
|
|
||||||
($_:ident $b:ident $nam:ident i8 $n:expr) => {
|
($_:ident $b:ident $nam:ident i8 $n:expr) => {
|
||||||
let $nam = i8::from_ne_bytes([$b[$n]]);
|
let $nam = i8::from_ne_bytes([$b[$n]]);
|
||||||
};
|
};
|
||||||
|
@ -122,8 +118,8 @@ macro_rules! _durandal_read_impl {
|
||||||
/// - `opts` may be one of:
|
/// - `opts` may be one of:
|
||||||
/// - `slice` when `type` is `u8`: `place` is a range specifying a `u8` slice
|
/// - `slice` when `type` is `u8`: `place` is a range specifying a `u8` slice
|
||||||
/// to be taken from `source`.
|
/// to be taken from `source`.
|
||||||
/// - `usize` when `type` is `u16` or `u32`: converts the resulting integer
|
/// - `usize` when `type` is `u16` or `u32`: converts the resulting integer to
|
||||||
/// to `usize` by `usize_to_u32` for `u32` or by `from` for `u16`.
|
/// `usize` by `usize_to_u32` for `u32` or by `from` for `u16`.
|
||||||
/// - `no_try` when `type` is a function name: does not use the `?` operator
|
/// - `no_try` when `type` is a function name: does not use the `?` operator
|
||||||
/// on the resulting function call.
|
/// on the resulting function call.
|
||||||
/// - Nothing at all.
|
/// - Nothing at all.
|
||||||
|
|
|
@ -22,7 +22,8 @@ fn crc_init() -> [u32; 256]
|
||||||
pub fn crc32(b: &[u8], s: u32) -> u32
|
pub fn crc32(b: &[u8], s: u32) -> u32
|
||||||
{
|
{
|
||||||
let t = crc_init();
|
let t = crc_init();
|
||||||
!b.iter().fold(s, |a, &o| a >> 8 ^ t[usize::from(a as u8 ^ o)])
|
!b.iter()
|
||||||
|
.fold(s, |a, &o| a >> 8 ^ t[usize::from(a as u8 ^ o)])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -52,7 +52,10 @@ impl fmt::Debug for ReprError
|
||||||
|
|
||||||
impl fmt::Display for ErrMsg
|
impl fmt::Display for ErrMsg
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {f.write_str(self.0)}
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
|
{
|
||||||
|
f.write_str(self.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ErrMsg
|
impl fmt::Debug for ErrMsg
|
||||||
|
|
|
@ -26,7 +26,9 @@ pub fn r5g5b5_to_rgb16(rgb: u16) -> Color16
|
||||||
/// Creates a RGB16 color from a RGB8 format color.
|
/// Creates a RGB16 color from a RGB8 format color.
|
||||||
pub fn rgb8_to_rgb16(r: u8, g: u8, b: u8) -> Color16
|
pub fn rgb8_to_rgb16(r: u8, g: u8, b: u8) -> Color16
|
||||||
{
|
{
|
||||||
Color16::new(u16::from(r) << 8, u16::from(g) << 8, u16::from(b) << 8)
|
Color16::new(u16::from(r) << 8,
|
||||||
|
u16::from(g) << 8,
|
||||||
|
u16::from(b) << 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes a PPM file from an image.
|
/// Writes a PPM file from an image.
|
||||||
|
@ -49,13 +51,20 @@ pub fn write_ppm(out: &mut impl io::Write, im: &impl Image) -> ResultS<()>
|
||||||
/// Writes a TGA file from an image.
|
/// Writes a TGA file from an image.
|
||||||
pub fn write_tga(out: &mut impl io::Write, im: &impl Image) -> ResultS<()>
|
pub fn write_tga(out: &mut impl io::Write, im: &impl Image) -> ResultS<()>
|
||||||
{
|
{
|
||||||
out.write_all(&[0, 0, 2])?; // id len, color map type, image type
|
// id len, color map type, image type
|
||||||
out.write_all(&[0, 0, 0, 0, 0])?; // color map spec
|
out.write_all(&[0, 0, 2])?;
|
||||||
out.write_all(&[0, 0])?; // x origin
|
// color map spec
|
||||||
out.write_all(&[0, 0])?; // y origin
|
out.write_all(&[0, 0, 0, 0, 0])?;
|
||||||
out.write_all(&(im.w() as u16).to_le_bytes())?; // width
|
// x origin
|
||||||
out.write_all(&(im.h() as u16).to_le_bytes())?; // height
|
out.write_all(&[0, 0])?;
|
||||||
out.write_all(&[32, 0])?; // depth, descriptor
|
// y origin
|
||||||
|
out.write_all(&[0, 0])?;
|
||||||
|
// width
|
||||||
|
out.write_all(&u16::to_le_bytes(im.w() as u16))?;
|
||||||
|
// height
|
||||||
|
out.write_all(&u16::to_le_bytes(im.h() as u16))?;
|
||||||
|
// depth, descriptor
|
||||||
|
out.write_all(&[32, 0])?;
|
||||||
|
|
||||||
for y in (0..im.h()).rev() {
|
for y in (0..im.h()).rev() {
|
||||||
for x in 0..im.w() {
|
for x in 0..im.w() {
|
||||||
|
|
|
@ -6,22 +6,27 @@ use std::io;
|
||||||
/// Writes a WAVE file from a sound.
|
/// Writes a WAVE file from a sound.
|
||||||
pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()>
|
pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()>
|
||||||
{
|
{
|
||||||
let rate = u32::from(snd.rate());
|
let smp_rate = u32::from(snd.rate());
|
||||||
let bps = rate * 2;
|
let smp_size = smp_rate * 2;
|
||||||
let dat_size = snd.len() as u32 * 2;
|
let dat_size = snd.len() as u32 * 2;
|
||||||
let hdr_size = 36 + dat_size;
|
|
||||||
|
|
||||||
out.write_all(b"RIFF")?;
|
out.write_all(b"RIFF")?;
|
||||||
out.write_all(&u32::to_le_bytes(hdr_size))?;
|
out.write_all(&u32::to_le_bytes(36 + dat_size))?;
|
||||||
out.write_all(b"WAVE")?;
|
out.write_all(b"WAVE")?;
|
||||||
|
|
||||||
out.write_all(b"fmt ")?;
|
out.write_all(b"fmt ")?;
|
||||||
out.write_all(&u32::to_le_bytes(16))?;
|
out.write_all(&u32::to_le_bytes(16))?;
|
||||||
out.write_all(&u16::to_le_bytes(1))?; // PCM
|
// PCM
|
||||||
out.write_all(&u16::to_le_bytes(1))?; // mono
|
out.write_all(&u16::to_le_bytes(1))?;
|
||||||
out.write_all(&u32::to_le_bytes(rate))?;
|
// mono
|
||||||
out.write_all(&u32::to_le_bytes(bps))?;
|
out.write_all(&u16::to_le_bytes(1))?;
|
||||||
out.write_all(&u16::to_le_bytes(2))?; // block alignment
|
out.write_all(&u32::to_le_bytes(smp_rate))?;
|
||||||
out.write_all(&u16::to_le_bytes(16))?; // bits per sample
|
out.write_all(&u32::to_le_bytes(smp_size))?;
|
||||||
|
// block alignment
|
||||||
|
out.write_all(&u16::to_le_bytes(2))?;
|
||||||
|
// bits per sample
|
||||||
|
out.write_all(&u16::to_le_bytes(16))?;
|
||||||
|
|
||||||
out.write_all(b"data")?;
|
out.write_all(b"data")?;
|
||||||
out.write_all(&u32::to_le_bytes(dat_size))?;
|
out.write_all(&u32::to_le_bytes(dat_size))?;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::{fs, io};
|
||||||
fn make_tga(_opt: &Options, fname: &str, im: &impl Image) -> ResultS<()>
|
fn make_tga(_opt: &Options, fname: &str, im: &impl Image) -> ResultS<()>
|
||||||
{
|
{
|
||||||
let mut out = io::BufWriter::new(fs::File::create(fname)?);
|
let mut out = io::BufWriter::new(fs::File::create(fname)?);
|
||||||
|
|
||||||
write_tga(&mut out, im)
|
write_tga(&mut out, im)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ fn make_yaml<T>(opt: &Options, data: &T) -> ResultS<()>
|
||||||
serde_yaml::to_writer(io::stdout(), &data)?;
|
serde_yaml::to_writer(io::stdout(), &data)?;
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,15 +66,10 @@ fn dump_bitmaps(opt: &Options, c: &shp::Collection, i: usize) -> ResultS<()>
|
||||||
|
|
||||||
fn write_shp_objs(opt: &Options, cl: &shp::Collection) -> ResultS<()>
|
fn write_shp_objs(opt: &Options, cl: &shp::Collection) -> ResultS<()>
|
||||||
{
|
{
|
||||||
if opt.shp_tab {
|
if opt.shp_tab {make_yaml(opt, &cl.tabs)?;}
|
||||||
make_yaml(opt, &cl.tabs)?;
|
if opt.shp_frm {make_yaml(opt, &cl.frms)?;}
|
||||||
}
|
if opt.shp_seq {make_yaml(opt, &cl.seqs)?;}
|
||||||
if opt.shp_frm {
|
|
||||||
make_yaml(opt, &cl.frms)?;
|
|
||||||
}
|
|
||||||
if opt.shp_seq {
|
|
||||||
make_yaml(opt, &cl.seqs)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +80,7 @@ fn process_shp(opt: &Options, b: &[u8]) -> ResultS<()>
|
||||||
dump_bitmaps(opt, cl, i)?;
|
dump_bitmaps(opt, cl, i)?;
|
||||||
write_shp_objs(opt, cl)?;
|
write_shp_objs(opt, cl)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cl) = &cl.1 {
|
if let Some(cl) = &cl.1 {
|
||||||
dump_bitmaps(opt, cl, i + 100)?;
|
dump_bitmaps(opt, cl, i + 100)?;
|
||||||
write_shp_objs(opt, cl)?;
|
write_shp_objs(opt, cl)?;
|
||||||
|
|
|
@ -36,6 +36,7 @@ pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
||||||
pub fn check_macbin(b: &[u8]) -> Option<usize>
|
pub fn check_macbin(b: &[u8]) -> Option<usize>
|
||||||
{
|
{
|
||||||
// check legacy version, length, zero fill, and macbin2 version
|
// check legacy version, length, zero fill, and macbin2 version
|
||||||
|
// I swear this isn't *completely* magic
|
||||||
if b.len() < 128 || b[0] != 0 || b[1] > 63 || b[74] != 0 || b[123] > 129 {
|
if b.len() < 128 || b[0] != 0 || b[1] > 63 || b[74] != 0 || b[123] > 129 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ pub fn check_macbin(b: &[u8]) -> Option<usize>
|
||||||
for &byte in b.iter().take(124) {
|
for &byte in b.iter().take(124) {
|
||||||
for j in 8..16 {
|
for j in 8..16 {
|
||||||
let d = u16::from(byte) << j;
|
let d = u16::from(byte) << j;
|
||||||
|
|
||||||
if (d ^ crc) & 0x8000 == 0 {
|
if (d ^ crc) & 0x8000 == 0 {
|
||||||
crc <<= 1;
|
crc <<= 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,11 +57,7 @@ pub fn check_macbin(b: &[u8]) -> Option<usize>
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ok, resource fork follows
|
// if ok, resource fork follows
|
||||||
if crc == u16b(&b[124..]) {
|
if crc == u16b(&b[124..]) {Some(128)} else {None}
|
||||||
Some(128)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a `MacBin` or `AppleSingle` header if there is one and returns the
|
/// Reads a `MacBin` or `AppleSingle` header if there is one and returns the
|
||||||
|
|
|
@ -67,7 +67,9 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
for _ in 0..im.h() {
|
for _ in 0..im.h() {
|
||||||
for _ in 0..im.w() {
|
for _ in 0..im.w() {
|
||||||
let idx = usize::from(b[p]);
|
let idx = usize::from(b[p]);
|
||||||
|
|
||||||
im.cr.push(ok!(clut.get(idx), "invalid index")?.clone());
|
im.cr.push(ok!(clut.get(idx), "invalid index")?.clone());
|
||||||
|
|
||||||
p += 1;
|
p += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,11 +79,8 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
// RLE compressed 1, 2, 4 or 8 bit colormap indices
|
// RLE compressed 1, 2, 4 or 8 bit colormap indices
|
||||||
for _ in 0..im.h() {
|
for _ in 0..im.h() {
|
||||||
let (d, pp) = read_rle::<u8>(&b[p..], hdr.pitch)?;
|
let (d, pp) = read_rle::<u8>(&b[p..], hdr.pitch)?;
|
||||||
let d = if hdr.depth < 8 {
|
|
||||||
expand_data(d, hdr.depth)?
|
let d = if hdr.depth < 8 {expand_data(d, hdr.depth)?} else {d};
|
||||||
} else {
|
|
||||||
d
|
|
||||||
};
|
|
||||||
|
|
||||||
p += pp;
|
p += pp;
|
||||||
|
|
||||||
|
@ -107,6 +106,7 @@ fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
||||||
for _ in 0..im.h() {
|
for _ in 0..im.h() {
|
||||||
for _ in 0..im.w() {
|
for _ in 0..im.w() {
|
||||||
let cr = u16b(&b[p..]);
|
let cr = u16b(&b[p..]);
|
||||||
|
|
||||||
im.cr.push(r5g5b5_to_rgb8(cr));
|
im.cr.push(r5g5b5_to_rgb8(cr));
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,9 +149,11 @@ impl fmt::Debug for Group
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "Group{{{:?} {} {}", self.ttype, self.pdata, self.lines)?;
|
write!(f, "Group{{{:?} {} {}", self.ttype, self.pdata, self.lines)?;
|
||||||
|
|
||||||
if !self.text.is_empty() {
|
if !self.text.is_empty() {
|
||||||
write!(f, ";\n{}", self.text)?;
|
write!(f, ";\n{}", self.text)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "}}")
|
write!(f, "}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Marathon Wad format handling.
|
//! Marathon Wad format handling.
|
||||||
|
|
||||||
use crate::durandal::{bin::*, err::*, image, text::mac_roman_conv};
|
use crate::{durandal::{bin::*, err::*, image, text::mac_roman_conv},
|
||||||
use crate::marathon::{map, phy, pict, trm};
|
marathon::{map, phy, pict, trm}};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
/// Reads all chunks in an entry.
|
/// Reads all chunks in an entry.
|
||||||
|
|
|
@ -25,6 +25,12 @@ pub type Coord = i32;
|
||||||
pub type Point = (Coord, Coord);
|
pub type Point = (Coord, Coord);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Rect {pub x: Coord, pub y: Coord, pub w: Coord, pub h: Coord}
|
pub struct Rect
|
||||||
|
{
|
||||||
|
pub x: Coord,
|
||||||
|
pub y: Coord,
|
||||||
|
pub w: Coord,
|
||||||
|
pub h: Coord,
|
||||||
|
}
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -4,8 +4,7 @@ fn main()
|
||||||
{
|
{
|
||||||
println!("cargo:rerun-if-changed=data");
|
println!("cargo:rerun-if-changed=data");
|
||||||
|
|
||||||
Command::new("glib-compile-resources")
|
Command::new("glib-compile-resources").arg("data/tycho_res.xml")
|
||||||
.arg("data/tycho_res.xml")
|
|
||||||
.arg("--target=data/tycho.res")
|
.arg("--target=data/tycho.res")
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use maraiah::durandal::image::*;
|
use maraiah::{durandal::image::*,
|
||||||
use maraiah::marathon::*;
|
marathon::*,
|
||||||
use maraiah::rozinante::{color::*, draw::*};
|
rozinante::{color::*, draw::*}};
|
||||||
|
|
||||||
pub fn draw_map_none<D, I>(d: &D, im: &I)
|
pub fn draw_map_none<D, I>(d: &D, im: &I)
|
||||||
where D: DrawArea<NativeImage = I>,
|
where D: DrawArea<NativeImage = I>,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
mod hiddenprotocol;
|
mod hiddenprotocol;
|
||||||
mod noroom;
|
mod noroom;
|
||||||
|
|
||||||
use crate::hiddenprotocol::*;
|
use crate::{hiddenprotocol::*, noroom::*};
|
||||||
use crate::noroom::*;
|
|
||||||
use gio::prelude::*;
|
use gio::prelude::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use maraiah::durandal::err::*;
|
use maraiah::durandal::err::*;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use maraiah::rozinante::draw::*;
|
use maraiah::{durandal::image::*, rozinante::draw::*};
|
||||||
use maraiah::durandal::image::*;
|
|
||||||
|
|
||||||
fn flt_color(cr: impl Color) -> (f64, f64, f64)
|
fn flt_color(cr: impl Color) -> (f64, f64, f64)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +34,8 @@ impl DrawArea for CairoDrawArea
|
||||||
|
|
||||||
self.rect(Rect{x: 0, y: 0, w: self.w(), h: self.h()}, cr);
|
self.rect(Rect{x: 0, y: 0, w: self.w(), h: self.h()}, cr);
|
||||||
|
|
||||||
self.ctx.select_font_face("Sans", FontSlant::Normal, FontWeight::Normal);
|
self.ctx
|
||||||
|
.select_font_face("Sans", FontSlant::Normal, FontWeight::Normal);
|
||||||
self.ctx.set_font_size(14.0);
|
self.ctx.set_font_size(14.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,8 @@ impl DrawArea for CairoDrawArea
|
||||||
fn image(&self, pos: Point, im: &Self::NativeImage)
|
fn image(&self, pos: Point, im: &Self::NativeImage)
|
||||||
{
|
{
|
||||||
use gdk::prelude::*;
|
use gdk::prelude::*;
|
||||||
self.ctx.set_source_pixbuf(&im.0, f64::from(pos.0), f64::from(pos.1));
|
self.ctx
|
||||||
|
.set_source_pixbuf(&im.0, f64::from(pos.0), f64::from(pos.1));
|
||||||
self.ctx.paint();
|
self.ctx.paint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue