Java Integer Clip clip(int[][][] data, int startX, int startY, int stopX, int stopY)

Here you can find the source of clip(int[][][] data, int startX, int startY, int stopX, int stopY)

Description

This method clips the values of the pixel so that they are in the range 0-255

License

Open Source License

Parameter

Parameter Description
data The image data
startX is the x pixel of the image to start from
startY is the y pixel of the image to start from
stopX is the x pixel of the image to stop
stopY is the y pixel of the image to stop

Declaration

public static void clip(int[][][] data, int startX, int startY, int stopX, int stopY) 

Method Source Code

//package com.java2s;
/*/*ww  w.  j a  v  a 2 s  .co m*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Ziver Koc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

public class Main {
    /**
     * This method clips the values of the pixel so that they
     * are in the range 0-255
     *
     * @param   data    The image data
     * @param   startX  is the x pixel of the image to start from
     * @param   startY  is the y pixel of the image to start from
     * @param   stopX   is the x pixel of the image to stop
     * @param   stopY   is the y pixel of the image to stop
     */
    public static void clip(int[][][] data, int startX, int startY, int stopX, int stopY) {
        for (int y = startY; y < stopY; y++) {
            for (int x = startX; x < stopX; x++) {
                data[y][x][1] = clip(data[y][x][1]);
                data[y][x][2] = clip(data[y][x][2]);
                data[y][x][3] = clip(data[y][x][3]);
            }
        }
    }

    /**
     * This method clips the values of a color so that it
     * is in the range 0-255
     */
    public static int clip(int color) {
        if (color < 0)
            return 0;
        else if (color > 255)
            return 255;
        else
            return color;
    }
}

Related

  1. clip(int a, int min, int max)
  2. clip(int lower, int upper, int x)
  3. clip(int val, int from, int to)
  4. clip(int val, int from, int to)
  5. clip(int x)
  6. clipColor(final int compIn, final boolean allowRGB555)
  7. clipHistogram(final int[] hist, final int[] clippedHist, final int limit)
  8. clipInt(int value, int max)
  9. clipInt(int value, int min, int max)