Commit 13bc683e42164fc1c5a3773e6c473113b2d81883

Authored by Archit Taneja
Committed by Jacob Stiffler
1 parent d5f25a39ac

media: ti-vpe: vpe: Add cropping ioctl support

Add crop ioctl ops. For VPE, cropping only makes sense with the input to VPE, or
the V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE buffer type.

For the CAPTURE type, a S_CROP ioctl results in setting the crop region as the
whole image itself, hence making crop dimensions same as the pix dimensions.

Setting the crop successfully should result in re-configuration of those
registers which are affected when either source or destination dimensions
change, set_srcdst_params() is called for thist purpose.

Some standard crop parameter checks are done in __vpe_try_crop().

Change-Id: I9329dee27db526bde54000552b1184e8f061244f
Signed-off-by: Archit Taneja <archit@ti.com>
Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>

Showing 1 changed file with 88 additions and 0 deletions Side-by-side Diff

drivers/media/platform/ti-vpe/vpe.c
... ... @@ -1888,6 +1888,90 @@
1888 1888 return set_srcdst_params(ctx);
1889 1889 }
1890 1890  
  1891 +static int __vpe_try_crop(struct vpe_ctx *ctx, struct v4l2_crop *cr)
  1892 +{
  1893 + struct vpe_q_data *q_data;
  1894 +
  1895 + q_data = get_q_data(ctx, cr->type);
  1896 + if (!q_data)
  1897 + return -EINVAL;
  1898 +
  1899 + /* we don't support crop on capture plane */
  1900 + if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  1901 + cr->c.top = cr->c.left = 0;
  1902 + cr->c.width = q_data->width;
  1903 + cr->c.height = q_data->height;
  1904 + return 0;
  1905 + }
  1906 +
  1907 + if (cr->c.top < 0 || cr->c.left < 0) {
  1908 + vpe_err(ctx->dev, "negative values for top and left\n");
  1909 + cr->c.top = cr->c.left = 0;
  1910 + }
  1911 +
  1912 + v4l_bound_align_image(&cr->c.width, MIN_W, q_data->width, 1,
  1913 + &cr->c.height, MIN_H, q_data->height, H_ALIGN, S_ALIGN);
  1914 +
  1915 + /* adjust left/top if cropping rectangle is out of bounds */
  1916 + if (cr->c.left + cr->c.width > q_data->width)
  1917 + cr->c.left = q_data->width - cr->c.width;
  1918 + if (cr->c.top + cr->c.height > q_data->height)
  1919 + cr->c.top = q_data->height - cr->c.height;
  1920 +
  1921 + return 0;
  1922 +}
  1923 +
  1924 +static int vpe_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cr)
  1925 +{
  1926 + struct vpe_ctx *ctx = file2ctx(file);
  1927 + struct vpe_q_data *q_data;
  1928 +
  1929 + q_data = get_q_data(ctx, cr->type);
  1930 + if (!q_data)
  1931 + return -EINVAL;
  1932 +
  1933 + cr->bounds.left = 0;
  1934 + cr->bounds.top = 0;
  1935 + cr->bounds.width = q_data->width;
  1936 + cr->bounds.height = q_data->height;
  1937 + cr->defrect = cr->bounds;
  1938 +
  1939 + return 0;
  1940 +}
  1941 +
  1942 +static int vpe_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  1943 +{
  1944 + struct vpe_ctx *ctx = file2ctx(file);
  1945 + struct vpe_q_data *q_data;
  1946 +
  1947 + q_data = get_q_data(ctx, cr->type);
  1948 + if (!q_data)
  1949 + return -EINVAL;
  1950 +
  1951 + cr->c = q_data->c_rect;
  1952 +
  1953 + return 0;
  1954 +}
  1955 +
  1956 +static int vpe_s_crop(struct file *file, void *priv,
  1957 + const struct v4l2_crop *crop)
  1958 +{
  1959 + struct vpe_ctx *ctx = file2ctx(file);
  1960 + struct vpe_q_data *q_data;
  1961 + struct v4l2_crop cr = *crop;
  1962 + int ret;
  1963 +
  1964 + ret = __vpe_try_crop(ctx, &cr);
  1965 + if (ret)
  1966 + return ret;
  1967 +
  1968 + q_data = get_q_data(ctx, cr.type);
  1969 +
  1970 + q_data->c_rect = cr.c;
  1971 +
  1972 + return set_srcdst_params(ctx);
  1973 +}
  1974 +
1891 1975 static int vpe_reqbufs(struct file *file, void *priv,
1892 1976 struct v4l2_requestbuffers *reqbufs)
1893 1977 {
... ... @@ -1982,6 +2066,10 @@
1982 2066  
1983 2067 .vidioc_g_selection = vpe_g_selection,
1984 2068 .vidioc_s_selection = vpe_s_selection,
  2069 +
  2070 + .vidioc_cropcap = vpe_cropcap,
  2071 + .vidioc_g_crop = vpe_g_crop,
  2072 + .vidioc_s_crop = vpe_s_crop,
1985 2073  
1986 2074 .vidioc_reqbufs = vpe_reqbufs,
1987 2075 .vidioc_querybuf = vpe_querybuf,