formatting

png-branch
an 2019-03-04 05:18:57 -05:00
parent 892efbdb13
commit ec106d3224
19 changed files with 150 additions and 133 deletions

View File

@ -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]]);
}; };
@ -108,24 +104,24 @@ macro_rules! _durandal_read_impl {
/// - `u16` or `i16`: two bytes will be read at `place` with `from_*_bytes`. /// - `u16` or `i16`: two bytes will be read at `place` with `from_*_bytes`.
/// - `u32` or `i32`: four bytes will be read at `place` with `from_*_bytes`. /// - `u32` or `i32`: four bytes will be read at `place` with `from_*_bytes`.
/// - `Ident`: four bytes will be read at `place` into an array, disregarding /// - `Ident`: four bytes will be read at `place` into an array, disregarding
/// endianness, creating an `Ident` object. /// endianness, creating an `Ident` object.
/// - `Angle`: same as `u16`, but the result is passed to /// - `Angle`: same as `u16`, but the result is passed to
/// `fixed::Angle::from_bits`, resulting in a `fixed::Angle` object. /// `fixed::Angle::from_bits`, resulting in a `fixed::Angle` object.
/// - `Fixed`: same as `u32`, but the result is passed to /// - `Fixed`: same as `u32`, but the result is passed to
/// `fixed::Fixed::from_bits`, resulting in a `fixed::Fixed` object. /// `fixed::Fixed::from_bits`, resulting in a `fixed::Fixed` object.
/// - `Unit`: same as `u16`, but the result is passed to /// - `Unit`: same as `u16`, but the result is passed to
/// `fixed::Unit::from_bits`, resulting in a `fixed::Unit` object. /// `fixed::Unit::from_bits`, resulting in a `fixed::Unit` object.
/// - `OptU16`: same as `u16`, but the result is passed to /// - `OptU16`: same as `u16`, but the result is passed to
/// `OptU16::from_repr`, resulting in an `OptU16` object. /// `OptU16::from_repr`, resulting in an `OptU16` object.
/// - The name of a function, which is passed `&source[place]` as its only /// - The name of a function, which is passed `&source[place]` as its only
/// argument. The function's result has the `?` operator applied to it. /// argument. The function's result has the `?` operator applied to it.
/// - `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.
/// - `place` is either an integer literal which must be representable as /// - `place` is either an integer literal which must be representable as
/// `usize`, or a range, which may only be used when `type` is a function /// `usize`, or a range, which may only be used when `type` is a function
@ -245,7 +241,7 @@ impl OptU16
pub fn get_repr(&self) -> u16 pub fn get_repr(&self) -> u16
{ {
match self.0 { match self.0 {
None => u16::max_value(), None => u16::max_value(),
Some(n) => n.get() - 1, Some(n) => n.get() - 1,
} }
} }
@ -254,7 +250,7 @@ impl OptU16
pub fn get(&self) -> Option<u16> pub fn get(&self) -> Option<u16>
{ {
match self.0 { match self.0 {
None => None, None => None,
Some(n) => Some(n.get() - 1), Some(n) => Some(n.get() - 1),
} }
} }

View File

@ -32,7 +32,7 @@ macro_rules! c_enum
{ {
match n { match n {
$($value => Ok($E::$Enum),)+ $($value => Ok($E::$Enum),)+
n => Err(ReprError(n.into())) n => Err(ReprError(n.into()))
} }
} }
} }

View File

@ -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]

View File

@ -8,7 +8,7 @@ macro_rules! ok {
($v:expr, $msg:expr) => { ($v:expr, $msg:expr) => {
match $v { match $v {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(err_msg($msg)), None => Err(err_msg($msg)),
} }
}; };
} }
@ -17,7 +17,7 @@ macro_rules! flag_ok {
($t:ident, $v:expr) => { ($t:ident, $v:expr) => {
match $t::from_bits($v) { match $t::from_bits($v) {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(err_msg(concat!("bad ", stringify!($t)))), None => Err(err_msg(concat!("bad ", stringify!($t)))),
} }
}; };
} }
@ -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

View File

@ -190,9 +190,9 @@ fn fixed_basic_ops()
assert_eq!((Fixed::from(1) + 1.into()).to_bits(), 2 << Fixed::FRACBITS); assert_eq!((Fixed::from(1) + 1.into()).to_bits(), 2 << Fixed::FRACBITS);
assert_eq!((Fixed::from(2) - 1.into()).to_bits(), 1 << Fixed::FRACBITS); assert_eq!((Fixed::from(2) - 1.into()).to_bits(), 1 << Fixed::FRACBITS);
assert_eq!((Fixed::from(6) * 2.into()).to_bits(), 12 << Fixed::FRACBITS); assert_eq!((Fixed::from(6) * 2.into()).to_bits(), 12 << Fixed::FRACBITS);
assert_eq!((Fixed::from(6).mul_i(2)).to_bits(), 12 << Fixed::FRACBITS); assert_eq!((Fixed::from(6).mul_i(2)) .to_bits(), 12 << Fixed::FRACBITS);
assert_eq!((Fixed::from(7) / 2.into()).to_bits(), seven_div_2); assert_eq!((Fixed::from(7) / 2.into()).to_bits(), seven_div_2);
assert_eq!((Fixed::from(7).div_i(2)).to_bits(), seven_div_2); assert_eq!((Fixed::from(7).div_i(2)) .to_bits(), seven_div_2);
} }
#[test] #[test]
@ -203,7 +203,7 @@ fn fixed_overflow() {Fixed::from(i16::max_value()) + 1.into();}
#[test] #[test]
fn fixed_printing() fn fixed_printing()
{ {
assert_eq!(format!("{}", Fixed::from(6)), "6.0"); assert_eq!(format!("{}", Fixed::from(6)), "6.0");
assert_eq!(format!("{}", Fixed::from(7).div_i(2)), "3.5"); assert_eq!(format!("{}", Fixed::from(7).div_i(2)), "3.5");
assert_eq!(format!("{:7.7}", Fixed::from_bits(0xDEAD_BEEF)), assert_eq!(format!("{:7.7}", Fixed::from_bits(0xDEAD_BEEF)),
" -8531.7458343"); " -8531.7458343");

View File

@ -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() {

View File

@ -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))?;

View File

@ -81,11 +81,11 @@ pub fn mac_roman_conv(s: &[u8]) -> String
for &c in s.iter() { for &c in s.iter() {
v.push(match c { v.push(match c {
0 => break, 0 => break,
b'\r' => '\n', b'\r' => '\n',
c if c & 0x80 != 0 => TR[usize::from(c) & 0x7F], c if c & 0x80 != 0 => TR[usize::from(c) & 0x7F],
c => char::from(c), c => char::from(c),
}); });
} }
v v
@ -118,17 +118,17 @@ const TR: [char; 128] =
#[test] #[test]
fn to_binsize_integrals() fn to_binsize_integrals()
{ {
assert_eq!(to_binsize(0), "empty"); assert_eq!(to_binsize(0), "empty");
assert_eq!(to_binsize(1), "1 byte"); assert_eq!(to_binsize(1), "1 byte");
assert_eq!(to_binsize(2), "2 bytes"); assert_eq!(to_binsize(2), "2 bytes");
assert_eq!(to_binsize(999), "999 bytes"); assert_eq!(to_binsize(999), "999 bytes");
assert_eq!(to_binsize(1000), "1kB"); assert_eq!(to_binsize(1000), "1kB");
assert_eq!(to_binsize(1000 * 7), "7kB"); assert_eq!(to_binsize(1000 * 7), "7kB");
assert_eq!(to_binsize(1000 * 1000), "1MB"); assert_eq!(to_binsize(1000 * 1000), "1MB");
assert_eq!(to_binsize(1000 * 1000 * 7), "7MB"); assert_eq!(to_binsize(1000 * 1000 * 7), "7MB");
assert_eq!(to_binsize(1000 * 1000 * 1000), "1GB"); assert_eq!(to_binsize(1000 * 1000 * 1000), "1GB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 7), "7GB"); assert_eq!(to_binsize(1000 * 1000 * 1000 * 7), "7GB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000), "1TB"); assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000), "1TB");
assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000 * 7), "7TB"); assert_eq!(to_binsize(1000 * 1000 * 1000 * 1000 * 7), "7TB");
} }

View File

@ -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)?;
@ -243,7 +241,7 @@ fn main() -> ResultS<()>
"wad:" => process_wad(&opt, b), "wad:" => process_wad(&opt, b),
"shp:" => process_shp(&opt, b), "shp:" => process_shp(&opt, b),
"snd:" => process_snd(&opt, b), "snd:" => process_snd(&opt, b),
_ => Err(err_msg("invalid file type specified on commandline")), _ => Err(err_msg("invalid file type specified on commandline")),
}?; }?;
} }

View File

@ -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

View File

@ -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;
} }

View File

@ -18,8 +18,8 @@ fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()>
let l = match l { let l = match l {
128 => Ok(true), 128 => Ok(true),
0 => Ok(false), 0 => Ok(false),
_ => Err(err_msg("invalid flag in color")), _ => Err(err_msg("invalid flag in color")),
}?; }?;
let cr = ColorShp::Opaque{r, g, b, l}; let cr = ColorShp::Opaque{r, g, b, l};

View File

@ -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, "}}")
} }
} }

View File

@ -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.
@ -27,30 +27,30 @@ pub fn read_chunks(b: &[u8], old_dat: bool, siz_cnk: usize)
let data = &b[beg..end]; let data = &b[beg..end];
chunks.push(match &iden.0 { chunks.push(match &iden.0 {
b"PICT" => Chunk::Pict(pict::load_pict(data)?), b"PICT" => Chunk::Pict(pict::load_pict(data)?),
b"Minf" => Chunk::Minf(map::read_minf(data)?), b"Minf" => Chunk::Minf(map::read_minf(data)?),
b"iidx" => Chunk::Iidx(rd_array(data, map::read_iidx)?), b"iidx" => Chunk::Iidx(rd_array(data, map::read_iidx)?),
b"EPNT" => Chunk::Pnts(rd_array(data, map::read_epnt)?), b"EPNT" => Chunk::Pnts(rd_array(data, map::read_epnt)?),
b"PNTS" => Chunk::Pnts(rd_array(data, map::read_pnts)?), b"PNTS" => Chunk::Pnts(rd_array(data, map::read_pnts)?),
b"LINS" => Chunk::Lins(rd_array(data, map::read_lins)?), b"LINS" => Chunk::Lins(rd_array(data, map::read_lins)?),
b"SIDS" => Chunk::Sids(rd_array(data, map_read_sides)?), b"SIDS" => Chunk::Sids(rd_array(data, map_read_sides)?),
b"POLY" => Chunk::Poly(rd_array(data, map_read_polys)?), b"POLY" => Chunk::Poly(rd_array(data, map_read_polys)?),
b"OBJS" => Chunk::Objs(rd_array(data, map::read_objs)?), b"OBJS" => Chunk::Objs(rd_array(data, map::read_objs)?),
b"LITE" => Chunk::Lite(rd_array(data, map_read_light)?), b"LITE" => Chunk::Lite(rd_array(data, map_read_light)?),
b"plac" => Chunk::Plac(rd_array(data, map::read_plac)?), b"plac" => Chunk::Plac(rd_array(data, map::read_plac)?),
b"ambi" => Chunk::Ambi(rd_array(data, map::read_ambi)?), b"ambi" => Chunk::Ambi(rd_array(data, map::read_ambi)?),
b"bonk" => Chunk::Bonk(rd_array(data, map::read_bonk)?), b"bonk" => Chunk::Bonk(rd_array(data, map::read_bonk)?),
b"medi" => Chunk::Medi(rd_array(data, map::read_medi)?), b"medi" => Chunk::Medi(rd_array(data, map::read_medi)?),
b"plat" => Chunk::Plat(rd_array(data, map::read_plat)?), b"plat" => Chunk::Plat(rd_array(data, map::read_plat)?),
b"NOTE" => Chunk::Note(rd_array(data, map::read_note)?), b"NOTE" => Chunk::Note(rd_array(data, map::read_note)?),
b"term" => Chunk::Term(rd_array(data, trm::read_term)?), b"term" => Chunk::Term(rd_array(data, trm::read_term)?),
b"FXpx" => Chunk::Fxpx(rd_array(data, phy::read_fxpx)?), b"FXpx" => Chunk::Fxpx(rd_array(data, phy::read_fxpx)?),
b"MNpx" => Chunk::Mnpx(rd_array(data, phy::read_mnpx)?), b"MNpx" => Chunk::Mnpx(rd_array(data, phy::read_mnpx)?),
b"PRpx" => Chunk::Prpx(rd_array(data, phy::read_prpx)?), b"PRpx" => Chunk::Prpx(rd_array(data, phy::read_prpx)?),
b"PXpx" => Chunk::Pxpx(rd_array(data, phy::read_pxpx)?), b"PXpx" => Chunk::Pxpx(rd_array(data, phy::read_pxpx)?),
b"WPpx" => Chunk::Wppx(rd_array(data, phy::read_wppx)?), b"WPpx" => Chunk::Wppx(rd_array(data, phy::read_wppx)?),
_ => Chunk::Data{iden, data: data.to_vec()}, _ => Chunk::Data{iden, data: data.to_vec()},
}); });
p = end; p = end;
} }

View File

@ -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

View File

@ -4,11 +4,10 @@ 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();
} }
// EOF // EOF

View File

@ -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>,

View File

@ -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::*;
@ -23,21 +22,21 @@ fn mk_draw_area(b: &gtk::Builder)
let im = CairoPixbuf(load_img("/net/greyserv/maraiah/tycho/tycho1")); let im = CairoPixbuf(load_img("/net/greyserv/maraiah/tycho/tycho1"));
area.connect_draw(move |area, cr| { area.connect_draw(move |area, cr| {
let w = f64::from(area.get_allocated_width()); let w = f64::from(area.get_allocated_width());
let h = f64::from(area.get_allocated_height()); let h = f64::from(area.get_allocated_height());
ax.set_lower(0.0); ax.set_lower(0.0);
ax.set_upper(w); ax.set_upper(w);
ay.set_lower(0.0); ay.set_lower(0.0);
ay.set_upper(h); ay.set_upper(h);
let d = CairoDrawArea::new(cr.clone(), w, h); let d = CairoDrawArea::new(cr.clone(), w, h);
draw_map_none(&d, &im); draw_map_none(&d, &im);
Inhibit(true) Inhibit(true)
}); });
} }
fn run_app(app: &gtk::Application) fn run_app(app: &gtk::Application)

View File

@ -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();
} }
} }