Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. /**
  2. * Default amount to shift colors by. Not used by the testing suite, so feel free to change this
  3. * value.
  4. */
  5. public static final int DEFAULT_COLOR_SHIFT = 32;
  6. /**
  7. * All ones.
  8. */
  9. public static final int FULL = 0xff;
  10. /**
  11. * Green shift.
  12. */
  13. public static final int GREEN_SHIFT = 8;
  14. /**
  15. * Blue shift.
  16. */
  17. public static final int BLUE_SHIFT = 16;
  18. /**
  19. * Alpha shift.
  20. */
  21. public static final int ALPHA_SHIFT = 24;
  22. /**
  23. *
  24. * @param shiftAmount amount to be shifted
  25. * @param colorShift which color is being shifted
  26. * @param originalImage image to be shifted
  27. * @return shifted image
  28. */
  29.  
  30. public static int[][]colorShift(final int shiftAmount, final int colorShift,
  31. final int[][] originalImage) {
  32. int[][] shiftedImage = new int[originalImage.length][originalImage[0].length];
  33. for (int x = 0; x < originalImage.length; x++) {
  34. for (int y = 0; y < originalImage[x].length; y++) {
  35. int redVal = originalImage[x][y] & FULL;
  36. int greenVal = (originalImage[x][y] >> GREEN_SHIFT) & FULL;
  37. int blueVal = (originalImage[x][y] >> BLUE_SHIFT) & FULL;
  38. int alphaVal = (originalImage[x][y] >> ALPHA_SHIFT) & FULL;
  39. if (colorShift == 0) {
  40. if (alphaVal + shiftAmount >= FULL) {
  41. alphaVal = FULL;
  42. } else if (alphaVal + shiftAmount <= 0) {
  43. alphaVal = 0;
  44. } else {
  45. alphaVal += shiftAmount;
  46. }
  47. } else if (colorShift == 1) {
  48. if (redVal + shiftAmount >= FULL) {
  49. redVal = FULL;
  50. } else if (redVal + shiftAmount <= 0) {
  51. redVal = 0;
  52. } else {
  53. redVal += shiftAmount;
  54. }
  55. } else if (colorShift == 2) {
  56. if (greenVal + shiftAmount >= FULL) {
  57. greenVal = FULL;
  58. } else if (greenVal + shiftAmount <= 0) {
  59. greenVal = 0;
  60. } else {
  61. greenVal += shiftAmount;
  62. }
  63. } else if (colorShift == (1 + 1 + 1)) {
  64. if (blueVal + shiftAmount >= FULL) {
  65. blueVal = FULL;
  66. } else if (blueVal + shiftAmount <= 0) {
  67. blueVal = 0;
  68. } else {
  69. blueVal += shiftAmount;
  70. }
  71. }
  72. shiftedImage[x][y] = redVal | (greenVal << GREEN_SHIFT) | (blueVal << BLUE_SHIFT)
  73. | (alphaVal << ALPHA_SHIFT);
  74. }
  75. }
  76. return shiftedImage;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement