/
avgdctscaled.c
59 lines (54 loc) · 1.9 KB
/
avgdctscaled.c
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
#include "avgdctscaled.h"
#include "avgdct.h"
#include "assert.h"
#include <math.h>
#include "arith40.h"
#include "closure.h"
/*
* Compression: converts the arguments of floats and returns a scaled integer in
* the range of plus or minus 15.
*/
static int convertToScaledInt(float num) {
if(num > .3) num = .3;
else if (num < -.3) num = -.3;
int scaled = nearbyint(50.0*num);
if (scaled > 15)
scaled = 15;
if (scaled < -15)
scaled = -15;
return scaled;
}
/*
* Compression: void *ptr is a struct of AvgDCT to be filled with the
* calculations preformed on the AvgDCTScalled array in the closure.
*/
void applyCompToAvgDCTScaled(int col, int row, A2 toBeFilled, void* ptr,
void* cl) {
(void) toBeFilled;
struct Closure* mycl = cl;
struct AvgDCTScaled* toBeSet = ptr;
struct AvgDCT* original = mycl->methods->at(mycl->array, col, row);
toBeSet->pb = Arith40_index_of_chroma(original->pb);
toBeSet->pr = Arith40_index_of_chroma(original->pr);
toBeSet->a = (unsigned)(original->a * 511);
toBeSet->b = convertToScaledInt(original->b);
toBeSet->c = convertToScaledInt(original->c);
toBeSet->d = convertToScaledInt(original->d);
}
/*
* Decompression: void* ptr is a struct of AvgDCT to be filled with the
* calculations performed on the AvgDCTScaled array in the closure.
*/
void applyDecompToAvgDCT(int col, int row, A2 toBeFilled,
void* ptr, void* cl) {
(void) toBeFilled;
struct Closure *mycl = cl;
struct AvgDCT* toBeSet = ptr;
struct AvgDCTScaled* original = mycl->methods->at(mycl->array, col, row);
toBeSet->pb = Arith40_chroma_of_index(original->pb);
toBeSet->pr = Arith40_chroma_of_index(original->pr);
toBeSet->a = ((float)(original->a))/511.0;
toBeSet->b = ((float)(original->b))/50.0;
toBeSet->c = ((float)(original->c))/50.0;
toBeSet->d = ((float)(original->d))/50.0;
}