Libraryless. Click here for Pure Java version (17452L/112K).
1 | sclass JEImageCompressionTest1 { |
2 | settable BufferedImage originalImage; |
3 | settable BufferedImage scaledImage; |
4 | |
5 | *() { this(screenshot()); } |
6 | *(BufferedImage *originalImage) {} |
7 | |
8 | int rows = 20; |
9 | int imgHeight = 200; |
10 | |
11 | Matrix<Int> m; |
12 | long dataBytes, dataChars; |
13 | Matrix<Matrix<Int>> grid; |
14 | JE_CompressEachElementIndividually<LInt> strat; |
15 | CompressionSearch_AnyType<IJavaExpr, LLInt> search; |
16 | CompressionSearch_AnyType<IJavaExpr, LLInt>.Submission winner; |
17 | |
18 | S get() { |
19 | assertNotNull(originalImage); |
20 | scaledImage = resizeImageToHeight(originalImage, imgHeight); |
21 | |
22 | m = imageToMatrix(scaledImage); |
23 | dataBytes = m.nCells()*4+2; |
24 | dataChars = dataBytes*2 + l("lInt(\"\")"); |
25 | print("Matrix ~ " + takeFirst_str(60, m)); |
26 | print("Trivial comp ~ " + (m.nCells()*8)); |
27 | grid = matrixToMNGrid_rows(m, rows); |
28 | |
29 | // the cells as int matrices |
30 | L<Matrix<Int>> flat = matrixToList(grid); |
31 | |
32 | // the cells as int lists |
33 | //L<LByte> cells = map intMatrixToByteList_littleEndian(flat); |
34 | L<LInt> cells = map matrixToList(flat); |
35 | |
36 | search = jeCompressionSearch(cells, dataChars); |
37 | strat = new JE_CompressEachElementIndividually<LInt>() |
38 | .elementCompressionStrategy(-> new JE_RepElement) |
39 | .onCompressionFail(ints -> javaObjectToIJavaExpr(ints); |
40 | |
41 | //enableScaffolding(search.scheduler()); |
42 | //enableScaffolding(strat); |
43 | //print(scaffolding := metaGet(strat, "scaffolding")); |
44 | search.addStrategy(strat); |
45 | |
46 | runProbabilisticForNSeconds(5.0, search); |
47 | winner = search.bestSubmission(); |
48 | print(strat.stats()); |
49 | if (winner != null) { |
50 | //print("Hard result (score " + result.scoreRatio() + ")", result.checkUnder(hardJERegime()); |
51 | print(winner); |
52 | } |
53 | ret winnerCode(); |
54 | } |
55 | |
56 | S winnerCode() { |
57 | ret winner == null ?: str(winner.decompressor()); |
58 | } |
59 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033236 |
Snippet name: | JEImageCompressionTest1 |
Eternal ID of this version: | #1033236/8 |
Text MD5: | e8f67ba168fe2aa0d16fe9e4f1ac97f6 |
Transpilation MD5: | 20d99603915ba9e227f0e1d6009805e6 |
Author: | stefan |
Category: | javax / recognition by compression |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-16 11:21:42 |
Source code size: | 1902 bytes / 59 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 306 / 483 |
Version history: | 7 change(s) |
Referenced in: | [show references] |