Subversion Repositories seema-scanner

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jakw 1
/*
2
 * Common.h
3
 *
4
 * This module provides the common defines used by all the modules.
5
 *
6
 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
7
 * ALL RIGHTS RESERVED
8
 *
9
*/
10
 
11
#ifndef COMMON_H_
12
#define COMMON_H_
13
 
14
#include <stdlib.h>
15
#include <string.h>
16
#include <ctype.h>
17
 
18
 
19
#ifdef __cplusplus
20
extern "C" {
21
#endif
22
 
23
#define TRUE                    1
24
#define FALSE                   0
25
 
26
typedef enum
27
{
28
	IMAGE_PIX_FORMAT_RGB32,
29
	IMAGE_PIX_FORMAT_GREY8,
30
	IMAGE_PIX_FORMAT_GREY10,
31
	IMAGE_PIX_FORMAT_UYVY16,
32
	IMAGE_PIX_FORMAT_RGB16,
33
	IMAGE_PIX_FORMAT_SBGGR,
34
	IMAGE_PIX_FORMAT_RGB24,
35
} ImagePixFormat_t;
36
 
37
typedef struct
38
{
39
	unsigned char *Buffer;
40
	unsigned Width;
41
	unsigned Height;
42
	unsigned LineWidth;
43
	ImagePixFormat_t PixFormat;
44
}Image_t;
45
 
46
 
47
typedef int BOOL;
48
typedef unsigned uint32;
49
typedef unsigned char uint8;
50
typedef unsigned short uint16;
51
 
52
typedef uint16 PatternCount_t;
53
 
54
#define MIN(a, b)					((a) < (b) ? (a) : (b))
55
#define MAX(a, b)					((a) > (b) ? (a) : (b))
56
#define ALIGN_BYTES_PREV(x, b)      ((x) & ~(uint32)((b) - 1))
57
#define ALIGN_BYTES_NEXT(x, b)      (((x) + ((b)-1)) & ~(uint32)((b) - 1))
58
 
59
#define GET_BYTE0(x)				((x) & 0xFF)
60
#define GET_BYTE1(x)				(((x) >> 8) & 0xFF)
61
#define GET_BYTE2(x)				(((x) >> 16) & 0xFF)
62
#define GET_BYTE3(x)				(((x) >> 24) & 0xFF)
63
 
64
#define PARSE_WORD16_LE(Arr)        MAKE_WORD16((Arr)[1], (Arr)[0])
65
#define PARSE_WORD16_BE(Arr)        MAKE_WORD16((Arr)[0], (Arr)[1])
66
#define PARSE_WORD24_LE(Arr)        MAKE_WORD32(0, (Arr)[2], (Arr)[1], (Arr)[0])
67
#define PARSE_WORD24_BE(Arr)        MAKE_WORD32(0, (Arr)[0], (Arr)[1], (Arr)[2])
68
#define PARSE_WORD32_LE(Arr)        MAKE_WORD32((Arr)[3], (Arr)[2], (Arr)[1], (Arr)[0])
69
#define PARSE_WORD32_BE(Arr)        MAKE_WORD32((Arr)[0], (Arr)[1], (Arr)[2], (Arr)[3])
70
 
71
#define MAKE_WORD16(b1, b0)         (((b1) << 8) | (b0))
72
#define MAKE_WORD32(b3, b2, b1, b0) (((uint32)(b3)<<24)|((uint32)(b2)<<16)|((uint32)(b1)<<8)|(b0))
73
 
74
#define ARRAY_SIZE(x)               (sizeof(x)/sizeof(*x))
75
#define DIV_ROUND(x, y)             (((x)+(y)/2)/(y))
76
#define DIV_CEIL(x, y)              (((x)+(y)-1)/(y))
77
#define POW_OF_2(x)                 (1ul << (x))
78
 
79
#define IS_POW_OF_2(x)              (((x) & ((x)-1)) == 0)
80
 
81
// Generate bit mask of n bits starting from s bit
82
#define GEN_BIT_MASK(s, n)          (((1ul << (n)) - 1) << (s))
83
 
84
// Merge bits b into a according to mask
85
#define MERGE_BITS(a, b, mask)      ((a) ^ (((a) ^ (b)) & (mask)))
86
 
87
#define STRUCT_CLEAR(s)				(memset(&(s), 0, sizeof(s)))
88
#define BIT_REVERSE(x)				CMN_BitRevLUT[(uint8)(x)]
89
 
90
#define STR(x)	STR_(x)
91
#define STR_(x)	#x
92
 
93
extern const uint8 CMN_BitRevLUT[];
94
void PrintArray(char const *Prefix, uint8 const *Array, unsigned Size, BOOL Hex);
95
uint32 GetImagePixel(Image_t *Image, int x, int y);
96
uint32 Next2Power(uint32 Value);
97
unsigned Hex2BinArray(char *HexStr, unsigned Size, uint8 *BinArray);
98
int TrimString(char const *Input, char *Output);
99
int WriteTextToFile(char const *File, int Num, char const *Text);
100
int ReadTextFromFile(char const *File, int Num, char *Text, int Len);
101
BOOL FileExist(char const *File, int Num);
102
 
103
#ifdef __cplusplus
104
}
105
#endif
106
 
107
 
108
#endif /* COMMON_H_ */