Advertisement
xeromino

bright1

Jun 15th, 2016
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5.     dogImg.load("dog.jpg");
  6.     threshold = 0;
  7.    
  8.     dogTex.allocate(dogImg.getWidth(),dogImg.getHeight(), GL_RGB);
  9.    
  10. }
  11.  
  12. //--------------------------------------------------------------
  13. void ofApp::update(){
  14.    
  15.     // get a pointer to our image pixels
  16.    
  17.     //unsigned char * pixels = dogImg.getPixels();
  18.     threshold = ofMap(mouseX, 0, ofGetWidth(),0,255);
  19.    
  20.     ofPixels dogPixels = dogImg.getPixels();
  21.    
  22.     for (int i=0; i<dogImg.getWidth()*dogImg.getHeight(); i++) {
  23.         ofColor c = dogImg.getColor(i*3);
  24.         float brightness = c.getBrightness();
  25.         if (brightness < threshold) {
  26.             //dogImg.setColor(i*3, ofColor(255,0,0));
  27.             //pixels[i*3] = 255;
  28.             //pixels[i*3+1] = 255;
  29.             //pixels[i*3+2] = 255;
  30.             dogPixels.setColor(i*3, ofColor(255,0,0));
  31.         }
  32.     }
  33.     //dogImg.update();
  34.     dogTex.loadData(dogPixels, dogImg.getWidth(), dogImg.getHeight(), GL_RGB);
  35. }
  36.  
  37. //--------------------------------------------------------------
  38. void ofApp::draw(){
  39.    
  40.     ofSetColor(255);
  41.     dogImg.draw(0,0);
  42.    
  43.     // draw our texture with the changed pixel data
  44.    
  45.     dogTex.draw(dogImg.getWidth(),0);
  46.    
  47. }
  48.  
  49. //--------------------------------------------------------------
  50. void ofApp::keyPressed(int key){
  51.  
  52. }
  53.  
  54. //--------------------------------------------------------------
  55. void ofApp::keyReleased(int key){
  56.  
  57. }
  58.  
  59. //--------------------------------------------------------------
  60. void ofApp::mouseMoved(int x, int y ){
  61.  
  62. }
  63.  
  64. //--------------------------------------------------------------
  65. void ofApp::mouseDragged(int x, int y, int button){
  66.  
  67. }
  68.  
  69. //--------------------------------------------------------------
  70. void ofApp::mousePressed(int x, int y, int button){
  71.  
  72. }
  73.  
  74. //--------------------------------------------------------------
  75. void ofApp::mouseReleased(int x, int y, int button){
  76.  
  77. }
  78.  
  79. //--------------------------------------------------------------
  80. void ofApp::mouseEntered(int x, int y){
  81.  
  82. }
  83.  
  84. //--------------------------------------------------------------
  85. void ofApp::mouseExited(int x, int y){
  86.  
  87. }
  88.  
  89. //--------------------------------------------------------------
  90. void ofApp::windowResized(int w, int h){
  91.  
  92. }
  93.  
  94. //--------------------------------------------------------------
  95. void ofApp::gotMessage(ofMessage msg){
  96.  
  97. }
  98.  
  99. //--------------------------------------------------------------
  100. void ofApp::dragEvent(ofDragInfo dragInfo){
  101.  
  102. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement