List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
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;/*from w w w.j av a2s . c o m*/ 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
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;// ww w . j a v a 2 s. c om 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
public static float constrain(float min, float max, float v) { return Math.max(min, Math.min(max, v)); }
From source file:Main.java
public static Bitmap resize(Bitmap bitmap, int targetWidth, int targetHeight) { if (bitmap == null || targetWidth < 0 || targetHeight < 0) { return null; }//from ww w . j a v a 2 s. co m int pictureWidth = bitmap.getWidth(); int pictureHeight = bitmap.getHeight(); float scale = Math.min((float) targetWidth / pictureWidth, (float) targetHeight / pictureHeight); // (1) Matrix matrix = new Matrix(); matrix.postScale(scale, scale); return Bitmap.createBitmap(bitmap, 0, 0, pictureWidth, pictureHeight, matrix, true); }
From source file:Main.java
/** * Get a range from a list based on start and count parameters in a safe way. * * @param start The start index// ww w.ja v a2 s . c o m * @param count The number of elements to add * * @return The sublist consisting at most of {@code count} elements (less if the parameters * exceed the size of the list) */ public static <T> List<T> getRange(List<T> list, int start, int count) { if (start >= list.size() || count <= 0) { return new ArrayList<>(); } else if (start < 0) { start = 0; } int end = Math.min(list.size(), start + count); return list.subList(start, end); }
From source file:Main.java
/** * Expands an array of Objects to double of its current size. Remember to use cast to turn the result into an array of the appropriate class, i.e: * //w ww . j av a 2s . c om * <code>someArray=(SomeClass [])unlekker.util.Util.expandArray(someArray); * @param list Array to be expanded. * @return Array of Object [], must be cast to appropriate class. */ static public Object expandArray(Object[] list) { int newSize = list.length * 2; Class type = list.getClass().getComponentType(); Object temp = Array.newInstance(type, newSize); System.arraycopy(list, 0, temp, 0, Math.min(Array.getLength(list), newSize)); return temp; }
From source file:Main.java
static public long[] resizeArray(long[] f, int newSize) { long[] newf = new long[newSize]; System.arraycopy(f, 0, newf, 0, Math.min(f.length, newSize)); return newf;/* w w w . j a v a2s. c o m*/ }
From source file:Main.java
public static Bitmap getSampleBitmap(Activity activity, String filepath) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w.ja v a 2s.co m BitmapFactory.decodeFile(filepath, options); options.inJustDecodeBounds = false; int width = options.outWidth; int height = options.outHeight; DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int scale = Math.min(width / dm.widthPixels, height / dm.heightPixels); options.inSampleSize = scale; Bitmap bitmap2 = BitmapFactory.decodeFile(filepath, options); return bitmap2; }
From source file:com.naver.template.common.ChunkUtils.java
public static <T> List<List<T>> chunk(List<T> list, int chunkSize) { List<List<T>> chunkedList = new ArrayList<List<T>>(); int start = 0; while (start < list.size()) { int end = Math.min(chunkSize + start, list.size()); chunkedList.add(list.subList(start, end)); start = end;//from w w w . j a v a2 s . c o m } return chunkedList; }
From source file:Main.java
public static byte[] readInputStream(InputStream inputStream) throws IOException { byte[] buffer = new byte[4096]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(4096); // Do the first byte via a blocking read outputStream.write(inputStream.read()); // Slurp the rest int available = 0;// inputStream.available(); boolean run = true; while (run && (available = inputStream.available()) > 0) { // Log.d(TAG, "slurp " + available); while (available > 0) { int cbToRead = Math.min(buffer.length, available); int cbRead = inputStream.read(buffer, 0, cbToRead); if (cbRead <= 0) { run = false;/*from w ww . j a v a2s .c om*/ break; } outputStream.write(buffer, 0, cbRead); available -= cbRead; } } return outputStream.toByteArray(); }