img2raw.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #define NOB_IMPLEMENTATION
  4. #include "nob.h"
  5. #define STB_IMAGE_IMPLEMENTATION
  6. #include "stb_image.h"
  7. int main(int argc, char **argv)
  8. {
  9. const char *program = nob_shift_args(&argc, &argv);
  10. if (argc <= 0) {
  11. nob_log(NOB_ERROR, "No input is provided");
  12. nob_log(NOB_INFO, "Usage: %s <input...>", program);
  13. return 1;
  14. }
  15. for (int i = 0; i < argc; ++i) {
  16. const char *input_file_path = argv[i];
  17. nob_log(NOB_INFO, "Reading file %s", input_file_path);
  18. int width, height;
  19. uint32_t *pixels = (uint32_t *)stbi_load(input_file_path, &width, &height, NULL, 4);
  20. if (pixels == NULL) {
  21. nob_log(NOB_ERROR, "Could not load file %s", input_file_path);
  22. continue;
  23. }
  24. const char *output_file_path = nob_temp_sprintf("%s.raw", input_file_path);
  25. if (!nob_write_entire_file(output_file_path, pixels, sizeof(uint32_t)*width*height)) continue;
  26. nob_log(NOB_INFO, "Generated %s", output_file_path);
  27. stbi_image_free(pixels);
  28. nob_temp_reset();
  29. }
  30. return 0;
  31. }