take a -128..127 value and stbi__clamp it and convert to 0..255
| 2562 | |
| 2563 | // take a -128..127 value and stbi__clamp it and convert to 0..255 |
| 2564 | stbi_inline static stbi_uc stbi__clamp(int x) { |
| 2565 | // trick to use a single test to catch both cases |
| 2566 | if ((unsigned int)x > 255) { |
| 2567 | if (x < 0) |
| 2568 | return 0; |
| 2569 | if (x > 255) |
| 2570 | return 255; |
| 2571 | } |
| 2572 | return (stbi_uc)x; |
| 2573 | } |
| 2574 | |
| 2575 | #define stbi__f2f(x) ((int)(((x)*4096 + 0.5))) |
| 2576 | #define stbi__fsh(x) ((x)*4096) |