| 35 | } |
| 36 | |
| 37 | void FileSystemBase::SaveBitmapToFile(byte* data, uint32 width, uint32 height, uint32 bitsPerPixel, const uint32 padding, const String& path) |
| 38 | { |
| 39 | // Try to open file |
| 40 | auto file = File::Open(path, FileMode::CreateAlways, FileAccess::Write, FileShare::None); |
| 41 | if (file == nullptr) |
| 42 | return; |
| 43 | |
| 44 | const unsigned long headers_size = 54; |
| 45 | const unsigned long pixel_data_size = height * ((width * bitsPerPixel / 8) + padding); |
| 46 | const unsigned int filesize = headers_size + pixel_data_size; |
| 47 | uint8 bmpfileheader[14] = { 'B', 'M', 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0 }; |
| 48 | uint8 bmpinfoheader[40] = { 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0 }; |
| 49 | uint8 bmppad[3] = { 0, 0, 0 }; |
| 50 | |
| 51 | // Init the file header |
| 52 | bmpfileheader[2] = (uint8)(filesize); |
| 53 | bmpfileheader[3] = (uint8)(filesize >> 8); |
| 54 | bmpfileheader[4] = (uint8)(filesize >> 16); |
| 55 | bmpfileheader[5] = (uint8)(filesize >> 24); |
| 56 | |
| 57 | // Init the bitmap info header |
| 58 | bmpinfoheader[4] = (uint8)(width); |
| 59 | bmpinfoheader[5] = (uint8)(width >> 8); |
| 60 | bmpinfoheader[6] = (uint8)(width >> 16); |
| 61 | bmpinfoheader[7] = (uint8)(width >> 24); |
| 62 | bmpinfoheader[8] = (uint8)(height); |
| 63 | bmpinfoheader[9] = (uint8)(height >> 8); |
| 64 | bmpinfoheader[10] = (uint8)(height >> 16); |
| 65 | bmpinfoheader[11] = (uint8)(height >> 24); |
| 66 | |
| 67 | // Write the file header |
| 68 | file->Write(bmpfileheader, sizeof(bmpfileheader)); |
| 69 | |
| 70 | // Write the bitmap info header |
| 71 | file->Write(bmpinfoheader, sizeof(bmpinfoheader)); |
| 72 | |
| 73 | // Write the RGB Data |
| 74 | file->Write(data, pixel_data_size); |
| 75 | |
| 76 | // Close the file |
| 77 | Delete(file); |
| 78 | } |
| 79 | |
| 80 | bool FileSystemBase::AreFilePathsEqual(const StringView& path1, const StringView& path2) |
| 81 | { |