areaHashCRC64TFragmentShader.glsl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. */
  9. /* TODO Use textureOffset for newest version of GLSL */
  10. #version 130
  11. uniform sampler2D crc_table;
  12. uniform sampler2D sampler;
  13. uniform float xstep;
  14. uniform float ystep;
  15. varying vec2 tex_coord;
  16. const int scale = 4;
  17. const float ratio = 16.0;
  18. ivec2 crc64( ivec2 hval, int color )
  19. {
  20. int dx = 2 * ((hval[0] ^ color) & 0xff);
  21. float s = dx / 255.0;
  22. vec4 table_value_lo = round(texture2D( crc_table, vec2( s, 0.0 ) ) * 255.0);
  23. s = (dx+1) / 255.0;
  24. vec4 table_value_hi = round(texture2D( crc_table, vec2( s, 0.0 ) ) * 255.0);
  25. int tvalue_lo = int(table_value_lo[0]) | (int(table_value_lo[1]) << 8) | (int(table_value_lo[2]) << 16) | (int(table_value_lo[3]) << 24);
  26. int tvalue_hi = int(table_value_hi[0]) | (int(table_value_hi[1]) << 8) | (int(table_value_hi[2]) << 16) | (int(table_value_hi[3]) << 24);
  27. hval[1] = tvalue_hi ^ (hval[1] >> 8);
  28. hval[0] = tvalue_lo ^ ( (hval[1] << 24) | (hval[0] >> 8) );
  29. return hval;
  30. }
  31. void main(void)
  32. {
  33. ivec2 Crc = ivec2( 0xffffffff, 0xffffffff );
  34. vec2 offset = vec2( 0.0, 0.0 );
  35. vec2 next_coord = tex_coord.st;
  36. for( int y = 0; y < scale && next_coord.y <= 1.0; ++y )
  37. {
  38. for( int x = 0; x < scale && next_coord.x <= 1.0; ++x )
  39. {
  40. vec4 pixel = round(texture2D( sampler, next_coord ) * 255.0);
  41. int r = int(pixel.r); // 0..255
  42. int g = int(pixel.g); // 0..255
  43. int b = int(pixel.b); // 0..255
  44. int a = int(pixel.a); // 0..255
  45. Crc = crc64( Crc, r );
  46. Crc = crc64( Crc, g );
  47. Crc = crc64( Crc, b );
  48. Crc = crc64( Crc, a );
  49. offset.x += xstep;
  50. next_coord = tex_coord.st + offset;
  51. }
  52. offset.y += ystep;
  53. offset.x = 0.0;
  54. next_coord = tex_coord.st + offset;
  55. }
  56. Crc[0] = ~Crc[0];
  57. Crc[1] = ~Crc[1];
  58. int Hash = Crc[0] ^ Crc[1];
  59. float fr = ( Hash & 0xff) / 255.0;
  60. float fg = ((Hash >> 8) & 0xff) / 255.0;
  61. float fb = ((Hash >> 16) & 0xff) / 255.0;
  62. float fa = ((Hash >> 24) & 0xff) / 255.0;
  63. gl_FragColor = vec4(fr, fg, fb, fa);
  64. }
  65. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */