diff --git a/system/camerad/sensors/ar0231.cc b/system/camerad/sensors/ar0231.cc index a107a6e1b9..e4ef3af404 100644 --- a/system/camerad/sensors/ar0231.cc +++ b/system/camerad/sensors/ar0231.cc @@ -126,8 +126,8 @@ AR0231::AR0231() { 0x00000fbc, 0x000000bb, 0x00000009, 0x00000fb6, 0x00000fe0, 0x000000ea, }; - for (int i = 0; i < 64; i++) { - float fx = i / 63.0; + for (int i = 0; i < 65; i++) { + float fx = i / 64.0; const float gamma_k = 0.75; const float gamma_b = 0.125; const float mp = 0.01; // ideally midpoint should be adaptive @@ -138,6 +138,7 @@ AR0231::AR0231() { ((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)); } + prepare_gamma_lut(); linearization_lut = { 0x02000000, 0x02000000, 0x02000000, 0x02000000, 0x020007ff, 0x020007ff, 0x020007ff, 0x020007ff, diff --git a/system/camerad/sensors/os04c10.cc b/system/camerad/sensors/os04c10.cc index 08530989fe..53ac37f08a 100644 --- a/system/camerad/sensors/os04c10.cc +++ b/system/camerad/sensors/os04c10.cc @@ -68,10 +68,11 @@ OS04C10::OS04C10() { 0x00000fa7, 0x000000d9, 0x00001000, 0x00000fca, 0x00000fef, 0x000000c7, }; - for (int i = 0; i < 64; i++) { - float fx = i / 63.0; + for (int i = 0; i < 65; i++) { + float fx = i / 64.0; gamma_lut_rgb.push_back((uint32_t)(pow(fx, 0.7)*1023.0 + 0.5)); } + prepare_gamma_lut(); linearization_lut = { 0x02000000, 0x02000000, 0x02000000, 0x02000000, 0x020007ff, 0x020007ff, 0x020007ff, 0x020007ff, diff --git a/system/camerad/sensors/ox03c10.cc b/system/camerad/sensors/ox03c10.cc index 16ab0a65bc..19742661b1 100644 --- a/system/camerad/sensors/ox03c10.cc +++ b/system/camerad/sensors/ox03c10.cc @@ -70,11 +70,12 @@ OX03C10::OX03C10() { 0x00000fcc, 0x000000b9, 0x00000ffb, 0x00000fc2, 0x00000ff6, 0x000000c9, }; - for (int i = 0; i < 64; i++) { - float fx = i / 63.0; + for (int i = 0; i < 65; i++) { + float fx = i / 64.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)); } + prepare_gamma_lut(); linearization_lut = { 0x00200000, 0x00200000, 0x00200000, 0x00200000, 0x00404080, 0x00404080, 0x00404080, 0x00404080, diff --git a/system/camerad/sensors/sensor.h b/system/camerad/sensors/sensor.h index d94cd57c8d..dc2aadfe13 100644 --- a/system/camerad/sensors/sensor.h +++ b/system/camerad/sensors/sensor.h @@ -72,6 +72,12 @@ public: uint32_t black_level; std::vector color_correct_matrix; // 3x3 std::vector gamma_lut_rgb; // gamma LUTs are length 64 * sizeof(uint32_t); same for r/g/b here + void prepare_gamma_lut() { + for (int i = 0; i < 64; i++) { + gamma_lut_rgb[i] |= ((uint32_t)(gamma_lut_rgb[i+1] - gamma_lut_rgb[i]) << 10); + } + gamma_lut_rgb.pop_back(); + } std::vector linearization_lut; // length 288 std::vector linearization_pts; // length 4 std::vector vignetting_lut; // 2x length 884