// SPDX-License-Identifier: GPL-2.0 /* * Support for Intel Camera Imaging ISP subsystem. * Copyright (c) 2015, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. */ #include <linux/math.h> #include <linux/slab.h> #include <math_support.h> #include "sh_css_param_shading.h" #include "ia_css_shading.h" #include "assert_support.h" #include "sh_css_defs.h" #include "sh_css_internal.h" #include "ia_css_debug.h" #include "ia_css_pipe_binarydesc.h" #include "sh_css_hrt.h" #include "platform_support.h" /* Bilinear interpolation on shading tables: * For each target point T, we calculate the 4 surrounding source points: * ul (upper left), ur (upper right), ll (lower left) and lr (lower right). * We then calculate the distances from the T to the source points: x0, x1, * y0 and y1. * We then calculate the value of T: * dx0*dy0*Slr + dx0*dy1*Sur + dx1*dy0*Sll + dx1*dy1*Sul. * We choose a grid size of 1x1 which means: * dx1 = 1-dx0 * dy1 = 1-dy0 * * Sul dx0 dx1 Sur * .<----->|<------------->. * ^ * dy0| * v T * - . * ^ * | * dy1| * v * . . * Sll Slr * * Padding: * The area that the ISP operates on can include padding both on the left * and the right. We need to padd the shading table such that the shading * values end up on the correct pixel values. This means we must padd the * shading table to match the ISP padding. * We can have 5 cases: * 1. All 4 points fall in the left padding. * 2. The left 2 points fall in the left padding. * 3. All 4 points fall in the cropped (target) region. * 4. The right 2 points fall in the right padding. * 5. All 4 points fall in the right padding. * Cases 1 and 5 are easy to handle: we simply use the * value 1 in the shading table. * Cases 2 and 4 require interpolation that takes into * account how far into the padding area the pixels * fall. We extrapolate the shading table into the * padded area and then interpolate. */ static void crop_and_interpolate(unsigned int cropped_width, unsigned int cropped_height, unsigned int left_padding, int right_padding, int top_padding, const struct ia_css_shading_table *in_table, struct ia_css_shading_table *out_table, enum ia_css_sc_color color) { … } void sh_css_params_shading_id_table_generate( struct ia_css_shading_table **target_table, unsigned int table_width, unsigned int table_height) { … } 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) { … } struct ia_css_shading_table * ia_css_shading_table_alloc( unsigned int width, unsigned int height) { … } void ia_css_shading_table_free(struct ia_css_shading_table *table) { … }