| 267 | |
| 268 | template <int N> |
| 269 | static const char *writeOutput(const BitmapConstSection<float, N> &bitmap, const char *filename, Format &format) { |
| 270 | if (filename) { |
| 271 | if (format == AUTO) { |
| 272 | #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG) |
| 273 | if (cmpExtension(filename, ".png")) format = PNG; |
| 274 | #else |
| 275 | if (cmpExtension(filename, ".png")) |
| 276 | return "PNG format is not available in core-only version."; |
| 277 | #endif |
| 278 | else if (cmpExtension(filename, ".bmp")) format = BMP; |
| 279 | else if (cmpExtension(filename, ".tiff") || cmpExtension(filename, ".tif")) format = TIFF; |
| 280 | else if (cmpExtension(filename, ".rgba")) format = RGBA; |
| 281 | else if (cmpExtension(filename, ".fl32")) format = FL32; |
| 282 | else if (cmpExtension(filename, ".txt")) format = TEXT; |
| 283 | else if (cmpExtension(filename, ".bin")) format = BINARY; |
| 284 | else |
| 285 | return "Could not deduce format from output file name."; |
| 286 | } |
| 287 | switch (format) { |
| 288 | #if defined(MSDFGEN_EXTENSIONS) && !defined(MSDFGEN_DISABLE_PNG) |
| 289 | case PNG: return savePng(bitmap, filename) ? NULL : "Failed to write output PNG image."; |
| 290 | #endif |
| 291 | case BMP: return saveBmp(bitmap, filename) ? NULL : "Failed to write output BMP image."; |
| 292 | case TIFF: return saveTiff(bitmap, filename) ? NULL : "Failed to write output TIFF image."; |
| 293 | case RGBA: return saveRgba(bitmap, filename) ? NULL : "Failed to write output RGBA image."; |
| 294 | case FL32: return saveFl32(bitmap, filename) ? NULL : "Failed to write output FL32 image."; |
| 295 | case TEXT: case TEXT_FLOAT: { |
| 296 | FILE *file = fopen(filename, "w"); |
| 297 | if (!file) return "Failed to write output text file."; |
| 298 | if (format == TEXT) |
| 299 | writeTextBitmap(file, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 300 | else if (format == TEXT_FLOAT) |
| 301 | writeTextBitmapFloat(file, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 302 | fclose(file); |
| 303 | return NULL; |
| 304 | } |
| 305 | case BINARY: case BINARY_FLOAT: case BINARY_FLOAT_BE: { |
| 306 | FILE *file = fopen(filename, "wb"); |
| 307 | if (!file) return "Failed to write output binary file."; |
| 308 | if (format == BINARY) |
| 309 | writeBinBitmap(file, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 310 | else if (format == BINARY_FLOAT) |
| 311 | writeBinBitmapFloat(file, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 312 | else if (format == BINARY_FLOAT_BE) |
| 313 | writeBinBitmapFloatBE(file, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 314 | fclose(file); |
| 315 | return NULL; |
| 316 | } |
| 317 | default:; |
| 318 | } |
| 319 | } else { |
| 320 | if (format == AUTO || format == TEXT) |
| 321 | writeTextBitmap(stdout, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 322 | else if (format == TEXT_FLOAT) |
| 323 | writeTextBitmapFloat(stdout, bitmap.pixels, N*bitmap.width, bitmap.height, bitmap.rowStride); |
| 324 | else |
| 325 | return "Unsupported format for standard output."; |
| 326 | } |
nothing calls this directly
no test coverage detected