bool CLVaImage::merge_multi_plane ( const VideoBufferInfo &video_info, CLImageDesc &cl_desc) { if (cl_desc.array_size <= 1) return true; switch (video_info.format) { case V4L2_PIX_FMT_NV12: cl_desc.height = video_info.aligned_height + video_info.height / 2; break; case XCAM_PIX_FMT_RGB48_planar: case XCAM_PIX_FMT_RGB24_planar: cl_desc.height = video_info.aligned_height * 3; break; case XCAM_PIX_FMT_SGRBG16_planar: case XCAM_PIX_FMT_SGRBG8_planar: cl_desc.height = video_info.aligned_height * 4; break; default: XCAM_LOG_WARNING ("CLVaImage unknow format(%s) plane change", xcam_fourcc_to_string(video_info.format)); return false; } cl_desc.array_size = 0; cl_desc.slice_pitch = 0; return true; }
bool CL3aImageProcessor::set_output_format (uint32_t fourcc) { switch (fourcc) { case XCAM_PIX_FMT_RGBA64: case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_BGR32: case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_XRGB32: _out_smaple_type = OutSampleRGB; break; case V4L2_PIX_FMT_NV12: _out_smaple_type = OutSampleYuv; break; default: XCAM_LOG_WARNING ( "cl 3a processor doesn't support output format:%s", xcam_fourcc_to_string(fourcc)); return false; } _output_fourcc = fourcc; return true; }
bool CL3aImageProcessor::set_output_format (uint32_t fourcc) { XCAM_FAIL_RETURN ( WARNING, V4L2_PIX_FMT_NV12 == fourcc, false, "cl 3a processor doesn't support output format: %s", xcam_fourcc_to_string (fourcc)); _output_fourcc = fourcc; return true; }
XCamReturn CLBayer2RGBImageHandler::prepare_buffer_pool_video_info ( const VideoBufferInfo &input, VideoBufferInfo &output) { bool format_inited = output.init (_output_format, input.width, input.height); XCAM_FAIL_RETURN ( WARNING, format_inited, XCAM_RETURN_ERROR_PARAM, "CL image handler(%s) ouput format(%s) unsupported", get_name (), xcam_fourcc_to_string (_output_format)); return XCAM_RETURN_NO_ERROR; }
bool CLBayer2RGBImageHandler::set_output_format (uint32_t fourcc) { XCAM_FAIL_RETURN ( WARNING, fourcc == XCAM_PIX_FMT_RGBA64 || fourcc == V4L2_PIX_FMT_RGB24 || fourcc == V4L2_PIX_FMT_XBGR32 || fourcc == V4L2_PIX_FMT_ABGR32 || V4L2_PIX_FMT_BGR32 || //fourcc == V4L2_PIX_FMT_RGB32 || fourcc == V4L2_PIX_FMT_ARGB32 || V4L2_PIX_FMT_XRGB32 || fourcc == V4L2_PIX_FMT_RGBA32, false, "CL image handler(%s) doesn't support format(%s) settings", get_name (), xcam_fourcc_to_string (fourcc)); _output_format = fourcc; return true; }
XCamReturn CLBayerBasicImageHandler::prepare_buffer_pool_video_info ( const VideoBufferInfo &input, VideoBufferInfo &output) { uint32_t format = XCAM_PIX_FMT_SGRBG16_planar; bool format_inited = output.init (format, input.width / 2 , input.height / 2); XCAM_FAIL_RETURN ( WARNING, format_inited, XCAM_RETURN_ERROR_PARAM, "CL image handler(%s) output format(%s) unsupported", get_name (), xcam_fourcc_to_string (format)); return XCAM_RETURN_NO_ERROR; }
XCamReturn V4l2Device::set_format (struct v4l2_format &format) { XCamReturn ret = XCAM_RETURN_NO_ERROR; XCAM_FAIL_RETURN (ERROR, !is_activated (), XCAM_RETURN_ERROR_PARAM, "Cannot set format to v4l2 device while it is active."); XCAM_FAIL_RETURN (ERROR, is_opened (), XCAM_RETURN_ERROR_FILE, "Cannot set format to v4l2 device while it is closed."); struct v4l2_format tmp_format = format; ret = pre_set_format (format); if (ret != XCAM_RETURN_NO_ERROR) { XCAM_LOG_WARNING ("device(%s) pre_set_format failed", XCAM_STR (_name)); return ret; } if (io_control (VIDIOC_S_FMT, &format) < 0) { if (errno == EBUSY) { // TODO log device name XCAM_LOG_ERROR("Video device is busy, fail to set format."); } else { // TODO log format details and errno XCAM_LOG_ERROR("Fail to set format: %s", strerror(errno)); } return XCAM_RETURN_ERROR_IOCTL; } if (tmp_format.fmt.pix.width != format.fmt.pix.width || tmp_format.fmt.pix.height != format.fmt.pix.height) { XCAM_LOG_ERROR ( "device(%s) set v4l2 format failed, supported format: width:%d, height:%d", XCAM_STR (_name), format.fmt.pix.width, format.fmt.pix.height); return XCAM_RETURN_ERROR_PARAM; } while (_fps_n && _fps_d) { struct v4l2_streamparm param; xcam_mem_clear (param); param.type = _capture_buf_type; if (io_control (VIDIOC_G_PARM, ¶m) < 0) { XCAM_LOG_WARNING ("device(%s) set framerate failed on VIDIOC_G_PARM but continue", XCAM_STR (_name)); break; } if (!(param.parm.capture.capability & V4L2_CAP_TIMEPERFRAME)) break; param.parm.capture.timeperframe.numerator = _fps_d; param.parm.capture.timeperframe.denominator = _fps_n; if (io_control (VIDIOC_S_PARM, ¶m) < 0) { XCAM_LOG_WARNING ("device(%s) set framerate failed on VIDIOC_S_PARM but continue", XCAM_STR (_name)); break; } _fps_n = param.parm.capture.timeperframe.denominator; _fps_d = param.parm.capture.timeperframe.numerator; XCAM_LOG_INFO ("device(%s) set framerate(%d/%d)", XCAM_STR (_name), _fps_n, _fps_d); // exit here, otherwise it is an infinite loop break; } ret = post_set_format (format); if (ret != XCAM_RETURN_NO_ERROR) { XCAM_LOG_WARNING ("device(%s) post_set_format failed", XCAM_STR (_name)); return ret; } _format = format; XCAM_LOG_INFO ( "device(%s) set format(w:%d, h:%d, pixelformat:%s, bytesperline:%d,image_size:%d)", XCAM_STR (_name), format.fmt.pix.width, format.fmt.pix.height, xcam_fourcc_to_string (format.fmt.pix.pixelformat), format.fmt.pix.bytesperline, format.fmt.pix.sizeimage); return XCAM_RETURN_NO_ERROR; }
bool CLImage::video_info_2_cl_image_desc ( const VideoBufferInfo & video_info, CLImageDesc &image_desc) { image_desc.width = video_info.width; image_desc.height = video_info.height; image_desc.array_size = 0; image_desc.row_pitch = video_info.strides[0]; XCAM_ASSERT (image_desc.row_pitch >= image_desc.width); image_desc.slice_pitch = 0; switch (video_info.format) { case XCAM_PIX_FMT_RGB48: //cl_image_info.fmt.image_channel_order = CL_RGB; //cl_image_info.fmt.image_channel_data_type = CL_UNORM_INT16; XCAM_LOG_WARNING ( "video_info to cl_image_info doesn't support XCAM_PIX_FMT_RGB48, maybe try XCAM_PIX_FMT_RGBA64 instread\n" " **** XCAM_PIX_FMT_RGB48 need check with cl implementation ****"); return false; break; case XCAM_PIX_FMT_RGBA64: image_desc.format.image_channel_order = CL_RGBA; image_desc.format.image_channel_data_type = CL_UNORM_INT16; break; case V4L2_PIX_FMT_RGB24: image_desc.format.image_channel_order = CL_RGB; image_desc.format.image_channel_data_type = CL_UNORM_INT8; break; case V4L2_PIX_FMT_RGB565: image_desc.format.image_channel_order = CL_RGB; image_desc.format.image_channel_data_type = CL_UNORM_SHORT_565; break; case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_BGR32: image_desc.format.image_channel_order = CL_BGRA; image_desc.format.image_channel_data_type = CL_UNORM_INT8; break; // cl doesn'tn support ARGB32 up to now, how about consider V4L2_PIX_FMT_RGBA32 case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_XRGB32: image_desc.format.image_channel_order = CL_ARGB; image_desc.format.image_channel_data_type = CL_UNORM_INT8; break; case V4L2_PIX_FMT_RGBA32: image_desc.format.image_channel_order = CL_RGBA; image_desc.format.image_channel_data_type = CL_UNORM_INT8; break; case V4L2_PIX_FMT_SBGGR10: case V4L2_PIX_FMT_SGBRG10: case V4L2_PIX_FMT_SGRBG10: case V4L2_PIX_FMT_SRGGB10: case V4L2_PIX_FMT_SBGGR12: case V4L2_PIX_FMT_SGBRG12: case V4L2_PIX_FMT_SGRBG12: case V4L2_PIX_FMT_SRGGB12: case V4L2_PIX_FMT_SBGGR16: case XCAM_PIX_FMT_SGRBG16: image_desc.format.image_channel_order = CL_R; image_desc.format.image_channel_data_type = CL_UNORM_INT16; break; case V4L2_PIX_FMT_SBGGR8: case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: case V4L2_PIX_FMT_SRGGB8: image_desc.format.image_channel_order = CL_R; image_desc.format.image_channel_data_type = CL_UNORM_INT8; break; case V4L2_PIX_FMT_NV12: image_desc.format.image_channel_order = CL_R; image_desc.format.image_channel_data_type = CL_UNORM_INT8; image_desc.array_size = 2; image_desc.slice_pitch = video_info.strides [0] * video_info.aligned_height; break; case V4L2_PIX_FMT_YUYV: image_desc.format.image_channel_order = CL_RGBA; image_desc.format.image_channel_data_type = CL_UNORM_INT8; image_desc.width /= 2; break; case XCAM_PIX_FMT_LAB: image_desc.format.image_channel_order = CL_R; image_desc.format.image_channel_data_type = CL_FLOAT; break; case XCAM_PIX_FMT_RGB48_planar: case XCAM_PIX_FMT_RGB24_planar: image_desc.format.image_channel_order = CL_RGBA; if (XCAM_PIX_FMT_RGB48_planar == video_info.format) image_desc.format.image_channel_data_type = CL_UNORM_INT16; else image_desc.format.image_channel_data_type = CL_UNORM_INT8; image_desc.width = video_info.aligned_width / 4; image_desc.array_size = 3; image_desc.slice_pitch = video_info.strides [0] * video_info.aligned_height; break; case XCAM_PIX_FMT_SGRBG16_planar: case XCAM_PIX_FMT_SGRBG8_planar: image_desc.format.image_channel_order = CL_RGBA; if (XCAM_PIX_FMT_SGRBG16_planar == video_info.format) image_desc.format.image_channel_data_type = CL_UNORM_INT16; else image_desc.format.image_channel_data_type = CL_UNORM_INT8; image_desc.width = video_info.aligned_width / 4; image_desc.array_size = 4; image_desc.slice_pitch = video_info.strides [0] * video_info.aligned_height; break; default: XCAM_LOG_WARNING ( "video_info to cl_image_info doesn't support format:%s", xcam_fourcc_to_string (video_info.format)); return false; } return true; }
bool VideoBufferInfo::init ( uint32_t format, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size) { uint32_t image_size = 0; XCAM_ASSERT (!aligned_width || aligned_width >= width); XCAM_ASSERT (!aligned_height || aligned_height >= height); if (!aligned_width) aligned_width = XCAM_ALIGN_UP (width, 4); if (!aligned_height) aligned_height = XCAM_ALIGN_UP (height, 2); this->format = format; this->width = width; this->height = height; this->aligned_width = aligned_width; this->aligned_height = aligned_height; switch (format) { case V4L2_PIX_FMT_NV12: this->color_bits = 8; this->components = 2; this->strides [0] = aligned_width; this->strides [1] = this->strides [0]; this->offsets [0] = 0; this->offsets [1] = this->offsets [0] + this->strides [0] * aligned_height; image_size = this->strides [0] * aligned_height + this->strides [1] * aligned_height / 2; break; case V4L2_PIX_FMT_YUYV: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_RGB565: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_RGB24: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width * 3; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; // memory order RGBA 8-8-8-8 case V4L2_PIX_FMT_RGBA32: // memory order: BGRA 8-8-8-8 case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_BGR32: // memory order: ARGB 8-8-8-8 case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_XRGB32: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width * 4; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case XCAM_PIX_FMT_RGB48: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 3 * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case XCAM_PIX_FMT_RGBA64: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 4 * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR8: case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: case V4L2_PIX_FMT_SRGGB8: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR10: case V4L2_PIX_FMT_SGBRG10: case V4L2_PIX_FMT_SGRBG10: case V4L2_PIX_FMT_SRGGB10: this->color_bits = 10; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR12: case V4L2_PIX_FMT_SGBRG12: case V4L2_PIX_FMT_SGRBG12: case V4L2_PIX_FMT_SRGGB12: this->color_bits = 12; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR16: case XCAM_PIX_FMT_SGRBG16: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case XCAM_PIX_FMT_LAB: this->color_bits = 32; this->components = 1; this->strides [0] = aligned_width * 3 * 4; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; default: XCAM_LOG_WARNING ("VideoBufferInfo init failed, unsupported format:%s", xcam_fourcc_to_string (format)); return false; } if (!size) this->size = image_size; else { XCAM_ASSERT (size >= image_size); this->size = size; } return true; }
uint32_t VideoBufferInfo::get_pixel_bytes (const uint32_t format) const { uint32_t bytes = 0; switch (format) { case V4L2_PIX_FMT_NV12: case V4L2_PIX_FMT_SBGGR8: case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: case V4L2_PIX_FMT_SRGGB8: bytes = 1; break; case V4L2_PIX_FMT_YUYV: case V4L2_PIX_FMT_RGB565: case V4L2_PIX_FMT_SBGGR10: case V4L2_PIX_FMT_SGBRG10: case V4L2_PIX_FMT_SGRBG10: case V4L2_PIX_FMT_SRGGB10: case V4L2_PIX_FMT_SBGGR12: case V4L2_PIX_FMT_SGBRG12: case V4L2_PIX_FMT_SGRBG12: case V4L2_PIX_FMT_SRGGB12: case V4L2_PIX_FMT_SBGGR16: case XCAM_PIX_FMT_SGRBG16: bytes = 2; break; case V4L2_PIX_FMT_RGB24: bytes = 3; break; case V4L2_PIX_FMT_RGBA32: case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_BGR32: case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_XRGB32: bytes = 4; break; case XCAM_PIX_FMT_RGB48: bytes = 3 * 2; break; case XCAM_PIX_FMT_RGBA64: bytes = 4 * 2; break; case XCAM_PIX_FMT_LAB: bytes = 3 * 4; break; default: XCAM_LOG_WARNING ("VideoBufferInfo get_pixel_bytes failed, unsupported format:%s", xcam_fourcc_to_string (format)); } return bytes; }
bool VideoBufferInfo::get_planar_info ( const uint32_t format, const uint32_t width, const uint32_t height, VideoBufferPlanarInfo &planar, const uint32_t index) const { switch (format) { case V4L2_PIX_FMT_SBGGR8: case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: case V4L2_PIX_FMT_SRGGB8: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 1; break; case V4L2_PIX_FMT_NV12: XCAM_ASSERT (index <= 2); if (index == 0) { planar.width = width; planar.height = height; planar.pixel_bytes = 1; } else if (index == 1) { planar.width = width; planar.height = height / 2; planar.pixel_bytes = 1; } break; case V4L2_PIX_FMT_YUYV: case V4L2_PIX_FMT_RGB565: case V4L2_PIX_FMT_SBGGR10: case V4L2_PIX_FMT_SGBRG10: case V4L2_PIX_FMT_SGRBG10: case V4L2_PIX_FMT_SRGGB10: case V4L2_PIX_FMT_SBGGR12: case V4L2_PIX_FMT_SGBRG12: case V4L2_PIX_FMT_SGRBG12: case V4L2_PIX_FMT_SRGGB12: case V4L2_PIX_FMT_SBGGR16: case XCAM_PIX_FMT_SGRBG16: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 2; break; case V4L2_PIX_FMT_RGB24: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 3; break; case V4L2_PIX_FMT_RGBA32: case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_BGR32: case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_XRGB32: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 4; break; case XCAM_PIX_FMT_RGB48: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 3 * 2; break; case XCAM_PIX_FMT_RGBA64: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 4 * 2; break; case XCAM_PIX_FMT_LAB: XCAM_ASSERT (index <= 0); planar.width = width; planar.height = height; planar.pixel_bytes = 3 * 4; break; default: XCAM_LOG_WARNING ("VideoBufferInfo get_planar_info failed, unsupported format:%s", xcam_fourcc_to_string (format)); return false; } return true; }