-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdctz.h
129 lines (115 loc) · 2.53 KB
/
dctz.h
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
/**
* @file dctz.h
* @author Seung Woo Son
* @date July 2019
* @brief header for DCTZ routines
* (C) 2019 University of Massachusetts Lowell.
See LICENSE in the top-level directory.
*/
#ifndef _DCTZ_H_
#define _DCTZ_H_
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "fftw3.h"
#include "zlib.h"
#include "dct.h"
#define DCTZ_VERSION "0.2.2"
#define DCTZ_VERSION_MAJOR 0
#define DCTZ_VERSION_MINOR 2
#define DCTZ_VERSION_PATCH 2
#define BLK_SZ 64
#define BRSF 1.0 /* bin range scaling factor: 1 means no scaling */
#define SF_ADJ_AMT 1 /* scaling factor adjustment amount */
#define MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#define CEIL(a,b) (a+b-1)/b
typedef enum {
FLOAT = 0,
DOUBLE
} t_datatype;
typedef struct
{
t_datatype datatype;
double err_bound;
char *var_name;
union
{
float *f;
double *d;
} buf;
} t_var;
/* unsigned char => 1 byte: 0-255 */
/* unsigned short => 2 byte: 0-1023 */
typedef unsigned char t_bin_id;
#define NBITS (sizeof(t_bin_id)<<3) /* # of bits (8 or 16) for representing bin index */
#define NBINS ((1 << (NBITS)) - 1) /* e.g., if NBITS=8, 255 (0-254) */
typedef struct {
union
{
double d;
float f;
} mean;
union
{
double d;
float f;
} min;
union
{
double d;
float f;
} max;
union
{
double d;
float f;
} range;
union
{
double d;
float f;
} sf;
} t_bstat;
struct header
{
t_datatype datatype;
unsigned int num_elements;
double error_bound;
unsigned int tot_AC_exact_count;
union
{
double d;
float f;
} scaling_factor;
union
{
double d;
float f;
} mean;
unsigned int bindex_sz_compressed;
unsigned int DC_sz_compressed;
unsigned int AC_exact_sz_compressed;
#ifdef USE_QTABLE
unsigned int bindex_count;
#endif
/* unsigned int AC_exact_count_sz_compressed; */
};
void calc_data_stat(t_var *in, t_bstat *bs, int N);
int ceili(double i);
void gen_bins(double min, double max, double *bin_center, int nbins, double error_bound);
void gen_bins_f(float min, float max, float *bin_center, int nbins, float error_bound);
void *compress_thread(void *arg);
int dctz_compress(t_var *var, int N, size_t *outSize, t_var *var_z, double error_bound);
int dctz_decompress(t_var *var_z, t_var *var_r);
double calc_psnr(t_var *var, t_var *var_r, int N, double error_bound);
#endif