bool finalizeAndSave(std::string outputPath) { if (outputPath.empty()) return false; std::cout << "finalize & save " << outputPath << std::endl; auto img = finalize(); return GenericWriter(img, outputPath, EXR_FLOAT); };
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; }
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; }
bool finalizeAndSave(const char* outputPath) { printf("finalize & safe %s\n", outputPath); FIBITMAP *img = finalize(); return GenericWriter(img, outputPath, 0); }