Skip to content

Commit

Permalink
Apply sRGB patches from google#49
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Faust committed Nov 18, 2020
1 parent 9cd0f9c commit e5d729b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
14 changes: 14 additions & 0 deletions EtcLib/Etc/Etc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ namespace Etc

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

// Get out of the loop if both shifted dimensions are zero
if ((mipWidth==0) && (mipHeight==0))
{
break;
}
// Make sure to generate mipmap chain down to 1x1 for iOS
if (mipWidth==0)
{
mipWidth = 1;
}
if (mipHeight==0) {
mipHeight = 1;
}
}

*a_piEncodingTime_ms = totalEncodingTime;
Expand Down
24 changes: 12 additions & 12 deletions EtcLib/EtcCodec/EtcBlock4x4Encoding_RGB8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ namespace Etc
int iMaxRed1 = iColor1Red + (int)a_uiRadius;
if (iMaxRed1 > 15)
{
iMinRed1 = 15;
iMaxRed1 = 15;
}

int iMinGreen1 = iColor1Green - (int)a_uiRadius;
Expand All @@ -519,7 +519,7 @@ namespace Etc
int iMaxGreen1 = iColor1Green + (int)a_uiRadius;
if (iMaxGreen1 > 15)
{
iMinGreen1 = 15;
iMaxGreen1 = 15;
}

int iMinBlue1 = iColor1Blue - (int)a_uiRadius;
Expand All @@ -530,7 +530,7 @@ namespace Etc
int iMaxBlue1 = iColor1Blue + (int)a_uiRadius;
if (iMaxBlue1 > 15)
{
iMinBlue1 = 15;
iMaxBlue1 = 15;
}

int iColor2Red = m_frgbaOriginalColor2_TAndH.IntRed(15.0f);
Expand All @@ -545,7 +545,7 @@ namespace Etc
int iMaxRed2 = iColor2Red + (int)a_uiRadius;
if (iMaxRed2 > 15)
{
iMinRed2 = 15;
iMaxRed2 = 15;
}

int iMinGreen2 = iColor2Green - (int)a_uiRadius;
Expand All @@ -556,7 +556,7 @@ namespace Etc
int iMaxGreen2 = iColor2Green + (int)a_uiRadius;
if (iMaxGreen2 > 15)
{
iMinGreen2 = 15;
iMaxGreen2 = 15;
}

int iMinBlue2 = iColor2Blue - (int)a_uiRadius;
Expand All @@ -567,7 +567,7 @@ namespace Etc
int iMaxBlue2 = iColor2Blue + (int)a_uiRadius;
if (iMaxBlue2 > 15)
{
iMinBlue2 = 15;
iMaxBlue2 = 15;
}

for (unsigned int uiDistance = 0; uiDistance < TH_DISTANCES; uiDistance++)
Expand Down Expand Up @@ -761,7 +761,7 @@ namespace Etc
int iMaxRed1 = iColor1Red + (int)a_uiRadius;
if (iMaxRed1 > 15)
{
iMinRed1 = 15;
iMaxRed1 = 15;
}

int iMinGreen1 = iColor1Green - (int)a_uiRadius;
Expand All @@ -772,7 +772,7 @@ namespace Etc
int iMaxGreen1 = iColor1Green + (int)a_uiRadius;
if (iMaxGreen1 > 15)
{
iMinGreen1 = 15;
iMaxGreen1 = 15;
}

int iMinBlue1 = iColor1Blue - (int)a_uiRadius;
Expand All @@ -783,7 +783,7 @@ namespace Etc
int iMaxBlue1 = iColor1Blue + (int)a_uiRadius;
if (iMaxBlue1 > 15)
{
iMinBlue1 = 15;
iMaxBlue1 = 15;
}

int iColor2Red = m_frgbaOriginalColor2_TAndH.IntRed(15.0f);
Expand All @@ -798,7 +798,7 @@ namespace Etc
int iMaxRed2 = iColor2Red + (int)a_uiRadius;
if (iMaxRed2 > 15)
{
iMinRed2 = 15;
iMaxRed2 = 15;
}

int iMinGreen2 = iColor2Green - (int)a_uiRadius;
Expand All @@ -809,7 +809,7 @@ namespace Etc
int iMaxGreen2 = iColor2Green + (int)a_uiRadius;
if (iMaxGreen2 > 15)
{
iMinGreen2 = 15;
iMaxGreen2 = 15;
}

int iMinBlue2 = iColor2Blue - (int)a_uiRadius;
Expand All @@ -820,7 +820,7 @@ namespace Etc
int iMaxBlue2 = iColor2Blue + (int)a_uiRadius;
if (iMaxBlue2 > 15)
{
iMinBlue2 = 15;
iMaxBlue2 = 15;
}

for (unsigned int uiDistance = 0; uiDistance < TH_DISTANCES; uiDistance++)
Expand Down
12 changes: 12 additions & 0 deletions EtcTool/EtcFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,26 @@ File::File(const char *a_pstrFilename, Format a_fileformat)
{
m_imageformat = Image::Format::RGB8;
}
else if (uiInternalFormat == (uint32_t)FileHeader_Ktx::InternalFormat::ETC2_SRGB8 && uiBaseInternalFormat == (uint32_t)FileHeader_Ktx::BaseInternalFormat::ETC2_RGB8)
{
m_imageformat = Image::Format::SRGB8;
}
else if (uiInternalFormat == (uint32_t)FileHeader_Ktx::InternalFormat::ETC2_RGB8A1 && uiBaseInternalFormat == (uint32_t)FileHeader_Ktx::BaseInternalFormat::ETC2_RGB8A1)
{
m_imageformat = Image::Format::RGB8A1;
}
else if (uiInternalFormat == (uint32_t)FileHeader_Ktx::InternalFormat::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1 && uiBaseInternalFormat == (uint32_t)FileHeader_Ktx::BaseInternalFormat::ETC2_RGB8A1)
{
m_imageformat = Image::Format::SRGB8A1;
}
else if (uiInternalFormat == (uint32_t)FileHeader_Ktx::InternalFormat::ETC2_RGBA8 && uiBaseInternalFormat == (uint32_t)FileHeader_Ktx::BaseInternalFormat::ETC2_RGBA8)
{
m_imageformat = Image::Format::RGBA8;
}
else if (uiInternalFormat == (uint32_t)FileHeader_Ktx::InternalFormat::ETC2_SRGBA8 && uiBaseInternalFormat == (uint32_t)FileHeader_Ktx::BaseInternalFormat::ETC2_RGBA8)
{
m_imageformat = Image::Format::SRGBA8;
}
else if (uiInternalFormat == (uint32_t)FileHeader_Ktx::InternalFormat::ETC2_R11 && uiBaseInternalFormat == (uint32_t)FileHeader_Ktx::BaseInternalFormat::ETC2_R11)
{
m_imageformat = Image::Format::R11;
Expand Down
18 changes: 15 additions & 3 deletions EtcTool/EtcFileHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,32 @@ namespace Etc
switch (m_pfile->GetImageFormat())
{
case Image::Format::RGB8:
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_RGB8;
m_data.m_u32GlBaseInternalFormat = (unsigned int)BaseInternalFormat::ETC2_RGB8;
break;

case Image::Format::SRGB8:
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_RGB8;
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_SRGB8;
m_data.m_u32GlBaseInternalFormat = (unsigned int)BaseInternalFormat::ETC2_RGB8;
break;

case Image::Format::RGBA8:
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_RGBA8;
m_data.m_u32GlBaseInternalFormat = (unsigned int)BaseInternalFormat::ETC2_RGBA8;
break;

case Image::Format::SRGBA8:
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_RGBA8;
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_SRGBA8;
m_data.m_u32GlBaseInternalFormat = (unsigned int)BaseInternalFormat::ETC2_RGBA8;
break;

case Image::Format::RGB8A1:
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_RGB8A1;
m_data.m_u32GlBaseInternalFormat = (unsigned int)BaseInternalFormat::ETC2_RGB8A1;
break;

case Image::Format::SRGB8A1:
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_RGB8A1;
m_data.m_u32GlInternalFormat = (unsigned int)InternalFormat::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
m_data.m_u32GlBaseInternalFormat = (unsigned int)BaseInternalFormat::ETC2_RGB8A1;
break;

Expand Down
3 changes: 2 additions & 1 deletion EtcTool/EtcFileHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ namespace Etc
ETC2_SRGB8 = 0x9275,
ETC2_RGB8A1 = 0x9276,
ETC2_SRGB8_PUNCHTHROUGH_ALPHA1 = 0x9277,
ETC2_RGBA8 = 0x9278
ETC2_RGBA8 = 0x9278,
ETC2_SRGBA8 = 0x9279
};

enum class BaseInternalFormat
Expand Down
6 changes: 3 additions & 3 deletions EtcTool/EtcTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Commands
{
public:

static const unsigned int MIN_JOBS = 8;
static const unsigned int MIN_JOBS = 1;

Commands(void)
{
Expand Down Expand Up @@ -162,7 +162,7 @@ int main(int argc, const char * argv[])

// Calculate the maximum number of possible mipmaps
{
int dim = (uiSourceWidth < uiSourceHeight)?uiSourceWidth:uiSourceHeight;
int dim = (uiSourceWidth > uiSourceHeight)?uiSourceWidth:uiSourceHeight;
int maxMips = 0;
while(dim >= 1)
{
Expand Down Expand Up @@ -796,7 +796,7 @@ void Commands::PrintUsageMessage(void)
printf(" -errormetric <error_metric> specify the error metric, the options are\n");
printf(" rgba, rgbx, rec709, numeric and normalxyz\n");
printf(" -format <etc_format> ETC1, RGB8, SRGB8, RGBA8, SRGB8, RGB8A1,\n");
printf(" SRGB8A1 or R11\n");
printf(" SRGB8A1 or (SIGNED_)R11, (SIGNED_)RG11\n");
printf(" -help prints this message\n");
printf(" -jobs or -j <thread_count> specifies the number of threads (default=1)\n");
printf(" -normalizexyz normalize RGB to have a length of 1\n");
Expand Down

0 comments on commit e5d729b

Please sign in to comment.