lossless_enc.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. // Copyright 2015 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // Image transform methods for lossless encoder.
  11. //
  12. // Authors: Vikas Arora (vikaas.arora@gmail.com)
  13. // Jyrki Alakuijala (jyrki@google.com)
  14. // Urvang Joshi (urvang@google.com)
  15. #include "./dsp.h"
  16. #include <assert.h>
  17. #include <math.h>
  18. #include <stdlib.h>
  19. #include "../dec/vp8li_dec.h"
  20. #include "../utils/endian_inl_utils.h"
  21. #include "./lossless.h"
  22. #include "./lossless_common.h"
  23. #include "./yuv.h"
  24. // lookup table for small values of log2(int)
  25. const float kLog2Table[LOG_LOOKUP_IDX_MAX] = {
  26. 0.0000000000000000f, 0.0000000000000000f,
  27. 1.0000000000000000f, 1.5849625007211560f,
  28. 2.0000000000000000f, 2.3219280948873621f,
  29. 2.5849625007211560f, 2.8073549220576041f,
  30. 3.0000000000000000f, 3.1699250014423121f,
  31. 3.3219280948873621f, 3.4594316186372973f,
  32. 3.5849625007211560f, 3.7004397181410921f,
  33. 3.8073549220576041f, 3.9068905956085187f,
  34. 4.0000000000000000f, 4.0874628412503390f,
  35. 4.1699250014423121f, 4.2479275134435852f,
  36. 4.3219280948873626f, 4.3923174227787606f,
  37. 4.4594316186372973f, 4.5235619560570130f,
  38. 4.5849625007211560f, 4.6438561897747243f,
  39. 4.7004397181410917f, 4.7548875021634682f,
  40. 4.8073549220576037f, 4.8579809951275718f,
  41. 4.9068905956085187f, 4.9541963103868749f,
  42. 5.0000000000000000f, 5.0443941193584533f,
  43. 5.0874628412503390f, 5.1292830169449663f,
  44. 5.1699250014423121f, 5.2094533656289501f,
  45. 5.2479275134435852f, 5.2854022188622487f,
  46. 5.3219280948873626f, 5.3575520046180837f,
  47. 5.3923174227787606f, 5.4262647547020979f,
  48. 5.4594316186372973f, 5.4918530963296747f,
  49. 5.5235619560570130f, 5.5545888516776376f,
  50. 5.5849625007211560f, 5.6147098441152083f,
  51. 5.6438561897747243f, 5.6724253419714951f,
  52. 5.7004397181410917f, 5.7279204545631987f,
  53. 5.7548875021634682f, 5.7813597135246599f,
  54. 5.8073549220576037f, 5.8328900141647412f,
  55. 5.8579809951275718f, 5.8826430493618415f,
  56. 5.9068905956085187f, 5.9307373375628866f,
  57. 5.9541963103868749f, 5.9772799234999167f,
  58. 6.0000000000000000f, 6.0223678130284543f,
  59. 6.0443941193584533f, 6.0660891904577720f,
  60. 6.0874628412503390f, 6.1085244567781691f,
  61. 6.1292830169449663f, 6.1497471195046822f,
  62. 6.1699250014423121f, 6.1898245588800175f,
  63. 6.2094533656289501f, 6.2288186904958804f,
  64. 6.2479275134435852f, 6.2667865406949010f,
  65. 6.2854022188622487f, 6.3037807481771030f,
  66. 6.3219280948873626f, 6.3398500028846243f,
  67. 6.3575520046180837f, 6.3750394313469245f,
  68. 6.3923174227787606f, 6.4093909361377017f,
  69. 6.4262647547020979f, 6.4429434958487279f,
  70. 6.4594316186372973f, 6.4757334309663976f,
  71. 6.4918530963296747f, 6.5077946401986963f,
  72. 6.5235619560570130f, 6.5391588111080309f,
  73. 6.5545888516776376f, 6.5698556083309478f,
  74. 6.5849625007211560f, 6.5999128421871278f,
  75. 6.6147098441152083f, 6.6293566200796094f,
  76. 6.6438561897747243f, 6.6582114827517946f,
  77. 6.6724253419714951f, 6.6865005271832185f,
  78. 6.7004397181410917f, 6.7142455176661224f,
  79. 6.7279204545631987f, 6.7414669864011464f,
  80. 6.7548875021634682f, 6.7681843247769259f,
  81. 6.7813597135246599f, 6.7944158663501061f,
  82. 6.8073549220576037f, 6.8201789624151878f,
  83. 6.8328900141647412f, 6.8454900509443747f,
  84. 6.8579809951275718f, 6.8703647195834047f,
  85. 6.8826430493618415f, 6.8948177633079437f,
  86. 6.9068905956085187f, 6.9188632372745946f,
  87. 6.9307373375628866f, 6.9425145053392398f,
  88. 6.9541963103868749f, 6.9657842846620869f,
  89. 6.9772799234999167f, 6.9886846867721654f,
  90. 7.0000000000000000f, 7.0112272554232539f,
  91. 7.0223678130284543f, 7.0334230015374501f,
  92. 7.0443941193584533f, 7.0552824355011898f,
  93. 7.0660891904577720f, 7.0768155970508308f,
  94. 7.0874628412503390f, 7.0980320829605263f,
  95. 7.1085244567781691f, 7.1189410727235076f,
  96. 7.1292830169449663f, 7.1395513523987936f,
  97. 7.1497471195046822f, 7.1598713367783890f,
  98. 7.1699250014423121f, 7.1799090900149344f,
  99. 7.1898245588800175f, 7.1996723448363644f,
  100. 7.2094533656289501f, 7.2191685204621611f,
  101. 7.2288186904958804f, 7.2384047393250785f,
  102. 7.2479275134435852f, 7.2573878426926521f,
  103. 7.2667865406949010f, 7.2761244052742375f,
  104. 7.2854022188622487f, 7.2946207488916270f,
  105. 7.3037807481771030f, 7.3128829552843557f,
  106. 7.3219280948873626f, 7.3309168781146167f,
  107. 7.3398500028846243f, 7.3487281542310771f,
  108. 7.3575520046180837f, 7.3663222142458160f,
  109. 7.3750394313469245f, 7.3837042924740519f,
  110. 7.3923174227787606f, 7.4008794362821843f,
  111. 7.4093909361377017f, 7.4178525148858982f,
  112. 7.4262647547020979f, 7.4346282276367245f,
  113. 7.4429434958487279f, 7.4512111118323289f,
  114. 7.4594316186372973f, 7.4676055500829976f,
  115. 7.4757334309663976f, 7.4838157772642563f,
  116. 7.4918530963296747f, 7.4998458870832056f,
  117. 7.5077946401986963f, 7.5156998382840427f,
  118. 7.5235619560570130f, 7.5313814605163118f,
  119. 7.5391588111080309f, 7.5468944598876364f,
  120. 7.5545888516776376f, 7.5622424242210728f,
  121. 7.5698556083309478f, 7.5774288280357486f,
  122. 7.5849625007211560f, 7.5924570372680806f,
  123. 7.5999128421871278f, 7.6073303137496104f,
  124. 7.6147098441152083f, 7.6220518194563764f,
  125. 7.6293566200796094f, 7.6366246205436487f,
  126. 7.6438561897747243f, 7.6510516911789281f,
  127. 7.6582114827517946f, 7.6653359171851764f,
  128. 7.6724253419714951f, 7.6794800995054464f,
  129. 7.6865005271832185f, 7.6934869574993252f,
  130. 7.7004397181410917f, 7.7073591320808825f,
  131. 7.7142455176661224f, 7.7210991887071855f,
  132. 7.7279204545631987f, 7.7347096202258383f,
  133. 7.7414669864011464f, 7.7481928495894605f,
  134. 7.7548875021634682f, 7.7615512324444795f,
  135. 7.7681843247769259f, 7.7747870596011736f,
  136. 7.7813597135246599f, 7.7879025593914317f,
  137. 7.7944158663501061f, 7.8008998999203047f,
  138. 7.8073549220576037f, 7.8137811912170374f,
  139. 7.8201789624151878f, 7.8265484872909150f,
  140. 7.8328900141647412f, 7.8392037880969436f,
  141. 7.8454900509443747f, 7.8517490414160571f,
  142. 7.8579809951275718f, 7.8641861446542797f,
  143. 7.8703647195834047f, 7.8765169465649993f,
  144. 7.8826430493618415f, 7.8887432488982591f,
  145. 7.8948177633079437f, 7.9008668079807486f,
  146. 7.9068905956085187f, 7.9128893362299619f,
  147. 7.9188632372745946f, 7.9248125036057812f,
  148. 7.9307373375628866f, 7.9366379390025709f,
  149. 7.9425145053392398f, 7.9483672315846778f,
  150. 7.9541963103868749f, 7.9600019320680805f,
  151. 7.9657842846620869f, 7.9715435539507719f,
  152. 7.9772799234999167f, 7.9829935746943103f,
  153. 7.9886846867721654f, 7.9943534368588577f
  154. };
  155. const float kSLog2Table[LOG_LOOKUP_IDX_MAX] = {
  156. 0.00000000f, 0.00000000f, 2.00000000f, 4.75488750f,
  157. 8.00000000f, 11.60964047f, 15.50977500f, 19.65148445f,
  158. 24.00000000f, 28.52932501f, 33.21928095f, 38.05374781f,
  159. 43.01955001f, 48.10571634f, 53.30296891f, 58.60335893f,
  160. 64.00000000f, 69.48686830f, 75.05865003f, 80.71062276f,
  161. 86.43856190f, 92.23866588f, 98.10749561f, 104.04192499f,
  162. 110.03910002f, 116.09640474f, 122.21143267f, 128.38196256f,
  163. 134.60593782f, 140.88144886f, 147.20671787f, 153.58008562f,
  164. 160.00000000f, 166.46500594f, 172.97373660f, 179.52490559f,
  165. 186.11730005f, 192.74977453f, 199.42124551f, 206.13068654f,
  166. 212.87712380f, 219.65963219f, 226.47733176f, 233.32938445f,
  167. 240.21499122f, 247.13338933f, 254.08384998f, 261.06567603f,
  168. 268.07820003f, 275.12078236f, 282.19280949f, 289.29369244f,
  169. 296.42286534f, 303.57978409f, 310.76392512f, 317.97478424f,
  170. 325.21187564f, 332.47473081f, 339.76289772f, 347.07593991f,
  171. 354.41343574f, 361.77497759f, 369.16017124f, 376.56863518f,
  172. 384.00000000f, 391.45390785f, 398.93001188f, 406.42797576f,
  173. 413.94747321f, 421.48818752f, 429.04981119f, 436.63204548f,
  174. 444.23460010f, 451.85719280f, 459.49954906f, 467.16140179f,
  175. 474.84249102f, 482.54256363f, 490.26137307f, 497.99867911f,
  176. 505.75424759f, 513.52785023f, 521.31926438f, 529.12827280f,
  177. 536.95466351f, 544.79822957f, 552.65876890f, 560.53608414f,
  178. 568.42998244f, 576.34027536f, 584.26677867f, 592.20931226f,
  179. 600.16769996f, 608.14176943f, 616.13135206f, 624.13628279f,
  180. 632.15640007f, 640.19154569f, 648.24156472f, 656.30630539f,
  181. 664.38561898f, 672.47935976f, 680.58738488f, 688.70955430f,
  182. 696.84573069f, 704.99577935f, 713.15956818f, 721.33696754f,
  183. 729.52785023f, 737.73209140f, 745.94956849f, 754.18016116f,
  184. 762.42375127f, 770.68022275f, 778.94946161f, 787.23135586f,
  185. 795.52579543f, 803.83267219f, 812.15187982f, 820.48331383f,
  186. 828.82687147f, 837.18245171f, 845.54995518f, 853.92928416f,
  187. 862.32034249f, 870.72303558f, 879.13727036f, 887.56295522f,
  188. 896.00000000f, 904.44831595f, 912.90781569f, 921.37841320f,
  189. 929.86002376f, 938.35256392f, 946.85595152f, 955.37010560f,
  190. 963.89494641f, 972.43039537f, 980.97637504f, 989.53280911f,
  191. 998.09962237f, 1006.67674069f, 1015.26409097f, 1023.86160116f,
  192. 1032.46920021f, 1041.08681805f, 1049.71438560f, 1058.35183469f,
  193. 1066.99909811f, 1075.65610955f, 1084.32280357f, 1092.99911564f,
  194. 1101.68498204f, 1110.38033993f, 1119.08512727f, 1127.79928282f,
  195. 1136.52274614f, 1145.25545758f, 1153.99735821f, 1162.74838989f,
  196. 1171.50849518f, 1180.27761738f, 1189.05570047f, 1197.84268914f,
  197. 1206.63852876f, 1215.44316535f, 1224.25654560f, 1233.07861684f,
  198. 1241.90932703f, 1250.74862473f, 1259.59645914f, 1268.45278005f,
  199. 1277.31753781f, 1286.19068338f, 1295.07216828f, 1303.96194457f,
  200. 1312.85996488f, 1321.76618236f, 1330.68055071f, 1339.60302413f,
  201. 1348.53355734f, 1357.47210556f, 1366.41862452f, 1375.37307041f,
  202. 1384.33539991f, 1393.30557020f, 1402.28353887f, 1411.26926400f,
  203. 1420.26270412f, 1429.26381818f, 1438.27256558f, 1447.28890615f,
  204. 1456.31280014f, 1465.34420819f, 1474.38309138f, 1483.42941118f,
  205. 1492.48312945f, 1501.54420843f, 1510.61261078f, 1519.68829949f,
  206. 1528.77123795f, 1537.86138993f, 1546.95871952f, 1556.06319119f,
  207. 1565.17476976f, 1574.29342040f, 1583.41910860f, 1592.55180020f,
  208. 1601.69146137f, 1610.83805860f, 1619.99155871f, 1629.15192882f,
  209. 1638.31913637f, 1647.49314911f, 1656.67393509f, 1665.86146266f,
  210. 1675.05570047f, 1684.25661744f, 1693.46418280f, 1702.67836605f,
  211. 1711.89913698f, 1721.12646563f, 1730.36032233f, 1739.60067768f,
  212. 1748.84750254f, 1758.10076802f, 1767.36044551f, 1776.62650662f,
  213. 1785.89892323f, 1795.17766747f, 1804.46271172f, 1813.75402857f,
  214. 1823.05159087f, 1832.35537170f, 1841.66534438f, 1850.98148244f,
  215. 1860.30375965f, 1869.63214999f, 1878.96662767f, 1888.30716711f,
  216. 1897.65374295f, 1907.00633003f, 1916.36490342f, 1925.72943838f,
  217. 1935.09991037f, 1944.47629506f, 1953.85856831f, 1963.24670620f,
  218. 1972.64068498f, 1982.04048108f, 1991.44607117f, 2000.85743204f,
  219. 2010.27454072f, 2019.69737440f, 2029.12591044f, 2038.56012640f
  220. };
  221. const VP8LPrefixCode kPrefixEncodeCode[PREFIX_LOOKUP_IDX_MAX] = {
  222. { 0, 0}, { 0, 0}, { 1, 0}, { 2, 0}, { 3, 0}, { 4, 1}, { 4, 1}, { 5, 1},
  223. { 5, 1}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 7, 2}, { 7, 2}, { 7, 2},
  224. { 7, 2}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3},
  225. { 8, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3},
  226. { 9, 3}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
  227. {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
  228. {10, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
  229. {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
  230. {11, 4}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
  231. {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
  232. {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
  233. {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
  234. {12, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
  235. {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
  236. {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
  237. {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
  238. {13, 5}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  239. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  240. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  241. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  242. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  243. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  244. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  245. {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
  246. {14, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  247. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  248. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  249. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  250. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  251. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  252. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  253. {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
  254. {15, 6}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  255. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  256. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  257. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  258. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  259. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  260. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  261. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  262. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  263. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  264. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  265. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  266. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  267. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  268. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  269. {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
  270. {16, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  271. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  272. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  273. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  274. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  275. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  276. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  277. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  278. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  279. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  280. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  281. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  282. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  283. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  284. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  285. {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
  286. };
  287. const uint8_t kPrefixEncodeExtraBitsValue[PREFIX_LOOKUP_IDX_MAX] = {
  288. 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2, 3, 0, 1, 2, 3,
  289. 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
  290. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  291. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  292. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  293. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  294. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  295. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  296. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  297. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  298. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  299. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  300. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  301. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  302. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  303. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  304. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  305. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  306. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  307. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  308. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  309. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  310. 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
  311. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
  312. 127,
  313. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  314. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  315. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  316. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  317. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  318. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  319. 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
  320. 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126
  321. };
  322. static float FastSLog2Slow_C(uint32_t v) {
  323. assert(v >= LOG_LOOKUP_IDX_MAX);
  324. if (v < APPROX_LOG_WITH_CORRECTION_MAX) {
  325. #if !defined(WEBP_HAVE_SLOW_CLZ_CTZ)
  326. // use clz if available
  327. const int log_cnt = BitsLog2Floor(v) - 7;
  328. const uint32_t y = 1 << log_cnt;
  329. int correction = 0;
  330. const float v_f = (float)v;
  331. const uint32_t orig_v = v;
  332. v >>= log_cnt;
  333. #else
  334. int log_cnt = 0;
  335. uint32_t y = 1;
  336. int correction = 0;
  337. const float v_f = (float)v;
  338. const uint32_t orig_v = v;
  339. do {
  340. ++log_cnt;
  341. v = v >> 1;
  342. y = y << 1;
  343. } while (v >= LOG_LOOKUP_IDX_MAX);
  344. #endif
  345. // vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256
  346. // Xf = floor(Xf) * (1 + (v % y) / v)
  347. // log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v)
  348. // The correction factor: log(1 + d) ~ d; for very small d values, so
  349. // log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
  350. // LOG_2_RECIPROCAL ~ 23/16
  351. correction = (23 * (orig_v & (y - 1))) >> 4;
  352. return v_f * (kLog2Table[v] + log_cnt) + correction;
  353. } else {
  354. return (float)(LOG_2_RECIPROCAL * v * log((double)v));
  355. }
  356. }
  357. static float FastLog2Slow_C(uint32_t v) {
  358. assert(v >= LOG_LOOKUP_IDX_MAX);
  359. if (v < APPROX_LOG_WITH_CORRECTION_MAX) {
  360. #if !defined(WEBP_HAVE_SLOW_CLZ_CTZ)
  361. // use clz if available
  362. const int log_cnt = BitsLog2Floor(v) - 7;
  363. const uint32_t y = 1 << log_cnt;
  364. const uint32_t orig_v = v;
  365. double log_2;
  366. v >>= log_cnt;
  367. #else
  368. int log_cnt = 0;
  369. uint32_t y = 1;
  370. const uint32_t orig_v = v;
  371. double log_2;
  372. do {
  373. ++log_cnt;
  374. v = v >> 1;
  375. y = y << 1;
  376. } while (v >= LOG_LOOKUP_IDX_MAX);
  377. #endif
  378. log_2 = kLog2Table[v] + log_cnt;
  379. if (orig_v >= APPROX_LOG_MAX) {
  380. // Since the division is still expensive, add this correction factor only
  381. // for large values of 'v'.
  382. const int correction = (23 * (orig_v & (y - 1))) >> 4;
  383. log_2 += (double)correction / orig_v;
  384. }
  385. return (float)log_2;
  386. } else {
  387. return (float)(LOG_2_RECIPROCAL * log((double)v));
  388. }
  389. }
  390. //------------------------------------------------------------------------------
  391. // Methods to calculate Entropy (Shannon).
  392. // Compute the combined Shanon's entropy for distribution {X} and {X+Y}
  393. static float CombinedShannonEntropy_C(const int X[256], const int Y[256]) {
  394. int i;
  395. double retval = 0.;
  396. int sumX = 0, sumXY = 0;
  397. for (i = 0; i < 256; ++i) {
  398. const int x = X[i];
  399. if (x != 0) {
  400. const int xy = x + Y[i];
  401. sumX += x;
  402. retval -= VP8LFastSLog2(x);
  403. sumXY += xy;
  404. retval -= VP8LFastSLog2(xy);
  405. } else if (Y[i] != 0) {
  406. sumXY += Y[i];
  407. retval -= VP8LFastSLog2(Y[i]);
  408. }
  409. }
  410. retval += VP8LFastSLog2(sumX) + VP8LFastSLog2(sumXY);
  411. return (float)retval;
  412. }
  413. void VP8LBitEntropyInit(VP8LBitEntropy* const entropy) {
  414. entropy->entropy = 0.;
  415. entropy->sum = 0;
  416. entropy->nonzeros = 0;
  417. entropy->max_val = 0;
  418. entropy->nonzero_code = VP8L_NON_TRIVIAL_SYM;
  419. }
  420. void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n,
  421. VP8LBitEntropy* const entropy) {
  422. int i;
  423. VP8LBitEntropyInit(entropy);
  424. for (i = 0; i < n; ++i) {
  425. if (array[i] != 0) {
  426. entropy->sum += array[i];
  427. entropy->nonzero_code = i;
  428. ++entropy->nonzeros;
  429. entropy->entropy -= VP8LFastSLog2(array[i]);
  430. if (entropy->max_val < array[i]) {
  431. entropy->max_val = array[i];
  432. }
  433. }
  434. }
  435. entropy->entropy += VP8LFastSLog2(entropy->sum);
  436. }
  437. static WEBP_INLINE void GetEntropyUnrefinedHelper(
  438. uint32_t val, int i, uint32_t* const val_prev, int* const i_prev,
  439. VP8LBitEntropy* const bit_entropy, VP8LStreaks* const stats) {
  440. const int streak = i - *i_prev;
  441. // Gather info for the bit entropy.
  442. if (*val_prev != 0) {
  443. bit_entropy->sum += (*val_prev) * streak;
  444. bit_entropy->nonzeros += streak;
  445. bit_entropy->nonzero_code = *i_prev;
  446. bit_entropy->entropy -= VP8LFastSLog2(*val_prev) * streak;
  447. if (bit_entropy->max_val < *val_prev) {
  448. bit_entropy->max_val = *val_prev;
  449. }
  450. }
  451. // Gather info for the Huffman cost.
  452. stats->counts[*val_prev != 0] += (streak > 3);
  453. stats->streaks[*val_prev != 0][(streak > 3)] += streak;
  454. *val_prev = val;
  455. *i_prev = i;
  456. }
  457. static void GetEntropyUnrefined_C(const uint32_t X[], int length,
  458. VP8LBitEntropy* const bit_entropy,
  459. VP8LStreaks* const stats) {
  460. int i;
  461. int i_prev = 0;
  462. uint32_t x_prev = X[0];
  463. memset(stats, 0, sizeof(*stats));
  464. VP8LBitEntropyInit(bit_entropy);
  465. for (i = 1; i < length; ++i) {
  466. const uint32_t x = X[i];
  467. if (x != x_prev) {
  468. GetEntropyUnrefinedHelper(x, i, &x_prev, &i_prev, bit_entropy, stats);
  469. }
  470. }
  471. GetEntropyUnrefinedHelper(0, i, &x_prev, &i_prev, bit_entropy, stats);
  472. bit_entropy->entropy += VP8LFastSLog2(bit_entropy->sum);
  473. }
  474. static void GetCombinedEntropyUnrefined_C(const uint32_t X[],
  475. const uint32_t Y[],
  476. int length,
  477. VP8LBitEntropy* const bit_entropy,
  478. VP8LStreaks* const stats) {
  479. int i = 1;
  480. int i_prev = 0;
  481. uint32_t xy_prev = X[0] + Y[0];
  482. memset(stats, 0, sizeof(*stats));
  483. VP8LBitEntropyInit(bit_entropy);
  484. for (i = 1; i < length; ++i) {
  485. const uint32_t xy = X[i] + Y[i];
  486. if (xy != xy_prev) {
  487. GetEntropyUnrefinedHelper(xy, i, &xy_prev, &i_prev, bit_entropy, stats);
  488. }
  489. }
  490. GetEntropyUnrefinedHelper(0, i, &xy_prev, &i_prev, bit_entropy, stats);
  491. bit_entropy->entropy += VP8LFastSLog2(bit_entropy->sum);
  492. }
  493. //------------------------------------------------------------------------------
  494. void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels) {
  495. int i;
  496. for (i = 0; i < num_pixels; ++i) {
  497. const int argb = argb_data[i];
  498. const int green = (argb >> 8) & 0xff;
  499. const uint32_t new_r = (((argb >> 16) & 0xff) - green) & 0xff;
  500. const uint32_t new_b = (((argb >> 0) & 0xff) - green) & 0xff;
  501. argb_data[i] = (argb & 0xff00ff00u) | (new_r << 16) | new_b;
  502. }
  503. }
  504. static WEBP_INLINE int ColorTransformDelta(int8_t color_pred, int8_t color) {
  505. return ((int)color_pred * color) >> 5;
  506. }
  507. static WEBP_INLINE int8_t U32ToS8(uint32_t v) {
  508. return (int8_t)(v & 0xff);
  509. }
  510. void VP8LTransformColor_C(const VP8LMultipliers* const m, uint32_t* data,
  511. int num_pixels) {
  512. int i;
  513. for (i = 0; i < num_pixels; ++i) {
  514. const uint32_t argb = data[i];
  515. const int8_t green = U32ToS8(argb >> 8);
  516. const int8_t red = U32ToS8(argb >> 16);
  517. int new_red = red & 0xff;
  518. int new_blue = argb & 0xff;
  519. new_red -= ColorTransformDelta(m->green_to_red_, green);
  520. new_red &= 0xff;
  521. new_blue -= ColorTransformDelta(m->green_to_blue_, green);
  522. new_blue -= ColorTransformDelta(m->red_to_blue_, red);
  523. new_blue &= 0xff;
  524. data[i] = (argb & 0xff00ff00u) | (new_red << 16) | (new_blue);
  525. }
  526. }
  527. static WEBP_INLINE uint8_t TransformColorRed(uint8_t green_to_red,
  528. uint32_t argb) {
  529. const int8_t green = U32ToS8(argb >> 8);
  530. int new_red = argb >> 16;
  531. new_red -= ColorTransformDelta(green_to_red, green);
  532. return (new_red & 0xff);
  533. }
  534. static WEBP_INLINE uint8_t TransformColorBlue(uint8_t green_to_blue,
  535. uint8_t red_to_blue,
  536. uint32_t argb) {
  537. const int8_t green = U32ToS8(argb >> 8);
  538. const int8_t red = U32ToS8(argb >> 16);
  539. uint8_t new_blue = argb & 0xff;
  540. new_blue -= ColorTransformDelta(green_to_blue, green);
  541. new_blue -= ColorTransformDelta(red_to_blue, red);
  542. return (new_blue & 0xff);
  543. }
  544. void VP8LCollectColorRedTransforms_C(const uint32_t* argb, int stride,
  545. int tile_width, int tile_height,
  546. int green_to_red, int histo[]) {
  547. while (tile_height-- > 0) {
  548. int x;
  549. for (x = 0; x < tile_width; ++x) {
  550. ++histo[TransformColorRed((uint8_t)green_to_red, argb[x])];
  551. }
  552. argb += stride;
  553. }
  554. }
  555. void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride,
  556. int tile_width, int tile_height,
  557. int green_to_blue, int red_to_blue,
  558. int histo[]) {
  559. while (tile_height-- > 0) {
  560. int x;
  561. for (x = 0; x < tile_width; ++x) {
  562. ++histo[TransformColorBlue((uint8_t)green_to_blue, (uint8_t)red_to_blue,
  563. argb[x])];
  564. }
  565. argb += stride;
  566. }
  567. }
  568. //------------------------------------------------------------------------------
  569. static int VectorMismatch_C(const uint32_t* const array1,
  570. const uint32_t* const array2, int length) {
  571. int match_len = 0;
  572. while (match_len < length && array1[match_len] == array2[match_len]) {
  573. ++match_len;
  574. }
  575. return match_len;
  576. }
  577. // Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
  578. void VP8LBundleColorMap_C(const uint8_t* const row, int width, int xbits,
  579. uint32_t* dst) {
  580. int x;
  581. if (xbits > 0) {
  582. const int bit_depth = 1 << (3 - xbits);
  583. const int mask = (1 << xbits) - 1;
  584. uint32_t code = 0xff000000;
  585. for (x = 0; x < width; ++x) {
  586. const int xsub = x & mask;
  587. if (xsub == 0) {
  588. code = 0xff000000;
  589. }
  590. code |= row[x] << (8 + bit_depth * xsub);
  591. dst[x >> xbits] = code;
  592. }
  593. } else {
  594. for (x = 0; x < width; ++x) dst[x] = 0xff000000 | (row[x] << 8);
  595. }
  596. }
  597. //------------------------------------------------------------------------------
  598. static double ExtraCost_C(const uint32_t* population, int length) {
  599. int i;
  600. double cost = 0.;
  601. for (i = 2; i < length - 2; ++i) cost += (i >> 1) * population[i + 2];
  602. return cost;
  603. }
  604. static double ExtraCostCombined_C(const uint32_t* X, const uint32_t* Y,
  605. int length) {
  606. int i;
  607. double cost = 0.;
  608. for (i = 2; i < length - 2; ++i) {
  609. const int xy = X[i + 2] + Y[i + 2];
  610. cost += (i >> 1) * xy;
  611. }
  612. return cost;
  613. }
  614. //------------------------------------------------------------------------------
  615. static void AddVector_C(const uint32_t* a, const uint32_t* b, uint32_t* out,
  616. int size) {
  617. int i;
  618. for (i = 0; i < size; ++i) out[i] = a[i] + b[i];
  619. }
  620. static void AddVectorEq_C(const uint32_t* a, uint32_t* out, int size) {
  621. int i;
  622. for (i = 0; i < size; ++i) out[i] += a[i];
  623. }
  624. #define ADD(X, ARG, LEN) do { \
  625. if (a->is_used_[X]) { \
  626. if (b->is_used_[X]) { \
  627. VP8LAddVector(a->ARG, b->ARG, out->ARG, (LEN)); \
  628. } else { \
  629. memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
  630. } \
  631. } else if (b->is_used_[X]) { \
  632. memcpy(&out->ARG[0], &b->ARG[0], (LEN) * sizeof(out->ARG[0])); \
  633. } else { \
  634. memset(&out->ARG[0], 0, (LEN) * sizeof(out->ARG[0])); \
  635. } \
  636. } while (0)
  637. #define ADD_EQ(X, ARG, LEN) do { \
  638. if (a->is_used_[X]) { \
  639. if (out->is_used_[X]) { \
  640. VP8LAddVectorEq(a->ARG, out->ARG, (LEN)); \
  641. } else { \
  642. memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
  643. } \
  644. } \
  645. } while (0)
  646. void VP8LHistogramAdd(const VP8LHistogram* const a,
  647. const VP8LHistogram* const b, VP8LHistogram* const out) {
  648. int i;
  649. const int literal_size = VP8LHistogramNumCodes(a->palette_code_bits_);
  650. assert(a->palette_code_bits_ == b->palette_code_bits_);
  651. if (b != out) {
  652. ADD(0, literal_, literal_size);
  653. ADD(1, red_, NUM_LITERAL_CODES);
  654. ADD(2, blue_, NUM_LITERAL_CODES);
  655. ADD(3, alpha_, NUM_LITERAL_CODES);
  656. ADD(4, distance_, NUM_DISTANCE_CODES);
  657. for (i = 0; i < 5; ++i) {
  658. out->is_used_[i] = (a->is_used_[i] | b->is_used_[i]);
  659. }
  660. } else {
  661. ADD_EQ(0, literal_, literal_size);
  662. ADD_EQ(1, red_, NUM_LITERAL_CODES);
  663. ADD_EQ(2, blue_, NUM_LITERAL_CODES);
  664. ADD_EQ(3, alpha_, NUM_LITERAL_CODES);
  665. ADD_EQ(4, distance_, NUM_DISTANCE_CODES);
  666. for (i = 0; i < 5; ++i) out->is_used_[i] |= a->is_used_[i];
  667. }
  668. }
  669. #undef ADD
  670. #undef ADD_EQ
  671. //------------------------------------------------------------------------------
  672. // Image transforms.
  673. static void PredictorSub0_C(const uint32_t* in, const uint32_t* upper,
  674. int num_pixels, uint32_t* out) {
  675. int i;
  676. for (i = 0; i < num_pixels; ++i) out[i] = VP8LSubPixels(in[i], ARGB_BLACK);
  677. (void)upper;
  678. }
  679. static void PredictorSub1_C(const uint32_t* in, const uint32_t* upper,
  680. int num_pixels, uint32_t* out) {
  681. int i;
  682. for (i = 0; i < num_pixels; ++i) out[i] = VP8LSubPixels(in[i], in[i - 1]);
  683. (void)upper;
  684. }
  685. // It subtracts the prediction from the input pixel and stores the residual
  686. // in the output pixel.
  687. #define GENERATE_PREDICTOR_SUB(PREDICTOR_I) \
  688. static void PredictorSub##PREDICTOR_I##_C(const uint32_t* in, \
  689. const uint32_t* upper, \
  690. int num_pixels, uint32_t* out) { \
  691. int x; \
  692. assert(upper != NULL); \
  693. for (x = 0; x < num_pixels; ++x) { \
  694. const uint32_t pred = \
  695. VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \
  696. out[x] = VP8LSubPixels(in[x], pred); \
  697. } \
  698. }
  699. GENERATE_PREDICTOR_SUB(2)
  700. GENERATE_PREDICTOR_SUB(3)
  701. GENERATE_PREDICTOR_SUB(4)
  702. GENERATE_PREDICTOR_SUB(5)
  703. GENERATE_PREDICTOR_SUB(6)
  704. GENERATE_PREDICTOR_SUB(7)
  705. GENERATE_PREDICTOR_SUB(8)
  706. GENERATE_PREDICTOR_SUB(9)
  707. GENERATE_PREDICTOR_SUB(10)
  708. GENERATE_PREDICTOR_SUB(11)
  709. GENERATE_PREDICTOR_SUB(12)
  710. GENERATE_PREDICTOR_SUB(13)
  711. //------------------------------------------------------------------------------
  712. VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
  713. VP8LTransformColorFunc VP8LTransformColor;
  714. VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
  715. VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
  716. VP8LFastLog2SlowFunc VP8LFastLog2Slow;
  717. VP8LFastLog2SlowFunc VP8LFastSLog2Slow;
  718. VP8LCostFunc VP8LExtraCost;
  719. VP8LCostCombinedFunc VP8LExtraCostCombined;
  720. VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
  721. VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
  722. VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;
  723. VP8LAddVectorFunc VP8LAddVector;
  724. VP8LAddVectorEqFunc VP8LAddVectorEq;
  725. VP8LVectorMismatchFunc VP8LVectorMismatch;
  726. VP8LBundleColorMapFunc VP8LBundleColorMap;
  727. VP8LPredictorAddSubFunc VP8LPredictorsSub[16];
  728. VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];
  729. extern void VP8LEncDspInitSSE2(void);
  730. extern void VP8LEncDspInitSSE41(void);
  731. extern void VP8LEncDspInitNEON(void);
  732. extern void VP8LEncDspInitMIPS32(void);
  733. extern void VP8LEncDspInitMIPSdspR2(void);
  734. extern void VP8LEncDspInitMSA(void);
  735. WEBP_DSP_INIT_FUNC(VP8LEncDspInit) {
  736. VP8LDspInit();
  737. #if !WEBP_NEON_OMIT_C_CODE
  738. VP8LSubtractGreenFromBlueAndRed = VP8LSubtractGreenFromBlueAndRed_C;
  739. VP8LTransformColor = VP8LTransformColor_C;
  740. #endif
  741. VP8LCollectColorBlueTransforms = VP8LCollectColorBlueTransforms_C;
  742. VP8LCollectColorRedTransforms = VP8LCollectColorRedTransforms_C;
  743. VP8LFastLog2Slow = FastLog2Slow_C;
  744. VP8LFastSLog2Slow = FastSLog2Slow_C;
  745. VP8LExtraCost = ExtraCost_C;
  746. VP8LExtraCostCombined = ExtraCostCombined_C;
  747. VP8LCombinedShannonEntropy = CombinedShannonEntropy_C;
  748. VP8LGetEntropyUnrefined = GetEntropyUnrefined_C;
  749. VP8LGetCombinedEntropyUnrefined = GetCombinedEntropyUnrefined_C;
  750. VP8LAddVector = AddVector_C;
  751. VP8LAddVectorEq = AddVectorEq_C;
  752. VP8LVectorMismatch = VectorMismatch_C;
  753. VP8LBundleColorMap = VP8LBundleColorMap_C;
  754. VP8LPredictorsSub[0] = PredictorSub0_C;
  755. VP8LPredictorsSub[1] = PredictorSub1_C;
  756. VP8LPredictorsSub[2] = PredictorSub2_C;
  757. VP8LPredictorsSub[3] = PredictorSub3_C;
  758. VP8LPredictorsSub[4] = PredictorSub4_C;
  759. VP8LPredictorsSub[5] = PredictorSub5_C;
  760. VP8LPredictorsSub[6] = PredictorSub6_C;
  761. VP8LPredictorsSub[7] = PredictorSub7_C;
  762. VP8LPredictorsSub[8] = PredictorSub8_C;
  763. VP8LPredictorsSub[9] = PredictorSub9_C;
  764. VP8LPredictorsSub[10] = PredictorSub10_C;
  765. VP8LPredictorsSub[11] = PredictorSub11_C;
  766. VP8LPredictorsSub[12] = PredictorSub12_C;
  767. VP8LPredictorsSub[13] = PredictorSub13_C;
  768. VP8LPredictorsSub[14] = PredictorSub0_C; // <- padding security sentinels
  769. VP8LPredictorsSub[15] = PredictorSub0_C;
  770. VP8LPredictorsSub_C[0] = PredictorSub0_C;
  771. VP8LPredictorsSub_C[1] = PredictorSub1_C;
  772. VP8LPredictorsSub_C[2] = PredictorSub2_C;
  773. VP8LPredictorsSub_C[3] = PredictorSub3_C;
  774. VP8LPredictorsSub_C[4] = PredictorSub4_C;
  775. VP8LPredictorsSub_C[5] = PredictorSub5_C;
  776. VP8LPredictorsSub_C[6] = PredictorSub6_C;
  777. VP8LPredictorsSub_C[7] = PredictorSub7_C;
  778. VP8LPredictorsSub_C[8] = PredictorSub8_C;
  779. VP8LPredictorsSub_C[9] = PredictorSub9_C;
  780. VP8LPredictorsSub_C[10] = PredictorSub10_C;
  781. VP8LPredictorsSub_C[11] = PredictorSub11_C;
  782. VP8LPredictorsSub_C[12] = PredictorSub12_C;
  783. VP8LPredictorsSub_C[13] = PredictorSub13_C;
  784. VP8LPredictorsSub_C[14] = PredictorSub0_C; // <- padding security sentinels
  785. VP8LPredictorsSub_C[15] = PredictorSub0_C;
  786. // If defined, use CPUInfo() to overwrite some pointers with faster versions.
  787. if (VP8GetCPUInfo != NULL) {
  788. #if defined(WEBP_HAVE_SSE2)
  789. if (VP8GetCPUInfo(kSSE2)) {
  790. VP8LEncDspInitSSE2();
  791. #if defined(WEBP_HAVE_SSE41)
  792. if (VP8GetCPUInfo(kSSE4_1)) {
  793. VP8LEncDspInitSSE41();
  794. }
  795. #endif
  796. }
  797. #endif
  798. #if defined(WEBP_USE_MIPS32)
  799. if (VP8GetCPUInfo(kMIPS32)) {
  800. VP8LEncDspInitMIPS32();
  801. }
  802. #endif
  803. #if defined(WEBP_USE_MIPS_DSP_R2)
  804. if (VP8GetCPUInfo(kMIPSdspR2)) {
  805. VP8LEncDspInitMIPSdspR2();
  806. }
  807. #endif
  808. #if defined(WEBP_USE_MSA)
  809. if (VP8GetCPUInfo(kMSA)) {
  810. VP8LEncDspInitMSA();
  811. }
  812. #endif
  813. }
  814. #if defined(WEBP_HAVE_NEON)
  815. if (WEBP_NEON_OMIT_C_CODE ||
  816. (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kNEON))) {
  817. VP8LEncDspInitNEON();
  818. }
  819. #endif
  820. assert(VP8LSubtractGreenFromBlueAndRed != NULL);
  821. assert(VP8LTransformColor != NULL);
  822. assert(VP8LCollectColorBlueTransforms != NULL);
  823. assert(VP8LCollectColorRedTransforms != NULL);
  824. assert(VP8LFastLog2Slow != NULL);
  825. assert(VP8LFastSLog2Slow != NULL);
  826. assert(VP8LExtraCost != NULL);
  827. assert(VP8LExtraCostCombined != NULL);
  828. assert(VP8LCombinedShannonEntropy != NULL);
  829. assert(VP8LGetEntropyUnrefined != NULL);
  830. assert(VP8LGetCombinedEntropyUnrefined != NULL);
  831. assert(VP8LAddVector != NULL);
  832. assert(VP8LAddVectorEq != NULL);
  833. assert(VP8LVectorMismatch != NULL);
  834. assert(VP8LBundleColorMap != NULL);
  835. assert(VP8LPredictorsSub[0] != NULL);
  836. assert(VP8LPredictorsSub[1] != NULL);
  837. assert(VP8LPredictorsSub[2] != NULL);
  838. assert(VP8LPredictorsSub[3] != NULL);
  839. assert(VP8LPredictorsSub[4] != NULL);
  840. assert(VP8LPredictorsSub[5] != NULL);
  841. assert(VP8LPredictorsSub[6] != NULL);
  842. assert(VP8LPredictorsSub[7] != NULL);
  843. assert(VP8LPredictorsSub[8] != NULL);
  844. assert(VP8LPredictorsSub[9] != NULL);
  845. assert(VP8LPredictorsSub[10] != NULL);
  846. assert(VP8LPredictorsSub[11] != NULL);
  847. assert(VP8LPredictorsSub[12] != NULL);
  848. assert(VP8LPredictorsSub[13] != NULL);
  849. assert(VP8LPredictorsSub[14] != NULL);
  850. assert(VP8LPredictorsSub[15] != NULL);
  851. assert(VP8LPredictorsSub_C[0] != NULL);
  852. assert(VP8LPredictorsSub_C[1] != NULL);
  853. assert(VP8LPredictorsSub_C[2] != NULL);
  854. assert(VP8LPredictorsSub_C[3] != NULL);
  855. assert(VP8LPredictorsSub_C[4] != NULL);
  856. assert(VP8LPredictorsSub_C[5] != NULL);
  857. assert(VP8LPredictorsSub_C[6] != NULL);
  858. assert(VP8LPredictorsSub_C[7] != NULL);
  859. assert(VP8LPredictorsSub_C[8] != NULL);
  860. assert(VP8LPredictorsSub_C[9] != NULL);
  861. assert(VP8LPredictorsSub_C[10] != NULL);
  862. assert(VP8LPredictorsSub_C[11] != NULL);
  863. assert(VP8LPredictorsSub_C[12] != NULL);
  864. assert(VP8LPredictorsSub_C[13] != NULL);
  865. assert(VP8LPredictorsSub_C[14] != NULL);
  866. assert(VP8LPredictorsSub_C[15] != NULL);
  867. }
  868. //------------------------------------------------------------------------------