Lines Matching +full:2 +full:- +full:1

1 // SPDX-License-Identifier: LGPL-2.1
11 #include "codec-v4l2-fwht.h"
14 { V4L2_PIX_FMT_YUV420, 1, 3, 2, 1, 1, 2, 2, 3, 3, V4L2_FWHT_FL_PIXENC_YUV},
15 { V4L2_PIX_FMT_YVU420, 1, 3, 2, 1, 1, 2, 2, 3, 3, V4L2_FWHT_FL_PIXENC_YUV},
16 { V4L2_PIX_FMT_YUV422P, 1, 2, 1, 1, 1, 2, 1, 3, 3, V4L2_FWHT_FL_PIXENC_YUV},
17 { V4L2_PIX_FMT_NV12, 1, 3, 2, 1, 2, 2, 2, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
18 { V4L2_PIX_FMT_NV21, 1, 3, 2, 1, 2, 2, 2, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
19 { V4L2_PIX_FMT_NV16, 1, 2, 1, 1, 2, 2, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
20 { V4L2_PIX_FMT_NV61, 1, 2, 1, 1, 2, 2, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
21 { V4L2_PIX_FMT_NV24, 1, 3, 1, 1, 2, 1, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
22 { V4L2_PIX_FMT_NV42, 1, 3, 1, 1, 2, 1, 1, 3, 2, V4L2_FWHT_FL_PIXENC_YUV},
23 { V4L2_PIX_FMT_YUYV, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
24 { V4L2_PIX_FMT_YVYU, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
25 { V4L2_PIX_FMT_UYVY, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
26 { V4L2_PIX_FMT_VYUY, 2, 2, 1, 2, 4, 2, 1, 3, 1, V4L2_FWHT_FL_PIXENC_YUV},
27 { V4L2_PIX_FMT_BGR24, 3, 3, 1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, 1, 1, 1, V4L2_FWHT_FL_PIXENC_RGB},
48 if (info->width_div == width_div && in v4l2_fwht_validate_fmt()
49 info->height_div == height_div && in v4l2_fwht_validate_fmt()
50 (!pixenc || info->pixenc == pixenc) && in v4l2_fwht_validate_fmt()
51 info->components_num == components_num) in v4l2_fwht_validate_fmt()
71 start_idx--; in v4l2_fwht_find_nth_fmt()
98 rf->luma = buf; in prepare_raw_frame()
99 rf->width_div = info->width_div; in prepare_raw_frame()
100 rf->height_div = info->height_div; in prepare_raw_frame()
101 rf->luma_alpha_step = info->luma_alpha_step; in prepare_raw_frame()
102 rf->chroma_step = info->chroma_step; in prepare_raw_frame()
103 rf->alpha = NULL; in prepare_raw_frame()
104 rf->components_num = info->components_num; in prepare_raw_frame()
108 * frame of an I-frame in the stateless decoder in prepare_raw_frame()
111 rf->luma = NULL; in prepare_raw_frame()
112 rf->cb = NULL; in prepare_raw_frame()
113 rf->cr = NULL; in prepare_raw_frame()
114 rf->alpha = NULL; in prepare_raw_frame()
117 switch (info->id) { in prepare_raw_frame()
119 rf->cb = NULL; in prepare_raw_frame()
120 rf->cr = NULL; in prepare_raw_frame()
123 rf->cb = rf->luma + size; in prepare_raw_frame()
124 rf->cr = rf->cb + size / 4; in prepare_raw_frame()
127 rf->cr = rf->luma + size; in prepare_raw_frame()
128 rf->cb = rf->cr + size / 4; in prepare_raw_frame()
131 rf->cb = rf->luma + size; in prepare_raw_frame()
132 rf->cr = rf->cb + size / 2; in prepare_raw_frame()
137 rf->cb = rf->luma + size; in prepare_raw_frame()
138 rf->cr = rf->cb + 1; in prepare_raw_frame()
143 rf->cr = rf->luma + size; in prepare_raw_frame()
144 rf->cb = rf->cr + 1; in prepare_raw_frame()
147 rf->cb = rf->luma + 1; in prepare_raw_frame()
148 rf->cr = rf->cb + 2; in prepare_raw_frame()
151 rf->cr = rf->luma + 1; in prepare_raw_frame()
152 rf->cb = rf->cr + 2; in prepare_raw_frame()
155 rf->cb = rf->luma; in prepare_raw_frame()
156 rf->cr = rf->cb + 2; in prepare_raw_frame()
157 rf->luma++; in prepare_raw_frame()
160 rf->cr = rf->luma; in prepare_raw_frame()
161 rf->cb = rf->cr + 2; in prepare_raw_frame()
162 rf->luma++; in prepare_raw_frame()
166 rf->cr = rf->luma; in prepare_raw_frame()
167 rf->cb = rf->cr + 2; in prepare_raw_frame()
168 rf->luma++; in prepare_raw_frame()
171 rf->cb = rf->luma; in prepare_raw_frame()
172 rf->cr = rf->cb + 2; in prepare_raw_frame()
173 rf->luma++; in prepare_raw_frame()
179 rf->alpha = rf->luma; in prepare_raw_frame()
180 rf->cr = rf->luma + 1; in prepare_raw_frame()
181 rf->cb = rf->cr + 2; in prepare_raw_frame()
182 rf->luma += 2; in prepare_raw_frame()
187 rf->cb = rf->luma; in prepare_raw_frame()
188 rf->cr = rf->cb + 2; in prepare_raw_frame()
189 rf->luma++; in prepare_raw_frame()
190 rf->alpha = rf->cr + 1; in prepare_raw_frame()
194 rf->alpha = rf->luma; in prepare_raw_frame()
195 rf->cb = rf->luma + 1; in prepare_raw_frame()
196 rf->cr = rf->cb + 2; in prepare_raw_frame()
197 rf->luma += 2; in prepare_raw_frame()
201 rf->alpha = rf->luma + 3; in prepare_raw_frame()
202 rf->cr = rf->luma; in prepare_raw_frame()
203 rf->cb = rf->cr + 2; in prepare_raw_frame()
204 rf->luma++; in prepare_raw_frame()
207 return -EINVAL; in prepare_raw_frame()
214 unsigned int size = state->stride * state->coded_height; in v4l2_fwht_encode()
215 unsigned int chroma_stride = state->stride; in v4l2_fwht_encode()
216 const struct v4l2_fwht_pixfmt_info *info = state->info; in v4l2_fwht_encode()
224 return -EINVAL; in v4l2_fwht_encode()
227 return -EINVAL; in v4l2_fwht_encode()
229 if (info->planes_num == 3) in v4l2_fwht_encode()
230 chroma_stride /= 2; in v4l2_fwht_encode()
232 if (info->id == V4L2_PIX_FMT_NV24 || in v4l2_fwht_encode()
233 info->id == V4L2_PIX_FMT_NV42) in v4l2_fwht_encode()
234 chroma_stride *= 2; in v4l2_fwht_encode()
236 cf.i_frame_qp = state->i_frame_qp; in v4l2_fwht_encode()
237 cf.p_frame_qp = state->p_frame_qp; in v4l2_fwht_encode()
240 encoding = fwht_encode_frame(&rf, &state->ref_frame, &cf, in v4l2_fwht_encode()
241 !state->gop_cnt, in v4l2_fwht_encode()
242 state->gop_cnt == state->gop_size - 1, in v4l2_fwht_encode()
243 state->visible_width, in v4l2_fwht_encode()
244 state->visible_height, in v4l2_fwht_encode()
245 state->stride, chroma_stride); in v4l2_fwht_encode()
247 state->gop_cnt = 0; in v4l2_fwht_encode()
248 if (++state->gop_cnt >= state->gop_size) in v4l2_fwht_encode()
249 state->gop_cnt = 0; in v4l2_fwht_encode()
252 p_hdr->magic1 = FWHT_MAGIC1; in v4l2_fwht_encode()
253 p_hdr->magic2 = FWHT_MAGIC2; in v4l2_fwht_encode()
254 p_hdr->version = htonl(V4L2_FWHT_VERSION); in v4l2_fwht_encode()
255 p_hdr->width = htonl(state->visible_width); in v4l2_fwht_encode()
256 p_hdr->height = htonl(state->visible_height); in v4l2_fwht_encode()
257 flags |= (info->components_num - 1) << V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET; in v4l2_fwht_encode()
258 flags |= info->pixenc; in v4l2_fwht_encode()
269 if (rf.height_div == 1) in v4l2_fwht_encode()
271 if (rf.width_div == 1) in v4l2_fwht_encode()
273 p_hdr->flags = htonl(flags); in v4l2_fwht_encode()
274 p_hdr->colorspace = htonl(state->colorspace); in v4l2_fwht_encode()
275 p_hdr->xfer_func = htonl(state->xfer_func); in v4l2_fwht_encode()
276 p_hdr->ycbcr_enc = htonl(state->ycbcr_enc); in v4l2_fwht_encode()
277 p_hdr->quantization = htonl(state->quantization); in v4l2_fwht_encode()
278 p_hdr->size = htonl(cf.size); in v4l2_fwht_encode()
291 unsigned int dst_chroma_stride = state->stride; in v4l2_fwht_decode()
292 unsigned int ref_chroma_stride = state->ref_stride; in v4l2_fwht_decode()
293 unsigned int dst_size = state->stride * state->coded_height; in v4l2_fwht_decode()
296 if (!state->info) in v4l2_fwht_decode()
297 return -EINVAL; in v4l2_fwht_decode()
299 info = state->info; in v4l2_fwht_decode()
301 version = ntohl(state->header.version); in v4l2_fwht_decode()
305 return -EINVAL; in v4l2_fwht_decode()
308 if (state->header.magic1 != FWHT_MAGIC1 || in v4l2_fwht_decode()
309 state->header.magic2 != FWHT_MAGIC2) in v4l2_fwht_decode()
310 return -EINVAL; in v4l2_fwht_decode()
313 if (ntohl(state->header.width) != state->visible_width || in v4l2_fwht_decode()
314 ntohl(state->header.height) != state->visible_height) in v4l2_fwht_decode()
315 return -EINVAL; in v4l2_fwht_decode()
317 flags = ntohl(state->header.flags); in v4l2_fwht_decode()
319 if (version >= 2) { in v4l2_fwht_decode()
320 if ((flags & V4L2_FWHT_FL_PIXENC_MSK) != info->pixenc) in v4l2_fwht_decode()
321 return -EINVAL; in v4l2_fwht_decode()
322 components_num = 1 + ((flags & V4L2_FWHT_FL_COMPONENTS_NUM_MSK) >> in v4l2_fwht_decode()
326 if (components_num != info->components_num) in v4l2_fwht_decode()
327 return -EINVAL; in v4l2_fwht_decode()
329 state->colorspace = ntohl(state->header.colorspace); in v4l2_fwht_decode()
330 state->xfer_func = ntohl(state->header.xfer_func); in v4l2_fwht_decode()
331 state->ycbcr_enc = ntohl(state->header.ycbcr_enc); in v4l2_fwht_decode()
332 state->quantization = ntohl(state->header.quantization); in v4l2_fwht_decode()
334 cf.size = ntohl(state->header.size); in v4l2_fwht_decode()
336 hdr_width_div = (flags & V4L2_FWHT_FL_CHROMA_FULL_WIDTH) ? 1 : 2; in v4l2_fwht_decode()
337 hdr_height_div = (flags & V4L2_FWHT_FL_CHROMA_FULL_HEIGHT) ? 1 : 2; in v4l2_fwht_decode()
338 if (hdr_width_div != info->width_div || in v4l2_fwht_decode()
339 hdr_height_div != info->height_div) in v4l2_fwht_decode()
340 return -EINVAL; in v4l2_fwht_decode()
343 return -EINVAL; in v4l2_fwht_decode()
344 if (info->planes_num == 3) { in v4l2_fwht_decode()
345 dst_chroma_stride /= 2; in v4l2_fwht_decode()
346 ref_chroma_stride /= 2; in v4l2_fwht_decode()
348 if (info->id == V4L2_PIX_FMT_NV24 || in v4l2_fwht_decode()
349 info->id == V4L2_PIX_FMT_NV42) { in v4l2_fwht_decode()
350 dst_chroma_stride *= 2; in v4l2_fwht_decode()
351 ref_chroma_stride *= 2; in v4l2_fwht_decode()
355 ref_size = state->ref_stride * state->coded_height; in v4l2_fwht_decode()
357 if (prepare_raw_frame(&state->ref_frame, info, state->ref_frame.buf, in v4l2_fwht_decode()
359 return -EINVAL; in v4l2_fwht_decode()
362 state->visible_width, state->visible_height, in v4l2_fwht_decode()
363 &state->ref_frame, state->ref_stride, ref_chroma_stride, in v4l2_fwht_decode()
364 &dst_rf, state->stride, dst_chroma_stride)) in v4l2_fwht_decode()
365 return -EINVAL; in v4l2_fwht_decode()