Guest User

Untitled

a guest
Oct 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // Utilisé pour réécrire chaque pixel d'une image.
  2. //
  3. // Used to rewrite each pixel of an image.
  4. public static Bitmap fixLimitedColor(Bitmap bitmap) {
  5. int redValue = 0;
  6. int blueValue = 0;
  7. int greenValue = 0;
  8.  
  9. int pixel = 0;
  10. for (int i = 0; i < bitmap.getHeight() - 1; i++) {
  11. for (int j = 0; j < bitmap.getWidth() - 1; j++) {
  12. pixel = bitmap.getPixel(j, i);
  13. redValue = Color.red(pixel);
  14. blueValue = Color.blue(pixel);
  15. greenValue = Color.green(pixel);
  16.  
  17. redValue = fixValue(redValue);
  18. blueValue = fixValue(blueValue);
  19. greenValue = fixValue(greenValue);
  20.  
  21. bitmap.setPixel(j, i, Color.rgb(redValue, greenValue, blueValue));
  22. }
  23. }
  24.  
  25. return bitmap;
  26. }
  27.  
  28. // Ecreteur de valeur, chaque couleur ne peux plus avoir que 5 valeur différentes.
  29. // Ce qui donne un total d'environs 125 valeur de couleur diffentes (RGB)
  30. //
  31. // Value scaler, each color can only have 5 different value.
  32. // Which is giving a total of 125 uniques color in RGB.
  33. private static int fixValue(int colorValue) {
  34. int minTol = 10;
  35. int min = 0;
  36. int max = 255;
  37. int medium = 128;
  38. int quarter = 64;
  39.  
  40. if (colorValue < quarter) {
  41. colorValue = min;
  42. } else if (colorValue < medium) {
  43. colorValue = quarter;
  44. } else if (colorValue < medium + quarter) {
  45. colorValue = medium;
  46. } else if (colorValue < max - minTol) {
  47. colorValue = medium + quarter;
  48. } else {
  49. colorValue = max;
  50. }
  51.  
  52. return colorValue;
  53. }
Add Comment
Please, Sign In to add comment