Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/torchcodec/_core/DecodeAvif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ torch::stable::Tensor decode_avif(
int num_channels = return_rgb ? 3 : 4;

bool output_16 = should_output_uint16(
static_cast<OutputDtype>(output_dtype), decoder->image->depth > 8);
static_cast<ImageOutputDtypeConfig>(output_dtype),
decoder->image->depth > 8);

torch::stable::Tensor output;
uint8_t* output_ptr = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/DecodeHeic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<OutputDtype>(output_dtype), source_gt_8bit);
static_cast<ImageOutputDtypeConfig>(output_dtype), source_gt_8bit);
decode_16 = source_gt_8bit && output_16;

constexpr bool little_endian = std::endian::native == std::endian::little;
Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/_core/DecodePng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -368,7 +368,7 @@ torch::stable::Tensor decode_png(
error_ctx,
source_ctx,
static_cast<ImageReadMode>(mode),
static_cast<OutputDtype>(output_dtype));
static_cast<ImageOutputDtypeConfig>(output_dtype));

auto output_16 = header.output_16;
output = torch::stable::empty(
Expand Down
19 changes: 12 additions & 7 deletions src/torchcodec/_core/ImageCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<int64_t>(output_dtype),
static_cast<int64_t>(output_dtype_config),
". This should never happen, please report a bug to the TorchCodec repo.");
}
}
Expand Down
Loading