OSDN Git Service

AI003:config.txt, words.txtを追加。
[chnosproject/CHNOSProject.git] / CHNOSProject / chnos / tolset_chn_000 / chnos_010 / chnos / fmt_bmp.c
1 \r
2 #include "core.h"\r
3 \r
4 //\83p\83f\83B\83\93\83O\82Ì\8aÖ\8cW\82Å\82±\82ñ\82È\82±\82Æ\82É\82È\82Á\82Ä\82é\r
5 typedef struct DATA_FORMAT_BMP_FILE_HEADER {\r
6         uchar sign[2];\r
7         uchar filesize[4];\r
8         uchar reserved0[2];\r
9         uchar reserved1[2];\r
10         uchar offset_to_data[4];\r
11 } DATA_Format_BMP_FileHeader;\r
12 \r
13 //OS/2 Type\r
14 typedef struct DATA_FORMAT_BMP_CORE_HEADER {\r
15         uint headersize;\r
16         short xsize;\r
17         short ysize;\r
18         ushort planes;\r
19         ushort bpp;\r
20 } DATA_Format_BMP_CoreHeader;\r
21 \r
22 //Windows Type\r
23 typedef struct DATA_FORMAT_BMP_INFO_HEADER {\r
24         uint headersize;\r
25         int xsize;\r
26         int ysize;\r
27         ushort planes;\r
28         ushort bpp;\r
29         uint compression_type;  //0:no compression, 1:RLE8 2:RLE4 3:bit field\r
30         uint image_data_size;\r
31         uint pixel_per_meter_x;\r
32         uint pixel_per_meter_y;\r
33         uint colors_in_palette;\r
34         uint index_of_important_color;\r
35 } DATA_Format_BMP_InformationHeader;\r
36 \r
37 typedef struct DATA_FORMAT_BMP_RGB24 {\r
38         uchar b;\r
39         uchar g;\r
40         uchar r;\r
41 } DATA_Format_BMP_RGB24;\r
42 \r
43 uint Format_BMP_DrawPicture(void *vram, uint xsize, uint x, uint y, uint pxsize, uint pysize, void *bmp)\r
44 {\r
45         uchar s[128];\r
46         DATA_Format_BMP_FileHeader *fheader;\r
47         DATA_Format_BMP_InformationHeader *infoheader;\r
48         uint *read32;\r
49         DATA_Format_BMP_RGB24 *rgb24;\r
50         uint ix, iy;\r
51 \r
52         uint offset_to_data, filesize;\r
53 \r
54         fheader = (DATA_Format_BMP_FileHeader *)bmp;\r
55 \r
56         if(fheader->sign[0] != 'B' || fheader->sign[1] != 'M'){\r
57                 Drawing_Put_String(vram, xsize, x, y, 0x000000, "BMP:Unknown File Format.");\r
58                 return 1;\r
59         }\r
60 \r
61         read32 = (uint *)(&fheader->filesize[0]);\r
62         filesize = *read32;\r
63         read32 = (uint *)(&fheader->offset_to_data[0]);\r
64         offset_to_data = *read32;\r
65 \r
66         //snprintf(s, sizeof(s), "size:%d offset:%d", filesize, offset_to_data);\r
67         //Drawing_Put_String(vram, xsize, x, y, 0x000000, s);\r
68 \r
69         read32 = (uint *)(bmp + 0x0e);\r
70 \r
71         if(*read32 == 12){\r
72                 Drawing_Put_String(vram, xsize, x, y + 16 * 1, 0x000000, "BMP Core Header.(not implemented.)");\r
73                 return 2;\r
74         } else if(*read32 == 40){\r
75                 //Drawing_Put_String(vram, xsize, x, y + 16 * 1, 0x000000, "BMP INFO Header.");\r
76                 infoheader = (DATA_Format_BMP_InformationHeader *)(bmp + 0x0e);\r
77                 if(infoheader->ysize > 0){\r
78                         //Drawing_Put_String(vram, xsize, x, y + 16 * 2, 0x000000, "Bottom Up.");\r
79                 } else{\r
80                         Drawing_Put_String(vram, xsize, x, y + 16 * 2, 0x000000, "Top Down (not implemented).");\r
81                         return 5;\r
82                 }\r
83 \r
84                 if(infoheader->compression_type == 0){\r
85                         //Drawing_Put_String(vram, xsize, x, y + 16 * 3, 0x000000, "No compression.");\r
86                 } else{\r
87                         Drawing_Put_String(vram, xsize, x, y + 16 * 3, 0x000000, "Compressed (not implemented).");\r
88                         return 4;\r
89                 }\r
90 \r
91                 if(infoheader->bpp == 24){\r
92                         //Drawing_Put_String(vram, xsize, x, y + 16 * 4, 0x000000, "24 bpp.");\r
93                 } else{\r
94                         snprintf(s, sizeof(s), "%d bpp(not implemented).", infoheader->bpp);\r
95                         Drawing_Put_String(vram, xsize, x, y + 16 * 4, 0x000000, s);\r
96                         return 6;\r
97                 }\r
98 \r
99                 //snprintf(s, sizeof(s), "xsize:%d ysize:%d", infoheader->xsize, infoheader->ysize);\r
100                 //Drawing_Put_String(vram, xsize, x, y + 16 * 5, 0x000000, s);\r
101 \r
102                 rgb24 = (DATA_Format_BMP_RGB24 *)(bmp + offset_to_data);\r
103 \r
104                 for(iy = infoheader->ysize; iy > 0; iy--){\r
105                         for(ix = 0; ix < infoheader->xsize; ix++){\r
106                                 Drawing_Draw_Point(vram, xsize, x + ix, y + iy - 1, rgb24->r << 16 | rgb24->g << 8 | rgb24->b);\r
107                                 rgb24 = (DATA_Format_BMP_RGB24 *)((uint)rgb24 + 3);\r
108                         }\r
109                         rgb24 = (DATA_Format_BMP_RGB24 *)((uint)rgb24 + ((infoheader->xsize + 3) & ~3) - infoheader->xsize);\r
110                 }\r
111         } else{\r
112                 Drawing_Put_String(vram, xsize, x, y + 16 * 1, 0x000000, "Unknown BMP Header.");\r
113                 return 3;\r
114         }\r
115 \r
116         return 0;\r
117 }\r