OpenCores
URL https://opencores.org/ocsvn/mb-jpeg/mb-jpeg/trunk

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [STEP2_2b/] [mb-bmp2jpg/] [zzq.c] - Blame information for rev 56

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 quickwayne
#include "ejpgl.h"
2
 
3
unsigned char quantization_table[MATRIX_SIZE][MATRIX_SIZE] ={
4
        {4, 3, 3, 4, 4, 5, 6, 6},
5
        {3, 3, 4, 4, 5, 6, 6, 6},
6
        {4, 4, 4, 4, 5, 6, 6, 6},
7
        {4, 4, 4, 5, 6, 6, 6, 6},
8
        {4, 4, 5, 6, 6, 7, 7, 6},
9
        {4, 5, 6, 6, 6, 7, 7, 6},
10
        {6, 6, 6, 6, 7, 7, 7, 7},
11
        {6, 6, 6, 7, 7, 7, 7, 7}
12
    };
13
 
14
signed char bitstream[NUMBER_OF_PIXELS] ;
15
 
16
int zzq_encode_init_start(int compression) {
17
 
18
        return 0;
19
 
20
}
21
 
22
int zzq_encode_stop_done() {
23
 
24
 
25
}
26
 
27
void zzq_encode(signed short pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], int color)
28
{
29
    int i, x, y, jumped, deltax, deltay;
30
 
31
    x = y = deltax = deltay = jumped = 0;
32
 
33
    for(i=0;i<NUMBER_OF_PIXELS;i++)
34
    {
35
                if(pixelmatrix[y][x]>0)
36
                        bitstream[i] = (pixelmatrix[y][x]>>quantization_table[y][x]);
37
                else
38
                        bitstream[i] = -((-pixelmatrix[y][x])>>quantization_table[y][x]);
39
 
40
        if((y == 0) || (y == MATRIX_SIZE-1)) { //on top or bottom side of matrix
41
                if(!jumped) { //first jump to element on the right
42
                        x++;
43
                        jumped = 1;
44
                } else { //modify direction
45
                        if(i<(NUMBER_OF_PIXELS>>1)) {
46
                                deltax = -1;
47
                                deltay = 1;
48
                        } else {
49
                                deltax = 1;
50
                                deltay = -1;
51
                        }
52
                        x += deltax;
53
                        y += deltay;
54
                        jumped = 0;
55
                }
56
        } else if ((x == 0) || (x == MATRIX_SIZE-1)) { //on left or right side of matrix
57
                if(!jumped) { //jump to element below
58
                        y++;
59
                        jumped = 1;
60
                } else { //modify direction
61
                        if(i<(NUMBER_OF_PIXELS>>1)) {
62
                                deltax = 1;
63
                                deltay = -1;
64
                        } else {
65
                                deltax = -1;
66
                                deltay = 1;
67
                        }
68
                        x += deltax;
69
                        y += deltay;
70
                        jumped = 0;
71
                }
72
        }
73
        else {//not on the edges of the matrix
74
                x += deltax;
75
                y += deltay;
76
        }
77
    }
78
 
79
    EncodeDataUnit(bitstream, color);
80
 
81
        return;
82
 
83
}
84
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.