Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. /*********************************
  2. *Name: Heewon Suh
  3. *Date: 2016/2/12
  4. *Student#:100936360
  5. **********************************/
  6.  
  7. import controlP5.*;
  8.  
  9. PImage img;
  10. ControlP5 debugUI;
  11. int brightness1 = 255;
  12. int saturation1= 255;
  13. int hue1= 255;
  14. boolean inverse1 = false;
  15.  
  16. void setup()
  17. {
  18. size(1000, 750); //set window size to same resolution as image
  19.  
  20. colorMode(HSB, 255, 255, 255);
  21.  
  22. img = loadImage( "GracefieldMorning.jpg" ); //loading image into memory (RAM) - no GPU acceleration here
  23.  
  24. //setting up our slider and adding the "brightness" so it knows that the variable it controls
  25. debugUI = new ControlP5(this);
  26.  
  27. debugUI.addSlider("brightness1")
  28. .setPosition(20, height-30)
  29. .setRange( 0 , 300 )
  30. .setSize(100, 20);
  31.  
  32.  
  33. debugUI.addSlider("saturation1")
  34. .setPosition(20, height-60)
  35. .setRange( 0, 100 )
  36. .setSize(100, 20);
  37.  
  38.  
  39. debugUI.addSlider("hue1")
  40. .setPosition(20, height-90)
  41. .setRange( 0, 400 )
  42. .setSize(100, 20);
  43.  
  44. debugUI.addButton("inverse1")
  45. .setPosition(20, height-120)
  46. .setSize(100, 20);
  47.  
  48. }
  49.  
  50. void draw()
  51. {
  52. //MAke a copy so we can keep original intact
  53. PImage imgcopy = img.get();
  54.  
  55. imgcopy.loadPixels();
  56.  
  57. float brightRatio = (float)brightness1 / 255.0f;
  58. float satRatio = (float)saturation1/ 255.0f;
  59. float hueRatio = (float)hue1 / 255.0f;
  60. if(inverse1 == true) {
  61. inverse();
  62. }
  63. int numPixels = imgcopy.pixels.length;
  64. for(int i = 0; i < numPixels; i++)
  65. {
  66. color prevCol = imgcopy.pixels[i];
  67. color newCol = color( hue(prevCol) * hueRatio, saturation(prevCol) * satRatio, brightness(prevCol) * brightRatio);
  68. imgcopy.pixels[i] = newCol;
  69. }
  70.  
  71. imgcopy.updatePixels();
  72.  
  73. image(imgcopy, 0, 0, width, height);
  74. }
  75.  
  76. void inverse()
  77. {
  78. PImage imgcopy = img.get();
  79.  
  80. imgcopy.loadPixels();
  81. filter(INVERT);
  82. imgcopy.updatePixels();
  83.  
  84. image(imgcopy, 0, 0, width, height);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement