Exemplo n.º 1
0
ezResult ezImageConversion::ConvertSingleStep(const ezImageConversionStep* pStep, const ezImageView& source, ezImage& target,
                                              ezImageFormat::Enum targetFormat)
{
  if (!pStep)
  {
    target.ResetAndCopy(source);
    return EZ_SUCCESS;
  }

  ezImageFormat::Enum sourceFormat = source.GetImageFormat();

  ezImageHeader header = source.GetHeader();
  header.SetImageFormat(targetFormat);
  target.ResetAndAlloc(header);

  if (!ezImageFormat::IsCompressed(sourceFormat))
  {
    if (!ezImageFormat::IsCompressed(targetFormat))
    {
      // we have to do the computation in 64-bit otherwise it might overflow for very large textures (8k x 4k or bigger).
      ezUInt64 numElements =
          ezUInt64(8) * (ezUInt64)target.GetArrayPtr<void>().GetCount() / (ezUInt64)ezImageFormat::GetBitsPerPixel(targetFormat);
      return static_cast<const ezImageConversionStepLinear*>(pStep)->ConvertPixels(source.GetArrayPtr<void>(), target.GetArrayPtr<void>(),
                                                                                   (ezUInt32)numElements, sourceFormat, targetFormat);
    }
    else
    {
      return ConvertSingleStepCompress(source, target, sourceFormat, targetFormat, pStep);
    }
  }
  else
  {
    return ConvertSingleStepDecompress(source, target, sourceFormat, targetFormat, pStep);
  }
}
Exemplo n.º 2
0
ezResult ezImageConversion::Convert(const ezImageView& source, ezImage& target, ezImageFormat::Enum targetFormat)
{
  ezImageFormat::Enum sourceFormat = source.GetImageFormat();

  // Trivial copy
  if (sourceFormat == targetFormat)
  {
    if (&source != &target)
    {
      // copy if not already the same
      target.ResetAndCopy(source);
    }
    return EZ_SUCCESS;
  }

  ezHybridArray<ConversionPathNode, 16> path;
  ezUInt32 numScratchBuffers = 0;
  if (BuildPath(sourceFormat, targetFormat, &source == &target, path, numScratchBuffers).Failed())
  {
    return EZ_FAILURE;
  }

  return Convert(source, target, path, numScratchBuffers);
}