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

Function stbi__convert_format

include/stb/stb_image.h:1755–1797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1753// nothing
1754#else
1755static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y)
1756{
1757 int i,j;
1758 unsigned char *good;
1759
1760 if (req_comp == img_n) return data;
1761 STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
1762
1763 good = (unsigned char *) stbi__malloc_mad3(req_comp, x, y, 0);
1764 if (good == NULL) {
1765 STBI_FREE(data);
1766 return stbi__errpuc("outofmem", "Out of memory");
1767 }
1768
1769 for (j=0; j < (int) y; ++j) {
1770 unsigned char *src = data + j * x * img_n ;
1771 unsigned char *dest = good + j * x * req_comp;
1772
1773 #define STBI__COMBO(a,b) ((a)*8+(b))
1774 #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
1775 // convert source image with img_n components to one with req_comp components;
1776 // avoid switch per pixel, so use switch per scanline and massive macros
1777 switch (STBI__COMBO(img_n, req_comp)) {
1778 STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=255; } break;
1779 STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
1780 STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=255; } break;
1781 STBI__CASE(2,1) { dest[0]=src[0]; } break;
1782 STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
1783 STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break;
1784 STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=255; } break;
1785 STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
1786 STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = 255; } break;
1787 STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
1788 STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = src[3]; } break;
1789 STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break;
1790 default: STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); return stbi__errpuc("unsupported", "Unsupported format conversion");
1791 }
1792 #undef STBI__CASE
1793 }
1794
1795 STBI_FREE(data);
1796 return good;
1797}
1798#endif
1799
1800#if defined(STBI_NO_PNG) && defined(STBI_NO_PSD)

Callers 8

stbi__do_pngFunction · 0.85
stbi__bmp_loadFunction · 0.85
stbi__tga_loadFunction · 0.85
stbi__psd_loadFunction · 0.85
stbi__pic_loadFunction · 0.85
stbi__load_gif_mainFunction · 0.85
stbi__gif_loadFunction · 0.85
stbi__pnm_loadFunction · 0.85

Calls 2

stbi__malloc_mad3Function · 0.85
stbi__compute_yFunction · 0.85

Tested by

no test coverage detected