int camera_get_trim_rect(struct img_rect *src_trim_rect, uint32_t zoom_level, struct img_size *dst_size) { uint32_t trim_width; uint32_t trim_height; uint32_t zoom_step_w = 0, zoom_step_h = 0; if (NULL == src_trim_rect || NULL == dst_size) { CMR_LOGE("0x%x, 0x%x", (uint32_t)src_trim_rect, (uint32_t)dst_size); return -CAMERA_INVALID_PARM; } trim_width = src_trim_rect->width; trim_height = src_trim_rect->height; if (0 == dst_size->width || 0 == dst_size->height) { CMR_LOGE("0x%x, 0x%x", dst_size->width, dst_size->height); return -CAMERA_INVALID_PARM; } if (dst_size->width * src_trim_rect->height < dst_size->height * src_trim_rect->width) { trim_width = dst_size->width * src_trim_rect->height / dst_size->height; } else { trim_height = dst_size->height * src_trim_rect->width / dst_size->width; } zoom_step_w = ZOOM_STEP(trim_width); zoom_step_w &= ~1; zoom_step_w *= zoom_level; zoom_step_h = ZOOM_STEP(trim_height); zoom_step_h &= ~1; zoom_step_h *= zoom_level; trim_width = trim_width - zoom_step_w; trim_height = trim_height - zoom_step_h; src_trim_rect->start_x += (src_trim_rect->width - trim_width) >> 1; src_trim_rect->start_y += (src_trim_rect->height - trim_height) >> 1; src_trim_rect->start_x = CAMERA_WIDTH(src_trim_rect->start_x); src_trim_rect->start_y = CAMERA_HEIGHT(src_trim_rect->start_y); src_trim_rect->width = CAMERA_WIDTH(trim_width); src_trim_rect->height = CAMERA_HEIGHT(trim_height); CMR_LOGI("zoom_level %d, trim rect, %d %d %d %d", zoom_level, src_trim_rect->start_x, src_trim_rect->start_y, src_trim_rect->width, src_trim_rect->height); return CAMERA_SUCCESS; }
cmr_int camera_get_trim_rect(struct img_rect *src_trim_rect, cmr_uint zoom_level, struct img_size *dst_size) { cmr_int ret = CMR_CAMERA_SUCCESS; cmr_uint trim_width = 0, trim_height = 0; cmr_uint zoom_step_w = 0, zoom_step_h = 0; if (!src_trim_rect || !dst_size) { CMR_LOGE("0x%lx 0x%lx", (cmr_uint)src_trim_rect, (cmr_uint)dst_size); ret = -CMR_CAMERA_INVALID_PARAM; goto exit; } trim_width = src_trim_rect->width; trim_height = src_trim_rect->height; if (0 == dst_size->width || 0 == dst_size->height) { CMR_LOGE("0x%x 0x%x", dst_size->width, dst_size->height); ret = -CMR_CAMERA_INVALID_PARAM; goto exit; } if (dst_size->width * src_trim_rect->height < dst_size->height * src_trim_rect->width) { trim_width = dst_size->width * src_trim_rect->height / dst_size->height; } else { trim_height = dst_size->height * src_trim_rect->width / dst_size->width; } zoom_step_w = ZOOM_STEP(trim_width); zoom_step_w &= ~1; zoom_step_w *= zoom_level; zoom_step_h = ZOOM_STEP(trim_height); zoom_step_h &= ~1; zoom_step_h *= zoom_level; trim_width = trim_width - zoom_step_w; trim_height = trim_height - zoom_step_h; src_trim_rect->start_x += (src_trim_rect->width - trim_width) >> 1; src_trim_rect->start_y += (src_trim_rect->height - trim_height) >> 1; src_trim_rect->start_x = CAMERA_WIDTH(src_trim_rect->start_x); src_trim_rect->start_y = CAMERA_HEIGHT(src_trim_rect->start_y); src_trim_rect->width = CAMERA_WIDTH(trim_width); src_trim_rect->height = CAMERA_HEIGHT(trim_height); CMR_LOGI("zoom_level %ld trim rect %d %d %d %d", zoom_level, src_trim_rect->start_x, src_trim_rect->start_y, src_trim_rect->width, src_trim_rect->height); exit: return ret; }