OSDN Git Service

svn rev.329より移動。
[chnosproject/CHNOSProject.git] / CHNOSProject / chnos / tolset_chn_000 / chnos_010 / chnos / fmt_bmp.c
diff --git a/CHNOSProject/chnos/tolset_chn_000/chnos_010/chnos/fmt_bmp.c b/CHNOSProject/chnos/tolset_chn_000/chnos_010/chnos/fmt_bmp.c
new file mode 100644 (file)
index 0000000..9d1f795
--- /dev/null
@@ -0,0 +1,117 @@
+\r
+#include "core.h"\r
+\r
+//\83p\83f\83B\83\93\83O\82Ì\8aÖ\8cW\82Å\82±\82ñ\82È\82±\82Æ\82É\82È\82Á\82Ä\82é\r
+typedef struct DATA_FORMAT_BMP_FILE_HEADER {\r
+       uchar sign[2];\r
+       uchar filesize[4];\r
+       uchar reserved0[2];\r
+       uchar reserved1[2];\r
+       uchar offset_to_data[4];\r
+} DATA_Format_BMP_FileHeader;\r
+\r
+//OS/2 Type\r
+typedef struct DATA_FORMAT_BMP_CORE_HEADER {\r
+       uint headersize;\r
+       short xsize;\r
+       short ysize;\r
+       ushort planes;\r
+       ushort bpp;\r
+} DATA_Format_BMP_CoreHeader;\r
+\r
+//Windows Type\r
+typedef struct DATA_FORMAT_BMP_INFO_HEADER {\r
+       uint headersize;\r
+       int xsize;\r
+       int ysize;\r
+       ushort planes;\r
+       ushort bpp;\r
+       uint compression_type;  //0:no compression, 1:RLE8 2:RLE4 3:bit field\r
+       uint image_data_size;\r
+       uint pixel_per_meter_x;\r
+       uint pixel_per_meter_y;\r
+       uint colors_in_palette;\r
+       uint index_of_important_color;\r
+} DATA_Format_BMP_InformationHeader;\r
+\r
+typedef struct DATA_FORMAT_BMP_RGB24 {\r
+       uchar b;\r
+       uchar g;\r
+       uchar r;\r
+} DATA_Format_BMP_RGB24;\r
+\r
+uint Format_BMP_DrawPicture(void *vram, uint xsize, uint x, uint y, uint pxsize, uint pysize, void *bmp)\r
+{\r
+       uchar s[128];\r
+       DATA_Format_BMP_FileHeader *fheader;\r
+       DATA_Format_BMP_InformationHeader *infoheader;\r
+       uint *read32;\r
+       DATA_Format_BMP_RGB24 *rgb24;\r
+       uint ix, iy;\r
+\r
+       uint offset_to_data, filesize;\r
+\r
+       fheader = (DATA_Format_BMP_FileHeader *)bmp;\r
+\r
+       if(fheader->sign[0] != 'B' || fheader->sign[1] != 'M'){\r
+               Drawing_Put_String(vram, xsize, x, y, 0x000000, "BMP:Unknown File Format.");\r
+               return 1;\r
+       }\r
+\r
+       read32 = (uint *)(&fheader->filesize[0]);\r
+       filesize = *read32;\r
+       read32 = (uint *)(&fheader->offset_to_data[0]);\r
+       offset_to_data = *read32;\r
+\r
+       //snprintf(s, sizeof(s), "size:%d offset:%d", filesize, offset_to_data);\r
+       //Drawing_Put_String(vram, xsize, x, y, 0x000000, s);\r
+\r
+       read32 = (uint *)(bmp + 0x0e);\r
+\r
+       if(*read32 == 12){\r
+               Drawing_Put_String(vram, xsize, x, y + 16 * 1, 0x000000, "BMP Core Header.(not implemented.)");\r
+               return 2;\r
+       } else if(*read32 == 40){\r
+               //Drawing_Put_String(vram, xsize, x, y + 16 * 1, 0x000000, "BMP INFO Header.");\r
+               infoheader = (DATA_Format_BMP_InformationHeader *)(bmp + 0x0e);\r
+               if(infoheader->ysize > 0){\r
+                       //Drawing_Put_String(vram, xsize, x, y + 16 * 2, 0x000000, "Bottom Up.");\r
+               } else{\r
+                       Drawing_Put_String(vram, xsize, x, y + 16 * 2, 0x000000, "Top Down (not implemented).");\r
+                       return 5;\r
+               }\r
+\r
+               if(infoheader->compression_type == 0){\r
+                       //Drawing_Put_String(vram, xsize, x, y + 16 * 3, 0x000000, "No compression.");\r
+               } else{\r
+                       Drawing_Put_String(vram, xsize, x, y + 16 * 3, 0x000000, "Compressed (not implemented).");\r
+                       return 4;\r
+               }\r
+\r
+               if(infoheader->bpp == 24){\r
+                       //Drawing_Put_String(vram, xsize, x, y + 16 * 4, 0x000000, "24 bpp.");\r
+               } else{\r
+                       snprintf(s, sizeof(s), "%d bpp(not implemented).", infoheader->bpp);\r
+                       Drawing_Put_String(vram, xsize, x, y + 16 * 4, 0x000000, s);\r
+                       return 6;\r
+               }\r
+\r
+               //snprintf(s, sizeof(s), "xsize:%d ysize:%d", infoheader->xsize, infoheader->ysize);\r
+               //Drawing_Put_String(vram, xsize, x, y + 16 * 5, 0x000000, s);\r
+\r
+               rgb24 = (DATA_Format_BMP_RGB24 *)(bmp + offset_to_data);\r
+\r
+               for(iy = infoheader->ysize; iy > 0; iy--){\r
+                       for(ix = 0; ix < infoheader->xsize; ix++){\r
+                               Drawing_Draw_Point(vram, xsize, x + ix, y + iy - 1, rgb24->r << 16 | rgb24->g << 8 | rgb24->b);\r
+                               rgb24 = (DATA_Format_BMP_RGB24 *)((uint)rgb24 + 3);\r
+                       }\r
+                       rgb24 = (DATA_Format_BMP_RGB24 *)((uint)rgb24 + ((infoheader->xsize + 3) & ~3) - infoheader->xsize);\r
+               }\r
+       } else{\r
+               Drawing_Put_String(vram, xsize, x, y + 16 * 1, 0x000000, "Unknown BMP Header.");\r
+               return 3;\r
+       }\r
+\r
+       return 0;\r
+}\r