Instrument Neutral Distributed Interface INDI  1.9.5
gammalut16.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2020 by Pawel Soja <kernel32.pl@gmail.com>
3  Copyright (C) 2015 by Jasem Mutlaq <mutlaqja@ikarustech.com>
4  Copyright (C) 2014 by geehalel <geehalel@gmail.com>
5 
6  Stream Recorder
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 */
23 #include "gammalut16.h"
24 #include <cmath>
25 
26 GammaLut16::GammaLut16(double gamma, double a, double b, double Ii)
27 {
28  mLookUpTable.resize(65536);
29 
30  unsigned int i = 0;
31  for (auto &value: mLookUpTable)
32  {
33  double I = static_cast<double>(i++) / 65535.0;
34  double p;
35  if (I <= Ii)
36  p = a * I;
37  else
38  p = (1 + b) * powf(I, 1.0 / gamma) - b;
39  value = round(255.0 * p);
40  }
41 }
42 
43 void GammaLut16::apply(const uint16_t *source, size_t count, uint8_t *destination) const
44 {
45  apply(source, source + count, destination);
46 }
47 
48 
49 void GammaLut16::apply(const uint16_t *first, const uint16_t *last, uint8_t *destination) const
50 {
51  const uint16_t *lookUpTable = mLookUpTable.data();
52 
53  while (first != last)
54  *destination++ = lookUpTable[*first++];
55 }
round
double round(double value, int decimal_places)
Definition: test_alignment.cpp:32
gammalut16.h
GammaLut16::apply
void apply(const uint16_t *source, size_t count, uint8_t *destination) const
Definition: gammalut16.cpp:43
GammaLut16::mLookUpTable
std::vector< uint16_t > mLookUpTable
Definition: gammalut16.h:39
GammaLut16::GammaLut16
GammaLut16(double gamma=2.4, double a=12.92, double b=0.055, double Ii=0.00304)
Definition: gammalut16.cpp:26