diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 2aab416aad..5a8e57894d 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -22,6 +22,7 @@ #include "common/params.h" #include "common/swaglog.h" #include "common/util.h" +#include "modeldata.h" #include "imgproc/utils.h" static cl_program build_debayer_program(cl_device_id device_id, cl_context context, const CameraInfo *ci, const CameraBuf *b, const CameraState *s) { @@ -69,16 +70,8 @@ void CameraBuf::init(cl_device_id device_id, cl_context context, CameraState *s, rgb_width = ci->frame_width / 2; rgb_height = ci->frame_height / 2; } - float db_s = 0.5; -#else - float db_s = 1.0; #endif - const mat3 transform = (mat3){{ - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0 - }}; - yuv_transform = ci->bayer ? transform_scale_buffer(transform, db_s) : transform; + yuv_transform = get_model_yuv_transform(ci->bayer); vipc_server->create_buffers(rgb_type, UI_BUF_COUNT, true, rgb_width, rgb_height); rgb_stride = vipc_server->get_buffer(rgb_type)->stride; diff --git a/selfdrive/common/modeldata.h b/selfdrive/common/modeldata.h index 826f2089c4..fbbd9ce46c 100644 --- a/selfdrive/common/modeldata.h +++ b/selfdrive/common/modeldata.h @@ -34,5 +34,19 @@ const mat3 fcam_intrinsic_matrix = (mat3){{ }}; #endif +static inline mat3 get_model_yuv_transform(bool bayer = true) { +#ifndef QCOM2 + float db_s = 0.5; // debayering does a 2x downscale +#else + float db_s = 1.0; +#endif + const mat3 transform = (mat3){{ + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0 + }}; + return bayer ? transform_scale_buffer(transform, db_s) : transform; +} + #endif diff --git a/selfdrive/modeld/modeld.cc b/selfdrive/modeld/modeld.cc index 64d32bb7b8..83d0dec131 100644 --- a/selfdrive/modeld/modeld.cc +++ b/selfdrive/modeld/modeld.cc @@ -37,17 +37,7 @@ void* live_thread(void *arg) { -1.84808520e-20, 9.00738606e-04,-4.28751576e-02; Eigen::Matrix fcam_intrinsics = Eigen::Matrix(fcam_intrinsic_matrix.v); -#ifndef QCOM2 - float db_s = 0.5; // debayering does a 2x downscale -#else - float db_s = 1.0; -#endif - - mat3 yuv_transform = transform_scale_buffer((mat3){{ - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0, - }}, db_s); + const mat3 yuv_transform = get_model_yuv_transform(); while (!do_exit) { if (sm.update(100) > 0){