Skip to content

Commit

Permalink
Add support for fewer components in input files
Browse files Browse the repository at this point in the history
  • Loading branch information
aqnuep committed Aug 22, 2023
1 parent e437ec4 commit 1d639ef
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 116 deletions.
2 changes: 1 addition & 1 deletion tests/cts
Submodule cts updated 95 files
+2 −0 clitests/CMakeLists.txt
+14 −9 clitests/clitest.py
+ clitests/golden/create/fewer_components_exr/A2B10G10R10_SINT_PACK32_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2B10G10R10_SINT_PACK32_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2B10G10R10_SINT_PACK32_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2B10G10R10_UINT_PACK32_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2B10G10R10_UINT_PACK32_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2B10G10R10_UINT_PACK32_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2R10G10B10_SINT_PACK32_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2R10G10B10_SINT_PACK32_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2R10G10B10_SINT_PACK32_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2R10G10B10_UINT_PACK32_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2R10G10B10_UINT_PACK32_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/A2R10G10B10_UINT_PACK32_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/B10G11R11_UFLOAT_PACK32_RG_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/B10G11R11_UFLOAT_PACK32_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/B8G8R8A8_SINT_RGB_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/B8G8R8A8_SINT_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/B8G8R8A8_UINT_RGB_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/B8G8R8A8_UINT_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/E5B9G9R9_UFLOAT_PACK32_RG_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/E5B9G9R9_UFLOAT_PACK32_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SFLOAT_RGB_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SFLOAT_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SFLOAT_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SFLOAT_R_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SINT_RGB_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SINT_RGB_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SINT_RG_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_SINT_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_UINT_RGB_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_UINT_RGB_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_UINT_RG_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16A16_UINT_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16_SFLOAT_RG_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16_SFLOAT_R_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16_SINT_RG_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16_SINT_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16_UINT_RG_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16B16_UINT_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16_SFLOAT_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16_SINT_R_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R16G16_UINT_R_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_SFLOAT_RGB_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_SFLOAT_RGB_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_SFLOAT_RG_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_SFLOAT_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_UINT_RGB_UINT_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_UINT_RG_UINT_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32A32_UINT_R_UINT_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32_SFLOAT_RG_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32_SFLOAT_R_FLOAT_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32_UINT_RG_UINT_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32B32_UINT_R_UINT_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32_SFLOAT_R_FLOAT_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R32G32_UINT_R_UINT_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_SINT_RGB_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_SINT_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_SINT_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_SINT_R_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_UINT_RGB_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_UINT_RGB_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_UINT_RG_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8A8_UINT_R_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8_SINT_RG_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8_SINT_R_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8_UINT_RG_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8B8_UINT_R_HALF_LDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8_SINT_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_exr/R8G8_UINT_R_HALF_HDR_16x16.ktx2
+ clitests/golden/create/fewer_components_png/A1R5G5B5_UNORM_PACK16_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/A2B10G10R10_UNORM_PACK32_RGB16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/A2R10G10B10_UNORM_PACK32_RGB16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/A4B4G4R4_UNORM_PACK16_EXT_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/A4R4G4B4_UNORM_PACK16_EXT_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/B4G4R4A4_UNORM_PACK16_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/B5G5R5A1_UNORM_PACK16_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/B8G8R8A8_SRGB_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/B8G8R8A8_UNORM_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R10X6G10X6B10X6A10X6_UNORM_4PACK16_RGB16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R12X4G12X4B12X4A12X4_UNORM_4PACK16_RGB16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R16G16B16A16_UNORM_L16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R16G16B16A16_UNORM_RGB16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R4G4B4A4_UNORM_PACK16_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R5G5B5A1_UNORM_PACK16_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_SRGB_RGB8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_L16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_L1_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_L2_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_L4_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_L8_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_RGB16_16x16.ktx2
+ clitests/golden/create/fewer_components_png/R8G8B8A8_UNORM_RGB8_16x16.ktx2
+83 −0 clitests/tests/create/fewer_components_exr.json
+40 −0 clitests/tests/create/fewer_components_png.json
37 changes: 20 additions & 17 deletions tools/imageio/exr.imageio/exrinput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ void ExrInput::readImage(void* outputBuffer, size_t bufferByteCount,
const auto numSourceChannels = static_cast<uint32_t>(image.num_channels);
const auto numTargetChannels = targetFormat.channelCount();

if (numTargetChannels > numSourceChannels)
throw std::runtime_error(fmt::format("EXR load error: "
"Requested {} channels but the input file only has {}.", numTargetChannels, numSourceChannels));

const auto expectedBufferByteCount = height * width * numTargetChannels * targetBitDepth / 8;
if (bufferByteCount != expectedBufferByteCount)
throw std::runtime_error(fmt::format("EXR load error: "
Expand All @@ -253,35 +249,42 @@ void ExrInput::readImage(void* outputBuffer, size_t bufferByteCount,
warning(fmt::format("EXR load warning: Unrecognized channel \"{}\" is ignored.", header.channels[i].name));
}

for (uint32_t i = 0; i < numTargetChannels; ++i)
if (!channels[i])
throw std::runtime_error(fmt::format("EXR load error: Requested channel {} is not present in the input file.", i));

// Copy the data
const auto copyData = [&](unsigned char* ptr, uint32_t dataSize) {
const auto copyData = [&](unsigned char* ptr, uint32_t dataSize, const void* defaultColor) {
const auto sourcePtr = [&](uint32_t channel, uint32_t x, uint32_t y) {
return reinterpret_cast<const unsigned char*>(image.images[channel] + (y * width + x) * dataSize);
};

for (uint32_t y = 0; y < height; ++y) {
for (uint32_t x = 0; x < width; ++x) {
auto* targetPixel = ptr + (y * width * numTargetChannels + x * numTargetChannels) * dataSize;
for (uint32_t c = 0; c < numTargetChannels; ++c)
std::memcpy(targetPixel + c * dataSize, sourcePtr(*channels[c], x, y), dataSize);
for (uint32_t c = 0; c < numTargetChannels; ++c) {
if (channels[c].has_value()) {
std::memcpy(targetPixel + c * dataSize, sourcePtr(*channels[c], x, y), dataSize);
} else {
std::memcpy(targetPixel + c * dataSize, static_cast<const uint8_t*>(defaultColor) + c * dataSize, dataSize);
}
}
}
}
};

switch (requestedType) {
case TINYEXR_PIXELTYPE_HALF:
copyData(reinterpret_cast<unsigned char*>(outputBuffer), 2); // sizeof(half)
case TINYEXR_PIXELTYPE_HALF: {
uint16_t defaultColor[] = { 0x0000, 0x0000, 0x0000, 0x3C00 }; // { 0.h, 0.h, 0.h,1.h }
copyData(reinterpret_cast<unsigned char*>(outputBuffer), sizeof(defaultColor[0]), &defaultColor[0]);
break;
case TINYEXR_PIXELTYPE_FLOAT:
copyData(reinterpret_cast<unsigned char*>(outputBuffer), sizeof(float));
}
case TINYEXR_PIXELTYPE_FLOAT: {
float defaultColor[] = { 0.f, 0.f, 0.f, 1.f };
copyData(reinterpret_cast<unsigned char*>(outputBuffer), sizeof(defaultColor[0]), &defaultColor[0]);
break;
case TINYEXR_PIXELTYPE_UINT:
copyData(reinterpret_cast<unsigned char*>(outputBuffer), sizeof(uint32_t));
}
case TINYEXR_PIXELTYPE_UINT: {
uint32_t defaultColor[] = { 0, 0, 0, 1 };
copyData(reinterpret_cast<unsigned char*>(outputBuffer), sizeof(defaultColor[0]), &defaultColor[0]);
break;
}
default:
assert(false && "Internal error");
break;
Expand Down
Loading

0 comments on commit 1d639ef

Please sign in to comment.