-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the Z64 and B64 compression schemes. (#169)
* Added support for the Z64 and B64 compression schemes. Optimized ACS compression scheme to remove "G" character usage. "G" encodes for a repeat of 1, so you end up 2 characters instead of just 1. Updated Tests to cover all compression schemes. Updated TestConsole to cover all compression schemes. Update Viewer to cover all compression schemes. * cleaning up previous commit. * Cleaned up deflate compression method. * Cleaned up Crc16 implementation according to feedback from primo-ppcg. Added more tests to check the various compression levels. Cleaned up formatting. * Unify compression output across platform Both libraries agree on the output of `CompressionLevel.SmallestSize`. * Fix bug for ACS compression on net472. Tests cleaned up to be able to complie for net472. * Clean up Protocol Add unit tests for Protocol. Fix compression levels to match Label.
- Loading branch information
Showing
35 changed files
with
1,211 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,3 +251,6 @@ paket-files/ | |
.idea/ | ||
*.sln.iml | ||
/SGHLabel | ||
|
||
# CodeRush | ||
.cr/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/BinaryKits.Zpl.Label.UnitTest/ZebraB64CompressionHelperTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using BinaryKits.Zpl.Label.Helpers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
|
||
namespace BinaryKits.Zpl.Label.UnitTest | ||
{ | ||
[TestClass] | ||
public class ZebraB64CompressionHelperTest | ||
{ | ||
[TestMethod] | ||
public void Compress_ValidData1_Successful() | ||
{ | ||
var compressed = ZebraB64CompressionHelper.Compress("FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"); | ||
Assert.AreEqual(":B64://///////////4AA//8AAP//AAGAAP//AAD//wABgAD//wAA//8AAf//AAD//wAA/////wAA//8AAP////8AAP//AAD///////////////8=:e4b3", compressed); | ||
//^XA | ||
//~DGR:SAMPLE.GRF,00006,02,JFGFH0GFJF | ||
//^FO20,20 | ||
//^XGR:SAMPLE.GRF,1,1^FS | ||
//^XZ | ||
} | ||
[TestMethod] | ||
public void CompressUncompress_Flow_Successful() | ||
{ | ||
var originalData = "FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"; | ||
|
||
string compressed = ZebraB64CompressionHelper.Compress(originalData); | ||
string uncompressed = ZebraB64CompressionHelper.Uncompress(compressed).ToHexFromBytes(); | ||
Assert.AreEqual(originalData, uncompressed); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/BinaryKits.Zpl.Label.UnitTest/ZebraZ64CompressionHelperTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using BinaryKits.Zpl.Label.Helpers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO.Compression; | ||
|
||
namespace BinaryKits.Zpl.Label.UnitTest | ||
{ | ||
[TestClass] | ||
public class ZebraZ64CompressionHelperTest | ||
{ | ||
[TestMethod] | ||
public void Compress_ValidData1_Successful() | ||
{ | ||
var compressed = ZebraZ64CompressionHelper.Compress("FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"); | ||
Assert.AreEqual(":Z64:eNr7/x8GGhj+/2cAYUZsLCjNAFKJjQUDAOLDM1I=:8f39", compressed); | ||
//^XA | ||
//~DGR:SAMPLE.GRF,00006,02,JFGFH0GFJF | ||
//^FO20,20 | ||
//^XGR:SAMPLE.GRF,1,1^FS | ||
//^XZ | ||
} | ||
[TestMethod] | ||
public void CompressUncompress_Flow_Successful() | ||
{ | ||
var originalData = "FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"; | ||
|
||
string compressed = ZebraZ64CompressionHelper.Compress(originalData); | ||
string uncompressed = ZebraZ64CompressionHelper.Uncompress(compressed).ToHexFromBytes(); | ||
Assert.AreEqual(originalData, uncompressed); | ||
} | ||
#if NET5_0_OR_GREATER | ||
[TestMethod] | ||
public void DeflateNetStandardSameAsNetCore_Optimal_Successful() | ||
{ | ||
var originalData = "FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"; | ||
|
||
var compressionLevel = CompressionLevel.Optimal; | ||
string compressed = ZebraZ64CompressionHelper.Deflate(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
string compressedCore = ZebraZ64CompressionHelper.DeflateCore(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
|
||
Assert.AreEqual(compressed, compressedCore); | ||
} | ||
[TestMethod] | ||
public void DeflateNetStandardSameAsNetCore_Fastest_Successful() | ||
{ | ||
var originalData = "FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"; | ||
|
||
var compressionLevel = CompressionLevel.Fastest; | ||
string compressed = ZebraZ64CompressionHelper.Deflate(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
string compressedCore = ZebraZ64CompressionHelper.DeflateCore(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
|
||
Assert.AreEqual(compressed, compressedCore); | ||
} | ||
[TestMethod] | ||
public void DeflateNetStandardSameAsNetCore_SmallestSize_Successful() | ||
{ | ||
var originalData = "FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"; | ||
|
||
var compressionLevel = CompressionLevel.SmallestSize; | ||
string compressed = ZebraZ64CompressionHelper.Deflate(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
string compressedCore = ZebraZ64CompressionHelper.DeflateCore(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
|
||
Assert.AreEqual(compressed, compressedCore); | ||
} | ||
[TestMethod] | ||
public void DeflateNetStandardSameAsNetCore_NoCompression_Successful() | ||
{ | ||
var originalData = "FFFFFFFFFFFFFFFFFFFF8000FFFF0000FFFF00018000FFFF0000FFFF00018000FFFF0000FFFF0001FFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFF0000FFFF0000FFFFFFFFFFFFFFFFFFFFFFFF"; | ||
|
||
var compressionLevel = CompressionLevel.NoCompression; | ||
string compressed = ZebraZ64CompressionHelper.Deflate(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
string compressedCore = ZebraZ64CompressionHelper.DeflateCore(originalData.ToBytesFromHex(), compressionLevel).ToHexFromBytes(); | ||
|
||
Assert.AreEqual(compressed, compressedCore); | ||
} | ||
[TestMethod] | ||
public void InflateNetStandardSameAsNetCore_Successful() | ||
{ | ||
var originalData = "eJz7/x8GGhj+/2cAYUZsLCgNxNhZMAAA4sMzUg=="; | ||
|
||
string compressed = ZebraZ64CompressionHelper.Inflate(originalData.FromBase64()).ToHexFromBytes(); | ||
string compressedCore = ZebraZ64CompressionHelper.InflateCore(originalData.FromBase64()).ToHexFromBytes(); | ||
|
||
Assert.AreEqual(compressed, compressedCore); | ||
} | ||
#endif | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
src/BinaryKits.Zpl.Label.UnitTest/ZplData/DownloadGraphics.txt
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/BinaryKits.Zpl.Label.UnitTest/ZplData/DownloadGraphicsACS.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
^XA | ||
^LH0,0 | ||
^CI28 | ||
|
||
^FO0,0 | ||
^GB100,100,4,B,0^FS | ||
|
||
~DGR:SAMPLE.GRF,1190,17, | ||
,:::::::::H03MF803MF803HF8,H02M0803M0802H08,H02L01H028L0802H08,H02L01H024L0802H08,H02L02H0H2L0802H08,H02L02H021L0802H08,H02L04H0208K0802H08,H02L04H0204K0802H08,H02L08H0202K0802H08,H02L08H0201K0802H08,H03IFC01I02H0HFEH0802H08,L0401I02H0802H0802H08,L0802I02H0802H0802H08,:K01H04I02H0802H0802H08,:K02H08I02H0802H0802H08,:K0401J02H0802H0802H08,:K0802J02H0HFEH0802H08,K0802J02M0802H08,J01H04J02M0802H08,:J02H08J02M0802H08,:J0401K02M0802H08,:J0802K02M0802H08,:I01H04K02H0KF802H08,I01H04K02H08L02H08,I02H08K02H08L02H08,:I0401L02H08L02H08,:I0802L02H08L02H08,:H01H04L02H08L02H08,:H02H0KF802H08L02H0KF8,H02M0802H08L02M08,::::::::H03MF803HF8L03MF8,,:::::::: | ||
|
||
^FO100,100 | ||
^XGR:SAMPLE.GRF,1,1^FS | ||
^XZ |
13 changes: 13 additions & 0 deletions
13
src/BinaryKits.Zpl.Label.UnitTest/ZplData/DownloadGraphicsB64.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
^XA | ||
^LH0,0 | ||
^CI28 | ||
|
||
^FO0,0 | ||
^GB100,100,4,B,0^FS | ||
|
||
~DGR:SAMPLE.GRF,1190,17, | ||
:B64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////4A/////gD/4AAAAAAAgAAAAgDAAAACAIAgAAAAAACAAAAEAKAAAAIAgCAAAAAAAIAAAAQAkAAAAgCAIAAAAAAAgAAACACIAAACAIAgAAAAAACAAAAIAIQAAAIAgCAAAAAAAIAAABAAggAAAgCAIAAAAAAAgAAAEACBAAACAIAgAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=:9723 | ||
|
||
^FO100,100 | ||
^XGR:SAMPLE.GRF,1,1^FS | ||
^XZ |
13 changes: 13 additions & 0 deletions
13
src/BinaryKits.Zpl.Label.UnitTest/ZplData/DownloadGraphicsZ64.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
^XA | ||
^LH0,0 | ||
^CI28 | ||
|
||
^FO0,0 | ||
^GB100,100,4,B,0^FS | ||
|
||
~DGR:SAMPLE.GRF,1190,17, | ||
:Z64:eNrV0z0OwyAMBeBHxMBWjuBUHTr2BuFoHK3H6hRq07T8DPaaRoI8fUv8ggD+5tlKKfmzvSoQr/yQjcIXHO4z3EZYcJ1hHcGD8gxpgACiGWKDrTwj6LL/AEgMYekgkwEOyQCOBngHAziPk1bo/geit0DeOnB7A7i9DtKeJ+XTHyAcnzva6yDtdZD2Okh7HdqQNfU1ajoPtMtU03mv/huIbE59:1804 | ||
|
||
^FO100,100 | ||
^XGR:SAMPLE.GRF,1,1^FS | ||
^XZ |
Oops, something went wrong.