// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
TEST(FieldsTest, U64CoderTest) { // Values that should take 2 bits (selector 00): 0
TestU64Coder(0, 2);
// Values that should take 6 bits (2 for selector, 4 for value): 1..16
TestU64Coder(1, 6);
TestU64Coder(2, 6);
TestU64Coder(8, 6);
TestU64Coder(15, 6);
TestU64Coder(16, 6);
// Values that should take 10 bits (2 for selector, 8 for value): 17..272
TestU64Coder(17, 10);
TestU64Coder(18, 10);
TestU64Coder(100, 10);
TestU64Coder(271, 10);
TestU64Coder(272, 10);
// Values that should take 15 bits (2 for selector, 12 for value, 1 for varint // end): (0)..273..4095
TestU64Coder(273, 15);
TestU64Coder(274, 15);
TestU64Coder(1000, 15);
TestU64Coder(4094, 15);
TestU64Coder(4095, 15);
// Take 24 bits (of which 20 actual value): (0)..4096..1048575
TestU64Coder(4096, 24);
TestU64Coder(4097, 24);
TestU64Coder(10000, 24);
TestU64Coder(1048574, 24);
TestU64Coder(1048575, 24);
// Take 33 bits (of which 28 actual value): (0)..1048576..268435455
TestU64Coder(1048576, 33);
TestU64Coder(1048577, 33);
TestU64Coder(10000000, 33);
TestU64Coder(268435454, 33);
TestU64Coder(268435455, 33);
// Take 42 bits (of which 36 actual value): (0)..268435456..68719476735
TestU64Coder(268435456ull, 42);
TestU64Coder(268435457ull, 42);
TestU64Coder(1000000000ull, 42);
TestU64Coder(68719476734ull, 42);
TestU64Coder(68719476735ull, 42);
// Take 51 bits (of which 44 actual value): (0)..68719476736..17592186044415
TestU64Coder(68719476736ull, 51);
TestU64Coder(68719476737ull, 51);
TestU64Coder(1000000000000ull, 51);
TestU64Coder(17592186044414ull, 51);
TestU64Coder(17592186044415ull, 51);
// Take 60 bits (of which 52 actual value): // (0)..17592186044416..4503599627370495
TestU64Coder(17592186044416ull, 60);
TestU64Coder(17592186044417ull, 60);
TestU64Coder(100000000000000ull, 60);
TestU64Coder(4503599627370494ull, 60);
TestU64Coder(4503599627370495ull, 60);
// Take 69 bits (of which 60 actual value): // (0)..4503599627370496..1152921504606846975
TestU64Coder(4503599627370496ull, 69);
TestU64Coder(4503599627370497ull, 69);
TestU64Coder(10000000000000000ull, 69);
TestU64Coder(1152921504606846974ull, 69);
TestU64Coder(1152921504606846975ull, 69);
// Take 73 bits (of which 64 actual value): // (0)..1152921504606846976..18446744073709551615
TestU64Coder(1152921504606846976ull, 73);
TestU64Coder(1152921504606846977ull, 73);
TestU64Coder(10000000000000000000ull, 73);
TestU64Coder(18446744073709551614ull, 73);
TestU64Coder(18446744073709551615ull, 73);
}
Status TestF16Coder(constfloat value) {
JxlMemoryManager* memory_manager = jxl::test::MemoryManager();
size_t max_encoded_bits; // It is not a fatal error if it can't be encoded. if (!F16Coder::CanEncode(value, &max_encoded_bits)) returnfalse;
EXPECT_EQ(F16Coder::MaxEncodedBits(), max_encoded_bits);
BitReader reader(writer.GetSpan()); float decoded_value;
EXPECT_TRUE(F16Coder::Read(&reader, &decoded_value)); // All values we test can be represented exactly.
EXPECT_EQ(value, decoded_value);
EXPECT_TRUE(reader.Close()); returntrue;
}
TEST(FieldsTest, F16CoderTest) { for (float sign : {-1.0f, 1.0f}) { // (anything less than 1E-3 are subnormals) for (float mag : {0.0f, 0.5f, 1.0f, 2.0f, 2.5f, 16.015625f, 1.0f / 4096,
1.0f / 16384, 65504.0f}) {
EXPECT_TRUE(TestF16Coder(sign * mag));
}
}
// Out of range
EXPECT_FALSE(TestF16Coder(65504.01f));
EXPECT_FALSE(TestF16Coder(-65505.0f));
}
// Ensures Read(Write()) returns the same fields.
TEST(FieldsTest, TestRoundtripSize) {
JxlMemoryManager* memory_manager = jxl::test::MemoryManager(); for (int i = 0; i < 8; i++) {
SizeHeader size;
ASSERT_TRUE(size.Set(123 + 77 * i, 7 + i));
// Old fields are the same in both
EXPECT_EQ(old_bundle.extensions, new_bundle.extensions);
EXPECT_EQ(old_bundle.old_small, new_bundle.old_small);
EXPECT_EQ(old_bundle.old_f, new_bundle.old_f);
EXPECT_EQ(old_bundle.old_large, new_bundle.old_large); // New fields match their defaults
EXPECT_EQ(2u, new_bundle.new_small);
EXPECT_EQ(-2.0f, new_bundle.new_f);
EXPECT_EQ(0u, new_bundle.new_large);
}
// Old fields are the same in both
EXPECT_EQ(new_bundle.extensions, old_bundle.extensions);
EXPECT_EQ(new_bundle.old_small, old_bundle.old_small);
EXPECT_EQ(new_bundle.old_f, old_bundle.old_f);
EXPECT_EQ(new_bundle.old_large, old_bundle.old_large); // (Can't check new fields because old decoder doesn't know about them)
}
} // namespace
} // namespace jxl
Messung V0.5
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.