From 8f4833019168e9a40c8260b9491a784d9b4b25ac Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Thu, 18 Feb 2021 16:21:59 -0800 Subject: [PATCH] Some debugging for single tables --- .gitmodules | 3 +++ CMakeLists.txt | 2 ++ extern/gif-h | 1 + src/BC1/BC1Encoder.cpp | 21 +++++++++++++++-- src/BC1/SelectorHistogram.h | 45 +++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 160000 extern/gif-h create mode 100644 src/BC1/SelectorHistogram.h diff --git a/.gitmodules b/.gitmodules index aecfec5..38fd3a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = extern/pybind11 url = https://github.com/pybind/pybind11.git branch = stable +[submodule "extern/gif-h"] + path = extern/gif-h + url = https://github.com/charlietangora/gif-h.git diff --git a/CMakeLists.txt b/CMakeLists.txt index d518b56..af7a160 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ file(GLOB TEST_FILES "src/test/*.c" "src/test/*.cpp" "src/test/*.h") # Organize source files together for some IDEs source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES} ${HEADER_FILES} ${PYTHON_FILES}) +include_directories(${CMAKE_SOURCE_DIR}/extern/gif-h) + # Add python module pybind11_add_module(python_rgbcx ${SOURCE_FILES} diff --git a/extern/gif-h b/extern/gif-h new file mode 160000 index 0000000..3d2657b --- /dev/null +++ b/extern/gif-h @@ -0,0 +1 @@ +Subproject commit 3d2657b9ad40aac9fd6f75ad079335856e94d664 diff --git a/src/BC1/BC1Encoder.cpp b/src/BC1/BC1Encoder.cpp index 06a1021..3c4ee9a 100644 --- a/src/BC1/BC1Encoder.cpp +++ b/src/BC1/BC1Encoder.cpp @@ -19,6 +19,9 @@ #include "BC1Encoder.h" +#include +#include + #include #include @@ -47,13 +50,19 @@ inline void PrepSingleColorTableEntry(unsigned &error, MatchList &match_table, u match_table[i].high = (uint8_t)high; match_table[i].error = (uint8_t)new_error; - error = new_error; +// error = new_error; } + error = new_error; } template void PrepSingleColorTable(MatchList &match_table, MatchList &match_table_half, Interpolator &interpolator) { unsigned size = 1 << S; + std::vector frame(size * size * 4, 0); + auto fileName = "lut" + std::to_string(S) + ".gif"; + GifWriter g; + GifBegin(&g, fileName.c_str(), size, size, 10); + assert((S == 5 && size == 32) || (S == 6 && size == 64)); bool ideal = interpolator.IsIdeal(); @@ -69,7 +78,7 @@ template void PrepSingleColorTable(MatchList &match_table, MatchList uint8_t low8 = (S == 5) ? scale5To8(low) : scale6To8(low); for (uint8_t high = 0; high < size; high++) { - uint8_t high8 = (S == 5) ? scale5To8(high) : scale6To8(low); + uint8_t high8 = (S == 5) ? scale5To8(high) : scale6To8(high); uint8_t value, value_half; if (use_8bit) { @@ -82,9 +91,17 @@ template void PrepSingleColorTable(MatchList &match_table, MatchList PrepSingleColorTableEntry(error, match_table, value, i, low, high, low8, high8, ideal); PrepSingleColorTableEntry(error_half, match_table_half, value_half, i, low, high, low8, high8, ideal); + frame[(low + (size * high))*4] = error; + frame[(low + (size * high))*4+1] = error; + frame[(low + (size * high))*4+2] = error; + frame[(low + (size * high))*4+3] = 255; + } } + GifWriteFrame(&g, frame.data(), size, size, 10); } + + GifEnd(&g); } // endregion diff --git a/src/BC1/SelectorHistogram.h b/src/BC1/SelectorHistogram.h new file mode 100644 index 0000000..34976cb --- /dev/null +++ b/src/BC1/SelectorHistogram.h @@ -0,0 +1,45 @@ +/* Python-rgbcx Texture Compression Library + Copyright (C) 2021 Andrew Cassidy + Partially derived from rgbcx.h written by Richard Geldreich + and licenced under the public domain + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + */ + +#pragma once + +#include + +namespace rgbcx { +// +//class SelectorHistogram { +// public: +// std::array histogram; +// +// bool operator==(const SelectorHistogram &other) const { +// for (unsigned i = 0; i < Size; i++) { +// if (histogram[i] != other.histogram[i]) return false; +// } +// return true; +// } +// +// bool AnyMax() cost { +// for (unsigned i = 0; i < Size; i++) { +// if (histogram[i] == Max) return true; +// } +// return false; +// } +//}; + +} // namespace rgbcx \ No newline at end of file