fix: enable Z loupe/zoom across modes, 1-30 timelapse FPS, and CM0-safe MP4 compile

This commit is contained in:
2026-11-19 20:28:35 -05:00
parent d0c0ac1029
commit 9359779afa
11 changed files with 239 additions and 100 deletions

View File

@@ -307,6 +307,15 @@ void test_config_defaults_roundtrip_and_corrupt_fallback() {
assert(loaded.ev == custom.ev);
assert(loaded.camera_transform == custom.camera_transform);
// Custom timelapse FPS (1..30) round-trips and out-of-range values clamp to [1, 30]
custom.timelapse_fps = 12;
assert(cz::save_config(custom));
assert(cz::load_config().timelapse_fps == 12);
write_bytes(env_cfg, "{ \"timelapse_fps\": 0 }");
assert(cz::load_config().timelapse_fps == 1);
write_bytes(env_cfg, "{ \"timelapse_fps\": 99 }");
assert(cz::load_config().timelapse_fps == 30);
// Corrupt JSON falls back gracefully to defaults without throwing
write_bytes(env_cfg, "{ \"theme\": \"light\", broken_json ");
const cz::AppConfig recovered = cz::load_config();

View File

@@ -310,23 +310,31 @@ void test_timelapse_compile_8mp_scaling_and_h264_fallback() {
const auto cmd_8mp_hw =
cz::TimelapseEngine::build_compile_command(paths, 24, "8mp", true);
assert(has_arg_pair(cmd_8mp_hw, "-vf", "scale=1440:1080:flags=lanczos"));
assert(has_arg_pair(cmd_8mp_hw, "-threads", "1"));
assert(has_arg_pair(cmd_8mp_hw, "-filter_threads", "1"));
assert(has_arg_pair(cmd_8mp_hw, "-vf", "scale=1024:768:flags=bilinear,setsar=1"));
assert(has_arg_pair(cmd_8mp_hw, "-c:v", "h264_v4l2m2m"));
assert(has_arg_pair(cmd_8mp_hw, "-num_output_buffers", "4"));
assert(has_arg_pair(cmd_8mp_hw, "-b:v", "5M"));
assert(has_arg_pair(cmd_8mp_hw, "-f", "mp4"));
assert(has_arg_pair(cmd_8mp_hw, "-movflags", "+faststart"));
assert(has_arg(cmd_8mp_hw, paths.mp4_tmp_path));
const auto cmd_2mp_sw =
cz::TimelapseEngine::build_compile_command(paths, 24, "2mp", false);
assert(!has_arg(cmd_2mp_sw, "-vf"));
cz::TimelapseEngine::build_compile_command(paths, 12, "2mp", false);
assert(has_arg_pair(cmd_2mp_sw, "-framerate", "12"));
assert(has_arg_pair(cmd_2mp_sw, "-vf", "scale=1024:768:flags=bilinear,setsar=1"));
assert(has_arg_pair(cmd_2mp_sw, "-c:v", "libx264"));
assert(has_arg_pair(cmd_2mp_sw, "-preset", "veryfast"));
assert(has_arg_pair(cmd_2mp_sw, "-crf", "22"));
assert(has_arg_pair(cmd_2mp_sw, "-threads", "2"));
assert(has_arg_pair(cmd_2mp_sw, "-preset", "ultrafast"));
assert(has_arg_pair(cmd_2mp_sw, "-crf", "23"));
assert(has_arg_pair(cmd_2mp_sw, "-x264-params",
"rc-lookahead=0:ref=1:bframes=0:threads=2:lookahead-threads=1:sync-lookahead=0"));
assert(has_arg_pair(cmd_2mp_sw, "-f", "mp4"));
const auto cmd_1080_hw =
cz::TimelapseEngine::build_compile_command(paths, 30, "1080p", true);
assert(!has_arg(cmd_1080_hw, "-vf"));
assert(has_arg_pair(cmd_1080_hw, "-vf", "scale=1280:720:flags=bilinear,setsar=1"));
assert(has_arg_pair(cmd_1080_hw, "-framerate", "30"));
// Generate 3 real JPEGs and compile with 8mp scaling (triggers h264_v4l2m2m -> libx264 fallback on macOS)
@@ -366,15 +374,15 @@ void test_timelapse_compile_8mp_scaling_and_h264_fallback() {
assert(!engine.state().compiling);
assert(engine.state().last_error.empty());
// Probe compiled MP4 via GalleryStore to verify 1440x1080 scaled output
// Probe compiled MP4 via GalleryStore to verify CM0-safe 1024x768 scaled output
cz::GalleryStore gallery;
assert(gallery.refresh(out_dir));
assert(gallery.items().size() == 1);
cz::GalleryItem item = gallery.items()[0];
assert(item.type == cz::GalleryItemType::Video);
assert(gallery.probe_video_meta(item));
assert(item.width == 1440);
assert(item.height == 1080);
assert(item.width == 1024);
assert(item.height == 768);
// Also test video-mode live capture + request_stop() + cancel_compile() preserving staging files
cz::SimCameraBackend sim;

View File

@@ -269,18 +269,27 @@ void test_photo_controls_zoom_loupe_filters_and_timer() {
ctrl.handle_key('5', cz::KeyCode::Char, now);
assert(ctrl.state().zoom == 1.0f);
// Loupe L toggles 2x viewfinder magnification without changing sensor zoom
// Loupe Z toggles 2x viewfinder magnification without changing sensor zoom;
// lowercase 'l' acts as Right (adjust_rail_setting(+1)) for hjkl navigation.
ctrl.handle_key('7', cz::KeyCode::Char, now);
assert(ctrl.state().zoom == 1.5f);
const int calls_before_loupe = spy->set_controls_calls;
ctrl.handle_key('l', cz::KeyCode::Char, now);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(ctrl.state().loupe_enabled);
assert(ctrl.state().zoom == 1.5f);
assert(spy->last_zoom == 1.5f);
assert(spy->set_controls_calls == calls_before_loupe);
ctrl.handle_key('L', cz::KeyCode::Char, now);
ctrl.handle_key('Z', cz::KeyCode::Char, now);
assert(!ctrl.state().loupe_enabled);
assert(ctrl.state().rail_cursor == 1);
assert(ctrl.state().config.ev == 0.0);
ctrl.handle_key('l', cz::KeyCode::Char, now);
assert(!ctrl.state().loupe_enabled);
assert(ctrl.state().config.ev == 0.5);
ctrl.handle_key('h', cz::KeyCode::Char, now);
assert(ctrl.state().config.ev == 0.0);
// F cycles through all 9 filters and wraps back to None
const cz::FilterId expected_filters[9] = {
cz::FilterId::BW, cz::FilterId::HiCon, cz::FilterId::Sepia,
@@ -461,6 +470,25 @@ void test_video_mode_locks_transitions_while_recording() {
assert(ctrl.state().config.ev == ev_before);
assert(cz::load_config(cfg_path).ev == ev_before);
// Idle Z toggles Loupe in Video mode too and renders distinctly
assert(!ctrl.state().loupe_enabled);
cz::PreviewFrame vid_live;
assert(ctrl.backend()->copy_latest_preview(0, vid_live));
cz::AppView vid_view;
vid_view.render(ctrl.state(), &vid_live, nullptr);
std::vector<uint32_t> vid_no_loupe(
vid_view.pixels(),
vid_view.pixels() + cz::AppView::kWidth * cz::AppView::kHeight);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(ctrl.state().loupe_enabled);
vid_view.render(ctrl.state(), &vid_live, nullptr);
std::vector<uint32_t> vid_with_loupe(
vid_view.pixels(),
vid_view.pixels() + cz::AppView::kWidth * cz::AppView::kHeight);
assert(vid_no_loupe != vid_with_loupe);
ctrl.handle_key('Z', cz::KeyCode::Char, now);
assert(!ctrl.state().loupe_enabled);
// Start recording with Enter
ctrl.handle_key(0, cz::KeyCode::Enter, now);
assert(ctrl.state().video_recording);
@@ -479,9 +507,13 @@ void test_video_mode_locks_transitions_while_recording() {
assert(!ctrl.should_quit());
}
// Zoom 5/7 still works live during recording
// Zoom 5/7 and Loupe Z still work live during recording
ctrl.handle_key('7', cz::KeyCode::Char, now);
assert(ctrl.state().zoom == 1.5f);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(ctrl.state().loupe_enabled);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(!ctrl.state().loupe_enabled);
now += 1500;
ctrl.tick(now);
@@ -818,19 +850,80 @@ void test_text_input_timelapse_custom_recovery_and_modal_renders() {
assert(ctrl.state().modal == cz::OverlayModal::TimelapseCustomInput);
ctrl.handle_key('1', cz::KeyCode::Char, now);
ctrl.handle_key('2', cz::KeyCode::Char, now);
assert(ctrl.state().tl_custom_interval_sec == 12);
ctrl.handle_key(0, cz::KeyCode::Down, now);
ctrl.handle_key(0, cz::KeyCode::Right, now); // 24 -> 30 fps
assert(ctrl.state().tl_custom_fps == 30);
ctrl.handle_key(0, cz::KeyCode::Down, now);
ctrl.handle_key(0, cz::KeyCode::Right, now); // manual -> shots
assert(ctrl.state().tl_custom_stop_mode == "shots");
view.render(ctrl.state(), &live, nullptr);
ctrl.handle_key(0, cz::KeyCode::Enter, now);
assert(ctrl.state().modal == cz::OverlayModal::None);
assert(ctrl.state().config.timelapse_interval_sec == 12);
assert(ctrl.state().config.timelapse_fps == 30);
assert(ctrl.state().config.timelapse_stop_mode == "shots");
assert(ctrl.state().tl_custom_interval_sec == 12);
ctrl.handle_key(0, cz::KeyCode::Down, now);
// Custom FPS supports +/-1 stepping AND direct 1..30 numeric typing
assert(ctrl.state().tl_custom_fps == 24);
ctrl.handle_key(0, cz::KeyCode::Right, now);
assert(ctrl.state().tl_custom_fps == 25);
ctrl.handle_key('h', cz::KeyCode::Char, now);
assert(ctrl.state().tl_custom_fps == 24);
ctrl.handle_key('1', cz::KeyCode::Char, now);
ctrl.handle_key('2', cz::KeyCode::Char, now);
assert(ctrl.state().tl_custom_fps == 12);
ctrl.handle_key(0, cz::KeyCode::Backspace, now);
assert(ctrl.state().tl_custom_fps == 1);
ctrl.handle_key(0, cz::KeyCode::Backspace, now);
ctrl.handle_key('3', cz::KeyCode::Char, now);
ctrl.handle_key('5', cz::KeyCode::Char, now);
assert(ctrl.state().tl_custom_fps == 30);
ctrl.handle_key(0, cz::KeyCode::Backspace, now);
ctrl.handle_key(0, cz::KeyCode::Backspace, now);
ctrl.handle_key('7', cz::KeyCode::Char, now);
assert(ctrl.state().tl_custom_fps == 7);
ctrl.handle_key(0, cz::KeyCode::Down, now);
ctrl.handle_key(0, cz::KeyCode::Right, now); // manual -> shots
assert(ctrl.state().tl_custom_stop_mode == "shots");
view.render(ctrl.state(), &live, nullptr);
ctrl.handle_key(0, cz::KeyCode::Enter, now);
assert(ctrl.state().modal == cz::OverlayModal::None);
assert(ctrl.state().config.timelapse_interval_sec == 12);
assert(ctrl.state().config.timelapse_fps == 7);
assert(cz::load_config(cfg_path).timelapse_fps == 7);
assert(ctrl.state().config.timelapse_stop_mode == "shots");
// Timelapse idle & active zoom (5/7) and Loupe (Z) work cleanly
assert(ctrl.state().zoom == 1.0f);
assert(!ctrl.state().loupe_enabled);
ctrl.handle_key('7', cz::KeyCode::Char, now);
assert(ctrl.state().zoom == 1.5f);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(ctrl.state().loupe_enabled);
view.render(ctrl.state(), &live, nullptr);
std::vector<uint32_t> tl_with_loupe(
view.pixels(), view.pixels() + cz::AppView::kWidth * cz::AppView::kHeight);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(!ctrl.state().loupe_enabled);
view.render(ctrl.state(), &live, nullptr);
std::vector<uint32_t> tl_no_loupe(
view.pixels(), view.pixels() + cz::AppView::kWidth * cz::AppView::kHeight);
assert(tl_with_loupe != tl_no_loupe);
// Also verify zoom & Loupe stay responsive while Timelapse is actively running
ctrl.handle_key(0, cz::KeyCode::Enter, now);
ctrl.tick(now);
assert(ctrl.state().timelapse.running);
ctrl.handle_key('7', cz::KeyCode::Char, now);
assert(ctrl.state().zoom == 2.0f);
ctrl.handle_key('5', cz::KeyCode::Char, now);
assert(ctrl.state().zoom == 1.5f);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(ctrl.state().loupe_enabled);
ctrl.handle_key('z', cz::KeyCode::Char, now);
assert(!ctrl.state().loupe_enabled);
ctrl.handle_key(0, cz::KeyCode::Esc, now);
assert(ctrl.state().modal == cz::OverlayModal::TimelapseStopConfirm);
ctrl.handle_key('y', cz::KeyCode::Char, now);
{
const auto dl =
std::chrono::steady_clock::now() + std::chrono::seconds(8);
while (ctrl.state().modal == cz::OverlayModal::TimelapseCompiling &&
std::chrono::steady_clock::now() < dl) {
std::this_thread::sleep_for(std::chrono::milliseconds(20));
now += 20;
ctrl.tick(now);
}
}
// Settings -> DirPicker -> [T] TextInput manual directory entry
ctrl.handle_key('s', cz::KeyCode::Char, now);