MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / stbi__convert_format16

Function stbi__convert_format16

include/stb/stb_image.h:1812–1854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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