sclass JEImageCompressionTest2 { settable BufferedImage originalImage; settable BufferedImage scaledImage; settable BufferedImage restoredScaledImage; *() { this(screenshot()); } *(BufferedImage *originalImage) {} int rows = 20; int imgHeight = 200; replace m with matrix. Matrix matrix; long dataBytes, dataChars; Matrix> grid; LL flatGrid; JE_CompressEachElementIndividually strat; CompressionSearch_AnyType search; CompressionSearch_AnyType.Submission winner; S get() { // JavaX "null propagation" (handle null gracefully) if (originalImage == null) null; // Preprocess input image (scale to imgHeight) // [this step is not reversed] scaledImage = resizeImageToHeight(originalImage, imgHeight); // see image as matrix, calculate how big the matrix literal is // (dataBytes/dataChars) m = imageToMatrix(scaledImage); dataBytes = m.nCells()*4+2; dataChars = dataBytes*2 + l("lInt(\"\")"); print("Matrix ~ " + takeFirst_str(60, m)); print("Matrix literal ~ " + (m.nCells()*8)); // split matrix into cells grid = matrixToMNGrid_rows(m, rows); // flatten whole grid & each cell to 1D flatGrid = map matrixToList(matrixToList(grid)); search = jeCompressionSearch(flatGrid, dataChars); strat = new JE_CompressEachElementIndividually() .elementCompressionStrategy(-> new JE_RepElement) .onCompressionFail(ints -> javaObjectToIJavaExpr(ints); search.addStrategy(strat); runProbabilisticForNSeconds(5.0, search); winner = search.bestSubmission(); print(strat.stats()); if (winner != null) { //print("Hard result (score " + result.scoreRatio() + ")", result.checkUnder(hardJERegime()); print(winner); } ret winnerCode(); } S winnerCode() { ret winner?.decompressor_str(); } void restoreScaledImage { restoredScaledImage = matrixToImage(m); } }