Beispiel #1
0
Texture::Texture(const Texture& copy) :
Resource<Texture>(),
myWidth        (0),
myHeight       (0),
myTextureWidth (0),
myTextureHeight(0),
myTexture      (0),
myIsSmooth     (copy.myIsSmooth),
myPixelsFlipped(false)
{
    if (copy.myTexture)
        LoadFromImage(copy.CopyToImage());
}
Beispiel #2
0
Texture::Texture(const Texture& copy) :
myWidth        (0),
myHeight       (0),
myTextureWidth (0),
myTextureHeight(0),
myTexture      (0),
myIsSmooth     (copy.myIsSmooth),
myIsRepeated   (copy.myIsRepeated),
myPixelsFlipped(false),
myCacheId      (GetUniqueId())
{
    if (copy.myTexture)
        LoadFromImage(copy.CopyToImage());
}
Beispiel #3
0
bool CBaseTexture::LoadFromFileInMem(unsigned char* buffer, size_t size, const std::string& mimeType, unsigned int maxWidth, unsigned int maxHeight)
{
  if (!buffer || !size)
    return false;

  //ImageLib is sooo sloow for jpegs. Try our own decoder first. If it fails, fall back to ImageLib.
  if (mimeType == "image/jpeg")
  {
    CJpegIO jpegfile;
    if (jpegfile.Read(buffer, size, maxWidth, maxHeight))
    {
      if (jpegfile.Width() > 0 && jpegfile.Height() > 0)
      {
        Allocate(jpegfile.Width(), jpegfile.Height(), XB_FMT_A8R8G8B8);
        if (jpegfile.Decode(m_pixels, GetPitch(), XB_FMT_A8R8G8B8))
        {
          m_hasAlpha=false;
          ClampToEdge();
          return true;
        }
      }
    }
  }
  DllImageLib dll;
  if (!dll.Load())
    return false;

  ImageInfo image;
  memset(&image, 0, sizeof(image));

  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();

  CStdString ext = mimeType;
  int nPos = ext.Find('/');
  if (nPos > -1)
    ext.Delete(0, nPos + 1);

  if(!dll.LoadImageFromMemory(buffer, size, ext.c_str(), width, height, &image))
  {
    CLog::Log(LOGERROR, "Texture manager unable to load image from memory");
    return false;
  }
  LoadFromImage(image);
  dll.ReleaseImage(&image);

  return true;
}
  bool HeightFeederParser::Load (float* outputBuffer, size_t outputWidth, 
    size_t outputHeight, size_t outputPitch, float heightScale, float offset)
  {
    if (sourceFormat == HEIGHT_SOURCE_IMAGE)
    {
      return LoadFromImage (outputBuffer, outputWidth, outputHeight,
        outputPitch, heightScale, offset);
    }
    
    // Handle loading from all other (raw) formats
    if (!vfs)
      return false;
    
    size_t valueSize = 0;
    switch (sourceFormat)
    {
    case HEIGHT_SOURCE_RAW8:
      valueSize = sizeof (uint8);
      break;
    case HEIGHT_SOURCE_RAW16LE:
    case HEIGHT_SOURCE_RAW16BE:
      valueSize = sizeof (uint16);
      break;
    case HEIGHT_SOURCE_RAW32LE:
    case HEIGHT_SOURCE_RAW32BE:
    case HEIGHT_SOURCE_RAWFLOATLE:
    case HEIGHT_SOURCE_RAWFLOATBE:
      valueSize = sizeof (uint32);
      break;
    case HEIGHT_SOURCE_IMAGE:
      // Can not happen.
      CS_ASSERT (false);
    }

    csRef<iDataBuffer> buf = vfs->ReadFile (sourceLocation.GetDataSafe (),
	false);
    if (!buf ||
	((outputHeight * outputWidth * valueSize) != buf->GetSize ()))
      return false;

    switch (sourceFormat)
    {
      case HEIGHT_SOURCE_RAW8:
        {
          RawHeightmapReader<GetterUint8> reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_RAW16LE:
        {
          RawHeightmapReader<GetterUint16<csLittleEndian> > reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_RAW16BE:
        {
          RawHeightmapReader<GetterUint16<csBigEndian> > reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_RAW32LE:
        {
          RawHeightmapReader<GetterUint32<csLittleEndian> > reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_RAW32BE:
        {
          RawHeightmapReader<GetterUint32<csBigEndian> > reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_RAWFLOATLE:
        {
          RawHeightmapReader<GetterFloat<csLittleEndian> > reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_RAWFLOATBE:
        {
          RawHeightmapReader<GetterFloat<csBigEndian> > reader;
          return reader.ReadData (outputBuffer, outputWidth, outputHeight, 
            outputPitch, heightScale, offset, buf->GetData ());
        }
        break;
      case HEIGHT_SOURCE_IMAGE:
	// @@@FIXME: Handle this case?
	break;
    }

    return false;
  }
Beispiel #5
0
bool CBaseTexture::LoadFromFileInternal(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate)
{
#if defined(HAS_OMXPLAYER)
  if (URIUtils::GetExtension(texturePath).Equals(".jpg") || 
      URIUtils::GetExtension(texturePath).Equals(".tbn") 
      /*|| URIUtils::GetExtension(texturePath).Equals(".png")*/)
  {
    COMXImage omx_image;

    if(omx_image.ReadFile(texturePath))
    {
      // TODO: we only decode as half width and height. this is a workaround for the PI memory limitation
      if(omx_image.Decode(omx_image.GetWidth() / 2, omx_image.GetHeight() / 2))
      {
        Allocate(omx_image.GetDecodedWidth(), omx_image.GetDecodedHeight(), XB_FMT_A8R8G8B8);

        if(!m_pixels)
        {
          CLog::Log(LOGERROR, "Texture manager (OMX) out of memory");
          omx_image.Close();
          return false;
        }

        m_originalWidth  = omx_image.GetOriginalWidth();
        m_originalHeight = omx_image.GetOriginalHeight();

        m_hasAlpha = omx_image.IsAlpha();

        if (autoRotate && omx_image.GetOrientation())
          m_orientation = omx_image.GetOrientation() - 1;

        if(omx_image.GetDecodedData())
        {
          int size = ( ( GetPitch() * GetRows() ) > omx_image.GetDecodedSize() ) ?
                           omx_image.GetDecodedSize() : ( GetPitch() * GetRows() );

          memcpy(m_pixels, (unsigned char *)omx_image.GetDecodedData(), size);
        }

        omx_image.Close();

        return true;
      }
      else
      {
        omx_image.Close();
      }
    }
  }
#endif
  if (URIUtils::GetExtension(texturePath).Equals(".dds"))
  { // special case for DDS images
    CDDSImage image;
    if (image.ReadFile(texturePath))
    {
      Update(image.GetWidth(), image.GetHeight(), 0, image.GetFormat(), image.GetData(), false);
      return true;
    }
    return false;
  }

  //ImageLib is sooo sloow for jpegs. Try our own decoder first. If it fails, fall back to ImageLib.
  if (URIUtils::GetExtension(texturePath).Equals(".jpg") || URIUtils::GetExtension(texturePath).Equals(".tbn"))
  {
    CJpegIO jpegfile;
    if (jpegfile.Open(texturePath, maxWidth, maxHeight))
    {
      if (jpegfile.Width() > 0 && jpegfile.Height() > 0)
      {
        Allocate(jpegfile.Width(), jpegfile.Height(), XB_FMT_A8R8G8B8);
        if (jpegfile.Decode(m_pixels, GetPitch(), XB_FMT_A8R8G8B8))
        {
          if (autoRotate && jpegfile.Orientation())
            m_orientation = jpegfile.Orientation() - 1;
          m_hasAlpha=false;
          ClampToEdge();
          return true;
        }
      }
    }
    CLog::Log(LOGDEBUG, "%s - Load of %s failed. Falling back to ImageLib", __FUNCTION__, texturePath.c_str());
  }

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

  ImageInfo image;
  memset(&image, 0, sizeof(image));

  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;
  }

  LoadFromImage(image, autoRotate);
  dll.ReleaseImage(&image);

  return true;
}
Beispiel #6
0
bool CBaseTexture::LoadFromFile(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight,
                                bool autoRotate, unsigned int *originalWidth, unsigned int *originalHeight)
{
  if (URIUtils::GetExtension(texturePath).Equals(".dds"))
  { // special case for DDS images
    CDDSImage image;
    if (image.ReadFile(texturePath))
    {
      Update(image.GetWidth(), image.GetHeight(), 0, image.GetFormat(), image.GetData(), false);
      return true;
    }
    return false;
  }

  //ImageLib is sooo sloow for jpegs. Try our own decoder first. If it fails, fall back to ImageLib.
  if (URIUtils::GetExtension(texturePath).Equals(".jpg") || URIUtils::GetExtension(texturePath).Equals(".tbn"))
  {
    CJpegIO jpegfile;
    if (jpegfile.Open(texturePath, maxWidth, maxHeight))
    {
      if (jpegfile.Width() > 0 && jpegfile.Height() > 0)
      {
        Allocate(jpegfile.Width(), jpegfile.Height(), XB_FMT_A8R8G8B8);
        if (jpegfile.Decode(m_pixels, GetPitch(), XB_FMT_A8R8G8B8))
        {
          if (autoRotate && jpegfile.Orientation())
            m_orientation = jpegfile.Orientation() - 1;
          m_hasAlpha=false;
          ClampToEdge();
          return true;
        }
      }
    }
    CLog::Log(LOGDEBUG, "%s - Load of %s failed. Falling back to ImageLib", __FUNCTION__, texturePath.c_str());
  }

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

  ImageInfo image;
  memset(&image, 0, sizeof(image));

  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;
  }

  if (originalWidth)
    *originalWidth = image.originalwidth;
  if (originalHeight)
    *originalHeight = image.originalheight;

  LoadFromImage(image, autoRotate);
  dll.ReleaseImage(&image);

  return true;
}
Beispiel #7
0
bool Texture::LoadFromStream(InputStream& stream, const IntRect& area)
{
    Image image;
    return image.LoadFromStream(stream) && LoadFromImage(image, area);
}
Beispiel #8
0
bool Texture::LoadFromMemory(const void* data, std::size_t size, const IntRect& area)
{
    Image image;
    return image.LoadFromMemory(data, size) && LoadFromImage(image, area);
}
Beispiel #9
0
bool Texture::LoadFromFile(const std::string& filename, const IntRect& area)
{
    Image image;
    return image.LoadFromFile(filename) && LoadFromImage(image, area);
}