// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//!DESC RAVU-Zoom-AR (luma, r3)
//!HOOK LUMA
//!BIND HOOKED
//!BIND ravu_zoom_lut3
//!BIND ravu_zoom_lut3_ar
//!WIDTH OUTPUT.w
//!HEIGHT OUTPUT.h
//!OFFSET ALIGN
//!WHEN HOOKED.w OUTPUT.w < HOOKED.h OUTPUT.h < *
#define LUTPOS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))
vec4 hook() {
vec2 pos = HOOKED_pos * HOOKED_size;
vec2 subpix = fract(pos - 0.5);
pos -= subpix;
subpix = LUTPOS(subpix, vec2(9.0));
vec2 subpix_inv = 1.0 - subpix;
vec2 subpix_ar = subpix / vec2(2.0, 288.0);
vec2 subpix_inv_ar = subpix_inv / vec2(2.0, 288.0);
subpix /= vec2(5.0, 288.0);
subpix_inv /= vec2(5.0, 288.0);
float sample0 = HOOKED_tex((pos + vec2(-2.0,-2.0)) * HOOKED_pt).x;
float sample1 = HOOKED_tex((pos + vec2(-2.0,-1.0)) * HOOKED_pt).x;
float sample2 = HOOKED_tex((pos + vec2(-2.0,0.0)) * HOOKED_pt).x;
float sample3 = HOOKED_tex((pos + vec2(-2.0,1.0)) * HOOKED_pt).x;
float sample4 = HOOKED_tex((pos + vec2(-2.0,2.0)) * HOOKED_pt).x;
float sample5 = HOOKED_tex((pos + vec2(-2.0,3.0)) * HOOKED_pt).x;
float sample6 = HOOKED_tex((pos + vec2(-1.0,-2.0)) * HOOKED_pt).x;
float sample7 = HOOKED_tex((pos + vec2(-1.0,-1.0)) * HOOKED_pt).x;
float sample8 = HOOKED_tex((pos + vec2(-1.0,0.0)) * HOOKED_pt).x;
float sample9 = HOOKED_tex((pos + vec2(-1.0,1.0)) * HOOKED_pt).x;
float sample10 = HOOKED_tex((pos + vec2(-1.0,2.0)) * HOOKED_pt).x;
float sample11 = HOOKED_tex((pos + vec2(-1.0,3.0)) * HOOKED_pt).x;
float sample12 = HOOKED_tex((pos + vec2(0.0,-2.0)) * HOOKED_pt).x;
float sample13 = HOOKED_tex((pos + vec2(0.0,-1.0)) * HOOKED_pt).x;
float sample14 = HOOKED_tex((pos + vec2(0.0,0.0)) * HOOKED_pt).x;
float sample15 = HOOKED_tex((pos + vec2(0.0,1.0)) * HOOKED_pt).x;
float sample16 = HOOKED_tex((pos + vec2(0.0,2.0)) * HOOKED_pt).x;
float sample17 = HOOKED_tex((pos + vec2(0.0,3.0)) * HOOKED_pt).x;
float sample18 = HOOKED_tex((pos + vec2(1.0,-2.0)) * HOOKED_pt).x;
float sample19 = HOOKED_tex((pos + vec2(1.0,-1.0)) * HOOKED_pt).x;
float sample20 = HOOKED_tex((pos + vec2(1.0,0.0)) * HOOKED_pt).x;
float sample21 = HOOKED_tex((pos + vec2(1.0,1.0)) * HOOKED_pt).x;
float sample22 = HOOKED_tex((pos + vec2(1.0,2.0)) * HOOKED_pt).x;
float sample23 = HOOKED_tex((pos + vec2(1.0,3.0)) * HOOKED_pt).x;
float sample24 = HOOKED_tex((pos + vec2(2.0,-2.0)) * HOOKED_pt).x;
float sample25 = HOOKED_tex((pos + vec2(2.0,-1.0)) * HOOKED_pt).x;
float sample26 = HOOKED_tex((pos + vec2(2.0,0.0)) * HOOKED_pt).x;
float sample27 = HOOKED_tex((pos + vec2(2.0,1.0)) * HOOKED_pt).x;
float sample28 = HOOKED_tex((pos + vec2(2.0,2.0)) * HOOKED_pt).x;
float sample29 = HOOKED_tex((pos + vec2(2.0,3.0)) * HOOKED_pt).x;
float sample30 = HOOKED_tex((pos + vec2(3.0,-2.0)) * HOOKED_pt).x;
float sample31 = HOOKED_tex((pos + vec2(3.0,-1.0)) * HOOKED_pt).x;
float sample32 = HOOKED_tex((pos + vec2(3.0,0.0)) * HOOKED_pt).x;
float sample33 = HOOKED_tex((pos + vec2(3.0,1.0)) * HOOKED_pt).x;
float sample34 = HOOKED_tex((pos + vec2(3.0,2.0)) * HOOKED_pt).x;
float sample35 = HOOKED_tex((pos + vec2(3.0,3.0)) * HOOKED_pt).x;
vec3 abd = vec3(0.0);
float gx, gy;
gx = (sample13-sample1)/2.0;
gy = (sample8-sample6)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
gx = (sample14-sample2)/2.0;
gy = (-sample10+8.0*sample9-8.0*sample7+sample6)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (sample15-sample3)/2.0;
gy = (-sample11+8.0*sample10-8.0*sample8+sample7)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (sample16-sample4)/2.0;
gy = (sample11-sample9)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
gx = (-sample25+8.0*sample19-8.0*sample7+sample1)/12.0;
gy = (sample14-sample12)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (-sample26+8.0*sample20-8.0*sample8+sample2)/12.0;
gy = (-sample16+8.0*sample15-8.0*sample13+sample12)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-sample27+8.0*sample21-8.0*sample9+sample3)/12.0;
gy = (-sample17+8.0*sample16-8.0*sample14+sample13)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-sample28+8.0*sample22-8.0*sample10+sample4)/12.0;
gy = (sample17-sample15)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (-sample31+8.0*sample25-8.0*sample13+sample7)/12.0;
gy = (sample20-sample18)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (-sample32+8.0*sample26-8.0*sample14+sample8)/12.0;
gy = (-sample22+8.0*sample21-8.0*sample19+sample18)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-sample33+8.0*sample27-8.0*sample15+sample9)/12.0;
gy = (-sample23+8.0*sample22-8.0*sample20+sample19)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-sample34+8.0*sample28-8.0*sample16+sample10)/12.0;
gy = (sample23-sample21)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (sample31-sample19)/2.0;
gy = (sample26-sample24)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
gx = (sample32-sample20)/2.0;
gy = (-sample28+8.0*sample27-8.0*sample25+sample24)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (sample33-sample21)/2.0;
gy = (-sample29+8.0*sample28-8.0*sample26+sample25)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (sample34-sample22)/2.0;
gy = (sample29-sample27)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
float a = abd.x, b = abd.y, d = abd.z;
float T = a + d, D = a * d - b * b;
float delta = sqrt(max(T * T / 4.0 - D, 0.0));
float L1 = T / 2.0 + delta, L2 = T / 2.0 - delta;
float sqrtL1 = sqrt(L1), sqrtL2 = sqrt(L2);
float theta = mix(mod(atan(L1 - a, b) + 3.141592653589793, 3.141592653589793), 0.0, abs(b) < 1.192092896e-7);
float lambda = sqrtL1;
float mu = mix((sqrtL1 - sqrtL2) / (sqrtL1 + sqrtL2), 0.0, sqrtL1 + sqrtL2 < 1.192092896e-7);
float angle = floor(theta * 24.0 / 3.141592653589793);
float strength = mix(mix(0.0, 1.0, lambda >= 0.004), mix(2.0, 3.0, lambda >= 0.05), lambda >= 0.016);
float coherence = mix(mix(0.0, 1.0, mu >= 0.25), 2.0, mu >= 0.5);
float coord_y = ((angle * 4.0 + strength) * 3.0 + coherence) / 288.0;
float res = 0.0;
vec4 w;
vec4 cg, cg1;
float lo = 0.0, hi = 0.0;
float lo2 = 0.0, hi2 = 0.0;
w = texture(ravu_zoom_lut3, vec2(0.0, coord_y) + subpix);
res += sample0 * w[0];
res += sample1 * w[1];
res += sample2 * w[2];
res += sample3 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.2, coord_y) + subpix);
res += sample4 * w[0];
res += sample5 * w[1];
res += sample6 * w[2];
res += sample7 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.4, coord_y) + subpix);
res += sample8 * w[0];
res += sample9 * w[1];
res += sample10 * w[2];
res += sample11 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.6, coord_y) + subpix);
res += sample12 * w[0];
res += sample13 * w[1];
res += sample14 * w[2];
res += sample15 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.8, coord_y) + subpix);
res += sample16 * w[0];
res += sample17 * w[1];
w = texture(ravu_zoom_lut3, vec2(0.0, coord_y) + subpix_inv);
res += sample35 * w[0];
res += sample34 * w[1];
res += sample33 * w[2];
res += sample32 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.2, coord_y) + subpix_inv);
res += sample31 * w[0];
res += sample30 * w[1];
res += sample29 * w[2];
res += sample28 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.4, coord_y) + subpix_inv);
res += sample27 * w[0];
res += sample26 * w[1];
res += sample25 * w[2];
res += sample24 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.6, coord_y) + subpix_inv);
res += sample23 * w[0];
res += sample22 * w[1];
res += sample21 * w[2];
res += sample20 * w[3];
w = texture(ravu_zoom_lut3, vec2(0.8, coord_y) + subpix_inv);
res += sample19 * w[0];
res += sample18 * w[1];
w = texture(ravu_zoom_lut3_ar, vec2(0.0, coord_y) + subpix_ar);
cg = vec4(0.1 + sample7, 1.1 - sample7, 0.1 + sample8, 1.1 - sample8);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + sample9, 1.1 - sample9, 0.1 + sample10, 1.1 - sample10);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
w = texture(ravu_zoom_lut3_ar, vec2(0.5, coord_y) + subpix_ar);
cg = vec4(0.1 + sample13, 1.1 - sample13, 0.1 + sample14, 1.1 - sample14);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + sample15, 1.1 - sample15, 0.1 + sample16, 1.1 - sample16);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
w = texture(ravu_zoom_lut3_ar, vec2(0.0, coord_y) + subpix_inv_ar);
cg = vec4(0.1 + sample28, 1.1 - sample28, 0.1 + sample27, 1.1 - sample27);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + sample26, 1.1 - sample26, 0.1 + sample25, 1.1 - sample25);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
w = texture(ravu_zoom_lut3_ar, vec2(0.5, coord_y) + subpix_inv_ar);
cg = vec4(0.1 + sample22, 1.1 - sample22, 0.1 + sample21, 1.1 - sample21);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + sample20, 1.1 - sample20, 0.1 + sample19, 1.1 - sample19);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
hi = hi2 / hi - 0.1;
lo = 1.1 - lo2 / lo;
res = mix(res, clamp(res, lo, hi), 0.800000);
return vec4(res, 0.0, 0.0, 0.0);
}
//!TEXTURE ravu_zoom_lut3
//!SIZE 45 2592
//!FORMAT rgba16f
//!FILTER LINEAR
[encoded data, 3732480 characters]
//!TEXTURE ravu_zoom_lut3_ar
//!SIZE 18 2592
//!FORMAT rgba16f
//!FILTER LINEAR
[encoded data, 1492992 characters]
