|
From: kosmirror <kos...@us...> - 2025-08-26 18:17:57
|
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 7bd48056e76e750d1c90e0cc4aeb156f46da31f8 (commit)
via 20819a1c4b039cc3a64e3aadeea6485337776612 (commit)
via 3545637cfa0013c120501326f68a984283290e25 (commit)
via eaf857d4f450e8f7a058950215f4901b3a4bb6c9 (commit)
from 959ce90028b86a0595c1392bf5e549d955bc1071 (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 7bd48056e76e750d1c90e0cc4aeb156f46da31f8
Author: QuzarDC <qu...@co...>
Date: Mon Aug 25 17:50:57 2025 -0400
pvrtex: Provide compatibility for systems without `sincosf`
commit 20819a1c4b039cc3a64e3aadeea6485337776612
Author: QuzarDC <qu...@co...>
Date: Mon Aug 25 14:40:37 2025 -0400
pvrtex: Reimplement #749
commit 3545637cfa0013c120501326f68a984283290e25
Author: QuzarDC <qu...@co...>
Date: Mon Aug 25 13:49:10 2025 -0400
pvrtex: Reimplement fixes from #791 and #789.
commit eaf857d4f450e8f7a058950215f4901b3a4bb6c9
Author: QuzarDC <qu...@co...>
Date: Mon Aug 25 11:29:03 2025 -0400
pvrtex: Clean up whitespace
-----------------------------------------------------------------------
Summary of changes:
utils/pvrtex/Makefile | 28 ++--
utils/pvrtex/dither.cpp | 74 +++++------
utils/pvrtex/file_common.c | 24 ++--
utils/pvrtex/file_dctex.c | 40 +++---
utils/pvrtex/file_dctex.h | 154 +++++++++++-----------
utils/pvrtex/file_pvr.c | 78 +++++------
utils/pvrtex/file_tex.c | 28 ++--
utils/pvrtex/main.c | 74 +++++------
utils/pvrtex/mem.c | 2 +-
utils/pvrtex/nvmath.h | 86 +++++++------
utils/pvrtex/palette.c | 28 ++--
utils/pvrtex/pixel.h | 38 +++---
utils/pvrtex/pvr_texture.c | 90 ++++++-------
utils/pvrtex/pvr_texture.h | 10 +-
utils/pvrtex/pvr_texture_decoder.c | 44 +++----
utils/pvrtex/pvr_texture_decoder.h | 14 +-
utils/pvrtex/pvr_texture_encoder.c | 256 ++++++++++++++++++-------------------
utils/pvrtex/pvr_texture_encoder.h | 68 +++++-----
utils/pvrtex/tddither.c | 40 +++---
utils/pvrtex/vqcompress.c | 42 +++---
utils/pvrtex/vqcompress.h | 6 +-
21 files changed, 614 insertions(+), 610 deletions(-)
diff --git a/utils/pvrtex/Makefile b/utils/pvrtex/Makefile
index b6bd20bc..8f3cced0 100644
--- a/utils/pvrtex/Makefile
+++ b/utils/pvrtex/Makefile
@@ -7,15 +7,17 @@ OBJS = elbg.o mem.o log.o bprint.o avstring.o lfg.o crc.o md5.o stb_image_impl.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
+
ifeq ($(DEBUGBUILD), true)
-OPTMODE= -Og -pg -g
+ CXXFLAGS += -Og -pg -g
else
-OPTMODE= -O3 -flto=auto -march=native
+ CXXFLAGS += -O3
endif
-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
+CFLAGS := $(CXXFLAGS) -Wno-pointer-sign -std=gnu17
define textSegment2Header
mkdir -p info
@@ -24,22 +26,15 @@ define textSegment2Header
rm $2/$3.txt
endef
+.PHONY: all clean
+
all: $(TARGET) README
-.PHONY: all clean install
+$(TARGET): $(OBJS)
+ $(CXX) $(CXXFLAGS) -o $@ $^
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
@@ -49,7 +44,6 @@ 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)
diff --git a/utils/pvrtex/dither.cpp b/utils/pvrtex/dither.cpp
index 054762fa..5c09de5b 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;
@@ -255,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);
@@ -302,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 {
@@ -310,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 {
@@ -319,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;
{
@@ -331,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);
@@ -401,36 +401,36 @@ MixingPlan DeviseBestMixingPlan(unsigned color, size_t limit) {
(int)((color>>8)&0xFF),
(int)(color&0xFF)
};
-
+
// 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)
};
-
+
#if COMPARE_RGB
double penalty = ColorCompare(
input_rgb[0],input_rgb[1],input_rgb[2],
@@ -446,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;
}
@@ -462,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/file_common.c b/utils/pvrtex/file_common.c
index aa527871..8049bce3 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);
assert(len < sizeof(paddingarea));
-
+
CheckedFwrite(&paddingarea, len, f);
}
void WritePvrTexEncoder(const PvrTexEncoder *pte, FILE *f, ptewSmallVQType svq, int mip_skip) {
assert(pte);
assert(pte->pvr_tex);
assert(f);
-
+
unsigned texsize = CalcTextureSize(pte->w, pte->h, pte->pixel_format, pteHasMips(pte), pteIsCompressed(pte), 0);
-
+
if (pteIsCompressed(pte)) {
assert(pte->pvr_codebook);
@@ -52,7 +52,7 @@ void WritePvrTexEncoder(const PvrTexEncoder *pte, FILE *f, ptewSmallVQType svq,
pteLog(LOG_DEBUG, "Writing %u bytes for codebook\n", (unsigned)cbsize);
CheckedFwrite(pte->pvr_codebook + pte->pvr_idx_offset * PVR_CODEBOOK_ENTRY_SIZE_BYTES, cbsize, f);
}
-
+
if (!pteIsCompressed(pte) && pteHasMips(pte)) {
CheckedFwrite(pte->pvr_tex + mip_skip, texsize-mip_skip, f);
} else {
@@ -62,7 +62,7 @@ void WritePvrTexEncoder(const PvrTexEncoder *pte, FILE *f, ptewSmallVQType svq,
int FileSize(const char *fname) {
assert(fname);
-
+
FILE *f = fopen(fname, "r");
if (f == NULL)
return -1;
@@ -74,21 +74,21 @@ int FileSize(const char *fname) {
size_t Slurp(const char *fname, void **data) {
assert(fname);
-
+
FILE *f = fopen(fname, "r");
if (f == NULL)
return 0;
-
+
fseek(f, 0, SEEK_END);
int size = ftell(f);
-
+
fseek(f, 0, SEEK_SET);
-
+
SMART_ALLOC(data, size);
size_t readamt = fread(*data, 1, size, f);
-
+
fclose(f);
-
+
return readamt;
}
diff --git a/utils/pvrtex/file_dctex.c b/utils/pvrtex/file_dctex.c
index 6216217e..af66def2 100644
--- a/utils/pvrtex/file_dctex.c
+++ b/utils/pvrtex/file_dctex.c
@@ -22,35 +22,35 @@ static int convert_size(int size) {
return 1;
else
return 0;
-
+
}
void fDtWrite(const PvrTexEncoder *pte, const char *outfname) {
assert(pte);
-
+
FILE *f = fopen(outfname, "w");
assert(f);
-
+
unsigned textype = 0;
textype |= pteHasMips(pte) << FDT_MIPMAP_SHIFT;
textype |= pteIsCompressed(pte) << FDT_VQ_SHIFT;
textype |= pte->hw_pixel_format << FDT_PIXEL_FORMAT_SHIFT;
textype |= !pte->raw_is_twiddled << FDT_NOT_TWIDDLED_SHIFT;
-
+
//If the width is a power of two, we don't need the stride bit set
textype |= (pteIsStrided(pte) && !IsPow2(pte->w)) << FDT_STRIDE_SHIFT;
-
+
textype |= ((pte->w / 32) & FDT_STRIDE_VAL_MASK) << FDT_STRIDE_VAL_SHIFT;
textype |= !IsPow2(pte->h) << FDT_PARTIAL_SHIFT;
textype |= convert_size(pte->w) << FDT_WIDTH_SHIFT;
textype |= convert_size(pte->h) << FDT_HEIGHT_SHIFT;
-
+
//Include size of header
unsigned origsize = 32 + CalcTextureSize(pte->w, pte->h, pte->pixel_format, pteHasMips(pte), pteIsCompressed(pte), pte->codebook_size * 8);
unsigned size = ROUND_UP_POW2(origsize, 32);
unsigned paddingamt = size - origsize;
pteLog(LOG_DEBUG, "File size: %u orig + %u pad = %u total\n", origsize, paddingamt, size);
-
+
WriteFourCC("DcTx", f);
Write32LE(size, f);
Write8(0, f); //Version
@@ -63,17 +63,17 @@ void fDtWrite(const PvrTexEncoder *pte, const char *outfname) {
Write32LE(0, f);
Write32LE(0, f);
Write32LE(0, f);
-
+
WritePvrTexEncoder(pte, f, PTEW_FILE_DCTEX_SMALL_VQ, 0);
-
+
//Pad to 32 bytes
WritePadZero(paddingamt, f);
fclose(f);
-
+
//Validate resulting file
unsigned resultsize = FileSize(outfname);
ErrorExitOn(resultsize != size, "Size of file written for \"%s\" was incorrect. Expected file to be %u bytes, but result was %u bytes.\n", outfname, size, resultsize);
-
+
f = fopen(outfname, "r");
void *readbuff = malloc(size);
if (fread(readbuff, size, 1, f) == 1) {
@@ -91,24 +91,24 @@ void fDtWrite(const PvrTexEncoder *pte, const char *outfname) {
int fDtLoad(const char *fname, PvrTexDecoder *dst) {
assert(fname);
assert(dst);
-
+
void *data = NULL;
size_t size = Slurp(fname, &data);
-
+
if (size == 0 || data == 0)
goto err_exit;
-
+
fDtHeader *hdr = data;
if (size < sizeof(*hdr) || fDtGetTotalSize(hdr) < size) {
pteLog(LOG_WARNING, ".PVR file appears invalid (incomplete file?)\n");
goto err_exit;
}
-
+
if (!fDtValidateHeader(hdr)) {
pteLog(LOG_WARNING, ".DT file appears corrupt\n");
goto err_exit;
}
-
...<truncated>...
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|