Example #1
0
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;

}
void
prepare_shading_table(const struct ia_css_shading_table *in_table,
		      unsigned int sensor_binning,
		      bool raw_binning,
		      struct ia_css_shading_table **target_table,
		      const struct sh_css_binary *binary)
{
	unsigned int input_width,
		     input_height,
		     table_width,
		     table_height,
		     left_padding,
		     right_padding,
		     i;
	struct ia_css_shading_table *result;

	assert(target_table != NULL);
	assert(binary != NULL);

	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.res.height;
	input_width   = binary->in_frame_info.res.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_height = binary->sctbl_height;

	result = ia_css_shading_table_alloc(table_width, table_height);
	if (result == NULL) {
		*target_table = NULL;
		return;
	}
	result->sensor_width  = in_table->sensor_width;
	result->sensor_height = in_table->sensor_height;
	result->fraction_bits = in_table->fraction_bits;

	/* now we crop the original shading table and then interpolate to the
	   requested resolution and decimation factor. */
	for (i = 0; i < IA_CSS_SC_NUM_COLORS; i++) {
		crop_and_interpolate(input_width, input_height,
				     left_padding, right_padding,
				     in_table,
				     result, i);
	}
	*target_table = result;
}
void
prepare_shading_table(const struct ia_css_shading_table *in_table,
		      unsigned int sensor_binning,
		      struct ia_css_shading_table **target_table,
		      const struct ia_css_binary *binary,
		      unsigned int bds_factor)
{
	unsigned int input_width,
		     input_height,
		     table_width,
		     table_height,
		     left_padding,
		     top_padding,
		     padded_width,
		     left_cropping,
		     i;
	unsigned int bds_numerator, bds_denominator;
	int right_padding;

	struct ia_css_shading_table *result;

	assert(target_table != NULL);
	assert(binary != NULL);

	if (!in_table) {
		sh_css_params_shading_id_table_generate(target_table, binary);
		return;
	}

	padded_width = binary->in_frame_info.padded_width;
	/* We use the ISP input resolution for the shading table because
	   shading correction is performed in the bayer domain (before bayer
	   down scaling). */
#if defined(USE_INPUT_SYSTEM_VERSION_2401)
	padded_width = CEIL_MUL(binary->effective_in_frame_res.width + 2*ISP_VEC_NELEMS,
					2*ISP_VEC_NELEMS);
#endif
	input_height  = binary->in_frame_info.res.height;
	input_width   = binary->in_frame_info.res.width;
	left_padding  = binary->left_padding;
	left_cropping = (binary->info->sp.pipeline.left_cropping == 0) ?
			binary->dvs_envelope.width : 2*ISP_VEC_NELEMS;

	sh_css_bds_factor_get_numerator_denominator
		(bds_factor, &bds_numerator, &bds_denominator);

	left_padding  = (left_padding + binary->info->sp.pipeline.left_cropping) * bds_numerator / bds_denominator - binary->info->sp.pipeline.left_cropping;
	right_padding = (binary->internal_frame_info.res.width - binary->effective_in_frame_res.width * bds_denominator / bds_numerator - left_cropping) * bds_numerator / bds_denominator;
	top_padding = binary->info->sp.pipeline.top_cropping * bds_numerator / bds_denominator - binary->info->sp.pipeline.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;
	top_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_height = binary->sctbl_height;

	result = ia_css_shading_table_alloc(table_width, table_height);
	if (result == NULL) {
		*target_table = NULL;
		return;
	}
	result->sensor_width  = in_table->sensor_width;
	result->sensor_height = in_table->sensor_height;
	result->fraction_bits = in_table->fraction_bits;

	/* now we crop the original shading table and then interpolate to the
	   requested resolution and decimation factor. */
	for (i = 0; i < IA_CSS_SC_NUM_COLORS; i++) {
		crop_and_interpolate(input_width, input_height,
				     left_padding, right_padding, top_padding,
				     in_table,
				     result, i);
	}
	*target_table = result;
}