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

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [STEP2_2b/] [encoder/] [zzq.c] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 quickwayne
//---------------------------------------------------------------------------
2
#include <stdio.h>
3
#include "zzq.h"
4
#pragma hdrstop
5
//---------------------------------------------------------------------------
6
#pragma argsused
7
 
8
static unsigned char quantization_table[MATRIX_SIZE][MATRIX_SIZE] ={
9
        {4, 3, 3, 4, 4, 5, 6, 6},
10
        {3, 3, 4, 4, 5, 6, 6, 6},
11
        {4, 4, 4, 4, 5, 6, 6, 6},
12
        {4, 4, 4, 5, 6, 6, 6, 6},
13
        {4, 4, 5, 6, 6, 7, 7, 6},
14
        {4, 5, 6, 6, 6, 7, 7, 6},
15
        {6, 6, 6, 6, 7, 7, 7, 7},
16
        {6, 6, 6, 7, 7, 7, 7, 7}
17
    };
18
 
19
//static int __count3=0;
20
 
21
void zzq(signed short pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], signed char *bitstream, int compression, int encode)
22
{
23
    int i, x, y, jumped, deltax, deltay;
24
 
25
    x = y = deltax = deltay = jumped = 0;
26
  //  printf("\nZigZag order pixelmatrix:\n\n");
27
    for(i=0;i<NUMBER_OF_PIXELS;i++)
28
    {
29
        if (encode == 0) {
30
                pixelmatrix[y][x] = (bitstream[i]*quantization_table[y][x]);
31
        } else {
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
              //  printf("%i ",bitstream[i]);
37
#if 0              
38
 #ifdef __MICROBLAZE
39
       if (__count3<256*3) {
40
        xil_printf("%x ", bitstream[i]);
41
        __count3++;
42
        if ((__count3&0x0f)==0) xil_printf("\r\n");
43
        }
44
#else
45
       if (__count3<256*3) {
46
        printf(" %x ", bitstream[i]);
47
        __count3++;
48
        if ((__count3&0x0f)==0) printf("\r\n");
49
        }
50
#endif
51
#endif
52
       }
53
 
54
        if((y == 0) || (y == MATRIX_SIZE-1)) { //on top or bottom side of matrix
55
                if(!jumped) { //first jump to element on the right
56
                        x++;
57
                        jumped = 1;
58
                } else { //modify direction
59
                        if(i<(NUMBER_OF_PIXELS>>1)) {
60
                                deltax = -1;
61
                                deltay = 1;
62
                        } else {
63
                                deltax = 1;
64
                                deltay = -1;
65
                        }
66
                        x += deltax;
67
                        y += deltay;
68
                        jumped = 0;
69
                }
70
        } else if ((x == 0) || (x == MATRIX_SIZE-1)) { //on left or right side of matrix
71
                if(!jumped) { //jump to element below
72
                        y++;
73
                        jumped = 1;
74
                } else { //modify direction
75
                        if(i<(NUMBER_OF_PIXELS>>1)) {
76
                                deltax = 1;
77
                                deltay = -1;
78
                        } else {
79
                                deltax = -1;
80
                                deltay = 1;
81
                        }
82
                        x += deltax;
83
                        y += deltay;
84
                        jumped = 0;
85
                }
86
        }
87
        else {//not on the edges of the matrix
88
                x += deltax;
89
                y += deltay;
90
        }
91
    }
92
}
93
//---------------------------------------------------------------------------
94
 

powered by: WebSVN 2.1.0

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