GLubyte * EJTexture::loadPixelsWithLodePNGFromPath(NSString * path) { unsigned int w, h; unsigned char * origPixels = NULL; unsigned int error = lodepng_decode32_file(&origPixels, &w, &h, path->getCString()); if( error ) { NSLOG("Error Loading image %s - %u: %s", path->getCString(), error, lodepng_error_text(error)); return origPixels; } setWidthAndHeight(w, h); // If the image is already in the correct (power of 2) size, just return // the original pixels unmodified if( width == realWidth && height == realHeight ) { return origPixels; } // Copy the original pixels into the upper left corner of a larger // (power of 2) pixel buffer, free the original pixels and return // the larger buffer else { GLubyte * pixels = (GLubyte *)calloc( realWidth * realHeight * 4, sizeof(GLubyte) ); for( int y = 0; y < height; y++ ) { memcpy( &pixels[y*realWidth*4], &origPixels[y*width*4], width*4 ); } free( origPixels ); return pixels; } }
EJTexture::EJTexture(int widthp, int heightp, GLenum formatp) : textureId(0), width(0), height(0), realWidth(0), realHeight(0) { // Create an empty texture contentScale = 1; NSString* empty = NSStringMake("[Empty]"); empty->retain(); fullPath = empty; setWidthAndHeight(widthp, heightp); createTextureWithPixels(NULL, formatp); }
void GLFramebuffer::finish(bool depth) { if (mFinished) { return; } mFinished = true; glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); if (depth and mDepthTexture == NULL) { glGenRenderbuffers(1, &mDepthRBO); glBindRenderbuffer(GL_RENDERBUFFER, mDepthRBO); } setWidthAndHeight(mWidth, mHeight); }
EJTexture::EJTexture(int widthp, int heightp, GLubyte * pixels) : textureId(0), width(0), height(0), realWidth(0), realHeight(0) { // Creates a texture with the given pixels contentScale = 1; NSString* empty = NSStringMake("[From Pixels]"); empty->retain(); fullPath = empty; setWidthAndHeight(widthp, heightp); if( width != realWidth || height != realHeight ) { GLubyte * pixelsPow2 = (GLubyte *)calloc( realWidth * realHeight * 4, sizeof(GLubyte) ); for( int y = 0; y < height; y++ ) { memcpy( &pixelsPow2[y*realWidth*4], &pixels[y*width*4], width * 4 ); } createTextureWithPixels(pixelsPow2, GL_RGBA); free(pixelsPow2); } else { createTextureWithPixels(pixels, GL_RGBA); } }
Driver::Driver( const Config& cfg, const hydroutil::Context& context ) : config_(cfg), context_(context) { cameras_.resize( config_.size() ); frames_.resize( config_.size() ); for( unsigned int i=0; i<cameras_.size(); ++i ) { // picks up the first camera it finds on the firewire bus cameras_.at(i) = cvCreateCameraCapture( i ); if( cameras_.at(i) == NULL ) { std::string ss = "Failed to initialize CvCameraDevice " + i ; gbxutilacfr::Exception( ERROR_INFO, ss ); throw ss; } // the default in opencv is CV_CAP_PROP_CONVERT_RGB=1 which causes // cameras with bayer encoding to be converted from mono to rgb // without using the bayer functions. CV_CAP_PROP_CONVERT_RGB=0 // keeps the original format. cvSetCaptureProperty( cameras_.at(i), CV_CAP_PROP_CONVERT_RGB, 0 ); // assume all the cameras should be set to the same size as camera 0 setWidthAndHeight(static_cast<int>(config_.at(i).width), static_cast<int>(config_.at(i).height), i ); // record the actual width and height frames_.at(i) = cvQueryFrame( cameras_.at(i) ); // int width = frame_->width; // int height = frame_->height; // this following call should work in opencv but have had mixed results // int width = (int)cvGetCaptureProperty( capture_, CV_CAP_PROP_FRAME_WIDTH ); //int height = (int)cvGetCaptureProperty( capture_, CV_CAP_PROP_FRAME_HEIGHT ); if(cameras_.at(i) == NULL ) { stringstream ss; ss << "Camera " << i << " could not be initialized" ; throw gbxutilacfr::Exception( ERROR_INFO, ss.str() ); } if( frames_.at(i)->width != static_cast<int>(config_.at(i).width) ) { std::stringstream sse; sse << "config does not match image properties of camera " << i << ": actual width=" << frames_.at(i)->width << " config width=" << config_.at(i).width; throw gbxutilacfr::Exception(ERROR_INFO, sse.str()); } if( frames_.at(i)->height != static_cast<int>(config_.at(i).height) ) { std::stringstream sse; sse << "config does not match image properties " << i << ": actual height=" << frames_.at(i)->height << " config height=" << config_.at(i).height; throw gbxutilacfr::Exception(ERROR_INFO, sse.str()); } if( frames_.at(i)->width*frames_.at(i)->height*3 != static_cast<int>(config_.at(i).size) ) { std::stringstream sse; sse << "config does not match image properties " << i << ": actual size=" << frames_.at(i)->width*frames_.at(i)->height*3 << " config size=" << config_.at(i).size; throw gbxutilacfr::Exception(ERROR_INFO, sse.str()); } if( config_.at(i).format!="BGR8" && config_.at(i).format!="RGB8" && config_.at(i).format!="BayerRG8" && config_.at(i).format!="BayerGR8" && config_.at(i).format!="BayerGB8" && config_.at(i).format!="BayerBG8" && config_.at(i).format!="GRAY8" ) { std::stringstream sse; sse << "config does not match supported image properties " << i << ": config format=" << config_.at(i).format; throw gbxutilacfr::Exception(ERROR_INFO, sse.str()); } } }
void GLFramebuffer::setWidth(unsigned int width) { setWidthAndHeight(width, mHeight); }
void GLFramebuffer::setHeight(unsigned int height) { setWidthAndHeight(mWidth, height); }