#include "raylib.h" #include static char const DECLARATION_BEGIN[] = "static const unsigned char "; static char const DECLARATION_END[] = "[] = {\n"; static char const FILE_END[] = "};"; static char const LINE[] = " 0x00\n"; static int const DECLARATION_BEGIN_SIZE = sizeof(DECLARATION_BEGIN) - 1; static int const DECLARATION_END_SIZE = sizeof(DECLARATION_END) - 1; static int const FILE_END_SIZE = sizeof(FILE_END) - 1; static int const LINE_SIZE = sizeof(LINE) - 1; static int const ADDITIONAL_SIZE = DECLARATION_BEGIN_SIZE + DECLARATION_END_SIZE + FILE_END_SIZE; void fileToBytes(char const *const inputFileName, char const *const outputFileName, char const *const arrayName) { unsigned int fileSize = 0; unsigned char *const fileData = LoadFileData(inputFileName, &fileSize); char *const content = (char *const)MemAlloc(sizeof(char) * fileSize * 10); int cursor = 0; for (unsigned int i = 0; i < fileSize; i++) { TextAppend(content, TextFormat(" 0x%02x,\n", fileData[i]), &cursor); } cursor = 0; char *const final = (char *const)MemAlloc((ADDITIONAL_SIZE + strlen(arrayName) + (LINE_SIZE * fileSize)) * sizeof(char)); TextAppend(final, DECLARATION_BEGIN, &cursor); TextAppend(final, arrayName, &cursor); TextAppend(final, DECLARATION_END, &cursor); TextAppend(final, content, &cursor); TextAppend(final, FILE_END, &cursor); MemFree(content); SaveFileText(outputFileName, final); MemFree(final); } void bytesToFile(unsigned char const *const input, unsigned int const inputSize, char const *const outputFileName, char const *const arrayName) { char *const content = (char *const)MemAlloc(sizeof(char) * inputSize * sizeof(" 0x00,\n")); int cursor = 0; for (unsigned int i = 0; i < inputSize; i++) { TextAppend(content, TextFormat(" 0x%02x,\n", input[i]), &cursor); } cursor = 0; char *const final = (char *const)MemAlloc((ADDITIONAL_SIZE + strlen(arrayName) + (LINE_SIZE * inputSize)) * sizeof(char)); TextAppend(final, DECLARATION_BEGIN, &cursor); TextAppend(final, arrayName, &cursor); TextAppend(final, DECLARATION_END, &cursor); TextAppend(final, content, &cursor); TextAppend(final, FILE_END, &cursor); MemFree(content); SaveFileText(outputFileName, final); MemFree(final); }