Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Gnome/gsk/gpu/shaders/   (Gnome Linux Desktop Version 4.23.2©)  Datei vom 30.5.2026 mit Größe 9 kB image not shown  

Quelle  gskgpuconvertcicp.glsl   Sprache: unbekannt

 
Spracherkennung für: .glsl vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

#ifdef GSK_PREAMBLE
textures = 1;
var_name = "gsk_gpu_convert_cicp";
struct_name = "GskGpuConvertCicp";

graphene_rect_t bounds;
graphene_rect_t tex_rect;
float opacity;
guint32 color_primaries;
guint32 transfer_function;
guint32 matrix_coefficients;
guint32 range;

variation: gboolean premultiply;
variation: gboolean reverse;
#endif /* GSK_PREAMBLE */

#include "gskgpuconvertcicpinstance.glsl"

PASS(0) vec2 _pos;
PASS_FLAT(1) Rect _bounds;
PASS(2) vec2 _tex_coord;
PASS_FLAT(3) float _opacity;
PASS_FLAT(4) uint _transfer_function;
PASS_FLAT(5) mat3 _mat;
PASS_FLAT(8) mat3 _yuv;
PASS_FLAT(11) vec3 _yuv_add;
PASS_FLAT(12) uint _range;


#ifdef GSK_VERTEX_SHADER

const mat3 identity = mat3(
  1.00.00.0,
  0.01.00.0,
  0.00.01.0
);

const mat3 srgb_to_xyz = mat3(
  0.41245640.21267290.0193339,
  0.35757610.71515220.1191920,
  0.18043750.07217500.9503041
);

const mat3 xyz_to_srgb = mat3(
  3.2404542, -0.9692660,  0.0556434,
 -1.5371385,  1.8760108, -0.2040259,
 -0.4985314,  0.0415560,  1.0572252
);

const mat3 rec2020_to_xyz = mat3(
  0.63695800.26270020.0000000,
  0.14461690.67799810.0280727,
  0.16888100.05930171.0609851
);

const mat3 xyz_to_rec2020 = mat3(
  1.7166512, -0.6666844,  0.0176399,
 -0.3556708,  1.6164812, -0.0427706,
 -0.2533663,  0.0157685,  0.9421031
);

const mat3 pal_to_xyz = mat3(
 0.43055380.22200430.0201822,
 0.34154980.70665480.1295534,
 0.17835230.07134090.9393222
);

const mat3 xyz_to_pal = mat3(
  3.0633611, -0.9692436,  0.0678610,
 -1.3933902,  1.8759675, -0.2287993,
 -0.4758237,  0.0415551,  1.0690896
);

const mat3 ntsc_to_xyz = mat3(
 0.39352090.21237640.0187391,
 0.36525810.70105990.1119339,
 0.19167690.08656380.9583847
);

const mat3 xyz_to_ntsc = mat3(
  3.5060033, -1.0690476,  0.0563066,
 -1.7397907,  1.9777789, -0.1969757,
 -0.5440583,  0.0351714,  1.0499523
);

const mat3 p3_to_xyz = mat3(
 0.48657090.22897460.0000000,
 0.26566770.69173850.0451134,
 0.19821730.07928691.0439444
);

const mat3 xyz_to_p3 = mat3(
  2.4934969, -0.8294890,  0.0358458,
 -0.9313836,  1.7626641, -0.0761724,
 -0.4027108,  0.0236247,  0.9568845
);

const mat3 rgb_to_bt601 = mat3(
  0.5000000.299000, -0.168736,
  -0.4186880.587000, -0.331264,
  -0.0813120.1140000.500000
);

const mat3 bt601_to_rgb = mat3(
  1.402000, -0.7141360.000000,
  1.0000001.0000001.000000,
  0.000000, -0.3441361.772000
);

const mat3 rgb_to_bt709 = mat3(
  0.5000000.212600, -0.114572,
  -0.4541530.715200, -0.385428,
  -0.0458470.0722000.500000
);

const mat3 bt709_to_rgb = mat3(
  1.574800, -0.468124, -0.000000,
  1.0000001.0000001.000000,
  0.000000, -0.1873241.855600
);

const mat3 rgb_to_bt2020 = mat3(
  0.5000000.262700, -0.139630,
  -0.4597860.678000, -0.360370,
  -0.0402140.0593000.500000
);

const mat3 bt2020_to_rgb = mat3(
  1.474600, -0.571353, -0.000000,
  1.0000001.0000001.000000,
  -0.000000, -0.1645531.881400
);

mat3
cicp_to_xyz (uint cp)
{
  switch (cp)
    {
    case 1u: return srgb_to_xyz;
    case 5u: return pal_to_xyz;
    case 6u:
    case 7u: return ntsc_to_xyz;
    case 9u: return rec2020_to_xyz;
    case 10u: return identity;
    case 12u: return p3_to_xyz;
    default: return identity;
    }
}

mat3
cicp_from_xyz (uint cp)
{
  switch (cp)
    {
    case 1u: return xyz_to_srgb;
    case 5u: return xyz_to_pal;
    case 6u:
    case 7u: return xyz_to_ntsc;
    case 9u: return xyz_to_rec2020;
    case 10u: return identity;
    case 12u: return xyz_to_p3;
    default: return identity;
    }
}


mat3
yuv_to_rgb (uint mc, out vec3 yuv_add)
{
  if (mc == 0u)
    yuv_add = vec3(0.00.00.0);
  else
    yuv_add = vec3(-0.50.0, -0.5);

  switch (mc)
    {
    case 0u: return identity;
    case 1u: return bt709_to_rgb;
    case 5u:
    case 6u: return bt601_to_rgb;
    case 9u: return bt2020_to_rgb;
    }
  return mat3(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
}

mat3
rgb_to_yuv (uint mc, out vec3 yuv_add)
{
  if (mc == 0u)
    yuv_add = vec3(0.00.00.0);
  else
    yuv_add = vec3(0.50.00.5);

  switch (mc)
    {
    case 0u: return identity;
    case 1u: return rgb_to_bt709;
    case 5u:
    case 6u: return rgb_to_bt601;
    case 9u: return rgb_to_bt2020;
    }
  return mat3(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
}

void
run (out vec2 pos)
{
  Rect b = rect_from_gsk (in_bounds);

  pos = rect_get_position (b);

  _pos = pos;
  _bounds = b;
  _tex_coord = rect_get_coord (rect_from_gsk (in_tex_rect), pos);
  _opacity = in_opacity;
  _transfer_function = in_transfer_function;
  _range = in_range;

  if (VARIATION_REVERSE)
    {
      if (ALT_COLOR_SPACE == GDK_COLOR_STATE_ID_SRGB_LINEAR)
        _mat = cicp_from_xyz (in_color_primaries) * srgb_to_xyz;
      else if (ALT_COLOR_SPACE == GDK_COLOR_STATE_ID_REC2100_LINEAR)
        _mat = cicp_from_xyz (in_color_primaries) * rec2020_to_xyz;
      else
        _mat = mat3(1.01.01.00.00.00.00.80.80.8);

      _yuv = rgb_to_yuv (in_matrix_coefficients, _yuv_add);
    }
  else
    {
      if (ALT_COLOR_SPACE == GDK_COLOR_STATE_ID_SRGB_LINEAR)
        _mat = xyz_to_srgb * cicp_to_xyz (in_color_primaries);
      else if (ALT_COLOR_SPACE == GDK_COLOR_STATE_ID_REC2100_LINEAR)
        _mat = xyz_to_rec2020 * cicp_to_xyz (in_color_primaries);
      else
        _mat = mat3(1.01.01.00.00.00.00.80.80.8);

      _yuv = yuv_to_rgb (in_matrix_coefficients, _yuv_add);
    }
}

#endif


#ifdef GSK_FRAGMENT_SHADER


vec3
bt709_eotf (vec3 v)
{
  const float a = 1.099;
  const float d = 0.0812;

  vec3 lo = v / 4.5;
  vec3 hi = sign (v) * pow ((abs (v) + (a - 1.0)) / a, vec3 (1.0 / 0.45));
  return mix (hi, lo, lessThan (abs (v), vec3 (d)));
}

vec3
bt709_oetf (vec3 v)
{
  const float a = 1.099;
  const float b = 0.018;

  vec3 lo = v * 4.5;
  vec3 hi = sign (v) * (a * pow (abs (v), vec3 (0.45)) - (a - 1.0));
  return mix (hi, lo, lessThan (abs (v), vec3 (b)));
}

vec3
gamma22_oetf (vec3 v)
{
  return sign (v) * pow (abs (v), vec3 (1.0 / 2.2));
}

vec3
gamma22_eotf (vec3 v)
{
  return sign (v) * pow (abs (v), vec3 (2.2));
}

vec3
gamma28_oetf (vec3 v)
{
  return sign (v) * pow (abs (v), vec3 (1.0 / 2.8));
}

vec3
gamma28_eotf (vec3 v)
{
  return sign (v) * pow (abs (v), vec3 (2.8));
}

vec3
hlg_eotf (vec3 v)
{
  const float a = 0.17883277;
  const float b = 0.28466892;
  const float c = 0.55991073;

  vec3 lo = sign (v) * ((v * v) / 3.0);
  vec3 hi = sign (v) * ((exp ((abs (v) - c) / a) + b) / 12.0);
  v = mix (hi, lo, lessThanEqual (abs (v), vec3 (0.5)));

  float Ys = dot (vec3 (0.26270.67800.0593), v);
  v *= (1000.0 / 203.0) * pow (max (Ys, 0.0), 0.2);

  return v;
}

vec3
hlg_oetf (vec3 v)
{
  const float a = 0.17883277;
  const float b = 0.28466892;
  const float c = 0.55991073;

  float Yd = dot (vec3 (0.26270.67800.0593), v);
  if (Yd > 0.0)
    v *= pow (203.0 / 1000.01.0 / 1.2) * pow (Yd, 1.0 / 1.2 - 1.0);

  vec3 lo = sign (v) * sqrt (3.0 * abs (v));
  vec3 hi = sign (v) * (a * log (12.0 * abs (v) - b) + c);
  return mix (hi, lo, lessThanEqual (abs (v), vec3 (1.0 / 12.0)));
}

vec3
apply_cicp_eotf (vec3 color,
                 uint transfer_function)
{
  switch (transfer_function)
    {
    case 1u:
    case 6u:
    case 14u:
    case 15u:
      return bt709_eotf (color);

    case 4u:
      return gamma22_eotf (color);

    case 5u:
      return gamma28_eotf (color);

    case 8u:
      return color;

    case 13u:
      return srgb_eotf (color);

    case 16u:
      return pq_eotf (color);

    case 18u:
      return hlg_eotf (color);

    default:
      return vec3 (1.00.20.8);
    }
}

vec3
apply_cicp_oetf (vec3 color,
                 uint transfer_function)
{
  switch (transfer_function)
    {
    case 1u:
    case 6u:
    case 14u:
    case 15u:
      return bt709_oetf (color);

    case 4u:
      return gamma22_oetf (color);

    case 5u:
      return gamma28_oetf (color);

    case 8u:
      return color;

    case 13u:
      return srgb_oetf (color);

    case 16u:
      return pq_oetf (color);

    case 18u:
      return hlg_oetf (color);

    default:
      return vec3 (1.00.20.8);
    }
}

vec4
convert_color_from_cicp (vec4 color)
{
  if (VARIATION_PREMULTIPLY)
    color = color_unpremultiply (color);

  if (_range == 0u)
    {
      color.r = clamp ((color.r - 16.0/255.0) * 255.0/224.00.01.0);
      color.g = clamp ((color.g - 16.0/255.0) * 255.0/219.00.01.0);
      color.b = clamp ((color.b - 16.0/255.0) * 255.0/224.00.01.0);
    }

  color.rgb = _yuv * (color.rgb + _yuv_add);

  color.rgb = apply_cicp_eotf (color.rgb, _transfer_function);
  color.rgb = _mat * color.rgb;

  color = output_color_from_alt (color);

  return color;
}

vec4
convert_color_to_cicp (vec4 color)
{
  color = alt_color_from_output (color);

  color.rgb = _mat * color.rgb;
  color.rgb = apply_cicp_oetf (color.rgb, _transfer_function);

  color.rgb = _yuv * color.rgb + _yuv_add;

  color.rgb = clamp (color.rgb, 0.01.0);

  if (_range == 0u)
    {
      color.r = color.r * 224.0/255.0 + 16.0/255.0;
      color.g = color.g * 219.0/255.0 + 16.0/255.0;
      color.b = color.b * 224.0/255.0 + 16.0/255.0;
    }

  if (VARIATION_PREMULTIPLY)
    color = color_premultiply (color);

  return color;
}

void
run (out vec4 color,
     out vec2 position)
{
  vec4 pixel = gsk_texture0 (_tex_coord);

  if (VARIATION_REVERSE)
    pixel = convert_color_to_cicp (pixel);
  else
    pixel = convert_color_from_cicp (pixel);

  float alpha = rect_coverage (_bounds, _pos) * _opacity;

  color = output_color_alpha (pixel, alpha);

  position = _pos;
}

#endif

[Dauer der Verarbeitung: 0.13 Sekunden, vorverarbeitet 2026-07-02]