enum sh_css_err sh_css_binary_uninit(void) { unsigned int i; struct sh_css_binary_info *b; for (i = 0; i < SH_CSS_BINARY_NUM_MODES; i++) { for (b = binary_infos[i]; b; b = b->next) { if (b->xmem_addr) mmgr_free(b->xmem_addr); b->xmem_addr = mmgr_NULL; } binary_infos[i] = NULL; } sh_css_free(all_binaries); return sh_css_success; }
void ia_css_isp_param_destroy_isp_parameters( struct ia_css_isp_param_host_segments *mem_params, struct ia_css_isp_param_css_segments *css_params) { unsigned mem, pclass; for (mem = 0; mem < IA_CSS_NUM_MEMORIES; mem++) { for (pclass = 0; pclass < IA_CSS_NUM_PARAM_CLASSES; pclass++) { if (mem_params->params[pclass][mem].address) sh_css_free(mem_params->params[pclass][mem].address); if (css_params->params[pclass][mem].address) mmgr_free(css_params->params[pclass][mem].address); mem_params->params[pclass][mem].address = NULL; css_params->params[pclass][mem].address = 0x0; } } }
static void generate_id_shading_table(struct sh_css_shading_table_isp **target_table, const struct sh_css_binary *binary) { unsigned int c, l, x, table_width, table_height, table_stride; struct sh_css_shading_table_isp *result; table_width = binary->sctbl_width_per_color; table_stride = binary->sctbl_aligned_width_per_color; table_height = binary->sctbl_height; result = sh_css_malloc(sizeof(*result)); if (result == NULL) { *target_table = NULL; return; } result->width = table_width; result->stride = table_stride; result->height = table_height; result->sensor_width = 0; result->sensor_height = 0; result->fraction_bits = 0; result->data = sh_css_malloc(SH_CSS_SC_NUM_COLORS * table_stride * table_height * sizeof(*result->data)); if (result->data == NULL) { sh_css_free(result); *target_table = NULL; return; } /* initialize table with ones and padding with zeros*/ for (c = 0; c < SH_CSS_SC_NUM_COLORS; c++) { for (l = 0; l < table_height; l++) { for (x = 0; x < table_width; x++) *sh_table_entry(result, c, l, x) = 1; for (; x < table_stride; x++) *sh_table_entry(result, c, l, x) = 0; } } *target_table = result; }
void sh_css_refcount_uninit(void) { struct sh_css_refcount_entry *entry; uint32_t i; for (i = 0; i < myrefcount.size; i++) { entry = &myrefcount.items[i]; if (entry->data != mmgr_NULL) { /* sh_css_dtrace(SH_DBG_TRACE_PRIVATE, "sh_css_refcount_uninit: freeing (%x)\n", entry->data);*/ mmgr_free(entry->data); entry->data = mmgr_NULL; entry->size = 0; entry->count = 0; entry->id = 0; } } sh_css_free(myrefcount.items); myrefcount.items = NULL; myrefcount.size = 0; }
enum ia_css_err ia_css_frame_create_from_info(struct ia_css_frame **frame, const struct ia_css_frame_info *info) { enum ia_css_err err = IA_CSS_SUCCESS; struct ia_css_frame *me; ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_frame_create_from_info() enter:\n"); if (frame == NULL || info == NULL) { ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_frame_create_from_info() leave:" " invalid arguments\n"); return IA_CSS_ERR_INVALID_ARGUMENTS; } me = frame_create(info->res.width, info->res.height, info->format, info->padded_width, info->raw_bit_depth, false, false); if (me == NULL) { ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_frame_create_from_info() leave:" " frame create failed\n"); return IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY; } err = ia_css_frame_init_planes(me); if (err == IA_CSS_SUCCESS) *frame = me; else sh_css_free(me); ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_frame_create_from_info() leave:\n"); return err; }
struct sh_css_shading_table * sh_css_param_shading_table_get( unsigned int sensor_binning, bool raw_binning) { struct sh_css_shading_table *sc_table_css; struct sh_css_shading_table_isp *tmp_sc_table_isp; struct sh_css_binary *binary = NULL; unsigned num_pipes, p, l; sh_css_dtrace(SH_DBG_TRACE_PRIVATE, "sh_css_param_shading_table_get() enter:\n"); sh_css_pipeline_stream_get_num_pipelines(&num_pipes); for (p = 0; p < num_pipes; p++) { struct sh_css_pipeline *pipeline; struct sh_css_pipeline_stage *stage; unsigned int thread_id; sh_css_pipeline_stream_get_pipeline(p, &pipeline); assert(pipeline != NULL); sh_css_query_sp_thread_id(pipeline->pipe_id, &thread_id); for (stage = pipeline->stages; stage; stage = stage->next) { if (stage && stage->binary) { if (stage->binary->info->enable.sc) { binary = stage->binary; break; } } } if (binary) break; } if (binary) sh_css_param_shading_table_prepare( (const struct sh_css_shading_table *)sc_table, sensor_binning, raw_binning, &tmp_sc_table_isp, binary); sc_table_css = sh_css_shading_table_alloc( binary->sctbl_width_per_color, binary->sctbl_height); sc_table_css->sensor_width = tmp_sc_table_isp->sensor_width; sc_table_css->sensor_height = tmp_sc_table_isp->sensor_height; sc_table_css->width = tmp_sc_table_isp->width; sc_table_css->height = tmp_sc_table_isp->height; sc_table_css->fraction_bits = tmp_sc_table_isp->fraction_bits; /* Copy + reformat shading table data from ISP to CSS data structure */ for (l = 0; l < sc_table_css->height; l++) { unsigned int c; for (c = 0; c < SH_CSS_SC_NUM_COLORS; c++) { memcpy(&sc_table_css->data[c][l*sc_table_css->width], sh_table_entry(tmp_sc_table_isp, c, l, 0), sc_table_css->width * sizeof(short)); } } /* Free the isp shading table in HMM */ sh_css_free(tmp_sc_table_isp->data); sh_css_free(tmp_sc_table_isp); sh_css_dtrace(SH_DBG_TRACE_PRIVATE, "sh_css_param_shading_table_get() leave:\n"); return sc_table_css; }
static void sh_css_param_shading_table_prepare(const struct sh_css_shading_table *in_table, unsigned int sensor_binning, bool raw_binning, struct sh_css_shading_table_isp **target_table, const struct sh_css_binary *binary) { unsigned int input_width, input_height, table_width, table_stride, table_height, left_padding, right_padding; struct sh_css_shading_table_isp *result; if (!in_table) { generate_id_shading_table(target_table, binary); return; } /* We use the ISP input resolution for the shading table because shading correction is performed in the bayer domain (before bayer down scaling). */ input_height = binary->in_frame_info.height; input_width = binary->in_frame_info.width; left_padding = binary->left_padding; right_padding = binary->in_frame_info.padded_width - (input_width + left_padding); if ((binary->info->mode == SH_CSS_BINARY_MODE_PREVIEW) && raw_binning && binary->info->enable.raw_binning) { input_width = input_width * 2 - binary->info->left_cropping; input_height = input_height * 2 - binary->info->top_cropping; } /* We take into account the binning done by the sensor. We do this by cropping the non-binned part of the shading table and then increasing the size of a grid cell with this same binning factor. */ input_width <<= sensor_binning; input_height <<= sensor_binning; /* We also scale the padding by the same binning factor. This will make it much easier later on to calculate the padding of the shading table. */ left_padding <<= sensor_binning; right_padding <<= sensor_binning; /* during simulation, the used resolution can exceed the sensor resolution, so we clip it. */ input_width = min(input_width, in_table->sensor_width); input_height = min(input_height, in_table->sensor_height); table_width = binary->sctbl_width_per_color; table_stride = binary->sctbl_aligned_width_per_color; table_height = binary->sctbl_height; result = sh_css_malloc(sizeof(*result)); if (result == NULL) { *target_table = NULL; return; } result->width = table_width; result->stride = table_stride; result->height = table_height; result->sensor_width = in_table->sensor_width; result->sensor_height = in_table->sensor_height; result->fraction_bits = in_table->fraction_bits; result->data = sh_css_malloc(SH_CSS_SC_NUM_COLORS * table_stride * table_height * sizeof(*result->data)); if (result->data == NULL) { sh_css_free(result); *target_table = NULL; return; } crop_and_interpolate(input_width, input_height, left_padding, right_padding, in_table, result); *target_table = result; }