GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/convert.c Lines: 12 28 42.9 %
Date: 2017-05-26 Branches: 1 18 5.6 %

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 "Convert to another type (as if by cast, w/ optional clamp)"
28
static const char *_unrrdu_convertInfoL =
29
(INFO ". By default this does not transform, scale, or intelligently "
30
 "quantize values; it just copies them from one type to another, which "
31
 "replicates exactly what you'd get in C when you assign from a variable "
32
 "of one type to another, or when you cast to a different type. However, "
33
 "clamping values to the representable range of the output type is possible. "
34
 "with \"-clamp\". "
35
 "See also \"unu quantize\","
36
 "\"unu 2op x\", and \"unu 3op clamp\".\n "
37
 "* Uses nrrdConvert or nrrdClampConvert");
38
39
int
40
unrrdu_convertMain(int argc, const char **argv, const char *me,
41
                   hestParm *hparm) {
42
2
  hestOpt *opt = NULL;
43
1
  char *out, *err;
44
1
  Nrrd *nin, *nout;
45
1
  int type, pret, E, doClamp;
46
  airArray *mop;
47
48
1
  OPT_ADD_TYPE(type, "type to convert to", NULL);
49
1
  OPT_ADD_NIN(nin, "input nrrd");
50
1
  hestOptAdd(&opt, "clamp", NULL, airTypeInt, 0, 0, &doClamp, NULL,
51
             "clamp input values to representable range of values of "
52
             "output type, to avoid wrap-around problems");
53
1
  OPT_ADD_NOUT(out, "output nrrd");
54
55
1
  mop = airMopNew();
56
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
57
58
2
  USAGE(_unrrdu_convertInfoL);
59
  PARSE();
60
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
61
62
  nout = nrrdNew();
63
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
64
65
  if (doClamp) {
66
    E = nrrdClampConvert(nout, nin, type);
67
  } else {
68
    E = nrrdConvert(nout, nin, type);
69
  }
70
  if (E) {
71
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
72
    fprintf(stderr, "%s: error converting nrrd:\n%s", me, err);
73
    airMopError(mop);
74
    return 1;
75
  }
76
77
  SAVE(out, nout, NULL);
78
79
  airMopOkay(mop);
80
  return 0;
81
1
}
82
83
UNRRDU_CMD(convert, INFO);