Bomb Bloke, on 15 November 2017 - 04:17 AM, said:
File file = new File(fileName); BufferedImage image = ImageIO.read(file); Files.deleteIfExists(Paths.get(outputName)); FileOutputStream fileOut = new FileOutputStream(outputName); BufferedOutputStream writer = new BufferedOutputStream(fileOut); writer.write(1); //1 Volume (Future Implementation) writer.write(image.getHeight() & 255); writer.write((image.getHeight() >> 8) & 255); writer.write(image.getWidth() & 255); writer.write((image.getWidth() >> 8) & 255); int[][] lengths = new int[image.getHeight()][image.getWidth()]; for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int leng = 1; while (x + leng < image.getWidth() && image.getRGB(x, y) == image.getRGB(x + leng, y)) { leng++; } lengths[y][x] = leng; x += leng - 1; } } //Scan Left to right; Up to Down for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int clr = image.getRGB(x, y); int red = (clr & 0x00ff0000) >> 16; int green = (clr & 0x0000ff00) >> 8; int blue = clr & 0x000000ff; int alpha = (clr & 0xff000000) >>> 24; writer.write(lengths[y][x] & 255); writer.write((lengths[y][x] >> 8) & 255); writer.write(red); writer.write(green); writer.write(blue); writer.write(alpha); } }And the Lua:
local fileName = "input" -- Glasses Bridge Side local side = "top" local g = peripheral.wrap(side) local lastTime = os.clock() local queueEvent = os.queueEvent local pullEvent = os.pullEvent local myEvent local addBox = g.addBox local sync = g.sync local function b(x,y,leng,hex,opacity) addBox(x,y,leng,1,hex,opacity) end g.clear() local input = fs.open(fileName, "rb") local read = input.read volumes = read() local height = read() + read() * 256 local width = read() + read() * 256 local heighty local widthy for heighty=0, height-1 do for widthy=0, width-1 do --local r,g,b,a = input.read(),input.read(),input.read(),input.read() b(widthy,heighty,read() + read() * 256,((read()*65536)+(read()*256))+read(),read()*0.00392156863) myEvent = tostring({}) queueEvent(myEvent) pullEvent(myEvent) end end print("T: "..os.clock()-lastTime) --Takes 53.3 seconds using a moderately intensive image input.close() g.sync()My only issue now is that it is still super slow. I skimmed through this handy guide and took anything that could apply to JLua but it still isn't that quick. Is it even possible to go faster?