srecord noeq GridCodec1(BufferedImage stage0_image) is JavaCodec { settable int rows = 20; static GridCodec1 demo() { ret GridCodec1(defaultScreenshot()); } // interim data & searches Matrix stage1_matrix; long dataBytes, dataChars; Matrix> stage2_grid; JE_CompressEachElementIndividually strat; JECompressionSearch search; JECompressionSearch forward() { assertNotNull(stage0_image); var m = stage1_matrix = imageToMatrix(stage0_image); dataBytes = m.nCells()*4+2; dataChars = dataBytes*2 + l("lInt(\"\")"); print("Matrix ~ " + shorten_str(60, m)); print("Trivial comp ~ " + (m.nCells()*8)); stage2_grid = matrixToMNGrid_rows(m, rows); // list of lists LL stage3_cells = matrixOfMatricesToListOfLists(stage2_grid); search = jeCompressionSearch(stage3_cells, dataChars); strat = new JE_CompressEachElementIndividually() .elementCompressionStrategy(-> new JE_RepElement) .onCompressionFail(ints -> javaObjectToIJavaExpr(ints); search.addStrategy(strat); ret search; } S stats() { ret strat?.stats(); } JECompressionSearch.Submission winner() { ret search?.bestSubmission(); } IJavaExpr> winnerCodeWithoutPostProcessing() { ret winner()?.decompressor(); } IJavaExpr winnerCode() { var innerWinner = winnerCodeWithoutPostProcessing(); if (innerWinner == null) null; L cellWidths = lambdaMapMethod getWidth(rowToList(stage2_grid, 0)); L cellHeights = lambdaMapMethod getHeight(colToList(stage2_grid, 0)); ret new IJavaExpr { public IJavaExpr unpack() { ret FunctionCall gridLOLToImage(toJava(cellWidths), toJava(cellHeights), innerWinner); } public BufferedImage quickEval() { ret gridLOLToImage(cellWidths, cellHeights, innerWinner); } }; } BufferedImage renderCellsLinearly() { ret mergeBufferedImagesHorizontally( map intMatrixToImage(matrixToList(stage2_grid))); } }