/** * @brief Adaptive logarithmic tone mapping * * Adaptive logarithmic mapping for displaying high contrast * scenes. * F. Drago, K. Myszkowski, T. Annen, and N. Chiba. In Eurographics 2003. * * This file is a part of PFSTMO package. * ---------------------------------------------------------------------- * Copyright (C) 2003,2004 Grzegorz Krawczyk * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ---------------------------------------------------------------------- * * @author Grzegorz Krawczyk, * * $Id: pfstmo_drago03.cpp,v 1.2 2007/06/14 10:40:27 gkrawczyk Exp $ */ #include #include #include #include #include #include #include #include #define PROG_NAME "pfstmo_drago03" using namespace std; class QuietException { }; void printHelp() { fprintf( stderr, PROG_NAME " (" PACKAGE_STRING ") : \n" "\t [--bias ] [--verbose] [--help] \n" "See man page for more information. \n" ); } void tmo_drago03( int argc, char* argv[] ) { pfs::DOMIO pfsio; //--- default tone mapping parameters; float biasValue = 0.85f; //--- process command line args bool verbose = false; static struct option cmdLineOptions[] = { { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, { "bias", required_argument, NULL, 'b' }, { NULL, 0, NULL, 0 } }; int optionIndex = 0; while( 1 ) { int c = getopt_long (argc, argv, "vhb:", cmdLineOptions, &optionIndex); if( c == -1 ) break; switch( c ) { case 'h': printHelp(); throw QuietException(); case 'v': verbose = true; break; case 'b': biasValue = (float)strtod( optarg, NULL ); if( biasValue<0.0f || biasValue>1.0f ) throw pfs::Exception("incorrect bias value, accepted range is (0..1)"); break; case '?': throw QuietException(); case ':': throw QuietException(); } } VERBOSE_STR << ": bias: " << biasValue << endl; while( true ) { pfs::Frame *frame = pfsio.readFrame( stdin ); if( frame == NULL ) break; // No more frames pfs::Channel *X, *Y, *Z; frame->getXYZChannels( X, Y, Z ); frame->getTags()->setString("LUMINANCE", "RELATIVE"); //--- if( Y == NULL ) throw pfs::Exception( "Missing X, Y, Z channels in the PFS stream" ); float maxLum,avLum; calculateLuminance( Y, avLum, maxLum ); VERBOSE_STR << ": maximum luminance: " << maxLum << endl; VERBOSE_STR << ": average luminance: " << avLum << endl; int w = Y->getCols(); int h = Y->getRows(); pfs::Array2D* L = new pfs::Array2DImpl(w,h); tmo_drago03(Y, L, maxLum, avLum, biasValue); for( int x=0 ; x