List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** * @param color/*from w w w .j av a 2 s . com*/ * @param factor * @return a new color, darker than the one passed as argument by a percentage factor * * <br>author Cyril Gambis - [Mar 17, 2005] */ public static Color darker(Color color, double factor) { return new Color(Math.max((int) (color.getRed() * factor), 0), Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0)); }
From source file:Main.java
public static BitmapFactory.Options createBitmapScaledOptions(int targetResolution, int actualResolution) { double scaleFactor = Math.log((double) actualResolution / (double) targetResolution) / Math.log(2); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = Math.max(1, (int) Math.floor(scaleFactor)); return options; }
From source file:Main.java
public static void center(Component c) { Dimension screenSize = c.getToolkit().getScreenSize(); Dimension componentSize = c.getSize(); int xPos = (screenSize.width - componentSize.width) / 2; xPos = Math.max(xPos, 0); int yPos = (screenSize.height - componentSize.height) / 2; yPos = Math.max(yPos, 0);//from ww w.j a v a 2 s. c o m c.setLocation(new Point(xPos, yPos)); }
From source file:Main.java
public static int colsToInt(int r, int g, int b) { return (255 << 24) + (Math.max(Math.min(r, 255), 0) << 16) + (Math.max(Math.min(g, 255), 0) << 8) + Math.max(Math.min(b, 255), 0); }
From source file:Main.java
/** * Returns the brightness component of a color int. * * @return A value between 0.0f and 1.0f * * @hide Pending API council/*ww w .j a v a 2s. c o m*/ */ public static float brightness(int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); return (V / 255.f); }
From source file:Main.java
public static Bitmap createCroppedScaleBitmap(Bitmap src, int reqWidth, int reqHeight) { final int bWidth = src.getWidth(); final int bHeight = src.getHeight(); Matrix matrix = new Matrix(); int maxSize = Math.max(reqHeight, reqWidth); float scaleX; if (bWidth * bHeight < reqWidth * reqHeight) scaleX = 0;//from w ww . j ava 2 s.co m else { if (bWidth > bHeight) { scaleX = (float) maxSize / bWidth; } else scaleX = (float) maxSize / bHeight; } Bitmap sourceBitmap; if (scaleX > 0 && scaleX != 1) { matrix.setScale(scaleX, scaleX); sourceBitmap = Bitmap.createBitmap(src, 0, 0, bWidth, bHeight, matrix, true); if (sourceBitmap != src && !src.isRecycled()) src.recycle(); } else sourceBitmap = src; return sourceBitmap; }
From source file:Main.java
public static int lighten(int color) { double r = Color.red(color); double g = Color.green(color); double b = Color.blue(color); r *= 1.1;/* w w w. jav a 2 s. c o m*/ g *= 1.1; b *= 1.1; double threshold = 255.999; double max = Math.max(r, Math.max(g, b)); if (max > threshold) { double total = r + g + b; if (total >= 3 * threshold) return Color.WHITE; double x = (3 * threshold - total) / (3 * max - total); double gray = threshold - x * max; r = gray + x * r; g = gray + x * g; b = gray + x * b; } return Color.argb(255, (int) r, (int) g, (int) b); }
From source file:Main.java
/** * Get bottom value of the bounding rectangle of the given points. *///from w w w .jav a 2 s . c om static float getRectBottom(float[] points) { return Math.max(Math.max(Math.max(points[1], points[3]), points[5]), points[7]); }
From source file:Main.java
/** * @param options/*from w w w.j av a2 s. co m*/ * @param target * @return */ public static int computeSampleSize(Options options, int target) { int w = options.outWidth; int h = options.outHeight; int candidateW = w / target; int candidateH = h / target; int candidate = Math.max(candidateW, candidateH); if (candidate == 0) { return 1; } if (candidate > 1) { if ((w > target) && (w / candidate) < target) { candidate -= 1; } } if (candidate > 1) { if ((h > target) && (h / candidate) < target) { candidate -= 1; } } return candidate; }
From source file:Main.java
/** * Computes the lightness value in HSL standard for the given color. */// w ww .j av a2 s .c o m public static float getLightnessForColor(int color) { int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); int largest = Math.max(red, Math.max(green, blue)); int smallest = Math.min(red, Math.min(green, blue)); int average = (largest + smallest) / 2; return average / 255.0f; }