Skip to content

Commit

Permalink
Clamp and Map Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BytingBulldogs3539 committed Jan 2, 2024
1 parent 0ad83c6 commit 4994ffc
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public void setExposure(double exposure) {
// Auto-exposure is active right now, don't set anything.
return;
}

// Map exposure from 0 to 100 (UI Values) to 0.1 to 100 since 0 in libcamera is auto exposure.
// 0.1 since it is the next lowest value available through the UI.
MathUtils.map(exposure, 0.0, 100.0, 0.1, 100);

// HACKS!
Expand All @@ -141,9 +144,13 @@ public void setExposure(double exposure) {
// For now, band-aid this by just not setting it lower than the "it breaks" limit
// is different depending on camera.
if (sensorModel == LibCameraJNI.SensorModel.OV9281) {
// Map and clamp exposure to 6 to 100 since setting exposure on ov9281 lower
// than 6 will crash libcamera at resolutions lower than max.
exposure = MathUtils.map(exposure, 0.1, 100.0, 6.0, 100);
exposure = MathUtil.clamp(exposure, 0.1, 100.0);
} else if (sensorModel == LibCameraJNI.SensorModel.OV5647) {
// Map and clamp exposure to 0.7 to 100 since setting exposure on ov5647 lower
// than 0.7 will crash libcamera at resolutions lower than max.
exposure = MathUtils.map(exposure, 0.1, 100.0, 0.7, 100);
exposure = MathUtil.clamp(exposure, 0.1, 100.0);
}
Expand All @@ -165,6 +172,8 @@ public void setBrightness(int brightness) {
public void setGain(int gain) {
lastGain = gain;

// Map and clamp gain to values between 1 and 10 (libcamera min and gain that just seems higher
// than ever needed) from 0 to 100 (UI values).
var success =
LibCameraJNI.setAnalogGain(
r_ptr, MathUtil.clamp(MathUtils.map(gain, 0.0, 100.0, 1.0, 10.0), 1.0, 10.0));
Expand Down

0 comments on commit 4994ffc

Please sign in to comment.