template<bool avx, bool aligned> void typeToBGRA(const void* const src, void* const dest, const PixelTypes::PixelType type, const size_t size)
{
  const __m_auto_i* const pSrc = reinterpret_cast<const __m_auto_i*>(src);
  const __m_auto_i* const srcEnd = reinterpret_cast<const __m_auto_i*>(src) + (size * PixelTypes::pixelSize(type)) / sizeof(__m_auto_i);
  __m_auto_i* pDest = reinterpret_cast<__m_auto_i*>(dest);

  switch(type)
  {
    case PixelTypes::PixelType::RGB:
      rgbToBGRA<avx, aligned>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::YUV:
      yuvToBGRA<avx, aligned>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::YUYV:
      yuyvToBGRA<avx, aligned>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::Colored:
      coloredToBGRA<avx, aligned>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::Grayscale:
      grayscaledToBGRA<avx, aligned>(pSrc, srcEnd, pDest);
      break;
    default:
      ASSERT(false);
  }

  size_t rest = (size * PixelTypes::pixelSize(type)) % sizeof(__m_auto_i);
  if(rest != 0)
  {
    PixelTypes::BGRAPixel* const ppDest = reinterpret_cast<PixelTypes::BGRAPixel*>(dest) + size - rest;
    switch(type)
    {
      case PixelTypes::PixelType::RGB:
        rgbToBGRA(reinterpret_cast<const PixelTypes::RGBPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::RGBPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::YUV:
        yuvToBGRA(reinterpret_cast<const PixelTypes::YUVPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::YUVPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::YUYV:
        yuyvToBGRA(reinterpret_cast<const PixelTypes::YUYVPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::YUYVPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::Colored:
        coloredToBGRA(reinterpret_cast<const PixelTypes::ColoredPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::ColoredPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::Grayscale:
        grayscaledToBGRA(reinterpret_cast<const PixelTypes::GrayscaledPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::GrayscaledPixel*>(src) + size, ppDest);
        break;
      default:
        ASSERT(false);
    }
  }
}
Exemple #2
0
template<bool avx> void typeToBGRA(const void* const src, void* const dest, const PixelTypes::PixelType type, const size_t size)
{
  const __m_auto_i* const pSrc = reinterpret_cast<const __m_auto_i*>(src);
  const __m_auto_i* const srcEnd = reinterpret_cast<const __m_auto_i*>(src) + (size * PixelTypes::pixelSize(type)) / sizeof(__m_auto_i);
  __m_auto_i* pDest = reinterpret_cast<__m_auto_i*>(dest);

  switch(type)
  {
    case PixelTypes::PixelType::RGB:
      rgbToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::YUV:
      yuvToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::YUYV:
      yuyvToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::Colored:
      coloredToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::Grayscale:
      grayscaledToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::Hue:
      hueToBGRA(reinterpret_cast<const PixelTypes::HuePixel*>(src), reinterpret_cast<const PixelTypes::HuePixel*>(srcEnd), reinterpret_cast<PixelTypes::BGRAPixel*>(dest));
      break;
    case PixelTypes::PixelType::Edge2:
      edge2ToBGRA<avx>(pSrc, srcEnd, pDest, reinterpret_cast<const __m_auto_i*>(dest) + (size * PixelTypes::pixelSize(PixelTypes::BGRA)) / sizeof(__m_auto_i));
      break;/*
    case PixelTypes::PixelType::Edge2MonoAvg:
      //edge2MonoAvgToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    case PixelTypes::PixelType::Edge2MonoAbsAvg:
      //edge2MonoAbsAvgBGRA<avx>(pSrc, srcEnd, pDest);
      break;*/
    case PixelTypes::PixelType::Binary:
      binaryToBGRA<avx>(pSrc, srcEnd, pDest);
      break;
    default:
      FAIL("Unknown pixel type.");
  }

  size_t rest = (size * PixelTypes::pixelSize(type)) % sizeof(__m_auto_i);
  if(rest != 0)
  {
    PixelTypes::BGRAPixel* const ppDest = reinterpret_cast<PixelTypes::BGRAPixel*>(dest) + size - rest;
    switch(type)
    {
      case PixelTypes::PixelType::RGB:
        rgbToBGRA(reinterpret_cast<const PixelTypes::RGBPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::RGBPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::YUV:
        yuvToBGRA(reinterpret_cast<const PixelTypes::YUVPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::YUVPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::YUYV:
        yuyvToBGRA(reinterpret_cast<const PixelTypes::YUYVPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::YUYVPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::Colored:
        coloredToBGRA(reinterpret_cast<const PixelTypes::ColoredPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::ColoredPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::Grayscale:
        grayscaledToBGRA(reinterpret_cast<const PixelTypes::GrayscaledPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::GrayscaledPixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::Hue:
        hueToBGRA(reinterpret_cast<const PixelTypes::HuePixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::HuePixel*>(src) + size, ppDest);
        break;
      case PixelTypes::PixelType::Edge2:
        edge2ToBGRA(reinterpret_cast<const PixelTypes::Edge2Pixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::Edge2Pixel*>(src) + size, ppDest, reinterpret_cast<PixelTypes::BGRAPixel*>(dest) + size);
        break;
      case PixelTypes::PixelType::Binary:
        binaryToBGRA(reinterpret_cast<const PixelTypes::BinaryPixel*>(src) + size - rest, reinterpret_cast<const PixelTypes::BinaryPixel*>(src) + size, ppDest);
        break;
      default:
        FAIL("Unknown pixel type.");
    }
  }
}