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

Function stbi__convert_format

Source/Utils/stb_image.h:1754–1796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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