diff --git a/src/torchcodec/_core/DecodeAvif.cpp b/src/torchcodec/_core/DecodeAvif.cpp index b40b9b97c..73e52c1d0 100644 --- a/src/torchcodec/_core/DecodeAvif.cpp +++ b/src/torchcodec/_core/DecodeAvif.cpp @@ -134,7 +134,8 @@ torch::stable::Tensor decode_avif( int num_channels = return_rgb ? 3 : 4; bool output_16 = should_output_uint16( - static_cast(output_dtype), decoder->image->depth > 8); + static_cast(output_dtype), + decoder->image->depth > 8); torch::stable::Tensor output; uint8_t* output_ptr = nullptr; diff --git a/src/torchcodec/_core/DecodeHeic.cpp b/src/torchcodec/_core/DecodeHeic.cpp index 4e3d1a88f..a49372f50 100644 --- a/src/torchcodec/_core/DecodeHeic.cpp +++ b/src/torchcodec/_core/DecodeHeic.cpp @@ -161,7 +161,7 @@ torch::stable::Tensor decode_heic( // *widen* an 8-bit source to 16 bits: that would be a lossy 8->10->16 // hop, so 8->16 is done exactly as `* 257` in Python instead. bool output_16 = should_output_uint16( - static_cast(output_dtype), source_gt_8bit); + static_cast(output_dtype), source_gt_8bit); decode_16 = source_gt_8bit && output_16; constexpr bool little_endian = std::endian::native == std::endian::little; diff --git a/src/torchcodec/_core/DecodePng.cpp b/src/torchcodec/_core/DecodePng.cpp index 5a94615c5..1fc1f9584 100644 --- a/src/torchcodec/_core/DecodePng.cpp +++ b/src/torchcodec/_core/DecodePng.cpp @@ -122,7 +122,7 @@ PngHeader read_header_and_configure( ErrorCtx& error_ctx, SourceCtx& source_ctx, ImageReadMode read_mode, - OutputDtype output_dtype) { + ImageOutputDtypeConfig output_dtype) { if (setjmp(png_jmpbuf(png_ptr)) != 0) { png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); STD_TORCH_CHECK(false, "decode_png failed: ", error_ctx.error_message); @@ -368,7 +368,7 @@ torch::stable::Tensor decode_png( error_ctx, source_ctx, static_cast(mode), - static_cast(output_dtype)); + static_cast(output_dtype)); auto output_16 = header.output_16; output = torch::stable::empty( diff --git a/src/torchcodec/_core/ImageCommon.h b/src/torchcodec/_core/ImageCommon.h index b286d18e6..fa84b3f78 100644 --- a/src/torchcodec/_core/ImageCommon.h +++ b/src/torchcodec/_core/ImageCommon.h @@ -29,7 +29,12 @@ enum class ImageReadMode : int64_t { // relevant for the decoders whose source can carry more than 8 bits per channel // (PNG, AVIF, HEIC); AUTO keeps the source's native precision (16-bit for // >8-bit sources, 8-bit otherwise). -enum class OutputDtype : int64_t { +// +// The image counterpart of OutputDtypeConfig (StreamOptions.h), which the video +// side resolves in the same way against its own source. The two aren't shared +// because the dtypes they choose between differ: uint8/uint16 here against +// uint8/float32 there. +enum class ImageOutputDtypeConfig : int64_t { UINT8 = 0, UINT16 = 1, AUTO = 2, @@ -39,20 +44,20 @@ enum class OutputDtype : int64_t { // requeted dtype, and the source. This is assumed to be called on a decoder // that supports >8bit sources. inline bool should_output_uint16( - OutputDtype output_dtype, + ImageOutputDtypeConfig output_dtype_config, bool source_gt_8bit) { - switch (output_dtype) { - case OutputDtype::UINT8: + switch (output_dtype_config) { + case ImageOutputDtypeConfig::UINT8: return false; - case OutputDtype::UINT16: + case ImageOutputDtypeConfig::UINT16: return true; - case OutputDtype::AUTO: + case ImageOutputDtypeConfig::AUTO: return source_gt_8bit; default: STD_TORCH_CHECK( false, "Unexpected output_dtype ", - static_cast(output_dtype), + static_cast(output_dtype_config), ". This should never happen, please report a bug to the TorchCodec repo."); } }