| 1979 | |
| 1980 | #ifndef STBI_NO_LINEAR |
| 1981 | static float* stbi__ldr_to_hdr(stbi_uc* data, int x, int y, int comp) { |
| 1982 | int i, k, n; |
| 1983 | float* output; |
| 1984 | if (!data) |
| 1985 | return NULL; |
| 1986 | output = (float*)stbi__malloc_mad4(x, y, comp, sizeof(float), 0); |
| 1987 | if (output == NULL) { |
| 1988 | STBI_FREE(data); |
| 1989 | return stbi__errpf("outofmem", "Out of memory"); |
| 1990 | } |
| 1991 | // compute number of non-alpha components |
| 1992 | if (comp & 1) |
| 1993 | n = comp; |
| 1994 | else |
| 1995 | n = comp - 1; |
| 1996 | for (i = 0; i < x * y; ++i) { |
| 1997 | for (k = 0; k < n; ++k) { |
| 1998 | output[i * comp + k] = |
| 1999 | (float)(pow(data[i * comp + k] / 255.0f, stbi__l2h_gamma) * |
| 2000 | stbi__l2h_scale); |
| 2001 | } |
| 2002 | } |
| 2003 | if (n < comp) { |
| 2004 | for (i = 0; i < x * y; ++i) { |
| 2005 | output[i * comp + n] = data[i * comp + n] / 255.0f; |
| 2006 | } |
| 2007 | } |
| 2008 | STBI_FREE(data); |
| 2009 | return output; |
| 2010 | } |
| 2011 | #endif |
| 2012 | |
| 2013 | #ifndef STBI_NO_HDR |
no test coverage detected