OpenCores
URL https://opencores.org/ocsvn/mpdma/mpdma/trunk

Subversion Repositories mpdma

[/] [mpdma/] [trunk/] [mb-bmp2jpg/] [zzq.c] - Blame information for rev 7

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

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

powered by: WebSVN 2.1.0

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