Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DLLEXPORT DecodedFrame::DecodedFrame(aom_image* img)
- {
- Image image;
- image.Width = img->w;
- image.Height = img->h;
- image.BitDepth = img->bit_depth;
- // img->bps
- image.ConvertImage = [img, image](uint8_t* target, size_t targetlength,
- Image::IMAGE_TARGET_FORMAT format) -> bool {
- if(format != Image::IMAGE_TARGET_FORMAT::RGBA)
- return false;
- const auto targetStride = image.Width * 4;
- if(targetlength != targetStride * image.Height)
- return false;
- std::array<int, 3> planeIndices = {0, 1, 2};
- // Depending on the img->fmt the Y, U and V planes can be in different order
- if(img->fmt & AOM_IMG_FMT_UV_FLIP) {
- planeIndices = {0, 2, 1};
- }
- if(img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
- LOG_ERROR("AOM high bit depth doesn't work");
- }
- if(img->fmt & AOM_IMG_FMT_HAS_ALPHA) {
- LOG_WARNING("AOM alpha channel handling is not implemented");
- }
- if(img->fmt == AOM_IMG_FMT_AOMYV12 || img->fmt == AOM_IMG_FMT_AOMI420) {
- LOG_WARNING("AOM colourspace handling not implemented");
- }
- // Setup plane data for the conversion call
- std::array<const uint8_t*, 3> planes;
- std::array<int, 3> strides;
- std::array<std::tuple<int, int>, 3> planeSizes;
- for(int plane = 0; plane < 3; ++plane) {
- const auto aomPlane = planeIndices[plane];
- planes[plane] = img->planes[aomPlane];
- strides[plane] = img->stride[aomPlane];
- planeSizes[plane] = {aom_img_plane_width(img, aomPlane) *
- ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1),
- aom_img_plane_height(img, aomPlane)};
- }
- int result = -1;
- switch(img->fmt) {
- case AOM_IMG_FMT_NONE: std::cout << "fmt: AOM_IMG_FMT_NONE\n"; break;
- case AOM_IMG_FMT_YV12: std::cout << "fmt: AOM_IMG_FMT_YV12\n"; break;
- case AOM_IMG_FMT_I420: std::cout << "fmt: AOM_IMG_FMT_I420\n"; break;
- case AOM_IMG_FMT_AOMYV12: std::cout << "fmt: AOM_IMG_FMT_AOMYV12\n"; break;
- case AOM_IMG_FMT_AOMI420: std::cout << "fmt: AOM_IMG_FMT_AOMI420\n"; break;
- case AOM_IMG_FMT_I422: std::cout << "fmt: AOM_IMG_FMT_I422\n"; break;
- case AOM_IMG_FMT_I444: std::cout << "fmt: AOM_IMG_FMT_I444\n"; break;
- case AOM_IMG_FMT_444A: std::cout << "fmt: AOM_IMG_FMT_444A\n"; break;
- case AOM_IMG_FMT_I42016: std::cout << "fmt: AOM_IMG_FMT_I42016\n"; break;
- case AOM_IMG_FMT_I42216: std::cout << "fmt: AOM_IMG_FMT_I42216\n"; break;
- case AOM_IMG_FMT_I44416: std::cout << "fmt: AOM_IMG_FMT_I44416\n"; break;
- }
- // Use libyuv to convert the data
- if(img->fmt & AOM_IMG_FMT_I420) {
- result = libyuv::I420ToABGR(planes[0], strides[0], planes[1], strides[1],
- planes[2], strides[2], target, targetStride, image.Width, image.Height);
- } else if(img->fmt & AOM_IMG_FMT_I422) {
- result = libyuv::I422ToABGR(planes[0], strides[0], planes[1], strides[1],
- planes[2], strides[2], target, targetStride, image.Width, image.Height);
- } else if(img->fmt & AOM_IMG_FMT_I444) {
- result = libyuv::I444ToABGR(planes[0], strides[0], planes[1], strides[1],
- planes[2], strides[2], target, targetStride, image.Width, image.Height);
- } else {
- LOG_FATAL("unimplemented AOM image format type");
- }
- return result == 0;
- };
- TypeSpecificData = image;
- }
Advertisement
Add Comment
Please, Sign In to add comment