MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__convert_format16

Function stbi__convert_format16

lite/example/cpp_example/mge/cv/stb_image.h:1891–1977  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1889// nothing
1890#else
1891static stbi__uint16* stbi__convert_format16(
1892 stbi__uint16* data, int img_n, int req_comp, unsigned int x, unsigned int y) {
1893 int i, j;
1894 stbi__uint16* good;
1895
1896 if (req_comp == img_n)
1897 return data;
1898 STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
1899
1900 good = (stbi__uint16*)stbi__malloc(req_comp * x * y * 2);
1901 if (good == NULL) {
1902 STBI_FREE(data);
1903 return (stbi__uint16*)stbi__errpuc("outofmem", "Out of memory");
1904 }
1905
1906 for (j = 0; j < (int)y; ++j) {
1907 stbi__uint16* src = data + j * x * img_n;
1908 stbi__uint16* dest = good + j * x * req_comp;
1909
1910#define STBI__COMBO(a, b) ((a)*8 + (b))
1911#define STBI__CASE(a, b) \
1912 case STBI__COMBO(a, b): \
1913 for (i = x - 1; i >= 0; --i, src += a, dest += b)
1914 // convert source image with img_n components to one with req_comp components;
1915 // avoid switch per pixel, so use switch per scanline and massive macros
1916 switch (STBI__COMBO(img_n, req_comp)) {
1917 STBI__CASE(1, 2) {
1918 dest[0] = src[0];
1919 dest[1] = 0xffff;
1920 }
1921 break;
1922 STBI__CASE(1, 3) { dest[0] = dest[1] = dest[2] = src[0]; }
1923 break;
1924 STBI__CASE(1, 4) {
1925 dest[0] = dest[1] = dest[2] = src[0];
1926 dest[3] = 0xffff;
1927 }
1928 break;
1929 STBI__CASE(2, 1) { dest[0] = src[0]; }
1930 break;
1931 STBI__CASE(2, 3) { dest[0] = dest[1] = dest[2] = src[0]; }
1932 break;
1933 STBI__CASE(2, 4) {
1934 dest[0] = dest[1] = dest[2] = src[0];
1935 dest[3] = src[1];
1936 }
1937 break;
1938 STBI__CASE(3, 4) {
1939 dest[0] = src[0];
1940 dest[1] = src[1];
1941 dest[2] = src[2];
1942 dest[3] = 0xffff;
1943 }
1944 break;
1945 STBI__CASE(3, 1) { dest[0] = stbi__compute_y_16(src[0], src[1], src[2]); }
1946 break;
1947 STBI__CASE(3, 2) {
1948 dest[0] = stbi__compute_y_16(src[0], src[1], src[2]);

Callers 2

stbi__do_pngFunction · 0.85
stbi__psd_loadFunction · 0.85

Calls 3

stbi__mallocFunction · 0.85
STBI__CASEFunction · 0.85
stbi__compute_y_16Function · 0.85

Tested by

no test coverage detected