-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.cpp2
81 lines (63 loc) · 2.48 KB
/
tests.cpp2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "thumbhash.h2"
main: () -> int = {
{ // test1
test_data1_rgba : const std::array<u8, 16> = (
0xff, 0xff, 0xff, 0xff, /* sep */ 0xff, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff, /* sep */ 0xff, 0xff, 0xff, 0xff,
);
test_data1_hash : const std::array<u8, 24> = (
// old (blury upscale)
//0xF5, 0x78, 0x0E, 0x2F, 0x12, 0x7F, 0x87, 0x87,
//0xC0, 0x77, 0x77, 0x78, 0x88, 0x88, 0x87, 0x78,
//0x78, 0x78, 0x07, 0xF8, 0x73, 0x80, 0x3F, 0x07,
// new (nn upscale 64x64 + blur upscale to 100x100)
//0xF4, 0x78, 0x0E, 0x2F, 0x14, 0x7F, 0x85, 0x79,
//0xC0, 0x67, 0x88, 0x78, 0x87, 0xA7, 0x86, 0x78,
//0x78, 0x86, 0x08, 0xF8, 0x73, 0x80, 0x3F, 0x07,
// new (nn upscale 128x128 + blur downscale to 100x100)
//0xF4, 0x78, 0x0E, 0x2F, 0x14, 0x8F, 0x85, 0x89,
//0xC0, 0x67, 0x88, 0x87, 0x78, 0xA7, 0x76, 0x78,
//0x87, 0x86, 0x08, 0xF7, 0x83, 0x70, 0x3F, 0x07,
// new (nn upscale 100x100) output of ref js
//0xF4, 0x78, 0x0E, 0x2F, 0x14, 0x8F, 0x85, 0x89,
//0xC0, 0x67, 0x88, 0x87, 0x78, 0xA7, 0x76, 0x78,
//0x87, 0x86, 0x08, 0xF7, 0x83, 0x70, 0x3F, 0x07,
// new (nn upscale 100x100) output of self
0xF4, 0x78, 0x0E, 0x2F, 0x14, 0x8F, 0x85, 0x89,
0xC0, 0x67, 0x87, 0x78, 0x88, 0xA8, 0x86, 0x88,
0x88, 0x86, 0x08, 0xF8, 0x83, 0x80, 0x3F, 0x08,
);
src_w : const = 2;
src_h : const = 2;
// fist resize to 100x100 (aprox)
resized := thumbhash::scale_to_size_nn(test_data1_rgba, src_w, src_h);
// run hash
//hash_result : _ = thumbhash::rgba_to_hash(test_data1_rgba, src_w, src_h);
hash_result : _ = thumbhash::rgba_to_hash(resized.out_img, resized.out_w, resized.out_h);
std::cout << "computed hash: ";
for hash_result do (e) {
std::cout << "(e:02x)$ ";
}
std::cout << "\n";
// compare
//assert(hash_result.ssize() == test_data1_hash.ssize());
if (hash_result.ssize() != test_data1_hash.ssize()) {
std::cerr << "hash size mismatch, should be (test_data1_hash.ssize())$ but is (hash_result.ssize())$\n";
//return 1;
hash_result.resize(test_data1_hash.size());
}
for 0 ..< hash_result.ssize() do (i) {
if (hash_result[i] != test_data1_hash[i]) {
std::cerr << "hash mismatch @ (i)$, should be (test_data1_hash[i]:#04x)$ but is (hash_result[i]:#04x)$\n";
std::cerr << "test hash: ";
for test_data1_hash do (e) {
std::cerr << "(e:02x)$ ";
}
std::cerr << "\n";
return 1;
}
}
std::cout << "reconstructed aspect ratio: (thumbhash::hash_to_aspect_ratio(hash_result))$\n";
}
return 0;
}