Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import controlP5.*;
  2.  
  3. PImage img;
  4. ControlP5 debugUI;
  5. int brightness1 = 255;
  6. int saturation1= 255;
  7. int hue1= 255;
  8.  
  9. void setup()
  10. {
  11. size(1000, 750); //set window size to same resolution as image
  12.  
  13. colorMode(HSB, 255, 255, 255);
  14.  
  15. img = loadImage( "GracefieldMorning.jpg" ); //loading image into memory (RAM) - no GPU acceleration here
  16.  
  17. //setting up our slider and adding the "brightness" so it knows that the variable it controls
  18. debugUI = new ControlP5(this);
  19.  
  20. debugUI.addKnob("brightness1")
  21. .setRadius(30)
  22. .setPosition( 10, 10 )
  23. .setRange( 0 , 510 )
  24. .setValue(255);
  25.  
  26. debugUI.addKnob("saturation1")
  27. .setRadius(30)
  28. .setPosition( 80, 10 )
  29. .setRange( 0, 510 )
  30. .setValue(255);
  31.  
  32. debugUI.addKnob("hue1")
  33. .setRadius(30)
  34. .setPosition( 150, 10 )
  35. .setRange( 0, 20 );
  36. }
  37.  
  38. void draw()
  39. {
  40. //MAke a copy so we can keep original intact
  41. PImage imgcopy = img.get();
  42.  
  43. imgcopy.loadPixels();
  44.  
  45. float brightRatio = (float)brightness1 / 255.0f;
  46. float satRatio = (float)saturation1/ 255.0f;
  47. float hueRatio = (float)hue1;//255.0;
  48.  
  49. int numPixels = imgcopy.pixels.length;
  50. for(int i = 0; i < numPixels; i++)
  51. {
  52. color prevCol = imgcopy.pixels[i];
  53. color newCol = color( hue(prevCol) * hueRatio, saturation(prevCol) * satRatio, brightness(prevCol) * brightRatio);
  54. imgcopy.pixels[i] = newCol;
  55. }
  56.  
  57. imgcopy.updatePixels();
  58.  
  59. image(imgcopy, 0, 0, width, height);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement