| 24 | |
| 25 | /* |
| 26 | Class to save out a canvas to a directory of .jpgs |
| 27 | */ |
| 28 | public class SaverFBO { |
| 29 | |
| 30 | private final int numWorkers; |
| 31 | |
| 32 | public final int width; |
| 33 | public final int height; |
| 34 | |
| 35 | private final ExecutorService pool; |
| 36 | |
| 37 | String prefix; |
| 38 | private Supplier<FBO> fbo; |
| 39 | |
| 40 | public SaverFBO(int width, int height, int numWorkers, String prefix, Supplier<FBO> fbo) { |
| 41 | this.width = width; |
| 42 | this.height = height; |
| 43 | this.numWorkers = numWorkers; |
| 44 | this.prefix = prefix; |
| 45 | this.fbo = fbo; |
| 46 | |
| 47 | pool = Executors.newCachedThreadPool(); |
| 48 | } |
| 49 | |
| 50 | public SaverFBO(int width, int height, int numWorkers, String prefix, FBO fbo) { |
| 51 | this(width, height, numWorkers, prefix, () -> fbo); |
| 52 | } |
| 53 | |
| 54 | List<FutureTask<Pair<ByteBuffer, ByteBuffer>>> workers = new ArrayList<>(); |
| 55 | |
| 56 | public int frameNumber = 0; |
| 57 | |
| 58 | @HiddenInAutocomplete |
| 59 | boolean on = false; |
| 60 | @HiddenInAutocomplete |
| 61 | boolean drip = false; |
| 62 | |
| 63 | private String lastFilename; |
| 64 | |
| 65 | |
| 66 | @HiddenInAutocomplete |
| 67 | public void setOn(boolean on) { |
| 68 | this.on = on; |
| 69 | drip = false; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | public SaverFBO setPrefix(String prefix) { |
| 74 | this.prefix = prefix; |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * call to start streaming jpgs out to disk |
| 80 | */ |
| 81 | public String start() { |
| 82 | setOn(true); |
| 83 | return "Saving to '" + prefix + "'"; |