void image::saveImageRGB(string filename){ unsigned char* bitmapData = new unsigned char[3 * xSize * ySize]; int i = 0; //read data to buffer for stb_image output for(int y = 0; y < ySize; y++) { for(int x = 0; x < xSize; x++) { if(gamma.applyGamma){ bitmapData[i] = (unsigned char)utilityCore::clamp(applyGamma(readPixelR(x,y))*255,0,255); bitmapData[i+1] = (unsigned char)utilityCore::clamp(applyGamma(readPixelG(x,y))*255,0,255); bitmapData[i+2] = (unsigned char)utilityCore::clamp(applyGamma(readPixelB(x,y))*255,0,255); }else{ bitmapData[i] = (unsigned char)utilityCore::clamp(readPixelR(x,y)*255, 0, 255); bitmapData[i+1] = (unsigned char)utilityCore::clamp(readPixelG(x,y)*255, 0, 255); bitmapData[i+2] = (unsigned char)utilityCore::clamp(readPixelB(x,y)*255, 0, 255); } i=i+3; } } //check requested output type int imagetype = 0; //0 for png, 1 for bmp if(filename[filename.size()-1]=='\r'){ //OSX Version if(filename[filename.size()-4]=='b' && filename[filename.size()-3]=='m' && filename[filename.size()-2]=='p'){ imagetype = 1; } }else{ //Windows Version if(filename[filename.size()-3]=='b' && filename[filename.size()-2]=='m' && filename[filename.size()-1]=='p'){ imagetype = 1; } } //write output file if(imagetype==1){ stbi_write_bmp(filename.c_str(), xSize, ySize, 3, bitmapData); }else{ stbi_write_png(filename.c_str(), xSize, ySize, 3, bitmapData, xSize * 3); } }
inline void storeFramebuffer(int resultIndex, const FilePath& pngDir, const FilePath& exrDir, const FilePath& baseName, float gamma, const Framebuffer& framebuffer) { // Create output directories in case they don't exist createDirectory(pngDir.str()); createDirectory(exrDir.str()); // Path of primary output image files FilePath pngFile = pngDir + baseName.addExt(".png"); FilePath exrFile = exrDir + baseName.addExt(".exr"); // Make a copy of the image Image copy = framebuffer.getChannel(0); // Store the EXR image "as is" storeEXRImage(exrFile.str(), copy); // Post-process copy of image and store PNG file copy.flipY(); copy.divideByAlpha(); copy.applyGamma(gamma); storeImage(pngFile.str(), copy); // Store complete framebuffer as a single EXR multi layer image auto exrFramebufferFilePath = exrDir + baseName.addExt(".bnzframebuffer.exr"); storeEXRFramebuffer(exrFramebufferFilePath.str(), framebuffer); // Store complete framebuffer as PNG indivual files in a dediacted subdirectory auto pngFramebufferDirPath = pngDir + "framebuffers/"; createDirectory(pngFramebufferDirPath.str()); if(resultIndex >= 0) { pngFramebufferDirPath = pngFramebufferDirPath + toString3(resultIndex); // Split different results of the same batch in different subdirectories } createDirectory(pngFramebufferDirPath.str()); // Store each channel of the framebuffer for(auto i = 0u; i < framebuffer.getChannelCount(); ++i) { auto name = framebuffer.getChannelName(i); // Prefix by the index of the channel FilePath pngFile = pngFramebufferDirPath + FilePath(toString3(i)).addExt("_" + name + ".png"); auto copy = framebuffer.getChannel(i); copy.flipY(); copy.divideByAlpha(); copy.applyGamma(gamma); storeImage(pngFile.str(), copy); } }
void MainWindow::on_applyBrightnessButton_clicked() { emit applyBrightness(ui->brightnessSlider->value()); emit applyContrast(ui->contrastSlider->value()); emit applyGamma(ui->expSlider->value()); }