Exemplo n.º 1
0
//------------------------------------
void ofImage::allocate(int w, int h, int type){


	int newBpp = 0;

	switch (type){
		case OF_IMAGE_GRAYSCALE:
			newBpp = 8;
			break;
		case OF_IMAGE_COLOR:
			newBpp = 24;
			break;
		case OF_IMAGE_COLOR_ALPHA:
			newBpp = 32;
			break;
		default:
			ofLog(OF_LOG_ERROR,"error = bad imageType in ofImage::allocate");
			return;
	}

	allocatePixels(myPixels, w, h, newBpp);

	// take care of texture allocation --
	if (myPixels.bAllocated == true && bUseTexture == true){
		tex.allocate(myPixels.width, myPixels.height, myPixels.glDataType);
	}

	update();
}
void FrameSequence::loadFrames(string path, int maxFrameCount) {
  ofImage image;

  int firstFrameIndex = getFirstFrameIndex(path);
  if (firstFrameIndex < 0) {
    cout << "Couldn't find frame: " << path << "/frame%04d.png" << endl;
    return;
  }

  image.loadImage(path + "/frame" + ofToString(firstFrameIndex, 0, 4, '0') + ".png");

  int totalFrameCount = countFrames(path, firstFrameIndex);
  totalFrameCount = MIN(maxFrameCount, totalFrameCount);

  allocatePixels(totalFrameCount, image.width, image.height);

  cout << "Loading " << frameCount << " frames " << endl
    << "\tPath: " << path << endl
    << "\tDimensions: " << frameWidth << "x" << frameHeight << endl
    << "\tSize: " << floor(frameCount * frameWidth * frameHeight * 3 / 1024 / 1024) << " MB" << endl;

  for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
    image.loadImage(path + "/frame" + ofToString(firstFrameIndex + frameIndex, 0, 4, '0') + ".png");
    image.setImageType(OF_IMAGE_COLOR);

    for (int i = 0; i < frameWidth * frameHeight * 3; i++) {
      unsigned char c = image.getPixels()[i];
      pixels[frameIndex * frameWidth * frameHeight * 3 + i] = c;
    }
  }

  cout << "Loading complete." << endl;
}
	FluidSolver* FluidDrawerBase::setup(FluidSolver* f) {
		deleteFluidSolver();
		_fluidSolver = f;
		allocatePixels();
		createTexture();
		
		return _fluidSolver;
	}
	FluidSolver* FluidDrawerBase::setup(int NX, int NY) {
		deleteFluidSolver();
		_fluidSolver = new FluidSolver;
		_fluidSolver->setup(NX, NY);
		allocatePixels();
		createTexture();
		
		return _fluidSolver;
	}
Exemplo n.º 5
0
//----------------------------------------------------
void ofImage::putBmpIntoPixels(FIBITMAP * bmp, ofPixels &pix){
	int width			= FreeImage_GetWidth(bmp);
	int height			= FreeImage_GetHeight(bmp);
	int bpp				= FreeImage_GetBPP(bmp);
	int bytesPerPixel	= bpp / 8;
	//------------------------------------------
	// call the allocation routine (which checks if really need to allocate) here:
	allocatePixels(pix, width, height, bpp);
	FreeImage_ConvertToRawBits(pix.pixels, bmp, width*bytesPerPixel, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true);  // get bits
}
Exemplo n.º 6
0
//------------------------------------
void ofImage::clone(const ofImage &mom){

	allocatePixels(myPixels, mom.width, mom.height, mom.bpp);
	memcpy(myPixels.pixels, mom.myPixels.pixels, myPixels.width*myPixels.height*myPixels.bytesPerPixel);

	tex.clear();
	bUseTexture = mom.bUseTexture;
	if (bUseTexture == true){
		tex.allocate(myPixels.width, myPixels.height, myPixels.glDataType);
	}

	update();
}
	void FluidDrawerBase::enableAlpha(bool b) {
		_alphaEnabled = b;
		if(_alphaEnabled) {
			_glType = GL_RGBA;
			_bpp = 4;
		} else {
			_glType = GL_RGB;
			_bpp = 3;
		}
		
		if(isFluidReady()) {
			allocatePixels();
			createTexture();
		}
	}
Exemplo n.º 8
0
//------------------------------------
void  ofImage::setFromPixels(unsigned char * newPixels, int w, int h, int newType, bool bOrderIsRGB){

	if (!myPixels.bAllocated){
		allocate(w, h, newType);
	}

	if (!((width == w) && (height == h) && (type == newType))){
		bool bCacheBUseTexture = bUseTexture;
		clear();
		bUseTexture = bCacheBUseTexture;
		allocate(w,h, newType);
	}


	int newBpp = 0;
	switch (type){
		case OF_IMAGE_GRAYSCALE:
			newBpp = 8;
			break;
		case OF_IMAGE_COLOR:
			newBpp = 24;
			break;
		case OF_IMAGE_COLOR_ALPHA:
			newBpp = 32;
			break;
		default:
			ofLog(OF_LOG_ERROR,"error = bad imageType in ofImage::setFromPixels");
			return;
	}

	allocatePixels(myPixels, w, h, newBpp);
	int bytesPerPixel = myPixels.bitsPerPixel / 8;
	memcpy(myPixels.pixels, newPixels, w*h*bytesPerPixel);

	if (myPixels.bytesPerPixel > 1){
		if (!bOrderIsRGB){
			swapRgb(myPixels);
		}
	}

	update();
}
Exemplo n.º 9
0
int main(){
	int x, y, height, width, length;
	int divisibility;
	freopen("input4.in", "r", stdin);
	//freopen("output4.out", "w", stdout);
	printf("Enter the details of the image\n");
	printf("Height : ");
	scanf("%d", &d.height);
	printf("Width : ");
	scanf("%d", &d.width);
	allocatePixels();
	printf("Enter the left top corner x : ");
	scanf("%d", &x);
	printf("Enter the left top corner y : ");
	scanf("%d", &y);
	printf("Enter the widht of the rectangle : "); scanf("%d", &width);
	printf("Enter the height of the rectangle : "); scanf("%d", &height);
	printf("Enter the divisibility number : "); scanf("%d", &divisibility);
	drawRectangle(x,y,width, height, 'B', ' ',divisibility);
	printBoard();
}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------
void ofxCvImage::allocate( int w, int h ) {
	if (bAllocated == true){
		ofLogVerbose("ofxCvImage") << "allocate(): reallocating";
		clear();
	}
	
	if( w == 0 || h == 0 ){
		ofLogError("ofxCvImage") << "allocate(): width and height are zero";
		return;
	}

	cvImage = cvCreateImage( cvSize(w,h), ipldepth, iplchannels );
	cvImageTemp	= cvCreateImage( cvSize(w,h), ipldepth, iplchannels );

	width = w;
	height = h;
	bAllocated = true;

    if( bUseTexture ) {
    	allocatePixels(w,h);
        allocateTexture();
        bTextureDirty = true;
    }
}
Exemplo n.º 11
0
//----------------------------------------------------
bool ofImage::loadImageIntoPixels(string fileName, ofPixels &pix){

	int					width, height, bpp;
	fileName			= ofToDataPath(fileName);
	bool bLoaded		= false;
	FIBITMAP 			* bmp = NULL;


	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	fif = FreeImage_GetFileType(fileName.c_str(), 0);
	if(fif == FIF_UNKNOWN) {
		// or guess via filename
		fif = FreeImage_GetFIFFromFilename(fileName.c_str());
	}
	if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
		bmp					= FreeImage_Load(fif, fileName.c_str(), 0);
		bLoaded = true;
		if (bmp == NULL){
			bLoaded = false;
		}
	}
	//-----------------------------

	if (bLoaded ){

		width 		= FreeImage_GetWidth(bmp);
		height 		= FreeImage_GetHeight(bmp);
		bpp 		= FreeImage_GetBPP(bmp);

		bool bPallette = (FreeImage_GetColorType(bmp) == FIC_PALETTE);

		switch (bpp){
			case 8:
				if (bPallette) {
					FIBITMAP 	* bmpTemp =		FreeImage_ConvertTo24Bits(bmp);
					if (bmp != NULL)			FreeImage_Unload(bmp);
					bmp							= bmpTemp;
					bpp							= FreeImage_GetBPP(bmp);
				} else {
					// do nothing we are grayscale
				}
				break;
			case 24:
				// do nothing we are color
				break;
			case 32:
				// do nothing we are colorAlpha
				break;
			default:
				FIBITMAP 	* bmpTemp =		FreeImage_ConvertTo24Bits(bmp);
				if (bmp != NULL)			FreeImage_Unload(bmp);
				bmp							= bmpTemp;
				bpp							= FreeImage_GetBPP(bmp);
		}


		int byteCount = bpp / 8;

		//------------------------------------------
		// call the allocation routine (which checks if really need to allocate) here:
		allocatePixels(pix, width, height, bpp);



		FreeImage_ConvertToRawBits(pix.pixels, bmp, width*byteCount, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true);  // get bits

		//------------------------------------------
		// RGB or RGBA swap
		// this can be done with some ill pointer math.
		// anyone game?
		//

		#ifdef TARGET_LITTLE_ENDIAN
			if (byteCount != 1) swapRgb(pix);
		#endif
		//------------------------------------------


	} else {
		width = height = bpp = 0;
	}

	if (bmp != NULL){
		FreeImage_Unload(bmp);
	}

	return bLoaded;
}
Exemplo n.º 12
0
bool ofMemoryImage::loadFromDataIntoPixels(const unsigned char * datasource, int len, ofPixels &pix ) {

    int					width, height, bpp;
    bool bLoaded		= false;
    FIBITMAP 			* bmp = NULL;

    FIMEMORY *hmem = NULL;

    hmem = FreeImage_OpenMemory((Byte *)datasource, len);
    if (hmem == NULL) {
        printf("couldn't create memory handle! \n");
    }
    cout << "memory open " << endl;
    //get the file type!
    FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);

    cout << "image format "<<  fif << endl;
    if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
        bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
        if (bmp == NULL) {
            cout << "we could not load from memory!! " << endl;
        }
        else {
            FreeImage_CloseMemory(hmem);
        }

        bLoaded = true;
        if (bmp == NULL) {
            bLoaded = false;
            cout << "we are not loadded " << endl;
        }

    }


    if (bLoaded ) {

        width 		= FreeImage_GetWidth(bmp);
        height 		= FreeImage_GetHeight(bmp);
        bpp 		= FreeImage_GetBPP(bmp);

        bool bPallette = (FreeImage_GetColorType(bmp) == FIC_PALETTE);

        switch (bpp) {
        case 8:
            if (bPallette) {
                FIBITMAP 	* bmpTemp =		FreeImage_ConvertTo24Bits(bmp);
                if (bmp != NULL)			FreeImage_Unload(bmp);
                bmp							= bmpTemp;
                bpp							= FreeImage_GetBPP(bmp);
            } else {
                // do nothing we are grayscale
            }
            break;
        case 24:
            // do nothing we are color
            break;
        case 32:
            // do nothing we are colorAlpha
            break;
        default:
            FIBITMAP 	* bmpTemp =		FreeImage_ConvertTo24Bits(bmp);
            if (bmp != NULL)			FreeImage_Unload(bmp);
            bmp							= bmpTemp;
            bpp							= FreeImage_GetBPP(bmp);
        }


        int byteCount = bpp / 8;

        //------------------------------------------
        // call the allocation routine (which checks if really need to allocate) here:
        allocatePixels(pix, width, height, bpp);



        FreeImage_ConvertToRawBits(pix.pixels, bmp, width*byteCount, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, false);  // get bits

        //------------------------------------------
        // RGB or RGBA swap
        // this can be done with some ill pointer math.
        // anyone game?
        //

#ifdef TARGET_LITTLE_ENDIAN
        if (byteCount != 1) swapRgb(pix);
#endif
        //------------------------------------------


    } else {
        width = height = bpp = 0;
    }

    if (bmp != NULL) {
        FreeImage_Unload(bmp);
    }
    cout << bLoaded << endl;
    return bLoaded;


}