| 1882 | #ifndef STBI_NO_HDR |
| 1883 | #define stbi__float2int(x) ((int) (x)) |
| 1884 | static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp) |
| 1885 | { |
| 1886 | int i,k,n; |
| 1887 | stbi_uc *output; |
| 1888 | if (!data) return NULL; |
| 1889 | output = (stbi_uc *) stbi__malloc_mad3(x, y, comp, 0); |
| 1890 | if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); } |
| 1891 | // compute number of non-alpha components |
| 1892 | if (comp & 1) n = comp; else n = comp-1; |
| 1893 | for (i=0; i < x*y; ++i) { |
| 1894 | for (k=0; k < n; ++k) { |
| 1895 | float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f; |
| 1896 | if (z < 0) z = 0; |
| 1897 | if (z > 255) z = 255; |
| 1898 | output[i*comp + k] = (stbi_uc) stbi__float2int(z); |
| 1899 | } |
| 1900 | if (k < comp) { |
| 1901 | float z = data[i*comp+k] * 255 + 0.5f; |
| 1902 | if (z < 0) z = 0; |
| 1903 | if (z > 255) z = 255; |
| 1904 | output[i*comp + k] = (stbi_uc) stbi__float2int(z); |
| 1905 | } |
| 1906 | } |
| 1907 | STBI_FREE(data); |
| 1908 | return output; |
| 1909 | } |
| 1910 | #endif |
| 1911 | |
| 1912 | ////////////////////////////////////////////////////////////////////////////// |
no test coverage detected