Logo Search packages:      
Sourcecode: inkscape version File versions

void sp_gradient_ensure_colors ( SPGradient *  gradient  ) 

Ensures that color array is populated

Definition at line 779 of file sp-gradient.cpp.

References sp_gradient_ensure_colors().

Referenced by sp_gradient_ensure_colors(), and sp_gradient_render_vector_line_rgba().

{
      if (!gr->vector) {
            sp_gradient_rebuild_vector (gr);
      }

      if (!gr->color) {
            gr->color = g_new (guchar, 4 * NCOLORS);
      }

      for (gint i = 0; i < gr->vector->nstops - 1; i++) {
            guint32 color = sp_color_get_rgba32_falpha (&gr->vector->stops[i].color, gr->vector->stops[i].opacity);
            gint r0 = (color >> 24) & 0xff;
            gint g0 = (color >> 16) & 0xff;
            gint b0 = (color >> 8) & 0xff;
            gint a0 = color & 0xff;
            color = sp_color_get_rgba32_falpha (&gr->vector->stops[i + 1].color, gr->vector->stops[i + 1].opacity);
            gint r1 = (color >> 24) & 0xff;
            gint g1 = (color >> 16) & 0xff;
            gint b1 = (color >> 8) & 0xff;
            gint a1 = color & 0xff;
            gint o0 = (gint) floor (gr->vector->stops[i].offset * (NCOLORS - 0.001));
            gint o1 = (gint) floor (gr->vector->stops[i + 1].offset * (NCOLORS - 0.001));
            if (o1 > o0) {
                  gint dr = ((r1 - r0) << 16) / (o1 - o0);
                  gint dg = ((g1 - g0) << 16) / (o1 - o0);
                  gint db = ((b1 - b0) << 16) / (o1 - o0);
                  gint da = ((a1 - a0) << 16) / (o1 - o0);
                  gint r = r0 << 16;
                  gint g = g0 << 16;
                  gint b = b0 << 16;
                  gint a = a0 << 16;
                  for (int j = o0; j < o1 + 1; j++) {
                        gr->color[4 * j] = r >> 16;
                        gr->color[4 * j + 1] = g >> 16;
                        gr->color[4 * j + 2] = b >> 16;
                        gr->color[4 * j + 3] = a >> 16;
                        r += dr;
                        g += dg;
                        b += db;
                        a += da;
                  }
            }
      }

      gr->len = gr->vector->end - gr->vector->start;
}


Generated by  Doxygen 1.6.0   Back to index