Facebook
From Salu Ramos, 3 Weeks ago, written in Java.
Embed
Download Paste or View Raw
Hits: 116
  1. int numColors = 256;
  2. int[] preComputed = new int[numColors]{-16744602,
  3. -16744602,
  4. -16678810,
  5. -16613274,
  6. -16547482,
  7. -16481946,
  8. -16416154,
  9. -16350618,
  10. -16284826,
  11. -16219290,
  12. -16153498,
  13. -16087962,
  14. -16022170,
  15. -15956634,
  16. -15890842,
  17. -15825306,
  18. -15759514,
  19. -15693978,
  20. -15628186,
  21. -15562650,
  22. -15496858,
  23. -15431322,
  24. -15365530,
  25. -15299994,
  26. -15234202,
  27. -15168666,
  28. -15102874,
  29. -15037338,
  30. -14971546,
  31. -14906010,
  32. -14840218,
  33. -14774682,
  34. -14708890,
  35. -14643354,
  36. -14577562,
  37. -14512026,
  38. -14446234,
  39. -14380698,
  40. -14314906,
  41. -14249370,
  42. -14183578,
  43. -14118042,
  44. -14052250,
  45. -13986714,
  46. -13920922,
  47. -13855386,
  48. -13789594,
  49. -13724058,
  50. -13658266,
  51. -13592730,
  52. -13526938,
  53. -13461402,
  54. -13395610,
  55. -13330074,
  56. -13264282,
  57. -13198746,
  58. -13132954,
  59. -13067418,
  60. -13001626,
  61. -12936090,
  62. -12870298,
  63. -12804762,
  64. -12738970,
  65. -12673434,
  66. -12607642,
  67. -12542106,
  68. -12476314,
  69. -12410778,
  70. -12344986,
  71. -12279450,
  72. -12213658,
  73. -12148122,
  74. -12082330,
  75. -12016794,
  76. -11951002,
  77. -11885466,
  78. -11819674,
  79. -11754138,
  80. -11688346,
  81. -11622810,
  82. -11557018,
  83. -11491482,
  84. -11425690,
  85. -11360154,
  86. -11294362,
  87. -11228826,
  88. -11163034,
  89. -11097498,
  90. -11031706,
  91. -10966170,
  92. -10900378,
  93. -10834842,
  94. -10769050,
  95. -10703514,
  96. -10637722,
  97. -10572186,
  98. -10506394,
  99. -10440858,
  100. -10375066,
  101. -10309530,
  102. -10243738,
  103. -10178202,
  104. -10112410,
  105. -10046874,
  106. -9981082,
  107. -9915546,
  108. -9849754,
  109. -9784218,
  110. -9718426,
  111. -9652890,
  112. -9587098,
  113. -9521562,
  114. -9455770,
  115. -9390234,
  116. -9324442,
  117. -9258906,
  118. -9193114,
  119. -9127578,
  120. -9061786,
  121. -8996250,
  122. -8930458,
  123. -8864922,
  124. -8799130,
  125. -8733594,
  126. -8667802,
  127. -8602266,
  128. -8536474,
  129. -8470938,
  130. -8339610,
  131. -8273818,
  132. -8208282,
  133. -8142490,
  134. -8076954,
  135. -8011162,
  136. -7945626,
  137. -7879834,
  138. -7814298,
  139. -7748506,
  140. -7682970,
  141. -7617178,
  142. -7551642,
  143. -7485850,
  144. -7420314,
  145. -7354522,
  146. -7288986,
  147. -7223194,
  148. -7157658,
  149. -7091866,
  150. -7026330,
  151. -6960538,
  152. -6895002,
  153. -6829210,
  154. -6763674,
  155. -6697882,
  156. -6632346,
  157. -6566554,
  158. -6501018,
  159. -6435226,
  160. -6369690,
  161. -6303898,
  162. -6238362,
  163. -6172570,
  164. -6107034,
  165. -6041242,
  166. -5975706,
  167. -5909914,
  168. -5844378,
  169. -5778586,
  170. -5713050,
  171. -5647258,
  172. -5581722,
  173. -5515930,
  174. -5450394,
  175. -5384602,
  176. -5319066,
  177. -5253274,
  178. -5187738,
  179. -5121946,
  180. -5056410,
  181. -4990618,
  182. -4925082,
  183. -4859290,
  184. -4793754,
  185. -4727962,
  186. -4662426,
  187. -4596634,
  188. -4531098,
  189. -4465306,
  190. -4399770,
  191. -4333978,
  192. -4268442,
  193. -4202650,
  194. -4137114,
  195. -4071322,
  196. -4005786,
  197. -3939994,
  198. -3874458,
  199. -3808666,
  200. -3743130,
  201. -3677338,
  202. -3611802,
  203. -3546010,
  204. -3480474,
  205. -3414682,
  206. -3349146,
  207. -3283354,
  208. -3217818,
  209. -3152026,
  210. -3086490,
  211. -3020698,
  212. -2955162,
  213. -2889370,
  214. -2823834,
  215. -2758042,
  216. -2692506,
  217. -2626714,
  218. -2561178,
  219. -2495386,
  220. -2429850,
  221. -2364058,
  222. -2298522,
  223. -2232730,
  224. -2167194,
  225. -2101402,
  226. -2035866,
  227. -1970074,
  228. -1904538,
  229. -1838746,
  230. -1773210,
  231. -1707418,
  232. -1641882,
  233. -1576090,
  234. -1510554,
  235. -1444762,
  236. -1379226,
  237. -1313434,
  238. -1247898,
  239. -1182106,
  240. -1116570,
  241. -1050778,
  242. -985242,
  243. -919450,
  244. -853914,
  245. -788122,
  246. -722586,
  247. -656794,
  248. -591258,
  249. -525466,
  250. -459930,
  251. -394138,
  252. -328602,
  253. -262810,
  254. -197274,
  255. -131482,
  256. -65946,
  257. -154};
  258.  
  259. private void setLutTexture() {
  260.   int lutTextureID = glGenTextures();
  261.   glActiveTexture(GL_TEXTURE2);
  262.   glBindTexture(GL_TEXTURE_1D, lutTextureID);
  263.   glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  264.   glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  265.   glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  266.   glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32I, numColors, 0, GL_RGBA, GL_INT, getPreComputedBuffer());
  267.   glBindTexture(GL_TEXTURE_1D, 0);
  268. }
  269.  
  270. public int[] getPreComputedBuffer() {
  271.   int[] buffer = new int[this.numColors*4];
  272.   int pixelIndex = 0;
  273.   for (int i = 0; i < numColors; i++) {
  274.     int[] rgba = intToRGBAInts(preComputed[i]);
  275.     buffer[pixelIndex] = rgba[0];
  276.     buffer[pixelIndex + 1] = rgba[1];
  277.     buffer[pixelIndex + 2] = rgba[2];
  278.     buffer[pixelIndex + 3] = rgba[3];
  279.     pixelIndex += 4;
  280.   }
  281.   return buffer;
  282. }
  283.  
  284. public int[] intToRGBAInts (int rgba) {
  285.   int alpha = (rgba >> 24) & 0xFF;
  286.   int red = (rgba >> 16) & 0xFF;
  287.   int green = (rgba >> 8) & 0xFF;
  288.   int blue = (rgba) & 0xFF;
  289.   return new int[]{red, green, blue, alpha};
  290. }