00001 #include "MercuryFiles.h"
00002 #include "BMPWriter.h"
00003
00004 void WriteBMP(const MString& path, const RawImageData& image)
00005 {
00006 BMPHeader header;
00007 BMPInfoHeader info;
00008 char buffer[3];
00009
00010 info.imagesize = image.attrs.m_height * image.attrs.m_width * 3;
00011 unsigned int realSize = image.attrs.m_height * image.attrs.m_width * ColorBytesToSize(image.attrs.m_ColorByteType);
00012
00013 header.offset = 54;
00014 memcpy(header.ID, "BM", 2);
00015 header.fileSize = 54 + info.imagesize;
00016 header.reserved = 0;
00017
00018 info.bbp = 24;
00019 info.compression = 0;
00020 info.headerSize = 40;
00021 info.height = image.attrs.m_height;
00022 info.width = image.attrs.m_width;
00023 info.importantColor = 0;
00024 info.numColor = 0;
00025 info.planes = 1;
00026 info.resx = (int)(image.attrs.m_dpi_x * 39.3700787);
00027 info.resy = (int)(image.attrs.m_dpi_y * 39.3700787);
00028
00029 MercuryFile* f = FILEMAN.Open(path, MFP_WRITE_ONLY);
00030
00031
00032 f->Write(header.ID, 2);
00033 f->Write(&header.fileSize, 4);
00034 f->Write(&header.reserved, 4);
00035 f->Write(&header.offset, 4);
00036
00037 f->Write(&info, 40);
00038
00039
00040 if (image.attrs.m_ColorByteType == RGB)
00041 for (unsigned int x = 0; x < realSize; x += 3)
00042 {
00043 buffer[2] = image.data[x];
00044 buffer[1] = image.data[x+1];
00045 buffer[0] = image.data[x+2];
00046 f->Write(buffer, 3);
00047 }
00048 else if (image.attrs.m_ColorByteType == RGBA)
00049 for (unsigned int x = 0; x < realSize; x += 4)
00050 {
00051 buffer[2] = image.data[x];
00052 buffer[1] = image.data[x+1];
00053 buffer[0] = image.data[x+2];
00054 f->Write(buffer, 3);
00055 }
00056
00057 SAFE_DELETE(f);
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086