Skip to repository content50 lines · 2.0 KB · text
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T05:01:11.257Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
alpha_correction.hlsl
1// Adapted from https://github.com/microsoft/terminal/blob/1283c0f5b99a2961673249fa77c6b986efb5086c/src/renderer/atlas/dwrite.hlsl
2// Copyright (c) Microsoft Corporation.
3// Licensed under the MIT license.
4
5float color_brightness(float3 color) {
6 // REC. 601 luminance coefficients for perceived brightness
7 return dot(color, float3(0.30f, 0.59f, 0.11f));
8}
9
10float light_on_dark_contrast(float enhancedContrast, float3 color) {
11 float brightness = color_brightness(color);
12 float multiplier = saturate(4.0f * (0.75f - brightness));
13 return enhancedContrast * multiplier;
14}
15
16float enhance_contrast(float alpha, float k) {
17 return alpha * (k + 1.0f) / (alpha * k + 1.0f);
18}
19
20float3 enhance_contrast3(float3 alpha, float k) {
21 return alpha * (k + 1.0f) / (alpha * k + 1.0f);
22}
23
24float apply_alpha_correction(float a, float b, float4 g) {
25 float brightness_adjustment = g.x * b + g.y;
26 float correction = brightness_adjustment * a + (g.z * b + g.w);
27 return a + a * (1.0f - a) * correction;
28}
29
30float3 apply_alpha_correction3(float3 a, float3 b, float4 g) {
31 float3 brightness_adjustment = g.x * b + g.y;
32 float3 correction = brightness_adjustment * a + (g.z * b + g.w);
33 return a + a * (1.0f - a) * correction;
34}
35
36float apply_contrast_and_gamma_correction(float sample, float3 color, float enhanced_contrast_factor, float4 gamma_ratios) {
37 float enhanced_contrast = light_on_dark_contrast(enhanced_contrast_factor, color);
38 float brightness = color_brightness(color);
39
40 float contrasted = enhance_contrast(sample, enhanced_contrast);
41 return apply_alpha_correction(contrasted, brightness, gamma_ratios);
42}
43
44float3 apply_contrast_and_gamma_correction3(float3 sample, float3 color, float enhanced_contrast_factor, float4 gamma_ratios) {
45 float enhanced_contrast = light_on_dark_contrast(enhanced_contrast_factor, color);
46
47 float3 contrasted = enhance_contrast3(sample, enhanced_contrast);
48 return apply_alpha_correction3(contrasted, color, gamma_ratios);
49}
50