Java Number Multiply multiply(int a, int b)

Here you can find the source of multiply(int a, int b)

Description

multiply

License

LGPL

Declaration

public static int multiply(int a, int b) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static int multiply(int a, int b) {
        int ar = getRed(a);
        int ag = getGreen(a);
        int ab = getBlue(a);

        ar *= getRed(b);//from   w w  w.  j a v  a 2  s  .  com
        ag *= getGreen(b);
        ab *= getBlue(b);

        return getRGB(clamp(ar), clamp(ag), clamp(ab));
    }

    public static int getRed(int rgb) {
        return (rgb >> 16) & 0xFF;
    }

    public static int getGreen(int rgb) {
        return (rgb >> 8) & 0xFF;
    }

    public static int getBlue(int rgb) {
        return rgb & 0xFF;
    }

    public static int getRGB(int red, int green, int blue) {
        int alpha = 0xff;
        int rgb = alpha;
        rgb = (rgb << 8) + red;
        rgb = (rgb << 8) + green;
        rgb = (rgb << 8) + blue;

        return rgb;
    }

    public static int clamp(int a) {
        if (a < 0) {
            return 0;
        } else if (a > 0xff) {
            return 0xff;
        }
        return a;
    }

    public static double clamp(double a) {
        if (a < 0) {
            return 0;
        } else if (a > 0xff) {
            return 0xff;
        }
        return a;
    }
}

Related

  1. multiply(Double a, Double b)
  2. Multiply(double px0, double py0, double px1, double py1, double px2, double py2)
  3. multiply(final long a, final long b)
  4. multiply(final long x, final long y)
  5. multiply(int x, int y)
  6. multiply(Number a, Number b)
  7. multiply(Number a, Number b, Class cl)
  8. multiply(Number n1, Number n2)