Skip to content

Commit

Permalink
support full color range transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba-z committed Feb 7, 2020
1 parent f457fd3 commit 635b0ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
52 changes: 34 additions & 18 deletions src/img/Convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
#include "avif/img/Image.hpp"
#include "avif/img/Conversion.hpp"

template <uint8_t rgbBits, uint8_t yuvBits>
template <uint8_t rgbBits, uint8_t yuvBits, bool isFullRange>
void convert(avif::img::Image<rgbBits>& src, aom_image& dst) {
switch (dst.fmt) {
case AOM_IMG_FMT_I420:
case AOM_IMG_FMT_I42016:
avif::img::FromRGB<rgbBits, yuvBits>().toI420(src,
avif::img::FromRGB<rgbBits, yuvBits, isFullRange>().toI420(src,
dst.planes[0], dst.stride[0],
dst.planes[1], dst.stride[1],
dst.planes[2], dst.stride[2]);
break;
case AOM_IMG_FMT_I422:
case AOM_IMG_FMT_I42216:
avif::img::FromRGB<rgbBits, yuvBits>().toI422(src,
avif::img::FromRGB<rgbBits, yuvBits, isFullRange>().toI422(src,
dst.planes[0], dst.stride[0],
dst.planes[1], dst.stride[1],
dst.planes[2], dst.stride[2]);
break;
case AOM_IMG_FMT_I444:
case AOM_IMG_FMT_I44416:
avif::img::FromRGB<rgbBits, yuvBits>().toI444(src,
avif::img::FromRGB<rgbBits, yuvBits, isFullRange>().toI444(src,
dst.planes[0], dst.stride[0],
dst.planes[1], dst.stride[1],
dst.planes[2], dst.stride[2]);
Expand All @@ -38,19 +38,35 @@ void convert(avif::img::Image<rgbBits>& src, aom_image& dst) {
}


template <size_t BitsPerPixel>
void convert(avif::img::Image<BitsPerPixel>& src, aom_image& dst, int const yuvBits) {
switch (yuvBits) {
case 8:
convert<BitsPerPixel, 8>(src, dst);
break;
case 10:
convert<BitsPerPixel, 10>(src, dst);
break;
case 12:
convert<BitsPerPixel, 12>(src, dst);
break;
default:
throw std::invalid_argument(fmt::format("Unsupported YUV bit-depth: {}", dst.bit_depth));
template <size_t rgbBits>
void convert(avif::img::Image<rgbBits>& src, aom_image& dst, int const yuvBits) {
if (dst.range == AOM_CR_STUDIO_RANGE) {
switch (yuvBits) {
case 8:
convert<rgbBits, 8, false>(src, dst);
break;
case 10:
convert<rgbBits, 10, false>(src, dst);
break;
case 12:
convert<rgbBits, 12, false>(src, dst);
break;
default:
throw std::invalid_argument(fmt::format("Unsupported YUV bit-depth: {}", dst.bit_depth));
}
} else {
switch (yuvBits) {
case 8:
convert<rgbBits, 8, true>(src, dst);
break;
case 10:
convert<rgbBits, 10, true>(src, dst);
break;
case 12:
convert<rgbBits, 12, true>(src, dst);
break;
default:
throw std::invalid_argument(fmt::format("Unsupported YUV bit-depth: {}", dst.bit_depth));
}
}
}

0 comments on commit 635b0ab

Please sign in to comment.