From 0c8d2fd115796615fc6a253fcba4409de4c06c5c Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Sat, 12 Sep 2020 16:15:21 +0200 Subject: [PATCH] Improve image positioning a little --- docs/changelog.md | 1 + src/cli/sdoc.rs | 2 +- src/print/mod.rs | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index ff2f2e8..d1ab436 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,7 @@ - Added `--plain` option to the `dump` command to skip printing tags that provide debugging information on lines and paragraphs. +- Minor improvements in image positioning and scaling. ### 11.09.2020 diff --git a/src/cli/sdoc.rs b/src/cli/sdoc.rs index a8ebffd..55f3fe8 100644 --- a/src/cli/sdoc.rs +++ b/src/cli/sdoc.rs @@ -678,7 +678,7 @@ impl<'a> Document<'a> { if let Some(pd) = self.print_driver { let px = pd.scale_x(10 + site.pos_x); let w = pd.scale_x(site._3); - let py = pd.scale_y(10 + site.pos_y); + let py = pd.scale_y(10 + site.pos_y - site._5 / 2); let h = pd.scale_y(site._4 / 2); let image = &self.images[site.img as usize]; page.draw_image(px, py, w, h, image, site.sel); diff --git a/src/print/mod.rs b/src/print/mod.rs index 552d5b3..de180d6 100644 --- a/src/print/mod.rs +++ b/src/print/mod.rs @@ -33,6 +33,7 @@ struct VScaler<'a> { last_vcount: usize, iubpl: usize, ibyte_index: usize, + skip_bits: u16, ivpixel_rem: usize, vpxl: bool, } @@ -42,6 +43,8 @@ impl<'a> VScaler<'a> { let iubpl = image.bytes_per_line as usize; let pixel_v_len = (h as usize) / (sel.h as usize); let ivpixel_rem = 0; + let ibyte_index = (sel.y as usize) * iubpl + (sel.x as usize) / 8; + let skip_bits = sel.x % 8; let vpxl = false; Self { sel_h: sel.h as usize, @@ -54,7 +57,8 @@ impl<'a> VScaler<'a> { vpixel_count: 0, last_vcount: 0, iubpl, - ibyte_index: (sel.y as usize) * iubpl + (sel.x as usize) / 8, + ibyte_index, + skip_bits, ivpixel_rem, vpxl, } @@ -66,6 +70,9 @@ impl<'a> VScaler<'a> { let last_hcount = 0; let hpxl = self.vpxl; let ipixel_rem = 0; + for _ in 0..self.skip_bits { + let _ = ibit_iter.next(); + } let icurr = ibit_iter.next().unwrap_or(true); HScaler { vscaler: self, @@ -93,6 +100,13 @@ impl<'a, 'b> HScaler<'a, 'b> { fn next(&mut self) -> bool { if self.vscaler.pixel_h_len == 0 { while self.last_hcount < self.hpixel_count * self.vscaler.sel_w / self.vscaler.w { + if self.ipixel_rem == 7 { + self.hpxl = !self.hpxl; + //self.icurr = self.hpxl; + self.ipixel_rem = 0; + } else { + self.ipixel_rem += 1; + } self.icurr = self.ibit_iter.next().unwrap(); self.last_hcount += 1; }