summaryrefslogtreecommitdiffstats
path: root/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/xnr/xnr3_0_11/ia_css_xnr3_0_11.host.c
blob: 7e86bc8be0542b33645226ac17ca722a0aad16f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * 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 "type_support.h"
#include "math_support.h"
#include "sh_css_defs.h"
#include "assert_support.h"
#include "ia_css_xnr3_0_11.host.h"

/*
 * XNR 3.0.11 division look-up table
 */
#define XNR3_0_11_LOOK_UP_TABLE_POINTS 16

static const int16_t x[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
512, 637, 782, 952, 1147, 1372, 1627, 1917, 2242,
2597, 2992, 3427, 3907, 4432, 5007, 5632};

static const int16_t a[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
-6587, -4309, -2886, -1970, -1362, -7710, -5508,
-4008, -2931, -2219, -1676, -1280, -999, -769, -616, 0};

static const int16_t b[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
4096, 3292, 2682, 2203, 1828, 1529, 1289, 1094,
935, 808, 701, 612, 537, 473, 419, 372};

static const int16_t c[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};


/*
 * Default kernel parameters (weights). In general, default is bypass mode or as close
 * to the ineffective values as possible. Due to the chroma down+upsampling,
 * perfect bypass mode is not possible for xnr3.
 */
const struct ia_css_xnr3_0_11_config default_xnr3_0_11_config = {
	7, 7, 7, 7, 7, 2 };


/* (void) = ia_css_xnr3_0_11_vmem_encode(*to, *from)
 * -----------------------------------------------
 * VMEM Encode Function to translate UV parameters from userspace into ISP space
*/
void
ia_css_xnr3_0_11_vmem_encode(
	struct sh_css_isp_xnr3_0_11_vmem_params *to,
	const struct ia_css_xnr3_0_11_config *from,
	unsigned size)
{
	unsigned i, j, base;
	const unsigned total_blocks = 4;
	const unsigned shuffle_block = 16;

	(void)from;
	(void)size;

	/* Init */
	for (i = 0; i < ISP_VEC_NELEMS; i++) {
		to->x[0][i] = 0;
		to->a[0][i] = 0;
		to->b[0][i] = 0;
		to->c[0][i] = 0;
	}


	/* Constraints on "x":
	 * - values should be greater or equal to 0.
	 * - values should be ascending.
	 */
	assert(x[0] >= 0);

	for (j = 1; j < XNR3_0_11_LOOK_UP_TABLE_POINTS; j++) {
		assert(x[j] >= 0);
		assert(x[j] > x[j-1]);

	}


	/* The implementation of the calulating 1/x is based on the availability
	 * of the OP_vec_shuffle16 operation.
	 * A 64 element vector is split up in 4 blocks of 16 element. Each array is copied to
	 * a vector 4 times, (starting at 0, 16, 32 and 48). All array elements are copied or
	 * initialised as described in the KFS. The remaining elements of a vector are set to 0.
	 */
	/* TODO: guard this code with above assumptions */
	for(i = 0; i < total_blocks; i++) {
		base = shuffle_block * i;

		for (j = 0; j < XNR3_0_11_LOOK_UP_TABLE_POINTS; j++) {
			to->x[0][base + j] = x[j];
			to->a[0][base + j] = a[j];
			to->b[0][base + j] = b[j];
			to->c[0][base + j] = c[j];
		}
	}

}



/* (void) = ia_css_xnr3_0_11_encode(*to, *from)
 * -----------------------------------------------
 * DMEM Encode Function to translate UV parameters from userspace into ISP space
 */
void
ia_css_xnr3_0_11_encode(
	struct sh_css_isp_xnr3_0_11_params *to,
	const struct ia_css_xnr3_0_11_config *from,
	unsigned size)
{
	int kernel_size = XNR_FILTER_SIZE;
	/* The adjust factor is the next power of 2
	   w.r.t. the kernel size*/
	int adjust_factor = ceil_pow2(kernel_size);

	int32_t weight_y0 = from->weight_y0;
	int32_t weight_y1 = from->weight_y1;
	int32_t weight_u0 = from->weight_u0;
	int32_t weight_u1 = from->weight_u1;
	int32_t weight_v0 = from->weight_v0;
	int32_t weight_v1 = from->weight_v1;

	(void)size;

	to->weight_y0 = weight_y0;
	to->weight_u0 = weight_u0;
	to->weight_v0 = weight_v0;
	to->weight_ydiff = (weight_y1 - weight_y0) * adjust_factor / kernel_size;
	to->weight_udiff = (weight_u1 - weight_u0) * adjust_factor / kernel_size;
	to->weight_vdiff = (weight_v1 - weight_v0) * adjust_factor / kernel_size;
}

/* (void) = ia_css_xnr3_0_11_debug_dtrace(*config, level)
 * -----------------------------------------------
 * Dummy Function added as the tool expects it
 */
void
ia_css_xnr3_0_11_debug_dtrace(
	const struct ia_css_xnr3_0_11_config *config,
	unsigned level)
{
	(void)config;
	(void)level;
}
OpenPOWER on IntegriCloud