本文整理汇总了C++中FreeImage_GetHeight函数的典型用法代码示例。如果您正苦于以下问题:C++ FreeImage_GetHeight函数的具体用法?C++ FreeImage_GetHeight怎么用?C++ FreeImage_GetHeight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FreeImage_GetHeight函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LoadTexture
unsigned int LoadTexture(const char* a_szTexture, unsigned int a_uiFormat /* =
GL_RGBA */, unsigned int* a_uiWidth /* = nullptr */, unsigned int* a_uiHeight /* =
nullptr */, unsigned int* a_uiBPP /* = nullptr*/)
{
FIBITMAP* pBitmap = nullptr;
// check the file signature and deduce its format and load it
FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(a_szTexture, 0);
if (fif != FIF_UNKNOWN && FreeImage_FIFSupportsReading(fif))
{
pBitmap = FreeImage_Load(fif, a_szTexture);
}
if (pBitmap == nullptr)
{
printf("Error: Failed to load image '%s'!\n", a_szTexture);
return 0;
}
// optionally get the image width and height
if (a_uiWidth != nullptr)
*a_uiWidth = FreeImage_GetWidth(pBitmap);
if (a_uiHeight != nullptr)
*a_uiHeight = FreeImage_GetHeight(pBitmap);
// force the image to RGBA
unsigned int bpp = FreeImage_GetBPP(pBitmap);
if( a_uiBPP != nullptr )
*a_uiBPP = bpp/8;
FREE_IMAGE_COLOR_TYPE fi_colourType = FreeImage_GetColorType(pBitmap);
if (fi_colourType != FIC_RGBALPHA )
{
FIBITMAP* ndib = FreeImage_ConvertTo32Bits(pBitmap);
FreeImage_Unload(pBitmap);
pBitmap = ndib;
bpp = FreeImage_GetBPP(pBitmap);
fi_colourType = FreeImage_GetColorType(pBitmap);
}
// get the pixel data
BYTE* pData = FreeImage_GetBits(pBitmap);
// try to determine data type of file (bytes/floats)
FREE_IMAGE_TYPE fit = FreeImage_GetImageType(pBitmap);
GLenum eType = (fit == FIT_RGBF || fit == FIT_FLOAT) ?
GL_FLOAT:GL_UNSIGNED_BYTE;
// create GL texture
GLuint textureID;
glGenTextures( 1, &textureID );
glBindTexture( GL_TEXTURE_2D, textureID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
FreeImage_GetWidth(pBitmap),
FreeImage_GetHeight(pBitmap), 0,
a_uiFormat, eType, pData);
//CREATING A GL BUFFER
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer( GL_Array_Buffer, VBO);
// specify default filtering and wrapping
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
// unbind texture
glBindTexture( GL_TEXTURE_2D, 0 );
// delete data
FreeImage_Unload(pBitmap);
//DELETING THE GL BUFFER MADE ABOVE
glDeleteBuffers(1, &VBO);
return textureID;
}
开发者ID:Vinessa,项目名称:VinessaAIEProgramming,代码行数:77,代码来源:Main.cpp
示例2: EncodeImage
/**
Encode a FIBITMAP to a WebP image
@param hmem Memory output stream, containing on return the encoded image
@param dib The FIBITMAP to encode
@param flags FreeImage save flags
@return Returns TRUE if successfull, returns FALSE otherwise
*/
static BOOL
EncodeImage(FIMEMORY *hmem, FIBITMAP *dib, int flags) {
WebPPicture picture; // Input buffer
WebPConfig config; // Coding parameters
BOOL bIsFlipped = FALSE;
try {
const unsigned width = FreeImage_GetWidth(dib);
const unsigned height = FreeImage_GetHeight(dib);
const unsigned bpp = FreeImage_GetBPP(dib);
const unsigned pitch = FreeImage_GetPitch(dib);
// check image type
FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
if( !((image_type == FIT_BITMAP) && ((bpp == 24) || (bpp == 32))) ) {
throw FI_MSG_ERROR_UNSUPPORTED_FORMAT;
}
// check format limits
if(MAX(width, height) > WEBP_MAX_DIMENSION) {
FreeImage_OutputMessageProc(s_format_id, "Unsupported image size: width x height = %d x %d", width, height);
return FALSE;
}
// Initialize output I/O
if(WebPPictureInit(&picture) == 1) {
picture.writer = WebP_MemoryWriter;
picture.custom_ptr = hmem;
picture.width = (int)width;
picture.height = (int)height;
} else {
throw "Couldn't initialize WebPPicture";
}
// --- Set encoding parameters ---
// Initialize encoding parameters to default values
WebPConfigInit(&config);
// quality/speed trade-off (0=fast, 6=slower-better)
config.method = 6;
if((flags & WEBP_LOSSLESS) == WEBP_LOSSLESS) {
// lossless encoding
config.lossless = 1;
picture.use_argb = 1;
} else if((flags & 0x7F) > 0) {
// lossy encoding
config.lossless = 0;
// quality is between 1 (smallest file) and 100 (biggest) - default to 75
config.quality = (float)(flags & 0x7F);
if(config.quality > 100) {
config.quality = 100;
}
}
// validate encoding parameters
if(WebPValidateConfig(&config) == 0) {
throw "Failed to initialize encoder";
}
// --- Perform encoding ---
// Invert dib scanlines
bIsFlipped = FreeImage_FlipVertical(dib);
// convert dib buffer to output stream
const BYTE *bits = FreeImage_GetBits(dib);
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
switch(bpp) {
case 24:
WebPPictureImportBGR(&picture, bits, pitch);
break;
case 32:
WebPPictureImportBGRA(&picture, bits, pitch);
break;
}
#else
switch(bpp) {
case 24:
WebPPictureImportRGB(&picture, bits, pitch);
break;
case 32:
WebPPictureImportRGBA(&picture, bits, pitch);
break;
}
#endif // FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
//.........这里部分代码省略.........
开发者ID:Antranilan,项目名称:Sparky,代码行数:101,代码来源:PluginWebP.cpp
示例3: FreeImage_Load
void Engine::TextureCube::loadFromFiles(
const CHAR *posx, const CHAR *negx,
const CHAR *posy, const CHAR *negy,
const CHAR *posz, const CHAR *negz)
{
UINT i;
FIBITMAP *image[6];
FIBITMAP *tmp;
ID3D11Texture2D *texture;
const CHAR *tex[] = { posx, negx, negy, posy, posz, negz };
image[0] = FreeImage_Load(FreeImage_GetFileType(tex[0]), tex[0]);
image[1] = FreeImage_Load(FreeImage_GetFileType(tex[1]), tex[1]);
image[2] = FreeImage_Load(FreeImage_GetFileType(tex[2]), tex[2]);
image[3] = FreeImage_Load(FreeImage_GetFileType(tex[3]), tex[3]);
image[4] = FreeImage_Load(FreeImage_GetFileType(tex[4]), tex[4]);
image[5] = FreeImage_Load(FreeImage_GetFileType(tex[5]), tex[5]);
if (_pShaderResourceView) _pShaderResourceView->Release();
if (_pSamplerState) _pSamplerState->Release();
D3D11_TEXTURE2D_DESC descTexture;
descTexture.Width = FreeImage_GetWidth(image[0]);
descTexture.Height = FreeImage_GetHeight(image[0]);
descTexture.MipLevels = 1;
descTexture.ArraySize = 6;
descTexture.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
descTexture.SampleDesc.Count = 1;
descTexture.SampleDesc.Quality = 0;
descTexture.Usage = D3D11_USAGE_IMMUTABLE;
descTexture.BindFlags = D3D11_BIND_SHADER_RESOURCE;
descTexture.CPUAccessFlags = 0;
descTexture.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
D3D11_SUBRESOURCE_DATA data[6];
for (i = 0; i < 6; i++)
{
if (image[i] == NULL)
{
std::string text = "Error while loading image: ";
text.append(tex[i]);
MessageBoxA(NULL, text.c_str(), __FILE__, MB_OK);
exit(1);
}
tmp = image[i];
image[i] = FreeImage_ConvertTo32Bits(image[i]);
FreeImage_Unload(tmp);
data[i].pSysMem = FreeImage_GetBits(image[i]);
data[i].SysMemPitch = 4 * descTexture.Width;
data[i].SysMemSlicePitch = 0;
}
Device->CreateTexture2D(&descTexture, data, &texture);
D3D11_SHADER_RESOURCE_VIEW_DESC descShaderResourceView;
descShaderResourceView.Format = descTexture.Format;
descShaderResourceView.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
descShaderResourceView.TextureCube.MostDetailedMip = 0;
descShaderResourceView.TextureCube.MipLevels = descTexture.MipLevels;
Device->CreateShaderResourceView(texture, &descShaderResourceView, &_pShaderResourceView);
D3D11_SAMPLER_DESC descSampler;
descSampler.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
descSampler.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
descSampler.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
descSampler.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
descSampler.ComparisonFunc = D3D11_COMPARISON_NEVER;
descSampler.MipLODBias = 0.0f;
descSampler.MaxAnisotropy = 1;
descSampler.BorderColor[0] = 0.0f;
descSampler.BorderColor[1] = 0.0f;
descSampler.BorderColor[2] = 0.0f;
descSampler.BorderColor[3] = 0.0f;
descSampler.MinLOD = 0;
descSampler.MaxLOD = D3D11_FLOAT32_MAX;
Device->CreateSamplerState(&descSampler, &_pSamplerState);
texture->Release();
}
开发者ID:CCJY,项目名称:Engine-DX11-,代码行数:80,代码来源:TextureCube.cpp
示例4: FreeImage_SetOutputMessage
//---------------------------------------------------------------------
Codec::DecodeResult FreeImageCodec::decode(DataStreamPtr& input) const
{
// Set error handler
FreeImage_SetOutputMessage(FreeImageLoadErrorHandler);
// Buffer stream into memory (TODO: override IO functions instead?)
MemoryDataStream memStream(input, true);
FIMEMORY* fiMem =
FreeImage_OpenMemory(memStream.getPtr(), static_cast<DWORD>(memStream.size()));
FIBITMAP* fiBitmap = FreeImage_LoadFromMemory(
(FREE_IMAGE_FORMAT)mFreeImageType, fiMem);
if (!fiBitmap)
{
OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
"Error decoding image",
"FreeImageCodec::decode");
}
ImageData* imgData = OGRE_NEW ImageData();
MemoryDataStreamPtr output;
imgData->depth = 1; // only 2D formats handled by this codec
imgData->width = FreeImage_GetWidth(fiBitmap);
imgData->height = FreeImage_GetHeight(fiBitmap);
imgData->num_mipmaps = 0; // no mipmaps in non-DDS
imgData->flags = 0;
// Must derive format first, this may perform conversions
FREE_IMAGE_TYPE imageType = FreeImage_GetImageType(fiBitmap);
FREE_IMAGE_COLOR_TYPE colourType = FreeImage_GetColorType(fiBitmap);
unsigned bpp = FreeImage_GetBPP(fiBitmap);
switch(imageType)
{
case FIT_UNKNOWN:
case FIT_COMPLEX:
case FIT_UINT32:
case FIT_INT32:
case FIT_DOUBLE:
default:
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Unknown or unsupported image format",
"FreeImageCodec::decode");
break;
case FIT_BITMAP:
// Standard image type
// Perform any colour conversions for greyscale
if (colourType == FIC_MINISWHITE || colourType == FIC_MINISBLACK)
{
FIBITMAP* newBitmap = FreeImage_ConvertToGreyscale(fiBitmap);
// free old bitmap and replace
FreeImage_Unload(fiBitmap);
fiBitmap = newBitmap;
// get new formats
bpp = FreeImage_GetBPP(fiBitmap);
colourType = FreeImage_GetColorType(fiBitmap);
}
// Perform any colour conversions for RGB
else if (bpp < 8 || colourType == FIC_PALETTE || colourType == FIC_CMYK)
{
FIBITMAP* newBitmap = FreeImage_ConvertTo24Bits(fiBitmap);
// free old bitmap and replace
FreeImage_Unload(fiBitmap);
fiBitmap = newBitmap;
// get new formats
bpp = FreeImage_GetBPP(fiBitmap);
colourType = FreeImage_GetColorType(fiBitmap);
}
// by this stage, 8-bit is greyscale, 16/24/32 bit are RGB[A]
switch(bpp)
{
case 8:
imgData->format = PF_L8;
break;
case 16:
// Determine 555 or 565 from green mask
// cannot be 16-bit greyscale since that's FIT_UINT16
if(FreeImage_GetGreenMask(fiBitmap) == FI16_565_GREEN_MASK)
{
imgData->format = PF_R5G6B5;
}
else
{
// FreeImage doesn't support 4444 format so must be 1555
imgData->format = PF_A1R5G5B5;
}
break;
case 24:
// FreeImage differs per platform
// PF_BYTE_BGR[A] for little endian (== PF_ARGB native)
// PF_BYTE_RGB[A] for big endian (== PF_RGBA native)
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB
imgData->format = PF_BYTE_RGB;
//.........这里部分代码省略.........
开发者ID:akadjoker,项目名称:gmogre3d,代码行数:101,代码来源:OgreFreeImageCodec.cpp
示例5: loadTexture
Int32 loadTexture(Texture *out_texture, const char *fileAddress)
{
__BLITZ_ASSERT(out_texture);
__BLITZ_ASSERT(fileAddress);
auto existingTexture = textureList.find(std::string(fileAddress));
if (existingTexture != textureList.end())
{
*out_texture = existingTexture->second;
return 0;
}
FREE_IMAGE_FORMAT freeImageFormat;
freeImageFormat = FreeImage_GetFileType(fileAddress, 0);
if (freeImageFormat == FIF_UNKNOWN)
{
freeImageFormat = FreeImage_GetFIFFromFilename(fileAddress);
}
if (freeImageFormat == FIF_UNKNOWN)
{
__BLITZ_THROW_ERROR("Failed to load image \"" +
std::string(fileAddress) + "\" : Image format is not supported.");
return 1;
}
Bool loadAlphaChannel = 0;
switch (freeImageFormat)
{
case FIF_BMP:
case FIF_GIF:
case FIF_JPEG:
loadAlphaChannel = 0;
break;
case FIF_DDS:
case FIF_PNG:
case FIF_TARGA:
loadAlphaChannel = 1;
break;
}
if (FreeImage_FIFSupportsReading(freeImageFormat) == 0)
{
__BLITZ_THROW_ERROR("Failed to load image \"" +
std::string(fileAddress) +
"\" : Reading from this image format is not supported.");
return 1;
}
FIBITMAP *freeImageBitmap = FreeImage_Load(freeImageFormat, fileAddress, 0);
if (freeImageBitmap == 0)
{
__BLITZ_THROW_ERROR("Failed to load image \"" +
std::string(fileAddress) + "\" : Failed to load image file.");
return 1;
}
BYTE *imageData = FreeImage_GetBits(freeImageBitmap);
if (imageData == 0)
{
__BLITZ_THROW_ERROR("Failed to load image \"" +
std::string(fileAddress) + "\" : Failed to get image data.");
return 1;
}
Int32 imageWidth = FreeImage_GetWidth(freeImageBitmap),
imageHeight = FreeImage_GetHeight(freeImageBitmap);
if (imageWidth <= 0 || imageHeight <= 0)
{
__BLITZ_THROW_ERROR("Failed to load image \"" +
std::string(fileAddress) + "\" : Image dimensions are invalid.");
return 1;
}
glGenTextures(1, out_texture);
glBindTexture(GL_TEXTURE_2D, *out_texture);
GLint imageFormat = loadAlphaChannel ? GL_BGRA : GL_BGR;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, imageWidth, imageHeight, 0,
imageFormat, GL_UNSIGNED_BYTE, imageData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D, 0);
FreeImage_Unload(freeImageBitmap);
std::pair<std::string, Texture> newPair =
std::pair<std::string, Texture>(fileAddress, *out_texture);
textureList.insert(newPair);
blitz::__debug::throwMessage("Image \"" + std::string(fileAddress) +
"\" loaded.");
return 0;
}
开发者ID:SahandMalaei,项目名称:Blitz,代码行数:83,代码来源:Blitz_Graphics.cpp
示例6: FreeImage_OpenMemory
Texture* FreeImageImageCodec::load(const RawDataContainer& data, Texture* result)
{
int len = (int)data.getSize();
FIMEMORY *mem = 0;
FIBITMAP *img = 0;
Texture *retval = 0;
try
{
mem = FreeImage_OpenMemory(static_cast<BYTE*>(const_cast<std::uint8_t*>(data.getDataPtr())), len);
if (mem == 0)
throw MemoryException("Unable to open memory stream, FreeImage_OpenMemory failed");
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(mem, len);
if (fif == FIF_UNKNOWN) // it may be that it's TARGA or MNG
{
fif = FIF_TARGA;
img = FreeImage_LoadFromMemory(fif, mem, 0);
if (img == 0)
{
fif = FIF_MNG;
img = FreeImage_LoadFromMemory(fif, mem, 0);
}
}
else
img = FreeImage_LoadFromMemory(fif, mem, 0);
if (img == 0)
throw GenericException("Unable to load image, FreeImage_LoadFromMemory failed");
FIBITMAP *newImg = FreeImage_ConvertTo32Bits(img);
if (newImg == 0)
throw GenericException("Unable to convert image, FreeImage_ConvertTo32Bits failed");
FreeImage_Unload(img);
img = newImg;
newImg = 0;
// FreeImage pixel format for little-endian architecture (which CEGUI
// supports) is like BGRA. We need to convert that to RGBA.
//
// It is now:
// RED_MASK 0x00FF0000
// GREEN_MASK 0x0000FF00
// BLUE_MASK 0x000000FF
// ALPHA_MASK 0xFF000000
//
// It should be:
// RED_MASK 0x000000FF
// GREEN_MASK 0x0000FF00
// BLUE_MASK 0x00FF0000
// ALPHA_MASK 0xFF000000
unsigned int pitch = FreeImage_GetPitch(img);
unsigned int height = FreeImage_GetHeight(img);
unsigned int width = FreeImage_GetWidth(img);
std::uint8_t *rawBuf = new std::uint8_t[width * height << 2];
// convert the bitmap to raw bits (top-left pixel first)
FreeImage_ConvertToRawBits(rawBuf, img, pitch, 32,
FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true);
// We need to convert pixel format a little
// NB: little endian only - I think(!)
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
for (unsigned int i = 0; i < height; ++i)
{
for (unsigned int j = 0; j < width; ++j)
{
unsigned int p = *(((unsigned int*)(rawBuf + i * pitch)) + j);
unsigned int r = (p >> 16) & 0x000000FF;
unsigned int b = (p << 16) & 0x00FF0000;
p &= 0xFF00FF00;
p |= r | b;
// write the adjusted pixel back
*(((unsigned int*)(rawBuf + i * pitch)) + j) = p;
}
}
#endif
FreeImage_Unload(img);
img = 0;
result->loadFromMemory(rawBuf, Sizef(width, height), Texture::PF_RGBA);
delete [] rawBuf;
retval = result;
}
catch (Exception&)
{
}
if (img != 0) FreeImage_Unload(img);
if (mem != 0) FreeImage_CloseMemory(mem);
return retval;
}
开发者ID:arkana-fts,项目名称:cegui,代码行数:96,代码来源:ImageCodec.cpp
示例7: block_usr1_signal
static void *bg_new_img(void *data)
{
/* so we can poll for it */
block_usr1_signal();
struct imv_loader *ldr = data;
char path[PATH_MAX] = "-";
pthread_mutex_lock(&ldr->lock);
int from_stdin = !strncmp(path, ldr->path, 2);
if(!from_stdin) {
(void)snprintf(path, PATH_MAX, "%s", ldr->path);
}
pthread_mutex_unlock(&ldr->lock);
FREE_IMAGE_FORMAT fmt;
if (from_stdin) {
pthread_mutex_lock(&ldr->lock);
ldr->fi_buffer = FreeImage_OpenMemory(ldr->buffer, ldr->buffer_size);
fmt = FreeImage_GetFileTypeFromMemory(ldr->fi_buffer, 0);
pthread_mutex_unlock(&ldr->lock);
} else {
fmt = FreeImage_GetFileType(path, 0);
}
if(fmt == FIF_UNKNOWN) {
if (from_stdin) {
pthread_mutex_lock(&ldr->lock);
FreeImage_CloseMemory(ldr->fi_buffer);
pthread_mutex_unlock(&ldr->lock);
}
error_occurred(ldr);
return NULL;
}
int num_frames = 1;
FIMULTIBITMAP *mbmp = NULL;
FIBITMAP *bmp = NULL;
int width, height;
int raw_frame_time = 100; /* default to 100 */
if(fmt == FIF_GIF) {
if(from_stdin) {
pthread_mutex_lock(&ldr->lock);
mbmp = FreeImage_LoadMultiBitmapFromMemory(FIF_GIF, ldr->fi_buffer,
GIF_LOAD256);
pthread_mutex_unlock(&ldr->lock);
} else {
mbmp = FreeImage_OpenMultiBitmap(FIF_GIF, path,
/* don't create file */ 0,
/* read only */ 1,
/* keep in memory */ 1,
/* flags */ GIF_LOAD256);
}
if(!mbmp) {
error_occurred(ldr);
return NULL;
}
num_frames = FreeImage_GetPageCount(mbmp);
FIBITMAP *frame = FreeImage_LockPage(mbmp, 0);
width = FreeImage_GetWidth(frame);
height = FreeImage_GetHeight(frame);
bmp = FreeImage_ConvertTo32Bits(frame);
/* get duration of first frame */
FITAG *tag = NULL;
FreeImage_GetMetadata(FIMD_ANIMATION, frame, "FrameTime", &tag);
if(FreeImage_GetTagValue(tag)) {
raw_frame_time = *(int*)FreeImage_GetTagValue(tag);
}
FreeImage_UnlockPage(mbmp, frame, 0);
} else {
/* Future TODO: If we load image line-by-line we could stop loading large
* ones before wasting much more time/memory on them. */
int flags = (fmt == FIF_JPEG) ? JPEG_EXIFROTATE : 0;
FIBITMAP *image;
if(from_stdin) {
pthread_mutex_lock(&ldr->lock);
image = FreeImage_LoadFromMemory(fmt, ldr->fi_buffer, flags);
pthread_mutex_unlock(&ldr->lock);
} else {
image = FreeImage_Load(fmt, path, flags);
}
if(!image) {
error_occurred(ldr);
pthread_mutex_lock(&ldr->lock);
FreeImage_CloseMemory(ldr->fi_buffer);
ldr->fi_buffer = NULL;
pthread_mutex_unlock(&ldr->lock);
return NULL;
}
/* Check for cancellation before we convert pixel format */
if(is_thread_cancelled()) {
FreeImage_Unload(image);
return NULL;
}
//.........这里部分代码省略.........
开发者ID:eXeC64,项目名称:imv,代码行数:101,代码来源:loader.c
示例8: printf
bool Texture::loadTexture(const char* path, bool generateMipMaps, bool defaultParameters)
{
printf("Reading image %s\n", path);
FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
FIBITMAP* dib(0);
format = FreeImage_GetFileType(path, 0); // Check the file signature and deduce its format
if (format == FIF_UNKNOWN) // If still unknown, try to guess the file format from the file extension
format = FreeImage_GetFIFFromFilename(path);
if (format == FIF_UNKNOWN) // If still unkown, return failure
{
printf("Failure(1)\n");
return false;
}
// Check if the plugin has reading capabilities and load the file
if (FreeImage_FIFSupportsReading(format))
dib = FreeImage_Load(format, path);
if (!dib)
{
printf("Failure(2)\n");
return false;
}
BYTE* dataPointer = FreeImage_GetBits(dib); // Retrieve image data
int width = FreeImage_GetWidth(dib); // Get the image width and height
int height = FreeImage_GetHeight(dib);
int BPP = FreeImage_GetBPP(dib); // bytes per pixel
// If somehow one of these failed (they shouldn't), return failure
if (dataPointer == NULL || width == 0 || height == 0)
{
printf("Failure(3)\n");
return false;
}
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
int texFormat = BPP == 24 ? GL_BGR : BPP == 8 ? GL_LUMINANCE : 0;
//int internalFormat = BPP == 24 ? GL_RGB : GL_DEPTH_COMPONENT;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, texFormat, GL_UNSIGNED_BYTE, dataPointer);
FreeImage_Unload(dib);
if (defaultParameters)
{
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_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
if (generateMipMaps)
{
glGenerateMipmap(GL_TEXTURE_2D);
mipMapsGenerated = generateMipMaps;
}
return true;
}
开发者ID:Okonos,项目名称:ProjektNaGrafike,代码行数:65,代码来源:Texture.cpp
示例9: FreeImage_GetDIBSize
unsigned DLL_CALLCONV
FreeImage_GetDIBSize(FIBITMAP *dib) {
return (dib) ? sizeof(BITMAPINFOHEADER) + (FreeImage_GetColorsUsed(dib) * sizeof(RGBQUAD)) + (FreeImage_GetPitch(dib) * FreeImage_GetHeight(dib)) : 0;
}
开发者ID:2php,项目名称:ogre-android,代码行数:4,代码来源:BitmapAccess.cpp
示例10: FreeImage_ConvertToUINT16
FIBITMAP * DLL_CALLCONV
FreeImage_ConvertToUINT16(FIBITMAP *dib) {
FIBITMAP *src = NULL;
FIBITMAP *dst = NULL;
if(!FreeImage_HasPixels(dib)) return NULL;
const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
// check for allowed conversions
switch(src_type) {
case FIT_BITMAP:
{
// convert to greyscale if needed
if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) {
src = dib;
} else {
src = FreeImage_ConvertToGreyscale(dib);
if(!src) return NULL;
}
break;
}
case FIT_UINT16:
// UINT16 type : clone the src
return FreeImage_Clone(dib);
break;
case FIT_RGB16:
// allow conversion from 48-bit RGB
src = dib;
break;
case FIT_RGBA16:
// allow conversion from 64-bit RGBA (ignore the alpha channel)
src = dib;
break;
default:
return NULL;
}
// allocate dst image
const unsigned width = FreeImage_GetWidth(src);
const unsigned height = FreeImage_GetHeight(src);
dst = FreeImage_AllocateT(FIT_UINT16, width, height);
if(!dst) return NULL;
// copy metadata from src to dst
FreeImage_CloneMetadata(dst, src);
// convert from src type to UINT16
switch(src_type) {
case FIT_BITMAP:
{
for(unsigned y = 0; y < height; y++) {
const BYTE *src_bits = (BYTE*)FreeImage_GetScanLine(src, y);
WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y);
for(unsigned x = 0; x < width; x++) {
dst_bits[x] = src_bits[x] << 8;
}
}
}
break;
case FIT_RGB16:
{
for(unsigned y = 0; y < height; y++) {
const FIRGB16 *src_bits = (FIRGB16*)FreeImage_GetScanLine(src, y);
WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y);
for(unsigned x = 0; x < width; x++) {
// convert to grey
dst_bits[x] = (WORD)LUMA_REC709(src_bits[x].red, src_bits[x].green, src_bits[x].blue);
}
}
}
break;
case FIT_RGBA16:
{
for(unsigned y = 0; y < height; y++) {
const FIRGBA16 *src_bits = (FIRGBA16*)FreeImage_GetScanLine(src, y);
WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y);
for(unsigned x = 0; x < width; x++) {
// convert to grey
dst_bits[x] = (WORD)LUMA_REC709(src_bits[x].red, src_bits[x].green, src_bits[x].blue);
}
}
}
break;
default:
break;
}
if(src != dib) {
FreeImage_Unload(src);
}
return dst;
}
开发者ID:louisfeng,项目名称:FreeImage,代码行数:100,代码来源:ConversionUINT16.cpp
示例11: FreeImage_GetColorType
FREE_IMAGE_COLOR_TYPE DLL_CALLCONV
FreeImage_GetColorType(FIBITMAP *dib) {
RGBQUAD *rgb;
const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
// special bitmap type
if(image_type != FIT_BITMAP) {
switch(image_type) {
case FIT_RGB16:
case FIT_RGBF:
return FIC_RGB;
case FIT_RGBA16:
case FIT_RGBAF:
return FIC_RGBALPHA;
}
return FIC_MINISBLACK;
}
// standard image type
switch (FreeImage_GetBPP(dib)) {
case 1:
{
rgb = FreeImage_GetPalette(dib);
if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) && (rgb->rgbBlue == 0)) {
rgb++;
if ((rgb->rgbRed == 255) && (rgb->rgbGreen == 255) && (rgb->rgbBlue == 255))
return FIC_MINISBLACK;
}
if ((rgb->rgbRed == 255) && (rgb->rgbGreen == 255) && (rgb->rgbBlue == 255)) {
rgb++;
if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) && (rgb->rgbBlue == 0))
return FIC_MINISWHITE;
}
return FIC_PALETTE;
}
case 4:
case 8: // Check if the DIB has a color or a greyscale palette
{
int ncolors = FreeImage_GetColorsUsed(dib);
int minisblack = 1;
rgb = FreeImage_GetPalette(dib);
for (int i = 0; i < ncolors; i++) {
if ((rgb->rgbRed != rgb->rgbGreen) || (rgb->rgbRed != rgb->rgbBlue))
return FIC_PALETTE;
// The DIB has a color palette if the greyscale isn't a linear ramp
// Take care of reversed grey images
if (rgb->rgbRed != i) {
if ((ncolors-i-1) != rgb->rgbRed)
return FIC_PALETTE;
else
minisblack = 0;
}
rgb++;
}
return minisblack ? FIC_MINISBLACK : FIC_MINISWHITE;
}
case 16:
case 24:
return FIC_RGB;
case 32:
{
if (FreeImage_GetICCProfile(dib)->flags & FIICC_COLOR_IS_CMYK)
return FIC_CMYK;
for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) {
rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y);
for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++)
if (rgb[x].rgbReserved != 0xFF)
return FIC_RGBALPHA;
}
return FIC_RGB;
}
default :
return FIC_MINISBLACK;
}
}
开发者ID:2php,项目名称:ogre-android,代码行数:93,代码来源:BitmapAccess.cpp
示例12: FreeImage_Clone
FIBITMAP * DLL_CALLCONV
FreeImage_Clone(FIBITMAP *dib) {
if(!dib) return NULL;
unsigned width = FreeImage_GetWidth(dib);
unsigned height = FreeImage_GetHeight(dib);
unsigned bpp = FreeImage_GetBPP(dib);
// check for pixel availability ...
BOOL header_only = FreeImage_HasPixels(dib) ? FALSE : TRUE;
// allocate a new dib
FIBITMAP *new_dib = FreeImage_AllocateHeaderT(header_only, FreeImage_GetImageType(dib), width, height, bpp,
FreeImage_GetRedMask(dib), FreeImage_GetGreenMask(dib), FreeImage_GetBlueMask(dib));
if (new_dib) {
// save ICC profile links
FIICCPROFILE *src_iccProfile = FreeImage_GetICCProfile(dib);
FIICCPROFILE *dst_iccProfile = FreeImage_GetICCProfile(new_dib);
// save metadata links
METADATAMAP *src_metadata = ((FREEIMAGEHEADER *)dib->data)->metadata;
METADATAMAP *dst_metadata = ((FREEIMAGEHEADER *)new_dib->data)->metadata;
// calculate the size of a FreeImage image
// align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary
// palette is aligned on a 16 bytes boundary
// pixels are aligned on a 16 bytes boundary
size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp);
// copy the bitmap + internal pointers (remember to restore new_dib internal pointers later)
memcpy(new_dib->data, dib->data, dib_size);
// reset ICC profile link for new_dib
memset(dst_iccProfile, 0, sizeof(FIICCPROFILE));
// restore metadata link for new_dib
((FREEIMAGEHEADER *)new_dib->data)->metadata = dst_metadata;
// reset thumbnail link for new_dib
((FREEIMAGEHEADER *)new_dib->data)->thumbnail = NULL;
// copy possible ICC profile
FreeImage_CreateICCProfile(new_dib, src_iccProfile->data, src_iccProfile->size);
dst_iccProfile->flags = src_iccProfile->flags;
// copy metadata models
for(METADATAMAP::iterator i = (*src_metadata).begin(); i != (*src_metadata).end(); i++) {
int model = (*i).first;
TAGMAP *src_tagmap = (*i).second;
if(src_tagmap) {
// create a metadata model
TAGMAP *dst_tagmap = new(std::nothrow) TAGMAP();
if(dst_tagmap) {
// fill the model
for(TAGMAP::iterator j = src_tagmap->begin(); j != src_tagmap->end(); j++) {
std::string dst_key = (*j).first;
FITAG *dst_tag = FreeImage_CloneTag( (*j).second );
// assign key and tag value
(*dst_tagmap)[dst_key] = dst_tag;
}
// assign model and tagmap
(*dst_metadata)[model] = dst_tagmap;
}
}
}
// copy the thumbnail
FreeImage_SetThumbnail(new_dib, FreeImage_GetThumbnail(dib));
return new_dib;
}
return NULL;
}
开发者ID:2php,项目名称:ogre-android,代码行数:80,代码来源:BitmapAccess.cpp
示例13: main
//.........这里部分代码省略.........
if (dot != std::string::npos)
{
sResultFilename = sResultFilename.substr(0, dot);
}
sResultFilename += "_boxFilterFII.pgm";
if (argc >= 3)
{
sResultFilename = argv[2];
}
FREE_IMAGE_FORMAT eFormat = FreeImage_GetFileType(sFilename.c_str());
// no signature? try to guess the file format from the file extension
if (eFormat == FIF_UNKNOWN)
{
eFormat = FreeImage_GetFIFFromFilename(sFilename.c_str());
}
NPP_ASSERT(eFormat != FIF_UNKNOWN);
// check that the plugin has reading capabilities ...
FIBITMAP *pBitmap;
if (FreeImage_FIFSupportsReading(eFormat))
{
pBitmap = FreeImage_Load(eFormat, sFilename.c_str());
}
NPP_ASSERT(pBitmap != 0);
// Dump the bitmap information to the console
std::cout << (*pBitmap) << std::endl;
// make sure this is an 8-bit single channel image
NPP_ASSERT(FreeImage_GetColorType(pBitmap) == FIC_MINISBLACK);
NPP_ASSERT(FreeImage_GetBPP(pBitmap) == 8);
unsigned int nImageWidth = FreeImage_GetWidth(pBitmap);
unsigned int nImageHeight = FreeImage_GetHeight(pBitmap);
unsigned int nSrcPitch = FreeImage_GetPitch(pBitmap);
unsigned char *pSrcData = FreeImage_GetBits(pBitmap);
int nSrcPitchCUDA;
Npp8u *pSrcImageCUDA = nppiMalloc_8u_C1(nImageWidth, nImageHeight, &nSrcPitchCUDA);
NPP_ASSERT_NOT_NULL(pSrcImageCUDA);
// copy image loaded via FreeImage to into CUDA device memory, i.e.
// transfer the image-data up to the GPU's video-memory
NPP_CHECK_CUDA(cudaMemcpy2D(pSrcImageCUDA, nSrcPitchCUDA, pSrcData, nSrcPitch,
nImageWidth, nImageHeight, cudaMemcpyHostToDevice));
// define size of the box filter
const NppiSize oMaskSize = {7, 7};
const NppiPoint oMaskAchnor = {0, 0};
// compute maximal result image size
const NppiSize oSizeROI = {nImageWidth - (oMaskSize.width - 1),
nImageHeight - (oMaskSize.height - 1)
};
// allocate result image memory
int nDstPitchCUDA;
Npp8u *pDstImageCUDA = nppiMalloc_8u_C1(oSizeROI.width, oSizeROI.height, &nDstPitchCUDA);
NPP_ASSERT_NOT_NULL(pDstImageCUDA);
NPP_CHECK_NPP(nppiFilterBox_8u_C1R(pSrcImageCUDA, nSrcPitchCUDA, pDstImageCUDA, nDstPitchCUDA,
oSizeROI, oMaskSize, oMaskAchnor));
// create the result image storage using FreeImage so we can easily
// save
FIBITMAP *pResultBitmap = FreeImage_Allocate(oSizeROI.width, oSizeROI.height, 8 /* bits per pixel */);
NPP_ASSERT_NOT_NULL(pResultBitmap);
unsigned int nResultPitch = FreeImage_GetPitch(pResultBitmap);
unsigned char *pResultData = FreeImage_GetBits(pResultBitmap);
NPP_CHECK_CUDA(cudaMemcpy2D(pResultData, nResultPitch, pDstImageCUDA, nDstPitchCUDA,
oSizeROI.width, oSizeROI.height, cudaMemcpyDeviceToHost));
// now save the result image
bool bSuccess;
bSuccess = FreeImage_Save(FIF_PGM, pResultBitmap, sResultFilename.c_str(), 0) == TRUE;
NPP_ASSERT_MSG(bSuccess, "Failed to save result image.");
//free nppiImage
nppiFree(pSrcImageCUDA);
nppiFree(pDstImageCUDA);
cudaDeviceReset();
exit(EXIT_SUCCESS);
}
catch (npp::Exception &rException)
{
std::cerr << "Program error! The following exception occurred: \n";
std::cerr << rException << std::endl;
std::cerr << "Aborting." << std::endl;
exit(EXIT_FAILURE);
}
catch (...)
{
std::cerr << "Program error! An unknow type of exception occurred. \n";
std::cerr << "Aborting." << std::endl;
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
开发者ID:chengli1986,项目名称:571e,代码行数:101,代码来源:freeImageInteropNPP.cpp
示例14: FreeImage_GetHeight
unsigned fipImage::getHeight() const {
return FreeImage_GetHeight(_dib);
}
开发者ID:EduardoFF,项目名称:argos2-RoboNetSim,代码行数:3,代码来源:fipImage.cpp
示例15: mymnggetcanvasline
mng_ptr
mymnggetcanvasline(mng_handle mng, mng_uint32 line) {
FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(mng))->bitmap;
return FreeImage_GetScanLine(bitmap, FreeImage_GetHeight(bitmap) - line - 1);
}
开发者ID:Bihlerben,项目名称:oce-win-bundle,代码行数:6,代码来源:_FI_3151_PluginMNG.cpp
示例16: getScanLine
BYTE* fipImage::getScanLine(unsigned scanline) const {
if(scanline < FreeImage_GetHeight(_dib)) {
return FreeImage_GetScanLine(_dib, scanline);
}
return NULL;
}
开发者ID:EduardoFF,项目名称:argos2-RoboNetSim,代码行数:6,代码来源:fipImage.cpp
示例17: load_image
void load_image(const char *fname) {
// active only for static linking
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif
FIBITMAP *bitmap;
// Get the format of the image file
FREE_IMAGE_FORMAT fif =FreeImage_GetFileType(fname, 0);
// If the format can't be determined, try to guess the format from the file name
if(fif == FIF_UNKNOWN) {
fif = FreeImage_GetFIFFromFilename(fname);
}
// Load the data in bitmap if possible
if(fif != FIF_UNKNOWN && FreeImage_FIFSupportsReading(fif)) {
bitmap = FreeImage_Load(fif, fname);
}
else {
bitmap = NULL;
}
// PROCESS IMAGE if bitmap was successfully initialized
if(bitmap) {
unsigned int w = FreeImage_GetWidth(bitmap);
unsigned int h = FreeImage_GetHeight(bitmap);
unsigned pixel_size = FreeImage_GetBPP(bitmap);
// Get a pointer to the pixel data
BYTE *data = (BYTE*)FreeImage_GetBits(bitmap);
// Process only RGB and RGBA images
if(pixel_size == 24) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, (GLvoid*)data);
}
else if (pixel_size == 32) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)data);
}
else {
std::cerr << "pixel size = " << pixel_size << " don't know how to process this case. I'm out!" << std::endl;
exit(-1);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else {
std::cerr << "Unable to load the image file " << fname << " I'm out!" << std::endl;
exit(-1);
}
// Clean bitmap;
FreeImage_Unload(bitmap);
// active only for static linking
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif
}
开发者ID:hustcalm,项目名称:OpenGL-101,代码行数:61,代码来源:ex_14.cpp
示例18: FreePictureData
//.........这里部分代码省略.........
}
else
{
delete [] lpIcons;
lpIcons = NULL;
}
}
}
}
else if (pBitmap) // Image loaded successfully with GDI+
{
m_Height = pBitmap->GetHeight();
m_Width = pBitmap->GetWidth();
bResult = true;
}
// If still failed to load the file...
if (!bResult)
{
// Attempt to load the FreeImage library as an optional DLL to support additional formats
// NOTE: Currently just loading via FreeImage & using GDI+ for drawing.
// It might be nice to remove this dependency in the future.
HMODULE hFreeImageLib = LoadLibrary(_T("FreeImage.dll"));
// FreeImage DLL functions
typedef const char* (__stdcall *FreeImage_GetVersion_t)(void);
typedef int (__stdcall *FreeImage_GetFileType_t)(const TCHAR *filename, int size);
typedef int (__stdcall *FreeImage_GetFIFFromFilename_t)(const TCHAR *filename);
typedef void* (__stdcall *FreeImage_Load_t)(int format, const TCHAR *filename, int flags);
typedef void (__stdcall *FreeImage_Unload_t)(void* dib);
typedef int (__stdcall *FreeImage_GetColorType_t)(void* dib);
typedef unsigned (__stdcall *FreeImage_GetWidth_t)(void* dib);
typedef unsigned (__stdcall *FreeImage_GetHeight_t)(void* dib);
typedef void (__stdcall *FreeImage_ConvertToRawBits_t)(BYTE *bits, void *dib, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown);
//FreeImage_GetVersion_t FreeImage_GetVersion = NULL;
FreeImage_GetFileType_t FreeImage_GetFileType = NULL;
FreeImage_GetFIFFromFilename_t FreeImage_GetFIFFromFilename = NULL;
FreeImage_Load_t FreeImage_Load = NULL;
FreeImage_Unload_t FreeImage_Unload = NULL;
//FreeImage_GetColorType_t FreeImage_GetColorType = NULL;
FreeImage_GetWidth_t FreeImage_GetWidth = NULL;
FreeImage_GetHeight_t FreeImage_GetHeight = NULL;
FreeImage_ConvertToRawBits_t FreeImage_ConvertToRawBits = NULL;
if (hFreeImageLib)
{
bool exportsValid = true;
//FreeImage_GetVersion = (FreeImage_GetVersion_t)s_GetProcAddressEx(hFreeImageLib, "[email protected]", valid);
FreeImage_GetWidth = (FreeImage_GetWidth_t)s_GetProcAddressEx(hFreeImageLib, "[email protected]", exportsValid);
FreeImage_GetHeight = (FreeImage_GetHeight_t)s_GetProcAddressEx(hFreeImageLib, "[email protected]", exportsValid);
FreeImage_Unload = (FreeImage_Unload_t)s_GetProcAddressEx(hFreeImageLib, "[email protect
|
请发表评论