1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 /* TODO Use textureOffset for newest version of GLSL */
15 uniform sampler2D crc_table;
16 uniform sampler2D sampler;
20 varying vec2 tex_coord;
23 const float ratio = 16.0;
26 ivec2 crc64( ivec2 hval, int color )
28 int dx = 2 * ((hval[0] ^ color) & 0xff);
30 vec4 table_value_lo = round(texture2D( crc_table, vec2( s, 0.0 ) ) * 255.0);
32 vec4 table_value_hi = round(texture2D( crc_table, vec2( s, 0.0 ) ) * 255.0);
34 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);
35 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);
37 hval[1] = tvalue_hi ^ (hval[1] >> 8);
38 hval[0] = tvalue_lo ^ ( (hval[1] << 24) | (hval[0] >> 8) );
46 ivec2 Crc = ivec2( 0xffffffff, 0xffffffff );
47 vec2 offset = vec2( 0.0, 0.0 );
48 vec2 next_coord = tex_coord.st;
49 for( int y = 0; y < scale && next_coord.y <= 1.0; ++y )
51 for( int x = 0; x < scale && next_coord.x <= 1.0; ++x )
53 vec4 pixel = round(texture2D( sampler, next_coord ) * 255.0);
55 int r = int(pixel.r); // 0..255
56 int g = int(pixel.g); // 0..255
57 int b = int(pixel.b); // 0..255
58 int a = int(pixel.a); // 0..255
60 Crc = crc64( Crc, r );
61 Crc = crc64( Crc, g );
62 Crc = crc64( Crc, b );
63 Crc = crc64( Crc, a );
66 next_coord = tex_coord.st + offset;
70 next_coord = tex_coord.st + offset;
76 int Hash = Crc[0] ^ Crc[1];
78 float fr = ( Hash & 0xff) / 255.0;
79 float fg = ((Hash >> 8) & 0xff) / 255.0;
80 float fb = ((Hash >> 16) & 0xff) / 255.0;
81 float fa = ((Hash >> 24) & 0xff) / 255.0;
84 gl_FragColor = vec4(fr, fg, fb, fa);
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */