/*! loads an image from a file with auto-detection of format */ Ref<Image> loadImageFromDisk(const FileName& fileName) try { std::string ext = std::strlwr(fileName.ext()); #ifdef USE_OPENEXR if (ext == "exr" ) return loadExr(fileName); #endif #ifdef USE_IMAGEMAGICK if (ext == "bmp" ) return loadMagick(fileName); if (ext == "gif" ) return loadMagick(fileName); if (ext == "png" ) return loadMagick(fileName); if (ext == "tga" ) return loadMagick(fileName); if (ext == "tif" ) return loadMagick(fileName); if (ext == "tiff") return loadMagick(fileName); #endif #ifdef USE_LIBJPEG if (ext == "jpg" ) return loadJPEG(fileName); #endif if (ext == "pfm" ) return loadPFM(fileName); if (ext == "ppm" ) return loadPPM(fileName); throw std::runtime_error("image format " + ext + " not supported"); } catch (const std::exception& e) { std::cout << "cannot read file " << fileName << ": " << e.what() << std::endl; return null; }
void Image::initialise(const char * inputImage) { this->buffer = loadPFM(inputImage, width, height, numComponents); cdfX = new uint[CDFRESOLUTION]; for (uint i = 0; i < CDFRESOLUTION; ++i) { cdfX[i] = 0.0; } cdfY = new uint*[width]; for (uint i = 0; i < width; ++i) { cdfY[i] = new uint[CDFRESOLUTION]; for (uint j = 0; j < CDFRESOLUTION; ++j) { cdfY[i][j] = 0.0; } } }
void LoadAndSavePFM(const char *image_in, const char *image_out) { float *img_in = loadPFM(image_in, width, height, numComponents); float *img_out = new float [width*height*numComponents]; for ( uint i = 0 ; i < height ; ++i ) // height { for ( uint j = 0 ; j < width ; ++j ) // width { for ( uint k = 0 ; k < numComponents ; ++k ) // color channels - 3 for RGB images { uint index = i*width*numComponents + j*numComponents + k; //index within the image img_out[index] = img_in[index]; //R img_out[index + 1] = img_in[index + 1];//G img_out[index + 2] = img_in[index + 2];//B } } } WritePFM(image_out, width, height, numComponents, img_out); }
void LoadPFMAndSavePPM(const char *image_in, const char *image_out) { float *img_in = loadPFM(image_in, width, height, numComponents); unsigned char *img_out = new unsigned char [width*height*numComponents]; for ( uint i = 0 ; i < height ; ++i ) // height { for ( uint j = 0 ; j < width ; ++j ) // width { for ( uint k = 0 ; k < numComponents ; ++k ) // color channels - 3 for RGB images { uint index = i*width*numComponents + j*numComponents + k; //index within the image //typecast 0.0f -> 1.0f values to the 0 - 255 range img_out[index] = static_cast<unsigned char>(img_in[index]*255.0f); //R img_out[index + 1] = static_cast<unsigned char>(img_in[index + 1]*255.0f);//G img_out[index + 2] = static_cast<unsigned char>(img_in[index + 2]*255.0f);//B } } } WritePNM(image_out, width, height, numComponents, img_out); }
int main(int count, char** argv) { unsigned int i; // all for CW1 // printf("----------------------------- HDR ----------------------------------\n\n"); // char* imgdir = "/Users/paul/Dropbox/Imperial/advanced-graphics/HW1/CO417-HW1/Memorial/"; // // // applying HDR to original images // char fileOutputNamePFM[1024]; // char fileOutputNamePPM[1024]; // concatenate(imgdir, "memorial_hdr.pfm", fileOutputNamePFM); // concatenate(imgdir, "memorial_hdr.ppm", fileOutputNamePPM); // FP_IMG* hdrImage = (FP_IMG*) malloc(sizeof(FP_IMG)); // makeHDRImage(imgdir, hdrImage); // WritePFM(fileOutputNamePFM, hdrImage); // LoadPFMAndSavePPM(fileOutputNamePFM, fileOutputNamePPM); // // // applying linear tone-mapping to HDR image // char toneMappedFilenamePFM[1024]; // char toneMappedFilenamePPM[1024]; // concatenate(imgdir, "memorial_tonemap.pfm", toneMappedFilenamePFM); // concatenate(imgdir, "memorial_tonemap.ppm", toneMappedFilenamePPM); // FP_IMG* toneMappedHDR = (FP_IMG*) malloc(sizeof(FP_IMG)); // toneMap(hdrImage, toneMappedHDR); // WritePFM(toneMappedFilenamePFM, toneMappedHDR); // LoadPFMAndSavePPM(toneMappedFilenamePFM, toneMappedFilenamePPM); // // // applying brightening to tone-mapped // char toneMappedBrightenedFilenamePFM[1024]; // char toneMappedBrightenedFilenamePPM[1024]; // concatenate(imgdir, "memorial_tm_brighter.pfm", toneMappedBrightenedFilenamePFM); // concatenate(imgdir, "memorial_tm_brighter.ppm", toneMappedBrightenedFilenamePPM); // FP_IMG* brighterHDRImage = (FP_IMG*) malloc(sizeof(FP_IMG)); // brightenPFM(toneMappedHDR, brighterHDRImage, 5000); // WritePFM(toneMappedBrightenedFilenamePFM, brighterHDRImage); // LoadPFMAndSavePPM(toneMappedBrightenedFilenamePFM, toneMappedBrightenedFilenamePPM); // // // applying gamma to brighened image // char gammaAppliedPFM[1024]; // char gammaAppliedPPM[1024]; // concatenate(imgdir, "memorial_gamma.pfm", gammaAppliedPFM); // concatenate(imgdir, "memorial_gamma.ppm", gammaAppliedPPM); // applyGamma(brighterHDRImage, 2.2); // WritePFM(gammaAppliedPFM, brighterHDRImage); // LoadPFMAndSavePPM(gammaAppliedPFM, gammaAppliedPPM); // // // printf("------------------------------ IBL ----------------------------------\n\n"); // // char* grace_imgdir = "/Users/paul/Dropbox/Imperial/advanced-graphics/HW1/CO417-HW1/GraceCathedral/"; // char ibl_original[1024]; // concatenate(grace_imgdir, "grace_latlong.pfm", ibl_original); // FP_IMG* relitImage = (FP_IMG*) malloc(sizeof(FP_IMG)); // generateRelitSphere(ibl_original, relitImage, 511, grace_imgdir); // // char EMSpherePFM[1024]; // char EMSpherePPM[1024]; // concatenate(grace_imgdir, "latlong_em.pfm", EMSpherePFM); // concatenate(grace_imgdir, "latlong_em.ppm", EMSpherePPM); // WritePFM(EMSpherePFM, relitImage); // LoadPFMAndSaveClampedPPM(EMSpherePFM, EMSpherePPM, 1.0); //// printImageData((void*)relitImage->data, 511, 511, 3, 1); // // printf("\n----------------------------- done --------------------------------\n\n"); // all for CW2 srand((unsigned int) time(NULL)); char* graceEMDir ="/Users/paul/Dropbox/Imperial/advanced-graphics/GraceCathedral/"; char graceEMPath[1024]; concatenate(graceEMDir, "grace_latlong.pfm", graceEMPath); char pfmFileName[1024], ppmFileName[1024]; char ppmPath[1024], pfmPath[1024]; FP_IMG* grace_em = (FP_IMG*) malloc(sizeof(FP_IMG)); loadPFM(graceEMPath, grace_em); // WritePFM("/Users/paul/Destop.test.pfm", grace_em); // LoadPFMAndSavePPM("/Users/paul/Destop.test.pfm", "/Users/paul/Destop.test.ppm"); FP_IMG* cdf_sampled = (FP_IMG*) malloc(sizeof(FP_IMG)); FP_IMG* phong_sampled = (FP_IMG*) malloc(sizeof(FP_IMG)); int nums[] = {64, 256, 1024}; for ( i = 0; i < 3; ++i ) { char buff[20], buff2[20]; sprintf(buff, "%d.pfm", nums[i]); sprintf(buff2, "%d.ppm", nums[i]); generateCDFSamples(grace_em, cdf_sampled, nums[i]); concatenate("grace_cdf_sampled", buff, pfmFileName); concatenate(graceEMDir, pfmFileName, pfmPath); concatenate("grace_cdf_sampled", buff2, ppmFileName); concatenate(graceEMDir, ppmFileName, ppmPath); WritePFM(pfmPath, cdf_sampled); LoadPFMAndSavePPM(pfmPath, ppmPath); generatePhongSamples(grace_em, phong_sampled, nums[i]); } cleanupFP(cdf_sampled); cleanupFP(grace_em); return 0; }
void TextureLoader::load( const std::string& _path, const FILE_FORMAT _fileFormat ) { // argument checks if ( _path.empty() ) GEM_ERROR( "Path argument is empty." ); // always create new if ( isLoaded_ ) clear(); // local variables FILE_FORMAT fileFormat = _fileFormat; std::string path = _path; // split path std::string dir, name, ext; splitPath( path, &dir, &name, &ext ); // Tell the user that we are trying to load the file GEM_CONSOLE( "Loading texture " + name + (ext.empty() ? "" : ".") + ext ); // Determine file format from extension if ( fileFormat == FILE_FORMAT_NONE ) { if ( ext == "bmp" ) { fileFormat = FILE_FORMAT_BMP; } else if ( ext == "pfm" ) { fileFormat = FILE_FORMAT_PFM; } else if ( ext == "dds" ) { fileFormat = FILE_FORMAT_DDS; } } // activate the right file loader depending on file type try { switch ( fileFormat ) { case FILE_FORMAT_BMP: loadBMP( path ); break; case FILE_FORMAT_PFM: loadPFM( path ); break; case FILE_FORMAT_DDS: loadDDS( path ); break; default: GEM_THROW( "Unsupported file type ." + ext ); break; } } catch( const std::exception& e ) { clear(); GEM_ERROR( e.what() ); } // we got this far, so we are ok to setup member variables path_ = path; fileFormat_ = fileFormat; isLoaded_ = true; }
void Image::initialise(const char * inputImage){ this->buffer = loadPFM(inputImage, width, height, numComponents); }