MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / loadInputImage

Method loadInputImage

tools/ktx/command_create.cpp:1905–1949  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1903// -------------------------------------------------------------------------------------------------
1904
1905std::unique_ptr<Image> CommandCreate::loadInputImage(ImageInput& inputImageFile) {
1906 std::unique_ptr<Image> image = nullptr;
1907
1908 const auto& inputFormat = inputImageFile.spec().format();
1909 const auto width = inputImageFile.spec().width();
1910 const auto height = inputImageFile.spec().height();
1911
1912 const auto inputBitLength = inputFormat.largestChannelBitLength();
1913 const auto requestBitLength = std::max(imageio::bit_ceil(inputBitLength), 8u);
1914 FormatDescriptor loadFormat;
1915
1916 switch (inputImageFile.formatType()) {
1917 case ImageInputFormatType::exr_uint:
1918 image = std::make_unique<rgba32image>(width, height);
1919 loadFormat = createFormatDescriptor(VK_FORMAT_R32G32B32A32_UINT, *this);
1920 break;
1921
1922 case ImageInputFormatType::exr_float:
1923 image = std::make_unique<rgba32fimage>(width, height);
1924 loadFormat = createFormatDescriptor(VK_FORMAT_R32G32B32A32_SFLOAT, *this);
1925 break;
1926
1927 case ImageInputFormatType::npbm: [[fallthrough]];
1928 case ImageInputFormatType::jpg: [[fallthrough]];
1929 case ImageInputFormatType::png_l: [[fallthrough]];
1930 case ImageInputFormatType::png_la: [[fallthrough]];
1931 case ImageInputFormatType::png_rgb: [[fallthrough]];
1932 case ImageInputFormatType::png_rgba:
1933 if (requestBitLength == 8) {
1934 image = std::make_unique<rgba8image>(width, height);
1935 loadFormat = createFormatDescriptor(VK_FORMAT_R8G8B8A8_UNORM, *this);
1936 break;
1937 } else if (requestBitLength == 16) {
1938 image = std::make_unique<rgba16image>(width, height);
1939 loadFormat = createFormatDescriptor(VK_FORMAT_R16G16B16A16_UNORM, *this);
1940 break;
1941 } else {
1942 fatal(rc::INVALID_FILE, "Unsupported format with {}-bit channels.", requestBitLength);
1943 }
1944 break;
1945 }
1946
1947 inputImageFile.readImage(static_cast<uint8_t*>(*image), image->getByteCount(), 0, 0, loadFormat);
1948 return image;
1949}
1950
1951std::vector<uint8_t> convertUNORMPacked(const std::unique_ptr<Image>& image, uint32_t C0, uint32_t C1, uint32_t C2, uint32_t C3, std::string_view swizzle = "") {
1952 if (!swizzle.empty())

Callers

nothing calls this directly

Calls 12

createFormatDescriptorFunction · 0.85
fatalClass · 0.85
specMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
formatTypeMethod · 0.80
getByteCountMethod · 0.80
maxFunction · 0.50
bit_ceilFunction · 0.50
formatMethod · 0.45
readImageMethod · 0.45

Tested by

no test coverage detected