GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/gamma.c Lines: 16 31 51.6 %
Date: 2017-05-26 Branches: 1 14 7.1 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "unrrdu.h"
25
#include "privateUnrrdu.h"
26
27
#define INFO "Brighten or darken values with a gamma"
28
static const char *_unrrdu_gammaInfoL =
29
(INFO
30
 ". Just as in xv, the gamma value here is actually the "
31
 "reciprocal of the exponent actually used to transform "
32
 "the values.\n "
33
 "* Uses nrrdArithGamma");
34
35
int
36
unrrdu_gammaMain(int argc, const char **argv, const char *me,
37
                 hestParm *hparm) {
38
2
  hestOpt *opt = NULL;
39
1
  char *out, *err;
40
1
  Nrrd *nin, *nout;
41
1
  double min, max, Gamma;
42
  airArray *mop;
43
1
  int pret, blind8BitRange;
44
  NrrdRange *range;
45
46
1
  hestOptAdd(&opt, "g,gamma", "gamma", airTypeDouble, 1, 1, &Gamma, NULL,
47
             "gamma > 1.0 brightens; gamma < 1.0 darkens. "
48
             "Negative gammas invert values (like in xv). ");
49
1
  hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan",
50
             "Value to implicitly map to 0.0 prior to calling pow(). "
51
             "Defaults to lowest value found in input nrrd.");
52
1
  hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan",
53
             "Value to implicitly map to 1.0 prior to calling pow(). "
54
             "Defaults to highest value found in input nrrd.");
55
1
  hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange,
56
1
             nrrdStateBlind8BitRange ? "true" : "false",
57
             "Whether to know the range of 8-bit data blindly "
58
             "(uchar is always [0,255], signed char is [-128,127]).");
59
1
  OPT_ADD_NIN(nin, "input nrrd");
60
1
  OPT_ADD_NOUT(out, "output nrrd");
61
62
1
  mop = airMopNew();
63
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
64
65
2
  USAGE(_unrrdu_gammaInfoL);
66
  PARSE();
67
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
68
69
  nout = nrrdNew();
70
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
71
72
  range = nrrdRangeNew(min, max);
73
  airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways);
74
  nrrdRangeSafeSet(range, nin, blind8BitRange);
75
  if (nrrdArithGamma(nout, nin, range, Gamma)) {
76
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
77
    fprintf(stderr, "%s: error doing gamma:\n%s", me, err);
78
    airMopError(mop);
79
    return 1;
80
  }
81
82
  SAVE(out, nout, NULL);
83
84
  airMopOkay(mop);
85
  return 0;
86
1
}
87
88
UNRRDU_CMD(gamma, INFO);