| 129 | } |
| 130 | |
| 131 | void ImageExport::SavePNGTransparent(const char *file_path, unsigned char *data, unsigned long width, unsigned long height, unsigned short levels) { |
| 132 | std::vector<unsigned char> scaled_data; |
| 133 | ImageExport::ScaleImageUp(data, levels, &width, &height, &scaled_data); |
| 134 | |
| 135 | int bytespp = 4; |
| 136 | for (unsigned y = 0; y < height; y++) { |
| 137 | unsigned char *bits = scaled_data.data() + y * width * 4; |
| 138 | for (unsigned x = 0; x < width; x++) { |
| 139 | // Set pixel color to green with a transparency of 128 |
| 140 | bits[0] = min(255, (int)((bits[0] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255)); |
| 141 | bits[1] = min(255, (int)((bits[1] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255)); |
| 142 | bits[2] = min(255, (int)((bits[2] / 255.0f / (scaled_data[y * width * 4 + x * 4 + 3] / 255.0f)) * 255)); |
| 143 | bits[3] = scaled_data[y * width * 4 + x * 4 + 3]; |
| 144 | // jump to next pixel |
| 145 | bits += bytespp; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | CreateParentDirs(file_path); |
| 150 | #ifdef _WIN32 |
| 151 | createfile(file_path); |
| 152 | std::string short_path(file_path); |
| 153 | ShortenWindowsPath(short_path); |
| 154 | if (!stbi_write_png(short_path.c_str(), width, height, 4, scaled_data.data(), width * 4)) { |
| 155 | DisplayError("Error", "Problem exporting .png file"); |
| 156 | } |
| 157 | #else |
| 158 | if (!stbi_write_png(file_path, width, height, 4, scaled_data.data(), width * 4)) { |
| 159 | DisplayError("Error", "Problem exporting .png file"); |
| 160 | } |
| 161 | #endif |
| 162 | } |
| 163 | |
| 164 | void ImageExport::SaveJPEG(const char *abs_path, unsigned char *data, unsigned long width, unsigned long height) { |
| 165 | CreateParentDirs(abs_path); |
nothing calls this directly
no test coverage detected