I hate my life

This commit is contained in:
2021-11-05 10:55:10 -07:00
parent f6ea081b2d
commit 715ecd3a73
16 changed files with 522 additions and 86 deletions

View File

@ -5,8 +5,10 @@
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../utils/common.h"
#include "../utils/file.h"
#include "../utils/image.h"
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
@ -22,6 +24,7 @@ int RESIZE_SCALES[RESIZE_VARIANT_COUNT] = { 1, 2, 3, 4 };
int main(int argc, char *argv[]) {
FILE *file;
char path[FILENAME_MAX + 1];
char xml[2048];
char *in;
char *out;
char pathSep;
@ -38,7 +41,7 @@ int main(int argc, char *argv[]) {
pathSep = FILE_PATH_SEP;
in = argv[1];
out = argv[2];
// Normalize slashes
fileNormalizeSlashes(in);
fileNormalizeSlashes(out);
@ -57,6 +60,13 @@ int main(int argc, char *argv[]) {
}
fclose(file);
// Begin XML buffering
xml[0] = '\0';
sprintf(xml,
"<texture channels=\"%i\" width=\"%i\" height=\"%i\">",
channels, w, h
);
// For each scale.
for(i = 0; i < RESIZE_VARIANT_COUNT; i++) {
// Resize image
@ -68,22 +78,15 @@ int main(int argc, char *argv[]) {
// Determine output path
path[0] = '\0';
if(getcwd(path,sizeof(path)) == NULL) {
printf("Failed to get current dir!\n");
stbi_image_free(dataOriginal);
return 1;
}
// Determine Output path
sprintf(path, "%s%c%s_%i.texture", path, FILE_PATH_SEP, out, scale);
printf("Writing %s\n", path);
sprintf(path, "%s_%i.texture", out, scale);
// Open output file
fileMkdirp(path);
printf("OPOut %s\n", path);
file = fopen(path, "wb");
if(file == NULL) {
printf("Invalid file out!\n");
printf("Invalid texture file out!\n");
return 1;
}
@ -93,10 +96,33 @@ int main(int argc, char *argv[]) {
// Cleanup
fclose(file);
free(dataResized);
// Buffer XML info.
sprintf(xml,
"%s\n <texture-scale scale=\"%i\" width=\"%i\" height=\"%i\" asset=\"%s_%i.texture\" />",
xml, scale, rw, rh, out, scale
);
}
// Cleanup
stbi_image_free(dataOriginal);
// Finalize XML
sprintf(xml, "%s\n</texture>", xml);
// Determine XML path
path[0] = '\0';
sprintf(path, "%s.xml", out);
// Write XML
fileMkdirp(path);
file = fopen(path, "w");
if(file == NULL) {
printf("Invalid XML File Out!\n");
return 1;
}
fwrite(xml, sizeof(char), strlen(xml), file);
fclose(file);
return 0;
}