|
From: kosmirror <kos...@us...> - 2025-08-25 14:02:28
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "A pseudo Operating System for the Dreamcast.".
The branch, master has been updated
via 959ce90028b86a0595c1392bf5e549d955bc1071 (commit)
from efd7da8be7fa2808899d3bcaa86cd29c3b56262f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 959ce90028b86a0595c1392bf5e549d955bc1071
Author: dfchil <dan...@gm...>
Date: Mon Aug 25 16:02:08 2025 +0200
updated pvrtex tool to version 2, per the latest release from TapamN (#1145)
Co-authored-by: drxl <da...@vm...>
https://dcemulation.org/phpBB/viewtopic.php?p=1061943#p1061943
-----------------------------------------------------------------------
Summary of changes:
utils/pvrtex/CHANGELOG | 27 +-
utils/pvrtex/Makefile | 40 +-
.../texture.dt | Bin 43744 -> 43744 bytes
utils/pvrtex/avstring.c | 1 +
addons/lib/.keepme => utils/pvrtex/config.h | 0
utils/pvrtex/crc.c | 2 +
utils/pvrtex/dither.cpp | 85 +-
utils/pvrtex/elbg.c | 9 +-
utils/pvrtex/file_common.c | 34 +-
utils/pvrtex/file_common.h | 2 +
utils/pvrtex/file_dctex.c | 74 +-
utils/pvrtex/file_dctex.h | 160 +-
utils/pvrtex/file_pvr.c | 198 +-
utils/pvrtex/file_pvr.h | 3 +
utils/pvrtex/file_tex.c | 32 +-
utils/pvrtex/libavutil/internal.h | 1 +
utils/pvrtex/libavutil/thread.h | 2 +
utils/pvrtex/log.c | 2 +
utils/pvrtex/main.c | 175 +-
utils/pvrtex/mem.c | 4 +-
utils/pvrtex/nvmath.h | 374 +++-
utils/pvrtex/palette.c | 85 +
utils/pvrtex/pixel.h | 79 +-
utils/pvrtex/pvr_texture.c | 123 +-
utils/pvrtex/pvr_texture.h | 24 +-
utils/pvrtex/pvr_texture_decoder.c | 166 ++
utils/pvrtex/pvr_texture_decoder.h | 45 +
utils/pvrtex/pvr_texture_encoder.c | 529 +++---
utils/pvrtex/pvr_texture_encoder.h | 111 +-
utils/pvrtex/pvrtex-completion.bash | 64 +
utils/pvrtex/readme_unformatted.txt | 147 +-
utils/pvrtex/stb_ds.h | 1895 ++++++++++++++++++++
utils/pvrtex/tddither.c | 66 +-
utils/pvrtex/tddither.h | 5 +-
utils/pvrtex/vqcompress.c | 65 +-
utils/pvrtex/vqcompress.h | 6 +-
36 files changed, 3851 insertions(+), 784 deletions(-)
copy addons/lib/.keepme => utils/pvrtex/config.h (100%)
create mode 100644 utils/pvrtex/palette.c
create mode 100644 utils/pvrtex/pvr_texture_decoder.c
create mode 100644 utils/pvrtex/pvr_texture_decoder.h
create mode 100755 utils/pvrtex/pvrtex-completion.bash
create mode 100644 utils/pvrtex/stb_ds.h
diff --git a/utils/pvrtex/CHANGELOG b/utils/pvrtex/CHANGELOG
index 7c51f43c..ed5e2d17 100644
--- a/utils/pvrtex/CHANGELOG
+++ b/utils/pvrtex/CHANGELOG
@@ -1,16 +1,35 @@
Based on code by TapamN
Source released here: https://dcemulation.org/phpBB/viewtopic.php?t=106138
- Version 1.0
- Initial release
+ Version 2.00
+ Mipmaps can now be generationed optionally only if
+ texture is already square, using "--mip-resize opt".
+
+ .PVR and .DT files can be used as input files.
+
+ Custom palettes can be specified with --palette option.
+
+ Option to generate texconv style normal maps.
+
+ Added flip-v option.
+
+ Texture size is printed when --verbose is enabled.
+
+ Speed optimizations.
Version 1.01
- Program now displays error message when an error occurs loading a source image. Previously, the program would hit an assertion.
+ Program now displays error message when an error occurs
+ loading a source image. Previously, the program would
+ hit an assertion.
- Fixed "--resize down" option. Previously, the program would round down sizes that were already a power-of-two, now sizes that are already POT are left unchanged.
+ Fixed "--resize down" option. Previously, the program
+ would round down sizes that were already a power-of-two,
+ now sizes that are already POT are left unchanged.
Included a missing FFmpeg header file.
+ Version 1.0
+ Initial release
---------------------------
Adaption into KOS by Daniel Fairchild, 2024
diff --git a/utils/pvrtex/Makefile b/utils/pvrtex/Makefile
index 87586755..b6bd20bc 100644
--- a/utils/pvrtex/Makefile
+++ b/utils/pvrtex/Makefile
@@ -4,19 +4,18 @@
TARGET = pvrtex
OBJS = elbg.o mem.o log.o bprint.o avstring.o lfg.o crc.o md5.o stb_image_impl.o \
stb_image_write_impl.o stb_image_resize_impl.o optparse_impl.o pvr_texture.o \
- dither.o tddither.o vqcompress.o mycommon.o file_common.o \
- file_pvr.o file_tex.o file_dctex.o pvr_texture_encoder.o main.o
+ dither.o tddither.o vqcompress.o mycommon.o palette.o file_common.o \
+ file_pvr.o file_tex.o file_dctex.o pvr_texture_encoder.o pvr_texture_decoder.o main.o
-CPPFLAGS = -Ilibavutil -I. -DCONFIG_MEMORY_POISONING=0 -DHAVE_FAST_UNALIGNED=0
-CXXFLAGS = -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare
-
-ifdef $(DEBUGBUILD)
- CXXFLAGS += -Og -pg -g
+ifeq ($(DEBUGBUILD), true)
+OPTMODE= -Og -pg -g
else
- CXXFLAGS += -O3
+OPTMODE= -O3 -flto=auto -march=native
endif
-CFLAGS := $(CXXFLAGS) -Wno-pointer-sign -std=gnu17
+MYFLAGS=-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Ilibavutil -I. -DCONFIG_MEMORY_POISONING=0 -DHAVE_FAST_UNALIGNED=0
+MYCPPFLAGS=$(MYFLAGS)
+MYCFLAGS=$(MYFLAGS) -Wno-pointer-sign
define textSegment2Header
mkdir -p info
@@ -25,15 +24,22 @@ define textSegment2Header
rm $2/$3.txt
endef
-.PHONY: all clean
-
all: $(TARGET) README
-$(TARGET): $(OBJS)
- $(CXX) $(CXXFLAGS) -o $@ $^
+.PHONY: all clean install
main.o: main.c info/options.h info/examples.h
+%.o: %.c
+ gcc $(CFLAGS) $(MYCFLAGS) $(OPTMODE) -c $< -o $@
+
+%.o: %.cpp
+ gcc $(CFLAGS) $(MYCPPFLAGS) $(CXXFLAGS) $(OPTMODE) -c $< -o $@
+
+$(TARGET): $(OBJS)
+ gcc $(OPTMODE) -o $(TARGET) \
+ $(OBJS) $(PROGMAIN) -lm -lstdc++
+
clean:
rm -f $(TARGET) $(OBJS) README
@@ -43,8 +49,16 @@ README: readme_unformatted.txt
install: all
install -m 755 $(TARGET) $(DC_TOOLS_BASE)/
+
info/options.h: README Makefile
$(call textSegment2Header,Command Line Options:,info,options)
info/examples.h: README Makefile
$(call textSegment2Header,Usage Examples:,info,examples)
+
+bash-completion-dir:
+ mkdir -p ~/.local/share/bash-completion/completions
+
+
+install-bash-completion: bash-completion-dir
+ install pvrtex-completion.bash ~/.local/share/bash-completion/completions/pvrtex.bash
diff --git a/utils/pvrtex/approvaltest/tests/approved/-i_crate_png_-o_tests_run_texture_dt_-f_normal_-m/texture.dt b/utils/pvrtex/approvaltest/tests/approved/-i_crate_png_-o_tests_run_texture_dt_-f_normal_-m/texture.dt
index 93df029c..6eaba52d 100644
Binary files a/utils/pvrtex/approvaltest/tests/approved/-i_crate_png_-o_tests_run_texture_dt_-f_normal_-m/texture.dt and b/utils/pvrtex/approvaltest/tests/approved/-i_crate_png_-o_tests_run_texture_dt_-f_normal_-m/texture.dt differ
diff --git a/utils/pvrtex/avstring.c b/utils/pvrtex/avstring.c
index 99f06690..e460b5be 100644
--- a/utils/pvrtex/avstring.c
+++ b/utils/pvrtex/avstring.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
+#include "config.h"
#include "mem.h"
#include "avassert.h"
#include "avstring.h"
diff --git a/addons/lib/.keepme b/utils/pvrtex/config.h
similarity index 100%
copy from addons/lib/.keepme
copy to utils/pvrtex/config.h
diff --git a/utils/pvrtex/crc.c b/utils/pvrtex/crc.c
index 4ce8f96d..703b56f4 100644
--- a/utils/pvrtex/crc.c
+++ b/utils/pvrtex/crc.c
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "config.h"
+
#include "thread.h"
#include "avassert.h"
#include "bswap.h"
diff --git a/utils/pvrtex/dither.cpp b/utils/pvrtex/dither.cpp
index b195bd11..054762fa 100644
--- a/utils/pvrtex/dither.cpp
+++ b/utils/pvrtex/dither.cpp
@@ -22,20 +22,20 @@ class KDTree {
public:
struct KDPoint {
double coord[K];
-
+
KDPoint() { }
-
+
KDPoint(double a,double b,double c) {
coord[0] = a;
coord[1] = b;
coord[2] = c;
}
-
+
KDPoint(double v[K]) {
for(unsigned n=0; n<K; ++n)
coord[n] = v[n];
}
-
+
bool operator==(const KDPoint& b) const {
for(unsigned n=0; n<K; ++n)
if(coord[n] != b.coord[n]) return false;
@@ -53,7 +53,7 @@ public:
private:
struct KDRect {
KDPoint min, max;
-
+
KDPoint bound(const KDPoint& t) const {
KDPoint p;
for(unsigned i=0; i<K; ++i)
@@ -72,7 +72,7 @@ private:
}
}
};
-
+
struct KDNode {
KDPoint k;
V v;
@@ -80,12 +80,12 @@ private:
public:
KDNode() : k(),v(),left(0),right(0) { }
KDNode(const KDPoint& kk, const V& vv) : k(kk), v(vv), left(0), right(0) { }
-
+
virtual ~KDNode() {
delete (left);
delete (right);
}
-
+
static KDNode* ins( const KDPoint& key, const V& val,
KDNode*& t, int lev) {
if(!t)
@@ -110,14 +110,14 @@ private:
Nearest& nearest) {
// 1. if kd is empty then set dist-sqd to infinity and exit.
if (!kd) return;
-
+
// 2. s := split field of kd
int s = lev % K;
-
+
// 3. pivot := dom-elt field of kd
const KDPoint& pivot = kd->k;
double pivot_to_target = pivot.sqrdist(target);
-
+
// 4. Cut hr into to sub-hyperrectangles left-hr and right-hr.
// The cut plane is through pivot and perpendicular to the s
// dimension.
@@ -125,15 +125,15 @@ private:
KDRect right_hr = hr;
left_hr.max.coord[s] = pivot.coord[s];
right_hr.min.coord[s] = pivot.coord[s];
-
+
// 5. target-in-left := target_s <= pivot_s
bool target_in_left = target.coord[s] < pivot.coord[s];
-
+
const KDNode* nearer_kd;
const KDNode* further_kd;
KDRect nearer_hr;
KDRect further_hr;
-
+
// 6. if target-in-left then nearer is left, further is right
if (target_in_left) {
nearer_kd = kd->left;
@@ -148,12 +148,12 @@ private:
further_kd = kd->left;
further_hr = left_hr;
}
-
+
// 8. Recursively call Nearest Neighbor with parameters
// (nearer-kd, target, nearer-hr, max-dist-sqd), storing the
// results in nearest and dist-sqd
nnbr(nearer_kd, target, nearer_hr, lev + 1, nearest);
-
+
// 10. A nearer point could only lie in further-kd if there were some
// part of further-hr within distance sqrt(max-dist-sqd) of
// target. If this is the case then
@@ -166,7 +166,7 @@ private:
// 10.1.2 dist-sqd = (pivot-target)^2
nearest.dist_sqd = pivot_to_target;
}
-
+
// 10.2 Recursively call Nearest Neighbor with parameters
// (further-kd, target, further-hr, max-dist_sqd)
nnbr(further_kd, target, further_hr, lev + 1, nearest);
@@ -192,15 +192,15 @@ public:
virtual ~KDTree() {
delete (m_root);
}
-
+
bool insert(const KDPoint& key, const V& val) {
return KDNode::ins(key, val, m_root, 0);
}
-
+
const std::pair<V,double> nearest(const KDPoint& key) const {
KDRect hr;
hr.MakeInfinite();
-
+
typename KDNode::Nearest nn;
nn.kd = 0;
nn.dist_sqd = 1e99;
@@ -226,6 +226,17 @@ public:
#define COMPARE_RGB 1
+/* 8x8 threshold map */
+static const unsigned char map[8*8] = {
+ 0,48,12,60, 3,51,15,63,
+ 32,16,44,28,35,19,47,31,
+ 8,56, 4,52,11,59, 7,55,
+ 40,24,36,20,43,27,39,23,
+ 2,50,14,62, 1,49,13,61,
+ 34,18,46,30,33,17,45,29,
+ 10,58, 6,54, 9,57, 5,53,
+ 42,26,38,22,41,25,37,21
+};
static const double Gamma = 2.2; // Gamma correction we use.
@@ -244,7 +255,7 @@ static const double illum[3*3] = {
};
struct LabItem { // CIE L*a*b* color value with C and h added.
double L,a,b,C,h;
-
+
LabItem() { }
LabItem(double R,double G,double B) {
Set(R,G,B);
@@ -291,7 +302,7 @@ double ColorCompare(const LabItem& lab1, const LabItem& lab2) {
double a2 = (1.0 + G) * lab2.a;
C1 = sqrt(a1 * a1 + lab1.b * lab1.b);
C2 = sqrt(a2 * a2 + lab2.b * lab2.b);
-
+
if (C1 < 1e-9)
h1 = 0.0;
else {
@@ -299,7 +310,7 @@ double ColorCompare(const LabItem& lab1, const LabItem& lab2) {
if (h1 < 0.0)
h1 += 360.0;
}
-
+
if (C2 < 1e-9)
h2 = 0.0;
else {
@@ -308,7 +319,7 @@ double ColorCompare(const LabItem& lab1, const LabItem& lab2) {
h2 += 360.0;
}
}
-
+
/* Compute delta L, C and H */
double dL = lab2.L - lab1.L, dC = C2 - C1, dH;
{
@@ -320,10 +331,10 @@ double ColorCompare(const LabItem& lab1, const LabItem& lab2) {
/**/ if (dh > 180.0) dh -= 360.0;
else if (dh < -180.0) dh += 360.0;
}
-
+
dH = 2.0 * sqrt(C1 * C2) * sin(DEG2RAD(0.5 * dh));
}
-
+
double h;
double L = 0.5 * (lab1.L + lab2.L);
double C = 0.5 * (C1 + C2);
@@ -369,6 +380,10 @@ double ColorCompare(int r1,int g1,int b1, int r2,int g2,int b2) {
/* Palette */
static const unsigned palettesize = 16;
+static const unsigned pal[palettesize] = {
+ 0x080000,0x201A0B,0x432817,0x492910, 0x234309,0x5D4F1E,0x9C6B20,0xA9220F,
+ 0x2B347C,0x2B7409,0xD0CA40,0xE8A077, 0x6A94AB,0xD5C4B3,0xFCE76E,0xFCFAE2
+};
/* Luminance for each palette entry, to be initialized as soon as the program begins */
static unsigned luma[palettesize];
@@ -389,28 +404,28 @@ MixingPlan DeviseBestMixingPlan(unsigned color, size_t limit) {
// Input color in CIE L*a*b*
LabItem input(color);
-
+
// Tally so far (gamma-corrected)
double so_far[3] = { 0,0,0 };
-
+
MixingPlan result;
while(result.size() < limit) {
unsigned chosen_amount = 1;
unsigned chosen = 0;
-
+
const unsigned max_test_count = result.empty() ? 1 : result.size();
-
+
double least_penalty = -1;
for(unsigned index=0; index<palettesize; ++index) {
//~ const unsigned color = pal[index];
double sum[3] = { so_far[0], so_far[1], so_far[2] };
double add[3] = { pal_g[index][0], pal_g[index][1], pal_g[index][2] };
-
+
for(unsigned p=1; p<=max_test_count; p*=2) {
for(unsigned c=0; c<3; ++c) sum[c] += add[c];
for(unsigned c=0; c<3; ++c) add[c] += add[c];
double t = result.size() + p;
-
+
double test[3] = { GammaUncorrect(sum[0]/t),
GammaUncorrect(sum[1]/t),
GammaUncorrect(sum[2]/t)
@@ -431,10 +446,10 @@ MixingPlan DeviseBestMixingPlan(unsigned color, size_t limit) {
}
}
}
-
+
// Append "chosen_amount" times "chosen" to the color list
result.resize(result.size() + chosen_amount, chosen);
-
+
for(unsigned c=0; c<3; ++c)
so_far[c] += pal_g[chosen][c] * chosen_amount;
}
@@ -447,7 +462,7 @@ int main(int argc, char**argv) {
FILE* fp = fopen(argv[1], "rb");
gdImagePtr srcim = gdImageCreateFromPng(fp);
fclose(fp);
-
+
unsigned w = gdImageSX(srcim), h = gdImageSY(srcim);
gdImagePtr im = gdImageCreate(w, h);
for(unsigned c=0; c<palettesize; ++c) {
diff --git a/utils/pvrtex/elbg.c b/utils/pvrtex/elbg.c
index 7a6a84fb..e258ef38 100644
--- a/utils/pvrtex/elbg.c
+++ b/utils/pvrtex/elbg.c
@@ -73,17 +73,20 @@ typedef struct ELBGContext {
static inline int distance_limited(int *a, int *b, int dim, int limit)
{
+ //Changing the conditional allows for auto-vectorization, and does not seem to
+ //have any affect on final result
int i, dist=0;
for (i=0; i<dim; i++) {
int64_t distance = a[i] - b[i];
distance *= distance;
- if (dist >= limit - distance)
- return limit;
+// if (dist >= limit - distance)
+// return limit;
dist += distance;
}
- return dist;
+// return dist;
+ return dist > limit ? limit : dist;
}
static inline void vect_division(int *res, int *vect, int div, int dim)
diff --git a/utils/pvrtex/file_common.c b/utils/pvrtex/file_common.c
index 739de151..aa527871 100644
--- a/utils/pvrtex/file_common.c
+++ b/utils/pvrtex/file_common.c
@@ -29,19 +29,19 @@ void Write16LE(unsigned int val, FILE *f) {
}
void WritePadZero(size_t len, FILE *f) {
static char paddingarea[64] = {0};
-
+
assert(f);
...<truncated>...
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|