Warning: session_start(): open(/var/lib/php/sessions/sess_vsgq5c84e6bg7hmq5lvq22epav, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass G22ShapeCollectorPanel is Swingable {
settable G22Utils g22utils;
settable bool qoiAlways;
AnalyzedImage completedImage;
new MouseInComponentMonitor mouseMonitor;
PicturesByMD5 pics;
JMaxSpeedAnimation anim;
JCheckBox cbOn = jcheckbox("On", true);
JCheckBox cbFreezeOnHover = jcheckbox("Freeze on hover", true);
JSpinner colorsSpinner = jListSpinner(dropFirst(firstNCubes(16)));
JSpinner blurSpinner = jSpinner(0, 0, 99);
JLabel lblStats = rightAlignedLabel();
class AnalyzedImage {
new G22DataWrangler wrangler;
BufferedImage inputImage() {
ret wrangler.inputImage;
}
simplyCached byte[] qoiData() {
ret g22utils.timeFunction("QOI compress",
-> toQOI(inputImage()));
}
simplyCached S qoiMD5() {
ret md5(qoiData());
}
void saveImage() {
pics.put(qoiMD5(), qoiData());
}
}
void init {
if (pics != null) ret;
pics = new PicturesByMD5(g22utils.projectFile("Images"));
pics.extension(".qoi");
looselyBindLiveValueToCheckBox(g22utils.liveProjectVar("Freeze on hover"), cbFreezeOnHover);
looselyBindLiveValueToSpinner(g22utils.liveProjectVar("colors"), colorsSpinner);
looselyBindLiveValueToSpinner(g22utils.liveProjectVar("blur"), blurSpinner);
}
BufferedImage nextInputImage() {
ret shootLeftScreenHalf();
}
BufferedImage nextFrame() {
if (!isChecked(cbOn)
|| isChecked(cbFreezeOnHover) && mouseMonitor!) {
sleepSeconds(0.1);
null;
}
var inputImage = nextInputImage();
new AnalyzedImage ai;
var wrangler = new G22DataWrangler;
wrangler.timings(g22utils.functionTimings());
wrangler.inputImage(inputImage);
wrangler.colors(intFromSpinner(colorsSpinner));
wrangler.blur(intFromSpinner(blurSpinner));
wrangler.stepUntilStage(wrangler.regionsStage);
g22utils.setTransientProjectVar("Last wrangler", wrangler);
L qoiInfo = !qoiAlways ? null : ll(
"QOI: " + str_toK(l(ai.qoiData())),
"Hash: " + takeFirst(3, ai.qoiMD5()),
"Saved: " + yesNo_short(pics.has(ai.qoiMD5)));
setText(lblStats, commaCombine(
anim.fps(),
nRegions(wrangler.regions),
qoiInfo
);
completedImage = ai;
ret toBufferedImage(wrangler.posterizedImage);
}
cachedVisualize {
init();
anim = new JMaxSpeedAnimation;
anim.renderFrame(l0 nextFrame);
mouseMonitor.init(anim.imageSurface());
ret northAndCenterWithMargins(
jCenteredSection(" Visual Controls ", vstackWithSpacing(
jcenteredline(cbOn, cbFreezeOnHover),
jcenteredline(
jCenteredSection("Colors", colorsSpinner),
jCenteredSection("Blur", blurSpinner)
))),
centerAndSouthWithMargin(
jCenteredSection(" What I See ", anim),
centerAndEastWithMargin(lblStats,
jThreadedButton("Save image", -> {
completedImage?.saveImage();
})))
);
}
}