当前位置: 首页>>代码示例>>C++>>正文


C++ DllImageLib::GetBackgroundColor方法代码示例

本文整理汇总了C++中DllImageLib::GetBackgroundColor方法的典型用法代码示例。如果您正苦于以下问题:C++ DllImageLib::GetBackgroundColor方法的具体用法?C++ DllImageLib::GetBackgroundColor怎么用?C++ DllImageLib::GetBackgroundColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DllImageLib的用法示例。


在下文中一共展示了DllImageLib::GetBackgroundColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadFromFile

bool CBaseTexture::LoadFromFile(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight,
                                bool autoRotate, unsigned int *originalWidth, unsigned int *originalHeight,
                                unsigned int dstWidth, unsigned int dstHeight)
{
  //Quick and dirty check if the file is DDS file...

  CFile file;
  if (!file.Open(texturePath))
  {  
    CLog::Log(LOGERROR, "%s - Error opening texture file: %s", __FUNCTION__, texturePath.c_str());
    return false;
  }

  // read the header
  uint32_t magic;
  if (file.Read(&magic, 4) != 4)
  {
    CLog::Log(LOGERROR, "%s - Can't read signature from file: %s", __FUNCTION__, texturePath.c_str());
    return false;
  }

  if (strncmp((const char *)&magic, "DDS ", 4) == 0 || CUtil::GetExtension(texturePath).Equals(".dds"))
  { // special case for DDS images
    CDDSImage image;
    CLog::Log(LOGDEBUG, "%s - loading dds file: %s", __FUNCTION__, texturePath.c_str());
    image.ReadFile(texturePath);
    Update(image.GetWidth(), image.GetHeight(), 0, image.GetFormat(), image.GetData(), false);
    return true;
  }

  DllImageLib dll;
  if (!dll.Load())
    return false;

  ImageInfo image;
  memset(&image, 0, sizeof(image));
  //image.width = dstWidth;
  //image.height = dstHeight;

  unsigned int width = maxWidth ? std::min(maxWidth, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize();
  unsigned int height = maxHeight ? std::min(maxHeight, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize();

  if(!dll.LoadImage(texturePath.c_str(), width, height, &image))
  {
    CLog::Log(LOGERROR, "Texture manager unable to load file: %s", texturePath.c_str());
    return false;
  }

  Allocate(image.width, image.height, XB_FMT_B8G8R8A8);
  if (autoRotate && image.exifInfo.Orientation)
    m_orientation = image.exifInfo.Orientation - 1;
  if (originalWidth)
    *originalWidth = image.originalwidth;
  if (originalHeight)
    *originalHeight = image.originalheight;

  unsigned int destPitch = GetPitch();
  unsigned int srcPitch = ((image.width + 1)* 3 / 4) * 4; // bitmap row length is aligned to 4 bytes

  // test background color for alpha blending
  long  nBkgndIndex;
  RGBQUAD nBkgndColor;
  dll.GetBackgroundColor(&image, &nBkgndColor, &nBkgndIndex);

  for (unsigned int y = 0; y < m_imageHeight; y++)
  {
    unsigned char *dst = m_pixels + y * destPitch;
    unsigned char *src = image.texture + (m_imageHeight - 1 - y) * srcPitch;
    unsigned char *alpha = image.alpha + (m_imageHeight - 1 - y) * m_imageWidth;
    for (unsigned int x = 0; x < m_imageWidth; x++)
    {
      *dst++ = *src++;
      *dst++ = *src++;
      *dst++ = *src++;
      *dst++ = (image.alpha) ? *alpha++ : 0xff;
    }
  }

  if (nBkgndIndex != -1)
  {
    for (unsigned int y = 0; y < m_imageHeight; y++)
    {
      unsigned char *dst = m_pixels + y * destPitch;
      //unsigned char *src = image.texture + (m_imageHeight - 1 - y) * srcPitch;
      //unsigned char *alpha = image.alpha + (m_imageHeight - 1 - y) * m_imageWidth;
      for (unsigned int x = 0; x < m_imageWidth; x++)
      {
        if (*dst == nBkgndColor.rgbBlue
            && *(dst + 1) == nBkgndColor.rgbGreen
            && *(dst + 2) == nBkgndColor.rgbRed)
        {
          *(dst + 3) = 0x00;
        }
        dst += 4;
      }
    }
  }

  dll.ReleaseImage(&image);

//.........这里部分代码省略.........
开发者ID:Kr0nZ,项目名称:boxee,代码行数:101,代码来源:Texture.cpp


注:本文中的DllImageLib::GetBackgroundColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。