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