| 7788 | } |
| 7789 | |
| 7790 | static void stbi__hdr_convert(float* output, stbi_uc* input, int req_comp) { |
| 7791 | if (input[3] != 0) { |
| 7792 | float f1; |
| 7793 | // Exponent |
| 7794 | f1 = (float)ldexp(1.0f, input[3] - (int)(128 + 8)); |
| 7795 | if (req_comp <= 2) |
| 7796 | output[0] = (input[0] + input[1] + input[2]) * f1 / 3; |
| 7797 | else { |
| 7798 | output[0] = input[0] * f1; |
| 7799 | output[1] = input[1] * f1; |
| 7800 | output[2] = input[2] * f1; |
| 7801 | } |
| 7802 | if (req_comp == 2) |
| 7803 | output[1] = 1; |
| 7804 | if (req_comp == 4) |
| 7805 | output[3] = 1; |
| 7806 | } else { |
| 7807 | switch (req_comp) { |
| 7808 | case 4: |
| 7809 | output[3] = 1; /* fallthrough */ |
| 7810 | case 3: |
| 7811 | output[0] = output[1] = output[2] = 0; |
| 7812 | break; |
| 7813 | case 2: |
| 7814 | output[1] = 1; /* fallthrough */ |
| 7815 | case 1: |
| 7816 | output[0] = 0; |
| 7817 | break; |
| 7818 | } |
| 7819 | } |
| 7820 | } |
| 7821 | |
| 7822 | static float* stbi__hdr_load( |
| 7823 | stbi__context* s, int* x, int* y, int* comp, int req_comp, |
no test coverage detected