Exemplo n.º 1
0
void CPreview::SetFile(const char * fname)
{
	if (fname == m_fname) return;   // avoid flicker by continually redisplaying the same file
	m_fname = fname;

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

	// If a file name was given
	if (fname != NULL && fname[0] != '\0')
	{
		FREE_IMAGE_FORMAT fmt = FreeImage_GetFileType(fname);  // Try to work out the file type
		m_dib = FreeImage_Load(fmt, fname);
	}

	Invalidate();
}
Exemplo n.º 2
0
/** Generic image loader
	@param lpszPathName Pointer to the full file name
	@param flag Optional load flag constant
	@return Returns the loaded dib if successful, returns NULL otherwise
*/
FIBITMAP* GenericLoader(const char* lpszPathName, int flag) {
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;

	// check the file signature and deduce its format
	// (the second argument is currently not used by FreeImage)
	fif = FreeImage_GetFileType(lpszPathName, 0);
	if(fif == FIF_UNKNOWN) {
		// no signature ?
		// try to guess the file format from the file extension
		fif = FreeImage_GetFIFFromFilename(lpszPathName);
	}
	// check that the plugin has reading capabilities ...
	if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
		// ok, let's load the file
		FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag);
		// unless a bad file format, we are done !
		return dib;
	}
	return NULL;
}
Exemplo n.º 3
0
//This method is used to load the skybox textures, since it is handled differently than a regular texture
int TextureLoader::LoadSkyboxTexture(const char* imagepath, GLuint skyTexture, GLenum side)
{    
    // Load image using the Free Image library
    FREE_IMAGE_FORMAT format = FreeImage_GetFileType(imagepath, 0);
    FIBITMAP* image = FreeImage_Load(format, imagepath);
    FIBITMAP* image32bits = FreeImage_ConvertTo32Bits(image);
    

    //Generate the cube map texture in Opengl
    //glActiveTexture (GL_TEXTURE0);
    glGenTextures (1, &skyTexture);
    //GLuint textureInd = 0;
    //glGenTextures(1, &textureInd);
    assert(skyTexture != 0);
    
    // Set OpenGL filtering properties (bi-linear interpolation)
    //Bind the texture to the cube map
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	//Texture parameters
    //Clamp-to-edge parameter helps to hide the seams of the cube textures
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    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);

    
    // Retrieve width and hight
    int width = FreeImage_GetWidth(image32bits);
    int height = FreeImage_GetHeight(image32bits);
    
    // This will upload the texture to the GPU memory
    glTexImage2D(side, 0, GL_RGBA8, width, height,
                 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(image32bits));
    
    // Free images
    FreeImage_Unload(image);
    FreeImage_Unload(image32bits);
 
    return skyTexture;
}
Exemplo n.º 4
0
bool GrayScaleHMap::loadMap(char* strFile)
{
	//image format
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	
	//pointer to the image, once loaded
	FIBITMAP *dib(0);
	
	//check the file signature and deduce its format
	fif = FreeImage_GetFileType(strFile, 0);
	
	//if still unknown, try to guess the file format from the file extension
	if(fif == FIF_UNKNOWN) 
		fif = FreeImage_GetFIFFromFilename(strFile);
	
	//if still unkown, return failure
	if(fif == FIF_UNKNOWN)
		return false;
	
	//check that the plugin has reading capabilities and load the file
	if(FreeImage_FIFSupportsReading(fif))
		dib = FreeImage_Load(fif, strFile);
	
	//if the image failed to load, return failure
	if(!dib)
		return false;
	
	//retrieve the image data
	bits = FreeImage_GetBits(dib);
	
	width = FreeImage_GetWidth(dib);
	height = FreeImage_GetHeight(dib);
	
	if((bits == NULL) || (width == 0) || (height == 0))
		return false;
	
	//Free FreeImage's copy of the data
	FreeImage_Unload(dib);
	
	return true;
}
Exemplo n.º 5
0
bool cTexture::loadTexture(const char* FilePath){
	//防止重复加载同一张图片
	if(strcmp(FilePath,_FilePath)==0){
		return true;
	}
	//获取图片
	fif=FreeImage_GetFileType(FilePath,0);									
	//识别图片格式
	if(fif == FIF_UNKNOWN){
		fif=FreeImage_GetFIFFromFilename(FilePath);
	}
	if(fif==FIF_UNKNOWN || !FreeImage_FIFSupportsReading(fif)){
		printf("FIError: not support type");
		return false;
	}
	//加载图片
	pic=FreeImage_Load(fif,FilePath);
	if(!pic){
		printf("Texture Error: cant not load!\n");
		return false;
	}
	//获取像素格式
	bits = FreeImage_GetBits(pic);
	width = FreeImage_GetWidth(pic);
	height = FreeImage_GetHeight(pic);
	show(width);show(height);
	if(bits==0 || width ==0 || height==0)
		return false;
	strcpy(_FilePath,FilePath);
	//加载texture 到显存
	glGenTextures(1, &texureId);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	glBindTexture(GL_TEXTURE_2D,texureId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Min Filter
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Mag Filter
	if(fif==FIF_PNG||fif==FIF_TARGA||fif==FIF_GIF)
		glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,bits);//支持透明的图片格式 需要设置格式为BGRA
	else
		glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_BGR_EXT,GL_UNSIGNED_BYTE,bits);//不支持透明的图片格式 
	return true;
}
Exemplo n.º 6
0
FIBITMAP *loadDIB(const std::string &url) {
	// figure out if the file exists
	if(!fs::exists(url)) {
		printf("poImage: image file not found (%s)\n", url.c_str());
		return NULL;
	}
	
	loadFreeImageIfNeeded();

	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	fif = FreeImage_GetFileType(url.c_str());
//	if(fif == FIF_UNKNOWN)
//		fif = FreeImage_GetFIFFromFilename(url.c_str());
	if(fif == FIF_UNKNOWN) {
		printf("poImage: image isn't a supported file type (%s)\n", url.c_str());
		return NULL;
	}
	
	FIBITMAP *dib = NULL;
	if(FreeImage_FIFSupportsReading(fif))
		dib = FreeImage_Load(fif, url.c_str());
	if(!dib) {
		printf("poImage: image file not found (%s)\n", url.c_str());
		return NULL;
	}

	unsigned bpp = FreeImage_GetBPP(dib);
	if(bpp == 24 || bpp == 32) {
		// there has got to be a more efficient way of doing this
		FIBITMAP *red = FreeImage_GetChannel(dib,FICC_RED);
		FIBITMAP *blue = FreeImage_GetChannel(dib,FICC_BLUE);
		
		FreeImage_SetChannel(dib,red,FICC_BLUE);
		FreeImage_SetChannel(dib,blue,FICC_RED);
		
		FreeImage_Unload(red);
		FreeImage_Unload(blue);
	}
	
	return dib;
}
Exemplo n.º 7
0
void Texture::loadBMP(const char *fileName)
{

    //image format
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    //check the file signature and deduce its format
    fif = FreeImage_GetFileType(fileName, 0);
    if(fif == FIF_UNKNOWN)
        return ;
    FIBITMAP *bitmap = FreeImage_Load(fif,fileName);
    BYTE *data (0);
    if(FreeImage_FIFSupportsReading(fif))
        data= FreeImage_GetBits(bitmap);
    if(!data)
        return;
    int width=FreeImage_GetWidth(bitmap);
    int height=FreeImage_GetHeight(bitmap);
    //

    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glGenTextures(1,&m_textureID);
    glBindTexture(GL_TEXTURE_2D,m_textureID);
    //give the image to OpenGL
    glTexImage2D(GL_TEXTURE_2D          //Always GL_TEXTURE_2D
                 ,0                     //0 for now
                 ,GL_RGB                //Format OpenGL uses for image
                 ,width,height          //Width and height
                 ,0                     //The border of the image
                 ,GL_RGB                //GL_RGB, because pixels are stored in RGB format
                 ,GL_UNSIGNED_BYTE      //GL_UNSIGNED_BYTE, because pixels are stored as unsigned numbers
                 ,data                  //The actual pixel data
                );

    FreeImage_Unload(bitmap);

    //    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    //    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
Exemplo n.º 8
0
Texture::Texture(const char* filename, GLenum image_format, GLint internal_format, GLint level, GLint border)
{
	glGenTextures(1, &this->id);

	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	FIBITMAP *dib(0);
	BYTE* bits(0);
	unsigned int width(0), height(0);
	GLuint gl_texID;

	fif = FreeImage_GetFileType(filename, 0);  //pobieranie typu tekstury
	if (fif == FIF_UNKNOWN)
		fif = FreeImage_GetFIFFromFilename(filename);
	if (fif == FIF_UNKNOWN){
		ReportWarning("Texture file format undefined");
		return;
	}


	if (FreeImage_FIFSupportsReading(fif))	//sprawdza czy moze odczytac
		dib = FreeImage_Load(fif, filename);	//odczytuje

	if (!dib)
		ReportWarning("Could not load texture");

	bits = FreeImage_GetBits(dib); //rozmiar piksela
	width = FreeImage_GetWidth(dib);	//wielkosc tekstury
	height = FreeImage_GetHeight(dib);

	
	glBindTexture(GL_TEXTURE_2D, this->id);		//bindowanie i ustawianie parametrow tekstury
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


	glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,	//generowanie tekstury
		border, image_format, GL_UNSIGNED_BYTE, bits);


	FreeImage_Unload(dib);
}
Exemplo n.º 9
0
bool Image::load(std::string file)
{
    //image format
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    //check the file signature and deduce its format
    fif = FreeImage_GetFileType(file.c_str(), 0);
    if(fif == FIF_UNKNOWN)
        return false;
    FIBITMAP *bitmap = FreeImage_Load(fif,file.c_str());
    if(FreeImage_FIFSupportsReading(fif))
    {
        m_data= FreeImage_GetBits(bitmap);
        if(!m_data)
            return false;
        m_width=FreeImage_GetWidth(bitmap);
        m_heigth=FreeImage_GetHeight(bitmap);
    }
    FreeImage_Unload(bitmap);

    return true;
}
Exemplo n.º 10
0
FIBITMAP* CBigle3DApp::LoadFile(CString strFile)
{
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;

    // check the file signature and deduce its format
    // (the second argument is currently not used by FreeImage)
    fif = FreeImage_GetFileType(strFile, 0);
    if(fif == FIF_UNKNOWN) {
        // no signature ?
        // try to guess the file format from the file extension
        fif = FreeImage_GetFIFFromFilename(strFile);
    }
    // check that the plugin has reading capabilities ...
    if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
        // ok, let's load the file
        FIBITMAP *dib = FreeImage_Load(fif, strFile, 0);
        // unless a bad file format, we are done !
        return dib;
    }
    return NULL;
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    FiaWindow *window = new FiaWindow;

    FIBITMAP *fib = FreeImage_Load(FIF_JPEG,
		"/home/glenn/Devel/Fia/Tests/FiaViewer/Test.jpg", JPEG_DEFAULT);

 
    window->viewer()->setImage(fib);

std::cout << "gg" << std::endl;

    //viewer->fitImageToViewer(false);
    //viewer->zoom(50.0);

    app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
    window->show();

    return app.exec();
}
Exemplo n.º 12
0
void testSaveMemIO(const char *lpszPathName) {
    FIMEMORY *hmem = NULL;

    // load a regular file
    FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName);
    FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0);

    // open a memory handle
    hmem = FreeImage_OpenMemory();

    // save the file to memory
    FreeImage_SaveToMemory(fif, dib, hmem, 0);

    // at this point, hmem contains the entire PNG data in memory.
    // the amount of space used by the memory is equal to file_size
    long file_size = FreeImage_TellMemory(hmem);
    printf("File size : %ld\n", file_size);


    // its easy load an image from memory as well

    // seek to the start of the memory stream
    FreeImage_SeekMemory(hmem, 0L, SEEK_SET);

    // get the file type
    FREE_IMAGE_FORMAT mem_fif = FreeImage_GetFileTypeFromMemory(hmem, 0);

    // load an image from the memory handle
    FIBITMAP *check = FreeImage_LoadFromMemory(mem_fif, hmem, 0);

    // save as a regular file
    FreeImage_Save(FIF_PNG, check, "dump.png", PNG_DEFAULT);

    // make sure to free the data since FreeImage_SaveToMemory
    // will cause it to be malloc'd
    FreeImage_CloseMemory(hmem);

    FreeImage_Unload(check);
    FreeImage_Unload(dib);
}
Exemplo n.º 13
0
    void GLTexture2D::Load()
    {
        auto fileOptions = GetParameters();
        auto filename = application->GetConfig().resourceBase + "/" + fileOptions[0];
        if (!boost::filesystem::exists(filename)) {
            LOG(ERROR) << "File \"" << filename.c_str() << L"\" cannot be opened.";
            throw resource_loading_error() << ::boost::errinfo_file_name(filename) << resid_info(id)
                << errdesc_info("Cannot open include file.");
        }

        auto format = FreeImage_GetFileType(filename.c_str());
        auto flags = 0;

        if (format == FIF_JPEG) {
            flags = JPEG_ACCURATE;
        } else if (format == FIF_TARGA) {
            flags = TARGA_LOAD_RGB888;
        }

        auto bitmap = FreeImage_Load(format, filename.c_str(), flags);
        auto bitmap32 = FreeImage_ConvertTo32Bits(bitmap);
        auto width = FreeImage_GetWidth(bitmap32);
        auto height = FreeImage_GetHeight(bitmap32);
        auto redMask = FreeImage_GetRedMask(bitmap32);
        auto greenMask = FreeImage_GetGreenMask(bitmap32);
        auto blueMask = FreeImage_GetBlueMask(bitmap32);
        void* data = FreeImage_GetBits(bitmap32);
        GLenum fmt = GL_RGBA;
        if (redMask > greenMask && greenMask > blueMask) fmt = GL_BGRA;
        auto internalFmt = GL_RGBA8;
        for (unsigned int i = 1; i < fileOptions.size(); ++i) {
            boost::trim(fileOptions[i]);
            if (fileOptions[i] == "sRGB" && application->GetConfig().useSRGB) internalFmt = GL_SRGB8_ALPHA8;
        }
        TextureDescriptor texDesc(4, internalFmt, fmt, GL_UNSIGNED_BYTE);
        texture = std::make_unique<GLTexture>(width, height, texDesc, data);
        FreeImage_Unload(bitmap32);
        FreeImage_Unload(bitmap);
        Resource::Load();
    }
Exemplo n.º 14
0
void atTexture::Load( const char* filename ) {
    FREE_IMAGE_FORMAT format = FreeImage_GetFileType(filename,0);//Automatocally detects the format(from over 20 formats!)
    if (format == FIF_UNKNOWN) {
        atContext::log->Error("Error derecting imaga file format of %s", filename);
    }
    FIBITMAP* image = FreeImage_Load(format, filename);
    if (!image) {
        atContext::log->Error("There was an error loading the texture");
    }

    FIBITMAP* temp = image;
    image = FreeImage_ConvertTo32Bits(image);
    FreeImage_Unload(temp);

    int w = FreeImage_GetWidth(image);
    int h = FreeImage_GetHeight(image);

    GLubyte* texture = new GLubyte[4*w*h];
    char* pixels = (char*)FreeImage_GetBits(image);

    for(int j= 0; j<w*h; j++){
        texture[j*4+0]= pixels[j*4+2];
        texture[j*4+1]= pixels[j*4+1];
        texture[j*4+2]= pixels[j*4+0];
        texture[j*4+3]= pixels[j*4+3];
    }

    glGenTextures(1, &m_TextureID);
    glBindTexture(GL_TEXTURE_2D, m_TextureID);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, w, h, 0, GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)texture );
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    GLenum huboError = glGetError();
    if(huboError){
        atContext::log->Error("There was an error loading the texture");
    }
}
Exemplo n.º 15
0
	static GLuint loadTexture(const char *filename) {

		FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
		FIBITMAP *dib(0);
		BYTE* bits(0);
		GLuint gl_texID;
		unsigned int width(0), height(0);

		fif = FreeImage_GetFileType(filename, 0);
		if(fif == FIF_UNKNOWN) {
			fif = FreeImage_GetFIFFromFilename(filename);
			return 0;
		}

		if(FreeImage_FIFSupportsReading(fif))
			dib = FreeImage_Load(fif, filename);
		if(!dib)
			return false;

		dib = FreeImage_ConvertTo24Bits(dib);
		bits = FreeImage_GetBits(dib);
		width = FreeImage_GetWidth(dib);
		height = FreeImage_GetHeight(dib);
		if((bits == 0) || (width == 0) || (height == 0))
			return 0;

		glGenTextures(1, &gl_texID);
		glBindTexture(GL_TEXTURE_2D, gl_texID);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, bits);
		// FreeImage loads textures in BGR format.

		FreeImage_Unload(dib);

		return gl_texID;
	}
Exemplo n.º 16
0
static bool loadImage(ofPixels_<PixelType> & pix, string fileName){
	ofInitFreeImage();
	if(fileName.substr(0, 7) == "http://") {
		return ofLoadImage(pix, ofLoadURL(fileName).data);
	}
	
	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);

		if (bmp != NULL){
			bLoaded = true;
		}
	}
	
	//-----------------------------

	if ( bLoaded ){
		putBmpIntoPixels(bmp,pix);
	} else {
		width = height = bpp = 0;
	}

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

	return bLoaded;
}
Exemplo n.º 17
0
Image::Image(const Path& path)
	: Base(path)
{
	// Open the file
	FREE_IMAGE_FORMAT format = FreeImage_GetFileType(path.ToString().Cstr());
	FIBITMAP* image = FreeImage_Load(format, path.ToString().Cstr(), 0);

	if (!image)
	{
		Console::Warning("'@' could not be opened", path);
		return;
	}

	FIBITMAP* temp = image;
	_bitmap = (uint32*)FreeImage_ConvertTo32Bits(image);
	FreeImage_Unload(temp);

	_width = FreeImage_GetWidth(image);
	_height = FreeImage_GetHeight(image);

	Console::WriteLine("'@' loaded successfully", path);
}
Exemplo n.º 18
0
	GLuint LoadTexture(char* szFileName)
	{
		GLuint glTexture;

		FIBITMAP* pBitmap = FreeImage_Load(FreeImage_GetFileType("Images/Charmander.png", 0), "Images/Charmander.png");
		FIBITMAP* pImage = FreeImage_ConvertTo32Bits(pBitmap);

		int iWidth = FreeImage_GetWidth(pImage);
		int iHeight = FreeImage_GetHeight(pImage);

		glGenTextures(1, &glTexture);

		glBindTexture(GL_TEXTURE_2D, glTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, iWidth, iHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(pImage));

		FreeImage_Unload(pImage);

		return glTexture;
	}
Exemplo n.º 19
0
  unsigned char* Texture::loadTexture( const char* fileName_,
                                       unsigned int &width_,
                                       unsigned int &height_ )
  {
    FreeImage_Initialise(TRUE);

    FREE_IMAGE_FORMAT format = FreeImage_GetFileType(fileName_, 0);
    if (format == FIF_UNKNOWN)
      format = FreeImage_GetFIFFromFilename(fileName_);
    if ((format == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading(format))
      return NULL;

    FIBITMAP* img = FreeImage_Load(format, fileName_);
    if (img == NULL)
      return NULL;

    FIBITMAP* tempImg = img;
    img = FreeImage_ConvertTo32Bits(img);
    FreeImage_Unload(tempImg);

    width_ = FreeImage_GetWidth(img);
    height_ = FreeImage_GetHeight(img);

    //BGRA a RGBA
    unsigned char * map = new unsigned char[4 * width_*height_];
    char *buff = (char*)FreeImage_GetBits(img);

    for (unsigned int j = 0; j<width_*height_; j++){
      map[j * 4 + 0] = buff[j * 4 + 2];
      map[j * 4 + 1] = buff[j * 4 + 1];
      map[j * 4 + 2] = buff[j * 4 + 0];
      map[j * 4 + 3] = buff[j * 4 + 3];
    }

    FreeImage_Unload(img);
    FreeImage_DeInitialise();

    return map;
  }
void load_o14_FromHDtoSystemRAM(void*) 
{                                                                           
    fifmt_o14 = FreeImage_GetFileType(o14_FilePath, 0);                       
    dib_o14   = FreeImage_Load(fifmt_o14, o14_FilePath, 0);                    
    temp_o14  = dib_o14;                                                      
    dib_o14   = FreeImage_ConvertTo32Bits(temp_o14);                          
    FreeImage_Unload(temp_o14);                                            

    if( dib_o14 != NULL )                                                    
    {                                                                       
        pixels_o14 = (BYTE*)FreeImage_GetBits(dib_o14);                       
    }                                                                     

    o14_isLoadedFromDriveAndWaiting = true;                                  
    //---------------------                                                 
    if(MAX_THREADS > 0)                                                     
    {                                                                       
         MAX_THREADS -= 1;                                                  
    }                                                                       
    //---------------------                                                 
    _endthread();                                                           
}                                                                           
void load_copperEntrance_FromHDtoSystemRAM(void*) 
{                                                                           
    fifmt_copperEntrance = FreeImage_GetFileType(copperEntrance_FilePath, 0);                       
    dib_copperEntrance   = FreeImage_Load(fifmt_copperEntrance, copperEntrance_FilePath, 0);                    
    temp_copperEntrance  = dib_copperEntrance;                                                      
    dib_copperEntrance   = FreeImage_ConvertTo32Bits(temp_copperEntrance);                          
    FreeImage_Unload(temp_copperEntrance);                                            

    if( dib_copperEntrance != NULL )                                                    
    {                                                                       
        pixels_copperEntrance = (BYTE*)FreeImage_GetBits(dib_copperEntrance);                       
    }                                                                     

    copperEntrance_isLoadedFromDriveAndWaiting = true;                                  
    //---------------------                                                 
    if(MAX_THREADS > 0)                                                     
    {                                                                       
         MAX_THREADS -= 1;                                                  
    }                                                                       
    //---------------------                                                 
    _endthread();                                                           
}                                                                           
void load_rocks_o15_FromHDtoSystemRAM(void*) 
{                                                                           
    fifmt_rocks_o15 = FreeImage_GetFileType(rocks_o15_FilePath, 0);                       
    dib_rocks_o15   = FreeImage_Load(fifmt_rocks_o15, rocks_o15_FilePath, 0);                    
    temp_rocks_o15  = dib_rocks_o15;                                                      
    dib_rocks_o15   = FreeImage_ConvertTo32Bits(temp_rocks_o15);                          
    FreeImage_Unload(temp_rocks_o15);                                            

    if( dib_rocks_o15 != NULL )                                                    
    {                                                                       
        pixels_rocks_o15 = (BYTE*)FreeImage_GetBits(dib_rocks_o15);                       
    }                                                                     

    rocks_o15_isLoadedFromDriveAndWaiting = true;                                  
    //---------------------                                                 
    if(MAX_THREADS > 0)                                                     
    {                                                                       
         MAX_THREADS -= 1;                                                  
    }                                                                       
    //---------------------                                                 
    _endthread();                                                           
}                                                                           
Exemplo n.º 23
0
/// Loading a PNG file
gli::texture2D load_png(char const * Filename)
{
	FreeImageInit();

	FIBITMAP * Bitmap = FreeImage_Load(FIF_PNG, Filename, 0);
	if(!Bitmap)
		return gli::texture2D();

	glm::uint BPP = FreeImage_GetBPP(Bitmap);
	glm::uint Width = FreeImage_GetWidth(Bitmap);
	glm::uint Height = FreeImage_GetHeight(Bitmap);

	gli::texture2D Texture(1, BPP == 24 ? gli::RGB8_UNORM : gli::RGBA8_UNORM, gli::texture2D::dimensions_type(Width, Height));
	memcpy(Texture.data(), FreeImage_GetBits(Bitmap), Texture.size());
	FreeImage_Unload(Bitmap);

	switch(gli::component_count(Texture.format()))
	{
	default:
		assert(0);
		break;
	case 3:
		for(std::size_t Offset = 0; Offset < Texture.size() / 3; ++Offset)
		{
			glm::u8vec3 Src = *(reinterpret_cast<glm::u8vec3 const *>(Texture.data()) + Offset);
			*(reinterpret_cast<glm::u8vec3*>(Texture.data()) + Offset) = glm::u8vec3(Src.z, Src.y, Src.x);
		}
		break;
	case 4:
		for(std::size_t Offset = 0; Offset < Texture.size() / 4; ++Offset)
		{
			glm::u8vec4 Src = *(reinterpret_cast<glm::u8vec4 const *>(Texture.data()) + Offset);
			*(reinterpret_cast<glm::u8vec4*>(Texture.data()) + Offset) = glm::u8vec4(Src.z, Src.y, Src.x, Src.w);
		}
		break;
	}

	return Texture;
}
Exemplo n.º 24
0
Image::Image(int width, int height, const char *fname) {
    FreeImage_Initialise();
    FIBITMAP *bitmap = FreeImage_Load(FIF_BMP, fname, BMP_DEFAULT);
    FIBITMAP *bitmap32 = FreeImage_ConvertTo32Bits(bitmap);
    _width = width;
    _height = height;
    if (!bitmap || !bitmap32) {
        throw "Failed to load image!";
    }
    //image scaling
    FIBITMAP *bitmap32scale = FreeImage_Rescale(bitmap32, width, height, FILTER_BICUBIC);

    BYTE* texturebits = FreeImage_GetBits(bitmap32scale);

    _pixels = new Pixel[_width*_height];
    Pixel *texture = (Pixel*)texturebits;
    for (unsigned int i = 0; i<_width*_height; ++i) {
        _pixels[i].setRGBA(texture[i].getB(), texture[i].getG(),
                texture[i].getR(), texture[i].getA());
    }
    FreeImage_Unload(bitmap);
}
Exemplo n.º 25
0
    /// Load a gray-scale image from disk.
    void 
    loadImage(const std::string & rFileName, ImageCPU_8u_C1 & rImage)
    {
	            // set your own FreeImage error handler
	    FreeImage_SetOutputMessage(FreeImageErrorHandler);

        FREE_IMAGE_FORMAT eFormat = FreeImage_GetFileType(rFileName.c_str());
                // no signature? try to guess the file format from the file extension
        if (eFormat == FIF_UNKNOWN)
            eFormat = FreeImage_GetFIFFromFilename(rFileName.c_str());
        NPP_ASSERT(eFormat != FIF_UNKNOWN);
                // check that the plugin has reading capabilities ...
        FIBITMAP * pBitmap;
        if (FreeImage_FIFSupportsReading(eFormat)) 
            pBitmap = FreeImage_Load(eFormat, rFileName.c_str());
        NPP_ASSERT(pBitmap != 0);
                // make sure this is an 8-bit single channel image
        NPP_ASSERT(FreeImage_GetColorType(pBitmap) == FIC_MINISBLACK);
        NPP_ASSERT(FreeImage_GetBPP(pBitmap) == 8);
        
                // create an ImageCPU to receive the loaded image data
        ImageCPU_8u_C1 oImage(FreeImage_GetWidth(pBitmap), FreeImage_GetHeight(pBitmap));
        
                // Copy the FreeImage data into the new ImageCPU
        unsigned int nSrcPitch = FreeImage_GetPitch(pBitmap);
        const Npp8u * pSrcLine = FreeImage_GetBits(pBitmap) + nSrcPitch * (FreeImage_GetHeight(pBitmap) -1);
        Npp8u * pDstLine = oImage.data();
        unsigned int nDstPitch = oImage.pitch();
        for (size_t iLine = 0; iLine < oImage.height(); ++iLine)
        {
            memcpy(pDstLine, pSrcLine, oImage.width() * sizeof(Npp8u));
            pSrcLine -= nSrcPitch;
            pDstLine += nDstPitch;
        }
        
                // swap the user given image with our result image, effecively
                // moving our newly loaded image data into the user provided shell
        oImage.swap(rImage);
    }
Image::Image(const char *image_path, GLuint textureUnit, bool& success) {
	success = true;
	FreeImage_Initialise();
	texture_unit = textureUnit;
	// Load Texture
	FREE_IMAGE_FORMAT image_format = FreeImage_GetFileType(image_path,0);
	FIBITMAP* image_bgr = FreeImage_Load(image_format, image_path);
	if (!image_bgr) {
		fprintf(stdout, "Failed to load image %s", image_path);
		success = false;
	}
	FIBITMAP* temp = image_bgr;
	image_bgr = FreeImage_ConvertTo32Bits(image_bgr);
	FreeImage_Unload(temp);
	im_width = FreeImage_GetWidth(image_bgr);
	im_height = FreeImage_GetHeight(image_bgr);
	GLubyte* image_texture = new GLubyte[4*im_width*im_height];
	char* image_pixeles = (char*)FreeImage_GetBits(image_bgr);
	//FreeImage loads in BGR format, so you need to swap some bytes(Or use GL_BGR).
	for(int j= 0; j<im_width*im_height; j++){
		image_texture[j*4+0]= image_pixeles[j*4+2];
		image_texture[j*4+1]= image_pixeles[j*4+1];
		image_texture[j*4+2]= image_pixeles[j*4+0];
		image_texture[j*4+3]= image_pixeles[j*4+3];
	}
	FreeImage_DeInitialise();
	// Create one OpenGL texture
	glGenTextures(1, &texture_handle);
	glActiveTexture(GL_TEXTURE0 + textureUnit);
	glBindTexture(GL_TEXTURE_2D, texture_handle);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, im_width, im_height, 0, GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)image_texture );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
	glGenerateMipmap(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,0);
}
Exemplo n.º 27
0
bool OpenImage(Graphics::TBitmap* picture, const AnsiString& path)
{
	FREE_IMAGE_FORMAT imgFormat;
	
	imgFormat = FreeImage_GetFileType(path.c_str(), 0);
	
	if(imgFormat != FIF_UNKNOWN)
	{
		FIBITMAP *image = FreeImage_Load(imgFormat, path.c_str(), 0);		
		if(image)
		{
			FIBITMAP* tempImage = FreeImage_ConvertTo32Bits(image);
			if(!tempImage)
			{
				FreeImage_Unload(image);
				return false;
			}
			if(LoadImage(tempImage, picture))
			{
				FreeImage_Unload(image);
				FreeImage_Unload(tempImage);
				return true;
			}
			else
			{
				FreeImage_Unload(image);
				FreeImage_Unload(tempImage);
				return false;
			}
		}
		else 
		{
			return false;
		}
	}

	return false;	
}
Exemplo n.º 28
0
bool CTexture::ReloadTexture()
{
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	FIBITMAP* dib(0);

	fif = FreeImage_GetFileType(sPath.c_str(), 0); // Check the file signature and deduce its format

	if(fif == FIF_UNKNOWN) // If still unknown, try to guess the file format from the file extension
		fif = FreeImage_GetFIFFromFilename(sPath.c_str());
	
	if(fif == FIF_UNKNOWN) // If still unknown, return failure
		return false;

	if(FreeImage_FIFSupportsReading(fif)) // Check if the plugin has reading capabilities and load the file
		dib = FreeImage_Load(fif, sPath.c_str());
	if(!dib)
		return false;

	BYTE* bDataPointer = FreeImage_GetBits(dib); // Retrieve the image data

	// If somehow one of these failed (they shouldn't), return failure
	if(bDataPointer == NULL || FreeImage_GetWidth(dib) == 0 || FreeImage_GetHeight(dib) == 0)
		return false;

	GLenum format;
	int bada = FreeImage_GetBPP(dib);
	if(FreeImage_GetBPP(dib) == 32)format = GL_RGBA;
	if(FreeImage_GetBPP(dib) == 24)format = GL_BGR;
	if(FreeImage_GetBPP(dib) == 8)format = GL_LUMINANCE;

	glBindTexture(GL_TEXTURE_2D, uiTexture);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, iWidth, iHeight, format, GL_UNSIGNED_BYTE, bDataPointer);
	if(bMipMapsGenerated)glGenerateMipmap(GL_TEXTURE_2D);
	
	FreeImage_Unload(dib);

	return true; // Success
}
Exemplo n.º 29
0
static INT_PTR serviceLoad(WPARAM wParam, LPARAM lParam)
{
	char *lpszFilename = (char *)wParam;
	if(lpszFilename==NULL) return 0;
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;

	if(lParam & IMGL_WCHAR)
		fif = FreeImage_GetFileTypeU((wchar_t *)lpszFilename, 0);
	else
		fif = FreeImage_GetFileType(lpszFilename, 0);

	if(fif == FIF_UNKNOWN) {
		if(lParam & IMGL_WCHAR)
			fif = FreeImage_GetFIFFromFilenameU((wchar_t *)lpszFilename);
		else
			fif = FreeImage_GetFIFFromFilename(lpszFilename);
	}
	// check that the plugin has reading capabilities ...

	if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
		// ok, let's load the file
		FIBITMAP *dib;

		if (lParam & IMGL_WCHAR)
			dib = FreeImage_LoadU(fif, (wchar_t *)lpszFilename, 0);
		else
			dib = FreeImage_Load(fif, lpszFilename, 0);

		if(dib == NULL || (lParam & IMGL_RETURNDIB))
			return (INT_PTR)dib;

		HBITMAP hbm = FreeImage_CreateHBITMAPFromDIB(dib);
		FreeImage_Unload(dib);
		FI_CorrectBitmap32Alpha(hbm, FALSE);
		return ((INT_PTR)hbm);
	}
	return NULL;
}
Exemplo n.º 30
0
uint8_t picture_load(const char* filename) {
  FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
  int flag = 0;
  FIBITMAP *temp;
  fif=FreeImage_GetFileType(filename, 0);
  if(fif == FIF_UNKNOWN) {
    fif=FreeImage_GetFIFFromFilename(filename);
  }
  if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
    temp = FreeImage_Load(fif, filename,flag);
    if(temp) {
      dib = FreeImage_ConvertTo24Bits(temp);
      FreeImage_Unload(temp);
      if(dib) {
        w = FreeImage_GetWidth(dib);
        h = FreeImage_GetHeight(dib);
        if(w == 0 || h == 0) {
          FreeImage_Unload(dib);
          dib=NULL;
          return (last_error = PIC_LOADING);
        } else if(w > 1000 || h > 4000) {
          FreeImage_Unload(dib);
          dib=NULL;
          return (last_error = PIC_SIZE);
        } else {
          return (last_error = analyze());
        }
      } else {
        return (last_error = PIC_CONVERT);
      }
    } else {
      return (last_error = PIC_LOADING);
    }
  } else {
    return (last_error = PIC_FORMAT);
  }
}