MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__hdr_load

Function stbi__hdr_load

lite/example/cpp_example/mge/cv/stb_image.h:7822–7978  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7820}
7821
7822static float* stbi__hdr_load(
7823 stbi__context* s, int* x, int* y, int* comp, int req_comp,
7824 stbi__result_info* ri) {
7825 char buffer[STBI__HDR_BUFLEN];
7826 char* token;
7827 int valid = 0;
7828 int width, height;
7829 stbi_uc* scanline;
7830 float* hdr_data;
7831 int len;
7832 unsigned char count, value;
7833 int i, j, k, c1, c2, z;
7834 const char* headerToken;
7835 STBI_NOTUSED(ri);
7836
7837 // Check identifier
7838 headerToken = stbi__hdr_gettoken(s, buffer);
7839 if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
7840 return stbi__errpf("not HDR", "Corrupt HDR image");
7841
7842 // Parse header
7843 for (;;) {
7844 token = stbi__hdr_gettoken(s, buffer);
7845 if (token[0] == 0)
7846 break;
7847 if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0)
7848 valid = 1;
7849 }
7850
7851 if (!valid)
7852 return stbi__errpf("unsupported format", "Unsupported HDR format");
7853
7854 // Parse width and height
7855 // can't use sscanf() if we're not using stdio!
7856 token = stbi__hdr_gettoken(s, buffer);
7857 if (strncmp(token, "-Y ", 3))
7858 return stbi__errpf("unsupported data layout", "Unsupported HDR format");
7859 token += 3;
7860 height = (int)strtol(token, &token, 10);
7861 while (*token == ' ')
7862 ++token;
7863 if (strncmp(token, "+X ", 3))
7864 return stbi__errpf("unsupported data layout", "Unsupported HDR format");
7865 token += 3;
7866 width = (int)strtol(token, NULL, 10);
7867
7868 if (height > STBI_MAX_DIMENSIONS)
7869 return stbi__errpf("too large", "Very large image (corrupt?)");
7870 if (width > STBI_MAX_DIMENSIONS)
7871 return stbi__errpf("too large", "Very large image (corrupt?)");
7872
7873 *x = width;
7874 *y = height;
7875
7876 if (comp)
7877 *comp = 3;
7878 if (req_comp == 0)
7879 req_comp = 3;

Callers 2

stbi__load_mainFunction · 0.85
stbi__loadf_mainFunction · 0.85

Calls 7

stbi__hdr_gettokenFunction · 0.85
stbi__mad4sizes_validFunction · 0.85
stbi__malloc_mad4Function · 0.85
stbi__getnFunction · 0.85
stbi__hdr_convertFunction · 0.85
stbi__get8Function · 0.85
stbi__malloc_mad2Function · 0.85

Tested by

no test coverage detected