1 /*
2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15 #include "ia_css_util.h"
16 #include <ia_css_frame.h>
17 #include <assert_support.h>
18 #include <math_support.h>
19
20 /* for ia_css_binary_max_vf_width() */
21 #include "ia_css_binary.h"
22
23
ia_css_convert_errno(int in_err)24 enum ia_css_err ia_css_convert_errno(
25 int in_err)
26 {
27 enum ia_css_err out_err;
28
29 switch (in_err) {
30 case 0:
31 out_err = IA_CSS_SUCCESS;
32 break;
33 case EINVAL:
34 out_err = IA_CSS_ERR_INVALID_ARGUMENTS;
35 break;
36 case ENODATA:
37 out_err = IA_CSS_ERR_QUEUE_IS_EMPTY;
38 break;
39 case ENOSYS:
40 case ENOTSUP:
41 out_err = IA_CSS_ERR_INTERNAL_ERROR;
42 break;
43 case ENOBUFS:
44 out_err = IA_CSS_ERR_QUEUE_IS_FULL;
45 break;
46 default:
47 out_err = IA_CSS_ERR_INTERNAL_ERROR;
48 break;
49 }
50 return out_err;
51 }
52
53 /* MW: Table look-up ??? */
ia_css_util_input_format_bpp(enum ia_css_stream_format format,bool two_ppc)54 unsigned int ia_css_util_input_format_bpp(
55 enum ia_css_stream_format format,
56 bool two_ppc)
57 {
58 unsigned int rval = 0;
59 switch (format) {
60 case IA_CSS_STREAM_FORMAT_YUV420_8_LEGACY:
61 case IA_CSS_STREAM_FORMAT_YUV420_8:
62 case IA_CSS_STREAM_FORMAT_YUV422_8:
63 case IA_CSS_STREAM_FORMAT_RGB_888:
64 case IA_CSS_STREAM_FORMAT_RAW_8:
65 case IA_CSS_STREAM_FORMAT_BINARY_8:
66 case IA_CSS_STREAM_FORMAT_EMBEDDED:
67 rval = 8;
68 break;
69 case IA_CSS_STREAM_FORMAT_YUV420_10:
70 case IA_CSS_STREAM_FORMAT_YUV422_10:
71 case IA_CSS_STREAM_FORMAT_RAW_10:
72 rval = 10;
73 break;
74 case IA_CSS_STREAM_FORMAT_YUV420_16:
75 case IA_CSS_STREAM_FORMAT_YUV422_16:
76 rval = 16;
77 break;
78 case IA_CSS_STREAM_FORMAT_RGB_444:
79 rval = 4;
80 break;
81 case IA_CSS_STREAM_FORMAT_RGB_555:
82 rval = 5;
83 break;
84 case IA_CSS_STREAM_FORMAT_RGB_565:
85 rval = 65;
86 break;
87 case IA_CSS_STREAM_FORMAT_RGB_666:
88 case IA_CSS_STREAM_FORMAT_RAW_6:
89 rval = 6;
90 break;
91 case IA_CSS_STREAM_FORMAT_RAW_7:
92 rval = 7;
93 break;
94 case IA_CSS_STREAM_FORMAT_RAW_12:
95 rval = 12;
96 break;
97 case IA_CSS_STREAM_FORMAT_RAW_14:
98 if (two_ppc)
99 rval = 14;
100 else
101 rval = 12;
102 break;
103 case IA_CSS_STREAM_FORMAT_RAW_16:
104 if (two_ppc)
105 rval = 16;
106 else
107 rval = 12;
108 break;
109 default:
110 rval = 0;
111 break;
112
113 }
114 return rval;
115 }
116
ia_css_util_check_vf_info(const struct ia_css_frame_info * const info)117 enum ia_css_err ia_css_util_check_vf_info(
118 const struct ia_css_frame_info * const info)
119 {
120 enum ia_css_err err;
121 unsigned int max_vf_width;
122 assert(info != NULL);
123 err = ia_css_frame_check_info(info);
124 if (err != IA_CSS_SUCCESS)
125 return err;
126 max_vf_width = ia_css_binary_max_vf_width();
127 if (max_vf_width != 0 && info->res.width > max_vf_width*2)
128 return IA_CSS_ERR_INVALID_ARGUMENTS;
129 return IA_CSS_SUCCESS;
130 }
131
ia_css_util_check_vf_out_info(const struct ia_css_frame_info * const out_info,const struct ia_css_frame_info * const vf_info)132 enum ia_css_err ia_css_util_check_vf_out_info(
133 const struct ia_css_frame_info * const out_info,
134 const struct ia_css_frame_info * const vf_info)
135 {
136 enum ia_css_err err;
137
138 assert(out_info != NULL);
139 assert(vf_info != NULL);
140
141 err = ia_css_frame_check_info(out_info);
142 if (err != IA_CSS_SUCCESS)
143 return err;
144 err = ia_css_util_check_vf_info(vf_info);
145 if (err != IA_CSS_SUCCESS)
146 return err;
147 return IA_CSS_SUCCESS;
148 }
149
ia_css_util_check_res(unsigned int width,unsigned int height)150 enum ia_css_err ia_css_util_check_res(unsigned int width, unsigned int height)
151 {
152 /* height can be odd number for jpeg/embedded data from ISYS2401 */
153 if (((width == 0) ||
154 (height == 0) ||
155 IS_ODD(width))) {
156 return IA_CSS_ERR_INVALID_ARGUMENTS;
157 }
158 return IA_CSS_SUCCESS;
159 }
160
161 #ifdef ISP2401
ia_css_util_res_leq(struct ia_css_resolution a,struct ia_css_resolution b)162 bool ia_css_util_res_leq(struct ia_css_resolution a, struct ia_css_resolution b)
163 {
164 return a.width <= b.width && a.height <= b.height;
165 }
166
ia_css_util_resolution_is_zero(const struct ia_css_resolution resolution)167 bool ia_css_util_resolution_is_zero(const struct ia_css_resolution resolution)
168 {
169 return (resolution.width == 0) || (resolution.height == 0);
170 }
171
ia_css_util_resolution_is_even(const struct ia_css_resolution resolution)172 bool ia_css_util_resolution_is_even(const struct ia_css_resolution resolution)
173 {
174 return IS_EVEN(resolution.height) && IS_EVEN(resolution.width);
175 }
176
177 #endif
ia_css_util_is_input_format_raw(enum ia_css_stream_format format)178 bool ia_css_util_is_input_format_raw(enum ia_css_stream_format format)
179 {
180 return ((format == IA_CSS_STREAM_FORMAT_RAW_6) ||
181 (format == IA_CSS_STREAM_FORMAT_RAW_7) ||
182 (format == IA_CSS_STREAM_FORMAT_RAW_8) ||
183 (format == IA_CSS_STREAM_FORMAT_RAW_10) ||
184 (format == IA_CSS_STREAM_FORMAT_RAW_12));
185 /* raw_14 and raw_16 are not supported as input formats to the ISP.
186 * They can only be copied to a frame in memory using the
187 * copy binary.
188 */
189 }
190
ia_css_util_is_input_format_yuv(enum ia_css_stream_format format)191 bool ia_css_util_is_input_format_yuv(enum ia_css_stream_format format)
192 {
193 return format == IA_CSS_STREAM_FORMAT_YUV420_8_LEGACY ||
194 format == IA_CSS_STREAM_FORMAT_YUV420_8 ||
195 format == IA_CSS_STREAM_FORMAT_YUV420_10 ||
196 format == IA_CSS_STREAM_FORMAT_YUV420_16 ||
197 format == IA_CSS_STREAM_FORMAT_YUV422_8 ||
198 format == IA_CSS_STREAM_FORMAT_YUV422_10 ||
199 format == IA_CSS_STREAM_FORMAT_YUV422_16;
200 }
201
ia_css_util_check_input(const struct ia_css_stream_config * const stream_config,bool must_be_raw,bool must_be_yuv)202 enum ia_css_err ia_css_util_check_input(
203 const struct ia_css_stream_config * const stream_config,
204 bool must_be_raw,
205 bool must_be_yuv)
206 {
207 assert(stream_config != NULL);
208
209 if (stream_config == NULL)
210 return IA_CSS_ERR_INVALID_ARGUMENTS;
211
212 #ifdef IS_ISP_2400_SYSTEM
213 if (stream_config->input_config.effective_res.width == 0 ||
214 stream_config->input_config.effective_res.height == 0)
215 return IA_CSS_ERR_INVALID_ARGUMENTS;
216 #endif
217 if (must_be_raw &&
218 !ia_css_util_is_input_format_raw(stream_config->input_config.format))
219 return IA_CSS_ERR_INVALID_ARGUMENTS;
220
221 if (must_be_yuv &&
222 !ia_css_util_is_input_format_yuv(stream_config->input_config.format))
223 return IA_CSS_ERR_INVALID_ARGUMENTS;
224
225 return IA_CSS_SUCCESS;
226 }
227
228