fixed bug with color layering issue
This commit is contained in:
+61
-21
@@ -77,16 +77,36 @@ pub fn parse(data: &[u8]) -> Result<Vec<StitchCommand>, Error> {
|
||||
/// Standard bit layout for dx across bytes b0, b1, b2.
|
||||
fn decode_dx(b0: u8, b1: u8, b2: u8) -> i16 {
|
||||
let mut x: i16 = 0;
|
||||
if b0 & 0x01 != 0 { x += 1; }
|
||||
if b0 & 0x02 != 0 { x -= 1; }
|
||||
if b0 & 0x04 != 0 { x += 9; }
|
||||
if b0 & 0x08 != 0 { x -= 9; }
|
||||
if b1 & 0x01 != 0 { x += 3; }
|
||||
if b1 & 0x02 != 0 { x -= 3; }
|
||||
if b1 & 0x04 != 0 { x += 27; }
|
||||
if b1 & 0x08 != 0 { x -= 27; }
|
||||
if b2 & 0x04 != 0 { x += 81; }
|
||||
if b2 & 0x08 != 0 { x -= 81; }
|
||||
if b0 & 0x01 != 0 {
|
||||
x += 1;
|
||||
}
|
||||
if b0 & 0x02 != 0 {
|
||||
x -= 1;
|
||||
}
|
||||
if b0 & 0x04 != 0 {
|
||||
x += 9;
|
||||
}
|
||||
if b0 & 0x08 != 0 {
|
||||
x -= 9;
|
||||
}
|
||||
if b1 & 0x01 != 0 {
|
||||
x += 3;
|
||||
}
|
||||
if b1 & 0x02 != 0 {
|
||||
x -= 3;
|
||||
}
|
||||
if b1 & 0x04 != 0 {
|
||||
x += 27;
|
||||
}
|
||||
if b1 & 0x08 != 0 {
|
||||
x -= 27;
|
||||
}
|
||||
if b2 & 0x04 != 0 {
|
||||
x += 81;
|
||||
}
|
||||
if b2 & 0x08 != 0 {
|
||||
x -= 81;
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
@@ -94,16 +114,36 @@ fn decode_dx(b0: u8, b1: u8, b2: u8) -> i16 {
|
||||
/// Standard bit layout for dy across bytes b0, b1, b2.
|
||||
fn decode_dy(b0: u8, b1: u8, b2: u8) -> i16 {
|
||||
let mut y: i16 = 0;
|
||||
if b0 & 0x80 != 0 { y += 1; }
|
||||
if b0 & 0x40 != 0 { y -= 1; }
|
||||
if b0 & 0x20 != 0 { y += 9; }
|
||||
if b0 & 0x10 != 0 { y -= 9; }
|
||||
if b1 & 0x80 != 0 { y += 3; }
|
||||
if b1 & 0x40 != 0 { y -= 3; }
|
||||
if b1 & 0x20 != 0 { y += 27; }
|
||||
if b1 & 0x10 != 0 { y -= 27; }
|
||||
if b2 & 0x20 != 0 { y += 81; }
|
||||
if b2 & 0x10 != 0 { y -= 81; }
|
||||
if b0 & 0x80 != 0 {
|
||||
y += 1;
|
||||
}
|
||||
if b0 & 0x40 != 0 {
|
||||
y -= 1;
|
||||
}
|
||||
if b0 & 0x20 != 0 {
|
||||
y += 9;
|
||||
}
|
||||
if b0 & 0x10 != 0 {
|
||||
y -= 9;
|
||||
}
|
||||
if b1 & 0x80 != 0 {
|
||||
y += 3;
|
||||
}
|
||||
if b1 & 0x40 != 0 {
|
||||
y -= 3;
|
||||
}
|
||||
if b1 & 0x20 != 0 {
|
||||
y += 27;
|
||||
}
|
||||
if b1 & 0x10 != 0 {
|
||||
y -= 27;
|
||||
}
|
||||
if b2 & 0x20 != 0 {
|
||||
y += 81;
|
||||
}
|
||||
if b2 & 0x10 != 0 {
|
||||
y -= 81;
|
||||
}
|
||||
// DST Y axis is inverted (positive = up in machine coords, down in screen coords)
|
||||
-y
|
||||
}
|
||||
@@ -166,7 +206,7 @@ mod tests {
|
||||
assert_eq!(decode_dx(0x04, 0x00, 0x00), 9);
|
||||
assert_eq!(decode_dx(0x00, 0x04, 0x00), 27);
|
||||
assert_eq!(decode_dx(0x00, 0x00, 0x04), 81);
|
||||
assert_eq!(decode_dx(0x05, 0x05, 0x04), 1 + 9 + 27 + 81); // 118
|
||||
assert_eq!(decode_dx(0x05, 0x05, 0x04), 1 + 9 + 3 + 27 + 81); // 121
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user