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

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [STEP2_2b/] [mb-bmp2jpg/] [xupv2p.c] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 quickwayne
#ifdef __XUPV2P
2
 
3
//  Microblaze related declaration
4
 
5
#include <xparameters.h>
6
#include <sysace_stdio.h>
7
 
8
#include "xio.h"
9
 
10
#include "ejpgl.h"
11
 
12
#define __MICROBLAZE
13
#define __BIGENDIAN
14
 
15
// XUPV2P board related declaration 
16
 
17 58 quickwayne
#define BMP_ADDRESS  0x30000000
18 56 quickwayne
#define BMP_MAXSIZE   4*1024*1024
19
 
20
 
21
SYSACE_FILE *infile;
22
SYSACE_FILE *outfile;
23
 
24
char* bmpimage;
25
int bmpsize;
26
 
27
INFOHEADER _bmpheader;
28
INFOHEADER *bmpheader;
29
JPEGHEADER _jpegheader;
30
 
31
int getbmpheader(INFOHEADER *header);
32
void writejpegfooter();
33
 
34
 
35
unsigned long htonl(unsigned long x) {
36
 
37
        return ((((x)&0xff000000)>>24) | (((x)&0x00ff0000)>>8) | (((x)&0x0000ff00)<<8) | (((x)&0x000000ff)<<24));
38
 
39
}
40
 
41
unsigned short hton(unsigned short x) {
42
 
43
        return ((((x) & 0xff00)>>8) | (((x) &0x00ff)<<8));
44
 
45
}
46
 
47
 
48 57 quickwayne
int openBMPJPG(int argc, char* bmpfilename, char* jpgfilename) {
49 56 quickwayne
        int jpegheadersize;
50
 
51 58 quickwayne
        bmpimage=(unsigned char*)BMP_ADDRESS;
52 56 quickwayne
        bmpsize=0;
53
 
54
        xil_printf("\r\nBMP2JPG Code Compiled at %s %s\r\n", __DATE__, __TIME__);
55 57 quickwayne
 
56
        bmpfilename = "image01.bmp";  // argc argv is not accepted on XUPV2P yet
57
        jpgfilename = "image01.jpg";
58 56 quickwayne
 
59
        bmpheader=&_bmpheader;
60
 
61
        if ((infile = sysace_fopen(bmpfilename, "r")) == NULL) {   // not "rb"
62
        xil_printf("\n\r%s is not a valid BMP-file",bmpfilename);
63 57 quickwayne
                exit(0);
64 56 quickwayne
        }
65
 
66
        bmpsize = sysace_fread(bmpimage, 1, BMP_MAXSIZE, infile);
67
        xil_printf("bmpsize %d\r\n", bmpsize);
68
        if (bmpsize==BMP_MAXSIZE) {
69
        xil_printf("\n\r%s is too large",bmpfilename);
70 57 quickwayne
                exit(0);
71 56 quickwayne
        }
72
 
73
 
74
        if (getbmpheader(bmpheader) == 0) { //File is a valid BMP
75
        xil_printf("\r\n%s is not a valid BMP-file",bmpfilename);
76 57 quickwayne
                exit(0);
77 56 quickwayne
        }
78
 
79
        xil_printf("Image width: %d pixels\r\n", bmpheader->width);
80
        xil_printf("Image height: %d pixels\r\n", bmpheader->height);
81
 
82
       outfile = sysace_fopen(jpgfilename, "w");  // not "wb"
83 57 quickwayne
        if (outfile == NULL) {
84
        xil_printf("\r\nerror in writing jpg header");
85
                exit(0);
86
                }
87 56 quickwayne
 
88
        jpegheadersize = writejpegheader(bmpheader, &_jpegheader);
89
        if (jpegheadersize == 0) return 0;
90
 
91
        sysace_fwrite(&_jpegheader,jpegheadersize,1,outfile);
92
 
93
        return 1;
94
 
95
}
96
 
97
int closeBMPJPG() {
98
        unsigned int col, cols, row, rows;
99
 
100
        rows = bmpheader->height>>4;
101
       cols = bmpheader->width>>4;
102
       xil_printf("\r\nProcessed more than %d %dx%d-blocks.",(row-1)*cols,MATRIX_SIZE,MATRIX_SIZE);  // +col
103
 
104
        writejpegfooter();
105
 
106
        sysace_fclose(outfile);
107
        sysace_fclose(infile);
108
 
109
        return 0;
110
 
111
}
112
 
113
static unsigned char buffer[MACRO_BLOCK_SIZE*3];  // move array on main memory
114
 
115
void get_MB(int mb_row, int mb_col, signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_SIZE*3]) {
116
       unsigned int row, col;
117
        int offset;
118
 
119
        for(row = 0;row < MACRO_BLOCK_SIZE; row++) {
120
//              offset = bmpsize-3*bmpheader->width*(row + 1 + mb_row*MATRIX_SIZE)+MATRIX_SIZE*3*mb_col;
121
//              memcpy(pixelmatrix[row], bmpimage + offset, MATRIX_SIZE*3);
122
                offset = bmpsize-3*bmpheader->width*(row + 1 + mb_row*MACRO_BLOCK_SIZE)+MACRO_BLOCK_SIZE*3*mb_col;
123
                memcpy(buffer, bmpimage + offset, MACRO_BLOCK_SIZE*3);
124
                        for(col = 0; col < MACRO_BLOCK_SIZE*3; col++) {
125
                                pixelmatrix[row][col] = buffer[col]- 128;
126
                        }
127
        }
128
 
129
}
130
 
131
void put_char(unsigned char c) {
132
 
133
        sysace_fwrite(&c, 1, 1, outfile);
134
 
135
}
136
 
137
 
138
int getbmpheader(INFOHEADER *header)
139
{
140
       memcpy(header, bmpimage+14, sizeof(INFOHEADER));
141
 
142
#if defined(__BIGENDIAN)      // for Big Endian processors
143
 
144
        header->size = htonl(header->size);
145
        header->width = htonl(header->width);
146
        header->height = htonl(header->height);
147
        header->planes = hton(header->planes);
148
        header->bits = hton(header->bits);
149
        header->compression = htonl(header->compression);
150
        header->imagesize = htonl(header->imagesize);
151
        header->xresolution = htonl(header->xresolution);
152
        header->yresolution= htonl(header->yresolution);
153
        header->ncolours= htonl(header->ncolours);
154
        header->importantcolours= htonl(header->importantcolours);
155
 
156
#endif
157
 
158
        return 1;
159
 
160
}
161
 
162
void writejpegfooter()
163
{
164
        unsigned char footer[2];
165
        footer[0] = 0xff;
166
        footer[1] = 0xd9;
167
//        fseek(file,0,SEEK_END);
168
        sysace_fwrite(footer,sizeof(footer),1, outfile);
169
 
170
}
171
 
172
 
173
 
174
 
175
 
176
 
177
 
178
#endif
179
 
180
 
181
 

powered by: WebSVN 2.1.0

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