Add NeoUI 240x320 UI SDK, migrate all GUI plugins, add Yabasic FFI wrapper and fix camera rotation
This commit is contained in:
1 parent
1f9138f0c6
commit
c137feee0e
59 files changed
+5932
-2128
No files matched your search
@@ -116,30 +116,31 @@ std::vector<PhotoEntry> listSavedPhotos() {
|
||||
void saveZoomedRgb24AsJpeg(const std::string& path,
|
||||
const uint8_t* src800x600,
|
||||
int zoomFactor) {
|
||||
if (zoomFactor <= 1) {
|
||||
saveRgb24AsJpeg(path, src800x600, kCamW, kCamH, 92);
|
||||
return;
|
||||
}
|
||||
// Rotate 90 degrees clockwise from raw 800x600 sensor into upright 600x800
|
||||
constexpr int kOutW = kCamH; // 600
|
||||
constexpr int kOutH = kCamW; // 800
|
||||
zoomFactor = std::clamp(zoomFactor, 1, 4);
|
||||
int cropW = kCamW / zoomFactor;
|
||||
int cropH = kCamH / zoomFactor;
|
||||
int startX = (kCamW - cropW) / 2;
|
||||
int startY = (kCamH - cropH) / 2;
|
||||
int cropRotW = kOutW / zoomFactor;
|
||||
int cropRotH = kOutH / zoomFactor;
|
||||
int startRotX = (kOutW - cropRotW) / 2;
|
||||
int startRotY = (kOutH - cropRotH) / 2;
|
||||
|
||||
std::vector<uint8_t> zoomed(kCamFrameBytes);
|
||||
for (int dy = 0; dy < kCamH; ++dy) {
|
||||
int sy = startY + (dy * cropH) / kCamH;
|
||||
const uint8_t* srow = src800x600 + static_cast<size_t>(sy) * kCamW * 3;
|
||||
uint8_t* drow = zoomed.data() + static_cast<size_t>(dy) * kCamW * 3;
|
||||
for (int dx = 0; dx < kCamW; ++dx) {
|
||||
int sx = startX + (dx * cropW) / kCamW;
|
||||
const uint8_t* px = srow + sx * 3;
|
||||
std::vector<uint8_t> rotated(kCamFrameBytes);
|
||||
for (int dy = 0; dy < kOutH; ++dy) {
|
||||
int rotY = std::clamp(startRotY + (dy * cropRotH) / kOutH, 0, kCamW - 1);
|
||||
int sx = rotY;
|
||||
uint8_t* drow = rotated.data() + static_cast<size_t>(dy) * kOutW * 3;
|
||||
for (int dx = 0; dx < kOutW; ++dx) {
|
||||
int rotX = std::clamp(startRotX + (dx * cropRotW) / kOutW, 0, kCamH - 1);
|
||||
int sy = (kCamH - 1) - rotX;
|
||||
const uint8_t* px =
|
||||
src800x600 + (static_cast<size_t>(sy) * kCamW + sx) * 3;
|
||||
drow[dx * 3 + 0] = px[0];
|
||||
drow[dx * 3 + 1] = px[1];
|
||||
drow[dx * 3 + 2] = px[2];
|
||||
}
|
||||
}
|
||||
saveRgb24AsJpeg(path, zoomed.data(), kCamW, kCamH, 92);
|
||||
saveRgb24AsJpeg(path, rotated.data(), kOutW, kOutH, 92);
|
||||
}
|
||||
|
||||
int runCameraApp(int argc, char** argv) {
|
||||
@@ -184,8 +185,8 @@ int runCameraApp(int argc, char** argv) {
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xcamera", "XCamera", "Camera")) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
if (vfPipe[0] >= 0) ::close(vfPipe[0]);
|
||||
if (vfPipe[1] >= 0) ::close(vfPipe[1]);
|
||||
@@ -193,40 +194,13 @@ int runCameraApp(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch {};
|
||||
char resName[] = "xcamera";
|
||||
char resClass[] = "XCamera";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "Camera");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
|
||||
DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PluginTheme pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PluginTheme& pt = neo.theme;
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
@@ -487,47 +461,13 @@ int runCameraApp(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
int tw = 0, th = 0;
|
||||
pango_layout_get_pixel_size(layout, &tw, &th);
|
||||
int dy = y + std::max(0, (h - th) / 2);
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
dy * PANGO_SCALE);
|
||||
return tw;
|
||||
return neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto drawSoftkeyBar = [&](const std::string& leftLabel,
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, centerLabel.c_str(),
|
||||
static_cast<int>(centerLabel.size()));
|
||||
int cw = 0, chh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
|
||||
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
|
||||
centerLabel);
|
||||
|
||||
pango_layout_set_width(layoutMain, -1);
|
||||
pango_layout_set_text(layoutMain, rightLabel.c_str(),
|
||||
static_cast<int>(rightLabel.size()));
|
||||
int rw = 0, rhh = 0;
|
||||
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
|
||||
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
|
||||
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
|
||||
};
|
||||
|
||||
auto drawUI = [&]() {
|
||||
|
||||
Reference in new issue
Block a user