| 2049 | } |
| 2050 | |
| 2051 | std::vector<uint8_t> CommandCreate::convert(const std::unique_ptr<Image>& image, VkFormat vkFormat, |
| 2052 | ImageInput& inputFile) { |
| 2053 | |
| 2054 | const uint32_t inputBitDepth = std::max(8u, inputFile.spec().format().largestChannelBitLength()); |
| 2055 | |
| 2056 | const auto require = [&](uint32_t bitDepth) { |
| 2057 | if (inputBitDepth < bitDepth) |
| 2058 | fatal(rc::INVALID_FILE, "{}: Not enough precision to convert {} bit input to {} bit output for {}.", |
| 2059 | inputFile.filename(), inputBitDepth, bitDepth, toString(vkFormat)); |
| 2060 | if (inputBitDepth > imageio::bit_ceil(bitDepth)) |
| 2061 | warning("{}: Possible loss of precision with converting {} bit input to {} bit output for {}.", |
| 2062 | inputFile.filename(), inputBitDepth, bitDepth, toString(vkFormat)); |
| 2063 | }; |
| 2064 | const auto requireUNORM = [&](uint32_t bitDepth) { |
| 2065 | switch (inputFile.formatType()) { |
| 2066 | case ImageInputFormatType::png_l: [[fallthrough]]; |
| 2067 | case ImageInputFormatType::png_la: [[fallthrough]]; |
| 2068 | case ImageInputFormatType::png_rgb: [[fallthrough]]; |
| 2069 | case ImageInputFormatType::png_rgba: [[fallthrough]]; |
| 2070 | case ImageInputFormatType::npbm: [[fallthrough]]; |
| 2071 | case ImageInputFormatType::jpg: |
| 2072 | break; // Accept |
| 2073 | case ImageInputFormatType::exr_uint: [[fallthrough]]; |
| 2074 | case ImageInputFormatType::exr_float: |
| 2075 | fatal(rc::INVALID_FILE, "{}: Input file data type \"{}\" does not match the expected input data type of {} bit \"{}\" for {}.", |
| 2076 | inputFile.filename(), toString(inputFile.formatType()), bitDepth, "UNORM", toString(vkFormat)); |
| 2077 | } |
| 2078 | require(bitDepth); |
| 2079 | }; |
| 2080 | const auto requireSFloat = [&](uint32_t bitDepth) { |
| 2081 | switch (inputFile.formatType()) { |
| 2082 | case ImageInputFormatType::exr_float: |
| 2083 | break; // Accept |
| 2084 | case ImageInputFormatType::png_l: [[fallthrough]]; |
| 2085 | case ImageInputFormatType::png_la: [[fallthrough]]; |
| 2086 | case ImageInputFormatType::png_rgb: [[fallthrough]]; |
| 2087 | case ImageInputFormatType::png_rgba: [[fallthrough]]; |
| 2088 | case ImageInputFormatType::npbm: [[fallthrough]]; |
| 2089 | case ImageInputFormatType::jpg: [[fallthrough]]; |
| 2090 | case ImageInputFormatType::exr_uint: |
| 2091 | fatal(rc::INVALID_FILE, "{}: Input file data type \"{}\" does not match the expected input data type of {} bit \"{}\" for {}.", |
| 2092 | inputFile.filename(), toString(inputFile.formatType()), bitDepth, "SFLOAT", toString(vkFormat)); |
| 2093 | } |
| 2094 | require(bitDepth); |
| 2095 | }; |
| 2096 | const auto requireUINT = [&](uint32_t bitDepth) { |
| 2097 | switch (inputFile.formatType()) { |
| 2098 | case ImageInputFormatType::exr_uint: |
| 2099 | break; // Accept |
| 2100 | case ImageInputFormatType::png_l: [[fallthrough]]; |
| 2101 | case ImageInputFormatType::png_la: [[fallthrough]]; |
| 2102 | case ImageInputFormatType::png_rgb: [[fallthrough]]; |
| 2103 | case ImageInputFormatType::png_rgba: [[fallthrough]]; |
| 2104 | case ImageInputFormatType::npbm: [[fallthrough]]; |
| 2105 | case ImageInputFormatType::jpg: [[fallthrough]]; |
| 2106 | case ImageInputFormatType::exr_float: |
| 2107 | fatal(rc::INVALID_FILE, "{}: Input file data type \"{}\" does not match the expected input data type of {} bit \"{}\" for {}.", |
| 2108 | inputFile.filename(), toString(inputFile.formatType()), bitDepth, "UINT", toString(vkFormat)); |
nothing calls this directly
no test coverage detected