2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
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.
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
15 #include "ia_css_util.h"
16 #include <ia_css_frame.h>
17 #include <assert_support.h>
18 #include <math_support.h>
20 /* for ia_css_binary_max_vf_width() */
21 #include "ia_css_binary.h"
24 enum ia_css_err ia_css_convert_errno(
27 enum ia_css_err out_err;
31 out_err = IA_CSS_SUCCESS;
34 out_err = IA_CSS_ERR_INVALID_ARGUMENTS;
37 out_err = IA_CSS_ERR_QUEUE_IS_EMPTY;
41 out_err = IA_CSS_ERR_INTERNAL_ERROR;
44 out_err = IA_CSS_ERR_QUEUE_IS_FULL;
47 out_err = IA_CSS_ERR_INTERNAL_ERROR;
53 /* MW: Table look-up ??? */
54 unsigned int ia_css_util_input_format_bpp(
55 enum ia_css_stream_format format,
58 unsigned int rval = 0;
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:
69 case IA_CSS_STREAM_FORMAT_YUV420_10:
70 case IA_CSS_STREAM_FORMAT_YUV422_10:
71 case IA_CSS_STREAM_FORMAT_RAW_10:
74 case IA_CSS_STREAM_FORMAT_YUV420_16:
75 case IA_CSS_STREAM_FORMAT_YUV422_16:
78 case IA_CSS_STREAM_FORMAT_RGB_444:
81 case IA_CSS_STREAM_FORMAT_RGB_555:
84 case IA_CSS_STREAM_FORMAT_RGB_565:
87 case IA_CSS_STREAM_FORMAT_RGB_666:
88 case IA_CSS_STREAM_FORMAT_RAW_6:
91 case IA_CSS_STREAM_FORMAT_RAW_7:
94 case IA_CSS_STREAM_FORMAT_RAW_12:
97 case IA_CSS_STREAM_FORMAT_RAW_14:
103 case IA_CSS_STREAM_FORMAT_RAW_16:
117 enum ia_css_err ia_css_util_check_vf_info(
118 const struct ia_css_frame_info * const info)
121 unsigned int max_vf_width;
122 assert(info != NULL);
123 err = ia_css_frame_check_info(info);
124 if (err != IA_CSS_SUCCESS)
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;
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)
138 assert(out_info != NULL);
139 assert(vf_info != NULL);
141 err = ia_css_frame_check_info(out_info);
142 if (err != IA_CSS_SUCCESS)
144 err = ia_css_util_check_vf_info(vf_info);
145 if (err != IA_CSS_SUCCESS)
147 return IA_CSS_SUCCESS;
150 enum ia_css_err ia_css_util_check_res(unsigned int width, unsigned int height)
152 /* height can be odd number for jpeg/embedded data from ISYS2401 */
156 return IA_CSS_ERR_INVALID_ARGUMENTS;
158 return IA_CSS_SUCCESS;
162 bool ia_css_util_res_leq(struct ia_css_resolution a, struct ia_css_resolution b)
164 return a.width <= b.width && a.height <= b.height;
167 bool ia_css_util_resolution_is_zero(const struct ia_css_resolution resolution)
169 return (resolution.width == 0) || (resolution.height == 0);
172 bool ia_css_util_resolution_is_even(const struct ia_css_resolution resolution)
174 return IS_EVEN(resolution.height) && IS_EVEN(resolution.width);
178 bool ia_css_util_is_input_format_raw(enum ia_css_stream_format format)
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
191 bool ia_css_util_is_input_format_yuv(enum ia_css_stream_format format)
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;
202 enum ia_css_err ia_css_util_check_input(
203 const struct ia_css_stream_config * const stream_config,
207 assert(stream_config != NULL);
209 if (stream_config == NULL)
210 return IA_CSS_ERR_INVALID_ARGUMENTS;
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;
218 !ia_css_util_is_input_format_raw(stream_config->input_config.format))
219 return IA_CSS_ERR_INVALID_ARGUMENTS;
222 !ia_css_util_is_input_format_yuv(stream_config->input_config.format))
223 return IA_CSS_ERR_INVALID_ARGUMENTS;
225 return IA_CSS_SUCCESS;