1 | #!/usr/bin/env python |
---|
2 | # This file is part of Xpra. |
---|
3 | # Copyright (C) 2020 Antoine Martin <antoine@xpra.org> |
---|
4 | # Xpra is released under the terms of the GNU GPL v2, or, at your option, any |
---|
5 | # later version. See the file COPYING for details. |
---|
6 | |
---|
7 | import sys |
---|
8 | |
---|
9 | from PIL import Image |
---|
10 | from xpra.util import csv |
---|
11 | from xpra.server.window.motion import ScrollData #@UnresolvedImport |
---|
12 | |
---|
13 | |
---|
14 | def main(): |
---|
15 | scroll_data = ScrollData() |
---|
16 | for i, x in enumerate(sys.argv[1:]): |
---|
17 | img = Image.open(x) |
---|
18 | img = img.convert("RGBA") |
---|
19 | pixels = img.tobytes("raw", "BGRA") |
---|
20 | w, h = img.size |
---|
21 | Bpp = 4 |
---|
22 | stride = w*Bpp |
---|
23 | scroll_data.update(pixels, 0, 0, w, h, stride, Bpp) |
---|
24 | if i==0: |
---|
25 | continue |
---|
26 | scroll_data.calculate(1000) |
---|
27 | scroll, count = scroll_data.get_best_match() |
---|
28 | match_pct = int(100*count/h) |
---|
29 | print("best scroll guess matches %i%% of %i lines: %s" % (match_pct, h, scroll)) |
---|
30 | assert match_pct>10 |
---|
31 | raw_scroll, non_scroll = scroll_data.get_scroll_values() |
---|
32 | scrolls = [] |
---|
33 | for scroll, line_defs in raw_scroll.items(): |
---|
34 | if scroll==0: |
---|
35 | continue |
---|
36 | for line, count in line_defs.items(): |
---|
37 | scrolls.append((0, 0+line, w, count, 0, scroll)) |
---|
38 | print("scrolls:") |
---|
39 | for scroll in scrolls: |
---|
40 | print("%s" % (csv(scroll),)) |
---|
41 | #self.encode_scrolling(scroll_data, image, options, match_pct) |
---|
42 | |
---|
43 | |
---|
44 | if __name__ == "__main__": |
---|
45 | main() |
---|