Beispiel #1
0
gdImagePtr rs_gdImageThickLineBrush(int line_weight, RS_Color& color)
{
    if (line_weight % 2 == 1)
        line_weight += 1;

    int sx = line_weight;
    int sy = line_weight;

    gdImagePtr brush = gdImageCreateTrueColor(sx, sy);
    int transparent = gdImageColorAllocateAlpha(brush, 0, 0, 0, 127);

    gdImageAlphaBlending(brush, 0);
    gdImageFilledRectangle(brush, 0, 0, sx, sy, transparent);

    //compute fractional alpha value for antialiasing effect
    //each pixel should be hit by line_weight / 2 number of circles
    //so the alpha is computed as 255 / line_weight * 2
    RS_Color falpha = color;
    falpha.alpha() = falpha.alpha() / line_weight * 2 + 1;
    falpha.alpha() = (falpha.alpha() < 255)? falpha.alpha() : 255;

    //outer transparent circle -- for antialiased effect
    rs_gdImageCircleForBrush(brush, sx/2, sy/2, line_weight / 2,  falpha);

    gdImageAlphaBlending(brush, 1);

    //inner non-transparent circle
    rs_gdImageCircleForBrush(brush, sx/2, sy/2, (line_weight - 2) / 2, color);

    return brush;
}
Beispiel #2
0
//axis aligned circle for setting up brushes for thick lines
void rs_gdImageCircleForBrush(gdImagePtr im, int x, int y, int rad, RS_Color& color)
{
    int gdc = ConvertColor(im, color);
    float rad2 = (float)rad*rad;

    for (int j = -rad, k = y+j; j <= rad; j++, k++)
    {
        float j_offset = j + 0.5f;

        float hlen = sqrt(rad2 - j_offset*j_offset);

        int solidwid = (int)hlen;

        if (solidwid)
            gdImageLine(im, x-solidwid, k, x+solidwid-1, k, gdc);

        float aalpha = hlen - solidwid;
        RS_Color ac = color;
        ac.alpha() = (int)(ac.alpha() * aalpha);
        int gdc2 = ConvertColor(im, ac);

        gdImageSetPixel(im, x-solidwid-1, k, gdc2);
        gdImageSetPixel(im, x+solidwid, k, gdc2);
    }
}
Beispiel #3
0
int ConvertColor(gdImagePtr i, RS_Color& c)
{
    return gdImageColorAllocateAlpha(i, c.red(), c.green(), c.blue(), 127 - c.alpha()/2 );
}
Beispiel #4
0
bool GeometryAdapter::EvalColor(const MdfModel::MdfString& exprstr, RS_Color& rscolor)
{
    // TODO: needs an expression processor argument to eval expressions

    // string is in the form "AARRGGBB"
    const wchar_t* scolor = exprstr.c_str();

    size_t len = wcslen(scolor);
    unsigned int color = 0;
    bool isConst = false;

    // try to check if the expression is constant
    int status = 0;
    if (len == 0)
    {
        // error or a color was not set
        // use transparent black which indicates "not set"
        rscolor = RS_Color(RS_Color::EMPTY_COLOR_RGBA);
        return true;
    }
    else if (len == 8)
    {
        status = swscanf(scolor, L"%8X", &color);
    }
    else if (len == 6)
    {
        status = swscanf(scolor, L"%6X", &color);

        // there was no alpha specified in the constant string, add it
        color |= 0xFF000000;
    }

    if (status != 1)
    {
        // if not constant try to evaluate as expression
        if (!m_exec)
        {
            _ASSERT(false);
            rscolor = RS_Color(0x000000FF);
            return true;
        }

        FdoExpression* expr = ObtainFdoExpression(&exprstr);

        // make sure we have a parsed expression
        if (!expr)
        {
            _ASSERT(false);
            rscolor = RS_Color(0x000000FF);
            return false;
        }

        try
        {
            FdoPtr<FdoLiteralValue> lval = m_exec->Evaluate(expr);
            color = (unsigned int)ExpressionHelper::GetAsInt32(lval.p);
        }
        catch (FdoException* e)
        {
            ProcessStylizerException(e, __LINE__, __WFILE__);
            rscolor = RS_Color(0x000000FF);
            return false;
        }
        catch (...)
        {
            return false;
        }
    }
    else
    {
        isConst = true;
    }

    rscolor.alpha() =  color >> 24;
    rscolor.red()   = (color >> 16) & 0xFF;
    rscolor.green() = (color >>  8) & 0xFF;
    rscolor.blue()  =  color        & 0xFF;

    return isConst;
}