dispc_coefs.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * linux/drivers/video/omap2/dss/dispc_coefs.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Chandrabhanu Mahapatra <cmahapatra@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <video/omapdss.h>
  21. #include "dispc.h"
  22. static const struct dispc_coef coef3_M8[8] = {
  23. { 0, 0, 128, 0, 0 },
  24. { 0, -4, 123, 9, 0 },
  25. { 0, -4, 108, 24, 0 },
  26. { 0, -2, 87, 43, 0 },
  27. { 0, 64, 64, 0, 0 },
  28. { 0, 43, 87, -2, 0 },
  29. { 0, 24, 108, -4, 0 },
  30. { 0, 9, 123, -4, 0 },
  31. };
  32. static const struct dispc_coef coef3_M9[8] = {
  33. { 0, 6, 116, 6, 0 },
  34. { 0, 0, 112, 16, 0 },
  35. { 0, -2, 100, 30, 0 },
  36. { 0, -2, 83, 47, 0 },
  37. { 0, 64, 64, 0, 0 },
  38. { 0, 47, 83, -2, 0 },
  39. { 0, 30, 100, -2, 0 },
  40. { 0, 16, 112, 0, 0 },
  41. };
  42. static const struct dispc_coef coef3_M10[8] = {
  43. { 0, 10, 108, 10, 0 },
  44. { 0, 3, 104, 21, 0 },
  45. { 0, 0, 94, 34, 0 },
  46. { 0, -1, 80, 49, 0 },
  47. { 0, 64, 64, 0, 0 },
  48. { 0, 49, 80, -1, 0 },
  49. { 0, 34, 94, 0, 0 },
  50. { 0, 21, 104, 3, 0 },
  51. };
  52. static const struct dispc_coef coef3_M11[8] = {
  53. { 0, 14, 100, 14, 0 },
  54. { 0, 6, 98, 24, 0 },
  55. { 0, 2, 90, 36, 0 },
  56. { 0, 0, 78, 50, 0 },
  57. { 0, 64, 64, 0, 0 },
  58. { 0, 50, 78, 0, 0 },
  59. { 0, 36, 90, 2, 0 },
  60. { 0, 24, 98, 6, 0 },
  61. };
  62. static const struct dispc_coef coef3_M12[8] = {
  63. { 0, 16, 96, 16, 0 },
  64. { 0, 9, 93, 26, 0 },
  65. { 0, 4, 86, 38, 0 },
  66. { 0, 1, 76, 51, 0 },
  67. { 0, 64, 64, 0, 0 },
  68. { 0, 51, 76, 1, 0 },
  69. { 0, 38, 86, 4, 0 },
  70. { 0, 26, 93, 9, 0 },
  71. };
  72. static const struct dispc_coef coef3_M13[8] = {
  73. { 0, 18, 92, 18, 0 },
  74. { 0, 10, 90, 28, 0 },
  75. { 0, 5, 83, 40, 0 },
  76. { 0, 1, 75, 52, 0 },
  77. { 0, 64, 64, 0, 0 },
  78. { 0, 52, 75, 1, 0 },
  79. { 0, 40, 83, 5, 0 },
  80. { 0, 28, 90, 10, 0 },
  81. };
  82. static const struct dispc_coef coef3_M14[8] = {
  83. { 0, 20, 88, 20, 0 },
  84. { 0, 12, 86, 30, 0 },
  85. { 0, 6, 81, 41, 0 },
  86. { 0, 2, 74, 52, 0 },
  87. { 0, 64, 64, 0, 0 },
  88. { 0, 52, 74, 2, 0 },
  89. { 0, 41, 81, 6, 0 },
  90. { 0, 30, 86, 12, 0 },
  91. };
  92. static const struct dispc_coef coef3_M16[8] = {
  93. { 0, 22, 84, 22, 0 },
  94. { 0, 14, 82, 32, 0 },
  95. { 0, 8, 78, 42, 0 },
  96. { 0, 3, 72, 53, 0 },
  97. { 0, 64, 64, 0, 0 },
  98. { 0, 53, 72, 3, 0 },
  99. { 0, 42, 78, 8, 0 },
  100. { 0, 32, 82, 14, 0 },
  101. };
  102. static const struct dispc_coef coef3_M19[8] = {
  103. { 0, 24, 80, 24, 0 },
  104. { 0, 16, 79, 33, 0 },
  105. { 0, 9, 76, 43, 0 },
  106. { 0, 4, 70, 54, 0 },
  107. { 0, 64, 64, 0, 0 },
  108. { 0, 54, 70, 4, 0 },
  109. { 0, 43, 76, 9, 0 },
  110. { 0, 33, 79, 16, 0 },
  111. };
  112. static const struct dispc_coef coef3_M22[8] = {
  113. { 0, 25, 78, 25, 0 },
  114. { 0, 17, 77, 34, 0 },
  115. { 0, 10, 74, 44, 0 },
  116. { 0, 5, 69, 54, 0 },
  117. { 0, 64, 64, 0, 0 },
  118. { 0, 54, 69, 5, 0 },
  119. { 0, 44, 74, 10, 0 },
  120. { 0, 34, 77, 17, 0 },
  121. };
  122. static const struct dispc_coef coef3_M26[8] = {
  123. { 0, 26, 76, 26, 0 },
  124. { 0, 19, 74, 35, 0 },
  125. { 0, 11, 72, 45, 0 },
  126. { 0, 5, 69, 54, 0 },
  127. { 0, 64, 64, 0, 0 },
  128. { 0, 54, 69, 5, 0 },
  129. { 0, 45, 72, 11, 0 },
  130. { 0, 35, 74, 19, 0 },
  131. };
  132. static const struct dispc_coef coef3_M32[8] = {
  133. { 0, 27, 74, 27, 0 },
  134. { 0, 19, 73, 36, 0 },
  135. { 0, 12, 71, 45, 0 },
  136. { 0, 6, 68, 54, 0 },
  137. { 0, 64, 64, 0, 0 },
  138. { 0, 54, 68, 6, 0 },
  139. { 0, 45, 71, 12, 0 },
  140. { 0, 36, 73, 19, 0 },
  141. };
  142. static const struct dispc_coef coef5_M8[8] = {
  143. { 0, 0, 128, 0, 0 },
  144. { -2, 14, 125, -10, 1 },
  145. { -6, 33, 114, -15, 2 },
  146. { -10, 55, 98, -16, 1 },
  147. { 0, -14, 78, 78, -14 },
  148. { 1, -16, 98, 55, -10 },
  149. { 2, -15, 114, 33, -6 },
  150. { 1, -10, 125, 14, -2 },
  151. };
  152. static const struct dispc_coef coef5_M9[8] = {
  153. { -3, 10, 114, 10, -3 },
  154. { -6, 24, 111, 0, -1 },
  155. { -8, 40, 103, -7, 0 },
  156. { -11, 58, 91, -11, 1 },
  157. { 0, -12, 76, 76, -12 },
  158. { 1, -11, 91, 58, -11 },
  159. { 0, -7, 103, 40, -8 },
  160. { -1, 0, 111, 24, -6 },
  161. };
  162. static const struct dispc_coef coef5_M10[8] = {
  163. { -4, 18, 100, 18, -4 },
  164. { -6, 30, 99, 8, -3 },
  165. { -8, 44, 93, 0, -1 },
  166. { -9, 58, 84, -5, 0 },
  167. { 0, -8, 72, 72, -8 },
  168. { 0, -5, 84, 58, -9 },
  169. { -1, 0, 93, 44, -8 },
  170. { -3, 8, 99, 30, -6 },
  171. };
  172. static const struct dispc_coef coef5_M11[8] = {
  173. { -5, 23, 92, 23, -5 },
  174. { -6, 34, 90, 13, -3 },
  175. { -6, 45, 85, 6, -2 },
  176. { -6, 57, 78, 0, -1 },
  177. { 0, -4, 68, 68, -4 },
  178. { -1, 0, 78, 57, -6 },
  179. { -2, 6, 85, 45, -6 },
  180. { -3, 13, 90, 34, -6 },
  181. };
  182. static const struct dispc_coef coef5_M12[8] = {
  183. { -4, 26, 84, 26, -4 },
  184. { -5, 36, 82, 18, -3 },
  185. { -4, 46, 78, 10, -2 },
  186. { -3, 55, 72, 5, -1 },
  187. { 0, 0, 64, 64, 0 },
  188. { -1, 5, 72, 55, -3 },
  189. { -2, 10, 78, 46, -4 },
  190. { -3, 18, 82, 36, -5 },
  191. };
  192. static const struct dispc_coef coef5_M13[8] = {
  193. { -3, 28, 78, 28, -3 },
  194. { -3, 37, 76, 21, -3 },
  195. { -2, 45, 73, 14, -2 },
  196. { 0, 53, 68, 8, -1 },
  197. { 0, 3, 61, 61, 3 },
  198. { -1, 8, 68, 53, 0 },
  199. { -2, 14, 73, 45, -2 },
  200. { -3, 21, 76, 37, -3 },
  201. };
  202. static const struct dispc_coef coef5_M14[8] = {
  203. { -2, 30, 72, 30, -2 },
  204. { -1, 37, 71, 23, -2 },
  205. { 0, 45, 69, 16, -2 },
  206. { 3, 52, 64, 10, -1 },
  207. { 0, 6, 58, 58, 6 },
  208. { -1, 10, 64, 52, 3 },
  209. { -2, 16, 69, 45, 0 },
  210. { -2, 23, 71, 37, -1 },
  211. };
  212. static const struct dispc_coef coef5_M16[8] = {
  213. { 0, 31, 66, 31, 0 },
  214. { 1, 38, 65, 25, -1 },
  215. { 3, 44, 62, 20, -1 },
  216. { 6, 49, 59, 14, 0 },
  217. { 0, 10, 54, 54, 10 },
  218. { 0, 14, 59, 49, 6 },
  219. { -1, 20, 62, 44, 3 },
  220. { -1, 25, 65, 38, 1 },
  221. };
  222. static const struct dispc_coef coef5_M19[8] = {
  223. { 3, 32, 58, 32, 3 },
  224. { 4, 38, 58, 27, 1 },
  225. { 7, 42, 55, 23, 1 },
  226. { 10, 46, 54, 18, 0 },
  227. { 0, 14, 50, 50, 14 },
  228. { 0, 18, 54, 46, 10 },
  229. { 1, 23, 55, 42, 7 },
  230. { 1, 27, 58, 38, 4 },
  231. };
  232. static const struct dispc_coef coef5_M22[8] = {
  233. { 4, 33, 54, 33, 4 },
  234. { 6, 37, 54, 28, 3 },
  235. { 9, 41, 53, 24, 1 },
  236. { 12, 45, 51, 20, 0 },
  237. { 0, 16, 48, 48, 16 },
  238. { 0, 20, 51, 45, 12 },
  239. { 1, 24, 53, 41, 9 },
  240. { 3, 28, 54, 37, 6 },
  241. };
  242. static const struct dispc_coef coef5_M26[8] = {
  243. { 6, 33, 50, 33, 6 },
  244. { 8, 36, 51, 29, 4 },
  245. { 11, 40, 50, 25, 2 },
  246. { 14, 43, 48, 22, 1 },
  247. { 0, 18, 46, 46, 18 },
  248. { 1, 22, 48, 43, 14 },
  249. { 2, 25, 50, 40, 11 },
  250. { 4, 29, 51, 36, 8 },
  251. };
  252. static const struct dispc_coef coef5_M32[8] = {
  253. { 7, 33, 48, 33, 7 },
  254. { 10, 36, 48, 29, 5 },
  255. { 13, 39, 47, 26, 3 },
  256. { 16, 42, 46, 23, 1 },
  257. { 0, 19, 45, 45, 19 },
  258. { 1, 23, 46, 42, 16 },
  259. { 3, 26, 47, 39, 13 },
  260. { 5, 29, 48, 36, 10 },
  261. };
  262. const struct dispc_coef *dispc_ovl_get_scale_coef(int inc, int five_taps)
  263. {
  264. int i;
  265. static const struct {
  266. int Mmin;
  267. int Mmax;
  268. const struct dispc_coef *coef_3;
  269. const struct dispc_coef *coef_5;
  270. } coefs[] = {
  271. { 27, 32, coef3_M32, coef5_M32 },
  272. { 23, 26, coef3_M26, coef5_M26 },
  273. { 20, 22, coef3_M22, coef5_M22 },
  274. { 17, 19, coef3_M19, coef5_M19 },
  275. { 15, 16, coef3_M16, coef5_M16 },
  276. { 14, 14, coef3_M14, coef5_M14 },
  277. { 13, 13, coef3_M13, coef5_M13 },
  278. { 12, 12, coef3_M12, coef5_M12 },
  279. { 11, 11, coef3_M11, coef5_M11 },
  280. { 10, 10, coef3_M10, coef5_M10 },
  281. { 9, 9, coef3_M9, coef5_M9 },
  282. { 4, 8, coef3_M8, coef5_M8 },
  283. /*
  284. * When upscaling more than two times, blockiness and outlines
  285. * around the image are observed when M8 tables are used. M11,
  286. * M16 and M19 tables are used to prevent this.
  287. */
  288. { 3, 3, coef3_M11, coef5_M11 },
  289. { 2, 2, coef3_M16, coef5_M16 },
  290. { 0, 1, coef3_M19, coef5_M19 },
  291. };
  292. inc /= 128;
  293. for (i = 0; i < ARRAY_SIZE(coefs); ++i)
  294. if (inc >= coefs[i].Mmin && inc <= coefs[i].Mmax)
  295. return five_taps ? coefs[i].coef_5 : coefs[i].coef_3;
  296. return NULL;
  297. }