MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__convert_format16

Function stbi__convert_format16

Source/Utils/stb_image.h:1811–1853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1809// nothing
1810#else
1811static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y)
1812{
1813 int i,j;
1814 stbi__uint16 *good;
1815
1816 if (req_comp == img_n) return data;
1817 STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
1818
1819 good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2);
1820 if (good == NULL) {
1821 STBI_FREE(data);
1822 return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
1823 }
1824
1825 for (j=0; j < (int) y; ++j) {
1826 stbi__uint16 *src = data + j * x * img_n ;
1827 stbi__uint16 *dest = good + j * x * req_comp;
1828
1829 #define STBI__COMBO(a,b) ((a)*8+(b))
1830 #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
1831 // convert source image with img_n components to one with req_comp components;
1832 // avoid switch per pixel, so use switch per scanline and massive macros
1833 switch (STBI__COMBO(img_n, req_comp)) {
1834 STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=0xffff; } break;
1835 STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
1836 STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=0xffff; } break;
1837 STBI__CASE(2,1) { dest[0]=src[0]; } break;
1838 STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
1839 STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break;
1840 STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=0xffff; } break;
1841 STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
1842 STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = 0xffff; } break;
1843 STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
1844 STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = src[3]; } break;
1845 STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break;
1846 default: STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); return (stbi__uint16*) stbi__errpuc("unsupported", "Unsupported format conversion");
1847 }
1848 #undef STBI__CASE
1849 }
1850
1851 STBI_FREE(data);
1852 return good;
1853}
1854#endif
1855
1856#ifndef STBI_NO_LINEAR

Callers 3

stbi__do_pngFunction · 0.85
stbi__psd_loadFunction · 0.85
stbi__pnm_loadFunction · 0.85

Calls 2

stbi__mallocFunction · 0.85
stbi__compute_y_16Function · 0.85

Tested by

no test coverage detected