-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc63.h
143 lines (105 loc) · 3.14 KB
/
c63.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef CPU_MJPEG_H
#define CPU_MJPEG_H
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#define MAX_FILELENGTH 200
#define DEFAULT_OUTPUT_FILE "a.mjpg"
#define ISQRT2 0.70710678118654f
#define PI 3.14159265358979
#define ILOG2 1.442695040888963 // 1/log(2);
#define COLOR_COMPONENTS 3
#define YX 2
#define YY 2
#define UX 1
#define UY 1
#define VX 1
#define VY 1
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
struct yuv
{
uint8_t *Y;
uint8_t *U;
uint8_t *V;
float *Yfloat;
float *Ufloat;
float *Vfloat;
};
struct dct
{
int16_t *Ydct;
int16_t *Udct;
int16_t *Vdct;
};
typedef struct yuv yuv_t;
typedef struct dct dct_t;
struct entropy_ctx
{
FILE *fp;
unsigned int bit_buffer;
unsigned int bit_buffer_width;
};
struct macroblock
{
int use_mv;
int8_t mv_x, mv_y;
uint8_t pad[10];
} __attribute((aligned(16)));
typedef struct workcomplete
{
int completed;
int pad[3];
} workcomplete_t __attribute__((aligned(16)));
struct frame
{
yuv_t *orig; // Original input image
yuv_t *recons; // Reconstructed image
yuv_t *predicted; // Predicted frame from intra-prediction
dct_t *residuals; // Difference between original image and predicted frame
// Meh
struct macroblock *mbs[3];
int keyframe;
// Cell impl specific
workcomplete_t *work_complete_Y __attribute__((aligned(16)));
workcomplete_t *work_complete_U __attribute__((aligned(16)));
workcomplete_t *work_complete_V __attribute__((aligned(16)));
};
struct c63_common
{
int width, height;
int ypw, yph, upw, uph, vpw, vph;
int padw[3], padh[3];
int mb_cols, mb_rows;
uint8_t qp; // Quality parameter
int me_search_range;
uint8_t quanttbl[3][64];
struct frame *refframe;
struct frame *curframe;
int framenum;
int keyframe_interval;
int frames_since_keyframe;
struct entropy_ctx e_ctx;
};
void put_bytes(FILE *fp, const void* data, unsigned int len);
void put_byte(FILE *fp, int byte);
void put_bits(struct entropy_ctx *c, uint16_t bits, uint8_t n);
void flush_bits(struct entropy_ctx *c);
uint8_t get_byte(FILE *fp);
int read_bytes(FILE *fp, void *data, unsigned int sz);
uint16_t get_bits(struct entropy_ctx *c, uint8_t n);
void dct_quant_block_8x8(int16_t *in_data, int16_t *out_data, uint8_t *quant_tbl);
void dequant_idct_block_8x8(int16_t *in_data, int16_t *out_data, uint8_t *quant_tbl);
void sad_block_8x8(uint8_t *block1, uint8_t *block2, int stride, int *result);
void write_frame(struct c63_common *cm);
void dequantize_idct(int16_t *in_data, uint8_t *prediction, uint32_t width, uint32_t height,
uint8_t *out_data, uint8_t *quantization);
void dct_quantize(uint8_t *in_data, uint8_t *prediction,
uint32_t width, uint32_t height,
int16_t *out_data, uint8_t *quantization);
void destroy_frame(struct frame *f);
struct frame* create_frame(struct c63_common *cm, yuv_t *image);
void c63_motion_estimate(struct c63_common *cm);
void c63_motion_compensate(struct c63_common *cm);
void dump_image(yuv_t *image, int w, int h, FILE *fp);
#endif /* mjpeg_encoder.h */