summaryrefslogtreecommitdiff
path: root/src/im_datatype.cpp
blob: c75483e73b159eab3094d4a03709a3c2c555f794 (plain)
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
/** \file
 * \brief Data Type Utilities
 *
 * See Copyright Notice in im_lib.h
 * $Id: im_datatype.cpp,v 1.1 2008/10/17 06:10:16 scuri Exp $
 */


#include "im.h"
#include "im_util.h"

#include <assert.h>

typedef struct _iTypeInfo
{
  int size;
  unsigned long max;
  long min;
  char* name;
} iTypeInfo;

static iTypeInfo iTypeInfoTable[] =  
{        
  {1,  255,                  0,                       "byte"}, 
  {2,  65535,                0,                       "ushort"},
  {4,  2147483647,           -2147483647-1,           "int"},
  {4,  0,                    0,                       "float"}, 
  {8,  0,                    0,                       "cfloat"}
};

const char* imDataTypeName(int data_type)
{
  assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT);
  return iTypeInfoTable[data_type].name;
}

int imDataTypeSize(int data_type)
{
  assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT);
  assert(sizeof(int) == 4);
  return iTypeInfoTable[data_type].size;
}

unsigned long imDataTypeIntMax(int data_type)
{
  assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT);
  return iTypeInfoTable[data_type].max;
}

long imDataTypeIntMin(int data_type)
{
  assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT);
  return iTypeInfoTable[data_type].min;
}