sh_mobile_ceu_camera.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. Cropping and Scaling algorithm, used in the sh_mobile_ceu_camera driver
  2. =======================================================================
  3. Terminology
  4. -----------
  5. sensor scales: horizontal and vertical scales, configured by the sensor driver
  6. host scales: -"- host driver
  7. combined scales: sensor_scale * host_scale
  8. Generic scaling / cropping scheme
  9. ---------------------------------
  10. -1--
  11. |
  12. -2-- -\
  13. | --\
  14. | --\
  15. +-5-- -\ -- -3--
  16. | ---\
  17. | --- -4-- -\
  18. | -\
  19. | - -6--
  20. |
  21. | - -6'-
  22. | -/
  23. | --- -4'- -/
  24. | ---/
  25. +-5'- -/
  26. | -- -3'-
  27. | --/
  28. | --/
  29. -2'- -/
  30. |
  31. |
  32. -1'-
  33. Produced by user requests:
  34. S_CROP(left / top = (5) - (1), width / height = (5') - (5))
  35. S_FMT(width / height = (6') - (6))
  36. Here:
  37. (1) to (1') - whole max width or height
  38. (1) to (2) - sensor cropped left or top
  39. (2) to (2') - sensor cropped width or height
  40. (3) to (3') - sensor scale
  41. (3) to (4) - CEU cropped left or top
  42. (4) to (4') - CEU cropped width or height
  43. (5) to (5') - reverse sensor scale applied to CEU cropped width or height
  44. (2) to (5) - reverse sensor scale applied to CEU cropped left or top
  45. (6) to (6') - CEU scale - user window
  46. S_FMT
  47. -----
  48. Do not touch input rectangle - it is already optimal.
  49. 1. Calculate current sensor scales:
  50. scale_s = ((3') - (3)) / ((2') - (2))
  51. 2. Calculate "effective" input crop (sensor subwindow) - CEU crop scaled back at
  52. current sensor scales onto input window - this is user S_CROP:
  53. width_u = (5') - (5) = ((4') - (4)) * scale_s
  54. 3. Calculate new combined scales from "effective" input window to requested user
  55. window:
  56. scale_comb = width_u / ((6') - (6))
  57. 4. Calculate sensor output window by applying combined scales to real input
  58. window:
  59. width_s_out = ((2') - (2)) / scale_comb
  60. 5. Apply iterative sensor S_FMT for sensor output window.
  61. subdev->video_ops->s_fmt(.width = width_s_out)
  62. 6. Retrieve sensor output window (g_fmt)
  63. 7. Calculate new sensor scales:
  64. scale_s_new = ((3')_new - (3)_new) / ((2') - (2))
  65. 8. Calculate new CEU crop - apply sensor scales to previously calculated
  66. "effective" crop:
  67. width_ceu = (4')_new - (4)_new = width_u / scale_s_new
  68. left_ceu = (4)_new - (3)_new = ((5) - (2)) / scale_s_new
  69. 9. Use CEU cropping to crop to the new window:
  70. ceu_crop(.width = width_ceu, .left = left_ceu)
  71. 10. Use CEU scaling to scale to the requested user window:
  72. scale_ceu = width_ceu / width
  73. S_CROP
  74. ------
  75. If old scale applied to new crop is invalid produce nearest new scale possible
  76. 1. Calculate current combined scales.
  77. scale_comb = (((4') - (4)) / ((6') - (6))) * (((2') - (2)) / ((3') - (3)))
  78. 2. Apply iterative sensor S_CROP for new input window.
  79. 3. If old combined scales applied to new crop produce an impossible user window,
  80. adjust scales to produce nearest possible window.
  81. width_u_out = ((5') - (5)) / scale_comb
  82. if (width_u_out > max)
  83. scale_comb = ((5') - (5)) / max;
  84. else if (width_u_out < min)
  85. scale_comb = ((5') - (5)) / min;
  86. 4. Issue G_CROP to retrieve actual input window.
  87. 5. Using actual input window and calculated combined scales calculate sensor
  88. target output window.
  89. width_s_out = ((3') - (3)) = ((2') - (2)) / scale_comb
  90. 6. Apply iterative S_FMT for new sensor target output window.
  91. 7. Issue G_FMT to retrieve the actual sensor output window.
  92. 8. Calculate sensor scales.
  93. scale_s = ((3') - (3)) / ((2') - (2))
  94. 9. Calculate sensor output subwindow to be cropped on CEU by applying sensor
  95. scales to the requested window.
  96. width_ceu = ((5') - (5)) / scale_s
  97. 10. Use CEU cropping for above calculated window.
  98. 11. Calculate CEU scales from sensor scales from results of (10) and user window
  99. from (3)
  100. scale_ceu = calc_scale(((5') - (5)), &width_u_out)
  101. 12. Apply CEU scales.
  102. --
  103. Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>