Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add single exposure PiSP HDR mode #582

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/libcamera_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ void LibcameraApp::StartCamera()
controls_.set(controls::Saturation, options_->saturation);
if (!controls_.get(controls::Sharpness))
controls_.set(controls::Sharpness, options_->sharpness);
if (!controls_.get(controls::HdrMode) &&
(options_->hdr == "auto" || options_->hdr == "single-exp"))
controls_.set(controls::HdrMode, controls::HdrModeSingleExposure);

// AF Controls, where supported and not already set
if (!controls_.get(controls::AfMode) && camera_->controls().count(&controls::AfMode) > 0)
Expand Down
17 changes: 11 additions & 6 deletions core/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ bool Options::Parse(int argc, char *argv[])
shutter.set(shutter_);
flicker_period.set(flicker_period_);

// HDR control. Set this before opening or listing any cameras.
if (hdr != "off" && hdr != "single-exp" && hdr != "sensor" && hdr != "auto")
throw std::runtime_error("Invalid HDR option provided: " + hdr);

// HDR control. Set the sensor control before opening or listing any cameras.
// Currently this does not exist in libcamera, so go directly to V4L2
// XXX it's not obvious which v4l2-subdev to use for which camera!
{
bool en = (hdr == "auto" || hdr == "sensor");
bool ok = false;
for (int i = 0; i < 4 && !ok; i++)
{
Expand All @@ -159,12 +163,14 @@ bool Options::Parse(int argc, char *argv[])
if (fd < 0)
continue;

v4l2_control ctrl { V4L2_CID_WIDE_DYNAMIC_RANGE, hdr };
v4l2_control ctrl { V4L2_CID_WIDE_DYNAMIC_RANGE, en };
ok = !xioctl(fd, VIDIOC_S_CTRL, &ctrl);
close(fd);
}
if (hdr && !ok)
LOG_ERROR("WARNING: Unable to set HDR mode");
if (hdr == "sensor" && en && !ok)
LOG_ERROR("WARNING: Unable to set sensor HDR mode");
else if (hdr == "auto" && en && ok)
hdr = "sensor";
}

// We have to pass the tuning file name through an environment variable.
Expand Down Expand Up @@ -488,8 +494,7 @@ void Options::Print() const
<< afWindow_height << std::endl;
if (!lens_position_.empty())
std::cerr << " lens-position: " << lens_position_ << std::endl;
if (hdr)
std::cerr << " hdr: enabled" << hdr << std::endl;
std::cerr << " hdr: " << hdr << std::endl;
std::cerr << " mode: " << mode.ToString() << std::endl;
std::cerr << " viewfinder-mode: " << viewfinder_mode.ToString() << std::endl;
if (buffer_count > 0)
Expand Down
8 changes: 5 additions & 3 deletions core/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ struct Options
"Sets AfMetering to AfMeteringWindows an set region used, e.g. 0.25,0.25,0.5,0.5")
("lens-position", value<std::string>(&lens_position_)->default_value(""),
"Set the lens to a particular focus position, expressed as a reciprocal distance (0 moves the lens to infinity), or \"default\" for the hyperfocal distance")
("hdr", value<bool>(&hdr)->default_value(false)->implicit_value(true),
"Enable (1) or disable (0) High Dynamic Range, where supported")
("hdr", value<std::string>(&hdr)->default_value("off")->implicit_value("auto"),
"Enable High Dynamic Range, where supported. Available values are \"off\", \"auto\", "
"\"sensor\" for sensor HDR (e.g. for Camera Module 3), "
"\"single-exp\" for PiSP based single exposure multiframe HDR")
("metadata", value<std::string>(&metadata),
"Save captured image metadata to a file or \"-\" for stdout")
("metadata-format", value<std::string>(&metadata_format)->default_value("json"),
Expand Down Expand Up @@ -281,7 +283,7 @@ struct Options
bool af_on_capture;
std::string metadata;
std::string metadata_format;
bool hdr;
std::string hdr;
TimeVal<std::chrono::microseconds> flicker_period;
bool no_raw;

Expand Down
Loading