1 Cropping and Scaling algorithm, used in the sh_mobile_ceu_camera driver
2 =======================================================================
7 sensor scales: horizontal and vertical scales, configured by the sensor driver
8 host scales: -"- host driver
9 combined scales: sensor_scale * host_scale
12 Generic scaling / cropping scheme
13 ---------------------------------
39 Produced by user requests:
41 S_CROP(left / top = (5) - (1), width / height = (5') - (5))
42 S_FMT(width / height = (6') - (6))
46 (1) to (1') - whole max width or height
47 (1) to (2) - sensor cropped left or top
48 (2) to (2') - sensor cropped width or height
49 (3) to (3') - sensor scale
50 (3) to (4) - CEU cropped left or top
51 (4) to (4') - CEU cropped width or height
52 (5) to (5') - reverse sensor scale applied to CEU cropped width or height
53 (2) to (5) - reverse sensor scale applied to CEU cropped left or top
54 (6) to (6') - CEU scale - user window
60 Do not touch input rectangle - it is already optimal.
62 1. Calculate current sensor scales:
64 scale_s = ((3') - (3)) / ((2') - (2))
66 2. Calculate "effective" input crop (sensor subwindow) - CEU crop scaled back at
67 current sensor scales onto input window - this is user S_CROP:
69 width_u = (5') - (5) = ((4') - (4)) * scale_s
71 3. Calculate new combined scales from "effective" input window to requested user
74 scale_comb = width_u / ((6') - (6))
76 4. Calculate sensor output window by applying combined scales to real input
79 width_s_out = ((2') - (2)) / scale_comb
81 5. Apply iterative sensor S_FMT for sensor output window.
83 subdev->video_ops->s_fmt(.width = width_s_out)
85 6. Retrieve sensor output window (g_fmt)
87 7. Calculate new sensor scales:
89 scale_s_new = ((3')_new - (3)_new) / ((2') - (2))
91 8. Calculate new CEU crop - apply sensor scales to previously calculated
94 width_ceu = (4')_new - (4)_new = width_u / scale_s_new
95 left_ceu = (4)_new - (3)_new = ((5) - (2)) / scale_s_new
97 9. Use CEU cropping to crop to the new window:
99 ceu_crop(.width = width_ceu, .left = left_ceu)
101 10. Use CEU scaling to scale to the requested user window:
103 scale_ceu = width_ceu / width
109 If old scale applied to new crop is invalid produce nearest new scale possible
111 1. Calculate current combined scales.
113 scale_comb = (((4') - (4)) / ((6') - (6))) * (((2') - (2)) / ((3') - (3)))
115 2. Apply iterative sensor S_CROP for new input window.
117 3. If old combined scales applied to new crop produce an impossible user window,
118 adjust scales to produce nearest possible window.
120 width_u_out = ((5') - (5)) / scale_comb
122 if (width_u_out > max)
123 scale_comb = ((5') - (5)) / max;
124 else if (width_u_out < min)
125 scale_comb = ((5') - (5)) / min;
127 4. Issue G_CROP to retrieve actual input window.
129 5. Using actual input window and calculated combined scales calculate sensor
130 target output window.
132 width_s_out = ((3') - (3)) = ((2') - (2)) / scale_comb
134 6. Apply iterative S_FMT for new sensor target output window.
136 7. Issue G_FMT to retrieve the actual sensor output window.
138 8. Calculate sensor scales.
140 scale_s = ((3') - (3)) / ((2') - (2))
142 9. Calculate sensor output subwindow to be cropped on CEU by applying sensor
143 scales to the requested window.
145 width_ceu = ((5') - (5)) / scale_s
147 10. Use CEU cropping for above calculated window.
149 11. Calculate CEU scales from sensor scales from results of (10) and user window
152 scale_ceu = calc_scale(((5') - (5)), &width_u_out)
154 12. Apply CEU scales.
157 Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>