/** @brief Convert a frame from YUYV to BGR * @ingroup frame * * @param in YUYV frame * @param out BGR frame */ uvc_error_t uvc_yuyv2bgr(uvc_frame_t *in, uvc_frame_t *out) { if (in->frame_format != UVC_FRAME_FORMAT_YUYV) return UVC_ERROR_INVALID_PARAM; if (uvc_ensure_frame_size(out, in->width * in->height * 3) < 0) return UVC_ERROR_NO_MEM; out->width = in->width; out->height = in->height; out->frame_format = UVC_FRAME_FORMAT_BGR; out->step = in->width * 3; out->sequence = in->sequence; out->capture_time = in->capture_time; out->source = in->source; uint8_t *pyuv = static_cast<uint8_t *>(in->data); uint8_t *pbgr = static_cast<uint8_t *>(out->data); uint8_t *pbgr_end = pbgr + out->data_bytes; while (pbgr < pbgr_end) { IYUYV2BGR_8(pyuv, pbgr); pbgr += 3 * 8; pyuv += 2 * 8; } return UVC_SUCCESS; }
/** @brief Convert a frame from YUYV to BGR * @ingroup frame * * @param in YUYV frame * @param out BGR frame */ uvc_error_t uvc_yuyv2bgr(uvc_frame_t *in, uvc_frame_t *out) { size_t need_bytes; if (in->color_format != UVC_COLOR_FORMAT_YUYV) return UVC_ERROR_INVALID_PARAM; out->width = in->width; out->height = in->height; out->color_format = UVC_COLOR_FORMAT_BGR; out->step = in->width * 3; out->sequence = in->sequence; out->capture_time = in->capture_time; out->source = in->source; need_bytes = out->step * out->height; if (!out->data || out->data_bytes != need_bytes) { out->data_bytes = out->step * out->height; out->data = realloc(out->data, out->data_bytes); } if (!out->data) return UVC_ERROR_NO_MEM; uint8_t *pyuv = in->data; uint8_t *pbgr = out->data; uint8_t *pbgr_end = pbgr + out->data_bytes; while (pbgr < pbgr_end) { IYUYV2BGR_8(pyuv, pbgr); pbgr += 3 * 8; pyuv += 2 * 8; } return UVC_SUCCESS; }