本文整理汇总了C++中FreeImage_Unload函数的典型用法代码示例。如果您正苦于以下问题:C++ FreeImage_Unload函数的具体用法?C++ FreeImage_Unload怎么用?C++ FreeImage_Unload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FreeImage_Unload函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: defined
FIBITMAP *GraphicsHelps::loadImage(std::string file, bool convertTo32bit)
{
#ifdef DEBUG_BUILD
ElapsedTimer loadingTime;
ElapsedTimer fReadTime;
ElapsedTimer imgConvTime;
loadingTime.start();
fReadTime.start();
#endif
#if defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
FileMapper fileMap;
if(!fileMap.open_file(file.c_str()))
return NULL;
FIMEMORY *imgMEM = FreeImage_OpenMemory(reinterpret_cast<unsigned char *>(fileMap.data()),
static_cast<unsigned int>(fileMap.size()));
FREE_IMAGE_FORMAT formato = FreeImage_GetFileTypeFromMemory(imgMEM);
if(formato == FIF_UNKNOWN)
return NULL;
FIBITMAP *img = FreeImage_LoadFromMemory(formato, imgMEM, 0);
FreeImage_CloseMemory(imgMEM);
fileMap.close_file();
if(!img)
return NULL;
#else
FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(file.toUtf8().data(), 0);
if(formato == FIF_UNKNOWN)
return NULL;
FIBITMAP *img = FreeImage_Load(formato, file.toUtf8().data());
if(!img)
return NULL;
#endif
#ifdef DEBUG_BUILD
long long fReadTimeElapsed = static_cast<long long>(fReadTime.elapsed());
long long imgConvertElapsed = 0;
#endif
if(convertTo32bit)
{
#ifdef DEBUG_BUILD
imgConvTime.start();
#endif
FIBITMAP *temp;
temp = FreeImage_ConvertTo32Bits(img);
if(!temp)
return NULL;
FreeImage_Unload(img);
img = temp;
#ifdef DEBUG_BUILD
imgConvertElapsed = static_cast<long long>(imgConvTime.elapsed());
#endif
}
#ifdef DEBUG_BUILD
D_pLogDebug("File read of texture %s passed in %d milliseconds", file.c_str(), static_cast<int>(fReadTimeElapsed));
D_pLogDebug("Conv to 32-bit of %s passed in %d milliseconds", file.c_str(), static_cast<int>(imgConvertElapsed));
D_pLogDebug("Total Loading of image %s passed in %d milliseconds", file.c_str(), static_cast<int>(loadingTime.elapsed()));
#endif
return img;
}
开发者ID:jpmac26,项目名称:PGE-Project,代码行数:71,代码来源:graphics_funcs.cpp
示例2: liimg_png_load
int liimg_png_load (
const char* file,
int* result_width,
int* result_height,
void** result_pixels)
{
#ifdef HAVE_FREEIMAGE
size_t i;
size_t x;
size_t y;
size_t w;
size_t h;
uint8_t* pixels;
FIBITMAP* image;
RGBQUAD color;
/* Load the image. */
image = FreeImage_Load (FIF_PNG, file, PNG_DEFAULT);
if (image == NULL)
return 0;
/* Allocate pixel data. */
w = FreeImage_GetWidth (image);
h = FreeImage_GetHeight (image);
if (w > 0 && h > 0)
{
pixels = lisys_calloc (w * h * 4, 1);
if (pixels == NULL)
{
FreeImage_Unload (image);
return 0;
}
}
else
pixels = NULL;
/* Copy the pixel data. */
for (y = 0, i = 0 ; y < h ; y++)
{
for (x = 0 ; x < w ; x++, i++)
{
FreeImage_GetPixelColor (image, x, h - y - 1, &color);
pixels[4 * i + 0] = color.rgbRed;
pixels[4 * i + 1] = color.rgbGreen;
pixels[4 * i + 2] = color.rgbBlue;
if (FreeImage_GetBPP (image) == 32)
pixels[4 * i + 3] = color.rgbReserved;
else
pixels[4 * i + 3] = 0xFF;
}
}
/* Set the results. */
*result_width = w;
*result_height = h;
*result_pixels = pixels;
FreeImage_Unload (image);
return 1;
#else
int x;
int y;
int depth;
int width;
int height;
char* dst;
void* pixels;
FILE* fp;
png_bytepp rows;
png_infop info;
png_structp png;
/* Initialize structures. */
png = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png == NULL)
{
lisys_error_set (ENOMEM, NULL);
return 0;
}
info = png_create_info_struct (png);
if (info == NULL)
{
png_destroy_read_struct (&png, NULL, NULL);
lisys_error_set (ENOMEM, NULL);
return 0;
}
/* Open file. */
fp = fopen (file, "rb");
if (fp == NULL)
{
lisys_error_set (EIO, "cannot open file `%s'", file);
png_destroy_read_struct (&png, &info, NULL);
return 0;
}
/* Read data. */
if (setjmp (png_jmpbuf (png)))
{
lisys_error_set (EIO, "error while reading `%s'", file);
//.........这里部分代码省略.........
开发者ID:bsmr-games,项目名称:lipsofsuna,代码行数:101,代码来源:image-png.c
示例3: FreeImage_GetFIFFromFilename
bool Texture::saveImToFile(const std::string& filename, const uint8_t* im,
const uint32_t width, const uint32_t height, const bool save_flipped,
const uint32_t num_channels) {
freeimage_init_lock_.lock();
if (!freeimage_init_) {
freeimage_init_lock_.unlock();
throw std::wruntime_error("Texture::Texture() - ERROR: Please call "
"initTextureSystem() before loading textures from file!");
}
freeimage_init_lock_.unlock();
// NEW CODE USING THE FREEIMAGE LIBRARY
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; //image format
// if still unknown, try to guess the file format from the file extension
if (fif == FIF_UNKNOWN) {
fif = FreeImage_GetFIFFromFilename(filename.c_str());
}
// if still unkown, return failure
if (fif == FIF_UNKNOWN) {
throw wruntime_error(wstring(L"saveRGBToFile() - ERROR: Cannot deduce "
L"format of the filename: ") + string_util::ToWideString(filename));
}
if (!FreeImage_FIFSupportsWriting(fif)) {
throw std::wruntime_error("saveRGBToFile() - ERROR: Freeimage does not "
"support writing to this image format!");
return false;
}
BYTE* fi_bits = NULL;
uint8_t* im_rev = NULL;
// Unfortunately, Freeimage has a bug:
// http://sourceforge.net/p/freeimage/bugs/172/
// It ignores the mask properties and so the red and blue channels (24bpp)
// get flipped. Unfortunately, we have to swap them around.
// As of 4/26/2013 this issue still isn't fixed.
switch (num_channels) {
case 0:
throw std::wruntime_error("saveImToFile() - ERROR: num_channels == 0");
case 1:
fi_bits = (BYTE*)im;
break;
case 2:
case 3:
im_rev = new uint8_t[width * height * num_channels];
for (uint32_t i = 0; i < width * height * num_channels; i+=num_channels) {
for (uint32_t j = 0; j < num_channels; j++) {
im_rev[i + j] = im[i + (num_channels - 1 - j)];
}
}
fi_bits = (BYTE*)im_rev;
break;
default:
throw std::wruntime_error("saveImToFile() - ERROR: num_channels > 0."
" Saving images with alpha not yet supported.");
}
uint32_t pitch = num_channels * width;
uint32_t bpp = 8 * num_channels;
uint32_t red_mask = 0x0000FF; // Free image likes the mask backwards?
uint32_t green_mask = 0x00FF00;
uint32_t blue_mask = 0xFF0000;
FIBITMAP* fi_bit_map = FreeImage_ConvertFromRawBits(fi_bits, width, height,
pitch, bpp, red_mask, blue_mask, green_mask, save_flipped);
bool ret = false;
if (fi_bit_map) {
ret = (bool)FreeImage_Save(fif, fi_bit_map, filename.c_str(),
JPEG_QUALITYSUPERB);
}
if (fi_bit_map) {
FreeImage_Unload(fi_bit_map);
}
SAFE_DELETE_ARR(im_rev);
return ret;
}
开发者ID:jonathantompson,项目名称:jtil,代码行数:77,代码来源:texture.cpp
示例4: Divergence
/**
Compute gradients in x and y directions, attenuate them with the attenuation matrix,
then compute the divergence div G from the attenuated gradient.
@param H Normalized luminance
@param PHI Attenuation matrix
@return Returns the divergence matrix if successful, returns NULL otherwise
*/
static FIBITMAP* Divergence(FIBITMAP *H, FIBITMAP *PHI) {
FIBITMAP *Gx = NULL, *Gy = NULL, *divG = NULL;
float *phi, *h, *gx, *gy, *divg;
try {
const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(H);
if(image_type != FIT_FLOAT) throw(1);
const unsigned width = FreeImage_GetWidth(H);
const unsigned height = FreeImage_GetHeight(H);
Gx = FreeImage_AllocateT(image_type, width, height);
if(!Gx) throw(1);
Gy = FreeImage_AllocateT(image_type, width, height);
if(!Gy) throw(1);
const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float);
// perform gradient attenuation
phi = (float*)FreeImage_GetBits(PHI);
h = (float*)FreeImage_GetBits(H);
gx = (float*)FreeImage_GetBits(Gx);
gy = (float*)FreeImage_GetBits(Gy);
for(unsigned y = 0; y < height; y++) {
const unsigned s = (y+1 == height ? y : y+1);
for(unsigned x = 0; x < width; x++) {
const unsigned e = (x+1 == width ? x : x+1);
// forward difference
const unsigned index = y*pitch + x;
const float phi_xy = phi[index];
const float h_xy = h[index];
gx[x] = (h[y*pitch+e] - h_xy) * phi_xy; // [H(x+1, y) - H(x, y)] * PHI(x, y)
gy[x] = (h[s*pitch+x] - h_xy) * phi_xy; // [H(x, y+1) - H(x, y)] * PHI(x, y)
}
// next line
gx += pitch;
gy += pitch;
}
// calculate the divergence
divG = FreeImage_AllocateT(image_type, width, height);
if(!divG) throw(1);
gx = (float*)FreeImage_GetBits(Gx);
gy = (float*)FreeImage_GetBits(Gy);
divg = (float*)FreeImage_GetBits(divG);
for(unsigned y0 = 0; y0 < height; y0++) {
for(unsigned x = 0; x < width; x++) {
// backward difference approximation
// divG = Gx(x, y) - Gx(x-1, y) + Gy(x, y) - Gy(x, y-1)
const unsigned index = y0*pitch + x;
divg[index] = gx[index] + gy[index];
if(x > 0) divg[index] -= gx[index-1];
if(y0 > 0) divg[index] -= gy[index-pitch];
}
}
// no longer needed ...
FreeImage_Unload(Gx);
FreeImage_Unload(Gy);
// return the divergence
return divG;
} catch(int) {
if(Gx) FreeImage_Unload(Gx);
if(Gy) FreeImage_Unload(Gy);
if(divG) FreeImage_Unload(divG);
return NULL;
}
}
开发者ID:raoergsls,项目名称:miranda,代码行数:82,代码来源:tmoFattal02.cpp
示例5: paper
/**
Gradient Domain HDR tone mapping operator
@param Y Image luminance values
@param alpha Parameter alpha of the paper (suggested value is 0.1)
@param beta Parameter beta of the paper (suggested value is between 0.8 and 0.9)
@return returns the tone mapped luminance
*/
static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) {
const unsigned MIN_PYRAMID_SIZE = 32; // minimun size (width or height) of the coarsest level of the pyramid
FIBITMAP *H = NULL;
FIBITMAP **pyramid = NULL;
FIBITMAP **gradients = NULL;
FIBITMAP *phy = NULL;
FIBITMAP *divG = NULL;
FIBITMAP *U = NULL;
float *avgGrad = NULL;
int k;
int nlevels = 0;
try {
// get the normalized luminance
FIBITMAP *H = LogLuminance(Y);
if(!H) throw(1);
// get the number of levels for the pyramid
const unsigned width = FreeImage_GetWidth(H);
const unsigned height = FreeImage_GetHeight(H);
unsigned minsize = MIN(width, height);
while(minsize >= MIN_PYRAMID_SIZE) {
nlevels++;
minsize /= 2;
}
// create the Gaussian pyramid
pyramid = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*));
if(!pyramid) throw(1);
memset(pyramid, 0, nlevels * sizeof(FIBITMAP*));
if(!GaussianPyramid(H, pyramid, nlevels)) throw(1);
// calculate gradient magnitude and its average value on each pyramid level
gradients = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*));
if(!gradients) throw(1);
memset(gradients, 0, nlevels * sizeof(FIBITMAP*));
avgGrad = (float*)malloc(nlevels * sizeof(float));
if(!avgGrad) throw(1);
if(!GradientPyramid(pyramid, nlevels, gradients, avgGrad)) throw(1);
// free the Gaussian pyramid
for(k = 0; k < nlevels; k++) {
if(pyramid[k]) FreeImage_Unload(pyramid[k]);
}
free(pyramid); pyramid = NULL;
// compute the gradient attenuation function PHI(x, y)
phy = PhiMatrix(gradients, avgGrad, nlevels, alpha, beta);
if(!phy) throw(1);
// free the gradient pyramid
for(k = 0; k < nlevels; k++) {
if(gradients[k]) FreeImage_Unload(gradients[k]);
}
free(gradients); gradients = NULL;
free(avgGrad); avgGrad = NULL;
// compute gradients in x and y directions, attenuate them with the attenuation matrix,
// then compute the divergence div G from the attenuated gradient.
divG = Divergence(H, phy);
if(!divG) throw(1);
// H & phy no longer needed
FreeImage_Unload(H); H = NULL;
FreeImage_Unload(phy); phy = NULL;
// solve the PDE (Poisson equation) using a multigrid solver and 3 cycles
FIBITMAP *U = FreeImage_MultigridPoissonSolver(divG, 3);
if(!U) throw(1);
FreeImage_Unload(divG);
// perform exponentiation and recover the log compressed image
ExpLuminance(U);
return U;
} catch(int) {
if(H) FreeImage_Unload(H);
if(pyramid) {
for(int i = 0; i < nlevels; i++) {
if(pyramid[i]) FreeImage_Unload(pyramid[i]);
}
free(pyramid);
}
if(gradients) {
for(int i = 0; i < nlevels; i++) {
if(gradients[i]) FreeImage_Unload(gradients[i]);
}
//.........这里部分代码省略.........
开发者ID:raoergsls,项目名称:miranda,代码行数:101,代码来源:tmoFattal02.cpp
示例6: FreeImage_Unload
psdThumbnail::~psdThumbnail() {
FreeImage_Unload(_dib);
}
开发者ID:mdecicco,项目名称:HelloWorld,代码行数:3,代码来源:PSDParser.cpp
示例7: sizeof
//.........这里部分代码省略.........
for(unsigned h = 0; h < nHeight; ++h, dst_line_start -= dstLineSize) {//<*** flipped
io->read_proc(line_start, lineSize, 1, handle);
for (BYTE *line = line_start, *dst_line = dst_line_start; line < line_start + lineSize;
line += bytes, dst_line += dstBpp) {
#ifdef FREEIMAGE_BIGENDIAN
memcpy(dst_line + channelOffset, line, bytes);
#else
// reverse copy bytes
for (unsigned b = 0; b < bytes; ++b) {
dst_line[channelOffset + b] = line[(bytes-1) - b];
}
#endif // FREEIMAGE_BIGENDIAN
}
} //< h
}//< ch
SAFE_DELETE_ARRAY(line_start);
}
break;
case PSDP_COMPRESSION_RLE: // RLE compression
{
// The RLE-compressed data is preceeded by a 2-byte line size for each row in the data,
// store an array of these
// later use this array as WORD rleLineSizeList[nChannels][nHeight];
WORD *rleLineSizeList = new (std::nothrow) WORD[nChannels*nHeight];
if(!rleLineSizeList) {
FreeImage_Unload(bitmap);
SAFE_DELETE_ARRAY(line_start);
throw std::bad_alloc();
}
io->read_proc(rleLineSizeList, 2, nChannels * nHeight, handle);
WORD largestRLELine = 0;
for(unsigned ch = 0; ch < nChannels; ++ch) {
for(unsigned h = 0; h < nHeight; ++h) {
const unsigned index = ch * nHeight + h;
#ifndef FREEIMAGE_BIGENDIAN
SwapShort(&rleLineSizeList[index]);
#endif
if(largestRLELine < rleLineSizeList[index]) {
largestRLELine = rleLineSizeList[index];
}
}
}
BYTE* rle_line_start = new (std::nothrow) BYTE[largestRLELine];
if(!rle_line_start) {
FreeImage_Unload(bitmap);
SAFE_DELETE_ARRAY(line_start);
SAFE_DELETE_ARRAY(rleLineSizeList);
throw std::bad_alloc();
}
// Read the RLE data (assume 8-bit)
const BYTE* const line_end = line_start + lineSize;
开发者ID:mdecicco,项目名称:HelloWorld,代码行数:66,代码来源:PSDParser.cpp
示例8: FreeImage_ConvertToRGBF
FIBITMAP * DLL_CALLCONV
FreeImage_ConvertToRGBF(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:
{
// allow conversion from 24- and 32-bit
const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
if((color_type != FIC_RGB) && (color_type != FIC_RGBALPHA)) {
src = FreeImage_ConvertTo24Bits(dib);
if(!src) return NULL;
} else {
src = dib;
}
break;
}
case FIT_UINT16:
// allow conversion from 16-bit
src = 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;
case FIT_FLOAT:
// allow conversion from 32-bit float
src = dib;
break;
case FIT_RGBAF:
// allow conversion from 128-bit RGBAF
src = dib;
break;
case FIT_RGBF:
// RGBF type : clone the src
return FreeImage_Clone(dib);
break;
default:
return NULL;
}
// allocate dst image
const unsigned width = FreeImage_GetWidth(src);
const unsigned height = FreeImage_GetHeight(src);
dst = FreeImage_AllocateT(FIT_RGBF, width, height);
if(!dst) {
if(src != dib) {
FreeImage_Unload(src);
}
return NULL;
}
// copy metadata from src to dst
FreeImage_CloneMetadata(dst, src);
// convert from src type to RGBF
const unsigned src_pitch = FreeImage_GetPitch(src);
const unsigned dst_pitch = FreeImage_GetPitch(dst);
switch(src_type) {
case FIT_BITMAP:
{
// calculate the number of bytes per pixel (3 for 24-bit or 4 for 32-bit)
const unsigned bytespp = FreeImage_GetLine(src) / FreeImage_GetWidth(src);
const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src);
BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst);
for(unsigned y = 0; y < height; y++) {
const BYTE *src_pixel = (BYTE*)src_bits;
FIRGBF *dst_pixel = (FIRGBF*)dst_bits;
for(unsigned x = 0; x < width; x++) {
// convert and scale to the range [0..1]
dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F;
dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F;
dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F;
src_pixel += bytespp;
dst_pixel ++;
}
src_bits += src_pitch;
dst_bits += dst_pitch;
}
}
break;
case FIT_UINT16:
//.........这里部分代码省略.........
开发者ID:bai-lu-sz,项目名称:VirtualGEVCam,代码行数:101,代码来源:ConversionRGBF.cpp
示例9: Load
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FIBITMAP *dib = NULL;
LibRaw RawProcessor;
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
// wrap the input datastream
LibRaw_freeimage_datastream datastream(io, handle);
// open the datastream
if(RawProcessor.open_datastream(&datastream) != LIBRAW_SUCCESS) {
throw "LibRaw : failed to open input stream (unknown format)";
}
if(header_only) {
// header only mode
dib = FreeImage_AllocateHeaderT(header_only, FIT_RGB16, RawProcessor.imgdata.sizes.width, RawProcessor.imgdata.sizes.height);
// try to get JPEG embedded Exif metadata
if(dib) {
FIBITMAP *metadata_dib = libraw_LoadEmbeddedPreview(RawProcessor, FIF_LOAD_NOPIXELS);
if(metadata_dib) {
FreeImage_CloneMetadata(dib, metadata_dib);
FreeImage_Unload(metadata_dib);
}
}
}
else if((flags & RAW_PREVIEW) == RAW_PREVIEW) {
// try to get the embedded JPEG
dib = libraw_LoadEmbeddedPreview(RawProcessor, 0);
if(!dib) {
// no JPEG preview: try to load as 8-bit/sample (i.e. RGB 24-bit)
dib = libraw_LoadRawData(RawProcessor, 8);
}
}
else if((flags & RAW_DISPLAY) == RAW_DISPLAY) {
// load raw data as 8-bit/sample (i.e. RGB 24-bit)
dib = libraw_LoadRawData(RawProcessor, 8);
}
else {
// default: load raw data as linear 16-bit/sample (i.e. RGB 48-bit)
dib = libraw_LoadRawData(RawProcessor, 16);
}
// save ICC profile if present
if(NULL != RawProcessor.imgdata.color.profile) {
FreeImage_CreateICCProfile(dib, RawProcessor.imgdata.color.profile, RawProcessor.imgdata.color.profile_length);
}
// try to get JPEG embedded Exif metadata
if(dib && !((flags & RAW_PREVIEW) == RAW_PREVIEW) ) {
FIBITMAP *metadata_dib = libraw_LoadEmbeddedPreview(RawProcessor, FIF_LOAD_NOPIXELS);
if(metadata_dib) {
FreeImage_CloneMetadata(dib, metadata_dib);
FreeImage_Unload(metadata_dib);
}
}
// clean-up internal memory allocations
RawProcessor.recycle();
return dib;
} catch(const char *text) {
if(dib) {
FreeImage_Unload(dib);
}
RawProcessor.recycle();
FreeImage_OutputMessageProc(s_format_id, text);
}
return NULL;
}
开发者ID:louisfeng,项目名称:FreeImage,代码行数:74,代码来源:PluginRAW.cpp
示例10: saveImage
static void saveImage(ofPixels_<PixelType> & pix, string fileName, ofImageQualityType qualityLevel) {
ofInitFreeImage();
if (pix.isAllocated() == false){
ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
return;
}
#ifdef TARGET_LITTLE_ENDIAN
if(sizeof(PixelType) == 1) {
pix.swapRgb();
}
#endif
FIBITMAP * bmp = getBmpFromPixels(pix);
#ifdef TARGET_LITTLE_ENDIAN
if(sizeof(PixelType) == 1) {
pix.swapRgb();
}
#endif
fileName = ofToDataPath(fileName);
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)) {
if(fif == FIF_JPEG) {
int quality = JPEG_QUALITYSUPERB;
switch(qualityLevel) {
case OF_IMAGE_QUALITY_WORST: quality = JPEG_QUALITYBAD; break;
case OF_IMAGE_QUALITY_LOW: quality = JPEG_QUALITYAVERAGE; break;
case OF_IMAGE_QUALITY_MEDIUM: quality = JPEG_QUALITYNORMAL; break;
case OF_IMAGE_QUALITY_HIGH: quality = JPEG_QUALITYGOOD; break;
case OF_IMAGE_QUALITY_BEST: quality = JPEG_QUALITYSUPERB; break;
}
FreeImage_Save(fif, bmp, fileName.c_str(), quality);
} else {
if(qualityLevel != OF_IMAGE_QUALITY_BEST) {
ofLogWarning() << "ofImageCompressionType only applies to JPEG images, ignoring value";
}
if (fif == FIF_GIF) {
FIBITMAP* convertedBmp;
if(pix.getImageType() == OF_IMAGE_COLOR_ALPHA) {
// this just converts the image to grayscale so it can save something
convertedBmp = FreeImage_ConvertTo8Bits(bmp);
} else {
// this will create a 256-color palette from the image
convertedBmp = FreeImage_ColorQuantize(bmp, FIQ_NNQUANT);
}
FreeImage_Save(fif, convertedBmp, fileName.c_str());
if (convertedBmp != NULL){
FreeImage_Unload(convertedBmp);
}
} else {
FreeImage_Save(fif, bmp, fileName.c_str());
}
}
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
}
开发者ID:prettyextreme,项目名称:openFrameworks-0.7,代码行数:67,代码来源:ofImage.cpp
示例11: LoadTexture
unsigned int LoadTexture(const char* a_szTexture)
{
FIBITMAP* pBitmap = nullptr;
// Determime File Type from File Signature
FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(a_szTexture, 0);
// Success
if (fif != FIF_UNKNOWN && FreeImage_FIFSupportsReading(fif))
{
pBitmap = FreeImage_Load(fif, a_szTexture);
}
// Failure
if (pBitmap == nullptr)
{
printf("Error: Failed to load image '%s'!\n", a_szTexture);
return 0;
}
// Force the image to RGBA
// Get size of pixel in bits
unsigned int bpp = FreeImage_GetBPP(pBitmap);
/*
// How does this conversion to RGBA work?
if( a_uiBPP != nullptr )
{
*a_uiBPP = bpp/8;
//RGBA has 8 bits per color channel...
}
*/
// Get Color Type
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);
// VARIABLE = ( CONDITION TO EVALUATE ) ? IF_TRUE : IF_FALSE ;
GLenum eType = (fit == FIT_RGBF || fit == FIT_FLOAT) ? GL_FLOAT:GL_UNSIGNED_BYTE;
// Create variable to store OGL Tex ID
GLuint textureID;
// Generate OGL Tex ID
glGenTextures( 1, &textureID );
// Bind Texture for Use by using the OGL Tex DI
glBindTexture( GL_TEXTURE_2D, textureID );
// Texturing allows elements of an image array to be read by shaders.
glTexImage2D( GL_TEXTURE_2D, // TARGET
0, // level of detail
GL_RGBA, // color format
FreeImage_GetWidth(pBitmap), // width
FreeImage_GetHeight(pBitmap), // height
0, // border (must be 0)
fi_colourType, // pixel data format - i.e. RGBA
eType, // pixel data type
pData); // data
// 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);
return textureID;
}
开发者ID:Vinessa,项目名称:VinessaAIEProgramming,代码行数:93,代码来源:Utilities.cpp
示例12: order
/**
Image rotation using a 3rd order (cubic) B-Splines.
@param dib Input dib (8, 24 or 32-bit)
@param angle Output image rotation
@param x_shift Output image horizontal shift
@param y_shift Output image vertical shift
@param x_origin Output origin of the x-axis
@param y_origin Output origin of the y-axis
@param use_mask Whether or not to mask the image
@return Returns the translated & rotated dib if successful, returns NULL otherwise
*/
FIBITMAP * DLL_CALLCONV
FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask) {
int x, y, bpp;
int channel, nb_channels;
BYTE *src_bits, *dst_bits;
FIBITMAP *src8 = NULL, *dst8 = NULL, *dst = NULL;
try {
bpp = FreeImage_GetBPP(dib);
if(bpp == 8) {
return Rotate8Bit(dib, angle, x_shift, y_shift, x_origin, y_origin, ROTATE_CUBIC, use_mask);
}
if((bpp == 24) || (bpp == 32)) {
// allocate dst image
int width = FreeImage_GetWidth(dib);
int height = FreeImage_GetHeight(dib);
if( bpp == 24 ) {
dst = FreeImage_Allocate(width, height, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
} else {
dst = FreeImage_Allocate(width, height, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
}
if(!dst) throw(1);
// allocate a temporary 8-bit dib (no need to build a palette)
src8 = FreeImage_Allocate(width, height, 8);
if(!src8) throw(1);
// process each channel separately
// -------------------------------
nb_channels = (bpp / 8);
for(channel = 0; channel < nb_channels; channel++) {
// extract channel from source dib
for(y = 0; y < height; y++) {
src_bits = FreeImage_GetScanLine(dib, y);
dst_bits = FreeImage_GetScanLine(src8, y);
for(x = 0; x < width; x++) {
dst_bits[x] = src_bits[channel];
src_bits += nb_channels;
}
}
// process channel
dst8 = Rotate8Bit(src8, angle, x_shift, y_shift, x_origin, y_origin, ROTATE_CUBIC, use_mask);
if(!dst8) throw(1);
// insert channel to destination dib
for(y = 0; y < height; y++) {
src_bits = FreeImage_GetScanLine(dst8, y);
dst_bits = FreeImage_GetScanLine(dst, y);
for(x = 0; x < width; x++) {
dst_bits[channel] = src_bits[x];
dst_bits += nb_channels;
}
}
FreeImage_Unload(dst8);
}
FreeImage_Unload(src8);
return dst;
}
} catch(int) {
if(src8) FreeImage_Unload(src8);
if(dst8) FreeImage_Unload(dst8);
if(dst) FreeImage_Unload(dst);
}
return NULL;
}
开发者ID:BackupTheBerlios,项目名称:mimplugins-svn,代码行数:86,代码来源:BSplineRotate.cpp
示例13: Rotate8Bit
/**
Image translation and rotation using B-Splines.
@param dib Input 8-bit greyscale image
@param angle Output image rotation in degree
@param x_shift Output image horizontal shift
@param y_shift Output image vertical shift
@param x_origin Output origin of the x-axis
@param y_origin Output origin of the y-axis
@param spline_degree Output degree of the B-spline model
@param use_mask Whether or not to mask the image
@return Returns the translated & rotated dib if successful, returns NULL otherwise
*/
static FIBITMAP *
Rotate8Bit(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, long spline_degree, BOOL use_mask) {
double *ImageRasterArray;
double p;
double a11, a12, a21, a22;
double x0, y0, x1, y1;
long x, y;
long spline;
bool bResult;
int bpp = FreeImage_GetBPP(dib);
if(bpp != 8) {
return NULL;
}
int width = FreeImage_GetWidth(dib);
int height = FreeImage_GetHeight(dib);
switch(spline_degree) {
case ROTATE_QUADRATIC:
spline = 2L; // Use splines of degree 2 (quadratic interpolation)
break;
case ROTATE_CUBIC:
spline = 3L; // Use splines of degree 3 (cubic interpolation)
break;
case ROTATE_QUARTIC:
spline = 4L; // Use splines of degree 4 (quartic interpolation)
break;
case ROTATE_QUINTIC:
spline = 5L; // Use splines of degree 5 (quintic interpolation)
break;
default:
spline = 3L;
}
// allocate output image
FIBITMAP *dst = FreeImage_Allocate(width, height, bpp);
if(!dst)
return NULL;
// buid a grey scale palette
RGBQUAD *pal = FreeImage_GetPalette(dst);
for(int i = 0; i < 256; i++) {
pal[i].rgbRed = pal[i].rgbGreen = pal[i].rgbBlue = (BYTE)i;
}
// allocate a temporary array
ImageRasterArray = (double*)malloc(width * height * sizeof(double));
if(!ImageRasterArray) {
FreeImage_Unload(dst);
return NULL;
}
// copy data samples
for(y = 0; y < height; y++) {
double *pImage = &ImageRasterArray[y*width];
BYTE *src_bits = FreeImage_GetScanLine(dib, height-1-y);
for(x = 0; x < width; x++) {
pImage[x] = (double)src_bits[x];
}
}
// convert between a representation based on image samples
// and a representation based on image B-spline coefficients
bResult = SamplesToCoefficients(ImageRasterArray, width, height, spline);
if(!bResult) {
FreeImage_Unload(dst);
free(ImageRasterArray);
return NULL;
}
// prepare the geometry
angle *= PI / 180.0;
a11 = cos(angle);
a12 = -sin(angle);
a21 = sin(angle);
a22 = cos(angle);
x0 = a11 * (x_shift + x_origin) + a12 * (y_shift + y_origin);
y0 = a21 * (x_shift + x_origin) + a22 * (y_shift + y_origin);
x_shift = x_origin - x0;
y_shift = y_origin - y0;
// visit all pixels of the output image and assign their value
for(y = 0; y < height; y++) {
BYTE *dst_bits = FreeImage_GetScanLine(dst, height-1-y);
x0 = a12 * (double)y + x_shift;
y0 = a22 * (double)y + y_shift;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:mimplugins-svn,代码行数:101,代码来源:BSplineRotate.cpp
示例14: FreeImage_CloseMultiBitmap
BOOL DLL_CALLCONV
FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) {
if (bitmap) {
BOOL success = TRUE;
if (bitmap->data) {
MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap);
if (header->changed) {
// open a temp file
char spool_name[256];
ReplaceExtension(spool_name, header->m_filename, "fispool");
// open the spool file and the source file
FILE *f = fopen(spool_name, "w+b");
void *data = FreeImage_Open(header->node, header->io, (fi_handle)f, FALSE);
void *data_read = NULL;
if (header->handle) {
header->io->seek_proc(header->handle, 0, SEEK_SET);
data_read = FreeImage_Open(header->node, header->io, header->handle, TRUE);
}
// write all the pages to the temp file
int count = 0;
for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); i++) {
if (success) {
switch((*i)->m_type) {
case BLOCK_CONTINUEUS :
{
BlockContinueus *block = (BlockContinueus *)(*i);
for (int j = block->m_start; j <= block->m_end; j++) {
FIBITMAP *dib = header->node->m_plugin->load_proc(header->io, header->handle, j, header->load_flags, data_read);
success = header->node->m_plugin->save_proc(header->io, dib, (fi_handle)f, count, flags, data);
count++;
FreeImage_Unload(dib);
}
break;
}
case BLOCK_REFERENCE :
{
BlockReference *ref = (BlockReference *)(*i);
// read the compressed data
BYTE *compressed_data = (BYTE*)malloc(ref->m_size * sizeof(BYTE));
header->m_cachefile->readFile((BYTE *)compressed_data, ref->m_reference, ref->m_size);
// uncompress the data
FIMEMORY *hmem = FreeImage_OpenMemory(compressed_data, ref->m_size);
FIBITMAP *dib = FreeImage_LoadFromMemory(header->cache_fif, hmem, 0);
FreeImage_CloseMemory(hmem);
// get rid of the buffer
free(compressed_data);
// save the data
success = header->node->m_plugin->save_proc(header->io, dib, (fi_handle)f, count, flags, data);
count++;
// unload the dib
FreeImage_Unload(dib);
break;
}
}
} else {
break;
}
}
// close the files
FreeImage_Close(header->node, header->io, (fi_handle)f, data);
fclose(f);
if (header->handle) {
FreeImage_Close(header->node, header->io, header->handle, data_read);
fclose((FILE *)header->handle);
}
if (success) {
//.........这里部分代码省略.........
开发者ID:barsnadcat,项目名称:steelandconcrete,代码行数:101,代码来源:MultiPage.cpp
示例15: FreeImage_SaveMultiBitmapToHandle
BOOL DLL_CALLCONV
FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags) {
if(!bitmap || !bitmap->data || !io || !handle) {
return FALSE;
}
BOOL success = TRUE;
// retrieve the plugin list to find the node belonging to this plugin
PluginList *list = FreeImage_GetPluginList();
if (list) {
PluginNode *node = list->FindNodeFromFIF(fif);
if(node) {
MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap);
// dst data
void *data = FreeImage_Open(node, io, handle, FALSE);
// src data
void *data_read = NULL;
if(header->handle) {
// open src
header->io->seek_proc(header->handle, 0, SEEK_SET);
data_read = FreeImage_Open(header->node, header->io, header->handle, TRUE);
}
// write all the pages to the file using handle and io
int count = 0;
for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); i++) {
if (success) {
switch((*i)->m_type) {
case BLOCK_CONTINUEUS:
{
BlockContinueus *block = (BlockContinueus *)(*i);
for (int j = block->m_start; j <= block->m_end; j++) {
// load the original source data
FIBITMAP *dib = header->node->m_plugin->load_proc(header->io, header->handle, j, header->load_flags, data_read);
// save the data
success = node->m_plugin->save_proc(io, dib, handle, count, flags, data);
count++;
FreeImage_Unload(dib);
}
break;
}
case BLOCK_REFERENCE:
{
BlockReference *ref = (BlockReference *)(*i);
// read the compressed data
BYTE *compressed_data = (BYTE*)malloc(ref->m_size * sizeof(BYTE));
header->m_cachefile->readFile((BYTE *)compressed_data, ref->m_reference, ref->m_size);
// uncompress the data
FIMEMORY *hmem = FreeImage_OpenMemory(compressed_data, ref->m_size);
FIBITMAP *dib = FreeImage_LoadFromMemory(header->cache_fif, hmem, 0);
FreeImage_CloseMemory(hmem);
// get rid of the buffer
free(compressed_data);
// save the data
success = node->m_plugin->save_proc(io, dib, handle, count, flags, data);
count++;
// unload the dib
FreeImage_Unload(dib);
break;
}
}
} else {
break;
}
}
// close the files
FreeImage_Close(header->node, header->io, header->handle, data_read);
FreeImage_Close(node, io, handle, data);
return success;
}
}
//.........这里部分代码省略.........
开发者ID:0xmono,项目名称:miranda-ng,代码行数:101,代码来源:MultiPage.cpp
示例16: FreeImage_UnlockPage
void DLL_CALLCONV
FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *page, BOOL changed) {
if ((bitmap) && (page)) {
MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap);
// find out if the page we try to unlock is actually locked...
if (header->locked_pages.find(page) != header->locked_pages.end()) {
// store the bitmap compressed in the cache for later writing
if (changed && !header->read_only) {
header->changed = TRUE;
// cut loose the block from the rest
BlockListIterator i = FreeImage_FindBlock(bitmap, header->locked_pages[page]);
// compress the data
DWORD compressed_size = 0;
BYTE *compressed_data = NULL;
// open a memory handle
FIMEMORY *hmem = FreeImage_OpenMemory();
// save the page to memory
FreeImage_SaveToMemory(header->cache_fif, page, hmem, 0);
// get the buffer from the memory stream
FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size);
// write the data to the cache
switch ((*i)->m_type) {
case BLOCK_CONTINUEUS :
{
int iPage = header->m_cachefile->writeFile(compressed_data, compressed_size);
delete (*i);
*i = (BlockTypeS *)new BlockReference(iPage, compressed_size);
break;
}
case BLOCK_REFERENCE :
{
BlockReference *reference = (BlockReference *)(*i);
header->m_cachefile->deleteFile(reference->m_reference);
delete (*i);
int iPage = header->m_cachefile->writeFile(compressed_data, compressed_size);
*i = (BlockTypeS *)new BlockReference(iPage, compressed_size);
break;
}
}
// get rid of the compressed data
FreeImage_CloseMemory(hmem);
}
// reset the locked page so that another page can be locked
FreeImage_Unload(page);
header->locked_pages.erase(page);
}
}
}
开发者ID:barsnadcat,项目名称:steelandconcrete,代码行数:72,代码来源:MultiPage.cpp
示例17: FreeImage_CloseMultiBitmap
BOOL DLL_CALLCONV
FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) {
if (bitmap) {
BOOL success = TRUE;
if (bitmap->data) {
MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap);
// saves changes only of images loaded directly from a file
if (header->changed && header->m_filename) {
try {
// open a temp file
std::string spool_name;
ReplaceExtension(spool_name, header->m_filename, "fispool");
// open the spool file and the source file
FILE *f = fopen(spool_name.c_str(), "w+b");
// saves changes
if (f == NULL) {
FreeImage_OutputMessageProc(header->fif, "Failed to open %s, %s", spool_name.c_str(), strerror(errno));
success = FALSE;
} else {
success = FreeImage_SaveMultiBitmapToHandle(header->fif, bitmap, header->io, (fi_handle)f, flags);
// close the files
if (fclose(f) != 0) {
success = FALSE;
FreeImage_OutputMessageProc(header->fif, "Failed to close %s, %s", spool_name.c_str(), strerror(errno));
}
}
if (header->handle) {
fclose((FILE *)header->handle);
}
// applies changes to the destination file
if (success) {
remove(header->m_filename);
success = (rename(spool_name.c_str(), header->m_filename) == 0) ? TRUE:FALSE;
if(!success) {
FreeImage_OutputMessageProc(header->fif, "Failed to rename %s to %s", spool_name.c_str(), header->m_filename);
}
} else {
remove(spool_name.c_str());
}
} catch (std::bad_alloc &) {
success = FALSE;
}
} else {
if (header->handle && header->m_filename) {
fclose((FILE *)header->handle);
}
}
// clear the blocks list
for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) {
delete *i;
}
// flush and dispose the cache
if (header->m_cachefile) {
header->m_cachefile->close();
delete header->m_cachefile;
}
// delete the last open bitmaps
while (!header->locked_pages.empty()) {
FreeImage_Unload(header->locked_pages.begin()->first);
header->locked_pages.erase(header->locked_pages.begin()->first);
}
// get rid of the IO structure
delete header->io;
// delete the filename
if(header->m_filename) {
delete[] header->m_filename;
}
// delete the FIMULTIBITMAPHEADER
delete header;
}
delete bitmap;
return success;
}
//.........这里部分代码省略.........
开发者ID:0xmono,项目名称:miranda-ng,代码行数:101,代码来源:MultiPage.cpp
示例 |
请发表评论