Esempio n. 1
0
        void draw(){
            wc.begin();
            if(!switchVideo){
                wc.setUniformTexture("colorMap", img.getTexture(),  1);
                wc.setUniformTexture("heightMap",gray.getTexture(), 2);
            }
            else{
                wc.setUniformTexture("colorMap", player.getTexture(), 1);
                fboDepth.begin();
                player.draw(0,0);
                fboDepth.end();
                wc.setUniformTexture("heightMap",fboDepth.getDepthTexture(),2);
            }
            wc.setUniform1f("time", ofGetElapsedTimef()*time);
            wc.setUniform1f("gradientStep", stepGradient);
            wc.setUniform1f("advectStep",   advectStep);
            wc.setUniform1f("flipHeightMap",flipHeightMap);
            wc.setUniform4f("advectMatrix",advectMatrix->w,advectMatrix->x,advectMatrix->y,advectMatrix->z);

            fbo.draw(0,0);

            wc.end();
            img.draw(0,0,img.getWidth()/4,img.getHeight()/4);
            player.draw(img.getWidth()/4,0,img.getWidth()/4,img.getHeight()/4);
            gui.draw();
        }
Esempio n. 2
0
// image2data converts an image to OctoWS2811's raw data format.
// The number of vertical pixels in the image must be a multiple
// of 8.  The data array must be the proper size for the image.
//--------------------------------------------------------------
void ofxTeensyOcto::image2data(ofImage image, unsigned char* data, bool layout)
{    
    int offset = 3;
    int x, y, xbegin, xend, xinc, mask;
    int linesPerPin = image.getHeight() / 8;
    int* pixel = new int[8];
    
    // get the copied image pixels
    pixels2 = image.getPixels();

    // 2d array of our pixel colors
    for (int x = 0; x < ledWidth; x++)
    {
        for (int y = 0; y < (ledHeight * stripsPerPort * numPortsMain); y++)
        {
            int loc = x + y * ledWidth;
            colors[loc] = pixels2.getColor(x, y);
        }
    }
    
    for (y = 0; y < linesPerPin; y++)
    {
        if ((y & 1) == (layout ? 0 : 1))
        {
            // even numbered rows are left to right
            xbegin = 0;
            xend = image.getWidth();
            xinc = 1;
        }
        else
        {
            // odd numbered rows are right to left
            xbegin = image.getWidth() - 1;
            xend = -1;
            xinc = -1;
        }
        
        for (x = xbegin; x != xend; x += xinc)
        {
            for (int i=0; i < 8; i++)
            {
                int temploc = x + (y + linesPerPin * i) * image.getWidth();
                pixel[i] = colors[temploc].getHex();
                pixel[i] = colorWiring(pixel[i]);
            }
            
            // convert 8 pixels to 24 bytes
            for (mask = 0x800000; mask != 0; mask >>= 1)
            {
                unsigned char b = 0;
                for (int i=0; i < 8; i++)
                {
                    if ((pixel[i] & mask) != 0) b |= (1 << i);
                }
                data[offset++] = b;
            }
        }
    }
}
genImg::genImg(ofImage &src, int scale, int nColors) {
    dna = DNA(src.getWidth()*scale * src.getHeight()*scale, nColors);
    img.allocate(src.getWidth()*scale, src.getHeight()*scale, OF_IMAGE_COLOR);
    heatmap.allocate(src.getWidth()*scale, src.getHeight()*scale, OF_IMAGE_COLOR);
    fitness = 1;
    
    
}
Esempio n. 4
0
void RunningDraw::drawTitle(ofImage title){
    Settings* settings = Settings::getInstance();

    float title_x= settings->getWidth() / 2 - title.getWidth() * SCALE/2;
    float title_y = settings->getTitleY();

    title.draw(title_x, title_y, title.getWidth() * SCALE, title.getHeight() * SCALE);
}
Esempio n. 5
0
//-------------------------------------------------------------------------
void ofxRfeUIImageButton::setup(ofImage _button_image, float _x, float _y){
    
    x = _x;
    y = _y;
    w = _button_image.getWidth();
    h = _button_image.getHeight();
    
    buttonImage = _button_image;
    buttonImageHighlight = _button_image;
    
    ofPixels pixels = buttonImageHighlight.getPixelsRef();
    
    for (int x = 0; x < buttonImageHighlight.getWidth(); x++) {
        for (int y = 0; y < buttonImageHighlight.getHeight(); y++) {
            
            ofColor cur = pixels.getColor(x, y);
            cur.r = 255 - cur.r;
            cur.g = 255 - cur.g;
            cur.b = 255 - cur.b;
            pixels.setColor(x, y, cur);
        }
    }
    
    buttonImageHighlight.setFromPixels(pixels);
    
}
Esempio n. 6
0
string ofxBaseGui::saveStencilToHex(ofImage& img) {
	stringstream strm;
	int width = img.getWidth();
	int height = img.getHeight();
	int n = width * height;
	unsigned char cur = 0;
	int shift = 0;
	strm << "{";
	for(int i = 0; i < n;) {
		if(img.getPixels()[i * 4 + 3] > 0) {
			cur |= 1 << shift;
		}
		i++;
		if(i % 8 == 0) {
			strm << "0x" << hex << (unsigned int) cur;
			cur = 0;
			shift = 0;
			if(i < n) {
				strm << ",";
			}
		} else {
			shift++;
		}
	}
	strm << "}";
	return strm.str();
}
Esempio n. 7
0
		void setup(float x, float y, string path, string videoPath){
			img.loadImage(path);
			r.set(x,y,img.getWidth(),img.getHeight());
			video = videoPath;
			thumbPath = path;
			loadPos();
		}
Esempio n. 8
0
bool StateCreateOrigami::inBound(ofTouchEventArgs & touch, ofImage mImage, ofPoint pos, float scale){
    if (touch.x < pos.x + mImage.getWidth()*scale + offset && touch.x > pos.x - offset && touch.y < pos.y + mImage.getHeight()*scale + offset  && touch.y > pos.y - offset) {
        return true;
    }
    
    return false;
}
Esempio n. 9
0
    void draw() {
        ofBackgroundGradient(64, 0);

	if(reflect || sreflect) 
		env.draw(0,0,env.getWidth()/8,env.getHeight()/8);
	if(sreflect) 
		env1.draw(env.getWidth()/8,0,env1.getWidth()/8,env1.getHeight()/8);

	ofEnableDepthTest();
        cam.begin();
        shader.begin();

	if(sreflect){
//        	shader.setUniform3f("CameraPos",cam.getGlobalPosition().x, cam.getGlobalPosition().y, cam.getGlobalPosition().z);
//		shader.setUniformMatrix4f("ModelWorld4x4",cam.getGlobalTransformMatrix());
        	shader.setUniform3f("CameraPos",cam.getPosition().x, cam.getPosition().y, cam.getPosition().z);
		shader.setUniformMatrix4f("ModelWorld4x4",cam.getModelViewMatrix());//getLocalTransformMatrix());
	        shader.setUniformTexture("frontMap",  env,1);
	        shader.setUniformTexture("backMap",  env1,2);
	}

	if(reflect){
        	shader.setUniformTexture("colorMap",env1,1);
	        shader.setUniformTexture("envMap",  env,2);
	}else if(sreflect==false){
        	shader.setUniformTexture("texture", img, 1);
        	shader.setUniform1f("time", ofGetElapsedTimef());
	}

	if(cube)
		ofDrawBox(200);
	else {
		ofTranslate(0,-150,0);
		ofRotateX(-90);
		ofRotateY(-90);
		ofRotateZ(45);
		model.drawFaces();
	}

        shader.end();
        cam.end();
	ofDisableDepthTest();

        ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
    }
ofVec3f getVertexFromImg(ofImage& img, int x, int y) {
	ofColor color = img.getColor(x, y);
	if(color.a > 200) {  //adjust to get a good image
		float z = ofMap(color.a, 200, 255, -480, 480); //mapping alpha to a good range
		return ofVec3f(x - img.getWidth() /2, y - img.getHeight() / 2, z);
	} else {
		return ofVec3f(0, 0, 0);
	}
}
ofVec3f getVertexFromImg(ofImage& img, int x, int y) {
	ofColor color = img.getColor(x, y);
	if(color.a > 0) {
		float z = ofMap(color.a, 0, 255, -480, 480);
		return ofVec3f(x - img.getWidth() / 2, y - img.getHeight() / 2, z);
	} else {
		return ofVec3f(0, 0, 0);
	}
}
Esempio n. 12
0
void makeThumb(string vidPath, string thumb){
	ofVideoPlayer tmp;
	tmp.loadMovie(vidPath);
	tmp.play();
	tmp.setPosition(0.3);
	ofImage img;
	img.setFromPixels( tmp.getPixelsRef() );
	img.resize(120, 120.0f * (img.getHeight() / img.getWidth()) );
	img.saveImage(thumb);
}
//-----------------------------------------------------
void ofxSURFTracker::detect(ofImage &img) {

    int inputWidth = img.getWidth();
    int inputHeight = img.getHeight();

    if(inputWidth < width || inputHeight < height) {
        return; // detection impossible, because I can't crop out of this image
    }
    detect(img.getPixels(), inputWidth, inputHeight);
}
Esempio n. 14
0
ofVec3f getVertexFromImg(ofImage& pastImg, int x, int y) {   
	ofColor color = pastImg.getColor(x, y);
	if(color.a > 0) {
		float z = ofMap(color.a, 0, 255, -480, 480);
        // this maps this to -480, 480
		return ofVec3f(x - pastImg.getWidth() / 2, y - pastImg.getHeight() / 2, z);
	} else {
		return ofVec3f(0, 0, 0);
	}
}
Esempio n. 15
0
//--------------------------------------------------------------
void testApp::setup(){

	quadmesh.create(150, 50, 400, 300, 8);

	quadimage.loadImage("1.jpg");
	quadtexture = genTex(quadimage.getWidth(), quadimage.getHeight(), quadimage.getPixels());

	// if use GL_TEXTURE_RECTANGLE, change texture coord from [1,1] to [width, height]
	//quadmesh.ResetTextureCoords(quadimage.getWidth(), quadimage.getHeight());
}
Esempio n. 16
0
static int getAvgBrightness(ofImage img) {
    int total = 0;
    int width = img.getWidth();
    int height = img.getHeight();
    for(int i = 0; i < width; i++) {
        for(int j = 0; j < height; j++) {
            total += img.getPixels().getColor(i, j).getBrightness();
        }
    }
    return total / (width*height);
}
Esempio n. 17
0
void ofxCubeMap::loadFromOfImages(  ofImage pos_x, ofImage neg_x,
								  	ofImage pos_y, ofImage neg_y,
								  	ofImage pos_z, ofImage neg_z )
{

	//_ofEnable( GL_TEXTURE_CUBE_MAP_SEAMLESS );

	//create a texture object
	glGenTextures(1, &textureObjectID);
	glBindTexture(GL_TEXTURE_CUBE_MAP, textureObjectID);

	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

#ifndef TARGET_OPENGLES
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); // GL_TEXTURE_WRAP_R is not in the ES2 header, hmm..
#endif

	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


	unsigned char * data_px, * data_nx, * data_py, * data_ny, * data_pz, * data_nz;

	size = pos_x.getWidth();

	//cout << "ofxCubeMap::loadFromOfImages, size: " << size << "  bpp: " << pos_x.bpp << endl;

//	data_px = new unsigned char [size * size * 3];
//	data_py = new unsigned char [size * size * 3];
//	data_pz = new unsigned char [size * size * 3];

//	data_nx = new unsigned char [size * size * 3];
//	data_ny = new unsigned char [size * size * 3];
//	data_nz = new unsigned char [size * size * 3];

	data_px = pos_x.getPixels();
	data_py = pos_y.getPixels();
	data_pz = pos_z.getPixels();

	data_nx = neg_x.getPixels();
	data_ny = neg_y.getPixels();
	data_nz = neg_z.getPixels();

	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_px); // positive x
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_py); // positive y
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_pz); // positive z

	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_nx); // negative x
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_ny); // negative y
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_nz); // negative z
}
Esempio n. 18
0
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    
    //load image file
    string path = ofToDataPath("logo.png");
    of_image.loadImage( path );
    ci_surface = ci::loadImage( path );
    
    //convert images
    ci_texture = ci::gl::Texture( ofxCi::toCi(of_image), GL_RGBA, of_image.getWidth(), of_image.getHeight() );
    of_image.setFromPixels(ofxCi::toOf(ci_surface), ci_surface.getWidth(), ci_surface.getHeight(), OF_IMAGE_COLOR_ALPHA);
    
}
Esempio n. 19
0
static ofPoint getAvgColor(ofImage img) {
    ofPoint total(0,0,0);
    int width = img.getWidth();
    int height = img.getHeight();
    ofPixels pixels = img.getPixels();
    for(int i = 0; i < width; i++) {
        for(int j = 0; j < height; j++) {
            ofColor col = pixels.getColor(i, j);
            total += ofPoint(col.r, col.g, col.b);
        }
    }
    return total / (width*height);
}
Esempio n. 20
0
//--------------------------------------------------------------
ofMesh testApp::pixelManipulate(ofImage imageA, ofMesh meshA, float intensityThreshold, float sketchDepth){
    
    
    imageA.resize(200, 200);
    
    //create mesh with points as the primitive
    //meshA.setMode(OF_PRIMITIVE_POINTS);
    
    //create a mesh with lines
      meshA.setMode(OF_PRIMITIVE_LINE_LOOP);
    
    //meshA.setMode(OF_PRIMITIVE_LINE_STRIP);
    
    
    int w = imageA.getWidth();
    
    int h = imageA.getHeight();
    
    //loop through each pixel in the image using image width & height
    for (int x=0; x<w; x++){
        for(int y=0; y<h; y++){
            
            //create the color object at that pixel
            //ofColor c = imageA.getColor(x, y);
            
            ofColor c = imageA.getColor(x, y);

            
            //check the intensity of the pixel's color
            float intensity = c.getLightness();
            
            //if the intensity exceeds the threshold, create a vertex at the location of the pixel
            //& color it with the pixel's color
            if (intensity >= intensityThreshold){
                
                //pushes brighter colors in the positive z direction
                //pushes whiter colors in the negative z direction
                float saturation = c.getSaturation();
                float z = ofMap(saturation, 0, 255, -sketchDepth, sketchDepth);
                
                //the image is now 1/4 the size of the OF window, so multiply
                //the pixel location by 4 so that the mesh covers the OF window
                ofVec3f pos(5*x, 4*y, z);
                meshA.addVertex(pos);
                meshA.addColor(c);
            }
        }
    }
    
    return meshA;
}
Esempio n. 21
0
void faceColorToTexture(ofMesh& mesh, ofImage& image)
{
	vector<ofFloatColor> &color = mesh.getColors();
	int num_face = color.size() / 3;
	
	int tex_size = ofNextPow2(ceil(sqrt(num_face)));
	
	bool arb = ofGetUsingArbTex();
	ofDisableArbTex();
	image.allocate(tex_size, tex_size, OF_IMAGE_COLOR);
	if (arb) ofEnableArbTex();
	
	mesh.clearTexCoords();
	
	image.getPixelsRef().set(0);
	
	float texel_size = (1. / image.getWidth()) * 0.5;
	
	for (int i = 0; i < num_face; i++)
	{
		int u = (i % tex_size);
		int v = (i / tex_size);
		
		ofColor c = color[i * 3];
		
		image.setColor(u, v, c);
		
		float uu = (float)u / image.getWidth() + texel_size;
		float vv = (float)v / image.getHeight() + texel_size;
		
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
	}
	
	image.update();
	mesh.clearColors();
}
Esempio n. 22
0
ofTexture ofxImageTS::invert(ofImage image){
    
    ofTexture texture;
    ofPixels copy;
    copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
    texture.allocate(image);
    for(int i = 0; i < image.getPixels().size()-3; i += 3){
        copy[i] = 255 - image.getPixels()[i];
        copy[i+1] = 255 - image.getPixels()[i+1];
        copy[i+2] = 255 - image.getPixels()[i+2];
    }
    texture.loadData(copy);
    return texture;
}
Esempio n. 23
0
ofTexture ofxImageTS::alterColorB(ofImage image,float B){
    
    ofTexture texture;
    ofPixels copy;
    copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
    texture.allocate(image);
    for(int i = 0; i < image.getPixels().size()-3; i += 3){
        copy[i] = 0;
        copy[i+1] = 0;
        copy[i+2] = image.getPixels()[i] * B;
    }
    texture.loadData(copy);
    return texture;
}
Esempio n. 24
0
    void draw()
	{

        fbo.draw(0, 0);
		
		stringstream info;
		info << "UPDATING FBO IN draw()" << "\n";
		info << "This text should be yellow" << "\n";
		info << ofGetFrameRate() << "\n";
		ofDrawBitmapStringHighlight(info.str(), testImage.getWidth(), 100, ofColor::black, ofColor::yellow);
		
		ofCircle(100, 400, 100);
		
    }
Esempio n. 25
0
void ofxPencil::setup(ofImage tip,int tipSize,int width,int height) {
    
    this->tip = tip;
    this->tipScale = (float)tipSize/tip.getWidth();
    
    
	fbo.allocate(ofGetWidth(),ofGetHeight());
    
    fbo.begin();
    
    ofClear(0, 0, 0,0);
    fbo.end();
    stroke.setup(1);
    
}
Esempio n. 26
0
ofTexture ofxImageTS::noise(ofImage image, float mix) {
    
    float avg;
    ofTexture texture;
    ofPixels copy;
    copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
    texture.allocate(image);
    for(int i = 0; i < image.getPixels().size()-3; i += 3){
        avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3.0f;
        copy[i] = avg * (125 - avg) * mix;
        copy[i+1] = avg * (125 - avg) * mix;
        copy[i+2] = avg * (125 - avg) * mix;
    }
    texture.loadData(copy);
    return texture;
}
Esempio n. 27
0
ofTexture ofxImageTS::sinusoidal(ofImage image){
    
    ofTexture texture;
    ofPixels copy;
    copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
    texture.allocate(image);
    float Sin;
    for(int i = 0; i < image.getPixels().size()-3; i += 3){
        Sin = (sin(i) + 1)/2.0f;
        copy[i] = Sin * image.getPixels()[i];
        copy[i+1] = Sin *  image.getPixels()[i+1];
        copy[i+2] = Sin *  image.getPixels()[i+2];
    }
    texture.loadData(copy);
    return texture;
}
Esempio n. 28
0
ofTexture ofxImageTS::tanGB(ofImage image){
    
    ofTexture texture;
    ofPixels copy;
    copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
    texture.allocate(image);
    float Tan;
    for(int i = 0; i < image.getPixels().size()-3; i += 3){
        Tan = tan(i);
        copy[i] =  image.getPixels()[i];
        copy[i+1] = Tan * image.getPixels()[i+1];
        copy[i+2] = Tan * image.getPixels()[i+2];
    }
    texture.loadData(copy);
    return texture;
}
Esempio n. 29
0
ofTexture ofxImageTS::greyScale(ofImage image) {
    
    int avg;
    ofTexture texture;
    ofPixels copy;
    copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
    texture.allocate(image);
    for(int i = 0; i < image.getPixels().size()-3; i += 3){
        avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3;
        copy[i] = avg;
        copy[i+1] = avg;
        copy[i+2] = avg;
    }
    texture.loadData(copy);
    return texture;
}
Esempio n. 30
0
void ofxBaseGui::loadStencilFromHex(ofImage& img, unsigned char* data) {
	int width = img.getWidth();
	int height = img.getHeight();
	int i = 0;
	ofColor on(255, 255);
	ofColor off(255, 0);
	for(int y = 0; y < height; y++) {
		for(int x = 0; x < width; x++) {
			int shift = i % 8;
			int offset = i / 8;
			bool cur = (data[offset] >> shift) & 1;
			img.setColor(x, y, cur ? on : off);
			i++;
		}
	}
	img.update();
}