"Fossies" - the Fresh Open Source Software Archive

Member "pfstools-2.2.0/src/tmo/drago03/pfstmo_drago03.cpp" (12 Aug 2021, 4154 Bytes) of package /linux/privat/pfstools-2.2.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pfstmo_drago03.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.1.0_vs_2.2.0.

    1 /**
    2  * @brief Adaptive logarithmic tone mapping
    3  * 
    4  * Adaptive logarithmic mapping for displaying high contrast
    5  * scenes. 
    6  * F. Drago, K. Myszkowski, T. Annen, and N. Chiba. In Eurographics 2003.
    7  *
    8  * This file is a part of PFSTMO package.
    9  * ---------------------------------------------------------------------- 
   10  * Copyright (C) 2003,2004 Grzegorz Krawczyk
   11  * 
   12  *  This program is free software; you can redistribute it and/or modify
   13  *  it under the terms of the GNU General Public License as published by
   14  *  the Free Software Foundation; either version 2 of the License, or
   15  *  (at your option) any later version.
   16  *
   17  *  This program is distributed in the hope that it will be useful,
   18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20  *  GNU General Public License for more details.
   21  *
   22  *  You should have received a copy of the GNU General Public License
   23  *  along with this program; if not, write to the Free Software
   24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25  * ---------------------------------------------------------------------- 
   26  * 
   27  * @author Grzegorz Krawczyk, <krawczyk@mpi-inf.mpg.de>
   28  *
   29  * $Id: pfstmo_drago03.cpp,v 1.4 2009/04/15 11:49:32 julians37 Exp $
   30  */
   31 
   32 #include <config.h>
   33 
   34 #include <iostream>
   35 #include <stdio.h>
   36 #include <stdlib.h>
   37 #include <getopt.h>
   38 #include <math.h>
   39 
   40 #include <pfs.h>
   41 
   42 #include "tmo_drago03.h"
   43 
   44 #define PROG_NAME "pfstmo_drago03"
   45 
   46 using namespace std;
   47 
   48 class QuietException 
   49 {
   50 };
   51 
   52 
   53 void printHelp()
   54 {
   55   fprintf( stderr, PROG_NAME " (" PACKAGE_VERSION ") : \n"
   56     "\t [--bias <val>] [--verbose] [--help] \n"
   57     "See man page for more information. \n" );
   58 }
   59 
   60 void tmo_drago03( int argc, char* argv[] )
   61 {
   62   pfs::DOMIO pfsio;
   63 
   64   //--- default tone mapping parameters;
   65   float biasValue = 0.85f;
   66 
   67   //--- process command line args
   68   bool verbose = false;
   69 
   70   static struct option cmdLineOptions[] = {
   71     { "help", no_argument, NULL, 'h' },
   72     { "verbose", no_argument, NULL, 'v' },
   73     { "bias", required_argument, NULL, 'b' },
   74     { NULL, 0, NULL, 0 }
   75   };
   76 
   77   int optionIndex = 0;
   78   while( 1 ) {
   79     int c = getopt_long (argc, argv, "vhb:", cmdLineOptions, &optionIndex);
   80     if( c == -1 ) break;
   81     switch( c ) {
   82     case 'h':
   83       printHelp();
   84       throw QuietException();
   85     case 'v':
   86       verbose = true;
   87       break;
   88     case 'b':
   89       biasValue = (float)strtod( optarg, NULL );
   90       if( biasValue<0.0f || biasValue>1.0f )
   91         throw pfs::Exception("incorrect bias value, accepted range is (0..1)");
   92       break;
   93     case '?':
   94       throw QuietException();
   95     case ':':
   96       throw QuietException();
   97     }
   98   }
   99 
  100   VERBOSE_STR << ": bias: " << biasValue << endl;
  101    
  102   while( true ) {
  103     pfs::Frame *frame = pfsio.readFrame( stdin );
  104     if( frame == NULL ) break; // No more frames
  105 
  106     pfs::Channel *X, *Y, *Z;
  107     frame->getXYZChannels( X, Y, Z );
  108     frame->getTags()->setString("LUMINANCE", "RELATIVE");
  109     //---
  110 
  111     if( Y == NULL )
  112       throw pfs::Exception( "Missing X, Y, Z channels in the PFS stream" );
  113 
  114     int w = Y->getCols();
  115     int h = Y->getRows();
  116         
  117     float maxLum,avLum;
  118     calculateLuminance( w, h, Y->getRawData(), avLum, maxLum );
  119     VERBOSE_STR << ": maximum luminance: " << maxLum << endl;
  120     VERBOSE_STR << ": average luminance: " << avLum << endl;
  121 
  122     pfs::Array2DImpl* L = new pfs::Array2DImpl(w,h);
  123     tmo_drago03(w, h, Y->getRawData(), L->getRawData(), maxLum, avLum, biasValue);
  124         
  125     for( int y=0 ; y<h ; y++ )
  126     {
  127       for( int x=0 ; x<w ; x++ )
  128       {
  129         float scale = (*L)(x,y) / (*Y)(x,y);
  130         (*Y)(x,y) *= scale;
  131         (*X)(x,y) *= scale;
  132         (*Z)(x,y) *= scale;
  133       }
  134     }
  135 
  136     delete L;
  137     
  138     //---
  139     pfsio.writeFrame( frame, stdout );
  140     pfsio.freeFrame( frame );        
  141   }
  142 }
  143 
  144 
  145 int main( int argc, char* argv[] )
  146 {
  147   try {
  148     tmo_drago03( argc, argv );
  149   }
  150   catch( pfs::Exception ex ) {
  151     fprintf( stderr, PROG_NAME " error: %s\n", ex.getMessage() );
  152     return EXIT_FAILURE;
  153   }        
  154   catch( QuietException ) {
  155     return EXIT_FAILURE;
  156   }        
  157   return EXIT_SUCCESS;
  158 }