1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #if !defined(HAS_NO_HMEM)
17 
18 #include "ia_css_types.h"
19 #include "sh_css_internal.h"
20 #include "assert_support.h"
21 #include "sh_css_frac.h"
22 
23 #include "ia_css_bh.host.h"
24 
25 void
26 ia_css_bh_hmem_decode(
27     struct ia_css_3a_rgby_output *out_ptr,
28     const struct ia_css_bh_table *hmem_buf)
29 {
30 	int i;
31 
32 	/*
33 	 * No weighted histogram, hence no grid definition
34 	 */
35 	if (!hmem_buf)
36 		return;
37 	assert(sizeof_hmem(HMEM0_ID) == sizeof(*hmem_buf));
38 
39 	/* Deinterleave */
40 	for (i = 0; i < HMEM_UNIT_SIZE; i++) {
41 		out_ptr[i].r = hmem_buf->hmem[BH_COLOR_R][i];
42 		out_ptr[i].g = hmem_buf->hmem[BH_COLOR_G][i];
43 		out_ptr[i].b = hmem_buf->hmem[BH_COLOR_B][i];
44 		out_ptr[i].y = hmem_buf->hmem[BH_COLOR_Y][i];
45 		/* sh_css_print ("hmem[%d] = %d, %d, %d, %d\n",
46 			i, out_ptr[i].r, out_ptr[i].g, out_ptr[i].b, out_ptr[i].y); */
47 	}
48 }
49 
50 void
51 ia_css_bh_encode(
52     struct sh_css_isp_bh_params *to,
53     const struct ia_css_3a_config *from,
54     unsigned int size)
55 {
56 	(void)size;
57 	/* coefficients to calculate Y */
58 	to->y_coef_r =
59 	    uDIGIT_FITTING(from->ae_y_coef_r, 16, SH_CSS_AE_YCOEF_SHIFT);
60 	to->y_coef_g =
61 	    uDIGIT_FITTING(from->ae_y_coef_g, 16, SH_CSS_AE_YCOEF_SHIFT);
62 	to->y_coef_b =
63 	    uDIGIT_FITTING(from->ae_y_coef_b, 16, SH_CSS_AE_YCOEF_SHIFT);
64 }
65 
66 #endif
67