Beispiel #1
0
/*-----------------------------------------------------------------------------
    Name        : teColorAdjust
    Description : Adjust a color according to a HLS colorizing table.
    Inputs      : baseColor - origional color
                  colorize - HLS parameters to adjust by.
    Outputs     :
    Return      : newly adjusted color
----------------------------------------------------------------------------*/
color teColorAdjust(color baseColor, trhlscolorize *colorize)
{
    real32 red, green, blue, hue, lum, sat;
    colRGBToHLS(&hue, &lum, &sat, colUbyteToReal(colRed(baseColor)),
                colUbyteToReal(colGreen(baseColor)),
                colUbyteToReal(colBlue(baseColor)));
    hue += colorize->hue;
    if (hue < 0)
    {
        hue += 1.0f;
    }
    if (hue > 1.0f)
    {
        hue -= 1.0f;
    }
    lum *= colorize->lum;
    sat *= colorize->sat;
    if (lum > 1.0f)
    {
        lum = 1.0f;
    }
    if (sat > 1.0f)
    {
        sat = 1.0f;
    }
    colHLSToRGB(&red, &green, &blue, hue, lum, sat);
    return(colRGB(colRealToUbyte(red), colRealToUbyte(green), colRealToUbyte(blue)));
}
Beispiel #2
0
void teTeamColorsSet(sdword iTeam, color baseColor, color stripeColor)
{
    sdword index;
    real32 red, green, blue, hue, sat, val;

    dbgAssert(iTeam >= 0 && iTeam < TE_NumberPlayers);

    if (multiPlayerGame)
    {                                                       //if somebody in a multiplayer game
        red = colUbyteToReal(colRed(baseColor));
        green = colUbyteToReal(colGreen(baseColor));
        blue = colUbyteToReal(colBlue(baseColor));
        colRGBToHSV(&hue, &sat, &val, red, green, blue);
        if (colRealToUbyte(val) < cpDarkestColor0 * TE_DarkColorGraceFactor)
        {                                                   //is trying to set his ships to black
            baseColor = TE_DorkyCheaterBaseColor;
            stripeColor = TE_DorkyCheaterStripeColor;
        }
    }
    teColorSchemes[iTeam].textureColor.base = baseColor;
    teColorSchemes[iTeam].textureColor.detail = stripeColor;

#if !TO_STANDARD_COLORS
    teColorSchemes[iTeam].tacticalColor =
        teColorAdjust(baseColor, &teTacticalColorize);
#endif
    for (index = 0; index < TE_NumberTrailColors; index++)
    {
        teColorSchemes[iTeam].trailColors[index] =
            teColorAdjust(baseColor, &teTrailColorize[index]);
    }
    for (iTeam = 0; iTeam < TE_NumberPlayers; iTeam++)
    {
        teColorSchemes[iTeam].ambient = colRGB(colClamp256(colRed(teColorSchemes[iTeam].textureColor.base) * teAmbientAdjust / 65536),
            colClamp256(colGreen(teColorSchemes[iTeam].textureColor.base) * teAmbientAdjust / 65536),
            colClamp256(colBlue(teColorSchemes[iTeam].textureColor.base) * teAmbientAdjust / 65536));
        teColorSchemes[iTeam].diffuse = colRGB(colClamp256(colRed(teColorSchemes[iTeam].textureColor.base) * teDiffuseAdjust / 65536),
            colClamp256(colGreen(teColorSchemes[iTeam].textureColor.base) * teDiffuseAdjust / 65536),
            colClamp256(colBlue(teColorSchemes[iTeam].textureColor.base) * teDiffuseAdjust / 65536));
        teColorSchemes[iTeam].specular = colRGB(colClamp256(colRed(teColorSchemes[iTeam].textureColor.base) * teSpecularAdjust / 65536),
            colClamp256(colGreen(teColorSchemes[iTeam].textureColor.base) * teSpecularAdjust / 65536),
            colClamp256(colBlue(teColorSchemes[iTeam].textureColor.base) * teSpecularAdjust / 65536));
        teColorSchemes[iTeam].stripeAmbient = colRGB(colClamp256(colRed(teColorSchemes[iTeam].textureColor.base) * teAmbientAdjust / 65536),
            colClamp256(colGreen(teColorSchemes[iTeam].textureColor.base) * teAmbientAdjust / 65536),
            colClamp256(colBlue(teColorSchemes[iTeam].textureColor.base) * teAmbientAdjust / 65536));
        teColorSchemes[iTeam].stripeDiffuse = colRGB(colClamp256(colRed(teColorSchemes[iTeam].textureColor.base) * teDiffuseAdjust / 65536),
            colClamp256(colGreen(teColorSchemes[iTeam].textureColor.base) * teDiffuseAdjust / 65536),
            colClamp256(colBlue(teColorSchemes[iTeam].textureColor.base) * teDiffuseAdjust / 65536));
        teColorSchemes[iTeam].stripeSpecular = colRGB(colClamp256(colRed(teColorSchemes[iTeam].textureColor.base) * teSpecularAdjust / 65536),
            colClamp256(colGreen(teColorSchemes[iTeam].textureColor.base) * teSpecularAdjust / 65536),
            colClamp256(colBlue(teColorSchemes[iTeam].textureColor.base) * teSpecularAdjust / 65536));
    }
}
Beispiel #3
0
void liBlendScreen(color *buffer, color *layer, real32 opacity, sdword nPixels)
{
    real32 redSource, greenSource, blueSource, alpha;
    real32 redDest, greenDest, blueDest;//, alphaDest;
    real32 oneMinusAlpha;

    while (nPixels > 0)
    {
        alpha = colUbyteToReal(colAlpha(*layer)) * opacity;
        oneMinusAlpha = 1.0f - alpha;
        redSource = colUbyteToReal(colRed(*layer));    //read pixel to floating point
        greenSource = colUbyteToReal(colGreen(*layer));
        blueSource = colUbyteToReal(colBlue(*layer));
        redDest = colUbyteToReal(colRed(*buffer));
        greenDest = colUbyteToReal(colGreen(*buffer));
        blueDest = colUbyteToReal(colBlue(*buffer));

        redDest = (1.0f - (1.0f - redDest) * (1.0f - redSource)) * alpha + redDest * oneMinusAlpha;
        greenDest = (1.0f - (1.0f - greenDest) * (1.0f - greenSource)) * alpha + greenDest * oneMinusAlpha;
        blueDest = (1.0f - (1.0f - blueDest) * (1.0f - blueSource)) * alpha + blueDest * oneMinusAlpha;
        redDest = min(redDest, 1.0f);
        greenDest = min(greenDest, 1.0f);
        blueDest = min(blueDest, 1.0f);
        *buffer = colRGB(colRealToUbyte(redDest), colRealToUbyte(greenDest),
                         colRealToUbyte(blueDest));
        buffer++;
        layer++;
        nPixels--;
    }
}
Beispiel #4
0
void liBlendOverlay(color *buffer, color *layer, real32 opacity, sdword nPixels)
{
    real32 redSource, greenSource, blueSource, alpha;
    real32 redDest, greenDest, blueDest;//, alphaDest;
    real32 oneMinusAlpha;
    real32 redTemp, greenTemp, blueTemp;

    while (nPixels > 0)
    {
        alpha = colUbyteToReal(colAlpha(*layer)) * opacity;
        oneMinusAlpha = 1.0f - alpha;
        redSource = colUbyteToReal(colRed(*layer));    //read pixel to floating point
        greenSource = colUbyteToReal(colGreen(*layer));
        blueSource = colUbyteToReal(colBlue(*layer));
        redDest = colUbyteToReal(colRed(*buffer));
        greenDest = colUbyteToReal(colGreen(*buffer));
        blueDest = colUbyteToReal(colBlue(*buffer));
        if (redDest < 0.5f)
        {
            redTemp = (2.0f * redSource * 2.0f * redDest) / 2.0f;
        }
        else
        {
            redTemp = 1.0f - ((2.0f * (1.0f - redSource)) * (2.0f * (1.0f - redDest)) / 2.0f);
        }
        if (greenDest < 0.5f)
        {
            greenTemp = (2.0f * greenSource * 2.0f * greenDest) / 2.0f;
        }
        else
        {
            greenTemp = 1.0f - ((2.0f * (1.0f - greenSource)) * (2.0f * (1.0f - greenDest)) / 2.0f);
        }
        if (blueDest < 0.5f)
        {
            blueTemp = (2.0f * blueSource * 2.0f * blueDest) / 2.0f;
        }
        else
        {
            blueTemp = 1.0f - ((2.0f * (1.0f - blueSource)) * (2.0f * (1.0f - blueDest)) / 2.0f);
        }
        redDest = redTemp * alpha + redDest * oneMinusAlpha;
        greenDest = greenTemp * alpha + greenDest * oneMinusAlpha;
        blueDest = blueTemp * alpha + blueDest * oneMinusAlpha;
        redDest = min(redDest, 1.0f);
        greenDest = min(greenDest, 1.0f);
        blueDest = min(blueDest, 1.0f);
        *buffer = colRGB(colRealToUbyte(redDest), colRealToUbyte(greenDest),
                         colRealToUbyte(blueDest));
        buffer++;
        layer++;
        nPixels--;
    }
}
Beispiel #5
0
//This one not a perfect copy, but pretty close
void liBlendColor(color *buffer, color *layer, real32 opacity, sdword nPixels)
{
    real32 redSource, greenSource, blueSource, alpha;
    real32 redDest, greenDest, blueDest;//, alphaDest;
    real32 oneMinusAlpha;
    real32 hueS, satS, hueD, satD, lumS, lumD;
    real32 clumD, clumS;
    real32 redTemp, greenTemp, blueTemp;

#if LI_VERBOSE_LEVEL >= 2
    dbgMessagef("\nColor: Blending mode not implemented perfectly.");
#endif

    while (nPixels > 0)
    {
        alpha = colUbyteToReal(colAlpha(*layer)) * opacity;
        oneMinusAlpha = 1.0f - alpha;
        redSource = colUbyteToReal(colRed(*layer));    //read pixel to floating point
        greenSource = colUbyteToReal(colGreen(*layer));
        blueSource = colUbyteToReal(colBlue(*layer));
        redDest = colUbyteToReal(colRed(*buffer));
        greenDest = colUbyteToReal(colGreen(*buffer));
        blueDest = colUbyteToReal(colBlue(*buffer));
        clumS = (redSource * LI_RedGamma + greenSource * LI_GreenGamma + blueSource * LI_BlueGamma) / LI_TotalGamma;
        clumD = (redDest * LI_RedGamma + greenDest * LI_GreenGamma + blueDest * LI_BlueGamma) / LI_TotalGamma;

        colRGBToHLS(&hueS, &lumS, &satS, redSource, greenSource, blueSource);
        colRGBToHLS(&hueD, &lumD, &satD, redDest, greenDest, blueDest);
        colHLSToRGB(&redTemp, &greenTemp, &blueTemp, hueS, clumD, satS);

        redDest = redTemp * alpha + redDest * oneMinusAlpha;
        greenDest = greenTemp * alpha + greenDest * oneMinusAlpha;
        blueDest = blueTemp * alpha + blueDest * oneMinusAlpha;
        redDest = min(redDest, 1.0f);
        greenDest = min(greenDest, 1.0f);
        blueDest = min(blueDest, 1.0f);

        *buffer = colRGB(colRealToUbyte(redDest), colRealToUbyte(greenDest),
                         colRealToUbyte(blueDest));
        buffer++;
        layer++;
        nPixels--;
    }
}
Beispiel #6
0
void liBlendColorDodge(color *buffer, color *layer, real32 opacity, sdword nPixels)
{
    real32 redSource, greenSource, blueSource, alpha;
    real32 redDest, greenDest, blueDest;//, alphaDest;
    real32 oneMinusAlpha;

    while (nPixels > 0)
    {
        alpha = colUbyteToReal(colAlpha(*layer)) * opacity;
        oneMinusAlpha = 1.0f - alpha;
        redSource = colUbyteToReal(colRed(*layer));    //read pixel to floating point
        greenSource = colUbyteToReal(colGreen(*layer));
        blueSource = colUbyteToReal(colBlue(*layer));
        redDest = colUbyteToReal(colRed(*buffer));
        greenDest = colUbyteToReal(colGreen(*buffer));
        blueDest = colUbyteToReal(colBlue(*buffer));
        redDest = (redDest + redSource * redSource * redDest) * alpha + redDest * oneMinusAlpha;
        greenDest = (greenDest + greenSource * greenSource * greenDest) * alpha + greenDest * oneMinusAlpha;
        blueDest = (blueDest + blueSource * blueSource * blueDest) * alpha + blueDest * oneMinusAlpha;
        redDest = min(redDest, 1.0f);
        greenDest = min(greenDest, 1.0f);
        blueDest = min(blueDest, 1.0f);
        *buffer = colRGB(colRealToUbyte(redDest), colRealToUbyte(greenDest),
                         colRealToUbyte(blueDest));
        buffer++;
        layer++;
        nPixels--;
    }
/*
    real32 redSource, greenSource, blueSource, alpha;
    real32 redDest, greenDest, blueDest;//, alphaDest;
    real32 oneMinusAlpha;
    real32 hueS, satS, valS, hueD, satD, valD;
//    real32 cvalD, cvalS;

    while (nPixels > 0)
    {
        alpha = colUbyteToReal(colAlpha(*layer)) * opacity;
        oneMinusAlpha = 1.0f - alpha;
        redSource = colUbyteToReal(colRed(*layer));    //read pixel to floating point
        greenSource = colUbyteToReal(colGreen(*layer));
        blueSource = colUbyteToReal(colBlue(*layer));
        redDest = colUbyteToReal(colRed(*buffer));
        greenDest = colUbyteToReal(colGreen(*buffer));
        blueDest = colUbyteToReal(colBlue(*buffer));
//        redDest = (redDest + redSource * redSource * redDest) * alpha + redDest * oneMinusAlpha;
//        greenDest = (greenDest + greenSource * greenSource * greenDest) * alpha + greenDest * oneMinusAlpha;
//        blueDest = (blueDest + blueSource * blueSource * blueDest) * alpha + blueDest * oneMinusAlpha;
        colRGBToHSV(&hueS, &satS, &valS, redSource * alpha, greenSource * alpha, blueSource * alpha);
        colRGBToHSV(&hueD, &satD, &valD, redDest, greenDest, blueDest);
        valD += valS;
        valD = min(valD, 1.0f);
        colHSVToRGB(&redDest, &greenDest, &blueDest, hueD, satD, valD);

        *buffer = colRGB(colRealToUbyte(redDest), colRealToUbyte(greenDest),
                         colRealToUbyte(blueDest));
        buffer++;
        layer++;
        nPixels--;
    }
*/
}