From 581308c97b2fdc0220aca91bd9c7666ffc10e48b Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Tue, 12 Jul 2011 13:33:02 +0200 Subject: [PATCH] add a SRGB_MIXED mode --- s2tc.cpp | 40 +++++++++++++++++++++++++++++++++++++++- test.sh | 28 ++++++++++++++++------------ 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/s2tc.cpp b/s2tc.cpp index 1c6c4d6..5e8592a 100644 --- a/s2tc.cpp +++ b/s2tc.cpp @@ -560,6 +560,38 @@ inline int color_dist_srgb(const color_t &a, const color_t &b) // weight for v: sqrt(2^-5) / (0.5 / (1 - 0.11)) = 0.315 } +inline int srgb_get_y(const color_t &a) +{ + // convert to linear + int r = a.r * (int) a.r; + int g = a.g * (int) a.g; + int b = a.b * (int) a.b; + // find luminance + int y = 37 * (r * 21*2*2 + g * 72 + b * 7*2*2); // multiplier: 14555800 + // square root it (!) + y = sqrt(y); // now in range 0 to 3815 + return y; +} + +inline int color_dist_srgb_mixed(const color_t &a, const color_t &b) +{ + // get Y + int ay = srgb_get_y(a); + int by = srgb_get_y(b); + // get UV + int au = a.r * 20 - ay; + int av = a.b * 20 - ay; + int bu = b.r * 20 - by; + int bv = b.b * 20 - by; + // get differences + int y = ay - by; + int u = au - bu; + int v = av - bv; + return ((y*y) << 3) + SHRR(u*u, 1) + SHRR(v*v, 2); + // weight for u: ??? + // weight for v: ??? +} + // FIXME this is likely broken inline int color_dist_lab_srgb(const color_t &a, const color_t &b) { @@ -775,6 +807,7 @@ enum ColorDistMode RGB, YUV, SRGB, + SRGB_MIXED, LAB, AVG, NORMALMAP @@ -978,6 +1011,9 @@ void s2tc_encode_block(unsigned char *out, const unsigned char *rgba, int iw, in case SRGB: s2tc_encode_block(out, rgba, iw, w, h, dxt, nrandom); break; + case SRGB_MIXED: + s2tc_encode_block(out, rgba, iw, w, h, dxt, nrandom); + break; case LAB: s2tc_encode_block(out, rgba, iw, w, h, dxt, nrandom); break; @@ -1013,7 +1049,7 @@ int usage(const char *me) " [-o outfile.dds]\n" " [-t {DXT1|DXT3|DXT5}]\n" " [-r randomcount]\n" - " [-c {RGB|YUV|SRGB|LAB|AVG|NORMALMAP}]\n", + " [-c {RGB|YUV|SRGB|SRGB_MIXED|LAB|AVG|NORMALMAP}]\n", me); return 1; } @@ -1062,6 +1098,8 @@ int main(int argc, char **argv) cd = YUV; else if(!strcasecmp(optarg, "SRGB")) cd = SRGB; + else if(!strcasecmp(optarg, "SRGB_MIXED")) + cd = SRGB_MIXED; else if(!strcasecmp(optarg, "LAB")) cd = LAB; else if(!strcasecmp(optarg, "AVG")) diff --git a/test.sh b/test.sh index d2492ce..5a5ed50 100644 --- a/test.sh +++ b/test.sh @@ -16,13 +16,15 @@ html_start() echo >&3 "Original" echo >&3 "nvcompress" echo >&3 "rand64-sRGB" - echo >&3 "norand-sRGB" +# echo >&3 "norand-sRGB" + echo >&3 "rand64-sRGB-mixed" +# echo >&3 "norand-sRGB-mixed" echo >&3 "rand64-YUV" - echo >&3 "norand-YUV" +# echo >&3 "norand-YUV" echo >&3 "rand64" - echo >&3 "norand" +# echo >&3 "norand" echo >&3 "rand64-avg" - echo >&3 "norand-avg" +# echo >&3 "norand-avg" echo >&3 "" } html_rowstart() @@ -60,14 +62,16 @@ for i in amelia dxtfail base_concrete1a disabled floor_tile3a lift02 panel_ceil1 nvcompress "$i".tga "$i".dds html "$i".dds - t "$i".tga "$i"-rand64-srgb.dds ./s2tc -c SRGB -r 64 - t "$i".tga "$i"-norand-srgb.dds ./s2tc -c SRGB -r 0 - t "$i".tga "$i"-rand64-yuv.dds ./s2tc -c YUV -r 64 - t "$i".tga "$i"-norand-yuv.dds ./s2tc -c YUV -r 0 - t "$i".tga "$i"-rand64.dds ./s2tc -c RGB -r 64 - t "$i".tga "$i"-norand.dds ./s2tc -c RGB -r 0 - t "$i".tga "$i"-rand64-avg.dds ./s2tc -c AVG -r 64 - t "$i".tga "$i"-norand-avg.dds ./s2tc -c AVG -r 0 + t "$i".tga "$i"-rand64-srgb.dds ./s2tc -c SRGB -r 64 +# t "$i".tga "$i"-norand-srgb.dds ./s2tc -c SRGB -r 0 + t "$i".tga "$i"-rand64-mrgb.dds ./s2tc -c SRGB_MIXED -r 64 +# t "$i".tga "$i"-norand-mrgb.dds ./s2tc -c SRGB_MIXED -r 0 + t "$i".tga "$i"-rand64-yuv.dds ./s2tc -c YUV -r 64 +# t "$i".tga "$i"-norand-yuv.dds ./s2tc -c YUV -r 0 + t "$i".tga "$i"-rand64.dds ./s2tc -c RGB -r 64 +# t "$i".tga "$i"-norand.dds ./s2tc -c RGB -r 0 + t "$i".tga "$i"-rand64-avg.dds ./s2tc -c AVG -r 64 +# t "$i".tga "$i"-norand-avg.dds ./s2tc -c AVG -r 0 html_rowend done -- 2.11.0