Logo Search packages:      
Sourcecode: inkscape version File versions

void sp_gradient_ensure_colors ( SPGradient gr  ) 

Ensures that color array is populated

The gradient's color array is newly created and set up from vector.

Todo:
Where is the memory freed?

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

References SPGradientVector::built, SPGradient::color, NCOLORS, sp_gradient_rebuild_vector(), SPGradientVector::stops, and SPGradient::vector.

Referenced by sp_gradient_modified(), sp_gradient_render_vector_line_rgba(), sp_lg_fill(), sp_lineargradient_painter_new(), sp_radialgradient_painter_new(), and sp_rg_fill().

{
    if (!gr->vector.built) {
        sp_gradient_rebuild_vector(gr);
    }
    g_return_if_fail(!gr->vector.stops.empty());

    /// \todo Where is the memory freed?
    if (!gr->color) {
        gr->color = g_new(guchar, 4 * NCOLORS);
    }

    for (guint i = 0; i < gr->vector.stops.size() - 1; i++) {
        guint32 color = gr->vector.stops[i].color.toRGBA32( 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 = gr->vector.stops[i + 1].color.toRGBA32( 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;
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index