MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / stbi__hdr_load

Function stbi__hdr_load

include/stb/stb_image.h:7158–7287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7156}
7157
7158static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
7159{
7160 char buffer[STBI__HDR_BUFLEN];
7161 char *token;
7162 int valid = 0;
7163 int width, height;
7164 stbi_uc *scanline;
7165 float *hdr_data;
7166 int len;
7167 unsigned char count, value;
7168 int i, j, k, c1,c2, z;
7169 const char *headerToken;
7170 STBI_NOTUSED(ri);
7171
7172 // Check identifier
7173 headerToken = stbi__hdr_gettoken(s,buffer);
7174 if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
7175 return stbi__errpf("not HDR", "Corrupt HDR image");
7176
7177 // Parse header
7178 for(;;) {
7179 token = stbi__hdr_gettoken(s,buffer);
7180 if (token[0] == 0) break;
7181 if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
7182 }
7183
7184 if (!valid) return stbi__errpf("unsupported format", "Unsupported HDR format");
7185
7186 // Parse width and height
7187 // can't use sscanf() if we're not using stdio!
7188 token = stbi__hdr_gettoken(s,buffer);
7189 if (strncmp(token, "-Y ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format");
7190 token += 3;
7191 height = (int) strtol(token, &token, 10);
7192 while (*token == ' ') ++token;
7193 if (strncmp(token, "+X ", 3)) return stbi__errpf("unsupported data layout", "Unsupported HDR format");
7194 token += 3;
7195 width = (int) strtol(token, NULL, 10);
7196
7197 if (height > STBI_MAX_DIMENSIONS) return stbi__errpf("too large","Very large image (corrupt?)");
7198 if (width > STBI_MAX_DIMENSIONS) return stbi__errpf("too large","Very large image (corrupt?)");
7199
7200 *x = width;
7201 *y = height;
7202
7203 if (comp) *comp = 3;
7204 if (req_comp == 0) req_comp = 3;
7205
7206 if (!stbi__mad4sizes_valid(width, height, req_comp, sizeof(float), 0))
7207 return stbi__errpf("too large", "HDR image is too large");
7208
7209 // Read data
7210 hdr_data = (float *) stbi__malloc_mad4(width, height, req_comp, sizeof(float), 0);
7211 if (!hdr_data)
7212 return stbi__errpf("outofmem", "Out of memory");
7213
7214 // Load image data
7215 // image data is stored as some number of sca

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