OpenCores
URL https://opencores.org/ocsvn/kiss-board/kiss-board/trunk

Subversion Repositories kiss-board

[/] [kiss-board/] [trunk/] [kiss-board_soc/] [sw/] [bmp2c/] [bmp2c_rgb565.c] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 fukuchi
 
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
 
6
#include "bmp.h"
7
 
8
int WIDTH;
9
int HEIGHT;
10
 
11
int             xx,yy;
12
BITMAP          bitmap;
13
 
14
int main(int,char **);
15
void start_blue(void);
16
 
17
int main(int argc,char *argv[]){
18
        unsigned short int r,g,b,rgb565;
19
 
20
        if (argc!=2) {fprintf(stderr,"argc error%d\n",argc); return -1;}
21
 
22
        BmpRead((BITMAP*)&bitmap);
23
 
24
        WIDTH  = bitmap.bitMapInfo.biWidth;
25
        HEIGHT = bitmap.bitMapInfo.biHeight;
26
 
27
        fprintf(stdout,"\n");
28
        fprintf(stdout,"#include \"image.h\"\n");
29
        fprintf(stdout,"\n");
30
 
31
        {
32
                char temp[256];
33
                strcpy(temp,argv[1]);
34
                strupr(temp);
35
                fprintf(stdout,"\n");
36
                fprintf(stdout,"#define %s_SRC_SIZE %d\n",temp,WIDTH*HEIGHT);
37
                fprintf(stdout,"\n");
38
        }
39
 
40
        fprintf(stdout,"const unsigned short int %s_src[%d][%d] = {\n",argv[1],HEIGHT,WIDTH);
41
        for (yy=0;yy<HEIGHT;yy++) {
42
                fprintf(stdout,"\t{ // line:%d",yy);
43
                for (xx=0;xx<WIDTH;xx++) {
44
                        r = (unsigned short int)bitmap.bitColor[xx][yy].r;
45
                        g = (unsigned short int)bitmap.bitColor[xx][yy].g;
46
                        b = (unsigned short int)bitmap.bitColor[xx][yy].b;
47
                        r = ( (0x0004==(r&0x0004)) ) ? r + 1: r;
48
                        g = ( (0x0008==(g&0x0008)) ) ? g + 1: g;
49
                        b = ( (0x0004==(b&0x0004)) ) ? b + 1: b;
50
                        r = (r>255) ? 255: r;
51
                        g = (g>255) ? 255: g;
52
                        b = (b>255) ? 255: b;
53
                        r = (r<<8)&0xf800;
54
                        g = (g<<3)&0x07e0;
55
                        b = (b>>3)&0x001f;
56
                        rgb565 = r + g + b;
57
                        if (0==xx%16) fprintf(stdout,"\n\t\t");
58
                        fprintf(stdout,"0x%04x",rgb565);
59
                        if (xx!=(WIDTH-1)) fprintf(stdout,",");
60
                }
61
                fprintf(stdout,"\n\t}");
62
                if (yy!=(HEIGHT-1)) fprintf(stdout,",");
63
                fprintf(stdout,"\n");
64
        }
65
        fprintf(stdout,"};\n");
66
        fprintf(stdout,"\n");
67
 
68
        fprintf(stdout,"const IMAGE %s = { %d , %d , (void *)%s_src };\n",argv[1],WIDTH,HEIGHT,argv[1]);
69
        fprintf(stdout,"\n");
70
 
71
        return 0;
72
}

powered by: WebSVN 2.1.0

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