void ofxThreadedImage::resizeIfNeeded(){
	if (resizeAfterLoad){
		int w = getWidth();
		int h = getHeight();
		int largestSide = MAX(w, h);
		if(largestSide > maxSideSize){ //we need resize!
			float scale = maxSideSize / (float)largestSide;
			//float t1 = ofGetElapsedTimef();
			int newW = w * scale;
			int newH = h * scale;
			#if USE_OPENCV_TO_RESIZE
			if (type == OF_IMAGE_COLOR){
				ofxCvColorImage cvImg;
				cvImg.setUseTexture(false);
				cvImg.allocate(w, h);
				cvImg.setFromPixels(getPixels(), w, h);
				ofxCvColorImage cvImgsmall;
				cvImgsmall.setUseTexture(false);
				cvImgsmall.allocate(newW, newH);
				cvImgsmall.scaleIntoMe(cvImg, CV_INTER_AREA);
				setFromPixels(cvImgsmall.getPixels(), newW, newH, OF_IMAGE_COLOR);
			}else{
				resize(newW, newH); //TODO opencv resizing is much faster!
			}
			#else
			resize(newW, newH); //TODO opencv resizing is much faster!
			#endif
			//ofLog() << "time resize: " + ofToString( ofGetElapsedTimef() - t1 );
		}
	}
}
Ejemplo n.º 2
0
void ofxSurfImage::loadImage(string url){
    ofImage img;
    img.loadImage(url);
    img.setImageType( OF_IMAGE_COLOR );
    allocate(img.width,img.height);
    unsigned char * pix = img.getPixels();
    setFromPixels(pix,img.width,img.height);
}
Ejemplo n.º 3
0
void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels,int w, int h, ofImageType type){
	allocate(w,h,type);
	switch(type){
	case OF_IMAGE_GRAYSCALE:
		setFromPixels(newPixels,w,h,1);
		break;
	case OF_IMAGE_COLOR:
		setFromPixels(newPixels,w,h,3);
		break;
	case OF_IMAGE_COLOR_ALPHA:
		setFromPixels(newPixels,w,h,4);
		break;
	default:
		ofLog(OF_LOG_ERROR,"ofPixels: image type not supported");
		break;
	}
}
void ofPixels_<PixelType>::setFromAlignedPixels(const PixelType * newPixels, int width, int height, ofPixelFormat _pixelFormat, std::vector<int> strides) {
	int channels = channelsFromPixelFormat(_pixelFormat);
	if(channels==0) return;

	switch(pixelFormat){
	case OF_PIXELS_I420: {
	    if(strides.size() != 3){
		ofLogError("ofPixels") << "number of planes for I420 should be 3";
		break;
	    }

	    if(width==strides[0] && width/2==strides[1] && width/2==strides[2]){
		setFromPixels(newPixels,width,height,_pixelFormat);
		return;
	    }

	    allocate(width, height, _pixelFormat);

	    const unsigned char* src = (unsigned char*) newPixels;
	    unsigned char* dst =  (unsigned char*) pixels;
	    // Y Plane
	    for(int i = 0; i < height; i++) {
		memcpy(dst, src, width);
		src += strides[0];
		dst += width;
	    }
	    // U Plane
	    for(int i = 0; i < height /2; i++){
		memcpy(dst,src,width/2);
		src += strides[1];
		dst += width/2;
	    }
	    // V Plane
	    for(int i = 0; i < height /2; i++){
		memcpy(dst,src,width/2);
		src += strides[2];
		dst += width/2;
	    }
	    break;
	}
	case OF_PIXELS_RGB:
	case OF_PIXELS_RGBA:
	case OF_PIXELS_GRAY:
	case OF_PIXELS_GRAY_ALPHA:
	    setFromAlignedPixels(newPixels,width,height,_pixelFormat,strides[0]);
	    return;
	default:
	    ofLogError("ofPixels") << "setFromAlignedPixels with planes strides: pixel format not supported yet";
	    break;
	}
	return;
}
Ejemplo n.º 5
0
ofImage_<PixelType>::ofImage_(const ofPixels_<PixelType> & pix){
	width						= 0;
	height						= 0;
	bpp							= 0;
	type						= OF_IMAGE_UNDEFINED;
	bUseTexture					= true;		// the default is, yes, use a texture

	//----------------------- init free image if necessary
	ofInitFreeImage();


	setFromPixels(pix);
}
Ejemplo n.º 6
0
ofImage_<PixelType>::ofImage_(const ofPixels_<PixelType> & pix){
	width						= 0;
	height						= 0;
	bpp							= 0;
	type						= OF_IMAGE_UNDEFINED;
	bUseTexture					= true;		// the default is, yes, use a texture

	//----------------------- init free image if necessary
	ofInitFreeImage();

#if defined(TARGET_ANDROID) || defined(TARGET_OF_IPHONE)
	registerImage(this);
#endif

	setFromPixels(pix);
}
Ejemplo n.º 7
0
void ofPixels_<PixelType>::setFromAlignedPixels(const PixelType * newPixels, int width, int height, ofPixelFormat _pixelFormat, int stride) {
	int channels = channelsFromPixelFormat(_pixelFormat);
	if(channels==0) return;

	if(width*channels==stride){
		setFromPixels(newPixels,width,height,_pixelFormat);
		return;
	}
	allocate(width, height, _pixelFormat);
	int dstStride = width * pixelBytesFromPixelFormat<PixelType>(_pixelFormat);
	const unsigned char* src = (unsigned char*) newPixels;
	unsigned char* dst =  (unsigned char*) pixels;
	for(int i = 0; i < height; i++) {
		memcpy(dst, src, dstStride);
		src += stride;
		dst += dstStride;
	}
}
Ejemplo n.º 8
0
void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels, int w, int h, ofImageType type){
	allocate(w,h,type);
	setFromPixels(newPixels,w,h,ofPixelFormatFromImageType(type));
}
Ejemplo n.º 9
0
//--------------------------------------------------------------------------------
void ofxCvFloatImage::operator = ( float* _pixels ) {
    setFromPixels( _pixels, width, height );
}
Ejemplo n.º 10
0
/*! Set image from pixels data (dense unsigned char array)
	\param pixels pixel data
	\param w width
	\param h height
	\param d depth (e.g., CV_8U)
	\param c channels (e.g., 3 for color image)
*/
void 
ofxCv2Image::setFromPixels( unsigned char* pixels, int w, int h, int d, int c)
{
	setFromPixels(pixels, w, h, CV_MAKETYPE(CV_MAT_DEPTH(d),c));
}
Ejemplo n.º 11
0
ofImage_<PixelType> & ofImage_<PixelType>::operator=(ofPixels_<PixelType> & pixels){
	setFromPixels(pixels);
	return *this;
}
//--------------------------------------------------------------------------------
void setfilter::operator =	( unsigned char* _pixels ) {
    
	//-- for using pixels --//
	setFromPixels( _pixels, width, height );
}
Ejemplo n.º 13
0
//--------------------------------------------------------------------------------
void ofxCvImage::setFromPixels( const ofPixels & pixels ){
	setFromPixels(pixels.getData(),pixels.getWidth(),pixels.getHeight());
}
Ejemplo n.º 14
0
void ofPixels::setFromPixels(unsigned char * newPixels,int w, int h, int bitsPerPixel){
	ofImageType type = getImageTypeFromBits(bitsPerPixel);
	setFromPixels(newPixels,w,h,type);
}
Ejemplo n.º 15
0
//--------------------------------------------------------------------------------
void ofxCvGrayscaleImage::operator = ( const ofPixels & _pixels ) {
    setFromPixels( _pixels);
}
Ejemplo n.º 16
0
void ofImage_<PixelType>::setFromPixels(const ofPixels_<PixelType> & pixels){
	setFromPixels(pixels.getPixels(),pixels.getWidth(),pixels.getHeight(),pixels.getImageType());
}
Ejemplo n.º 17
0
//--------------------------------------------------------------------------------
void ofxCvFloatImage::operator = ( unsigned char* _pixels ) {
    setFromPixels( _pixels, width, height );
}
Ejemplo n.º 18
0
//--------------------------------------------------------------------------------
void CPUImageFilter::operator =	( unsigned char* _pixels ) {
    setFromPixels( _pixels, width, height );
}
//--------------------------------------------------------------------------------
void ofxCvColorImageAlpha::operator = ( unsigned char* _pixels ) {
    setFromPixels( _pixels, width, height );
}