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

Subversion Repositories mpdma

[/] [mpdma/] [trunk/] [mb-bmp2jpg/] [io.h] - Blame information for rev 28

Details | Compare with Previous | View Log

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