Example usage for java.lang Math max

List of usage examples for java.lang Math max

Introduction

In this page you can find the example usage for java.lang Math max.

Prototype

@HotSpotIntrinsicCandidate
public static double max(double a, double b) 

Source Link

Document

Returns the greater of two double values.

Usage

From source file:Main.java

/**
 * Creates an animation to fade the dialog opacity from 1 to 0.
 *//*from  w ww.j  a va  2 s.  c  o  m*/
public static void fadeOut(final JDialog dialog) {
    final Timer timer = new Timer(10, null);
    timer.setRepeats(true);
    timer.addActionListener(new ActionListener() {
        private float opacity = 1;

        @Override
        public void actionPerformed(ActionEvent e) {
            opacity -= 0.15f;
            dialog.setOpacity(Math.max(opacity, 0));
            if (opacity <= 0) {
                timer.stop();
                dialog.dispose();
            }
        }
    });

    dialog.setOpacity(1);
    timer.start();
}

From source file:Main.java

private static void rgbToHsl(int color, float hsl[]) {

    float r = Color.red(color) / 255.f;
    float g = Color.green(color) / 255.f;
    float b = Color.blue(color) / 255.f;
    float max = Math.max(Math.max(r, g), b);
    float min = Math.min(Math.min(r, g), b);
    float h;//from ww  w.j  a  v  a  2 s  .  co  m
    float s;
    float l;

    h = s = l = (max + min) / 2;

    if (max == min) {
        h = s = 0;
    } else {
        float delta = max - min;
        s = l > 0.5f ? delta / (2f - max - min) : delta / (max + min);
        if (max == r) {
            h = (g - b) / delta;
        } else if (max == g) {
            h = (b - r) / delta + 2f;
        } else if (max == b) {
            h = (r - g) / delta + 4f;
        }
        h *= 60f;
        if (h < 0f) {
            h += 360f;
        } else if (h > 360f) {
            h -= 360f;
        }
    }
    hsl[0] = h;
    hsl[1] = s;
    hsl[2] = l;
}

From source file:Main.java

/**
 * Clamp a value to be within the provided range.
 * @param value the value to clamp/*from   w  w  w .j a  v  a2s . co  m*/
 * @param low the low end of the range
 * @param high the high end of the range
 * @return the clamped value
 */
public static double clamp(double value, double low, double high) {
    return Math.min(Math.max(value, low), high);
}

From source file:Main.java

public static Bitmap resizeImage(Bitmap image, int maxWidth, int maxHeight) {
    Log.d(TAG, "[AirImagePickerUtils] Entering resizeImage: " + String.valueOf(maxWidth) + " x "
            + String.valueOf(maxHeight));
    Bitmap result = image;//from  ww w  .  j  a  va 2  s.  c  o  m
    // make sure that the image has the correct height
    if (image.getWidth() > maxWidth || image.getHeight() > maxHeight && maxWidth != -1 && maxHeight != -1) {
        float reductionFactor = Math.max(Float.valueOf(image.getWidth()) / maxWidth,
                Float.valueOf(image.getHeight()) / maxHeight);

        result = Bitmap.createScaledBitmap(image, (int) (image.getWidth() / reductionFactor),
                (int) (image.getHeight() / reductionFactor), true);
        Log.d(TAG, "[AirImagePickerUtils] resized image to: " + String.valueOf(result.getWidth()) + " x "
                + String.valueOf(result.getHeight()));
    }
    Log.d(TAG, "[AirImagePickerUtils] Exiting resizeImage");
    return result;
}

From source file:Main.java

public static BufferedImage joinBufferedImage(BufferedImage img1, BufferedImage img2) {
    int offset = 2;
    int width = img1.getWidth() + img2.getWidth() + offset;
    int height = Math.max(img1.getHeight(), img2.getHeight()) + offset;
    BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = newImage.createGraphics();
    Color oldColor = g2.getColor();
    g2.setPaint(Color.BLACK);/*w w w  . j  a v  a 2  s .c  o m*/
    g2.fillRect(0, 0, width, height);
    g2.setColor(oldColor);
    g2.drawImage(img1, null, 0, 0);
    g2.drawImage(img2, null, img1.getWidth() + offset, 0);
    g2.dispose();
    return newImage;
}

From source file:Main.java

public static Bitmap applySaturationFilter(Bitmap source, int level) {
    int width = source.getWidth();
    int height = source.getHeight();
    int[] pixels = new int[width * height];
    float[] HSV = new float[3];
    source.getPixels(pixels, 0, width, 0, 0, width, height);

    int index = 0;
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            index = y * width + x;//  ww w  .java2  s .  c om
            Color.colorToHSV(pixels[index], HSV);
            HSV[1] *= level;
            HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
            pixels[index] |= Color.HSVToColor(HSV);
        }
    }
    Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
    return bmOut;
}

From source file:Main.java

public static float calculateZoomScale(int originalWidth, int originalHeight, int expectWidth,
        int expectHeight) {
    float hScale = expectWidth / (float) originalWidth;
    float vScale = expectHeight / (float) originalHeight;
    return Math.max(hScale, vScale);
}

From source file:Main.java

@SuppressLint("NewApi")
public static void revealView(View toBeRevealed, View frame) {
    try {/*  w  w  w . j  av  a  2s. c o  m*/
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            // get the center for the clipping circle
            int cx = (frame.getLeft() + frame.getRight()) / 2;
            int cy = (frame.getTop() + frame.getBottom()) / 2;

            // get the final radius for the clipping circle
            int finalRadius = Math.max(frame.getWidth(), frame.getHeight());

            // create the animator for this view (the start radius is zero)
            Animator anim = ViewAnimationUtils.createCircularReveal(toBeRevealed, cx, cy, 0, finalRadius);

            // make the view visible and start the animation
            toBeRevealed.setVisibility(View.VISIBLE);
            anim.start();
        } else {
            toBeRevealed.setVisibility(View.VISIBLE);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static int getSampleSize(BitmapFactory.Options options, int maxWidth, int maxHeight) {
    // raw height and width of image
    int rawWidth = options.outWidth;
    int rawHeight = options.outHeight;

    // calculate best sample size
    int inSampleSize = 0;
    if (rawHeight > maxHeight || rawWidth > maxWidth) {
        float ratioWidth = (float) rawWidth / maxWidth;
        float ratioHeight = (float) rawHeight / maxHeight;
        inSampleSize = (int) Math.min(ratioHeight, ratioWidth);
    }/*from   w  w  w .  j a v a  2 s. com*/
    inSampleSize = Math.max(1, inSampleSize);

    return inSampleSize;
}

From source file:Main.java

public static int max(final int... values) {
    int max = Integer.MIN_VALUE;
    for (final int v : values) {
        max = Math.max(v, max);
    }/*from   w w  w  .jav  a 2 s .co  m*/
    return max;
}