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

Subversion Repositories mpdma

[/] [mpdma/] [trunk/] [mb-cc/] [io.h] - Blame information for rev 20

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

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

powered by: WebSVN 2.1.0

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