Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************
- *Name: Heewon Suh
- *Date: 2016/2/12
- *Student#:100936360
- **********************************/
- import controlP5.*;
- PImage img;
- ControlP5 debugUI;
- int brightness1 = 255;
- int saturation1= 255;
- int hue1= 255;
- boolean inverse1 = false;
- void setup()
- {
- size(1000, 750); //set window size to same resolution as image
- colorMode(HSB, 255, 255, 255);
- img = loadImage( "GracefieldMorning.jpg" ); //loading image into memory (RAM) - no GPU acceleration here
- //setting up our slider and adding the "brightness" so it knows that the variable it controls
- debugUI = new ControlP5(this);
- debugUI.addSlider("brightness1")
- .setPosition(20, height-30)
- .setRange( 0 , 300 )
- .setSize(100, 20);
- debugUI.addSlider("saturation1")
- .setPosition(20, height-60)
- .setRange( 0, 100 )
- .setSize(100, 20);
- debugUI.addSlider("hue1")
- .setPosition(20, height-90)
- .setRange( 0, 400 )
- .setSize(100, 20);
- debugUI.addButton("inverse1")
- .setPosition(20, height-120)
- .setSize(100, 20);
- }
- void draw()
- {
- //MAke a copy so we can keep original intact
- PImage imgcopy = img.get();
- imgcopy.loadPixels();
- float brightRatio = (float)brightness1 / 255.0f;
- float satRatio = (float)saturation1/ 255.0f;
- float hueRatio = (float)hue1 / 255.0f;
- if(inverse1 == true) {
- inverse();
- }
- int numPixels = imgcopy.pixels.length;
- for(int i = 0; i < numPixels; i++)
- {
- color prevCol = imgcopy.pixels[i];
- color newCol = color( hue(prevCol) * hueRatio, saturation(prevCol) * satRatio, brightness(prevCol) * brightRatio);
- imgcopy.pixels[i] = newCol;
- }
- imgcopy.updatePixels();
- image(imgcopy, 0, 0, width, height);
- }
- void inverse()
- {
- PImage imgcopy = img.get();
- imgcopy.loadPixels();
- filter(INVERT);
- imgcopy.updatePixels();
- image(imgcopy, 0, 0, width, height);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement