From 95635b4b02837b927e1d1894497be282b73b86bc Mon Sep 17 00:00:00 2001 From: bjorn Date: Sun, 10 May 2020 02:35:13 -0600 Subject: [PATCH] Support loading 16 bit images; With 1, 2, or 4 channels; --- src/modules/data/textureData.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/modules/data/textureData.c b/src/modules/data/textureData.c index b55097d7..e528f5d9 100644 --- a/src/modules/data/textureData.c +++ b/src/modules/data/textureData.c @@ -494,7 +494,26 @@ TextureData* lovrTextureDataInitFromBlob(TextureData* textureData, Blob* blob, b int width, height; int length = (int) blob->size; stbi_set_flip_vertically_on_load(flip); - if (stbi_is_hdr_from_memory(blob->data, length)) { + if (stbi_is_16_bit_from_memory(blob->data, length)) { + int channels; + textureData->blob->data = stbi_load_16_from_memory(blob->data, length, &width, &height, &channels, 0); + switch (channels) { + case 1: + textureData->format = FORMAT_R16; + textureData->blob->size = 2 * width * height; + break; + case 2: + textureData->format = FORMAT_RG16; + textureData->blob->size = 4 * width * height; + break; + case 4: + textureData->format = FORMAT_RGBA16; + textureData->blob->size = 8 * width * height; + break; + default: + lovrThrow("Unsupported channel count for 16 bit image: %d", channels); + } + } else if (stbi_is_hdr_from_memory(blob->data, length)) { textureData->format = FORMAT_RGBA32F; textureData->blob->data = stbi_loadf_from_memory(blob->data, length, &width, &height, NULL, 4); textureData->blob->size = 16 * width * height;