Java Lerp lerpAndPremultiplyColorWithAlpha(float t, int[] color1, int[] color2)

Here you can find the source of lerpAndPremultiplyColorWithAlpha(float t, int[] color1, int[] color2)

Description

lerp And Premultiply Color With Alpha

License

Open Source License

Declaration

public static int lerpAndPremultiplyColorWithAlpha(float t, int[] color1, int[] color2) 

Method Source Code

//package com.java2s;
/*/*from  ww w  . j av a 2 s  .  c om*/
 * Copyright 2015 Laszlo Balazs-Csiki
 *
 * This file is part of Pixelitor. Pixelitor is free software: you
 * can redistribute it and/or modify it under the terms of the GNU
 * General Public License, version 3 as published by the Free
 * Software Foundation.
 *
 * Pixelitor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Pixelitor. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static int lerpAndPremultiplyColorWithAlpha(float t, int[] color1, int[] color2) {
        int alpha = color1[0] + (int) (t * (color2[0] - color1[0]));
        int red;
        int green;
        int blue;
        if (alpha == 0) {
            red = 0;
            green = 0;
            blue = 0;
        } else {
            red = color1[1] + (int) (t * (color2[1] - color1[1]));
            green = color1[2] + (int) (t * (color2[2] - color1[2]));
            blue = color1[3] + (int) (t * (color2[3] - color1[3]));

            if (alpha != 255) { // premultiply
                float f = alpha / 255.0f;
                red *= f;
                green *= f;
                blue *= f;
            }
        }

        return (alpha << 24 | red << 16 | green << 8 | blue);
    }
}

Related

  1. lerp(float va, float vb, float t)
  2. lerp(float value1, float value2, float amount)
  3. lerp(int a, int b, float value)
  4. lerp(int a, int b, int mul, int div)
  5. lerpa(double a1, double a2, double t)
  6. lerpAngle(float fromRadians, float toRadians, float progress)
  7. LerpDegrees(float start, float end, float amount)
  8. lerpInt(int i1, int i2, double f)
  9. lerpQuad(double p0, double k0, double p1, double t)