  
    auto [resized_buf, resized_u_buf, resized_v_buf] = get_yuv_buf(s->resized_buf, resized_width, resized_height);
    uint8_t *resized_y_buf = resized_buf;
    libyuv::FilterMode mode = libyuv::FilterModeEnum::kFilterBilinear;
    libyuv::I420Scale(cropped_y_buf, cropped_width,
                      cropped_u_buf, cropped_width/2,
                      cropped_v_buf, cropped_width/2,
                      cropped_width, cropped_height,
                      resized_y_buf, resized_width,
                      resized_u_buf, resized_width/2,
                      resized_v_buf, resized_width/2,
                      resized_width, resized_height,
                      mode);
  
    int yuv_buf_len = (MODEL_WIDTH/2) * (MODEL_HEIGHT/2) * 6; // Y|u|v -> y|y|y|y|u|v
    float *net_input_buf = get_buffer(s->net_input_buf, yuv_buf_len);
 
</s> remove   auto [resized_buf, resized_u_buf, resized_v_buf] = get_yuv_buf(s->resized_buf, resized_width, resized_height);
  uint8_t *resized_y_buf = resized_buf;
 </s> add   auto [resized_buf, resized_u, resized_v] = get_yuv_buf(s->resized_buf, resized_width, resized_height);
  uint8_t *resized_y = resized_buf; </s> remove     auto [premirror_cropped_y_buf, premirror_cropped_u_buf, premirror_cropped_v_buf] = get_yuv_buf(s->premirror_cropped_buf, cropped_width, cropped_height);
    for (int r = 0; r < cropped_height/2; r++) {
      memcpy(premirror_cropped_y_buf + (2*r)*cropped_width, raw_y_buf + (2*r + global_y_offset + crop_y_offset)*width + global_x_offset, cropped_width);
      memcpy(premirror_cropped_y_buf + (2*r+1)*cropped_width, raw_y_buf + (2*r + global_y_offset + crop_y_offset + 1)*width + global_x_offset, cropped_width);
      memcpy(premirror_cropped_u_buf + r*(cropped_width/2), raw_u_buf + (r + (global_y_offset + crop_y_offset)/2)*width/2 + global_x_offset/2, cropped_width/2);
      memcpy(premirror_cropped_v_buf + r*(cropped_width/2), raw_v_buf + (r + (global_y_offset + crop_y_offset)/2)*width/2 + global_x_offset/2, cropped_width/2);
    }
    libyuv::I420Mirror(premirror_cropped_y_buf, cropped_width,
                       premirror_cropped_u_buf, cropped_width/2,
                       premirror_cropped_v_buf, cropped_width/2,
                       cropped_y_buf, cropped_width,
                       cropped_u_buf, cropped_width/2,
                       cropped_v_buf, cropped_width/2,
                       cropped_width, cropped_height);
 </s> add     auto [mirror_y, mirror_u, mirror_v] = get_yuv_buf(s->premirror_cropped_buf, crop_rect.w, crop_rect.h);
    crop_yuv((uint8_t *)stream_buf, width, height, mirror_y, mirror_u, mirror_v, crop_rect);
    libyuv::I420Mirror(mirror_y, crop_rect.w,
                       mirror_u, crop_rect.w / 2,
                       mirror_v, crop_rect.w / 2,
                       cropped_y, crop_rect.w,
                       cropped_u, crop_rect.w / 2,
                       cropped_v, crop_rect.w / 2,
                       crop_rect.w, crop_rect.h); </s> remove DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_buf, int width, int height) {
  uint8_t *raw_buf = (uint8_t*) stream_buf;
  uint8_t *raw_y_buf = raw_buf;
  uint8_t *raw_u_buf = raw_y_buf + (width * height);
  uint8_t *raw_v_buf = raw_u_buf + ((width/2) * (height/2));
 </s> add struct Rect {int x, y, w, h;};
void crop_yuv(uint8_t *raw, int width, int height, uint8_t *y, uint8_t *u, uint8_t *v, const Rect &rect) {
  uint8_t *raw_y = raw;
  uint8_t *raw_u = raw_y + (width * height);
  uint8_t *raw_v = raw_u + ((width / 2) * (height / 2));
  for (int r = 0; r < rect.h / 2; r++) {
    memcpy(y + 2 * r * rect.w, raw_y + (2 * r + rect.y) * width + rect.x, rect.w);
    memcpy(y + (2 * r + 1) * rect.w, raw_y + (2 * r + rect.y + 1) * width + rect.x, rect.w);
    memcpy(u + r * (rect.w / 2), raw_u + (r + (rect.y / 2)) * width / 2 + (rect.x / 2), rect.w / 2);
    memcpy(v + r * (rect.w / 2), raw_v + (r + (rect.y / 2)) * width / 2 + (rect.x / 2), rect.w / 2);
  }
} </s> remove   const int cropped_width = height/2;
  const int cropped_height = height;
  const int global_x_offset = 0;
  const int global_y_offset = 0;
  const int crop_x_offset = width - cropped_width;
  const int crop_y_offset = 0;
 </s> add   Rect crop_rect = {0, 0, height / 2, height};
  if (!s->is_rhd) {
    crop_rect.x += width - crop_rect.w;
  } </s> remove   auto [cropped_y_buf, cropped_u_buf, cropped_v_buf] = get_yuv_buf(s->cropped_buf, cropped_width, cropped_height);
 </s> add   auto [cropped_y, cropped_u, cropped_v] = get_yuv_buf(s->cropped_buf, crop_rect.w, crop_rect.h);
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  
    auto [resized_buf, resized_u_buf, resized_v_buf] = get_yuv_buf(s->resized_buf, resized_width, resized_height);
    uint8_t *resized_y_buf = resized_buf;
    libyuv::FilterMode mode = libyuv::FilterModeEnum::kFilterBilinear;
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
  libyuv::I420Scale(cropped_y, crop_rect.w,
                    cropped_u, crop_rect.w / 2,
                    cropped_v, crop_rect.w / 2,
                    crop_rect.w, crop_rect.h,
                    resized_y, resized_width,
                    resized_u, resized_width / 2,
                    resized_v, resized_width / 2,
                      resized_width, resized_height,
                      mode);
  
    int yuv_buf_len = (MODEL_WIDTH/2) * (MODEL_HEIGHT/2) * 6; // Y|u|v -> y|y|y|y|u|v
    float *net_input_buf = get_buffer(s->net_input_buf, yuv_buf_len);
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
 dmoniitoring: new function crop_yuv (#20344)

* crop_yuv

* shorten variables name

* space 
selfdrive/modeld/models/dmonitoring.cc