Closed ghost closed 6 years ago
Hello @AnthonyRonning ,
thanks for your report. Indeed I see the differences and your point. Unfortunately this isn't the fault of QRCoder - so I can't barely do anything.
I compared both PNG files in a hex editor and via debugging at runtime. The input to the PNG class is the same on both system (WIN and MAC). So the differences appear when creating the PNG files. A PNG file contains the image information in a compressed way (deflate compression). For this I use the following code in the PngByteQRCode.cs-class:
//[...]
private static void Deflate(Stream output, byte[] bytes)
{
using (var deflateStream = new DeflateStream(output, CompressionMode.Compress, leaveOpen: true))
{
deflateStream.Write(bytes, 0, bytes.Length);
}
}
//[...]
The deflate stream behaves differently on Win and Mac. Thus the payload of the PNG image changes (and also some header information like payload size).
To fix this problem, the DeflateStream from System.IO.Compression has to be fixed, which isn't anything I can do.
To workaround your issue you could either do your tests on a QRCode data level (like running the tests on the QRCodeData instead of the output of the PngByteQRCode) or do it on a pixel level, by opening the PngByteQrCode as Image/Bitmap object and then compare the outcome pixel by pixel.
If I missunderstood you in any point or if you think I'm wrong with my analysis, please let me know and feel free to re-open this issue.
Type of issue
[x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement
Expected Behavior
Using the same payload on windows & Mac environments, should generate the same QR encoding.
Current Behavior
The same payload shows differently on Mac than on windows, rendering tests useless. The QR code image shows correctly, but the actual text is different.
Even just taking an empty string, this is produced:
Windows:
Mac:
Putting those strings into https://codebeautify.org/base64-to-image-converter produces the same image.
Steps to Reproduce (for bugs)
Using the following code:
Your Environment