本文整理汇总了C++中FreeImage_Load函数的典型用法代码示例。如果您正苦于以下问题:C++ FreeImage_Load函数的具体用法?C++ FreeImage_Load怎么用?C++ FreeImage_Load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FreeImage_Load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FreeImage_Unload
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();
}
示例2: GenericLoader
/** 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;
}
示例3: FreeImage_GetFileType
//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;
}
示例4: FreeImage_GetFileType
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;
}
示例5: printf
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;
}
示例6: FreeImage_GetFileType
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);
}
示例7: glGenTextures
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);
}
示例8: FreeImage_GetFileType
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;
}
示例9: FreeImage_GetFileType
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;
}
示例10: main
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();
}
示例11: testSaveMemIO
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);
}
示例12: GetParameters
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();
}
示例13: FreeImage_GetFileType
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");
}
}
示例14: loadTexture
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;
}
示例15: Base
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);
}