public void TestInvalid1() { byte[] data = { 0, 255, 255, 255 }; FingerprintDecompressor decompressor = new FingerprintDecompressor(); int algorithm = -1; int[] value = decompressor.Decompress(Base64.ByteEncoding.GetString(data), out algorithm); Assert.AreEqual(value.Length, 0); Assert.AreEqual(0, algorithm); }
public void TestOneItemOneBit() { int[] expected = { 1 }; byte[] data = { 0, 0, 0, 1, 1 }; FingerprintDecompressor decompressor = new FingerprintDecompressor(); int algorithm = -1; int[] actual = decompressor.Decompress(Base64.ByteEncoding.GetString(data), out algorithm); Assert.AreEqual(0, algorithm); CollectionAssert.AreEqual(actual, expected); }
public void TestLong() { int[] expected = { -587455133, -591649759, -574868448, -576973520, -543396544, 1330439488, 1326360000, 1326355649, 1191625921, 1192674515, 1194804466, 1195336818, 1165981042, 1165956451, 1157441379, 1157441299, 1291679571, 1291673457, 1170079601 }; string data = Base64.Decode("AQAAEwkjrUmSJQpUHflR9mjSJMdZpcO_Imdw9dCO9Clu4_wQPvhCB01w6xAtXNcAp5RASgDBhDSCGGIAcwA"); FingerprintDecompressor decompressor = new FingerprintDecompressor(); int algorithm = -1; int[] value = decompressor.Decompress(data, out algorithm); Assert.AreEqual(1, algorithm); CollectionAssert.AreEqual(value, expected); }
/// <summary> /// Uncompress and optionally base64-decode an encoded fingerprint. /// </summary> /// <param name="encoded_fp">Pointer to an encoded fingerprint</param> /// <param name="base64">Whether the encoded_fp parameter contains binary data or base64-encoded /// ASCII data. If 1, it will base64-decode the data before uncompressing the fingerprint.</param> /// <param name="algorithm">Chromaprint algorithm version which was used to generate the raw /// fingerprint</param> /// <returns>The decoded raw fingerprint (array of 32-bit integers)</returns> public static int[] DecodeFingerprint(byte[] encoded_fp, bool base64, out int algorithm) { string encoded = Base64.ByteEncoding.GetString(encoded_fp); string compressed = base64 ? Base64.Decode(encoded) : encoded; FingerprintDecompressor decompressor = new FingerprintDecompressor(); int[] uncompressed = decompressor.Decompress(compressed, out algorithm); int size = uncompressed.Length; int[] fp = new int[size]; // TODO: copying necessary? Array.Copy(uncompressed, fp, size); return(fp); }