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

Function stbi__convert_16_to_8

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

Source from the content-addressed store, hash-verified

1205}
1206
1207static stbi_uc* stbi__convert_16_to_8(stbi__uint16* orig, int w, int h, int channels) {
1208 int i;
1209 int img_len = w * h * channels;
1210 stbi_uc* reduced;
1211
1212 reduced = (stbi_uc*)stbi__malloc(img_len);
1213 if (reduced == NULL)
1214 return stbi__errpuc("outofmem", "Out of memory");
1215
1216 for (i = 0; i < img_len; ++i)
1217 reduced[i] =
1218 (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient
1219 // approx of 16->8 bit scaling
1220
1221 STBI_FREE(orig);
1222 return reduced;
1223}
1224
1225static stbi__uint16* stbi__convert_8_to_16(stbi_uc* orig, int w, int h, int channels) {
1226 int i;

Callers 1

Calls 1

stbi__mallocFunction · 0.85

Tested by

no test coverage detected