This file is indexed.

/usr/include/odindata/converter.h is in libodin-dev 1.8.5-2ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/***************************************************************************
                          converter.h  -  description
                             -------------------
    begin                : Tue Dec 4 2001
    copyright            : (C) 2001 by Michael von Mengershausen
    email                : mengers@cns.mpg.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef CONVERTER_H
#define CONVERTER_H

#include <limits>
#include <assert.h>
#include <stdint.h>

#include <tjutils/tjcomplex.h>
#include <tjutils/tjtypes.h>
#include <tjutils/tjlog.h>

/**
  * @addtogroup odindata
  * @{
  */

// helper class used for debugging the odindata component
class OdinData {
 public:
  static const char* get_compName();
};

////////////////////////////////////////////////////////////////////

/**
  * Scaling strategy when converting data to integer types:
  * - noscale: No scaling
  * - autoscale: scale/offset values so they will fit into the numeric limits of the destination (0 < scaling factor < inv)
  * - noupscale: dont upscale values to fit them into the destination (0 < scaling factor <=1)
  * Note: if destination is non integer no scaling is done at all
  */
enum autoscaleOption {noscale, autoscale,noupscale};

////////////////////////////////////////////////////////////////////

/**
  * Helper class for conversion between numbers
  */
class Converter {

public:



//////////////////////////////////////////////////////////
// get_elements function overloading

//  specializations for complex type
static unsigned int get_elements(const STD_complex&) {
  return 2;
}

/**
  * Returns number of scalar numbers in this number type, e.g. complex has 2
  */
template<typename T>
static unsigned int get_elements(const T&) {
  return 1;
}


//////////////////////////////////////////////////////////


/**
  * Converts array 'src' with 'srcsize' elements to array 'dst' with 'dstsize' elements
  * Will scale "around 0" if 0 is part of the source value range. Elsewise values will be offset towards 0.
  * If destination is unsigned values will be offset to be positive domain if necessary.
  * If autoscaleOption is "noscale" or if destination is floating point no scaling is done at all.
  */
template<typename Src, typename Dst>
static void convert_array(const Src* src, Dst* dst, unsigned int srcsize, unsigned int dstsize, autoscaleOption scaleopt=autoscale) {
  Log<OdinData> odinlog("Converter","convert_array");
  unsigned int srcstep=get_elements(*dst);
  unsigned int dststep=get_elements(*src);
  bool doScale = (scaleopt!=noscale && std::numeric_limits<Dst>::is_integer);

  if(dststep*srcsize != srcstep*dstsize) {
    ODINLOG(odinlog,warningLog) << "size mismatch: dststep(" << dststep << ") * srcsize(" << srcsize << ") != srcstep(" << srcstep << ") * dstsize(" << dstsize << ")" << STD_endl;
  }

  double scale=1.0;
  double offset=0.0;
  if(doScale) {
    const double domain_minus=creal(std::numeric_limits<Dst>::min());//negative value domain of this dst
    const double domain_plus =creal(std::numeric_limits<Dst>::max());//positive value domain of this dst
    double minval=std::numeric_limits<double>::min();
    double maxval=std::numeric_limits<double>::max();
    if(srcsize>0) minval=maxval=creal(src[0]);
    for(unsigned int i=1; i<srcsize; i++) {
      if(src[i]<minval) minval=creal(src[i]);
      if(src[i]>maxval) maxval=creal(src[i]);
    }

    ODINLOG(odinlog,normalDebug) << "src Range:" << minval << "=>" << maxval << STD_endl;
    ODINLOG(odinlog,normalDebug) << "dst Domain:" << domain_minus << "=>" << domain_plus << STD_endl;

    assert(domain_minus<=0 && domain_plus>=0); //I think we can assume this
    assert(domain_minus<domain_plus);//we also should assume this

    //set offset for src
    //if all src is completly on positive domain, or if there is no negative domain use minval
    //else if src is completly on negative dmain, or if there is no positive domain use maxval
    //elsewise leave it at 0 and scale both sides
    if(minval>0 || !domain_minus)offset=-minval;
    else if(maxval<0 || !domain_plus)offset=-maxval;

    //calculate range of values which will be on postive/negative domain when offset is applied
    const double range_plus =maxval+offset; //allways >=0
    const double range_minus=minval+offset; //allways <=0

    //set scaling factor to fit src-range into dst domain
    //some compilers dont make x/0 = inf, so we use std::numeric_limits<double>::max() instead, in this case
    const double scale_plus =
        range_plus ? domain_plus/range_plus :
        std::numeric_limits<double>::max();
    const double scale_minus=
        range_minus ? domain_minus/ range_minus:
        std::numeric_limits<double>::max();
    ODINLOG(odinlog,normalDebug) << "scale_minus/scale_plus=" << scale_minus << "/" << scale_plus << STD_endl;

    scale = STD_min(scale_plus,scale_minus);//get the smaller scaling factor so the bigger range will fit into his domain
    if(scale<1){
      ODINLOG(odinlog,normalDebug) << "Downscaling your values by Factor " << scale << " you might lose information."<< STD_endl;
    } else if(scaleopt==noupscale){
      if(scale>1) {
        ODINLOG(odinlog,normalDebug) << "upscale not given, clamping scale " << scale << " to 1"<< STD_endl;
      }
      scale=1;
    }
    doScale=(scale!=1. || offset);
    offset*=scale;//calc offset for dst
  }
  if(doScale)ODINLOG(odinlog,normalDebug) << "converting with scale/offset=" << scale << "/" << offset << STD_endl;
  else ODINLOG(odinlog,normalDebug) << "converting without scaling" << STD_endl;

  if(srcstep==dststep)//use common convert for data of same complexity
  {
     if(doScale)
      convert_array_impl(src,dst, srcsize < dstsize?srcsize:dstsize,scale,offset);
    else
      convert_array_impl(src,dst, srcsize < dstsize?srcsize:dstsize);
  }
  else //do generic convert for data of different complexity
  {
    unsigned int srcindex=0, dstindex=0;
    while(srcindex<srcsize && dstindex<dstsize) {
      convert(src+srcindex, dst+dstindex,scale,offset);
      srcindex+=srcstep;
      dstindex+=dststep;
    }
  }
}

private:

//////////////////////////////////////////////////////////
// convert

/**
  * simple convert just do "inc" on both pointers and "dec" on the counter
  */
template<typename Src, typename Dst> static void convert_array_impl(const Src* src, Dst* dst, unsigned int count,double scale=1,double offset=0) {
	Log<OdinData> odinlog("Converter","convert_array_impl(generic)");
	ODINLOG(odinlog,normalDebug) << "generic convert " << TypeTraits::type2label(*src) << "=>" << TypeTraits::type2label(*dst) << STD_endl;
	ODINLOG(odinlog,normalDebug) << "scale/offset=" << scale << "/" << offset << STD_endl;
	while(count--)
		convert(src++, dst++,scale,offset);
}



// Implementing our own round functions since lround/lroundf do not work for unsigned numbers, and they are flawed in MinGW
template<typename T> static T round(double x) {
  return (T)(x < 0 ? x - 0.5 : x + 0.5);
}

// specialized converter functions

// to complex
static void convert(const s8bit* src, STD_complex* dst,float scale,float offset) {
  (*dst)=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const u8bit* src, STD_complex* dst,float scale,float offset) {
  (*dst)=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const u16bit* src, STD_complex* dst,float scale,float offset) {
  (*dst)=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const s16bit* src, STD_complex* dst,float scale,float offset) {
  (*dst)=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const u32bit* src, STD_complex* dst,float scale,float offset) {
  (*dst)=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const s32bit* src, STD_complex* dst,float scale,float offset) {
  (*dst)=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const float *src, STD_complex* dst,float scale,float offset) {
  dst[0]=STD_complex(src[0]*scale+offset,src[1]*scale);
}
static void convert(const double *src, STD_complex* dst,float scale,float offset) {
  dst[0]=STD_complex(src[0]*scale+offset,src[1]*scale);
}

// from complex
static void convert(const STD_complex* src, s8bit* dst,float scale,float offset) {
  dst[0]=round<s8bit>(src->real()*scale+offset);
  dst[1]=round<s8bit>(src->imag()*scale);
}
static void convert(const STD_complex* src, u8bit* dst,float scale,float offset) {
  dst[0]=round<u8bit>(src->real()*scale+offset);
  dst[1]=round<u8bit>(src->imag()*scale);
}
static void convert(const STD_complex* src, s16bit* dst,float scale,float offset) {
  dst[0]=round<s16bit>(src->real()*scale+offset);
  dst[1]=round<s16bit>(src->imag()*scale);
}
static void convert(const STD_complex* src, u16bit* dst,float scale,float offset) {
  dst[0]=round<u16bit>(src->real()*scale+offset);
  dst[1]=round<u16bit>(src->imag()*scale);
}
static void convert(const STD_complex* src, s32bit* dst,float scale,float offset) {
  dst[0]=round<s32bit>(src->real()*scale+offset);
  dst[1]=round<s32bit>(src->imag()*scale);
}
static void convert(const STD_complex* src, u32bit* dst,float scale,float offset) {
  dst[0]=round<u32bit>(src->real()*scale+offset);
  dst[1]=round<u32bit>(src->imag()*scale);
}
static void convert(const STD_complex* src, float* dst,float scale,float offset) {
  dst[0]=src->real()*scale+offset;
  dst[1]=src->imag()*scale;
}
static void convert(const STD_complex* src, double* dst,float scale,float offset) {
  dst[0]=src->real()*scale+offset;
  dst[1]=src->imag()*scale;
}

// from float to integer
static void convert(const float* src, s8bit* dst,float scale,float offset) {
  dst[0]=round<s8bit>(src[0]*scale+offset);
}
static void convert(const float* src, u8bit* dst,float scale,float offset) {
  dst[0]=round<u8bit>(src[0]*scale+offset);
}
static void convert(const float* src, s16bit* dst,float scale,float offset) {
  dst[0]=round<s16bit>(src[0]*scale+offset);
}
static void convert(const float* src, u16bit* dst,float scale,float offset) {
  dst[0]=round<u16bit>(src[0]*scale+offset);
}
static void convert(const float* src, s32bit* dst,float scale,float offset) {
  dst[0]=round<s32bit>(src[0]*scale+offset);
}
static void convert(const float* src, u32bit* dst,float scale,float offset) {
  dst[0]=round<u32bit>(src[0]*scale+offset);
}

// from double to integer
static void convert(const double* src, s8bit* dst,float scale,float offset) {
  dst[0]=round<s8bit>(src[0]*scale+offset);
}
static void convert(const double* src, u8bit* dst,float scale,float offset) {
  dst[0]=round<u8bit>(src[0]*scale+offset);
}
static void convert(const double* src, s16bit* dst,float scale,float offset) {
  dst[0]=round<s16bit>(src[0]*scale+offset);
}
static void convert(const double* src, u16bit* dst,float scale,float offset) {
  dst[0]=round<u16bit>(src[0]*scale+offset);
}
static void convert(const double* src, s32bit* dst,float scale,float offset) {
  dst[0]=round<s32bit>(src[0]*scale+offset);
}
static void convert(const double* src, u32bit* dst,float scale,float offset) {
  dst[0]=round<u32bit>(src[0]*scale+offset);
}



//default
template<typename Src, typename Dst>
    static void convert(const Src* src, Dst* dst,float scale,float offset) {
      dst[0]=(Dst)(src[0]*scale+offset);
}

//////////////////////////////////////////////////////////

Converter() {} // Do not allow instances

};

/** @}
  */

#endif