示例#1
0
  static ezResult DecompressZStd(ezArrayPtr<const ezUInt8> pCompressedData, ezDynamicArray<ezUInt8>& out_Data)
  {
    size_t uiSize = ZSTD_findDecompressedSize(pCompressedData.GetPtr(), pCompressedData.GetCount());

    if (uiSize == ZSTD_CONTENTSIZE_ERROR)
    {
      ezLog::Error("Can't decompress since it wasn't compressed with ZStd");
      return EZ_FAILURE;
    }
    else if (uiSize == ZSTD_CONTENTSIZE_UNKNOWN)
    {
      ezLog::Error("Can't decompress since the original size can't be determined, was the data compressed using the streaming variant?");
      return EZ_FAILURE;
    }

    if (uiSize > std::numeric_limits<ezUInt32>::max())
    {
      ezLog::Error("Can't compress since the output container can't hold enough elements ({0})", static_cast<ezUInt64>(uiSize));
      return EZ_FAILURE;
    }

    out_Data.SetCountUninitialized(static_cast<ezUInt32>(uiSize));

    size_t const uiActualSize = ZSTD_decompress(out_Data.GetData(), uiSize, pCompressedData.GetPtr(), pCompressedData.GetCount());

    if (uiActualSize != uiSize)
    {
      ezLog::Error("Error during ZStd decompression: '{0}'.", ZSTD_getErrorName(uiActualSize));
      return EZ_FAILURE;
    }

    return EZ_SUCCESS;
  }
示例#2
0
ezResult ezImageConversion::ConvertRaw(ezArrayPtr<const void> source, ezArrayPtr<void> target, ezUInt32 numElements,
                                       ezArrayPtr<ConversionPathNode> path, ezUInt32 numScratchBuffers)
{
  EZ_ASSERT_DEV(path.GetCount() > 0, "Path of length 0 is invalid.");

  if (numElements == 0)
  {
    return EZ_SUCCESS;
  }

  if (ezImageFormat::IsCompressed(path.GetPtr()->m_sourceFormat) || ezImageFormat::IsCompressed((path.GetEndPtr() - 1)->m_targetFormat))
  {
    return EZ_FAILURE;
  }

  ezHybridArray<ezDynamicArray<char>, 16> intermediates;
  intermediates.SetCount(numScratchBuffers);

  for (ezUInt32 i = 0; i < path.GetCount(); ++i)
  {
    ezUInt32 targetIndex = path[i].m_targetBufferIndex;
    ezUInt32 targetBpp = ezImageFormat::GetBitsPerPixel(path[i].m_targetFormat);

    ezArrayPtr<void> stepTarget;
    if (targetIndex == 0)
    {
      stepTarget = target;
    }
    else
    {
      ezUInt32 expectedSize = static_cast<ezUInt32>(targetBpp * numElements / 8);
      intermediates[targetIndex - 1].SetCount(expectedSize);
      stepTarget = ezArrayPtr<void>(intermediates[targetIndex - 1].GetData(), intermediates[targetIndex - 1].GetCount());
    }

    if (path[i].m_step == nullptr)
    {
      memcpy(stepTarget.GetPtr(), source.GetPtr(), numElements * targetBpp / 8);
    }
    else
    {
      if (static_cast<const ezImageConversionStepLinear*>(path[i].m_step)
              ->ConvertPixels(source, stepTarget, numElements, path[i].m_sourceFormat, path[i].m_targetFormat)
              .Failed())
      {
        return EZ_FAILURE;
      }
    }

    source = stepTarget;
  }

  return EZ_SUCCESS;
}
示例#3
0
ezResult ezImageConversion::ConvertRaw(ezArrayPtr<const void> source, ezArrayPtr<void> target, ezUInt32 numElements,
                                       ezImageFormat::Enum sourceFormat, ezImageFormat::Enum targetFormat)
{
  if (numElements == 0)
  {
    return EZ_SUCCESS;
  }

  // Trivial copy
  if (sourceFormat == targetFormat)
  {
    if (target.GetPtr() != source.GetPtr())
      memcpy(target.GetPtr(), source.GetPtr(), numElements * ezUInt64(ezImageFormat::GetBitsPerPixel(sourceFormat)) / 8);
    return EZ_SUCCESS;
  }

  if (ezImageFormat::IsCompressed(sourceFormat) || ezImageFormat::IsCompressed(targetFormat))
  {
    return EZ_FAILURE;
  }

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

  return ConvertRaw(source, target, numElements, path, numScratchBuffers);
}
示例#4
0
  static ezResult CompressZStd(ezArrayPtr<const ezUInt8> pUncompressedData, ezDynamicArray<ezUInt8>& out_Data)
  {
    size_t uiSizeBound = ZSTD_compressBound(pUncompressedData.GetCount());
    if(uiSizeBound > std::numeric_limits<ezUInt32>::max())
    {
      ezLog::Error("Can't compress since the output container can't hold enough elements ({0})", static_cast<ezUInt64>(uiSizeBound));
      return EZ_FAILURE;
    }

    out_Data.SetCountUninitialized(static_cast<ezUInt32>(uiSizeBound));

    size_t const cSize = ZSTD_compress(out_Data.GetData(), uiSizeBound, pUncompressedData.GetPtr(), pUncompressedData.GetCount(), 1);
    if (ZSTD_isError(cSize))
    {
      ezLog::Error("Compression failed with error: '{0}'.", ZSTD_getErrorName(cSize));
      return EZ_FAILURE;
    }

    out_Data.SetCount(static_cast<ezUInt32>(cSize));

    return EZ_SUCCESS;
  }
示例#5
0
#include <PCH.h>
#include <Foundation/Containers/DynamicArray.h>

EZ_CREATE_SIMPLE_TEST(Basics, ArrayPtr)
{
  EZ_TEST_BLOCK(ezTestBlock::Enabled, "Empty Constructor")
  {
    ezArrayPtr<ezInt32> Empty;

    EZ_TEST_BOOL(Empty.GetPtr() == nullptr);
    EZ_TEST_BOOL(Empty.GetCount() == 0);
  }

  EZ_TEST_BLOCK(ezTestBlock::Enabled, "Constructor")
  {
    ezInt32 pIntData[] = { 1, 2, 3, 4, 5 };

    ezArrayPtr<ezInt32> ap(pIntData, 3);
    EZ_TEST_BOOL(ap.GetPtr() == pIntData);
    EZ_TEST_BOOL(ap.GetCount() == 3);

    ezArrayPtr<ezInt32> ap2(pIntData, 0);
    EZ_TEST_BOOL(ap2.GetPtr() == nullptr);
    EZ_TEST_BOOL(ap2.GetCount() == 0);

    ezArrayPtr<ezInt32> ap3(pIntData);
    EZ_TEST_BOOL(ap3.GetPtr() == pIntData);
    EZ_TEST_BOOL(ap3.GetCount() == 5);

    ezArrayPtr<ezInt32> ap4(ap);
    EZ_TEST_BOOL(ap4.GetPtr() == pIntData);