Lines Matching +full:flip +full:- +full:horizontal

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Author: Ping-Hsun Wu <ping-hsun.wu@mediatek.com>
8 #include <media/v4l2-common.h>
9 #include <media/videobuf2-v4l2.h>
10 #include <media/videobuf2-dma-contig.h>
11 #include "mtk-mdp3-core.h"
12 #include "mtk-mdp3-regs.h"
13 #include "mtk-mdp3-m2m.h"
22 for (i = 0; i < mdp_data->format_len; ++i) { in mdp_find_fmt()
23 if (!(mdp_data->format[i].flags & flag)) in mdp_find_fmt()
25 if (mdp_data->format[i].pixelformat == pixelformat) in mdp_find_fmt()
26 return &mdp_data->format[i]; in mdp_find_fmt()
38 for (i = 0; i < mdp_data->format_len; ++i) { in mdp_find_fmt_by_index()
39 if (!(mdp_data->format[i].flags & flag)) in mdp_find_fmt_by_index()
42 return &mdp_data->format[i]; in mdp_find_fmt_by_index()
51 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; in mdp_map_ycbcr_prof_mplane()
56 switch (pix_mp->colorspace) { in mdp_map_ycbcr_prof_mplane()
61 if (pix_mp->quantization == V4L2_QUANTIZATION_FULL_RANGE) in mdp_map_ycbcr_prof_mplane()
65 if (pix_mp->quantization == V4L2_QUANTIZATION_FULL_RANGE) in mdp_map_ycbcr_prof_mplane()
69 if (pix_mp->quantization == V4L2_QUANTIZATION_FULL_RANGE) in mdp_map_ycbcr_prof_mplane()
83 v4l_bound_align_image(w, s->min_width, s->max_width, s->step_width, in mdp_bound_align_image()
84 h, s->min_height, s->max_height, s->step_height, in mdp_bound_align_image()
87 s->min_width = org_w; in mdp_bound_align_image()
88 s->min_height = org_h; in mdp_bound_align_image()
97 return -ERANGE; in mdp_clamp_align()
100 mask = ~((1 << align) - 1); in mdp_clamp_align()
105 return -ERANGE; in mdp_clamp_align()
112 *x = (*x + (1 << (align - 1))) & mask; in mdp_clamp_align()
120 fmt = mdp_find_fmt_by_index(mdp->mdp_data, f->index, f->type); in mdp_enum_fmt_mplane()
122 return -EINVAL; in mdp_enum_fmt_mplane()
124 f->pixelformat = fmt->pixelformat; in mdp_enum_fmt_mplane()
133 struct device *dev = &param->ctx->mdp_dev->pdev->dev; in mdp_try_fmt_mplane()
134 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; in mdp_try_fmt_mplane()
141 fmt = mdp_find_fmt(mdp->mdp_data, pix_mp->pixelformat, f->type); in mdp_try_fmt_mplane()
143 fmt = mdp_find_fmt_by_index(mdp->mdp_data, 0, f->type); in mdp_try_fmt_mplane()
146 (pix_mp->pixelformat & 0xff), in mdp_try_fmt_mplane()
147 (pix_mp->pixelformat >> 8) & 0xff, in mdp_try_fmt_mplane()
148 (pix_mp->pixelformat >> 16) & 0xff, in mdp_try_fmt_mplane()
149 (pix_mp->pixelformat >> 24) & 0xff); in mdp_try_fmt_mplane()
154 pix_mp->field = V4L2_FIELD_NONE; in mdp_try_fmt_mplane()
155 pix_mp->flags = 0; in mdp_try_fmt_mplane()
156 pix_mp->pixelformat = fmt->pixelformat; in mdp_try_fmt_mplane()
157 if (V4L2_TYPE_IS_CAPTURE(f->type)) { in mdp_try_fmt_mplane()
158 pix_mp->colorspace = param->colorspace; in mdp_try_fmt_mplane()
159 pix_mp->xfer_func = param->xfer_func; in mdp_try_fmt_mplane()
160 pix_mp->ycbcr_enc = param->ycbcr_enc; in mdp_try_fmt_mplane()
161 pix_mp->quantization = param->quant; in mdp_try_fmt_mplane()
164 pix_limit = V4L2_TYPE_IS_OUTPUT(f->type) ? &param->limit->out_limit : in mdp_try_fmt_mplane()
165 &param->limit->cap_limit; in mdp_try_fmt_mplane()
166 s.min_width = pix_limit->wmin; in mdp_try_fmt_mplane()
167 s.max_width = pix_limit->wmax; in mdp_try_fmt_mplane()
168 s.step_width = fmt->walign; in mdp_try_fmt_mplane()
169 s.min_height = pix_limit->hmin; in mdp_try_fmt_mplane()
170 s.max_height = pix_limit->hmax; in mdp_try_fmt_mplane()
171 s.step_height = fmt->halign; in mdp_try_fmt_mplane()
172 org_w = pix_mp->width; in mdp_try_fmt_mplane()
173 org_h = pix_mp->height; in mdp_try_fmt_mplane()
175 mdp_bound_align_image(&pix_mp->width, &pix_mp->height, &s, fmt->salign); in mdp_try_fmt_mplane()
176 if (org_w != pix_mp->width || org_h != pix_mp->height) in mdp_try_fmt_mplane()
178 org_w, org_h, pix_mp->width, pix_mp->height); in mdp_try_fmt_mplane()
180 if (pix_mp->num_planes && pix_mp->num_planes != fmt->num_planes) in mdp_try_fmt_mplane()
182 pix_mp->num_planes, fmt->num_planes); in mdp_try_fmt_mplane()
183 pix_mp->num_planes = fmt->num_planes; in mdp_try_fmt_mplane()
185 for (i = 0; i < pix_mp->num_planes; ++i) { in mdp_try_fmt_mplane()
186 u32 min_bpl = (pix_mp->width * fmt->row_depth[i]) >> 3; in mdp_try_fmt_mplane()
187 u32 max_bpl = (pix_limit->wmax * fmt->row_depth[i]) >> 3; in mdp_try_fmt_mplane()
188 u32 bpl = pix_mp->plane_fmt[i].bytesperline; in mdp_try_fmt_mplane()
190 u32 si = pix_mp->plane_fmt[i].sizeimage; in mdp_try_fmt_mplane()
194 pix_mp->plane_fmt[i].bytesperline = bpl; in mdp_try_fmt_mplane()
196 di = (u64)bpl * pix_mp->height * fmt->depth[i]; in mdp_try_fmt_mplane()
197 min_si = (u32)div_u64(di, fmt->row_depth[i]); in mdp_try_fmt_mplane()
198 di = (u64)bpl * s.max_height * fmt->depth[i]; in mdp_try_fmt_mplane()
199 max_si = (u32)div_u64(di, fmt->row_depth[i]); in mdp_try_fmt_mplane()
202 pix_mp->plane_fmt[i].sizeimage = si; in mdp_try_fmt_mplane()
234 struct device *dev = &ctx->mdp_dev->pdev->dev; in mdp_try_crop()
239 dev_dbg(dev, "%d target:%d, set:(%d,%d) %ux%u", ctx->id, in mdp_try_crop()
240 s->target, s->r.left, s->r.top, s->r.width, s->r.height); in mdp_try_crop()
242 left = s->r.left; in mdp_try_crop()
243 top = s->r.top; in mdp_try_crop()
244 right = s->r.left + s->r.width; in mdp_try_crop()
245 bottom = s->r.top + s->r.height; in mdp_try_crop()
246 framew = frame->format.fmt.pix_mp.width; in mdp_try_crop()
247 frameh = frame->format.fmt.pix_mp.height; in mdp_try_crop()
249 if (mdp_target_is_crop(s->target)) { in mdp_try_crop()
253 walign = frame->mdp_fmt->walign; in mdp_try_crop()
254 halign = frame->mdp_fmt->halign; in mdp_try_crop()
257 dev_dbg(dev, "%d align:%u,%u, bound:%ux%u", ctx->id, in mdp_try_crop()
260 ret = mdp_clamp_start(&left, 0, right, walign, s->flags); in mdp_try_crop()
263 ret = mdp_clamp_start(&top, 0, bottom, halign, s->flags); in mdp_try_crop()
266 ret = mdp_clamp_end(&right, left, framew, walign, s->flags); in mdp_try_crop()
269 ret = mdp_clamp_end(&bottom, top, frameh, halign, s->flags); in mdp_try_crop()
273 r->left = left; in mdp_try_crop()
274 r->top = top; in mdp_try_crop()
275 r->width = right - left; in mdp_try_crop()
276 r->height = bottom - top; in mdp_try_crop()
278 dev_dbg(dev, "%d crop:(%d,%d) %ux%u", ctx->id, in mdp_try_crop()
279 r->left, r->top, r->width, r->height); in mdp_try_crop()
289 crop_w = crop->width; in mdp_check_scaling_ratio()
290 crop_h = crop->height; in mdp_check_scaling_ratio()
292 comp_w = compose->height; in mdp_check_scaling_ratio()
293 comp_h = compose->width; in mdp_check_scaling_ratio()
295 comp_w = compose->width; in mdp_check_scaling_ratio()
296 comp_h = compose->height; in mdp_check_scaling_ratio()
299 if ((crop_w / comp_w) > limit->h_scale_down_max || in mdp_check_scaling_ratio()
300 (crop_h / comp_h) > limit->v_scale_down_max || in mdp_check_scaling_ratio()
301 (comp_w / crop_w) > limit->h_scale_up_max || in mdp_check_scaling_ratio()
302 (comp_h / crop_h) > limit->v_scale_up_max) in mdp_check_scaling_ratio()
303 return -ERANGE; in mdp_check_scaling_ratio()
314 if (!mdp->mdp_data->pp_criteria) in mdp_check_pp_enable()
317 s = mdp->mdp_data->pp_criteria->width * in mdp_check_pp_enable()
318 mdp->mdp_data->pp_criteria->height; in mdp_check_pp_enable()
319 r1 = frame->crop.c.width * frame->crop.c.height; in mdp_check_pp_enable()
320 r2 = frame->compose.width * frame->compose.height; in mdp_check_pp_enable()
329 enum mdp_color c = fmt->mdp_color; in mdp_fmt_get_stride()
333 / fmt->row_depth[0]; in mdp_fmt_get_stride()
348 enum mdp_color c = fmt->mdp_color; in mdp_fmt_get_stride_contig()
366 enum mdp_color c = fmt->mdp_color; in mdp_fmt_get_plane_size()
369 bytesperline = (stride * fmt->row_depth[0]) in mdp_fmt_get_plane_size()
385 struct v4l2_pix_format_mplane *pix_mp = &frame->format.fmt.pix_mp; in mdp_prepare_buffer()
388 b->format.colorformat = frame->mdp_fmt->mdp_color; in mdp_prepare_buffer()
389 b->format.ycbcr_prof = frame->ycbcr_prof; in mdp_prepare_buffer()
390 for (i = 0; i < pix_mp->num_planes; ++i) { in mdp_prepare_buffer()
391 u32 stride = mdp_fmt_get_stride(frame->mdp_fmt, in mdp_prepare_buffer()
392 pix_mp->plane_fmt[i].bytesperline, i); in mdp_prepare_buffer()
394 b->format.plane_fmt[i].stride = stride; in mdp_prepare_buffer()
395 b->format.plane_fmt[i].size = in mdp_prepare_buffer()
396 mdp_fmt_get_plane_size(frame->mdp_fmt, stride, in mdp_prepare_buffer()
397 pix_mp->height, i); in mdp_prepare_buffer()
398 b->iova[i] = vb2_dma_contig_plane_dma_addr(vb, i); in mdp_prepare_buffer()
400 for (; i < MDP_COLOR_GET_PLANE_COUNT(b->format.colorformat); ++i) { in mdp_prepare_buffer()
401 u32 stride = mdp_fmt_get_stride_contig(frame->mdp_fmt, in mdp_prepare_buffer()
402 b->format.plane_fmt[0].stride, i); in mdp_prepare_buffer()
404 b->format.plane_fmt[i].stride = stride; in mdp_prepare_buffer()
405 b->format.plane_fmt[i].size = in mdp_prepare_buffer()
406 mdp_fmt_get_plane_size(frame->mdp_fmt, stride, in mdp_prepare_buffer()
407 pix_mp->height, i); in mdp_prepare_buffer()
408 b->iova[i] = b->iova[i - 1] + b->format.plane_fmt[i - 1].size; in mdp_prepare_buffer()
410 b->usage = frame->usage; in mdp_prepare_buffer()
416 in->buffer.format.width = frame->format.fmt.pix_mp.width; in mdp_set_src_config()
417 in->buffer.format.height = frame->format.fmt.pix_mp.height; in mdp_set_src_config()
418 mdp_prepare_buffer(&in->buffer, frame, vb); in mdp_set_src_config()
425 if (f->denominator == 0) { in mdp_to_fixed()
430 q = f->numerator / f->denominator; in mdp_to_fixed()
431 *r = div_u64(((u64)f->numerator - q * f->denominator) << in mdp_to_fixed()
432 IMG_SUBPIXEL_SHIFT, f->denominator); in mdp_to_fixed()
438 c->left = crop->c.left in mdp_set_src_crop()
439 + mdp_to_fixed(&c->left_subpix, &crop->left_subpix); in mdp_set_src_crop()
440 c->top = crop->c.top in mdp_set_src_crop()
441 + mdp_to_fixed(&c->top_subpix, &crop->top_subpix); in mdp_set_src_crop()
442 c->width = crop->c.width in mdp_set_src_crop()
443 + mdp_to_fixed(&c->width_subpix, &crop->width_subpix); in mdp_set_src_crop()
444 c->height = crop->c.height in mdp_set_src_crop()
445 + mdp_to_fixed(&c->height_subpix, &crop->height_subpix); in mdp_set_src_crop()
451 u8 flip = 0; in mdp_set_orientation() local
454 flip ^= 1; in mdp_set_orientation()
457 * A vertical flip is equivalent to in mdp_set_orientation()
458 * a 180-degree rotation with a horizontal flip in mdp_set_orientation()
461 flip ^= 1; in mdp_set_orientation()
464 out->rotation = rotation % 360; in mdp_set_orientation()
465 if (flip != 0) in mdp_set_orientation()
466 out->flags |= IMG_CTRL_FLAG_HFLIP; in mdp_set_orientation()
468 out->flags &= ~IMG_CTRL_FLAG_HFLIP; in mdp_set_orientation()
474 out->buffer.format.width = frame->compose.width; in mdp_set_dst_config()
475 out->buffer.format.height = frame->compose.height; in mdp_set_dst_config()
476 mdp_prepare_buffer(&out->buffer, frame, vb); in mdp_set_dst_config()
477 mdp_set_src_crop(&out->crop, &frame->crop); in mdp_set_dst_config()
478 mdp_set_orientation(out, frame->rotation, frame->hflip, frame->vflip); in mdp_set_dst_config()
486 return -EINVAL; in mdp_frameparam_init()
488 INIT_LIST_HEAD(&param->list); in mdp_frameparam_init()
489 param->limit = mdp->mdp_data->def_limit; in mdp_frameparam_init()
490 param->type = MDP_STREAM_TYPE_BITBLT; in mdp_frameparam_init()
492 frame = &param->output; in mdp_frameparam_init()
493 frame->format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in mdp_frameparam_init()
494 frame->mdp_fmt = mdp_try_fmt_mplane(mdp, &frame->format, param, 0); in mdp_frameparam_init()
495 frame->ycbcr_prof = in mdp_frameparam_init()
496 mdp_map_ycbcr_prof_mplane(&frame->format, in mdp_frameparam_init()
497 frame->mdp_fmt->mdp_color); in mdp_frameparam_init()
498 frame->usage = MDP_BUFFER_USAGE_HW_READ; in mdp_frameparam_init()
500 param->num_captures = 1; in mdp_frameparam_init()
501 frame = &param->captures[0]; in mdp_frameparam_init()
502 frame->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in mdp_frameparam_init()
503 frame->mdp_fmt = mdp_try_fmt_mplane(mdp, &frame->format, param, 0); in mdp_frameparam_init()
504 frame->ycbcr_prof = in mdp_frameparam_init()
505 mdp_map_ycbcr_prof_mplane(&frame->format, in mdp_frameparam_init()
506 frame->mdp_fmt->mdp_color); in mdp_frameparam_init()
507 frame->usage = MDP_BUFFER_USAGE_MDP; in mdp_frameparam_init()
508 frame->crop.c.width = param->output.format.fmt.pix_mp.width; in mdp_frameparam_init()
509 frame->crop.c.height = param->output.format.fmt.pix_mp.height; in mdp_frameparam_init()
510 frame->compose.width = frame->format.fmt.pix_mp.width; in mdp_frameparam_init()
511 frame->compose.height = frame->format.fmt.pix_mp.height; in mdp_frameparam_init()