🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 KiB

  1. #define TINYEXR_IMPLEMENTATION
  2. #include "tinyexr.h"
  3. #include "exr-io.h"
  4. #include <cstdio>
  5. #include <iostream>
  6. namespace exrio {
  7. bool GetEXRLayers(const char *filename)
  8. {
  9. const char** layer_names = nullptr;
  10. int num_layers = 0;
  11. const char *err = nullptr;
  12. int ret = EXRLayers(filename, &layer_names, &num_layers, &err);
  13. if (err) {
  14. fprintf(stderr, "EXR error = %s\n", err);
  15. }
  16. if (ret != 0) {
  17. fprintf(stderr, "Load EXR err: %s\n", err);
  18. return false;
  19. }
  20. if (num_layers > 0)
  21. {
  22. fprintf(stdout, "EXR Contains %i Layers\n", num_layers);
  23. for (size_t i = 0; i < num_layers; ++i) {
  24. fprintf(stdout, "Layer %i : %s\n", i + 1, layer_names[i]);
  25. }
  26. }
  27. free(layer_names);
  28. return true;
  29. }
  30. bool LoadEXRRGBA(float** rgba, int *w, int *h, const char* filename, const char* layername)
  31. {
  32. int width, height;
  33. float* image;
  34. const char *err = nullptr;
  35. int ret = LoadEXRWithLayer(&image, &width, &height, filename, layername, &err);
  36. if (err) {
  37. fprintf(stderr, "EXR error = %s\n", err);
  38. }
  39. if (ret != 0) {
  40. fprintf(stderr, "Load EXR err: %s\n", err);
  41. return false;
  42. }
  43. (*rgba) = image;
  44. (*w) = width;
  45. (*h) = height;
  46. return true;
  47. }
  48. }