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

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [Step2_2/] [encoder/] [io.h] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 quickwayne
#ifndef _IO_H
2
#define _IO_H 1
3
#define MATRIX_SIZE 8
4
typedef struct {
5
   unsigned int size;               /* Header size in bytes      */
6
   int width,height;                /* Width and height of image */
7
   unsigned short int planes;       /* Number of colour planes   */
8
   unsigned short int bits;         /* Bits per pixel            */
9
   unsigned int compression;        /* Compression type          */
10
   unsigned int imagesize;          /* Image size in bytes       */
11
   int xresolution,yresolution;     /* Pixels per meter          */
12
   unsigned int ncolours;           /* Number of colours         */
13
   unsigned int importantcolours;   /* Important colours         */
14
   unsigned char palette[1024];      /* Storage for palette       */
15
} INFOHEADER;
16
 
17
typedef struct {
18
   int restofheader; //TODO
19
   INFOHEADER info;                 /* Information header        */
20
} BMPHEADER;
21
 
22
typedef struct {
23
   unsigned int row;     /* Width and height of image */
24
   unsigned int col;   /* Width and height of image */
25
} BLOCKINFO;
26
 
27
typedef struct {
28
        unsigned char QTMarker[2];
29
        unsigned char Length[2];
30
        unsigned char QTInfo[130]; //bit 0..3: number of QT (0..3, otherwise error)
31
                                //     bit 4..7: precision of QT, 0 = 8 bit, otherwise 16 bit
32
    //    unsigned char ValuesQT[]; //max 192 values. 64*(precision+1) bytes
33
} QTINFO;
34
 
35
typedef struct {
36
            unsigned char HTMarker[2];
37
            unsigned char Length[2];
38
            unsigned char HuffmanInfo[416]; //Array containing ALL huffman information
39
            //For each color component holds:
40
                    //First byte is used as info byte, followed by 16 bytes with values used
41
                    //for counting the different huffman codes, finally the corresponding
42
                    //huffman codes will follow. This sequence can repeat it self for
43
                    //different Huffman tables, both DC or AC tables.
44
 
45
                    //The structure of the information byte is as follows:
46
                    //bit 0..3 : number of HT (0..3, otherwise error)
47
                    //bit 4     : type of HT, 0 = DC table, 1 = AC table
48
                    //bit 5..7 : not used, must be 0 (Used for  progressive scan JPEG)
49
} HTINFO;
50
 
51
 
52
typedef struct {
53
            unsigned char APP0Marker[2];
54
            unsigned char Length[2];
55
            unsigned char Identifier[5];
56
            unsigned char Version[2];
57
            unsigned char Units;
58
            unsigned char XDensity[2];
59
            unsigned char YDensity[2];
60
            unsigned char ThumbWidth;
61
            unsigned char ThumbHeight;
62
} APP0INFO;
63
 
64
typedef struct {
65
            unsigned char SOF0Marker[2];
66
            unsigned char Length[2];
67
            unsigned char DataPrecision; //This is in bits/sample, usually 8 (12 and 16 not supported by most software).
68
            unsigned char ImageHeight[2];
69
            unsigned char ImageWidth[2];
70
            unsigned char Components; //Usually 1 = grey scaled, 3 = color YcbCr or YIQ 4 = color CMYK
71
            unsigned char ComponentInfo[3][3]; //Read each component data of 3 bytes. It contains,
72
                                       //(component Id(1byte)(1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q),
73
                                         //sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),
74
                                           //quantization table number (1 byte)).
75
} SOF0INFO;
76
 
77
typedef struct {
78
            unsigned char SOSMarker[2];
79
            unsigned char Length[2]; //This must be equal to 6+2*(number of components in scan).
80
            unsigned char ComponentCount; //This must be >= 1 and <=4 (otherwise error), usually 1 or 3
81
            unsigned char Component[3][2]; // For each component, read 2 bytes. It contains,
82
                                          //1 byte   Component Id (1=Y, 2=Cb, 3=Cr, 4=I, 5=Q),
83
                                            //1 byte   Huffman table to use :
84
                                              //bit 0..3 : AC table (0..3)
85
                                                //bit 4..7 : DC table (0..3)
86
            unsigned char Ignore[3]; //We have to skip 3 bytes
87
} SOSINFO;
88
 
89
typedef struct {
90
            unsigned char DRIMarker[2];
91
            unsigned char Length[2];
92
            unsigned char RestartInteral[2]; // Interval of the restart markers
93
} DRIINFO;
94
 
95
typedef struct {
96
            unsigned char SOIMarker[2]; //Start of image marker
97
            APP0INFO app0;
98
            QTINFO qt;
99
            SOF0INFO sof0;
100
            HTINFO ht;
101
//            DRIINFO dri;
102
            SOSINFO sos;
103
} JPEGHEADER;
104
 
105
/*
106
 * Read BMP header and return it in header, for now only the width and height
107
 * are returned, since the other values are of no use.
108
 */
109
int getbmpheader(FILE * file, INFOHEADER *header);
110
 
111
int getjpegheader(FILE * file, JPEGHEADER *header);
112
 
113
void writebmpheader(FILE * file, BMPHEADER *header);
114
 
115
void writejpegheader(FILE * file, INFOHEADER *header);
116
 
117
void writejpegfooter(FILE * file);
118
 
119
/*
120
 * Read BMP to retrieve 8*8 block starting at horizontal position mcol*8, and
121
 * vertical position mrow*8 in the image. This block is returned in pixelmatrix.
122
 *
123
 */
124
void readbmpfile(FILE * file, signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3], unsigned int mrow, unsigned int mcol, INFOHEADER * header);
125
 
126
void RGB2YCrCb(signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],signed char YMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CrMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CbMatrix[MATRIX_SIZE][MATRIX_SIZE]);
127
 
128
void readjpegfile(FILE * file, unsigned char bitstream[]);
129
 
130
void writebmpfile(FILE * file, unsigned char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], unsigned int mrow, unsigned int mcol, unsigned int width);
131
 
132
void writejpegfile(FILE * file, unsigned char bitstream[]);
133
#else
134
#error "ERROR file io.h multiple times included"
135
#endif /* --- _IO_H --- */
136
 

powered by: WebSVN 2.1.0

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