1/*
2 * soc-camera generic scaling-cropping manipulation functions
3 *
4 * Copyright (C) 2013 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef SOC_SCALE_CROP_H
13#define SOC_SCALE_CROP_H
14
15#include <linux/kernel.h>
16
17struct soc_camera_device;
18
19struct v4l2_crop;
20struct v4l2_mbus_framefmt;
21struct v4l2_pix_format;
22struct v4l2_rect;
23struct v4l2_subdev;
24
25static inline unsigned int soc_camera_shift_scale(unsigned int size,
26				unsigned int shift, unsigned int scale)
27{
28	return DIV_ROUND_CLOSEST(size << shift, scale);
29}
30
31#define soc_camera_calc_scale(in, shift, out) soc_camera_shift_scale(in, shift, out)
32
33int soc_camera_client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
34int soc_camera_client_s_crop(struct v4l2_subdev *sd,
35			struct v4l2_crop *crop, struct v4l2_crop *cam_crop,
36			struct v4l2_rect *target_rect, struct v4l2_rect *subrect);
37int soc_camera_client_scale(struct soc_camera_device *icd,
38			struct v4l2_rect *rect, struct v4l2_rect *subrect,
39			struct v4l2_mbus_framefmt *mf,
40			unsigned int *width, unsigned int *height,
41			bool host_can_scale, unsigned int shift);
42void soc_camera_calc_client_output(struct soc_camera_device *icd,
43		struct v4l2_rect *rect, struct v4l2_rect *subrect,
44		const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf,
45		unsigned int shift);
46
47#endif
48