Skip to content

Commit

Permalink
Incremental compression
Browse files Browse the repository at this point in the history
  • Loading branch information
Андрей Евстюхин committed May 11, 2020
1 parent 4a00ab5 commit 4db23df
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Andrew Evstyukhin
Copyright (c) 2019-2020 Andrew Evstyukhin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nebc7 - Nearly Exhaustive BC7 compressor

Nebc7 is an experimental solution published as is.
Nebc7 is an open-source software published as is.

Nebc7 converts specified RGBA image to BC7 format. It focuses on image quality and uses weighted PSNR metric with some assistance of SSIM.

Expand Down
30 changes: 16 additions & 14 deletions src/Bc7Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ static INLINED int ComputeOpaqueAlphaError(const Area& area) noexcept
return error;
}

static INLINED void MakeCell(Cell& input) noexcept
static INLINED void MakeCell(Cell& input, const Cell& decoded) noexcept
{
input.BestColor0 = _mm_setzero_si128();
input.BestColor1 = _mm_setzero_si128();
input.BestColor2 = _mm_setzero_si128();
//input.BestParameter = 0;
//input.BestMode = 8;
input.BestColor0 = decoded.BestColor0;
input.BestColor1 = decoded.BestColor1;
input.BestColor2 = decoded.BestColor2;
input.BestParameter = decoded.BestParameter;
input.BestMode = decoded.BestMode;

int flags = 0;
int flags_mask = 1;
Expand Down Expand Up @@ -862,6 +862,10 @@ void DecompressBlock(uint8_t input[16], Cell& output) noexcept
_mm_store_si128(&output.ImageRows_U8[2], mzero);
_mm_store_si128(&output.ImageRows_U8[3], mzero);

output.BestColor0 = mzero;
output.BestColor1 = mzero;
output.BestColor2 = mzero;
output.BestParameter = 0;
output.BestMode = 8;
}
}
Expand Down Expand Up @@ -895,8 +899,6 @@ static void CompressBlockFastOpaque(Cell& input) noexcept
if (*(const short*)&input.Area1.MinMax_U16 <= (255 - 16))
return;

input.OpaqueAlphaError = ComputeOpaqueAlphaError(input.Area1);

if (input.Error.Total > input.OpaqueAlphaError)
{
Mode1::CompressBlockFast(input);
Expand Down Expand Up @@ -933,18 +935,18 @@ void CompressBlock(uint8_t output[16], Cell& input) noexcept

Cell temp;
DecompressBlock(output, temp);
input.BestParameter = temp.BestParameter;
input.BestMode = temp.BestMode;

input.Error = CompareBlocks(input, temp);
if (input.Error.Total > 0)
{
MakeCell(input);
MakeCell(input, temp);

MakeAreaFromCell(input.Area1, input, 16, gTableSelection11);

if (gDoDraft)
{
input.OpaqueAlphaError = ComputeOpaqueAlphaError(input.Area1);

int water = input.Error.Total;

if (input.Area1.IsOpaque)
Expand All @@ -964,9 +966,6 @@ void CompressBlock(uint8_t output[16], Cell& input) noexcept

if (gDoFast)
{
input.PersonalParameter = input.BestParameter;
input.PersonalMode = input.BestMode;

switch (input.BestMode)
{
case 0:
Expand Down Expand Up @@ -1026,6 +1025,9 @@ void CompressBlock(uint8_t output[16], Cell& input) noexcept
break;
}

input.PersonalParameter = input.BestParameter;
input.PersonalMode = input.BestMode;

if (input.Area1.IsOpaque)
{
if (input.Error.Total > input.OpaqueAlphaError)
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ namespace Mode0 {
DecompressIndexedSubset<3>(mc1, gTableSelection23[partitionIndex], (int*)output.ImageRows_U8, data1);
DecompressIndexedSubset<3>(mc2, gTableSelection33[partitionIndex], (int*)output.ImageRows_U8, data1);

output.BestColor0 = mc0;
output.BestColor1 = mc1;
output.BestColor2 = mc2;
output.BestParameter = partitionIndex;
output.BestMode = 0;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ namespace Mode1 {
DecompressIndexedSubset<3>(mc0, gTableSelection12[partitionIndex], (int*)output.ImageRows_U8, data1);
DecompressIndexedSubset<3>(mc1, gTableSelection22[partitionIndex], (int*)output.ImageRows_U8, data1);

output.BestColor0 = mc0;
output.BestColor1 = mc1;
output.BestColor2 = _mm_setzero_si128();
output.BestParameter = partitionIndex;
output.BestMode = 1;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace Mode2 {
DecompressIndexedSubset<2>(mc1, gTableSelection23[partitionIndex], (int*)output.ImageRows_U8, data1);
DecompressIndexedSubset<2>(mc2, gTableSelection33[partitionIndex], (int*)output.ImageRows_U8, data1);

output.BestColor0 = mc0;
output.BestColor1 = mc1;
output.BestColor2 = mc2;
output.BestParameter = partitionIndex;
output.BestMode = 2;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ namespace Mode3 {
DecompressIndexedSubset<2>(mc0, gTableSelection12[partitionIndex], (int*)output.ImageRows_U8, data1);
DecompressIndexedSubset<2>(mc1, gTableSelection22[partitionIndex], (int*)output.ImageRows_U8, data1);

output.BestColor0 = mc0;
output.BestColor1 = mc1;
output.BestColor2 = _mm_setzero_si128();
output.BestParameter = partitionIndex;
output.BestMode = 3;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ namespace Mode4 {

DecompressSubset(mc0, (int*)output.ImageRows_U8, data2, data3, rotation);

output.BestColor0 = mc0;
output.BestColor1 = _mm_setzero_si128();
output.BestColor2 = _mm_setzero_si128();
output.BestParameter = rotation;
output.BestMode = 4;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ namespace Mode5 {

DecompressSubset(mc0, (int*)output.ImageRows_U8, data1, data1 >> 32, rotation);

output.BestColor0 = mc0;
output.BestColor1 = _mm_setzero_si128();
output.BestColor2 = _mm_setzero_si128();
output.BestParameter = rotation;
output.BestMode = 5;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ namespace Mode6 {

DecompressSubset(mc0, (int*)output.ImageRows_U8, data1);

output.BestColor0 = mc0;
output.BestColor1 = _mm_setzero_si128();
output.BestColor2 = _mm_setzero_si128();
output.BestParameter = 0;
output.BestMode = 6;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7CoreMode7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ namespace Mode7 {
DecompressIndexedSubset<2>(mc0, gTableSelection12[partitionIndex], (int*)output.ImageRows_U8, data1);
DecompressIndexedSubset<2>(mc1, gTableSelection22[partitionIndex], (int*)output.ImageRows_U8, data1);

output.BestColor0 = mc0;
output.BestColor1 = mc1;
output.BestColor2 = _mm_setzero_si128();
output.BestParameter = partitionIndex;
output.BestMode = 7;
}
Expand Down

0 comments on commit 4db23df

Please sign in to comment.