source: rtems/c/src/lib/libbsp/arm/nds/tools/ndstool/source/banner.cpp @ 9a12c7e5

4.104.115
Last change on this file since 9a12c7e5 was 9a12c7e5, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/09 at 02:04:42

2009-05-03 Joel Sherrill <joel.sherrill@…>

  • ndstool/include/banner.h, ndstool/include/header.h, ndstool/include/ndstree.h, ndstool/source/banner.cpp, ndstool/source/header.cpp, ndstool/source/ndscreate.cpp, ndstool/source/ndstool.cpp, ndstool/source/passme.cpp: Remove warnings for deprecated character conversions.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include "ndstool.h"
2#include "raster.h"
3#include "banner.h"
4#include "crc.h"
5
6const char *bannerLanguages[] = { "Japanese", "English", "French", "German", "Italian", "Spanish" };
7
8#define RGB16(r,g,b)                    ((r) | (g<<5) | (b<<10))
9
10/*
11 * RGBQuadToRGB16
12 */
13inline unsigned short RGBQuadToRGB16(RGBQUAD quad)
14{
15        unsigned short r = quad.rgbRed;
16        unsigned short g = quad.rgbGreen;
17        unsigned short b = quad.rgbBlue;
18        return RGB16(r>>3, g>>3, b>>3);
19}
20
21/*
22 * CalcBannerCRC
23 */
24unsigned short CalcBannerCRC(Banner &banner)
25{
26        return CalcCrc16((unsigned char *)&banner + 32, 0x840 - 32);
27}
28
29/*
30 * IconFromBMP
31 */
32void IconFromBMP()
33{
34        CRaster bmp;
35        int rval = bmp.LoadBMP(bannerfilename);
36        if (rval < 0) exit(1);
37
38        if (bmp.width != 32 || bmp.height != 32) {
39                fprintf(stderr, "Image should be 32 x 32.\n");
40                exit(1);
41        }
42
43        Banner banner;
44        memset(&banner, 0, sizeof(banner));
45        banner.version = 1;
46
47        // tile data (4 bit / tile, 4x4 total tiles)
48        // 32 bytes per tile (in 4 bit mode)
49        for (int row=0; row<4; row++)
50        {
51                for (int col=0; col<4; col++)
52                {
53                        for (int y=0; y<8; y++)
54                        {
55                                for (int x=0; x<8; x+=2)
56                                {
57                                        unsigned char b0 = bmp[row*8 + y][col*8 + x + 0];
58                                        unsigned char b1 = bmp[row*8 + y][col*8 + x + 1];
59                                        banner.tile_data[row][col][y][x/2] = (b1 << 4) | b0;
60                                }
61                        }
62                }
63        }
64
65        // palette
66        for (int i = 0; i < 16; i++)
67        {
68                banner.palette[i] = RGBQuadToRGB16(bmp.palette[i]);
69        }
70
71        // put title
72        for (int i=0; bannertext[i]; i++)
73        {
74                char c = bannertext[i];
75                if (c == ';') c = 0x0A;
76                for (int l=0; l<6; l++)
77                {
78                        banner.title[l][i] = c;
79                }
80        }
81       
82        // calculate CRC
83        banner.crc = CalcBannerCRC(banner);
84
85        fwrite(&banner, 1, sizeof(banner), fNDS);
86}
Note: See TracBrowser for help on using the repository browser.