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
|
#include <stdio.h>
#include "dct.h"
#define ENCODE 0
#define DECODE 1
#define MAXROWS 1024
#define MAXCOLS 768
unsigned char Image1[MAXCOLS*3*MAXROWS];
int main(int argc, char *argv[]) {
int retval, i;
int workspace[DCTSIZE_BLOCK];
int type;
int x, y, offset, depth;
char *fileIn, *fileOut;
FILE *fI, *fO;
unsigned char ch, mrgb[3];
/* Just for testing on the PC */
if(argc != 4)
{
printf("need more arguments");
return 0;
}
type = atoi(argv[1]);
fileIn = argv[2];
fileOut = argv[3];
if (NULL == (fI = fopen(fileIn, "rb"))){
printf("unable to open the file to read from (%s)",fileIn);
return 0;
}
if ((fO = fopen(fileOut,"wb")) == NULL) {
printf("unable to open the file to write (%s)",fileOut);
return 0;
}
switch(type) {
case ENCODE:
fseek(fI, 10L, SEEK_SET);
fread(mrgb, 1, 4, fI);
offset = mrgb[3];
offset <<= 8;
offset += mrgb[2];
offset <<= 8;
offset += mrgb[1];
offset <<= 8;
offset += mrgb[0];
fseek(fI, 18L, SEEK_SET);
fread(mrgb, 1, 4, fI);
x = ((int)mrgb[3] << 24) + ((int)mrgb[2] << 16) + ((int)mrgb[1] << 8) + mrgb[0];
fseek(fI, 22L, SEEK_SET);
fread(mrgb, 1, 4, fI);
y = ((int)mrgb[3] << 24) + ((int)mrgb[2] << 16) + ((int)mrgb[1] << 8) + mrgb[0];
fseek(fI, 28L, SEEK_SET);
fread(mrgb, 1, 2, fI);
depth = ((int)mrgb[1] << 8) + mrgb[0];
printf("Image Resolution: %d x %d x %i \n", x, y, depth);
fseek(fI, offset, SEEK_SET);
fread(Image1, sizeof(unsigned char), (x*y*(depth/3)), fI);
break;
case DECODE:
break;
}
/* End for just for testing on the PC */
retval = 0;
type = ENCODE;
switch(type) {
case ENCODE:
// RGB -> YUV
// Convert to 8x8
// DCT
fdct(workspace);
// ZZ
// Q
// VLC (huffman)
break;
case DECODE:
// VLD (huffman)
// IQ
// ZZ
// IDCT
//idct(workspace);
// Convert 8x8 to lines
// YUV -> RGB
break;
}
return retval;
}
|