diff --git a/system/camerad/cameras/camera_common.cc b/system/camerad/cameras/camera_common.cc index 6945c89ecf..d2e3f6739a 100644 --- a/system/camerad/cameras/camera_common.cc +++ b/system/camerad/cameras/camera_common.cc @@ -27,7 +27,7 @@ public: "-cl-fast-relaxed-math -cl-denorms-are-zero " "-DFRAME_WIDTH=%d -DFRAME_HEIGHT=%d -DFRAME_STRIDE=%d -DFRAME_OFFSET=%d " "-DRGB_WIDTH=%d -DRGB_HEIGHT=%d -DYUV_STRIDE=%d -DUV_OFFSET=%d " - "-DIS_OX=%d -DIS_OS=%d -DIS_10BIT -DIS_BGGR=%d -DCAM_NUM=%d%s", + "-DIS_OX=%d -DIS_OS=%d -DIS_10BIT -DIS_HDR -DIS_BGGR=%d -DCAM_NUM=%d%s", ci->frame_width, ci->frame_height, ci->frame_stride * 2, ci->frame_offset, b->rgb_width, b->rgb_height, buf_width, uv_offset, ci->image_sensor == cereal::FrameData::ImageSensor::OX03C10, @@ -42,7 +42,7 @@ public: } void queue(cl_command_queue q, VisionBuf cam_buff, cl_mem cam_buf_cl, cl_mem buf_cl, int width, int height, cl_event *debayer_event, bool todump) { - if (todump && false) { + if (todump && 0) { uint8_t *cam_buf = (uint8_t *)cam_buff.addr; printf("queueing buf %zu \n", cam_buff.len); FILE *dump_raw_file = fopen("/tmp/os.raw", "wb"); diff --git a/system/camerad/cameras/real_debayer.cl b/system/camerad/cameras/real_debayer.cl index 3e16ca83c8..72aff61f84 100644 --- a/system/camerad/cameras/real_debayer.cl +++ b/system/camerad/cameras/real_debayer.cl @@ -1,6 +1,6 @@ #define UV_WIDTH RGB_WIDTH / 2 #define UV_HEIGHT RGB_HEIGHT / 2 -#define HDR_OFFSET 20 +#define HDR_OFFSET 12 #define RGB_TO_Y(r, g, b) ((((mul24(b, 13) + mul24(g, 65) + mul24(r, 33)) + 64) >> 7) + 16) #define RGB_TO_U(r, g, b) ((mul24(b, 56) - mul24(g, 37) - mul24(r, 19) + 0x8080) >> 8) @@ -26,7 +26,7 @@ float3 color_correct(float3 rgb) { #if IS_OX return -0.507089*exp(-12.54124638*x)+0.9655*powr(x,0.5)-0.472597*x+0.507089; #elif IS_OS - return powr(x,0.7); + return clamp(log(1+x*65536.0) * 28.8 - 65, 0.0, 255.0) / 255.0; #else // tone mapping params const float gamma_k = 0.75; @@ -138,15 +138,31 @@ float4 val4_from_210(uchar8 long_pvs, uchar long_ext, uchar8 short_pvs, uchar sh float4 pv; // 16-bits? - if (parsed_long > 1000) { - if (parsed_short <= 273) { - pv = (convert_float4(parsed_short) * 240.0 - 64.0) / (65536.0 - 64.0); - } else { - pv = 1.0; - } + if (parsed_long.s0 > 1022) { + pv.s0 = (convert_float(parsed_short.s0) * 300.0 - 64.0) / (65536.0 - 64.0); } else { - pv = (convert_float4(parsed_long) - 64.0) / (65536.0 - 64.0); + pv.s0 = (convert_float(parsed_long.s0) - 64.0) / (65536.0 - 64.0); } + + if (parsed_long.s1 > 1022) { + pv.s1 = (convert_float(parsed_short.s1) * 300.0 - 64.0) / (65536.0 - 64.0); + } else { + pv.s1 = (convert_float(parsed_long.s1) - 64.0) / (65536.0 - 64.0); + } + + if (parsed_long.s2 > 1022) { + pv.s2 = (convert_float(parsed_short.s2) * 300.0 - 64.0) / (65536.0 - 64.0); + } else { + pv.s2 = (convert_float(parsed_long.s2) - 64.0) / (65536.0 - 64.0); + } + + if (parsed_long.s3 > 1022) { + pv.s3 = (convert_float(parsed_short.s3) * 300.0 - 64.0) / (65536.0 - 64.0); + } else { + pv.s3 = (convert_float(parsed_long.s3) - 64.0) / (65536.0 - 64.0); + } + + return clamp(pv*gain, 0.0, 1.0); }