Libraryless. Click here for Pure Java version (17569L/113K).
1 | sclass JEImageCompressionTest2 { |
2 | settable BufferedImage originalImage; |
3 | |
4 | settable BufferedImage scaledImage; |
5 | settable BufferedImage restoredScaledImage; |
6 | |
7 | *() { this(screenshot()); } |
8 | *(BufferedImage *originalImage) {} |
9 | |
10 | int rows = 20; |
11 | int imgHeight = 200; |
12 | |
13 | replace m with matrix. |
14 | |
15 | Matrix<Int> matrix; |
16 | long dataBytes, dataChars; |
17 | Matrix<Matrix<Int>> grid; |
18 | LL<Int> flatGrid; |
19 | |
20 | JE_CompressEachElementIndividually<LInt> strat; |
21 | CompressionSearch_AnyType<IJavaExpr, LLInt> search; |
22 | CompressionSearch_AnyType<IJavaExpr, LLInt>.Submission winner; |
23 | |
24 | S get() { |
25 | // JavaX "null propagation" (handle null gracefully) |
26 | |
27 | if (originalImage == null) null; |
28 | |
29 | // Preprocess input image (scale to imgHeight) |
30 | // [this step is not reversed] |
31 | |
32 | scaledImage = resizeImageToHeight(originalImage, imgHeight); |
33 | |
34 | // see image as matrix, calculate how big the matrix literal is |
35 | // (dataBytes/dataChars) |
36 | |
37 | m = imageToMatrix(scaledImage); |
38 | dataBytes = m.nCells()*4+2; |
39 | dataChars = dataBytes*2 + l("lInt(\"\")"); |
40 | |
41 | print("Matrix ~ " + takeFirst_str(60, m)); |
42 | print("Matrix literal ~ " + (m.nCells()*8)); |
43 | |
44 | // split matrix into cells |
45 | |
46 | grid = matrixToMNGrid_rows(m, rows); |
47 | |
48 | // flatten whole grid & each cell to 1D |
49 | flatGrid = map matrixToList(matrixToList(grid)); |
50 | |
51 | search = jeCompressionSearch(flatGrid, dataChars); |
52 | strat = new JE_CompressEachElementIndividually<LInt>() |
53 | .elementCompressionStrategy(-> new JE_RepElement) |
54 | .onCompressionFail(ints -> javaObjectToIJavaExpr(ints); |
55 | |
56 | search.addStrategy(strat); |
57 | |
58 | runProbabilisticForNSeconds(5.0, search); |
59 | winner = search.bestSubmission(); |
60 | print(strat.stats()); |
61 | if (winner != null) { |
62 | //print("Hard result (score " + result.scoreRatio() + ")", result.checkUnder(hardJERegime()); |
63 | print(winner); |
64 | } |
65 | ret winnerCode(); |
66 | } |
67 | |
68 | S winnerCode() { |
69 | ret winner?.decompressor_str(); |
70 | } |
71 | |
72 | void restoreScaledImage { |
73 | restoredScaledImage = matrixToImage(m); |
74 | } |
75 | } |
Began life as a copy of #1033236
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033242 |
Snippet name: | JEImageCompressionTest2 [dev.] |
Eternal ID of this version: | #1033242/7 |
Text MD5: | 8b7f63a493be862a0be4794fb05292ec |
Transpilation MD5: | 8d36b5605c0025208a57c677b1164a0b |
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-22 23:23:54 |
Source code size: | 2140 bytes / 75 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 149 / 214 |
Version history: | 6 change(s) |
Referenced in: | [show references] |