LZanio CCCCLLLL NOTE: length is always in L+1 NOTE 2: Length in nibble merge commands are length for nibbles, not bytes 0000LLLL 00 fill. 0001LLLL FF fill. 0010LLLL XX RLE byte fill. 0011LLLL XXYY RLE word fill 0100LLLL XY [...] Direct copy (how could I almost forget this) 0101LLLL XY [...] Left-sided nibble merge. example 0101 0011 33 83 11 AA -> 30 30 80 30 10 10 A0 A0 0110LLLL XY [...] Right-sided nibble merge. example 0110 0011 33 83 11 AA -> 03 03 08 03 01 01 0A 0A 0111LLLL NNNNRRRR RRRR RRRR [...] Left-sided constant nibble merge. example 0111 1000 F1 31 26 9F F1 -> F1 F3 F1 F2 F6 F9 FF FF F1 1000LLLL NNNNRRRR RRRR RRRR [...] Right-sided constant nibble merge. example 0111 1000 F1 31 26 9F F1 -> 1F 3F 1F 2F 6F 9F FF FF 1F 1001LLLL XX YY YY YY [...] Left-sided constant word fill. example 1001 0011 69 01 33 55 AA -> 69 01 69 33 69 55 69 AA 1010LLLL XX YY YY YY [...] Right-sided constant word fill. example 1001 0011 69 01 33 55 AA -> 01 69 33 69 55 69 AA 69 1011LLLL XX NNNN RRRR RRRR RRRR [...] Left-sided constant word left-sided nibble merge fill. example 1011 0011 AA 12 34 -> AA 10 AA 20 AA 30 AA 40 1100LLLL XX NNNN RRRR RRRR RRRR [...] Left-sided constant word right-sided nibble merge fill. example 1011 0011 AA 12 34 -> AA 01 AA 02 AA 03 AA 04 1101LLLL IIIIIIII Repeat (8-bit range, 4-bit length) 1110CCCC LLLLLLLL Double length 11101110 LLLLLLLL IIIIIIII Repeat (8-bit range, 8-bit length) 11101111 LLLLLLLL IIIIIIII IIIIIIII XOR with 0xFF Repeat (16-bit range, 8-bit length) 1111CCCC LLLLLLLL LLLLLLLL Quadruple length 11111110 WDM 11111111 EOF Steps for compression - Check RLE Word first - Check n+0, n+2, n+4, etc. - If they are all the same - Check n+1, n+3, n+5, etc. - If they are all the same - Use command 0011LLLL - Else, if n+0, n+1, n+2 etc can be left-sided/right-sided nibble merge fill. like, 11 40 11 90 -> 11 49 - Use command 1011LLLL - Else if, check byte RLE - Check if RLE bytes are 0 - if 0 - Use command 0000LLLL - else, if FF - use command 0001LLLL - if neither of those - use command 0010LLLL - Else if, check for left-sided nibble merge (F0, 90, 10, etc) - If it's possible - If left nibble is constant AND right nibble is not constant - Use command 0111LLLL (left-sided constant nibble merge) - Else - Use command 0101LLLL (left-sided nibble merge) - Else if, check for right-sided nibble merge - If it's possible - Check if right nibble is constant AND left nibble is not constant - Use command 1000LLLL - Else - Use command 0110LLLL