| 84 | } |
| 85 | |
| 86 | std::vector<unsigned char> loadTextureARGBfromfile(const char* filename, int& w, |
| 87 | int& h) |
| 88 | { |
| 89 | std::vector<unsigned char> data; |
| 90 | FILE* file; |
| 91 | unsigned char header[54]; |
| 92 | |
| 93 | const std::string resolvedPath = resolveResourcePath(filename); |
| 94 | file = fopen(resolvedPath.c_str(), "rb"); |
| 95 | |
| 96 | if (file == NULL) |
| 97 | { |
| 98 | printf("loadTexture error! %s\n", filename); |
| 99 | return data; |
| 100 | } |
| 101 | |
| 102 | fread(header, 1, 54, file); |
| 103 | w = *(int*)&(header[0x12]); |
| 104 | h = *(int*)&(header[0x16]); |
| 105 | int dataOffset = *(int*)&(header[0x0A]); |
| 106 | short bitsPerPixel = *(short*)&(header[0x1C]); |
| 107 | |
| 108 | if (bitsPerPixel != 32 || w <= 0 || h <= 0) |
| 109 | { |
| 110 | fclose(file); |
| 111 | printf("loadTexture unsupported format! %s\n", filename); |
| 112 | return data; |
| 113 | } |
| 114 | |
| 115 | data.resize(w * h * 4); |
| 116 | fseek(file, dataOffset, SEEK_SET); |
| 117 | fread(data.data(), w * h * 4, 1, file); |
| 118 | |
| 119 | fclose(file); |
| 120 | |
| 121 | for (int i = 0; i < w * h; ++i) |
| 122 | { |
| 123 | int index = i * 4; |
| 124 | unsigned char A, R, G, B; |
| 125 | B = data[index]; |
| 126 | G = data[index + 1]; |
| 127 | R = data[index + 2]; |
| 128 | A = data[index + 3]; |
| 129 | |
| 130 | data[index] = A; |
| 131 | data[index + 1] = R; |
| 132 | data[index + 2] = G; |
| 133 | data[index + 3] = B; |
| 134 | } |
| 135 | return data; |
| 136 | } |
no test coverage detected