本文整理汇总了C++中FreeImage_Save函数的典型用法代码示例。如果您正苦于以下问题:C++ FreeImage_Save函数的具体用法?C++ FreeImage_Save怎么用?C++ FreeImage_Save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FreeImage_Save函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportImage
/* Exports the left and right eye view as images */
void exportImage(void) {
unsigned char *image;
image = (unsigned char*)malloc((3*Settings::pixelWidth*Settings::pixelHeight)*sizeof(char));
glPixelStorei(GL_PACK_ALIGNMENT,1);
// Left Image
glReadBuffer(GL_BACK_LEFT);
glReadPixels(0, 0, (int)Settings::pixelWidth, (int)Settings::pixelHeight,
GL_BGR,GL_UNSIGNED_BYTE, image);
FIBITMAP* leftImage = FreeImage_ConvertFromRawBits(image, (int)Settings::pixelWidth,
(int)Settings::pixelHeight,
3*Settings::pixelWidth, 24, 0xFF0000,
0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, leftImage, "left.bmp", 0);
// Right image
glReadBuffer(GL_BACK_RIGHT);
glReadPixels(0, 0, (int)Settings::pixelWidth, (int)Settings::pixelHeight,
GL_BGR, GL_UNSIGNED_BYTE, image);
FIBITMAP* rightImage = FreeImage_ConvertFromRawBits(image, (int)Settings::pixelWidth,
(int)Settings::pixelHeight,
3*Settings::pixelWidth, 24, 0xFF0000,
0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, rightImage, "right.bmp", 0);
free(image);
}
示例2: process_image
bool process_image(std::string infile, std::string outfile, double brightness, double gamma)
{
DIR *editdir = opendir("img/edit");
struct dirent *file;
while ((file = readdir(editdir)) != NULL)
{
if (strcmp(file -> d_name, outfile.c_str()) == 0)
{
return false;
}
}
closedir(editdir);
infile = "img/" + infile;
outfile = "img/edit/" + outfile;
FIBITMAP *input = FreeImage_Load(FIF_PNG, infile.c_str());
if (input == NULL)
{
std::cerr << "Failed to load " << infile << std::endl;
exit(1);
}
if (!FreeImage_Save(FIF_PNG, input, outfile.c_str()))
{
FreeImage_Unload(input);
std::cerr << "Failed to save " << outfile << std::endl;
exit(1);
}
FreeImage_Unload(input);
FIBITMAP *output = FreeImage_Load(FIF_PNG, outfile.c_str());
if (output == NULL)
{
std::cerr << "Failed to load " << outfile << std::endl;
exit(1);
}
unsigned int img_w = FreeImage_GetWidth(output);
unsigned int img_h = FreeImage_GetHeight(output);
RGBQUAD pixel;
for (unsigned int x = 0; x < img_w; x++)
{
for (unsigned int y = 0; y < img_h; y++)
{
FreeImage_GetPixelColor(output, x, y, &pixel);
pixel.rgbRed = int(clamp(0, pixel.rgbRed * brightness, 255));
pixel.rgbBlue = int(clamp(0, pixel.rgbBlue * brightness, 255));
pixel.rgbGreen = int(clamp(0, pixel.rgbGreen * brightness, 255));
pixel.rgbRed = int(clamp(0, pow(((double) pixel.rgbRed) / 255.0f, gamma) * 255.0, 255));
pixel.rgbBlue = int(clamp(0, pow(((double) pixel.rgbBlue) / 255.0f, gamma) * 255.0, 255));
pixel.rgbGreen = int(clamp(0, pow(((double) pixel.rgbGreen) / 255.0f, gamma) * 255.0, 255));
FreeImage_SetPixelColor(output, x, y, &pixel);
}
}
if (!FreeImage_Save(FIF_PNG, output, outfile.c_str()))
{
FreeImage_Unload(input);
std::cerr << "Failed to save " << outfile << std::endl;
exit(1);
}
FreeImage_Unload(output);
return true;
}
示例3: storeFreeImage
void storeFreeImage(const Ref<Image>& img, const FileName& fileName)
{
FIBITMAP* dib = FreeImage_Allocate((int)img->width, (int)img->height, 24);
for(size_t y = 0; y < img->height; y++)
{
for(size_t x = 0; x < img->width; x++)
{
Color4 c = img->get(x, y);
RGBQUAD Value = {0};
Value.rgbRed = (BYTE)(clamp(c.r) * 255.0f);
Value.rgbGreen = (BYTE)(clamp(c.g) * 255.0f);
Value.rgbBlue = (BYTE)(clamp(c.b) * 255.0f);
FreeImage_SetPixelColor(dib, (unsigned int)x, (unsigned int)y, &Value);
}
}
FIBITMAP* fiLogo = loadWatermark();
unsigned int LogoWidth = FreeImage_GetWidth (fiLogo);
unsigned int LogoHeight = FreeImage_GetHeight(fiLogo);
if(LogoWidth > img->width || LogoHeight > img->height)
{
FreeImage_Unload(fiLogo);
FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(fileName.c_str());
if(FreeImage_FIFSupportsWriting(fif))
FreeImage_Save(fif, dib, fileName.c_str());
FreeImage_Unload(dib);
}
else
{
int x_pos = (int)img->width - LogoWidth;
int y_pos = (int)img->height - LogoHeight;
FIBITMAP* fiFG = FreeImage_Allocate((int)img->width, (int)img->height, 32);
BOOL b = FreeImage_Paste(fiFG, fiLogo, x_pos, y_pos, 255);
FreeImage_Unload(fiLogo);
FIBITMAP* fiNew = FreeImage_Composite(fiFG, FALSE, NULL, dib);
FreeImage_Unload(dib);
FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(fileName.c_str());
int save_flags = 0;
if(fif == FIF_JPEG)
save_flags = JPEG_QUALITYSUPERB | JPEG_BASELINE | JPEG_OPTIMIZE;
if(FreeImage_FIFSupportsWriting(fif))
FreeImage_Save(fif, fiNew, fileName.c_str(), save_flags);
FreeImage_Unload(fiNew);
}
}
示例4: ofLog
//----------------------------------------------------------------
void ofImage::saveImageFromPixels(string fileName, ofPixels &pix){
if (pix.bAllocated == false){
ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
return;
}
#ifdef TARGET_LITTLE_ENDIAN
if (pix.bytesPerPixel != 1) swapRgb(pix);
#endif
FIBITMAP * bmp = getBmpFromPixels(pix);
#ifdef TARGET_LITTLE_ENDIAN
if (pix.bytesPerPixel != 1) swapRgb(pix);
#endif
fileName = ofToDataPath(fileName);
if (pix.bAllocated == true){
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)) {
FreeImage_Save(fif, bmp, fileName.c_str(), 0);
}
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
}
示例5: capture
void capture()
{
if (doo > 0){ doo = 0; }
else{ doo++; return; }
if (capture_frame >= 250) exit(0);
int mWin_width = 800;
int mWin_height = 600;
// Make the BYTE array, factor of 3 because it's RBG.
BYTE* pixels = new BYTE[3 * mWin_width * mWin_height];
glReadPixels(0, 0, mWin_width, mWin_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
for (int i = 0; i < mWin_height; i++)
for (int j = 0; j < mWin_width; j++)
{
BYTE tmp = pixels[i*(mWin_width * 3) + (j * 3) + 0];
pixels[i*(mWin_width * 3) + (j * 3) + 0] = pixels[i*(mWin_width * 3) + (j * 3) + 2];
pixels[i*(mWin_width * 3) + (j * 3) + 2] = tmp;
}
// Convert to FreeImage format & save to file
FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, mWin_width, mWin_height, 3 * mWin_width, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
char filename[200];
sprintf(filename, "F:/Result_Seen/temp/Image/%05d.png", capture_frame);
capture_frame++;
FreeImage_Save(FIF_PNG, image, filename, 0);
// Free resources
FreeImage_Unload(image);
delete[] pixels;
}
示例6: write_img
static int
write_img(char *name, const greyscale_image *img) {
FIBITMAP *image;
RGBQUAD aPixel;
int i,j;
image = FreeImage_Allocate(img->width, img->height, 24, 0, 0, 0);
if(!image) {
perror("FreeImage_Allocate");
return -1;
}
for(i = 0; i < img->height; i++) {
for(j = 0; j < img->width; j++) {
float v = img->v[i*img->width + j];
if (v > 1.0) v = 1.0;
else if (v < 0) v = 0.0;
v *= 255.0;
aPixel.rgbRed = (unsigned char) v;
aPixel.rgbGreen = (unsigned char) v;
aPixel.rgbBlue = (unsigned char) v;
FreeImage_SetPixelColor(image, j, i, &aPixel);
}
}
if(!FreeImage_Save(FIF_JPEG, image, name, 0)) {
perror("FreeImage_Save");
}
FreeImage_Unload(image);
return 0;
}
示例7: write_image
void write_image(const string& file, const SampleBuffer& buffer)
{
const float samples = static_cast<float>(buffer.samples());
FIBITMAP* dib = FreeImage_Allocate(buffer.width(), buffer.height(),
32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
const unsigned int BYTESPP =
FreeImage_GetLine(dib) / FreeImage_GetWidth(dib);
for (unsigned int y = 0; y < FreeImage_GetHeight(dib); ++y) {
BYTE* bits = FreeImage_GetScanLine(dib, y);
for (unsigned int x = 0; x < FreeImage_GetWidth(dib); ++x) {
vec3 c = gamma_correct(buffer.get(x, y) / samples) * 255.0f;
bits[FI_RGBA_RED] = static_cast<BYTE>(c.r);
bits[FI_RGBA_GREEN] = static_cast<BYTE>(c.g);
bits[FI_RGBA_BLUE] = static_cast<BYTE>(c.b);
bits[FI_RGBA_ALPHA] = 255;
bits += BYTESPP;
}
}
if (!FreeImage_Save(FIF_PNG, dib, file.c_str(), 0)) {
string err = "Failed to save screenshot to file '";
err += file;
err += '\'';
throw err;
}
FreeImage_Unload(dib);
}
示例8: test32BitsChannels
void test32BitsChannels(unsigned width, unsigned height) {
BOOL bResult = FALSE;
// create a test 8-bit image
FIBITMAP *src = createZonePlateImage(width, height, 128);
if(src != NULL) {
// convert to 32-bit
FIBITMAP *tmp = FreeImage_ConvertTo32Bits(src);
FreeImage_Unload(src);
src = tmp;
}
assert(src != NULL);
// save for further examination
bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT);
assert(bResult);
// test get/set channel
// -------------------------
FIBITMAP *channel = FreeImage_GetChannel(src, FICC_ALPHA);
assert(channel != NULL);
bResult = FreeImage_SetChannel(src, channel, FICC_ALPHA);
assert(bResult);
FreeImage_Unload(channel);
FreeImage_Unload(src);
}
示例9: FreeImage_GetFIFFromFilename
BOOL fipImage::save(const char* lpszPathName, int flag) const {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
BOOL bSuccess = FALSE;
// Try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
if(fif != FIF_UNKNOWN ) {
// Check that the dib can be saved in this format
BOOL bCanSave;
FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib);
if(image_type == FIT_BITMAP) {
// standard bitmap type
WORD bpp = FreeImage_GetBPP(_dib);
bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp));
} else {
// special bitmap type
bCanSave = FreeImage_FIFSupportsExportType(fif, image_type);
}
if(bCanSave) {
bSuccess = FreeImage_Save(fif, _dib, lpszPathName, flag);
return bSuccess;
}
}
return bSuccess;
}
示例10: GenericWriter
/** Generic image writer
@param dib Pointer to the dib to be saved
@param lpszPathName Pointer to the full file name
@param flag Optional save flag constant
@return Returns true if successful, returns false otherwise
*/
bool GenericWriter(const bitmap_ptr& dib, const std::string& lpszPathName, int flag) {
auto fif = FIF_UNKNOWN;
auto bSuccess = FALSE;
// check if file path is not empty
if (lpszPathName.empty())
return false;
if (dib) {
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName.c_str());
if (fif != FIF_UNKNOWN) {
// check that the plugin has sufficient writing and export capabilities ...
if (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportType(fif, FreeImage_GetImageType(dib.get()))) {
// ok, we can save the file
bSuccess = FreeImage_Save(fif, dib.get(), lpszPathName.c_str(), flag);
// unless an abnormal bug, we are done !
}
else {
std::cout << "Can't save file" << lpszPathName << std::endl;
}
}
else {
std::cerr << "Can't determine output file type" << std::endl;
}
}
return (bSuccess == TRUE);
}
示例11: FreeImage_Allocate
bool ZitexConverter::convert(const QString & inFileName, const ConfigDao & configuration)
{
auto inFileNameStdStr = inFileName.toStdString();
Zitex::Reader reader;
Zitex::Reader::Data data;
reader.readFromFile(inFileNameStdStr, data);
for (uint32_t it = 0; it < data.header->texImagesNum; ++it)
{
Zitex::TexImageHeader * texImageHeader = data.texImages[it].header;
if (texImageHeader->level == 0)
{
auto width = texImageHeader->width;
auto height = texImageHeader->height;
FIBITMAP * fiBitmap = FreeImage_Allocate(width, height, 32);
squish::DecompressImage(FreeImage_GetBits(fiBitmap), width, height, data.texImages[it].data,
data.header->squishFlags);
// section(".", 0, -2) copyes from begin to 2nd section from end.
// The first section from end is the extension
std::string outFileNameStdStr = inFileName.section(".", 0, -2).append(".png").toStdString();
FreeImage_FlipVertical(fiBitmap);
FreeImage_Save(FIF_PNG, fiBitmap, outFileNameStdStr.c_str());
FreeImage_Unload(fiBitmap);
}
}
}
示例12: FreeImage_GetFIFFromFilename
bool RGBAImage::WriteToFile(const char* filename)
{
const FREE_IMAGE_FORMAT fileType = FreeImage_GetFIFFromFilename(filename);
if(FIF_UNKNOWN == fileType)
{
printf("Can't save to unknown filetype %s\n", filename);
return false;
}
FIBITMAP* bitmap = FreeImage_Allocate(Width, Height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000);
if(!bitmap)
{
printf("Failed to create freeimage for %s\n", filename);
return false;
}
const unsigned int* source = Data;
for( int y=0; y < Height; y++, source += Width )
{
unsigned int* scanline = (unsigned int*)FreeImage_GetScanLine(bitmap, Height - y - 1 );
memcpy(scanline, source, sizeof(source[0]) * Width);
}
FreeImage_SetTransparent(bitmap, true);
FIBITMAP* converted = FreeImage_ConvertTo24Bits(bitmap);
const bool result = !!FreeImage_Save(fileType, converted, filename);
if(!result)
printf("Failed to save to %s\n", filename);
FreeImage_Unload(converted);
FreeImage_Unload(bitmap);
return result;
}
示例13: SaveTextureToFile
bool SaveTextureToFile(const char* filename, const void* data, int w, int h)
{
bool ret = false;
FIBITMAP* bitmap = nullptr;
bitmap = FreeImage_AllocateT(FIT_BITMAP, w, h, 32);
CHECK(bitmap);
RGBQUAD dst;
const Color* imageData = (const Color*)data;
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
const Color& src = imageData[((h - 1 - y) * w + x)];
dst.rgbBlue = (BYTE)(src.b * 255);
dst.rgbGreen = (BYTE)(src.g * 255);
dst.rgbRed = (BYTE)(src.r * 255);
dst.rgbReserved = 255;
CHECK(FreeImage_SetPixelColor(bitmap, x, y, &dst));
}
}
CHECK(FreeImage_Save(FIF_BMP, bitmap, filename, BMP_DEFAULT));
ret = true;
Exit0:
if (bitmap)
FreeImage_Unload(bitmap);
return ret;
}
示例14: FreeImage_Initialise
void Film::output(string path){
int maxIntensity = 255;
int bpp = 24;
RGBQUAD color;
FreeImage_Initialise();
FIBITMAP* bitmap = FreeImage_Allocate(sceneWidth,
sceneHeight,
bpp);
for(int h = 0; h < sceneHeight; h++){
vector<Color> row = pixelData[h];
for(int w = 0; w < sceneWidth; w++){
Color pixelColor = row[w];
color.rgbRed = pixelColor.getR() * maxIntensity;
color.rgbGreen = pixelColor.getG() * maxIntensity;
color.rgbBlue = pixelColor.getB() * maxIntensity;
FreeImage_SetPixelColor(bitmap, w, h, &color);
}
}
if (FreeImage_Save(FIF_PNG, bitmap, path.c_str(), 0)) {
cout << "Image saved to " << path << endl;
cout << sceneWidth << endl;
}
else {
cerr << "Couldn't save image to " << path << endl;
exit(1);
}
FreeImage_DeInitialise();
}
示例15: FreeImage_Initialise
void pre_lzw::do_lzw(const QDir & d){
FreeImage_Initialise(true);
QString label_out = "";
QString dst = ui.lineEdit_2->text();
QString d_src = d.path();
QString serial_str = d_src.right(5);
QDir dst_dir(dst);
dst_dir.mkdir(serial_str);
QString image_name = "", image_name_path(""), saved_name("");
int dot_pos = 0;
QFileInfoList handled_images = d.entryInfoList();
QList<QFileInfo>::iterator images_iter = handled_images.begin();
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
for(; images_iter < handled_images.end(); ++images_iter){
image_name_path = (*images_iter).absoluteFilePath();
if((*images_iter).isDir()){
continue;
}
FIBITMAP *handled_image = 0;
image_name = (*images_iter).fileName();
dot_pos = image_name.indexOf(".");
saved_name = dst + "\\" + serial_str + "\\" + image_name.left(dot_pos) + "_c.tif";
label_out += saved_name + "\n";
fif = FreeImage_GetFileType(image_name_path.toStdString().c_str());
handled_image = FreeImage_Load(fif, image_name_path.toStdString().c_str());
FreeImage_Save(FIF_TIFF, handled_image, saved_name.toStdString().c_str(), TIFF_LZW);
FreeImage_Unload(handled_image);
}
// ui.label->setText(label_out);
FreeImage_DeInitialise();
}