/** * Copyright (c) 2021 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "../utils/file.h" #ifndef STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #include #endif int main(int argc, char *argv[]) { FILE *file; char path[FILENAME_MAX + 1]; char *in; char *out; char pathSep; int x, y, channels; stbi_uc *data; if(argc != 3) { printf("Invalid number of arguments\n"); return 1; } pathSep = FILE_PATH_SEP; in = argv[1]; out = argv[2]; // Normalize slashes fileNormalizeSlashes(in); fileNormalizeSlashes(out); // Read in original texture printf("Opening %s\n", in); file = fopen(in, "rb"); if(file == NULL) { printf("Failed to open file!\n"); return 1; } data = stbi_load_from_file(file, &x, &y, &channels, STBI_rgb_alpha); if(data == NULL) { printf("Failed to load input texture!\n"); return 1; } // Write out texture path[0] = '\0'; if(getcwd(path,sizeof(path)) == NULL) { printf("Failed to get current dir!\n"); stbi_image_free(data); return 1; } // Determine Output path strncat(path, &pathSep, 1); strcat(path, out); printf("Writing %s\n", path); // Open output file fileMkdirp(path); file = fopen(path, "wb"); if(file == NULL) { printf("Invalid file out!\n"); return 1; } // Write texture fwrite(data, sizeof(unsigned char), x*y*channels, file); // Cleanup fclose(file); stbi_image_free(data); return 0; }