From b586e27166f0dc5bb749fba7ecb5670614b61b83 Mon Sep 17 00:00:00 2001 From: ZwX1616 Date: Tue, 22 Oct 2024 14:10:22 -0700 Subject: [PATCH] fill and clean up --- system/camerad/cameras/ife.h | 59 ------------------------------- system/camerad/cameras/spectra.cc | 6 ++-- system/camerad/sensors/ar0231.cc | 12 +++++++ system/camerad/sensors/os04c10.cc | 4 +++ system/camerad/sensors/ox03c10.cc | 6 ++-- system/camerad/sensors/sensor.h | 4 +-- 6 files changed, 23 insertions(+), 68 deletions(-) diff --git a/system/camerad/cameras/ife.h b/system/camerad/cameras/ife.h index eb426728495728..18fbfb00678342 100644 --- a/system/camerad/cameras/ife.h +++ b/system/camerad/cameras/ife.h @@ -178,19 +178,6 @@ int build_initial_config(uint8_t *dst, const SensorInfo *s, std::vectorcolor_correct_matrix); - dst += write_cont(dst, 0x794, { - 0x00000000, - }); - /* TODO - cdm_dmi_cmd_t 568 - .length = 511 - .reserved = 33 - .cmd = 11 - .addr = 0 - .DMIAddr = 3108 - .DMISel = 24 - */ - // gamma dst += write_cont(dst, 0x798, { 0x00000000, @@ -498,52 +485,6 @@ int build_first_update(uint8_t *dst) { 0x08000066, }); - dst += write_cont(dst, 0x794, { - 0x00000001, - }); - /* TODO - cdm_dmi_cmd_t 432 - .length = 511 - .reserved = 33 - .cmd = 11 - .addr = 832 - .DMIAddr = 3108 - .DMISel = 25 - */ - - /* - dst += write_cont(dst, 0x798, { - 0x00000007, - }); - */ - /* TODO - cdm_dmi_cmd_t 444 - .length = 255 - .reserved = 33 - .cmd = 10 - .addr = 5344 - .DMIAddr = 3108 - .DMISel = 27 - */ - /* TODO - cdm_dmi_cmd_t 444 - .length = 255 - .reserved = 33 - .cmd = 10 - .addr = 5344 - .DMIAddr = 3108 - .DMISel = 29 - */ - /* TODO - cdm_dmi_cmd_t 444 - .length = 255 - .reserved = 33 - .cmd = 10 - .addr = 5344 - .DMIAddr = 3108 - .DMISel = 31 - */ - dst += write_cont(dst, 0xd84, { 0x000004b7, 0x00000787, diff --git a/system/camerad/cameras/spectra.cc b/system/camerad/cameras/spectra.cc index df8e8578d61445..0504325c3a0916 100644 --- a/system/camerad/cameras/spectra.cc +++ b/system/camerad/cameras/spectra.cc @@ -857,9 +857,9 @@ void SpectraCamera::configISP() { ife_dmi.init(m, 64*sizeof(uint32_t), 0x20, CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE, m->device_iommu, m->cdm_iommu, 3); // 3 for RGB - memcpy(ife_dmi.ptr + ife_dmi.size*0, sensor->gamma_lut_r.data(), ife_dmi.size); - memcpy(ife_dmi.ptr + ife_dmi.size*1, sensor->gamma_lut_g.data(), ife_dmi.size); - memcpy(ife_dmi.ptr + ife_dmi.size*2, sensor->gamma_lut_b.data(), ife_dmi.size); + for (int i = 0; i < 3; i++) { + memcpy(ife_dmi.ptr + ife_dmi.size*i, sensor->gamma_lut_rgb.data(), ife_dmi.size); + } config_ife(0, 1, true); } diff --git a/system/camerad/sensors/ar0231.cc b/system/camerad/sensors/ar0231.cc index 3d7426664518c9..5b2b7445b109fc 100644 --- a/system/camerad/sensors/ar0231.cc +++ b/system/camerad/sensors/ar0231.cc @@ -124,6 +124,18 @@ AR0231::AR0231() { 0x00000fbc, 0x000000bb, 0x00000009, 0x00000fb6, 0x00000fe0, 0x000000ea, }; + for (int i = 0; i < 64; i++) { + float fx = i / 63.0; + const float gamma_k = 0.75; + const float gamma_b = 0.125; + const float mp = 0.01; // ideally midpoint should be adaptive + const float rk = 9 - 100*mp; + // poly approximation for s curve + fx = (fx > mp) ? + ((rk * (fx-mp) * (1-(gamma_k*mp+gamma_b)) * (1+1/(rk*(1-mp))) / (1+rk*(fx-mp))) + gamma_k*mp + gamma_b) : + ((rk * (fx-mp) * (gamma_k*mp+gamma_b) * (1+1/(rk*mp)) / (1-rk*(fx-mp))) + gamma_k*mp + gamma_b); + gamma_lut_rgb.push_back((uint32_t)(fx*1023.0 + 0.5)); + } } void AR0231::processRegisters(uint8_t *cur_buf, cereal::FrameData::Builder &framed) const { diff --git a/system/camerad/sensors/os04c10.cc b/system/camerad/sensors/os04c10.cc index dbdceb91893e4c..0ec891a4c0d5ab 100644 --- a/system/camerad/sensors/os04c10.cc +++ b/system/camerad/sensors/os04c10.cc @@ -68,6 +68,10 @@ OS04C10::OS04C10() { 0x00000fa7, 0x000000d9, 0x00001000, 0x00000fca, 0x00000fef, 0x000000c7, }; + for (int i = 0; i < 64; i++) { + float fx = i / 63.0; + gamma_lut_rgb.push_back((uint32_t)(pow(fx, 0.7)*1023.0 + 0.5)); + } } std::vector OS04C10::getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const { diff --git a/system/camerad/sensors/ox03c10.cc b/system/camerad/sensors/ox03c10.cc index 86257cf1d595b0..04184cc99b1396 100644 --- a/system/camerad/sensors/ox03c10.cc +++ b/system/camerad/sensors/ox03c10.cc @@ -69,9 +69,9 @@ OX03C10::OX03C10() { 0x00000fc2, 0x00000ff6, 0x000000c9, }; for (int i = 0; i < 64; i++) { - gamma_lut_r.push_back(0xaa); - gamma_lut_g.push_back(0xaa); - gamma_lut_b.push_back(0xaa); + float fx = i / 63.0; + fx = -0.507089*exp(-12.54124638*fx) + 0.9655*pow(fx, 0.5) - 0.472597*fx + 0.507089; + gamma_lut_rgb.push_back((uint32_t)(fx*1023.0 + 0.5)); } } diff --git a/system/camerad/sensors/sensor.h b/system/camerad/sensors/sensor.h index 2fb90d03c4625a..2dfb4d647b8d4a 100644 --- a/system/camerad/sensors/sensor.h +++ b/system/camerad/sensors/sensor.h @@ -69,9 +69,7 @@ class SensorInfo { // ISP image processing params uint32_t black_level; std::vector color_correct_matrix; // 3x3 - std::vector gamma_lut_r; // gamma LUTs are length 64 * sizeof(uint32_t) - std::vector gamma_lut_g; - std::vector gamma_lut_b; + std::vector gamma_lut_rgb; // gamma LUTs are length 64 * sizeof(uint32_t); same for r/g/b here }; class AR0231 : public SensorInfo {