Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Default amount to shift colors by. Not used by the testing suite, so feel free to change this
- * value.
- */
- public static final int DEFAULT_COLOR_SHIFT = 32;
- /**
- * All ones.
- */
- public static final int FULL = 0xff;
- /**
- * Green shift.
- */
- public static final int GREEN_SHIFT = 8;
- /**
- * Blue shift.
- */
- public static final int BLUE_SHIFT = 16;
- /**
- * Alpha shift.
- */
- public static final int ALPHA_SHIFT = 24;
- /**
- *
- * @param shiftAmount amount to be shifted
- * @param colorShift which color is being shifted
- * @param originalImage image to be shifted
- * @return shifted image
- */
- public static int[][]colorShift(final int shiftAmount, final int colorShift,
- final int[][] originalImage) {
- int[][] shiftedImage = new int[originalImage.length][originalImage[0].length];
- for (int x = 0; x < originalImage.length; x++) {
- for (int y = 0; y < originalImage[x].length; y++) {
- int redVal = originalImage[x][y] & FULL;
- int greenVal = (originalImage[x][y] >> GREEN_SHIFT) & FULL;
- int blueVal = (originalImage[x][y] >> BLUE_SHIFT) & FULL;
- int alphaVal = (originalImage[x][y] >> ALPHA_SHIFT) & FULL;
- if (colorShift == 0) {
- if (alphaVal + shiftAmount >= FULL) {
- alphaVal = FULL;
- } else if (alphaVal + shiftAmount <= 0) {
- alphaVal = 0;
- } else {
- alphaVal += shiftAmount;
- }
- } else if (colorShift == 1) {
- if (redVal + shiftAmount >= FULL) {
- redVal = FULL;
- } else if (redVal + shiftAmount <= 0) {
- redVal = 0;
- } else {
- redVal += shiftAmount;
- }
- } else if (colorShift == 2) {
- if (greenVal + shiftAmount >= FULL) {
- greenVal = FULL;
- } else if (greenVal + shiftAmount <= 0) {
- greenVal = 0;
- } else {
- greenVal += shiftAmount;
- }
- } else if (colorShift == (1 + 1 + 1)) {
- if (blueVal + shiftAmount >= FULL) {
- blueVal = FULL;
- } else if (blueVal + shiftAmount <= 0) {
- blueVal = 0;
- } else {
- blueVal += shiftAmount;
- }
- }
- shiftedImage[x][y] = redVal | (greenVal << GREEN_SHIFT) | (blueVal << BLUE_SHIFT)
- | (alphaVal << ALPHA_SHIFT);
- }
- }
- return shiftedImage;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement