diff --git a/src/vtfpp/ImageConversion.cpp b/src/vtfpp/ImageConversion.cpp index 044c8939..91a5df77 100644 --- a/src/vtfpp/ImageConversion.cpp +++ b/src/vtfpp/ImageConversion.cpp @@ -1306,6 +1306,56 @@ std::vector ImageConversion::convertFileToImageData(std::span= 1 && channels < 4) { + // There are no other 16-bit integer formats in Source, so we have to do a conversion here + format = ImageFormat::RGBA16161616; + + std::vector out(ImageFormatDetails::getDataLength(format, width, height)); + std::span outPixels{reinterpret_cast(out.data()), out.size() / sizeof(ImagePixel::RGBA16161616)}; + + switch (channels) { + case 1: { + std::span inPixels{reinterpret_cast(stbImage.get()), outPixels.size()}; + std::transform( +#ifdef SOURCEPP_BUILD_WITH_TBB + std::execution::par_unseq, +#endif + inPixels.begin(), inPixels.end(), outPixels.begin(), [](uint16_t pixel) -> ImagePixel::RGBA16161616 { + return {pixel, 0, 0, 0xffff}; + }); + } + case 2: { + struct RG1616 { + uint16_t r; + uint16_t g; + }; + std::span inPixels{reinterpret_cast(stbImage.get()), outPixels.size()}; + std::transform( +#ifdef SOURCEPP_BUILD_WITH_TBB + std::execution::par_unseq, +#endif + inPixels.begin(), inPixels.end(), outPixels.begin(), [](RG1616 pixel) -> ImagePixel::RGBA16161616 { + return {pixel.r, pixel.g, 0, 0xffff}; + }); + } + case 3: { + struct RGB161616 { + uint16_t r; + uint16_t g; + uint16_t b; + }; + std::span inPixels{reinterpret_cast(stbImage.get()), outPixels.size()}; + std::transform( +#ifdef SOURCEPP_BUILD_WITH_TBB + std::execution::par_unseq, +#endif + inPixels.begin(), inPixels.end(), outPixels.begin(), [](RGB161616 pixel) -> ImagePixel::RGBA16161616 { + return {pixel.r, pixel.g, pixel.b, 0xffff}; + }); + } + default: + return {}; + } } else { return {}; }