Skip to content

Commit

Permalink
Added BSI improvements, including RGBX format and mipmap support
Browse files Browse the repository at this point in the history
  • Loading branch information
kablammyman committed Feb 27, 2017
1 parent 7e65aff commit 45dd3d0
Show file tree
Hide file tree
Showing 14 changed files with 1,051 additions and 64 deletions.
70 changes: 70 additions & 0 deletions EtcLib/Etc/Etc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "EtcConfig.h"
#include "Etc.h"
#include "EtcFilter.h"

#include <string.h>

Expand Down Expand Up @@ -52,6 +53,75 @@ namespace Etc
*a_piEncodingTime_ms = image.GetEncodingTimeMs();
}

void EncodeMipmaps(float *a_pafSourceRGBA,
unsigned int a_uiSourceWidth,
unsigned int a_uiSourceHeight,
Image::Format a_format,
ErrorMetric a_eErrMetric,
float a_fEffort,
unsigned int a_uiJobs,
unsigned int a_uiMaxJobs,
unsigned int a_uiMaxMipmaps,
unsigned int a_uiMipFilterFlags,
RawImage* a_pMipmapImages,
int *a_piEncodingTime_ms,
bool a_bVerboseOutput)
{
auto mipWidth = a_uiSourceWidth;
auto mipHeight = a_uiSourceHeight;
int totalEncodingTime = 0;
for(unsigned int mip = 0; mip < a_uiMaxMipmaps && mipWidth >= 1 && mipHeight >= 1; mip++)
{
float* pImageData = nullptr;
float* pMipImage = nullptr;

if(mip == 0)
{
pImageData = a_pafSourceRGBA;
}
else
{
pMipImage = new float[mipWidth*mipHeight*4];
if(FilterTwoPass(a_pafSourceRGBA, a_uiSourceWidth, a_uiSourceHeight, pMipImage, mipWidth, mipHeight, a_uiMipFilterFlags, Etc::FilterLanczos3) )
{
pImageData = pMipImage;
}
}

if ( pImageData )
{

Image image(pImageData, mipWidth, mipHeight, a_eErrMetric);

image.m_bVerboseOutput = a_bVerboseOutput;
image.Encode(a_format, a_eErrMetric, a_fEffort, a_uiJobs, a_uiMaxJobs);

a_pMipmapImages[mip].paucEncodingBits = std::shared_ptr<unsigned char>(image.GetEncodingBits(), [](unsigned char *p) { delete[] p; });
a_pMipmapImages[mip].uiEncodingBitsBytes = image.GetEncodingBitsBytes();
a_pMipmapImages[mip].uiExtendedWidth = image.GetExtendedWidth();
a_pMipmapImages[mip].uiExtendedHeight = image.GetExtendedHeight();

totalEncodingTime += image.GetEncodingTimeMs();
}

if(pMipImage)
{
delete[] pMipImage;
}

if (!pImageData)
{
break;
}

mipWidth >>= 1;
mipHeight >>= 1;
}

*a_piEncodingTime_ms = totalEncodingTime;
}


// ----------------------------------------------------------------------------------------------------
//

Expand Down
24 changes: 24 additions & 0 deletions EtcLib/Etc/Etc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "EtcImage.h"
#include "EtcColor.h"
#include "EtcErrorMetric.h"
#include <memory>

#define ETCCOMP_MIN_EFFORT_LEVEL (0.0f)
#define ETCCOMP_DEFAULT_EFFORT_LEVEL (40.0f)
Expand All @@ -29,6 +30,16 @@ namespace Etc
{
class Block4x4EncodingBits;

struct RawImage
{
int uiExtendedWidth;
int uiExtendedHeight;
unsigned int uiEncodingBitsBytes;
std::shared_ptr<unsigned char> paucEncodingBits;
};



// C-style inteface to the encoder
void Encode(float *a_pafSourceRGBA,
unsigned int a_uiSourceWidth,
Expand All @@ -44,4 +55,17 @@ namespace Etc
unsigned int *a_puiExtendedHeight,
int *a_piEncodingTime_ms, bool a_bVerboseOutput = false);

void EncodeMipmaps(float *a_pafSourceRGBA,
unsigned int a_uiSourceWidth,
unsigned int a_uiSourceHeight,
Image::Format a_format,
ErrorMetric a_eErrMetric,
float a_fEffort,
unsigned int a_uiJobs,
unsigned int a_uiMaxJobs,
unsigned int a_uiMaxMipmaps,
unsigned int a_uiMipFilterFlags,
RawImage* a_pMipmaps,
int *a_piEncodingTime_ms, bool a_bVerboseOutput = false);

}
Loading

0 comments on commit 45dd3d0

Please sign in to comment.