int main(int argc, char *argv[]) { // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_Initialise(); #endif // FREEIMAGE_LIB // initialize FreeImage error handler FreeImage_SetOutputMessage(MyMessageFunc); // print version & copyright infos cout << "FreeImage " << FreeImage_GetVersion() << "\n"; cout << FreeImage_GetCopyrightMessage() << "\n\n"; // Print input formats (including external plugins) known by the library fstream importFile("fif_import.csv", ios::out); PrintImportFormats(importFile); importFile.close(); // Print output formats (including plugins) known by the library // for each export format, supported bitdepths are given fstream exportFile("fif_export.csv", ios::out); PrintExportFormats(exportFile); exportFile.close(); // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_DeInitialise(); #endif // FREEIMAGE_LIB return 0; }
int main(int argc, char *argv[]) { char *input_filename = "images\\input.tif"; char *output_filename = "images\\clone.tif"; // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_Initialise(); #endif // FREEIMAGE_LIB // initialize our own FreeImage error handler FreeImage_SetOutputMessage(MyMessageFunc); // Copy 'input.tif' to 'clone.tif' CloneMultiPage(FIF_TIFF, input_filename, output_filename, 0); // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_DeInitialise(); #endif // FREEIMAGE_LIB return 0; }
//--------------------------------------------------------------------- DataStreamPtr FreeImageCodec::code(MemoryDataStreamPtr& input, Codec::CodecDataPtr& pData) const { // Set error handler FreeImage_SetOutputMessage(FreeImageSaveErrorHandler); FIBITMAP* fiBitmap = encode(input, pData); // open memory chunk allocated by FreeImage FIMEMORY* mem = FreeImage_OpenMemory(); // write data into memory FreeImage_SaveToMemory((FREE_IMAGE_FORMAT)mFreeImageType, fiBitmap, mem); // Grab data information BYTE* data; DWORD size; FreeImage_AcquireMemory(mem, &data, &size); // Copy data into our own buffer // Because we're asking MemoryDataStream to free this, must create in a compatible way BYTE* ourData = OGRE_ALLOC_T(BYTE, size, MEMCATEGORY_GENERAL); memcpy(ourData, data, size); // Wrap data in stream, tell it to free on close DataStreamPtr outstream(OGRE_NEW MemoryDataStream(ourData, size, true)); // Now free FreeImage memory buffers FreeImage_CloseMemory(mem); // Unload bitmap FreeImage_Unload(fiBitmap); return outstream; }
bool ImageImporter::load(QIODevice *device) { d->deleteBitmap(); FreeImage_SetOutputMessage(outputMessage); FreeImageIO io; io.read_proc = readFromQIODevice; io.write_proc = 0; io.seek_proc = seekQIODevice; io.tell_proc = tellQIODevice; auto format = FreeImage_GetFileTypeFromHandle(&io, device); if (format != FIF_UNKNOWN) { int flags = 0; if (format == FIF_JPEG) flags = JPEG_ACCURATE; d->bitmap = FreeImage_LoadFromHandle(format, &io, device, flags); } if (d->bitmap) { int w = FreeImage_GetWidth(d->bitmap); int h = FreeImage_GetHeight(d->bitmap); d->size = QSize(w, h); } return d->bitmap; }
FIMULTIBITMAP* LoadAnim(const char* filename) { FreeImage_SetOutputMessage(FreeImageErrorHandler); FIMULTIBITMAP* ret(NULL); // try animated GIF { someError=false; ret = FreeImage_OpenMultiBitmap(FIF_GIF, filename, FALSE, TRUE); if (ret && !someError) { fprintf(stderr, "Loaded animated GIF..\n"); return ret; } } // try AVI { ret = ReadFromAvi(filename); if (ret) { fprintf(stderr, "Loaded AVI..\n"); return ret; } } return NULL; }
int main(int argc, char *argv[]) { // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_Initialise(); #endif // FREEIMAGE_LIB // initialize your own FreeImage error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); // print version & copyright infos printf("FreeImage version : %s", FreeImage_GetVersion()); printf("\n"); printf(FreeImage_GetCopyrightMessage()); printf("\n"); if(argc != 3) { printf("Usage : CreateAlpha <input file name> <output file name>\n"); return 0; } // Load the source image FIBITMAP *src = GenericLoader(argv[1], 0); if(src) { // Create a transparent image from the lightness image of src FIBITMAP *dst = CreateAlphaFromLightness(src); if(dst) { // Save the destination image bool bSuccess = GenericWriter(dst, argv[2], 0); if(!bSuccess) { printf("\nUnable to save %s file", argv[2]); printf("\nThis format does not support 32-bit images"); } // Free dst FreeImage_Unload(dst); } // Free src FreeImage_Unload(src); } // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_DeInitialise(); #endif // FREEIMAGE_LIB return 0; }
void Init_Inline_ImageScience_aa58() { VALUE c = rb_cObject; c = rb_const_get(c,rb_intern("ImageScience")); rb_define_method(c, "height", (VALUE(*)(ANYARGS))height, 0); rb_define_method(c, "resize", (VALUE(*)(ANYARGS))resize, 2); rb_define_method(c, "save", (VALUE(*)(ANYARGS))save, 1); rb_define_method(c, "width", (VALUE(*)(ANYARGS))width, 0); rb_define_method(c, "with_crop", (VALUE(*)(ANYARGS))with_crop, 4); rb_define_singleton_method(c, "with_image", (VALUE(*)(ANYARGS))with_image, 1); FreeImage_SetOutputMessage(FreeImageErrorHandler); }
//--------------------------------------------------------------------- void FreeImageCodec::codeToFile(MemoryDataStreamPtr& input, const String& outFileName, Codec::CodecDataPtr& pData) const { // Set error handler FreeImage_SetOutputMessage(FreeImageSaveErrorHandler); FIBITMAP* fiBitmap = encode(input, pData); FreeImage_Save((FREE_IMAGE_FORMAT)mFreeImageType, fiBitmap, outFileName.c_str()); FreeImage_Unload(fiBitmap); }
//--------------------------------------------------------------------- void FreeImageCodec::startup(void) { FreeImage_Initialise(false); LogManager::getSingleton().logMessage( LML_NORMAL, "FreeImage version: " + String(FreeImage_GetVersion())); LogManager::getSingleton().logMessage( LML_NORMAL, FreeImage_GetCopyrightMessage()); // Register codecs StringUtil::StrStreamType strExt; strExt << "Supported formats: "; bool first = true; for (int i = 0; i < FreeImage_GetFIFCount(); ++i) { // Skip DDS codec since FreeImage does not have the option // to keep DXT data compressed, we'll use our own codec if ((FREE_IMAGE_FORMAT)i == FIF_DDS) continue; String exts(FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i)); if (!first) { strExt << ","; } first = false; strExt << exts; // Pull off individual formats (separated by comma by FI) StringVector extsVector = StringUtil::split(exts, ","); for (StringVector::iterator v = extsVector.begin(); v != extsVector.end(); ++v) { ImageCodec* codec = OGRE_NEW FreeImageCodec(*v, i); msCodecList.push_back(codec); Codec::registerCodec(codec); } } LogManager::getSingleton().logMessage( LML_NORMAL, strExt.str()); // Set error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); }
int main(int argc, char *argv[]) { unsigned width = 512; unsigned height = 512; #if defined(_DEBUG) && defined(WIN32) // check for memory leaks at program exit (after the 'return 0') // through a call to _CrtDumpMemoryLeaks // note that in debug mode, objects allocated with the new operator // may be destroyed *after* the end of the main function. _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); #endif #if defined(FREEIMAGE_LIB) || !defined(WIN32) FreeImage_Initialise(); #endif // initialize our own FreeImage error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); // test plugins capabilities showPlugins(); // test the clone function testAllocateCloneUnload("exif.jpg"); // test internal image types testImageType(width, height); // test loading / saving / converting image types using the TIFF plugin testImageTypeTIFF(width, height); // test multipage creation testBuildMPage("sample.png", "sample.ico", FIF_ICO, 24); testBuildMPage("sample.png", "sample.tif", FIF_TIFF, 24); //testBuildMPage("sample.png", "sample.gif", FIF_GIF, 8); // test multipage cache testMPageCache("sample.png"); // test memory IO testMemIO("sample.png"); // test JPEG lossless transform & cropping testJPEG(); #if defined(FREEIMAGE_LIB) || !defined(WIN32) FreeImage_DeInitialise(); #endif return 0; }
BOOL CBigle3DApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. // call this ONLY when linking with FreeImage as a static library //FreeImage_Initialise(); // initialize your own FreeImage error handler FreeImage_SetOutputMessage(MyMessageFunc); CStartPP pp1; CFondPP pp2; CReliefPP pp3; CCreateImgPP pp4; CAboutPP pp5; pp1.m_psp.dwFlags -= PSP_HASHELP; pp2.m_psp.dwFlags -= PSP_HASHELP; pp3.m_psp.dwFlags -= PSP_HASHELP; pp4.m_psp.dwFlags -= PSP_HASHELP; pp5.m_psp.dwFlags -= PSP_HASHELP; m_ps.AddPage( &pp1 ); m_ps.AddPage( &pp2 ); m_ps.AddPage( &pp3 ); m_ps.AddPage( &pp4 ); m_ps.AddPage( &pp5 ); m_ps.SetWizardMode(); m_pMainWnd = &m_ps; int nResponse = (int)m_ps.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } FreeImage_DeInitialise(); // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
moTextureManager::moTextureManager() { SetType( MO_OBJECT_RESOURCE ); SetResourceType( MO_RESOURCETYPE_TEXTURE ); SetName("Texture Manager"); // In your main program ... FreeImage_SetOutputMessage(FreeImageErrorHandler); m_glmanager = NULL; m_fbmanager = NULL; m_textures_buffers.Init(0,NULL); }
/// Load a gray-scale image from disk. void loadImage(const std::string & rFileName, ImageCPU_8u_C1 & rImage) { // set your own FreeImage error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); FREE_IMAGE_FORMAT eFormat = FreeImage_GetFileType(rFileName.c_str()); // no signature? try to guess the file format from the file extension if (eFormat == FIF_UNKNOWN) eFormat = FreeImage_GetFIFFromFilename(rFileName.c_str()); NPP_ASSERT(eFormat != FIF_UNKNOWN); // check that the plugin has reading capabilities ... FIBITMAP * pBitmap; if (FreeImage_FIFSupportsReading(eFormat)) pBitmap = FreeImage_Load(eFormat, rFileName.c_str()); NPP_ASSERT(pBitmap != 0); // make sure this is an 8-bit single channel image NPP_ASSERT(FreeImage_GetColorType(pBitmap) == FIC_MINISBLACK); NPP_ASSERT(FreeImage_GetBPP(pBitmap) == 8); // create an ImageCPU to receive the loaded image data ImageCPU_8u_C1 oImage(FreeImage_GetWidth(pBitmap), FreeImage_GetHeight(pBitmap)); // Copy the FreeImage data into the new ImageCPU unsigned int nSrcPitch = FreeImage_GetPitch(pBitmap); const Npp8u * pSrcLine = FreeImage_GetBits(pBitmap) + nSrcPitch * (FreeImage_GetHeight(pBitmap) -1); Npp8u * pDstLine = oImage.data(); unsigned int nDstPitch = oImage.pitch(); for (size_t iLine = 0; iLine < oImage.height(); ++iLine) { memcpy(pDstLine, pSrcLine, oImage.width() * sizeof(Npp8u)); pSrcLine -= nSrcPitch; pDstLine += nDstPitch; } // swap the user given image with our result image, effecively // moving our newly loaded image data into the user provided shell oImage.swap(rImage); }
/* MainApp::initLogFile * Sets up the SLADE log file *******************************************************************/ void MainApp::initLogFile() { // Set wxLog target(s) wxLog::SetActiveTarget(new SLADELog()); FILE* log_file = fopen(CHR(appPath("slade3.log", DIR_DATA)), "wt"); new wxLogChain(new wxLogStderr(log_file)); // Write logfile header string year = wxNow().Right(4); wxLogMessage("SLADE - It's a Doom Editor"); wxLogMessage("Version %s", Global::version); wxLogMessage("Written by Simon Judd, 2008-%s", year); #ifdef SFML_VERSION_MAJOR wxLogMessage("Compiled with wxWidgets %i.%i.%i and SFML %i.%i", wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, SFML_VERSION_MAJOR, SFML_VERSION_MINOR); #else wxLogMessage("Compiled with wxWidgets %i.%i.%i", wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER); #endif wxLogMessage("--------------------------------"); // Set up FreeImage to use our log: FreeImage_SetOutputMessage(FreeImageErrorHandler); }
//--------------------------------------------------------------------- String FreeImageCodec::magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const { // Set error handler FreeImage_SetOutputMessage(FreeImageLoadErrorHandler); FIMEMORY* fiMem = FreeImage_OpenMemory((BYTE*)magicNumberPtr, static_cast<DWORD>(maxbytes)); FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(fiMem, (int)maxbytes); FreeImage_CloseMemory(fiMem); if (fif != FIF_UNKNOWN) { String ext(FreeImage_GetFormatFromFIF(fif)); StringUtil::toLowerCase(ext); return ext; } else { return StringUtil::BLANK; } }
bool ImageExporter::save(QIODevice *device) { if (!d->bitmap) return false; if (d->format == FIF_UNKNOWN) return false; int flags = 0; if (d->format == FIF_JPEG) flags = d->quality; FreeImage_SetOutputMessage(outputMessage); FreeImageIO io; io.read_proc = 0; io.write_proc = writeToQIODevice; io.seek_proc = seekQIODevice; io.tell_proc = tellQIODevice; return FreeImage_SaveToHandle(d->format, d->bitmap, &io, device, flags); }
FreeImageImageCodec::FreeImageImageCodec() : ImageCodec("FreeImageCodec - FreeImage based image codec") { FreeImage_Initialise(true); FreeImage_SetOutputMessage(&FreeImageErrorHandler); // Getting extensions for (int i = 0; i < FreeImage_GetFIFCount(); ++i) { String exts(FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i)); // Replace commas with spaces for (size_t i = 0; i < exts.length(); ++i) if (exts[i] == ',') exts[i] = ' '; // Add space after existing extensions if (!d_supportedFormat.empty()) d_supportedFormat += ' '; d_supportedFormat += exts; } }
int main(int argc, char *argv[]) { unsigned width = 512; unsigned height = 512; #if defined(_DEBUG) && defined(WIN32) // check for memory leaks at program exit (after the 'return 0') // through a call to _CrtDumpMemoryLeaks // note that in debug mode, objects allocated with the new operator // may be destroyed *after* the end of the main function. _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); #endif #if defined(FREEIMAGE_LIB) || !defined(WIN32) FreeImage_Initialise(); #endif // initialize our own FreeImage error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); // test plugins capabilities showPlugins(); // test the clone function testAllocateCloneUnload("exif.jpg"); // test internal image types testImageType(width, height); // test loading / saving / converting image types using the TIFF plugin testImageTypeTIFF(width, height); // test memory IO testMemIO("sample.png"); testMemIO("exif.jxr"); // test multipage functions testMultiPage("sample.png"); // test multipage streaming testStreamMultiPage("sample.tif"); // test multipage streaming with memory IO testMultiPageMemory("sample.tif"); // test JPEG lossless transform & cropping testJPEG(); // test get/set channel testImageChannels(width, height); // test loading header only testHeaderOnly(); // test Exif raw metadata loading & saving testExifRaw(); // test thumbnail functions testThumbnail("exif.jpg", 0); // test wrapped user buffer testWrappedBuffer("exif.jpg", 0); #if defined(FREEIMAGE_LIB) || !defined(WIN32) FreeImage_DeInitialise(); #endif return 0; }
int main(int argc, char *argv[]) { const char *input_dir = "d:\\images\\"; FIBITMAP *dib = NULL; int id = 1; // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_Initialise(); #endif // FREEIMAGE_LIB // initialize your own FreeImage error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); // print version & copyright infos printf(FreeImage_GetVersion()); printf("\n"); printf(FreeImage_GetCopyrightMessage()); printf("\n"); // open the log file FILE *log_file = fopen("log_file.txt", "w"); // batch convert all supported bitmaps _finddata_t finddata; long handle; char image_path[MAX_PATH]; // scan all files strcpy(image_path, input_dir); strcat(image_path, "*.*"); if ((handle = _findfirst(image_path, &finddata)) != -1) { do { // make a path to a directory char *directory = new char[MAX_PATH]; strcpy(directory, input_dir); strcat(directory, finddata.name); // make a unique filename char *unique = new char[128]; itoa(id, unique, 10); strcat(unique, ".png"); // open and load the file using the default load option dib = GenericLoader(directory, 0); if (dib != NULL) { // save the file as PNG bool bSuccess = GenericWriter(dib, unique, PNG_DEFAULT); // free the dib FreeImage_Unload(dib); if(bSuccess) { fwrite(unique, strlen(unique), 1, log_file); } else { strcpy(unique, "FAILED"); fwrite(unique, strlen(unique), 1, log_file); } fwrite(" >> ", 4, 1, log_file); fwrite(directory, strlen(directory), 1, log_file); fwrite("\n", 1, 1, log_file); id++; } delete [] unique; delete [] directory; } while (_findnext(handle, &finddata) == 0); _findclose(handle); } fclose(log_file); // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_DeInitialise(); #endif // FREEIMAGE_LIB return 0; }
int main(int argc, char *argv[]) { printf("%s Starting...\n\n", argv[0]); try { std::string sFilename; char *filePath = sdkFindFilePath("Lena.pgm", argv[0]); if (filePath) { sFilename = filePath; } else { printf("Error unable to find Lena.pgm\n"); exit(EXIT_FAILURE); } // set your own FreeImage error handler FreeImage_SetOutputMessage(FreeImageErrorHandler); cudaDeviceInit(argc, (const char **)argv); // Min spec is SM 1.0 devices if (printfNPPinfo(argc, argv, 1, 0) == false) { cudaDeviceReset(); exit(EXIT_SUCCESS); } if (argc > 1) { sFilename = argv[1]; } // if we specify the filename at the command line, then we only test sFilename // otherwise we will check both sFilename[0,1] int file_errors = 0; std::ifstream infile(sFilename.data(), std::ifstream::in); if (infile.good()) { std::cout << "freeImageInteropNPP opened: <" << sFilename.data() << "> successfully!" << std::endl; file_errors = 0; infile.close(); } else { std::cout << "freeImageInteropNPP unable to open: <" << sFilename.data() << ">" << std::endl; file_errors++; infile.close(); } if (file_errors > 0) { exit(EXIT_FAILURE); } std::string sResultFilename = sFilename; std::string::size_type dot = sResultFilename.rfind('.'); 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); }
int main(int argc, char *argv[]) { #if defined(__GNUC__) && !defined(__CYGWIN__) set_terminate(SLGTerminate); #endif // This is required to run AMD GPU profiler //XInitThreads(); luxrays::sdl::LuxRaysSDLDebugHandler = SDLDebugHandler; try { // Initialize FreeImage Library FreeImage_Initialise(TRUE); FreeImage_SetOutputMessage(FreeImageErrorHandler); bool batchMode = false; bool telnetServerEnabled = false; Properties cmdLineProp; string configFileName; for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { // I should check for out of range array index... if (argv[i][1] == 'h') { SLG_LOG("Usage: " << argv[0] << " [options] [configuration file]" << endl << " -o [configuration file]" << endl << " -f [scene file]" << endl << " -w [window width]" << endl << " -e [window height]" << endl << " -t [halt time in secs]" << endl << " -T <enable the telnet server>" << endl << " -D [property name] [property value]" << endl << " -d [current directory path]" << endl << " -m Makes the mouse operations work in \"grab mode\"" << endl << " -h <display this help and exit>"); exit(EXIT_SUCCESS); } else if (argv[i][1] == 'o') { if (configFileName.compare("") != 0) throw runtime_error("Used multiple configuration files"); configFileName = string(argv[++i]); } else if (argv[i][1] == 'e') cmdLineProp.SetString("image.height", argv[++i]); else if (argv[i][1] == 'w') cmdLineProp.SetString("image.width", argv[++i]); else if (argv[i][1] == 'f') cmdLineProp.SetString("scene.file", argv[++i]); else if (argv[i][1] == 't') cmdLineProp.SetString("batch.halttime", argv[++i]); else if (argv[i][1] == 'T') telnetServerEnabled = true; else if (argv[i][1] == 'm') mouseGrabMode = true; else if (argv[i][1] == 'D') { cmdLineProp.SetString(argv[i + 1], argv[i + 2]); i += 2; } else if (argv[i][1] == 'd') boost::filesystem::current_path(boost::filesystem::path(argv[++i])); else { SLG_LOG("Invalid option: " << argv[i]); exit(EXIT_FAILURE); } } else { string s = argv[i]; if ((s.length() >= 4) && (s.substr(s.length() - 4) == ".cfg")) { if (configFileName.compare("") != 0) throw runtime_error("Used multiple configuration files"); configFileName = s; } else throw runtime_error("Unknown file extension: " + s); } } if (configFileName.compare("") == 0) configFileName = "scenes/luxball/luxball.cfg"; RenderConfig *config = new RenderConfig(&configFileName, &cmdLineProp); const unsigned int halttime = config->cfg.GetInt("batch.halttime", 0); const unsigned int haltspp = config->cfg.GetInt("batch.haltspp", 0); const float haltthreshold = config->cfg.GetFloat("batch.haltthreshold", -1.f); if ((halttime > 0) || (haltspp > 0) || (haltthreshold >= 0.f)) batchMode = true; else batchMode = false; if (batchMode) { session = new RenderSession(config); // Check if I have to do tile rendering if (config->cfg.IsDefined("batch.tile")) return BatchTileMode(haltspp, haltthreshold); else return BatchSimpleMode(halttime, haltspp, haltthreshold); } else { // It is important to initialize OpenGL before OpenCL // (for OpenGL/OpenCL inter-operability) u_int width, height; config->GetScreenSize(&width, &height); InitGlut(argc, argv, width, height); session = new RenderSession(config); // Start the rendering session->Start(); if (telnetServerEnabled) { TelnetServer telnetServer(18081, session); RunGlut(); } else RunGlut(); } #if !defined(LUXRAYS_DISABLE_OPENCL) } catch (cl::Error err) { SLG_LOG("OpenCL ERROR: " << err.what() << "(" << luxrays::utils::oclErrorString(err.err()) << ")"); return EXIT_FAILURE; #endif } catch (runtime_error err) { SLG_LOG("RUNTIME ERROR: " << err.what()); return EXIT_FAILURE; } catch (exception err) { SLG_LOG("ERROR: " << err.what()); return EXIT_FAILURE; } return EXIT_SUCCESS; }
MainWindow::MainWindow() : playerCosmetics(18), civilianCosmetics(12) { QSettings::setDefaultFormat(QSettings::IniFormat); QCoreApplication::setOrganizationName("TEMP_ORG"); //TODO: Add a proper organization name. QCoreApplication::setOrganizationDomain("TEMP_ORG.com"); QCoreApplication::setApplicationName("Driver Level Editor"); levelHasChanged = false; d3dHasChanged = false; civCosHasChanged = false; playerCosHasChanged = false; civDentHasChanged = false; playerDentHasChanged = false; wdfHasChanged = false; mainLog.createLogfile("debug.txt"); levelLog.createLogfile("levelDebug.txt"); levelLog.setLogPriority(DEBUG_LEVEL_RIDICULOUS); level.setLogger(&levelLog); levelTextures.setTextureProvider(&level.textures); levelTextures.setD3D(&d3d); if(QDir("./settings").exists()) { mainLog.Log("Settings folder exists in working directory, settings will be saved portably."); if(!QDir("./settings/User").exists()) QDir().mkdir("./settings/User"); if(!QDir("./settings/System").exists()) QDir().mkdir("./settings/System"); QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, "./settings/User"); QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "./settings/System"); } else mainLog.Log("No settings folder found. Saving settings locally."); #ifdef DEBUG_ENABLED mainLog.Log("Executable is a debug build."); setWindowTitle(QApplication::translate("windowtitle", "Driver Level Editor [DEBUG][*]")); #else mainLog.Log("Executable is a release build."); setWindowTitle(QApplication::translate("windowtitle", "Driver Level Editor[*]")); #endif #ifdef FREEIMAGE_LIB mainLog.Log("FreeImage is static linked."); FreeImage_Initialise(); #endif FreeImageLogger = &mainLog; FreeImage_SetOutputMessage(FreeImageErrorHandler); mainLog.Log("FreeImage version: %s",FreeImage_GetVersion()); mainLog.Log("%s",FreeImage_GetCopyrightMessage()); mainLog.Log("Initializing widgets..."); centralWindow = new QStackedWidget(this); startPage = new StartScreen(this); customLevelDialog = new CustomLevelDialog(this); aboutDialog = new AboutDialog(this); //TODO: Enter final about information aboutDialog->setDescription(tr("Description goes here!")); aboutDialog->setInformation(tr("Information goes here!")); aboutDialog->setThanks(tr("Thanks goes here!")); aboutDialog->setImage("data/about.png"); modelViewPanel = new ModelViewPanel(this, NULL, 0, &mainLog); modelViewPanel->setLevel(&level); modelViewPanel->setTextureProvider(&levelTextures); definitionEditor = new TextureDefinitionEditor(this, modelViewPanel->glViewer()); //Don't forget, this needs a share widget when model viewing is done definitionEditor->setLevel(&level); definitionEditor->setTextureProvider(&levelTextures); definitionEditor->overlay()->makeCurrent(); textureBrowser = new TextureBrowser(this, modelViewPanel->glViewer()); textureBrowser->setLevel(&level); textureBrowser->setTextureList(&levelTextures); textureBrowser->setD3D(&d3d); levelLoader = new LevelLoadingDialog(this); levelLoader->setLevel(&level); levelLoader->setD3D(&d3d); levelLoader->setWheelDefinitions(&wheels); levelLoader->setPlayerCosmetics(&playerCosmetics); levelLoader->setCivilianCosmetics(&civilianCosmetics); levelLoader->setPlayerDenting(&playerDenting); levelLoader->setCivilianDenting(&civilianDenting); levelLoader->setLog(&mainLog); saveDialog = new SaveAsDialog(this); connect(saveDialog, SIGNAL(saveLevel(QString,unsigned int)), this, SLOT(saveLevel(QString,unsigned int))); connect(saveDialog, SIGNAL(saveD3D(QString)), this, SLOT(saveD3D(QString))); connect(saveDialog, SIGNAL(savePlayerDenting(QString)), this, SLOT(savePlayerDenting(QString))); connect(saveDialog, SIGNAL(saveCivilianDenting(QString)), this, SLOT(saveCivilianDenting(QString))); connect(saveDialog, SIGNAL(savePlayerCosmetics(QString)), this, SLOT(savePlayerCosmetics(QString))); connect(saveDialog, SIGNAL(saveCivilianCosmetics(QString)), this, SLOT(saveCivilianCosmetics(QString))); connect(saveDialog, SIGNAL(saveWheelDefinitions(QString)), this, SLOT(saveWheelDefinitions(QString))); createActions(); createMenus(); textureBrowser->setupEditMenu(editMenu); setConvenienceActionsEnabled(false); centralWindow->addWidget(startPage); centralWindow->addWidget(modelViewPanel); centralWindow->addWidget(textureBrowser); centralWindow->addWidget(definitionEditor); statusBar(); setCentralWidget(centralWindow); mainLog.Log("Finished initializing widgets."); loadSettings(); show(); };
//--------------------------------------------------------------------- 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 = NULL; if (FreeImage_IsTransparent(fiBitmap)) { // convert to 32 bit to preserve the transparency // (the alpha byte will be 0 if pixel is transparent) newBitmap = FreeImage_ConvertTo32Bits(fiBitmap); } else { // no transparency - only 3 bytes are needed 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; #else imgData->format = PF_BYTE_BGR; #endif break; case 32: #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB imgData->format = PF_BYTE_RGBA; #else imgData->format = PF_BYTE_BGRA; #endif break; }; break; case FIT_UINT16: case FIT_INT16: // 16-bit greyscale imgData->format = PF_L16; break; case FIT_FLOAT: // Single-component floating point data imgData->format = PF_FLOAT32_R; break; case FIT_RGB16: imgData->format = PF_SHORT_RGB; break; case FIT_RGBA16: imgData->format = PF_SHORT_RGBA; break; case FIT_RGBF: imgData->format = PF_FLOAT32_RGB; break; case FIT_RGBAF: imgData->format = PF_FLOAT32_RGBA; break; }; unsigned char* srcData = FreeImage_GetBits(fiBitmap); unsigned srcPitch = FreeImage_GetPitch(fiBitmap); // Final data - invert image and trim pitch at the same time size_t dstPitch = imgData->width * PixelUtil::getNumElemBytes(imgData->format); imgData->size = dstPitch * imgData->height; // Bind output buffer output.bind(OGRE_NEW MemoryDataStream(imgData->size)); uchar* pSrc; uchar* pDst = output->getPtr(); for (size_t y = 0; y < imgData->height; ++y) { pSrc = srcData + (imgData->height - y - 1) * srcPitch; memcpy(pDst, pSrc, dstPitch); pDst += dstPitch; } FreeImage_Unload(fiBitmap); FreeImage_CloseMemory(fiMem); DecodeResult ret; ret.first = output; ret.second = CodecDataPtr(imgData); return ret; }
int main(int argc, char *argv[]) { #if defined(__GNUC__) set_terminate(SLGTerminate); #endif try { cerr << "Usage: " << argv[0] << " [options] [configuration file]" << endl << " -o [configuration file]" << endl << " -f [scene file]" << endl << " -w [window width]" << endl << " -e [window height]" << endl << " -g <disable OpenCL GPU device>" << endl << " -p <enable OpenCL CPU device>" << endl << " -n [native thread count]" << endl << " -r [gpu thread count]" << endl << " -l [set high/low latency mode]" << endl << " -b <enable high latency mode>" << endl << " -s [GPU workgroup size]" << endl << " -t [halt time in secs]" << endl << " -T <enable the telnet server>" << endl << " -D [property name] [property value]" << endl << " -d [current directory path]" << endl << " -h <display this help and exit>" << endl; // Initialize FreeImage Library FreeImage_Initialise(TRUE); FreeImage_SetOutputMessage(FreeImageErrorHandler); bool batchMode = false; bool telnetServerEnabled = false; Properties cmdLineProp; for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { // I should check for out of range array index... if (argv[i][1] == 'h') exit(EXIT_SUCCESS); else if (argv[i][1] == 'o') { if (config) throw runtime_error("Used multiple configuration files"); config = new RenderingConfig(argv[++i]); } else if (argv[i][1] == 'e') cmdLineProp.SetString("image.height", argv[++i]); else if (argv[i][1] == 'w') cmdLineProp.SetString("image.width", argv[++i]); else if (argv[i][1] == 'f') cmdLineProp.SetString("scene.file", argv[++i]); else if (argv[i][1] == 'p') cmdLineProp.SetString("opencl.cpu.use", "1"); else if (argv[i][1] == 'g') cmdLineProp.SetString("opencl.gpu.use", "0"); else if (argv[i][1] == 'l') cmdLineProp.SetString("opencl.latency.mode", argv[++i]); else if (argv[i][1] == 'n') cmdLineProp.SetString("opencl.nativethread.count", argv[++i]); else if (argv[i][1] == 'r') cmdLineProp.SetString("opencl.renderthread.count", argv[++i]); else if (argv[i][1] == 's') cmdLineProp.SetString("opencl.gpu.workgroup.size", argv[++i]); else if (argv[i][1] == 't') cmdLineProp.SetString("batch.halttime", argv[++i]); else if (argv[i][1] == 'T') telnetServerEnabled = true; else if (argv[i][1] == 'D') { cmdLineProp.SetString(argv[i + 1], argv[i + 2]); i += 2; } else if (argv[i][1] == 'd') boost::filesystem::current_path(boost::filesystem::path(argv[++i])); else { cerr << "Invalid option: " << argv[i] << endl; exit(EXIT_FAILURE); } } else { string s = argv[i]; if ((s.length() >= 4) && (s.substr(s.length() - 4) == ".cfg")) { if (config) throw runtime_error("Used multiple configuration files"); config = new RenderingConfig(s); } else throw runtime_error("Unknow file extension: " + s); } } if (!config) config = new RenderingConfig("scenes/luxball/render-fast.cfg"); config->cfg.Load(cmdLineProp); const unsigned int halttime = config->cfg.GetInt("batch.halttime", 0); const unsigned int haltspp = config->cfg.GetInt("batch.haltspp", 0); if ((halttime > 0) || (haltspp > 0)) batchMode = true; else batchMode = false; if (batchMode) { config->Init(); return BatchMode(halttime, haltspp); } else { // It is important to initialize OpenGL before OpenCL unsigned int width = config->cfg.GetInt("image.width", 640); unsigned int height = config->cfg.GetInt("image.height", 480); InitGlut(argc, argv, width, height); config->Init(); if (telnetServerEnabled) { TelnetServer telnetServer(18081, config); RunGlut(); } else RunGlut(); } #if !defined(LUXRAYS_DISABLE_OPENCL) } catch (cl::Error err) { cerr << "OpenCL ERROR: " << err.what() << "(" << err.err() << ")" << endl; #endif } catch (runtime_error err) { cerr << "RUNTIME ERROR: " << err.what() << endl; } catch (exception err) { cerr << "ERROR: " << err.what() << endl; } return EXIT_SUCCESS; }
//--------------------------------------------------------------------- FIBITMAP* FreeImageCodec::encode(MemoryDataStreamPtr& input, CodecDataPtr& pData) const { // Set error handler FreeImage_SetOutputMessage(FreeImageSaveErrorHandler); FIBITMAP* ret = 0; ImageData* pImgData = static_cast< ImageData * >( pData.getPointer() ); PixelBox src(pImgData->width, pImgData->height, pImgData->depth, pImgData->format, input->getPtr()); // The required format, which will adjust to the format // actually supported by FreeImage. PixelFormat requiredFormat = pImgData->format; // determine the settings FREE_IMAGE_TYPE imageType; PixelFormat determiningFormat = pImgData->format; switch(determiningFormat) { case PF_R5G6B5: case PF_B5G6R5: case PF_R8G8B8: case PF_B8G8R8: case PF_A8R8G8B8: case PF_X8R8G8B8: case PF_A8B8G8R8: case PF_X8B8G8R8: case PF_B8G8R8A8: case PF_R8G8B8A8: case PF_A4L4: case PF_BYTE_LA: case PF_R3G3B2: case PF_A4R4G4B4: case PF_A1R5G5B5: case PF_A2R10G10B10: case PF_A2B10G10R10: // I'd like to be able to use r/g/b masks to get FreeImage to load the data // in it's existing format, but that doesn't work, FreeImage needs to have // data in RGB[A] (big endian) and BGR[A] (little endian), always. if (PixelUtil::hasAlpha(determiningFormat)) { #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB requiredFormat = PF_BYTE_RGBA; #else requiredFormat = PF_BYTE_BGRA; #endif } else { #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB requiredFormat = PF_BYTE_RGB; #else requiredFormat = PF_BYTE_BGR; #endif } // fall through case PF_L8: case PF_A8: imageType = FIT_BITMAP; break; case PF_L16: imageType = FIT_UINT16; break; case PF_SHORT_GR: requiredFormat = PF_SHORT_RGB; // fall through case PF_SHORT_RGB: imageType = FIT_RGB16; break; case PF_SHORT_RGBA: imageType = FIT_RGBA16; break; case PF_FLOAT16_R: requiredFormat = PF_FLOAT32_R; // fall through case PF_FLOAT32_R: imageType = FIT_FLOAT; break; case PF_FLOAT16_GR: case PF_FLOAT16_RGB: case PF_FLOAT32_GR: requiredFormat = PF_FLOAT32_RGB; // fall through case PF_FLOAT32_RGB: imageType = FIT_RGBF; break; case PF_FLOAT16_RGBA: requiredFormat = PF_FLOAT32_RGBA; // fall through case PF_FLOAT32_RGBA: imageType = FIT_RGBAF; break; default: OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Invalid image format", "FreeImageCodec::encode"); }; // Check support for this image type & bit depth if (!FreeImage_FIFSupportsExportType((FREE_IMAGE_FORMAT)mFreeImageType, imageType) || !FreeImage_FIFSupportsExportBPP((FREE_IMAGE_FORMAT)mFreeImageType, (int)PixelUtil::getNumElemBits(requiredFormat))) { // Ok, need to allocate a fallback // Only deal with RGBA -> RGB for now switch (requiredFormat) { case PF_BYTE_RGBA: requiredFormat = PF_BYTE_RGB; break; case PF_BYTE_BGRA: requiredFormat = PF_BYTE_BGR; break; default: break; }; } bool conversionRequired = false; unsigned char* srcData = input->getPtr(); // Check BPP unsigned bpp = static_cast<unsigned>(PixelUtil::getNumElemBits(requiredFormat)); if (!FreeImage_FIFSupportsExportBPP((FREE_IMAGE_FORMAT)mFreeImageType, (int)bpp)) { if (bpp == 32 && PixelUtil::hasAlpha(pImgData->format) && FreeImage_FIFSupportsExportBPP((FREE_IMAGE_FORMAT)mFreeImageType, 24)) { // drop to 24 bit (lose alpha) #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB requiredFormat = PF_BYTE_RGB; #else requiredFormat = PF_BYTE_BGR; #endif bpp = 24; } else if (bpp == 128 && PixelUtil::hasAlpha(pImgData->format) && FreeImage_FIFSupportsExportBPP((FREE_IMAGE_FORMAT)mFreeImageType, 96)) { // drop to 96-bit floating point requiredFormat = PF_FLOAT32_RGB; } } PixelBox convBox(pImgData->width, pImgData->height, 1, requiredFormat); if (requiredFormat != pImgData->format) { conversionRequired = true; // Allocate memory convBox.data = OGRE_ALLOC_T(uchar, convBox.getConsecutiveSize(), MEMCATEGORY_GENERAL); // perform conversion and reassign source PixelBox src(pImgData->width, pImgData->height, 1, pImgData->format, input->getPtr()); PixelUtil::bulkPixelConversion(src, convBox); srcData = static_cast<unsigned char*>(convBox.data); } ret = FreeImage_AllocateT( imageType, static_cast<int>(pImgData->width), static_cast<int>(pImgData->height), bpp); if (!ret) { if (conversionRequired) OGRE_FREE(convBox.data, MEMCATEGORY_GENERAL); OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "FreeImage_AllocateT failed - possibly out of memory. ", __FUNCTION__); } if (requiredFormat == PF_L8 || requiredFormat == PF_A8) { // Must explicitly tell FreeImage that this is greyscale by setting // a "grey" palette (otherwise it will save as a normal RGB // palettized image). FIBITMAP *tmp = FreeImage_ConvertToGreyscale(ret); FreeImage_Unload(ret); ret = tmp; } size_t dstPitch = FreeImage_GetPitch(ret); size_t srcPitch = pImgData->width * PixelUtil::getNumElemBytes(requiredFormat); // Copy data, invert scanlines and respect FreeImage pitch uchar* pSrc; uchar* pDst = FreeImage_GetBits(ret); for (size_t y = 0; y < pImgData->height; ++y) { pSrc = srcData + (pImgData->height - y - 1) * srcPitch; memcpy(pDst, pSrc, srcPitch); pDst += dstPitch; } if (conversionRequired) { // delete temporary conversion area OGRE_FREE(convBox.data, MEMCATEGORY_GENERAL); } return ret; }