Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- dogImg.load("dog.jpg");
- threshold = 0;
- dogTex.allocate(dogImg.getWidth(),dogImg.getHeight(), GL_RGB);
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- // get a pointer to our image pixels
- //unsigned char * pixels = dogImg.getPixels();
- threshold = ofMap(mouseX, 0, ofGetWidth(),0,255);
- ofPixels dogPixels = dogImg.getPixels();
- for (int i=0; i<dogImg.getWidth()*dogImg.getHeight(); i++) {
- ofColor c = dogImg.getColor(i*3);
- float brightness = c.getBrightness();
- if (brightness < threshold) {
- //dogImg.setColor(i*3, ofColor(255,0,0));
- //pixels[i*3] = 255;
- //pixels[i*3+1] = 255;
- //pixels[i*3+2] = 255;
- dogPixels.setColor(i*3, ofColor(255,0,0));
- }
- }
- //dogImg.update();
- dogTex.loadData(dogPixels, dogImg.getWidth(), dogImg.getHeight(), GL_RGB);
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- ofSetColor(255);
- dogImg.draw(0,0);
- // draw our texture with the changed pixel data
- dogTex.draw(dogImg.getWidth(),0);
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- }
- //--------------------------------------------------------------
- void ofApp::keyReleased(int key){
- }
- //--------------------------------------------------------------
- void ofApp::mouseMoved(int x, int y ){
- }
- //--------------------------------------------------------------
- void ofApp::mouseDragged(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mousePressed(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseReleased(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseEntered(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::mouseExited(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::windowResized(int w, int h){
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg){
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement