Boost

Untitled

Dec 4th, 2019
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. DLLEXPORT DecodedFrame::DecodedFrame(aom_image* img)
  2. {
  3.     Image image;
  4.  
  5.     image.Width = img->w;
  6.     image.Height = img->h;
  7.     image.BitDepth = img->bit_depth;
  8.     // img->bps
  9.  
  10.     image.ConvertImage = [img, image](uint8_t* target, size_t targetlength,
  11.                              Image::IMAGE_TARGET_FORMAT format) -> bool {
  12.         if(format != Image::IMAGE_TARGET_FORMAT::RGBA)
  13.             return false;
  14.  
  15.         const auto targetStride = image.Width * 4;
  16.  
  17.         if(targetlength != targetStride * image.Height)
  18.             return false;
  19.  
  20.         std::array<int, 3> planeIndices = {0, 1, 2};
  21.  
  22.         // Depending on the img->fmt the Y, U and V planes can be in different order
  23.         if(img->fmt & AOM_IMG_FMT_UV_FLIP) {
  24.             planeIndices = {0, 2, 1};
  25.         }
  26.  
  27.         if(img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
  28.             LOG_ERROR("AOM high bit depth doesn't work");
  29.         }
  30.  
  31.         if(img->fmt & AOM_IMG_FMT_HAS_ALPHA) {
  32.             LOG_WARNING("AOM alpha channel handling is not implemented");
  33.         }
  34.  
  35.         if(img->fmt == AOM_IMG_FMT_AOMYV12 || img->fmt == AOM_IMG_FMT_AOMI420) {
  36.             LOG_WARNING("AOM colourspace handling not implemented");
  37.         }
  38.  
  39.         // Setup plane data for the conversion call
  40.         std::array<const uint8_t*, 3> planes;
  41.         std::array<int, 3> strides;
  42.         std::array<std::tuple<int, int>, 3> planeSizes;
  43.  
  44.         for(int plane = 0; plane < 3; ++plane) {
  45.             const auto aomPlane = planeIndices[plane];
  46.             planes[plane] = img->planes[aomPlane];
  47.             strides[plane] = img->stride[aomPlane];
  48.             planeSizes[plane] = {aom_img_plane_width(img, aomPlane) *
  49.                                      ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1),
  50.                 aom_img_plane_height(img, aomPlane)};
  51.         }
  52.  
  53.         int result = -1;
  54.  
  55.         switch(img->fmt) {
  56.         case AOM_IMG_FMT_NONE: std::cout << "fmt: AOM_IMG_FMT_NONE\n"; break;
  57.         case AOM_IMG_FMT_YV12: std::cout << "fmt: AOM_IMG_FMT_YV12\n"; break;
  58.         case AOM_IMG_FMT_I420: std::cout << "fmt: AOM_IMG_FMT_I420\n"; break;
  59.         case AOM_IMG_FMT_AOMYV12: std::cout << "fmt: AOM_IMG_FMT_AOMYV12\n"; break;
  60.         case AOM_IMG_FMT_AOMI420: std::cout << "fmt: AOM_IMG_FMT_AOMI420\n"; break;
  61.         case AOM_IMG_FMT_I422: std::cout << "fmt: AOM_IMG_FMT_I422\n"; break;
  62.         case AOM_IMG_FMT_I444: std::cout << "fmt: AOM_IMG_FMT_I444\n"; break;
  63.         case AOM_IMG_FMT_444A: std::cout << "fmt: AOM_IMG_FMT_444A\n"; break;
  64.         case AOM_IMG_FMT_I42016: std::cout << "fmt: AOM_IMG_FMT_I42016\n"; break;
  65.         case AOM_IMG_FMT_I42216: std::cout << "fmt: AOM_IMG_FMT_I42216\n"; break;
  66.         case AOM_IMG_FMT_I44416: std::cout << "fmt: AOM_IMG_FMT_I44416\n"; break;
  67.         }
  68.  
  69.         // Use libyuv to convert the data
  70.         if(img->fmt & AOM_IMG_FMT_I420) {
  71.             result = libyuv::I420ToABGR(planes[0], strides[0], planes[1], strides[1],
  72.                 planes[2], strides[2], target, targetStride, image.Width, image.Height);
  73.         } else if(img->fmt & AOM_IMG_FMT_I422) {
  74.             result = libyuv::I422ToABGR(planes[0], strides[0], planes[1], strides[1],
  75.                 planes[2], strides[2], target, targetStride, image.Width, image.Height);
  76.         } else if(img->fmt & AOM_IMG_FMT_I444) {
  77.             result = libyuv::I444ToABGR(planes[0], strides[0], planes[1], strides[1],
  78.                 planes[2], strides[2], target, targetStride, image.Width, image.Height);
  79.         } else {
  80.             LOG_FATAL("unimplemented AOM image format type");
  81.         }
  82.  
  83.         return result == 0;
  84.     };
  85.  
  86.     TypeSpecificData = image;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment