本文整理汇总了C++中FreeImage_ConvertTo32Bits函数的典型用法代码示例。如果您正苦于以下问题:C++ FreeImage_ConvertTo32Bits函数的具体用法?C++ FreeImage_ConvertTo32Bits怎么用?C++ FreeImage_ConvertTo32Bits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FreeImage_ConvertTo32Bits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FreeImage_GetFileType
int TextureLoader::LoadTexture(const char * imagepath)
{
// 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);
// Get an available texture index from OpenGL
GLuint texture = 0;
glGenTextures(1, &texture);
assert(texture != 0);
// Set OpenGL filtering properties (bi-linear interpolation)
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Retrieve width and hight
int width = FreeImage_GetWidth(image32bits);
int height = FreeImage_GetHeight(image32bits);
// This will upload the texture to the GPU memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,
0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(image32bits));
// Free images
FreeImage_Unload(image);
FreeImage_Unload(image32bits);
return texture;
}
示例2: SDL_assert_release
FIBITMAP *GraphicsHelps::loadImageRC(const char *file)
{
unsigned char *memory = nullptr;
size_t fileSize = 0;
SDL_assert_release(RES_getMem(file, memory, fileSize));
//{
//pLogCritical("Resource file \"%s\" is not found!", file);
//return nullptr;
//}
FIMEMORY *imgMEM = FreeImage_OpenMemory(memory, static_cast<FI_DWORD>(fileSize));
FREE_IMAGE_FORMAT formato = FreeImage_GetFileTypeFromMemory(imgMEM);
if(formato == FIF_UNKNOWN)
return nullptr;
FIBITMAP *img = FreeImage_LoadFromMemory(formato, imgMEM, 0);
FreeImage_CloseMemory(imgMEM);
if(!img)
return nullptr;
FIBITMAP *temp;
temp = FreeImage_ConvertTo32Bits(img);
if(!temp)
return nullptr;
FreeImage_Unload(img);
img = temp;
return img;
}
示例3: FreeImage_ConvertTo32Bits
GLuint Engine::useTexture(char* texDir, bool wrap) {
FIBITMAP* imagePtr =
FreeImage_ConvertTo32Bits(
FreeImage_Load(
FreeImage_GetFileType(texDir, 0), texDir)
);
GLuint texture;
glGenTextures(1, &texture); // i used to be 1
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_SRGB_ALPHA,
FreeImage_GetWidth(imagePtr),
FreeImage_GetHeight(imagePtr),
0, GL_BGRA, GL_UNSIGNED_BYTE,
(void*)FreeImage_GetBits(imagePtr));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP);
// Clear from RAM
FreeImage_Unload(imagePtr);
// Unbind when finished uplloading
glBindTexture(GL_TEXTURE_2D, 0);
return texture;
}
示例4: load_image
std::shared_ptr<FIBITMAP> load_image(const std::wstring& filename)
{
if(!boost::filesystem::exists(filename))
BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename)));
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
fif = FreeImage_GetFileTypeU(filename.c_str(), 0);
if(fif == FIF_UNKNOWN)
fif = FreeImage_GetFIFFromFilenameU(filename.c_str());
if(fif == FIF_UNKNOWN || !FreeImage_FIFSupportsReading(fif))
BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));
auto bitmap = std::shared_ptr<FIBITMAP>(FreeImage_LoadU(fif, filename.c_str(), 0), FreeImage_Unload);
if(FreeImage_GetBPP(bitmap.get()) != 32)
{
bitmap = std::shared_ptr<FIBITMAP>(FreeImage_ConvertTo32Bits(bitmap.get()), FreeImage_Unload);
if(!bitmap)
BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));
}
//PNG-images need to be premultiplied with their alpha
if(fif == FIF_PNG)
{
image_view<bgra_pixel> original_view(FreeImage_GetBits(bitmap.get()), FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()));
premultiply(original_view);
}
return bitmap;
}
示例5: FreeImage_GetFileType
GLubyte* Texture::loadToBitmap(std::string path, bool flip)
{
const char* pathCStr = path.c_str();
FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
format = FreeImage_GetFileType(pathCStr);
if (format == FIF_UNKNOWN)
format = FreeImage_GetFIFFromFilename(pathCStr);
if (format == FIF_UNKNOWN) {
std::cout << "Failed to load image at " << pathCStr << std::endl;
return nullptr;
}
if (!FreeImage_FIFSupportsReading(format))
{
std::cout << "Detected image format cannot be read! " << pathCStr << std::endl;
return nullptr;
}
m_bitmap = FreeImage_Load(format, pathCStr);
if (flip)
FreeImage_FlipVertical(m_bitmap);
GLint bitsPerPixel = FreeImage_GetBPP(m_bitmap);
if (bitsPerPixel == 32)
m_bitmap32 = m_bitmap;
else
m_bitmap32 = FreeImage_ConvertTo32Bits(m_bitmap);
m_width = FreeImage_GetWidth(m_bitmap32);
m_height = FreeImage_GetHeight(m_bitmap32);
return FreeImage_GetBits(m_bitmap32);
}
示例6: compatible
void ImageLoader::
compatible()
{
// BITMAP数据是从下往上的, 需要翻转
FreeImage_FlipVertical(mDIB);
// FreeImage是BGR顺序, 与NVTT要求的一致, 而PVRT需要RGB顺序, 两者都需要32bits数据
if (config.imageCompressionType != CT_DXTC)
{
// 将BGR改为RGB, 交换R channel和B channel
const unsigned bytesperpixel = FreeImage_GetBPP(mDIB) / 8;
const unsigned height = FreeImage_GetHeight(mDIB);
const unsigned pitch = FreeImage_GetPitch(mDIB);
const unsigned lineSize = FreeImage_GetLine(mDIB);
BYTE* line = FreeImage_GetBits(mDIB);
for (unsigned y = 0; y < height; ++y, line += pitch) {
for (BYTE* pixel = line; pixel < line + lineSize; pixel += bytesperpixel) {
INPLACESWAP(pixel[0], pixel[2]);
}
}
}
if (FreeImage_GetBPP(mDIB) != 32)
{
FIBITMAP* convertDIB = FreeImage_ConvertTo32Bits(mDIB);
FreeImage_Unload(mDIB);
mDIB = convertDIB;
}
}
示例7: createTexture
image* createTexture(char* filePath){
//FreeImage_Initialise(FALSE);
FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(filePath,0);//Automatocally detects the format(from over 20 formats!)
FIBITMAP* imagen = FreeImage_Load(formato, filePath,JPEG_ACCURATE);
FIBITMAP* temp = imagen;
imagen = FreeImage_ConvertTo32Bits(imagen);
FreeImage_Unload(temp);
int w = FreeImage_GetWidth(imagen);
int h = FreeImage_GetHeight(imagen);
GLubyte* textura = (GLubyte*) malloc(4*w*h);
char* pixeles = (char*)FreeImage_GetBits(imagen);
//FreeImage loads in BGR format, so you need to swap some bytes(Or use GL_BGR).
int j = 0;
for(; j<w*h; j++){
textura[j*4+0]= pixeles[j*4+2];
textura[j*4+1]= pixeles[j*4+1];
textura[j*4+2]= pixeles[j*4+0];
textura[j*4+3]= pixeles[j*4+3];
}
free(pixeles);
FreeImage_Unload(imagen);
image* imageToReturn = malloc(sizeof(image));
imageToReturn->height = h;
imageToReturn->width = w;
imageToReturn->texture = textura;
return imageToReturn;
}
示例8: loadTexture
void loadTexture(char *textureFileName, GLuint &textureMapID)
{
FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(textureFileName, 0);
FIBITMAP *dib = FreeImage_Load(fifmt, textureFileName,0);
FIBITMAP *temp = dib;
dib = FreeImage_ConvertTo32Bits(temp);
FreeImage_Unload(temp);
if( dib != NULL )
{
glGenTextures( 1, &textureMapID );
glBindTexture( GL_TEXTURE_2D, textureMapID );
BYTE *pixels = (BYTE*)FreeImage_GetBits(dib);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
ConfigureAndLoadTexture(pixels, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib) );
glActiveTexture (GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureMapID);
//===================================================================================================
//===================================================================================================
free(pixels);
FreeImage_Unload(dib);
}
}
示例9: FreeImage_ConvertTo32Bits
BOOL fipImage::convertTo32Bits() {
if(_dib) {
FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(_dib);
return replace(dib32);
}
return FALSE;
}
示例10: Init
int Init ( AAContext *aaContext )
{
UserData *userData = (UserData*) aaContext->userData;
userData->animation = (Animation*) malloc(sizeof(Animation));
memset(userData->animation, 0x0, sizeof(Animation));
glGenTextures(1, &userData->earth_texture);
glBindTexture(GL_TEXTURE_2D, userData->earth_texture);
FIBITMAP* bitmap = FreeImage_Load(
FreeImage_GetFileType("earth.png", 0),
"earth.png");
FIBITMAP *pImage = FreeImage_ConvertTo32Bits(bitmap);
int nWidth = FreeImage_GetWidth(pImage);
int nHeight = FreeImage_GetHeight(pImage);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, nWidth, nHeight,
0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(pImage));
FreeImage_Unload(pImage);
FreeImage_Unload(bitmap); // correct?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
const char vShaderStr[] =
"uniform mat4 u_mvp; \n"
"attribute vec2 a_texCoords; \n"
"varying vec2 v_texCoords; \n"
"attribute vec4 a_position; \n"
"out float debug; \n"
"void main() \n"
"{ \n"
"vec4 pos = u_mvp * a_position; \n"
"gl_Position = pos; \n"
"v_texCoords = a_texCoords; \n"
"debug = a_position.y; \n"
"} \n";
const char fShaderStr[] =
"in float debug; \n"
"varying vec2 v_texCoords; \n"
"uniform sampler2D s_earthTexture; \n"
"precision mediump float; \n"
"void main() \n"
"{ \n"
"vec4 color = texture(s_earthTexture, v_texCoords); \n"
// "if(debug>0) \n"
// "color = vec4(1.0, 0.0, 0.0, 1.0); \n"
"gl_FragColor = color; \n"
"} \n";
// Load the shaders and get a linked program object
userData->programObject = LoadProgram ( vShaderStr, fShaderStr );
// Get the attribute locations
userData->positionLoc = glGetAttribLocation ( userData->programObject, "a_position" );
userData->mvpLoc = glGetUniformLocation(userData->programObject, "u_mvp");
userData->texCoordsLoc = glGetAttribLocation(userData->programObject, "a_texCoords");
userData->texLoc = glGetUniformLocation(userData->programObject, "s_earthTexture");
glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
glEnable(GL_DEPTH_TEST);
return TRUE;
}
示例11: FreeImage_GetFileType
RGBAImage* RGBAImage::ReadFromFile(const char* filename)
{
const FREE_IMAGE_FORMAT fileType = FreeImage_GetFileType(filename);
if(FIF_UNKNOWN == fileType)
{
printf("Unknown filetype %s\n", filename);
return 0;
}
FIBITMAP* freeImage = 0;
if(FIBITMAP* temporary = FreeImage_Load(fileType, filename, 0))
{
freeImage = FreeImage_ConvertTo32Bits(temporary);
FreeImage_Unload(temporary);
}
if(!freeImage)
{
printf( "Failed to load the image %s\n", filename);
return 0;
}
RGBAImage *result = ToRGBAImage(freeImage);
FreeImage_Unload(freeImage);
return result;
}
示例12: make_texture
GLuint make_texture(const char *filename) {
GLuint texture;
// Get the image file type from FreeImage.
FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(filename, 0);
// Actually load the image file.
FIBITMAP *dib = FreeImage_Load(fifmt, filename, 0);
// Now, there is no guarantee that the image file
// loaded will be GL_RGB, so we force FreeImage to
// convert the image to GL_RGB.
dib = FreeImage_ConvertTo32Bits(dib);
if (dib != NULL) {
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// This is important to note, FreeImage loads textures in
// BGR format. Now we could just use the GL_BGR extension
// But, we will simply swap the B and R components ourselves.
// Firstly, allocate the new bit data doe the image.
//BYTE *bits = malloc(FreeImage_GetWidth(dib) * FreeImage_GetHeight(dib) * 4);
// get a pointer to FreeImage's data.
BYTE *pixels = (BYTE*) FreeImage_GetBits(dib);
// Iterate through the pixels, copying the data
// from 'pixels' to 'bits' except in RGB format.
/*
int pix;
for (pix = 0; pix < FreeImage_GetWidth(dib) * FreeImage_GetHeight(dib); pix++) {
bits[pix * 4 + 0] = pixels[pix * 4 + 2];
bits[pix * 4 + 1] = pixels[pix * 4 + 1];
bits[pix * 4 + 2] = pixels[pix * 4 + 0];
bits[pix * 4 + 3] = pixels[pix * 4 + 3];
}*/
// The new 'glTexImage2D' function, the prime difference
// being that it gets the width, height and pixel information
// from 'bits', which is the RGB pixel data..
//glTexImage2D(GL_TEXTURE_2D, 0, 4, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,
// GL_RGBA, GL_UNSIGNED_BYTE, bits);
glTexImage2D(GL_TEXTURE_2D, 0, 4, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,
GL_BGRA, GL_UNSIGNED_BYTE, pixels);
// Unload the image.
// and free the bit data.
FreeImage_Unload(dib);
//free(bits);
} else {
fprintf(stderr, "Can't load texture: %s\n", filename);
}
return texture;
}
示例13: stuff
bool FreeimagelibPlugin::LoadDoc(cpcl::IOStream *input, plcl::Doc **r) {
FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)freeimagelib_format;
FreeimagelibStuff stuff(input);
boost::shared_ptr<FIBITMAP> fibitmap(FreeImage_LoadFromHandle(fif, &stuff.io, stuff.io_handle), FreeImage_Unload);
if (!fibitmap) {
cpcl::Error(cpcl::StringPieceFromLiteral("FreeimagelibPlugin::LoadDoc(): unable to load image"));
return false;
}
if (FreeImage_GetImageType(fibitmap.get()) != FIT_BITMAP) {
boost::shared_ptr<FIBITMAP> tmp(FreeImage_ConvertToType(fibitmap.get(), FIT_BITMAP), FreeImage_Unload);
if (!tmp || (FreeImage_GetImageType(tmp.get()) != FIT_BITMAP)) {
cpcl::Error(cpcl::StringPieceFromLiteral("FreeimagelibPlugin::LoadDoc(): unable to convert the image to FIT_BITMAP"));
return false;
}
fibitmap = tmp;
}
unsigned int const bpp = FreeImage_GetBPP(fibitmap.get());
if (!(bpp == 24 || bpp == 32)) {
boost::shared_ptr<FIBITMAP> tmp((bpp > 32) ? FreeImage_ConvertTo32Bits(fibitmap.get()) : FreeImage_ConvertTo24Bits(fibitmap.get()), FreeImage_Unload);
if (!tmp) {
cpcl::Trace(CPCL_TRACE_LEVEL_ERROR,
"FreeimagelibPlugin::LoadDoc(): unable to convert image with bpp %u",
bpp);
}
fibitmap = tmp;
}
if (r)
*r = new FreeimagelibDoc(fibitmap);
return true;
}
示例14: bits
/*
* \brief Method that import a texture to be used on the model
* \param[in] fTexture a constant char array containing the path to the file of the texture
* \param[in] tex_number an unsigned integer representing the type of texture (i.e. 0 = Diffuse color, 1 = Normalmap, 2 = Specular Color)
* \return a boolean indicating if the import was successful of not
*/
GLboolean Model::importTexture(const GLchar * fTexture, GLuint tex_number)
{
GLboolean import_is_ok = GL_FALSE;
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
FIBITMAP *dib(0);
BYTE* bits(0);
GLuint width(0), height(0);
fif = FreeImage_GetFileType(fTexture, 0);
if (FreeImage_FIFSupportsReading(fif))
{
dib = FreeImage_Load(fif, fTexture);
dib = FreeImage_ConvertTo32Bits(dib);
bits = FreeImage_GetBits(dib);
width = FreeImage_GetWidth(dib);
height = FreeImage_GetHeight(dib);
import_is_ok = GL_TRUE;
glBindTexture(GL_TEXTURE_2D, m_texture_id[tex_number]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, &bits[0]);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
FreeImage_Unload(dib);
}
return import_is_ok;
}
示例15: switch
/**
* Helper to encapsulate Bpp conversion using FreeImage, taking into consideration color type. Creates a new bitmap if needed. Can return the same one.
* @param pHandle FIBITMAP as defined by the Freeimage library.
* @param pNewBpp the new bpp that the supplied FIBITMAP is to be coverted to.
*/
FIBITMAP* FreeImageHelper::convertBpp(FIBITMAP* pHandle, int pNewBpp) {
//Convert the bit depth
FIBITMAP *converted = NULL;
//Convert Bpp only if needed
if (pNewBpp != static_cast<int>(FreeImage_GetBPP(pHandle))) {
//Transform bpp to the pixel format
switch (pNewBpp) {
case (4):
converted = FreeImage_ConvertTo4Bits(pHandle);
break;
case (8):
converted = FreeImage_ConvertTo8Bits(pHandle);
break;
case(16):
converted = FreeImage_ConvertTo16Bits565(pHandle); //There's option of 16Bits555. But leaves unused bits. Chosen 565 because it's most common
break;
case(24):
converted = FreeImage_ConvertTo24Bits(pHandle);
break;
case(32): {
converted = FreeImage_ConvertTo32Bits (pHandle);
}
break;
default:
converted = NULL;
break;
}
} else {
//No change, just set 'converted' handle to current one
converted = pHandle;
}
return converted;
}