示例#1
0
文件: ycbcr.c 项目: GNOME/babl
static void
ycbcr709_to_rgba (const Babl *conversion,
                  char       *src,
                  char       *dst,
                  long        n)
{
  while (n--)
    {
      double luminance = ((double *) src)[0];
      double cb        = ((double *) src)[1];
      double cr        = ((double *) src)[2];

      double red, green, blue;

      red   = 1.0 * luminance + 0.0    * cb + 1.5748 * cr;
      green = 1.0 * luminance - 0.1873 * cb - 0.4681 * cr;
      blue  = 1.0 * luminance + 1.8556 * cb + 0.0    * cr;

      red   = gamma_2_2_to_linear (red);
      green = gamma_2_2_to_linear (green);
      blue  = gamma_2_2_to_linear (blue);

      ((double *) dst)[0] = red;
      ((double *) dst)[1] = green;
      ((double *) dst)[2] = blue;
      ((double *) dst)[3] = 1.0;

      src += sizeof (double) * 3;
      dst += sizeof (double) * 4;
    }
}
示例#2
0
文件: HSV.c 项目: GNOME/babl
static void
hsv_to_rgba_step (char *src,
                  char *dst)
{
  double hue        = ((double *) src)[0];
  double saturation = ((double *) src)[1];
  double value      = ((double *) src)[2];

  double red = 0, green = 0, blue = 0;

  double chroma, h_tmp, x, min;

  chroma = saturation * value;
  h_tmp = hue * 6.0;
  x = chroma * (1.0 - fabs (fmod (h_tmp, 2.0) - 1.0));

  if (h_tmp < 1.0)
    {
      red   = chroma;
      green = x;
    }
  else if (h_tmp < 2.0)
    {
      red   = x;
      green = chroma;
    }
  else if (h_tmp < 3.0)
    {
      green = chroma;
      blue  = x;
    }
  else if (h_tmp < 4.0)
    {
      green = x;
      blue  = chroma;
    }
  else if (h_tmp < 5.0)
    {
      red  = x;
      blue = chroma;
    }
  else if (h_tmp < 6.0)
    {
      red  = chroma;
      blue = x;
    }

  min = value - chroma;

  red   += min;
  green += min;
  blue  += min;

  ((double *) dst)[0] = gamma_2_2_to_linear (red);
  ((double *) dst)[1] = gamma_2_2_to_linear (green);
  ((double *) dst)[2] = gamma_2_2_to_linear (blue);
}
示例#3
0
static void
table_init (void)
{
  if (table_inited)
    return;
  table_inited = 1;

  /* fill tables for conversion from integer to float */
  {
    int i;
    for (i = 0; i < 1 << 8; i++)
      {
        float direct = i / 255.0;
        table_8_F[i]  = direct;
        table_8g_F[i] = gamma_2_2_to_linear (direct);
      }
  }
  /* fill tables for conversion from float to integer */
  {
    union
    {
      float    f;
      uint32_t s;
    } u;
    u.f = 0.0;

    //u.s[0] = 0;

    for (u.s = 0; u.s < 4294900000U; u.s += 32768)
      {
        int c;
        int cg;

        if (u.f <= 0.0)
          {
            c  = 0;
            cg = 0;
          }
        else
          {
            c  = (u.f * 255.1619) + 0.5;
            cg = (linear_to_gamma_2_2 (u.f) * 255.1619) + 0.5;
            if (cg > 255) cg = 255;
            if (c > 255) c = 255;
          }

        table_F_8[(u.s >> 15) & ((1 << 17)-1)]  = c;
        table_F_8g[(u.s >> 15) & ((1 << 17)-1)] = cg;
      }
  }
#if 0
  /* fix tables to ensure 1:1 conversions back and forth */
  if (0)
    {
      int i;
      for (i = 0; i < 256; i++)
        {
          float           f;
          unsigned short *hi = ((unsigned short *) (void *) &f);
          unsigned short *lo = ((unsigned short *) (void *) &f);

          f = table_8_F[i];
          *lo              = 0;
          table_F_8[*hi] = i;
          f  = table_8g_F[i];
          *lo              = 0;
          table_F_8g[*hi] = i;
        }
    }
#endif
}