Created
July 1, 2021 13:49
-
-
Save Pikachuxxxx/53b1f9816499513f3254069f7dc7e736 to your computer and use it in GitHub Desktop.
Converts the given image into a inl file with image pixel data and meta data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include <fstream> | |
#define STB_IMAGE_IMPLEMENTATION | |
#include "stb_image.h" | |
int main(int argc, char** argv) | |
{ | |
// Read the image data | |
int width, height, bpp; | |
auto data = stbi_load(argv[1], &width, &height, &bpp, STBI_rgb_alpha); | |
std::cout << "Image Width : " << width << " Height : " << height << " and BPP : " << bpp << std::endl; | |
// Write the image to a .inl file | |
std::ofstream outfile; | |
outfile.open("RazixLogo.inl"); | |
outfile << "// Generated by Razix for RazixLogo.png" << std::endl; | |
outfile << "static const uint32_t RazixLogoWidth = " << width << ";" << std::endl; | |
outfile << "static const uint32_t RazixLogoHeight = " << height << ";" << std::endl; | |
outfile << "static const uint32_t RazixLogoBPP = " << bpp << ";" << std::endl; | |
outfile << "static const uint8_t RazixLogoPixels[] = {" << std::endl; | |
const int32_t size = width * height * bpp; | |
uint8_t* result = new uint8_t[size]; | |
outfile << uint32_t(result[0]); | |
memcpy(result, data, size); | |
for (size_t i = 1; i < size; i++) { | |
outfile << ", " << uint32_t(result[i]); | |
} | |
outfile << "};"; | |
// Deallocate the resources and close the file | |
outfile.close(); | |
stbi_image_free(data); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment